tcpdf.php 884 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005
  1. <?php
  2. //============================================================+
  3. // File name : tcpdf.php
  4. // Version : 6.3.2
  5. // Begin : 2002-08-03
  6. // Last Update : 2019-09-20
  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-2019 Nicola Asuni - Tecnick.com LTD
  11. //
  12. // This file is part of TCPDF software library.
  13. //
  14. // TCPDF is free software: you can redistribute it and/or modify it
  15. // under the terms of the GNU Lesser General Public License as
  16. // published by the Free Software Foundation, either version 3 of the
  17. // License, or (at your option) any later version.
  18. //
  19. // TCPDF is distributed in the hope that it will be useful, but
  20. // WITHOUT ANY WARRANTY; without even the implied warranty of
  21. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. // See the GNU Lesser General Public License for more details.
  23. //
  24. // You should have received a copy of the License
  25. // along with TCPDF. If not, see
  26. // <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
  27. //
  28. // See LICENSE.TXT file for more information.
  29. // -------------------------------------------------------------------
  30. //
  31. // Description :
  32. // This is a PHP class for generating PDF documents without requiring external extensions.
  33. //
  34. // NOTE:
  35. // This class was originally derived in 2002 from the Public
  36. // Domain FPDF class by Olivier Plathey (http://www.fpdf.org),
  37. // but now is almost entirely rewritten and contains thousands of
  38. // new lines of code and hundreds new features.
  39. //
  40. // Main features:
  41. // * no external libraries are required for the basic functions;
  42. // * all standard page formats, custom page formats, custom margins and units of measure;
  43. // * UTF-8 Unicode and Right-To-Left languages;
  44. // * TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;
  45. // * font subsetting;
  46. // * methods to publish some XHTML + CSS code, Javascript and Forms;
  47. // * images, graphic (geometric figures) and transformation methods;
  48. // * supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImageMagick (http://www.imagemagick.org/www/formats.html)
  49. // * 1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extension, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;
  50. // * JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  51. // * automatic page header and footer management;
  52. // * document encryption up to 256 bit and digital signature certifications;
  53. // * transactions to UNDO commands;
  54. // * PDF annotations, including links, text and file attachments;
  55. // * text rendering modes (fill, stroke and clipping);
  56. // * multiple columns mode;
  57. // * no-write page regions;
  58. // * bookmarks, named destinations and table of content;
  59. // * text hyphenation;
  60. // * text stretching and spacing (tracking);
  61. // * automatic page break, line break and text alignments including justification;
  62. // * automatic page numbering and page groups;
  63. // * move and delete pages;
  64. // * page compression (requires php-zlib extension);
  65. // * XOBject Templates;
  66. // * Layers and object visibility.
  67. // * PDF/A-1b support
  68. //============================================================+
  69. /**
  70. * @file
  71. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  72. * TCPDF project (http://www.tcpdf.org) was originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
  73. * <h3>TCPDF main features are:</h3>
  74. * <ul>
  75. * <li>no external libraries are required for the basic functions;</li>
  76. * <li>all standard page formats, custom page formats, custom margins and units of measure;</li>
  77. * <li>UTF-8 Unicode and Right-To-Left languages;</li>
  78. * <li>TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;</li>
  79. * <li>font subsetting;</li>
  80. * <li>methods to publish some XHTML + CSS code, Javascript and Forms;</li>
  81. * <li>images, graphic (geometric figures) and transformation methods;
  82. * <li>supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImageMagick (http://www.imagemagick.org/www/formats.html)</li>
  83. * <li>1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extension, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;</li>
  84. * <li>JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;</li>
  85. * <li>automatic page header and footer management;</li>
  86. * <li>document encryption up to 256 bit and digital signature certifications;</li>
  87. * <li>transactions to UNDO commands;</li>
  88. * <li>PDF annotations, including links, text and file attachments;</li>
  89. * <li>text rendering modes (fill, stroke and clipping);</li>
  90. * <li>multiple columns mode;</li>
  91. * <li>no-write page regions;</li>
  92. * <li>bookmarks, named destinations and table of content;</li>
  93. * <li>text hyphenation;</li>
  94. * <li>text stretching and spacing (tracking);</li>
  95. * <li>automatic page break, line break and text alignments including justification;</li>
  96. * <li>automatic page numbering and page groups;</li>
  97. * <li>move and delete pages;</li>
  98. * <li>page compression (requires php-zlib extension);</li>
  99. * <li>XOBject Templates;</li>
  100. * <li>Layers and object visibility;</li>
  101. * <li>PDF/A-1b support.</li>
  102. * </ul>
  103. * Tools to encode your unicode fonts are on fonts/utils directory.</p>
  104. * @package com.tecnick.tcpdf
  105. * @author Nicola Asuni
  106. * @version 6.3.2
  107. */
  108. // TCPDF configuration
  109. require_once dirname(__FILE__).'/tcpdf_autoconfig.php';
  110. // TCPDF static font methods and data
  111. require_once dirname(__FILE__).'/include/tcpdf_font_data.php';
  112. // TCPDF static font methods and data
  113. require_once dirname(__FILE__).'/include/tcpdf_fonts.php';
  114. // TCPDF static color methods and data
  115. require_once dirname(__FILE__).'/include/tcpdf_colors.php';
  116. // TCPDF static image methods and data
  117. require_once dirname(__FILE__).'/include/tcpdf_images.php';
  118. // TCPDF static methods and data
  119. require_once dirname(__FILE__).'/include/tcpdf_static.php';
  120. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  121. /**
  122. * @class TCPDF
  123. * PHP class for generating PDF documents without requiring external extensions.
  124. * TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
  125. * @package com.tecnick.tcpdf
  126. * @brief PHP class for generating PDF documents without requiring external extensions.
  127. * @version 6.3.2
  128. * @author Nicola Asuni - info@tecnick.com
  129. * @IgnoreAnnotation("protected")
  130. * @IgnoreAnnotation("public")
  131. * @IgnoreAnnotation("pre")
  132. */
  133. class TCPDF
  134. {
  135. // Protected properties
  136. /**
  137. * Current page number.
  138. * @protected
  139. */
  140. protected $page;
  141. /**
  142. * Current object number.
  143. * @protected
  144. */
  145. protected $n;
  146. /**
  147. * Array of object offsets.
  148. * @protected
  149. */
  150. protected $offsets = array();
  151. /**
  152. * Array of object IDs for each page.
  153. * @protected
  154. */
  155. protected $pageobjects = array();
  156. /**
  157. * Buffer holding in-memory PDF.
  158. * @protected
  159. */
  160. protected $buffer;
  161. /**
  162. * Array containing pages.
  163. * @protected
  164. */
  165. protected $pages = array();
  166. /**
  167. * Current document state.
  168. * @protected
  169. */
  170. protected $state;
  171. /**
  172. * Compression flag.
  173. * @protected
  174. */
  175. protected $compress;
  176. /**
  177. * Current page orientation (P = Portrait, L = Landscape).
  178. * @protected
  179. */
  180. protected $CurOrientation;
  181. /**
  182. * Page dimensions.
  183. * @protected
  184. */
  185. protected $pagedim = array();
  186. /**
  187. * Scale factor (number of points in user unit).
  188. * @protected
  189. */
  190. protected $k;
  191. /**
  192. * Width of page format in points.
  193. * @protected
  194. */
  195. protected $fwPt;
  196. /**
  197. * Height of page format in points.
  198. * @protected
  199. */
  200. protected $fhPt;
  201. /**
  202. * Current width of page in points.
  203. * @protected
  204. */
  205. protected $wPt;
  206. /**
  207. * Current height of page in points.
  208. * @protected
  209. */
  210. protected $hPt;
  211. /**
  212. * Current width of page in user unit.
  213. * @protected
  214. */
  215. protected $w;
  216. /**
  217. * Current height of page in user unit.
  218. * @protected
  219. */
  220. protected $h;
  221. /**
  222. * Left margin.
  223. * @protected
  224. */
  225. protected $lMargin;
  226. /**
  227. * Right margin.
  228. * @protected
  229. */
  230. protected $rMargin;
  231. /**
  232. * Cell left margin (used by regions).
  233. * @protected
  234. */
  235. protected $clMargin;
  236. /**
  237. * Cell right margin (used by regions).
  238. * @protected
  239. */
  240. protected $crMargin;
  241. /**
  242. * Top margin.
  243. * @protected
  244. */
  245. protected $tMargin;
  246. /**
  247. * Page break margin.
  248. * @protected
  249. */
  250. protected $bMargin;
  251. /**
  252. * Array of cell internal paddings ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
  253. * @since 5.9.000 (2010-10-03)
  254. * @protected
  255. */
  256. protected $cell_padding = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  257. /**
  258. * Array of cell margins ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
  259. * @since 5.9.000 (2010-10-04)
  260. * @protected
  261. */
  262. protected $cell_margin = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  263. /**
  264. * Current horizontal position in user unit for cell positioning.
  265. * @protected
  266. */
  267. protected $x;
  268. /**
  269. * Current vertical position in user unit for cell positioning.
  270. * @protected
  271. */
  272. protected $y;
  273. /**
  274. * Height of last cell printed.
  275. * @protected
  276. */
  277. protected $lasth;
  278. /**
  279. * Line width in user unit.
  280. * @protected
  281. */
  282. protected $LineWidth;
  283. /**
  284. * Array of standard font names.
  285. * @protected
  286. */
  287. protected $CoreFonts;
  288. /**
  289. * Array of used fonts.
  290. * @protected
  291. */
  292. protected $fonts = array();
  293. /**
  294. * Array of font files.
  295. * @protected
  296. */
  297. protected $FontFiles = array();
  298. /**
  299. * Array of encoding differences.
  300. * @protected
  301. */
  302. protected $diffs = array();
  303. /**
  304. * Array of used images.
  305. * @protected
  306. */
  307. protected $images = array();
  308. /**
  309. * Depth of the svg tag, to keep track if the svg tag is a subtag or the root tag.
  310. * @protected
  311. */
  312. protected $svg_tag_depth = 0;
  313. /**
  314. * Array of Annotations in pages.
  315. * @protected
  316. */
  317. protected $PageAnnots = array();
  318. /**
  319. * Array of internal links.
  320. * @protected
  321. */
  322. protected $links = array();
  323. /**
  324. * Current font family.
  325. * @protected
  326. */
  327. protected $FontFamily;
  328. /**
  329. * Current font style.
  330. * @protected
  331. */
  332. protected $FontStyle;
  333. /**
  334. * Current font ascent (distance between font top and baseline).
  335. * @protected
  336. * @since 2.8.000 (2007-03-29)
  337. */
  338. protected $FontAscent;
  339. /**
  340. * Current font descent (distance between font bottom and baseline).
  341. * @protected
  342. * @since 2.8.000 (2007-03-29)
  343. */
  344. protected $FontDescent;
  345. /**
  346. * Underlining flag.
  347. * @protected
  348. */
  349. protected $underline;
  350. /**
  351. * Overlining flag.
  352. * @protected
  353. */
  354. protected $overline;
  355. /**
  356. * Current font info.
  357. * @protected
  358. */
  359. protected $CurrentFont;
  360. /**
  361. * Current font size in points.
  362. * @protected
  363. */
  364. protected $FontSizePt;
  365. /**
  366. * Current font size in user unit.
  367. * @protected
  368. */
  369. protected $FontSize;
  370. /**
  371. * Commands for drawing color.
  372. * @protected
  373. */
  374. protected $DrawColor;
  375. /**
  376. * Commands for filling color.
  377. * @protected
  378. */
  379. protected $FillColor;
  380. /**
  381. * Commands for text color.
  382. * @protected
  383. */
  384. protected $TextColor;
  385. /**
  386. * Indicates whether fill and text colors are different.
  387. * @protected
  388. */
  389. protected $ColorFlag;
  390. /**
  391. * Automatic page breaking.
  392. * @protected
  393. */
  394. protected $AutoPageBreak;
  395. /**
  396. * Threshold used to trigger page breaks.
  397. * @protected
  398. */
  399. protected $PageBreakTrigger;
  400. /**
  401. * Flag set when processing page header.
  402. * @protected
  403. */
  404. protected $InHeader = false;
  405. /**
  406. * Flag set when processing page footer.
  407. * @protected
  408. */
  409. protected $InFooter = false;
  410. /**
  411. * Zoom display mode.
  412. * @protected
  413. */
  414. protected $ZoomMode;
  415. /**
  416. * Layout display mode.
  417. * @protected
  418. */
  419. protected $LayoutMode;
  420. /**
  421. * If true set the document information dictionary in Unicode.
  422. * @protected
  423. */
  424. protected $docinfounicode = true;
  425. /**
  426. * Document title.
  427. * @protected
  428. */
  429. protected $title = '';
  430. /**
  431. * Document subject.
  432. * @protected
  433. */
  434. protected $subject = '';
  435. /**
  436. * Document author.
  437. * @protected
  438. */
  439. protected $author = '';
  440. /**
  441. * Document keywords.
  442. * @protected
  443. */
  444. protected $keywords = '';
  445. /**
  446. * Document creator.
  447. * @protected
  448. */
  449. protected $creator = '';
  450. /**
  451. * Starting page number.
  452. * @protected
  453. */
  454. protected $starting_page_number = 1;
  455. /**
  456. * The right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image.
  457. * @since 2002-07-31
  458. * @author Nicola Asuni
  459. * @protected
  460. */
  461. protected $img_rb_x;
  462. /**
  463. * The right-bottom corner Y coordinate of last inserted image.
  464. * @since 2002-07-31
  465. * @author Nicola Asuni
  466. * @protected
  467. */
  468. protected $img_rb_y;
  469. /**
  470. * Adjusting factor to convert pixels to user units.
  471. * @since 2004-06-14
  472. * @author Nicola Asuni
  473. * @protected
  474. */
  475. protected $imgscale = 1;
  476. /**
  477. * Boolean flag set to true when the input text is unicode (require unicode fonts).
  478. * @since 2005-01-02
  479. * @author Nicola Asuni
  480. * @protected
  481. */
  482. protected $isunicode = false;
  483. /**
  484. * PDF version.
  485. * @since 1.5.3
  486. * @protected
  487. */
  488. protected $PDFVersion = '1.7';
  489. /**
  490. * ID of the stored default header template (-1 = not set).
  491. * @protected
  492. */
  493. protected $header_xobjid = false;
  494. /**
  495. * If true reset the Header Xobject template at each page
  496. * @protected
  497. */
  498. protected $header_xobj_autoreset = false;
  499. /**
  500. * Minimum distance between header and top page margin.
  501. * @protected
  502. */
  503. protected $header_margin;
  504. /**
  505. * Minimum distance between footer and bottom page margin.
  506. * @protected
  507. */
  508. protected $footer_margin;
  509. /**
  510. * Original left margin value.
  511. * @protected
  512. * @since 1.53.0.TC013
  513. */
  514. protected $original_lMargin;
  515. /**
  516. * Original right margin value.
  517. * @protected
  518. * @since 1.53.0.TC013
  519. */
  520. protected $original_rMargin;
  521. /**
  522. * Default font used on page header.
  523. * @protected
  524. */
  525. protected $header_font;
  526. /**
  527. * Default font used on page footer.
  528. * @protected
  529. */
  530. protected $footer_font;
  531. /**
  532. * Language templates.
  533. * @protected
  534. */
  535. protected $l;
  536. /**
  537. * Barcode to print on page footer (only if set).
  538. * @protected
  539. */
  540. protected $barcode = false;
  541. /**
  542. * Boolean flag to print/hide page header.
  543. * @protected
  544. */
  545. protected $print_header = true;
  546. /**
  547. * Boolean flag to print/hide page footer.
  548. * @protected
  549. */
  550. protected $print_footer = true;
  551. /**
  552. * Header image logo.
  553. * @protected
  554. */
  555. protected $header_logo = '';
  556. /**
  557. * Width of header image logo in user units.
  558. * @protected
  559. */
  560. protected $header_logo_width = 30;
  561. /**
  562. * Title to be printed on default page header.
  563. * @protected
  564. */
  565. protected $header_title = '';
  566. /**
  567. * String to pring on page header after title.
  568. * @protected
  569. */
  570. protected $header_string = '';
  571. /**
  572. * Color for header text (RGB array).
  573. * @since 5.9.174 (2012-07-25)
  574. * @protected
  575. */
  576. protected $header_text_color = array(0,0,0);
  577. /**
  578. * Color for header line (RGB array).
  579. * @since 5.9.174 (2012-07-25)
  580. * @protected
  581. */
  582. protected $header_line_color = array(0,0,0);
  583. /**
  584. * Color for footer text (RGB array).
  585. * @since 5.9.174 (2012-07-25)
  586. * @protected
  587. */
  588. protected $footer_text_color = array(0,0,0);
  589. /**
  590. * Color for footer line (RGB array).
  591. * @since 5.9.174 (2012-07-25)
  592. * @protected
  593. */
  594. protected $footer_line_color = array(0,0,0);
  595. /**
  596. * Text shadow data array.
  597. * @since 5.9.174 (2012-07-25)
  598. * @protected
  599. */
  600. protected $txtshadow = array('enabled'=>false, 'depth_w'=>0, 'depth_h'=>0, 'color'=>false, 'opacity'=>1, 'blend_mode'=>'Normal');
  601. /**
  602. * Default number of columns for html table.
  603. * @protected
  604. */
  605. protected $default_table_columns = 4;
  606. // variables for html parser
  607. /**
  608. * HTML PARSER: array to store current link and rendering styles.
  609. * @protected
  610. */
  611. protected $HREF = array();
  612. /**
  613. * List of available fonts on filesystem.
  614. * @protected
  615. */
  616. protected $fontlist = array();
  617. /**
  618. * Current foreground color.
  619. * @protected
  620. */
  621. protected $fgcolor;
  622. /**
  623. * HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  624. * @protected
  625. */
  626. protected $listordered = array();
  627. /**
  628. * HTML PARSER: array count list items on nested lists.
  629. * @protected
  630. */
  631. protected $listcount = array();
  632. /**
  633. * HTML PARSER: current list nesting level.
  634. * @protected
  635. */
  636. protected $listnum = 0;
  637. /**
  638. * HTML PARSER: indent amount for lists.
  639. * @protected
  640. */
  641. protected $listindent = 0;
  642. /**
  643. * HTML PARSER: current list indententation level.
  644. * @protected
  645. */
  646. protected $listindentlevel = 0;
  647. /**
  648. * Current background color.
  649. * @protected
  650. */
  651. protected $bgcolor;
  652. /**
  653. * Temporary font size in points.
  654. * @protected
  655. */
  656. protected $tempfontsize = 10;
  657. /**
  658. * Spacer string for LI tags.
  659. * @protected
  660. */
  661. protected $lispacer = '';
  662. /**
  663. * Default encoding.
  664. * @protected
  665. * @since 1.53.0.TC010
  666. */
  667. protected $encoding = 'UTF-8';
  668. /**
  669. * PHP internal encoding.
  670. * @protected
  671. * @since 1.53.0.TC016
  672. */
  673. protected $internal_encoding;
  674. /**
  675. * Boolean flag to indicate if the document language is Right-To-Left.
  676. * @protected
  677. * @since 2.0.000
  678. */
  679. protected $rtl = false;
  680. /**
  681. * Boolean flag used to force RTL or LTR string direction.
  682. * @protected
  683. * @since 2.0.000
  684. */
  685. protected $tmprtl = false;
  686. // --- Variables used for document encryption:
  687. /**
  688. * IBoolean flag indicating whether document is protected.
  689. * @protected
  690. * @since 2.0.000 (2008-01-02)
  691. */
  692. protected $encrypted;
  693. /**
  694. * Array containing encryption settings.
  695. * @protected
  696. * @since 5.0.005 (2010-05-11)
  697. */
  698. protected $encryptdata = array();
  699. /**
  700. * Last RC4 key encrypted (cached for optimisation).
  701. * @protected
  702. * @since 2.0.000 (2008-01-02)
  703. */
  704. protected $last_enc_key;
  705. /**
  706. * Last RC4 computed key.
  707. * @protected
  708. * @since 2.0.000 (2008-01-02)
  709. */
  710. protected $last_enc_key_c;
  711. /**
  712. * File ID (used on document trailer).
  713. * @protected
  714. * @since 5.0.005 (2010-05-12)
  715. */
  716. protected $file_id;
  717. // --- bookmark ---
  718. /**
  719. * Outlines for bookmark.
  720. * @protected
  721. * @since 2.1.002 (2008-02-12)
  722. */
  723. protected $outlines = array();
  724. /**
  725. * Outline root for bookmark.
  726. * @protected
  727. * @since 2.1.002 (2008-02-12)
  728. */
  729. protected $OutlineRoot;
  730. // --- javascript and form ---
  731. /**
  732. * Javascript code.
  733. * @protected
  734. * @since 2.1.002 (2008-02-12)
  735. */
  736. protected $javascript = '';
  737. /**
  738. * Javascript counter.
  739. * @protected
  740. * @since 2.1.002 (2008-02-12)
  741. */
  742. protected $n_js;
  743. /**
  744. * line through state
  745. * @protected
  746. * @since 2.8.000 (2008-03-19)
  747. */
  748. protected $linethrough;
  749. /**
  750. * Array with additional document-wide usage rights for the document.
  751. * @protected
  752. * @since 5.8.014 (2010-08-23)
  753. */
  754. protected $ur = array();
  755. /**
  756. * DPI (Dot Per Inch) Document Resolution (do not change).
  757. * @protected
  758. * @since 3.0.000 (2008-03-27)
  759. */
  760. protected $dpi = 72;
  761. /**
  762. * Array of page numbers were a new page group was started (the page numbers are the keys of the array).
  763. * @protected
  764. * @since 3.0.000 (2008-03-27)
  765. */
  766. protected $newpagegroup = array();
  767. /**
  768. * Array that contains the number of pages in each page group.
  769. * @protected
  770. * @since 3.0.000 (2008-03-27)
  771. */
  772. protected $pagegroups = array();
  773. /**
  774. * Current page group number.
  775. * @protected
  776. * @since 3.0.000 (2008-03-27)
  777. */
  778. protected $currpagegroup = 0;
  779. /**
  780. * Array of transparency objects and parameters.
  781. * @protected
  782. * @since 3.0.000 (2008-03-27)
  783. */
  784. protected $extgstates;
  785. /**
  786. * Set the default JPEG compression quality (1-100).
  787. * @protected
  788. * @since 3.0.000 (2008-03-27)
  789. */
  790. protected $jpeg_quality;
  791. /**
  792. * Default cell height ratio.
  793. * @protected
  794. * @since 3.0.014 (2008-05-23)
  795. */
  796. protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  797. /**
  798. * PDF viewer preferences.
  799. * @protected
  800. * @since 3.1.000 (2008-06-09)
  801. */
  802. protected $viewer_preferences;
  803. /**
  804. * A name object specifying how the document should be displayed when opened.
  805. * @protected
  806. * @since 3.1.000 (2008-06-09)
  807. */
  808. protected $PageMode;
  809. /**
  810. * Array for storing gradient information.
  811. * @protected
  812. * @since 3.1.000 (2008-06-09)
  813. */
  814. protected $gradients = array();
  815. /**
  816. * Array used to store positions inside the pages buffer (keys are the page numbers).
  817. * @protected
  818. * @since 3.2.000 (2008-06-26)
  819. */
  820. protected $intmrk = array();
  821. /**
  822. * Array used to store positions inside the pages buffer (keys are the page numbers).
  823. * @protected
  824. * @since 5.7.000 (2010-08-03)
  825. */
  826. protected $bordermrk = array();
  827. /**
  828. * Array used to store page positions to track empty pages (keys are the page numbers).
  829. * @protected
  830. * @since 5.8.007 (2010-08-18)
  831. */
  832. protected $emptypagemrk = array();
  833. /**
  834. * Array used to store content positions inside the pages buffer (keys are the page numbers).
  835. * @protected
  836. * @since 4.6.021 (2009-07-20)
  837. */
  838. protected $cntmrk = array();
  839. /**
  840. * Array used to store footer positions of each page.
  841. * @protected
  842. * @since 3.2.000 (2008-07-01)
  843. */
  844. protected $footerpos = array();
  845. /**
  846. * Array used to store footer length of each page.
  847. * @protected
  848. * @since 4.0.014 (2008-07-29)
  849. */
  850. protected $footerlen = array();
  851. /**
  852. * Boolean flag to indicate if a new line is created.
  853. * @protected
  854. * @since 3.2.000 (2008-07-01)
  855. */
  856. protected $newline = true;
  857. /**
  858. * End position of the latest inserted line.
  859. * @protected
  860. * @since 3.2.000 (2008-07-01)
  861. */
  862. protected $endlinex = 0;
  863. /**
  864. * PDF string for width value of the last line.
  865. * @protected
  866. * @since 4.0.006 (2008-07-16)
  867. */
  868. protected $linestyleWidth = '';
  869. /**
  870. * PDF string for CAP value of the last line.
  871. * @protected
  872. * @since 4.0.006 (2008-07-16)
  873. */
  874. protected $linestyleCap = '0 J';
  875. /**
  876. * PDF string for join value of the last line.
  877. * @protected
  878. * @since 4.0.006 (2008-07-16)
  879. */
  880. protected $linestyleJoin = '0 j';
  881. /**
  882. * PDF string for dash value of the last line.
  883. * @protected
  884. * @since 4.0.006 (2008-07-16)
  885. */
  886. protected $linestyleDash = '[] 0 d';
  887. /**
  888. * Boolean flag to indicate if marked-content sequence is open.
  889. * @protected
  890. * @since 4.0.013 (2008-07-28)
  891. */
  892. protected $openMarkedContent = false;
  893. /**
  894. * Count the latest inserted vertical spaces on HTML.
  895. * @protected
  896. * @since 4.0.021 (2008-08-24)
  897. */
  898. protected $htmlvspace = 0;
  899. /**
  900. * Array of Spot colors.
  901. * @protected
  902. * @since 4.0.024 (2008-09-12)
  903. */
  904. protected $spot_colors = array();
  905. /**
  906. * Symbol used for HTML unordered list items.
  907. * @protected
  908. * @since 4.0.028 (2008-09-26)
  909. */
  910. protected $lisymbol = '';
  911. /**
  912. * String used to mark the beginning and end of EPS image blocks.
  913. * @protected
  914. * @since 4.1.000 (2008-10-18)
  915. */
  916. protected $epsmarker = 'x#!#EPS#!#x';
  917. /**
  918. * Array of transformation matrix.
  919. * @protected
  920. * @since 4.2.000 (2008-10-29)
  921. */
  922. protected $transfmatrix = array();
  923. /**
  924. * Current key for transformation matrix.
  925. * @protected
  926. * @since 4.8.005 (2009-09-17)
  927. */
  928. protected $transfmatrix_key = 0;
  929. /**
  930. * Booklet mode for double-sided pages.
  931. * @protected
  932. * @since 4.2.000 (2008-10-29)
  933. */
  934. protected $booklet = false;
  935. /**
  936. * Epsilon value used for float calculations.
  937. * @protected
  938. * @since 4.2.000 (2008-10-29)
  939. */
  940. protected $feps = 0.005;
  941. /**
  942. * Array used for custom vertical spaces for HTML tags.
  943. * @protected
  944. * @since 4.2.001 (2008-10-30)
  945. */
  946. protected $tagvspaces = array();
  947. /**
  948. * HTML PARSER: custom indent amount for lists. Negative value means disabled.
  949. * @protected
  950. * @since 4.2.007 (2008-11-12)
  951. */
  952. protected $customlistindent = -1;
  953. /**
  954. * Boolean flag to indicate if the border of the cell sides that cross the page should be removed.
  955. * @protected
  956. * @since 4.2.010 (2008-11-14)
  957. */
  958. protected $opencell = true;
  959. /**
  960. * Array of files to embedd.
  961. * @protected
  962. * @since 4.4.000 (2008-12-07)
  963. */
  964. protected $embeddedfiles = array();
  965. /**
  966. * Boolean flag to indicate if we are inside a PRE tag.
  967. * @protected
  968. * @since 4.4.001 (2008-12-08)
  969. */
  970. protected $premode = false;
  971. /**
  972. * Array used to store positions of graphics transformation blocks inside the page buffer.
  973. * keys are the page numbers
  974. * @protected
  975. * @since 4.4.002 (2008-12-09)
  976. */
  977. protected $transfmrk = array();
  978. /**
  979. * Default color for html links.
  980. * @protected
  981. * @since 4.4.003 (2008-12-09)
  982. */
  983. protected $htmlLinkColorArray = array(0, 0, 255);
  984. /**
  985. * Default font style to add to html links.
  986. * @protected
  987. * @since 4.4.003 (2008-12-09)
  988. */
  989. protected $htmlLinkFontStyle = 'U';
  990. /**
  991. * Counts the number of pages.
  992. * @protected
  993. * @since 4.5.000 (2008-12-31)
  994. */
  995. protected $numpages = 0;
  996. /**
  997. * Array containing page lengths in bytes.
  998. * @protected
  999. * @since 4.5.000 (2008-12-31)
  1000. */
  1001. protected $pagelen = array();
  1002. /**
  1003. * Counts the number of pages.
  1004. * @protected
  1005. * @since 4.5.000 (2008-12-31)
  1006. */
  1007. protected $numimages = 0;
  1008. /**
  1009. * Store the image keys.
  1010. * @protected
  1011. * @since 4.5.000 (2008-12-31)
  1012. */
  1013. protected $imagekeys = array();
  1014. /**
  1015. * Length of the buffer in bytes.
  1016. * @protected
  1017. * @since 4.5.000 (2008-12-31)
  1018. */
  1019. protected $bufferlen = 0;
  1020. /**
  1021. * Counts the number of fonts.
  1022. * @protected
  1023. * @since 4.5.000 (2009-01-02)
  1024. */
  1025. protected $numfonts = 0;
  1026. /**
  1027. * Store the font keys.
  1028. * @protected
  1029. * @since 4.5.000 (2009-01-02)
  1030. */
  1031. protected $fontkeys = array();
  1032. /**
  1033. * Store the font object IDs.
  1034. * @protected
  1035. * @since 4.8.001 (2009-09-09)
  1036. */
  1037. protected $font_obj_ids = array();
  1038. /**
  1039. * Store the fage status (true when opened, false when closed).
  1040. * @protected
  1041. * @since 4.5.000 (2009-01-02)
  1042. */
  1043. protected $pageopen = array();
  1044. /**
  1045. * Default monospace font.
  1046. * @protected
  1047. * @since 4.5.025 (2009-03-10)
  1048. */
  1049. protected $default_monospaced_font = 'freemono';
  1050. /**
  1051. * Cloned copy of the current class object.
  1052. * @protected
  1053. * @since 4.5.029 (2009-03-19)
  1054. */
  1055. protected $objcopy;
  1056. /**
  1057. * Array used to store the lengths of cache files.
  1058. * @protected
  1059. * @since 4.5.029 (2009-03-19)
  1060. */
  1061. protected $cache_file_length = array();
  1062. /**
  1063. * Table header content to be repeated on each new page.
  1064. * @protected
  1065. * @since 4.5.030 (2009-03-20)
  1066. */
  1067. protected $thead = '';
  1068. /**
  1069. * Margins used for table header.
  1070. * @protected
  1071. * @since 4.5.030 (2009-03-20)
  1072. */
  1073. protected $theadMargins = array();
  1074. /**
  1075. * Boolean flag to enable document digital signature.
  1076. * @protected
  1077. * @since 4.6.005 (2009-04-24)
  1078. */
  1079. protected $sign = false;
  1080. /**
  1081. * Digital signature data.
  1082. * @protected
  1083. * @since 4.6.005 (2009-04-24)
  1084. */
  1085. protected $signature_data = array();
  1086. /**
  1087. * Digital signature max length.
  1088. * @protected
  1089. * @since 4.6.005 (2009-04-24)
  1090. */
  1091. protected $signature_max_length = 11742;
  1092. /**
  1093. * Data for digital signature appearance.
  1094. * @protected
  1095. * @since 5.3.011 (2010-06-16)
  1096. */
  1097. protected $signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
  1098. /**
  1099. * Array of empty digital signature appearances.
  1100. * @protected
  1101. * @since 5.9.101 (2011-07-06)
  1102. */
  1103. protected $empty_signature_appearance = array();
  1104. /**
  1105. * Boolean flag to enable document timestamping with TSA.
  1106. * @protected
  1107. * @since 6.0.085 (2014-06-19)
  1108. */
  1109. protected $tsa_timestamp = false;
  1110. /**
  1111. * Timestamping data.
  1112. * @protected
  1113. * @since 6.0.085 (2014-06-19)
  1114. */
  1115. protected $tsa_data = array();
  1116. /**
  1117. * Regular expression used to find blank characters (required for word-wrapping).
  1118. * @protected
  1119. * @since 4.6.006 (2009-04-28)
  1120. */
  1121. protected $re_spaces = '/[^\S\xa0]/';
  1122. /**
  1123. * Array of $re_spaces parts.
  1124. * @protected
  1125. * @since 5.5.011 (2010-07-09)
  1126. */
  1127. protected $re_space = array('p' => '[^\S\xa0]', 'm' => '');
  1128. /**
  1129. * Digital signature object ID.
  1130. * @protected
  1131. * @since 4.6.022 (2009-06-23)
  1132. */
  1133. protected $sig_obj_id = 0;
  1134. /**
  1135. * ID of page objects.
  1136. * @protected
  1137. * @since 4.7.000 (2009-08-29)
  1138. */
  1139. protected $page_obj_id = array();
  1140. /**
  1141. * List of form annotations IDs.
  1142. * @protected
  1143. * @since 4.8.000 (2009-09-07)
  1144. */
  1145. protected $form_obj_id = array();
  1146. /**
  1147. * 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.
  1148. * @protected
  1149. * @since 4.8.000 (2009-09-07)
  1150. */
  1151. protected $default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1152. /**
  1153. * Javascript objects array.
  1154. * @protected
  1155. * @since 4.8.000 (2009-09-07)
  1156. */
  1157. protected $js_objects = array();
  1158. /**
  1159. * Current form action (used during XHTML rendering).
  1160. * @protected
  1161. * @since 4.8.000 (2009-09-07)
  1162. */
  1163. protected $form_action = '';
  1164. /**
  1165. * Current form encryption type (used during XHTML rendering).
  1166. * @protected
  1167. * @since 4.8.000 (2009-09-07)
  1168. */
  1169. protected $form_enctype = 'application/x-www-form-urlencoded';
  1170. /**
  1171. * Current method to submit forms.
  1172. * @protected
  1173. * @since 4.8.000 (2009-09-07)
  1174. */
  1175. protected $form_mode = 'post';
  1176. /**
  1177. * List of fonts used on form fields (fontname => fontkey).
  1178. * @protected
  1179. * @since 4.8.001 (2009-09-09)
  1180. */
  1181. protected $annotation_fonts = array();
  1182. /**
  1183. * List of radio buttons parent objects.
  1184. * @protected
  1185. * @since 4.8.001 (2009-09-09)
  1186. */
  1187. protected $radiobutton_groups = array();
  1188. /**
  1189. * List of radio group objects IDs.
  1190. * @protected
  1191. * @since 4.8.001 (2009-09-09)
  1192. */
  1193. protected $radio_groups = array();
  1194. /**
  1195. * Text indentation value (used for text-indent CSS attribute).
  1196. * @protected
  1197. * @since 4.8.006 (2009-09-23)
  1198. */
  1199. protected $textindent = 0;
  1200. /**
  1201. * Store page number when startTransaction() is called.
  1202. * @protected
  1203. * @since 4.8.006 (2009-09-23)
  1204. */
  1205. protected $start_transaction_page = 0;
  1206. /**
  1207. * Store Y position when startTransaction() is called.
  1208. * @protected
  1209. * @since 4.9.001 (2010-03-28)
  1210. */
  1211. protected $start_transaction_y = 0;
  1212. /**
  1213. * True when we are printing the thead section on a new page.
  1214. * @protected
  1215. * @since 4.8.027 (2010-01-25)
  1216. */
  1217. protected $inthead = false;
  1218. /**
  1219. * Array of column measures (width, space, starting Y position).
  1220. * @protected
  1221. * @since 4.9.001 (2010-03-28)
  1222. */
  1223. protected $columns = array();
  1224. /**
  1225. * Number of colums.
  1226. * @protected
  1227. * @since 4.9.001 (2010-03-28)
  1228. */
  1229. protected $num_columns = 1;
  1230. /**
  1231. * Current column number.
  1232. * @protected
  1233. * @since 4.9.001 (2010-03-28)
  1234. */
  1235. protected $current_column = 0;
  1236. /**
  1237. * Starting page for columns.
  1238. * @protected
  1239. * @since 4.9.001 (2010-03-28)
  1240. */
  1241. protected $column_start_page = 0;
  1242. /**
  1243. * Maximum page and column selected.
  1244. * @protected
  1245. * @since 5.8.000 (2010-08-11)
  1246. */
  1247. protected $maxselcol = array('page' => 0, 'column' => 0);
  1248. /**
  1249. * Array of: X difference between table cell x start and starting page margin, cellspacing, cellpadding.
  1250. * @protected
  1251. * @since 5.8.000 (2010-08-11)
  1252. */
  1253. protected $colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  1254. /**
  1255. * 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.
  1256. * @protected
  1257. * @since 4.9.008 (2010-04-03)
  1258. */
  1259. protected $textrendermode = 0;
  1260. /**
  1261. * Text stroke width in doc units.
  1262. * @protected
  1263. * @since 4.9.008 (2010-04-03)
  1264. */
  1265. protected $textstrokewidth = 0;
  1266. /**
  1267. * Current stroke color.
  1268. * @protected
  1269. * @since 4.9.008 (2010-04-03)
  1270. */
  1271. protected $strokecolor;
  1272. /**
  1273. * Default unit of measure for document.
  1274. * @protected
  1275. * @since 5.0.000 (2010-04-22)
  1276. */
  1277. protected $pdfunit = 'mm';
  1278. /**
  1279. * Boolean flag true when we are on TOC (Table Of Content) page.
  1280. * @protected
  1281. */
  1282. protected $tocpage = false;
  1283. /**
  1284. * Boolean flag: if true convert vector images (SVG, EPS) to raster image using GD or ImageMagick library.
  1285. * @protected
  1286. * @since 5.0.000 (2010-04-26)
  1287. */
  1288. protected $rasterize_vector_images = false;
  1289. /**
  1290. * Boolean flag: if true enables font subsetting by default.
  1291. * @protected
  1292. * @since 5.3.002 (2010-06-07)
  1293. */
  1294. protected $font_subsetting = true;
  1295. /**
  1296. * Array of default graphic settings.
  1297. * @protected
  1298. * @since 5.5.008 (2010-07-02)
  1299. */
  1300. protected $default_graphic_vars = array();
  1301. /**
  1302. * Array of XObjects.
  1303. * @protected
  1304. * @since 5.8.014 (2010-08-23)
  1305. */
  1306. protected $xobjects = array();
  1307. /**
  1308. * Boolean value true when we are inside an XObject.
  1309. * @protected
  1310. * @since 5.8.017 (2010-08-24)
  1311. */
  1312. protected $inxobj = false;
  1313. /**
  1314. * Current XObject ID.
  1315. * @protected
  1316. * @since 5.8.017 (2010-08-24)
  1317. */
  1318. protected $xobjid = '';
  1319. /**
  1320. * Percentage of character stretching.
  1321. * @protected
  1322. * @since 5.9.000 (2010-09-29)
  1323. */
  1324. protected $font_stretching = 100;
  1325. /**
  1326. * Increases or decreases the space between characters in a text by the specified amount (tracking).
  1327. * @protected
  1328. * @since 5.9.000 (2010-09-29)
  1329. */
  1330. protected $font_spacing = 0;
  1331. /**
  1332. * Array of no-write regions.
  1333. * ('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)
  1334. * @protected
  1335. * @since 5.9.003 (2010-10-14)
  1336. */
  1337. protected $page_regions = array();
  1338. /**
  1339. * Boolean value true when page region check is active.
  1340. * @protected
  1341. */
  1342. protected $check_page_regions = true;
  1343. /**
  1344. * Array of PDF layers data.
  1345. * @protected
  1346. * @since 5.9.102 (2011-07-13)
  1347. */
  1348. protected $pdflayers = array();
  1349. /**
  1350. * A dictionary of names and corresponding destinations (Dests key on document Catalog).
  1351. * @protected
  1352. * @since 5.9.097 (2011-06-23)
  1353. */
  1354. protected $dests = array();
  1355. /**
  1356. * Object ID for Named Destinations
  1357. * @protected
  1358. * @since 5.9.097 (2011-06-23)
  1359. */
  1360. protected $n_dests;
  1361. /**
  1362. * Embedded Files Names
  1363. * @protected
  1364. * @since 5.9.204 (2013-01-23)
  1365. */
  1366. protected $efnames = array();
  1367. /**
  1368. * Directory used for the last SVG image.
  1369. * @protected
  1370. * @since 5.0.000 (2010-05-05)
  1371. */
  1372. protected $svgdir = '';
  1373. /**
  1374. * Deafult unit of measure for SVG.
  1375. * @protected
  1376. * @since 5.0.000 (2010-05-02)
  1377. */
  1378. protected $svgunit = 'px';
  1379. /**
  1380. * Array of SVG gradients.
  1381. * @protected
  1382. * @since 5.0.000 (2010-05-02)
  1383. */
  1384. protected $svggradients = array();
  1385. /**
  1386. * ID of last SVG gradient.
  1387. * @protected
  1388. * @since 5.0.000 (2010-05-02)
  1389. */
  1390. protected $svggradientid = 0;
  1391. /**
  1392. * Boolean value true when in SVG defs group.
  1393. * @protected
  1394. * @since 5.0.000 (2010-05-02)
  1395. */
  1396. protected $svgdefsmode = false;
  1397. /**
  1398. * Array of SVG defs.
  1399. * @protected
  1400. * @since 5.0.000 (2010-05-02)
  1401. */
  1402. protected $svgdefs = array();
  1403. /**
  1404. * Boolean value true when in SVG clipPath tag.
  1405. * @protected
  1406. * @since 5.0.000 (2010-04-26)
  1407. */
  1408. protected $svgclipmode = false;
  1409. /**
  1410. * Array of SVG clipPath commands.
  1411. * @protected
  1412. * @since 5.0.000 (2010-05-02)
  1413. */
  1414. protected $svgclippaths = array();
  1415. /**
  1416. * Array of SVG clipPath tranformation matrix.
  1417. * @protected
  1418. * @since 5.8.022 (2010-08-31)
  1419. */
  1420. protected $svgcliptm = array();
  1421. /**
  1422. * ID of last SVG clipPath.
  1423. * @protected
  1424. * @since 5.0.000 (2010-05-02)
  1425. */
  1426. protected $svgclipid = 0;
  1427. /**
  1428. * SVG text.
  1429. * @protected
  1430. * @since 5.0.000 (2010-05-02)
  1431. */
  1432. protected $svgtext = '';
  1433. /**
  1434. * SVG text properties.
  1435. * @protected
  1436. * @since 5.8.013 (2010-08-23)
  1437. */
  1438. protected $svgtextmode = array();
  1439. /**
  1440. * Array of SVG properties.
  1441. * @protected
  1442. * @since 5.0.000 (2010-05-02)
  1443. */
  1444. protected $svgstyles = array(array(
  1445. 'alignment-baseline' => 'auto',
  1446. 'baseline-shift' => 'baseline',
  1447. 'clip' => 'auto',
  1448. 'clip-path' => 'none',
  1449. 'clip-rule' => 'nonzero',
  1450. 'color' => 'black',
  1451. 'color-interpolation' => 'sRGB',
  1452. 'color-interpolation-filters' => 'linearRGB',
  1453. 'color-profile' => 'auto',
  1454. 'color-rendering' => 'auto',
  1455. 'cursor' => 'auto',
  1456. 'direction' => 'ltr',
  1457. 'display' => 'inline',
  1458. 'dominant-baseline' => 'auto',
  1459. 'enable-background' => 'accumulate',
  1460. 'fill' => 'black',
  1461. 'fill-opacity' => 1,
  1462. 'fill-rule' => 'nonzero',
  1463. 'filter' => 'none',
  1464. 'flood-color' => 'black',
  1465. 'flood-opacity' => 1,
  1466. 'font' => '',
  1467. 'font-family' => 'helvetica',
  1468. 'font-size' => 'medium',
  1469. 'font-size-adjust' => 'none',
  1470. 'font-stretch' => 'normal',
  1471. 'font-style' => 'normal',
  1472. 'font-variant' => 'normal',
  1473. 'font-weight' => 'normal',
  1474. 'glyph-orientation-horizontal' => '0deg',
  1475. 'glyph-orientation-vertical' => 'auto',
  1476. 'image-rendering' => 'auto',
  1477. 'kerning' => 'auto',
  1478. 'letter-spacing' => 'normal',
  1479. 'lighting-color' => 'white',
  1480. 'marker' => '',
  1481. 'marker-end' => 'none',
  1482. 'marker-mid' => 'none',
  1483. 'marker-start' => 'none',
  1484. 'mask' => 'none',
  1485. 'opacity' => 1,
  1486. 'overflow' => 'auto',
  1487. 'pointer-events' => 'visiblePainted',
  1488. 'shape-rendering' => 'auto',
  1489. 'stop-color' => 'black',
  1490. 'stop-opacity' => 1,
  1491. 'stroke' => 'none',
  1492. 'stroke-dasharray' => 'none',
  1493. 'stroke-dashoffset' => 0,
  1494. 'stroke-linecap' => 'butt',
  1495. 'stroke-linejoin' => 'miter',
  1496. 'stroke-miterlimit' => 4,
  1497. 'stroke-opacity' => 1,
  1498. 'stroke-width' => 1,
  1499. 'text-anchor' => 'start',
  1500. 'text-decoration' => 'none',
  1501. 'text-rendering' => 'auto',
  1502. 'unicode-bidi' => 'normal',
  1503. 'visibility' => 'visible',
  1504. 'word-spacing' => 'normal',
  1505. 'writing-mode' => 'lr-tb',
  1506. 'text-color' => 'black',
  1507. 'transfmatrix' => array(1, 0, 0, 1, 0, 0)
  1508. ));
  1509. /**
  1510. * If true force sRGB color profile for all document.
  1511. * @protected
  1512. * @since 5.9.121 (2011-09-28)
  1513. */
  1514. protected $force_srgb = false;
  1515. /**
  1516. * If true set the document to PDF/A mode.
  1517. * @protected
  1518. * @since 5.9.121 (2011-09-27)
  1519. */
  1520. protected $pdfa_mode = false;
  1521. /**
  1522. * version of PDF/A mode (1 - 3).
  1523. * @protected
  1524. * @since 6.2.26 (2019-03-12)
  1525. */
  1526. protected $pdfa_version = 1;
  1527. /**
  1528. * Document creation date-time
  1529. * @protected
  1530. * @since 5.9.152 (2012-03-22)
  1531. */
  1532. protected $doc_creation_timestamp;
  1533. /**
  1534. * Document modification date-time
  1535. * @protected
  1536. * @since 5.9.152 (2012-03-22)
  1537. */
  1538. protected $doc_modification_timestamp;
  1539. /**
  1540. * Custom XMP data.
  1541. * @protected
  1542. * @since 5.9.128 (2011-10-06)
  1543. */
  1544. protected $custom_xmp = '';
  1545. /**
  1546. * Custom XMP RDF data.
  1547. * @protected
  1548. * @since 6.3.0 (2019-09-19)
  1549. */
  1550. protected $custom_xmp_rdf = '';
  1551. /**
  1552. * Overprint mode array.
  1553. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  1554. * @protected
  1555. * @since 5.9.152 (2012-03-23)
  1556. */
  1557. protected $overprint = array('OP' => false, 'op' => false, 'OPM' => 0);
  1558. /**
  1559. * Alpha mode array.
  1560. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  1561. * @protected
  1562. * @since 5.9.152 (2012-03-23)
  1563. */
  1564. protected $alpha = array('CA' => 1, 'ca' => 1, 'BM' => '/Normal', 'AIS' => false);
  1565. /**
  1566. * Define the page boundaries boxes to be set on document.
  1567. * @protected
  1568. * @since 5.9.152 (2012-03-23)
  1569. */
  1570. protected $page_boxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  1571. /**
  1572. * If true print TCPDF meta link.
  1573. * @protected
  1574. * @since 5.9.152 (2012-03-23)
  1575. */
  1576. protected $tcpdflink = true;
  1577. /**
  1578. * Cache array for computed GD gamma values.
  1579. * @protected
  1580. * @since 5.9.1632 (2012-06-05)
  1581. */
  1582. protected $gdgammacache = array();
  1583. //------------------------------------------------------------
  1584. // METHODS
  1585. //------------------------------------------------------------
  1586. /**
  1587. * This is the class constructor.
  1588. * It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).
  1589. *
  1590. * IMPORTANT: Please note that this method sets the mb_internal_encoding to ASCII, so if you are using the mbstring module functions with TCPDF you need to correctly set/unset the mb_internal_encoding when needed.
  1591. *
  1592. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li><li>'' (empty string) for automatic orientation</li></ul>
  1593. * @param $unit (string) User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
  1594. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  1595. * @param $unicode (boolean) TRUE means that the input text is unicode (default = true)
  1596. * @param $encoding (string) Charset encoding (used only when converting back html entities); default is UTF-8.
  1597. * @param $diskcache (boolean) DEPRECATED FEATURE
  1598. * @param $pdfa (integer) If not false, set the document to PDF/A mode and the good version (1 or 3).
  1599. * @public
  1600. * @see getPageSizeFromFormat(), setPageFormat()
  1601. */
  1602. public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4', $unicode = true, $encoding = 'UTF-8', $diskcache = false, $pdfa = false)
  1603. {
  1604. /* Set internal character encoding to ASCII */
  1605. if (function_exists('mb_internal_encoding') AND mb_internal_encoding()) {
  1606. $this->internal_encoding = mb_internal_encoding();
  1607. mb_internal_encoding('ASCII');
  1608. }
  1609. // set file ID for trailer
  1610. $serformat = (is_array($format) ? json_encode($format) : $format);
  1611. $this->file_id = md5(TCPDF_STATIC::getRandomSeed('TCPDF'.$orientation.$unit.$serformat.$encoding));
  1612. $this->font_obj_ids = array();
  1613. $this->page_obj_id = array();
  1614. $this->form_obj_id = array();
  1615. // set pdf/a mode
  1616. if ($pdfa != false) {
  1617. $this->pdfa_mode = true;
  1618. $this->pdfa_version = $pdfa; // 1 or 3
  1619. } else $this->pdfa_mode = false;
  1620. $this->force_srgb = false;
  1621. // set language direction
  1622. $this->rtl = false;
  1623. $this->tmprtl = false;
  1624. // some checks
  1625. $this->_dochecks();
  1626. // initialization of properties
  1627. $this->isunicode = $unicode;
  1628. $this->page = 0;
  1629. $this->transfmrk[0] = array();
  1630. $this->pagedim = array();
  1631. $this->n = 2;
  1632. $this->buffer = '';
  1633. $this->pages = array();
  1634. $this->state = 0;
  1635. $this->fonts = array();
  1636. $this->FontFiles = array();
  1637. $this->diffs = array();
  1638. $this->images = array();
  1639. $this->links = array();
  1640. $this->gradients = array();
  1641. $this->InFooter = false;
  1642. $this->lasth = 0;
  1643. $this->FontFamily = defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica';
  1644. $this->FontStyle = '';
  1645. $this->FontSizePt = 12;
  1646. $this->underline = false;
  1647. $this->overline = false;
  1648. $this->linethrough = false;
  1649. $this->DrawColor = '0 G';
  1650. $this->FillColor = '0 g';
  1651. $this->TextColor = '0 g';
  1652. $this->ColorFlag = false;
  1653. $this->pdflayers = array();
  1654. // encryption values
  1655. $this->encrypted = false;
  1656. $this->last_enc_key = '';
  1657. // standard Unicode fonts
  1658. $this->CoreFonts = array(
  1659. 'courier'=>'Courier',
  1660. 'courierB'=>'Courier-Bold',
  1661. 'courierI'=>'Courier-Oblique',
  1662. 'courierBI'=>'Courier-BoldOblique',
  1663. 'helvetica'=>'Helvetica',
  1664. 'helveticaB'=>'Helvetica-Bold',
  1665. 'helveticaI'=>'Helvetica-Oblique',
  1666. 'helveticaBI'=>'Helvetica-BoldOblique',
  1667. 'times'=>'Times-Roman',
  1668. 'timesB'=>'Times-Bold',
  1669. 'timesI'=>'Times-Italic',
  1670. 'timesBI'=>'Times-BoldItalic',
  1671. 'symbol'=>'Symbol',
  1672. 'zapfdingbats'=>'ZapfDingbats'
  1673. );
  1674. // set scale factor
  1675. $this->setPageUnit($unit);
  1676. // set page format and orientation
  1677. $this->setPageFormat($format, $orientation);
  1678. // page margins (1 cm)
  1679. $margin = 28.35 / $this->k;
  1680. $this->SetMargins($margin, $margin);
  1681. $this->clMargin = $this->lMargin;
  1682. $this->crMargin = $this->rMargin;
  1683. // internal cell padding
  1684. $cpadding = $margin / 10;
  1685. $this->setCellPaddings($cpadding, 0, $cpadding, 0);
  1686. // cell margins
  1687. $this->setCellMargins(0, 0, 0, 0);
  1688. // line width (0.2 mm)
  1689. $this->LineWidth = 0.57 / $this->k;
  1690. $this->linestyleWidth = sprintf('%F w', ($this->LineWidth * $this->k));
  1691. $this->linestyleCap = '0 J';
  1692. $this->linestyleJoin = '0 j';
  1693. $this->linestyleDash = '[] 0 d';
  1694. // automatic page break
  1695. $this->SetAutoPageBreak(true, (2 * $margin));
  1696. // full width display mode
  1697. $this->SetDisplayMode('fullwidth');
  1698. // compression
  1699. $this->SetCompression();
  1700. // set default PDF version number
  1701. $this->setPDFVersion();
  1702. $this->tcpdflink = true;
  1703. $this->encoding = $encoding;
  1704. $this->HREF = array();
  1705. $this->getFontsList();
  1706. $this->fgcolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1707. $this->strokecolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1708. $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255);
  1709. $this->extgstates = array();
  1710. $this->setTextShadow();
  1711. // signature
  1712. $this->sign = false;
  1713. $this->tsa_timestamp = false;
  1714. $this->tsa_data = array();
  1715. $this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0', 'name' => 'Signature');
  1716. $this->empty_signature_appearance = array();
  1717. // user's rights
  1718. $this->ur['enabled'] = false;
  1719. $this->ur['document'] = '/FullSave';
  1720. $this->ur['annots'] = '/Create/Delete/Modify/Copy/Import/Export';
  1721. $this->ur['form'] = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1722. $this->ur['signature'] = '/Modify';
  1723. $this->ur['ef'] = '/Create/Delete/Modify/Import';
  1724. $this->ur['formex'] = '';
  1725. // set default JPEG quality
  1726. $this->jpeg_quality = 75;
  1727. // initialize some settings
  1728. TCPDF_FONTS::utf8Bidi(array(), '', false, $this->isunicode, $this->CurrentFont);
  1729. // set default font
  1730. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  1731. $this->setHeaderFont(array($this->FontFamily, $this->FontStyle, $this->FontSizePt));
  1732. $this->setFooterFont(array($this->FontFamily, $this->FontStyle, $this->FontSizePt));
  1733. // check if PCRE Unicode support is enabled
  1734. if ($this->isunicode AND (@preg_match('/\pL/u', 'a') == 1)) {
  1735. // PCRE unicode support is turned ON
  1736. // \s : any whitespace character
  1737. // \p{Z} : any separator
  1738. // \p{Lo} : Unicode letter or ideograph that does not have lowercase and uppercase variants. Is used to chunk chinese words.
  1739. // \xa0 : Unicode Character 'NO-BREAK SPACE' (U+00A0)
  1740. //$this->setSpacesRE('/(?!\xa0)[\s\p{Z}\p{Lo}]/u');
  1741. $this->setSpacesRE('/(?!\xa0)[\s\p{Z}]/u');
  1742. } else {
  1743. // PCRE unicode support is turned OFF
  1744. $this->setSpacesRE('/[^\S\xa0]/');
  1745. }
  1746. $this->default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1747. // set document creation and modification timestamp
  1748. $this->doc_creation_timestamp = time();
  1749. $this->doc_modification_timestamp = $this->doc_creation_timestamp;
  1750. // get default graphic vars
  1751. $this->default_graphic_vars = $this->getGraphicVars();
  1752. $this->header_xobj_autoreset = false;
  1753. $this->custom_xmp = '';
  1754. $this->custom_xmp_rdf = '';
  1755. // Call cleanup method after script execution finishes or exit() is called.
  1756. // NOTE: This will not be executed if the process is killed with a SIGTERM or SIGKILL signal.
  1757. register_shutdown_function(array($this, '_destroy'), true);
  1758. }
  1759. /**
  1760. * Default destructor.
  1761. * @public
  1762. * @since 1.53.0.TC016
  1763. */
  1764. public function __destruct()
  1765. {
  1766. // cleanup
  1767. $this->_destroy(true);
  1768. }
  1769. /**
  1770. * Set the units of measure for the document.
  1771. * @param $unit (string) User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
  1772. * @public
  1773. * @since 3.0.015 (2008-06-06)
  1774. */
  1775. public function setPageUnit($unit)
  1776. {
  1777. $unit = strtolower($unit);
  1778. //Set scale factor
  1779. switch ($unit) {
  1780. // points
  1781. case 'px':
  1782. case 'pt': {
  1783. $this->k = 1;
  1784. break;
  1785. }
  1786. // millimeters
  1787. case 'mm': {
  1788. $this->k = $this->dpi / 25.4;
  1789. break;
  1790. }
  1791. // centimeters
  1792. case 'cm': {
  1793. $this->k = $this->dpi / 2.54;
  1794. break;
  1795. }
  1796. // inches
  1797. case 'in': {
  1798. $this->k = $this->dpi;
  1799. break;
  1800. }
  1801. // unsupported unit
  1802. default : {
  1803. $this->Error('Incorrect unit: '.$unit);
  1804. break;
  1805. }
  1806. }
  1807. $this->pdfunit = $unit;
  1808. if (isset($this->CurOrientation)) {
  1809. $this->setPageOrientation($this->CurOrientation);
  1810. }
  1811. }
  1812. /**
  1813. * Change the format of the current page
  1814. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() documentation or an array of two numbers (width, height) or an array containing the following measures and options:<ul>
  1815. * <li>['format'] = page format name (one of the above);</li>
  1816. * <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>
  1817. * <li>['PZ'] : The page's preferred zoom (magnification) factor.</li>
  1818. * <li>['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed:</li>
  1819. * <li>['MediaBox']['llx'] : lower-left x coordinate</li>
  1820. * <li>['MediaBox']['lly'] : lower-left y coordinate</li>
  1821. * <li>['MediaBox']['urx'] : upper-right x coordinate</li>
  1822. * <li>['MediaBox']['ury'] : upper-right y coordinate</li>
  1823. * <li>['CropBox'] : the visible region of default user space:</li>
  1824. * <li>['CropBox']['llx'] : lower-left x coordinate</li>
  1825. * <li>['CropBox']['lly'] : lower-left y coordinate</li>
  1826. * <li>['CropBox']['urx'] : upper-right x coordinate</li>
  1827. * <li>['CropBox']['ury'] : upper-right y coordinate</li>
  1828. * <li>['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment:</li>
  1829. * <li>['BleedBox']['llx'] : lower-left x coordinate</li>
  1830. * <li>['BleedBox']['lly'] : lower-left y coordinate</li>
  1831. * <li>['BleedBox']['urx'] : upper-right x coordinate</li>
  1832. * <li>['BleedBox']['ury'] : upper-right y coordinate</li>
  1833. * <li>['TrimBox'] : the intended dimensions of the finished page after trimming:</li>
  1834. * <li>['TrimBox']['llx'] : lower-left x coordinate</li>
  1835. * <li>['TrimBox']['lly'] : lower-left y coordinate</li>
  1836. * <li>['TrimBox']['urx'] : upper-right x coordinate</li>
  1837. * <li>['TrimBox']['ury'] : upper-right y coordinate</li>
  1838. * <li>['ArtBox'] : the extent of the page's meaningful content:</li>
  1839. * <li>['ArtBox']['llx'] : lower-left x coordinate</li>
  1840. * <li>['ArtBox']['lly'] : lower-left y coordinate</li>
  1841. * <li>['ArtBox']['urx'] : upper-right x coordinate</li>
  1842. * <li>['ArtBox']['ury'] : upper-right y coordinate</li>
  1843. * <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>
  1844. * <li>['BoxColorInfo'][BOXTYPE]['C'] : an array of three numbers in the range 0-255, representing the components in the DeviceRGB colour space.</li>
  1845. * <li>['BoxColorInfo'][BOXTYPE]['W'] : the guideline width in default user units</li>
  1846. * <li>['BoxColorInfo'][BOXTYPE]['S'] : the guideline style: S = Solid; D = Dashed</li>
  1847. * <li>['BoxColorInfo'][BOXTYPE]['D'] : dash array defining a pattern of dashes and gaps to be used in drawing dashed guidelines</li>
  1848. * <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>
  1849. * <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>
  1850. * <li>['trans']['S'] : transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li>
  1851. * <li>['trans']['D'] : The duration of the transition effect, in seconds.</li>
  1852. * <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>
  1853. * <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>
  1854. * <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>
  1855. * <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>
  1856. * <li>['trans']['B'] : (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li>
  1857. * </ul>
  1858. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul>
  1859. * <li>P or Portrait (default)</li>
  1860. * <li>L or Landscape</li>
  1861. * <li>'' (empty string) for automatic orientation</li>
  1862. * </ul>
  1863. * @protected
  1864. * @since 3.0.015 (2008-06-06)
  1865. * @see getPageSizeFromFormat()
  1866. */
  1867. protected function setPageFormat($format, $orientation = 'P')
  1868. {
  1869. if (!empty($format) AND isset($this->pagedim[$this->page])) {
  1870. // remove inherited values
  1871. unset($this->pagedim[$this->page]);
  1872. }
  1873. if (is_string($format)) {
  1874. // get page measures from format name
  1875. $pf = TCPDF_STATIC::getPageSizeFromFormat($format);
  1876. $this->fwPt = $pf[0];
  1877. $this->fhPt = $pf[1];
  1878. } else {
  1879. // the boundaries of the physical medium on which the page shall be displayed or printed
  1880. if (isset($format['MediaBox'])) {
  1881. $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);
  1882. $this->fwPt = (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k);
  1883. $this->fhPt = (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k);
  1884. } else {
  1885. if (isset($format[0]) AND is_numeric($format[0]) AND isset($format[1]) AND is_numeric($format[1])) {
  1886. $pf = array(($format[0] * $this->k), ($format[1] * $this->k));
  1887. } else {
  1888. if (!isset($format['format'])) {
  1889. // default value
  1890. $format['format'] = 'A4';
  1891. }
  1892. $pf = TCPDF_STATIC::getPageSizeFromFormat($format['format']);
  1893. }
  1894. $this->fwPt = $pf[0];
  1895. $this->fhPt = $pf[1];
  1896. $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true, $this->k, $this->pagedim);
  1897. }
  1898. // the visible region of default user space
  1899. if (isset($format['CropBox'])) {
  1900. $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);
  1901. }
  1902. // the region to which the contents of the page shall be clipped when output in a production environment
  1903. if (isset($format['BleedBox'])) {
  1904. $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);
  1905. }
  1906. // the intended dimensions of the finished page after trimming
  1907. if (isset($format['TrimBox'])) {
  1908. $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);
  1909. }
  1910. // the page's meaningful content (including potential white space)
  1911. if (isset($format['ArtBox'])) {
  1912. $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);
  1913. }
  1914. // specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for the various page boundaries
  1915. if (isset($format['BoxColorInfo'])) {
  1916. $this->pagedim[$this->page]['BoxColorInfo'] = $format['BoxColorInfo'];
  1917. }
  1918. if (isset($format['Rotate']) AND (($format['Rotate'] % 90) == 0)) {
  1919. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  1920. $this->pagedim[$this->page]['Rotate'] = intval($format['Rotate']);
  1921. }
  1922. if (isset($format['PZ'])) {
  1923. // The page's preferred zoom (magnification) factor
  1924. $this->pagedim[$this->page]['PZ'] = floatval($format['PZ']);
  1925. }
  1926. if (isset($format['trans'])) {
  1927. // The style and duration of the visual transition to use when moving from another page to the given page during a presentation
  1928. if (isset($format['trans']['Dur'])) {
  1929. // The page's display duration
  1930. $this->pagedim[$this->page]['trans']['Dur'] = floatval($format['trans']['Dur']);
  1931. }
  1932. $stansition_styles = array('Split', 'Blinds', 'Box', 'Wipe', 'Dissolve', 'Glitter', 'R', 'Fly', 'Push', 'Cover', 'Uncover', 'Fade');
  1933. if (isset($format['trans']['S']) AND in_array($format['trans']['S'], $stansition_styles)) {
  1934. // The transition style that shall be used when moving to this page from another during a presentation
  1935. $this->pagedim[$this->page]['trans']['S'] = $format['trans']['S'];
  1936. $valid_effect = array('Split', 'Blinds');
  1937. $valid_vals = array('H', 'V');
  1938. if (isset($format['trans']['Dm']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['Dm'], $valid_vals)) {
  1939. $this->pagedim[$this->page]['trans']['Dm'] = $format['trans']['Dm'];
  1940. }
  1941. $valid_effect = array('Split', 'Box', 'Fly');
  1942. $valid_vals = array('I', 'O');
  1943. if (isset($format['trans']['M']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['M'], $valid_vals)) {
  1944. $this->pagedim[$this->page]['trans']['M'] = $format['trans']['M'];
  1945. }
  1946. $valid_effect = array('Wipe', 'Glitter', 'Fly', 'Cover', 'Uncover', 'Push');
  1947. if (isset($format['trans']['Di']) AND in_array($format['trans']['S'], $valid_effect)) {
  1948. if (((($format['trans']['Di'] == 90) OR ($format['trans']['Di'] == 180)) AND ($format['trans']['S'] == 'Wipe'))
  1949. OR (($format['trans']['Di'] == 315) AND ($format['trans']['S'] == 'Glitter'))
  1950. OR (($format['trans']['Di'] == 0) OR ($format['trans']['Di'] == 270))) {
  1951. $this->pagedim[$this->page]['trans']['Di'] = intval($format['trans']['Di']);
  1952. }
  1953. }
  1954. if (isset($format['trans']['SS']) AND ($format['trans']['S'] == 'Fly')) {
  1955. $this->pagedim[$this->page]['trans']['SS'] = floatval($format['trans']['SS']);
  1956. }
  1957. if (isset($format['trans']['B']) AND ($format['trans']['B'] === true) AND ($format['trans']['S'] == 'Fly')) {
  1958. $this->pagedim[$this->page]['trans']['B'] = 'true';
  1959. }
  1960. } else {
  1961. $this->pagedim[$this->page]['trans']['S'] = 'R';
  1962. }
  1963. if (isset($format['trans']['D'])) {
  1964. // The duration of the transition effect, in seconds
  1965. $this->pagedim[$this->page]['trans']['D'] = floatval($format['trans']['D']);
  1966. } else {
  1967. $this->pagedim[$this->page]['trans']['D'] = 1;
  1968. }
  1969. }
  1970. }
  1971. $this->setPageOrientation($orientation);
  1972. }
  1973. /**
  1974. * Set page orientation.
  1975. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li><li>'' (empty string) for automatic orientation</li></ul>
  1976. * @param $autopagebreak (boolean) Boolean indicating if auto-page-break mode should be on or off.
  1977. * @param $bottommargin (float) bottom margin of the page.
  1978. * @public
  1979. * @since 3.0.015 (2008-06-06)
  1980. */
  1981. public function setPageOrientation($orientation, $autopagebreak = '', $bottommargin = '')
  1982. {
  1983. if (!isset($this->pagedim[$this->page]['MediaBox'])) {
  1984. // the boundaries of the physical medium on which the page shall be displayed or printed
  1985. $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true, $this->k, $this->pagedim);
  1986. }
  1987. if (!isset($this->pagedim[$this->page]['CropBox'])) {
  1988. // the visible region of default user space
  1989. $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);
  1990. }
  1991. if (!isset($this->pagedim[$this->page]['BleedBox'])) {
  1992. // the region to which the contents of the page shall be clipped when output in a production environment
  1993. $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);
  1994. }
  1995. if (!isset($this->pagedim[$this->page]['TrimBox'])) {
  1996. // the intended dimensions of the finished page after trimming
  1997. $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);
  1998. }
  1999. if (!isset($this->pagedim[$this->page]['ArtBox'])) {
  2000. // the page's meaningful content (including potential white space)
  2001. $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);
  2002. }
  2003. if (!isset($this->pagedim[$this->page]['Rotate'])) {
  2004. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  2005. $this->pagedim[$this->page]['Rotate'] = 0;
  2006. }
  2007. if (!isset($this->pagedim[$this->page]['PZ'])) {
  2008. // The page's preferred zoom (magnification) factor
  2009. $this->pagedim[$this->page]['PZ'] = 1;
  2010. }
  2011. if ($this->fwPt > $this->fhPt) {
  2012. // landscape
  2013. $default_orientation = 'L';
  2014. } else {
  2015. // portrait
  2016. $default_orientation = 'P';
  2017. }
  2018. $valid_orientations = array('P', 'L');
  2019. if (empty($orientation)) {
  2020. $orientation = $default_orientation;
  2021. } else {
  2022. $orientation = strtoupper($orientation[0]);
  2023. }
  2024. if (in_array($orientation, $valid_orientations) AND ($orientation != $default_orientation)) {
  2025. $this->CurOrientation = $orientation;
  2026. $this->wPt = $this->fhPt;
  2027. $this->hPt = $this->fwPt;
  2028. } else {
  2029. $this->CurOrientation = $default_orientation;
  2030. $this->wPt = $this->fwPt;
  2031. $this->hPt = $this->fhPt;
  2032. }
  2033. if ((abs($this->pagedim[$this->page]['MediaBox']['urx'] - $this->hPt) < $this->feps) AND (abs($this->pagedim[$this->page]['MediaBox']['ury'] - $this->wPt) < $this->feps)) {
  2034. // swap X and Y coordinates (change page orientation)
  2035. $this->pagedim = TCPDF_STATIC::swapPageBoxCoordinates($this->page, $this->pagedim);
  2036. }
  2037. $this->w = ($this->wPt / $this->k);
  2038. $this->h = ($this->hPt / $this->k);
  2039. if (TCPDF_STATIC::empty_string($autopagebreak)) {
  2040. if (isset($this->AutoPageBreak)) {
  2041. $autopagebreak = $this->AutoPageBreak;
  2042. } else {
  2043. $autopagebreak = true;
  2044. }
  2045. }
  2046. if (TCPDF_STATIC::empty_string($bottommargin)) {
  2047. if (isset($this->bMargin)) {
  2048. $bottommargin = $this->bMargin;
  2049. } else {
  2050. // default value = 2 cm
  2051. $bottommargin = 2 * 28.35 / $this->k;
  2052. }
  2053. }
  2054. $this->SetAutoPageBreak($autopagebreak, $bottommargin);
  2055. // store page dimensions
  2056. $this->pagedim[$this->page]['w'] = $this->wPt;
  2057. $this->pagedim[$this->page]['h'] = $this->hPt;
  2058. $this->pagedim[$this->page]['wk'] = $this->w;
  2059. $this->pagedim[$this->page]['hk'] = $this->h;
  2060. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  2061. $this->pagedim[$this->page]['bm'] = $bottommargin;
  2062. $this->pagedim[$this->page]['lm'] = $this->lMargin;
  2063. $this->pagedim[$this->page]['rm'] = $this->rMargin;
  2064. $this->pagedim[$this->page]['pb'] = $autopagebreak;
  2065. $this->pagedim[$this->page]['or'] = $this->CurOrientation;
  2066. $this->pagedim[$this->page]['olm'] = $this->original_lMargin;
  2067. $this->pagedim[$this->page]['orm'] = $this->original_rMargin;
  2068. }
  2069. /**
  2070. * Set regular expression to detect withespaces or word separators.
  2071. * The pattern delimiter must be the forward-slash character "/".
  2072. * Some example patterns are:
  2073. * <pre>
  2074. * Non-Unicode or missing PCRE unicode support: "/[^\S\xa0]/"
  2075. * Unicode and PCRE unicode support: "/(?!\xa0)[\s\p{Z}]/u"
  2076. * Unicode and PCRE unicode support in Chinese mode: "/(?!\xa0)[\s\p{Z}\p{Lo}]/u"
  2077. * if PCRE unicode support is turned ON ("\P" is the negate class of "\p"):
  2078. * \s : any whitespace character
  2079. * \p{Z} : any separator
  2080. * \p{Lo} : Unicode letter or ideograph that does not have lowercase and uppercase variants. Is used to chunk chinese words.
  2081. * \xa0 : Unicode Character 'NO-BREAK SPACE' (U+00A0)
  2082. * </pre>
  2083. * @param $re (string) regular expression (leave empty for default).
  2084. * @public
  2085. * @since 4.6.016 (2009-06-15)
  2086. */
  2087. public function setSpacesRE($re = '/[^\S\xa0]/')
  2088. {
  2089. $this->re_spaces = $re;
  2090. $re_parts = explode('/', $re);
  2091. // get pattern parts
  2092. $this->re_space = array();
  2093. if (isset($re_parts[1]) AND !empty($re_parts[1])) {
  2094. $this->re_space['p'] = $re_parts[1];
  2095. } else {
  2096. $this->re_space['p'] = '[\s]';
  2097. }
  2098. // set pattern modifiers
  2099. if (isset($re_parts[2]) AND !empty($re_parts[2])) {
  2100. $this->re_space['m'] = $re_parts[2];
  2101. } else {
  2102. $this->re_space['m'] = '';
  2103. }
  2104. }
  2105. /**
  2106. * Enable or disable Right-To-Left language mode
  2107. * @param $enable (Boolean) if true enable Right-To-Left language mode.
  2108. * @param $resetx (Boolean) if true reset the X position on direction change.
  2109. * @public
  2110. * @since 2.0.000 (2008-01-03)
  2111. */
  2112. public function setRTL($enable, $resetx = true)
  2113. {
  2114. $enable = $enable ? true : false;
  2115. $resetx = ($resetx AND ($enable != $this->rtl));
  2116. $this->rtl = $enable;
  2117. $this->tmprtl = false;
  2118. if ($resetx) {
  2119. $this->Ln(0);
  2120. }
  2121. }
  2122. /**
  2123. * Return the RTL status
  2124. * @return boolean
  2125. * @public
  2126. * @since 4.0.012 (2008-07-24)
  2127. */
  2128. public function getRTL()
  2129. {
  2130. return $this->rtl;
  2131. }
  2132. /**
  2133. * Force temporary RTL language direction
  2134. * @param $mode (mixed) can be false, 'L' for LTR or 'R' for RTL
  2135. * @public
  2136. * @since 2.1.000 (2008-01-09)
  2137. */
  2138. public function setTempRTL($mode)
  2139. {
  2140. $newmode = false;
  2141. switch (strtoupper($mode)) {
  2142. case 'LTR':
  2143. case 'L': {
  2144. if ($this->rtl) {
  2145. $newmode = 'L';
  2146. }
  2147. break;
  2148. }
  2149. case 'RTL':
  2150. case 'R': {
  2151. if (!$this->rtl) {
  2152. $newmode = 'R';
  2153. }
  2154. break;
  2155. }
  2156. case false:
  2157. default: {
  2158. $newmode = false;
  2159. break;
  2160. }
  2161. }
  2162. $this->tmprtl = $newmode;
  2163. }
  2164. /**
  2165. * Return the current temporary RTL status
  2166. * @return boolean
  2167. * @public
  2168. * @since 4.8.014 (2009-11-04)
  2169. */
  2170. public function isRTLTextDir()
  2171. {
  2172. return ($this->rtl OR ($this->tmprtl == 'R'));
  2173. }
  2174. /**
  2175. * Set the last cell height.
  2176. * @param $h (float) cell height.
  2177. * @author Nicola Asuni
  2178. * @public
  2179. * @since 1.53.0.TC034
  2180. */
  2181. public function setLastH($h)
  2182. {
  2183. $this->lasth = $h;
  2184. }
  2185. /**
  2186. * Return the cell height
  2187. * @param $fontsize (int) Font size in internal units
  2188. * @param $padding (boolean) If true add cell padding
  2189. * @public
  2190. */
  2191. public function getCellHeight($fontsize, $padding = true)
  2192. {
  2193. $height = ($fontsize * $this->cell_height_ratio);
  2194. if ($padding) {
  2195. $height += ($this->cell_padding['T'] + $this->cell_padding['B']);
  2196. }
  2197. return round($height, 6);
  2198. }
  2199. /**
  2200. * Reset the last cell height.
  2201. * @public
  2202. * @since 5.9.000 (2010-10-03)
  2203. */
  2204. public function resetLastH()
  2205. {
  2206. $this->lasth = $this->getCellHeight($this->FontSize);
  2207. }
  2208. /**
  2209. * Get the last cell height.
  2210. * @return last cell height
  2211. * @public
  2212. * @since 4.0.017 (2008-08-05)
  2213. */
  2214. public function getLastH()
  2215. {
  2216. return $this->lasth;
  2217. }
  2218. /**
  2219. * Set the adjusting factor to convert pixels to user units.
  2220. * @param $scale (float) adjusting factor to convert pixels to user units.
  2221. * @author Nicola Asuni
  2222. * @public
  2223. * @since 1.5.2
  2224. */
  2225. public function setImageScale($scale)
  2226. {
  2227. $this->imgscale = $scale;
  2228. }
  2229. /**
  2230. * Returns the adjusting factor to convert pixels to user units.
  2231. * @return float adjusting factor to convert pixels to user units.
  2232. * @author Nicola Asuni
  2233. * @public
  2234. * @since 1.5.2
  2235. */
  2236. public function getImageScale()
  2237. {
  2238. return $this->imgscale;
  2239. }
  2240. /**
  2241. * Returns an array of page dimensions:
  2242. * <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>
  2243. * @param $pagenum (int) page number (empty = current page)
  2244. * @return array of page dimensions.
  2245. * @author Nicola Asuni
  2246. * @public
  2247. * @since 4.5.027 (2009-03-16)
  2248. */
  2249. public function getPageDimensions($pagenum = '')
  2250. {
  2251. if (empty($pagenum)) {
  2252. $pagenum = $this->page;
  2253. }
  2254. return $this->pagedim[$pagenum];
  2255. }
  2256. /**
  2257. * Returns the page width in units.
  2258. * @param $pagenum (int) page number (empty = current page)
  2259. * @return int page width.
  2260. * @author Nicola Asuni
  2261. * @public
  2262. * @since 1.5.2
  2263. * @see getPageDimensions()
  2264. */
  2265. public function getPageWidth($pagenum = '')
  2266. {
  2267. if (empty($pagenum)) {
  2268. return $this->w;
  2269. }
  2270. return $this->pagedim[$pagenum]['w'];
  2271. }
  2272. /**
  2273. * Returns the page height in units.
  2274. * @param $pagenum (int) page number (empty = current page)
  2275. * @return int page height.
  2276. * @author Nicola Asuni
  2277. * @public
  2278. * @since 1.5.2
  2279. * @see getPageDimensions()
  2280. */
  2281. public function getPageHeight($pagenum = '')
  2282. {
  2283. if (empty($pagenum)) {
  2284. return $this->h;
  2285. }
  2286. return $this->pagedim[$pagenum]['h'];
  2287. }
  2288. /**
  2289. * Returns the page break margin.
  2290. * @param $pagenum (int) page number (empty = current page)
  2291. * @return int page break margin.
  2292. * @author Nicola Asuni
  2293. * @public
  2294. * @since 1.5.2
  2295. * @see getPageDimensions()
  2296. */
  2297. public function getBreakMargin($pagenum = '')
  2298. {
  2299. if (empty($pagenum)) {
  2300. return $this->bMargin;
  2301. }
  2302. return $this->pagedim[$pagenum]['bm'];
  2303. }
  2304. /**
  2305. * Returns the scale factor (number of points in user unit).
  2306. * @return int scale factor.
  2307. * @author Nicola Asuni
  2308. * @public
  2309. * @since 1.5.2
  2310. */
  2311. public function getScaleFactor()
  2312. {
  2313. return $this->k;
  2314. }
  2315. /**
  2316. * Defines the left, top and right margins.
  2317. * @param $left (float) Left margin.
  2318. * @param $top (float) Top margin.
  2319. * @param $right (float) Right margin. Default value is the left one.
  2320. * @param $keepmargins (boolean) if true overwrites the default page margins
  2321. * @public
  2322. * @since 1.0
  2323. * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  2324. */
  2325. public function SetMargins($left, $top, $right = -1, $keepmargins = false)
  2326. {
  2327. //Set left, top and right margins
  2328. $this->lMargin = $left;
  2329. $this->tMargin = $top;
  2330. if ($right == -1) {
  2331. $right = $left;
  2332. }
  2333. $this->rMargin = $right;
  2334. if ($keepmargins) {
  2335. // overwrite original values
  2336. $this->original_lMargin = $this->lMargin;
  2337. $this->original_rMargin = $this->rMargin;
  2338. }
  2339. }
  2340. /**
  2341. * 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.
  2342. * @param $margin (float) The margin.
  2343. * @public
  2344. * @since 1.4
  2345. * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2346. */
  2347. public function SetLeftMargin($margin)
  2348. {
  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 $margin (float) The margin.
  2358. * @public
  2359. * @since 1.5
  2360. * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2361. */
  2362. public function SetTopMargin($margin)
  2363. {
  2364. //Set top margin
  2365. $this->tMargin = $margin;
  2366. if (($this->page > 0) AND ($this->y < $margin)) {
  2367. $this->y = $margin;
  2368. }
  2369. }
  2370. /**
  2371. * Defines the right margin. The method can be called before creating the first page.
  2372. * @param $margin (float) The margin.
  2373. * @public
  2374. * @since 1.5
  2375. * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  2376. */
  2377. public function SetRightMargin($margin)
  2378. {
  2379. $this->rMargin = $margin;
  2380. if (($this->page > 0) AND ($this->x > ($this->w - $margin))) {
  2381. $this->x = $this->w - $margin;
  2382. }
  2383. }
  2384. /**
  2385. * Set the same internal Cell padding for top, right, bottom, left-
  2386. * @param $pad (float) internal padding.
  2387. * @public
  2388. * @since 2.1.000 (2008-01-09)
  2389. * @see getCellPaddings(), setCellPaddings()
  2390. */
  2391. public function SetCellPadding($pad)
  2392. {
  2393. if ($pad >= 0) {
  2394. $this->cell_padding['L'] = $pad;
  2395. $this->cell_padding['T'] = $pad;
  2396. $this->cell_padding['R'] = $pad;
  2397. $this->cell_padding['B'] = $pad;
  2398. }
  2399. }
  2400. /**
  2401. * Set the internal Cell paddings.
  2402. * @param $left (float) left padding
  2403. * @param $top (float) top padding
  2404. * @param $right (float) right padding
  2405. * @param $bottom (float) bottom padding
  2406. * @public
  2407. * @since 5.9.000 (2010-10-03)
  2408. * @see getCellPaddings(), SetCellPadding()
  2409. */
  2410. public function setCellPaddings($left = '', $top = '', $right = '', $bottom = '')
  2411. {
  2412. if (($left !== '') AND ($left >= 0)) {
  2413. $this->cell_padding['L'] = $left;
  2414. }
  2415. if (($top !== '') AND ($top >= 0)) {
  2416. $this->cell_padding['T'] = $top;
  2417. }
  2418. if (($right !== '') AND ($right >= 0)) {
  2419. $this->cell_padding['R'] = $right;
  2420. }
  2421. if (($bottom !== '') AND ($bottom >= 0)) {
  2422. $this->cell_padding['B'] = $bottom;
  2423. }
  2424. }
  2425. /**
  2426. * Get the internal Cell padding array.
  2427. * @return array of padding values
  2428. * @public
  2429. * @since 5.9.000 (2010-10-03)
  2430. * @see setCellPaddings(), SetCellPadding()
  2431. */
  2432. public function getCellPaddings()
  2433. {
  2434. return $this->cell_padding;
  2435. }
  2436. /**
  2437. * Set the internal Cell margins.
  2438. * @param $left (float) left margin
  2439. * @param $top (float) top margin
  2440. * @param $right (float) right margin
  2441. * @param $bottom (float) bottom margin
  2442. * @public
  2443. * @since 5.9.000 (2010-10-03)
  2444. * @see getCellMargins()
  2445. */
  2446. public function setCellMargins($left = '', $top = '', $right = '', $bottom = '')
  2447. {
  2448. if (($left !== '') AND ($left >= 0)) {
  2449. $this->cell_margin['L'] = $left;
  2450. }
  2451. if (($top !== '') AND ($top >= 0)) {
  2452. $this->cell_margin['T'] = $top;
  2453. }
  2454. if (($right !== '') AND ($right >= 0)) {
  2455. $this->cell_margin['R'] = $right;
  2456. }
  2457. if (($bottom !== '') AND ($bottom >= 0)) {
  2458. $this->cell_margin['B'] = $bottom;
  2459. }
  2460. }
  2461. /**
  2462. * Get the internal Cell margin array.
  2463. * @return array of margin values
  2464. * @public
  2465. * @since 5.9.000 (2010-10-03)
  2466. * @see setCellMargins()
  2467. */
  2468. public function getCellMargins()
  2469. {
  2470. return $this->cell_margin;
  2471. }
  2472. /**
  2473. * Adjust the internal Cell padding array to take account of the line width.
  2474. * @param $brd (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  2475. * @return array of adjustments
  2476. * @public
  2477. * @since 5.9.000 (2010-10-03)
  2478. */
  2479. protected function adjustCellPadding($brd = 0)
  2480. {
  2481. if (empty($brd)) {
  2482. return;
  2483. }
  2484. if (is_string($brd)) {
  2485. // convert string to array
  2486. $slen = strlen($brd);
  2487. $newbrd = array();
  2488. for ($i = 0; $i < $slen; ++$i) {
  2489. $newbrd[$brd[$i]] = true;
  2490. }
  2491. $brd = $newbrd;
  2492. } elseif (($brd === 1) OR ($brd === true) OR (is_numeric($brd) AND (intval($brd) > 0))) {
  2493. $brd = array('LRTB' => true);
  2494. }
  2495. if (!is_array($brd)) {
  2496. return;
  2497. }
  2498. // store current cell padding
  2499. $cp = $this->cell_padding;
  2500. // select border mode
  2501. if (isset($brd['mode'])) {
  2502. $mode = $brd['mode'];
  2503. unset($brd['mode']);
  2504. } else {
  2505. $mode = 'normal';
  2506. }
  2507. // process borders
  2508. foreach ($brd as $border => $style) {
  2509. $line_width = $this->LineWidth;
  2510. if (is_array($style) AND isset($style['width'])) {
  2511. // get border width
  2512. $line_width = $style['width'];
  2513. }
  2514. $adj = 0; // line width inside the cell
  2515. switch ($mode) {
  2516. case 'ext': {
  2517. $adj = 0;
  2518. break;
  2519. }
  2520. case 'int': {
  2521. $adj = $line_width;
  2522. break;
  2523. }
  2524. case 'normal':
  2525. default: {
  2526. $adj = ($line_width / 2);
  2527. break;
  2528. }
  2529. }
  2530. // correct internal cell padding if required to avoid overlap between text and lines
  2531. if ((strpos($border, 'T') !== false) AND ($this->cell_padding['T'] < $adj)) {
  2532. $this->cell_padding['T'] = $adj;
  2533. }
  2534. if ((strpos($border, 'R') !== false) AND ($this->cell_padding['R'] < $adj)) {
  2535. $this->cell_padding['R'] = $adj;
  2536. }
  2537. if ((strpos($border, 'B') !== false) AND ($this->cell_padding['B'] < $adj)) {
  2538. $this->cell_padding['B'] = $adj;
  2539. }
  2540. if ((strpos($border, 'L') !== false) AND ($this->cell_padding['L'] < $adj)) {
  2541. $this->cell_padding['L'] = $adj;
  2542. }
  2543. }
  2544. return array('T' => ($this->cell_padding['T'] - $cp['T']), 'R' => ($this->cell_padding['R'] - $cp['R']), 'B' => ($this->cell_padding['B'] - $cp['B']), 'L' => ($this->cell_padding['L'] - $cp['L']));
  2545. }
  2546. /**
  2547. * 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.
  2548. * @param $auto (boolean) Boolean indicating if mode should be on or off.
  2549. * @param $margin (float) Distance from the bottom of the page.
  2550. * @public
  2551. * @since 1.0
  2552. * @see Cell(), MultiCell(), AcceptPageBreak()
  2553. */
  2554. public function SetAutoPageBreak($auto, $margin = 0)
  2555. {
  2556. $this->AutoPageBreak = $auto ? true : false;
  2557. $this->bMargin = $margin;
  2558. $this->PageBreakTrigger = $this->h - $margin;
  2559. }
  2560. /**
  2561. * Return the auto-page-break mode (true or false).
  2562. * @return boolean auto-page-break mode
  2563. * @public
  2564. * @since 5.9.088
  2565. */
  2566. public function getAutoPageBreak()
  2567. {
  2568. return $this->AutoPageBreak;
  2569. }
  2570. /**
  2571. * Defines the way the document is to be displayed by the viewer.
  2572. * @param $zoom (mixed) The zoom to use. It can be one of the following string values or a number indicating the zooming factor to use. <ul><li>fullpage: displays the entire page on screen </li><li>fullwidth: uses maximum width of window</li><li>real: uses real size (equivalent to 100% zoom)</li><li>default: uses viewer default mode</li></ul>
  2573. * @param $layout (string) The page layout. Possible values are:<ul><li>SinglePage Display one page at a time</li><li>OneColumn Display the pages in one column</li><li>TwoColumnLeft Display the pages in two columns, with odd-numbered pages on the left</li><li>TwoColumnRight Display the pages in two columns, with odd-numbered pages on the right</li><li>TwoPageLeft (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the left</li><li>TwoPageRight (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the right</li></ul>
  2574. * @param $mode (string) A name object specifying how the document should be displayed when opened:<ul><li>UseNone Neither document outline nor thumbnail images visible</li><li>UseOutlines Document outline visible</li><li>UseThumbs Thumbnail images visible</li><li>FullScreen Full-screen mode, with no menu bar, window controls, or any other window visible</li><li>UseOC (PDF 1.5) Optional content group panel visible</li><li>UseAttachments (PDF 1.6) Attachments panel visible</li></ul>
  2575. * @public
  2576. * @since 1.2
  2577. */
  2578. public function SetDisplayMode($zoom, $layout = 'SinglePage', $mode = 'UseNone')
  2579. {
  2580. if (($zoom == 'fullpage') OR ($zoom == 'fullwidth') OR ($zoom == 'real') OR ($zoom == 'default') OR (!is_string($zoom))) {
  2581. $this->ZoomMode = $zoom;
  2582. } else {
  2583. $this->Error('Incorrect zoom display mode: '.$zoom);
  2584. }
  2585. $this->LayoutMode = TCPDF_STATIC::getPageLayoutMode($layout);
  2586. $this->PageMode = TCPDF_STATIC::getPageMode($mode);
  2587. }
  2588. /**
  2589. * 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.
  2590. * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  2591. * @param $compress (boolean) Boolean indicating if compression must be enabled.
  2592. * @public
  2593. * @since 1.4
  2594. */
  2595. public function SetCompression($compress = true)
  2596. {
  2597. $this->compress = false;
  2598. if (function_exists('gzcompress')) {
  2599. if ($compress) {
  2600. if ( !$this->pdfa_mode) {
  2601. $this->compress = true;
  2602. }
  2603. }
  2604. }
  2605. }
  2606. /**
  2607. * Set flag to force sRGB_IEC61966-2.1 black scaled ICC color profile for the whole document.
  2608. * @param $mode (boolean) If true force sRGB output intent.
  2609. * @public
  2610. * @since 5.9.121 (2011-09-28)
  2611. */
  2612. public function setSRGBmode($mode = false)
  2613. {
  2614. $this->force_srgb = $mode ? true : false;
  2615. }
  2616. /**
  2617. * Turn on/off Unicode mode for document information dictionary (meta tags).
  2618. * This has effect only when unicode mode is set to false.
  2619. * @param $unicode (boolean) if true set the meta information in Unicode
  2620. * @since 5.9.027 (2010-12-01)
  2621. * @public
  2622. */
  2623. public function SetDocInfoUnicode($unicode = true)
  2624. {
  2625. $this->docinfounicode = $unicode ? true : false;
  2626. }
  2627. /**
  2628. * Defines the title of the document.
  2629. * @param $title (string) The title.
  2630. * @public
  2631. * @since 1.2
  2632. * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  2633. */
  2634. public function SetTitle($title)
  2635. {
  2636. $this->title = $title;
  2637. }
  2638. /**
  2639. * Defines the subject of the document.
  2640. * @param $subject (string) The subject.
  2641. * @public
  2642. * @since 1.2
  2643. * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  2644. */
  2645. public function SetSubject($subject)
  2646. {
  2647. $this->subject = $subject;
  2648. }
  2649. /**
  2650. * Defines the author of the document.
  2651. * @param $author (string) The name of the author.
  2652. * @public
  2653. * @since 1.2
  2654. * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  2655. */
  2656. public function SetAuthor($author)
  2657. {
  2658. $this->author = $author;
  2659. }
  2660. /**
  2661. * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  2662. * @param $keywords (string) The list of keywords.
  2663. * @public
  2664. * @since 1.2
  2665. * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  2666. */
  2667. public function SetKeywords($keywords)
  2668. {
  2669. $this->keywords = $keywords;
  2670. }
  2671. /**
  2672. * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  2673. * @param $creator (string) The name of the creator.
  2674. * @public
  2675. * @since 1.2
  2676. * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  2677. */
  2678. public function SetCreator($creator)
  2679. {
  2680. $this->creator = $creator;
  2681. }
  2682. /**
  2683. * Throw an exception or print an error message and die if the K_TCPDF_PARSER_THROW_EXCEPTION_ERROR constant is set to true.
  2684. * @param $msg (string) The error message
  2685. * @public
  2686. * @since 1.0
  2687. */
  2688. public function Error($msg)
  2689. {
  2690. // unset all class variables
  2691. $this->_destroy(true);
  2692. if (defined('K_TCPDF_THROW_EXCEPTION_ERROR') AND !K_TCPDF_THROW_EXCEPTION_ERROR) {
  2693. die('<strong>TCPDF ERROR: </strong>'.$msg);
  2694. } else {
  2695. throw new Exception('TCPDF ERROR: '.$msg);
  2696. }
  2697. }
  2698. /**
  2699. * This method begins the generation of the PDF document.
  2700. * It is not necessary to call it explicitly because AddPage() does it automatically.
  2701. * Note: no page is created by this method
  2702. * @public
  2703. * @since 1.0
  2704. * @see AddPage(), Close()
  2705. */
  2706. public function Open()
  2707. {
  2708. $this->state = 1;
  2709. }
  2710. /**
  2711. * Terminates the PDF document.
  2712. * It is not necessary to call this method explicitly because Output() does it automatically.
  2713. * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  2714. * @public
  2715. * @since 1.0
  2716. * @see Open(), Output()
  2717. */
  2718. public function Close()
  2719. {
  2720. if ($this->state == 3) {
  2721. return;
  2722. }
  2723. if ($this->page == 0) {
  2724. $this->AddPage();
  2725. }
  2726. $this->endLayer();
  2727. if ($this->tcpdflink) {
  2728. // save current graphic settings
  2729. $gvars = $this->getGraphicVars();
  2730. $this->setEqualColumns();
  2731. $this->lastpage(true);
  2732. $this->SetAutoPageBreak(false);
  2733. $this->x = 0;
  2734. $this->y = $this->h - (1 / $this->k);
  2735. $this->lMargin = 0;
  2736. $this->_outSaveGraphicsState();
  2737. $font = defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica';
  2738. $this->SetFont($font, '', 1);
  2739. $this->setTextRenderingMode(0, false, false);
  2740. $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";
  2741. $lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67";
  2742. $this->Cell(0, 0, $msg, 0, 0, 'L', 0, $lnk, 0, false, 'D', 'B');
  2743. $this->_outRestoreGraphicsState();
  2744. // restore graphic settings
  2745. $this->setGraphicVars($gvars);
  2746. }
  2747. // close page
  2748. $this->endPage();
  2749. // close document
  2750. $this->_enddoc();
  2751. // unset all class variables (except critical ones)
  2752. $this->_destroy(false);
  2753. }
  2754. /**
  2755. * Move pointer at the specified document page and update page dimensions.
  2756. * @param $pnum (int) page number (1 ... numpages)
  2757. * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
  2758. * @public
  2759. * @since 2.1.000 (2008-01-07)
  2760. * @see getPage(), lastpage(), getNumPages()
  2761. */
  2762. public function setPage($pnum, $resetmargins = false)
  2763. {
  2764. if (($pnum == $this->page) AND ($this->state == 2)) {
  2765. return;
  2766. }
  2767. if (($pnum > 0) AND ($pnum <= $this->numpages)) {
  2768. $this->state = 2;
  2769. // save current graphic settings
  2770. //$gvars = $this->getGraphicVars();
  2771. $oldpage = $this->page;
  2772. $this->page = $pnum;
  2773. $this->wPt = $this->pagedim[$this->page]['w'];
  2774. $this->hPt = $this->pagedim[$this->page]['h'];
  2775. $this->w = $this->pagedim[$this->page]['wk'];
  2776. $this->h = $this->pagedim[$this->page]['hk'];
  2777. $this->tMargin = $this->pagedim[$this->page]['tm'];
  2778. $this->bMargin = $this->pagedim[$this->page]['bm'];
  2779. $this->original_lMargin = $this->pagedim[$this->page]['olm'];
  2780. $this->original_rMargin = $this->pagedim[$this->page]['orm'];
  2781. $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
  2782. $this->CurOrientation = $this->pagedim[$this->page]['or'];
  2783. $this->SetAutoPageBreak($this->AutoPageBreak, $this->bMargin);
  2784. // restore graphic settings
  2785. //$this->setGraphicVars($gvars);
  2786. if ($resetmargins) {
  2787. $this->lMargin = $this->pagedim[$this->page]['olm'];
  2788. $this->rMargin = $this->pagedim[$this->page]['orm'];
  2789. $this->SetY($this->tMargin);
  2790. } else {
  2791. // account for booklet mode
  2792. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  2793. $deltam = $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm'];
  2794. $this->lMargin += $deltam;
  2795. $this->rMargin -= $deltam;
  2796. }
  2797. }
  2798. } else {
  2799. $this->Error('Wrong page number on setPage() function: '.$pnum);
  2800. }
  2801. }
  2802. /**
  2803. * Reset pointer to the last document page.
  2804. * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
  2805. * @public
  2806. * @since 2.0.000 (2008-01-04)
  2807. * @see setPage(), getPage(), getNumPages()
  2808. */
  2809. public function lastPage($resetmargins = false)
  2810. {
  2811. $this->setPage($this->getNumPages(), $resetmargins);
  2812. }
  2813. /**
  2814. * Get current document page number.
  2815. * @return int page number
  2816. * @public
  2817. * @since 2.1.000 (2008-01-07)
  2818. * @see setPage(), lastpage(), getNumPages()
  2819. */
  2820. public function getPage()
  2821. {
  2822. return $this->page;
  2823. }
  2824. /**
  2825. * Get the total number of insered pages.
  2826. * @return int number of pages
  2827. * @public
  2828. * @since 2.1.000 (2008-01-07)
  2829. * @see setPage(), getPage(), lastpage()
  2830. */
  2831. public function getNumPages()
  2832. {
  2833. return $this->numpages;
  2834. }
  2835. /**
  2836. * Adds a new TOC (Table Of Content) page to the document.
  2837. * @param $orientation (string) page orientation.
  2838. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  2839. * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
  2840. * @public
  2841. * @since 5.0.001 (2010-05-06)
  2842. * @see AddPage(), startPage(), endPage(), endTOCPage()
  2843. */
  2844. public function addTOCPage($orientation = '', $format = '', $keepmargins = false)
  2845. {
  2846. $this->AddPage($orientation, $format, $keepmargins, true);
  2847. }
  2848. /**
  2849. * Terminate the current TOC (Table Of Content) page
  2850. * @public
  2851. * @since 5.0.001 (2010-05-06)
  2852. * @see AddPage(), startPage(), endPage(), addTOCPage()
  2853. */
  2854. public function endTOCPage()
  2855. {
  2856. $this->endPage(true);
  2857. }
  2858. /**
  2859. * 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).
  2860. * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
  2861. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2862. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  2863. * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
  2864. * @param $tocpage (boolean) if true set the tocpage state to true (the added page will be used to display Table Of Content).
  2865. * @public
  2866. * @since 1.0
  2867. * @see startPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  2868. */
  2869. public function AddPage($orientation = '', $format = '', $keepmargins = false, $tocpage = false)
  2870. {
  2871. if ($this->inxobj) {
  2872. // we are inside an XObject template
  2873. return;
  2874. }
  2875. if (!isset($this->original_lMargin) OR $keepmargins) {
  2876. $this->original_lMargin = $this->lMargin;
  2877. }
  2878. if (!isset($this->original_rMargin) OR $keepmargins) {
  2879. $this->original_rMargin = $this->rMargin;
  2880. }
  2881. // terminate previous page
  2882. $this->endPage();
  2883. // start new page
  2884. $this->startPage($orientation, $format, $tocpage);
  2885. }
  2886. /**
  2887. * Terminate the current page
  2888. * @param $tocpage (boolean) if true set the tocpage state to false (end the page used to display Table Of Content).
  2889. * @public
  2890. * @since 4.2.010 (2008-11-14)
  2891. * @see AddPage(), startPage(), addTOCPage(), endTOCPage()
  2892. */
  2893. public function endPage($tocpage = false)
  2894. {
  2895. // check if page is already closed
  2896. if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) {
  2897. return;
  2898. }
  2899. // print page footer
  2900. $this->setFooter();
  2901. // close page
  2902. $this->_endpage();
  2903. // mark page as closed
  2904. $this->pageopen[$this->page] = false;
  2905. if ($tocpage) {
  2906. $this->tocpage = false;
  2907. }
  2908. }
  2909. /**
  2910. * Starts a new page to the document. The page must be closed using the endPage() function.
  2911. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  2912. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2913. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  2914. * @param $tocpage (boolean) if true the page is designated to contain the Table-Of-Content.
  2915. * @since 4.2.010 (2008-11-14)
  2916. * @see AddPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  2917. * @public
  2918. */
  2919. public function startPage($orientation = '', $format = '', $tocpage = false)
  2920. {
  2921. if ($tocpage) {
  2922. $this->tocpage = true;
  2923. }
  2924. // move page numbers of documents to be attached
  2925. if ($this->tocpage) {
  2926. // move reference to unexistent pages (used for page attachments)
  2927. // adjust outlines
  2928. $tmpoutlines = $this->outlines;
  2929. foreach ($tmpoutlines as $key => $outline) {
  2930. if (!$outline['f'] AND ($outline['p'] > $this->numpages)) {
  2931. $this->outlines[$key]['p'] = ($outline['p'] + 1);
  2932. }
  2933. }
  2934. // adjust dests
  2935. $tmpdests = $this->dests;
  2936. foreach ($tmpdests as $key => $dest) {
  2937. if (!$dest['f'] AND ($dest['p'] > $this->numpages)) {
  2938. $this->dests[$key]['p'] = ($dest['p'] + 1);
  2939. }
  2940. }
  2941. // adjust links
  2942. $tmplinks = $this->links;
  2943. foreach ($tmplinks as $key => $link) {
  2944. if (!$link['f'] AND ($link['p'] > $this->numpages)) {
  2945. $this->links[$key]['p'] = ($link['p'] + 1);
  2946. }
  2947. }
  2948. }
  2949. if ($this->numpages > $this->page) {
  2950. // this page has been already added
  2951. $this->setPage($this->page + 1);
  2952. $this->SetY($this->tMargin);
  2953. return;
  2954. }
  2955. // start a new page
  2956. if ($this->state == 0) {
  2957. $this->Open();
  2958. }
  2959. ++$this->numpages;
  2960. $this->swapMargins($this->booklet);
  2961. // save current graphic settings
  2962. $gvars = $this->getGraphicVars();
  2963. // start new page
  2964. $this->_beginpage($orientation, $format);
  2965. // mark page as open
  2966. $this->pageopen[$this->page] = true;
  2967. // restore graphic settings
  2968. $this->setGraphicVars($gvars);
  2969. // mark this point
  2970. $this->setPageMark();
  2971. // print page header
  2972. $this->setHeader();
  2973. // restore graphic settings
  2974. $this->setGraphicVars($gvars);
  2975. // mark this point
  2976. $this->setPageMark();
  2977. // print table header (if any)
  2978. $this->setTableHeader();
  2979. // set mark for empty page check
  2980. $this->emptypagemrk[$this->page]= $this->pagelen[$this->page];
  2981. }
  2982. /**
  2983. * Set start-writing mark on current page stream used to put borders and fills.
  2984. * Borders and fills are always created after content and inserted on the position marked by this method.
  2985. * This function must be called after calling Image() function for a background image.
  2986. * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
  2987. * @public
  2988. * @since 4.0.016 (2008-07-30)
  2989. */
  2990. public function setPageMark()
  2991. {
  2992. $this->intmrk[$this->page] = $this->pagelen[$this->page];
  2993. $this->bordermrk[$this->page] = $this->intmrk[$this->page];
  2994. $this->setContentMark();
  2995. }
  2996. /**
  2997. * Set start-writing mark on selected page.
  2998. * Borders and fills are always created after content and inserted on the position marked by this method.
  2999. * @param $page (int) page number (default is the current page)
  3000. * @protected
  3001. * @since 4.6.021 (2009-07-20)
  3002. */
  3003. protected function setContentMark($page = 0)
  3004. {
  3005. if ($page <= 0) {
  3006. $page = $this->page;
  3007. }
  3008. if (isset($this->footerlen[$page])) {
  3009. $this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
  3010. } else {
  3011. $this->cntmrk[$page] = $this->pagelen[$page];
  3012. }
  3013. }
  3014. /**
  3015. * Set header data.
  3016. * @param $ln (string) header image logo
  3017. * @param $lw (string) header image logo width in mm
  3018. * @param $ht (string) string to print as title on document header
  3019. * @param $hs (string) string to print on document header
  3020. * @param $tc (array) RGB array color for text.
  3021. * @param $lc (array) RGB array color for line.
  3022. * @public
  3023. */
  3024. public function setHeaderData($ln = '', $lw = 0, $ht = '', $hs = '', $tc = array(0,0,0), $lc = array(0,0,0))
  3025. {
  3026. $this->header_logo = $ln;
  3027. $this->header_logo_width = $lw;
  3028. $this->header_title = $ht;
  3029. $this->header_string = $hs;
  3030. $this->header_text_color = $tc;
  3031. $this->header_line_color = $lc;
  3032. }
  3033. /**
  3034. * Set footer data.
  3035. * @param $tc (array) RGB array color for text.
  3036. * @param $lc (array) RGB array color for line.
  3037. * @public
  3038. */
  3039. public function setFooterData($tc = array(0,0,0), $lc = array(0,0,0))
  3040. {
  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()
  3048. * @public
  3049. * @since 4.0.012 (2008-07-24)
  3050. */
  3051. public function getHeaderData()
  3052. {
  3053. $ret = array();
  3054. $ret['logo'] = $this->header_logo;
  3055. $ret['logo_width'] = $this->header_logo_width;
  3056. $ret['title'] = $this->header_title;
  3057. $ret['string'] = $this->header_string;
  3058. $ret['text_color'] = $this->header_text_color;
  3059. $ret['line_color'] = $this->header_line_color;
  3060. return $ret;
  3061. }
  3062. /**
  3063. * Set header margin.
  3064. * (minimum distance between header and top page margin)
  3065. * @param $hm (int) distance in user units
  3066. * @public
  3067. */
  3068. public function setHeaderMargin($hm = 10)
  3069. {
  3070. $this->header_margin = $hm;
  3071. }
  3072. /**
  3073. * Returns header margin in user units.
  3074. * @return float
  3075. * @since 4.0.012 (2008-07-24)
  3076. * @public
  3077. */
  3078. public function getHeaderMargin()
  3079. {
  3080. return $this->header_margin;
  3081. }
  3082. /**
  3083. * Set footer margin.
  3084. * (minimum distance between footer and bottom page margin)
  3085. * @param $fm (int) distance in user units
  3086. * @public
  3087. */
  3088. public function setFooterMargin($fm = 10)
  3089. {
  3090. $this->footer_margin = $fm;
  3091. }
  3092. /**
  3093. * Returns footer margin in user units.
  3094. * @return float
  3095. * @since 4.0.012 (2008-07-24)
  3096. * @public
  3097. */
  3098. public function getFooterMargin()
  3099. {
  3100. return $this->footer_margin;
  3101. }
  3102. /**
  3103. * Set a flag to print page header.
  3104. * @param $val (boolean) set to true to print the page header (default), false otherwise.
  3105. * @public
  3106. */
  3107. public function setPrintHeader($val = true)
  3108. {
  3109. $this->print_header = $val ? true : false;
  3110. }
  3111. /**
  3112. * Set a flag to print page footer.
  3113. * @param $val (boolean) set to true to print the page footer (default), false otherwise.
  3114. * @public
  3115. */
  3116. public function setPrintFooter($val = true)
  3117. {
  3118. $this->print_footer = $val ? true : false;
  3119. }
  3120. /**
  3121. * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
  3122. * @return float
  3123. * @public
  3124. */
  3125. public function getImageRBX()
  3126. {
  3127. return $this->img_rb_x;
  3128. }
  3129. /**
  3130. * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
  3131. * @return float
  3132. * @public
  3133. */
  3134. public function getImageRBY()
  3135. {
  3136. return $this->img_rb_y;
  3137. }
  3138. /**
  3139. * Reset the xobject template used by Header() method.
  3140. * @public
  3141. */
  3142. public function resetHeaderTemplate()
  3143. {
  3144. $this->header_xobjid = false;
  3145. }
  3146. /**
  3147. * Set a flag to automatically reset the xobject template used by Header() method at each page.
  3148. * @param $val (boolean) set to true to reset Header xobject template at each page, false otherwise.
  3149. * @public
  3150. */
  3151. public function setHeaderTemplateAutoreset($val = true)
  3152. {
  3153. $this->header_xobj_autoreset = $val ? true : false;
  3154. }
  3155. /**
  3156. * This method is used to render the page header.
  3157. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3158. * @public
  3159. */
  3160. public function Header()
  3161. {
  3162. if ($this->header_xobjid === false) {
  3163. // start a new XObject Template
  3164. $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin);
  3165. $headerfont = $this->getHeaderFont();
  3166. $headerdata = $this->getHeaderData();
  3167. $this->y = $this->header_margin;
  3168. if ($this->rtl) {
  3169. $this->x = $this->w - $this->original_rMargin;
  3170. } else {
  3171. $this->x = $this->original_lMargin;
  3172. }
  3173. if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) {
  3174. $imgtype = TCPDF_IMAGES::getImageFileType(K_PATH_IMAGES.$headerdata['logo']);
  3175. if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  3176. $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3177. } elseif ($imgtype == 'svg') {
  3178. $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3179. } else {
  3180. $this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3181. }
  3182. $imgy = $this->getImageRBY();
  3183. } else {
  3184. $imgy = $this->y;
  3185. }
  3186. $cell_height = $this->getCellHeight($headerfont[2] / $this->k);
  3187. // set starting margin for text data cell
  3188. if ($this->getRTL()) {
  3189. $header_x = $this->original_rMargin + ($headerdata['logo_width'] * 1.1);
  3190. } else {
  3191. $header_x = $this->original_lMargin + ($headerdata['logo_width'] * 1.1);
  3192. }
  3193. $cw = $this->w - $this->original_lMargin - $this->original_rMargin - ($headerdata['logo_width'] * 1.1);
  3194. $this->SetTextColorArray($this->header_text_color);
  3195. // header title
  3196. $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1);
  3197. $this->SetX($header_x);
  3198. $this->Cell($cw, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
  3199. // header string
  3200. $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
  3201. $this->SetX($header_x);
  3202. $this->MultiCell($cw, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false, true, 0, 'T', false);
  3203. // print an ending header line
  3204. $this->SetLineStyle(array('width' => 0.85 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $headerdata['line_color']));
  3205. $this->SetY((2.835 / $this->k) + max($imgy, $this->y));
  3206. if ($this->rtl) {
  3207. $this->SetX($this->original_rMargin);
  3208. } else {
  3209. $this->SetX($this->original_lMargin);
  3210. }
  3211. $this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');
  3212. $this->endTemplate();
  3213. }
  3214. // print header template
  3215. $x = 0;
  3216. $dx = 0;
  3217. if (!$this->header_xobj_autoreset AND $this->booklet AND (($this->page % 2) == 0)) {
  3218. // adjust margins for booklet mode
  3219. $dx = ($this->original_lMargin - $this->original_rMargin);
  3220. }
  3221. if ($this->rtl) {
  3222. $x = $this->w + $dx;
  3223. } else {
  3224. $x = 0 + $dx;
  3225. }
  3226. $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false);
  3227. if ($this->header_xobj_autoreset) {
  3228. // reset header xobject template at each page
  3229. $this->header_xobjid = false;
  3230. }
  3231. }
  3232. /**
  3233. * This method is used to render the page footer.
  3234. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3235. * @public
  3236. */
  3237. public function Footer()
  3238. {
  3239. $cur_y = $this->y;
  3240. $this->SetTextColorArray($this->footer_text_color);
  3241. //set style for cell border
  3242. $line_width = (0.85 / $this->k);
  3243. $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $this->footer_line_color));
  3244. //print document barcode
  3245. $barcode = $this->getBarcode();
  3246. if (!empty($barcode)) {
  3247. $this->Ln($line_width);
  3248. $barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin) / 3);
  3249. $style = array(
  3250. 'position' => $this->rtl?'R':'L',
  3251. 'align' => $this->rtl?'R':'L',
  3252. 'stretch' => false,
  3253. 'fitwidth' => true,
  3254. 'cellfitalign' => '',
  3255. 'border' => false,
  3256. 'padding' => 0,
  3257. 'fgcolor' => array(0,0,0),
  3258. 'bgcolor' => false,
  3259. 'text' => false
  3260. );
  3261. $this->write1DBarcode($barcode, 'C128', '', $cur_y + $line_width, '', (($this->footer_margin / 3) - $line_width), 0.3, $style, '');
  3262. }
  3263. $w_page = isset($this->l['w_page']) ? $this->l['w_page'].' ' : '';
  3264. if (empty($this->pagegroups)) {
  3265. $pagenumtxt = $w_page.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
  3266. } else {
  3267. $pagenumtxt = $w_page.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
  3268. }
  3269. $this->SetY($cur_y);
  3270. //Print page number
  3271. if ($this->getRTL()) {
  3272. $this->SetX($this->original_rMargin);
  3273. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
  3274. } else {
  3275. $this->SetX($this->original_lMargin);
  3276. $this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');
  3277. }
  3278. }
  3279. /**
  3280. * This method is used to render the page header.
  3281. * @protected
  3282. * @since 4.0.012 (2008-07-24)
  3283. */
  3284. protected function setHeader()
  3285. {
  3286. if (!$this->print_header OR ($this->state != 2)) {
  3287. return;
  3288. }
  3289. $this->InHeader = true;
  3290. $this->setGraphicVars($this->default_graphic_vars);
  3291. $temp_thead = $this->thead;
  3292. $temp_theadMargins = $this->theadMargins;
  3293. $lasth = $this->lasth;
  3294. $newline = $this->newline;
  3295. $this->_outSaveGraphicsState();
  3296. $this->rMargin = $this->original_rMargin;
  3297. $this->lMargin = $this->original_lMargin;
  3298. $this->SetCellPadding(0);
  3299. //set current position
  3300. if ($this->rtl) {
  3301. $this->SetXY($this->original_rMargin, $this->header_margin);
  3302. } else {
  3303. $this->SetXY($this->original_lMargin, $this->header_margin);
  3304. }
  3305. $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
  3306. $this->Header();
  3307. //restore position
  3308. if ($this->rtl) {
  3309. $this->SetXY($this->original_rMargin, $this->tMargin);
  3310. } else {
  3311. $this->SetXY($this->original_lMargin, $this->tMargin);
  3312. }
  3313. $this->_outRestoreGraphicsState();
  3314. $this->lasth = $lasth;
  3315. $this->thead = $temp_thead;
  3316. $this->theadMargins = $temp_theadMargins;
  3317. $this->newline = $newline;
  3318. $this->InHeader = false;
  3319. }
  3320. /**
  3321. * This method is used to render the page footer.
  3322. * @protected
  3323. * @since 4.0.012 (2008-07-24)
  3324. */
  3325. protected function setFooter()
  3326. {
  3327. if ($this->state != 2) {
  3328. return;
  3329. }
  3330. $this->InFooter = true;
  3331. // save current graphic settings
  3332. $gvars = $this->getGraphicVars();
  3333. // mark this point
  3334. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  3335. $this->_out("\n");
  3336. if ($this->print_footer) {
  3337. $this->setGraphicVars($this->default_graphic_vars);
  3338. $this->current_column = 0;
  3339. $this->num_columns = 1;
  3340. $temp_thead = $this->thead;
  3341. $temp_theadMargins = $this->theadMargins;
  3342. $lasth = $this->lasth;
  3343. $this->_outSaveGraphicsState();
  3344. $this->rMargin = $this->original_rMargin;
  3345. $this->lMargin = $this->original_lMargin;
  3346. $this->SetCellPadding(0);
  3347. //set current position
  3348. $footer_y = $this->h - $this->footer_margin;
  3349. if ($this->rtl) {
  3350. $this->SetXY($this->original_rMargin, $footer_y);
  3351. } else {
  3352. $this->SetXY($this->original_lMargin, $footer_y);
  3353. }
  3354. $this->SetFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
  3355. $this->Footer();
  3356. //restore position
  3357. if ($this->rtl) {
  3358. $this->SetXY($this->original_rMargin, $this->tMargin);
  3359. } else {
  3360. $this->SetXY($this->original_lMargin, $this->tMargin);
  3361. }
  3362. $this->_outRestoreGraphicsState();
  3363. $this->lasth = $lasth;
  3364. $this->thead = $temp_thead;
  3365. $this->theadMargins = $temp_theadMargins;
  3366. }
  3367. // restore graphic settings
  3368. $this->setGraphicVars($gvars);
  3369. $this->current_column = $gvars['current_column'];
  3370. $this->num_columns = $gvars['num_columns'];
  3371. // calculate footer length
  3372. $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1;
  3373. $this->InFooter = false;
  3374. }
  3375. /**
  3376. * Check if we are on the page body (excluding page header and footer).
  3377. * @return true if we are not in page header nor in page footer, false otherwise.
  3378. * @protected
  3379. * @since 5.9.091 (2011-06-15)
  3380. */
  3381. protected function inPageBody()
  3382. {
  3383. return (($this->InHeader === false) AND ($this->InFooter === false));
  3384. }
  3385. /**
  3386. * This method is used to render the table header on new page (if any).
  3387. * @protected
  3388. * @since 4.5.030 (2009-03-25)
  3389. */
  3390. protected function setTableHeader()
  3391. {
  3392. if ($this->num_columns > 1) {
  3393. // multi column mode
  3394. return;
  3395. }
  3396. if (isset($this->theadMargins['top'])) {
  3397. // restore the original top-margin
  3398. $this->tMargin = $this->theadMargins['top'];
  3399. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3400. $this->y = $this->tMargin;
  3401. }
  3402. if (!TCPDF_STATIC::empty_string($this->thead) AND (!$this->inthead)) {
  3403. // set margins
  3404. $prev_lMargin = $this->lMargin;
  3405. $prev_rMargin = $this->rMargin;
  3406. $prev_cell_padding = $this->cell_padding;
  3407. $this->lMargin = $this->theadMargins['lmargin'] + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$this->theadMargins['page']]['olm']);
  3408. $this->rMargin = $this->theadMargins['rmargin'] + ($this->pagedim[$this->page]['orm'] - $this->pagedim[$this->theadMargins['page']]['orm']);
  3409. $this->cell_padding = $this->theadMargins['cell_padding'];
  3410. if ($this->rtl) {
  3411. $this->x = $this->w - $this->rMargin;
  3412. } else {
  3413. $this->x = $this->lMargin;
  3414. }
  3415. // account for special "cell" mode
  3416. if ($this->theadMargins['cell']) {
  3417. if ($this->rtl) {
  3418. $this->x -= $this->cell_padding['R'];
  3419. } else {
  3420. $this->x += $this->cell_padding['L'];
  3421. }
  3422. }
  3423. $gvars = $this->getGraphicVars();
  3424. if (!empty($this->theadMargins['gvars'])) {
  3425. // set the correct graphic style
  3426. $this->setGraphicVars($this->theadMargins['gvars']);
  3427. $this->rMargin = $gvars['rMargin'];
  3428. $this->lMargin = $gvars['lMargin'];
  3429. }
  3430. // print table header
  3431. $this->writeHTML($this->thead, false, false, false, false, '');
  3432. $this->setGraphicVars($gvars);
  3433. // set new top margin to skip the table headers
  3434. if (!isset($this->theadMargins['top'])) {
  3435. $this->theadMargins['top'] = $this->tMargin;
  3436. }
  3437. // store end of header position
  3438. if (!isset($this->columns[0]['th'])) {
  3439. $this->columns[0]['th'] = array();
  3440. }
  3441. $this->columns[0]['th']['\''.$this->page.'\''] = $this->y;
  3442. $this->tMargin = $this->y;
  3443. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3444. $this->lasth = 0;
  3445. $this->lMargin = $prev_lMargin;
  3446. $this->rMargin = $prev_rMargin;
  3447. $this->cell_padding = $prev_cell_padding;
  3448. }
  3449. }
  3450. /**
  3451. * Returns the current page number.
  3452. * @return int page number
  3453. * @public
  3454. * @since 1.0
  3455. * @see getAliasNbPages()
  3456. */
  3457. public function PageNo()
  3458. {
  3459. return $this->page;
  3460. }
  3461. /**
  3462. * Returns the array of spot colors.
  3463. * @return (array) Spot colors array.
  3464. * @public
  3465. * @since 6.0.038 (2013-09-30)
  3466. */
  3467. public function getAllSpotColors()
  3468. {
  3469. return $this->spot_colors;
  3470. }
  3471. /**
  3472. * Defines a new spot color.
  3473. * It can be expressed in RGB components or gray scale.
  3474. * The method can be called before the first page is created and the value is retained from page to page.
  3475. * @param $name (string) Full name of the spot color.
  3476. * @param $c (float) Cyan color for CMYK. Value between 0 and 100.
  3477. * @param $m (float) Magenta color for CMYK. Value between 0 and 100.
  3478. * @param $y (float) Yellow color for CMYK. Value between 0 and 100.
  3479. * @param $k (float) Key (Black) color for CMYK. Value between 0 and 100.
  3480. * @public
  3481. * @since 4.0.024 (2008-09-12)
  3482. * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  3483. */
  3484. public function AddSpotColor($name, $c, $m, $y, $k)
  3485. {
  3486. if (!isset($this->spot_colors[$name])) {
  3487. $i = (1 + count($this->spot_colors));
  3488. $this->spot_colors[$name] = array('C' => $c, 'M' => $m, 'Y' => $y, 'K' => $k, 'name' => $name, 'i' => $i);
  3489. }
  3490. }
  3491. /**
  3492. * Set the spot color for the specified type ('draw', 'fill', 'text').
  3493. * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  3494. * @param $name (string) Name of the spot color.
  3495. * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3496. * @return (string) PDF color command.
  3497. * @public
  3498. * @since 5.9.125 (2011-10-03)
  3499. */
  3500. public function setSpotColor($type, $name, $tint = 100)
  3501. {
  3502. $spotcolor = TCPDF_COLORS::getSpotColor($name, $this->spot_colors);
  3503. if ($spotcolor === false) {
  3504. $this->Error('Undefined spot color: '.$name.', you must add it using the AddSpotColor() method.');
  3505. }
  3506. $tint = (max(0, min(100, $tint)) / 100);
  3507. $pdfcolor = sprintf('/CS%d ', $this->spot_colors[$name]['i']);
  3508. switch ($type) {
  3509. case 'draw': {
  3510. $pdfcolor .= sprintf('CS %F SCN', $tint);
  3511. $this->DrawColor = $pdfcolor;
  3512. $this->strokecolor = $spotcolor;
  3513. break;
  3514. }
  3515. case 'fill': {
  3516. $pdfcolor .= sprintf('cs %F scn', $tint);
  3517. $this->FillColor = $pdfcolor;
  3518. $this->bgcolor = $spotcolor;
  3519. break;
  3520. }
  3521. case 'text': {
  3522. $pdfcolor .= sprintf('cs %F scn', $tint);
  3523. $this->TextColor = $pdfcolor;
  3524. $this->fgcolor = $spotcolor;
  3525. break;
  3526. }
  3527. }
  3528. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3529. if ($this->state == 2) {
  3530. $this->_out($pdfcolor);
  3531. }
  3532. if ($this->inxobj) {
  3533. // we are inside an XObject template
  3534. $this->xobjects[$this->xobjid]['spot_colors'][$name] = $this->spot_colors[$name];
  3535. }
  3536. return $pdfcolor;
  3537. }
  3538. /**
  3539. * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
  3540. * @param $name (string) Name of the spot color.
  3541. * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3542. * @public
  3543. * @since 4.0.024 (2008-09-12)
  3544. * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  3545. */
  3546. public function SetDrawSpotColor($name, $tint = 100)
  3547. {
  3548. $this->setSpotColor('draw', $name, $tint);
  3549. }
  3550. /**
  3551. * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
  3552. * @param $name (string) Name of the spot color.
  3553. * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3554. * @public
  3555. * @since 4.0.024 (2008-09-12)
  3556. * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
  3557. */
  3558. public function SetFillSpotColor($name, $tint = 100)
  3559. {
  3560. $this->setSpotColor('fill', $name, $tint);
  3561. }
  3562. /**
  3563. * Defines the spot color used for text.
  3564. * @param $name (string) Name of the spot color.
  3565. * @param $tint (int) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3566. * @public
  3567. * @since 4.0.024 (2008-09-12)
  3568. * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
  3569. */
  3570. public function SetTextSpotColor($name, $tint = 100)
  3571. {
  3572. $this->setSpotColor('text', $name, $tint);
  3573. }
  3574. /**
  3575. * Set the color array for the specified type ('draw', 'fill', 'text').
  3576. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3577. * The method can be called before the first page is created and the value is retained from page to page.
  3578. * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  3579. * @param $color (array) Array of colors (1=gray, 3=RGB, 4=CMYK or 5=spotcolor=CMYK+name values).
  3580. * @param $ret (boolean) If true do not send the PDF command.
  3581. * @return (string) The PDF command or empty string.
  3582. * @public
  3583. * @since 3.1.000 (2008-06-11)
  3584. */
  3585. public function setColorArray($type, $color, $ret = false)
  3586. {
  3587. if (is_array($color)) {
  3588. $color = array_values($color);
  3589. // component: grey, RGB red or CMYK cyan
  3590. $c = isset($color[0]) ? $color[0] : -1;
  3591. // component: RGB green or CMYK magenta
  3592. $m = isset($color[1]) ? $color[1] : -1;
  3593. // component: RGB blue or CMYK yellow
  3594. $y = isset($color[2]) ? $color[2] : -1;
  3595. // component: CMYK black
  3596. $k = isset($color[3]) ? $color[3] : -1;
  3597. // color name
  3598. $name = isset($color[4]) ? $color[4] : '';
  3599. if ($c >= 0) {
  3600. return $this->setColor($type, $c, $m, $y, $k, $ret, $name);
  3601. }
  3602. }
  3603. return '';
  3604. }
  3605. /**
  3606. * Defines the color used for all drawing operations (lines, rectangles and cell borders).
  3607. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3608. * The method can be called before the first page is created and the value is retained from page to page.
  3609. * @param $color (array) Array of colors (1, 3 or 4 values).
  3610. * @param $ret (boolean) If true do not send the PDF command.
  3611. * @return string the PDF command
  3612. * @public
  3613. * @since 3.1.000 (2008-06-11)
  3614. * @see SetDrawColor()
  3615. */
  3616. public function SetDrawColorArray($color, $ret = false)
  3617. {
  3618. return $this->setColorArray('draw', $color, $ret);
  3619. }
  3620. /**
  3621. * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
  3622. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3623. * The method can be called before the first page is created and the value is retained from page to page.
  3624. * @param $color (array) Array of colors (1, 3 or 4 values).
  3625. * @param $ret (boolean) If true do not send the PDF command.
  3626. * @public
  3627. * @since 3.1.000 (2008-6-11)
  3628. * @see SetFillColor()
  3629. */
  3630. public function SetFillColorArray($color, $ret = false)
  3631. {
  3632. return $this->setColorArray('fill', $color, $ret);
  3633. }
  3634. /**
  3635. * Defines the color used for text. It can be expressed in RGB components or gray scale.
  3636. * The method can be called before the first page is created and the value is retained from page to page.
  3637. * @param $color (array) Array of colors (1, 3 or 4 values).
  3638. * @param $ret (boolean) If true do not send the PDF command.
  3639. * @public
  3640. * @since 3.1.000 (2008-6-11)
  3641. * @see SetFillColor()
  3642. */
  3643. public function SetTextColorArray($color, $ret = false)
  3644. {
  3645. return $this->setColorArray('text', $color, $ret);
  3646. }
  3647. /**
  3648. * Defines the color used by the specified type ('draw', 'fill', 'text').
  3649. * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  3650. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3651. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3652. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3653. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  3654. * @param $ret (boolean) If true do not send the command.
  3655. * @param $name (string) spot color name (if any)
  3656. * @return (string) The PDF command or empty string.
  3657. * @public
  3658. * @since 5.9.125 (2011-10-03)
  3659. */
  3660. public function setColor($type, $col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1, $ret = false, $name = '')
  3661. {
  3662. // set default values
  3663. if (!is_numeric($col1)) {
  3664. $col1 = 0;
  3665. }
  3666. if (!is_numeric($col2)) {
  3667. $col2 = -1;
  3668. }
  3669. if (!is_numeric($col3)) {
  3670. $col3 = -1;
  3671. }
  3672. if (!is_numeric($col4)) {
  3673. $col4 = -1;
  3674. }
  3675. // set color by case
  3676. $suffix = '';
  3677. if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
  3678. // Grey scale
  3679. $col1 = max(0, min(255, $col1));
  3680. $intcolor = array('G' => $col1);
  3681. $pdfcolor = sprintf('%F ', ($col1 / 255));
  3682. $suffix = 'g';
  3683. } elseif ($col4 == -1) {
  3684. // RGB
  3685. $col1 = max(0, min(255, $col1));
  3686. $col2 = max(0, min(255, $col2));
  3687. $col3 = max(0, min(255, $col3));
  3688. $intcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  3689. $pdfcolor = sprintf('%F %F %F ', ($col1 / 255), ($col2 / 255), ($col3 / 255));
  3690. $suffix = 'rg';
  3691. } else {
  3692. $col1 = max(0, min(100, $col1));
  3693. $col2 = max(0, min(100, $col2));
  3694. $col3 = max(0, min(100, $col3));
  3695. $col4 = max(0, min(100, $col4));
  3696. if (empty($name)) {
  3697. // CMYK
  3698. $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  3699. $pdfcolor = sprintf('%F %F %F %F ', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
  3700. $suffix = 'k';
  3701. } else {
  3702. // SPOT COLOR
  3703. $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
  3704. $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
  3705. $pdfcolor = $this->setSpotColor($type, $name, 100);
  3706. }
  3707. }
  3708. switch ($type) {
  3709. case 'draw': {
  3710. $pdfcolor .= strtoupper($suffix);
  3711. $this->DrawColor = $pdfcolor;
  3712. $this->strokecolor = $intcolor;
  3713. break;
  3714. }
  3715. case 'fill': {
  3716. $pdfcolor .= $suffix;
  3717. $this->FillColor = $pdfcolor;
  3718. $this->bgcolor = $intcolor;
  3719. break;
  3720. }
  3721. case 'text': {
  3722. $pdfcolor .= $suffix;
  3723. $this->TextColor = $pdfcolor;
  3724. $this->fgcolor = $intcolor;
  3725. break;
  3726. }
  3727. }
  3728. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3729. if (($type != 'text') AND ($this->state == 2)) {
  3730. if (!$ret) {
  3731. $this->_out($pdfcolor);
  3732. }
  3733. return $pdfcolor;
  3734. }
  3735. return '';
  3736. }
  3737. /**
  3738. * 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.
  3739. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3740. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3741. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3742. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  3743. * @param $ret (boolean) If true do not send the command.
  3744. * @param $name (string) spot color name (if any)
  3745. * @return string the PDF command
  3746. * @public
  3747. * @since 1.3
  3748. * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  3749. */
  3750. public function SetDrawColor($col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1, $ret = false, $name = '')
  3751. {
  3752. return $this->setColor('draw', $col1, $col2, $col3, $col4, $ret, $name);
  3753. }
  3754. /**
  3755. * 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.
  3756. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3757. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3758. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3759. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  3760. * @param $ret (boolean) If true do not send the command.
  3761. * @param $name (string) Spot color name (if any).
  3762. * @return (string) The PDF command.
  3763. * @public
  3764. * @since 1.3
  3765. * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  3766. */
  3767. public function SetFillColor($col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1, $ret = false, $name = '')
  3768. {
  3769. return $this->setColor('fill', $col1, $col2, $col3, $col4, $ret, $name);
  3770. }
  3771. /**
  3772. * 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.
  3773. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3774. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3775. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3776. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  3777. * @param $ret (boolean) If true do not send the command.
  3778. * @param $name (string) Spot color name (if any).
  3779. * @return (string) Empty string.
  3780. * @public
  3781. * @since 1.3
  3782. * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  3783. */
  3784. public function SetTextColor($col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1, $ret = false, $name = '')
  3785. {
  3786. return $this->setColor('text', $col1, $col2, $col3, $col4, $ret, $name);
  3787. }
  3788. /**
  3789. * Returns the length of a string in user unit. A font must be selected.<br>
  3790. * @param $s (string) The string whose length is to be computed
  3791. * @param $fontname (string) Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
  3792. * @param $fontstyle (string) Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line-through</li><li>O: overline</li></ul> or any combination. The default value is regular.
  3793. * @param $fontsize (float) Font size in points. The default value is the current size.
  3794. * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
  3795. * @return mixed int total string length or array of characted widths
  3796. * @author Nicola Asuni
  3797. * @public
  3798. * @since 1.2
  3799. */
  3800. public function GetStringWidth($s, $fontname = '', $fontstyle = '', $fontsize = 0, $getarray = false)
  3801. {
  3802. 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);
  3803. }
  3804. /**
  3805. * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
  3806. * @param $sa (string) The array of chars whose total length is to be computed
  3807. * @param $fontname (string) Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
  3808. * @param $fontstyle (string) Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line through</li><li>O: overline</li></ul> or any combination. The default value is regular.
  3809. * @param $fontsize (float) Font size in points. The default value is the current size.
  3810. * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
  3811. * @return mixed int total string length or array of characted widths
  3812. * @author Nicola Asuni
  3813. * @public
  3814. * @since 2.4.000 (2008-03-06)
  3815. */
  3816. public function GetArrStringWidth($sa, $fontname = '', $fontstyle = '', $fontsize = 0, $getarray = false)
  3817. {
  3818. // store current values
  3819. if (!TCPDF_STATIC::empty_string($fontname)) {
  3820. $prev_FontFamily = $this->FontFamily;
  3821. $prev_FontStyle = $this->FontStyle;
  3822. $prev_FontSizePt = $this->FontSizePt;
  3823. $this->SetFont($fontname, $fontstyle, $fontsize, '', 'default', false);
  3824. }
  3825. // convert UTF-8 array to Latin1 if required
  3826. if ($this->isunicode AND (!$this->isUnicodeFont())) {
  3827. $sa = TCPDF_FONTS::UTF8ArrToLatin1Arr($sa);
  3828. }
  3829. $w = 0; // total width
  3830. $wa = array(); // array of characters widths
  3831. foreach ($sa as $ck => $char) {
  3832. // character width
  3833. $cw = $this->GetCharWidth($char, isset($sa[($ck + 1)]));
  3834. $wa[] = $cw;
  3835. $w += $cw;
  3836. }
  3837. // restore previous values
  3838. if (!TCPDF_STATIC::empty_string($fontname)) {
  3839. $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt, '', 'default', false);
  3840. }
  3841. if ($getarray) {
  3842. return $wa;
  3843. }
  3844. return $w;
  3845. }
  3846. /**
  3847. * Returns the length of the char in user unit for the current font considering current stretching and spacing (tracking).
  3848. * @param $char (int) The char code whose length is to be returned
  3849. * @param $notlast (boolean) If false ignore the font-spacing.
  3850. * @return float char width
  3851. * @author Nicola Asuni
  3852. * @public
  3853. * @since 2.4.000 (2008-03-06)
  3854. */
  3855. public function GetCharWidth($char, $notlast = true)
  3856. {
  3857. // get raw width
  3858. $chw = $this->getRawCharWidth($char);
  3859. if (($this->font_spacing < 0) OR (($this->font_spacing > 0) AND $notlast)) {
  3860. // increase/decrease font spacing
  3861. $chw += $this->font_spacing;
  3862. }
  3863. if ($this->font_stretching != 100) {
  3864. // fixed stretching mode
  3865. $chw *= ($this->font_stretching / 100);
  3866. }
  3867. return $chw;
  3868. }
  3869. /**
  3870. * Returns the length of the char in user unit for the current font.
  3871. * @param $char (int) The char code whose length is to be returned
  3872. * @return float char width
  3873. * @author Nicola Asuni
  3874. * @public
  3875. * @since 5.9.000 (2010-09-28)
  3876. */
  3877. public function getRawCharWidth($char)
  3878. {
  3879. if ($char == 173) {
  3880. // SHY character will not be printed
  3881. return (0);
  3882. }
  3883. if (isset($this->CurrentFont['cw'][$char])) {
  3884. $w = $this->CurrentFont['cw'][$char];
  3885. } elseif (isset($this->CurrentFont['dw'])) {
  3886. // default width
  3887. $w = $this->CurrentFont['dw'];
  3888. } elseif (isset($this->CurrentFont['cw'][32])) {
  3889. // default width
  3890. $w = $this->CurrentFont['cw'][32];
  3891. } else {
  3892. $w = 600;
  3893. }
  3894. return $this->getAbsFontMeasure($w);
  3895. }
  3896. /**
  3897. * Returns the numbero of characters in a string.
  3898. * @param $s (string) The input string.
  3899. * @return int number of characters
  3900. * @public
  3901. * @since 2.0.0001 (2008-01-07)
  3902. */
  3903. public function GetNumChars($s)
  3904. {
  3905. if ($this->isUnicodeFont()) {
  3906. return count(TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont));
  3907. }
  3908. return strlen($s);
  3909. }
  3910. /**
  3911. * Fill the list of available fonts ($this->fontlist).
  3912. * @protected
  3913. * @since 4.0.013 (2008-07-28)
  3914. */
  3915. protected function getFontsList()
  3916. {
  3917. if (($fontsdir = opendir(TCPDF_FONTS::_getfontpath())) !== false) {
  3918. while (($file = readdir($fontsdir)) !== false) {
  3919. if (substr($file, -4) == '.php') {
  3920. array_push($this->fontlist, strtolower(basename($file, '.php')));
  3921. }
  3922. }
  3923. closedir($fontsdir);
  3924. }
  3925. }
  3926. /**
  3927. * Imports a TrueType, Type1, core, or CID0 font and makes it available.
  3928. * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
  3929. * 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.
  3930. * @param $family (string) Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  3931. * @param $style (string) Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul>
  3932. * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  3933. * @return array containing the font data, or false in case of error.
  3934. * @param $subset (mixed) if true embedd only a subset of the font (stores only the information related to the used characters); if false embedd full font; if 'default' uses the default value set using setFontSubsetting(). This option is valid only for TrueTypeUnicode fonts. If you want to enable users to change the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only part of a font.
  3935. * @public
  3936. * @since 1.5
  3937. * @see SetFont(), setFontSubsetting()
  3938. */
  3939. public function AddFont($family, $style = '', $fontfile = '', $subset = 'default')
  3940. {
  3941. if ($subset === 'default') {
  3942. $subset = $this->font_subsetting;
  3943. }
  3944. if ($this->pdfa_mode) {
  3945. $subset = false;
  3946. }
  3947. if (TCPDF_STATIC::empty_string($family)) {
  3948. if (!TCPDF_STATIC::empty_string($this->FontFamily)) {
  3949. $family = $this->FontFamily;
  3950. } else {
  3951. $this->Error('Empty font family');
  3952. }
  3953. }
  3954. // move embedded styles on $style
  3955. if (substr($family, -1) == 'I') {
  3956. $style .= 'I';
  3957. $family = substr($family, 0, -1);
  3958. }
  3959. if (substr($family, -1) == 'B') {
  3960. $style .= 'B';
  3961. $family = substr($family, 0, -1);
  3962. }
  3963. // normalize family name
  3964. $family = strtolower($family);
  3965. if ((!$this->isunicode) AND ($family == 'arial')) {
  3966. $family = 'helvetica';
  3967. }
  3968. if (($family == 'symbol') OR ($family == 'zapfdingbats')) {
  3969. $style = '';
  3970. }
  3971. if ($this->pdfa_mode AND (isset($this->CoreFonts[$family]))) {
  3972. // all fonts must be embedded
  3973. $family = 'pdfa'.$family;
  3974. }
  3975. $tempstyle = strtoupper($style);
  3976. $style = '';
  3977. // underline
  3978. if (strpos($tempstyle, 'U') !== false) {
  3979. $this->underline = true;
  3980. } else {
  3981. $this->underline = false;
  3982. }
  3983. // line-through (deleted)
  3984. if (strpos($tempstyle, 'D') !== false) {
  3985. $this->linethrough = true;
  3986. } else {
  3987. $this->linethrough = false;
  3988. }
  3989. // overline
  3990. if (strpos($tempstyle, 'O') !== false) {
  3991. $this->overline = true;
  3992. } else {
  3993. $this->overline = false;
  3994. }
  3995. // bold
  3996. if (strpos($tempstyle, 'B') !== false) {
  3997. $style .= 'B';
  3998. }
  3999. // oblique
  4000. if (strpos($tempstyle, 'I') !== false) {
  4001. $style .= 'I';
  4002. }
  4003. $bistyle = $style;
  4004. $fontkey = $family.$style;
  4005. $font_style = $style.($this->underline ? 'U' : '').($this->linethrough ? 'D' : '').($this->overline ? 'O' : '');
  4006. $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style);
  4007. // check if the font has been already added
  4008. $fb = $this->getFontBuffer($fontkey);
  4009. if ($fb !== false) {
  4010. if ($this->inxobj) {
  4011. // we are inside an XObject template
  4012. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $fb['i'];
  4013. }
  4014. return $fontdata;
  4015. }
  4016. // get specified font directory (if any)
  4017. $fontdir = false;
  4018. if (!TCPDF_STATIC::empty_string($fontfile)) {
  4019. $fontdir = dirname($fontfile);
  4020. if (TCPDF_STATIC::empty_string($fontdir) OR ($fontdir == '.')) {
  4021. $fontdir = '';
  4022. } else {
  4023. $fontdir .= '/';
  4024. }
  4025. }
  4026. // true when the font style variation is missing
  4027. $missing_style = false;
  4028. // search and include font file
  4029. if (TCPDF_STATIC::empty_string($fontfile) OR (!@TCPDF_STATIC::file_exists($fontfile))) {
  4030. // build a standard filenames for specified font
  4031. $tmp_fontfile = str_replace(' ', '', $family).strtolower($style).'.php';
  4032. $fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir);
  4033. if (TCPDF_STATIC::empty_string($fontfile)) {
  4034. $missing_style = true;
  4035. // try to remove the style part
  4036. $tmp_fontfile = str_replace(' ', '', $family).'.php';
  4037. $fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir);
  4038. }
  4039. }
  4040. // include font file
  4041. if (!TCPDF_STATIC::empty_string($fontfile) AND (@TCPDF_STATIC::file_exists($fontfile))) {
  4042. include $fontfile;
  4043. } else {
  4044. $this->Error('Could not include font definition file: '.$family.'');
  4045. }
  4046. // check font parameters
  4047. if ((!isset($type)) OR (!isset($cw))) {
  4048. $this->Error('The font definition file has a bad format: '.$fontfile.'');
  4049. }
  4050. // SET default parameters
  4051. if (!isset($file) OR TCPDF_STATIC::empty_string($file)) {
  4052. $file = '';
  4053. }
  4054. if (!isset($enc) OR TCPDF_STATIC::empty_string($enc)) {
  4055. $enc = '';
  4056. }
  4057. if (!isset($cidinfo) OR TCPDF_STATIC::empty_string($cidinfo)) {
  4058. $cidinfo = array('Registry'=>'Adobe', 'Ordering'=>'Identity', 'Supplement'=>0);
  4059. $cidinfo['uni2cid'] = array();
  4060. }
  4061. if (!isset($ctg) OR TCPDF_STATIC::empty_string($ctg)) {
  4062. $ctg = '';
  4063. }
  4064. if (!isset($desc) OR TCPDF_STATIC::empty_string($desc)) {
  4065. $desc = array();
  4066. }
  4067. if (!isset($up) OR TCPDF_STATIC::empty_string($up)) {
  4068. $up = -100;
  4069. }
  4070. if (!isset($ut) OR TCPDF_STATIC::empty_string($ut)) {
  4071. $ut = 50;
  4072. }
  4073. if (!isset($cw) OR TCPDF_STATIC::empty_string($cw)) {
  4074. $cw = array();
  4075. }
  4076. if (!isset($dw) OR TCPDF_STATIC::empty_string($dw)) {
  4077. // set default width
  4078. if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) {
  4079. $dw = $desc['MissingWidth'];
  4080. } elseif (isset($cw[32])) {
  4081. $dw = $cw[32];
  4082. } else {
  4083. $dw = 600;
  4084. }
  4085. }
  4086. ++$this->numfonts;
  4087. if ($type == 'core') {
  4088. $name = $this->CoreFonts[$fontkey];
  4089. $subset = false;
  4090. } elseif (($type == 'TrueType') OR ($type == 'Type1')) {
  4091. $subset = false;
  4092. } elseif ($type == 'TrueTypeUnicode') {
  4093. $enc = 'Identity-H';
  4094. } elseif ($type == 'cidfont0') {
  4095. if ($this->pdfa_mode) {
  4096. $this->Error('All fonts must be embedded in PDF/A mode!');
  4097. }
  4098. } else {
  4099. $this->Error('Unknow font type: '.$type.'');
  4100. }
  4101. // set name if unset
  4102. if (!isset($name) OR empty($name)) {
  4103. $name = $fontkey;
  4104. }
  4105. // create artificial font style variations if missing (only works with non-embedded fonts)
  4106. if (($type != 'core') AND $missing_style) {
  4107. // style variations
  4108. $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic');
  4109. $name .= $styles[$bistyle];
  4110. // artificial bold
  4111. if (strpos($bistyle, 'B') !== false) {
  4112. if (isset($desc['StemV'])) {
  4113. // from normal to bold
  4114. $desc['StemV'] = round($desc['StemV'] * 1.75);
  4115. } else {
  4116. // bold
  4117. $desc['StemV'] = 123;
  4118. }
  4119. }
  4120. // artificial italic
  4121. if (strpos($bistyle, 'I') !== false) {
  4122. if (isset($desc['ItalicAngle'])) {
  4123. $desc['ItalicAngle'] -= 11;
  4124. } else {
  4125. $desc['ItalicAngle'] = -11;
  4126. }
  4127. if (isset($desc['Flags'])) {
  4128. $desc['Flags'] |= 64; //bit 7
  4129. } else {
  4130. $desc['Flags'] = 64;
  4131. }
  4132. }
  4133. }
  4134. // check if the array of characters bounding boxes is defined
  4135. if (!isset($cbbox)) {
  4136. $cbbox = array();
  4137. }
  4138. // initialize subsetchars
  4139. $subsetchars = array_fill(0, 255, true);
  4140. $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));
  4141. if ($this->inxobj) {
  4142. // we are inside an XObject template
  4143. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts;
  4144. }
  4145. if (isset($diff) AND (!empty($diff))) {
  4146. //Search existing encodings
  4147. $d = 0;
  4148. $nb = count($this->diffs);
  4149. for ($i=1; $i <= $nb; ++$i) {
  4150. if ($this->diffs[$i] == $diff) {
  4151. $d = $i;
  4152. break;
  4153. }
  4154. }
  4155. if ($d == 0) {
  4156. $d = $nb + 1;
  4157. $this->diffs[$d] = $diff;
  4158. }
  4159. $this->setFontSubBuffer($fontkey, 'diff', $d);
  4160. }
  4161. if (!TCPDF_STATIC::empty_string($file)) {
  4162. if (!isset($this->FontFiles[$file])) {
  4163. if ((strcasecmp($type, 'TrueType') == 0) OR (strcasecmp($type, 'TrueTypeUnicode') == 0)) {
  4164. $this->FontFiles[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  4165. } elseif ($type != 'core') {
  4166. $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  4167. }
  4168. } else {
  4169. // update fontkeys that are sharing this font file
  4170. $this->FontFiles[$file]['subset'] = ($this->FontFiles[$file]['subset'] AND $subset);
  4171. if (!in_array($fontkey, $this->FontFiles[$file]['fontkeys'])) {
  4172. $this->FontFiles[$file]['fontkeys'][] = $fontkey;
  4173. }
  4174. }
  4175. }
  4176. return $fontdata;
  4177. }
  4178. /**
  4179. * Sets the font used to print character strings.
  4180. * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  4181. * The method can be called before the first page is created and the font is retained from page to page.
  4182. * If you just wish to change the current font size, it is simpler to call SetFontSize().
  4183. * 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 />
  4184. * @param $family (string) Family font. It can be either a name defined by AddFont() or one of the standard Type1 families (case insensitive):<ul><li>times (Times-Roman)</li><li>timesb (Times-Bold)</li><li>timesi (Times-Italic)</li><li>timesbi (Times-BoldItalic)</li><li>helvetica (Helvetica)</li><li>helveticab (Helvetica-Bold)</li><li>helveticai (Helvetica-Oblique)</li><li>helveticabi (Helvetica-BoldOblique)</li><li>courier (Courier)</li><li>courierb (Courier-Bold)</li><li>courieri (Courier-Oblique)</li><li>courierbi (Courier-BoldOblique)</li><li>symbol (Symbol)</li><li>zapfdingbats (ZapfDingbats)</li></ul> It is also possible to pass an empty string. In that case, the current family is retained.
  4185. * @param $style (string) Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line through</li><li>O: overline</li></ul> or any combination. The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats basic fonts or other fonts when not defined.
  4186. * @param $size (float) Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12
  4187. * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  4188. * @param $subset (mixed) if true embedd only a subset of the font (stores only the information related to the used characters); if false embedd full font; if 'default' uses the default value set using setFontSubsetting(). This option is valid only for TrueTypeUnicode fonts. If you want to enable users to change the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only part of a font.
  4189. * @param $out (boolean) if true output the font size command, otherwise only set the font properties.
  4190. * @author Nicola Asuni
  4191. * @public
  4192. * @since 1.0
  4193. * @see AddFont(), SetFontSize()
  4194. */
  4195. public function SetFont($family, $style = '', $size = null, $fontfile = '', $subset = 'default', $out = true)
  4196. {
  4197. //Select a font; size given in points
  4198. if ($size === null) {
  4199. $size = $this->FontSizePt;
  4200. }
  4201. if ($size < 0) {
  4202. $size = 0;
  4203. }
  4204. // try to add font (if not already added)
  4205. $fontdata = $this->AddFont($family, $style, $fontfile, $subset);
  4206. $this->FontFamily = $fontdata['family'];
  4207. $this->FontStyle = $fontdata['style'];
  4208. if (isset($this->CurrentFont['fontkey']) AND isset($this->CurrentFont['subsetchars'])) {
  4209. // save subset chars of the previous font
  4210. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  4211. }
  4212. $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
  4213. $this->SetFontSize($size, $out);
  4214. }
  4215. /**
  4216. * Defines the size of the current font.
  4217. * @param $size (float) The font size in points.
  4218. * @param $out (boolean) if true output the font size command, otherwise only set the font properties.
  4219. * @public
  4220. * @since 1.0
  4221. * @see SetFont()
  4222. */
  4223. public function SetFontSize($size, $out = true)
  4224. {
  4225. $size = (float) $size;
  4226. // font size in points
  4227. $this->FontSizePt = $size;
  4228. // font size in user units
  4229. $this->FontSize = $size / $this->k;
  4230. // calculate some font metrics
  4231. if (isset($this->CurrentFont['desc']['FontBBox'])) {
  4232. $bbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  4233. $font_height = ((intval($bbox[3]) - intval($bbox[1])) * $size / 1000);
  4234. } else {
  4235. $font_height = $size * 1.219;
  4236. }
  4237. if (isset($this->CurrentFont['desc']['Ascent']) AND ($this->CurrentFont['desc']['Ascent'] > 0)) {
  4238. $font_ascent = ($this->CurrentFont['desc']['Ascent'] * $size / 1000);
  4239. }
  4240. if (isset($this->CurrentFont['desc']['Descent']) AND ($this->CurrentFont['desc']['Descent'] <= 0)) {
  4241. $font_descent = (- $this->CurrentFont['desc']['Descent'] * $size / 1000);
  4242. }
  4243. if (!isset($font_ascent) AND !isset($font_descent)) {
  4244. // core font
  4245. $font_ascent = 0.76 * $font_height;
  4246. $font_descent = $font_height - $font_ascent;
  4247. } elseif (!isset($font_descent)) {
  4248. $font_descent = $font_height - $font_ascent;
  4249. } elseif (!isset($font_ascent)) {
  4250. $font_ascent = $font_height - $font_descent;
  4251. }
  4252. $this->FontAscent = ($font_ascent / $this->k);
  4253. $this->FontDescent = ($font_descent / $this->k);
  4254. if ($out AND ($this->page > 0) AND (isset($this->CurrentFont['i'])) AND ($this->state == 2)) {
  4255. $this->_out(sprintf('BT /F%d %F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  4256. }
  4257. }
  4258. /**
  4259. * Returns the bounding box of the current font in user units.
  4260. * @return array
  4261. * @public
  4262. * @since 5.9.152 (2012-03-23)
  4263. */
  4264. public function getFontBBox()
  4265. {
  4266. $fbbox = array();
  4267. if (isset($this->CurrentFont['desc']['FontBBox'])) {
  4268. $tmpbbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  4269. $fbbox = array_map(array($this,'getAbsFontMeasure'), $tmpbbox);
  4270. } else {
  4271. // Find max width
  4272. if (isset($this->CurrentFont['desc']['MaxWidth'])) {
  4273. $maxw = $this->getAbsFontMeasure(intval($this->CurrentFont['desc']['MaxWidth']));
  4274. } else {
  4275. $maxw = 0;
  4276. if (isset($this->CurrentFont['desc']['MissingWidth'])) {
  4277. $maxw = max($maxw, $this->CurrentFont['desc']['MissingWidth']);
  4278. }
  4279. if (isset($this->CurrentFont['desc']['AvgWidth'])) {
  4280. $maxw = max($maxw, $this->CurrentFont['desc']['AvgWidth']);
  4281. }
  4282. if (isset($this->CurrentFont['dw'])) {
  4283. $maxw = max($maxw, $this->CurrentFont['dw']);
  4284. }
  4285. foreach ($this->CurrentFont['cw'] as $char => $w) {
  4286. $maxw = max($maxw, $w);
  4287. }
  4288. if ($maxw == 0) {
  4289. $maxw = 600;
  4290. }
  4291. $maxw = $this->getAbsFontMeasure($maxw);
  4292. }
  4293. $fbbox = array(0, (0 - $this->FontDescent), $maxw, $this->FontAscent);
  4294. }
  4295. return $fbbox;
  4296. }
  4297. /**
  4298. * Convert a relative font measure into absolute value.
  4299. * @param $s (int) Font measure.
  4300. * @return float Absolute measure.
  4301. * @since 5.9.186 (2012-09-13)
  4302. */
  4303. public function getAbsFontMeasure($s)
  4304. {
  4305. return ($s * $this->FontSize / 1000);
  4306. }
  4307. /**
  4308. * Returns the glyph bounding box of the specified character in the current font in user units.
  4309. * @param $char (int) Input character code.
  4310. * @return mixed array(xMin, yMin, xMax, yMax) or FALSE if not defined.
  4311. * @since 5.9.186 (2012-09-13)
  4312. */
  4313. public function getCharBBox($char)
  4314. {
  4315. $c = intval($char);
  4316. if (isset($this->CurrentFont['cw'][$c])) {
  4317. // glyph is defined ... use zero width & height for glyphs without outlines
  4318. $result = array(0,0,0,0);
  4319. if (isset($this->CurrentFont['cbbox'][$c])) {
  4320. $result = $this->CurrentFont['cbbox'][$c];
  4321. }
  4322. return array_map(array($this,'getAbsFontMeasure'), $result);
  4323. }
  4324. return false;
  4325. }
  4326. /**
  4327. * Return the font descent value
  4328. * @param $font (string) font name
  4329. * @param $style (string) font style
  4330. * @param $size (float) The size (in points)
  4331. * @return int font descent
  4332. * @public
  4333. * @author Nicola Asuni
  4334. * @since 4.9.003 (2010-03-30)
  4335. */
  4336. public function getFontDescent($font, $style = '', $size = 0)
  4337. {
  4338. $fontdata = $this->AddFont($font, $style);
  4339. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4340. if (isset($fontinfo['desc']['Descent']) AND ($fontinfo['desc']['Descent'] <= 0)) {
  4341. $descent = (- $fontinfo['desc']['Descent'] * $size / 1000);
  4342. } else {
  4343. $descent = (1.219 * 0.24 * $size);
  4344. }
  4345. return ($descent / $this->k);
  4346. }
  4347. /**
  4348. * Return the font ascent value.
  4349. * @param $font (string) font name
  4350. * @param $style (string) font style
  4351. * @param $size (float) The size (in points)
  4352. * @return int font ascent
  4353. * @public
  4354. * @author Nicola Asuni
  4355. * @since 4.9.003 (2010-03-30)
  4356. */
  4357. public function getFontAscent($font, $style = '', $size = 0)
  4358. {
  4359. $fontdata = $this->AddFont($font, $style);
  4360. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4361. if (isset($fontinfo['desc']['Ascent']) AND ($fontinfo['desc']['Ascent'] > 0)) {
  4362. $ascent = ($fontinfo['desc']['Ascent'] * $size / 1000);
  4363. } else {
  4364. $ascent = 1.219 * 0.76 * $size;
  4365. }
  4366. return ($ascent / $this->k);
  4367. }
  4368. /**
  4369. * Return true in the character is present in the specified font.
  4370. * @param $char (mixed) Character to check (integer value or string)
  4371. * @param $font (string) Font name (family name).
  4372. * @param $style (string) Font style.
  4373. * @return (boolean) true if the char is defined, false otherwise.
  4374. * @public
  4375. * @since 5.9.153 (2012-03-28)
  4376. */
  4377. public function isCharDefined($char, $font = '', $style = '')
  4378. {
  4379. if (is_string($char)) {
  4380. // get character code
  4381. $char = TCPDF_FONTS::UTF8StringToArray($char, $this->isunicode, $this->CurrentFont);
  4382. $char = $char[0];
  4383. }
  4384. if (TCPDF_STATIC::empty_string($font)) {
  4385. if (TCPDF_STATIC::empty_string($style)) {
  4386. return (isset($this->CurrentFont['cw'][intval($char)]));
  4387. }
  4388. $font = $this->FontFamily;
  4389. }
  4390. $fontdata = $this->AddFont($font, $style);
  4391. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4392. return (isset($fontinfo['cw'][intval($char)]));
  4393. }
  4394. /**
  4395. * Replace missing font characters on selected font with specified substitutions.
  4396. * @param $text (string) Text to process.
  4397. * @param $font (string) Font name (family name).
  4398. * @param $style (string) Font style.
  4399. * @param $subs (array) Array of possible character substitutions. The key is the character to check (integer value) and the value is a single intege value or an array of possible substitutes.
  4400. * @return (string) Processed text.
  4401. * @public
  4402. * @since 5.9.153 (2012-03-28)
  4403. */
  4404. public function replaceMissingChars($text, $font = '', $style = '', $subs = array())
  4405. {
  4406. if (empty($subs)) {
  4407. return $text;
  4408. }
  4409. if (TCPDF_STATIC::empty_string($font)) {
  4410. $font = $this->FontFamily;
  4411. }
  4412. $fontdata = $this->AddFont($font, $style);
  4413. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4414. $uniarr = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont);
  4415. foreach ($uniarr as $k => $chr) {
  4416. if (!isset($fontinfo['cw'][$chr])) {
  4417. // this character is missing on the selected font
  4418. if (isset($subs[$chr])) {
  4419. // we have available substitutions
  4420. if (is_array($subs[$chr])) {
  4421. foreach ($subs[$chr] as $s) {
  4422. if (isset($fontinfo['cw'][$s])) {
  4423. $uniarr[$k] = $s;
  4424. break;
  4425. }
  4426. }
  4427. } elseif (isset($fontinfo['cw'][$subs[$chr]])) {
  4428. $uniarr[$k] = $subs[$chr];
  4429. }
  4430. }
  4431. }
  4432. }
  4433. return TCPDF_FONTS::UniArrSubString(TCPDF_FONTS::UTF8ArrayToUniArray($uniarr, $this->isunicode));
  4434. }
  4435. /**
  4436. * Defines the default monospaced font.
  4437. * @param $font (string) Font name.
  4438. * @public
  4439. * @since 4.5.025
  4440. */
  4441. public function SetDefaultMonospacedFont($font)
  4442. {
  4443. $this->default_monospaced_font = $font;
  4444. }
  4445. /**
  4446. * 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 />
  4447. * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  4448. * @public
  4449. * @since 1.5
  4450. * @see Cell(), Write(), Image(), Link(), SetLink()
  4451. */
  4452. public function AddLink()
  4453. {
  4454. // create a new internal link
  4455. $n = count($this->links) + 1;
  4456. $this->links[$n] = array('p' => 0, 'y' => 0, 'f' => false);
  4457. return $n;
  4458. }
  4459. /**
  4460. * Defines the page and position a link points to.
  4461. * @param $link (int) The link identifier returned by AddLink()
  4462. * @param $y (float) Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  4463. * @param $page (int) Number of target page; -1 indicates the current page (default value). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages.
  4464. * @public
  4465. * @since 1.5
  4466. * @see AddLink()
  4467. */
  4468. public function SetLink($link, $y = 0, $page = -1)
  4469. {
  4470. $fixed = false;
  4471. if (!empty($page) AND ($page[0] == '*')) {
  4472. $page = intval(substr($page, 1));
  4473. // this page number will not be changed when moving/add/deleting pages
  4474. $fixed = true;
  4475. }
  4476. if ($page < 0) {
  4477. $page = $this->page;
  4478. }
  4479. if ($y == -1) {
  4480. $y = $this->y;
  4481. }
  4482. $this->links[$link] = array('p' => $page, 'y' => $y, 'f' => $fixed);
  4483. }
  4484. /**
  4485. * Puts a link on a rectangular area of the page.
  4486. * 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.
  4487. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  4488. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  4489. * @param $w (float) Width of the rectangle
  4490. * @param $h (float) Height of the rectangle
  4491. * @param $link (mixed) URL or identifier returned by AddLink()
  4492. * @param $spaces (int) number of spaces on the text to link
  4493. * @public
  4494. * @since 1.5
  4495. * @see AddLink(), Annotation(), Cell(), Write(), Image()
  4496. */
  4497. public function Link($x, $y, $w, $h, $link, $spaces = 0)
  4498. {
  4499. $this->Annotation($x, $y, $w, $h, $link, array('Subtype'=>'Link'), $spaces);
  4500. }
  4501. /**
  4502. * Puts a markup annotation on a rectangular area of the page.
  4503. * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
  4504. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  4505. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  4506. * @param $w (float) Width of the rectangle
  4507. * @param $h (float) Height of the rectangle
  4508. * @param $text (string) annotation text or alternate content
  4509. * @param $opt (array) array of options (see section 8.4 of PDF reference 1.7).
  4510. * @param $spaces (int) number of spaces on the text to link
  4511. * @public
  4512. * @since 4.0.018 (2008-08-06)
  4513. */
  4514. public function Annotation($x, $y, $w, $h, $text, $opt = array('Subtype'=>'Text'), $spaces = 0)
  4515. {
  4516. if ($this->inxobj) {
  4517. // store parameters for later use on template
  4518. $this->xobjects[$this->xobjid]['annotations'][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'text' => $text, 'opt' => $opt, 'spaces' => $spaces);
  4519. return;
  4520. }
  4521. if ($x === '') {
  4522. $x = $this->x;
  4523. }
  4524. if ($y === '') {
  4525. $y = $this->y;
  4526. }
  4527. // check page for no-write regions and adapt page margins if necessary
  4528. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  4529. // recalculate coordinates to account for graphic transformations
  4530. if (isset($this->transfmatrix) AND !empty($this->transfmatrix)) {
  4531. for ($i=$this->transfmatrix_key; $i > 0; --$i) {
  4532. $maxid = count($this->transfmatrix[$i]) - 1;
  4533. for ($j=$maxid; $j >= 0; --$j) {
  4534. $ctm = $this->transfmatrix[$i][$j];
  4535. if (isset($ctm['a'])) {
  4536. $x = $x * $this->k;
  4537. $y = ($this->h - $y) * $this->k;
  4538. $w = $w * $this->k;
  4539. $h = $h * $this->k;
  4540. // top left
  4541. $xt = $x;
  4542. $yt = $y;
  4543. $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4544. $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4545. // top right
  4546. $xt = $x + $w;
  4547. $yt = $y;
  4548. $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4549. $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4550. // bottom left
  4551. $xt = $x;
  4552. $yt = $y - $h;
  4553. $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4554. $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4555. // bottom right
  4556. $xt = $x + $w;
  4557. $yt = $y - $h;
  4558. $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4559. $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4560. // new coordinates (rectangle area)
  4561. $x = min($x1, $x2, $x3, $x4);
  4562. $y = max($y1, $y2, $y3, $y4);
  4563. $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k;
  4564. $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k;
  4565. $x = $x / $this->k;
  4566. $y = $this->h - ($y / $this->k);
  4567. }
  4568. }
  4569. }
  4570. }
  4571. if ($this->page <= 0) {
  4572. $page = 1;
  4573. } else {
  4574. $page = $this->page;
  4575. }
  4576. if (!isset($this->PageAnnots[$page])) {
  4577. $this->PageAnnots[$page] = array();
  4578. }
  4579. $this->PageAnnots[$page][] = array('n' => ++$this->n, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces);
  4580. if (!$this->pdfa_mode || ($this->pdfa_mode && $this->pdfa_version == 3)) {
  4581. if ((($opt['Subtype'] == 'FileAttachment') OR ($opt['Subtype'] == 'Sound')) AND (!TCPDF_STATIC::empty_string($opt['FS']))
  4582. AND (@TCPDF_STATIC::file_exists($opt['FS']) OR TCPDF_STATIC::isValidURL($opt['FS']))
  4583. AND (!isset($this->embeddedfiles[basename($opt['FS'])]))) {
  4584. $this->embeddedfiles[basename($opt['FS'])] = array('f' => ++$this->n, 'n' => ++$this->n, 'file' => $opt['FS']);
  4585. }
  4586. }
  4587. // Add widgets annotation's icons
  4588. if (isset($opt['mk']['i']) AND @TCPDF_STATIC::file_exists($opt['mk']['i'])) {
  4589. $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
  4590. }
  4591. if (isset($opt['mk']['ri']) AND @TCPDF_STATIC::file_exists($opt['mk']['ri'])) {
  4592. $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  4593. }
  4594. if (isset($opt['mk']['ix']) AND @TCPDF_STATIC::file_exists($opt['mk']['ix'])) {
  4595. $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  4596. }
  4597. }
  4598. /**
  4599. * Embedd the attached files.
  4600. * @since 4.4.000 (2008-12-07)
  4601. * @protected
  4602. * @see Annotation()
  4603. */
  4604. protected function _putEmbeddedFiles()
  4605. {
  4606. if ($this->pdfa_mode && $this->pdfa_version != 3) {
  4607. // embedded files are not allowed in PDF/A mode version 1 and 2
  4608. return;
  4609. }
  4610. reset($this->embeddedfiles);
  4611. foreach ($this->embeddedfiles as $filename => $filedata) {
  4612. $data = TCPDF_STATIC::fileGetContents($filedata['file']);
  4613. if ($data !== false) {
  4614. $rawsize = strlen($data);
  4615. if ($rawsize > 0) {
  4616. // update name tree
  4617. $this->efnames[$filename] = $filedata['f'].' 0 R';
  4618. // embedded file specification object
  4619. $out = $this->_getobj($filedata['f'])."\n";
  4620. $out .= '<</Type /Filespec /F '.$this->_datastring($filename, $filedata['f']);
  4621. $out .= ' /UF '.$this->_datastring($filename, $filedata['f']);
  4622. $out .= ' /AFRelationship /Source';
  4623. $out .= ' /EF <</F '.$filedata['n'].' 0 R>> >>';
  4624. $out .= "\n".'endobj';
  4625. $this->_out($out);
  4626. // embedded file object
  4627. $filter = '';
  4628. if ($this->compress) {
  4629. $data = gzcompress($data);
  4630. $filter = ' /Filter /FlateDecode';
  4631. }
  4632. if ($this->pdfa_version == 3) {
  4633. $filter = ' /Subtype /text#2Fxml';
  4634. }
  4635. $stream = $this->_getrawstream($data, $filedata['n']);
  4636. $out = $this->_getobj($filedata['n'])."\n";
  4637. $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' /Params <</Size '.$rawsize.'>> >>';
  4638. $out .= ' stream'."\n".$stream."\n".'endstream';
  4639. $out .= "\n".'endobj';
  4640. $this->_out($out);
  4641. }
  4642. }
  4643. }
  4644. }
  4645. /**
  4646. * Prints a text cell at the specified position.
  4647. * This method allows to place a string precisely on the page.
  4648. * @param $x (float) Abscissa of the cell origin
  4649. * @param $y (float) Ordinate of the cell origin
  4650. * @param $txt (string) String to print
  4651. * @param $fstroke (int) outline size in user units (false = disable)
  4652. * @param $fclip (boolean) if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
  4653. * @param $ffill (boolean) if true fills the text
  4654. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  4655. * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  4656. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  4657. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  4658. * @param $link (mixed) URL or identifier returned by AddLink().
  4659. * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  4660. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  4661. * @param $calign (string) cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li><li>B : cell bottom</li></ul>
  4662. * @param $valign (string) text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>C : center</li><li>B : bottom</li></ul>
  4663. * @param $rtloff (boolean) if true uses the page top-left corner as origin of axis for $x and $y initial position.
  4664. * @public
  4665. * @since 1.0
  4666. * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
  4667. */
  4668. public function Text($x, $y, $txt, $fstroke = false, $fclip = false, $ffill = true, $border = 0, $ln = 0, $align = '', $fill = false, $link = '', $stretch = 0, $ignore_min_height = false, $calign = 'T', $valign = 'M', $rtloff = false)
  4669. {
  4670. $textrendermode = $this->textrendermode;
  4671. $textstrokewidth = $this->textstrokewidth;
  4672. $this->setTextRenderingMode($fstroke, $ffill, $fclip);
  4673. $this->SetXY($x, $y, $rtloff);
  4674. $this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
  4675. // restore previous rendering mode
  4676. $this->textrendermode = $textrendermode;
  4677. $this->textstrokewidth = $textstrokewidth;
  4678. }
  4679. /**
  4680. * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
  4681. * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  4682. * This method is called automatically and should not be called directly by the application.
  4683. * @return boolean
  4684. * @public
  4685. * @since 1.4
  4686. * @see SetAutoPageBreak()
  4687. */
  4688. public function AcceptPageBreak()
  4689. {
  4690. if ($this->num_columns > 1) {
  4691. // multi column mode
  4692. if ($this->current_column < ($this->num_columns - 1)) {
  4693. // go to next column
  4694. $this->selectColumn($this->current_column + 1);
  4695. } elseif ($this->AutoPageBreak) {
  4696. // add a new page
  4697. $this->AddPage();
  4698. // set first column
  4699. $this->selectColumn(0);
  4700. }
  4701. // avoid page breaking from checkPageBreak()
  4702. return false;
  4703. }
  4704. return $this->AutoPageBreak;
  4705. }
  4706. /**
  4707. * Add page if needed.
  4708. * @param $h (float) Cell height. Default value: 0.
  4709. * @param $y (mixed) starting y position, leave empty for current position.
  4710. * @param $addpage (boolean) if true add a page, otherwise only return the true/false state
  4711. * @return boolean true in case of page break, false otherwise.
  4712. * @since 3.2.000 (2008-07-01)
  4713. * @protected
  4714. */
  4715. protected function checkPageBreak($h = 0, $y = '', $addpage = true)
  4716. {
  4717. if (TCPDF_STATIC::empty_string($y)) {
  4718. $y = $this->y;
  4719. }
  4720. $current_page = $this->page;
  4721. if ((($y + $h) > $this->PageBreakTrigger) AND ($this->inPageBody()) AND ($this->AcceptPageBreak())) {
  4722. if ($addpage) {
  4723. //Automatic page break
  4724. $x = $this->x;
  4725. $this->AddPage($this->CurOrientation);
  4726. $this->y = $this->tMargin;
  4727. $oldpage = $this->page - 1;
  4728. if ($this->rtl) {
  4729. if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm']) {
  4730. $this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']);
  4731. } else {
  4732. $this->x = $x;
  4733. }
  4734. } else {
  4735. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  4736. $this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']);
  4737. } else {
  4738. $this->x = $x;
  4739. }
  4740. }
  4741. }
  4742. return true;
  4743. }
  4744. if ($current_page != $this->page) {
  4745. // account for columns mode
  4746. return true;
  4747. }
  4748. return false;
  4749. }
  4750. /**
  4751. * 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 />
  4752. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  4753. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  4754. * @param $h (float) Cell height. Default value: 0.
  4755. * @param $txt (string) String to print. Default value: empty string.
  4756. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  4757. * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul> Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  4758. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  4759. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  4760. * @param $link (mixed) URL or identifier returned by AddLink().
  4761. * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  4762. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  4763. * @param $calign (string) cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>C : center</li><li>B : cell bottom</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li></ul>
  4764. * @param $valign (string) text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>C : center</li><li>B : bottom</li></ul>
  4765. * @public
  4766. * @since 1.0
  4767. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  4768. */
  4769. 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')
  4770. {
  4771. $prev_cell_margin = $this->cell_margin;
  4772. $prev_cell_padding = $this->cell_padding;
  4773. $this->adjustCellPadding($border);
  4774. if (!$ignore_min_height) {
  4775. $min_cell_height = $this->getCellHeight($this->FontSize);
  4776. if ($h < $min_cell_height) {
  4777. $h = $min_cell_height;
  4778. }
  4779. }
  4780. $this->checkPageBreak($h + $this->cell_margin['T'] + $this->cell_margin['B']);
  4781. // apply text shadow if enabled
  4782. if ($this->txtshadow['enabled']) {
  4783. // save data
  4784. $x = $this->x;
  4785. $y = $this->y;
  4786. $bc = $this->bgcolor;
  4787. $fc = $this->fgcolor;
  4788. $sc = $this->strokecolor;
  4789. $alpha = $this->alpha;
  4790. // print shadow
  4791. $this->x += $this->txtshadow['depth_w'];
  4792. $this->y += $this->txtshadow['depth_h'];
  4793. $this->SetFillColorArray($this->txtshadow['color']);
  4794. $this->SetTextColorArray($this->txtshadow['color']);
  4795. $this->SetDrawColorArray($this->txtshadow['color']);
  4796. if ($this->txtshadow['opacity'] != $alpha['CA']) {
  4797. $this->setAlpha($this->txtshadow['opacity'], $this->txtshadow['blend_mode']);
  4798. }
  4799. if ($this->state == 2) {
  4800. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  4801. }
  4802. //restore data
  4803. $this->x = $x;
  4804. $this->y = $y;
  4805. $this->SetFillColorArray($bc);
  4806. $this->SetTextColorArray($fc);
  4807. $this->SetDrawColorArray($sc);
  4808. if ($this->txtshadow['opacity'] != $alpha['CA']) {
  4809. $this->setAlpha($alpha['CA'], $alpha['BM'], $alpha['ca'], $alpha['AIS']);
  4810. }
  4811. }
  4812. if ($this->state == 2) {
  4813. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  4814. }
  4815. $this->cell_padding = $prev_cell_padding;
  4816. $this->cell_margin = $prev_cell_margin;
  4817. }
  4818. /**
  4819. * 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 />
  4820. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  4821. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  4822. * @param $h (float) Cell height. Default value: 0.
  4823. * @param $txt (string) String to print. Default value: empty string.
  4824. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  4825. * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  4826. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  4827. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  4828. * @param $link (mixed) URL or identifier returned by AddLink().
  4829. * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  4830. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  4831. * @param $calign (string) cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>C : center</li><li>B : cell bottom</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li></ul>
  4832. * @param $valign (string) text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>M : middle</li><li>B : bottom</li></ul>
  4833. * @return string containing cell code
  4834. * @protected
  4835. * @since 1.0
  4836. * @see Cell()
  4837. */
  4838. 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')
  4839. {
  4840. // replace 'NO-BREAK SPACE' (U+00A0) character with a simple space
  4841. $txt = str_replace(TCPDF_FONTS::unichr(160, $this->isunicode), ' ', $txt);
  4842. $prev_cell_margin = $this->cell_margin;
  4843. $prev_cell_padding = $this->cell_padding;
  4844. $txt = TCPDF_STATIC::removeSHY($txt, $this->isunicode);
  4845. $rs = ''; //string to be returned
  4846. $this->adjustCellPadding($border);
  4847. if (!$ignore_min_height) {
  4848. $min_cell_height = $this->getCellHeight($this->FontSize);
  4849. if ($h < $min_cell_height) {
  4850. $h = $min_cell_height;
  4851. }
  4852. }
  4853. $k = $this->k;
  4854. // check page for no-write regions and adapt page margins if necessary
  4855. list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
  4856. if ($this->rtl) {
  4857. $x = $this->x - $this->cell_margin['R'];
  4858. } else {
  4859. $x = $this->x + $this->cell_margin['L'];
  4860. }
  4861. $y = $this->y + $this->cell_margin['T'];
  4862. $prev_font_stretching = $this->font_stretching;
  4863. $prev_font_spacing = $this->font_spacing;
  4864. // cell vertical alignment
  4865. switch ($calign) {
  4866. case 'A': {
  4867. // font top
  4868. switch ($valign) {
  4869. case 'T': {
  4870. // top
  4871. $y -= $this->cell_padding['T'];
  4872. break;
  4873. }
  4874. case 'B': {
  4875. // bottom
  4876. $y -= ($h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent);
  4877. break;
  4878. }
  4879. default:
  4880. case 'C':
  4881. case 'M': {
  4882. // center
  4883. $y -= (($h - $this->FontAscent - $this->FontDescent) / 2);
  4884. break;
  4885. }
  4886. }
  4887. break;
  4888. }
  4889. case 'L': {
  4890. // font baseline
  4891. switch ($valign) {
  4892. case 'T': {
  4893. // top
  4894. $y -= ($this->cell_padding['T'] + $this->FontAscent);
  4895. break;
  4896. }
  4897. case 'B': {
  4898. // bottom
  4899. $y -= ($h - $this->cell_padding['B'] - $this->FontDescent);
  4900. break;
  4901. }
  4902. default:
  4903. case 'C':
  4904. case 'M': {
  4905. // center
  4906. $y -= (($h + $this->FontAscent - $this->FontDescent) / 2);
  4907. break;
  4908. }
  4909. }
  4910. break;
  4911. }
  4912. case 'D': {
  4913. // font bottom
  4914. switch ($valign) {
  4915. case 'T': {
  4916. // top
  4917. $y -= ($this->cell_padding['T'] + $this->FontAscent + $this->FontDescent);
  4918. break;
  4919. }
  4920. case 'B': {
  4921. // bottom
  4922. $y -= ($h - $this->cell_padding['B']);
  4923. break;
  4924. }
  4925. default:
  4926. case 'C':
  4927. case 'M': {
  4928. // center
  4929. $y -= (($h + $this->FontAscent + $this->FontDescent) / 2);
  4930. break;
  4931. }
  4932. }
  4933. break;
  4934. }
  4935. case 'B': {
  4936. // cell bottom
  4937. $y -= $h;
  4938. break;
  4939. }
  4940. case 'C':
  4941. case 'M': {
  4942. // cell center
  4943. $y -= ($h / 2);
  4944. break;
  4945. }
  4946. default:
  4947. case 'T': {
  4948. // cell top
  4949. break;
  4950. }
  4951. }
  4952. // text vertical alignment
  4953. switch ($valign) {
  4954. case 'T': {
  4955. // top
  4956. $yt = $y + $this->cell_padding['T'];
  4957. break;
  4958. }
  4959. case 'B': {
  4960. // bottom
  4961. $yt = $y + $h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent;
  4962. break;
  4963. }
  4964. default:
  4965. case 'C':
  4966. case 'M': {
  4967. // center
  4968. $yt = $y + (($h - $this->FontAscent - $this->FontDescent) / 2);
  4969. break;
  4970. }
  4971. }
  4972. $basefonty = $yt + $this->FontAscent;
  4973. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  4974. if ($this->rtl) {
  4975. $w = $x - $this->lMargin;
  4976. } else {
  4977. $w = $this->w - $this->rMargin - $x;
  4978. }
  4979. }
  4980. $s = '';
  4981. // fill and borders
  4982. if (is_string($border) AND (strlen($border) == 4)) {
  4983. // full border
  4984. $border = 1;
  4985. }
  4986. if ($fill OR ($border == 1)) {
  4987. if ($fill) {
  4988. $op = ($border == 1) ? 'B' : 'f';
  4989. } else {
  4990. $op = 'S';
  4991. }
  4992. if ($this->rtl) {
  4993. $xk = (($x - $w) * $k);
  4994. } else {
  4995. $xk = ($x * $k);
  4996. }
  4997. $s .= sprintf('%F %F %F %F re %s ', $xk, (($this->h - $y) * $k), ($w * $k), (-$h * $k), $op);
  4998. }
  4999. // draw borders
  5000. $s .= $this->getCellBorder($x, $y, $w, $h, $border);
  5001. if ($txt != '') {
  5002. $txt2 = $txt;
  5003. if ($this->isunicode) {
  5004. if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
  5005. $txt2 = TCPDF_FONTS::UTF8ToLatin1($txt2, $this->isunicode, $this->CurrentFont);
  5006. } else {
  5007. $unicode = TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont); // array of UTF-8 unicode values
  5008. $unicode = TCPDF_FONTS::utf8Bidi($unicode, '', $this->tmprtl, $this->isunicode, $this->CurrentFont);
  5009. // replace thai chars (if any)
  5010. if (defined('K_THAI_TOPCHARS') AND (K_THAI_TOPCHARS == true)) {
  5011. // number of chars
  5012. $numchars = count($unicode);
  5013. // po pla, for far, for fan
  5014. $longtail = array(0x0e1b, 0x0e1d, 0x0e1f);
  5015. // do chada, to patak
  5016. $lowtail = array(0x0e0e, 0x0e0f);
  5017. // mai hun arkad, sara i, sara ii, sara ue, sara uee
  5018. $upvowel = array(0x0e31, 0x0e34, 0x0e35, 0x0e36, 0x0e37);
  5019. // mai ek, mai tho, mai tri, mai chattawa, karan
  5020. $tonemark = array(0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c);
  5021. // sara u, sara uu, pinthu
  5022. $lowvowel = array(0x0e38, 0x0e39, 0x0e3a);
  5023. $output = array();
  5024. for ($i = 0; $i < $numchars; $i++) {
  5025. if (($unicode[$i] >= 0x0e00) && ($unicode[$i] <= 0x0e5b)) {
  5026. $ch0 = $unicode[$i];
  5027. $ch1 = ($i > 0) ? $unicode[($i - 1)] : 0;
  5028. $ch2 = ($i > 1) ? $unicode[($i - 2)] : 0;
  5029. $chn = ($i < ($numchars - 1)) ? $unicode[($i + 1)] : 0;
  5030. if (in_array($ch0, $tonemark)) {
  5031. if ($chn == 0x0e33) {
  5032. // sara um
  5033. if (in_array($ch1, $longtail)) {
  5034. // tonemark at upper left
  5035. $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
  5036. } else {
  5037. // tonemark at upper right (normal position)
  5038. $output[] = $ch0;
  5039. }
  5040. } elseif (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $lowvowel))) {
  5041. // tonemark at lower left
  5042. $output[] = $this->replaceChar($ch0, (0xf705 + $ch0 - 0x0e48));
  5043. } elseif (in_array($ch1, $upvowel)) {
  5044. if (in_array($ch2, $longtail)) {
  5045. // tonemark at upper left
  5046. $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
  5047. } else {
  5048. // tonemark at upper right (normal position)
  5049. $output[] = $ch0;
  5050. }
  5051. } else {
  5052. // tonemark at lower right
  5053. $output[] = $this->replaceChar($ch0, (0xf70a + $ch0 - 0x0e48));
  5054. }
  5055. } elseif (($ch0 == 0x0e33) AND (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $tonemark)))) {
  5056. // add lower left nikhahit and sara aa
  5057. if ($this->isCharDefined(0xf711) AND $this->isCharDefined(0x0e32)) {
  5058. $output[] = 0xf711;
  5059. $this->CurrentFont['subsetchars'][0xf711] = true;
  5060. $output[] = 0x0e32;
  5061. $this->CurrentFont['subsetchars'][0x0e32] = true;
  5062. } else {
  5063. $output[] = $ch0;
  5064. }
  5065. } elseif (in_array($ch1, $longtail)) {
  5066. if ($ch0 == 0x0e31) {
  5067. // lower left mai hun arkad
  5068. $output[] = $this->replaceChar($ch0, 0xf710);
  5069. } elseif (in_array($ch0, $upvowel)) {
  5070. // lower left
  5071. $output[] = $this->replaceChar($ch0, (0xf701 + $ch0 - 0x0e34));
  5072. } elseif ($ch0 == 0x0e47) {
  5073. // lower left mai tai koo
  5074. $output[] = $this->replaceChar($ch0, 0xf712);
  5075. } else {
  5076. // normal character
  5077. $output[] = $ch0;
  5078. }
  5079. } elseif (in_array($ch1, $lowtail) AND in_array($ch0, $lowvowel)) {
  5080. // lower vowel
  5081. $output[] = $this->replaceChar($ch0, (0xf718 + $ch0 - 0x0e38));
  5082. } elseif (($ch0 == 0x0e0d) AND in_array($chn, $lowvowel)) {
  5083. // yo ying without lower part
  5084. $output[] = $this->replaceChar($ch0, 0xf70f);
  5085. } elseif (($ch0 == 0x0e10) AND in_array($chn, $lowvowel)) {
  5086. // tho santan without lower part
  5087. $output[] = $this->replaceChar($ch0, 0xf700);
  5088. } else {
  5089. $output[] = $ch0;
  5090. }
  5091. } else {
  5092. // non-thai character
  5093. $output[] = $unicode[$i];
  5094. }
  5095. }
  5096. $unicode = $output;
  5097. // update font subsetchars
  5098. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  5099. } // end of K_THAI_TOPCHARS
  5100. $txt2 = TCPDF_FONTS::arrUTF8ToUTF16BE($unicode, false);
  5101. }
  5102. }
  5103. $txt2 = TCPDF_STATIC::_escape($txt2);
  5104. // get current text width (considering general font stretching and spacing)
  5105. $txwidth = $this->GetStringWidth($txt);
  5106. $width = $txwidth;
  5107. // check for stretch mode
  5108. if ($stretch > 0) {
  5109. // calculate ratio between cell width and text width
  5110. if ($width <= 0) {
  5111. $ratio = 1;
  5112. } else {
  5113. $ratio = (($w - $this->cell_padding['L'] - $this->cell_padding['R']) / $width);
  5114. }
  5115. // check if stretching is required
  5116. if (($ratio < 1) OR (($ratio > 1) AND (($stretch % 2) == 0))) {
  5117. // the text will be stretched to fit cell width
  5118. if ($stretch > 2) {
  5119. // set new character spacing
  5120. $this->font_spacing += ($w - $this->cell_padding['L'] - $this->cell_padding['R'] - $width) / (max(($this->GetNumChars($txt) - 1), 1) * ($this->font_stretching / 100));
  5121. } else {
  5122. // set new horizontal stretching
  5123. $this->font_stretching *= $ratio;
  5124. }
  5125. // recalculate text width (the text fills the entire cell)
  5126. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5127. // reset alignment
  5128. $align = '';
  5129. }
  5130. }
  5131. if ($this->font_stretching != 100) {
  5132. // apply font stretching
  5133. $rs .= sprintf('BT %F Tz ET ', $this->font_stretching);
  5134. }
  5135. if ($this->font_spacing != 0) {
  5136. // increase/decrease font spacing
  5137. $rs .= sprintf('BT %F Tc ET ', ($this->font_spacing * $this->k));
  5138. }
  5139. if ($this->ColorFlag AND ($this->textrendermode < 4)) {
  5140. $s .= 'q '.$this->TextColor.' ';
  5141. }
  5142. // rendering mode
  5143. $s .= sprintf('BT %d Tr %F w ET ', $this->textrendermode, ($this->textstrokewidth * $this->k));
  5144. // count number of spaces
  5145. $ns = substr_count($txt, chr(32));
  5146. // Justification
  5147. $spacewidth = 0;
  5148. if (($align == 'J') AND ($ns > 0)) {
  5149. if ($this->isUnicodeFont()) {
  5150. // get string width without spaces
  5151. $width = $this->GetStringWidth(str_replace(' ', '', $txt));
  5152. // calculate average space width
  5153. $spacewidth = -1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1) / ($this->FontSize?$this->FontSize:1);
  5154. if ($this->font_stretching != 100) {
  5155. // word spacing is affected by stretching
  5156. $spacewidth /= ($this->font_stretching / 100);
  5157. }
  5158. // set word position to be used with TJ operator
  5159. $txt2 = str_replace(chr(0).chr(32), ') '.sprintf('%F', $spacewidth).' (', $txt2);
  5160. $unicode_justification = true;
  5161. } else {
  5162. // get string width
  5163. $width = $txwidth;
  5164. // new space width
  5165. $spacewidth = (($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1)) * $this->k;
  5166. if ($this->font_stretching != 100) {
  5167. // word spacing (Tw) is affected by stretching
  5168. $spacewidth /= ($this->font_stretching / 100);
  5169. }
  5170. // set word spacing
  5171. $rs .= sprintf('BT %F Tw ET ', $spacewidth);
  5172. }
  5173. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5174. }
  5175. // replace carriage return characters
  5176. $txt2 = str_replace("\r", ' ', $txt2);
  5177. switch ($align) {
  5178. case 'C': {
  5179. $dx = ($w - $width) / 2;
  5180. break;
  5181. }
  5182. case 'R': {
  5183. if ($this->rtl) {
  5184. $dx = $this->cell_padding['R'];
  5185. } else {
  5186. $dx = $w - $width - $this->cell_padding['R'];
  5187. }
  5188. break;
  5189. }
  5190. case 'L': {
  5191. if ($this->rtl) {
  5192. $dx = $w - $width - $this->cell_padding['L'];
  5193. } else {
  5194. $dx = $this->cell_padding['L'];
  5195. }
  5196. break;
  5197. }
  5198. case 'J':
  5199. default: {
  5200. if ($this->rtl) {
  5201. $dx = $this->cell_padding['R'];
  5202. } else {
  5203. $dx = $this->cell_padding['L'];
  5204. }
  5205. break;
  5206. }
  5207. }
  5208. if ($this->rtl) {
  5209. $xdx = $x - $dx - $width;
  5210. } else {
  5211. $xdx = $x + $dx;
  5212. }
  5213. $xdk = $xdx * $k;
  5214. // print text
  5215. $s .= sprintf('BT %F %F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
  5216. if (isset($uniblock)) {
  5217. // print overlapping characters as separate string
  5218. $xshift = 0; // horizontal shift
  5219. $ty = (($this->h - $basefonty + (0.2 * $this->FontSize)) * $k);
  5220. $spw = (($w - $txwidth - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1));
  5221. foreach ($uniblock as $uk => $uniarr) {
  5222. if (($uk % 2) == 0) {
  5223. // x space to skip
  5224. if ($spacewidth != 0) {
  5225. // justification shift
  5226. $xshift += (count(array_keys($uniarr, 32)) * $spw);
  5227. }
  5228. $xshift += $this->GetArrStringWidth($uniarr); // + shift justification
  5229. } else {
  5230. // character to print
  5231. $topchr = TCPDF_FONTS::arrUTF8ToUTF16BE($uniarr, false);
  5232. $topchr = TCPDF_STATIC::_escape($topchr);
  5233. $s .= sprintf(' BT %F %F Td [(%s)] TJ ET', ($xdk + ($xshift * $k)), $ty, $topchr);
  5234. }
  5235. }
  5236. }
  5237. if ($this->underline) {
  5238. $s .= ' '.$this->_dounderlinew($xdx, $basefonty, $width);
  5239. }
  5240. if ($this->linethrough) {
  5241. $s .= ' '.$this->_dolinethroughw($xdx, $basefonty, $width);
  5242. }
  5243. if ($this->overline) {
  5244. $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width);
  5245. }
  5246. if ($this->ColorFlag AND ($this->textrendermode < 4)) {
  5247. $s .= ' Q';
  5248. }
  5249. if ($link) {
  5250. $this->Link($xdx, $yt, $width, ($this->FontAscent + $this->FontDescent), $link, $ns);
  5251. }
  5252. }
  5253. // output cell
  5254. if ($s) {
  5255. // output cell
  5256. $rs .= $s;
  5257. if ($this->font_spacing != 0) {
  5258. // reset font spacing mode
  5259. $rs .= ' BT 0 Tc ET';
  5260. }
  5261. if ($this->font_stretching != 100) {
  5262. // reset font stretching mode
  5263. $rs .= ' BT 100 Tz ET';
  5264. }
  5265. }
  5266. // reset word spacing
  5267. if (!$this->isUnicodeFont() AND ($align == 'J')) {
  5268. $rs .= ' BT 0 Tw ET';
  5269. }
  5270. // reset stretching and spacing
  5271. $this->font_stretching = $prev_font_stretching;
  5272. $this->font_spacing = $prev_font_spacing;
  5273. $this->lasth = $h;
  5274. if ($ln > 0) {
  5275. //Go to the beginning of the next line
  5276. $this->y = $y + $h + $this->cell_margin['B'];
  5277. if ($ln == 1) {
  5278. if ($this->rtl) {
  5279. $this->x = $this->w - $this->rMargin;
  5280. } else {
  5281. $this->x = $this->lMargin;
  5282. }
  5283. }
  5284. } else {
  5285. // go left or right by case
  5286. if ($this->rtl) {
  5287. $this->x = $x - $w - $this->cell_margin['L'];
  5288. } else {
  5289. $this->x = $x + $w + $this->cell_margin['R'];
  5290. }
  5291. }
  5292. $gstyles = ''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor."\n";
  5293. $rs = $gstyles.$rs;
  5294. $this->cell_padding = $prev_cell_padding;
  5295. $this->cell_margin = $prev_cell_margin;
  5296. return $rs;
  5297. }
  5298. /**
  5299. * Replace a char if is defined on the current font.
  5300. * @param $oldchar (int) Integer code (unicode) of the character to replace.
  5301. * @param $newchar (int) Integer code (unicode) of the new character.
  5302. * @return int the replaced char or the old char in case the new char i not defined
  5303. * @protected
  5304. * @since 5.9.167 (2012-06-22)
  5305. */
  5306. protected function replaceChar($oldchar, $newchar)
  5307. {
  5308. if ($this->isCharDefined($newchar)) {
  5309. // add the new char on the subset list
  5310. $this->CurrentFont['subsetchars'][$newchar] = true;
  5311. // return the new character
  5312. return $newchar;
  5313. }
  5314. // return the old char
  5315. return $oldchar;
  5316. }
  5317. /**
  5318. * Returns the code to draw the cell border
  5319. * @param $x (float) X coordinate.
  5320. * @param $y (float) Y coordinate.
  5321. * @param $w (float) Cell width.
  5322. * @param $h (float) Cell height.
  5323. * @param $brd (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  5324. * @return string containing cell border code
  5325. * @protected
  5326. * @see SetLineStyle()
  5327. * @since 5.7.000 (2010-08-02)
  5328. */
  5329. protected function getCellBorder($x, $y, $w, $h, $brd)
  5330. {
  5331. $s = ''; // string to be returned
  5332. if (empty($brd)) {
  5333. return $s;
  5334. }
  5335. if ($brd == 1) {
  5336. $brd = array('LRTB' => true);
  5337. }
  5338. // calculate coordinates for border
  5339. $k = $this->k;
  5340. if ($this->rtl) {
  5341. $xeL = ($x - $w) * $k;
  5342. $xeR = $x * $k;
  5343. } else {
  5344. $xeL = $x * $k;
  5345. $xeR = ($x + $w) * $k;
  5346. }
  5347. $yeL = (($this->h - ($y + $h)) * $k);
  5348. $yeT = (($this->h - $y) * $k);
  5349. $xeT = $xeL;
  5350. $xeB = $xeR;
  5351. $yeR = $yeT;
  5352. $yeB = $yeL;
  5353. if (is_string($brd)) {
  5354. // convert string to array
  5355. $slen = strlen($brd);
  5356. $newbrd = array();
  5357. for ($i = 0; $i < $slen; ++$i) {
  5358. $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
  5359. }
  5360. $brd = $newbrd;
  5361. }
  5362. if (isset($brd['mode'])) {
  5363. $mode = $brd['mode'];
  5364. unset($brd['mode']);
  5365. } else {
  5366. $mode = 'normal';
  5367. }
  5368. foreach ($brd as $border => $style) {
  5369. if (is_array($style) AND !empty($style)) {
  5370. // apply border style
  5371. $prev_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' ';
  5372. $s .= $this->SetLineStyle($style, true)."\n";
  5373. }
  5374. switch ($mode) {
  5375. case 'ext': {
  5376. $off = (($this->LineWidth / 2) * $k);
  5377. $xL = $xeL - $off;
  5378. $xR = $xeR + $off;
  5379. $yT = $yeT + $off;
  5380. $yL = $yeL - $off;
  5381. $xT = $xL;
  5382. $xB = $xR;
  5383. $yR = $yT;
  5384. $yB = $yL;
  5385. $w += $this->LineWidth;
  5386. $h += $this->LineWidth;
  5387. break;
  5388. }
  5389. case 'int': {
  5390. $off = ($this->LineWidth / 2) * $k;
  5391. $xL = $xeL + $off;
  5392. $xR = $xeR - $off;
  5393. $yT = $yeT - $off;
  5394. $yL = $yeL + $off;
  5395. $xT = $xL;
  5396. $xB = $xR;
  5397. $yR = $yT;
  5398. $yB = $yL;
  5399. $w -= $this->LineWidth;
  5400. $h -= $this->LineWidth;
  5401. break;
  5402. }
  5403. case 'normal':
  5404. default: {
  5405. $xL = $xeL;
  5406. $xT = $xeT;
  5407. $xB = $xeB;
  5408. $xR = $xeR;
  5409. $yL = $yeL;
  5410. $yT = $yeT;
  5411. $yB = $yeB;
  5412. $yR = $yeR;
  5413. break;
  5414. }
  5415. }
  5416. // draw borders by case
  5417. if (strlen($border) == 4) {
  5418. $s .= sprintf('%F %F %F %F re S ', $xT, $yT, ($w * $k), (-$h * $k));
  5419. } elseif (strlen($border) == 3) {
  5420. if (strpos($border, 'B') === false) { // LTR
  5421. $s .= sprintf('%F %F m ', $xL, $yL);
  5422. $s .= sprintf('%F %F l ', $xT, $yT);
  5423. $s .= sprintf('%F %F l ', $xR, $yR);
  5424. $s .= sprintf('%F %F l ', $xB, $yB);
  5425. $s .= 'S ';
  5426. } elseif (strpos($border, 'L') === false) { // TRB
  5427. $s .= sprintf('%F %F m ', $xT, $yT);
  5428. $s .= sprintf('%F %F l ', $xR, $yR);
  5429. $s .= sprintf('%F %F l ', $xB, $yB);
  5430. $s .= sprintf('%F %F l ', $xL, $yL);
  5431. $s .= 'S ';
  5432. } elseif (strpos($border, 'T') === false) { // RBL
  5433. $s .= sprintf('%F %F m ', $xR, $yR);
  5434. $s .= sprintf('%F %F l ', $xB, $yB);
  5435. $s .= sprintf('%F %F l ', $xL, $yL);
  5436. $s .= sprintf('%F %F l ', $xT, $yT);
  5437. $s .= 'S ';
  5438. } elseif (strpos($border, 'R') === false) { // BLT
  5439. $s .= sprintf('%F %F m ', $xB, $yB);
  5440. $s .= sprintf('%F %F l ', $xL, $yL);
  5441. $s .= sprintf('%F %F l ', $xT, $yT);
  5442. $s .= sprintf('%F %F l ', $xR, $yR);
  5443. $s .= 'S ';
  5444. }
  5445. } elseif (strlen($border) == 2) {
  5446. if ((strpos($border, 'L') !== false) AND (strpos($border, 'T') !== false)) { // LT
  5447. $s .= sprintf('%F %F m ', $xL, $yL);
  5448. $s .= sprintf('%F %F l ', $xT, $yT);
  5449. $s .= sprintf('%F %F l ', $xR, $yR);
  5450. $s .= 'S ';
  5451. } elseif ((strpos($border, 'T') !== false) AND (strpos($border, 'R') !== false)) { // TR
  5452. $s .= sprintf('%F %F m ', $xT, $yT);
  5453. $s .= sprintf('%F %F l ', $xR, $yR);
  5454. $s .= sprintf('%F %F l ', $xB, $yB);
  5455. $s .= 'S ';
  5456. } elseif ((strpos($border, 'R') !== false) AND (strpos($border, 'B') !== false)) { // RB
  5457. $s .= sprintf('%F %F m ', $xR, $yR);
  5458. $s .= sprintf('%F %F l ', $xB, $yB);
  5459. $s .= sprintf('%F %F l ', $xL, $yL);
  5460. $s .= 'S ';
  5461. } elseif ((strpos($border, 'B') !== false) AND (strpos($border, 'L') !== false)) { // BL
  5462. $s .= sprintf('%F %F m ', $xB, $yB);
  5463. $s .= sprintf('%F %F l ', $xL, $yL);
  5464. $s .= sprintf('%F %F l ', $xT, $yT);
  5465. $s .= 'S ';
  5466. } elseif ((strpos($border, 'L') !== false) AND (strpos($border, 'R') !== false)) { // LR
  5467. $s .= sprintf('%F %F m ', $xL, $yL);
  5468. $s .= sprintf('%F %F l ', $xT, $yT);
  5469. $s .= 'S ';
  5470. $s .= sprintf('%F %F m ', $xR, $yR);
  5471. $s .= sprintf('%F %F l ', $xB, $yB);
  5472. $s .= 'S ';
  5473. } elseif ((strpos($border, 'T') !== false) AND (strpos($border, 'B') !== false)) { // TB
  5474. $s .= sprintf('%F %F m ', $xT, $yT);
  5475. $s .= sprintf('%F %F l ', $xR, $yR);
  5476. $s .= 'S ';
  5477. $s .= sprintf('%F %F m ', $xB, $yB);
  5478. $s .= sprintf('%F %F l ', $xL, $yL);
  5479. $s .= 'S ';
  5480. }
  5481. } else { // strlen($border) == 1
  5482. if (strpos($border, 'L') !== false) { // L
  5483. $s .= sprintf('%F %F m ', $xL, $yL);
  5484. $s .= sprintf('%F %F l ', $xT, $yT);
  5485. $s .= 'S ';
  5486. } elseif (strpos($border, 'T') !== false) { // T
  5487. $s .= sprintf('%F %F m ', $xT, $yT);
  5488. $s .= sprintf('%F %F l ', $xR, $yR);
  5489. $s .= 'S ';
  5490. } elseif (strpos($border, 'R') !== false) { // R
  5491. $s .= sprintf('%F %F m ', $xR, $yR);
  5492. $s .= sprintf('%F %F l ', $xB, $yB);
  5493. $s .= 'S ';
  5494. } elseif (strpos($border, 'B') !== false) { // B
  5495. $s .= sprintf('%F %F m ', $xB, $yB);
  5496. $s .= sprintf('%F %F l ', $xL, $yL);
  5497. $s .= 'S ';
  5498. }
  5499. }
  5500. if (is_array($style) AND !empty($style)) {
  5501. // reset border style to previous value
  5502. $s .= "\n".$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor."\n";
  5503. }
  5504. }
  5505. return $s;
  5506. }
  5507. /**
  5508. * This method allows printing text with line breaks.
  5509. * 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 />
  5510. * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  5511. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  5512. * @param $h (float) Cell minimum height. The cell extends automatically if needed.
  5513. * @param $txt (string) String to print
  5514. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  5515. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align</li><li>C: center</li><li>R: right align</li><li>J: justification (default value when $ishtml=false)</li></ul>
  5516. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  5517. * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right</li><li>1: to the beginning of the next line [DEFAULT]</li><li>2: below</li></ul>
  5518. * @param $x (float) x position in user units
  5519. * @param $y (float) y position in user units
  5520. * @param $reseth (boolean) if true reset the last cell height (default true).
  5521. * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  5522. * @param $ishtml (boolean) INTERNAL USE ONLY -- set to true if $txt is HTML content (default = false). Never set this parameter to true, use instead writeHTMLCell() or writeHTML() methods.
  5523. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width.
  5524. * @param $maxh (float) maximum height. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature. This feature works only when $ishtml=false.
  5525. * @param $valign (string) Vertical alignment of text (requires $maxh = $h > 0). Possible values are:<ul><li>T: TOP</li><li>M: middle</li><li>B: bottom</li></ul>. This feature works only when $ishtml=false and the cell must fit in a single page.
  5526. * @param $fitcell (boolean) if true attempt to fit all the text within the cell by reducing the font size (do not work in HTML mode). $maxh must be greater than 0 and equal to $h.
  5527. * @return int Return the number of cells or 1 for html mode.
  5528. * @public
  5529. * @since 1.3
  5530. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  5531. */
  5532. public function MultiCell($w, $h, $txt, $border = 0, $align = 'J', $fill = false, $ln = 1, $x = '', $y = '', $reseth = true, $stretch = 0, $ishtml = false, $autopadding = true, $maxh = 0, $valign = 'T', $fitcell = false)
  5533. {
  5534. $prev_cell_margin = $this->cell_margin;
  5535. $prev_cell_padding = $this->cell_padding;
  5536. // adjust internal padding
  5537. $this->adjustCellPadding($border);
  5538. $mc_padding = $this->cell_padding;
  5539. $mc_margin = $this->cell_margin;
  5540. $this->cell_padding['T'] = 0;
  5541. $this->cell_padding['B'] = 0;
  5542. $this->setCellMargins(0, 0, 0, 0);
  5543. if (TCPDF_STATIC::empty_string($this->lasth) OR $reseth) {
  5544. // reset row height
  5545. $this->resetLastH();
  5546. }
  5547. if (!TCPDF_STATIC::empty_string($y)) {
  5548. $this->SetY($y); // set y in order to convert negative y values to positive ones
  5549. }
  5550. $y = $this->GetY();
  5551. $resth = 0;
  5552. if (($h > 0) AND $this->inPageBody() AND (($y + $h + $mc_margin['T'] + $mc_margin['B']) > $this->PageBreakTrigger)) {
  5553. // spit cell in more pages/columns
  5554. $newh = ($this->PageBreakTrigger - $y);
  5555. $resth = ($h - $newh); // cell to be printed on the next page/column
  5556. $h = $newh;
  5557. }
  5558. // get current page number
  5559. $startpage = $this->page;
  5560. // get current column
  5561. $startcolumn = $this->current_column;
  5562. if (!TCPDF_STATIC::empty_string($x)) {
  5563. $this->SetX($x);
  5564. } else {
  5565. $x = $this->GetX();
  5566. }
  5567. // check page for no-write regions and adapt page margins if necessary
  5568. list($x, $y) = $this->checkPageRegions(0, $x, $y);
  5569. // apply margins
  5570. $oy = $y + $mc_margin['T'];
  5571. if ($this->rtl) {
  5572. $ox = ($this->w - $x - $mc_margin['R']);
  5573. } else {
  5574. $ox = ($x + $mc_margin['L']);
  5575. }
  5576. $this->x = $ox;
  5577. $this->y = $oy;
  5578. // set width
  5579. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  5580. if ($this->rtl) {
  5581. $w = ($this->x - $this->lMargin - $mc_margin['L']);
  5582. } else {
  5583. $w = ($this->w - $this->x - $this->rMargin - $mc_margin['R']);
  5584. }
  5585. }
  5586. // store original margin values
  5587. $lMargin = $this->lMargin;
  5588. $rMargin = $this->rMargin;
  5589. if ($this->rtl) {
  5590. $this->rMargin = ($this->w - $this->x);
  5591. $this->lMargin = ($this->x - $w);
  5592. } else {
  5593. $this->lMargin = ($this->x);
  5594. $this->rMargin = ($this->w - $this->x - $w);
  5595. }
  5596. $this->clMargin = $this->lMargin;
  5597. $this->crMargin = $this->rMargin;
  5598. if ($autopadding) {
  5599. // add top padding
  5600. $this->y += $mc_padding['T'];
  5601. }
  5602. if ($ishtml) { // ******* Write HTML text
  5603. $this->writeHTML($txt, true, false, $reseth, true, $align);
  5604. $nl = 1;
  5605. } else { // ******* Write simple text
  5606. $prev_FontSizePt = $this->FontSizePt;
  5607. if ($fitcell) {
  5608. // ajust height values
  5609. $tobottom = ($this->h - $this->y - $this->bMargin - $this->cell_padding['T'] - $this->cell_padding['B']);
  5610. $h = $maxh = max(min($h, $tobottom), min($maxh, $tobottom));
  5611. }
  5612. // vertical alignment
  5613. if ($maxh > 0) {
  5614. // get text height
  5615. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5616. if ($fitcell AND ($text_height > $maxh) AND ($this->FontSizePt > 1)) {
  5617. // try to reduce font size to fit text on cell (use a quick search algorithm)
  5618. $fmin = 1;
  5619. $fmax = $this->FontSizePt;
  5620. $diff_epsilon = (1 / $this->k); // one point (min resolution)
  5621. $maxit = (2 * min(100, max(10, intval($fmax)))); // max number of iterations
  5622. while ($maxit >= 0) {
  5623. $fmid = (($fmax + $fmin) / 2);
  5624. $this->SetFontSize($fmid, false);
  5625. $this->resetLastH();
  5626. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5627. $diff = ($maxh - $text_height);
  5628. if ($diff >= 0) {
  5629. if ($diff <= $diff_epsilon) {
  5630. break;
  5631. }
  5632. $fmin = $fmid;
  5633. } else {
  5634. $fmax = $fmid;
  5635. }
  5636. --$maxit;
  5637. }
  5638. if ($maxit < 0) {
  5639. // premature exit, we get the minimum font value to fit the cell
  5640. $this->SetFontSize($fmin);
  5641. $this->resetLastH();
  5642. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5643. } else {
  5644. $this->SetFontSize($fmid);
  5645. $this->resetLastH();
  5646. }
  5647. }
  5648. if ($text_height < $maxh) {
  5649. if ($valign == 'M') {
  5650. // text vertically centered
  5651. $this->y += (($maxh - $text_height) / 2);
  5652. } elseif ($valign == 'B') {
  5653. // text vertically aligned on bottom
  5654. $this->y += ($maxh - $text_height);
  5655. }
  5656. }
  5657. }
  5658. $nl = $this->Write($this->lasth, $txt, '', 0, $align, true, $stretch, false, true, $maxh, 0, $mc_margin);
  5659. if ($fitcell) {
  5660. // restore font size
  5661. $this->SetFontSize($prev_FontSizePt);
  5662. }
  5663. }
  5664. if ($autopadding) {
  5665. // add bottom padding
  5666. $this->y += $mc_padding['B'];
  5667. }
  5668. // Get end-of-text Y position
  5669. $currentY = $this->y;
  5670. // get latest page number
  5671. $endpage = $this->page;
  5672. if ($resth > 0) {
  5673. $skip = ($endpage - $startpage);
  5674. $tmpresth = $resth;
  5675. while ($tmpresth > 0) {
  5676. if ($skip <= 0) {
  5677. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  5678. $this->checkPageBreak($this->PageBreakTrigger + 1);
  5679. }
  5680. if ($this->num_columns > 1) {
  5681. $tmpresth -= ($this->h - $this->y - $this->bMargin);
  5682. } else {
  5683. $tmpresth -= ($this->h - $this->tMargin - $this->bMargin);
  5684. }
  5685. --$skip;
  5686. }
  5687. $currentY = $this->y;
  5688. $endpage = $this->page;
  5689. }
  5690. // get latest column
  5691. $endcolumn = $this->current_column;
  5692. if ($this->num_columns == 0) {
  5693. $this->num_columns = 1;
  5694. }
  5695. // disable page regions check
  5696. $check_page_regions = $this->check_page_regions;
  5697. $this->check_page_regions = false;
  5698. // get border modes
  5699. $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
  5700. $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
  5701. $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  5702. // design borders around HTML cells.
  5703. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  5704. $ccode = '';
  5705. $this->setPage($page);
  5706. if ($this->num_columns < 2) {
  5707. // single-column mode
  5708. $this->SetX($x);
  5709. $this->y = $this->tMargin;
  5710. }
  5711. // account for margin changes
  5712. if ($page > $startpage) {
  5713. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  5714. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  5715. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  5716. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  5717. }
  5718. }
  5719. if ($startpage == $endpage) {
  5720. // single page
  5721. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  5722. if ($column != $this->current_column) {
  5723. $this->selectColumn($column);
  5724. }
  5725. if ($this->rtl) {
  5726. $this->x -= $mc_margin['R'];
  5727. } else {
  5728. $this->x += $mc_margin['L'];
  5729. }
  5730. if ($startcolumn == $endcolumn) { // single column
  5731. $cborder = $border;
  5732. $h = max($h, ($currentY - $oy));
  5733. $this->y = $oy;
  5734. } elseif ($column == $startcolumn) { // first column
  5735. $cborder = $border_start;
  5736. $this->y = $oy;
  5737. $h = $this->h - $this->y - $this->bMargin;
  5738. } elseif ($column == $endcolumn) { // end column
  5739. $cborder = $border_end;
  5740. $h = $currentY - $this->y;
  5741. if ($resth > $h) {
  5742. $h = $resth;
  5743. }
  5744. } else { // middle column
  5745. $cborder = $border_middle;
  5746. $h = $this->h - $this->y - $this->bMargin;
  5747. $resth -= $h;
  5748. }
  5749. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5750. } // end for each column
  5751. } elseif ($page == $startpage) { // first page
  5752. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  5753. if ($column != $this->current_column) {
  5754. $this->selectColumn($column);
  5755. }
  5756. if ($this->rtl) {
  5757. $this->x -= $mc_margin['R'];
  5758. } else {
  5759. $this->x += $mc_margin['L'];
  5760. }
  5761. if ($column == $startcolumn) { // first column
  5762. $cborder = $border_start;
  5763. $this->y = $oy;
  5764. $h = $this->h - $this->y - $this->bMargin;
  5765. } else { // middle column
  5766. $cborder = $border_middle;
  5767. $h = $this->h - $this->y - $this->bMargin;
  5768. $resth -= $h;
  5769. }
  5770. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5771. } // end for each column
  5772. } elseif ($page == $endpage) { // last page
  5773. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  5774. if ($column != $this->current_column) {
  5775. $this->selectColumn($column);
  5776. }
  5777. if ($this->rtl) {
  5778. $this->x -= $mc_margin['R'];
  5779. } else {
  5780. $this->x += $mc_margin['L'];
  5781. }
  5782. if ($column == $endcolumn) {
  5783. // end column
  5784. $cborder = $border_end;
  5785. $h = $currentY - $this->y;
  5786. if ($resth > $h) {
  5787. $h = $resth;
  5788. }
  5789. } else {
  5790. // middle column
  5791. $cborder = $border_middle;
  5792. $h = $this->h - $this->y - $this->bMargin;
  5793. $resth -= $h;
  5794. }
  5795. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5796. } // end for each column
  5797. } else { // middle page
  5798. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  5799. $this->selectColumn($column);
  5800. if ($this->rtl) {
  5801. $this->x -= $mc_margin['R'];
  5802. } else {
  5803. $this->x += $mc_margin['L'];
  5804. }
  5805. $cborder = $border_middle;
  5806. $h = $this->h - $this->y - $this->bMargin;
  5807. $resth -= $h;
  5808. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5809. } // end for each column
  5810. }
  5811. if ($cborder OR $fill) {
  5812. $offsetlen = strlen($ccode);
  5813. // draw border and fill
  5814. if ($this->inxobj) {
  5815. // we are inside an XObject template
  5816. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  5817. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  5818. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  5819. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  5820. } else {
  5821. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  5822. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  5823. }
  5824. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  5825. $pstart = substr($pagebuff, 0, $pagemark);
  5826. $pend = substr($pagebuff, $pagemark);
  5827. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  5828. } else {
  5829. if (end($this->transfmrk[$this->page]) !== false) {
  5830. $pagemarkkey = key($this->transfmrk[$this->page]);
  5831. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  5832. $this->transfmrk[$this->page][$pagemarkkey] += $offsetlen;
  5833. } elseif ($this->InFooter) {
  5834. $pagemark = $this->footerpos[$this->page];
  5835. $this->footerpos[$this->page] += $offsetlen;
  5836. } else {
  5837. $pagemark = $this->intmrk[$this->page];
  5838. $this->intmrk[$this->page] += $offsetlen;
  5839. }
  5840. $pagebuff = $this->getPageBuffer($this->page);
  5841. $pstart = substr($pagebuff, 0, $pagemark);
  5842. $pend = substr($pagebuff, $pagemark);
  5843. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  5844. }
  5845. }
  5846. } // end for each page
  5847. // restore page regions check
  5848. $this->check_page_regions = $check_page_regions;
  5849. // Get end-of-cell Y position
  5850. $currentY = $this->GetY();
  5851. // restore previous values
  5852. if ($this->num_columns > 1) {
  5853. $this->selectColumn();
  5854. } else {
  5855. // restore original margins
  5856. $this->lMargin = $lMargin;
  5857. $this->rMargin = $rMargin;
  5858. if ($this->page > $startpage) {
  5859. // check for margin variations between pages (i.e. booklet mode)
  5860. $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$startpage]['olm']);
  5861. $dr = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$startpage]['orm']);
  5862. if (($dl != 0) OR ($dr != 0)) {
  5863. $this->lMargin += $dl;
  5864. $this->rMargin += $dr;
  5865. }
  5866. }
  5867. }
  5868. if ($ln > 0) {
  5869. //Go to the beginning of the next line
  5870. $this->SetY($currentY + $mc_margin['B']);
  5871. if ($ln == 2) {
  5872. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  5873. }
  5874. } else {
  5875. // go left or right by case
  5876. $this->setPage($startpage);
  5877. $this->y = $y;
  5878. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  5879. }
  5880. $this->setContentMark();
  5881. $this->cell_padding = $prev_cell_padding;
  5882. $this->cell_margin = $prev_cell_margin;
  5883. $this->clMargin = $this->lMargin;
  5884. $this->crMargin = $this->rMargin;
  5885. return $nl;
  5886. }
  5887. /**
  5888. * This method return the estimated number of lines for print a simple text string using Multicell() method.
  5889. * @param $txt (string) String for calculating his height
  5890. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  5891. * @param $reseth (boolean) if true reset the last cell height (default false).
  5892. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
  5893. * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
  5894. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  5895. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  5896. * @author Alexander Escalona Fern\E1ndez, Nicola Asuni
  5897. * @public
  5898. * @since 4.5.011
  5899. */
  5900. public function getNumLines($txt, $w = 0, $reseth = false, $autopadding = true, $cellpadding = '', $border = 0)
  5901. {
  5902. if ($txt === null) {
  5903. return 0;
  5904. }
  5905. if ($txt === '') {
  5906. // empty string
  5907. return 1;
  5908. }
  5909. // adjust internal padding
  5910. $prev_cell_padding = $this->cell_padding;
  5911. $prev_lasth = $this->lasth;
  5912. if (is_array($cellpadding)) {
  5913. $this->cell_padding = $cellpadding;
  5914. }
  5915. $this->adjustCellPadding($border);
  5916. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  5917. if ($this->rtl) {
  5918. $w = $this->x - $this->lMargin;
  5919. } else {
  5920. $w = $this->w - $this->rMargin - $this->x;
  5921. }
  5922. }
  5923. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5924. if ($reseth) {
  5925. // reset row height
  5926. $this->resetLastH();
  5927. }
  5928. $lines = 1;
  5929. $sum = 0;
  5930. $chars = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont), $txt, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  5931. $charsWidth = $this->GetArrStringWidth($chars, '', '', 0, true);
  5932. $length = count($chars);
  5933. $lastSeparator = -1;
  5934. for ($i = 0; $i < $length; ++$i) {
  5935. $c = $chars[$i];
  5936. $charWidth = $charsWidth[$i];
  5937. if (($c != 160)
  5938. AND (($c == 173)
  5939. OR preg_match($this->re_spaces, TCPDF_FONTS::unichr($c, $this->isunicode))
  5940. OR (($c == 45)
  5941. AND ($i > 0) AND ($i < ($length - 1))
  5942. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i - 1)], $this->isunicode))
  5943. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i + 1)], $this->isunicode))
  5944. )
  5945. )
  5946. ) {
  5947. $lastSeparator = $i;
  5948. }
  5949. if ((($sum + $charWidth) > $wmax) OR ($c == 10)) {
  5950. ++$lines;
  5951. if ($c == 10) {
  5952. $lastSeparator = -1;
  5953. $sum = 0;
  5954. } elseif ($lastSeparator != -1) {
  5955. $i = $lastSeparator;
  5956. $lastSeparator = -1;
  5957. $sum = 0;
  5958. } else {
  5959. $sum = $charWidth;
  5960. }
  5961. } else {
  5962. $sum += $charWidth;
  5963. }
  5964. }
  5965. if ($chars[($length - 1)] == 10) {
  5966. --$lines;
  5967. }
  5968. $this->cell_padding = $prev_cell_padding;
  5969. $this->lasth = $prev_lasth;
  5970. return $lines;
  5971. }
  5972. /**
  5973. * This method return the estimated height needed for printing a simple text string using the Multicell() method.
  5974. * Generally, if you want to know the exact height for a block of content you can use the following alternative technique:
  5975. * @pre
  5976. * // store current object
  5977. * $pdf->startTransaction();
  5978. * // store starting values
  5979. * $start_y = $pdf->GetY();
  5980. * $start_page = $pdf->getPage();
  5981. * // call your printing functions with your parameters
  5982. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5983. * $pdf->MultiCell($w=0, $h=0, $txt, $border=1, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0);
  5984. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5985. * // get the new Y
  5986. * $end_y = $pdf->GetY();
  5987. * $end_page = $pdf->getPage();
  5988. * // calculate height
  5989. * $height = 0;
  5990. * if ($end_page == $start_page) {
  5991. * $height = $end_y - $start_y;
  5992. * } else {
  5993. * for ($page=$start_page; $page <= $end_page; ++$page) {
  5994. * $this->setPage($page);
  5995. * if ($page == $start_page) {
  5996. * // first page
  5997. * $height += $this->h - $start_y - $this->bMargin;
  5998. * } elseif ($page == $end_page) {
  5999. * // last page
  6000. * $height += $end_y - $this->tMargin;
  6001. * } else {
  6002. * $height += $this->h - $this->tMargin - $this->bMargin;
  6003. * }
  6004. * }
  6005. * }
  6006. * // restore previous object
  6007. * $pdf = $pdf->rollbackTransaction();
  6008. *
  6009. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  6010. * @param $txt (string) String for calculating his height
  6011. * @param $reseth (boolean) if true reset the last cell height (default false).
  6012. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
  6013. * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
  6014. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  6015. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  6016. * @author Nicola Asuni, Alexander Escalona Fern\E1ndez
  6017. * @public
  6018. */
  6019. public function getStringHeight($w, $txt, $reseth = false, $autopadding = true, $cellpadding = '', $border = 0)
  6020. {
  6021. // adjust internal padding
  6022. $prev_cell_padding = $this->cell_padding;
  6023. $prev_lasth = $this->lasth;
  6024. if (is_array($cellpadding)) {
  6025. $this->cell_padding = $cellpadding;
  6026. }
  6027. $this->adjustCellPadding($border);
  6028. $lines = $this->getNumLines($txt, $w, $reseth, $autopadding, $cellpadding, $border);
  6029. $height = $this->getCellHeight(($lines * $this->FontSize), $autopadding);
  6030. $this->cell_padding = $prev_cell_padding;
  6031. $this->lasth = $prev_lasth;
  6032. return $height;
  6033. }
  6034. /**
  6035. * This method prints text from the current position.<br />
  6036. * @param $h (float) Line height
  6037. * @param $txt (string) String to print
  6038. * @param $link (mixed) URL or identifier returned by AddLink()
  6039. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  6040. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  6041. * @param $ln (boolean) if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
  6042. * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  6043. * @param $firstline (boolean) if true prints only the first line and return the remaining string.
  6044. * @param $firstblock (boolean) if true the string is the starting of a line.
  6045. * @param $maxh (float) maximum height. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature.
  6046. * @param $wadj (float) first line width will be reduced by this amount (used in HTML mode).
  6047. * @param $margin (array) margin array of the parent container
  6048. * @return mixed Return the number of cells or the remaining string if $firstline = true.
  6049. * @public
  6050. * @since 1.5
  6051. */
  6052. public function Write($h, $txt, $link = '', $fill = false, $align = '', $ln = false, $stretch = 0, $firstline = false, $firstblock = false, $maxh = 0, $wadj = 0, $margin = '')
  6053. {
  6054. // check page for no-write regions and adapt page margins if necessary
  6055. list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
  6056. if (strlen($txt) == 0) {
  6057. // fix empty text
  6058. $txt = ' ';
  6059. }
  6060. if ($margin === '') {
  6061. // set default margins
  6062. $margin = $this->cell_margin;
  6063. }
  6064. // remove carriage returns
  6065. $s = str_replace("\r", '', $txt);
  6066. // check if string contains arabic text
  6067. if (preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_ARABIC, $s)) {
  6068. $arabic = true;
  6069. } else {
  6070. $arabic = false;
  6071. }
  6072. // check if string contains RTL text
  6073. if ($arabic OR ($this->tmprtl == 'R') OR preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_RTL, $s)) {
  6074. $rtlmode = true;
  6075. } else {
  6076. $rtlmode = false;
  6077. }
  6078. // get a char width
  6079. $chrwidth = $this->GetCharWidth(46); // dot character
  6080. // get array of unicode values
  6081. $chars = TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont);
  6082. // calculate maximum width for a single character on string
  6083. $chrw = $this->GetArrStringWidth($chars, '', '', 0, true);
  6084. array_walk($chrw, array($this, 'getRawCharWidth'));
  6085. $maxchwidth = max($chrw);
  6086. // get array of chars
  6087. $uchars = TCPDF_FONTS::UTF8ArrayToUniArray($chars, $this->isunicode);
  6088. // get the number of characters
  6089. $nb = count($chars);
  6090. // replacement for SHY character (minus symbol)
  6091. $shy_replacement = 45;
  6092. $shy_replacement_char = TCPDF_FONTS::unichr($shy_replacement, $this->isunicode);
  6093. // widht for SHY replacement
  6094. $shy_replacement_width = $this->GetCharWidth($shy_replacement);
  6095. // page width
  6096. $pw = $w = $this->w - $this->lMargin - $this->rMargin;
  6097. // calculate remaining line width ($w)
  6098. if ($this->rtl) {
  6099. $w = $this->x - $this->lMargin;
  6100. } else {
  6101. $w = $this->w - $this->rMargin - $this->x;
  6102. }
  6103. // max column width
  6104. $wmax = ($w - $wadj);
  6105. if (!$firstline) {
  6106. $wmax -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  6107. }
  6108. if ((!$firstline) AND (($chrwidth > $wmax) OR ($maxchwidth > $wmax))) {
  6109. // the maximum width character do not fit on column
  6110. return '';
  6111. }
  6112. // minimum row height
  6113. $row_height = max($h, $this->getCellHeight($this->FontSize));
  6114. // max Y
  6115. $maxy = $this->y + $maxh - max($row_height, $h);
  6116. $start_page = $this->page;
  6117. $i = 0; // character position
  6118. $j = 0; // current starting position
  6119. $sep = -1; // position of the last blank space
  6120. $prevsep = $sep; // previous separator
  6121. $shy = false; // true if the last blank is a soft hypen (SHY)
  6122. $prevshy = $shy; // previous shy mode
  6123. $l = 0; // current string length
  6124. $nl = 0; //number of lines
  6125. $linebreak = false;
  6126. $pc = 0; // previous character
  6127. // for each character
  6128. while ($i < $nb) {
  6129. if (($maxh > 0) AND ($this->y > $maxy) ) {
  6130. break;
  6131. }
  6132. //Get the current character
  6133. $c = $chars[$i];
  6134. if ($c == 10) { // 10 = "\n" = new line
  6135. //Explicit line break
  6136. if ($align == 'J') {
  6137. if ($this->rtl) {
  6138. $talign = 'R';
  6139. } else {
  6140. $talign = 'L';
  6141. }
  6142. } else {
  6143. $talign = $align;
  6144. }
  6145. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
  6146. if ($firstline) {
  6147. $startx = $this->x;
  6148. $tmparr = array_slice($chars, $j, ($i - $j));
  6149. if ($rtlmode) {
  6150. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6151. }
  6152. $linew = $this->GetArrStringWidth($tmparr);
  6153. unset($tmparr);
  6154. if ($this->rtl) {
  6155. $this->endlinex = $startx - $linew;
  6156. } else {
  6157. $this->endlinex = $startx + $linew;
  6158. }
  6159. $w = $linew;
  6160. $tmpcellpadding = $this->cell_padding;
  6161. if ($maxh == 0) {
  6162. $this->SetCellPadding(0);
  6163. }
  6164. }
  6165. if ($firstblock AND $this->isRTLTextDir()) {
  6166. $tmpstr = $this->stringRightTrim($tmpstr);
  6167. }
  6168. // Skip newlines at the beginning of a page or column
  6169. if (!empty($tmpstr) OR ($this->y < ($this->PageBreakTrigger - $row_height))) {
  6170. $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
  6171. }
  6172. unset($tmpstr);
  6173. if ($firstline) {
  6174. $this->cell_padding = $tmpcellpadding;
  6175. return (TCPDF_FONTS::UniArrSubString($uchars, $i));
  6176. }
  6177. ++$nl;
  6178. $j = $i + 1;
  6179. $l = 0;
  6180. $sep = -1;
  6181. $prevsep = $sep;
  6182. $shy = false;
  6183. // account for margin changes
  6184. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
  6185. $this->AcceptPageBreak();
  6186. if ($this->rtl) {
  6187. $this->x -= $margin['R'];
  6188. } else {
  6189. $this->x += $margin['L'];
  6190. }
  6191. $this->lMargin += $margin['L'];
  6192. $this->rMargin += $margin['R'];
  6193. }
  6194. $w = $this->getRemainingWidth();
  6195. $wmax = ($w - $this->cell_padding['L'] - $this->cell_padding['R']);
  6196. } else {
  6197. // 160 is the non-breaking space.
  6198. // 173 is SHY (Soft Hypen).
  6199. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  6200. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  6201. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  6202. if (($c != 160)
  6203. AND (($c == 173)
  6204. OR preg_match($this->re_spaces, TCPDF_FONTS::unichr($c, $this->isunicode))
  6205. OR (($c == 45)
  6206. AND ($i < ($nb - 1))
  6207. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($pc, $this->isunicode))
  6208. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i + 1)], $this->isunicode))
  6209. )
  6210. )
  6211. ) {
  6212. // update last blank space position
  6213. $prevsep = $sep;
  6214. $sep = $i;
  6215. // check if is a SHY
  6216. if (($c == 173) OR ($c == 45)) {
  6217. $prevshy = $shy;
  6218. $shy = true;
  6219. if ($pc == 45) {
  6220. $tmp_shy_replacement_width = 0;
  6221. $tmp_shy_replacement_char = '';
  6222. } else {
  6223. $tmp_shy_replacement_width = $shy_replacement_width;
  6224. $tmp_shy_replacement_char = $shy_replacement_char;
  6225. }
  6226. } else {
  6227. $shy = false;
  6228. }
  6229. }
  6230. // update string length
  6231. if ($this->isUnicodeFont() AND ($arabic)) {
  6232. // with bidirectional algorithm some chars may be changed affecting the line length
  6233. // *** very slow ***
  6234. $l = $this->GetArrStringWidth(TCPDF_FONTS::utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl, $this->isunicode, $this->CurrentFont));
  6235. } else {
  6236. $l += $this->GetCharWidth($c);
  6237. }
  6238. if (($l > $wmax) OR (($c == 173) AND (($l + $tmp_shy_replacement_width) >= $wmax))) {
  6239. if (($c == 173) AND (($l + $tmp_shy_replacement_width) > $wmax)) {
  6240. $sep = $prevsep;
  6241. $shy = $prevshy;
  6242. }
  6243. // we have reached the end of column
  6244. if ($sep == -1) {
  6245. // check if the line was already started
  6246. if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $this->cell_padding['R'] - $margin['R'] - $chrwidth)))
  6247. OR ((!$this->rtl) AND ($this->x >= ($this->lMargin + $this->cell_padding['L'] + $margin['L'] + $chrwidth)))) {
  6248. // print a void cell and go to next line
  6249. $this->Cell($w, $h, '', 0, 1);
  6250. $linebreak = true;
  6251. if ($firstline) {
  6252. return (TCPDF_FONTS::UniArrSubString($uchars, $j));
  6253. }
  6254. } else {
  6255. // truncate the word because do not fit on column
  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. }
  6288. } else {
  6289. // word wrapping
  6290. if ($this->rtl AND (!$firstblock) AND ($sep < $i)) {
  6291. $endspace = 1;
  6292. } else {
  6293. $endspace = 0;
  6294. }
  6295. // check the length of the next string
  6296. $strrest = TCPDF_FONTS::UniArrSubString($uchars, ($sep + $endspace));
  6297. $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'/', $this->re_space['m'], $this->stringTrim($strrest));
  6298. if (isset($nextstr[0]) AND ($this->GetStringWidth($nextstr[0]) > $pw)) {
  6299. // truncate the word because do not fit on a full page width
  6300. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
  6301. if ($firstline) {
  6302. $startx = $this->x;
  6303. $tmparr = array_slice($chars, $j, ($i - $j));
  6304. if ($rtlmode) {
  6305. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6306. }
  6307. $linew = $this->GetArrStringWidth($tmparr);
  6308. unset($tmparr);
  6309. if ($this->rtl) {
  6310. $this->endlinex = ($startx - $linew);
  6311. } else {
  6312. $this->endlinex = ($startx + $linew);
  6313. }
  6314. $w = $linew;
  6315. $tmpcellpadding = $this->cell_padding;
  6316. if ($maxh == 0) {
  6317. $this->SetCellPadding(0);
  6318. }
  6319. }
  6320. if ($firstblock AND $this->isRTLTextDir()) {
  6321. $tmpstr = $this->stringRightTrim($tmpstr);
  6322. }
  6323. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  6324. unset($tmpstr);
  6325. if ($firstline) {
  6326. $this->cell_padding = $tmpcellpadding;
  6327. return (TCPDF_FONTS::UniArrSubString($uchars, $i));
  6328. }
  6329. $j = $i;
  6330. --$i;
  6331. } else {
  6332. // word wrapping
  6333. if ($shy) {
  6334. // add hypen (minus symbol) at the end of the line
  6335. $shy_width = $tmp_shy_replacement_width;
  6336. if ($this->rtl) {
  6337. $shy_char_left = $tmp_shy_replacement_char;
  6338. $shy_char_right = '';
  6339. } else {
  6340. $shy_char_left = '';
  6341. $shy_char_right = $tmp_shy_replacement_char;
  6342. }
  6343. } else {
  6344. $shy_width = 0;
  6345. $shy_char_left = '';
  6346. $shy_char_right = '';
  6347. }
  6348. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, ($sep + $endspace));
  6349. if ($firstline) {
  6350. $startx = $this->x;
  6351. $tmparr = array_slice($chars, $j, (($sep + $endspace) - $j));
  6352. if ($rtlmode) {
  6353. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6354. }
  6355. $linew = $this->GetArrStringWidth($tmparr);
  6356. unset($tmparr);
  6357. if ($this->rtl) {
  6358. $this->endlinex = $startx - $linew - $shy_width;
  6359. } else {
  6360. $this->endlinex = $startx + $linew + $shy_width;
  6361. }
  6362. $w = $linew;
  6363. $tmpcellpadding = $this->cell_padding;
  6364. if ($maxh == 0) {
  6365. $this->SetCellPadding(0);
  6366. }
  6367. }
  6368. // print the line
  6369. if ($firstblock AND $this->isRTLTextDir()) {
  6370. $tmpstr = $this->stringRightTrim($tmpstr);
  6371. }
  6372. $this->Cell($w, $h, $shy_char_left.$tmpstr.$shy_char_right, 0, 1, $align, $fill, $link, $stretch);
  6373. unset($tmpstr);
  6374. if ($firstline) {
  6375. if ($chars[$sep] == 45) {
  6376. $endspace += 1;
  6377. }
  6378. // return the remaining text
  6379. $this->cell_padding = $tmpcellpadding;
  6380. return (TCPDF_FONTS::UniArrSubString($uchars, ($sep + $endspace)));
  6381. }
  6382. $i = $sep;
  6383. $sep = -1;
  6384. $shy = false;
  6385. $j = ($i + 1);
  6386. }
  6387. }
  6388. // account for margin changes
  6389. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
  6390. $this->AcceptPageBreak();
  6391. if ($this->rtl) {
  6392. $this->x -= $margin['R'];
  6393. } else {
  6394. $this->x += $margin['L'];
  6395. }
  6396. $this->lMargin += $margin['L'];
  6397. $this->rMargin += $margin['R'];
  6398. }
  6399. $w = $this->getRemainingWidth();
  6400. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6401. if ($linebreak) {
  6402. $linebreak = false;
  6403. } else {
  6404. ++$nl;
  6405. $l = 0;
  6406. }
  6407. }
  6408. }
  6409. // save last character
  6410. $pc = $c;
  6411. ++$i;
  6412. } // end while i < nb
  6413. // print last substring (if any)
  6414. if ($l > 0) {
  6415. switch ($align) {
  6416. case 'J':
  6417. case 'C': {
  6418. $w = $w;
  6419. break;
  6420. }
  6421. case 'L': {
  6422. if ($this->rtl) {
  6423. $w = $w;
  6424. } else {
  6425. $w = $l;
  6426. }
  6427. break;
  6428. }
  6429. case 'R': {
  6430. if ($this->rtl) {
  6431. $w = $l;
  6432. } else {
  6433. $w = $w;
  6434. }
  6435. break;
  6436. }
  6437. default: {
  6438. $w = $l;
  6439. break;
  6440. }
  6441. }
  6442. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $nb);
  6443. if ($firstline) {
  6444. $startx = $this->x;
  6445. $tmparr = array_slice($chars, $j, ($nb - $j));
  6446. if ($rtlmode) {
  6447. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6448. }
  6449. $linew = $this->GetArrStringWidth($tmparr);
  6450. unset($tmparr);
  6451. if ($this->rtl) {
  6452. $this->endlinex = $startx - $linew;
  6453. } else {
  6454. $this->endlinex = $startx + $linew;
  6455. }
  6456. $w = $linew;
  6457. $tmpcellpadding = $this->cell_padding;
  6458. if ($maxh == 0) {
  6459. $this->SetCellPadding(0);
  6460. }
  6461. }
  6462. if ($firstblock AND $this->isRTLTextDir()) {
  6463. $tmpstr = $this->stringRightTrim($tmpstr);
  6464. }
  6465. $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
  6466. unset($tmpstr);
  6467. if ($firstline) {
  6468. $this->cell_padding = $tmpcellpadding;
  6469. return (TCPDF_FONTS::UniArrSubString($uchars, $nb));
  6470. }
  6471. ++$nl;
  6472. }
  6473. if ($firstline) {
  6474. return '';
  6475. }
  6476. return $nl;
  6477. }
  6478. /**
  6479. * Returns the remaining width between the current position and margins.
  6480. * @return int Return the remaining width
  6481. * @protected
  6482. */
  6483. protected function getRemainingWidth()
  6484. {
  6485. list($this->x, $this->y) = $this->checkPageRegions(0, $this->x, $this->y);
  6486. if ($this->rtl) {
  6487. return ($this->x - $this->lMargin);
  6488. } else {
  6489. return ($this->w - $this->rMargin - $this->x);
  6490. }
  6491. }
  6492. /**
  6493. * Set the block dimensions accounting for page breaks and page/column fitting
  6494. * @param $w (float) width
  6495. * @param $h (float) height
  6496. * @param $x (float) X coordinate
  6497. * @param $y (float) Y coodiante
  6498. * @param $fitonpage (boolean) if true the block is resized to not exceed page dimensions.
  6499. * @return array($w, $h, $x, $y)
  6500. * @protected
  6501. * @since 5.5.009 (2010-07-05)
  6502. */
  6503. protected function fitBlock($w, $h, $x, $y, $fitonpage = false)
  6504. {
  6505. if ($w <= 0) {
  6506. // set maximum width
  6507. $w = ($this->w - $this->lMargin - $this->rMargin);
  6508. if ($w <= 0) {
  6509. $w = 1;
  6510. }
  6511. }
  6512. if ($h <= 0) {
  6513. // set maximum height
  6514. $h = ($this->PageBreakTrigger - $this->tMargin);
  6515. if ($h <= 0) {
  6516. $h = 1;
  6517. }
  6518. }
  6519. // resize the block to be vertically contained on a single page or single column
  6520. if ($fitonpage OR $this->AutoPageBreak) {
  6521. $ratio_wh = ($w / $h);
  6522. if ($h > ($this->PageBreakTrigger - $this->tMargin)) {
  6523. $h = $this->PageBreakTrigger - $this->tMargin;
  6524. $w = ($h * $ratio_wh);
  6525. }
  6526. // resize the block to be horizontally contained on a single page or single column
  6527. if ($fitonpage) {
  6528. $maxw = ($this->w - $this->lMargin - $this->rMargin);
  6529. if ($w > $maxw) {
  6530. $w = $maxw;
  6531. $h = ($w / $ratio_wh);
  6532. }
  6533. }
  6534. }
  6535. // Check whether we need a new page or new column first as this does not fit
  6536. $prev_x = $this->x;
  6537. $prev_y = $this->y;
  6538. if ($this->checkPageBreak($h, $y) OR ($this->y < $prev_y)) {
  6539. $y = $this->y;
  6540. if ($this->rtl) {
  6541. $x += ($prev_x - $this->x);
  6542. } else {
  6543. $x += ($this->x - $prev_x);
  6544. }
  6545. $this->newline = true;
  6546. }
  6547. // resize the block to be contained on the remaining available page or column space
  6548. if ($fitonpage) {
  6549. $ratio_wh = ($w / $h);
  6550. if (($y + $h) > $this->PageBreakTrigger) {
  6551. $h = $this->PageBreakTrigger - $y;
  6552. $w = ($h * $ratio_wh);
  6553. }
  6554. if ((!$this->rtl) AND (($x + $w) > ($this->w - $this->rMargin))) {
  6555. $w = $this->w - $this->rMargin - $x;
  6556. $h = ($w / $ratio_wh);
  6557. } elseif (($this->rtl) AND (($x - $w) < ($this->lMargin))) {
  6558. $w = $x - $this->lMargin;
  6559. $h = ($w / $ratio_wh);
  6560. }
  6561. }
  6562. return array($w, $h, $x, $y);
  6563. }
  6564. /**
  6565. * Puts an image in the page.
  6566. * The upper-left corner must be given.
  6567. * The dimensions can be specified in different ways:<ul>
  6568. * <li>explicit width and height (expressed in user unit)</li>
  6569. * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
  6570. * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  6571. * 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;
  6572. * The format can be specified explicitly or inferred from the file extension.<br />
  6573. * It is possible to put a link on the image.<br />
  6574. * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  6575. * @param $file (string) Name of the file containing the image or a '@' character followed by the image data string. To link an image without embedding it on the document, set an asterisk character before the URL (i.e.: '*http://www.example.com/image.jpg').
  6576. * @param $x (float) Abscissa of the upper-left corner (LTR) or upper-right corner (RTL).
  6577. * @param $y (float) Ordinate of the upper-left corner (LTR) or upper-right corner (RTL).
  6578. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6579. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6580. * @param $type (string) Image format. Possible values are (case insensitive): JPEG and PNG (whitout GD library) and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;. If not specified, the type is inferred from the file extension.
  6581. * @param $link (mixed) URL or identifier returned by AddLink().
  6582. * @param $align (string) Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  6583. * @param $resize (mixed) If true resize (reduce) the image to fit $w and $h (requires GD or ImageMagick library); if false do not resize; if 2 force resize in all cases (upscaling and downscaling).
  6584. * @param $dpi (int) dot-per-inch resolution used on resize
  6585. * @param $palign (string) Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  6586. * @param $ismask (boolean) true if this image is a mask, false otherwise
  6587. * @param $imgmask (mixed) image object returned by this function or false
  6588. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  6589. * @param $fitbox (mixed) If not false scale image dimensions proportionally to fit within the ($w, $h) box. $fitbox can be true or a 2 characters string indicating the image alignment inside the box. The first character indicate the horizontal alignment (L = left, C = center, R = right) the second character indicate the vertical algnment (T = top, M = middle, B = bottom).
  6590. * @param $hidden (boolean) If true do not display the image.
  6591. * @param $fitonpage (boolean) If true the image is resized to not exceed page dimensions.
  6592. * @param $alt (boolean) If true the image will be added as alternative and not directly printed (the ID of the image will be returned).
  6593. * @param $altimgs (array) Array of alternate images IDs. Each alternative image must be an array with two values: an integer representing the image ID (the value returned by the Image method) and a boolean value to indicate if the image is the default for printing.
  6594. * @return image information
  6595. * @public
  6596. * @since 1.1
  6597. */
  6598. public function Image($file, $x = '', $y = '', $w = 0, $h = 0, $type = '', $link = '', $align = '', $resize = false, $dpi = 300, $palign = '', $ismask = false, $imgmask = false, $border = 0, $fitbox = false, $hidden = false, $fitonpage = false, $alt = false, $altimgs = array())
  6599. {
  6600. if ($this->state != 2) {
  6601. return;
  6602. }
  6603. if (strcmp($x, '') === 0) {
  6604. $x = $this->x;
  6605. }
  6606. if (strcmp($y, '') === 0) {
  6607. $y = $this->y;
  6608. }
  6609. // check page for no-write regions and adapt page margins if necessary
  6610. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  6611. $exurl = ''; // external streams
  6612. $imsize = false;
  6613. // check if we are passing an image as file or string
  6614. if ($file[0] === '@') {
  6615. // image from string
  6616. $imgdata = substr($file, 1);
  6617. } else { // image file
  6618. if ($file[0] === '*') {
  6619. // image as external stream
  6620. $file = substr($file, 1);
  6621. $exurl = $file;
  6622. }
  6623. // check if file exist and it is valid
  6624. if (!@TCPDF_STATIC::file_exists($file)) {
  6625. // DOL CHANGE If we keep this, the image is not visible on pages after the first one.
  6626. //var_dump($file.' '.(!@TCPDF_STATIC::file_exists($file)));
  6627. //return false;
  6628. // try to encode spaces on filename
  6629. $tfile = str_replace(' ', '%20', $file);
  6630. if (@TCPDF_STATIC::file_exists($tfile)) {
  6631. $file = $tfile;
  6632. }
  6633. }
  6634. if (($imsize = @getimagesize($file)) === false) {
  6635. if (in_array($file, $this->imagekeys)) {
  6636. // get existing image data
  6637. $info = $this->getImageBuffer($file);
  6638. $imsize = array($info['w'], $info['h']);
  6639. } elseif (strpos($file, '__tcpdf_'.$this->file_id.'_img') === false) {
  6640. $imgdata = TCPDF_STATIC::fileGetContents($file);
  6641. }
  6642. }
  6643. }
  6644. if (!empty($imgdata)) {
  6645. // copy image to cache
  6646. $original_file = $file;
  6647. $file = TCPDF_STATIC::getObjFilename('img', $this->file_id);
  6648. $fp = TCPDF_STATIC::fopenLocal($file, 'w');
  6649. if (!$fp) {
  6650. $this->Error('Unable to write file: '.$file);
  6651. }
  6652. fwrite($fp, $imgdata);
  6653. fclose($fp);
  6654. unset($imgdata);
  6655. $imsize = @getimagesize($file);
  6656. if ($imsize === false) {
  6657. unlink($file);
  6658. $file = $original_file;
  6659. }
  6660. }
  6661. if ($imsize === false) {
  6662. if (($w > 0) AND ($h > 0)) {
  6663. // get measures from specified data
  6664. $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  6665. $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  6666. $imsize = array($pw, $ph);
  6667. } else {
  6668. $this->Error('[Image] Unable to get the size of the image: '.$file);
  6669. }
  6670. }
  6671. // file hash
  6672. $filehash = md5($file);
  6673. // get original image width and height in pixels
  6674. list($pixw, $pixh) = $imsize;
  6675. // calculate image width and height on document
  6676. if (($w <= 0) AND ($h <= 0)) {
  6677. // convert image size to document unit
  6678. $w = $this->pixelsToUnits($pixw);
  6679. $h = $this->pixelsToUnits($pixh);
  6680. } elseif ($w <= 0) {
  6681. $w = $h * $pixw / $pixh;
  6682. } elseif ($h <= 0) {
  6683. $h = $w * $pixh / $pixw;
  6684. } elseif (($fitbox !== false) AND ($w > 0) AND ($h > 0)) {
  6685. if (strlen($fitbox) !== 2) {
  6686. // set default alignment
  6687. $fitbox = '--';
  6688. }
  6689. // scale image dimensions proportionally to fit within the ($w, $h) box
  6690. if ((($w * $pixh) / ($h * $pixw)) < 1) {
  6691. // store current height
  6692. $oldh = $h;
  6693. // calculate new height
  6694. $h = $w * $pixh / $pixw;
  6695. // height difference
  6696. $hdiff = ($oldh - $h);
  6697. // vertical alignment
  6698. switch (strtoupper($fitbox[1])) {
  6699. case 'T': {
  6700. break;
  6701. }
  6702. case 'M': {
  6703. $y += ($hdiff / 2);
  6704. break;
  6705. }
  6706. case 'B': {
  6707. $y += $hdiff;
  6708. break;
  6709. }
  6710. }
  6711. } else {
  6712. // store current width
  6713. $oldw = $w;
  6714. // calculate new width
  6715. $w = $h * $pixw / $pixh;
  6716. // width difference
  6717. $wdiff = ($oldw - $w);
  6718. // horizontal alignment
  6719. switch (strtoupper($fitbox[0])) {
  6720. case 'L': {
  6721. if ($this->rtl) {
  6722. $x -= $wdiff;
  6723. }
  6724. break;
  6725. }
  6726. case 'C': {
  6727. if ($this->rtl) {
  6728. $x -= ($wdiff / 2);
  6729. } else {
  6730. $x += ($wdiff / 2);
  6731. }
  6732. break;
  6733. }
  6734. case 'R': {
  6735. if (!$this->rtl) {
  6736. $x += $wdiff;
  6737. }
  6738. break;
  6739. }
  6740. }
  6741. }
  6742. }
  6743. // fit the image on available space
  6744. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  6745. // calculate new minimum dimensions in pixels
  6746. $neww = round($w * $this->k * $dpi / $this->dpi);
  6747. $newh = round($h * $this->k * $dpi / $this->dpi);
  6748. // check if resize is necessary (resize is used only to reduce the image)
  6749. $newsize = ($neww * $newh);
  6750. $pixsize = ($pixw * $pixh);
  6751. if (intval($resize) == 2) {
  6752. $resize = true;
  6753. } elseif ($newsize >= $pixsize) {
  6754. $resize = false;
  6755. }
  6756. // check if image has been already added on document
  6757. $newimage = true;
  6758. if (in_array($file, $this->imagekeys)) {
  6759. $newimage = false;
  6760. // get existing image data
  6761. $info = $this->getImageBuffer($file);
  6762. if (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === false) {
  6763. // check if the newer image is larger
  6764. $oldsize = ($info['w'] * $info['h']);
  6765. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  6766. $newimage = true;
  6767. }
  6768. }
  6769. } elseif (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === false)) {
  6770. // create temp image file (without alpha channel)
  6771. $tempfile_plain = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_plain_'.$filehash;
  6772. // create temp alpha file
  6773. $tempfile_alpha = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_alpha_'.$filehash;
  6774. // check for cached images
  6775. if (in_array($tempfile_plain, $this->imagekeys)) {
  6776. // get existing image data
  6777. $info = $this->getImageBuffer($tempfile_plain);
  6778. // check if the newer image is larger
  6779. $oldsize = ($info['w'] * $info['h']);
  6780. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  6781. $newimage = true;
  6782. } else {
  6783. $newimage = false;
  6784. // embed mask image
  6785. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  6786. // embed image, masked with previously embedded mask
  6787. return $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  6788. }
  6789. }
  6790. }
  6791. if ($newimage) {
  6792. //First use of image, get info
  6793. $type = strtolower($type);
  6794. if ($type == '') {
  6795. $type = TCPDF_IMAGES::getImageFileType($file, $imsize);
  6796. } elseif ($type == 'jpg') {
  6797. $type = 'jpeg';
  6798. }
  6799. $mqr = TCPDF_STATIC::get_mqr();
  6800. TCPDF_STATIC::set_mqr(false);
  6801. // Specific image handlers (defined on TCPDF_IMAGES CLASS)
  6802. $mtd = '_parse'.$type;
  6803. // GD image handler function
  6804. $gdfunction = 'imagecreatefrom'.$type;
  6805. $info = false;
  6806. if ((method_exists('TCPDF_IMAGES', $mtd)) AND (!($resize AND (function_exists($gdfunction) OR extension_loaded('imagick'))))) {
  6807. // TCPDF image functions
  6808. $info = TCPDF_IMAGES::$mtd($file);
  6809. if (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === false)
  6810. AND (($info === 'pngalpha') OR (isset($info['trns']) AND !empty($info['trns'])))) {
  6811. return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign, $filehash);
  6812. }
  6813. }
  6814. if (($info === false) AND function_exists($gdfunction)) {
  6815. try {
  6816. // GD library
  6817. $img = $gdfunction($file);
  6818. if ($img !== false) {
  6819. if ($resize) {
  6820. $imgr = imagecreatetruecolor($neww, $newh);
  6821. if (($type == 'gif') OR ($type == 'png')) {
  6822. $imgr = TCPDF_IMAGES::setGDImageTransparency($imgr, $img);
  6823. }
  6824. imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
  6825. $img = $imgr;
  6826. }
  6827. if (($type == 'gif') OR ($type == 'png')) {
  6828. $info = TCPDF_IMAGES::_toPNG($img, TCPDF_STATIC::getObjFilename('img', $this->file_id));
  6829. } else {
  6830. $info = TCPDF_IMAGES::_toJPEG($img, $this->jpeg_quality, TCPDF_STATIC::getObjFilename('img', $this->file_id));
  6831. }
  6832. }
  6833. } catch (Exception $e) {
  6834. $info = false;
  6835. }
  6836. }
  6837. if (($info === false) AND extension_loaded('imagick')) {
  6838. try {
  6839. // ImageMagick library
  6840. $img = new Imagick();
  6841. if ($type == 'svg') {
  6842. if ($file[0] === '@') {
  6843. // image from string
  6844. $svgimg = substr($file, 1);
  6845. } else {
  6846. // get SVG file content
  6847. $svgimg = TCPDF_STATIC::fileGetContents($file);
  6848. }
  6849. if ($svgimg !== false) {
  6850. // get width and height
  6851. $regs = array();
  6852. if (preg_match('/<svg([^\>]*)>/si', $svgimg, $regs)) {
  6853. $svgtag = $regs[1];
  6854. $tmp = array();
  6855. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  6856. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  6857. $owu = sprintf('%F', ($ow * $dpi / 72)).$this->pdfunit;
  6858. $svgtag = preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si', ' width="'.$owu.'"', $svgtag, 1);
  6859. } else {
  6860. $ow = $w;
  6861. }
  6862. $tmp = array();
  6863. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  6864. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  6865. $ohu = sprintf('%F', ($oh * $dpi / 72)).$this->pdfunit;
  6866. $svgtag = preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si', ' height="'.$ohu.'"', $svgtag, 1);
  6867. } else {
  6868. $oh = $h;
  6869. }
  6870. $tmp = array();
  6871. if (!preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $svgtag, $tmp)) {
  6872. $vbw = ($ow * $this->imgscale * $this->k);
  6873. $vbh = ($oh * $this->imgscale * $this->k);
  6874. $vbox = sprintf(' viewBox="0 0 %F %F" ', $vbw, $vbh);
  6875. $svgtag = $vbox.$svgtag;
  6876. }
  6877. $svgimg = preg_replace('/<svg([^\>]*)>/si', '<svg'.$svgtag.'>', $svgimg, 1);
  6878. }
  6879. $img->readImageBlob($svgimg);
  6880. }
  6881. } else {
  6882. $img->readImage($file);
  6883. }
  6884. if ($resize) {
  6885. $img->resizeImage($neww, $newh, 10, 1, false);
  6886. }
  6887. $img->setCompressionQuality($this->jpeg_quality);
  6888. $img->setImageFormat('jpeg');
  6889. $tempname = TCPDF_STATIC::getObjFilename('img', $this->file_id);
  6890. $img->writeImage($tempname);
  6891. $info = TCPDF_IMAGES::_parsejpeg($tempname);
  6892. unlink($tempname);
  6893. $img->destroy();
  6894. } catch (Exception $e) {
  6895. $info = false;
  6896. }
  6897. }
  6898. if ($info === false) {
  6899. // unable to process image
  6900. return;
  6901. }
  6902. TCPDF_STATIC::set_mqr($mqr);
  6903. if ($ismask) {
  6904. // force grayscale
  6905. $info['cs'] = 'DeviceGray';
  6906. }
  6907. if ($imgmask !== false) {
  6908. $info['masked'] = $imgmask;
  6909. }
  6910. if (!empty($exurl)) {
  6911. $info['exurl'] = $exurl;
  6912. }
  6913. // array of alternative images
  6914. $info['altimgs'] = $altimgs;
  6915. // add image to document
  6916. $info['i'] = $this->setImageBuffer($file, $info);
  6917. }
  6918. // set alignment
  6919. $this->img_rb_y = $y + $h;
  6920. // set alignment
  6921. if ($this->rtl) {
  6922. if ($palign == 'L') {
  6923. $ximg = $this->lMargin;
  6924. } elseif ($palign == 'C') {
  6925. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  6926. } elseif ($palign == 'R') {
  6927. $ximg = $this->w - $this->rMargin - $w;
  6928. } else {
  6929. $ximg = $x - $w;
  6930. }
  6931. $this->img_rb_x = $ximg;
  6932. } else {
  6933. if ($palign == 'L') {
  6934. $ximg = $this->lMargin;
  6935. } elseif ($palign == 'C') {
  6936. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  6937. } elseif ($palign == 'R') {
  6938. $ximg = $this->w - $this->rMargin - $w;
  6939. } else {
  6940. $ximg = $x;
  6941. }
  6942. $this->img_rb_x = $ximg + $w;
  6943. }
  6944. if ($ismask OR $hidden) {
  6945. // image is not displayed
  6946. return $info['i'];
  6947. }
  6948. $xkimg = $ximg * $this->k;
  6949. if (!$alt) {
  6950. // only non-alternative immages will be set
  6951. $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']));
  6952. }
  6953. if (!empty($border)) {
  6954. $bx = $this->x;
  6955. $by = $this->y;
  6956. $this->x = $ximg;
  6957. if ($this->rtl) {
  6958. $this->x += $w;
  6959. }
  6960. $this->y = $y;
  6961. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  6962. $this->x = $bx;
  6963. $this->y = $by;
  6964. }
  6965. if ($link) {
  6966. $this->Link($ximg, $y, $w, $h, $link, 0);
  6967. }
  6968. // set pointer to align the next text/objects
  6969. switch ($align) {
  6970. case 'T': {
  6971. $this->y = $y;
  6972. $this->x = $this->img_rb_x;
  6973. break;
  6974. }
  6975. case 'M': {
  6976. $this->y = $y + round($h/2);
  6977. $this->x = $this->img_rb_x;
  6978. break;
  6979. }
  6980. case 'B': {
  6981. $this->y = $this->img_rb_y;
  6982. $this->x = $this->img_rb_x;
  6983. break;
  6984. }
  6985. case 'N': {
  6986. $this->SetY($this->img_rb_y);
  6987. break;
  6988. }
  6989. default:{
  6990. break;
  6991. }
  6992. }
  6993. $this->endlinex = $this->img_rb_x;
  6994. if ($this->inxobj) {
  6995. // we are inside an XObject template
  6996. $this->xobjects[$this->xobjid]['images'][] = $info['i'];
  6997. }
  6998. return $info['i'];
  6999. }
  7000. /**
  7001. * Extract info from a PNG image with alpha channel using the Imagick or GD library.
  7002. * @param $file (string) Name of the file containing the image.
  7003. * @param $x (float) Abscissa of the upper-left corner.
  7004. * @param $y (float) Ordinate of the upper-left corner.
  7005. * @param $wpx (float) Original width of the image in pixels.
  7006. * @param $hpx (float) original height of the image in pixels.
  7007. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  7008. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  7009. * @param $type (string) Image format. Possible values are (case insensitive): JPEG and PNG (whitout GD library) and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;. If not specified, the type is inferred from the file extension.
  7010. * @param $link (mixed) URL or identifier returned by AddLink().
  7011. * @param $align (string) Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  7012. * @param $resize (boolean) If true resize (reduce) the image to fit $w and $h (requires GD library).
  7013. * @param $dpi (int) dot-per-inch resolution used on resize
  7014. * @param $palign (string) Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  7015. * @param $filehash (string) File hash used to build unique file names.
  7016. * @author Nicola Asuni
  7017. * @protected
  7018. * @since 4.3.007 (2008-12-04)
  7019. * @see Image()
  7020. */
  7021. protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $filehash = '')
  7022. {
  7023. // create temp images
  7024. if (empty($filehash)) {
  7025. $filehash = md5($file);
  7026. }
  7027. // create temp image file (without alpha channel)
  7028. $tempfile_plain = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_plain_'.$filehash;
  7029. // create temp alpha file
  7030. $tempfile_alpha = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_alpha_'.$filehash;
  7031. $parsed = false;
  7032. $parse_error = '';
  7033. // ImageMagick extension
  7034. if (($parsed === false) AND extension_loaded('imagick')) {
  7035. try {
  7036. // ImageMagick library
  7037. $img = new Imagick();
  7038. $img->readImage($file);
  7039. // clone image object
  7040. $imga = TCPDF_STATIC::objclone($img);
  7041. // extract alpha channel
  7042. if (method_exists($img, 'setImageAlphaChannel') AND defined('Imagick::ALPHACHANNEL_EXTRACT')) {
  7043. $img->setImageAlphaChannel(Imagick::ALPHACHANNEL_EXTRACT);
  7044. } else {
  7045. $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE);
  7046. $img->negateImage(true);
  7047. }
  7048. $img->setImageFormat('png');
  7049. $img->writeImage($tempfile_alpha);
  7050. // remove alpha channel
  7051. if (method_exists($imga, 'setImageMatte')) {
  7052. $imga->setImageMatte(false);
  7053. } else {
  7054. $imga->separateImageChannel(39); // 39 = (imagick::CHANNEL_ALL & ~(imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE));
  7055. }
  7056. $imga->setImageFormat('png');
  7057. $imga->writeImage($tempfile_plain);
  7058. $parsed = true;
  7059. } catch (Exception $e) {
  7060. // Imagemagick fails, try with GD
  7061. $parse_error = 'Imagick library error: '.$e->getMessage();
  7062. }
  7063. }
  7064. // GD extension
  7065. if (($parsed === false) AND function_exists('imagecreatefrompng')) {
  7066. try {
  7067. // generate images
  7068. $img = imagecreatefrompng($file);
  7069. $imgalpha = imagecreate($wpx, $hpx);
  7070. // generate gray scale palette (0 -> 255)
  7071. for ($c = 0; $c < 256; ++$c) {
  7072. ImageColorAllocate($imgalpha, $c, $c, $c);
  7073. }
  7074. // extract alpha channel
  7075. for ($xpx = 0; $xpx < $wpx; ++$xpx) {
  7076. for ($ypx = 0; $ypx < $hpx; ++$ypx) {
  7077. $color = imagecolorat($img, $xpx, $ypx);
  7078. // get and correct gamma color
  7079. $alpha = $this->getGDgamma($img, $color);
  7080. imagesetpixel($imgalpha, $xpx, $ypx, $alpha);
  7081. }
  7082. }
  7083. imagepng($imgalpha, $tempfile_alpha);
  7084. imagedestroy($imgalpha);
  7085. // extract image without alpha channel
  7086. $imgplain = imagecreatetruecolor($wpx, $hpx);
  7087. imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
  7088. imagepng($imgplain, $tempfile_plain);
  7089. imagedestroy($imgplain);
  7090. $parsed = true;
  7091. } catch (Exception $e) {
  7092. // GD fails
  7093. $parse_error = 'GD library error: '.$e->getMessage();
  7094. }
  7095. }
  7096. if ($parsed === false) {
  7097. if (empty($parse_error)) {
  7098. $this->Error('TCPDF requires the Imagick or GD extension to handle PNG images with alpha channel.');
  7099. } else {
  7100. $this->Error($parse_error);
  7101. }
  7102. }
  7103. // embed mask image
  7104. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  7105. // embed image, masked with previously embedded mask
  7106. $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  7107. }
  7108. /**
  7109. * Get the GD-corrected PNG gamma value from alpha color
  7110. * @param $img (int) GD image Resource ID.
  7111. * @param $c (int) alpha color
  7112. * @protected
  7113. * @since 4.3.007 (2008-12-04)
  7114. */
  7115. protected function getGDgamma($img, $c)
  7116. {
  7117. if (!isset($this->gdgammacache['#'.$c])) {
  7118. $colors = imagecolorsforindex($img, $c);
  7119. // GD alpha is only 7 bit (0 -> 127)
  7120. $this->gdgammacache['#'.$c] = (((127 - $colors['alpha']) / 127) * 255);
  7121. // correct gamma
  7122. $this->gdgammacache['#'.$c] = (pow(($this->gdgammacache['#'.$c] / 255), 2.2) * 255);
  7123. // store the latest values on cache to improve performances
  7124. if (count($this->gdgammacache) > 8) {
  7125. // remove one element from the cache array
  7126. array_shift($this->gdgammacache);
  7127. }
  7128. }
  7129. return $this->gdgammacache['#'.$c];
  7130. }
  7131. /**
  7132. * Performs a line break.
  7133. * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  7134. * @param $h (float) The height of the break. By default, the value equals the height of the last printed cell.
  7135. * @param $cell (boolean) if true add the current left (or right o for RTL) padding to the X coordinate
  7136. * @public
  7137. * @since 1.0
  7138. * @see Cell()
  7139. */
  7140. public function Ln($h = '', $cell = false)
  7141. {
  7142. 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'])) {
  7143. // revove vertical space from the top of the column
  7144. return;
  7145. }
  7146. if ($cell) {
  7147. if ($this->rtl) {
  7148. $cellpadding = $this->cell_padding['R'];
  7149. } else {
  7150. $cellpadding = $this->cell_padding['L'];
  7151. }
  7152. } else {
  7153. $cellpadding = 0;
  7154. }
  7155. if ($this->rtl) {
  7156. $this->x = $this->w - $this->rMargin - $cellpadding;
  7157. } else {
  7158. $this->x = $this->lMargin + $cellpadding;
  7159. }
  7160. if (is_string($h)) {
  7161. $h = $this->lasth;
  7162. }
  7163. $this->y += $h;
  7164. $this->newline = true;
  7165. }
  7166. /**
  7167. * Returns the relative X value of current position.
  7168. * The value is relative to the left border for LTR languages and to the right border for RTL languages.
  7169. * @return float
  7170. * @public
  7171. * @since 1.2
  7172. * @see SetX(), GetY(), SetY()
  7173. */
  7174. public function GetX()
  7175. {
  7176. //Get x position
  7177. if ($this->rtl) {
  7178. return ($this->w - $this->x);
  7179. } else {
  7180. return $this->x;
  7181. }
  7182. }
  7183. /**
  7184. * Returns the absolute X value of current position.
  7185. * @return float
  7186. * @public
  7187. * @since 1.2
  7188. * @see SetX(), GetY(), SetY()
  7189. */
  7190. public function GetAbsX()
  7191. {
  7192. return $this->x;
  7193. }
  7194. /**
  7195. * Returns the ordinate of the current position.
  7196. * @return float
  7197. * @public
  7198. * @since 1.0
  7199. * @see SetY(), GetX(), SetX()
  7200. */
  7201. public function GetY()
  7202. {
  7203. return $this->y;
  7204. }
  7205. /**
  7206. * Defines the abscissa of the current position.
  7207. * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
  7208. * @param $x (float) The value of the abscissa in user units.
  7209. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  7210. * @public
  7211. * @since 1.2
  7212. * @see GetX(), GetY(), SetY(), SetXY()
  7213. */
  7214. public function SetX($x, $rtloff = false)
  7215. {
  7216. $x = floatval($x);
  7217. if (!$rtloff AND $this->rtl) {
  7218. if ($x >= 0) {
  7219. $this->x = $this->w - $x;
  7220. } else {
  7221. $this->x = abs($x);
  7222. }
  7223. } else {
  7224. if ($x >= 0) {
  7225. $this->x = $x;
  7226. } else {
  7227. $this->x = $this->w + $x;
  7228. }
  7229. }
  7230. if ($this->x < 0) {
  7231. $this->x = 0;
  7232. }
  7233. if ($this->x > $this->w) {
  7234. $this->x = $this->w;
  7235. }
  7236. }
  7237. /**
  7238. * Moves the current abscissa back to the left margin and sets the ordinate.
  7239. * If the passed value is negative, it is relative to the bottom of the page.
  7240. * @param $y (float) The value of the ordinate in user units.
  7241. * @param $resetx (bool) if true (default) reset the X position.
  7242. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  7243. * @public
  7244. * @since 1.0
  7245. * @see GetX(), GetY(), SetY(), SetXY()
  7246. */
  7247. public function SetY($y, $resetx = true, $rtloff = false)
  7248. {
  7249. $y = floatval($y);
  7250. if ($resetx) {
  7251. //reset x
  7252. if (!$rtloff AND $this->rtl) {
  7253. $this->x = $this->w - $this->rMargin;
  7254. } else {
  7255. $this->x = $this->lMargin;
  7256. }
  7257. }
  7258. if ($y >= 0) {
  7259. $this->y = $y;
  7260. } else {
  7261. $this->y = $this->h + $y;
  7262. }
  7263. if ($this->y < 0) {
  7264. $this->y = 0;
  7265. }
  7266. if ($this->y > $this->h) {
  7267. $this->y = $this->h;
  7268. }
  7269. }
  7270. /**
  7271. * Defines the abscissa and ordinate of the current position.
  7272. * If the passed values are negative, they are relative respectively to the right and bottom of the page.
  7273. * @param $x (float) The value of the abscissa.
  7274. * @param $y (float) The value of the ordinate.
  7275. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  7276. * @public
  7277. * @since 1.2
  7278. * @see SetX(), SetY()
  7279. */
  7280. public function SetXY($x, $y, $rtloff = false)
  7281. {
  7282. $this->SetY($y, false, $rtloff);
  7283. $this->SetX($x, $rtloff);
  7284. }
  7285. /**
  7286. * Set the absolute X coordinate of the current pointer.
  7287. * @param $x (float) The value of the abscissa in user units.
  7288. * @public
  7289. * @since 5.9.186 (2012-09-13)
  7290. * @see setAbsX(), setAbsY(), SetAbsXY()
  7291. */
  7292. public function SetAbsX($x)
  7293. {
  7294. $this->x = floatval($x);
  7295. }
  7296. /**
  7297. * Set the absolute Y coordinate of the current pointer.
  7298. * @param $y (float) (float) The value of the ordinate in user units.
  7299. * @public
  7300. * @since 5.9.186 (2012-09-13)
  7301. * @see setAbsX(), setAbsY(), SetAbsXY()
  7302. */
  7303. public function SetAbsY($y)
  7304. {
  7305. $this->y = floatval($y);
  7306. }
  7307. /**
  7308. * Set the absolute X and Y coordinates of the current pointer.
  7309. * @param $x (float) The value of the abscissa in user units.
  7310. * @param $y (float) (float) The value of the ordinate in user units.
  7311. * @public
  7312. * @since 5.9.186 (2012-09-13)
  7313. * @see setAbsX(), setAbsY(), SetAbsXY()
  7314. */
  7315. public function SetAbsXY($x, $y)
  7316. {
  7317. $this->SetAbsX($x);
  7318. $this->SetAbsY($y);
  7319. }
  7320. /**
  7321. * Send the document to a given destination: string, local file or browser.
  7322. * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  7323. * The method first calls Close() if necessary to terminate the document.
  7324. * @param $name (string) The name of the file when saved. Note that special characters are removed and blanks characters are replaced with the underscore character.
  7325. * @param $dest (string) Destination where to send the document. It can take one of the following values:<ul><li>I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.</li><li>D: send to the browser and force a file download with the name given by name.</li><li>F: save to a local server file with the name given by name.</li><li>S: return the document as a string (name is ignored).</li><li>FI: equivalent to F + I option</li><li>FD: equivalent to F + D option</li><li>E: return the document as base64 mime multi-part email attachment (RFC 2045)</li></ul>
  7326. * @return string
  7327. * @public
  7328. * @since 1.0
  7329. * @see Close()
  7330. */
  7331. public function Output($name = 'doc.pdf', $dest = 'I')
  7332. {
  7333. //Output PDF to some destination
  7334. //Finish document if necessary
  7335. if ($this->state < 3) {
  7336. $this->Close();
  7337. }
  7338. //Normalize parameters
  7339. if (is_bool($dest)) {
  7340. $dest = $dest ? 'D' : 'F';
  7341. }
  7342. $dest = strtoupper($dest);
  7343. if ($dest[0] != 'F') {
  7344. $name = preg_replace('/[\s]+/', '_', $name);
  7345. $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name);
  7346. }
  7347. if ($this->sign) {
  7348. // *** apply digital signature to the document ***
  7349. // get the document content
  7350. $pdfdoc = $this->getBuffer();
  7351. // remove last newline
  7352. $pdfdoc = substr($pdfdoc, 0, -1);
  7353. // remove filler space
  7354. $byterange_string_len = strlen(TCPDF_STATIC::$byterange_string);
  7355. // define the ByteRange
  7356. $byte_range = array();
  7357. $byte_range[0] = 0;
  7358. $byte_range[1] = strpos($pdfdoc, TCPDF_STATIC::$byterange_string) + $byterange_string_len + 10;
  7359. $byte_range[2] = $byte_range[1] + $this->signature_max_length + 2;
  7360. $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
  7361. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).substr($pdfdoc, $byte_range[2]);
  7362. // replace the ByteRange
  7363. $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]);
  7364. $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
  7365. $pdfdoc = str_replace(TCPDF_STATIC::$byterange_string, $byterange, $pdfdoc);
  7366. // write the document to a temporary folder
  7367. $tempdoc = TCPDF_STATIC::getObjFilename('doc', $this->file_id);
  7368. $f = TCPDF_STATIC::fopenLocal($tempdoc, 'wb');
  7369. if (!$f) {
  7370. $this->Error('Unable to create temporary file: '.$tempdoc);
  7371. }
  7372. $pdfdoc_length = strlen($pdfdoc);
  7373. fwrite($f, $pdfdoc, $pdfdoc_length);
  7374. fclose($f);
  7375. // get digital signature via openssl library
  7376. $tempsign = TCPDF_STATIC::getObjFilename('sig', $this->file_id);
  7377. if (empty($this->signature_data['extracerts'])) {
  7378. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED);
  7379. } else {
  7380. 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']);
  7381. }
  7382. // read signature
  7383. $signature = file_get_contents($tempsign);
  7384. // extract signature
  7385. $signature = substr($signature, $pdfdoc_length);
  7386. $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13));
  7387. $tmparr = explode("\n\n", $signature);
  7388. $signature = $tmparr[1];
  7389. // decode signature
  7390. $signature = base64_decode(trim($signature));
  7391. // add TSA timestamp to signature
  7392. $signature = $this->applyTSA($signature);
  7393. // convert signature to hex
  7394. $signature = current(unpack('H*', $signature));
  7395. $signature = str_pad($signature, $this->signature_max_length, '0');
  7396. // Add signature to the document
  7397. $this->buffer = substr($pdfdoc, 0, $byte_range[1]).'<'.$signature.'>'.substr($pdfdoc, $byte_range[1]);
  7398. $this->bufferlen = strlen($this->buffer);
  7399. }
  7400. switch ($dest) {
  7401. case 'I': {
  7402. // Send PDF to the standard output
  7403. if (ob_get_contents()) {
  7404. $this->Error('Some data has already been output, can\'t send PDF file');
  7405. }
  7406. if (php_sapi_name() != 'cli') {
  7407. // send output to a browser
  7408. header('Content-Type: application/pdf');
  7409. if (headers_sent()) {
  7410. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7411. }
  7412. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7413. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7414. header('Pragma: public');
  7415. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7416. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7417. header('Content-Disposition: inline; filename="'.basename($name).'"');
  7418. TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
  7419. } else {
  7420. echo $this->getBuffer();
  7421. }
  7422. break;
  7423. }
  7424. case 'D': {
  7425. // download PDF as file
  7426. if (ob_get_contents()) {
  7427. $this->Error('Some data has already been output, can\'t send PDF file');
  7428. }
  7429. header('Content-Description: File Transfer');
  7430. if (headers_sent()) {
  7431. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7432. }
  7433. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7434. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7435. header('Pragma: public');
  7436. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7437. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7438. // force download dialog
  7439. if (strpos(php_sapi_name(), 'cgi') === false) {
  7440. header('Content-Type: application/force-download');
  7441. header('Content-Type: application/octet-stream', false);
  7442. header('Content-Type: application/download', false);
  7443. header('Content-Type: application/pdf', false);
  7444. } else {
  7445. header('Content-Type: application/pdf');
  7446. }
  7447. // use the Content-Disposition header to supply a recommended filename
  7448. header('Content-Disposition: attachment; filename="'.basename($name).'"');
  7449. header('Content-Transfer-Encoding: binary');
  7450. TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
  7451. break;
  7452. }
  7453. case 'F':
  7454. case 'FI':
  7455. case 'FD': {
  7456. // save PDF to a local file
  7457. $f = TCPDF_STATIC::fopenLocal($name, 'wb');
  7458. if (!$f) {
  7459. $this->Error('Unable to create output file: '.$name);
  7460. }
  7461. fwrite($f, $this->getBuffer(), $this->bufferlen);
  7462. fclose($f);
  7463. if ($dest == 'FI') {
  7464. // send headers to browser
  7465. header('Content-Type: application/pdf');
  7466. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7467. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7468. header('Pragma: public');
  7469. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7470. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7471. header('Content-Disposition: inline; filename="'.basename($name).'"');
  7472. TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name));
  7473. } elseif ($dest == 'FD') {
  7474. // send headers to browser
  7475. if (ob_get_contents()) {
  7476. $this->Error('Some data has already been output, can\'t send PDF file');
  7477. }
  7478. header('Content-Description: File Transfer');
  7479. if (headers_sent()) {
  7480. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7481. }
  7482. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7483. header('Pragma: public');
  7484. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7485. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7486. // force download dialog
  7487. if (strpos(php_sapi_name(), 'cgi') === false) {
  7488. header('Content-Type: application/force-download');
  7489. header('Content-Type: application/octet-stream', false);
  7490. header('Content-Type: application/download', false);
  7491. header('Content-Type: application/pdf', false);
  7492. } else {
  7493. header('Content-Type: application/pdf');
  7494. }
  7495. // use the Content-Disposition header to supply a recommended filename
  7496. header('Content-Disposition: attachment; filename="'.basename($name).'"');
  7497. header('Content-Transfer-Encoding: binary');
  7498. TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name));
  7499. }
  7500. break;
  7501. }
  7502. case 'E': {
  7503. // return PDF as base64 mime multi-part email attachment (RFC 2045)
  7504. $retval = 'Content-Type: application/pdf;'."\r\n";
  7505. $retval .= ' name="'.$name.'"'."\r\n";
  7506. $retval .= 'Content-Transfer-Encoding: base64'."\r\n";
  7507. $retval .= 'Content-Disposition: attachment;'."\r\n";
  7508. $retval .= ' filename="'.$name.'"'."\r\n\r\n";
  7509. $retval .= chunk_split(base64_encode($this->getBuffer()), 76, "\r\n");
  7510. return $retval;
  7511. }
  7512. case 'S': {
  7513. // returns PDF as a string
  7514. return $this->getBuffer();
  7515. }
  7516. default: {
  7517. $this->Error('Incorrect output destination: '.$dest);
  7518. }
  7519. }
  7520. return '';
  7521. }
  7522. protected static $cleaned_ids = array();
  7523. /**
  7524. * Unset all class variables except the following critical variables.
  7525. * @param $destroyall (boolean) if true destroys all class variables, otherwise preserves critical variables.
  7526. * @param $preserve_objcopy (boolean) if true preserves the objcopy variable
  7527. * @public
  7528. * @since 4.5.016 (2009-02-24)
  7529. */
  7530. public function _destroy($destroyall = false, $preserve_objcopy = false)
  7531. {
  7532. // restore internal encoding
  7533. if (isset($this->internal_encoding) AND !empty($this->internal_encoding)) {
  7534. mb_internal_encoding($this->internal_encoding);
  7535. }
  7536. if (isset(self::$cleaned_ids[$this->file_id])) {
  7537. $destroyall = false;
  7538. }
  7539. if ($destroyall AND !$preserve_objcopy) {
  7540. self::$cleaned_ids[$this->file_id] = true;
  7541. // remove all temporary files
  7542. if ($handle = opendir(K_PATH_CACHE)) {
  7543. while ( false !== ( $file_name = readdir($handle) ) ) {
  7544. if (strpos($file_name, '__tcpdf_'.$this->file_id.'_') === 0) {
  7545. unlink(K_PATH_CACHE.$file_name);
  7546. }
  7547. }
  7548. closedir($handle);
  7549. }
  7550. if (isset($this->imagekeys)) {
  7551. foreach ($this->imagekeys as $file) {
  7552. // @CHANGE DOL
  7553. // unlink($file);
  7554. }
  7555. }
  7556. }
  7557. $preserve = array(
  7558. 'file_id',
  7559. 'internal_encoding',
  7560. 'state',
  7561. 'bufferlen',
  7562. 'buffer',
  7563. 'cached_files',
  7564. // @CHANGE DOL
  7565. // 'imagekeys',
  7566. 'sign',
  7567. 'signature_data',
  7568. 'signature_max_length',
  7569. 'byterange_string',
  7570. 'tsa_timestamp',
  7571. 'tsa_data'
  7572. );
  7573. foreach (array_keys(get_object_vars($this)) as $val) {
  7574. if ($destroyall OR !in_array($val, $preserve)) {
  7575. if ((!$preserve_objcopy OR ($val != 'objcopy')) AND ($val != 'file_id') AND isset($this->$val)) {
  7576. unset($this->$val);
  7577. }
  7578. }
  7579. }
  7580. }
  7581. /**
  7582. * Check for locale-related bug
  7583. * @protected
  7584. */
  7585. protected function _dochecks()
  7586. {
  7587. //Check for locale-related bug
  7588. if (1.1 == 1) {
  7589. $this->Error('Don\'t alter the locale before including class file');
  7590. }
  7591. //Check for decimal separator
  7592. if (sprintf('%.1F', 1.0) != '1.0') {
  7593. setlocale(LC_NUMERIC, 'C');
  7594. }
  7595. }
  7596. /**
  7597. * Return an array containing variations for the basic page number alias.
  7598. * @param $a (string) Base alias.
  7599. * @return array of page number aliases
  7600. * @protected
  7601. */
  7602. protected function getInternalPageNumberAliases($a = '')
  7603. {
  7604. $alias = array();
  7605. // build array of Unicode + ASCII variants (the order is important)
  7606. $alias = array('u' => array(), 'a' => array());
  7607. $u = '{'.$a.'}';
  7608. $alias['u'][] = TCPDF_STATIC::_escape($u);
  7609. if ($this->isunicode) {
  7610. $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($u, $this->isunicode, $this->CurrentFont));
  7611. $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($u, false, $this->tmprtl, $this->isunicode, $this->CurrentFont));
  7612. $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($a, $this->isunicode, $this->CurrentFont));
  7613. $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($a, false, $this->tmprtl, $this->isunicode, $this->CurrentFont));
  7614. }
  7615. $alias['a'][] = TCPDF_STATIC::_escape($a);
  7616. return $alias;
  7617. }
  7618. /**
  7619. * Return an array containing all internal page aliases.
  7620. * @return array of page number aliases
  7621. * @protected
  7622. */
  7623. protected function getAllInternalPageNumberAliases()
  7624. {
  7625. $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);
  7626. $pnalias = array();
  7627. foreach ($basic_alias as $k => $a) {
  7628. $pnalias[$k] = $this->getInternalPageNumberAliases($a);
  7629. }
  7630. return $pnalias;
  7631. }
  7632. /**
  7633. * Replace right shift page number aliases with spaces to correct right alignment.
  7634. * This works perfectly only when using monospaced fonts.
  7635. * @param $page (string) Page content.
  7636. * @param $aliases (array) Array of page aliases.
  7637. * @param $diff (int) initial difference to add.
  7638. * @return replaced page content.
  7639. * @protected
  7640. */
  7641. protected function replaceRightShiftPageNumAliases($page, $aliases, $diff)
  7642. {
  7643. foreach ($aliases as $type => $alias) {
  7644. foreach ($alias as $a) {
  7645. // find position of compensation factor
  7646. $startnum = (strpos($a, ':') + 1);
  7647. $a = substr($a, 0, $startnum);
  7648. if (($pos = strpos($page, $a)) !== false) {
  7649. // end of alias
  7650. $endnum = strpos($page, '}', $pos);
  7651. // string to be replaced
  7652. $aa = substr($page, $pos, ($endnum - $pos + 1));
  7653. // get compensation factor
  7654. $ratio = substr($page, ($pos + $startnum), ($endnum - $pos - $startnum));
  7655. $ratio = preg_replace('/[^0-9\.]/', '', $ratio);
  7656. $ratio = floatval($ratio);
  7657. if ($type == 'u') {
  7658. $chrdiff = floor(($diff + 12) * $ratio);
  7659. $shift = str_repeat(' ', $chrdiff);
  7660. $shift = TCPDF_FONTS::UTF8ToUTF16BE($shift, false, $this->isunicode, $this->CurrentFont);
  7661. } else {
  7662. $chrdiff = floor(($diff + 11) * $ratio);
  7663. $shift = str_repeat(' ', $chrdiff);
  7664. }
  7665. $page = str_replace($aa, $shift, $page);
  7666. }
  7667. }
  7668. }
  7669. return $page;
  7670. }
  7671. /**
  7672. * Set page boxes to be included on page descriptions.
  7673. * @param $boxes (array) Array of page boxes to set on document: ('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox').
  7674. * @protected
  7675. */
  7676. protected function setPageBoxTypes($boxes)
  7677. {
  7678. $this->page_boxes = array();
  7679. foreach ($boxes as $box) {
  7680. if (in_array($box, TCPDF_STATIC::$pageboxes)) {
  7681. $this->page_boxes[] = $box;
  7682. }
  7683. }
  7684. }
  7685. /**
  7686. * Output pages (and replace page number aliases).
  7687. * @protected
  7688. */
  7689. protected function _putpages()
  7690. {
  7691. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  7692. // get internal aliases for page numbers
  7693. $pnalias = $this->getAllInternalPageNumberAliases();
  7694. $num_pages = $this->numpages;
  7695. $ptpa = TCPDF_STATIC::formatPageNumber(($this->starting_page_number + $num_pages - 1));
  7696. $ptpu = TCPDF_FONTS::UTF8ToUTF16BE($ptpa, false, $this->isunicode, $this->CurrentFont);
  7697. $ptp_num_chars = $this->GetNumChars($ptpa);
  7698. $pagegroupnum = 0;
  7699. $groupnum = 0;
  7700. $ptgu = 1;
  7701. $ptga = 1;
  7702. $ptg_num_chars = 1;
  7703. for ($n = 1; $n <= $num_pages; ++$n) {
  7704. // get current page
  7705. $temppage = $this->getPageBuffer($n);
  7706. $pagelen = strlen($temppage);
  7707. // set replacements for total pages number
  7708. $pnpa = TCPDF_STATIC::formatPageNumber(($this->starting_page_number + $n - 1));
  7709. $pnpu = TCPDF_FONTS::UTF8ToUTF16BE($pnpa, false, $this->isunicode, $this->CurrentFont);
  7710. $pnp_num_chars = $this->GetNumChars($pnpa);
  7711. $pdiff = 0; // difference used for right shift alignment of page numbers
  7712. $gdiff = 0; // difference used for right shift alignment of page group numbers
  7713. if (!empty($this->pagegroups)) {
  7714. if (isset($this->newpagegroup[$n])) {
  7715. $pagegroupnum = 0;
  7716. ++$groupnum;
  7717. $ptga = TCPDF_STATIC::formatPageNumber($this->pagegroups[$groupnum]);
  7718. $ptgu = TCPDF_FONTS::UTF8ToUTF16BE($ptga, false, $this->isunicode, $this->CurrentFont);
  7719. $ptg_num_chars = $this->GetNumChars($ptga);
  7720. }
  7721. ++$pagegroupnum;
  7722. $pnga = TCPDF_STATIC::formatPageNumber($pagegroupnum);
  7723. $pngu = TCPDF_FONTS::UTF8ToUTF16BE($pnga, false, $this->isunicode, $this->CurrentFont);
  7724. $png_num_chars = $this->GetNumChars($pnga);
  7725. // replace page numbers
  7726. $replace = array();
  7727. $replace[] = array($ptgu, $ptg_num_chars, 9, $pnalias[2]['u']);
  7728. $replace[] = array($ptga, $ptg_num_chars, 7, $pnalias[2]['a']);
  7729. $replace[] = array($pngu, $png_num_chars, 9, $pnalias[3]['u']);
  7730. $replace[] = array($pnga, $png_num_chars, 7, $pnalias[3]['a']);
  7731. list($temppage, $gdiff) = TCPDF_STATIC::replacePageNumAliases($temppage, $replace, $gdiff);
  7732. }
  7733. // replace page numbers
  7734. $replace = array();
  7735. $replace[] = array($ptpu, $ptp_num_chars, 9, $pnalias[0]['u']);
  7736. $replace[] = array($ptpa, $ptp_num_chars, 7, $pnalias[0]['a']);
  7737. $replace[] = array($pnpu, $pnp_num_chars, 9, $pnalias[1]['u']);
  7738. $replace[] = array($pnpa, $pnp_num_chars, 7, $pnalias[1]['a']);
  7739. list($temppage, $pdiff) = TCPDF_STATIC::replacePageNumAliases($temppage, $replace, $pdiff);
  7740. // replace right shift alias
  7741. $temppage = $this->replaceRightShiftPageNumAliases($temppage, $pnalias[4], max($pdiff, $gdiff));
  7742. // replace EPS marker
  7743. $temppage = str_replace($this->epsmarker, '', $temppage);
  7744. //Page
  7745. $this->page_obj_id[$n] = $this->_newobj();
  7746. $out = '<<';
  7747. $out .= ' /Type /Page';
  7748. $out .= ' /Parent 1 0 R';
  7749. if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) {
  7750. $out .= ' /LastModified '.$this->_datestring(0, $this->doc_modification_timestamp);
  7751. }
  7752. $out .= ' /Resources 2 0 R';
  7753. foreach ($this->page_boxes as $box) {
  7754. $out .= ' /'.$box;
  7755. $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']);
  7756. }
  7757. if (isset($this->pagedim[$n]['BoxColorInfo']) AND !empty($this->pagedim[$n]['BoxColorInfo'])) {
  7758. $out .= ' /BoxColorInfo <<';
  7759. foreach ($this->page_boxes as $box) {
  7760. if (isset($this->pagedim[$n]['BoxColorInfo'][$box])) {
  7761. $out .= ' /'.$box.' <<';
  7762. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['C'])) {
  7763. $color = $this->pagedim[$n]['BoxColorInfo'][$box]['C'];
  7764. $out .= ' /C [';
  7765. $out .= sprintf(' %F %F %F', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
  7766. $out .= ' ]';
  7767. }
  7768. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['W'])) {
  7769. $out .= ' /W '.($this->pagedim[$n]['BoxColorInfo'][$box]['W'] * $this->k);
  7770. }
  7771. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['S'])) {
  7772. $out .= ' /S /'.$this->pagedim[$n]['BoxColorInfo'][$box]['S'];
  7773. }
  7774. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['D'])) {
  7775. $dashes = $this->pagedim[$n]['BoxColorInfo'][$box]['D'];
  7776. $out .= ' /D [';
  7777. foreach ($dashes as $dash) {
  7778. $out .= sprintf(' %F', ($dash * $this->k));
  7779. }
  7780. $out .= ' ]';
  7781. }
  7782. $out .= ' >>';
  7783. }
  7784. }
  7785. $out .= ' >>';
  7786. }
  7787. $out .= ' /Contents '.($this->n + 1).' 0 R';
  7788. $out .= ' /Rotate '.$this->pagedim[$n]['Rotate'];
  7789. if (!$this->pdfa_mode) {
  7790. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceRGB >>';
  7791. }
  7792. if (isset($this->pagedim[$n]['trans']) AND !empty($this->pagedim[$n]['trans'])) {
  7793. // page transitions
  7794. if (isset($this->pagedim[$n]['trans']['Dur'])) {
  7795. $out .= ' /Dur '.$this->pagedim[$n]['trans']['Dur'];
  7796. }
  7797. $out .= ' /Trans <<';
  7798. $out .= ' /Type /Trans';
  7799. if (isset($this->pagedim[$n]['trans']['S'])) {
  7800. $out .= ' /S /'.$this->pagedim[$n]['trans']['S'];
  7801. }
  7802. if (isset($this->pagedim[$n]['trans']['D'])) {
  7803. $out .= ' /D '.$this->pagedim[$n]['trans']['D'];
  7804. }
  7805. if (isset($this->pagedim[$n]['trans']['Dm'])) {
  7806. $out .= ' /Dm /'.$this->pagedim[$n]['trans']['Dm'];
  7807. }
  7808. if (isset($this->pagedim[$n]['trans']['M'])) {
  7809. $out .= ' /M /'.$this->pagedim[$n]['trans']['M'];
  7810. }
  7811. if (isset($this->pagedim[$n]['trans']['Di'])) {
  7812. $out .= ' /Di '.$this->pagedim[$n]['trans']['Di'];
  7813. }
  7814. if (isset($this->pagedim[$n]['trans']['SS'])) {
  7815. $out .= ' /SS '.$this->pagedim[$n]['trans']['SS'];
  7816. }
  7817. if (isset($this->pagedim[$n]['trans']['B'])) {
  7818. $out .= ' /B '.$this->pagedim[$n]['trans']['B'];
  7819. }
  7820. $out .= ' >>';
  7821. }
  7822. $out .= $this->_getannotsrefs($n);
  7823. $out .= ' /PZ '.$this->pagedim[$n]['PZ'];
  7824. $out .= ' >>';
  7825. $out .= "\n".'endobj';
  7826. $this->_out($out);
  7827. //Page content
  7828. $p = ($this->compress) ? gzcompress($temppage) : $temppage;
  7829. $this->_newobj();
  7830. $p = $this->_getrawstream($p);
  7831. $this->_out('<<'.$filter.'/Length '.strlen($p).'>> stream'."\n".$p."\n".'endstream'."\n".'endobj');
  7832. }
  7833. //Pages root
  7834. $out = $this->_getobj(1)."\n";
  7835. $out .= '<< /Type /Pages /Kids [';
  7836. foreach ($this->page_obj_id as $page_obj) {
  7837. $out .= ' '.$page_obj.' 0 R';
  7838. }
  7839. $out .= ' ] /Count '.$num_pages.' >>';
  7840. $out .= "\n".'endobj';
  7841. $this->_out($out);
  7842. }
  7843. /**
  7844. * Get references to page annotations.
  7845. * @param $n (int) page number
  7846. * @return string
  7847. * @protected
  7848. * @author Nicola Asuni
  7849. * @since 5.0.010 (2010-05-17)
  7850. */
  7851. protected function _getannotsrefs($n)
  7852. {
  7853. if (!(isset($this->PageAnnots[$n]) OR ($this->sign AND isset($this->signature_data['cert_type'])))) {
  7854. return '';
  7855. }
  7856. $out = ' /Annots [';
  7857. if (isset($this->PageAnnots[$n])) {
  7858. foreach ($this->PageAnnots[$n] as $key => $val) {
  7859. if (!in_array($val['n'], $this->radio_groups)) {
  7860. $out .= ' '.$val['n'].' 0 R';
  7861. }
  7862. }
  7863. // add radiobutton groups
  7864. if (isset($this->radiobutton_groups[$n])) {
  7865. foreach ($this->radiobutton_groups[$n] as $key => $data) {
  7866. if (isset($data['n'])) {
  7867. $out .= ' '.$data['n'].' 0 R';
  7868. }
  7869. }
  7870. }
  7871. }
  7872. if ($this->sign AND ($n == $this->signature_appearance['page']) AND isset($this->signature_data['cert_type'])) {
  7873. // set reference for signature object
  7874. $out .= ' '.$this->sig_obj_id.' 0 R';
  7875. }
  7876. if (!empty($this->empty_signature_appearance)) {
  7877. foreach ($this->empty_signature_appearance as $esa) {
  7878. if ($esa['page'] == $n) {
  7879. // set reference for empty signature objects
  7880. $out .= ' '.$esa['objid'].' 0 R';
  7881. }
  7882. }
  7883. }
  7884. $out .= ' ]';
  7885. return $out;
  7886. }
  7887. /**
  7888. * Output annotations objects for all pages.
  7889. * !!! THIS METHOD IS NOT YET COMPLETED !!!
  7890. * See section 12.5 of PDF 32000_2008 reference.
  7891. * @protected
  7892. * @author Nicola Asuni
  7893. * @since 4.0.018 (2008-08-06)
  7894. */
  7895. protected function _putannotsobjs()
  7896. {
  7897. // reset object counter
  7898. for ($n=1; $n <= $this->numpages; ++$n) {
  7899. if (isset($this->PageAnnots[$n])) {
  7900. // set page annotations
  7901. foreach ($this->PageAnnots[$n] as $key => $pl) {
  7902. $annot_obj_id = $this->PageAnnots[$n][$key]['n'];
  7903. // create annotation object for grouping radiobuttons
  7904. if (isset($this->radiobutton_groups[$n][$pl['txt']]) AND is_array($this->radiobutton_groups[$n][$pl['txt']])) {
  7905. $radio_button_obj_id = $this->radiobutton_groups[$n][$pl['txt']]['n'];
  7906. $annots = '<<';
  7907. $annots .= ' /Type /Annot';
  7908. $annots .= ' /Subtype /Widget';
  7909. $annots .= ' /Rect [0 0 0 0]';
  7910. if ($this->radiobutton_groups[$n][$pl['txt']]['#readonly#']) {
  7911. // read only
  7912. $annots .= ' /F 68';
  7913. $annots .= ' /Ff 49153';
  7914. } else {
  7915. $annots .= ' /F 4'; // default print for PDF/A
  7916. $annots .= ' /Ff 49152';
  7917. }
  7918. $annots .= ' /T '.$this->_datastring($pl['txt'], $radio_button_obj_id);
  7919. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  7920. $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $radio_button_obj_id);
  7921. }
  7922. $annots .= ' /FT /Btn';
  7923. $annots .= ' /Kids [';
  7924. $defval = '';
  7925. foreach ($this->radiobutton_groups[$n][$pl['txt']] as $key => $data) {
  7926. if (isset($data['kid'])) {
  7927. $annots .= ' '.$data['kid'].' 0 R';
  7928. if ($data['def'] !== 'Off') {
  7929. $defval = $data['def'];
  7930. }
  7931. }
  7932. }
  7933. $annots .= ' ]';
  7934. if (!empty($defval)) {
  7935. $annots .= ' /V /'.$defval;
  7936. }
  7937. $annots .= ' >>';
  7938. $this->_out($this->_getobj($radio_button_obj_id)."\n".$annots."\n".'endobj');
  7939. $this->form_obj_id[] = $radio_button_obj_id;
  7940. // store object id to be used on Parent entry of Kids
  7941. $this->radiobutton_groups[$n][$pl['txt']] = $radio_button_obj_id;
  7942. }
  7943. $formfield = false;
  7944. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  7945. $a = $pl['x'] * $this->k;
  7946. $b = $this->pagedim[$n]['h'] - (($pl['y'] + $pl['h']) * $this->k);
  7947. $c = $pl['w'] * $this->k;
  7948. $d = $pl['h'] * $this->k;
  7949. $rect = sprintf('%F %F %F %F', $a, $b, $a+$c, $b+$d);
  7950. // create new annotation object
  7951. $annots = '<</Type /Annot';
  7952. $annots .= ' /Subtype /'.$pl['opt']['subtype'];
  7953. $annots .= ' /Rect ['.$rect.']';
  7954. $ft = array('Btn', 'Tx', 'Ch', 'Sig');
  7955. if (isset($pl['opt']['ft']) AND in_array($pl['opt']['ft'], $ft)) {
  7956. $annots .= ' /FT /'.$pl['opt']['ft'];
  7957. $formfield = true;
  7958. }
  7959. if ($pl['opt']['subtype'] !== 'Link') {
  7960. $annots .= ' /Contents '.$this->_textstring($pl['txt'], $annot_obj_id);
  7961. }
  7962. $annots .= ' /P '.$this->page_obj_id[$n].' 0 R';
  7963. $annots .= ' /NM '.$this->_datastring(sprintf('%04u-%04u', $n, $key), $annot_obj_id);
  7964. $annots .= ' /M '.$this->_datestring($annot_obj_id, $this->doc_modification_timestamp);
  7965. if (isset($pl['opt']['f'])) {
  7966. $fval = 0;
  7967. if (is_array($pl['opt']['f'])) {
  7968. foreach ($pl['opt']['f'] as $f) {
  7969. switch (strtolower($f)) {
  7970. case 'invisible': {
  7971. $fval += 1 << 0;
  7972. break;
  7973. }
  7974. case 'hidden': {
  7975. $fval += 1 << 1;
  7976. break;
  7977. }
  7978. case 'print': {
  7979. $fval += 1 << 2;
  7980. break;
  7981. }
  7982. case 'nozoom': {
  7983. $fval += 1 << 3;
  7984. break;
  7985. }
  7986. case 'norotate': {
  7987. $fval += 1 << 4;
  7988. break;
  7989. }
  7990. case 'noview': {
  7991. $fval += 1 << 5;
  7992. break;
  7993. }
  7994. case 'readonly': {
  7995. $fval += 1 << 6;
  7996. break;
  7997. }
  7998. case 'locked': {
  7999. $fval += 1 << 8;
  8000. break;
  8001. }
  8002. case 'togglenoview': {
  8003. $fval += 1 << 9;
  8004. break;
  8005. }
  8006. case 'lockedcontents': {
  8007. $fval += 1 << 10;
  8008. break;
  8009. }
  8010. default: {
  8011. break;
  8012. }
  8013. }
  8014. }
  8015. } else {
  8016. $fval = intval($pl['opt']['f']);
  8017. }
  8018. } else {
  8019. $fval = 4;
  8020. }
  8021. if ($this->pdfa_mode) {
  8022. // force print flag for PDF/A mode
  8023. $fval |= 4;
  8024. }
  8025. $annots .= ' /F '.intval($fval);
  8026. if (isset($pl['opt']['as']) AND is_string($pl['opt']['as'])) {
  8027. $annots .= ' /AS /'.$pl['opt']['as'];
  8028. }
  8029. if (isset($pl['opt']['ap'])) {
  8030. // appearance stream
  8031. $annots .= ' /AP <<';
  8032. if (is_array($pl['opt']['ap'])) {
  8033. foreach ($pl['opt']['ap'] as $apmode => $apdef) {
  8034. // $apmode can be: n = normal; r = rollover; d = down;
  8035. $annots .= ' /'.strtoupper($apmode);
  8036. if (is_array($apdef)) {
  8037. $annots .= ' <<';
  8038. foreach ($apdef as $apstate => $stream) {
  8039. // reference to XObject that define the appearance for this mode-state
  8040. $apsobjid = $this->_putAPXObject($c, $d, $stream);
  8041. $annots .= ' /'.$apstate.' '.$apsobjid.' 0 R';
  8042. }
  8043. $annots .= ' >>';
  8044. } else {
  8045. // reference to XObject that define the appearance for this mode
  8046. $apsobjid = $this->_putAPXObject($c, $d, $apdef);
  8047. $annots .= ' '.$apsobjid.' 0 R';
  8048. }
  8049. }
  8050. } else {
  8051. $annots .= $pl['opt']['ap'];
  8052. }
  8053. $annots .= ' >>';
  8054. }
  8055. if (isset($pl['opt']['bs']) AND (is_array($pl['opt']['bs']))) {
  8056. $annots .= ' /BS <<';
  8057. $annots .= ' /Type /Border';
  8058. if (isset($pl['opt']['bs']['w'])) {
  8059. $annots .= ' /W '.intval($pl['opt']['bs']['w']);
  8060. }
  8061. $bstyles = array('S', 'D', 'B', 'I', 'U');
  8062. if (isset($pl['opt']['bs']['s']) AND in_array($pl['opt']['bs']['s'], $bstyles)) {
  8063. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  8064. }
  8065. if (isset($pl['opt']['bs']['d']) AND (is_array($pl['opt']['bs']['d']))) {
  8066. $annots .= ' /D [';
  8067. foreach ($pl['opt']['bs']['d'] as $cord) {
  8068. $annots .= ' '.intval($cord);
  8069. }
  8070. $annots .= ']';
  8071. }
  8072. $annots .= ' >>';
  8073. } else {
  8074. $annots .= ' /Border [';
  8075. if (isset($pl['opt']['border']) AND (count($pl['opt']['border']) >= 3)) {
  8076. $annots .= intval($pl['opt']['border'][0]).' ';
  8077. $annots .= intval($pl['opt']['border'][1]).' ';
  8078. $annots .= intval($pl['opt']['border'][2]);
  8079. if (isset($pl['opt']['border'][3]) AND is_array($pl['opt']['border'][3])) {
  8080. $annots .= ' [';
  8081. foreach ($pl['opt']['border'][3] as $dash) {
  8082. $annots .= intval($dash).' ';
  8083. }
  8084. $annots .= ']';
  8085. }
  8086. } else {
  8087. $annots .= '0 0 0';
  8088. }
  8089. $annots .= ']';
  8090. }
  8091. if (isset($pl['opt']['be']) AND (is_array($pl['opt']['be']))) {
  8092. $annots .= ' /BE <<';
  8093. $bstyles = array('S', 'C');
  8094. if (isset($pl['opt']['be']['s']) AND in_array($pl['opt']['be']['s'], $bstyles)) {
  8095. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  8096. } else {
  8097. $annots .= ' /S /S';
  8098. }
  8099. if (isset($pl['opt']['be']['i']) AND ($pl['opt']['be']['i'] >= 0) AND ($pl['opt']['be']['i'] <= 2)) {
  8100. $annots .= ' /I '.sprintf(' %F', $pl['opt']['be']['i']);
  8101. }
  8102. $annots .= '>>';
  8103. }
  8104. if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) {
  8105. $annots .= ' /C '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['c']);
  8106. }
  8107. //$annots .= ' /StructParent ';
  8108. //$annots .= ' /OC ';
  8109. $markups = array('text', 'freetext', 'line', 'square', 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp', 'caret', 'ink', 'fileattachment', 'sound');
  8110. if (in_array(strtolower($pl['opt']['subtype']), $markups)) {
  8111. // this is a markup type
  8112. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  8113. $annots .= ' /T '.$this->_textstring($pl['opt']['t'], $annot_obj_id);
  8114. }
  8115. //$annots .= ' /Popup ';
  8116. if (isset($pl['opt']['ca'])) {
  8117. $annots .= ' /CA '.sprintf('%F', floatval($pl['opt']['ca']));
  8118. }
  8119. if (isset($pl['opt']['rc'])) {
  8120. $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  8121. }
  8122. $annots .= ' /CreationDate '.$this->_datestring($annot_obj_id, $this->doc_creation_timestamp);
  8123. //$annots .= ' /IRT ';
  8124. if (isset($pl['opt']['subj'])) {
  8125. $annots .= ' /Subj '.$this->_textstring($pl['opt']['subj'], $annot_obj_id);
  8126. }
  8127. //$annots .= ' /RT ';
  8128. //$annots .= ' /IT ';
  8129. //$annots .= ' /ExData ';
  8130. }
  8131. $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt', 'ROpenArrow', 'RClosedArrow', 'Slash');
  8132. // Annotation types
  8133. switch (strtolower($pl['opt']['subtype'])) {
  8134. case 'text': {
  8135. if (isset($pl['opt']['open'])) {
  8136. $annots .= ' /Open '. (strtolower($pl['opt']['open']) == 'true' ? 'true' : 'false');
  8137. }
  8138. $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph');
  8139. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8140. $annots .= ' /Name /'.$pl['opt']['name'];
  8141. } else {
  8142. $annots .= ' /Name /Note';
  8143. }
  8144. $statemodels = array('Marked', 'Review');
  8145. if (isset($pl['opt']['statemodel']) AND in_array($pl['opt']['statemodel'], $statemodels)) {
  8146. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  8147. } else {
  8148. $pl['opt']['statemodel'] = 'Marked';
  8149. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  8150. }
  8151. if ($pl['opt']['statemodel'] == 'Marked') {
  8152. $states = array('Accepted', 'Unmarked');
  8153. } else {
  8154. $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None');
  8155. }
  8156. if (isset($pl['opt']['state']) AND in_array($pl['opt']['state'], $states)) {
  8157. $annots .= ' /State /'.$pl['opt']['state'];
  8158. } else {
  8159. if ($pl['opt']['statemodel'] == 'Marked') {
  8160. $annots .= ' /State /Unmarked';
  8161. } else {
  8162. $annots .= ' /State /None';
  8163. }
  8164. }
  8165. break;
  8166. }
  8167. case 'link': {
  8168. if (is_string($pl['txt']) && !empty($pl['txt'])) {
  8169. if ($pl['txt'][0] == '#') {
  8170. // internal destination
  8171. $annots .= ' /A <</S /GoTo /D '.TCPDF_STATIC::encodeNameObject(substr($pl['txt'], 1)).'>>';
  8172. } elseif ($pl['txt'][0] == '%') {
  8173. // embedded PDF file
  8174. $filename = basename(substr($pl['txt'], 1));
  8175. $annots .= ' /A << /S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($n - 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>';
  8176. } elseif ($pl['txt'][0] == '*') {
  8177. // embedded generic file
  8178. $filename = basename(substr($pl['txt'], 1));
  8179. $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});';
  8180. $annots .= ' /A << /S /JavaScript /JS '.$this->_textstring($jsa, $annot_obj_id).'>>';
  8181. } else {
  8182. $parsedUrl = parse_url($pl['txt']);
  8183. if (empty($parsedUrl['scheme']) AND (!empty($parsedUrl['path']) && strtolower(substr($parsedUrl['path'], -4)) == '.pdf')) {
  8184. // relative link to a PDF file
  8185. $dest = '[0 /Fit]'; // default page 0
  8186. if (!empty($parsedUrl['fragment'])) {
  8187. // check for named destination
  8188. $tmp = explode('=', $parsedUrl['fragment']);
  8189. $dest = '('.((count($tmp) == 2) ? $tmp[1] : $tmp[0]).')';
  8190. }
  8191. $annots .= ' /A <</S /GoToR /D '.$dest.' /F '.$this->_datastring($this->unhtmlentities($parsedUrl['path']), $annot_obj_id).' /NewWindow true>>';
  8192. } else {
  8193. // external URI link
  8194. $annots .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>';
  8195. }
  8196. }
  8197. } elseif (isset($this->links[$pl['txt']])) {
  8198. // internal link ID
  8199. $l = $this->links[$pl['txt']];
  8200. if (isset($this->page_obj_id[($l['p'])])) {
  8201. $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)));
  8202. }
  8203. }
  8204. $hmodes = array('N', 'I', 'O', 'P');
  8205. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmodes)) {
  8206. $annots .= ' /H /'.$pl['opt']['h'];
  8207. } else {
  8208. $annots .= ' /H /I';
  8209. }
  8210. //$annots .= ' /PA ';
  8211. //$annots .= ' /Quadpoints ';
  8212. break;
  8213. }
  8214. case 'freetext': {
  8215. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  8216. $annots .= ' /DA ('.$pl['opt']['da'].')';
  8217. }
  8218. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  8219. $annots .= ' /Q '.intval($pl['opt']['q']);
  8220. }
  8221. if (isset($pl['opt']['rc'])) {
  8222. $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  8223. }
  8224. if (isset($pl['opt']['ds'])) {
  8225. $annots .= ' /DS '.$this->_textstring($pl['opt']['ds'], $annot_obj_id);
  8226. }
  8227. if (isset($pl['opt']['cl']) AND is_array($pl['opt']['cl'])) {
  8228. $annots .= ' /CL [';
  8229. foreach ($pl['opt']['cl'] as $cl) {
  8230. $annots .= sprintf('%F ', $cl * $this->k);
  8231. }
  8232. $annots .= ']';
  8233. }
  8234. $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter');
  8235. if (isset($pl['opt']['it']) AND in_array($pl['opt']['it'], $tfit)) {
  8236. $annots .= ' /IT /'.$pl['opt']['it'];
  8237. }
  8238. if (isset($pl['opt']['rd']) AND is_array($pl['opt']['rd'])) {
  8239. $l = $pl['opt']['rd'][0] * $this->k;
  8240. $r = $pl['opt']['rd'][1] * $this->k;
  8241. $t = $pl['opt']['rd'][2] * $this->k;
  8242. $b = $pl['opt']['rd'][3] * $this->k;
  8243. $annots .= ' /RD ['.sprintf('%F %F %F %F', $l, $r, $t, $b).']';
  8244. }
  8245. if (isset($pl['opt']['le']) AND in_array($pl['opt']['le'], $lineendings)) {
  8246. $annots .= ' /LE /'.$pl['opt']['le'];
  8247. }
  8248. break;
  8249. }
  8250. case 'line': {
  8251. break;
  8252. }
  8253. case 'square': {
  8254. break;
  8255. }
  8256. case 'circle': {
  8257. break;
  8258. }
  8259. case 'polygon': {
  8260. break;
  8261. }
  8262. case 'polyline': {
  8263. break;
  8264. }
  8265. case 'highlight': {
  8266. break;
  8267. }
  8268. case 'underline': {
  8269. break;
  8270. }
  8271. case 'squiggly': {
  8272. break;
  8273. }
  8274. case 'strikeout': {
  8275. break;
  8276. }
  8277. case 'stamp': {
  8278. break;
  8279. }
  8280. case 'caret': {
  8281. break;
  8282. }
  8283. case 'ink': {
  8284. break;
  8285. }
  8286. case 'popup': {
  8287. break;
  8288. }
  8289. case 'fileattachment': {
  8290. if ($this->pdfa_mode && $this->pdfa_version != 3) {
  8291. // embedded files are not allowed in PDF/A mode version 1 and 2
  8292. break;
  8293. }
  8294. if (!isset($pl['opt']['fs'])) {
  8295. break;
  8296. }
  8297. $filename = basename($pl['opt']['fs']);
  8298. if (isset($this->embeddedfiles[$filename]['f'])) {
  8299. $annots .= ' /FS '.$this->embeddedfiles[$filename]['f'].' 0 R';
  8300. $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag');
  8301. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8302. $annots .= ' /Name /'.$pl['opt']['name'];
  8303. } else {
  8304. $annots .= ' /Name /PushPin';
  8305. }
  8306. // index (zero-based) of the annotation in the Annots array of this page
  8307. $this->embeddedfiles[$filename]['a'] = $key;
  8308. }
  8309. break;
  8310. }
  8311. case 'sound': {
  8312. if (!isset($pl['opt']['fs'])) {
  8313. break;
  8314. }
  8315. $filename = basename($pl['opt']['fs']);
  8316. if (isset($this->embeddedfiles[$filename]['f'])) {
  8317. // ... TO BE COMPLETED ...
  8318. // /R /C /B /E /CO /CP
  8319. $annots .= ' /Sound '.$this->embeddedfiles[$filename]['f'].' 0 R';
  8320. $iconsapp = array('Speaker', 'Mic');
  8321. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8322. $annots .= ' /Name /'.$pl['opt']['name'];
  8323. } else {
  8324. $annots .= ' /Name /Speaker';
  8325. }
  8326. }
  8327. break;
  8328. }
  8329. case 'movie': {
  8330. break;
  8331. }
  8332. case 'widget': {
  8333. $hmode = array('N', 'I', 'O', 'P', 'T');
  8334. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmode)) {
  8335. $annots .= ' /H /'.$pl['opt']['h'];
  8336. }
  8337. if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) {
  8338. $annots .= ' /MK <<';
  8339. if (isset($pl['opt']['mk']['r'])) {
  8340. $annots .= ' /R '.$pl['opt']['mk']['r'];
  8341. }
  8342. if (isset($pl['opt']['mk']['bc']) AND (is_array($pl['opt']['mk']['bc']))) {
  8343. $annots .= ' /BC '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['mk']['bc']);
  8344. }
  8345. if (isset($pl['opt']['mk']['bg']) AND (is_array($pl['opt']['mk']['bg']))) {
  8346. $annots .= ' /BG '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['mk']['bg']);
  8347. }
  8348. if (isset($pl['opt']['mk']['ca'])) {
  8349. $annots .= ' /CA '.$pl['opt']['mk']['ca'];
  8350. }
  8351. if (isset($pl['opt']['mk']['rc'])) {
  8352. $annots .= ' /RC '.$pl['opt']['mk']['rc'];
  8353. }
  8354. if (isset($pl['opt']['mk']['ac'])) {
  8355. $annots .= ' /AC '.$pl['opt']['mk']['ac'];
  8356. }
  8357. if (isset($pl['opt']['mk']['i'])) {
  8358. $info = $this->getImageBuffer($pl['opt']['mk']['i']);
  8359. if ($info !== false) {
  8360. $annots .= ' /I '.$info['n'].' 0 R';
  8361. }
  8362. }
  8363. if (isset($pl['opt']['mk']['ri'])) {
  8364. $info = $this->getImageBuffer($pl['opt']['mk']['ri']);
  8365. if ($info !== false) {
  8366. $annots .= ' /RI '.$info['n'].' 0 R';
  8367. }
  8368. }
  8369. if (isset($pl['opt']['mk']['ix'])) {
  8370. $info = $this->getImageBuffer($pl['opt']['mk']['ix']);
  8371. if ($info !== false) {
  8372. $annots .= ' /IX '.$info['n'].' 0 R';
  8373. }
  8374. }
  8375. if (isset($pl['opt']['mk']['if']) AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) {
  8376. $annots .= ' /IF <<';
  8377. $if_sw = array('A', 'B', 'S', 'N');
  8378. if (isset($pl['opt']['mk']['if']['sw']) AND in_array($pl['opt']['mk']['if']['sw'], $if_sw)) {
  8379. $annots .= ' /SW /'.$pl['opt']['mk']['if']['sw'];
  8380. }
  8381. $if_s = array('A', 'P');
  8382. if (isset($pl['opt']['mk']['if']['s']) AND in_array($pl['opt']['mk']['if']['s'], $if_s)) {
  8383. $annots .= ' /S /'.$pl['opt']['mk']['if']['s'];
  8384. }
  8385. if (isset($pl['opt']['mk']['if']['a']) AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) {
  8386. $annots .= sprintf(' /A [%F %F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]);
  8387. }
  8388. if (isset($pl['opt']['mk']['if']['fb']) AND ($pl['opt']['mk']['if']['fb'])) {
  8389. $annots .= ' /FB true';
  8390. }
  8391. $annots .= '>>';
  8392. }
  8393. if (isset($pl['opt']['mk']['tp']) AND ($pl['opt']['mk']['tp'] >= 0) AND ($pl['opt']['mk']['tp'] <= 6)) {
  8394. $annots .= ' /TP '.intval($pl['opt']['mk']['tp']);
  8395. }
  8396. $annots .= '>>';
  8397. } // end MK
  8398. // --- Entries for field dictionaries ---
  8399. if (isset($this->radiobutton_groups[$n][$pl['txt']])) {
  8400. // set parent
  8401. $annots .= ' /Parent '.$this->radiobutton_groups[$n][$pl['txt']].' 0 R';
  8402. }
  8403. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  8404. $annots .= ' /T '.$this->_datastring($pl['opt']['t'], $annot_obj_id);
  8405. }
  8406. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  8407. $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $annot_obj_id);
  8408. }
  8409. if (isset($pl['opt']['tm']) AND is_string($pl['opt']['tm'])) {
  8410. $annots .= ' /TM '.$this->_datastring($pl['opt']['tm'], $annot_obj_id);
  8411. }
  8412. if (isset($pl['opt']['ff'])) {
  8413. if (is_array($pl['opt']['ff'])) {
  8414. // array of bit settings
  8415. $flag = 0;
  8416. foreach ($pl['opt']['ff'] as $val) {
  8417. $flag += 1 << ($val - 1);
  8418. }
  8419. } else {
  8420. $flag = intval($pl['opt']['ff']);
  8421. }
  8422. $annots .= ' /Ff '.$flag;
  8423. }
  8424. if (isset($pl['opt']['maxlen'])) {
  8425. $annots .= ' /MaxLen '.intval($pl['opt']['maxlen']);
  8426. }
  8427. if (isset($pl['opt']['v'])) {
  8428. $annots .= ' /V';
  8429. if (is_array($pl['opt']['v'])) {
  8430. foreach ($pl['opt']['v'] AS $optval) {
  8431. if (is_float($optval)) {
  8432. $optval = sprintf('%F', $optval);
  8433. }
  8434. $annots .= ' '.$optval;
  8435. }
  8436. } else {
  8437. $annots .= ' '.$this->_textstring($pl['opt']['v'], $annot_obj_id);
  8438. }
  8439. }
  8440. if (isset($pl['opt']['dv'])) {
  8441. $annots .= ' /DV';
  8442. if (is_array($pl['opt']['dv'])) {
  8443. foreach ($pl['opt']['dv'] AS $optval) {
  8444. if (is_float($optval)) {
  8445. $optval = sprintf('%F', $optval);
  8446. }
  8447. $annots .= ' '.$optval;
  8448. }
  8449. } else {
  8450. $annots .= ' '.$this->_textstring($pl['opt']['dv'], $annot_obj_id);
  8451. }
  8452. }
  8453. if (isset($pl['opt']['rv'])) {
  8454. $annots .= ' /RV';
  8455. if (is_array($pl['opt']['rv'])) {
  8456. foreach ($pl['opt']['rv'] AS $optval) {
  8457. if (is_float($optval)) {
  8458. $optval = sprintf('%F', $optval);
  8459. }
  8460. $annots .= ' '.$optval;
  8461. }
  8462. } else {
  8463. $annots .= ' '.$this->_textstring($pl['opt']['rv'], $annot_obj_id);
  8464. }
  8465. }
  8466. if (isset($pl['opt']['a']) AND !empty($pl['opt']['a'])) {
  8467. $annots .= ' /A << '.$pl['opt']['a'].' >>';
  8468. }
  8469. if (isset($pl['opt']['aa']) AND !empty($pl['opt']['aa'])) {
  8470. $annots .= ' /AA << '.$pl['opt']['aa'].' >>';
  8471. }
  8472. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  8473. $annots .= ' /DA ('.$pl['opt']['da'].')';
  8474. }
  8475. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  8476. $annots .= ' /Q '.intval($pl['opt']['q']);
  8477. }
  8478. if (isset($pl['opt']['opt']) AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) {
  8479. $annots .= ' /Opt [';
  8480. foreach ($pl['opt']['opt'] AS $copt) {
  8481. if (is_array($copt)) {
  8482. $annots .= ' ['.$this->_textstring($copt[0], $annot_obj_id).' '.$this->_textstring($copt[1], $annot_obj_id).']';
  8483. } else {
  8484. $annots .= ' '.$this->_textstring($copt, $annot_obj_id);
  8485. }
  8486. }
  8487. $annots .= ']';
  8488. }
  8489. if (isset($pl['opt']['ti'])) {
  8490. $annots .= ' /TI '.intval($pl['opt']['ti']);
  8491. }
  8492. if (isset($pl['opt']['i']) AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) {
  8493. $annots .= ' /I [';
  8494. foreach ($pl['opt']['i'] AS $copt) {
  8495. $annots .= intval($copt).' ';
  8496. }
  8497. $annots .= ']';
  8498. }
  8499. break;
  8500. }
  8501. case 'screen': {
  8502. break;
  8503. }
  8504. case 'printermark': {
  8505. break;
  8506. }
  8507. case 'trapnet': {
  8508. break;
  8509. }
  8510. case 'watermark': {
  8511. break;
  8512. }
  8513. case '3d': {
  8514. break;
  8515. }
  8516. default: {
  8517. break;
  8518. }
  8519. }
  8520. $annots .= '>>';
  8521. // create new annotation object
  8522. $this->_out($this->_getobj($annot_obj_id)."\n".$annots."\n".'endobj');
  8523. if ($formfield AND !isset($this->radiobutton_groups[$n][$pl['txt']])) {
  8524. // store reference of form object
  8525. $this->form_obj_id[] = $annot_obj_id;
  8526. }
  8527. }
  8528. }
  8529. } // end for each page
  8530. }
  8531. /**
  8532. * Put appearance streams XObject used to define annotation's appearance states.
  8533. * @param $w (int) annotation width
  8534. * @param $h (int) annotation height
  8535. * @param $stream (string) appearance stream
  8536. * @return int object ID
  8537. * @protected
  8538. * @since 4.8.001 (2009-09-09)
  8539. */
  8540. protected function _putAPXObject($w = 0, $h = 0, $stream = '')
  8541. {
  8542. $stream = trim($stream);
  8543. $out = $this->_getobj()."\n";
  8544. $this->xobjects['AX'.$this->n] = array('n' => $this->n);
  8545. $out .= '<<';
  8546. $out .= ' /Type /XObject';
  8547. $out .= ' /Subtype /Form';
  8548. $out .= ' /FormType 1';
  8549. if ($this->compress) {
  8550. $stream = gzcompress($stream);
  8551. $out .= ' /Filter /FlateDecode';
  8552. }
  8553. $rect = sprintf('%F %F', $w, $h);
  8554. $out .= ' /BBox [0 0 '.$rect.']';
  8555. $out .= ' /Matrix [1 0 0 1 0 0]';
  8556. $out .= ' /Resources 2 0 R';
  8557. $stream = $this->_getrawstream($stream);
  8558. $out .= ' /Length '.strlen($stream);
  8559. $out .= ' >>';
  8560. $out .= ' stream'."\n".$stream."\n".'endstream';
  8561. $out .= "\n".'endobj';
  8562. $this->_out($out);
  8563. return $this->n;
  8564. }
  8565. /**
  8566. * Output fonts.
  8567. * @author Nicola Asuni
  8568. * @protected
  8569. */
  8570. protected function _putfonts()
  8571. {
  8572. $nf = $this->n;
  8573. foreach ($this->diffs as $diff) {
  8574. //Encodings
  8575. $this->_newobj();
  8576. $this->_out('<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.'] >>'."\n".'endobj');
  8577. }
  8578. $mqr = TCPDF_STATIC::get_mqr();
  8579. TCPDF_STATIC::set_mqr(false);
  8580. foreach ($this->FontFiles as $file => $info) {
  8581. // search and get font file to embedd
  8582. $fontfile = TCPDF_FONTS::getFontFullPath($file, $info['fontdir']);
  8583. if (!TCPDF_STATIC::empty_string($fontfile)) {
  8584. $font = file_get_contents($fontfile);
  8585. $compressed = (substr($file, -2) == '.z');
  8586. if ((!$compressed) AND (isset($info['length2']))) {
  8587. $header = (ord($font[0]) == 128);
  8588. if ($header) {
  8589. // strip first binary header
  8590. $font = substr($font, 6);
  8591. }
  8592. if ($header AND (ord($font[$info['length1']]) == 128)) {
  8593. // strip second binary header
  8594. $font = substr($font, 0, $info['length1']).substr($font, ($info['length1'] + 6));
  8595. }
  8596. } elseif ($info['subset'] AND ((!$compressed) OR ($compressed AND function_exists('gzcompress')))) {
  8597. if ($compressed) {
  8598. // uncompress font
  8599. $font = gzuncompress($font);
  8600. }
  8601. // merge subset characters
  8602. $subsetchars = array(); // used chars
  8603. foreach ($info['fontkeys'] as $fontkey) {
  8604. $fontinfo = $this->getFontBuffer($fontkey);
  8605. $subsetchars += $fontinfo['subsetchars'];
  8606. }
  8607. // rebuild a font subset
  8608. $font = TCPDF_FONTS::_getTrueTypeFontSubset($font, $subsetchars);
  8609. // calculate new font length
  8610. $info['length1'] = strlen($font);
  8611. if ($compressed) {
  8612. // recompress font
  8613. $font = gzcompress($font);
  8614. }
  8615. }
  8616. $this->_newobj();
  8617. $this->FontFiles[$file]['n'] = $this->n;
  8618. $stream = $this->_getrawstream($font);
  8619. $out = '<< /Length '.strlen($stream);
  8620. if ($compressed) {
  8621. $out .= ' /Filter /FlateDecode';
  8622. }
  8623. $out .= ' /Length1 '.$info['length1'];
  8624. if (isset($info['length2'])) {
  8625. $out .= ' /Length2 '.$info['length2'].' /Length3 0';
  8626. }
  8627. $out .= ' >>';
  8628. $out .= ' stream'."\n".$stream."\n".'endstream';
  8629. $out .= "\n".'endobj';
  8630. $this->_out($out);
  8631. }
  8632. }
  8633. TCPDF_STATIC::set_mqr($mqr);
  8634. foreach ($this->fontkeys as $k) {
  8635. //Font objects
  8636. $font = $this->getFontBuffer($k);
  8637. $type = $font['type'];
  8638. $name = $font['name'];
  8639. if ($type == 'core') {
  8640. // standard core font
  8641. $out = $this->_getobj($this->font_obj_ids[$k])."\n";
  8642. $out .= '<</Type /Font';
  8643. $out .= ' /Subtype /Type1';
  8644. $out .= ' /BaseFont /'.$name;
  8645. $out .= ' /Name /F'.$font['i'];
  8646. if ((strtolower($name) != 'symbol') AND (strtolower($name) != 'zapfdingbats')) {
  8647. $out .= ' /Encoding /WinAnsiEncoding';
  8648. }
  8649. if ($k == 'helvetica') {
  8650. // add default font for annotations
  8651. $this->annotation_fonts[$k] = $font['i'];
  8652. }
  8653. $out .= ' >>';
  8654. $out .= "\n".'endobj';
  8655. $this->_out($out);
  8656. } elseif (($type == 'Type1') OR ($type == 'TrueType')) {
  8657. // additional Type1 or TrueType font
  8658. $out = $this->_getobj($this->font_obj_ids[$k])."\n";
  8659. $out .= '<</Type /Font';
  8660. $out .= ' /Subtype /'.$type;
  8661. $out .= ' /BaseFont /'.$name;
  8662. $out .= ' /Name /F'.$font['i'];
  8663. $out .= ' /FirstChar 32 /LastChar 255';
  8664. $out .= ' /Widths '.($this->n + 1).' 0 R';
  8665. $out .= ' /FontDescriptor '.($this->n + 2).' 0 R';
  8666. if ($font['enc']) {
  8667. if (isset($font['diff'])) {
  8668. $out .= ' /Encoding '.($nf + $font['diff']).' 0 R';
  8669. } else {
  8670. $out .= ' /Encoding /WinAnsiEncoding';
  8671. }
  8672. }
  8673. $out .= ' >>';
  8674. $out .= "\n".'endobj';
  8675. $this->_out($out);
  8676. // Widths
  8677. $this->_newobj();
  8678. $s = '[';
  8679. for ($i = 32; $i < 256; ++$i) {
  8680. if (isset($font['cw'][$i])) {
  8681. $s .= $font['cw'][$i].' ';
  8682. } else {
  8683. $s .= $font['dw'].' ';
  8684. }
  8685. }
  8686. $s .= ']';
  8687. $s .= "\n".'endobj';
  8688. $this->_out($s);
  8689. //Descriptor
  8690. $this->_newobj();
  8691. $s = '<</Type /FontDescriptor /FontName /'.$name;
  8692. foreach ($font['desc'] as $fdk => $fdv) {
  8693. if (is_float($fdv)) {
  8694. $fdv = sprintf('%F', $fdv);
  8695. }
  8696. $s .= ' /'.$fdk.' '.$fdv.'';
  8697. }
  8698. if (!TCPDF_STATIC::empty_string($font['file'])) {
  8699. $s .= ' /FontFile'.($type == 'Type1' ? '' : '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R';
  8700. }
  8701. $s .= '>>';
  8702. $s .= "\n".'endobj';
  8703. $this->_out($s);
  8704. } else {
  8705. // additional types
  8706. $mtd = '_put'.strtolower($type);
  8707. if (!method_exists($this, $mtd)) {
  8708. $this->Error('Unsupported font type: '.$type);
  8709. }
  8710. $this->$mtd($font);
  8711. }
  8712. }
  8713. }
  8714. /**
  8715. * Adds unicode fonts.<br>
  8716. * Based on PDF Reference 1.3 (section 5)
  8717. * @param $font (array) font data
  8718. * @protected
  8719. * @author Nicola Asuni
  8720. * @since 1.52.0.TC005 (2005-01-05)
  8721. */
  8722. protected function _puttruetypeunicode($font)
  8723. {
  8724. $fontname = '';
  8725. if ($font['subset']) {
  8726. // change name for font subsetting
  8727. $subtag = sprintf('%06u', $font['i']);
  8728. $subtag = strtr($subtag, '0123456789', 'ABCDEFGHIJ');
  8729. $fontname .= $subtag.'+';
  8730. }
  8731. $fontname .= $font['name'];
  8732. // Type0 Font
  8733. // A composite font composed of other fonts, organized hierarchically
  8734. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  8735. $out .= '<< /Type /Font';
  8736. $out .= ' /Subtype /Type0';
  8737. $out .= ' /BaseFont /'.$fontname;
  8738. $out .= ' /Name /F'.$font['i'];
  8739. $out .= ' /Encoding /'.$font['enc'];
  8740. $out .= ' /ToUnicode '.($this->n + 1).' 0 R';
  8741. $out .= ' /DescendantFonts ['.($this->n + 2).' 0 R]';
  8742. $out .= ' >>';
  8743. $out .= "\n".'endobj';
  8744. $this->_out($out);
  8745. // ToUnicode map for Identity-H
  8746. $stream = TCPDF_FONT_DATA::$uni_identity_h;
  8747. // ToUnicode Object
  8748. $this->_newobj();
  8749. $stream = ($this->compress) ? gzcompress($stream) : $stream;
  8750. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  8751. $stream = $this->_getrawstream($stream);
  8752. $this->_out('<<'.$filter.'/Length '.strlen($stream).'>> stream'."\n".$stream."\n".'endstream'."\n".'endobj');
  8753. // CIDFontType2
  8754. // A CIDFont whose glyph descriptions are based on TrueType font technology
  8755. $oid = $this->_newobj();
  8756. $out = '<< /Type /Font';
  8757. $out .= ' /Subtype /CIDFontType2';
  8758. $out .= ' /BaseFont /'.$fontname;
  8759. // A dictionary containing entries that define the character collection of the CIDFont.
  8760. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  8761. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  8762. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  8763. $out .= ' /CIDSystemInfo << '.$cidinfo.' >>';
  8764. $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
  8765. $out .= ' /DW '.$font['dw']; // default width
  8766. $out .= "\n".TCPDF_FONTS::_putfontwidths($font, 0);
  8767. if (isset($font['ctg']) AND (!TCPDF_STATIC::empty_string($font['ctg']))) {
  8768. $out .= "\n".'/CIDToGIDMap '.($this->n + 2).' 0 R';
  8769. }
  8770. $out .= ' >>';
  8771. $out .= "\n".'endobj';
  8772. $this->_out($out);
  8773. // Font descriptor
  8774. // A font descriptor describing the CIDFont default metrics other than its glyph widths
  8775. $this->_newobj();
  8776. $out = '<< /Type /FontDescriptor';
  8777. $out .= ' /FontName /'.$fontname;
  8778. foreach ($font['desc'] as $key => $value) {
  8779. if (is_float($value)) {
  8780. $value = sprintf('%F', $value);
  8781. }
  8782. $out .= ' /'.$key.' '.$value;
  8783. }
  8784. $fontdir = false;
  8785. if (!TCPDF_STATIC::empty_string($font['file'])) {
  8786. // A stream containing a TrueType font
  8787. $out .= ' /FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R';
  8788. $fontdir = $this->FontFiles[$font['file']]['fontdir'];
  8789. }
  8790. $out .= ' >>';
  8791. $out .= "\n".'endobj';
  8792. $this->_out($out);
  8793. if (isset($font['ctg']) AND (!TCPDF_STATIC::empty_string($font['ctg']))) {
  8794. $this->_newobj();
  8795. // Embed CIDToGIDMap
  8796. // A specification of the mapping from CIDs to glyph indices
  8797. // search and get CTG font file to embedd
  8798. $ctgfile = strtolower($font['ctg']);
  8799. // search and get ctg font file to embedd
  8800. $fontfile = TCPDF_FONTS::getFontFullPath($ctgfile, $fontdir);
  8801. if (TCPDF_STATIC::empty_string($fontfile)) {
  8802. $this->Error('Font file not found: '.$ctgfile);
  8803. }
  8804. $stream = $this->_getrawstream(file_get_contents($fontfile));
  8805. $out = '<< /Length '.strlen($stream).'';
  8806. if (substr($fontfile, -2) == '.z') { // check file extension
  8807. // Decompresses data encoded using the public-domain
  8808. // zlib/deflate compression method, reproducing the
  8809. // original text or binary data
  8810. $out .= ' /Filter /FlateDecode';
  8811. }
  8812. $out .= ' >>';
  8813. $out .= ' stream'."\n".$stream."\n".'endstream';
  8814. $out .= "\n".'endobj';
  8815. $this->_out($out);
  8816. }
  8817. }
  8818. /**
  8819. * Output CID-0 fonts.
  8820. * A Type 0 CIDFont contains glyph descriptions based on the Adobe Type 1 font format
  8821. * @param $font (array) font data
  8822. * @protected
  8823. * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
  8824. * @since 3.2.000 (2008-06-23)
  8825. */
  8826. protected function _putcidfont0($font)
  8827. {
  8828. $cidoffset = 0;
  8829. if (!isset($font['cw'][1])) {
  8830. $cidoffset = 31;
  8831. }
  8832. if (isset($font['cidinfo']['uni2cid'])) {
  8833. // convert unicode to cid.
  8834. $uni2cid = $font['cidinfo']['uni2cid'];
  8835. $cw = array();
  8836. foreach ($font['cw'] as $uni => $width) {
  8837. if (isset($uni2cid[$uni])) {
  8838. $cw[($uni2cid[$uni] + $cidoffset)] = $width;
  8839. } elseif ($uni < 256) {
  8840. $cw[$uni] = $width;
  8841. } // else unknown character
  8842. }
  8843. $font = array_merge($font, array('cw' => $cw));
  8844. }
  8845. $name = $font['name'];
  8846. $enc = $font['enc'];
  8847. if ($enc) {
  8848. $longname = $name.'-'.$enc;
  8849. } else {
  8850. $longname = $name;
  8851. }
  8852. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  8853. $out .= '<</Type /Font';
  8854. $out .= ' /Subtype /Type0';
  8855. $out .= ' /BaseFont /'.$longname;
  8856. $out .= ' /Name /F'.$font['i'];
  8857. if ($enc) {
  8858. $out .= ' /Encoding /'.$enc;
  8859. }
  8860. $out .= ' /DescendantFonts ['.($this->n + 1).' 0 R]';
  8861. $out .= ' >>';
  8862. $out .= "\n".'endobj';
  8863. $this->_out($out);
  8864. $oid = $this->_newobj();
  8865. $out = '<</Type /Font';
  8866. $out .= ' /Subtype /CIDFontType0';
  8867. $out .= ' /BaseFont /'.$name;
  8868. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  8869. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  8870. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  8871. $out .= ' /CIDSystemInfo <<'.$cidinfo.'>>';
  8872. $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
  8873. $out .= ' /DW '.$font['dw'];
  8874. $out .= "\n".TCPDF_FONTS::_putfontwidths($font, $cidoffset);
  8875. $out .= ' >>';
  8876. $out .= "\n".'endobj';
  8877. $this->_out($out);
  8878. $this->_newobj();
  8879. $s = '<</Type /FontDescriptor /FontName /'.$name;
  8880. foreach ($font['desc'] as $k => $v) {
  8881. if ($k != 'Style') {
  8882. if (is_float($v)) {
  8883. $v = sprintf('%F', $v);
  8884. }
  8885. $s .= ' /'.$k.' '.$v.'';
  8886. }
  8887. }
  8888. $s .= '>>';
  8889. $s .= "\n".'endobj';
  8890. $this->_out($s);
  8891. }
  8892. /**
  8893. * Output images.
  8894. * @protected
  8895. */
  8896. protected function _putimages()
  8897. {
  8898. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  8899. foreach ($this->imagekeys as $file) {
  8900. $info = $this->getImageBuffer($file);
  8901. // set object for alternate images array
  8902. if ((!$this->pdfa_mode) AND isset($info['altimgs']) AND !empty($info['altimgs'])) {
  8903. $altoid = $this->_newobj();
  8904. $out = '[';
  8905. foreach ($info['altimgs'] as $altimage) {
  8906. if (isset($this->xobjects['I'.$altimage[0]]['n'])) {
  8907. $out .= ' << /Image '.$this->xobjects['I'.$altimage[0]]['n'].' 0 R';
  8908. $out .= ' /DefaultForPrinting';
  8909. if ($altimage[1] === true) {
  8910. $out .= ' true';
  8911. } else {
  8912. $out .= ' false';
  8913. }
  8914. $out .= ' >>';
  8915. }
  8916. }
  8917. $out .= ' ]';
  8918. $out .= "\n".'endobj';
  8919. $this->_out($out);
  8920. }
  8921. // set image object
  8922. $oid = $this->_newobj();
  8923. $this->xobjects['I'.$info['i']] = array('n' => $oid);
  8924. $this->setImageSubBuffer($file, 'n', $this->n);
  8925. $out = '<</Type /XObject';
  8926. $out .= ' /Subtype /Image';
  8927. $out .= ' /Width '.$info['w'];
  8928. $out .= ' /Height '.$info['h'];
  8929. if (array_key_exists('masked', $info)) {
  8930. $out .= ' /SMask '.($this->n - 1).' 0 R';
  8931. }
  8932. // set color space
  8933. $icc = false;
  8934. if (isset($info['icc']) AND ($info['icc'] !== false)) {
  8935. // ICC Colour Space
  8936. $icc = true;
  8937. $out .= ' /ColorSpace [/ICCBased '.($this->n + 1).' 0 R]';
  8938. } elseif ($info['cs'] == 'Indexed') {
  8939. // Indexed Colour Space
  8940. $out .= ' /ColorSpace [/Indexed /DeviceRGB '.((strlen($info['pal']) / 3) - 1).' '.($this->n + 1).' 0 R]';
  8941. } else {
  8942. // Device Colour Space
  8943. $out .= ' /ColorSpace /'.$info['cs'];
  8944. }
  8945. if ($info['cs'] == 'DeviceCMYK') {
  8946. $out .= ' /Decode [1 0 1 0 1 0 1 0]';
  8947. }
  8948. $out .= ' /BitsPerComponent '.$info['bpc'];
  8949. if (isset($altoid) AND ($altoid > 0)) {
  8950. // reference to alternate images dictionary
  8951. $out .= ' /Alternates '.$altoid.' 0 R';
  8952. }
  8953. if (isset($info['exurl']) AND !empty($info['exurl'])) {
  8954. // external stream
  8955. $out .= ' /Length 0';
  8956. $out .= ' /F << /FS /URL /F '.$this->_datastring($info['exurl'], $oid).' >>';
  8957. if (isset($info['f'])) {
  8958. $out .= ' /FFilter /'.$info['f'];
  8959. }
  8960. $out .= ' >>';
  8961. $out .= ' stream'."\n".'endstream';
  8962. } else {
  8963. if (isset($info['f'])) {
  8964. $out .= ' /Filter /'.$info['f'];
  8965. }
  8966. if (isset($info['parms'])) {
  8967. $out .= ' '.$info['parms'];
  8968. }
  8969. if (isset($info['trns']) AND is_array($info['trns'])) {
  8970. $trns = '';
  8971. $count_info = count($info['trns']);
  8972. if ($info['cs'] == 'Indexed') {
  8973. $maxval =(pow(2, $info['bpc']) - 1);
  8974. for ($i = 0; $i < $count_info; ++$i) {
  8975. if (($info['trns'][$i] != 0) AND ($info['trns'][$i] != $maxval)) {
  8976. // this is not a binary type mask @TODO: create a SMask
  8977. $trns = '';
  8978. break;
  8979. } elseif (empty($trns) AND ($info['trns'][$i] == 0)) {
  8980. // store the first fully transparent value
  8981. $trns .= $i.' '.$i.' ';
  8982. }
  8983. }
  8984. } else {
  8985. // grayscale or RGB
  8986. for ($i = 0; $i < $count_info; ++$i) {
  8987. if ($info['trns'][$i] == 0) {
  8988. $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
  8989. }
  8990. }
  8991. }
  8992. // Colour Key Masking
  8993. if (!empty($trns)) {
  8994. $out .= ' /Mask ['.$trns.']';
  8995. }
  8996. }
  8997. $stream = $this->_getrawstream($info['data']);
  8998. $out .= ' /Length '.strlen($stream).' >>';
  8999. $out .= ' stream'."\n".$stream."\n".'endstream';
  9000. }
  9001. $out .= "\n".'endobj';
  9002. $this->_out($out);
  9003. if ($icc) {
  9004. // ICC colour profile
  9005. $this->_newobj();
  9006. $icc = ($this->compress) ? gzcompress($info['icc']) : $info['icc'];
  9007. $icc = $this->_getrawstream($icc);
  9008. $this->_out('<</N '.$info['ch'].' /Alternate /'.$info['cs'].' '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
  9009. } elseif ($info['cs'] == 'Indexed') {
  9010. // colour palette
  9011. $this->_newobj();
  9012. $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  9013. $pal = $this->_getrawstream($pal);
  9014. $this->_out('<<'.$filter.'/Length '.strlen($pal).'>> stream'."\n".$pal."\n".'endstream'."\n".'endobj');
  9015. }
  9016. }
  9017. }
  9018. /**
  9019. * Output Form XObjects Templates.
  9020. * @author Nicola Asuni
  9021. * @since 5.8.017 (2010-08-24)
  9022. * @protected
  9023. * @see startTemplate(), endTemplate(), printTemplate()
  9024. */
  9025. protected function _putxobjects()
  9026. {
  9027. foreach ($this->xobjects as $key => $data) {
  9028. if (isset($data['outdata'])) {
  9029. $stream = str_replace($this->epsmarker, '', trim($data['outdata']));
  9030. $out = $this->_getobj($data['n'])."\n";
  9031. $out .= '<<';
  9032. $out .= ' /Type /XObject';
  9033. $out .= ' /Subtype /Form';
  9034. $out .= ' /FormType 1';
  9035. if ($this->compress) {
  9036. $stream = gzcompress($stream);
  9037. $out .= ' /Filter /FlateDecode';
  9038. }
  9039. $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));
  9040. $out .= ' /Matrix [1 0 0 1 0 0]';
  9041. $out .= ' /Resources <<';
  9042. $out .= ' /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  9043. if (!$this->pdfa_mode) {
  9044. // transparency
  9045. if (isset($data['extgstates']) AND !empty($data['extgstates'])) {
  9046. $out .= ' /ExtGState <<';
  9047. foreach ($data['extgstates'] as $k => $extgstate) {
  9048. if (isset($this->extgstates[$k]['name'])) {
  9049. $out .= ' /'.$this->extgstates[$k]['name'];
  9050. } else {
  9051. $out .= ' /GS'.$k;
  9052. }
  9053. $out .= ' '.$this->extgstates[$k]['n'].' 0 R';
  9054. }
  9055. $out .= ' >>';
  9056. }
  9057. if (isset($data['gradients']) AND !empty($data['gradients'])) {
  9058. $gp = '';
  9059. $gs = '';
  9060. foreach ($data['gradients'] as $id => $grad) {
  9061. // gradient patterns
  9062. $gp .= ' /p'.$id.' '.$this->gradients[$id]['pattern'].' 0 R';
  9063. // gradient shadings
  9064. $gs .= ' /Sh'.$id.' '.$this->gradients[$id]['id'].' 0 R';
  9065. }
  9066. $out .= ' /Pattern <<'.$gp.' >>';
  9067. $out .= ' /Shading <<'.$gs.' >>';
  9068. }
  9069. }
  9070. // spot colors
  9071. if (isset($data['spot_colors']) AND !empty($data['spot_colors'])) {
  9072. $out .= ' /ColorSpace <<';
  9073. foreach ($data['spot_colors'] as $name => $color) {
  9074. $out .= ' /CS'.$color['i'].' '.$this->spot_colors[$name]['n'].' 0 R';
  9075. }
  9076. $out .= ' >>';
  9077. }
  9078. // fonts
  9079. if (!empty($data['fonts'])) {
  9080. $out .= ' /Font <<';
  9081. foreach ($data['fonts'] as $fontkey => $fontid) {
  9082. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  9083. }
  9084. $out .= ' >>';
  9085. }
  9086. // images or nested xobjects
  9087. if (!empty($data['images']) OR !empty($data['xobjects'])) {
  9088. $out .= ' /XObject <<';
  9089. foreach ($data['images'] as $imgid) {
  9090. $out .= ' /I'.$imgid.' '.$this->xobjects['I'.$imgid]['n'].' 0 R';
  9091. }
  9092. foreach ($data['xobjects'] as $sub_id => $sub_objid) {
  9093. $out .= ' /'.$sub_id.' '.$sub_objid['n'].' 0 R';
  9094. }
  9095. $out .= ' >>';
  9096. }
  9097. $out .= ' >>'; //end resources
  9098. if (isset($data['group']) AND ($data['group'] !== false)) {
  9099. // set transparency group
  9100. $out .= ' /Group << /Type /Group /S /Transparency';
  9101. if (is_array($data['group'])) {
  9102. if (isset($data['group']['CS']) AND !empty($data['group']['CS'])) {
  9103. $out .= ' /CS /'.$data['group']['CS'];
  9104. }
  9105. if (isset($data['group']['I'])) {
  9106. $out .= ' /I /'.($data['group']['I']===true?'true':'false');
  9107. }
  9108. if (isset($data['group']['K'])) {
  9109. $out .= ' /K /'.($data['group']['K']===true?'true':'false');
  9110. }
  9111. }
  9112. $out .= ' >>';
  9113. }
  9114. $stream = $this->_getrawstream($stream, $data['n']);
  9115. $out .= ' /Length '.strlen($stream);
  9116. $out .= ' >>';
  9117. $out .= ' stream'."\n".$stream."\n".'endstream';
  9118. $out .= "\n".'endobj';
  9119. $this->_out($out);
  9120. }
  9121. }
  9122. }
  9123. /**
  9124. * Output Spot Colors Resources.
  9125. * @protected
  9126. * @since 4.0.024 (2008-09-12)
  9127. */
  9128. protected function _putspotcolors()
  9129. {
  9130. foreach ($this->spot_colors as $name => $color) {
  9131. $this->_newobj();
  9132. $this->spot_colors[$name]['n'] = $this->n;
  9133. $out = '[/Separation /'.str_replace(' ', '#20', $name);
  9134. $out .= ' /DeviceCMYK <<';
  9135. $out .= ' /Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0]';
  9136. $out .= ' '.sprintf('/C1 [%F %F %F %F] ', ($color['C'] / 100), ($color['M'] / 100), ($color['Y'] / 100), ($color['K'] / 100));
  9137. $out .= ' /FunctionType 2 /Domain [0 1] /N 1>>]';
  9138. $out .= "\n".'endobj';
  9139. $this->_out($out);
  9140. }
  9141. }
  9142. /**
  9143. * Return XObjects Dictionary.
  9144. * @return string XObjects dictionary
  9145. * @protected
  9146. * @since 5.8.014 (2010-08-23)
  9147. */
  9148. protected function _getxobjectdict()
  9149. {
  9150. $out = '';
  9151. foreach ($this->xobjects as $id => $objid) {
  9152. $out .= ' /'.$id.' '.$objid['n'].' 0 R';
  9153. }
  9154. return $out;
  9155. }
  9156. /**
  9157. * Output Resources Dictionary.
  9158. * @protected
  9159. */
  9160. protected function _putresourcedict()
  9161. {
  9162. $out = $this->_getobj(2)."\n";
  9163. $out .= '<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  9164. $out .= ' /Font <<';
  9165. foreach ($this->fontkeys as $fontkey) {
  9166. $font = $this->getFontBuffer($fontkey);
  9167. $out .= ' /F'.$font['i'].' '.$font['n'].' 0 R';
  9168. }
  9169. $out .= ' >>';
  9170. $out .= ' /XObject <<';
  9171. $out .= $this->_getxobjectdict();
  9172. $out .= ' >>';
  9173. // layers
  9174. if (!empty($this->pdflayers)) {
  9175. $out .= ' /Properties <<';
  9176. foreach ($this->pdflayers as $layer) {
  9177. $out .= ' /'.$layer['layer'].' '.$layer['objid'].' 0 R';
  9178. }
  9179. $out .= ' >>';
  9180. }
  9181. if (!$this->pdfa_mode) {
  9182. // transparency
  9183. if (isset($this->extgstates) AND !empty($this->extgstates)) {
  9184. $out .= ' /ExtGState <<';
  9185. foreach ($this->extgstates as $k => $extgstate) {
  9186. if (isset($extgstate['name'])) {
  9187. $out .= ' /'.$extgstate['name'];
  9188. } else {
  9189. $out .= ' /GS'.$k;
  9190. }
  9191. $out .= ' '.$extgstate['n'].' 0 R';
  9192. }
  9193. $out .= ' >>';
  9194. }
  9195. if (isset($this->gradients) AND !empty($this->gradients)) {
  9196. $gp = '';
  9197. $gs = '';
  9198. foreach ($this->gradients as $id => $grad) {
  9199. // gradient patterns
  9200. $gp .= ' /p'.$id.' '.$grad['pattern'].' 0 R';
  9201. // gradient shadings
  9202. $gs .= ' /Sh'.$id.' '.$grad['id'].' 0 R';
  9203. }
  9204. $out .= ' /Pattern <<'.$gp.' >>';
  9205. $out .= ' /Shading <<'.$gs.' >>';
  9206. }
  9207. }
  9208. // spot colors
  9209. if (isset($this->spot_colors) AND !empty($this->spot_colors)) {
  9210. $out .= ' /ColorSpace <<';
  9211. foreach ($this->spot_colors as $color) {
  9212. $out .= ' /CS'.$color['i'].' '.$color['n'].' 0 R';
  9213. }
  9214. $out .= ' >>';
  9215. }
  9216. $out .= ' >>';
  9217. $out .= "\n".'endobj';
  9218. $this->_out($out);
  9219. }
  9220. /**
  9221. * Output Resources.
  9222. * @protected
  9223. */
  9224. protected function _putresources()
  9225. {
  9226. $this->_putextgstates();
  9227. $this->_putocg();
  9228. $this->_putfonts();
  9229. $this->_putimages();
  9230. $this->_putspotcolors();
  9231. $this->_putshaders();
  9232. $this->_putxobjects();
  9233. $this->_putresourcedict();
  9234. $this->_putdests();
  9235. $this->_putEmbeddedFiles();
  9236. $this->_putannotsobjs();
  9237. $this->_putjavascript();
  9238. $this->_putbookmarks();
  9239. $this->_putencryption();
  9240. }
  9241. /**
  9242. * Adds some Metadata information (Document Information Dictionary)
  9243. * (see Chapter 14.3.3 Document Information Dictionary of PDF32000_2008.pdf Reference)
  9244. * @return int object id
  9245. * @protected
  9246. */
  9247. protected function _putinfo()
  9248. {
  9249. $oid = $this->_newobj();
  9250. $out = '<<';
  9251. // store current isunicode value
  9252. $prev_isunicode = $this->isunicode;
  9253. if ($this->docinfounicode) {
  9254. $this->isunicode = true;
  9255. }
  9256. if (!TCPDF_STATIC::empty_string($this->title)) {
  9257. // The document's title.
  9258. $out .= ' /Title '.$this->_textstring($this->title, $oid);
  9259. }
  9260. if (!TCPDF_STATIC::empty_string($this->author)) {
  9261. // The name of the person who created the document.
  9262. $out .= ' /Author '.$this->_textstring($this->author, $oid);
  9263. }
  9264. if (!TCPDF_STATIC::empty_string($this->subject)) {
  9265. // The subject of the document.
  9266. $out .= ' /Subject '.$this->_textstring($this->subject, $oid);
  9267. }
  9268. if (!TCPDF_STATIC::empty_string($this->keywords)) {
  9269. // Keywords associated with the document.
  9270. $out .= ' /Keywords '.$this->_textstring($this->keywords, $oid);
  9271. }
  9272. if (!TCPDF_STATIC::empty_string($this->creator)) {
  9273. // 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.
  9274. $out .= ' /Creator '.$this->_textstring($this->creator, $oid);
  9275. }
  9276. // restore previous isunicode value
  9277. $this->isunicode = $prev_isunicode;
  9278. // default producer
  9279. $out .= ' /Producer '.$this->_textstring(TCPDF_STATIC::getTCPDFProducer(), $oid);
  9280. // The date and time the document was created, in human-readable form
  9281. $out .= ' /CreationDate '.$this->_datestring(0, $this->doc_creation_timestamp);
  9282. // The date and time the document was most recently modified, in human-readable form
  9283. $out .= ' /ModDate '.$this->_datestring(0, $this->doc_modification_timestamp);
  9284. // A name object indicating whether the document has been modified to include trapping information
  9285. $out .= ' /Trapped /False';
  9286. $out .= ' >>';
  9287. $out .= "\n".'endobj';
  9288. $this->_out($out);
  9289. return $oid;
  9290. }
  9291. /**
  9292. * Set additional XMP data to be added on the default XMP data just before the end of "x:xmpmeta" tag.
  9293. * IMPORTANT: This data is added as-is without controls, so you have to validate your data before using this method!
  9294. * @param $xmp (string) Custom XMP data.
  9295. * @since 5.9.128 (2011-10-06)
  9296. * @public
  9297. */
  9298. public function setExtraXMP($xmp)
  9299. {
  9300. $this->custom_xmp = $xmp;
  9301. }
  9302. /**
  9303. * Set additional XMP data to be added on the default XMP data just before the end of "rdf:RDF" tag.
  9304. * IMPORTANT: This data is added as-is without controls, so you have to validate your data before using this method!
  9305. * @param $xmp (string) Custom XMP RDF data.
  9306. * @since 6.3.0 (2019-09-19)
  9307. * @public
  9308. */
  9309. public function setExtraXMPRDF($xmp)
  9310. {
  9311. $this->custom_xmp_rdf = $xmp;
  9312. }
  9313. /**
  9314. * Put XMP data object and return ID.
  9315. * @return (int) The object ID.
  9316. * @since 5.9.121 (2011-09-28)
  9317. * @protected
  9318. */
  9319. protected function _putXMP()
  9320. {
  9321. $oid = $this->_newobj();
  9322. // store current isunicode value
  9323. $prev_isunicode = $this->isunicode;
  9324. $this->isunicode = true;
  9325. $prev_encrypted = $this->encrypted;
  9326. $this->encrypted = false;
  9327. // set XMP data
  9328. $xmp = '<?xpacket begin="'.TCPDF_FONTS::unichr(0xfeff, $this->isunicode).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n";
  9329. $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";
  9330. $xmp .= "\t".'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n";
  9331. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
  9332. $xmp .= "\t\t\t".'<dc:format>application/pdf</dc:format>'."\n";
  9333. $xmp .= "\t\t\t".'<dc:title>'."\n";
  9334. $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
  9335. $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.TCPDF_STATIC::_escapeXML($this->title).'</rdf:li>'."\n";
  9336. $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
  9337. $xmp .= "\t\t\t".'</dc:title>'."\n";
  9338. $xmp .= "\t\t\t".'<dc:creator>'."\n";
  9339. $xmp .= "\t\t\t\t".'<rdf:Seq>'."\n";
  9340. $xmp .= "\t\t\t\t\t".'<rdf:li>'.TCPDF_STATIC::_escapeXML($this->author).'</rdf:li>'."\n";
  9341. $xmp .= "\t\t\t\t".'</rdf:Seq>'."\n";
  9342. $xmp .= "\t\t\t".'</dc:creator>'."\n";
  9343. $xmp .= "\t\t\t".'<dc:description>'."\n";
  9344. $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
  9345. $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.TCPDF_STATIC::_escapeXML($this->subject).'</rdf:li>'."\n";
  9346. $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
  9347. $xmp .= "\t\t\t".'</dc:description>'."\n";
  9348. $xmp .= "\t\t\t".'<dc:subject>'."\n";
  9349. $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
  9350. $xmp .= "\t\t\t\t\t".'<rdf:li>'.TCPDF_STATIC::_escapeXML($this->keywords).'</rdf:li>'."\n";
  9351. $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
  9352. $xmp .= "\t\t\t".'</dc:subject>'."\n";
  9353. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9354. // convert doc creation date format
  9355. $dcdate = TCPDF_STATIC::getFormattedDate($this->doc_creation_timestamp);
  9356. $doccreationdate = substr($dcdate, 0, 4).'-'.substr($dcdate, 4, 2).'-'.substr($dcdate, 6, 2);
  9357. $doccreationdate .= 'T'.substr($dcdate, 8, 2).':'.substr($dcdate, 10, 2).':'.substr($dcdate, 12, 2);
  9358. $doccreationdate .= substr($dcdate, 14, 3).':'.substr($dcdate, 18, 2);
  9359. $doccreationdate = TCPDF_STATIC::_escapeXML($doccreationdate);
  9360. // convert doc modification date format
  9361. $dmdate = TCPDF_STATIC::getFormattedDate($this->doc_modification_timestamp);
  9362. $docmoddate = substr($dmdate, 0, 4).'-'.substr($dmdate, 4, 2).'-'.substr($dmdate, 6, 2);
  9363. $docmoddate .= 'T'.substr($dmdate, 8, 2).':'.substr($dmdate, 10, 2).':'.substr($dmdate, 12, 2);
  9364. $docmoddate .= substr($dmdate, 14, 3).':'.substr($dmdate, 18, 2);
  9365. $docmoddate = TCPDF_STATIC::_escapeXML($docmoddate);
  9366. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n";
  9367. $xmp .= "\t\t\t".'<xmp:CreateDate>'.$doccreationdate.'</xmp:CreateDate>'."\n";
  9368. $xmp .= "\t\t\t".'<xmp:CreatorTool>'.$this->creator.'</xmp:CreatorTool>'."\n";
  9369. $xmp .= "\t\t\t".'<xmp:ModifyDate>'.$docmoddate.'</xmp:ModifyDate>'."\n";
  9370. $xmp .= "\t\t\t".'<xmp:MetadataDate>'.$doccreationdate.'</xmp:MetadataDate>'."\n";
  9371. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9372. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n";
  9373. $xmp .= "\t\t\t".'<pdf:Keywords>'.TCPDF_STATIC::_escapeXML($this->keywords).'</pdf:Keywords>'."\n";
  9374. $xmp .= "\t\t\t".'<pdf:Producer>'.TCPDF_STATIC::_escapeXML(TCPDF_STATIC::getTCPDFProducer()).'</pdf:Producer>'."\n";
  9375. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9376. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n";
  9377. $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);
  9378. $xmp .= "\t\t\t".'<xmpMM:DocumentID>'.$uuid.'</xmpMM:DocumentID>'."\n";
  9379. $xmp .= "\t\t\t".'<xmpMM:InstanceID>'.$uuid.'</xmpMM:InstanceID>'."\n";
  9380. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9381. if ($this->pdfa_mode) {
  9382. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">'."\n";
  9383. $xmp .= "\t\t\t".'<pdfaid:part>'.$this->pdfa_version.'</pdfaid:part>'."\n";
  9384. $xmp .= "\t\t\t".'<pdfaid:conformance>B</pdfaid:conformance>'."\n";
  9385. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9386. }
  9387. // XMP extension schemas
  9388. $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";
  9389. $xmp .= "\t\t\t".'<pdfaExtension:schemas>'."\n";
  9390. $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
  9391. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9392. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/pdf/1.3/</pdfaSchema:namespaceURI>'."\n";
  9393. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdf</pdfaSchema:prefix>'."\n";
  9394. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>Adobe PDF Schema</pdfaSchema:schema>'."\n";
  9395. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9396. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9397. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/xap/1.0/mm/</pdfaSchema:namespaceURI>'."\n";
  9398. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>xmpMM</pdfaSchema:prefix>'."\n";
  9399. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>XMP Media Management Schema</pdfaSchema:schema>'."\n";
  9400. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  9401. $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  9402. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9403. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9404. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>UUID based identifier for specific incarnation of a document</pdfaProperty:description>'."\n";
  9405. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>InstanceID</pdfaProperty:name>'."\n";
  9406. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>URI</pdfaProperty:valueType>'."\n";
  9407. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9408. $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  9409. $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  9410. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9411. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9412. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://www.aiim.org/pdfa/ns/id/</pdfaSchema:namespaceURI>'."\n";
  9413. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdfaid</pdfaSchema:prefix>'."\n";
  9414. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>PDF/A ID Schema</pdfaSchema:schema>'."\n";
  9415. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  9416. $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  9417. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9418. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9419. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Part of PDF/A standard</pdfaProperty:description>'."\n";
  9420. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>part</pdfaProperty:name>'."\n";
  9421. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Integer</pdfaProperty:valueType>'."\n";
  9422. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9423. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9424. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9425. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Amendment of PDF/A standard</pdfaProperty:description>'."\n";
  9426. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>amd</pdfaProperty:name>'."\n";
  9427. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
  9428. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9429. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9430. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9431. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Conformance level of PDF/A standard</pdfaProperty:description>'."\n";
  9432. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>conformance</pdfaProperty:name>'."\n";
  9433. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
  9434. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9435. $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  9436. $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  9437. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9438. $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
  9439. $xmp .= "\t\t\t".'</pdfaExtension:schemas>'."\n";
  9440. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9441. $xmp .= $this->custom_xmp_rdf;
  9442. $xmp .= "\t".'</rdf:RDF>'."\n";
  9443. $xmp .= $this->custom_xmp;
  9444. $xmp .= '</x:xmpmeta>'."\n";
  9445. $xmp .= '<?xpacket end="w"?>';
  9446. $out = '<< /Type /Metadata /Subtype /XML /Length '.strlen($xmp).' >> stream'."\n".$xmp."\n".'endstream'."\n".'endobj';
  9447. // restore previous isunicode value
  9448. $this->isunicode = $prev_isunicode;
  9449. $this->encrypted = $prev_encrypted;
  9450. $this->_out($out);
  9451. return $oid;
  9452. }
  9453. /**
  9454. * Output Catalog.
  9455. * @return int object id
  9456. * @protected
  9457. */
  9458. protected function _putcatalog()
  9459. {
  9460. // put XMP
  9461. $xmpobj = $this->_putXMP();
  9462. // if required, add standard sRGB ICC colour profile
  9463. if ($this->pdfa_mode OR $this->force_srgb) {
  9464. $iccobj = $this->_newobj();
  9465. $icc = file_get_contents(dirname(__FILE__).'/include/sRGB.icc');
  9466. $filter = '';
  9467. if ($this->compress) {
  9468. $filter = ' /Filter /FlateDecode';
  9469. $icc = gzcompress($icc);
  9470. }
  9471. $icc = $this->_getrawstream($icc);
  9472. $this->_out('<</N 3 '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
  9473. }
  9474. // start catalog
  9475. $oid = $this->_newobj();
  9476. $out = '<< /Type /Catalog';
  9477. $out .= ' /Version /'.$this->PDFVersion;
  9478. //$out .= ' /Extensions <<>>';
  9479. $out .= ' /Pages 1 0 R';
  9480. //$out .= ' /PageLabels ' //...;
  9481. $out .= ' /Names <<';
  9482. if ((!$this->pdfa_mode) AND !empty($this->n_js)) {
  9483. $out .= ' /JavaScript '.$this->n_js;
  9484. }
  9485. if (!empty($this->efnames)) {
  9486. $out .= ' /EmbeddedFiles <</Names [';
  9487. foreach ($this->efnames AS $fn => $fref) {
  9488. $out .= ' '.$this->_datastring($fn).' '.$fref;
  9489. }
  9490. $out .= ' ]>>';
  9491. }
  9492. $out .= ' >>';
  9493. if (!empty($this->dests)) {
  9494. $out .= ' /Dests '.($this->n_dests).' 0 R';
  9495. }
  9496. $out .= $this->_putviewerpreferences();
  9497. if (isset($this->LayoutMode) AND (!TCPDF_STATIC::empty_string($this->LayoutMode))) {
  9498. $out .= ' /PageLayout /'.$this->LayoutMode;
  9499. }
  9500. if (isset($this->PageMode) AND (!TCPDF_STATIC::empty_string($this->PageMode))) {
  9501. $out .= ' /PageMode /'.$this->PageMode;
  9502. }
  9503. if (count($this->outlines) > 0) {
  9504. $out .= ' /Outlines '.$this->OutlineRoot.' 0 R';
  9505. $out .= ' /PageMode /UseOutlines';
  9506. }
  9507. //$out .= ' /Threads []';
  9508. if ($this->ZoomMode == 'fullpage') {
  9509. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /Fit]';
  9510. } elseif ($this->ZoomMode == 'fullwidth') {
  9511. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /FitH null]';
  9512. } elseif ($this->ZoomMode == 'real') {
  9513. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null 1]';
  9514. } elseif (!is_string($this->ZoomMode)) {
  9515. $out .= sprintf(' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null %F]', ($this->ZoomMode / 100));
  9516. }
  9517. //$out .= ' /AA <<>>';
  9518. //$out .= ' /URI <<>>';
  9519. $out .= ' /Metadata '.$xmpobj.' 0 R';
  9520. //$out .= ' /StructTreeRoot <<>>';
  9521. //$out .= ' /MarkInfo <<>>';
  9522. if (isset($this->l['a_meta_language'])) {
  9523. $out .= ' /Lang '.$this->_textstring($this->l['a_meta_language'], $oid);
  9524. }
  9525. //$out .= ' /SpiderInfo <<>>';
  9526. // set OutputIntent to sRGB IEC61966-2.1 if required
  9527. if ($this->pdfa_mode OR $this->force_srgb) {
  9528. $out .= ' /OutputIntents [<<';
  9529. $out .= ' /Type /OutputIntent';
  9530. $out .= ' /S /GTS_PDFA1';
  9531. $out .= ' /OutputCondition '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  9532. $out .= ' /OutputConditionIdentifier '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  9533. $out .= ' /RegistryName '.$this->_textstring('http://www.color.org', $oid);
  9534. $out .= ' /Info '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  9535. $out .= ' /DestOutputProfile '.$iccobj.' 0 R';
  9536. $out .= ' >>]';
  9537. }
  9538. //$out .= ' /PieceInfo <<>>';
  9539. if (!empty($this->pdflayers)) {
  9540. $lyrobjs = '';
  9541. $lyrobjs_off = '';
  9542. $lyrobjs_lock = '';
  9543. foreach ($this->pdflayers as $layer) {
  9544. $layer_obj_ref = ' '.$layer['objid'].' 0 R';
  9545. $lyrobjs .= $layer_obj_ref;
  9546. if ($layer['view'] === false) {
  9547. $lyrobjs_off .= $layer_obj_ref;
  9548. }
  9549. if ($layer['lock']) {
  9550. $lyrobjs_lock .= $layer_obj_ref;
  9551. }
  9552. }
  9553. $out .= ' /OCProperties << /OCGs ['.$lyrobjs.']';
  9554. $out .= ' /D <<';
  9555. $out .= ' /Name '.$this->_textstring('Layers', $oid);
  9556. $out .= ' /Creator '.$this->_textstring('TCPDF', $oid);
  9557. $out .= ' /BaseState /ON';
  9558. $out .= ' /OFF ['.$lyrobjs_off.']';
  9559. $out .= ' /Locked ['.$lyrobjs_lock.']';
  9560. $out .= ' /Intent /View';
  9561. $out .= ' /AS [';
  9562. $out .= ' << /Event /Print /OCGs ['.$lyrobjs.'] /Category [/Print] >>';
  9563. $out .= ' << /Event /View /OCGs ['.$lyrobjs.'] /Category [/View] >>';
  9564. $out .= ' ]';
  9565. $out .= ' /Order ['.$lyrobjs.']';
  9566. $out .= ' /ListMode /AllPages';
  9567. //$out .= ' /RBGroups ['..']';
  9568. //$out .= ' /Locked ['..']';
  9569. $out .= ' >>';
  9570. $out .= ' >>';
  9571. }
  9572. // AcroForm
  9573. if (!empty($this->form_obj_id)
  9574. OR ($this->sign AND isset($this->signature_data['cert_type']))
  9575. OR !empty($this->empty_signature_appearance)) {
  9576. $out .= ' /AcroForm <<';
  9577. $objrefs = '';
  9578. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9579. // set reference for signature object
  9580. $objrefs .= $this->sig_obj_id.' 0 R';
  9581. }
  9582. if (!empty($this->empty_signature_appearance)) {
  9583. foreach ($this->empty_signature_appearance as $esa) {
  9584. // set reference for empty signature objects
  9585. $objrefs .= ' '.$esa['objid'].' 0 R';
  9586. }
  9587. }
  9588. if (!empty($this->form_obj_id)) {
  9589. foreach ($this->form_obj_id as $objid) {
  9590. $objrefs .= ' '.$objid.' 0 R';
  9591. }
  9592. }
  9593. $out .= ' /Fields ['.$objrefs.']';
  9594. // It's better to turn off this value and set the appearance stream for each annotation (/AP) to avoid conflicts with signature fields.
  9595. if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) {
  9596. $out .= ' /NeedAppearances false';
  9597. }
  9598. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9599. if ($this->signature_data['cert_type'] > 0) {
  9600. $out .= ' /SigFlags 3';
  9601. } else {
  9602. $out .= ' /SigFlags 1';
  9603. }
  9604. }
  9605. //$out .= ' /CO ';
  9606. if (isset($this->annotation_fonts) AND !empty($this->annotation_fonts)) {
  9607. $out .= ' /DR <<';
  9608. $out .= ' /Font <<';
  9609. foreach ($this->annotation_fonts as $fontkey => $fontid) {
  9610. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  9611. }
  9612. $out .= ' >> >>';
  9613. }
  9614. $font = $this->getFontBuffer('helvetica');
  9615. $out .= ' /DA (/F'.$font['i'].' 0 Tf 0 g)';
  9616. $out .= ' /Q '.(($this->rtl)?'2':'0');
  9617. //$out .= ' /XFA ';
  9618. $out .= ' >>';
  9619. // signatures
  9620. if ($this->sign AND isset($this->signature_data['cert_type'])
  9621. AND (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A'))) {
  9622. if ($this->signature_data['cert_type'] > 0) {
  9623. $out .= ' /Perms << /DocMDP '.($this->sig_obj_id + 1).' 0 R >>';
  9624. } else {
  9625. $out .= ' /Perms << /UR3 '.($this->sig_obj_id + 1).' 0 R >>';
  9626. }
  9627. }
  9628. }
  9629. //$out .= ' /Legal <<>>';
  9630. //$out .= ' /Requirements []';
  9631. //$out .= ' /Collection <<>>';
  9632. //$out .= ' /NeedsRendering true';
  9633. $out .= ' >>';
  9634. $out .= "\n".'endobj';
  9635. $this->_out($out);
  9636. return $oid;
  9637. }
  9638. /**
  9639. * Output viewer preferences.
  9640. * @return string for viewer preferences
  9641. * @author Nicola asuni
  9642. * @since 3.1.000 (2008-06-09)
  9643. * @protected
  9644. */
  9645. protected function _putviewerpreferences()
  9646. {
  9647. $vp = $this->viewer_preferences;
  9648. $out = ' /ViewerPreferences <<';
  9649. if ($this->rtl) {
  9650. $out .= ' /Direction /R2L';
  9651. } else {
  9652. $out .= ' /Direction /L2R';
  9653. }
  9654. if (isset($vp['HideToolbar']) AND ($vp['HideToolbar'])) {
  9655. $out .= ' /HideToolbar true';
  9656. }
  9657. if (isset($vp['HideMenubar']) AND ($vp['HideMenubar'])) {
  9658. $out .= ' /HideMenubar true';
  9659. }
  9660. if (isset($vp['HideWindowUI']) AND ($vp['HideWindowUI'])) {
  9661. $out .= ' /HideWindowUI true';
  9662. }
  9663. if (isset($vp['FitWindow']) AND ($vp['FitWindow'])) {
  9664. $out .= ' /FitWindow true';
  9665. }
  9666. if (isset($vp['CenterWindow']) AND ($vp['CenterWindow'])) {
  9667. $out .= ' /CenterWindow true';
  9668. }
  9669. if (isset($vp['DisplayDocTitle']) AND ($vp['DisplayDocTitle'])) {
  9670. $out .= ' /DisplayDocTitle true';
  9671. }
  9672. if (isset($vp['NonFullScreenPageMode'])) {
  9673. $out .= ' /NonFullScreenPageMode /'.$vp['NonFullScreenPageMode'];
  9674. }
  9675. if (isset($vp['ViewArea'])) {
  9676. $out .= ' /ViewArea /'.$vp['ViewArea'];
  9677. }
  9678. if (isset($vp['ViewClip'])) {
  9679. $out .= ' /ViewClip /'.$vp['ViewClip'];
  9680. }
  9681. if (isset($vp['PrintArea'])) {
  9682. $out .= ' /PrintArea /'.$vp['PrintArea'];
  9683. }
  9684. if (isset($vp['PrintClip'])) {
  9685. $out .= ' /PrintClip /'.$vp['PrintClip'];
  9686. }
  9687. if (isset($vp['PrintScaling'])) {
  9688. $out .= ' /PrintScaling /'.$vp['PrintScaling'];
  9689. }
  9690. if (isset($vp['Duplex']) AND (!TCPDF_STATIC::empty_string($vp['Duplex']))) {
  9691. $out .= ' /Duplex /'.$vp['Duplex'];
  9692. }
  9693. if (isset($vp['PickTrayByPDFSize'])) {
  9694. if ($vp['PickTrayByPDFSize']) {
  9695. $out .= ' /PickTrayByPDFSize true';
  9696. } else {
  9697. $out .= ' /PickTrayByPDFSize false';
  9698. }
  9699. }
  9700. if (isset($vp['PrintPageRange'])) {
  9701. $PrintPageRangeNum = '';
  9702. foreach ($vp['PrintPageRange'] as $k => $v) {
  9703. $PrintPageRangeNum .= ' '.($v - 1).'';
  9704. }
  9705. $out .= ' /PrintPageRange ['.substr($PrintPageRangeNum, 1).']';
  9706. }
  9707. if (isset($vp['NumCopies'])) {
  9708. $out .= ' /NumCopies '.intval($vp['NumCopies']);
  9709. }
  9710. $out .= ' >>';
  9711. return $out;
  9712. }
  9713. /**
  9714. * Output PDF File Header (7.5.2).
  9715. * @protected
  9716. */
  9717. protected function _putheader()
  9718. {
  9719. $this->_out('%PDF-'.$this->PDFVersion);
  9720. $this->_out('%'.chr(0xe2).chr(0xe3).chr(0xcf).chr(0xd3));
  9721. }
  9722. /**
  9723. * Output end of document (EOF).
  9724. * @protected
  9725. */
  9726. protected function _enddoc()
  9727. {
  9728. if (isset($this->CurrentFont['fontkey']) AND isset($this->CurrentFont['subsetchars'])) {
  9729. // save subset chars of the previous font
  9730. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  9731. }
  9732. $this->state = 1;
  9733. $this->_putheader();
  9734. $this->_putpages();
  9735. $this->_putresources();
  9736. // empty signature fields
  9737. if (!empty($this->empty_signature_appearance)) {
  9738. foreach ($this->empty_signature_appearance as $key => $esa) {
  9739. // widget annotation for empty signature
  9740. $out = $this->_getobj($esa['objid'])."\n";
  9741. $out .= '<< /Type /Annot';
  9742. $out .= ' /Subtype /Widget';
  9743. $out .= ' /Rect ['.$esa['rect'].']';
  9744. $out .= ' /P '.$this->page_obj_id[($esa['page'])].' 0 R'; // link to signature appearance page
  9745. $out .= ' /F 4';
  9746. $out .= ' /FT /Sig';
  9747. $signame = $esa['name'].sprintf(' [%03d]', ($key + 1));
  9748. $out .= ' /T '.$this->_textstring($signame, $esa['objid']);
  9749. $out .= ' /Ff 0';
  9750. $out .= ' >>';
  9751. $out .= "\n".'endobj';
  9752. $this->_out($out);
  9753. }
  9754. }
  9755. // Signature
  9756. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9757. // widget annotation for signature
  9758. $out = $this->_getobj($this->sig_obj_id)."\n";
  9759. $out .= '<< /Type /Annot';
  9760. $out .= ' /Subtype /Widget';
  9761. $out .= ' /Rect ['.$this->signature_appearance['rect'].']';
  9762. $out .= ' /P '.$this->page_obj_id[($this->signature_appearance['page'])].' 0 R'; // link to signature appearance page
  9763. $out .= ' /F 4';
  9764. $out .= ' /FT /Sig';
  9765. $out .= ' /T '.$this->_textstring($this->signature_appearance['name'], $this->sig_obj_id);
  9766. $out .= ' /Ff 0';
  9767. $out .= ' /V '.($this->sig_obj_id + 1).' 0 R';
  9768. $out .= ' >>';
  9769. $out .= "\n".'endobj';
  9770. $this->_out($out);
  9771. // signature
  9772. $this->_putsignature();
  9773. }
  9774. // Info
  9775. $objid_info = $this->_putinfo();
  9776. // Catalog
  9777. $objid_catalog = $this->_putcatalog();
  9778. // Cross-ref
  9779. $o = $this->bufferlen;
  9780. // XREF section
  9781. $this->_out('xref');
  9782. $this->_out('0 '.($this->n + 1));
  9783. $this->_out('0000000000 65535 f ');
  9784. $freegen = ($this->n + 2);
  9785. for ($i=1; $i <= $this->n; ++$i) {
  9786. if (!isset($this->offsets[$i]) AND ($i > 1)) {
  9787. $this->_out(sprintf('0000000000 %05d f ', $freegen));
  9788. ++$freegen;
  9789. } else {
  9790. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
  9791. }
  9792. }
  9793. // TRAILER
  9794. $out = 'trailer'."\n";
  9795. $out .= '<<';
  9796. $out .= ' /Size '.($this->n + 1);
  9797. $out .= ' /Root '.$objid_catalog.' 0 R';
  9798. $out .= ' /Info '.$objid_info.' 0 R';
  9799. if ($this->encrypted) {
  9800. $out .= ' /Encrypt '.$this->encryptdata['objid'].' 0 R';
  9801. }
  9802. $out .= ' /ID [ <'.$this->file_id.'> <'.$this->file_id.'> ]';
  9803. $out .= ' >>';
  9804. $this->_out($out);
  9805. $this->_out('startxref');
  9806. $this->_out($o);
  9807. $this->_out('%%EOF');
  9808. $this->state = 3; // end-of-doc
  9809. }
  9810. /**
  9811. * Initialize a new page.
  9812. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  9813. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  9814. * @protected
  9815. * @see getPageSizeFromFormat(), setPageFormat()
  9816. */
  9817. protected function _beginpage($orientation = '', $format = '')
  9818. {
  9819. ++$this->page;
  9820. $this->pageobjects[$this->page] = array();
  9821. $this->setPageBuffer($this->page, '');
  9822. // initialize array for graphics tranformation positions inside a page buffer
  9823. $this->transfmrk[$this->page] = array();
  9824. $this->state = 2;
  9825. if (TCPDF_STATIC::empty_string($orientation)) {
  9826. if (isset($this->CurOrientation)) {
  9827. $orientation = $this->CurOrientation;
  9828. } elseif ($this->fwPt > $this->fhPt) {
  9829. // landscape
  9830. $orientation = 'L';
  9831. } else {
  9832. // portrait
  9833. $orientation = 'P';
  9834. }
  9835. }
  9836. if (TCPDF_STATIC::empty_string($format)) {
  9837. $this->pagedim[$this->page] = $this->pagedim[($this->page - 1)];
  9838. $this->setPageOrientation($orientation);
  9839. } else {
  9840. $this->setPageFormat($format, $orientation);
  9841. }
  9842. if ($this->rtl) {
  9843. $this->x = $this->w - $this->rMargin;
  9844. } else {
  9845. $this->x = $this->lMargin;
  9846. }
  9847. $this->y = $this->tMargin;
  9848. if (isset($this->newpagegroup[$this->page])) {
  9849. // start a new group
  9850. $this->currpagegroup = $this->newpagegroup[$this->page];
  9851. $this->pagegroups[$this->currpagegroup] = 1;
  9852. } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) {
  9853. ++$this->pagegroups[$this->currpagegroup];
  9854. }
  9855. }
  9856. /**
  9857. * Mark end of page.
  9858. * @protected
  9859. */
  9860. protected function _endpage()
  9861. {
  9862. $this->setVisibility('all');
  9863. $this->state = 1;
  9864. }
  9865. /**
  9866. * Begin a new object and return the object number.
  9867. * @return int object number
  9868. * @protected
  9869. */
  9870. protected function _newobj()
  9871. {
  9872. $this->_out($this->_getobj());
  9873. return $this->n;
  9874. }
  9875. /**
  9876. * Return the starting object string for the selected object ID.
  9877. * @param $objid (int) Object ID (leave empty to get a new ID).
  9878. * @return string the starting object string
  9879. * @protected
  9880. * @since 5.8.009 (2010-08-20)
  9881. */
  9882. protected function _getobj($objid = '')
  9883. {
  9884. if ($objid === '') {
  9885. ++$this->n;
  9886. $objid = $this->n;
  9887. }
  9888. $this->offsets[$objid] = $this->bufferlen;
  9889. $this->pageobjects[$this->page][] = $objid;
  9890. return $objid.' 0 obj';
  9891. }
  9892. /**
  9893. * Underline text.
  9894. * @param $x (int) X coordinate
  9895. * @param $y (int) Y coordinate
  9896. * @param $txt (string) text to underline
  9897. * @protected
  9898. */
  9899. protected function _dounderline($x, $y, $txt)
  9900. {
  9901. $w = $this->GetStringWidth($txt);
  9902. return $this->_dounderlinew($x, $y, $w);
  9903. }
  9904. /**
  9905. * Underline for rectangular text area.
  9906. * @param $x (int) X coordinate
  9907. * @param $y (int) Y coordinate
  9908. * @param $w (int) width to underline
  9909. * @protected
  9910. * @since 4.8.008 (2009-09-29)
  9911. */
  9912. protected function _dounderlinew($x, $y, $w)
  9913. {
  9914. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  9915. return sprintf('%F %F %F %F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew), $w * $this->k, $linew);
  9916. }
  9917. /**
  9918. * Line through text.
  9919. * @param $x (int) X coordinate
  9920. * @param $y (int) Y coordinate
  9921. * @param $txt (string) text to linethrough
  9922. * @protected
  9923. */
  9924. protected function _dolinethrough($x, $y, $txt)
  9925. {
  9926. $w = $this->GetStringWidth($txt);
  9927. return $this->_dolinethroughw($x, $y, $w);
  9928. }
  9929. /**
  9930. * Line through for rectangular text area.
  9931. * @param $x (int) X coordinate
  9932. * @param $y (int) Y coordinate
  9933. * @param $w (int) line length (width)
  9934. * @protected
  9935. * @since 4.9.008 (2009-09-29)
  9936. */
  9937. protected function _dolinethroughw($x, $y, $w)
  9938. {
  9939. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  9940. return sprintf('%F %F %F %F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew + ($this->FontSizePt / 3)), $w * $this->k, $linew);
  9941. }
  9942. /**
  9943. * Overline text.
  9944. * @param $x (int) X coordinate
  9945. * @param $y (int) Y coordinate
  9946. * @param $txt (string) text to overline
  9947. * @protected
  9948. * @since 4.9.015 (2010-04-19)
  9949. */
  9950. protected function _dooverline($x, $y, $txt)
  9951. {
  9952. $w = $this->GetStringWidth($txt);
  9953. return $this->_dooverlinew($x, $y, $w);
  9954. }
  9955. /**
  9956. * Overline for rectangular text area.
  9957. * @param $x (int) X coordinate
  9958. * @param $y (int) Y coordinate
  9959. * @param $w (int) width to overline
  9960. * @protected
  9961. * @since 4.9.015 (2010-04-19)
  9962. */
  9963. protected function _dooverlinew($x, $y, $w)
  9964. {
  9965. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  9966. return sprintf('%F %F %F %F re f', $x * $this->k, (($this->h - $y + $this->FontAscent) * $this->k) - $linew, $w * $this->k, $linew);
  9967. }
  9968. /**
  9969. * Format a data string for meta information
  9970. * @param $s (string) data string to escape.
  9971. * @param $n (int) object ID
  9972. * @return string escaped string.
  9973. * @protected
  9974. */
  9975. protected function _datastring($s, $n = 0)
  9976. {
  9977. if ($n == 0) {
  9978. $n = $this->n;
  9979. }
  9980. $s = $this->_encrypt_data($n, $s);
  9981. return '('. TCPDF_STATIC::_escape($s).')';
  9982. }
  9983. /**
  9984. * Set the document creation timestamp
  9985. * @param $time (mixed) Document creation timestamp in seconds or date-time string.
  9986. * @public
  9987. * @since 5.9.152 (2012-03-23)
  9988. */
  9989. public function setDocCreationTimestamp($time)
  9990. {
  9991. if (is_string($time)) {
  9992. $time = TCPDF_STATIC::getTimestamp($time);
  9993. }
  9994. $this->doc_creation_timestamp = intval($time);
  9995. }
  9996. /**
  9997. * Set the document modification timestamp
  9998. * @param $time (mixed) Document modification timestamp in seconds or date-time string.
  9999. * @public
  10000. * @since 5.9.152 (2012-03-23)
  10001. */
  10002. public function setDocModificationTimestamp($time)
  10003. {
  10004. if (is_string($time)) {
  10005. $time = TCPDF_STATIC::getTimestamp($time);
  10006. }
  10007. $this->doc_modification_timestamp = intval($time);
  10008. }
  10009. /**
  10010. * Returns document creation timestamp in seconds.
  10011. * @return (int) Creation timestamp in seconds.
  10012. * @public
  10013. * @since 5.9.152 (2012-03-23)
  10014. */
  10015. public function getDocCreationTimestamp()
  10016. {
  10017. return $this->doc_creation_timestamp;
  10018. }
  10019. /**
  10020. * Returns document modification timestamp in seconds.
  10021. * @return (int) Modfication timestamp in seconds.
  10022. * @public
  10023. * @since 5.9.152 (2012-03-23)
  10024. */
  10025. public function getDocModificationTimestamp()
  10026. {
  10027. return $this->doc_modification_timestamp;
  10028. }
  10029. /**
  10030. * Returns a formatted date for meta information
  10031. * @param $n (int) Object ID.
  10032. * @param $timestamp (int) Timestamp to convert.
  10033. * @return string escaped date string.
  10034. * @protected
  10035. * @since 4.6.028 (2009-08-25)
  10036. */
  10037. protected function _datestring($n = 0, $timestamp = 0)
  10038. {
  10039. if ((empty($timestamp)) OR ($timestamp < 0)) {
  10040. $timestamp = $this->doc_creation_timestamp;
  10041. }
  10042. return $this->_datastring('D:'.TCPDF_STATIC::getFormattedDate($timestamp), $n);
  10043. }
  10044. /**
  10045. * Format a text string for meta information
  10046. * @param $s (string) string to escape.
  10047. * @param $n (int) object ID
  10048. * @return string escaped string.
  10049. * @protected
  10050. */
  10051. protected function _textstring($s, $n = 0)
  10052. {
  10053. if ($this->isunicode) {
  10054. //Convert string to UTF-16BE
  10055. $s = TCPDF_FONTS::UTF8ToUTF16BE($s, true, $this->isunicode, $this->CurrentFont);
  10056. }
  10057. return $this->_datastring($s, $n);
  10058. }
  10059. /**
  10060. * get raw output stream.
  10061. * @param $s (string) string to output.
  10062. * @param $n (int) object reference for encryption mode
  10063. * @protected
  10064. * @author Nicola Asuni
  10065. * @since 5.5.000 (2010-06-22)
  10066. */
  10067. protected function _getrawstream($s, $n = 0)
  10068. {
  10069. if ($n <= 0) {
  10070. // default to current object
  10071. $n = $this->n;
  10072. }
  10073. return $this->_encrypt_data($n, $s);
  10074. }
  10075. /**
  10076. * Output a string to the document.
  10077. * @param $s (string) string to output.
  10078. * @protected
  10079. */
  10080. protected function _out($s)
  10081. {
  10082. if ($this->state == 2) {
  10083. if ($this->inxobj) {
  10084. // we are inside an XObject template
  10085. $this->xobjects[$this->xobjid]['outdata'] .= $s."\n";
  10086. } elseif ((!$this->InFooter) AND isset($this->footerlen[$this->page]) AND ($this->footerlen[$this->page] > 0)) {
  10087. // puts data before page footer
  10088. $pagebuff = $this->getPageBuffer($this->page);
  10089. $page = substr($pagebuff, 0, -$this->footerlen[$this->page]);
  10090. $footer = substr($pagebuff, -$this->footerlen[$this->page]);
  10091. $this->setPageBuffer($this->page, $page.$s."\n".$footer);
  10092. // update footer position
  10093. $this->footerpos[$this->page] += strlen($s."\n");
  10094. } else {
  10095. // set page data
  10096. $this->setPageBuffer($this->page, $s."\n", true);
  10097. }
  10098. } elseif ($this->state > 0) {
  10099. // set general data
  10100. $this->setBuffer($s."\n");
  10101. }
  10102. }
  10103. /**
  10104. * Set header font.
  10105. * @param $font (array) Array describing the basic font parameters: (family, style, size).
  10106. * @public
  10107. * @since 1.1
  10108. */
  10109. public function setHeaderFont($font)
  10110. {
  10111. $this->header_font = $font;
  10112. }
  10113. /**
  10114. * Get header font.
  10115. * @return array() Array describing the basic font parameters: (family, style, size).
  10116. * @public
  10117. * @since 4.0.012 (2008-07-24)
  10118. */
  10119. public function getHeaderFont()
  10120. {
  10121. return $this->header_font;
  10122. }
  10123. /**
  10124. * Set footer font.
  10125. * @param $font (array) Array describing the basic font parameters: (family, style, size).
  10126. * @public
  10127. * @since 1.1
  10128. */
  10129. public function setFooterFont($font)
  10130. {
  10131. $this->footer_font = $font;
  10132. }
  10133. /**
  10134. * Get Footer font.
  10135. * @return array() Array describing the basic font parameters: (family, style, size).
  10136. * @public
  10137. * @since 4.0.012 (2008-07-24)
  10138. */
  10139. public function getFooterFont()
  10140. {
  10141. return $this->footer_font;
  10142. }
  10143. /**
  10144. * Set language array.
  10145. * @param $language (array)
  10146. * @public
  10147. * @since 1.1
  10148. */
  10149. public function setLanguageArray($language)
  10150. {
  10151. $this->l = $language;
  10152. if (isset($this->l['a_meta_dir'])) {
  10153. $this->rtl = $this->l['a_meta_dir']=='rtl' ? true : false;
  10154. } else {
  10155. $this->rtl = false;
  10156. }
  10157. }
  10158. /**
  10159. * Returns the PDF data.
  10160. * @public
  10161. */
  10162. public function getPDFData()
  10163. {
  10164. if ($this->state < 3) {
  10165. $this->Close();
  10166. }
  10167. return $this->buffer;
  10168. }
  10169. /**
  10170. * Output anchor link.
  10171. * @param $url (string) link URL or internal link (i.e.: &lt;a href="#23,4.5"&gt;link to page 23 at 4.5 Y position&lt;/a&gt;)
  10172. * @param $name (string) link name
  10173. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  10174. * @param $firstline (boolean) if true prints only the first line and return the remaining string.
  10175. * @param $color (array) array of RGB text color
  10176. * @param $style (string) font style (U, D, B, I)
  10177. * @param $firstblock (boolean) if true the string is the starting of a line.
  10178. * @return the number of cells used or the remaining text if $firstline = true;
  10179. * @public
  10180. */
  10181. public function addHtmlLink($url, $name, $fill = false, $firstline = false, $color = '', $style = -1, $firstblock = false)
  10182. {
  10183. if (isset($url[1]) AND ($url[0] == '#') AND is_numeric($url[1])) {
  10184. // convert url to internal link
  10185. $lnkdata = explode(',', $url);
  10186. if (isset($lnkdata[0]) ) {
  10187. $page = substr($lnkdata[0], 1);
  10188. if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
  10189. $lnky = floatval($lnkdata[1]);
  10190. } else {
  10191. $lnky = 0;
  10192. }
  10193. $url = $this->AddLink();
  10194. $this->SetLink($url, $lnky, $page);
  10195. }
  10196. }
  10197. // store current settings
  10198. $prevcolor = $this->fgcolor;
  10199. $prevstyle = $this->FontStyle;
  10200. if (empty($color)) {
  10201. $this->SetTextColorArray($this->htmlLinkColorArray);
  10202. } else {
  10203. $this->SetTextColorArray($color);
  10204. }
  10205. if ($style == -1) {
  10206. $this->SetFont('', $this->FontStyle.$this->htmlLinkFontStyle);
  10207. } else {
  10208. $this->SetFont('', $this->FontStyle.$style);
  10209. }
  10210. $ret = $this->Write($this->lasth, $name, $url, $fill, '', false, 0, $firstline, $firstblock, 0);
  10211. // restore settings
  10212. $this->SetFont('', $prevstyle);
  10213. $this->SetTextColorArray($prevcolor);
  10214. return $ret;
  10215. }
  10216. /**
  10217. * Converts pixels to User's Units.
  10218. * @param $px (int) pixels
  10219. * @return float value in user's unit
  10220. * @public
  10221. * @see setImageScale(), getImageScale()
  10222. */
  10223. public function pixelsToUnits($px)
  10224. {
  10225. return ($px / ($this->imgscale * $this->k));
  10226. }
  10227. /**
  10228. * Reverse function for htmlentities.
  10229. * Convert entities in UTF-8.
  10230. * @param $text_to_convert (string) Text to convert.
  10231. * @return string converted text string
  10232. * @public
  10233. */
  10234. public function unhtmlentities($text_to_convert)
  10235. {
  10236. return @html_entity_decode($text_to_convert, ENT_QUOTES, $this->encoding);
  10237. }
  10238. // ENCRYPTION METHODS ----------------------------------
  10239. /**
  10240. * Compute encryption key depending on object number where the encrypted data is stored.
  10241. * This is used for all strings and streams without crypt filter specifier.
  10242. * @param $n (int) object number
  10243. * @return int object key
  10244. * @protected
  10245. * @author Nicola Asuni
  10246. * @since 2.0.000 (2008-01-02)
  10247. */
  10248. protected function _objectkey($n)
  10249. {
  10250. $objkey = $this->encryptdata['key'].pack('VXxx', $n);
  10251. if ($this->encryptdata['mode'] == 2) { // AES-128
  10252. // AES padding
  10253. $objkey .= "\x73\x41\x6C\x54"; // sAlT
  10254. }
  10255. $objkey = substr(TCPDF_STATIC::_md5_16($objkey), 0, (($this->encryptdata['Length'] / 8) + 5));
  10256. $objkey = substr($objkey, 0, 16);
  10257. return $objkey;
  10258. }
  10259. /**
  10260. * Encrypt the input string.
  10261. * @param $n (int) object number
  10262. * @param $s (string) data string to encrypt
  10263. * @return encrypted string
  10264. * @protected
  10265. * @author Nicola Asuni
  10266. * @since 5.0.005 (2010-05-11)
  10267. */
  10268. protected function _encrypt_data($n, $s)
  10269. {
  10270. if (!$this->encrypted) {
  10271. return $s;
  10272. }
  10273. switch ($this->encryptdata['mode']) {
  10274. case 0: // RC4-40
  10275. case 1: { // RC4-128
  10276. $s = TCPDF_STATIC::_RC4($this->_objectkey($n), $s, $this->last_enc_key, $this->last_enc_key_c);
  10277. break;
  10278. }
  10279. case 2: { // AES-128
  10280. $s = TCPDF_STATIC::_AES($this->_objectkey($n), $s);
  10281. break;
  10282. }
  10283. case 3: { // AES-256
  10284. $s = TCPDF_STATIC::_AES($this->encryptdata['key'], $s);
  10285. break;
  10286. }
  10287. }
  10288. return $s;
  10289. }
  10290. /**
  10291. * Put encryption on PDF document.
  10292. * @protected
  10293. * @author Nicola Asuni
  10294. * @since 2.0.000 (2008-01-02)
  10295. */
  10296. protected function _putencryption()
  10297. {
  10298. if (!$this->encrypted) {
  10299. return;
  10300. }
  10301. $this->encryptdata['objid'] = $this->_newobj();
  10302. $out = '<<';
  10303. if (!isset($this->encryptdata['Filter']) OR empty($this->encryptdata['Filter'])) {
  10304. $this->encryptdata['Filter'] = 'Standard';
  10305. }
  10306. $out .= ' /Filter /'.$this->encryptdata['Filter'];
  10307. if (isset($this->encryptdata['SubFilter']) AND !empty($this->encryptdata['SubFilter'])) {
  10308. $out .= ' /SubFilter /'.$this->encryptdata['SubFilter'];
  10309. }
  10310. if (!isset($this->encryptdata['V']) OR empty($this->encryptdata['V'])) {
  10311. $this->encryptdata['V'] = 1;
  10312. }
  10313. // V is a code specifying the algorithm to be used in encrypting and decrypting the document
  10314. $out .= ' /V '.$this->encryptdata['V'];
  10315. if (isset($this->encryptdata['Length']) AND !empty($this->encryptdata['Length'])) {
  10316. // The length of the encryption key, in bits. The value shall be a multiple of 8, in the range 40 to 256
  10317. $out .= ' /Length '.$this->encryptdata['Length'];
  10318. } else {
  10319. $out .= ' /Length 40';
  10320. }
  10321. if ($this->encryptdata['V'] >= 4) {
  10322. if (!isset($this->encryptdata['StmF']) OR empty($this->encryptdata['StmF'])) {
  10323. $this->encryptdata['StmF'] = 'Identity';
  10324. }
  10325. if (!isset($this->encryptdata['StrF']) OR empty($this->encryptdata['StrF'])) {
  10326. // The name of the crypt filter that shall be used when decrypting all strings in the document.
  10327. $this->encryptdata['StrF'] = 'Identity';
  10328. }
  10329. // A dictionary whose keys shall be crypt filter names and whose values shall be the corresponding crypt filter dictionaries.
  10330. if (isset($this->encryptdata['CF']) AND !empty($this->encryptdata['CF'])) {
  10331. $out .= ' /CF <<';
  10332. $out .= ' /'.$this->encryptdata['StmF'].' <<';
  10333. $out .= ' /Type /CryptFilter';
  10334. if (isset($this->encryptdata['CF']['CFM']) AND !empty($this->encryptdata['CF']['CFM'])) {
  10335. // The method used
  10336. $out .= ' /CFM /'.$this->encryptdata['CF']['CFM'];
  10337. if ($this->encryptdata['pubkey']) {
  10338. $out .= ' /Recipients [';
  10339. foreach ($this->encryptdata['Recipients'] as $rec) {
  10340. $out .= ' <'.$rec.'>';
  10341. }
  10342. $out .= ' ]';
  10343. if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) {
  10344. $out .= ' /EncryptMetadata false';
  10345. } else {
  10346. $out .= ' /EncryptMetadata true';
  10347. }
  10348. }
  10349. } else {
  10350. $out .= ' /CFM /None';
  10351. }
  10352. if (isset($this->encryptdata['CF']['AuthEvent']) AND !empty($this->encryptdata['CF']['AuthEvent'])) {
  10353. // The event to be used to trigger the authorization that is required to access encryption keys used by this filter.
  10354. $out .= ' /AuthEvent /'.$this->encryptdata['CF']['AuthEvent'];
  10355. } else {
  10356. $out .= ' /AuthEvent /DocOpen';
  10357. }
  10358. if (isset($this->encryptdata['CF']['Length']) AND !empty($this->encryptdata['CF']['Length'])) {
  10359. // The bit length of the encryption key.
  10360. $out .= ' /Length '.$this->encryptdata['CF']['Length'];
  10361. }
  10362. $out .= ' >> >>';
  10363. }
  10364. // The name of the crypt filter that shall be used by default when decrypting streams.
  10365. $out .= ' /StmF /'.$this->encryptdata['StmF'];
  10366. // The name of the crypt filter that shall be used when decrypting all strings in the document.
  10367. $out .= ' /StrF /'.$this->encryptdata['StrF'];
  10368. if (isset($this->encryptdata['EFF']) AND !empty($this->encryptdata['EFF'])) {
  10369. // The name of the crypt filter that shall be used when encrypting embedded file streams that do not have their own crypt filter specifier.
  10370. $out .= ' /EFF /'.$this->encryptdata[''];
  10371. }
  10372. }
  10373. // Additional encryption dictionary entries for the standard security handler
  10374. if ($this->encryptdata['pubkey']) {
  10375. if (($this->encryptdata['V'] < 4) AND isset($this->encryptdata['Recipients']) AND !empty($this->encryptdata['Recipients'])) {
  10376. $out .= ' /Recipients [';
  10377. foreach ($this->encryptdata['Recipients'] as $rec) {
  10378. $out .= ' <'.$rec.'>';
  10379. }
  10380. $out .= ' ]';
  10381. }
  10382. } else {
  10383. $out .= ' /R';
  10384. if ($this->encryptdata['V'] == 5) { // AES-256
  10385. $out .= ' 5';
  10386. $out .= ' /OE ('.TCPDF_STATIC::_escape($this->encryptdata['OE']).')';
  10387. $out .= ' /UE ('.TCPDF_STATIC::_escape($this->encryptdata['UE']).')';
  10388. $out .= ' /Perms ('.TCPDF_STATIC::_escape($this->encryptdata['perms']).')';
  10389. } elseif ($this->encryptdata['V'] == 4) { // AES-128
  10390. $out .= ' 4';
  10391. } elseif ($this->encryptdata['V'] < 2) { // RC-40
  10392. $out .= ' 2';
  10393. } else { // RC-128
  10394. $out .= ' 3';
  10395. }
  10396. $out .= ' /O ('.TCPDF_STATIC::_escape($this->encryptdata['O']).')';
  10397. $out .= ' /U ('.TCPDF_STATIC::_escape($this->encryptdata['U']).')';
  10398. $out .= ' /P '.$this->encryptdata['P'];
  10399. if (isset($this->encryptdata['EncryptMetadata']) AND (!$this->encryptdata['EncryptMetadata'])) {
  10400. $out .= ' /EncryptMetadata false';
  10401. } else {
  10402. $out .= ' /EncryptMetadata true';
  10403. }
  10404. }
  10405. $out .= ' >>';
  10406. $out .= "\n".'endobj';
  10407. $this->_out($out);
  10408. }
  10409. /**
  10410. * Compute U value (used for encryption)
  10411. * @return string U value
  10412. * @protected
  10413. * @since 2.0.000 (2008-01-02)
  10414. * @author Nicola Asuni
  10415. */
  10416. protected function _Uvalue()
  10417. {
  10418. if ($this->encryptdata['mode'] == 0) { // RC4-40
  10419. return TCPDF_STATIC::_RC4($this->encryptdata['key'], TCPDF_STATIC::$enc_padding, $this->last_enc_key, $this->last_enc_key_c);
  10420. } elseif ($this->encryptdata['mode'] < 3) { // RC4-128, AES-128
  10421. $tmp = TCPDF_STATIC::_md5_16(TCPDF_STATIC::$enc_padding.$this->encryptdata['fileid']);
  10422. $enc = TCPDF_STATIC::_RC4($this->encryptdata['key'], $tmp, $this->last_enc_key, $this->last_enc_key_c);
  10423. $len = strlen($tmp);
  10424. for ($i = 1; $i <= 19; ++$i) {
  10425. $ek = '';
  10426. for ($j = 0; $j < $len; ++$j) {
  10427. $ek .= chr(ord($this->encryptdata['key'][$j]) ^ $i);
  10428. }
  10429. $enc = TCPDF_STATIC::_RC4($ek, $enc, $this->last_enc_key, $this->last_enc_key_c);
  10430. }
  10431. $enc .= str_repeat("\x00", 16);
  10432. return substr($enc, 0, 32);
  10433. } elseif ($this->encryptdata['mode'] == 3) { // AES-256
  10434. $seed = TCPDF_STATIC::_md5_16(TCPDF_STATIC::getRandomSeed());
  10435. // User Validation Salt
  10436. $this->encryptdata['UVS'] = substr($seed, 0, 8);
  10437. // User Key Salt
  10438. $this->encryptdata['UKS'] = substr($seed, 8, 16);
  10439. return hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UVS'], true).$this->encryptdata['UVS'].$this->encryptdata['UKS'];
  10440. }
  10441. }
  10442. /**
  10443. * Compute UE value (used for encryption)
  10444. * @return string UE value
  10445. * @protected
  10446. * @since 5.9.006 (2010-10-19)
  10447. * @author Nicola Asuni
  10448. */
  10449. protected function _UEvalue()
  10450. {
  10451. $hashkey = hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UKS'], true);
  10452. return TCPDF_STATIC::_AESnopad($hashkey, $this->encryptdata['key']);
  10453. }
  10454. /**
  10455. * Compute O value (used for encryption)
  10456. * @return string O value
  10457. * @protected
  10458. * @since 2.0.000 (2008-01-02)
  10459. * @author Nicola Asuni
  10460. */
  10461. protected function _Ovalue()
  10462. {
  10463. if ($this->encryptdata['mode'] < 3) { // RC4-40, RC4-128, AES-128
  10464. $tmp = TCPDF_STATIC::_md5_16($this->encryptdata['owner_password']);
  10465. if ($this->encryptdata['mode'] > 0) {
  10466. for ($i = 0; $i < 50; ++$i) {
  10467. $tmp = TCPDF_STATIC::_md5_16($tmp);
  10468. }
  10469. }
  10470. $owner_key = substr($tmp, 0, ($this->encryptdata['Length'] / 8));
  10471. $enc = TCPDF_STATIC::_RC4($owner_key, $this->encryptdata['user_password'], $this->last_enc_key, $this->last_enc_key_c);
  10472. if ($this->encryptdata['mode'] > 0) {
  10473. $len = strlen($owner_key);
  10474. for ($i = 1; $i <= 19; ++$i) {
  10475. $ek = '';
  10476. for ($j = 0; $j < $len; ++$j) {
  10477. $ek .= chr(ord($owner_key[$j]) ^ $i);
  10478. }
  10479. $enc = TCPDF_STATIC::_RC4($ek, $enc, $this->last_enc_key, $this->last_enc_key_c);
  10480. }
  10481. }
  10482. return $enc;
  10483. } elseif ($this->encryptdata['mode'] == 3) { // AES-256
  10484. $seed = TCPDF_STATIC::_md5_16(TCPDF_STATIC::getRandomSeed());
  10485. // Owner Validation Salt
  10486. $this->encryptdata['OVS'] = substr($seed, 0, 8);
  10487. // Owner Key Salt
  10488. $this->encryptdata['OKS'] = substr($seed, 8, 16);
  10489. return hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OVS'].$this->encryptdata['U'], true).$this->encryptdata['OVS'].$this->encryptdata['OKS'];
  10490. }
  10491. }
  10492. /**
  10493. * Compute OE value (used for encryption)
  10494. * @return string OE value
  10495. * @protected
  10496. * @since 5.9.006 (2010-10-19)
  10497. * @author Nicola Asuni
  10498. */
  10499. protected function _OEvalue()
  10500. {
  10501. $hashkey = hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OKS'].$this->encryptdata['U'], true);
  10502. return TCPDF_STATIC::_AESnopad($hashkey, $this->encryptdata['key']);
  10503. }
  10504. /**
  10505. * Convert password for AES-256 encryption mode
  10506. * @param $password (string) password
  10507. * @return string password
  10508. * @protected
  10509. * @since 5.9.006 (2010-10-19)
  10510. * @author Nicola Asuni
  10511. */
  10512. protected function _fixAES256Password($password)
  10513. {
  10514. $psw = ''; // password to be returned
  10515. $psw_array = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($password, $this->isunicode, $this->CurrentFont), $password, $this->rtl, $this->isunicode, $this->CurrentFont);
  10516. foreach ($psw_array as $c) {
  10517. $psw .= TCPDF_FONTS::unichr($c, $this->isunicode);
  10518. }
  10519. return substr($psw, 0, 127);
  10520. }
  10521. /**
  10522. * Compute encryption key
  10523. * @protected
  10524. * @since 2.0.000 (2008-01-02)
  10525. * @author Nicola Asuni
  10526. */
  10527. protected function _generateencryptionkey()
  10528. {
  10529. $keybytelen = ($this->encryptdata['Length'] / 8);
  10530. if (!$this->encryptdata['pubkey']) { // standard mode
  10531. if ($this->encryptdata['mode'] == 3) { // AES-256
  10532. // generate 256 bit random key
  10533. $this->encryptdata['key'] = substr(hash('sha256', TCPDF_STATIC::getRandomSeed(), true), 0, $keybytelen);
  10534. // truncate passwords
  10535. $this->encryptdata['user_password'] = $this->_fixAES256Password($this->encryptdata['user_password']);
  10536. $this->encryptdata['owner_password'] = $this->_fixAES256Password($this->encryptdata['owner_password']);
  10537. // Compute U value
  10538. $this->encryptdata['U'] = $this->_Uvalue();
  10539. // Compute UE value
  10540. $this->encryptdata['UE'] = $this->_UEvalue();
  10541. // Compute O value
  10542. $this->encryptdata['O'] = $this->_Ovalue();
  10543. // Compute OE value
  10544. $this->encryptdata['OE'] = $this->_OEvalue();
  10545. // Compute P value
  10546. $this->encryptdata['P'] = $this->encryptdata['protection'];
  10547. // Computing the encryption dictionary's Perms (permissions) value
  10548. $perms = TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']); // bytes 0-3
  10549. $perms .= chr(255).chr(255).chr(255).chr(255); // bytes 4-7
  10550. if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) { // byte 8
  10551. $perms .= 'F';
  10552. } else {
  10553. $perms .= 'T';
  10554. }
  10555. $perms .= 'adb'; // bytes 9-11
  10556. $perms .= 'nick'; // bytes 12-15
  10557. $this->encryptdata['perms'] = TCPDF_STATIC::_AESnopad($this->encryptdata['key'], $perms);
  10558. } else { // RC4-40, RC4-128, AES-128
  10559. // Pad passwords
  10560. $this->encryptdata['user_password'] = substr($this->encryptdata['user_password'].TCPDF_STATIC::$enc_padding, 0, 32);
  10561. $this->encryptdata['owner_password'] = substr($this->encryptdata['owner_password'].TCPDF_STATIC::$enc_padding, 0, 32);
  10562. // Compute O value
  10563. $this->encryptdata['O'] = $this->_Ovalue();
  10564. // get default permissions (reverse byte order)
  10565. $permissions = TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']);
  10566. // Compute encryption key
  10567. $tmp = TCPDF_STATIC::_md5_16($this->encryptdata['user_password'].$this->encryptdata['O'].$permissions.$this->encryptdata['fileid']);
  10568. if ($this->encryptdata['mode'] > 0) {
  10569. for ($i = 0; $i < 50; ++$i) {
  10570. $tmp = TCPDF_STATIC::_md5_16(substr($tmp, 0, $keybytelen));
  10571. }
  10572. }
  10573. $this->encryptdata['key'] = substr($tmp, 0, $keybytelen);
  10574. // Compute U value
  10575. $this->encryptdata['U'] = $this->_Uvalue();
  10576. // Compute P value
  10577. $this->encryptdata['P'] = $this->encryptdata['protection'];
  10578. }
  10579. } else { // Public-Key mode
  10580. // random 20-byte seed
  10581. $seed = sha1(TCPDF_STATIC::getRandomSeed(), true);
  10582. $recipient_bytes = '';
  10583. foreach ($this->encryptdata['pubkeys'] as $pubkey) {
  10584. // for each public certificate
  10585. if (isset($pubkey['p'])) {
  10586. $pkprotection = TCPDF_STATIC::getUserPermissionCode($pubkey['p'], $this->encryptdata['mode']);
  10587. } else {
  10588. $pkprotection = $this->encryptdata['protection'];
  10589. }
  10590. // get default permissions (reverse byte order)
  10591. $pkpermissions = TCPDF_STATIC::getEncPermissionsString($pkprotection);
  10592. // envelope data
  10593. $envelope = $seed.$pkpermissions;
  10594. // write the envelope data to a temporary file
  10595. $tempkeyfile = TCPDF_STATIC::getObjFilename('key', $this->file_id);
  10596. $f = TCPDF_STATIC::fopenLocal($tempkeyfile, 'wb');
  10597. if (!$f) {
  10598. $this->Error('Unable to create temporary key file: '.$tempkeyfile);
  10599. }
  10600. $envelope_length = strlen($envelope);
  10601. fwrite($f, $envelope, $envelope_length);
  10602. fclose($f);
  10603. $tempencfile = TCPDF_STATIC::getObjFilename('enc', $this->file_id);
  10604. if (!openssl_pkcs7_encrypt($tempkeyfile, $tempencfile, $pubkey['c'], array(), PKCS7_BINARY | PKCS7_DETACHED)) {
  10605. $this->Error('Unable to encrypt the file: '.$tempkeyfile);
  10606. }
  10607. // read encryption signature
  10608. $signature = file_get_contents($tempencfile, false, null, $envelope_length);
  10609. // extract signature
  10610. $signature = substr($signature, strpos($signature, 'Content-Disposition'));
  10611. $tmparr = explode("\n\n", $signature);
  10612. $signature = trim($tmparr[1]);
  10613. unset($tmparr);
  10614. // decode signature
  10615. $signature = base64_decode($signature);
  10616. // convert signature to hex
  10617. $hexsignature = current(unpack('H*', $signature));
  10618. // store signature on recipients array
  10619. $this->encryptdata['Recipients'][] = $hexsignature;
  10620. // The bytes of each item in the Recipients array of PKCS#7 objects in the order in which they appear in the array
  10621. $recipient_bytes .= $signature;
  10622. }
  10623. // calculate encryption key
  10624. if ($this->encryptdata['mode'] == 3) { // AES-256
  10625. $this->encryptdata['key'] = substr(hash('sha256', $seed.$recipient_bytes, true), 0, $keybytelen);
  10626. } else { // RC4-40, RC4-128, AES-128
  10627. $this->encryptdata['key'] = substr(sha1($seed.$recipient_bytes, true), 0, $keybytelen);
  10628. }
  10629. }
  10630. }
  10631. /**
  10632. * Set document protection
  10633. * Remark: the protection against modification is for people who have the full Acrobat product.
  10634. * 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.
  10635. * 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.
  10636. * @param $permissions (Array) the set of permissions (specify the ones you want to block):<ul><li>print : Print the document;</li><li>modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';</li><li>copy : Copy or otherwise extract text and graphics from the document;</li><li>annot-forms : Add or modify text annotations, fill in interactive form fields, and, if 'modify' is also set, create or modify interactive form fields (including signature fields);</li><li>fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;</li><li>extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);</li><li>assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;</li><li>print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality.</li><li>owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.</li></ul>
  10637. * @param $user_pass (String) user password. Empty by default.
  10638. * @param $owner_pass (String) owner password. If not specified, a random value is used.
  10639. * @param $mode (int) encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
  10640. * @param $pubkeys (String) array of recipients containing public-key certificates ('c') and permissions ('p'). For example: array(array('c' => 'file://../examples/data/cert/tcpdf.crt', 'p' => array('print')))
  10641. * @public
  10642. * @since 2.0.000 (2008-01-02)
  10643. * @author Nicola Asuni
  10644. */
  10645. 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)
  10646. {
  10647. if ($this->pdfa_mode) {
  10648. // encryption is not allowed in PDF/A mode
  10649. return;
  10650. }
  10651. $this->encryptdata['protection'] = TCPDF_STATIC::getUserPermissionCode($permissions, $mode);
  10652. if (($pubkeys !== null) AND (is_array($pubkeys))) {
  10653. // public-key mode
  10654. $this->encryptdata['pubkeys'] = $pubkeys;
  10655. if ($mode == 0) {
  10656. // public-Key Security requires at least 128 bit
  10657. $mode = 1;
  10658. }
  10659. if (!function_exists('openssl_pkcs7_encrypt')) {
  10660. $this->Error('Public-Key Security requires openssl library.');
  10661. }
  10662. // Set Public-Key filter (available are: Entrust.PPKEF, Adobe.PPKLite, Adobe.PubSec)
  10663. $this->encryptdata['pubkey'] = true;
  10664. $this->encryptdata['Filter'] = 'Adobe.PubSec';
  10665. $this->encryptdata['StmF'] = 'DefaultCryptFilter';
  10666. $this->encryptdata['StrF'] = 'DefaultCryptFilter';
  10667. } else {
  10668. // standard mode (password mode)
  10669. $this->encryptdata['pubkey'] = false;
  10670. $this->encryptdata['Filter'] = 'Standard';
  10671. $this->encryptdata['StmF'] = 'StdCF';
  10672. $this->encryptdata['StrF'] = 'StdCF';
  10673. }
  10674. if ($mode > 1) { // AES
  10675. if (!extension_loaded('openssl') && !extension_loaded('mcrypt')) {
  10676. $this->Error('AES encryption requires openssl or mcrypt extension (http://www.php.net/manual/en/mcrypt.requirements.php).');
  10677. }
  10678. if (extension_loaded('openssl') && !in_array('aes-256-cbc', openssl_get_cipher_methods())) {
  10679. $this->Error('AES encryption requires openssl/aes-256-cbc cypher.');
  10680. }
  10681. if (extension_loaded('mcrypt') && mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128) === false) {
  10682. $this->Error('AES encryption requires MCRYPT_RIJNDAEL_128 cypher.');
  10683. }
  10684. if (($mode == 3) AND !function_exists('hash')) {
  10685. // the Hash extension requires no external libraries and is enabled by default as of PHP 5.1.2.
  10686. $this->Error('AES 256 encryption requires HASH Message Digest Framework (http://www.php.net/manual/en/book.hash.php).');
  10687. }
  10688. }
  10689. if ($owner_pass === null) {
  10690. $owner_pass = md5(TCPDF_STATIC::getRandomSeed());
  10691. }
  10692. $this->encryptdata['user_password'] = $user_pass;
  10693. $this->encryptdata['owner_password'] = $owner_pass;
  10694. $this->encryptdata['mode'] = $mode;
  10695. switch ($mode) {
  10696. case 0: { // RC4 40 bit
  10697. $this->encryptdata['V'] = 1;
  10698. $this->encryptdata['Length'] = 40;
  10699. $this->encryptdata['CF']['CFM'] = 'V2';
  10700. break;
  10701. }
  10702. case 1: { // RC4 128 bit
  10703. $this->encryptdata['V'] = 2;
  10704. $this->encryptdata['Length'] = 128;
  10705. $this->encryptdata['CF']['CFM'] = 'V2';
  10706. if ($this->encryptdata['pubkey']) {
  10707. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s4';
  10708. $this->encryptdata['Recipients'] = array();
  10709. }
  10710. break;
  10711. }
  10712. case 2: { // AES 128 bit
  10713. $this->encryptdata['V'] = 4;
  10714. $this->encryptdata['Length'] = 128;
  10715. $this->encryptdata['CF']['CFM'] = 'AESV2';
  10716. $this->encryptdata['CF']['Length'] = 128;
  10717. if ($this->encryptdata['pubkey']) {
  10718. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  10719. $this->encryptdata['Recipients'] = array();
  10720. }
  10721. break;
  10722. }
  10723. case 3: { // AES 256 bit
  10724. $this->encryptdata['V'] = 5;
  10725. $this->encryptdata['Length'] = 256;
  10726. $this->encryptdata['CF']['CFM'] = 'AESV3';
  10727. $this->encryptdata['CF']['Length'] = 256;
  10728. if ($this->encryptdata['pubkey']) {
  10729. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  10730. $this->encryptdata['Recipients'] = array();
  10731. }
  10732. break;
  10733. }
  10734. }
  10735. $this->encrypted = true;
  10736. $this->encryptdata['fileid'] = TCPDF_STATIC::convertHexStringToString($this->file_id);
  10737. $this->_generateencryptionkey();
  10738. }
  10739. // END OF ENCRYPTION FUNCTIONS -------------------------
  10740. // START TRANSFORMATIONS SECTION -----------------------
  10741. /**
  10742. * Starts a 2D tranformation saving current graphic state.
  10743. * This function must be called before scaling, mirroring, translation, rotation and skewing.
  10744. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  10745. * @public
  10746. * @since 2.1.000 (2008-01-07)
  10747. * @see StartTransform(), StopTransform()
  10748. */
  10749. public function StartTransform()
  10750. {
  10751. if ($this->state != 2) {
  10752. return;
  10753. }
  10754. $this->_outSaveGraphicsState();
  10755. if ($this->inxobj) {
  10756. // we are inside an XObject template
  10757. $this->xobjects[$this->xobjid]['transfmrk'][] = strlen($this->xobjects[$this->xobjid]['outdata']);
  10758. } else {
  10759. $this->transfmrk[$this->page][] = $this->pagelen[$this->page];
  10760. }
  10761. ++$this->transfmatrix_key;
  10762. $this->transfmatrix[$this->transfmatrix_key] = array();
  10763. }
  10764. /**
  10765. * Stops a 2D tranformation restoring previous graphic state.
  10766. * This function must be called after scaling, mirroring, translation, rotation and skewing.
  10767. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  10768. * @public
  10769. * @since 2.1.000 (2008-01-07)
  10770. * @see StartTransform(), StopTransform()
  10771. */
  10772. public function StopTransform()
  10773. {
  10774. if ($this->state != 2) {
  10775. return;
  10776. }
  10777. $this->_outRestoreGraphicsState();
  10778. if (isset($this->transfmatrix[$this->transfmatrix_key])) {
  10779. array_pop($this->transfmatrix[$this->transfmatrix_key]);
  10780. --$this->transfmatrix_key;
  10781. }
  10782. if ($this->inxobj) {
  10783. // we are inside an XObject template
  10784. array_pop($this->xobjects[$this->xobjid]['transfmrk']);
  10785. } else {
  10786. array_pop($this->transfmrk[$this->page]);
  10787. }
  10788. }
  10789. /**
  10790. * Horizontal Scaling.
  10791. * @param $s_x (float) scaling factor for width as percent. 0 is not allowed.
  10792. * @param $x (int) abscissa of the scaling center. Default is current x position
  10793. * @param $y (int) ordinate of the scaling center. Default is current y position
  10794. * @public
  10795. * @since 2.1.000 (2008-01-07)
  10796. * @see StartTransform(), StopTransform()
  10797. */
  10798. public function ScaleX($s_x, $x = '', $y = '')
  10799. {
  10800. $this->Scale($s_x, 100, $x, $y);
  10801. }
  10802. /**
  10803. * Vertical Scaling.
  10804. * @param $s_y (float) scaling factor for height as percent. 0 is not allowed.
  10805. * @param $x (int) abscissa of the scaling center. Default is current x position
  10806. * @param $y (int) ordinate of the scaling center. Default is current y position
  10807. * @public
  10808. * @since 2.1.000 (2008-01-07)
  10809. * @see StartTransform(), StopTransform()
  10810. */
  10811. public function ScaleY($s_y, $x = '', $y = '')
  10812. {
  10813. $this->Scale(100, $s_y, $x, $y);
  10814. }
  10815. /**
  10816. * Vertical and horizontal proportional Scaling.
  10817. * @param $s (float) scaling factor for width and height as percent. 0 is not allowed.
  10818. * @param $x (int) abscissa of the scaling center. Default is current x position
  10819. * @param $y (int) ordinate of the scaling center. Default is current y position
  10820. * @public
  10821. * @since 2.1.000 (2008-01-07)
  10822. * @see StartTransform(), StopTransform()
  10823. */
  10824. public function ScaleXY($s, $x = '', $y = '')
  10825. {
  10826. $this->Scale($s, $s, $x, $y);
  10827. }
  10828. /**
  10829. * Vertical and horizontal non-proportional Scaling.
  10830. * @param $s_x (float) scaling factor for width as percent. 0 is not allowed.
  10831. * @param $s_y (float) scaling factor for height as percent. 0 is not allowed.
  10832. * @param $x (int) abscissa of the scaling center. Default is current x position
  10833. * @param $y (int) ordinate of the scaling center. Default is current y position
  10834. * @public
  10835. * @since 2.1.000 (2008-01-07)
  10836. * @see StartTransform(), StopTransform()
  10837. */
  10838. public function Scale($s_x, $s_y, $x = '', $y = '')
  10839. {
  10840. if ($x === '') {
  10841. $x = $this->x;
  10842. }
  10843. if ($y === '') {
  10844. $y = $this->y;
  10845. }
  10846. if (($s_x == 0) OR ($s_y == 0)) {
  10847. $this->Error('Please do not use values equal to zero for scaling');
  10848. }
  10849. $y = ($this->h - $y) * $this->k;
  10850. $x *= $this->k;
  10851. //calculate elements of transformation matrix
  10852. $s_x /= 100;
  10853. $s_y /= 100;
  10854. $tm = array();
  10855. $tm[0] = $s_x;
  10856. $tm[1] = 0;
  10857. $tm[2] = 0;
  10858. $tm[3] = $s_y;
  10859. $tm[4] = $x * (1 - $s_x);
  10860. $tm[5] = $y * (1 - $s_y);
  10861. //scale the coordinate system
  10862. $this->Transform($tm);
  10863. }
  10864. /**
  10865. * Horizontal Mirroring.
  10866. * @param $x (int) abscissa of the point. Default is current x position
  10867. * @public
  10868. * @since 2.1.000 (2008-01-07)
  10869. * @see StartTransform(), StopTransform()
  10870. */
  10871. public function MirrorH($x = '')
  10872. {
  10873. $this->Scale(-100, 100, $x);
  10874. }
  10875. /**
  10876. * Verical Mirroring.
  10877. * @param $y (int) ordinate of the point. Default is current y position
  10878. * @public
  10879. * @since 2.1.000 (2008-01-07)
  10880. * @see StartTransform(), StopTransform()
  10881. */
  10882. public function MirrorV($y = '')
  10883. {
  10884. $this->Scale(100, -100, '', $y);
  10885. }
  10886. /**
  10887. * Point reflection mirroring.
  10888. * @param $x (int) abscissa of the point. Default is current x position
  10889. * @param $y (int) ordinate of the point. Default is current y position
  10890. * @public
  10891. * @since 2.1.000 (2008-01-07)
  10892. * @see StartTransform(), StopTransform()
  10893. */
  10894. public function MirrorP($x = '', $y = '')
  10895. {
  10896. $this->Scale(-100, -100, $x, $y);
  10897. }
  10898. /**
  10899. * Reflection against a straight line through point (x, y) with the gradient angle (angle).
  10900. * @param $angle (float) gradient angle of the straight line. Default is 0 (horizontal line).
  10901. * @param $x (int) abscissa of the point. Default is current x position
  10902. * @param $y (int) ordinate of the point. Default is current y position
  10903. * @public
  10904. * @since 2.1.000 (2008-01-07)
  10905. * @see StartTransform(), StopTransform()
  10906. */
  10907. public function MirrorL($angle = 0, $x = '', $y = '')
  10908. {
  10909. $this->Scale(-100, 100, $x, $y);
  10910. $this->Rotate(-2*($angle-90), $x, $y);
  10911. }
  10912. /**
  10913. * Translate graphic object horizontally.
  10914. * @param $t_x (int) movement to the right (or left for RTL)
  10915. * @public
  10916. * @since 2.1.000 (2008-01-07)
  10917. * @see StartTransform(), StopTransform()
  10918. */
  10919. public function TranslateX($t_x)
  10920. {
  10921. $this->Translate($t_x, 0);
  10922. }
  10923. /**
  10924. * Translate graphic object vertically.
  10925. * @param $t_y (int) movement to the bottom
  10926. * @public
  10927. * @since 2.1.000 (2008-01-07)
  10928. * @see StartTransform(), StopTransform()
  10929. */
  10930. public function TranslateY($t_y)
  10931. {
  10932. $this->Translate(0, $t_y);
  10933. }
  10934. /**
  10935. * Translate graphic object horizontally and vertically.
  10936. * @param $t_x (int) movement to the right
  10937. * @param $t_y (int) movement to the bottom
  10938. * @public
  10939. * @since 2.1.000 (2008-01-07)
  10940. * @see StartTransform(), StopTransform()
  10941. */
  10942. public function Translate($t_x, $t_y)
  10943. {
  10944. //calculate elements of transformation matrix
  10945. $tm = array();
  10946. $tm[0] = 1;
  10947. $tm[1] = 0;
  10948. $tm[2] = 0;
  10949. $tm[3] = 1;
  10950. $tm[4] = $t_x * $this->k;
  10951. $tm[5] = -$t_y * $this->k;
  10952. //translate the coordinate system
  10953. $this->Transform($tm);
  10954. }
  10955. /**
  10956. * Rotate object.
  10957. * @param $angle (float) angle in degrees for counter-clockwise rotation
  10958. * @param $x (int) abscissa of the rotation center. Default is current x position
  10959. * @param $y (int) ordinate of the rotation center. Default is current y position
  10960. * @public
  10961. * @since 2.1.000 (2008-01-07)
  10962. * @see StartTransform(), StopTransform()
  10963. */
  10964. public function Rotate($angle, $x = '', $y = '')
  10965. {
  10966. if ($x === '') {
  10967. $x = $this->x;
  10968. }
  10969. if ($y === '') {
  10970. $y = $this->y;
  10971. }
  10972. $y = ($this->h - $y) * $this->k;
  10973. $x *= $this->k;
  10974. //calculate elements of transformation matrix
  10975. $tm = array();
  10976. $tm[0] = cos(deg2rad($angle));
  10977. $tm[1] = sin(deg2rad($angle));
  10978. $tm[2] = -$tm[1];
  10979. $tm[3] = $tm[0];
  10980. $tm[4] = $x + ($tm[1] * $y) - ($tm[0] * $x);
  10981. $tm[5] = $y - ($tm[0] * $y) - ($tm[1] * $x);
  10982. //rotate the coordinate system around ($x,$y)
  10983. $this->Transform($tm);
  10984. }
  10985. /**
  10986. * Skew horizontally.
  10987. * @param $angle_x (float) angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  10988. * @param $x (int) abscissa of the skewing center. default is current x position
  10989. * @param $y (int) ordinate of the skewing center. default is current y position
  10990. * @public
  10991. * @since 2.1.000 (2008-01-07)
  10992. * @see StartTransform(), StopTransform()
  10993. */
  10994. public function SkewX($angle_x, $x = '', $y = '')
  10995. {
  10996. $this->Skew($angle_x, 0, $x, $y);
  10997. }
  10998. /**
  10999. * Skew vertically.
  11000. * @param $angle_y (float) angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  11001. * @param $x (int) abscissa of the skewing center. default is current x position
  11002. * @param $y (int) ordinate of the skewing center. default is current y position
  11003. * @public
  11004. * @since 2.1.000 (2008-01-07)
  11005. * @see StartTransform(), StopTransform()
  11006. */
  11007. public function SkewY($angle_y, $x = '', $y = '')
  11008. {
  11009. $this->Skew(0, $angle_y, $x, $y);
  11010. }
  11011. /**
  11012. * Skew.
  11013. * @param $angle_x (float) angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  11014. * @param $angle_y (float) angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  11015. * @param $x (int) abscissa of the skewing center. default is current x position
  11016. * @param $y (int) ordinate of the skewing center. default is current y position
  11017. * @public
  11018. * @since 2.1.000 (2008-01-07)
  11019. * @see StartTransform(), StopTransform()
  11020. */
  11021. public function Skew($angle_x, $angle_y, $x = '', $y = '')
  11022. {
  11023. if ($x === '') {
  11024. $x = $this->x;
  11025. }
  11026. if ($y === '') {
  11027. $y = $this->y;
  11028. }
  11029. if (($angle_x <= -90) OR ($angle_x >= 90) OR ($angle_y <= -90) OR ($angle_y >= 90)) {
  11030. $this->Error('Please use values between -90 and +90 degrees for Skewing.');
  11031. }
  11032. $x *= $this->k;
  11033. $y = ($this->h - $y) * $this->k;
  11034. //calculate elements of transformation matrix
  11035. $tm = array();
  11036. $tm[0] = 1;
  11037. $tm[1] = tan(deg2rad($angle_y));
  11038. $tm[2] = tan(deg2rad($angle_x));
  11039. $tm[3] = 1;
  11040. $tm[4] = -$tm[2] * $y;
  11041. $tm[5] = -$tm[1] * $x;
  11042. //skew the coordinate system
  11043. $this->Transform($tm);
  11044. }
  11045. /**
  11046. * Apply graphic transformations.
  11047. * @param $tm (array) transformation matrix
  11048. * @protected
  11049. * @since 2.1.000 (2008-01-07)
  11050. * @see StartTransform(), StopTransform()
  11051. */
  11052. protected function Transform($tm)
  11053. {
  11054. if ($this->state != 2) {
  11055. return;
  11056. }
  11057. $this->_out(sprintf('%F %F %F %F %F %F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
  11058. // add tranformation matrix
  11059. $this->transfmatrix[$this->transfmatrix_key][] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]);
  11060. // update transformation mark
  11061. if ($this->inxobj) {
  11062. // we are inside an XObject template
  11063. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  11064. $key = key($this->xobjects[$this->xobjid]['transfmrk']);
  11065. $this->xobjects[$this->xobjid]['transfmrk'][$key] = strlen($this->xobjects[$this->xobjid]['outdata']);
  11066. }
  11067. } elseif (end($this->transfmrk[$this->page]) !== false) {
  11068. $key = key($this->transfmrk[$this->page]);
  11069. $this->transfmrk[$this->page][$key] = $this->pagelen[$this->page];
  11070. }
  11071. }
  11072. // END TRANSFORMATIONS SECTION -------------------------
  11073. // START GRAPHIC FUNCTIONS SECTION ---------------------
  11074. // The following section is based on the code provided by David Hernandez Sanz
  11075. /**
  11076. * 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.
  11077. * @param $width (float) The width.
  11078. * @public
  11079. * @since 1.0
  11080. * @see Line(), Rect(), Cell(), MultiCell()
  11081. */
  11082. public function SetLineWidth($width)
  11083. {
  11084. //Set line width
  11085. $this->LineWidth = $width;
  11086. $this->linestyleWidth = sprintf('%F w', ($width * $this->k));
  11087. if ($this->state == 2) {
  11088. $this->_out($this->linestyleWidth);
  11089. }
  11090. }
  11091. /**
  11092. * Returns the current the line width.
  11093. * @return int Line width
  11094. * @public
  11095. * @since 2.1.000 (2008-01-07)
  11096. * @see Line(), SetLineWidth()
  11097. */
  11098. public function GetLineWidth()
  11099. {
  11100. return $this->LineWidth;
  11101. }
  11102. /**
  11103. * Set line style.
  11104. * @param $style (array) Line style. Array with keys among the following:
  11105. * <ul>
  11106. * <li>width (float): Width of the line in user units.</li>
  11107. * <li>cap (string): Type of cap to put on the line. Possible values are:
  11108. * butt, round, square. The difference between "square" and "butt" is that
  11109. * "square" projects a flat end past the end of the line.</li>
  11110. * <li>join (string): Type of join. Possible values are: miter, round,
  11111. * bevel.</li>
  11112. * <li>dash (mixed): Dash pattern. Is 0 (without dash) or string with
  11113. * series of length values, which are the lengths of the on and off dashes.
  11114. * For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
  11115. * 1 off, 2 on, 1 off, ...</li>
  11116. * <li>phase (integer): Modifier on the dash pattern which is used to shift
  11117. * the point at which the pattern starts.</li>
  11118. * <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>
  11119. * </ul>
  11120. * @param $ret (boolean) if true do not send the command.
  11121. * @return string the PDF command
  11122. * @public
  11123. * @since 2.1.000 (2008-01-08)
  11124. */
  11125. public function SetLineStyle($style, $ret = false)
  11126. {
  11127. $s = ''; // string to be returned
  11128. if (!is_array($style)) {
  11129. return;
  11130. }
  11131. if (isset($style['width'])) {
  11132. $this->LineWidth = $style['width'];
  11133. $this->linestyleWidth = sprintf('%F w', ($style['width'] * $this->k));
  11134. $s .= $this->linestyleWidth.' ';
  11135. }
  11136. if (isset($style['cap'])) {
  11137. $ca = array('butt' => 0, 'round'=> 1, 'square' => 2);
  11138. if (isset($ca[$style['cap']])) {
  11139. $this->linestyleCap = $ca[$style['cap']].' J';
  11140. $s .= $this->linestyleCap.' ';
  11141. }
  11142. }
  11143. if (isset($style['join'])) {
  11144. $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2);
  11145. if (isset($ja[$style['join']])) {
  11146. $this->linestyleJoin = $ja[$style['join']].' j';
  11147. $s .= $this->linestyleJoin.' ';
  11148. }
  11149. }
  11150. if (isset($style['dash'])) {
  11151. $dash_string = '';
  11152. if ($style['dash']) {
  11153. if (preg_match('/^.+,/', $style['dash']) > 0) {
  11154. $tab = explode(',', $style['dash']);
  11155. } else {
  11156. $tab = array($style['dash']);
  11157. }
  11158. $dash_string = '';
  11159. foreach ($tab as $i => $v) {
  11160. if ($i) {
  11161. $dash_string .= ' ';
  11162. }
  11163. $dash_string .= sprintf('%F', $v);
  11164. }
  11165. }
  11166. if (!isset($style['phase']) OR !$style['dash']) {
  11167. $style['phase'] = 0;
  11168. }
  11169. $this->linestyleDash = sprintf('[%s] %F d', $dash_string, $style['phase']);
  11170. $s .= $this->linestyleDash.' ';
  11171. }
  11172. if (isset($style['color'])) {
  11173. $s .= $this->SetDrawColorArray($style['color'], true).' ';
  11174. }
  11175. if (!$ret AND ($this->state == 2)) {
  11176. $this->_out($s);
  11177. }
  11178. return $s;
  11179. }
  11180. /**
  11181. * Begin a new subpath by moving the current point to coordinates (x, y), omitting any connecting line segment.
  11182. * @param $x (float) Abscissa of point.
  11183. * @param $y (float) Ordinate of point.
  11184. * @protected
  11185. * @since 2.1.000 (2008-01-08)
  11186. */
  11187. protected function _outPoint($x, $y)
  11188. {
  11189. if ($this->state == 2) {
  11190. $this->_out(sprintf('%F %F m', ($x * $this->k), (($this->h - $y) * $this->k)));
  11191. }
  11192. }
  11193. /**
  11194. * Append a straight line segment from the current point to the point (x, y).
  11195. * The new current point shall be (x, y).
  11196. * @param $x (float) Abscissa of end point.
  11197. * @param $y (float) Ordinate of end point.
  11198. * @protected
  11199. * @since 2.1.000 (2008-01-08)
  11200. */
  11201. protected function _outLine($x, $y)
  11202. {
  11203. if ($this->state == 2) {
  11204. $this->_out(sprintf('%F %F l', ($x * $this->k), (($this->h - $y) * $this->k)));
  11205. }
  11206. }
  11207. /**
  11208. * Append a rectangle to the current path as a complete subpath, with lower-left corner (x, y) and dimensions widthand height in user space.
  11209. * @param $x (float) Abscissa of upper-left corner.
  11210. * @param $y (float) Ordinate of upper-left corner.
  11211. * @param $w (float) Width.
  11212. * @param $h (float) Height.
  11213. * @param $op (string) options
  11214. * @protected
  11215. * @since 2.1.000 (2008-01-08)
  11216. */
  11217. protected function _outRect($x, $y, $w, $h, $op)
  11218. {
  11219. if ($this->state == 2) {
  11220. $this->_out(sprintf('%F %F %F %F re %s', ($x * $this->k), (($this->h - $y) * $this->k), ($w * $this->k), (-$h * $this->k), $op));
  11221. }
  11222. }
  11223. /**
  11224. * 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.
  11225. * The new current point shall be (x3, y3).
  11226. * @param $x1 (float) Abscissa of control point 1.
  11227. * @param $y1 (float) Ordinate of control point 1.
  11228. * @param $x2 (float) Abscissa of control point 2.
  11229. * @param $y2 (float) Ordinate of control point 2.
  11230. * @param $x3 (float) Abscissa of end point.
  11231. * @param $y3 (float) Ordinate of end point.
  11232. * @protected
  11233. * @since 2.1.000 (2008-01-08)
  11234. */
  11235. protected function _outCurve($x1, $y1, $x2, $y2, $x3, $y3)
  11236. {
  11237. if ($this->state == 2) {
  11238. $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)));
  11239. }
  11240. }
  11241. /**
  11242. * 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.
  11243. * The new current point shall be (x3, y3).
  11244. * @param $x2 (float) Abscissa of control point 2.
  11245. * @param $y2 (float) Ordinate of control point 2.
  11246. * @param $x3 (float) Abscissa of end point.
  11247. * @param $y3 (float) Ordinate of end point.
  11248. * @protected
  11249. * @since 4.9.019 (2010-04-26)
  11250. */
  11251. protected function _outCurveV($x2, $y2, $x3, $y3)
  11252. {
  11253. if ($this->state == 2) {
  11254. $this->_out(sprintf('%F %F %F %F v', ($x2 * $this->k), (($this->h - $y2) * $this->k), ($x3 * $this->k), (($this->h - $y3) * $this->k)));
  11255. }
  11256. }
  11257. /**
  11258. * 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.
  11259. * The new current point shall be (x3, y3).
  11260. * @param $x1 (float) Abscissa of control point 1.
  11261. * @param $y1 (float) Ordinate of control point 1.
  11262. * @param $x3 (float) Abscissa of end point.
  11263. * @param $y3 (float) Ordinate of end point.
  11264. * @protected
  11265. * @since 2.1.000 (2008-01-08)
  11266. */
  11267. protected function _outCurveY($x1, $y1, $x3, $y3)
  11268. {
  11269. if ($this->state == 2) {
  11270. $this->_out(sprintf('%F %F %F %F y', ($x1 * $this->k), (($this->h - $y1) * $this->k), ($x3 * $this->k), (($this->h - $y3) * $this->k)));
  11271. }
  11272. }
  11273. /**
  11274. * Draws a line between two points.
  11275. * @param $x1 (float) Abscissa of first point.
  11276. * @param $y1 (float) Ordinate of first point.
  11277. * @param $x2 (float) Abscissa of second point.
  11278. * @param $y2 (float) Ordinate of second point.
  11279. * @param $style (array) Line style. Array like for SetLineStyle(). Default value: default line style (empty array).
  11280. * @public
  11281. * @since 1.0
  11282. * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
  11283. */
  11284. public function Line($x1, $y1, $x2, $y2, $style = array())
  11285. {
  11286. if ($this->state != 2) {
  11287. return;
  11288. }
  11289. if (is_array($style)) {
  11290. $this->SetLineStyle($style);
  11291. }
  11292. $this->_outPoint($x1, $y1);
  11293. $this->_outLine($x2, $y2);
  11294. $this->_out('S');
  11295. }
  11296. /**
  11297. * Draws a rectangle.
  11298. * @param $x (float) Abscissa of upper-left corner.
  11299. * @param $y (float) Ordinate of upper-left corner.
  11300. * @param $w (float) Width.
  11301. * @param $h (float) Height.
  11302. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11303. * @param $border_style (array) Border style of rectangle. Array with keys among the following:
  11304. * <ul>
  11305. * <li>all: Line style of all borders. Array like for SetLineStyle().</li>
  11306. * <li>L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for SetLineStyle().</li>
  11307. * </ul>
  11308. * If a key is not present or is null, the correspondent border is not drawn. Default value: default line style (empty array).
  11309. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11310. * @public
  11311. * @since 1.0
  11312. * @see SetLineStyle()
  11313. */
  11314. public function Rect($x, $y, $w, $h, $style = '', $border_style = array(), $fill_color = array())
  11315. {
  11316. if ($this->state != 2) {
  11317. return;
  11318. }
  11319. if (empty($style)) {
  11320. $style = 'S';
  11321. }
  11322. if (!(strpos($style, 'F') === false) AND !empty($fill_color)) {
  11323. // set background color
  11324. $this->SetFillColorArray($fill_color);
  11325. }
  11326. if (!empty($border_style)) {
  11327. if (isset($border_style['all']) AND !empty($border_style['all'])) {
  11328. //set global style for border
  11329. $this->SetLineStyle($border_style['all']);
  11330. $border_style = array();
  11331. } else {
  11332. // remove stroke operator from style
  11333. $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*' );
  11334. if (isset($opnostroke[$style])) {
  11335. $style = $opnostroke[$style];
  11336. }
  11337. }
  11338. }
  11339. if (!empty($style)) {
  11340. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11341. $this->_outRect($x, $y, $w, $h, $op);
  11342. }
  11343. if (!empty($border_style)) {
  11344. $border_style2 = array();
  11345. foreach ($border_style as $line => $value) {
  11346. $length = strlen($line);
  11347. for ($i = 0; $i < $length; ++$i) {
  11348. $border_style2[$line[$i]] = $value;
  11349. }
  11350. }
  11351. $border_style = $border_style2;
  11352. if (isset($border_style['L']) AND $border_style['L']) {
  11353. $this->Line($x, $y, $x, $y + $h, $border_style['L']);
  11354. }
  11355. if (isset($border_style['T']) AND $border_style['T']) {
  11356. $this->Line($x, $y, $x + $w, $y, $border_style['T']);
  11357. }
  11358. if (isset($border_style['R']) AND $border_style['R']) {
  11359. $this->Line($x + $w, $y, $x + $w, $y + $h, $border_style['R']);
  11360. }
  11361. if (isset($border_style['B']) AND $border_style['B']) {
  11362. $this->Line($x, $y + $h, $x + $w, $y + $h, $border_style['B']);
  11363. }
  11364. }
  11365. }
  11366. /**
  11367. * Draws a Bezier curve.
  11368. * The Bezier curve is a tangent to the line between the control points at
  11369. * either end of the curve.
  11370. * @param $x0 (float) Abscissa of start point.
  11371. * @param $y0 (float) Ordinate of start point.
  11372. * @param $x1 (float) Abscissa of control point 1.
  11373. * @param $y1 (float) Ordinate of control point 1.
  11374. * @param $x2 (float) Abscissa of control point 2.
  11375. * @param $y2 (float) Ordinate of control point 2.
  11376. * @param $x3 (float) Abscissa of end point.
  11377. * @param $y3 (float) Ordinate of end point.
  11378. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11379. * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
  11380. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11381. * @public
  11382. * @see SetLineStyle()
  11383. * @since 2.1.000 (2008-01-08)
  11384. */
  11385. public function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style = '', $line_style = array(), $fill_color = array())
  11386. {
  11387. if ($this->state != 2) {
  11388. return;
  11389. }
  11390. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11391. $this->SetFillColorArray($fill_color);
  11392. }
  11393. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11394. if ($line_style) {
  11395. $this->SetLineStyle($line_style);
  11396. }
  11397. $this->_outPoint($x0, $y0);
  11398. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  11399. $this->_out($op);
  11400. }
  11401. /**
  11402. * Draws a poly-Bezier curve.
  11403. * Each Bezier curve segment is a tangent to the line between the control points at
  11404. * either end of the curve.
  11405. * @param $x0 (float) Abscissa of start point.
  11406. * @param $y0 (float) Ordinate of start point.
  11407. * @param $segments (float) An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
  11408. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11409. * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
  11410. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11411. * @public
  11412. * @see SetLineStyle()
  11413. * @since 3.0008 (2008-05-12)
  11414. */
  11415. public function Polycurve($x0, $y0, $segments, $style = '', $line_style = array(), $fill_color = array())
  11416. {
  11417. if ($this->state != 2) {
  11418. return;
  11419. }
  11420. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11421. $this->SetFillColorArray($fill_color);
  11422. }
  11423. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11424. if ($op == 'f') {
  11425. $line_style = array();
  11426. }
  11427. if ($line_style) {
  11428. $this->SetLineStyle($line_style);
  11429. }
  11430. $this->_outPoint($x0, $y0);
  11431. foreach ($segments as $segment) {
  11432. list($x1, $y1, $x2, $y2, $x3, $y3) = $segment;
  11433. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  11434. }
  11435. $this->_out($op);
  11436. }
  11437. /**
  11438. * Draws an ellipse.
  11439. * An ellipse is formed from n Bezier curves.
  11440. * @param $x0 (float) Abscissa of center point.
  11441. * @param $y0 (float) Ordinate of center point.
  11442. * @param $rx (float) Horizontal radius.
  11443. * @param $ry (float) Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
  11444. * @param $angle: (float) Angle oriented (anti-clockwise). Default value: 0.
  11445. * @param $astart: (float) Angle start of draw line. Default value: 0.
  11446. * @param $afinish: (float) Angle finish of draw line. Default value: 360.
  11447. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11448. * @param $line_style (array) Line style of ellipse. Array like for SetLineStyle(). Default value: default line style (empty array).
  11449. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11450. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse.
  11451. * @author Nicola Asuni
  11452. * @public
  11453. * @since 2.1.000 (2008-01-08)
  11454. */
  11455. public function Ellipse($x0, $y0, $rx, $ry = '', $angle = 0, $astart = 0, $afinish = 360, $style = '', $line_style = array(), $fill_color = array(), $nc = 2)
  11456. {
  11457. if ($this->state != 2) {
  11458. return;
  11459. }
  11460. if (TCPDF_STATIC::empty_string($ry) OR ($ry == 0)) {
  11461. $ry = $rx;
  11462. }
  11463. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11464. $this->SetFillColorArray($fill_color);
  11465. }
  11466. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11467. if ($op == 'f') {
  11468. $line_style = array();
  11469. }
  11470. if ($line_style) {
  11471. $this->SetLineStyle($line_style);
  11472. }
  11473. $this->_outellipticalarc($x0, $y0, $rx, $ry, $angle, $astart, $afinish, false, $nc, true, true, false);
  11474. $this->_out($op);
  11475. }
  11476. /**
  11477. * Append an elliptical arc to the current path.
  11478. * An ellipse is formed from n Bezier curves.
  11479. * @param $xc (float) Abscissa of center point.
  11480. * @param $yc (float) Ordinate of center point.
  11481. * @param $rx (float) Horizontal radius.
  11482. * @param $ry (float) Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
  11483. * @param $xang: (float) Angle between the X-axis and the major axis of the ellipse. Default value: 0.
  11484. * @param $angs: (float) Angle start of draw line. Default value: 0.
  11485. * @param $angf: (float) Angle finish of draw line. Default value: 360.
  11486. * @param $pie (boolean) if true do not mark the border point (used to draw pie sectors).
  11487. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse.
  11488. * @param $startpoint (boolean) if true output a starting point.
  11489. * @param $ccw (boolean) if true draws in counter-clockwise.
  11490. * @param $svg (boolean) if true the angles are in svg mode (already calculated).
  11491. * @return array bounding box coordinates (x min, y min, x max, y max)
  11492. * @author Nicola Asuni
  11493. * @protected
  11494. * @since 4.9.019 (2010-04-26)
  11495. */
  11496. protected function _outellipticalarc($xc, $yc, $rx, $ry, $xang = 0, $angs = 0, $angf = 360, $pie = false, $nc = 2, $startpoint = true, $ccw = true, $svg = false)
  11497. {
  11498. if (($rx <= 0) OR ($ry < 0)) {
  11499. return;
  11500. }
  11501. $k = $this->k;
  11502. if ($nc < 2) {
  11503. $nc = 2;
  11504. }
  11505. $xmin = 2147483647;
  11506. $ymin = 2147483647;
  11507. $xmax = 0;
  11508. $ymax = 0;
  11509. if ($pie) {
  11510. // center of the arc
  11511. $this->_outPoint($xc, $yc);
  11512. }
  11513. $xang = deg2rad((float) $xang);
  11514. $angs = deg2rad((float) $angs);
  11515. $angf = deg2rad((float) $angf);
  11516. if ($svg) {
  11517. $as = $angs;
  11518. $af = $angf;
  11519. } else {
  11520. $as = atan2((sin($angs) / $ry), (cos($angs) / $rx));
  11521. $af = atan2((sin($angf) / $ry), (cos($angf) / $rx));
  11522. }
  11523. if ($as < 0) {
  11524. $as += (2 * M_PI);
  11525. }
  11526. if ($af < 0) {
  11527. $af += (2 * M_PI);
  11528. }
  11529. if ($ccw AND ($as > $af)) {
  11530. // reverse rotation
  11531. $as -= (2 * M_PI);
  11532. } elseif (!$ccw AND ($as < $af)) {
  11533. // reverse rotation
  11534. $af -= (2 * M_PI);
  11535. }
  11536. $total_angle = ($af - $as);
  11537. if ($nc < 2) {
  11538. $nc = 2;
  11539. }
  11540. // total arcs to draw
  11541. $nc *= (2 * abs($total_angle) / M_PI);
  11542. $nc = round($nc) + 1;
  11543. // angle of each arc
  11544. $arcang = ($total_angle / $nc);
  11545. // center point in PDF coordinates
  11546. $x0 = $xc;
  11547. $y0 = ($this->h - $yc);
  11548. // starting angle
  11549. $ang = $as;
  11550. $alpha = sin($arcang) * ((sqrt(4 + (3 * pow(tan(($arcang) / 2), 2))) - 1) / 3);
  11551. $cos_xang = cos($xang);
  11552. $sin_xang = sin($xang);
  11553. $cos_ang = cos($ang);
  11554. $sin_ang = sin($ang);
  11555. // first arc point
  11556. $px1 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
  11557. $py1 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
  11558. // first Bezier control point
  11559. $qx1 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
  11560. $qy1 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
  11561. if ($pie) {
  11562. // line from center to arc starting point
  11563. $this->_outLine($px1, $this->h - $py1);
  11564. } elseif ($startpoint) {
  11565. // arc starting point
  11566. $this->_outPoint($px1, $this->h - $py1);
  11567. }
  11568. // draw arcs
  11569. for ($i = 1; $i <= $nc; ++$i) {
  11570. // starting angle
  11571. $ang = $as + ($i * $arcang);
  11572. if ($i == $nc) {
  11573. $ang = $af;
  11574. }
  11575. $cos_ang = cos($ang);
  11576. $sin_ang = sin($ang);
  11577. // second arc point
  11578. $px2 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
  11579. $py2 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
  11580. // second Bezier control point
  11581. $qx2 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
  11582. $qy2 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
  11583. // draw arc
  11584. $cx1 = ($px1 + $qx1);
  11585. $cy1 = ($this->h - ($py1 + $qy1));
  11586. $cx2 = ($px2 - $qx2);
  11587. $cy2 = ($this->h - ($py2 - $qy2));
  11588. $cx3 = $px2;
  11589. $cy3 = ($this->h - $py2);
  11590. $this->_outCurve($cx1, $cy1, $cx2, $cy2, $cx3, $cy3);
  11591. // get bounding box coordinates
  11592. $xmin = min($xmin, $cx1, $cx2, $cx3);
  11593. $ymin = min($ymin, $cy1, $cy2, $cy3);
  11594. $xmax = max($xmax, $cx1, $cx2, $cx3);
  11595. $ymax = max($ymax, $cy1, $cy2, $cy3);
  11596. // move to next point
  11597. $px1 = $px2;
  11598. $py1 = $py2;
  11599. $qx1 = $qx2;
  11600. $qy1 = $qy2;
  11601. }
  11602. if ($pie) {
  11603. $this->_outLine($xc, $yc);
  11604. // get bounding box coordinates
  11605. $xmin = min($xmin, $xc);
  11606. $ymin = min($ymin, $yc);
  11607. $xmax = max($xmax, $xc);
  11608. $ymax = max($ymax, $yc);
  11609. }
  11610. return array($xmin, $ymin, $xmax, $ymax);
  11611. }
  11612. /**
  11613. * Draws a circle.
  11614. * A circle is formed from n Bezier curves.
  11615. * @param $x0 (float) Abscissa of center point.
  11616. * @param $y0 (float) Ordinate of center point.
  11617. * @param $r (float) Radius.
  11618. * @param $angstr: (float) Angle start of draw line. Default value: 0.
  11619. * @param $angend: (float) Angle finish of draw line. Default value: 360.
  11620. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11621. * @param $line_style (array) Line style of circle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11622. * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11623. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of circle.
  11624. * @public
  11625. * @since 2.1.000 (2008-01-08)
  11626. */
  11627. public function Circle($x0, $y0, $r, $angstr = 0, $angend = 360, $style = '', $line_style = array(), $fill_color = array(), $nc = 2)
  11628. {
  11629. $this->Ellipse($x0, $y0, $r, $r, 0, $angstr, $angend, $style, $line_style, $fill_color, $nc);
  11630. }
  11631. /**
  11632. * Draws a polygonal line
  11633. * @param $p (array) Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  11634. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11635. * @param $line_style (array) Line style of polygon. Array with keys among the following:
  11636. * <ul>
  11637. * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
  11638. * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
  11639. * </ul>
  11640. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  11641. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11642. * @since 4.8.003 (2009-09-15)
  11643. * @public
  11644. */
  11645. public function PolyLine($p, $style = '', $line_style = array(), $fill_color = array())
  11646. {
  11647. $this->Polygon($p, $style, $line_style, $fill_color, false);
  11648. }
  11649. /**
  11650. * Draws a polygon.
  11651. * @param $p (array) Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  11652. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11653. * @param $line_style (array) Line style of polygon. Array with keys among the following:
  11654. * <ul>
  11655. * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
  11656. * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
  11657. * </ul>
  11658. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  11659. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11660. * @param $closed (boolean) if true the polygon is closes, otherwise will remain open
  11661. * @public
  11662. * @since 2.1.000 (2008-01-08)
  11663. */
  11664. public function Polygon($p, $style = '', $line_style = array(), $fill_color = array(), $closed = true)
  11665. {
  11666. if ($this->state != 2) {
  11667. return;
  11668. }
  11669. $nc = count($p); // number of coordinates
  11670. $np = $nc / 2; // number of points
  11671. if ($closed) {
  11672. // close polygon by adding the first 2 points at the end (one line)
  11673. for ($i = 0; $i < 4; ++$i) {
  11674. $p[$nc + $i] = $p[$i];
  11675. }
  11676. // copy style for the last added line
  11677. if (isset($line_style[0])) {
  11678. $line_style[$np] = $line_style[0];
  11679. }
  11680. $nc += 4;
  11681. }
  11682. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11683. $this->SetFillColorArray($fill_color);
  11684. }
  11685. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11686. if ($op == 'f') {
  11687. $line_style = array();
  11688. }
  11689. $draw = true;
  11690. if ($line_style) {
  11691. if (isset($line_style['all'])) {
  11692. $this->SetLineStyle($line_style['all']);
  11693. } else {
  11694. $draw = false;
  11695. if ($op == 'B') {
  11696. // draw fill
  11697. $op = 'f';
  11698. $this->_outPoint($p[0], $p[1]);
  11699. for ($i = 2; $i < $nc; $i = $i + 2) {
  11700. $this->_outLine($p[$i], $p[$i + 1]);
  11701. }
  11702. $this->_out($op);
  11703. }
  11704. // draw outline
  11705. $this->_outPoint($p[0], $p[1]);
  11706. for ($i = 2; $i < $nc; $i = $i + 2) {
  11707. $line_num = ($i / 2) - 1;
  11708. if (isset($line_style[$line_num])) {
  11709. if ($line_style[$line_num] != 0) {
  11710. if (is_array($line_style[$line_num])) {
  11711. $this->_out('S');
  11712. $this->SetLineStyle($line_style[$line_num]);
  11713. $this->_outPoint($p[$i - 2], $p[$i - 1]);
  11714. $this->_outLine($p[$i], $p[$i + 1]);
  11715. $this->_out('S');
  11716. $this->_outPoint($p[$i], $p[$i + 1]);
  11717. } else {
  11718. $this->_outLine($p[$i], $p[$i + 1]);
  11719. }
  11720. }
  11721. } else {
  11722. $this->_outLine($p[$i], $p[$i + 1]);
  11723. }
  11724. }
  11725. $this->_out($op);
  11726. }
  11727. }
  11728. if ($draw) {
  11729. $this->_outPoint($p[0], $p[1]);
  11730. for ($i = 2; $i < $nc; $i = $i + 2) {
  11731. $this->_outLine($p[$i], $p[$i + 1]);
  11732. }
  11733. $this->_out($op);
  11734. }
  11735. }
  11736. /**
  11737. * Draws a regular polygon.
  11738. * @param $x0 (float) Abscissa of center point.
  11739. * @param $y0 (float) Ordinate of center point.
  11740. * @param $r: (float) Radius of inscribed circle.
  11741. * @param $ns (integer) Number of sides.
  11742. * @param $angle (float) Angle oriented (anti-clockwise). Default value: 0.
  11743. * @param $draw_circle (boolean) Draw inscribed circle or not. Default value: false.
  11744. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11745. * @param $line_style (array) Line style of polygon sides. Array with keys among the following:
  11746. * <ul>
  11747. * <li>all: Line style of all sides. Array like for SetLineStyle().</li>
  11748. * <li>0 to ($ns - 1): Line style of each side. Array like for SetLineStyle().</li>
  11749. * </ul>
  11750. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  11751. * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11752. * @param $circle_style (string) Style of rendering of inscribed circle (if draws). Possible values are:
  11753. * <ul>
  11754. * <li>D or empty string: Draw (default).</li>
  11755. * <li>F: Fill.</li>
  11756. * <li>DF or FD: Draw and fill.</li>
  11757. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  11758. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  11759. * </ul>
  11760. * @param $circle_outLine_style (array) Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
  11761. * @param $circle_fill_color (array) Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  11762. * @public
  11763. * @since 2.1.000 (2008-01-08)
  11764. */
  11765. 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())
  11766. {
  11767. if (3 > $ns) {
  11768. $ns = 3;
  11769. }
  11770. if ($draw_circle) {
  11771. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  11772. }
  11773. $p = array();
  11774. for ($i = 0; $i < $ns; ++$i) {
  11775. $a = $angle + ($i * 360 / $ns);
  11776. $a_rad = deg2rad((float) $a);
  11777. $p[] = $x0 + ($r * sin($a_rad));
  11778. $p[] = $y0 + ($r * cos($a_rad));
  11779. }
  11780. $this->Polygon($p, $style, $line_style, $fill_color);
  11781. }
  11782. /**
  11783. * Draws a star polygon
  11784. * @param $x0 (float) Abscissa of center point.
  11785. * @param $y0 (float) Ordinate of center point.
  11786. * @param $r (float) Radius of inscribed circle.
  11787. * @param $nv (integer) Number of vertices.
  11788. * @param $ng (integer) Number of gap (if ($ng % $nv = 1) then is a regular polygon).
  11789. * @param $angle: (float) Angle oriented (anti-clockwise). Default value: 0.
  11790. * @param $draw_circle: (boolean) Draw inscribed circle or not. Default value is false.
  11791. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11792. * @param $line_style (array) Line style of polygon sides. Array with keys among the following:
  11793. * <ul>
  11794. * <li>all: Line style of all sides. Array like for
  11795. * SetLineStyle().</li>
  11796. * <li>0 to (n - 1): Line style of each side. Array like for SetLineStyle().</li>
  11797. * </ul>
  11798. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  11799. * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11800. * @param $circle_style (string) Style of rendering of inscribed circle (if draws). Possible values are:
  11801. * <ul>
  11802. * <li>D or empty string: Draw (default).</li>
  11803. * <li>F: Fill.</li>
  11804. * <li>DF or FD: Draw and fill.</li>
  11805. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  11806. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  11807. * </ul>
  11808. * @param $circle_outLine_style (array) Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
  11809. * @param $circle_fill_color (array) Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  11810. * @public
  11811. * @since 2.1.000 (2008-01-08)
  11812. */
  11813. 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())
  11814. {
  11815. if ($nv < 2) {
  11816. $nv = 2;
  11817. }
  11818. if ($draw_circle) {
  11819. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  11820. }
  11821. $p2 = array();
  11822. $visited = array();
  11823. for ($i = 0; $i < $nv; ++$i) {
  11824. $a = $angle + ($i * 360 / $nv);
  11825. $a_rad = deg2rad((float) $a);
  11826. $p2[] = $x0 + ($r * sin($a_rad));
  11827. $p2[] = $y0 + ($r * cos($a_rad));
  11828. $visited[] = false;
  11829. }
  11830. $p = array();
  11831. $i = 0;
  11832. do {
  11833. $p[] = $p2[$i * 2];
  11834. $p[] = $p2[($i * 2) + 1];
  11835. $visited[$i] = true;
  11836. $i += $ng;
  11837. $i %= $nv;
  11838. } while (!$visited[$i]);
  11839. $this->Polygon($p, $style, $line_style, $fill_color);
  11840. }
  11841. /**
  11842. * Draws a rounded rectangle.
  11843. * @param $x (float) Abscissa of upper-left corner.
  11844. * @param $y (float) Ordinate of upper-left corner.
  11845. * @param $w (float) Width.
  11846. * @param $h (float) Height.
  11847. * @param $r (float) the radius of the circle used to round off the corners of the rectangle.
  11848. * @param $round_corner (string) Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top right, bottom right, bottom left and top left. Default value: all rounded corner ("1111").
  11849. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11850. * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11851. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11852. * @public
  11853. * @since 2.1.000 (2008-01-08)
  11854. */
  11855. public function RoundedRect($x, $y, $w, $h, $r, $round_corner = '1111', $style = '', $border_style = array(), $fill_color = array())
  11856. {
  11857. $this->RoundedRectXY($x, $y, $w, $h, $r, $r, $round_corner, $style, $border_style, $fill_color);
  11858. }
  11859. /**
  11860. * Draws a rounded rectangle.
  11861. * @param $x (float) Abscissa of upper-left corner.
  11862. * @param $y (float) Ordinate of upper-left corner.
  11863. * @param $w (float) Width.
  11864. * @param $h (float) Height.
  11865. * @param $rx (float) the x-axis radius of the ellipse used to round off the corners of the rectangle.
  11866. * @param $ry (float) the y-axis radius of the ellipse used to round off the corners of the rectangle.
  11867. * @param $round_corner (string) Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top right, bottom right, bottom left and top left. Default value: all rounded corner ("1111").
  11868. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11869. * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11870. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11871. * @public
  11872. * @since 4.9.019 (2010-04-22)
  11873. */
  11874. public function RoundedRectXY($x, $y, $w, $h, $rx, $ry, $round_corner = '1111', $style = '', $border_style = array(), $fill_color = array())
  11875. {
  11876. if ($this->state != 2) {
  11877. return;
  11878. }
  11879. if (($round_corner == '0000') OR (($rx == $ry) AND ($rx == 0))) {
  11880. // Not rounded
  11881. $this->Rect($x, $y, $w, $h, $style, $border_style, $fill_color);
  11882. return;
  11883. }
  11884. // Rounded
  11885. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11886. $this->SetFillColorArray($fill_color);
  11887. }
  11888. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11889. if ($op == 'f') {
  11890. $border_style = array();
  11891. }
  11892. if ($border_style) {
  11893. $this->SetLineStyle($border_style);
  11894. }
  11895. $MyArc = 4 / 3 * (sqrt(2) - 1);
  11896. $this->_outPoint($x + $rx, $y);
  11897. $xc = $x + $w - $rx;
  11898. $yc = $y + $ry;
  11899. $this->_outLine($xc, $y);
  11900. if ($round_corner[0]) {
  11901. $this->_outCurve($xc + ($rx * $MyArc), $yc - $ry, $xc + $rx, $yc - ($ry * $MyArc), $xc + $rx, $yc);
  11902. } else {
  11903. $this->_outLine($x + $w, $y);
  11904. }
  11905. $xc = $x + $w - $rx;
  11906. $yc = $y + $h - $ry;
  11907. $this->_outLine($x + $w, $yc);
  11908. if ($round_corner[1]) {
  11909. $this->_outCurve($xc + $rx, $yc + ($ry * $MyArc), $xc + ($rx * $MyArc), $yc + $ry, $xc, $yc + $ry);
  11910. } else {
  11911. $this->_outLine($x + $w, $y + $h);
  11912. }
  11913. $xc = $x + $rx;
  11914. $yc = $y + $h - $ry;
  11915. $this->_outLine($xc, $y + $h);
  11916. if ($round_corner[2]) {
  11917. $this->_outCurve($xc - ($rx * $MyArc), $yc + $ry, $xc - $rx, $yc + ($ry * $MyArc), $xc - $rx, $yc);
  11918. } else {
  11919. $this->_outLine($x, $y + $h);
  11920. }
  11921. $xc = $x + $rx;
  11922. $yc = $y + $ry;
  11923. $this->_outLine($x, $yc);
  11924. if ($round_corner[3]) {
  11925. $this->_outCurve($xc - $rx, $yc - ($ry * $MyArc), $xc - ($rx * $MyArc), $yc - $ry, $xc, $yc - $ry);
  11926. } else {
  11927. $this->_outLine($x, $y);
  11928. $this->_outLine($x + $rx, $y);
  11929. }
  11930. $this->_out($op);
  11931. }
  11932. /**
  11933. * Draws a grahic arrow.
  11934. * @param $x0 (float) Abscissa of first point.
  11935. * @param $y0 (float) Ordinate of first point.
  11936. * @param $x1 (float) Abscissa of second point.
  11937. * @param $y1 (float) Ordinate of second point.
  11938. * @param $head_style (int) (0 = draw only arrowhead arms, 1 = draw closed arrowhead, but no fill, 2 = closed and filled arrowhead, 3 = filled arrowhead)
  11939. * @param $arm_size (float) length of arrowhead arms
  11940. * @param $arm_angle (int) angle between an arm and the shaft
  11941. * @author Piotr Galecki, Nicola Asuni, Andy Meier
  11942. * @since 4.6.018 (2009-07-10)
  11943. */
  11944. public function Arrow($x0, $y0, $x1, $y1, $head_style = 0, $arm_size = 5, $arm_angle = 15)
  11945. {
  11946. // getting arrow direction angle
  11947. // 0 deg angle is when both arms go along X axis. angle grows clockwise.
  11948. $dir_angle = atan2(($y0 - $y1), ($x0 - $x1));
  11949. if ($dir_angle < 0) {
  11950. $dir_angle += (2 * M_PI);
  11951. }
  11952. $arm_angle = deg2rad($arm_angle);
  11953. $sx1 = $x1;
  11954. $sy1 = $y1;
  11955. if ($head_style > 0) {
  11956. // calculate the stopping point for the arrow shaft
  11957. $sx1 = $x1 + (($arm_size - $this->LineWidth) * cos($dir_angle));
  11958. $sy1 = $y1 + (($arm_size - $this->LineWidth) * sin($dir_angle));
  11959. }
  11960. // main arrow line / shaft
  11961. $this->Line($x0, $y0, $sx1, $sy1);
  11962. // left arrowhead arm tip
  11963. $x2L = $x1 + ($arm_size * cos($dir_angle + $arm_angle));
  11964. $y2L = $y1 + ($arm_size * sin($dir_angle + $arm_angle));
  11965. // right arrowhead arm tip
  11966. $x2R = $x1 + ($arm_size * cos($dir_angle - $arm_angle));
  11967. $y2R = $y1 + ($arm_size * sin($dir_angle - $arm_angle));
  11968. $mode = 'D';
  11969. $style = array();
  11970. switch ($head_style) {
  11971. case 0: {
  11972. // draw only arrowhead arms
  11973. $mode = 'D';
  11974. $style = array(1, 1, 0);
  11975. break;
  11976. }
  11977. case 1: {
  11978. // draw closed arrowhead, but no fill
  11979. $mode = 'D';
  11980. break;
  11981. }
  11982. case 2: {
  11983. // closed and filled arrowhead
  11984. $mode = 'DF';
  11985. break;
  11986. }
  11987. case 3: {
  11988. // filled arrowhead
  11989. $mode = 'F';
  11990. break;
  11991. }
  11992. }
  11993. $this->Polygon(array($x2L, $y2L, $x1, $y1, $x2R, $y2R), $mode, $style, array());
  11994. }
  11995. // END GRAPHIC FUNCTIONS SECTION -----------------------
  11996. /**
  11997. * Add a Named Destination.
  11998. * NOTE: destination names are unique, so only last entry will be saved.
  11999. * @param $name (string) Destination name.
  12000. * @param $y (float) Y position in user units of the destiantion on the selected page (default = -1 = current position; 0 = page start;).
  12001. * @param $page (int|string) Target page number (leave empty for current page). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages.
  12002. * @param $x (float) X position in user units of the destiantion on the selected page (default = -1 = current position;).
  12003. * @return (string) Stripped named destination identifier or false in case of error.
  12004. * @public
  12005. * @author Christian Deligant, Nicola Asuni
  12006. * @since 5.9.097 (2011-06-23)
  12007. */
  12008. public function setDestination($name, $y = -1, $page = '', $x = -1)
  12009. {
  12010. // remove unsupported characters
  12011. $name = TCPDF_STATIC::encodeNameObject($name);
  12012. if (TCPDF_STATIC::empty_string($name)) {
  12013. return false;
  12014. }
  12015. if ($y == -1) {
  12016. $y = $this->GetY();
  12017. } elseif ($y < 0) {
  12018. $y = 0;
  12019. } elseif ($y > $this->h) {
  12020. $y = $this->h;
  12021. }
  12022. if ($x == -1) {
  12023. $x = $this->GetX();
  12024. } elseif ($x < 0) {
  12025. $x = 0;
  12026. } elseif ($x > $this->w) {
  12027. $x = $this->w;
  12028. }
  12029. $fixed = false;
  12030. if (!empty($page) AND ($page[0] == '*')) {
  12031. $page = intval(substr($page, 1));
  12032. // this page number will not be changed when moving/add/deleting pages
  12033. $fixed = true;
  12034. }
  12035. if (empty($page)) {
  12036. $page = $this->PageNo();
  12037. if (empty($page)) {
  12038. return;
  12039. }
  12040. }
  12041. $this->dests[$name] = array('x' => $x, 'y' => $y, 'p' => $page, 'f' => $fixed);
  12042. return $name;
  12043. }
  12044. /**
  12045. * Return the Named Destination array.
  12046. * @return (array) Named Destination array.
  12047. * @public
  12048. * @author Nicola Asuni
  12049. * @since 5.9.097 (2011-06-23)
  12050. */
  12051. public function getDestination()
  12052. {
  12053. return $this->dests;
  12054. }
  12055. /**
  12056. * Insert Named Destinations.
  12057. * @protected
  12058. * @author Johannes G\FCntert, Nicola Asuni
  12059. * @since 5.9.098 (2011-06-23)
  12060. */
  12061. protected function _putdests()
  12062. {
  12063. if (empty($this->dests)) {
  12064. return;
  12065. }
  12066. $this->n_dests = $this->_newobj();
  12067. $out = ' <<';
  12068. foreach ($this->dests as $name => $o) {
  12069. $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)));
  12070. }
  12071. $out .= ' >>';
  12072. $out .= "\n".'endobj';
  12073. $this->_out($out);
  12074. }
  12075. /**
  12076. * Adds a bookmark - alias for Bookmark().
  12077. * @param $txt (string) Bookmark description.
  12078. * @param $level (int) Bookmark level (minimum value is 0).
  12079. * @param $y (float) Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
  12080. * @param $page (int|string) Target page number (leave empty for current page). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages.
  12081. * @param $style (string) Font style: B = Bold, I = Italic, BI = Bold + Italic.
  12082. * @param $color (array) RGB color array (values from 0 to 255).
  12083. * @param $x (float) X position in user units of the bookmark on the selected page (default = -1 = current position;).
  12084. * @param $link (mixed) URL, or numerical link ID, or named destination (# character followed by the destination name), or embedded file (* character followed by the file name).
  12085. * @public
  12086. */
  12087. public function setBookmark($txt, $level = 0, $y = -1, $page = '', $style = '', $color = array(0,0,0), $x = -1, $link = '')
  12088. {
  12089. $this->Bookmark($txt, $level, $y, $page, $style, $color, $x, $link);
  12090. }
  12091. /**
  12092. * Adds a bookmark.
  12093. * @param $txt (string) Bookmark description.
  12094. * @param $level (int) Bookmark level (minimum value is 0).
  12095. * @param $y (float) Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
  12096. * @param $page (int|string) Target page number (leave empty for current page). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages.
  12097. * @param $style (string) Font style: B = Bold, I = Italic, BI = Bold + Italic.
  12098. * @param $color (array) RGB color array (values from 0 to 255).
  12099. * @param $x (float) X position in user units of the bookmark on the selected page (default = -1 = current position;).
  12100. * @param $link (mixed) URL, or numerical link ID, or named destination (# character followed by the destination name), or embedded file (* character followed by the file name).
  12101. * @public
  12102. * @since 2.1.002 (2008-02-12)
  12103. */
  12104. public function Bookmark($txt, $level = 0, $y = -1, $page = '', $style = '', $color = array(0,0,0), $x = -1, $link = '')
  12105. {
  12106. if ($level < 0) {
  12107. $level = 0;
  12108. }
  12109. if (isset($this->outlines[0])) {
  12110. $lastoutline = end($this->outlines);
  12111. $maxlevel = $lastoutline['l'] + 1;
  12112. } else {
  12113. $maxlevel = 0;
  12114. }
  12115. if ($level > $maxlevel) {
  12116. $level = $maxlevel;
  12117. }
  12118. if ($y == -1) {
  12119. $y = $this->GetY();
  12120. } elseif ($y < 0) {
  12121. $y = 0;
  12122. } elseif ($y > $this->h) {
  12123. $y = $this->h;
  12124. }
  12125. if ($x == -1) {
  12126. $x = $this->GetX();
  12127. } elseif ($x < 0) {
  12128. $x = 0;
  12129. } elseif ($x > $this->w) {
  12130. $x = $this->w;
  12131. }
  12132. $fixed = false;
  12133. if (!empty($page) AND ($page[0] == '*')) {
  12134. $page = intval(substr($page, 1));
  12135. // this page number will not be changed when moving/add/deleting pages
  12136. $fixed = true;
  12137. }
  12138. if (empty($page)) {
  12139. $page = $this->PageNo();
  12140. if (empty($page)) {
  12141. return;
  12142. }
  12143. }
  12144. $this->outlines[] = array('t' => $txt, 'l' => $level, 'x' => $x, 'y' => $y, 'p' => $page, 'f' => $fixed, 's' => strtoupper($style), 'c' => $color, 'u' => $link);
  12145. }
  12146. /**
  12147. * Sort bookmarks for page and key.
  12148. * @protected
  12149. * @since 5.9.119 (2011-09-19)
  12150. */
  12151. protected function sortBookmarks()
  12152. {
  12153. // get sorting columns
  12154. $outline_p = array();
  12155. $outline_y = array();
  12156. foreach ($this->outlines as $key => $row) {
  12157. $outline_p[$key] = $row['p'];
  12158. $outline_k[$key] = $key;
  12159. }
  12160. // sort outlines by page and original position
  12161. array_multisort($outline_p, SORT_NUMERIC, SORT_ASC, $outline_k, SORT_NUMERIC, SORT_ASC, $this->outlines);
  12162. }
  12163. /**
  12164. * Create a bookmark PDF string.
  12165. * @protected
  12166. * @author Olivier Plathey, Nicola Asuni
  12167. * @since 2.1.002 (2008-02-12)
  12168. */
  12169. protected function _putbookmarks()
  12170. {
  12171. $nb = count($this->outlines);
  12172. if ($nb == 0) {
  12173. return;
  12174. }
  12175. // sort bookmarks
  12176. $this->sortBookmarks();
  12177. $lru = array();
  12178. $level = 0;
  12179. foreach ($this->outlines as $i => $o) {
  12180. if ($o['l'] > 0) {
  12181. $parent = $lru[($o['l'] - 1)];
  12182. //Set parent and last pointers
  12183. $this->outlines[$i]['parent'] = $parent;
  12184. $this->outlines[$parent]['last'] = $i;
  12185. if ($o['l'] > $level) {
  12186. //Level increasing: set first pointer
  12187. $this->outlines[$parent]['first'] = $i;
  12188. }
  12189. } else {
  12190. $this->outlines[$i]['parent'] = $nb;
  12191. }
  12192. if (($o['l'] <= $level) AND ($i > 0)) {
  12193. //Set prev and next pointers
  12194. $prev = $lru[$o['l']];
  12195. $this->outlines[$prev]['next'] = $i;
  12196. $this->outlines[$i]['prev'] = $prev;
  12197. }
  12198. $lru[$o['l']] = $i;
  12199. $level = $o['l'];
  12200. }
  12201. //Outline items
  12202. $n = $this->n + 1;
  12203. $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';
  12204. foreach ($this->outlines as $i => $o) {
  12205. $oid = $this->_newobj();
  12206. // covert HTML title to string
  12207. $title = preg_replace($nltags, "\n", $o['t']);
  12208. $title = preg_replace("/[\r]+/si", '', $title);
  12209. $title = preg_replace("/[\n]+/si", "\n", $title);
  12210. $title = strip_tags($title);
  12211. $title = $this->stringTrim($title);
  12212. $out = '<</Title '.$this->_textstring($title, $oid);
  12213. $out .= ' /Parent '.($n + $o['parent']).' 0 R';
  12214. if (isset($o['prev'])) {
  12215. $out .= ' /Prev '.($n + $o['prev']).' 0 R';
  12216. }
  12217. if (isset($o['next'])) {
  12218. $out .= ' /Next '.($n + $o['next']).' 0 R';
  12219. }
  12220. if (isset($o['first'])) {
  12221. $out .= ' /First '.($n + $o['first']).' 0 R';
  12222. }
  12223. if (isset($o['last'])) {
  12224. $out .= ' /Last '.($n + $o['last']).' 0 R';
  12225. }
  12226. if (isset($o['u']) AND !empty($o['u'])) {
  12227. // link
  12228. if (is_string($o['u'])) {
  12229. if ($o['u'][0] == '#') {
  12230. // internal destination
  12231. $out .= ' /Dest /'.TCPDF_STATIC::encodeNameObject(substr($o['u'], 1));
  12232. } elseif ($o['u'][0] == '%') {
  12233. // embedded PDF file
  12234. $filename = basename(substr($o['u'], 1));
  12235. $out .= ' /A <</S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($o['p'] - 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>';
  12236. } elseif ($o['u'][0] == '*') {
  12237. // embedded generic file
  12238. $filename = basename(substr($o['u'], 1));
  12239. $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});';
  12240. $out .= ' /A <</S /JavaScript /JS '.$this->_textstring($jsa, $oid).'>>';
  12241. } else {
  12242. // external URI link
  12243. $out .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($o['u']), $oid).'>>';
  12244. }
  12245. } elseif (isset($this->links[$o['u']])) {
  12246. // internal link ID
  12247. $l = $this->links[$o['u']];
  12248. if (isset($this->page_obj_id[($l['p'])])) {
  12249. $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)));
  12250. }
  12251. }
  12252. } elseif (isset($this->page_obj_id[($o['p'])])) {
  12253. // link to a page
  12254. $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)));
  12255. }
  12256. // set font style
  12257. $style = 0;
  12258. if (!empty($o['s'])) {
  12259. // bold
  12260. if (strpos($o['s'], 'B') !== false) {
  12261. $style |= 2;
  12262. }
  12263. // oblique
  12264. if (strpos($o['s'], 'I') !== false) {
  12265. $style |= 1;
  12266. }
  12267. }
  12268. $out .= sprintf(' /F %d', $style);
  12269. // set bookmark color
  12270. if (isset($o['c']) AND is_array($o['c']) AND (count($o['c']) == 3)) {
  12271. $color = array_values($o['c']);
  12272. $out .= sprintf(' /C [%F %F %F]', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
  12273. } else {
  12274. // black
  12275. $out .= ' /C [0.0 0.0 0.0]';
  12276. }
  12277. $out .= ' /Count 0'; // normally closed item
  12278. $out .= ' >>';
  12279. $out .= "\n".'endobj';
  12280. $this->_out($out);
  12281. }
  12282. //Outline root
  12283. $this->OutlineRoot = $this->_newobj();
  12284. $this->_out('<< /Type /Outlines /First '.$n.' 0 R /Last '.($n + $lru[0]).' 0 R >>'."\n".'endobj');
  12285. }
  12286. // --- JAVASCRIPT ------------------------------------------------------
  12287. /**
  12288. * Adds a javascript
  12289. * @param $script (string) Javascript code
  12290. * @public
  12291. * @author Johannes G\FCntert, Nicola Asuni
  12292. * @since 2.1.002 (2008-02-12)
  12293. */
  12294. public function IncludeJS($script)
  12295. {
  12296. $this->javascript .= $script;
  12297. }
  12298. /**
  12299. * Adds a javascript object and return object ID
  12300. * @param $script (string) Javascript code
  12301. * @param $onload (boolean) if true executes this object when opening the document
  12302. * @return int internal object ID
  12303. * @public
  12304. * @author Nicola Asuni
  12305. * @since 4.8.000 (2009-09-07)
  12306. */
  12307. public function addJavascriptObject($script, $onload = false)
  12308. {
  12309. if ($this->pdfa_mode) {
  12310. // javascript is not allowed in PDF/A mode
  12311. return false;
  12312. }
  12313. ++$this->n;
  12314. $this->js_objects[$this->n] = array('n' => $this->n, 'js' => $script, 'onload' => $onload);
  12315. return $this->n;
  12316. }
  12317. /**
  12318. * Create a javascript PDF string.
  12319. * @protected
  12320. * @author Johannes G\FCntert, Nicola Asuni
  12321. * @since 2.1.002 (2008-02-12)
  12322. */
  12323. protected function _putjavascript()
  12324. {
  12325. if ($this->pdfa_mode OR (empty($this->javascript) AND empty($this->js_objects))) {
  12326. return;
  12327. }
  12328. if (strpos($this->javascript, 'this.addField') > 0) {
  12329. if (!$this->ur['enabled']) {
  12330. //$this->setUserRights();
  12331. }
  12332. // the following two lines are used to avoid form fields duplication after saving
  12333. // The addField method only works when releasing user rights (UR3)
  12334. $jsa = sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%F,%F,%F,%F]);", 'tcpdfdocsaved', 'text', 0, 0, 1, 0, 1);
  12335. $jsb = "getField('tcpdfdocsaved').value='saved';";
  12336. $this->javascript = $jsa."\n".$this->javascript."\n".$jsb;
  12337. }
  12338. // name tree for javascript
  12339. $this->n_js = '<< /Names [';
  12340. if (!empty($this->javascript)) {
  12341. $this->n_js .= ' (EmbeddedJS) '.($this->n + 1).' 0 R';
  12342. }
  12343. if (!empty($this->js_objects)) {
  12344. foreach ($this->js_objects as $key => $val) {
  12345. if ($val['onload']) {
  12346. $this->n_js .= ' (JS'.$key.') '.$key.' 0 R';
  12347. }
  12348. }
  12349. }
  12350. $this->n_js .= ' ] >>';
  12351. // default Javascript object
  12352. if (!empty($this->javascript)) {
  12353. $obj_id = $this->_newobj();
  12354. $out = '<< /S /JavaScript';
  12355. $out .= ' /JS '.$this->_textstring($this->javascript, $obj_id);
  12356. $out .= ' >>';
  12357. $out .= "\n".'endobj';
  12358. $this->_out($out);
  12359. }
  12360. // additional Javascript objects
  12361. if (!empty($this->js_objects)) {
  12362. foreach ($this->js_objects as $key => $val) {
  12363. $out = $this->_getobj($key)."\n".' << /S /JavaScript /JS '.$this->_textstring($val['js'], $key).' >>'."\n".'endobj';
  12364. $this->_out($out);
  12365. }
  12366. }
  12367. }
  12368. /**
  12369. * Adds a javascript form field.
  12370. * @param $type (string) field type
  12371. * @param $name (string) field name
  12372. * @param $x (int) horizontal position
  12373. * @param $y (int) vertical position
  12374. * @param $w (int) width
  12375. * @param $h (int) height
  12376. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12377. * @protected
  12378. * @author Denis Van Nuffelen, Nicola Asuni
  12379. * @since 2.1.002 (2008-02-12)
  12380. */
  12381. protected function _addfield($type, $name, $x, $y, $w, $h, $prop)
  12382. {
  12383. if ($this->rtl) {
  12384. $x = $x - $w;
  12385. }
  12386. // the followind avoid fields duplication after saving the document
  12387. $this->javascript .= "if (getField('tcpdfdocsaved').value != 'saved') {";
  12388. $k = $this->k;
  12389. $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";
  12390. $this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n";
  12391. foreach ($prop as $key => $val) {
  12392. if (strcmp(substr($key, -5), 'Color') == 0) {
  12393. $val = TCPDF_COLORS::_JScolor($val);
  12394. } else {
  12395. $val = "'".$val."'";
  12396. }
  12397. $this->javascript .= 'f'.$name.'.'.$key.'='.$val.";\n";
  12398. }
  12399. if ($this->rtl) {
  12400. $this->x -= $w;
  12401. } else {
  12402. $this->x += $w;
  12403. }
  12404. $this->javascript .= '}';
  12405. }
  12406. // --- FORM FIELDS -----------------------------------------------------
  12407. /**
  12408. * Set default properties for form fields.
  12409. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12410. * @public
  12411. * @author Nicola Asuni
  12412. * @since 4.8.000 (2009-09-06)
  12413. */
  12414. public function setFormDefaultProp($prop = array())
  12415. {
  12416. $this->default_form_prop = $prop;
  12417. }
  12418. /**
  12419. * Return the default properties for form fields.
  12420. * @return array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12421. * @public
  12422. * @author Nicola Asuni
  12423. * @since 4.8.000 (2009-09-06)
  12424. */
  12425. public function getFormDefaultProp()
  12426. {
  12427. return $this->default_form_prop;
  12428. }
  12429. /**
  12430. * Creates a text field
  12431. * @param $name (string) field name
  12432. * @param $w (float) Width of the rectangle
  12433. * @param $h (float) Height of the rectangle
  12434. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12435. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12436. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12437. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12438. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12439. * @public
  12440. * @author Nicola Asuni
  12441. * @since 4.8.000 (2009-09-07)
  12442. */
  12443. public function TextField($name, $w, $h, $prop = array(), $opt = array(), $x = '', $y = '', $js = false)
  12444. {
  12445. if ($x === '') {
  12446. $x = $this->x;
  12447. }
  12448. if ($y === '') {
  12449. $y = $this->y;
  12450. }
  12451. // check page for no-write regions and adapt page margins if necessary
  12452. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12453. if ($js) {
  12454. $this->_addfield('text', $name, $x, $y, $w, $h, $prop);
  12455. return;
  12456. }
  12457. // get default style
  12458. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12459. // get annotation data
  12460. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12461. // set default appearance stream
  12462. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12463. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12464. $popt['da'] = $fontstyle;
  12465. // build appearance stream
  12466. $popt['ap'] = array();
  12467. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12468. $text = '';
  12469. if (isset($prop['value']) AND !empty($prop['value'])) {
  12470. $text = $prop['value'];
  12471. } elseif (isset($opt['v']) AND !empty($opt['v'])) {
  12472. $text = $opt['v'];
  12473. }
  12474. $tmpid = $this->startTemplate($w, $h, false);
  12475. $align = '';
  12476. if (isset($popt['q'])) {
  12477. switch ($popt['q']) {
  12478. case 0: {
  12479. $align = 'L';
  12480. break;
  12481. }
  12482. case 1: {
  12483. $align = 'C';
  12484. break;
  12485. }
  12486. case 2: {
  12487. $align = 'R';
  12488. break;
  12489. }
  12490. default: {
  12491. $align = '';
  12492. break;
  12493. }
  12494. }
  12495. }
  12496. $this->MultiCell($w, $h, $text, 0, $align, false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  12497. $this->endTemplate();
  12498. --$this->n;
  12499. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12500. unset($this->xobjects[$tmpid]);
  12501. $popt['ap']['n'] .= 'Q EMC';
  12502. // merge options
  12503. $opt = array_merge($popt, $opt);
  12504. // remove some conflicting options
  12505. unset($opt['bs']);
  12506. // set remaining annotation data
  12507. $opt['Subtype'] = 'Widget';
  12508. $opt['ft'] = 'Tx';
  12509. $opt['t'] = $name;
  12510. // Additional annotation's parameters (check _putannotsobj() method):
  12511. //$opt['f']
  12512. //$opt['as']
  12513. //$opt['bs']
  12514. //$opt['be']
  12515. //$opt['c']
  12516. //$opt['border']
  12517. //$opt['h']
  12518. //$opt['mk'];
  12519. //$opt['mk']['r']
  12520. //$opt['mk']['bc'];
  12521. //$opt['mk']['bg'];
  12522. unset($opt['mk']['ca']);
  12523. unset($opt['mk']['rc']);
  12524. unset($opt['mk']['ac']);
  12525. unset($opt['mk']['i']);
  12526. unset($opt['mk']['ri']);
  12527. unset($opt['mk']['ix']);
  12528. unset($opt['mk']['if']);
  12529. //$opt['mk']['if']['sw'];
  12530. //$opt['mk']['if']['s'];
  12531. //$opt['mk']['if']['a'];
  12532. //$opt['mk']['if']['fb'];
  12533. unset($opt['mk']['tp']);
  12534. //$opt['tu']
  12535. //$opt['tm']
  12536. //$opt['ff']
  12537. //$opt['v']
  12538. //$opt['dv']
  12539. //$opt['a']
  12540. //$opt['aa']
  12541. //$opt['q']
  12542. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12543. if ($this->rtl) {
  12544. $this->x -= $w;
  12545. } else {
  12546. $this->x += $w;
  12547. }
  12548. }
  12549. /**
  12550. * Creates a RadioButton field.
  12551. * @param $name (string) Field name.
  12552. * @param $w (int) Width of the radio button.
  12553. * @param $prop (array) Javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12554. * @param $opt (array) Annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12555. * @param $onvalue (string) Value to be returned if selected.
  12556. * @param $checked (boolean) Define the initial state.
  12557. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12558. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12559. * @param $js (boolean) If true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12560. * @public
  12561. * @author Nicola Asuni
  12562. * @since 4.8.000 (2009-09-07)
  12563. */
  12564. public function RadioButton($name, $w, $prop = array(), $opt = array(), $onvalue = 'On', $checked = false, $x = '', $y = '', $js = false)
  12565. {
  12566. if ($x === '') {
  12567. $x = $this->x;
  12568. }
  12569. if ($y === '') {
  12570. $y = $this->y;
  12571. }
  12572. // check page for no-write regions and adapt page margins if necessary
  12573. list($x, $y) = $this->checkPageRegions($w, $x, $y);
  12574. if ($js) {
  12575. $this->_addfield('radiobutton', $name, $x, $y, $w, $w, $prop);
  12576. return;
  12577. }
  12578. if (TCPDF_STATIC::empty_string($onvalue)) {
  12579. $onvalue = 'On';
  12580. }
  12581. if ($checked) {
  12582. $defval = $onvalue;
  12583. } else {
  12584. $defval = 'Off';
  12585. }
  12586. // set font
  12587. $font = 'zapfdingbats';
  12588. if ($this->pdfa_mode) {
  12589. // all fonts must be embedded
  12590. $font = 'pdfa'.$font;
  12591. }
  12592. $this->AddFont($font);
  12593. $tmpfont = $this->getFontBuffer($font);
  12594. // set data for parent group
  12595. if (!isset($this->radiobutton_groups[$this->page])) {
  12596. $this->radiobutton_groups[$this->page] = array();
  12597. }
  12598. if (!isset($this->radiobutton_groups[$this->page][$name])) {
  12599. $this->radiobutton_groups[$this->page][$name] = array();
  12600. ++$this->n;
  12601. $this->radiobutton_groups[$this->page][$name]['n'] = $this->n;
  12602. $this->radio_groups[] = $this->n;
  12603. }
  12604. $kid = ($this->n + 1);
  12605. // save object ID to be added on Kids entry on parent object
  12606. $this->radiobutton_groups[$this->page][$name][] = array('kid' => $kid, 'def' => $defval);
  12607. // get default style
  12608. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12609. $prop['NoToggleToOff'] = 'true';
  12610. $prop['Radio'] = 'true';
  12611. $prop['borderStyle'] = 'inset';
  12612. // get annotation data
  12613. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12614. // set additional default options
  12615. $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  12616. $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
  12617. $popt['da'] = $fontstyle;
  12618. // build appearance stream
  12619. $popt['ap'] = array();
  12620. $popt['ap']['n'] = array();
  12621. $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][108])) / 2) * $this->k);
  12622. $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k);
  12623. $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);
  12624. $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);
  12625. if (!isset($popt['mk'])) {
  12626. $popt['mk'] = array();
  12627. }
  12628. $popt['mk']['ca'] = '(l)';
  12629. // merge options
  12630. $opt = array_merge($popt, $opt);
  12631. // set remaining annotation data
  12632. $opt['Subtype'] = 'Widget';
  12633. $opt['ft'] = 'Btn';
  12634. if ($checked) {
  12635. $opt['v'] = array('/'.$onvalue);
  12636. $opt['as'] = $onvalue;
  12637. } else {
  12638. $opt['as'] = 'Off';
  12639. }
  12640. // store readonly flag
  12641. if (!isset($this->radiobutton_groups[$this->page][$name]['#readonly#'])) {
  12642. $this->radiobutton_groups[$this->page][$name]['#readonly#'] = false;
  12643. }
  12644. $this->radiobutton_groups[$this->page][$name]['#readonly#'] |= ($opt['f'] & 64);
  12645. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  12646. if ($this->rtl) {
  12647. $this->x -= $w;
  12648. } else {
  12649. $this->x += $w;
  12650. }
  12651. }
  12652. /**
  12653. * Creates a List-box field
  12654. * @param $name (string) field name
  12655. * @param $w (int) width
  12656. * @param $h (int) height
  12657. * @param $values (array) array containing the list of values.
  12658. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12659. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12660. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12661. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12662. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12663. * @public
  12664. * @author Nicola Asuni
  12665. * @since 4.8.000 (2009-09-07)
  12666. */
  12667. public function ListBox($name, $w, $h, $values, $prop = array(), $opt = array(), $x = '', $y = '', $js = false)
  12668. {
  12669. if ($x === '') {
  12670. $x = $this->x;
  12671. }
  12672. if ($y === '') {
  12673. $y = $this->y;
  12674. }
  12675. // check page for no-write regions and adapt page margins if necessary
  12676. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12677. if ($js) {
  12678. $this->_addfield('listbox', $name, $x, $y, $w, $h, $prop);
  12679. $s = '';
  12680. foreach ($values as $value) {
  12681. if (is_array($value)) {
  12682. $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
  12683. } else {
  12684. $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
  12685. }
  12686. }
  12687. $this->javascript .= 'f'.$name.'.setItems('.substr($s, 1).');'."\n";
  12688. return;
  12689. }
  12690. // get default style
  12691. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12692. // get annotation data
  12693. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12694. // set additional default values
  12695. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12696. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12697. $popt['da'] = $fontstyle;
  12698. // build appearance stream
  12699. $popt['ap'] = array();
  12700. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12701. $text = '';
  12702. foreach ($values as $item) {
  12703. if (is_array($item)) {
  12704. $text .= $item[1]."\n";
  12705. } else {
  12706. $text .= $item."\n";
  12707. }
  12708. }
  12709. $tmpid = $this->startTemplate($w, $h, false);
  12710. $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  12711. $this->endTemplate();
  12712. --$this->n;
  12713. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12714. unset($this->xobjects[$tmpid]);
  12715. $popt['ap']['n'] .= 'Q EMC';
  12716. // merge options
  12717. $opt = array_merge($popt, $opt);
  12718. // set remaining annotation data
  12719. $opt['Subtype'] = 'Widget';
  12720. $opt['ft'] = 'Ch';
  12721. $opt['t'] = $name;
  12722. $opt['opt'] = $values;
  12723. unset($opt['mk']['ca']);
  12724. unset($opt['mk']['rc']);
  12725. unset($opt['mk']['ac']);
  12726. unset($opt['mk']['i']);
  12727. unset($opt['mk']['ri']);
  12728. unset($opt['mk']['ix']);
  12729. unset($opt['mk']['if']);
  12730. unset($opt['mk']['tp']);
  12731. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12732. if ($this->rtl) {
  12733. $this->x -= $w;
  12734. } else {
  12735. $this->x += $w;
  12736. }
  12737. }
  12738. /**
  12739. * Creates a Combo-box field
  12740. * @param $name (string) field name
  12741. * @param $w (int) width
  12742. * @param $h (int) height
  12743. * @param $values (array) array containing the list of values.
  12744. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12745. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12746. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12747. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12748. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12749. * @public
  12750. * @author Nicola Asuni
  12751. * @since 4.8.000 (2009-09-07)
  12752. */
  12753. public function ComboBox($name, $w, $h, $values, $prop = array(), $opt = array(), $x = '', $y = '', $js = false)
  12754. {
  12755. if ($x === '') {
  12756. $x = $this->x;
  12757. }
  12758. if ($y === '') {
  12759. $y = $this->y;
  12760. }
  12761. // check page for no-write regions and adapt page margins if necessary
  12762. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12763. if ($js) {
  12764. $this->_addfield('combobox', $name, $x, $y, $w, $h, $prop);
  12765. $s = '';
  12766. foreach ($values as $value) {
  12767. if (is_array($value)) {
  12768. $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
  12769. } else {
  12770. $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
  12771. }
  12772. }
  12773. $this->javascript .= 'f'.$name.'.setItems('.substr($s, 1).');'."\n";
  12774. return;
  12775. }
  12776. // get default style
  12777. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12778. $prop['Combo'] = true;
  12779. // get annotation data
  12780. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12781. // set additional default options
  12782. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12783. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12784. $popt['da'] = $fontstyle;
  12785. // build appearance stream
  12786. $popt['ap'] = array();
  12787. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12788. $text = '';
  12789. foreach ($values as $item) {
  12790. if (is_array($item)) {
  12791. $text .= $item[1]."\n";
  12792. } else {
  12793. $text .= $item."\n";
  12794. }
  12795. }
  12796. $tmpid = $this->startTemplate($w, $h, false);
  12797. $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  12798. $this->endTemplate();
  12799. --$this->n;
  12800. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12801. unset($this->xobjects[$tmpid]);
  12802. $popt['ap']['n'] .= 'Q EMC';
  12803. // merge options
  12804. $opt = array_merge($popt, $opt);
  12805. // set remaining annotation data
  12806. $opt['Subtype'] = 'Widget';
  12807. $opt['ft'] = 'Ch';
  12808. $opt['t'] = $name;
  12809. $opt['opt'] = $values;
  12810. unset($opt['mk']['ca']);
  12811. unset($opt['mk']['rc']);
  12812. unset($opt['mk']['ac']);
  12813. unset($opt['mk']['i']);
  12814. unset($opt['mk']['ri']);
  12815. unset($opt['mk']['ix']);
  12816. unset($opt['mk']['if']);
  12817. unset($opt['mk']['tp']);
  12818. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12819. if ($this->rtl) {
  12820. $this->x -= $w;
  12821. } else {
  12822. $this->x += $w;
  12823. }
  12824. }
  12825. /**
  12826. * Creates a CheckBox field
  12827. * @param $name (string) field name
  12828. * @param $w (int) width
  12829. * @param $checked (boolean) define the initial state.
  12830. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12831. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12832. * @param $onvalue (string) value to be returned if selected.
  12833. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12834. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12835. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12836. * @public
  12837. * @author Nicola Asuni
  12838. * @since 4.8.000 (2009-09-07)
  12839. */
  12840. public function CheckBox($name, $w, $checked = false, $prop = array(), $opt = array(), $onvalue = 'Yes', $x = '', $y = '', $js = false)
  12841. {
  12842. if ($x === '') {
  12843. $x = $this->x;
  12844. }
  12845. if ($y === '') {
  12846. $y = $this->y;
  12847. }
  12848. // check page for no-write regions and adapt page margins if necessary
  12849. list($x, $y) = $this->checkPageRegions($w, $x, $y);
  12850. if ($js) {
  12851. $this->_addfield('checkbox', $name, $x, $y, $w, $w, $prop);
  12852. return;
  12853. }
  12854. if (!isset($prop['value'])) {
  12855. $prop['value'] = array('Yes');
  12856. }
  12857. // get default style
  12858. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12859. $prop['borderStyle'] = 'inset';
  12860. // get annotation data
  12861. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12862. // set additional default options
  12863. $font = 'zapfdingbats';
  12864. if ($this->pdfa_mode) {
  12865. // all fonts must be embedded
  12866. $font = 'pdfa'.$font;
  12867. }
  12868. $this->AddFont($font);
  12869. $tmpfont = $this->getFontBuffer($font);
  12870. $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  12871. $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
  12872. $popt['da'] = $fontstyle;
  12873. // build appearance stream
  12874. $popt['ap'] = array();
  12875. $popt['ap']['n'] = array();
  12876. $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][110])) / 2) * $this->k);
  12877. $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k);
  12878. $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);
  12879. $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);
  12880. // merge options
  12881. $opt = array_merge($popt, $opt);
  12882. // set remaining annotation data
  12883. $opt['Subtype'] = 'Widget';
  12884. $opt['ft'] = 'Btn';
  12885. $opt['t'] = $name;
  12886. if (TCPDF_STATIC::empty_string($onvalue)) {
  12887. $onvalue = 'Yes';
  12888. }
  12889. $opt['opt'] = array($onvalue);
  12890. if ($checked) {
  12891. $opt['v'] = array('/Yes');
  12892. $opt['as'] = 'Yes';
  12893. } else {
  12894. $opt['v'] = array('/Off');
  12895. $opt['as'] = 'Off';
  12896. }
  12897. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  12898. if ($this->rtl) {
  12899. $this->x -= $w;
  12900. } else {
  12901. $this->x += $w;
  12902. }
  12903. }
  12904. /**
  12905. * Creates a button field
  12906. * @param $name (string) field name
  12907. * @param $w (int) width
  12908. * @param $h (int) height
  12909. * @param $caption (string) caption.
  12910. * @param $action (mixed) action triggered by pressing the button. Use a string to specify a javascript action. Use an array to specify a form action options as on section 12.7.5 of PDF32000_2008.
  12911. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12912. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12913. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12914. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12915. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12916. * @public
  12917. * @author Nicola Asuni
  12918. * @since 4.8.000 (2009-09-07)
  12919. */
  12920. public function Button($name, $w, $h, $caption, $action, $prop = array(), $opt = array(), $x = '', $y = '', $js = false)
  12921. {
  12922. if ($x === '') {
  12923. $x = $this->x;
  12924. }
  12925. if ($y === '') {
  12926. $y = $this->y;
  12927. }
  12928. // check page for no-write regions and adapt page margins if necessary
  12929. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12930. if ($js) {
  12931. $this->_addfield('button', $name, $this->x, $this->y, $w, $h, $prop);
  12932. $this->javascript .= 'f'.$name.".buttonSetCaption('".addslashes($caption)."');\n";
  12933. $this->javascript .= 'f'.$name.".setAction('MouseUp','".addslashes($action)."');\n";
  12934. $this->javascript .= 'f'.$name.".highlight='push';\n";
  12935. $this->javascript .= 'f'.$name.".print=false;\n";
  12936. return;
  12937. }
  12938. // get default style
  12939. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12940. $prop['Pushbutton'] = 'true';
  12941. $prop['highlight'] = 'push';
  12942. $prop['display'] = 'display.noPrint';
  12943. // get annotation data
  12944. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12945. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12946. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12947. $popt['da'] = $fontstyle;
  12948. // build appearance stream
  12949. $popt['ap'] = array();
  12950. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12951. $tmpid = $this->startTemplate($w, $h, false);
  12952. $bw = (2 / $this->k); // border width
  12953. $border = array(
  12954. 'L' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
  12955. 'R' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)),
  12956. 'T' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
  12957. 'B' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)));
  12958. $this->SetFillColor(204);
  12959. $this->Cell($w, $h, $caption, $border, 0, 'C', true, '', 1, false, 'T', 'M');
  12960. $this->endTemplate();
  12961. --$this->n;
  12962. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12963. unset($this->xobjects[$tmpid]);
  12964. $popt['ap']['n'] .= 'Q EMC';
  12965. // set additional default options
  12966. if (!isset($popt['mk'])) {
  12967. $popt['mk'] = array();
  12968. }
  12969. $ann_obj_id = ($this->n + 1);
  12970. if (!empty($action) AND !is_array($action)) {
  12971. $ann_obj_id = ($this->n + 2);
  12972. }
  12973. $popt['mk']['ca'] = $this->_textstring($caption, $ann_obj_id);
  12974. $popt['mk']['rc'] = $this->_textstring($caption, $ann_obj_id);
  12975. $popt['mk']['ac'] = $this->_textstring($caption, $ann_obj_id);
  12976. // merge options
  12977. $opt = array_merge($popt, $opt);
  12978. // set remaining annotation data
  12979. $opt['Subtype'] = 'Widget';
  12980. $opt['ft'] = 'Btn';
  12981. $opt['t'] = $caption;
  12982. $opt['v'] = $name;
  12983. if (!empty($action)) {
  12984. if (is_array($action)) {
  12985. // form action options as on section 12.7.5 of PDF32000_2008.
  12986. $opt['aa'] = '/D <<';
  12987. $bmode = array('SubmitForm', 'ResetForm', 'ImportData');
  12988. foreach ($action AS $key => $val) {
  12989. if (($key == 'S') AND in_array($val, $bmode)) {
  12990. $opt['aa'] .= ' /S /'.$val;
  12991. } elseif (($key == 'F') AND (!empty($val))) {
  12992. $opt['aa'] .= ' /F '.$this->_datastring($val, $ann_obj_id);
  12993. } elseif (($key == 'Fields') AND is_array($val) AND !empty($val)) {
  12994. $opt['aa'] .= ' /Fields [';
  12995. foreach ($val AS $field) {
  12996. $opt['aa'] .= ' '.$this->_textstring($field, $ann_obj_id);
  12997. }
  12998. $opt['aa'] .= ']';
  12999. } elseif (($key == 'Flags')) {
  13000. $ff = 0;
  13001. if (is_array($val)) {
  13002. foreach ($val AS $flag) {
  13003. switch ($flag) {
  13004. case 'Include/Exclude': {
  13005. $ff += 1 << 0;
  13006. break;
  13007. }
  13008. case 'IncludeNoValueFields': {
  13009. $ff += 1 << 1;
  13010. break;
  13011. }
  13012. case 'ExportFormat': {
  13013. $ff += 1 << 2;
  13014. break;
  13015. }
  13016. case 'GetMethod': {
  13017. $ff += 1 << 3;
  13018. break;
  13019. }
  13020. case 'SubmitCoordinates': {
  13021. $ff += 1 << 4;
  13022. break;
  13023. }
  13024. case 'XFDF': {
  13025. $ff += 1 << 5;
  13026. break;
  13027. }
  13028. case 'IncludeAppendSaves': {
  13029. $ff += 1 << 6;
  13030. break;
  13031. }
  13032. case 'IncludeAnnotations': {
  13033. $ff += 1 << 7;
  13034. break;
  13035. }
  13036. case 'SubmitPDF': {
  13037. $ff += 1 << 8;
  13038. break;
  13039. }
  13040. case 'CanonicalFormat': {
  13041. $ff += 1 << 9;
  13042. break;
  13043. }
  13044. case 'ExclNonUserAnnots': {
  13045. $ff += 1 << 10;
  13046. break;
  13047. }
  13048. case 'ExclFKey': {
  13049. $ff += 1 << 11;
  13050. break;
  13051. }
  13052. case 'EmbedForm': {
  13053. $ff += 1 << 13;
  13054. break;
  13055. }
  13056. }
  13057. }
  13058. } else {
  13059. $ff = intval($val);
  13060. }
  13061. $opt['aa'] .= ' /Flags '.$ff;
  13062. }
  13063. }
  13064. $opt['aa'] .= ' >>';
  13065. } else {
  13066. // Javascript action or raw action command
  13067. $js_obj_id = $this->addJavascriptObject($action);
  13068. $opt['aa'] = '/D '.$js_obj_id.' 0 R';
  13069. }
  13070. }
  13071. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  13072. if ($this->rtl) {
  13073. $this->x -= $w;
  13074. } else {
  13075. $this->x += $w;
  13076. }
  13077. }
  13078. // --- END FORMS FIELDS ------------------------------------------------
  13079. /**
  13080. * Add certification signature (DocMDP or UR3)
  13081. * You can set only one signature type
  13082. * @protected
  13083. * @author Nicola Asuni
  13084. * @since 4.6.008 (2009-05-07)
  13085. */
  13086. protected function _putsignature()
  13087. {
  13088. if ((!$this->sign) OR (!isset($this->signature_data['cert_type']))) {
  13089. return;
  13090. }
  13091. $sigobjid = ($this->sig_obj_id + 1);
  13092. $out = $this->_getobj($sigobjid)."\n";
  13093. $out .= '<< /Type /Sig';
  13094. $out .= ' /Filter /Adobe.PPKLite';
  13095. $out .= ' /SubFilter /adbe.pkcs7.detached';
  13096. $out .= ' '.TCPDF_STATIC::$byterange_string;
  13097. $out .= ' /Contents<'.str_repeat('0', $this->signature_max_length).'>';
  13098. if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) {
  13099. $out .= ' /Reference ['; // array of signature reference dictionaries
  13100. $out .= ' << /Type /SigRef';
  13101. if ($this->signature_data['cert_type'] > 0) {
  13102. $out .= ' /TransformMethod /DocMDP';
  13103. $out .= ' /TransformParams <<';
  13104. $out .= ' /Type /TransformParams';
  13105. $out .= ' /P '.$this->signature_data['cert_type'];
  13106. $out .= ' /V /1.2';
  13107. } else {
  13108. $out .= ' /TransformMethod /UR3';
  13109. $out .= ' /TransformParams <<';
  13110. $out .= ' /Type /TransformParams';
  13111. $out .= ' /V /2.2';
  13112. if (!TCPDF_STATIC::empty_string($this->ur['document'])) {
  13113. $out .= ' /Document['.$this->ur['document'].']';
  13114. }
  13115. if (!TCPDF_STATIC::empty_string($this->ur['form'])) {
  13116. $out .= ' /Form['.$this->ur['form'].']';
  13117. }
  13118. if (!TCPDF_STATIC::empty_string($this->ur['signature'])) {
  13119. $out .= ' /Signature['.$this->ur['signature'].']';
  13120. }
  13121. if (!TCPDF_STATIC::empty_string($this->ur['annots'])) {
  13122. $out .= ' /Annots['.$this->ur['annots'].']';
  13123. }
  13124. if (!TCPDF_STATIC::empty_string($this->ur['ef'])) {
  13125. $out .= ' /EF['.$this->ur['ef'].']';
  13126. }
  13127. if (!TCPDF_STATIC::empty_string($this->ur['formex'])) {
  13128. $out .= ' /FormEX['.$this->ur['formex'].']';
  13129. }
  13130. }
  13131. $out .= ' >>'; // close TransformParams
  13132. // optional digest data (values must be calculated and replaced later)
  13133. //$out .= ' /Data ********** 0 R';
  13134. //$out .= ' /DigestMethod/MD5';
  13135. //$out .= ' /DigestLocation[********** 34]';
  13136. //$out .= ' /DigestValue<********************************>';
  13137. $out .= ' >>';
  13138. $out .= ' ]'; // end of reference
  13139. }
  13140. if (isset($this->signature_data['info']['Name']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Name'])) {
  13141. $out .= ' /Name '.$this->_textstring($this->signature_data['info']['Name'], $sigobjid);
  13142. }
  13143. if (isset($this->signature_data['info']['Location']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Location'])) {
  13144. $out .= ' /Location '.$this->_textstring($this->signature_data['info']['Location'], $sigobjid);
  13145. }
  13146. if (isset($this->signature_data['info']['Reason']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Reason'])) {
  13147. $out .= ' /Reason '.$this->_textstring($this->signature_data['info']['Reason'], $sigobjid);
  13148. }
  13149. if (isset($this->signature_data['info']['ContactInfo']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['ContactInfo'])) {
  13150. $out .= ' /ContactInfo '.$this->_textstring($this->signature_data['info']['ContactInfo'], $sigobjid);
  13151. }
  13152. $out .= ' /M '.$this->_datestring($sigobjid, $this->doc_modification_timestamp);
  13153. $out .= ' >>';
  13154. $out .= "\n".'endobj';
  13155. $this->_out($out);
  13156. }
  13157. /**
  13158. * Set User's Rights for PDF Reader
  13159. * WARNING: This is experimental and currently do not work.
  13160. * Check the PDF Reference 8.7.1 Transform Methods,
  13161. * Table 8.105 Entries in the UR transform parameters dictionary
  13162. * @param $enable (boolean) if true enable user's rights on PDF reader
  13163. * @param $document (string) Names specifying additional document-wide usage rights for the document. The only defined value is "/FullSave", which permits a user to save the document along with modified form and/or annotation data.
  13164. * @param $annots (string) Names specifying additional annotation-related usage rights for the document. Valid names in PDF 1.5 and later are /Create/Delete/Modify/Copy/Import/Export, which permit the user to perform the named operation on annotations.
  13165. * @param $form (string) Names specifying additional form-field-related usage rights for the document. Valid names are: /Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate
  13166. * @param $signature (string) Names specifying additional signature-related usage rights for the document. The only defined value is /Modify, which permits a user to apply a digital signature to an existing signature form field or clear a signed signature form field.
  13167. * @param $ef (string) Names specifying additional usage rights for named embedded files in the document. Valid names are /Create/Delete/Modify/Import, which permit the user to perform the named operation on named embedded files
  13168. Names specifying additional embedded-files-related usage rights for the document.
  13169. * @param $formex (string) Names specifying additional form-field-related usage rights. The only valid name is BarcodePlaintext, which permits text form field data to be encoded as a plaintext two-dimensional barcode.
  13170. * @public
  13171. * @author Nicola Asuni
  13172. * @since 2.9.000 (2008-03-26)
  13173. */
  13174. public function setUserRights(
  13175. $enable = true,
  13176. $document = '/FullSave',
  13177. $annots = '/Create/Delete/Modify/Copy/Import/Export',
  13178. $form = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate',
  13179. $signature = '/Modify',
  13180. $ef = '/Create/Delete/Modify/Import',
  13181. $formex = ''
  13182. ) {
  13183. $this->ur['enabled'] = $enable;
  13184. $this->ur['document'] = $document;
  13185. $this->ur['annots'] = $annots;
  13186. $this->ur['form'] = $form;
  13187. $this->ur['signature'] = $signature;
  13188. $this->ur['ef'] = $ef;
  13189. $this->ur['formex'] = $formex;
  13190. if (!$this->sign) {
  13191. $this->setSignature('', '', '', '', 0, array());
  13192. }
  13193. }
  13194. /**
  13195. * Enable document signature (requires the OpenSSL Library).
  13196. * The digital signature improve document authenticity and integrity and allows o enable extra features on Acrobat Reader.
  13197. * To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  13198. * To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  13199. * To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
  13200. * @param $signing_cert (mixed) signing certificate (string or filename prefixed with 'file://')
  13201. * @param $private_key (mixed) private key (string or filename prefixed with 'file://')
  13202. * @param $private_key_password (string) password
  13203. * @param $extracerts (string) specifies the name of a file containing a bunch of extra certificates to include in the signature which can for example be used to help the recipient to verify the certificate that you used.
  13204. * @param $cert_type (int) The access permissions granted for this document. Valid values shall be: 1 = No changes to the document shall be permitted; any change to the document shall invalidate the signature; 2 = Permitted changes shall be filling in forms, instantiating page templates, and signing; other changes shall invalidate the signature; 3 = Permitted changes shall be the same as for 2, as well as annotation creation, deletion, and modification; other changes shall invalidate the signature.
  13205. * @param $info (array) array of option information: Name, Location, Reason, ContactInfo.
  13206. * @param $approval (string) Enable approval signature eg. for PDF incremental update
  13207. * @public
  13208. * @author Nicola Asuni
  13209. * @since 4.6.005 (2009-04-24)
  13210. */
  13211. public function setSignature($signing_cert = '', $private_key = '', $private_key_password = '', $extracerts = '', $cert_type = 2, $info = array(), $approval = '')
  13212. {
  13213. // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  13214. // to export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  13215. // to convert pfx certificate to pem: openssl
  13216. // OpenSSL> pkcs12 -in <cert.pfx> -out <cert.crt> -nodes
  13217. $this->sign = true;
  13218. ++$this->n;
  13219. $this->sig_obj_id = $this->n; // signature widget
  13220. ++$this->n; // signature object ($this->sig_obj_id + 1)
  13221. $this->signature_data = array();
  13222. if (strlen($signing_cert) == 0) {
  13223. $this->Error('Please provide a certificate file and password!');
  13224. }
  13225. if (strlen($private_key) == 0) {
  13226. $private_key = $signing_cert;
  13227. }
  13228. $this->signature_data['signcert'] = $signing_cert;
  13229. $this->signature_data['privkey'] = $private_key;
  13230. $this->signature_data['password'] = $private_key_password;
  13231. $this->signature_data['extracerts'] = $extracerts;
  13232. $this->signature_data['cert_type'] = $cert_type;
  13233. $this->signature_data['info'] = $info;
  13234. $this->signature_data['approval'] = $approval;
  13235. }
  13236. /**
  13237. * Set the digital signature appearance (a cliccable rectangle area to get signature properties)
  13238. * @param $x (float) Abscissa of the upper-left corner.
  13239. * @param $y (float) Ordinate of the upper-left corner.
  13240. * @param $w (float) Width of the signature area.
  13241. * @param $h (float) Height of the signature area.
  13242. * @param $page (int) option page number (if < 0 the current page is used).
  13243. * @param $name (string) Name of the signature.
  13244. * @public
  13245. * @author Nicola Asuni
  13246. * @since 5.3.011 (2010-06-17)
  13247. */
  13248. public function setSignatureAppearance($x = 0, $y = 0, $w = 0, $h = 0, $page = -1, $name = '')
  13249. {
  13250. $this->signature_appearance = $this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name);
  13251. }
  13252. /**
  13253. * Add an empty digital signature appearance (a cliccable rectangle area to get signature properties)
  13254. * @param $x (float) Abscissa of the upper-left corner.
  13255. * @param $y (float) Ordinate of the upper-left corner.
  13256. * @param $w (float) Width of the signature area.
  13257. * @param $h (float) Height of the signature area.
  13258. * @param $page (int) option page number (if < 0 the current page is used).
  13259. * @param $name (string) Name of the signature.
  13260. * @public
  13261. * @author Nicola Asuni
  13262. * @since 5.9.101 (2011-07-06)
  13263. */
  13264. public function addEmptySignatureAppearance($x = 0, $y = 0, $w = 0, $h = 0, $page = -1, $name = '')
  13265. {
  13266. ++$this->n;
  13267. $this->empty_signature_appearance[] = array('objid' => $this->n) + $this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name);
  13268. }
  13269. /**
  13270. * Get the array that defines the signature appearance (page and rectangle coordinates).
  13271. * @param $x (float) Abscissa of the upper-left corner.
  13272. * @param $y (float) Ordinate of the upper-left corner.
  13273. * @param $w (float) Width of the signature area.
  13274. * @param $h (float) Height of the signature area.
  13275. * @param $page (int) option page number (if < 0 the current page is used).
  13276. * @param $name (string) Name of the signature.
  13277. * @return (array) Array defining page and rectangle coordinates of signature appearance.
  13278. * @protected
  13279. * @author Nicola Asuni
  13280. * @since 5.9.101 (2011-07-06)
  13281. */
  13282. protected function getSignatureAppearanceArray($x = 0, $y = 0, $w = 0, $h = 0, $page = -1, $name = '')
  13283. {
  13284. $sigapp = array();
  13285. if (($page < 1) OR ($page > $this->numpages)) {
  13286. $sigapp['page'] = $this->page;
  13287. } else {
  13288. $sigapp['page'] = intval($page);
  13289. }
  13290. if (empty($name)) {
  13291. $sigapp['name'] = 'Signature';
  13292. } else {
  13293. $sigapp['name'] = $name;
  13294. }
  13295. $a = $x * $this->k;
  13296. $b = $this->pagedim[($sigapp['page'])]['h'] - (($y + $h) * $this->k);
  13297. $c = $w * $this->k;
  13298. $d = $h * $this->k;
  13299. $sigapp['rect'] = sprintf('%F %F %F %F', $a, $b, ($a + $c), ($b + $d));
  13300. return $sigapp;
  13301. }
  13302. /**
  13303. * Enable document timestamping (requires the OpenSSL Library).
  13304. * The trusted timestamping improve document security that means that no one should be able to change the document once it has been recorded.
  13305. * Use with digital signature only!
  13306. * @param $tsa_host (string) Time Stamping Authority (TSA) server (prefixed with 'https://')
  13307. * @param $tsa_username (string) Specifies the username for TSA authorization (optional) OR specifies the TSA authorization PEM file (see: example_66.php, optional)
  13308. * @param $tsa_password (string) Specifies the password for TSA authorization (optional)
  13309. * @param $tsa_cert (string) Specifies the location of TSA certificate for authorization (optional for cURL)
  13310. * @public
  13311. * @author Richard Stockinger
  13312. * @since 6.0.090 (2014-06-16)
  13313. */
  13314. public function setTimeStamp($tsa_host = '', $tsa_username = '', $tsa_password = '', $tsa_cert = '')
  13315. {
  13316. $this->tsa_data = array();
  13317. if (!function_exists('curl_init')) {
  13318. $this->Error('Please enable cURL PHP extension!');
  13319. }
  13320. if (strlen($tsa_host) == 0) {
  13321. $this->Error('Please specify the host of Time Stamping Authority (TSA)!');
  13322. }
  13323. $this->tsa_data['tsa_host'] = $tsa_host;
  13324. if (is_file($tsa_username)) {
  13325. $this->tsa_data['tsa_auth'] = $tsa_username;
  13326. } else {
  13327. $this->tsa_data['tsa_username'] = $tsa_username;
  13328. }
  13329. $this->tsa_data['tsa_password'] = $tsa_password;
  13330. $this->tsa_data['tsa_cert'] = $tsa_cert;
  13331. $this->tsa_timestamp = true;
  13332. }
  13333. /**
  13334. * NOT YET IMPLEMENTED
  13335. * Request TSA for a timestamp
  13336. * @param $signature (string) Digital signature as binary string
  13337. * @return (string) Timestamped digital signature
  13338. * @protected
  13339. * @author Richard Stockinger
  13340. * @since 6.0.090 (2014-06-16)
  13341. */
  13342. protected function applyTSA($signature)
  13343. {
  13344. if (!$this->tsa_timestamp) {
  13345. return $signature;
  13346. }
  13347. //@TODO: implement this feature
  13348. return $signature;
  13349. }
  13350. /**
  13351. * Create a new page group.
  13352. * NOTE: call this function before calling AddPage()
  13353. * @param $page (int) starting group page (leave empty for next page).
  13354. * @public
  13355. * @since 3.0.000 (2008-03-27)
  13356. */
  13357. public function startPageGroup($page = '')
  13358. {
  13359. if (empty($page)) {
  13360. $page = $this->page + 1;
  13361. }
  13362. $this->newpagegroup[$page] = sizeof($this->newpagegroup) + 1;
  13363. }
  13364. /**
  13365. * Set the starting page number.
  13366. * @param $num (int) Starting page number.
  13367. * @since 5.9.093 (2011-06-16)
  13368. * @public
  13369. */
  13370. public function setStartingPageNumber($num = 1)
  13371. {
  13372. $this->starting_page_number = max(0, intval($num));
  13373. }
  13374. /**
  13375. * Returns the string alias used right align page numbers.
  13376. * If the current font is unicode type, the returned string wil contain an additional open curly brace.
  13377. * @return string
  13378. * @since 5.9.099 (2011-06-27)
  13379. * @public
  13380. */
  13381. public function getAliasRightShift()
  13382. {
  13383. // calculate aproximatively the ratio between widths of aliases and replacements.
  13384. $ref = '{'.TCPDF_STATIC::$alias_right_shift.'}{'.TCPDF_STATIC::$alias_tot_pages.'}{'.TCPDF_STATIC::$alias_num_page.'}';
  13385. $rep = str_repeat(' ', $this->GetNumChars($ref));
  13386. $wrep = $this->GetStringWidth($rep);
  13387. if ($wrep > 0) {
  13388. $wdiff = max(1, ($this->GetStringWidth($ref) / $wrep));
  13389. } else {
  13390. $wdiff = 1;
  13391. }
  13392. $sdiff = sprintf('%F', $wdiff);
  13393. $alias = TCPDF_STATIC::$alias_right_shift.$sdiff.'}';
  13394. if ($this->isUnicodeFont()) {
  13395. $alias = '{'.$alias;
  13396. }
  13397. return $alias;
  13398. }
  13399. /**
  13400. * Returns the string alias used for the total number of pages.
  13401. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13402. * This alias will be replaced by the total number of pages in the document.
  13403. * @return string
  13404. * @since 4.0.018 (2008-08-08)
  13405. * @public
  13406. */
  13407. public function getAliasNbPages()
  13408. {
  13409. if ($this->isUnicodeFont()) {
  13410. return '{'.TCPDF_STATIC::$alias_tot_pages.'}';
  13411. }
  13412. return TCPDF_STATIC::$alias_tot_pages;
  13413. }
  13414. /**
  13415. * Returns the string alias used for the page number.
  13416. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13417. * This alias will be replaced by the page number.
  13418. * @return string
  13419. * @since 4.5.000 (2009-01-02)
  13420. * @public
  13421. */
  13422. public function getAliasNumPage()
  13423. {
  13424. if ($this->isUnicodeFont()) {
  13425. return '{'.TCPDF_STATIC::$alias_num_page.'}';
  13426. }
  13427. return TCPDF_STATIC::$alias_num_page;
  13428. }
  13429. /**
  13430. * Return the alias for the total number of pages in the current page group.
  13431. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13432. * This alias will be replaced by the total number of pages in this group.
  13433. * @return alias of the current page group
  13434. * @public
  13435. * @since 3.0.000 (2008-03-27)
  13436. */
  13437. public function getPageGroupAlias()
  13438. {
  13439. if ($this->isUnicodeFont()) {
  13440. return '{'.TCPDF_STATIC::$alias_group_tot_pages.'}';
  13441. }
  13442. return TCPDF_STATIC::$alias_group_tot_pages;
  13443. }
  13444. /**
  13445. * Return the alias for the page number on the current page group.
  13446. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13447. * This alias will be replaced by the page number (relative to the belonging group).
  13448. * @return alias of the current page group
  13449. * @public
  13450. * @since 4.5.000 (2009-01-02)
  13451. */
  13452. public function getPageNumGroupAlias()
  13453. {
  13454. if ($this->isUnicodeFont()) {
  13455. return '{'.TCPDF_STATIC::$alias_group_num_page.'}';
  13456. }
  13457. return TCPDF_STATIC::$alias_group_num_page;
  13458. }
  13459. /**
  13460. * Return the current page in the group.
  13461. * @return current page in the group
  13462. * @public
  13463. * @since 3.0.000 (2008-03-27)
  13464. */
  13465. public function getGroupPageNo()
  13466. {
  13467. return $this->pagegroups[$this->currpagegroup];
  13468. }
  13469. /**
  13470. * Returns the current group page number formatted as a string.
  13471. * @public
  13472. * @since 4.3.003 (2008-11-18)
  13473. * @see PaneNo(), formatPageNumber()
  13474. */
  13475. public function getGroupPageNoFormatted()
  13476. {
  13477. return TCPDF_STATIC::formatPageNumber($this->getGroupPageNo());
  13478. }
  13479. /**
  13480. * Returns the current page number formatted as a string.
  13481. * @public
  13482. * @since 4.2.005 (2008-11-06)
  13483. * @see PaneNo(), formatPageNumber()
  13484. */
  13485. public function PageNoFormatted()
  13486. {
  13487. return TCPDF_STATIC::formatPageNumber($this->PageNo());
  13488. }
  13489. /**
  13490. * Put pdf layers.
  13491. * @protected
  13492. * @since 3.0.000 (2008-03-27)
  13493. */
  13494. protected function _putocg()
  13495. {
  13496. if (empty($this->pdflayers)) {
  13497. return;
  13498. }
  13499. foreach ($this->pdflayers as $key => $layer) {
  13500. $this->pdflayers[$key]['objid'] = $this->_newobj();
  13501. $out = '<< /Type /OCG';
  13502. $out .= ' /Name '.$this->_textstring($layer['name'], $this->pdflayers[$key]['objid']);
  13503. $out .= ' /Usage <<';
  13504. if (isset($layer['print']) AND ($layer['print'] !== null)) {
  13505. $out .= ' /Print <</PrintState /'.($layer['print']?'ON':'OFF').'>>';
  13506. }
  13507. $out .= ' /View <</ViewState /'.($layer['view']?'ON':'OFF').'>>';
  13508. $out .= ' >> >>';
  13509. $out .= "\n".'endobj';
  13510. $this->_out($out);
  13511. }
  13512. }
  13513. /**
  13514. * Start a new pdf layer.
  13515. * @param $name (string) Layer name (only a-z letters and numbers). Leave empty for automatic name.
  13516. * @param $print (boolean|null) Set to TRUE to print this layer, FALSE to not print and NULL to not set this option
  13517. * @param $view (boolean) Set to true to view this layer.
  13518. * @param $lock (boolean) If true lock the layer
  13519. * @public
  13520. * @since 5.9.102 (2011-07-13)
  13521. */
  13522. public function startLayer($name = '', $print = true, $view = true, $lock = true)
  13523. {
  13524. if ($this->state != 2) {
  13525. return;
  13526. }
  13527. $layer = sprintf('LYR%03d', (count($this->pdflayers) + 1));
  13528. if (empty($name)) {
  13529. $name = $layer;
  13530. } else {
  13531. $name = preg_replace('/[^a-zA-Z0-9_\-]/', '', $name);
  13532. }
  13533. $this->pdflayers[] = array('layer' => $layer, 'name' => $name, 'print' => $print, 'view' => $view, 'lock' => $lock);
  13534. $this->openMarkedContent = true;
  13535. $this->_out('/OC /'.$layer.' BDC');
  13536. }
  13537. /**
  13538. * End the current PDF layer.
  13539. * @public
  13540. * @since 5.9.102 (2011-07-13)
  13541. */
  13542. public function endLayer()
  13543. {
  13544. if ($this->state != 2) {
  13545. return;
  13546. }
  13547. if ($this->openMarkedContent) {
  13548. // close existing open marked-content layer
  13549. $this->_out('EMC');
  13550. $this->openMarkedContent = false;
  13551. }
  13552. }
  13553. /**
  13554. * Set the visibility of the successive elements.
  13555. * This can be useful, for instance, to put a background
  13556. * image or color that will show on screen but won't print.
  13557. * @param $v (string) visibility mode. Legal values are: all, print, screen or view.
  13558. * @public
  13559. * @since 3.0.000 (2008-03-27)
  13560. */
  13561. public function setVisibility($v)
  13562. {
  13563. if ($this->state != 2) {
  13564. return;
  13565. }
  13566. $this->endLayer();
  13567. switch ($v) {
  13568. case 'print': {
  13569. $this->startLayer('Print', true, false);
  13570. break;
  13571. }
  13572. case 'view':
  13573. case 'screen': {
  13574. $this->startLayer('View', false, true);
  13575. break;
  13576. }
  13577. case 'all': {
  13578. $this->_out('');
  13579. break;
  13580. }
  13581. default: {
  13582. $this->Error('Incorrect visibility: '.$v);
  13583. break;
  13584. }
  13585. }
  13586. }
  13587. /**
  13588. * Add transparency parameters to the current extgstate
  13589. * @param $parms (array) parameters
  13590. * @return the number of extgstates
  13591. * @protected
  13592. * @since 3.0.000 (2008-03-27)
  13593. */
  13594. protected function addExtGState($parms)
  13595. {
  13596. if ($this->pdfa_mode) {
  13597. // transparencies are not allowed in PDF/A mode
  13598. return;
  13599. }
  13600. // check if this ExtGState already exist
  13601. foreach ($this->extgstates as $i => $ext) {
  13602. if ($ext['parms'] == $parms) {
  13603. if ($this->inxobj) {
  13604. // we are inside an XObject template
  13605. $this->xobjects[$this->xobjid]['extgstates'][$i] = $ext;
  13606. }
  13607. // return reference to existing ExtGState
  13608. return $i;
  13609. }
  13610. }
  13611. $n = (count($this->extgstates) + 1);
  13612. $this->extgstates[$n] = array('parms' => $parms);
  13613. if ($this->inxobj) {
  13614. // we are inside an XObject template
  13615. $this->xobjects[$this->xobjid]['extgstates'][$n] = $this->extgstates[$n];
  13616. }
  13617. return $n;
  13618. }
  13619. /**
  13620. * Add an extgstate
  13621. * @param $gs (array) extgstate
  13622. * @protected
  13623. * @since 3.0.000 (2008-03-27)
  13624. */
  13625. protected function setExtGState($gs)
  13626. {
  13627. if ($this->pdfa_mode OR ($this->state != 2)) {
  13628. // transparency is not allowed in PDF/A mode
  13629. return;
  13630. }
  13631. $this->_out(sprintf('/GS%d gs', $gs));
  13632. }
  13633. /**
  13634. * Put extgstates for object transparency
  13635. * @protected
  13636. * @since 3.0.000 (2008-03-27)
  13637. */
  13638. protected function _putextgstates()
  13639. {
  13640. foreach ($this->extgstates as $i => $ext) {
  13641. $this->extgstates[$i]['n'] = $this->_newobj();
  13642. $out = '<< /Type /ExtGState';
  13643. foreach ($ext['parms'] as $k => $v) {
  13644. if (is_float($v)) {
  13645. $v = sprintf('%F', $v);
  13646. } elseif ($v === true) {
  13647. $v = 'true';
  13648. } elseif ($v === false) {
  13649. $v = 'false';
  13650. }
  13651. $out .= ' /'.$k.' '.$v;
  13652. }
  13653. $out .= ' >>';
  13654. $out .= "\n".'endobj';
  13655. $this->_out($out);
  13656. }
  13657. }
  13658. /**
  13659. * Set overprint mode for stroking (OP) and non-stroking (op) painting operations.
  13660. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13661. * @param $stroking (boolean) If true apply overprint for stroking operations.
  13662. * @param $nonstroking (boolean) If true apply overprint for painting operations other than stroking.
  13663. * @param $mode (integer) Overprint mode: (0 = each source colour component value replaces the value previously painted for the corresponding device colorant; 1 = a tint value of 0.0 for a source colour component shall leave the corresponding component of the previously painted colour unchanged).
  13664. * @public
  13665. * @since 5.9.152 (2012-03-23)
  13666. */
  13667. public function setOverprint($stroking = true, $nonstroking = '', $mode = 0)
  13668. {
  13669. if ($this->state != 2) {
  13670. return;
  13671. }
  13672. $stroking = $stroking ? true : false;
  13673. if (TCPDF_STATIC::empty_string($nonstroking)) {
  13674. // default value if not set
  13675. $nonstroking = $stroking;
  13676. } else {
  13677. $nonstroking = $nonstroking ? true : false;
  13678. }
  13679. if (($mode != 0) AND ($mode != 1)) {
  13680. $mode = 0;
  13681. }
  13682. $this->overprint = array('OP' => $stroking, 'op' => $nonstroking, 'OPM' => $mode);
  13683. $gs = $this->addExtGState($this->overprint);
  13684. $this->setExtGState($gs);
  13685. }
  13686. /**
  13687. * Get the overprint mode array (OP, op, OPM).
  13688. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13689. * @return array.
  13690. * @public
  13691. * @since 5.9.152 (2012-03-23)
  13692. */
  13693. public function getOverprint()
  13694. {
  13695. return $this->overprint;
  13696. }
  13697. /**
  13698. * Set alpha for stroking (CA) and non-stroking (ca) operations.
  13699. * @param $stroking (float) Alpha value for stroking operations: real value from 0 (transparent) to 1 (opaque).
  13700. * @param $bm (string) blend mode, one of the following: Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity
  13701. * @param $nonstroking (float) Alpha value for non-stroking operations: real value from 0 (transparent) to 1 (opaque).
  13702. * @param $ais (boolean)
  13703. * @public
  13704. * @since 3.0.000 (2008-03-27)
  13705. */
  13706. public function setAlpha($stroking = 1, $bm = 'Normal', $nonstroking = '', $ais = false)
  13707. {
  13708. if ($this->pdfa_mode) {
  13709. // transparency is not allowed in PDF/A mode
  13710. return;
  13711. }
  13712. $stroking = floatval($stroking);
  13713. if (TCPDF_STATIC::empty_string($nonstroking)) {
  13714. // default value if not set
  13715. $nonstroking = $stroking;
  13716. } else {
  13717. $nonstroking = floatval($nonstroking);
  13718. }
  13719. if ($bm[0] == '/') {
  13720. // remove trailing slash
  13721. $bm = substr($bm, 1);
  13722. }
  13723. if (!in_array($bm, array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge', 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion', 'Hue', 'Saturation', 'Color', 'Luminosity'))) {
  13724. $bm = 'Normal';
  13725. }
  13726. $ais = $ais ? true : false;
  13727. $this->alpha = array('CA' => $stroking, 'ca' => $nonstroking, 'BM' => '/'.$bm, 'AIS' => $ais);
  13728. $gs = $this->addExtGState($this->alpha);
  13729. $this->setExtGState($gs);
  13730. }
  13731. /**
  13732. * Get the alpha mode array (CA, ca, BM, AIS).
  13733. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13734. * @return array.
  13735. * @public
  13736. * @since 5.9.152 (2012-03-23)
  13737. */
  13738. public function getAlpha()
  13739. {
  13740. return $this->alpha;
  13741. }
  13742. /**
  13743. * Set the default JPEG compression quality (1-100)
  13744. * @param $quality (int) JPEG quality, integer between 1 and 100
  13745. * @public
  13746. * @since 3.0.000 (2008-03-27)
  13747. */
  13748. public function setJPEGQuality($quality)
  13749. {
  13750. if (($quality < 1) OR ($quality > 100)) {
  13751. $quality = 75;
  13752. }
  13753. $this->jpeg_quality = intval($quality);
  13754. }
  13755. /**
  13756. * Set the default number of columns in a row for HTML tables.
  13757. * @param $cols (int) number of columns
  13758. * @public
  13759. * @since 3.0.014 (2008-06-04)
  13760. */
  13761. public function setDefaultTableColumns($cols = 4)
  13762. {
  13763. $this->default_table_columns = intval($cols);
  13764. }
  13765. /**
  13766. * Set the height of the cell (line height) respect the font height.
  13767. * @param $h (int) cell proportion respect font height (typical value = 1.25).
  13768. * @public
  13769. * @since 3.0.014 (2008-06-04)
  13770. */
  13771. public function setCellHeightRatio($h)
  13772. {
  13773. $this->cell_height_ratio = $h;
  13774. }
  13775. /**
  13776. * return the height of cell repect font height.
  13777. * @public
  13778. * @since 4.0.012 (2008-07-24)
  13779. */
  13780. public function getCellHeightRatio()
  13781. {
  13782. return $this->cell_height_ratio;
  13783. }
  13784. /**
  13785. * Set the PDF version (check PDF reference for valid values).
  13786. * @param $version (string) PDF document version.
  13787. * @public
  13788. * @since 3.1.000 (2008-06-09)
  13789. */
  13790. public function setPDFVersion($version = '1.7')
  13791. {
  13792. if ($this->pdfa_mode && $this->pdfa_version == 1 ) {
  13793. // PDF/A mode
  13794. $this->PDFVersion = '1.4';
  13795. } else {
  13796. $this->PDFVersion = $version;
  13797. }
  13798. }
  13799. /**
  13800. * Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
  13801. * (see Section 8.1 of PDF reference, "Viewer Preferences").
  13802. * <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>
  13803. * @param $preferences (array) array of options.
  13804. * @author Nicola Asuni
  13805. * @public
  13806. * @since 3.1.000 (2008-06-09)
  13807. */
  13808. public function setViewerPreferences($preferences)
  13809. {
  13810. $this->viewer_preferences = $preferences;
  13811. }
  13812. /**
  13813. * Paints color transition registration bars
  13814. * @param $x (float) abscissa of the top left corner of the rectangle.
  13815. * @param $y (float) ordinate of the top left corner of the rectangle.
  13816. * @param $w (float) width of the rectangle.
  13817. * @param $h (float) height of the rectangle.
  13818. * @param $transition (boolean) if true prints tcolor transitions to white.
  13819. * @param $vertical (boolean) if true prints bar vertically.
  13820. * @param $colors (string) colors to print separated by comma. Valid values are: A,W,R,G,B,C,M,Y,K,RGB,CMYK,ALL,ALLSPOT,<SPOT_COLOR_NAME>. Where: A = grayscale black, W = grayscale white, R = RGB red, G RGB green, B RGB blue, C = CMYK cyan, M = CMYK magenta, Y = CMYK yellow, K = CMYK key/black, RGB = RGB registration color, CMYK = CMYK registration color, ALL = Spot registration color, ALLSPOT = print all defined spot colors, <SPOT_COLOR_NAME> = name of the spot color to print.
  13821. * @author Nicola Asuni
  13822. * @since 4.9.000 (2010-03-26)
  13823. * @public
  13824. */
  13825. public function colorRegistrationBar($x, $y, $w, $h, $transition = true, $vertical = false, $colors = 'A,R,G,B,C,M,Y,K')
  13826. {
  13827. if (strpos($colors, 'ALLSPOT') !== false) {
  13828. // expand spot colors
  13829. $spot_colors = '';
  13830. foreach ($this->spot_colors as $spot_color_name => $v) {
  13831. $spot_colors .= ','.$spot_color_name;
  13832. }
  13833. if (!empty($spot_colors)) {
  13834. $spot_colors = substr($spot_colors, 1);
  13835. $colors = str_replace('ALLSPOT', $spot_colors, $colors);
  13836. } else {
  13837. $colors = str_replace('ALLSPOT', 'NONE', $colors);
  13838. }
  13839. }
  13840. $bars = explode(',', $colors);
  13841. $numbars = count($bars); // number of bars to print
  13842. if ($numbars <= 0) {
  13843. return;
  13844. }
  13845. // set bar measures
  13846. if ($vertical) {
  13847. $coords = array(0, 0, 0, 1);
  13848. $wb = $w / $numbars; // bar width
  13849. $hb = $h; // bar height
  13850. $xd = $wb; // delta x
  13851. $yd = 0; // delta y
  13852. } else {
  13853. $coords = array(1, 0, 0, 0);
  13854. $wb = $w; // bar width
  13855. $hb = $h / $numbars; // bar height
  13856. $xd = 0; // delta x
  13857. $yd = $hb; // delta y
  13858. }
  13859. $xb = $x;
  13860. $yb = $y;
  13861. foreach ($bars as $col) {
  13862. switch ($col) {
  13863. // set transition colors
  13864. case 'A': { // BLACK (GRAYSCALE)
  13865. $col_a = array(255);
  13866. $col_b = array(0);
  13867. break;
  13868. }
  13869. case 'W': { // WHITE (GRAYSCALE)
  13870. $col_a = array(0);
  13871. $col_b = array(255);
  13872. break;
  13873. }
  13874. case 'R': { // RED (RGB)
  13875. $col_a = array(255,255,255);
  13876. $col_b = array(255,0,0);
  13877. break;
  13878. }
  13879. case 'G': { // GREEN (RGB)
  13880. $col_a = array(255,255,255);
  13881. $col_b = array(0,255,0);
  13882. break;
  13883. }
  13884. case 'B': { // BLUE (RGB)
  13885. $col_a = array(255,255,255);
  13886. $col_b = array(0,0,255);
  13887. break;
  13888. }
  13889. case 'C': { // CYAN (CMYK)
  13890. $col_a = array(0,0,0,0);
  13891. $col_b = array(100,0,0,0);
  13892. break;
  13893. }
  13894. case 'M': { // MAGENTA (CMYK)
  13895. $col_a = array(0,0,0,0);
  13896. $col_b = array(0,100,0,0);
  13897. break;
  13898. }
  13899. case 'Y': { // YELLOW (CMYK)
  13900. $col_a = array(0,0,0,0);
  13901. $col_b = array(0,0,100,0);
  13902. break;
  13903. }
  13904. case 'K': { // KEY - BLACK (CMYK)
  13905. $col_a = array(0,0,0,0);
  13906. $col_b = array(0,0,0,100);
  13907. break;
  13908. }
  13909. case 'RGB': { // BLACK REGISTRATION (RGB)
  13910. $col_a = array(255,255,255);
  13911. $col_b = array(0,0,0);
  13912. break;
  13913. }
  13914. case 'CMYK': { // BLACK REGISTRATION (CMYK)
  13915. $col_a = array(0,0,0,0);
  13916. $col_b = array(100,100,100,100);
  13917. break;
  13918. }
  13919. case 'ALL': { // SPOT COLOR REGISTRATION
  13920. $col_a = array(0,0,0,0,'None');
  13921. $col_b = array(100,100,100,100,'All');
  13922. break;
  13923. }
  13924. case 'NONE': { // SKIP THIS COLOR
  13925. $col_a = array(0,0,0,0,'None');
  13926. $col_b = array(0,0,0,0,'None');
  13927. break;
  13928. }
  13929. default: { // SPECIFIC SPOT COLOR NAME
  13930. $col_a = array(0,0,0,0,'None');
  13931. $col_b = TCPDF_COLORS::getSpotColor($col, $this->spot_colors);
  13932. if ($col_b === false) {
  13933. // in case of error defaults to the registration color
  13934. $col_b = array(100,100,100,100,'All');
  13935. }
  13936. break;
  13937. }
  13938. }
  13939. if ($col != 'NONE') {
  13940. if ($transition) {
  13941. // color gradient
  13942. $this->LinearGradient($xb, $yb, $wb, $hb, $col_a, $col_b, $coords);
  13943. } else {
  13944. $this->SetFillColorArray($col_b);
  13945. // colored rectangle
  13946. $this->Rect($xb, $yb, $wb, $hb, 'F', array());
  13947. }
  13948. $xb += $xd;
  13949. $yb += $yd;
  13950. }
  13951. }
  13952. }
  13953. /**
  13954. * Paints crop marks.
  13955. * @param $x (float) abscissa of the crop mark center.
  13956. * @param $y (float) ordinate of the crop mark center.
  13957. * @param $w (float) width of the crop mark.
  13958. * @param $h (float) height of the crop mark.
  13959. * @param $type (string) type of crop mark, one symbol per type separated by comma: T = TOP, F = BOTTOM, L = LEFT, R = RIGHT, TL = A = TOP-LEFT, TR = B = TOP-RIGHT, BL = C = BOTTOM-LEFT, BR = D = BOTTOM-RIGHT.
  13960. * @param $color (array) crop mark color (default spot registration color).
  13961. * @author Nicola Asuni
  13962. * @since 4.9.000 (2010-03-26)
  13963. * @public
  13964. */
  13965. public function cropMark($x, $y, $w, $h, $type = 'T,R,B,L', $color = array(100,100,100,100,'All'))
  13966. {
  13967. $this->SetLineStyle(array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $color));
  13968. $type = strtoupper($type);
  13969. $type = preg_replace('/[^A-Z\-\,]*/', '', $type);
  13970. // split type in single components
  13971. $type = str_replace('-', ',', $type);
  13972. $type = str_replace('TL', 'T,L', $type);
  13973. $type = str_replace('TR', 'T,R', $type);
  13974. $type = str_replace('BL', 'F,L', $type);
  13975. $type = str_replace('BR', 'F,R', $type);
  13976. $type = str_replace('A', 'T,L', $type);
  13977. $type = str_replace('B', 'T,R', $type);
  13978. $type = str_replace('T,RO', 'BO', $type);
  13979. $type = str_replace('C', 'F,L', $type);
  13980. $type = str_replace('D', 'F,R', $type);
  13981. $crops = explode(',', strtoupper($type));
  13982. // remove duplicates
  13983. $crops = array_unique($crops);
  13984. $dw = ($w / 4); // horizontal space to leave before the intersection point
  13985. $dh = ($h / 4); // vertical space to leave before the intersection point
  13986. foreach ($crops as $crop) {
  13987. switch ($crop) {
  13988. case 'T':
  13989. case 'TOP': {
  13990. $x1 = $x;
  13991. $y1 = ($y - $h);
  13992. $x2 = $x;
  13993. $y2 = ($y - $dh);
  13994. break;
  13995. }
  13996. case 'F':
  13997. case 'BOTTOM': {
  13998. $x1 = $x;
  13999. $y1 = ($y + $dh);
  14000. $x2 = $x;
  14001. $y2 = ($y + $h);
  14002. break;
  14003. }
  14004. case 'L':
  14005. case 'LEFT': {
  14006. $x1 = ($x - $w);
  14007. $y1 = $y;
  14008. $x2 = ($x - $dw);
  14009. $y2 = $y;
  14010. break;
  14011. }
  14012. case 'R':
  14013. case 'RIGHT': {
  14014. $x1 = ($x + $dw);
  14015. $y1 = $y;
  14016. $x2 = ($x + $w);
  14017. $y2 = $y;
  14018. break;
  14019. }
  14020. }
  14021. $this->Line($x1, $y1, $x2, $y2);
  14022. }
  14023. }
  14024. /**
  14025. * Paints a registration mark
  14026. * @param $x (float) abscissa of the registration mark center.
  14027. * @param $y (float) ordinate of the registration mark center.
  14028. * @param $r (float) radius of the crop mark.
  14029. * @param $double (boolean) if true print two concentric crop marks.
  14030. * @param $cola (array) crop mark color (default spot registration color 'All').
  14031. * @param $colb (array) second crop mark color (default spot registration color 'None').
  14032. * @author Nicola Asuni
  14033. * @since 4.9.000 (2010-03-26)
  14034. * @public
  14035. */
  14036. public function registrationMark($x, $y, $r, $double = false, $cola = array(100,100,100,100,'All'), $colb = array(0,0,0,0,'None'))
  14037. {
  14038. $line_style = array('width' => max((0.5 / $this->k), ($r / 30)), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $cola);
  14039. $this->SetFillColorArray($cola);
  14040. $this->PieSector($x, $y, $r, 90, 180, 'F');
  14041. $this->PieSector($x, $y, $r, 270, 360, 'F');
  14042. $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
  14043. if ($double) {
  14044. $ri = $r * 0.5;
  14045. $this->SetFillColorArray($colb);
  14046. $this->PieSector($x, $y, $ri, 90, 180, 'F');
  14047. $this->PieSector($x, $y, $ri, 270, 360, 'F');
  14048. $this->SetFillColorArray($cola);
  14049. $this->PieSector($x, $y, $ri, 0, 90, 'F');
  14050. $this->PieSector($x, $y, $ri, 180, 270, 'F');
  14051. $this->Circle($x, $y, $ri, 0, 360, 'C', $line_style, array(), 8);
  14052. }
  14053. }
  14054. /**
  14055. * Paints a CMYK registration mark
  14056. * @param $x (float) abscissa of the registration mark center.
  14057. * @param $y (float) ordinate of the registration mark center.
  14058. * @param $r (float) radius of the crop mark.
  14059. * @author Nicola Asuni
  14060. * @since 6.0.038 (2013-09-30)
  14061. * @public
  14062. */
  14063. public function registrationMarkCMYK($x, $y, $r)
  14064. {
  14065. // line width
  14066. $lw = max((0.5 / $this->k), ($r / 8));
  14067. // internal radius
  14068. $ri = ($r * 0.6);
  14069. // external radius
  14070. $re = ($r * 1.3);
  14071. // Cyan
  14072. $this->SetFillColorArray(array(100,0,0,0));
  14073. $this->PieSector($x, $y, $ri, 270, 360, 'F');
  14074. // Magenta
  14075. $this->SetFillColorArray(array(0,100,0,0));
  14076. $this->PieSector($x, $y, $ri, 0, 90, 'F');
  14077. // Yellow
  14078. $this->SetFillColorArray(array(0,0,100,0));
  14079. $this->PieSector($x, $y, $ri, 90, 180, 'F');
  14080. // Key - black
  14081. $this->SetFillColorArray(array(0,0,0,100));
  14082. $this->PieSector($x, $y, $ri, 180, 270, 'F');
  14083. // registration color
  14084. $line_style = array('width' => $lw, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(100,100,100,100,'All'));
  14085. $this->SetFillColorArray(array(100,100,100,100,'All'));
  14086. // external circle
  14087. $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
  14088. // cross lines
  14089. $this->Line($x, ($y - $re), $x, ($y - $ri));
  14090. $this->Line($x, ($y + $ri), $x, ($y + $re));
  14091. $this->Line(($x - $re), $y, ($x - $ri), $y);
  14092. $this->Line(($x + $ri), $y, ($x + $re), $y);
  14093. }
  14094. /**
  14095. * Paints a linear colour gradient.
  14096. * @param $x (float) abscissa of the top left corner of the rectangle.
  14097. * @param $y (float) ordinate of the top left corner of the rectangle.
  14098. * @param $w (float) width of the rectangle.
  14099. * @param $h (float) height of the rectangle.
  14100. * @param $col1 (array) first color (Grayscale, RGB or CMYK components).
  14101. * @param $col2 (array) second color (Grayscale, RGB or CMYK components).
  14102. * @param $coords (array) array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg). The default value is from left to right (x1=0, y1=0, x2=1, y2=0).
  14103. * @author Andreas W\FCrmser, Nicola Asuni
  14104. * @since 3.1.000 (2008-06-09)
  14105. * @public
  14106. */
  14107. public function LinearGradient($x, $y, $w, $h, $col1 = array(), $col2 = array(), $coords = array(0,0,1,0))
  14108. {
  14109. $this->Clip($x, $y, $w, $h);
  14110. $this->Gradient(2, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
  14111. }
  14112. /**
  14113. * Paints a radial colour gradient.
  14114. * @param $x (float) abscissa of the top left corner of the rectangle.
  14115. * @param $y (float) ordinate of the top left corner of the rectangle.
  14116. * @param $w (float) width of the rectangle.
  14117. * @param $h (float) height of the rectangle.
  14118. * @param $col1 (array) first color (Grayscale, RGB or CMYK components).
  14119. * @param $col2 (array) second color (Grayscale, RGB or CMYK components).
  14120. * @param $coords (array) array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1, (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg). (fx, fy) should be inside the circle, otherwise some areas will not be defined.
  14121. * @author Andreas W\FCrmser, Nicola Asuni
  14122. * @since 3.1.000 (2008-06-09)
  14123. * @public
  14124. */
  14125. public function RadialGradient($x, $y, $w, $h, $col1 = array(), $col2 = array(), $coords = array(0.5,0.5,0.5,0.5,1))
  14126. {
  14127. $this->Clip($x, $y, $w, $h);
  14128. $this->Gradient(3, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
  14129. }
  14130. /**
  14131. * Paints a coons patch mesh.
  14132. * @param $x (float) abscissa of the top left corner of the rectangle.
  14133. * @param $y (float) ordinate of the top left corner of the rectangle.
  14134. * @param $w (float) width of the rectangle.
  14135. * @param $h (float) height of the rectangle.
  14136. * @param $col1 (array) first color (lower left corner) (RGB components).
  14137. * @param $col2 (array) second color (lower right corner) (RGB components).
  14138. * @param $col3 (array) third color (upper right corner) (RGB components).
  14139. * @param $col4 (array) fourth color (upper left corner) (RGB components).
  14140. * @param $coords (array) <ul><li>for one patch mesh: array(float x1, float y1, .... float x12, float y12): 12 pairs of coordinates (normally from 0 to 1) which specify the Bezier control points that define the patch. First pair is the lower left edge point, next is its right control point (control point 2). Then the other points are defined in the order: control point 1, edge point, control point 2 going counter-clockwise around the patch. Last (x12, y12) is the first edge point's left control point (control point 1).</li><li>for two or more patch meshes: array[number of patches]: arrays with the following keys for each patch: f: where to put that patch (0 = first patch, 1, 2, 3 = right, top and left of precedent patch - I didn't figure this out completely - just try and error ;-) points: 12 pairs of coordinates of the Bezier control points as above for the first patch, 8 pairs of coordinates for the following patches, ignoring the coordinates already defined by the precedent patch (I also didn't figure out the order of these - also: try and see what's happening) colors: must be 4 colors for the first patch, 2 colors for the following patches</li></ul>
  14141. * @param $coords_min (array) minimum value used by the coordinates. If a coordinate's value is smaller than this it will be cut to coords_min. default: 0
  14142. * @param $coords_max (array) maximum value used by the coordinates. If a coordinate's value is greater than this it will be cut to coords_max. default: 1
  14143. * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  14144. * @author Andreas W\FCrmser, Nicola Asuni
  14145. * @since 3.1.000 (2008-06-09)
  14146. * @public
  14147. */
  14148. 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)
  14149. {
  14150. if ($this->pdfa_mode OR ($this->state != 2)) {
  14151. return;
  14152. }
  14153. $this->Clip($x, $y, $w, $h);
  14154. $n = count($this->gradients) + 1;
  14155. $this->gradients[$n] = array();
  14156. $this->gradients[$n]['type'] = 6; //coons patch mesh
  14157. $this->gradients[$n]['coords'] = array();
  14158. $this->gradients[$n]['antialias'] = $antialias;
  14159. $this->gradients[$n]['colors'] = array();
  14160. $this->gradients[$n]['transparency'] = false;
  14161. //check the coords array if it is the simple array or the multi patch array
  14162. if (!isset($coords[0]['f'])) {
  14163. //simple array -> convert to multi patch array
  14164. if (!isset($col1[1])) {
  14165. $col1[1] = $col1[2] = $col1[0];
  14166. }
  14167. if (!isset($col2[1])) {
  14168. $col2[1] = $col2[2] = $col2[0];
  14169. }
  14170. if (!isset($col3[1])) {
  14171. $col3[1] = $col3[2] = $col3[0];
  14172. }
  14173. if (!isset($col4[1])) {
  14174. $col4[1] = $col4[2] = $col4[0];
  14175. }
  14176. $patch_array[0]['f'] = 0;
  14177. $patch_array[0]['points'] = $coords;
  14178. $patch_array[0]['colors'][0]['r'] = $col1[0];
  14179. $patch_array[0]['colors'][0]['g'] = $col1[1];
  14180. $patch_array[0]['colors'][0]['b'] = $col1[2];
  14181. $patch_array[0]['colors'][1]['r'] = $col2[0];
  14182. $patch_array[0]['colors'][1]['g'] = $col2[1];
  14183. $patch_array[0]['colors'][1]['b'] = $col2[2];
  14184. $patch_array[0]['colors'][2]['r'] = $col3[0];
  14185. $patch_array[0]['colors'][2]['g'] = $col3[1];
  14186. $patch_array[0]['colors'][2]['b'] = $col3[2];
  14187. $patch_array[0]['colors'][3]['r'] = $col4[0];
  14188. $patch_array[0]['colors'][3]['g'] = $col4[1];
  14189. $patch_array[0]['colors'][3]['b'] = $col4[2];
  14190. } else {
  14191. //multi patch array
  14192. $patch_array = $coords;
  14193. }
  14194. $bpcd = 65535; //16 bits per coordinate
  14195. //build the data stream
  14196. $this->gradients[$n]['stream'] = '';
  14197. $count_patch = count($patch_array);
  14198. for ($i=0; $i < $count_patch; ++$i) {
  14199. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['f']); //start with the edge flag as 8 bit
  14200. $count_points = count($patch_array[$i]['points']);
  14201. for ($j=0; $j < $count_points; ++$j) {
  14202. //each point as 16 bit
  14203. $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $coords_min) / ($coords_max - $coords_min)) * $bpcd;
  14204. if ($patch_array[$i]['points'][$j] < 0) {
  14205. $patch_array[$i]['points'][$j] = 0;
  14206. }
  14207. if ($patch_array[$i]['points'][$j] > $bpcd) {
  14208. $patch_array[$i]['points'][$j] = $bpcd;
  14209. }
  14210. $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] / 256));
  14211. $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] % 256));
  14212. }
  14213. $count_cols = count($patch_array[$i]['colors']);
  14214. for ($j=0; $j < $count_cols; ++$j) {
  14215. //each color component as 8 bit
  14216. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['r']);
  14217. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['g']);
  14218. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['b']);
  14219. }
  14220. }
  14221. //paint the gradient
  14222. $this->_out('/Sh'.$n.' sh');
  14223. //restore previous Graphic State
  14224. $this->_outRestoreGraphicsState();
  14225. if ($this->inxobj) {
  14226. // we are inside an XObject template
  14227. $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
  14228. }
  14229. }
  14230. /**
  14231. * Set a rectangular clipping area.
  14232. * @param $x (float) abscissa of the top left corner of the rectangle (or top right corner for RTL mode).
  14233. * @param $y (float) ordinate of the top left corner of the rectangle.
  14234. * @param $w (float) width of the rectangle.
  14235. * @param $h (float) height of the rectangle.
  14236. * @author Andreas W\FCrmser, Nicola Asuni
  14237. * @since 3.1.000 (2008-06-09)
  14238. * @protected
  14239. */
  14240. protected function Clip($x, $y, $w, $h)
  14241. {
  14242. if ($this->state != 2) {
  14243. return;
  14244. }
  14245. if ($this->rtl) {
  14246. $x = $this->w - $x - $w;
  14247. }
  14248. //save current Graphic State
  14249. $s = 'q';
  14250. //set clipping area
  14251. $s .= sprintf(' %F %F %F %F re W n', $x*$this->k, ($this->h-$y)*$this->k, $w*$this->k, -$h*$this->k);
  14252. //set up transformation matrix for gradient
  14253. $s .= sprintf(' %F 0 0 %F %F %F cm', $w*$this->k, $h*$this->k, $x*$this->k, ($this->h-($y+$h))*$this->k);
  14254. $this->_out($s);
  14255. }
  14256. /**
  14257. * Output gradient.
  14258. * @param $type (int) type of gradient (1 Function-based shading; 2 Axial shading; 3 Radial shading; 4 Free-form Gouraud-shaded triangle mesh; 5 Lattice-form Gouraud-shaded triangle mesh; 6 Coons patch mesh; 7 Tensor-product patch mesh). (Not all types are currently supported)
  14259. * @param $coords (array) array of coordinates.
  14260. * @param $stops (array) array gradient color components: color = array of GRAY, RGB or CMYK color components; offset = (0 to 1) represents a location along the gradient vector; exponent = exponent of the exponential interpolation function (default = 1).
  14261. * @param $background (array) An array of colour components appropriate to the colour space, specifying a single background colour value.
  14262. * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  14263. * @author Nicola Asuni
  14264. * @since 3.1.000 (2008-06-09)
  14265. * @public
  14266. */
  14267. public function Gradient($type, $coords, $stops, $background = array(), $antialias = false)
  14268. {
  14269. if ($this->pdfa_mode OR ($this->state != 2)) {
  14270. return;
  14271. }
  14272. $n = count($this->gradients) + 1;
  14273. $this->gradients[$n] = array();
  14274. $this->gradients[$n]['type'] = $type;
  14275. $this->gradients[$n]['coords'] = $coords;
  14276. $this->gradients[$n]['antialias'] = $antialias;
  14277. $this->gradients[$n]['colors'] = array();
  14278. $this->gradients[$n]['transparency'] = false;
  14279. // color space
  14280. $numcolspace = count($stops[0]['color']);
  14281. $bcolor = array_values($background);
  14282. switch ($numcolspace) {
  14283. case 5: // SPOT
  14284. case 4: { // CMYK
  14285. $this->gradients[$n]['colspace'] = 'DeviceCMYK';
  14286. if (!empty($background)) {
  14287. $this->gradients[$n]['background'] = sprintf('%F %F %F %F', $bcolor[0]/100, $bcolor[1]/100, $bcolor[2]/100, $bcolor[3]/100);
  14288. }
  14289. break;
  14290. }
  14291. case 3: { // RGB
  14292. $this->gradients[$n]['colspace'] = 'DeviceRGB';
  14293. if (!empty($background)) {
  14294. $this->gradients[$n]['background'] = sprintf('%F %F %F', $bcolor[0]/255, $bcolor[1]/255, $bcolor[2]/255);
  14295. }
  14296. break;
  14297. }
  14298. case 1: { // GRAY SCALE
  14299. $this->gradients[$n]['colspace'] = 'DeviceGray';
  14300. if (!empty($background)) {
  14301. $this->gradients[$n]['background'] = sprintf('%F', $bcolor[0]/255);
  14302. }
  14303. break;
  14304. }
  14305. }
  14306. $num_stops = count($stops);
  14307. $last_stop_id = $num_stops - 1;
  14308. foreach ($stops as $key => $stop) {
  14309. $this->gradients[$n]['colors'][$key] = array();
  14310. // offset represents a location along the gradient vector
  14311. if (isset($stop['offset'])) {
  14312. $this->gradients[$n]['colors'][$key]['offset'] = $stop['offset'];
  14313. } else {
  14314. if ($key == 0) {
  14315. $this->gradients[$n]['colors'][$key]['offset'] = 0;
  14316. } elseif ($key == $last_stop_id) {
  14317. $this->gradients[$n]['colors'][$key]['offset'] = 1;
  14318. } else {
  14319. $offsetstep = (1 - $this->gradients[$n]['colors'][($key - 1)]['offset']) / ($num_stops - $key);
  14320. $this->gradients[$n]['colors'][$key]['offset'] = $this->gradients[$n]['colors'][($key - 1)]['offset'] + $offsetstep;
  14321. }
  14322. }
  14323. if (isset($stop['opacity'])) {
  14324. $this->gradients[$n]['colors'][$key]['opacity'] = $stop['opacity'];
  14325. if ((!$this->pdfa_mode) AND ($stop['opacity'] < 1)) {
  14326. $this->gradients[$n]['transparency'] = true;
  14327. }
  14328. } else {
  14329. $this->gradients[$n]['colors'][$key]['opacity'] = 1;
  14330. }
  14331. // exponent for the exponential interpolation function
  14332. if (isset($stop['exponent'])) {
  14333. $this->gradients[$n]['colors'][$key]['exponent'] = $stop['exponent'];
  14334. } else {
  14335. $this->gradients[$n]['colors'][$key]['exponent'] = 1;
  14336. }
  14337. // set colors
  14338. $color = array_values($stop['color']);
  14339. switch ($numcolspace) {
  14340. case 5: // SPOT
  14341. case 4: { // CMYK
  14342. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F %F', $color[0]/100, $color[1]/100, $color[2]/100, $color[3]/100);
  14343. break;
  14344. }
  14345. case 3: { // RGB
  14346. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F', $color[0]/255, $color[1]/255, $color[2]/255);
  14347. break;
  14348. }
  14349. case 1: { // GRAY SCALE
  14350. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F', $color[0]/255);
  14351. break;
  14352. }
  14353. }
  14354. }
  14355. if ($this->gradients[$n]['transparency']) {
  14356. // paint luminosity gradient
  14357. $this->_out('/TGS'.$n.' gs');
  14358. }
  14359. //paint the gradient
  14360. $this->_out('/Sh'.$n.' sh');
  14361. //restore previous Graphic State
  14362. $this->_outRestoreGraphicsState();
  14363. if ($this->inxobj) {
  14364. // we are inside an XObject template
  14365. $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
  14366. }
  14367. }
  14368. /**
  14369. * Output gradient shaders.
  14370. * @author Nicola Asuni
  14371. * @since 3.1.000 (2008-06-09)
  14372. * @protected
  14373. */
  14374. function _putshaders()
  14375. {
  14376. if ($this->pdfa_mode) {
  14377. return;
  14378. }
  14379. $idt = count($this->gradients); //index for transparency gradients
  14380. foreach ($this->gradients as $id => $grad) {
  14381. if (($grad['type'] == 2) OR ($grad['type'] == 3)) {
  14382. $fc = $this->_newobj();
  14383. $out = '<<';
  14384. $out .= ' /FunctionType 3';
  14385. $out .= ' /Domain [0 1]';
  14386. $functions = '';
  14387. $bounds = '';
  14388. $encode = '';
  14389. $i = 1;
  14390. $num_cols = count($grad['colors']);
  14391. $lastcols = $num_cols - 1;
  14392. for ($i = 1; $i < $num_cols; ++$i) {
  14393. $functions .= ($fc + $i).' 0 R ';
  14394. if ($i < $lastcols) {
  14395. $bounds .= sprintf('%F ', $grad['colors'][$i]['offset']);
  14396. }
  14397. $encode .= '0 1 ';
  14398. }
  14399. $out .= ' /Functions ['.trim($functions).']';
  14400. $out .= ' /Bounds ['.trim($bounds).']';
  14401. $out .= ' /Encode ['.trim($encode).']';
  14402. $out .= ' >>';
  14403. $out .= "\n".'endobj';
  14404. $this->_out($out);
  14405. for ($i = 1; $i < $num_cols; ++$i) {
  14406. $this->_newobj();
  14407. $out = '<<';
  14408. $out .= ' /FunctionType 2';
  14409. $out .= ' /Domain [0 1]';
  14410. $out .= ' /C0 ['.$grad['colors'][($i - 1)]['color'].']';
  14411. $out .= ' /C1 ['.$grad['colors'][$i]['color'].']';
  14412. $out .= ' /N '.$grad['colors'][$i]['exponent'];
  14413. $out .= ' >>';
  14414. $out .= "\n".'endobj';
  14415. $this->_out($out);
  14416. }
  14417. // set transparency functions
  14418. if ($grad['transparency']) {
  14419. $ft = $this->_newobj();
  14420. $out = '<<';
  14421. $out .= ' /FunctionType 3';
  14422. $out .= ' /Domain [0 1]';
  14423. $functions = '';
  14424. $i = 1;
  14425. $num_cols = count($grad['colors']);
  14426. for ($i = 1; $i < $num_cols; ++$i) {
  14427. $functions .= ($ft + $i).' 0 R ';
  14428. }
  14429. $out .= ' /Functions ['.trim($functions).']';
  14430. $out .= ' /Bounds ['.trim($bounds).']';
  14431. $out .= ' /Encode ['.trim($encode).']';
  14432. $out .= ' >>';
  14433. $out .= "\n".'endobj';
  14434. $this->_out($out);
  14435. for ($i = 1; $i < $num_cols; ++$i) {
  14436. $this->_newobj();
  14437. $out = '<<';
  14438. $out .= ' /FunctionType 2';
  14439. $out .= ' /Domain [0 1]';
  14440. $out .= ' /C0 ['.$grad['colors'][($i - 1)]['opacity'].']';
  14441. $out .= ' /C1 ['.$grad['colors'][$i]['opacity'].']';
  14442. $out .= ' /N '.$grad['colors'][$i]['exponent'];
  14443. $out .= ' >>';
  14444. $out .= "\n".'endobj';
  14445. $this->_out($out);
  14446. }
  14447. }
  14448. }
  14449. // set shading object
  14450. $this->_newobj();
  14451. $out = '<< /ShadingType '.$grad['type'];
  14452. if (isset($grad['colspace'])) {
  14453. $out .= ' /ColorSpace /'.$grad['colspace'];
  14454. } else {
  14455. $out .= ' /ColorSpace /DeviceRGB';
  14456. }
  14457. if (isset($grad['background']) AND !empty($grad['background'])) {
  14458. $out .= ' /Background ['.$grad['background'].']';
  14459. }
  14460. if (isset($grad['antialias']) AND ($grad['antialias'] === true)) {
  14461. $out .= ' /AntiAlias true';
  14462. }
  14463. if ($grad['type'] == 2) {
  14464. $out .= ' '.sprintf('/Coords [%F %F %F %F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]);
  14465. $out .= ' /Domain [0 1]';
  14466. $out .= ' /Function '.$fc.' 0 R';
  14467. $out .= ' /Extend [true true]';
  14468. $out .= ' >>';
  14469. } elseif ($grad['type'] == 3) {
  14470. //x0, y0, r0, x1, y1, r1
  14471. //at this this time radius of inner circle is 0
  14472. $out .= ' '.sprintf('/Coords [%F %F 0 %F %F %F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]);
  14473. $out .= ' /Domain [0 1]';
  14474. $out .= ' /Function '.$fc.' 0 R';
  14475. $out .= ' /Extend [true true]';
  14476. $out .= ' >>';
  14477. } elseif ($grad['type'] == 6) {
  14478. $out .= ' /BitsPerCoordinate 16';
  14479. $out .= ' /BitsPerComponent 8';
  14480. $out .= ' /Decode[0 1 0 1 0 1 0 1 0 1]';
  14481. $out .= ' /BitsPerFlag 8';
  14482. $stream = $this->_getrawstream($grad['stream']);
  14483. $out .= ' /Length '.strlen($stream);
  14484. $out .= ' >>';
  14485. $out .= ' stream'."\n".$stream."\n".'endstream';
  14486. }
  14487. $out .= "\n".'endobj';
  14488. $this->_out($out);
  14489. if ($grad['transparency']) {
  14490. $shading_transparency = preg_replace('/\/ColorSpace \/[^\s]+/si', '/ColorSpace /DeviceGray', $out);
  14491. $shading_transparency = preg_replace('/\/Function [0-9]+ /si', '/Function '.$ft.' ', $shading_transparency);
  14492. }
  14493. $this->gradients[$id]['id'] = $this->n;
  14494. // set pattern object
  14495. $this->_newobj();
  14496. $out = '<< /Type /Pattern /PatternType 2';
  14497. $out .= ' /Shading '.$this->gradients[$id]['id'].' 0 R';
  14498. $out .= ' >>';
  14499. $out .= "\n".'endobj';
  14500. $this->_out($out);
  14501. $this->gradients[$id]['pattern'] = $this->n;
  14502. // set shading and pattern for transparency mask
  14503. if ($grad['transparency']) {
  14504. // luminosity pattern
  14505. $idgs = $id + $idt;
  14506. $this->_newobj();
  14507. $this->_out($shading_transparency);
  14508. $this->gradients[$idgs]['id'] = $this->n;
  14509. $this->_newobj();
  14510. $out = '<< /Type /Pattern /PatternType 2';
  14511. $out .= ' /Shading '.$this->gradients[$idgs]['id'].' 0 R';
  14512. $out .= ' >>';
  14513. $out .= "\n".'endobj';
  14514. $this->_out($out);
  14515. $this->gradients[$idgs]['pattern'] = $this->n;
  14516. // luminosity XObject
  14517. $oid = $this->_newobj();
  14518. $this->xobjects['LX'.$oid] = array('n' => $oid);
  14519. $filter = '';
  14520. $stream = 'q /a0 gs /Pattern cs /p'.$idgs.' scn 0 0 '.$this->wPt.' '.$this->hPt.' re f Q';
  14521. if ($this->compress) {
  14522. $filter = ' /Filter /FlateDecode';
  14523. $stream = gzcompress($stream);
  14524. }
  14525. $stream = $this->_getrawstream($stream);
  14526. $out = '<< /Type /XObject /Subtype /Form /FormType 1'.$filter;
  14527. $out .= ' /Length '.strlen($stream);
  14528. $rect = sprintf('%F %F', $this->wPt, $this->hPt);
  14529. $out .= ' /BBox [0 0 '.$rect.']';
  14530. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceGray >>';
  14531. $out .= ' /Resources <<';
  14532. $out .= ' /ExtGState << /a0 << /ca 1 /CA 1 >> >>';
  14533. $out .= ' /Pattern << /p'.$idgs.' '.$this->gradients[$idgs]['pattern'].' 0 R >>';
  14534. $out .= ' >>';
  14535. $out .= ' >> ';
  14536. $out .= ' stream'."\n".$stream."\n".'endstream';
  14537. $out .= "\n".'endobj';
  14538. $this->_out($out);
  14539. // SMask
  14540. $this->_newobj();
  14541. $out = '<< /Type /Mask /S /Luminosity /G '.($this->n - 1).' 0 R >>'."\n".'endobj';
  14542. $this->_out($out);
  14543. // ExtGState
  14544. $this->_newobj();
  14545. $out = '<< /Type /ExtGState /SMask '.($this->n - 1).' 0 R /AIS false >>'."\n".'endobj';
  14546. $this->_out($out);
  14547. $this->extgstates[] = array('n' => $this->n, 'name' => 'TGS'.$id);
  14548. }
  14549. }
  14550. }
  14551. /**
  14552. * Draw the sector of a circle.
  14553. * It can be used for instance to render pie charts.
  14554. * @param $xc (float) abscissa of the center.
  14555. * @param $yc (float) ordinate of the center.
  14556. * @param $r (float) radius.
  14557. * @param $a (float) start angle (in degrees).
  14558. * @param $b (float) end angle (in degrees).
  14559. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  14560. * @param $cw: (float) indicates whether to go clockwise (default: true).
  14561. * @param $o: (float) origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock). Default: 90.
  14562. * @author Maxime Delorme, Nicola Asuni
  14563. * @since 3.1.000 (2008-06-09)
  14564. * @public
  14565. */
  14566. public function PieSector($xc, $yc, $r, $a, $b, $style = 'FD', $cw = true, $o = 90)
  14567. {
  14568. $this->PieSectorXY($xc, $yc, $r, $r, $a, $b, $style, $cw, $o);
  14569. }
  14570. /**
  14571. * Draw the sector of an ellipse.
  14572. * It can be used for instance to render pie charts.
  14573. * @param $xc (float) abscissa of the center.
  14574. * @param $yc (float) ordinate of the center.
  14575. * @param $rx (float) the x-axis radius.
  14576. * @param $ry (float) the y-axis radius.
  14577. * @param $a (float) start angle (in degrees).
  14578. * @param $b (float) end angle (in degrees).
  14579. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  14580. * @param $cw: (float) indicates whether to go clockwise.
  14581. * @param $o: (float) origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock).
  14582. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of arc.
  14583. * @author Maxime Delorme, Nicola Asuni
  14584. * @since 3.1.000 (2008-06-09)
  14585. * @public
  14586. */
  14587. public function PieSectorXY($xc, $yc, $rx, $ry, $a, $b, $style = 'FD', $cw = false, $o = 0, $nc = 2)
  14588. {
  14589. if ($this->state != 2) {
  14590. return;
  14591. }
  14592. if ($this->rtl) {
  14593. $xc = ($this->w - $xc);
  14594. }
  14595. $op = TCPDF_STATIC::getPathPaintOperator($style);
  14596. if ($op == 'f') {
  14597. $line_style = array();
  14598. }
  14599. if ($cw) {
  14600. $d = $b;
  14601. $b = (360 - $a + $o);
  14602. $a = (360 - $d + $o);
  14603. } else {
  14604. $b += $o;
  14605. $a += $o;
  14606. }
  14607. $this->_outellipticalarc($xc, $yc, $rx, $ry, 0, $a, $b, true, $nc);
  14608. $this->_out($op);
  14609. }
  14610. /**
  14611. * Embed vector-based Adobe Illustrator (AI) or AI-compatible EPS files.
  14612. * NOTE: EPS is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  14613. * Only vector drawing is supported, not text or bitmap.
  14614. * 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).
  14615. * @param $file (string) Name of the file containing the image or a '@' character followed by the EPS/AI data string.
  14616. * @param $x (float) Abscissa of the upper-left corner.
  14617. * @param $y (float) Ordinate of the upper-left corner.
  14618. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  14619. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  14620. * @param $link (mixed) URL or identifier returned by AddLink().
  14621. * @param $useBoundingBox (boolean) specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true.
  14622. * @param $align (string) Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  14623. * @param $palign (string) Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  14624. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  14625. * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
  14626. * @param $fixoutvals (boolean) if true remove values outside the bounding box.
  14627. * @author Valentin Schmidt, Nicola Asuni
  14628. * @since 3.1.000 (2008-06-09)
  14629. * @public
  14630. */
  14631. public function ImageEps($file, $x = '', $y = '', $w = 0, $h = 0, $link = '', $useBoundingBox = true, $align = '', $palign = '', $border = 0, $fitonpage = false, $fixoutvals = false)
  14632. {
  14633. if ($this->state != 2) {
  14634. return;
  14635. }
  14636. if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
  14637. // convert EPS to raster image using GD or ImageMagick libraries
  14638. return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
  14639. }
  14640. if ($x === '') {
  14641. $x = $this->x;
  14642. }
  14643. if ($y === '') {
  14644. $y = $this->y;
  14645. }
  14646. // check page for no-write regions and adapt page margins if necessary
  14647. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  14648. $k = $this->k;
  14649. if ($file[0] === '@') { // image from string
  14650. $data = substr($file, 1);
  14651. } else { // EPS/AI file
  14652. $data = TCPDF_STATIC::fileGetContents($file);
  14653. }
  14654. if ($data === false) {
  14655. $this->Error('EPS file not found: '.$file);
  14656. }
  14657. $regs = array();
  14658. // EPS/AI compatibility check (only checks files created by Adobe Illustrator!)
  14659. preg_match("/%%Creator:([^\r\n]+)/", $data, $regs); // find Creator
  14660. if (count($regs) > 1) {
  14661. $version_str = trim($regs[1]); // e.g. "Adobe Illustrator(R) 8.0"
  14662. if (strpos($version_str, 'Adobe Illustrator') !== false) {
  14663. $versexp = explode(' ', $version_str);
  14664. $version = (float) array_pop($versexp);
  14665. if ($version >= 9) {
  14666. $this->Error('This version of Adobe Illustrator file is not supported: '.$file);
  14667. }
  14668. }
  14669. }
  14670. // strip binary bytes in front of PS-header
  14671. $start = strpos($data, '%!PS-Adobe');
  14672. if ($start > 0) {
  14673. $data = substr($data, $start);
  14674. }
  14675. // find BoundingBox params
  14676. preg_match("/%%BoundingBox:([^\r\n]+)/", $data, $regs);
  14677. if (count($regs) > 1) {
  14678. list($x1, $y1, $x2, $y2) = explode(' ', trim($regs[1]));
  14679. } else {
  14680. $this->Error('No BoundingBox found in EPS/AI file: '.$file);
  14681. }
  14682. $start = strpos($data, '%%EndSetup');
  14683. if ($start === false) {
  14684. $start = strpos($data, '%%EndProlog');
  14685. }
  14686. if ($start === false) {
  14687. $start = strpos($data, '%%BoundingBox');
  14688. }
  14689. $data = substr($data, $start);
  14690. $end = strpos($data, '%%PageTrailer');
  14691. if ($end===false) {
  14692. $end = strpos($data, 'showpage');
  14693. }
  14694. if ($end) {
  14695. $data = substr($data, 0, $end);
  14696. }
  14697. // calculate image width and height on document
  14698. if (($w <= 0) AND ($h <= 0)) {
  14699. $w = ($x2 - $x1) / $k;
  14700. $h = ($y2 - $y1) / $k;
  14701. } elseif ($w <= 0) {
  14702. $w = ($x2-$x1) / $k * ($h / (($y2 - $y1) / $k));
  14703. } elseif ($h <= 0) {
  14704. $h = ($y2 - $y1) / $k * ($w / (($x2 - $x1) / $k));
  14705. }
  14706. // fit the image on available space
  14707. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  14708. if ($this->rasterize_vector_images) {
  14709. // convert EPS to raster image using GD or ImageMagick libraries
  14710. return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
  14711. }
  14712. // set scaling factors
  14713. $scale_x = $w / (($x2 - $x1) / $k);
  14714. $scale_y = $h / (($y2 - $y1) / $k);
  14715. // set alignment
  14716. $this->img_rb_y = $y + $h;
  14717. // set alignment
  14718. if ($this->rtl) {
  14719. if ($palign == 'L') {
  14720. $ximg = $this->lMargin;
  14721. } elseif ($palign == 'C') {
  14722. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14723. } elseif ($palign == 'R') {
  14724. $ximg = $this->w - $this->rMargin - $w;
  14725. } else {
  14726. $ximg = $x - $w;
  14727. }
  14728. $this->img_rb_x = $ximg;
  14729. } else {
  14730. if ($palign == 'L') {
  14731. $ximg = $this->lMargin;
  14732. } elseif ($palign == 'C') {
  14733. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14734. } elseif ($palign == 'R') {
  14735. $ximg = $this->w - $this->rMargin - $w;
  14736. } else {
  14737. $ximg = $x;
  14738. }
  14739. $this->img_rb_x = $ximg + $w;
  14740. }
  14741. if ($useBoundingBox) {
  14742. $dx = $ximg * $k - $x1;
  14743. $dy = $y * $k - $y1;
  14744. } else {
  14745. $dx = $ximg * $k;
  14746. $dy = $y * $k;
  14747. }
  14748. // save the current graphic state
  14749. $this->_out('q'.$this->epsmarker);
  14750. // translate
  14751. $this->_out(sprintf('%F %F %F %F %F %F cm', 1, 0, 0, 1, $dx, $dy + ($this->hPt - (2 * $y * $k) - ($y2 - $y1))));
  14752. // scale
  14753. if (isset($scale_x)) {
  14754. $this->_out(sprintf('%F %F %F %F %F %F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y)));
  14755. }
  14756. // handle pc/unix/mac line endings
  14757. $lines = preg_split('/[\r\n]+/si', $data, -1, PREG_SPLIT_NO_EMPTY);
  14758. $u=0;
  14759. $cnt = count($lines);
  14760. for ($i=0; $i < $cnt; ++$i) {
  14761. $line = $lines[$i];
  14762. if (($line == '') OR ($line[0] == '%')) {
  14763. continue;
  14764. }
  14765. $len = strlen($line);
  14766. // check for spot color names
  14767. $color_name = '';
  14768. if (strcasecmp('x', substr(trim($line), -1)) == 0) {
  14769. if (preg_match('/\([^\)]*\)/', $line, $matches) > 0) {
  14770. // extract spot color name
  14771. $color_name = $matches[0];
  14772. // remove color name from string
  14773. $line = str_replace(' '.$color_name, '', $line);
  14774. // remove pharentesis from color name
  14775. $color_name = substr($color_name, 1, -1);
  14776. }
  14777. }
  14778. $chunks = explode(' ', $line);
  14779. $cmd = trim(array_pop($chunks));
  14780. // RGB
  14781. if (($cmd == 'Xa') OR ($cmd == 'XA')) {
  14782. $b = array_pop($chunks);
  14783. $g = array_pop($chunks);
  14784. $r = array_pop($chunks);
  14785. $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!
  14786. continue;
  14787. }
  14788. $skip = false;
  14789. if ($fixoutvals) {
  14790. // check for values outside the bounding box
  14791. switch ($cmd) {
  14792. case 'm':
  14793. case 'l':
  14794. case 'L': {
  14795. // skip values outside bounding box
  14796. foreach ($chunks as $key => $val) {
  14797. if ((($key % 2) == 0) AND (($val < $x1) OR ($val > $x2))) {
  14798. $skip = true;
  14799. } elseif ((($key % 2) != 0) AND (($val < $y1) OR ($val > $y2))) {
  14800. $skip = true;
  14801. }
  14802. }
  14803. }
  14804. }
  14805. }
  14806. switch ($cmd) {
  14807. case 'm':
  14808. case 'l':
  14809. case 'v':
  14810. case 'y':
  14811. case 'c':
  14812. case 'k':
  14813. case 'K':
  14814. case 'g':
  14815. case 'G':
  14816. case 's':
  14817. case 'S':
  14818. case 'J':
  14819. case 'j':
  14820. case 'w':
  14821. case 'M':
  14822. case 'd':
  14823. case 'n': {
  14824. if ($skip) {
  14825. break;
  14826. }
  14827. $this->_out($line);
  14828. break;
  14829. }
  14830. case 'x': {// custom fill color
  14831. if (empty($color_name)) {
  14832. // CMYK color
  14833. list($col_c, $col_m, $col_y, $col_k) = $chunks;
  14834. $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' k');
  14835. } else {
  14836. // Spot Color (CMYK + tint)
  14837. list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
  14838. $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
  14839. $color_cmd = sprintf('/CS%d cs %F scn', $this->spot_colors[$color_name]['i'], (1 - $col_t));
  14840. $this->_out($color_cmd);
  14841. }
  14842. break;
  14843. }
  14844. case 'X': { // custom stroke color
  14845. if (empty($color_name)) {
  14846. // CMYK color
  14847. list($col_c, $col_m, $col_y, $col_k) = $chunks;
  14848. $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' K');
  14849. } else {
  14850. // Spot Color (CMYK + tint)
  14851. list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
  14852. $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
  14853. $color_cmd = sprintf('/CS%d CS %F SCN', $this->spot_colors[$color_name]['i'], (1 - $col_t));
  14854. $this->_out($color_cmd);
  14855. }
  14856. break;
  14857. }
  14858. case 'Y':
  14859. case 'N':
  14860. case 'V':
  14861. case 'L':
  14862. case 'C': {
  14863. if ($skip) {
  14864. break;
  14865. }
  14866. $line[($len - 1)] = strtolower($cmd);
  14867. $this->_out($line);
  14868. break;
  14869. }
  14870. case 'b':
  14871. case 'B': {
  14872. $this->_out($cmd . '*');
  14873. break;
  14874. }
  14875. case 'f':
  14876. case 'F': {
  14877. if ($u > 0) {
  14878. $isU = false;
  14879. $max = min(($i + 5), $cnt);
  14880. for ($j = ($i + 1); $j < $max; ++$j) {
  14881. $isU = ($isU OR (($lines[$j] == 'U') OR ($lines[$j] == '*U')));
  14882. }
  14883. if ($isU) {
  14884. $this->_out('f*');
  14885. }
  14886. } else {
  14887. $this->_out('f*');
  14888. }
  14889. break;
  14890. }
  14891. case '*u': {
  14892. ++$u;
  14893. break;
  14894. }
  14895. case '*U': {
  14896. --$u;
  14897. break;
  14898. }
  14899. }
  14900. }
  14901. // restore previous graphic state
  14902. $this->_out($this->epsmarker.'Q');
  14903. if (!empty($border)) {
  14904. $bx = $this->x;
  14905. $by = $this->y;
  14906. $this->x = $ximg;
  14907. if ($this->rtl) {
  14908. $this->x += $w;
  14909. }
  14910. $this->y = $y;
  14911. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  14912. $this->x = $bx;
  14913. $this->y = $by;
  14914. }
  14915. if ($link) {
  14916. $this->Link($ximg, $y, $w, $h, $link, 0);
  14917. }
  14918. // set pointer to align the next text/objects
  14919. switch ($align) {
  14920. case 'T':{
  14921. $this->y = $y;
  14922. $this->x = $this->img_rb_x;
  14923. break;
  14924. }
  14925. case 'M':{
  14926. $this->y = $y + round($h/2);
  14927. $this->x = $this->img_rb_x;
  14928. break;
  14929. }
  14930. case 'B':{
  14931. $this->y = $this->img_rb_y;
  14932. $this->x = $this->img_rb_x;
  14933. break;
  14934. }
  14935. case 'N':{
  14936. $this->SetY($this->img_rb_y);
  14937. break;
  14938. }
  14939. default:{
  14940. break;
  14941. }
  14942. }
  14943. $this->endlinex = $this->img_rb_x;
  14944. }
  14945. /**
  14946. * Set document barcode.
  14947. * @param $bc (string) barcode
  14948. * @public
  14949. */
  14950. public function setBarcode($bc = '')
  14951. {
  14952. $this->barcode = $bc;
  14953. }
  14954. /**
  14955. * Get current barcode.
  14956. * @return string
  14957. * @public
  14958. * @since 4.0.012 (2008-07-24)
  14959. */
  14960. public function getBarcode()
  14961. {
  14962. return $this->barcode;
  14963. }
  14964. /**
  14965. * Print a Linear Barcode.
  14966. * @param $code (string) code to print
  14967. * @param $type (string) type of barcode (see tcpdf_barcodes_1d.php for supported formats).
  14968. * @param $x (int) x position in user units (empty string = current x position)
  14969. * @param $y (int) y position in user units (empty string = current y position)
  14970. * @param $w (int) width in user units (empty string = remaining page width)
  14971. * @param $h (int) height in user units (empty string = remaining page height)
  14972. * @param $xres (float) width of the smallest bar in user units (empty string = default value = 0.4mm)
  14973. * @param $style (array) array of options:<ul>
  14974. * <li>boolean $style['border'] if true prints a border</li>
  14975. * <li>int $style['padding'] padding to leave around the barcode in user units (set to 'auto' for automatic padding)</li>
  14976. * <li>int $style['hpadding'] horizontal padding in user units (set to 'auto' for automatic padding)</li>
  14977. * <li>int $style['vpadding'] vertical padding in user units (set to 'auto' for automatic padding)</li>
  14978. * <li>array $style['fgcolor'] color array for bars and text</li>
  14979. * <li>mixed $style['bgcolor'] color array for background (set to false for transparent)</li>
  14980. * <li>boolean $style['text'] if true prints text below the barcode</li>
  14981. * <li>string $style['label'] override default label</li>
  14982. * <li>string $style['font'] font name for text</li><li>int $style['fontsize'] font size for text</li>
  14983. * <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>
  14984. * <li>string $style['position'] horizontal position of the containing barcode cell on the page: L = left margin; C = center; R = right margin.</li>
  14985. * <li>string $style['align'] horizontal position of the barcode on the containing rectangle: L = left; C = center; R = right.</li>
  14986. * <li>string $style['stretch'] if true stretch the barcode to best fit the available width, otherwise uses $xres resolution for a single bar.</li>
  14987. * <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>
  14988. * <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>
  14989. * @param $align (string) Indicates the alignment of the pointer next to barcode insertion relative to barcode height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  14990. * @author Nicola Asuni
  14991. * @since 3.1.000 (2008-06-09)
  14992. * @public
  14993. */
  14994. public function write1DBarcode($code, $type, $x = '', $y = '', $w = '', $h = '', $xres = '', $style = array(), $align = '')
  14995. {
  14996. if (TCPDF_STATIC::empty_string(trim($code))) {
  14997. return;
  14998. }
  14999. require_once dirname(__FILE__).'/tcpdf_barcodes_1d.php';
  15000. // save current graphic settings
  15001. $gvars = $this->getGraphicVars();
  15002. // create new barcode object
  15003. $barcodeobj = new TCPDFBarcode($code, $type);
  15004. $arrcode = $barcodeobj->getBarcodeArray();
  15005. if (($arrcode === false) OR empty($arrcode) OR ($arrcode['maxw'] <= 0)) {
  15006. $this->Error('Error in 1D barcode string');
  15007. }
  15008. if ($arrcode['maxh'] <= 0) {
  15009. $arrcode['maxh'] = 1;
  15010. }
  15011. // set default values
  15012. if (!isset($style['position'])) {
  15013. $style['position'] = '';
  15014. } elseif ($style['position'] == 'S') {
  15015. // keep this for backward compatibility
  15016. $style['position'] = '';
  15017. $style['stretch'] = true;
  15018. }
  15019. if (!isset($style['fitwidth'])) {
  15020. if (!isset($style['stretch'])) {
  15021. $style['fitwidth'] = true;
  15022. } else {
  15023. $style['fitwidth'] = false;
  15024. }
  15025. }
  15026. if ($style['fitwidth']) {
  15027. // disable stretch
  15028. $style['stretch'] = false;
  15029. }
  15030. if (!isset($style['stretch'])) {
  15031. if (($w === '') OR ($w <= 0)) {
  15032. $style['stretch'] = false;
  15033. } else {
  15034. $style['stretch'] = true;
  15035. }
  15036. }
  15037. if (!isset($style['fgcolor'])) {
  15038. $style['fgcolor'] = array(0,0,0); // default black
  15039. }
  15040. if (!isset($style['bgcolor'])) {
  15041. $style['bgcolor'] = false; // default transparent
  15042. }
  15043. if (!isset($style['border'])) {
  15044. $style['border'] = false;
  15045. }
  15046. $fontsize = 0;
  15047. if (!isset($style['text'])) {
  15048. $style['text'] = false;
  15049. }
  15050. if ($style['text'] AND isset($style['font'])) {
  15051. if (isset($style['fontsize'])) {
  15052. $fontsize = $style['fontsize'];
  15053. }
  15054. $this->SetFont($style['font'], '', $fontsize);
  15055. }
  15056. if (!isset($style['stretchtext'])) {
  15057. $style['stretchtext'] = 4;
  15058. }
  15059. if ($x === '') {
  15060. $x = $this->x;
  15061. }
  15062. if ($y === '') {
  15063. $y = $this->y;
  15064. }
  15065. // check page for no-write regions and adapt page margins if necessary
  15066. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  15067. if (($w === '') OR ($w <= 0)) {
  15068. if ($this->rtl) {
  15069. $w = $x - $this->lMargin;
  15070. } else {
  15071. $w = $this->w - $this->rMargin - $x;
  15072. }
  15073. }
  15074. // padding
  15075. if (!isset($style['padding'])) {
  15076. $padding = 0;
  15077. } elseif ($style['padding'] === 'auto') {
  15078. $padding = 10 * ($w / ($arrcode['maxw'] + 20));
  15079. } else {
  15080. $padding = floatval($style['padding']);
  15081. }
  15082. // horizontal padding
  15083. if (!isset($style['hpadding'])) {
  15084. $hpadding = $padding;
  15085. } elseif ($style['hpadding'] === 'auto') {
  15086. $hpadding = 10 * ($w / ($arrcode['maxw'] + 20));
  15087. } else {
  15088. $hpadding = floatval($style['hpadding']);
  15089. }
  15090. // vertical padding
  15091. if (!isset($style['vpadding'])) {
  15092. $vpadding = $padding;
  15093. } elseif ($style['vpadding'] === 'auto') {
  15094. $vpadding = ($hpadding / 2);
  15095. } else {
  15096. $vpadding = floatval($style['vpadding']);
  15097. }
  15098. // calculate xres (single bar width)
  15099. $max_xres = ($w - (2 * $hpadding)) / $arrcode['maxw'];
  15100. if ($style['stretch']) {
  15101. $xres = $max_xres;
  15102. } else {
  15103. if (TCPDF_STATIC::empty_string($xres)) {
  15104. $xres = (0.141 * $this->k); // default bar width = 0.4 mm
  15105. }
  15106. if ($xres > $max_xres) {
  15107. // correct xres to fit on $w
  15108. $xres = $max_xres;
  15109. }
  15110. if ((isset($style['padding']) AND ($style['padding'] === 'auto'))
  15111. OR (isset($style['hpadding']) AND ($style['hpadding'] === 'auto'))) {
  15112. $hpadding = 10 * $xres;
  15113. if (isset($style['vpadding']) AND ($style['vpadding'] === 'auto')) {
  15114. $vpadding = ($hpadding / 2);
  15115. }
  15116. }
  15117. }
  15118. if ($style['fitwidth']) {
  15119. $wold = $w;
  15120. $w = (($arrcode['maxw'] * $xres) + (2 * $hpadding));
  15121. if (isset($style['cellfitalign'])) {
  15122. switch ($style['cellfitalign']) {
  15123. case 'L': {
  15124. if ($this->rtl) {
  15125. $x -= ($wold - $w);
  15126. }
  15127. break;
  15128. }
  15129. case 'R': {
  15130. if (!$this->rtl) {
  15131. $x += ($wold - $w);
  15132. }
  15133. break;
  15134. }
  15135. case 'C': {
  15136. if ($this->rtl) {
  15137. $x -= (($wold - $w) / 2);
  15138. } else {
  15139. $x += (($wold - $w) / 2);
  15140. }
  15141. break;
  15142. }
  15143. default : {
  15144. break;
  15145. }
  15146. }
  15147. }
  15148. }
  15149. $text_height = $this->getCellHeight($fontsize / $this->k);
  15150. // height
  15151. if (($h === '') OR ($h <= 0)) {
  15152. // set default height
  15153. $h = (($arrcode['maxw'] * $xres) / 3) + (2 * $vpadding) + $text_height;
  15154. }
  15155. $barh = $h - $text_height - (2 * $vpadding);
  15156. if ($barh <=0) {
  15157. // try to reduce font or padding to fit barcode on available height
  15158. if ($text_height > $h) {
  15159. $fontsize = (($h * $this->k) / (4 * $this->cell_height_ratio));
  15160. $text_height = $this->getCellHeight($fontsize / $this->k);
  15161. $this->SetFont($style['font'], '', $fontsize);
  15162. }
  15163. if ($vpadding > 0) {
  15164. $vpadding = (($h - $text_height) / 4);
  15165. }
  15166. $barh = $h - $text_height - (2 * $vpadding);
  15167. }
  15168. // fit the barcode on available space
  15169. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
  15170. // set alignment
  15171. $this->img_rb_y = $y + $h;
  15172. // set alignment
  15173. if ($this->rtl) {
  15174. if ($style['position'] == 'L') {
  15175. $xpos = $this->lMargin;
  15176. } elseif ($style['position'] == 'C') {
  15177. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  15178. } elseif ($style['position'] == 'R') {
  15179. $xpos = $this->w - $this->rMargin - $w;
  15180. } else {
  15181. $xpos = $x - $w;
  15182. }
  15183. $this->img_rb_x = $xpos;
  15184. } else {
  15185. if ($style['position'] == 'L') {
  15186. $xpos = $this->lMargin;
  15187. } elseif ($style['position'] == 'C') {
  15188. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  15189. } elseif ($style['position'] == 'R') {
  15190. $xpos = $this->w - $this->rMargin - $w;
  15191. } else {
  15192. $xpos = $x;
  15193. }
  15194. $this->img_rb_x = $xpos + $w;
  15195. }
  15196. $xpos_rect = $xpos;
  15197. if (!isset($style['align'])) {
  15198. $style['align'] = 'C';
  15199. }
  15200. switch ($style['align']) {
  15201. case 'L': {
  15202. $xpos = $xpos_rect + $hpadding;
  15203. break;
  15204. }
  15205. case 'R': {
  15206. $xpos = $xpos_rect + ($w - ($arrcode['maxw'] * $xres)) - $hpadding;
  15207. break;
  15208. }
  15209. case 'C':
  15210. default : {
  15211. $xpos = $xpos_rect + (($w - ($arrcode['maxw'] * $xres)) / 2);
  15212. break;
  15213. }
  15214. }
  15215. $xpos_text = $xpos;
  15216. // barcode is always printed in LTR direction
  15217. $tempRTL = $this->rtl;
  15218. $this->rtl = false;
  15219. // print background color
  15220. if ($style['bgcolor']) {
  15221. $this->Rect($xpos_rect, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  15222. } elseif ($style['border']) {
  15223. $this->Rect($xpos_rect, $y, $w, $h, 'D');
  15224. }
  15225. // set foreground color
  15226. $this->SetDrawColorArray($style['fgcolor']);
  15227. $this->SetTextColorArray($style['fgcolor']);
  15228. // print bars
  15229. foreach ($arrcode['bcode'] as $k => $v) {
  15230. $bw = ($v['w'] * $xres);
  15231. if ($v['t']) {
  15232. // draw a vertical bar
  15233. $ypos = $y + $vpadding + ($v['p'] * $barh / $arrcode['maxh']);
  15234. $this->Rect($xpos, $ypos, $bw, ($v['h'] * $barh / $arrcode['maxh']), 'F', array(), $style['fgcolor']);
  15235. }
  15236. $xpos += $bw;
  15237. }
  15238. // print text
  15239. if ($style['text']) {
  15240. if (isset($style['label']) AND !TCPDF_STATIC::empty_string($style['label'])) {
  15241. $label = $style['label'];
  15242. } else {
  15243. $label = $code;
  15244. }
  15245. $txtwidth = ($arrcode['maxw'] * $xres);
  15246. if ($this->GetStringWidth($label) > $txtwidth) {
  15247. $style['stretchtext'] = 2;
  15248. }
  15249. // print text
  15250. $this->x = $xpos_text;
  15251. $this->y = $y + $vpadding + $barh;
  15252. $cellpadding = $this->cell_padding;
  15253. $this->SetCellPadding(0);
  15254. $this->Cell($txtwidth, '', $label, 0, 0, 'C', false, '', $style['stretchtext'], false, 'T', 'T');
  15255. $this->cell_padding = $cellpadding;
  15256. }
  15257. // restore original direction
  15258. $this->rtl = $tempRTL;
  15259. // restore previous settings
  15260. $this->setGraphicVars($gvars);
  15261. // set pointer to align the next text/objects
  15262. switch ($align) {
  15263. case 'T':{
  15264. $this->y = $y;
  15265. $this->x = $this->img_rb_x;
  15266. break;
  15267. }
  15268. case 'M':{
  15269. $this->y = $y + round($h / 2);
  15270. $this->x = $this->img_rb_x;
  15271. break;
  15272. }
  15273. case 'B':{
  15274. $this->y = $this->img_rb_y;
  15275. $this->x = $this->img_rb_x;
  15276. break;
  15277. }
  15278. case 'N':{
  15279. $this->SetY($this->img_rb_y);
  15280. break;
  15281. }
  15282. default:{
  15283. break;
  15284. }
  15285. }
  15286. $this->endlinex = $this->img_rb_x;
  15287. }
  15288. /**
  15289. * Print 2D Barcode.
  15290. * @param $code (string) code to print
  15291. * @param $type (string) type of barcode (see tcpdf_barcodes_2d.php for supported formats).
  15292. * @param $x (int) x position in user units
  15293. * @param $y (int) y position in user units
  15294. * @param $w (int) width in user units
  15295. * @param $h (int) height in user units
  15296. * @param $style (array) array of options:<ul>
  15297. * <li>boolean $style['border'] if true prints a border around the barcode</li>
  15298. * <li>int $style['padding'] padding to leave around the barcode in barcode units (set to 'auto' for automatic padding)</li>
  15299. * <li>int $style['hpadding'] horizontal padding in barcode units (set to 'auto' for automatic padding)</li>
  15300. * <li>int $style['vpadding'] vertical padding in barcode units (set to 'auto' for automatic padding)</li>
  15301. * <li>int $style['module_width'] width of a single module in points</li>
  15302. * <li>int $style['module_height'] height of a single module in points</li>
  15303. * <li>array $style['fgcolor'] color array for bars and text</li>
  15304. * <li>mixed $style['bgcolor'] color array for background or false for transparent</li>
  15305. * <li>string $style['position'] barcode position on the page: L = left margin; C = center; R = right margin; S = stretch</li>
  15306. * @param $align (string) Indicates the alignment of the pointer next to barcode insertion relative to barcode height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  15307. * @param $distort (boolean) if true distort the barcode to fit width and height, otherwise preserve aspect ratio
  15308. * @author Nicola Asuni
  15309. * @since 4.5.037 (2009-04-07)
  15310. * @public
  15311. */
  15312. public function write2DBarcode($code, $type, $x = '', $y = '', $w = '', $h = '', $style = array(), $align = '', $distort = false)
  15313. {
  15314. if (TCPDF_STATIC::empty_string(trim($code))) {
  15315. return;
  15316. }
  15317. require_once dirname(__FILE__).'/tcpdf_barcodes_2d.php';
  15318. // save current graphic settings
  15319. $gvars = $this->getGraphicVars();
  15320. // create new barcode object
  15321. $barcodeobj = new TCPDF2DBarcode($code, $type);
  15322. $arrcode = $barcodeobj->getBarcodeArray();
  15323. if (($arrcode === false) OR empty($arrcode) OR !isset($arrcode['num_rows']) OR ($arrcode['num_rows'] == 0) OR !isset($arrcode['num_cols']) OR ($arrcode['num_cols'] == 0)) {
  15324. $this->Error('Error in 2D barcode string');
  15325. }
  15326. // set default values
  15327. if (!isset($style['position'])) {
  15328. $style['position'] = '';
  15329. }
  15330. if (!isset($style['fgcolor'])) {
  15331. $style['fgcolor'] = array(0,0,0); // default black
  15332. }
  15333. if (!isset($style['bgcolor'])) {
  15334. $style['bgcolor'] = false; // default transparent
  15335. }
  15336. if (!isset($style['border'])) {
  15337. $style['border'] = false;
  15338. }
  15339. // padding
  15340. if (!isset($style['padding'])) {
  15341. $style['padding'] = 0;
  15342. } elseif ($style['padding'] === 'auto') {
  15343. $style['padding'] = 4;
  15344. }
  15345. if (!isset($style['hpadding'])) {
  15346. $style['hpadding'] = $style['padding'];
  15347. } elseif ($style['hpadding'] === 'auto') {
  15348. $style['hpadding'] = 4;
  15349. }
  15350. if (!isset($style['vpadding'])) {
  15351. $style['vpadding'] = $style['padding'];
  15352. } elseif ($style['vpadding'] === 'auto') {
  15353. $style['vpadding'] = 4;
  15354. }
  15355. $hpad = (2 * $style['hpadding']);
  15356. $vpad = (2 * $style['vpadding']);
  15357. // cell (module) dimension
  15358. if (!isset($style['module_width'])) {
  15359. $style['module_width'] = 1; // width of a single module in points
  15360. }
  15361. if (!isset($style['module_height'])) {
  15362. $style['module_height'] = 1; // height of a single module in points
  15363. }
  15364. if ($x === '') {
  15365. $x = $this->x;
  15366. }
  15367. if ($y === '') {
  15368. $y = $this->y;
  15369. }
  15370. // check page for no-write regions and adapt page margins if necessary
  15371. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  15372. // number of barcode columns and rows
  15373. $rows = $arrcode['num_rows'];
  15374. $cols = $arrcode['num_cols'];
  15375. if (($rows <= 0) || ($cols <= 0)) {
  15376. $this->Error('Error in 2D barcode string');
  15377. }
  15378. // module width and height
  15379. $mw = $style['module_width'];
  15380. $mh = $style['module_height'];
  15381. if (($mw <= 0) OR ($mh <= 0)) {
  15382. $this->Error('Error in 2D barcode string');
  15383. }
  15384. // get max dimensions
  15385. if ($this->rtl) {
  15386. $maxw = $x - $this->lMargin;
  15387. } else {
  15388. $maxw = $this->w - $this->rMargin - $x;
  15389. }
  15390. $maxh = ($this->h - $this->tMargin - $this->bMargin);
  15391. $ratioHW = ((($rows * $mh) + $hpad) / (($cols * $mw) + $vpad));
  15392. $ratioWH = ((($cols * $mw) + $vpad) / (($rows * $mh) + $hpad));
  15393. if (!$distort) {
  15394. if (($maxw * $ratioHW) > $maxh) {
  15395. $maxw = $maxh * $ratioWH;
  15396. }
  15397. if (($maxh * $ratioWH) > $maxw) {
  15398. $maxh = $maxw * $ratioHW;
  15399. }
  15400. }
  15401. // set maximum dimensions
  15402. if ($w > $maxw) {
  15403. $w = $maxw;
  15404. }
  15405. if ($h > $maxh) {
  15406. $h = $maxh;
  15407. }
  15408. // set dimensions
  15409. if ((($w === '') OR ($w <= 0)) AND (($h === '') OR ($h <= 0))) {
  15410. $w = ($cols + $hpad) * ($mw / $this->k);
  15411. $h = ($rows + $vpad) * ($mh / $this->k);
  15412. } elseif (($w === '') OR ($w <= 0)) {
  15413. $w = $h * $ratioWH;
  15414. } elseif (($h === '') OR ($h <= 0)) {
  15415. $h = $w * $ratioHW;
  15416. }
  15417. // barcode size (excluding padding)
  15418. $bw = ($w * $cols) / ($cols + $hpad);
  15419. $bh = ($h * $rows) / ($rows + $vpad);
  15420. // dimension of single barcode cell unit
  15421. $cw = $bw / $cols;
  15422. $ch = $bh / $rows;
  15423. if (!$distort) {
  15424. if (($cw / $ch) > ($mw / $mh)) {
  15425. // correct horizontal distortion
  15426. $cw = $ch * $mw / $mh;
  15427. $bw = $cw * $cols;
  15428. $style['hpadding'] = ($w - $bw) / (2 * $cw);
  15429. } else {
  15430. // correct vertical distortion
  15431. $ch = $cw * $mh / $mw;
  15432. $bh = $ch * $rows;
  15433. $style['vpadding'] = ($h - $bh) / (2 * $ch);
  15434. }
  15435. }
  15436. // fit the barcode on available space
  15437. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
  15438. // set alignment
  15439. $this->img_rb_y = $y + $h;
  15440. // set alignment
  15441. if ($this->rtl) {
  15442. if ($style['position'] == 'L') {
  15443. $xpos = $this->lMargin;
  15444. } elseif ($style['position'] == 'C') {
  15445. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  15446. } elseif ($style['position'] == 'R') {
  15447. $xpos = $this->w - $this->rMargin - $w;
  15448. } else {
  15449. $xpos = $x - $w;
  15450. }
  15451. $this->img_rb_x = $xpos;
  15452. } else {
  15453. if ($style['position'] == 'L') {
  15454. $xpos = $this->lMargin;
  15455. } elseif ($style['position'] == 'C') {
  15456. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  15457. } elseif ($style['position'] == 'R') {
  15458. $xpos = $this->w - $this->rMargin - $w;
  15459. } else {
  15460. $xpos = $x;
  15461. }
  15462. $this->img_rb_x = $xpos + $w;
  15463. }
  15464. $xstart = $xpos + ($style['hpadding'] * $cw);
  15465. $ystart = $y + ($style['vpadding'] * $ch);
  15466. // barcode is always printed in LTR direction
  15467. $tempRTL = $this->rtl;
  15468. $this->rtl = false;
  15469. // print background color
  15470. if ($style['bgcolor']) {
  15471. $this->Rect($xpos, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  15472. } elseif ($style['border']) {
  15473. $this->Rect($xpos, $y, $w, $h, 'D');
  15474. }
  15475. // set foreground color
  15476. $this->SetDrawColorArray($style['fgcolor']);
  15477. // print barcode cells
  15478. // for each row
  15479. for ($r = 0; $r < $rows; ++$r) {
  15480. $xr = $xstart;
  15481. // for each column
  15482. for ($c = 0; $c < $cols; ++$c) {
  15483. if ($arrcode['bcode'][$r][$c] == 1) {
  15484. // draw a single barcode cell
  15485. $this->Rect($xr, $ystart, $cw, $ch, 'F', array(), $style['fgcolor']);
  15486. }
  15487. $xr += $cw;
  15488. }
  15489. $ystart += $ch;
  15490. }
  15491. // restore original direction
  15492. $this->rtl = $tempRTL;
  15493. // restore previous settings
  15494. $this->setGraphicVars($gvars);
  15495. // set pointer to align the next text/objects
  15496. switch ($align) {
  15497. case 'T':{
  15498. $this->y = $y;
  15499. $this->x = $this->img_rb_x;
  15500. break;
  15501. }
  15502. case 'M':{
  15503. $this->y = $y + round($h/2);
  15504. $this->x = $this->img_rb_x;
  15505. break;
  15506. }
  15507. case 'B':{
  15508. $this->y = $this->img_rb_y;
  15509. $this->x = $this->img_rb_x;
  15510. break;
  15511. }
  15512. case 'N':{
  15513. $this->SetY($this->img_rb_y);
  15514. break;
  15515. }
  15516. default:{
  15517. break;
  15518. }
  15519. }
  15520. $this->endlinex = $this->img_rb_x;
  15521. }
  15522. /**
  15523. * Returns an array containing current margins:
  15524. * <ul>
  15525. <li>$ret['left'] = left margin</li>
  15526. <li>$ret['right'] = right margin</li>
  15527. <li>$ret['top'] = top margin</li>
  15528. <li>$ret['bottom'] = bottom margin</li>
  15529. <li>$ret['header'] = header margin</li>
  15530. <li>$ret['footer'] = footer margin</li>
  15531. <li>$ret['cell'] = cell padding array</li>
  15532. <li>$ret['padding_left'] = cell left padding</li>
  15533. <li>$ret['padding_top'] = cell top padding</li>
  15534. <li>$ret['padding_right'] = cell right padding</li>
  15535. <li>$ret['padding_bottom'] = cell bottom padding</li>
  15536. * </ul>
  15537. * @return array containing all margins measures
  15538. * @public
  15539. * @since 3.2.000 (2008-06-23)
  15540. */
  15541. public function getMargins()
  15542. {
  15543. $ret = array(
  15544. 'left' => $this->lMargin,
  15545. 'right' => $this->rMargin,
  15546. 'top' => $this->tMargin,
  15547. 'bottom' => $this->bMargin,
  15548. 'header' => $this->header_margin,
  15549. 'footer' => $this->footer_margin,
  15550. 'cell' => $this->cell_padding,
  15551. 'padding_left' => $this->cell_padding['L'],
  15552. 'padding_top' => $this->cell_padding['T'],
  15553. 'padding_right' => $this->cell_padding['R'],
  15554. 'padding_bottom' => $this->cell_padding['B']
  15555. );
  15556. return $ret;
  15557. }
  15558. /**
  15559. * Returns an array containing original margins:
  15560. * <ul>
  15561. <li>$ret['left'] = left margin</li>
  15562. <li>$ret['right'] = right margin</li>
  15563. * </ul>
  15564. * @return array containing all margins measures
  15565. * @public
  15566. * @since 4.0.012 (2008-07-24)
  15567. */
  15568. public function getOriginalMargins()
  15569. {
  15570. $ret = array(
  15571. 'left' => $this->original_lMargin,
  15572. 'right' => $this->original_rMargin
  15573. );
  15574. return $ret;
  15575. }
  15576. /**
  15577. * Returns the current font size.
  15578. * @return current font size
  15579. * @public
  15580. * @since 3.2.000 (2008-06-23)
  15581. */
  15582. public function getFontSize()
  15583. {
  15584. return $this->FontSize;
  15585. }
  15586. /**
  15587. * Returns the current font size in points unit.
  15588. * @return current font size in points unit
  15589. * @public
  15590. * @since 3.2.000 (2008-06-23)
  15591. */
  15592. public function getFontSizePt()
  15593. {
  15594. return $this->FontSizePt;
  15595. }
  15596. /**
  15597. * Returns the current font family name.
  15598. * @return string current font family name
  15599. * @public
  15600. * @since 4.3.008 (2008-12-05)
  15601. */
  15602. public function getFontFamily()
  15603. {
  15604. return $this->FontFamily;
  15605. }
  15606. /**
  15607. * Returns the current font style.
  15608. * @return string current font style
  15609. * @public
  15610. * @since 4.3.008 (2008-12-05)
  15611. */
  15612. public function getFontStyle()
  15613. {
  15614. return $this->FontStyle;
  15615. }
  15616. /**
  15617. * Cleanup HTML code (requires HTML Tidy library).
  15618. * @param $html (string) htmlcode to fix
  15619. * @param $default_css (string) CSS commands to add
  15620. * @param $tagvs (array) parameters for setHtmlVSpace method
  15621. * @param $tidy_options (array) options for tidy_parse_string function
  15622. * @return string XHTML code cleaned up
  15623. * @author Nicola Asuni
  15624. * @public
  15625. * @since 5.9.017 (2010-11-16)
  15626. * @see setHtmlVSpace()
  15627. */
  15628. public function fixHTMLCode($html, $default_css = '', $tagvs = '', $tidy_options = '')
  15629. {
  15630. return TCPDF_STATIC::fixHTMLCode($html, $default_css, $tagvs, $tidy_options, $this->tagvspaces);
  15631. }
  15632. /**
  15633. * Returns the border width from CSS property
  15634. * @param $width (string) border width
  15635. * @return int with in user units
  15636. * @protected
  15637. * @since 5.7.000 (2010-08-02)
  15638. */
  15639. protected function getCSSBorderWidth($width)
  15640. {
  15641. if ($width == 'thin') {
  15642. $width = (2 / $this->k);
  15643. } elseif ($width == 'medium') {
  15644. $width = (4 / $this->k);
  15645. } elseif ($width == 'thick') {
  15646. $width = (6 / $this->k);
  15647. } else {
  15648. $width = $this->getHTMLUnitToUnits($width, 1, 'px', false);
  15649. }
  15650. return $width;
  15651. }
  15652. /**
  15653. * Returns the border dash style from CSS property
  15654. * @param $style (string) border style to convert
  15655. * @return int sash style (return -1 in case of none or hidden border)
  15656. * @protected
  15657. * @since 5.7.000 (2010-08-02)
  15658. */
  15659. protected function getCSSBorderDashStyle($style)
  15660. {
  15661. switch (strtolower($style)) {
  15662. case 'none':
  15663. case 'hidden': {
  15664. $dash = -1;
  15665. break;
  15666. }
  15667. case 'dotted': {
  15668. $dash = 1;
  15669. break;
  15670. }
  15671. case 'dashed': {
  15672. $dash = 3;
  15673. break;
  15674. }
  15675. case 'double':
  15676. case 'groove':
  15677. case 'ridge':
  15678. case 'inset':
  15679. case 'outset':
  15680. case 'solid':
  15681. default: {
  15682. $dash = 0;
  15683. break;
  15684. }
  15685. }
  15686. return $dash;
  15687. }
  15688. /**
  15689. * Returns the border style array from CSS border properties
  15690. * @param $cssborder (string) border properties
  15691. * @return array containing border properties
  15692. * @protected
  15693. * @since 5.7.000 (2010-08-02)
  15694. */
  15695. protected function getCSSBorderStyle($cssborder)
  15696. {
  15697. $bprop = preg_split('/[\s]+/', trim($cssborder));
  15698. $border = array(); // value to be returned
  15699. switch (count($bprop)) {
  15700. case 3: {
  15701. $width = $bprop[0];
  15702. $style = $bprop[1];
  15703. $color = $bprop[2];
  15704. break;
  15705. }
  15706. case 2: {
  15707. $width = 'medium';
  15708. $style = $bprop[0];
  15709. $color = $bprop[1];
  15710. break;
  15711. }
  15712. case 1: {
  15713. $width = 'medium';
  15714. $style = $bprop[0];
  15715. $color = 'black';
  15716. break;
  15717. }
  15718. default: {
  15719. $width = 'medium';
  15720. $style = 'solid';
  15721. $color = 'black';
  15722. break;
  15723. }
  15724. }
  15725. if ($style == 'none') {
  15726. return array();
  15727. }
  15728. $border['cap'] = 'square';
  15729. $border['join'] = 'miter';
  15730. $border['dash'] = $this->getCSSBorderDashStyle($style);
  15731. if ($border['dash'] < 0) {
  15732. return array();
  15733. }
  15734. $border['width'] = $this->getCSSBorderWidth($width);
  15735. $border['color'] = TCPDF_COLORS::convertHTMLColorToDec($color, $this->spot_colors);
  15736. return $border;
  15737. }
  15738. /**
  15739. * Get the internal Cell padding from CSS attribute.
  15740. * @param $csspadding (string) padding properties
  15741. * @param $width (float) width of the containing element
  15742. * @return array of cell paddings
  15743. * @public
  15744. * @since 5.9.000 (2010-10-04)
  15745. */
  15746. public function getCSSPadding($csspadding, $width = 0)
  15747. {
  15748. $padding = preg_split('/[\s]+/', trim($csspadding));
  15749. $cell_padding = array(); // value to be returned
  15750. switch (count($padding)) {
  15751. case 4: {
  15752. $cell_padding['T'] = $padding[0];
  15753. $cell_padding['R'] = $padding[1];
  15754. $cell_padding['B'] = $padding[2];
  15755. $cell_padding['L'] = $padding[3];
  15756. break;
  15757. }
  15758. case 3: {
  15759. $cell_padding['T'] = $padding[0];
  15760. $cell_padding['R'] = $padding[1];
  15761. $cell_padding['B'] = $padding[2];
  15762. $cell_padding['L'] = $padding[1];
  15763. break;
  15764. }
  15765. case 2: {
  15766. $cell_padding['T'] = $padding[0];
  15767. $cell_padding['R'] = $padding[1];
  15768. $cell_padding['B'] = $padding[0];
  15769. $cell_padding['L'] = $padding[1];
  15770. break;
  15771. }
  15772. case 1: {
  15773. $cell_padding['T'] = $padding[0];
  15774. $cell_padding['R'] = $padding[0];
  15775. $cell_padding['B'] = $padding[0];
  15776. $cell_padding['L'] = $padding[0];
  15777. break;
  15778. }
  15779. default: {
  15780. return $this->cell_padding;
  15781. }
  15782. }
  15783. if ($width == 0) {
  15784. $width = $this->w - $this->lMargin - $this->rMargin;
  15785. }
  15786. $cell_padding['T'] = $this->getHTMLUnitToUnits($cell_padding['T'], $width, 'px', false);
  15787. $cell_padding['R'] = $this->getHTMLUnitToUnits($cell_padding['R'], $width, 'px', false);
  15788. $cell_padding['B'] = $this->getHTMLUnitToUnits($cell_padding['B'], $width, 'px', false);
  15789. $cell_padding['L'] = $this->getHTMLUnitToUnits($cell_padding['L'], $width, 'px', false);
  15790. return $cell_padding;
  15791. }
  15792. /**
  15793. * Get the internal Cell margin from CSS attribute.
  15794. * @param $cssmargin (string) margin properties
  15795. * @param $width (float) width of the containing element
  15796. * @return array of cell margins
  15797. * @public
  15798. * @since 5.9.000 (2010-10-04)
  15799. */
  15800. public function getCSSMargin($cssmargin, $width = 0)
  15801. {
  15802. $margin = preg_split('/[\s]+/', trim($cssmargin));
  15803. $cell_margin = array(); // value to be returned
  15804. switch (count($margin)) {
  15805. case 4: {
  15806. $cell_margin['T'] = $margin[0];
  15807. $cell_margin['R'] = $margin[1];
  15808. $cell_margin['B'] = $margin[2];
  15809. $cell_margin['L'] = $margin[3];
  15810. break;
  15811. }
  15812. case 3: {
  15813. $cell_margin['T'] = $margin[0];
  15814. $cell_margin['R'] = $margin[1];
  15815. $cell_margin['B'] = $margin[2];
  15816. $cell_margin['L'] = $margin[1];
  15817. break;
  15818. }
  15819. case 2: {
  15820. $cell_margin['T'] = $margin[0];
  15821. $cell_margin['R'] = $margin[1];
  15822. $cell_margin['B'] = $margin[0];
  15823. $cell_margin['L'] = $margin[1];
  15824. break;
  15825. }
  15826. case 1: {
  15827. $cell_margin['T'] = $margin[0];
  15828. $cell_margin['R'] = $margin[0];
  15829. $cell_margin['B'] = $margin[0];
  15830. $cell_margin['L'] = $margin[0];
  15831. break;
  15832. }
  15833. default: {
  15834. return $this->cell_margin;
  15835. }
  15836. }
  15837. if ($width == 0) {
  15838. $width = $this->w - $this->lMargin - $this->rMargin;
  15839. }
  15840. $cell_margin['T'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['T']), $width, 'px', false);
  15841. $cell_margin['R'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['R']), $width, 'px', false);
  15842. $cell_margin['B'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['B']), $width, 'px', false);
  15843. $cell_margin['L'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['L']), $width, 'px', false);
  15844. return $cell_margin;
  15845. }
  15846. /**
  15847. * Get the border-spacing from CSS attribute.
  15848. * @param $cssbspace (string) border-spacing CSS properties
  15849. * @param $width (float) width of the containing element
  15850. * @return array of border spacings
  15851. * @public
  15852. * @since 5.9.010 (2010-10-27)
  15853. */
  15854. public function getCSSBorderMargin($cssbspace, $width = 0)
  15855. {
  15856. $space = preg_split('/[\s]+/', trim($cssbspace));
  15857. $border_spacing = array(); // value to be returned
  15858. switch (count($space)) {
  15859. case 2: {
  15860. $border_spacing['H'] = $space[0];
  15861. $border_spacing['V'] = $space[1];
  15862. break;
  15863. }
  15864. case 1: {
  15865. $border_spacing['H'] = $space[0];
  15866. $border_spacing['V'] = $space[0];
  15867. break;
  15868. }
  15869. default: {
  15870. return array('H' => 0, 'V' => 0);
  15871. }
  15872. }
  15873. if ($width == 0) {
  15874. $width = $this->w - $this->lMargin - $this->rMargin;
  15875. }
  15876. $border_spacing['H'] = $this->getHTMLUnitToUnits($border_spacing['H'], $width, 'px', false);
  15877. $border_spacing['V'] = $this->getHTMLUnitToUnits($border_spacing['V'], $width, 'px', false);
  15878. return $border_spacing;
  15879. }
  15880. /**
  15881. * Returns the letter-spacing value from CSS value
  15882. * @param $spacing (string) letter-spacing value
  15883. * @param $parent (float) font spacing (tracking) value of the parent element
  15884. * @return float quantity to increases or decreases the space between characters in a text.
  15885. * @protected
  15886. * @since 5.9.000 (2010-10-02)
  15887. */
  15888. protected function getCSSFontSpacing($spacing, $parent = 0)
  15889. {
  15890. $val = 0; // value to be returned
  15891. $spacing = trim($spacing);
  15892. switch ($spacing) {
  15893. case 'normal': {
  15894. $val = 0;
  15895. break;
  15896. }
  15897. case 'inherit': {
  15898. if ($parent == 'normal') {
  15899. $val = 0;
  15900. } else {
  15901. $val = $parent;
  15902. }
  15903. break;
  15904. }
  15905. default: {
  15906. $val = $this->getHTMLUnitToUnits($spacing, 0, 'px', false);
  15907. }
  15908. }
  15909. return $val;
  15910. }
  15911. /**
  15912. * Returns the percentage of font stretching from CSS value
  15913. * @param $stretch (string) stretch mode
  15914. * @param $parent (float) stretch value of the parent element
  15915. * @return float font stretching percentage
  15916. * @protected
  15917. * @since 5.9.000 (2010-10-02)
  15918. */
  15919. protected function getCSSFontStretching($stretch, $parent = 100)
  15920. {
  15921. $val = 100; // value to be returned
  15922. $stretch = trim($stretch);
  15923. switch ($stretch) {
  15924. case 'ultra-condensed': {
  15925. $val = 40;
  15926. break;
  15927. }
  15928. case 'extra-condensed': {
  15929. $val = 55;
  15930. break;
  15931. }
  15932. case 'condensed': {
  15933. $val = 70;
  15934. break;
  15935. }
  15936. case 'semi-condensed': {
  15937. $val = 85;
  15938. break;
  15939. }
  15940. case 'normal': {
  15941. $val = 100;
  15942. break;
  15943. }
  15944. case 'semi-expanded': {
  15945. $val = 115;
  15946. break;
  15947. }
  15948. case 'expanded': {
  15949. $val = 130;
  15950. break;
  15951. }
  15952. case 'extra-expanded': {
  15953. $val = 145;
  15954. break;
  15955. }
  15956. case 'ultra-expanded': {
  15957. $val = 160;
  15958. break;
  15959. }
  15960. case 'wider': {
  15961. $val = ($parent + 10);
  15962. break;
  15963. }
  15964. case 'narrower': {
  15965. $val = ($parent - 10);
  15966. break;
  15967. }
  15968. case 'inherit': {
  15969. if ($parent == 'normal') {
  15970. $val = 100;
  15971. } else {
  15972. $val = $parent;
  15973. }
  15974. break;
  15975. }
  15976. default: {
  15977. $val = $this->getHTMLUnitToUnits($stretch, 100, '%', false);
  15978. }
  15979. }
  15980. return $val;
  15981. }
  15982. /**
  15983. * Convert HTML string containing font size value to points
  15984. * @param $val (string) String containing font size value and unit.
  15985. * @param $refsize (float) Reference font size in points.
  15986. * @param $parent_size (float) Parent font size in points.
  15987. * @param $defaultunit (string) Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  15988. * @return float value in points
  15989. * @public
  15990. */
  15991. public function getHTMLFontUnits($val, $refsize = 12, $parent_size = 12, $defaultunit = 'pt')
  15992. {
  15993. $refsize = TCPDF_FONTS::getFontRefSize($refsize);
  15994. $parent_size = TCPDF_FONTS::getFontRefSize($parent_size, $refsize);
  15995. switch ($val) {
  15996. case 'xx-small': {
  15997. $size = ($refsize - 4);
  15998. break;
  15999. }
  16000. case 'x-small': {
  16001. $size = ($refsize - 3);
  16002. break;
  16003. }
  16004. case 'small': {
  16005. $size = ($refsize - 2);
  16006. break;
  16007. }
  16008. case 'medium': {
  16009. $size = $refsize;
  16010. break;
  16011. }
  16012. case 'large': {
  16013. $size = ($refsize + 2);
  16014. break;
  16015. }
  16016. case 'x-large': {
  16017. $size = ($refsize + 4);
  16018. break;
  16019. }
  16020. case 'xx-large': {
  16021. $size = ($refsize + 6);
  16022. break;
  16023. }
  16024. case 'smaller': {
  16025. $size = ($parent_size - 3);
  16026. break;
  16027. }
  16028. case 'larger': {
  16029. $size = ($parent_size + 3);
  16030. break;
  16031. }
  16032. default: {
  16033. $size = $this->getHTMLUnitToUnits($val, $parent_size, $defaultunit, true);
  16034. }
  16035. }
  16036. return $size;
  16037. }
  16038. /**
  16039. * Returns the HTML DOM array.
  16040. * @param $html (string) html code
  16041. * @return array
  16042. * @protected
  16043. * @since 3.2.000 (2008-06-20)
  16044. */
  16045. protected function getHtmlDomArray($html)
  16046. {
  16047. // array of CSS styles ( selector => properties).
  16048. $css = array();
  16049. // get CSS array defined at previous call
  16050. $matches = array();
  16051. if (preg_match_all('/<cssarray>([^\<]*)<\/cssarray>/isU', $html, $matches) > 0) {
  16052. if (isset($matches[1][0])) {
  16053. $css = array_merge($css, json_decode($this->unhtmlentities($matches[1][0]), true));
  16054. }
  16055. $html = preg_replace('/<cssarray>(.*?)<\/cssarray>/isU', '', $html);
  16056. }
  16057. // extract external CSS files
  16058. $matches = array();
  16059. if (preg_match_all('/<link([^\>]*)>/isU', $html, $matches) > 0) {
  16060. foreach ($matches[1] as $key => $link) {
  16061. $type = array();
  16062. if (preg_match('/type[\s]*=[\s]*"text\/css"/', $link, $type)) {
  16063. $type = array();
  16064. preg_match('/media[\s]*=[\s]*"([^"]*)"/', $link, $type);
  16065. // get 'all' and 'print' media, other media types are discarded
  16066. // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  16067. if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
  16068. $type = array();
  16069. if (preg_match('/href[\s]*=[\s]*"([^"]*)"/', $link, $type) > 0) {
  16070. // read CSS data file
  16071. $cssdata = TCPDF_STATIC::fileGetContents(trim($type[1]));
  16072. if (($cssdata !== false) AND (strlen($cssdata) > 0)) {
  16073. $css = array_merge($css, TCPDF_STATIC::extractCSSproperties($cssdata));
  16074. }
  16075. }
  16076. }
  16077. }
  16078. }
  16079. }
  16080. // extract style tags
  16081. $matches = array();
  16082. if (preg_match_all('/<style([^\>]*)>([^\<]*)<\/style>/isU', $html, $matches) > 0) {
  16083. foreach ($matches[1] as $key => $media) {
  16084. $type = array();
  16085. preg_match('/media[\s]*=[\s]*"([^"]*)"/', $media, $type);
  16086. // get 'all' and 'print' media, other media types are discarded
  16087. // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  16088. if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
  16089. $cssdata = $matches[2][$key];
  16090. $css = array_merge($css, TCPDF_STATIC::extractCSSproperties($cssdata));
  16091. }
  16092. }
  16093. }
  16094. // create a special tag to contain the CSS array (used for table content)
  16095. $csstagarray = '<cssarray>'.htmlentities(json_encode($css)).'</cssarray>';
  16096. // remove head and style blocks
  16097. $html = preg_replace('/<head([^\>]*)>(.*?)<\/head>/siU', '', $html);
  16098. $html = preg_replace('/<style([^\>]*)>([^\<]*)<\/style>/isU', '', $html);
  16099. // define block tags
  16100. $blocktags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table','tr','td');
  16101. // define self-closing tags
  16102. $selfclosingtags = array('area','base','basefont','br','hr','input','img','link','meta');
  16103. // remove all unsupported tags (the line below lists all supported tags)
  16104. $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>');
  16105. //replace some blank characters
  16106. $html = preg_replace('/<pre/', '<xre', $html); // preserve pre tag
  16107. $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);
  16108. $html = preg_replace('@(\r\n|\r)@', "\n", $html);
  16109. $repTable = array("\t" => ' ', "\0" => ' ', "\x0B" => ' ', "\\" => "\\\\");
  16110. $html = strtr($html, $repTable);
  16111. $offset = 0;
  16112. while (($offset < strlen($html)) AND ($pos = strpos($html, '</pre>', $offset)) !== false) {
  16113. $html_a = substr($html, 0, $offset);
  16114. $html_b = substr($html, $offset, ($pos - $offset + 6));
  16115. while (preg_match("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", $html_b)) {
  16116. // preserve newlines on <pre> tag
  16117. $html_b = preg_replace("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", "<xre\\1>\\2<br />\\3</pre>", $html_b);
  16118. }
  16119. while (preg_match("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], $html_b)) {
  16120. // preserve spaces on <pre> tag
  16121. $html_b = preg_replace("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], "<xre\\1>\\2&nbsp;\\3</pre>", $html_b);
  16122. }
  16123. $html = $html_a.$html_b.substr($html, $pos + 6);
  16124. $offset = strlen($html_a.$html_b);
  16125. }
  16126. $offset = 0;
  16127. while (($offset < strlen($html)) AND ($pos = strpos($html, '</textarea>', $offset)) !== false) {
  16128. $html_a = substr($html, 0, $offset);
  16129. $html_b = substr($html, $offset, ($pos - $offset + 11));
  16130. while (preg_match("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", $html_b)) {
  16131. // preserve newlines on <textarea> tag
  16132. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", "<textarea\\1>\\2<TBR>\\3</textarea>", $html_b);
  16133. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)[\"](.*?)</textarea>'si", "<textarea\\1>\\2''\\3</textarea>", $html_b);
  16134. }
  16135. $html = $html_a.$html_b.substr($html, $pos + 11);
  16136. $offset = strlen($html_a.$html_b);
  16137. }
  16138. $html = preg_replace('/([\s]*)<option/si', '<option', $html);
  16139. $html = preg_replace('/<\/option>([\s]*)/si', '</option>', $html);
  16140. $offset = 0;
  16141. while (($offset < strlen($html)) AND ($pos = strpos($html, '</option>', $offset)) !== false) {
  16142. $html_a = substr($html, 0, $offset);
  16143. $html_b = substr($html, $offset, ($pos - $offset + 9));
  16144. while (preg_match("'<option([^\>]*)>(.*?)</option>'si", $html_b)) {
  16145. $html_b = preg_replace("'<option([\s]+)value=\"([^\"]*)\"([^\>]*)>(.*?)</option>'si", "\\2#!TaB!#\\4#!NwL!#", $html_b);
  16146. $html_b = preg_replace("'<option([^\>]*)>(.*?)</option>'si", "\\2#!NwL!#", $html_b);
  16147. }
  16148. $html = $html_a.$html_b.substr($html, $pos + 9);
  16149. $offset = strlen($html_a.$html_b);
  16150. }
  16151. if (preg_match("'</select'si", $html)) {
  16152. $html = preg_replace("'<select([^\>]*)>'si", "<select\\1 opt=\"", $html);
  16153. $html = preg_replace("'#!NwL!#</select>'si", "\" />", $html);
  16154. }
  16155. $html = str_replace("\n", ' ', $html);
  16156. // restore textarea newlines
  16157. $html = str_replace('<TBR>', "\n", $html);
  16158. // remove extra spaces from code
  16159. $html = preg_replace('/[\s]+<\/(table|tr|ul|ol|dl)>/', '</\\1>', $html);
  16160. $html = preg_replace('/'.$this->re_space['p'].'+<\/(td|th|li|dt|dd)>/'.$this->re_space['m'], '</\\1>', $html);
  16161. $html = preg_replace('/[\s]+<(tr|td|th|li|dt|dd)/', '<\\1', $html);
  16162. $html = preg_replace('/'.$this->re_space['p'].'+<(ul|ol|dl|br)/'.$this->re_space['m'], '<\\1', $html);
  16163. $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);
  16164. $html = preg_replace('/<\/(td|th)>/', '<marker style="font-size:0"/></\\1>', $html);
  16165. $html = preg_replace('/<\/table>([\s]*)<marker style="font-size:0"\/>/', '</table>', $html);
  16166. $html = preg_replace('/'.$this->re_space['p'].'+<img/'.$this->re_space['m'], chr(32).'<img', $html);
  16167. $html = preg_replace('/<img([^\>]*)>[\s]+([^\<])/xi', '<img\\1>&nbsp;\\2', $html);
  16168. $html = preg_replace('/<img([^\>]*)>/xi', '<img\\1><span><marker style="font-size:0"/></span>', $html);
  16169. $html = preg_replace('/<xre/', '<pre', $html); // restore pre tag
  16170. $html = preg_replace('/<textarea([^\>]*)>([^\<]*)<\/textarea>/xi', '<textarea\\1 value="\\2" />', $html);
  16171. $html = preg_replace('/<li([^\>]*)><\/li>/', '<li\\1>&nbsp;</li>', $html);
  16172. $html = preg_replace('/<li([^\>]*)>'.$this->re_space['p'].'*<img/'.$this->re_space['m'], '<li\\1><font size="1">&nbsp;</font><img', $html);
  16173. $html = preg_replace('/<([^\>\/]*)>[\s]/', '<\\1>&nbsp;', $html); // preserve some spaces
  16174. $html = preg_replace('/[\s]<\/([^\>]*)>/', '&nbsp;</\\1>', $html); // preserve some spaces
  16175. $html = preg_replace('/<su([bp])/', '<zws/><su\\1', $html); // fix sub/sup alignment
  16176. $html = preg_replace('/<\/su([bp])>/', '</su\\1><zws/>', $html); // fix sub/sup alignment
  16177. $html = preg_replace('/'.$this->re_space['p'].'+/'.$this->re_space['m'], chr(32), $html); // replace multiple spaces with a single space
  16178. // trim string
  16179. $html = $this->stringTrim($html);
  16180. // fix br tag after li
  16181. $html = preg_replace('/<li><br([^\>]*)>/', '<li> <br\\1>', $html);
  16182. // fix first image tag alignment
  16183. $html = preg_replace('/^<img/', '<span style="font-size:0"><br /></span> <img', $html, 1);
  16184. // pattern for generic tag
  16185. $tagpattern = '/(<[^>]+>)/';
  16186. // explodes the string
  16187. $a = preg_split($tagpattern, $html, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  16188. // count elements
  16189. $maxel = count($a);
  16190. $elkey = 0;
  16191. $key = 0;
  16192. // create an array of elements
  16193. $dom = array();
  16194. $dom[$key] = array();
  16195. // set inheritable properties fot the first void element
  16196. // 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
  16197. $dom[$key]['tag'] = false;
  16198. $dom[$key]['block'] = false;
  16199. $dom[$key]['value'] = '';
  16200. $dom[$key]['parent'] = 0;
  16201. $dom[$key]['hide'] = false;
  16202. $dom[$key]['fontname'] = $this->FontFamily;
  16203. $dom[$key]['fontstyle'] = $this->FontStyle;
  16204. $dom[$key]['fontsize'] = $this->FontSizePt;
  16205. $dom[$key]['font-stretch'] = $this->font_stretching;
  16206. $dom[$key]['letter-spacing'] = $this->font_spacing;
  16207. $dom[$key]['stroke'] = $this->textstrokewidth;
  16208. $dom[$key]['fill'] = (($this->textrendermode % 2) == 0);
  16209. $dom[$key]['clip'] = ($this->textrendermode > 3);
  16210. $dom[$key]['line-height'] = $this->cell_height_ratio;
  16211. $dom[$key]['bgcolor'] = false;
  16212. $dom[$key]['fgcolor'] = $this->fgcolor; // color
  16213. $dom[$key]['strokecolor'] = $this->strokecolor;
  16214. $dom[$key]['align'] = '';
  16215. $dom[$key]['listtype'] = '';
  16216. $dom[$key]['text-indent'] = 0;
  16217. $dom[$key]['text-transform'] = '';
  16218. $dom[$key]['border'] = array();
  16219. $dom[$key]['dir'] = $this->rtl?'rtl':'ltr';
  16220. $thead = false; // true when we are inside the THEAD tag
  16221. ++$key;
  16222. $level = array();
  16223. array_push($level, 0); // root
  16224. while ($elkey < $maxel) {
  16225. $dom[$key] = array();
  16226. $element = $a[$elkey];
  16227. $dom[$key]['elkey'] = $elkey;
  16228. if (preg_match($tagpattern, $element)) {
  16229. // html tag
  16230. $element = substr($element, 1, -1);
  16231. // get tag name
  16232. preg_match('/[\/]?([a-zA-Z0-9]*)/', $element, $tag);
  16233. $tagname = strtolower($tag[1]);
  16234. // check if we are inside a table header
  16235. if ($tagname == 'thead') {
  16236. if ($element[0] == '/') {
  16237. $thead = false;
  16238. } else {
  16239. $thead = true;
  16240. }
  16241. ++$elkey;
  16242. continue;
  16243. }
  16244. $dom[$key]['tag'] = true;
  16245. $dom[$key]['value'] = $tagname;
  16246. if (in_array($dom[$key]['value'], $blocktags)) {
  16247. $dom[$key]['block'] = true;
  16248. } else {
  16249. $dom[$key]['block'] = false;
  16250. }
  16251. if ($element[0] == '/') {
  16252. // *** closing html tag
  16253. $dom[$key]['opening'] = false;
  16254. $dom[$key]['parent'] = end($level);
  16255. array_pop($level);
  16256. $dom[$key]['hide'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['hide'];
  16257. $dom[$key]['fontname'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontname'];
  16258. $dom[$key]['fontstyle'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontstyle'];
  16259. $dom[$key]['fontsize'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize'];
  16260. $dom[$key]['font-stretch'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['font-stretch'];
  16261. $dom[$key]['letter-spacing'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['letter-spacing'];
  16262. $dom[$key]['stroke'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['stroke'];
  16263. $dom[$key]['fill'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fill'];
  16264. $dom[$key]['clip'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['clip'];
  16265. $dom[$key]['line-height'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['line-height'];
  16266. $dom[$key]['bgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor'];
  16267. $dom[$key]['fgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor'];
  16268. $dom[$key]['strokecolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['strokecolor'];
  16269. $dom[$key]['align'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['align'];
  16270. $dom[$key]['text-transform'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['text-transform'];
  16271. $dom[$key]['dir'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['dir'];
  16272. if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) {
  16273. $dom[$key]['listtype'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'];
  16274. }
  16275. // set the number of columns in table tag
  16276. if (($dom[$key]['value'] == 'tr') AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) {
  16277. $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'] = $dom[($dom[$key]['parent'])]['cols'];
  16278. }
  16279. if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  16280. $dom[($dom[$key]['parent'])]['content'] = $csstagarray;
  16281. for ($i = ($dom[$key]['parent'] + 1); $i < $key; ++$i) {
  16282. $dom[($dom[$key]['parent'])]['content'] .= stripslashes($a[$dom[$i]['elkey']]);
  16283. }
  16284. $key = $i;
  16285. // mark nested tables
  16286. $dom[($dom[$key]['parent'])]['content'] = str_replace('<table', '<table nested="true"', $dom[($dom[$key]['parent'])]['content']);
  16287. // remove thead sections from nested tables
  16288. $dom[($dom[$key]['parent'])]['content'] = str_replace('<thead>', '', $dom[($dom[$key]['parent'])]['content']);
  16289. $dom[($dom[$key]['parent'])]['content'] = str_replace('</thead>', '', $dom[($dom[$key]['parent'])]['content']);
  16290. }
  16291. // store header rows on a new table
  16292. if (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['thead'] === true)) {
  16293. if (TCPDF_STATIC::empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) {
  16294. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] = $csstagarray.$a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']];
  16295. }
  16296. for ($i = $dom[$key]['parent']; $i <= $key; ++$i) {
  16297. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] .= $a[$dom[$i]['elkey']];
  16298. }
  16299. if (!isset($dom[($dom[$key]['parent'])]['attribute'])) {
  16300. $dom[($dom[$key]['parent'])]['attribute'] = array();
  16301. }
  16302. // header elements must be always contained in a single page
  16303. $dom[($dom[$key]['parent'])]['attribute']['nobr'] = 'true';
  16304. }
  16305. if (($dom[$key]['value'] == 'table') AND (!TCPDF_STATIC::empty_string($dom[($dom[$key]['parent'])]['thead']))) {
  16306. // remove the nobr attributes from the table header
  16307. $dom[($dom[$key]['parent'])]['thead'] = str_replace(' nobr="true"', '', $dom[($dom[$key]['parent'])]['thead']);
  16308. $dom[($dom[$key]['parent'])]['thead'] .= '</tablehead>';
  16309. }
  16310. } else {
  16311. // *** opening or self-closing html tag
  16312. $dom[$key]['opening'] = true;
  16313. $dom[$key]['parent'] = end($level);
  16314. if ((substr($element, -1, 1) == '/') OR (in_array($dom[$key]['value'], $selfclosingtags))) {
  16315. // self-closing tag
  16316. $dom[$key]['self'] = true;
  16317. } else {
  16318. // opening tag
  16319. array_push($level, $key);
  16320. $dom[$key]['self'] = false;
  16321. }
  16322. // copy some values from parent
  16323. $parentkey = 0;
  16324. if ($key > 0) {
  16325. $parentkey = $dom[$key]['parent'];
  16326. $dom[$key]['hide'] = $dom[$parentkey]['hide'];
  16327. $dom[$key]['fontname'] = $dom[$parentkey]['fontname'];
  16328. $dom[$key]['fontstyle'] = $dom[$parentkey]['fontstyle'];
  16329. $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'];
  16330. $dom[$key]['font-stretch'] = $dom[$parentkey]['font-stretch'];
  16331. $dom[$key]['letter-spacing'] = $dom[$parentkey]['letter-spacing'];
  16332. $dom[$key]['stroke'] = $dom[$parentkey]['stroke'];
  16333. $dom[$key]['fill'] = $dom[$parentkey]['fill'];
  16334. $dom[$key]['clip'] = $dom[$parentkey]['clip'];
  16335. $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
  16336. $dom[$key]['bgcolor'] = $dom[$parentkey]['bgcolor'];
  16337. $dom[$key]['fgcolor'] = $dom[$parentkey]['fgcolor'];
  16338. $dom[$key]['strokecolor'] = $dom[$parentkey]['strokecolor'];
  16339. $dom[$key]['align'] = $dom[$parentkey]['align'];
  16340. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  16341. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  16342. $dom[$key]['text-transform'] = $dom[$parentkey]['text-transform'];
  16343. $dom[$key]['border'] = array();
  16344. $dom[$key]['dir'] = $dom[$parentkey]['dir'];
  16345. }
  16346. // get attributes
  16347. preg_match_all('/([^=\s]*)[\s]*=[\s]*"([^"]*)"/', $element, $attr_array, PREG_PATTERN_ORDER);
  16348. $dom[$key]['attribute'] = array(); // reset attribute array
  16349. foreach ($attr_array[1] as $id => $name) {
  16350. $dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id];
  16351. }
  16352. if (!empty($css)) {
  16353. // merge CSS style to current style
  16354. list($dom[$key]['csssel'], $dom[$key]['cssdata']) = TCPDF_STATIC::getCSSdataArray($dom, $key, $css);
  16355. $dom[$key]['attribute']['style'] = TCPDF_STATIC::getTagStyleFromCSSarray($dom[$key]['cssdata']);
  16356. }
  16357. // split style attributes
  16358. if (isset($dom[$key]['attribute']['style']) AND !empty($dom[$key]['attribute']['style'])) {
  16359. // get style attributes
  16360. preg_match_all('/([^;:\s]*):([^;]*)/', $dom[$key]['attribute']['style'], $style_array, PREG_PATTERN_ORDER);
  16361. $dom[$key]['style'] = array(); // reset style attribute array
  16362. foreach ($style_array[1] as $id => $name) {
  16363. // in case of duplicate attribute the last replace the previous
  16364. $dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]);
  16365. }
  16366. // --- get some style attributes ---
  16367. // text direction
  16368. if (isset($dom[$key]['style']['direction'])) {
  16369. $dom[$key]['dir'] = $dom[$key]['style']['direction'];
  16370. }
  16371. // display
  16372. if (isset($dom[$key]['style']['display'])) {
  16373. $dom[$key]['hide'] = (trim(strtolower($dom[$key]['style']['display'])) == 'none');
  16374. }
  16375. // font family
  16376. if (isset($dom[$key]['style']['font-family'])) {
  16377. $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['style']['font-family']);
  16378. }
  16379. // list-style-type
  16380. if (isset($dom[$key]['style']['list-style-type'])) {
  16381. $dom[$key]['listtype'] = trim(strtolower($dom[$key]['style']['list-style-type']));
  16382. if ($dom[$key]['listtype'] == 'inherit') {
  16383. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  16384. }
  16385. }
  16386. // text-indent
  16387. if (isset($dom[$key]['style']['text-indent'])) {
  16388. $dom[$key]['text-indent'] = $this->getHTMLUnitToUnits($dom[$key]['style']['text-indent']);
  16389. if ($dom[$key]['text-indent'] == 'inherit') {
  16390. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  16391. }
  16392. }
  16393. // text-transform
  16394. if (isset($dom[$key]['style']['text-transform'])) {
  16395. $dom[$key]['text-transform'] = $dom[$key]['style']['text-transform'];
  16396. }
  16397. // font size
  16398. if (isset($dom[$key]['style']['font-size'])) {
  16399. $fsize = trim($dom[$key]['style']['font-size']);
  16400. $dom[$key]['fontsize'] = $this->getHTMLFontUnits($fsize, $dom[0]['fontsize'], $dom[$parentkey]['fontsize'], 'pt');
  16401. }
  16402. // font-stretch
  16403. if (isset($dom[$key]['style']['font-stretch'])) {
  16404. $dom[$key]['font-stretch'] = $this->getCSSFontStretching($dom[$key]['style']['font-stretch'], $dom[$parentkey]['font-stretch']);
  16405. }
  16406. // letter-spacing
  16407. if (isset($dom[$key]['style']['letter-spacing'])) {
  16408. $dom[$key]['letter-spacing'] = $this->getCSSFontSpacing($dom[$key]['style']['letter-spacing'], $dom[$parentkey]['letter-spacing']);
  16409. }
  16410. // line-height (internally is the cell height ratio)
  16411. if (isset($dom[$key]['style']['line-height'])) {
  16412. $lineheight = trim($dom[$key]['style']['line-height']);
  16413. switch ($lineheight) {
  16414. // A normal line height. This is default
  16415. case 'normal': {
  16416. $dom[$key]['line-height'] = $dom[0]['line-height'];
  16417. break;
  16418. }
  16419. case 'inherit': {
  16420. $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
  16421. }
  16422. default: {
  16423. if (is_numeric($lineheight)) {
  16424. // convert to percentage of font height
  16425. $lineheight = ($lineheight * 100).'%';
  16426. }
  16427. $dom[$key]['line-height'] = $this->getHTMLUnitToUnits($lineheight, 1, '%', true);
  16428. if (substr($lineheight, -1) !== '%') {
  16429. if ($dom[$key]['fontsize'] <= 0) {
  16430. $dom[$key]['line-height'] = 1;
  16431. } else {
  16432. $dom[$key]['line-height'] = (($dom[$key]['line-height'] - $this->cell_padding['T'] - $this->cell_padding['B']) / $dom[$key]['fontsize']);
  16433. }
  16434. }
  16435. }
  16436. }
  16437. }
  16438. // font style
  16439. if (isset($dom[$key]['style']['font-weight'])) {
  16440. if (strtolower($dom[$key]['style']['font-weight'][0]) == 'n') {
  16441. if (strpos($dom[$key]['fontstyle'], 'B') !== false) {
  16442. $dom[$key]['fontstyle'] = str_replace('B', '', $dom[$key]['fontstyle']);
  16443. }
  16444. } elseif (strtolower($dom[$key]['style']['font-weight'][0]) == 'b') {
  16445. $dom[$key]['fontstyle'] .= 'B';
  16446. }
  16447. }
  16448. if (isset($dom[$key]['style']['font-style']) AND (strtolower($dom[$key]['style']['font-style'][0]) == 'i')) {
  16449. $dom[$key]['fontstyle'] .= 'I';
  16450. }
  16451. // font color
  16452. if (isset($dom[$key]['style']['color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['style']['color']))) {
  16453. $dom[$key]['fgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['color'], $this->spot_colors);
  16454. } elseif ($dom[$key]['value'] == 'a') {
  16455. $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  16456. }
  16457. // background color
  16458. if (isset($dom[$key]['style']['background-color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['style']['background-color']))) {
  16459. $dom[$key]['bgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['background-color'], $this->spot_colors);
  16460. }
  16461. // text-decoration
  16462. if (isset($dom[$key]['style']['text-decoration'])) {
  16463. $decors = explode(' ', strtolower($dom[$key]['style']['text-decoration']));
  16464. foreach ($decors as $dec) {
  16465. $dec = trim($dec);
  16466. if (!TCPDF_STATIC::empty_string($dec)) {
  16467. if ($dec[0] == 'u') {
  16468. // underline
  16469. $dom[$key]['fontstyle'] .= 'U';
  16470. } elseif ($dec[0] == 'l') {
  16471. // line-through
  16472. $dom[$key]['fontstyle'] .= 'D';
  16473. } elseif ($dec[0] == 'o') {
  16474. // overline
  16475. $dom[$key]['fontstyle'] .= 'O';
  16476. }
  16477. }
  16478. }
  16479. } elseif ($dom[$key]['value'] == 'a') {
  16480. $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  16481. }
  16482. // check for width attribute
  16483. if (isset($dom[$key]['style']['width'])) {
  16484. $dom[$key]['width'] = $dom[$key]['style']['width'];
  16485. }
  16486. // check for height attribute
  16487. if (isset($dom[$key]['style']['height'])) {
  16488. $dom[$key]['height'] = $dom[$key]['style']['height'];
  16489. }
  16490. // check for text alignment
  16491. if (isset($dom[$key]['style']['text-align'])) {
  16492. $dom[$key]['align'] = strtoupper($dom[$key]['style']['text-align'][0]);
  16493. }
  16494. // check for CSS border properties
  16495. if (isset($dom[$key]['style']['border'])) {
  16496. $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border']);
  16497. if (!empty($borderstyle)) {
  16498. $dom[$key]['border']['LTRB'] = $borderstyle;
  16499. }
  16500. }
  16501. if (isset($dom[$key]['style']['border-color'])) {
  16502. $brd_colors = preg_split('/[\s]+/', trim($dom[$key]['style']['border-color']));
  16503. if (isset($brd_colors[3])) {
  16504. $dom[$key]['border']['L']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[3], $this->spot_colors);
  16505. }
  16506. if (isset($brd_colors[1])) {
  16507. $dom[$key]['border']['R']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[1], $this->spot_colors);
  16508. }
  16509. if (isset($brd_colors[0])) {
  16510. $dom[$key]['border']['T']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[0], $this->spot_colors);
  16511. }
  16512. if (isset($brd_colors[2])) {
  16513. $dom[$key]['border']['B']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[2], $this->spot_colors);
  16514. }
  16515. }
  16516. if (isset($dom[$key]['style']['border-width'])) {
  16517. $brd_widths = preg_split('/[\s]+/', trim($dom[$key]['style']['border-width']));
  16518. if (isset($brd_widths[3])) {
  16519. $dom[$key]['border']['L']['width'] = $this->getCSSBorderWidth($brd_widths[3]);
  16520. }
  16521. if (isset($brd_widths[1])) {
  16522. $dom[$key]['border']['R']['width'] = $this->getCSSBorderWidth($brd_widths[1]);
  16523. }
  16524. if (isset($brd_widths[0])) {
  16525. $dom[$key]['border']['T']['width'] = $this->getCSSBorderWidth($brd_widths[0]);
  16526. }
  16527. if (isset($brd_widths[2])) {
  16528. $dom[$key]['border']['B']['width'] = $this->getCSSBorderWidth($brd_widths[2]);
  16529. }
  16530. }
  16531. if (isset($dom[$key]['style']['border-style'])) {
  16532. $brd_styles = preg_split('/[\s]+/', trim($dom[$key]['style']['border-style']));
  16533. if (isset($brd_styles[3]) AND ($brd_styles[3]!='none')) {
  16534. $dom[$key]['border']['L']['cap'] = 'square';
  16535. $dom[$key]['border']['L']['join'] = 'miter';
  16536. $dom[$key]['border']['L']['dash'] = $this->getCSSBorderDashStyle($brd_styles[3]);
  16537. if ($dom[$key]['border']['L']['dash'] < 0) {
  16538. $dom[$key]['border']['L'] = array();
  16539. }
  16540. }
  16541. if (isset($brd_styles[1])) {
  16542. $dom[$key]['border']['R']['cap'] = 'square';
  16543. $dom[$key]['border']['R']['join'] = 'miter';
  16544. $dom[$key]['border']['R']['dash'] = $this->getCSSBorderDashStyle($brd_styles[1]);
  16545. if ($dom[$key]['border']['R']['dash'] < 0) {
  16546. $dom[$key]['border']['R'] = array();
  16547. }
  16548. }
  16549. if (isset($brd_styles[0])) {
  16550. $dom[$key]['border']['T']['cap'] = 'square';
  16551. $dom[$key]['border']['T']['join'] = 'miter';
  16552. $dom[$key]['border']['T']['dash'] = $this->getCSSBorderDashStyle($brd_styles[0]);
  16553. if ($dom[$key]['border']['T']['dash'] < 0) {
  16554. $dom[$key]['border']['T'] = array();
  16555. }
  16556. }
  16557. if (isset($brd_styles[2])) {
  16558. $dom[$key]['border']['B']['cap'] = 'square';
  16559. $dom[$key]['border']['B']['join'] = 'miter';
  16560. $dom[$key]['border']['B']['dash'] = $this->getCSSBorderDashStyle($brd_styles[2]);
  16561. if ($dom[$key]['border']['B']['dash'] < 0) {
  16562. $dom[$key]['border']['B'] = array();
  16563. }
  16564. }
  16565. }
  16566. $cellside = array('L' => 'left', 'R' => 'right', 'T' => 'top', 'B' => 'bottom');
  16567. foreach ($cellside as $bsk => $bsv) {
  16568. if (isset($dom[$key]['style']['border-'.$bsv])) {
  16569. $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border-'.$bsv]);
  16570. if (!empty($borderstyle)) {
  16571. $dom[$key]['border'][$bsk] = $borderstyle;
  16572. }
  16573. }
  16574. if (isset($dom[$key]['style']['border-'.$bsv.'-color'])) {
  16575. $dom[$key]['border'][$bsk]['color'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['border-'.$bsv.'-color'], $this->spot_colors);
  16576. }
  16577. if (isset($dom[$key]['style']['border-'.$bsv.'-width'])) {
  16578. $dom[$key]['border'][$bsk]['width'] = $this->getCSSBorderWidth($dom[$key]['style']['border-'.$bsv.'-width']);
  16579. }
  16580. if (isset($dom[$key]['style']['border-'.$bsv.'-style'])) {
  16581. $dom[$key]['border'][$bsk]['dash'] = $this->getCSSBorderDashStyle($dom[$key]['style']['border-'.$bsv.'-style']);
  16582. if ($dom[$key]['border'][$bsk]['dash'] < 0) {
  16583. $dom[$key]['border'][$bsk] = array();
  16584. }
  16585. }
  16586. }
  16587. // check for CSS padding properties
  16588. if (isset($dom[$key]['style']['padding'])) {
  16589. $dom[$key]['padding'] = $this->getCSSPadding($dom[$key]['style']['padding']);
  16590. } else {
  16591. $dom[$key]['padding'] = $this->cell_padding;
  16592. }
  16593. foreach ($cellside as $psk => $psv) {
  16594. if (isset($dom[$key]['style']['padding-'.$psv])) {
  16595. $dom[$key]['padding'][$psk] = $this->getHTMLUnitToUnits($dom[$key]['style']['padding-'.$psv], 0, 'px', false);
  16596. }
  16597. }
  16598. // check for CSS margin properties
  16599. if (isset($dom[$key]['style']['margin'])) {
  16600. $dom[$key]['margin'] = $this->getCSSMargin($dom[$key]['style']['margin']);
  16601. } else {
  16602. $dom[$key]['margin'] = $this->cell_margin;
  16603. }
  16604. foreach ($cellside as $psk => $psv) {
  16605. if (isset($dom[$key]['style']['margin-'.$psv])) {
  16606. $dom[$key]['margin'][$psk] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $dom[$key]['style']['margin-'.$psv]), 0, 'px', false);
  16607. }
  16608. }
  16609. // check for CSS border-spacing properties
  16610. if (isset($dom[$key]['style']['border-spacing'])) {
  16611. $dom[$key]['border-spacing'] = $this->getCSSBorderMargin($dom[$key]['style']['border-spacing']);
  16612. }
  16613. // page-break-inside
  16614. if (isset($dom[$key]['style']['page-break-inside']) AND ($dom[$key]['style']['page-break-inside'] == 'avoid')) {
  16615. $dom[$key]['attribute']['nobr'] = 'true';
  16616. }
  16617. // page-break-before
  16618. if (isset($dom[$key]['style']['page-break-before'])) {
  16619. if ($dom[$key]['style']['page-break-before'] == 'always') {
  16620. $dom[$key]['attribute']['pagebreak'] = 'true';
  16621. } elseif ($dom[$key]['style']['page-break-before'] == 'left') {
  16622. $dom[$key]['attribute']['pagebreak'] = 'left';
  16623. } elseif ($dom[$key]['style']['page-break-before'] == 'right') {
  16624. $dom[$key]['attribute']['pagebreak'] = 'right';
  16625. }
  16626. }
  16627. // page-break-after
  16628. if (isset($dom[$key]['style']['page-break-after'])) {
  16629. if ($dom[$key]['style']['page-break-after'] == 'always') {
  16630. $dom[$key]['attribute']['pagebreakafter'] = 'true';
  16631. } elseif ($dom[$key]['style']['page-break-after'] == 'left') {
  16632. $dom[$key]['attribute']['pagebreakafter'] = 'left';
  16633. } elseif ($dom[$key]['style']['page-break-after'] == 'right') {
  16634. $dom[$key]['attribute']['pagebreakafter'] = 'right';
  16635. }
  16636. }
  16637. }
  16638. if (isset($dom[$key]['attribute']['display'])) {
  16639. $dom[$key]['hide'] = (trim(strtolower($dom[$key]['attribute']['display'])) == 'none');
  16640. }
  16641. if (isset($dom[$key]['attribute']['border']) AND ($dom[$key]['attribute']['border'] != 0)) {
  16642. $borderstyle = $this->getCSSBorderStyle($dom[$key]['attribute']['border'].' solid black');
  16643. if (!empty($borderstyle)) {
  16644. $dom[$key]['border']['LTRB'] = $borderstyle;
  16645. }
  16646. }
  16647. // check for font tag
  16648. if ($dom[$key]['value'] == 'font') {
  16649. // font family
  16650. if (isset($dom[$key]['attribute']['face'])) {
  16651. $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['attribute']['face']);
  16652. }
  16653. // font size
  16654. if (isset($dom[$key]['attribute']['size'])) {
  16655. if ($key > 0) {
  16656. if ($dom[$key]['attribute']['size'][0] == '+') {
  16657. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] + intval(substr($dom[$key]['attribute']['size'], 1));
  16658. } elseif ($dom[$key]['attribute']['size'][0] == '-') {
  16659. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] - intval(substr($dom[$key]['attribute']['size'], 1));
  16660. } else {
  16661. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  16662. }
  16663. } else {
  16664. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  16665. }
  16666. }
  16667. }
  16668. // force natural alignment for lists
  16669. if ((($dom[$key]['value'] == 'ul') OR ($dom[$key]['value'] == 'ol') OR ($dom[$key]['value'] == 'dl'))
  16670. AND (!isset($dom[$key]['align']) OR TCPDF_STATIC::empty_string($dom[$key]['align']) OR ($dom[$key]['align'] != 'J'))) {
  16671. if ($this->rtl) {
  16672. $dom[$key]['align'] = 'R';
  16673. } else {
  16674. $dom[$key]['align'] = 'L';
  16675. }
  16676. }
  16677. if (($dom[$key]['value'] == 'small') OR ($dom[$key]['value'] == 'sup') OR ($dom[$key]['value'] == 'sub')) {
  16678. if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
  16679. $dom[$key]['fontsize'] = $dom[$key]['fontsize'] * K_SMALL_RATIO;
  16680. }
  16681. }
  16682. if (($dom[$key]['value'] == 'strong') OR ($dom[$key]['value'] == 'b')) {
  16683. $dom[$key]['fontstyle'] .= 'B';
  16684. }
  16685. if (($dom[$key]['value'] == 'em') OR ($dom[$key]['value'] == 'i')) {
  16686. $dom[$key]['fontstyle'] .= 'I';
  16687. }
  16688. if ($dom[$key]['value'] == 'u') {
  16689. $dom[$key]['fontstyle'] .= 'U';
  16690. }
  16691. if (($dom[$key]['value'] == 'del') OR ($dom[$key]['value'] == 's') OR ($dom[$key]['value'] == 'strike')) {
  16692. $dom[$key]['fontstyle'] .= 'D';
  16693. }
  16694. if (!isset($dom[$key]['style']['text-decoration']) AND ($dom[$key]['value'] == 'a')) {
  16695. $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  16696. }
  16697. if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) {
  16698. $dom[$key]['fontname'] = $this->default_monospaced_font;
  16699. }
  16700. 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)) {
  16701. // headings h1, h2, h3, h4, h5, h6
  16702. if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
  16703. $headsize = (4 - intval($dom[$key]['value'][1])) * 2;
  16704. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + $headsize;
  16705. }
  16706. if (!isset($dom[$key]['style']['font-weight'])) {
  16707. $dom[$key]['fontstyle'] .= 'B';
  16708. }
  16709. }
  16710. if (($dom[$key]['value'] == 'table')) {
  16711. $dom[$key]['rows'] = 0; // number of rows
  16712. $dom[$key]['trids'] = array(); // IDs of TR elements
  16713. $dom[$key]['thead'] = ''; // table header rows
  16714. }
  16715. if (($dom[$key]['value'] == 'tr')) {
  16716. $dom[$key]['cols'] = 0;
  16717. if ($thead) {
  16718. $dom[$key]['thead'] = true;
  16719. // rows on thead block are printed as a separate table
  16720. } else {
  16721. $dom[$key]['thead'] = false;
  16722. // store the number of rows on table element
  16723. ++$dom[($dom[$key]['parent'])]['rows'];
  16724. // store the TR elements IDs on table element
  16725. array_push($dom[($dom[$key]['parent'])]['trids'], $key);
  16726. }
  16727. }
  16728. if (($dom[$key]['value'] == 'th') OR ($dom[$key]['value'] == 'td')) {
  16729. if (isset($dom[$key]['attribute']['colspan'])) {
  16730. $colspan = intval($dom[$key]['attribute']['colspan']);
  16731. } else {
  16732. $colspan = 1;
  16733. }
  16734. $dom[$key]['attribute']['colspan'] = $colspan;
  16735. $dom[($dom[$key]['parent'])]['cols'] += $colspan;
  16736. }
  16737. // text direction
  16738. if (isset($dom[$key]['attribute']['dir'])) {
  16739. $dom[$key]['dir'] = $dom[$key]['attribute']['dir'];
  16740. }
  16741. // set foreground color attribute
  16742. if (isset($dom[$key]['attribute']['color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['color']))) {
  16743. $dom[$key]['fgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['color'], $this->spot_colors);
  16744. } elseif (!isset($dom[$key]['style']['color']) AND ($dom[$key]['value'] == 'a')) {
  16745. $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  16746. }
  16747. // set background color attribute
  16748. if (isset($dom[$key]['attribute']['bgcolor']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['bgcolor']))) {
  16749. $dom[$key]['bgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['bgcolor'], $this->spot_colors);
  16750. }
  16751. // set stroke color attribute
  16752. if (isset($dom[$key]['attribute']['strokecolor']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['strokecolor']))) {
  16753. $dom[$key]['strokecolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['strokecolor'], $this->spot_colors);
  16754. }
  16755. // check for width attribute
  16756. if (isset($dom[$key]['attribute']['width'])) {
  16757. $dom[$key]['width'] = $dom[$key]['attribute']['width'];
  16758. }
  16759. // check for height attribute
  16760. if (isset($dom[$key]['attribute']['height'])) {
  16761. $dom[$key]['height'] = $dom[$key]['attribute']['height'];
  16762. }
  16763. // check for text alignment
  16764. if (isset($dom[$key]['attribute']['align']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['align'])) AND ($dom[$key]['value'] !== 'img')) {
  16765. $dom[$key]['align'] = strtoupper($dom[$key]['attribute']['align'][0]);
  16766. }
  16767. // check for text rendering mode (the following attributes do not exist in HTML)
  16768. if (isset($dom[$key]['attribute']['stroke'])) {
  16769. // font stroke width
  16770. $dom[$key]['stroke'] = $this->getHTMLUnitToUnits($dom[$key]['attribute']['stroke'], $dom[$key]['fontsize'], 'pt', true);
  16771. }
  16772. if (isset($dom[$key]['attribute']['fill'])) {
  16773. // font fill
  16774. if ($dom[$key]['attribute']['fill'] == 'true') {
  16775. $dom[$key]['fill'] = true;
  16776. } else {
  16777. $dom[$key]['fill'] = false;
  16778. }
  16779. }
  16780. if (isset($dom[$key]['attribute']['clip'])) {
  16781. // clipping mode
  16782. if ($dom[$key]['attribute']['clip'] == 'true') {
  16783. $dom[$key]['clip'] = true;
  16784. } else {
  16785. $dom[$key]['clip'] = false;
  16786. }
  16787. }
  16788. } // end opening tag
  16789. } else {
  16790. // text
  16791. $dom[$key]['tag'] = false;
  16792. $dom[$key]['block'] = false;
  16793. $dom[$key]['parent'] = end($level);
  16794. $dom[$key]['dir'] = $dom[$dom[$key]['parent']]['dir'];
  16795. if (!empty($dom[$dom[$key]['parent']]['text-transform'])) {
  16796. // text-transform for unicode requires mb_convert_case (Multibyte String Functions)
  16797. if (function_exists('mb_convert_case')) {
  16798. $ttm = array('capitalize' => MB_CASE_TITLE, 'uppercase' => MB_CASE_UPPER, 'lowercase' => MB_CASE_LOWER);
  16799. if (isset($ttm[$dom[$dom[$key]['parent']]['text-transform']])) {
  16800. $element = mb_convert_case($element, $ttm[$dom[$dom[$key]['parent']]['text-transform']], $this->encoding);
  16801. }
  16802. } elseif (!$this->isunicode) {
  16803. switch ($dom[$dom[$key]['parent']]['text-transform']) {
  16804. case 'capitalize': {
  16805. $element = ucwords(strtolower($element));
  16806. break;
  16807. }
  16808. case 'uppercase': {
  16809. $element = strtoupper($element);
  16810. break;
  16811. }
  16812. case 'lowercase': {
  16813. $element = strtolower($element);
  16814. break;
  16815. }
  16816. }
  16817. }
  16818. }
  16819. $dom[$key]['value'] = stripslashes($this->unhtmlentities($element));
  16820. }
  16821. ++$elkey;
  16822. ++$key;
  16823. }
  16824. return $dom;
  16825. }
  16826. /**
  16827. * Returns the string used to find spaces
  16828. * @return string
  16829. * @protected
  16830. * @author Nicola Asuni
  16831. * @since 4.8.024 (2010-01-15)
  16832. */
  16833. protected function getSpaceString()
  16834. {
  16835. $spacestr = chr(32);
  16836. if ($this->isUnicodeFont()) {
  16837. $spacestr = chr(0).chr(32);
  16838. }
  16839. return $spacestr;
  16840. }
  16841. /**
  16842. * Return an hash code used to ensure that the serialized data has been generated by this TCPDF instance.
  16843. * @param $data (string) serialized data
  16844. * @return string
  16845. * @public static
  16846. */
  16847. protected function getHashForTCPDFtagParams($data)
  16848. {
  16849. return md5(strlen($data).$this->file_id.$data);
  16850. }
  16851. /**
  16852. * Serialize an array of parameters to be used with TCPDF tag in HTML code.
  16853. * @param $data (array) parameters array
  16854. * @return string containing serialized data
  16855. * @public static
  16856. */
  16857. public function serializeTCPDFtagParameters($data)
  16858. {
  16859. $encoded = urlencode(json_encode($data));
  16860. return $this->getHashForTCPDFtagParams($encoded).$encoded;
  16861. }
  16862. /**
  16863. * Unserialize parameters to be used with TCPDF tag in HTML code.
  16864. * @param $data (string) serialized data
  16865. * @return array containing unserialized data
  16866. * @protected static
  16867. */
  16868. protected function unserializeTCPDFtagParameters($data)
  16869. {
  16870. $hash = substr($data, 0, 32);
  16871. $encoded = substr($data, 32);
  16872. if ($hash != $this->getHashForTCPDFtagParams($encoded)) {
  16873. $this->Error('Invalid parameters');
  16874. }
  16875. return json_decode(urldecode($encoded), true);
  16876. }
  16877. /**
  16878. * Prints a cell (rectangular area) with optional borders, background color and html text string.
  16879. * 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 />
  16880. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  16881. * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  16882. * 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
  16883. * NOTE: all the HTML attributes must be enclosed in double-quote.
  16884. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  16885. * @param $h (float) Cell minimum height. The cell extends automatically if needed.
  16886. * @param $x (float) upper-left corner X coordinate
  16887. * @param $y (float) upper-left corner Y coordinate
  16888. * @param $html (string) html text to print. Default value: empty string.
  16889. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  16890. * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL language)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul> Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  16891. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  16892. * @param $reseth (boolean) if true reset the last cell height (default true).
  16893. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  16894. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width.
  16895. * @see Multicell(), writeHTML()
  16896. * @public
  16897. */
  16898. public function writeHTMLCell($w, $h, $x, $y, $html = '', $border = 0, $ln = 0, $fill = false, $reseth = true, $align = '', $autopadding = true)
  16899. {
  16900. return $this->MultiCell($w, $h, $html, $border, $align, $fill, $ln, $x, $y, $reseth, 0, true, $autopadding, 0, 'T', false);
  16901. }
  16902. /**
  16903. * Allows to preserve some HTML formatting (limited support).<br />
  16904. * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  16905. * 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
  16906. * NOTE: all the HTML attributes must be enclosed in double-quote.
  16907. * @param $html (string) text to display
  16908. * @param $ln (boolean) if true add a new line after text (default = true)
  16909. * @param $fill (boolean) Indicates if the background must be painted (true) or transparent (false).
  16910. * @param $reseth (boolean) if true reset the last cell height (default false).
  16911. * @param $cell (boolean) if true add the current left (or right for RTL) padding to each Write (default false).
  16912. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  16913. * @public
  16914. */
  16915. public function writeHTML($html, $ln = true, $fill = false, $reseth = false, $cell = false, $align = '')
  16916. {
  16917. $gvars = $this->getGraphicVars();
  16918. // store current values
  16919. $prev_cell_margin = $this->cell_margin;
  16920. $prev_cell_padding = $this->cell_padding;
  16921. $prevPage = $this->page;
  16922. $prevlMargin = $this->lMargin;
  16923. $prevrMargin = $this->rMargin;
  16924. $curfontname = $this->FontFamily;
  16925. $curfontstyle = $this->FontStyle;
  16926. $curfontsize = $this->FontSizePt;
  16927. $curfontascent = $this->getFontAscent($curfontname, $curfontstyle, $curfontsize);
  16928. $curfontdescent = $this->getFontDescent($curfontname, $curfontstyle, $curfontsize);
  16929. $curfontstretcing = $this->font_stretching;
  16930. $curfonttracking = $this->font_spacing;
  16931. $this->newline = true;
  16932. $newline = true;
  16933. $startlinepage = $this->page;
  16934. $minstartliney = $this->y;
  16935. $maxbottomliney = 0;
  16936. $startlinex = $this->x;
  16937. $startliney = $this->y;
  16938. $yshift = 0;
  16939. $loop = 0;
  16940. $curpos = 0;
  16941. $this_method_vars = array();
  16942. $undo = false;
  16943. $fontaligned = false;
  16944. $reverse_dir = false; // true when the text direction is reversed
  16945. $this->premode = false;
  16946. if ($this->inxobj) {
  16947. // we are inside an XObject template
  16948. $pask = count($this->xobjects[$this->xobjid]['annotations']);
  16949. } elseif (isset($this->PageAnnots[$this->page])) {
  16950. $pask = count($this->PageAnnots[$this->page]);
  16951. } else {
  16952. $pask = 0;
  16953. }
  16954. if ($this->inxobj) {
  16955. // we are inside an XObject template
  16956. $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
  16957. } elseif (!$this->InFooter) {
  16958. if (isset($this->footerlen[$this->page])) {
  16959. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  16960. } else {
  16961. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  16962. }
  16963. $startlinepos = $this->footerpos[$this->page];
  16964. } else {
  16965. // we are inside the footer
  16966. $startlinepos = $this->pagelen[$this->page];
  16967. }
  16968. $lalign = $align;
  16969. $plalign = $align;
  16970. if ($this->rtl) {
  16971. $w = $this->x - $this->lMargin;
  16972. } else {
  16973. $w = $this->w - $this->rMargin - $this->x;
  16974. }
  16975. $w -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  16976. if ($cell) {
  16977. if ($this->rtl) {
  16978. $this->x -= $this->cell_padding['R'];
  16979. $this->lMargin += $this->cell_padding['L'];
  16980. } else {
  16981. $this->x += $this->cell_padding['L'];
  16982. $this->rMargin += $this->cell_padding['R'];
  16983. }
  16984. }
  16985. if ($this->customlistindent >= 0) {
  16986. $this->listindent = $this->customlistindent;
  16987. } else {
  16988. $this->listindent = $this->GetStringWidth('000000');
  16989. }
  16990. $this->listindentlevel = 0;
  16991. // save previous states
  16992. $prev_cell_height_ratio = $this->cell_height_ratio;
  16993. $prev_listnum = $this->listnum;
  16994. $prev_listordered = $this->listordered;
  16995. $prev_listcount = $this->listcount;
  16996. $prev_lispacer = $this->lispacer;
  16997. $this->listnum = 0;
  16998. $this->listordered = array();
  16999. $this->listcount = array();
  17000. $this->lispacer = '';
  17001. if ((TCPDF_STATIC::empty_string($this->lasth)) OR ($reseth)) {
  17002. // reset row height
  17003. $this->resetLastH();
  17004. }
  17005. $dom = $this->getHtmlDomArray($html);
  17006. $maxel = count($dom);
  17007. $key = 0;
  17008. while ($key < $maxel) {
  17009. if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND $dom[$key]['hide']) {
  17010. // store the node key
  17011. $hidden_node_key = $key;
  17012. if ($dom[$key]['self']) {
  17013. // skip just this self-closing tag
  17014. ++$key;
  17015. } else {
  17016. // skip this and all children tags
  17017. while (($key < $maxel) AND (!$dom[$key]['tag'] OR $dom[$key]['opening'] OR ($dom[$key]['parent'] != $hidden_node_key))) {
  17018. // skip hidden objects
  17019. ++$key;
  17020. }
  17021. ++$key;
  17022. }
  17023. }
  17024. if ($dom[$key]['tag'] AND isset($dom[$key]['attribute']['pagebreak'])) {
  17025. // check for pagebreak
  17026. if (($dom[$key]['attribute']['pagebreak'] == 'true') OR ($dom[$key]['attribute']['pagebreak'] == 'left') OR ($dom[$key]['attribute']['pagebreak'] == 'right')) {
  17027. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  17028. $this->checkPageBreak($this->PageBreakTrigger + 1);
  17029. $this->htmlvspace = ($this->PageBreakTrigger + 1);
  17030. }
  17031. if ((($dom[$key]['attribute']['pagebreak'] == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  17032. OR (($dom[$key]['attribute']['pagebreak'] == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  17033. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  17034. $this->checkPageBreak($this->PageBreakTrigger + 1);
  17035. $this->htmlvspace = ($this->PageBreakTrigger + 1);
  17036. }
  17037. }
  17038. if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND isset($dom[$key]['attribute']['nobr']) AND ($dom[$key]['attribute']['nobr'] == 'true')) {
  17039. if (isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) {
  17040. $dom[$key]['attribute']['nobr'] = false;
  17041. } else {
  17042. // store current object
  17043. $this->startTransaction();
  17044. // save this method vars
  17045. $this_method_vars['html'] = $html;
  17046. $this_method_vars['ln'] = $ln;
  17047. $this_method_vars['fill'] = $fill;
  17048. $this_method_vars['reseth'] = $reseth;
  17049. $this_method_vars['cell'] = $cell;
  17050. $this_method_vars['align'] = $align;
  17051. $this_method_vars['gvars'] = $gvars;
  17052. $this_method_vars['prevPage'] = $prevPage;
  17053. $this_method_vars['prev_cell_margin'] = $prev_cell_margin;
  17054. $this_method_vars['prev_cell_padding'] = $prev_cell_padding;
  17055. $this_method_vars['prevlMargin'] = $prevlMargin;
  17056. $this_method_vars['prevrMargin'] = $prevrMargin;
  17057. $this_method_vars['curfontname'] = $curfontname;
  17058. $this_method_vars['curfontstyle'] = $curfontstyle;
  17059. $this_method_vars['curfontsize'] = $curfontsize;
  17060. $this_method_vars['curfontascent'] = $curfontascent;
  17061. $this_method_vars['curfontdescent'] = $curfontdescent;
  17062. $this_method_vars['curfontstretcing'] = $curfontstretcing;
  17063. $this_method_vars['curfonttracking'] = $curfonttracking;
  17064. $this_method_vars['minstartliney'] = $minstartliney;
  17065. $this_method_vars['maxbottomliney'] = $maxbottomliney;
  17066. $this_method_vars['yshift'] = $yshift;
  17067. $this_method_vars['startlinepage'] = $startlinepage;
  17068. $this_method_vars['startlinepos'] = $startlinepos;
  17069. $this_method_vars['startlinex'] = $startlinex;
  17070. $this_method_vars['startliney'] = $startliney;
  17071. $this_method_vars['newline'] = $newline;
  17072. $this_method_vars['loop'] = $loop;
  17073. $this_method_vars['curpos'] = $curpos;
  17074. $this_method_vars['pask'] = $pask;
  17075. $this_method_vars['lalign'] = $lalign;
  17076. $this_method_vars['plalign'] = $plalign;
  17077. $this_method_vars['w'] = $w;
  17078. $this_method_vars['prev_cell_height_ratio'] = $prev_cell_height_ratio;
  17079. $this_method_vars['prev_listnum'] = $prev_listnum;
  17080. $this_method_vars['prev_listordered'] = $prev_listordered;
  17081. $this_method_vars['prev_listcount'] = $prev_listcount;
  17082. $this_method_vars['prev_lispacer'] = $prev_lispacer;
  17083. $this_method_vars['fontaligned'] = $fontaligned;
  17084. $this_method_vars['key'] = $key;
  17085. $this_method_vars['dom'] = $dom;
  17086. }
  17087. }
  17088. // print THEAD block
  17089. if (($dom[$key]['value'] == 'tr') AND isset($dom[$key]['thead']) AND $dom[$key]['thead']) {
  17090. if (isset($dom[$key]['parent']) AND isset($dom[$dom[$key]['parent']]['thead']) AND !TCPDF_STATIC::empty_string($dom[$dom[$key]['parent']]['thead'])) {
  17091. $this->inthead = true;
  17092. // print table header (thead)
  17093. $this->writeHTML($this->thead, false, false, false, false, '');
  17094. // check if we are on a new page or on a new column
  17095. if (($this->y < $this->start_transaction_y) OR ($this->checkPageBreak($this->lasth, '', false))) {
  17096. // we are on a new page or on a new column and the total object height is less than the available vertical space.
  17097. // restore previous object
  17098. $this->rollbackTransaction(true);
  17099. // restore previous values
  17100. foreach ($this_method_vars as $vkey => $vval) {
  17101. $$vkey = $vval;
  17102. }
  17103. // disable table header
  17104. $tmp_thead = $this->thead;
  17105. $this->thead = '';
  17106. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  17107. $pre_y = $this->y;
  17108. if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
  17109. // fix for multicolumn mode
  17110. $startliney = $this->y;
  17111. }
  17112. $this->start_transaction_page = $this->page;
  17113. $this->start_transaction_y = $this->y;
  17114. // restore table header
  17115. $this->thead = $tmp_thead;
  17116. // fix table border properties
  17117. if (isset($dom[$dom[$key]['parent']]['attribute']['cellspacing'])) {
  17118. $tmp_cellspacing = $this->getHTMLUnitToUnits($dom[$dom[$key]['parent']]['attribute']['cellspacing'], 1, 'px');
  17119. } elseif (isset($dom[$dom[$key]['parent']]['border-spacing'])) {
  17120. $tmp_cellspacing = $dom[$dom[$key]['parent']]['border-spacing']['V'];
  17121. } else {
  17122. $tmp_cellspacing = 0;
  17123. }
  17124. $dom[$dom[$key]['parent']]['borderposition']['page'] = $this->page;
  17125. $dom[$dom[$key]['parent']]['borderposition']['column'] = $this->current_column;
  17126. $dom[$dom[$key]['parent']]['borderposition']['y'] = $this->y + $tmp_cellspacing;
  17127. $xoffset = ($this->x - $dom[$dom[$key]['parent']]['borderposition']['x']);
  17128. $dom[$dom[$key]['parent']]['borderposition']['x'] += $xoffset;
  17129. $dom[$dom[$key]['parent']]['borderposition']['xmax'] += $xoffset;
  17130. // print table header (thead)
  17131. $this->writeHTML($this->thead, false, false, false, false, '');
  17132. }
  17133. }
  17134. // move $key index forward to skip THEAD block
  17135. while ( ($key < $maxel) AND (!(
  17136. ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'tr') AND (!isset($dom[$key]['thead']) OR !$dom[$key]['thead']))
  17137. OR ($dom[$key]['tag'] AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == 'table'))) )) {
  17138. ++$key;
  17139. }
  17140. }
  17141. if ($dom[$key]['tag'] OR ($key == 0)) {
  17142. if ((($dom[$key]['value'] == 'table') OR ($dom[$key]['value'] == 'tr')) AND (isset($dom[$key]['align']))) {
  17143. $dom[$key]['align'] = ($this->rtl) ? 'R' : 'L';
  17144. }
  17145. // vertically align image in line
  17146. if ((!$this->newline) AND ($dom[$key]['value'] == 'img') AND (isset($dom[$key]['height'])) AND ($dom[$key]['height'] > 0)) {
  17147. // get image height
  17148. $imgh = $this->getHTMLUnitToUnits($dom[$key]['height'], ($dom[$key]['fontsize'] / $this->k), 'px');
  17149. $autolinebreak = false;
  17150. if (!empty($dom[$key]['width'])) {
  17151. $imgw = $this->getHTMLUnitToUnits($dom[$key]['width'], ($dom[$key]['fontsize'] / $this->k), 'px', false);
  17152. if (($imgw <= ($this->w - $this->lMargin - $this->rMargin - $this->cell_padding['L'] - $this->cell_padding['R']))
  17153. AND ((($this->rtl) AND (($this->x - $imgw) < ($this->lMargin + $this->cell_padding['L'])))
  17154. OR ((!$this->rtl) AND (($this->x + $imgw) > ($this->w - $this->rMargin - $this->cell_padding['R']))))) {
  17155. // add automatic line break
  17156. $autolinebreak = true;
  17157. $this->Ln('', $cell);
  17158. if ((!$dom[($key-1)]['tag']) AND ($dom[($key-1)]['value'] == ' ')) {
  17159. // go back to evaluate this line break
  17160. --$key;
  17161. }
  17162. }
  17163. }
  17164. if (!$autolinebreak) {
  17165. if ($this->inPageBody()) {
  17166. $pre_y = $this->y;
  17167. // check for page break
  17168. if ((!$this->checkPageBreak($imgh)) AND ($this->y < $pre_y)) {
  17169. // fix for multicolumn mode
  17170. $startliney = $this->y;
  17171. }
  17172. }
  17173. if ($this->page > $startlinepage) {
  17174. // fix line splitted over two pages
  17175. if (isset($this->footerlen[$startlinepage])) {
  17176. $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  17177. }
  17178. // line to be moved one page forward
  17179. $pagebuff = $this->getPageBuffer($startlinepage);
  17180. $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
  17181. $tstart = substr($pagebuff, 0, $startlinepos);
  17182. $tend = substr($this->getPageBuffer($startlinepage), $curpos);
  17183. // remove line from previous page
  17184. $this->setPageBuffer($startlinepage, $tstart.''.$tend);
  17185. $pagebuff = $this->getPageBuffer($this->page);
  17186. $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
  17187. $tend = substr($pagebuff, $this->cntmrk[$this->page]);
  17188. // add line start to current page
  17189. $yshift = ($minstartliney - $this->y);
  17190. if ($fontaligned) {
  17191. $yshift += ($curfontsize / $this->k);
  17192. }
  17193. $try = sprintf('1 0 0 1 0 %F cm', ($yshift * $this->k));
  17194. $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  17195. // shift the annotations and links
  17196. if (isset($this->PageAnnots[$this->page])) {
  17197. $next_pask = count($this->PageAnnots[$this->page]);
  17198. } else {
  17199. $next_pask = 0;
  17200. }
  17201. if (isset($this->PageAnnots[$startlinepage])) {
  17202. foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
  17203. if ($pak >= $pask) {
  17204. $this->PageAnnots[$this->page][] = $pac;
  17205. unset($this->PageAnnots[$startlinepage][$pak]);
  17206. $npak = count($this->PageAnnots[$this->page]) - 1;
  17207. $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  17208. }
  17209. }
  17210. }
  17211. $pask = $next_pask;
  17212. $startlinepos = $this->cntmrk[$this->page];
  17213. $startlinepage = $this->page;
  17214. $startliney = $this->y;
  17215. $this->newline = false;
  17216. }
  17217. $this->y += ($this->getCellHeight($curfontsize / $this->k) - ($curfontdescent * $this->cell_height_ratio) - $imgh);
  17218. $minstartliney = min($this->y, $minstartliney);
  17219. $maxbottomliney = ($startliney + $this->getCellHeight($curfontsize / $this->k));
  17220. }
  17221. } elseif (isset($dom[$key]['fontname']) OR isset($dom[$key]['fontstyle']) OR isset($dom[$key]['fontsize']) OR isset($dom[$key]['line-height'])) {
  17222. // account for different font size
  17223. $pfontname = $curfontname;
  17224. $pfontstyle = $curfontstyle;
  17225. $pfontsize = $curfontsize;
  17226. $fontname = (isset($dom[$key]['fontname']) ? $dom[$key]['fontname'] : $curfontname);
  17227. $fontstyle = (isset($dom[$key]['fontstyle']) ? $dom[$key]['fontstyle'] : $curfontstyle);
  17228. $fontsize = (isset($dom[$key]['fontsize']) ? $dom[$key]['fontsize'] : $curfontsize);
  17229. $fontascent = $this->getFontAscent($fontname, $fontstyle, $fontsize);
  17230. $fontdescent = $this->getFontDescent($fontname, $fontstyle, $fontsize);
  17231. if (($fontname != $curfontname) OR ($fontstyle != $curfontstyle) OR ($fontsize != $curfontsize)
  17232. OR ($this->cell_height_ratio != $dom[$key]['line-height'])
  17233. OR ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li')) ) {
  17234. if (($key < ($maxel - 1)) AND (
  17235. ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li'))
  17236. OR ($this->cell_height_ratio != $dom[$key]['line-height'])
  17237. OR (!$this->newline AND is_numeric($fontsize) AND is_numeric($curfontsize)
  17238. AND ($fontsize >= 0) AND ($curfontsize >= 0)
  17239. AND (($fontsize != $curfontsize) OR ($fontstyle != $curfontstyle) OR ($fontname != $curfontname)))
  17240. )) {
  17241. if ($this->page > $startlinepage) {
  17242. // fix lines splitted over two pages
  17243. if (isset($this->footerlen[$startlinepage])) {
  17244. $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  17245. }
  17246. // line to be moved one page forward
  17247. $pagebuff = $this->getPageBuffer($startlinepage);
  17248. $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
  17249. $tstart = substr($pagebuff, 0, $startlinepos);
  17250. $tend = substr($this->getPageBuffer($startlinepage), $curpos);
  17251. // remove line start from previous page
  17252. $this->setPageBuffer($startlinepage, $tstart.''.$tend);
  17253. $pagebuff = $this->getPageBuffer($this->page);
  17254. $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
  17255. $tend = substr($pagebuff, $this->cntmrk[$this->page]);
  17256. // add line start to current page
  17257. $yshift = ($minstartliney - $this->y);
  17258. $try = sprintf('1 0 0 1 0 %F cm', ($yshift * $this->k));
  17259. $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  17260. // shift the annotations and links
  17261. if (isset($this->PageAnnots[$this->page])) {
  17262. $next_pask = count($this->PageAnnots[$this->page]);
  17263. } else {
  17264. $next_pask = 0;
  17265. }
  17266. if (isset($this->PageAnnots[$startlinepage])) {
  17267. foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
  17268. if ($pak >= $pask) {
  17269. $this->PageAnnots[$this->page][] = $pac;
  17270. unset($this->PageAnnots[$startlinepage][$pak]);
  17271. $npak = count($this->PageAnnots[$this->page]) - 1;
  17272. $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  17273. }
  17274. }
  17275. }
  17276. $pask = $next_pask;
  17277. $startlinepos = $this->cntmrk[$this->page];
  17278. $startlinepage = $this->page;
  17279. $startliney = $this->y;
  17280. }
  17281. if (!isset($dom[$key]['line-height'])) {
  17282. $dom[$key]['line-height'] = $this->cell_height_ratio;
  17283. }
  17284. if (!$dom[$key]['block']) {
  17285. 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']))) {
  17286. $this->y += (((($curfontsize * $this->cell_height_ratio) - ($fontsize * $dom[$key]['line-height'])) / $this->k) + $curfontascent - $fontascent - $curfontdescent + $fontdescent) / 2;
  17287. }
  17288. if (($dom[$key]['value'] != 'sup') AND ($dom[$key]['value'] != 'sub')) {
  17289. $current_line_align_data = array($key, $minstartliney, $maxbottomliney);
  17290. 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)))) {
  17291. $minstartliney = min($this->y, $line_align_data[1]);
  17292. $maxbottomliney = max(($this->y + $this->getCellHeight($fontsize / $this->k)), $line_align_data[2]);
  17293. } else {
  17294. $minstartliney = min($this->y, $minstartliney);
  17295. $maxbottomliney = max(($this->y + $this->getCellHeight($fontsize / $this->k)), $maxbottomliney);
  17296. }
  17297. $line_align_data = $current_line_align_data;
  17298. }
  17299. }
  17300. $this->cell_height_ratio = $dom[$key]['line-height'];
  17301. $fontaligned = true;
  17302. }
  17303. $this->SetFont($fontname, $fontstyle, $fontsize);
  17304. // reset row height
  17305. $this->resetLastH();
  17306. $curfontname = $fontname;
  17307. $curfontstyle = $fontstyle;
  17308. $curfontsize = $fontsize;
  17309. $curfontascent = $fontascent;
  17310. $curfontdescent = $fontdescent;
  17311. }
  17312. }
  17313. // set text rendering mode
  17314. $textstroke = isset($dom[$key]['stroke']) ? $dom[$key]['stroke'] : $this->textstrokewidth;
  17315. $textfill = isset($dom[$key]['fill']) ? $dom[$key]['fill'] : (($this->textrendermode % 2) == 0);
  17316. $textclip = isset($dom[$key]['clip']) ? $dom[$key]['clip'] : ($this->textrendermode > 3);
  17317. $this->setTextRenderingMode($textstroke, $textfill, $textclip);
  17318. if (isset($dom[$key]['font-stretch']) AND ($dom[$key]['font-stretch'] !== false)) {
  17319. $this->setFontStretching($dom[$key]['font-stretch']);
  17320. }
  17321. if (isset($dom[$key]['letter-spacing']) AND ($dom[$key]['letter-spacing'] !== false)) {
  17322. $this->setFontSpacing($dom[$key]['letter-spacing']);
  17323. }
  17324. if (($plalign == 'J') AND $dom[$key]['block']) {
  17325. $plalign = '';
  17326. }
  17327. // get current position on page buffer
  17328. $curpos = $this->pagelen[$startlinepage];
  17329. if (isset($dom[$key]['bgcolor']) AND ($dom[$key]['bgcolor'] !== false)) {
  17330. $this->SetFillColorArray($dom[$key]['bgcolor']);
  17331. $wfill = true;
  17332. } else {
  17333. $wfill = $fill | false;
  17334. }
  17335. if (isset($dom[$key]['fgcolor']) AND ($dom[$key]['fgcolor'] !== false)) {
  17336. $this->SetTextColorArray($dom[$key]['fgcolor']);
  17337. }
  17338. if (isset($dom[$key]['strokecolor']) AND ($dom[$key]['strokecolor'] !== false)) {
  17339. $this->SetDrawColorArray($dom[$key]['strokecolor']);
  17340. }
  17341. if (isset($dom[$key]['align'])) {
  17342. $lalign = $dom[$key]['align'];
  17343. }
  17344. if (TCPDF_STATIC::empty_string($lalign)) {
  17345. $lalign = $align;
  17346. }
  17347. }
  17348. // align lines
  17349. if ($this->newline AND (strlen($dom[$key]['value']) > 0) AND ($dom[$key]['value'] != 'td') AND ($dom[$key]['value'] != 'th')) {
  17350. $newline = true;
  17351. $fontaligned = false;
  17352. // we are at the beginning of a new line
  17353. if (isset($startlinex)) {
  17354. $yshift = ($minstartliney - $startliney);
  17355. if (($yshift > 0) OR ($this->page > $startlinepage)) {
  17356. $yshift = 0;
  17357. }
  17358. $t_x = 0;
  17359. // the last line must be shifted to be aligned as requested
  17360. $linew = abs($this->endlinex - $startlinex);
  17361. if ($this->inxobj) {
  17362. // we are inside an XObject template
  17363. $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
  17364. if (isset($opentagpos)) {
  17365. $midpos = $opentagpos;
  17366. } else {
  17367. $midpos = 0;
  17368. }
  17369. if ($midpos > 0) {
  17370. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
  17371. $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  17372. } else {
  17373. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  17374. $pend = '';
  17375. }
  17376. } else {
  17377. $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
  17378. if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  17379. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  17380. $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
  17381. } elseif (isset($opentagpos)) {
  17382. $midpos = $opentagpos;
  17383. } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  17384. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  17385. $midpos = $this->footerpos[$startlinepage];
  17386. } else {
  17387. $midpos = 0;
  17388. }
  17389. if ($midpos > 0) {
  17390. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
  17391. $pend = substr($this->getPageBuffer($startlinepage), $midpos);
  17392. } else {
  17393. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
  17394. $pend = '';
  17395. }
  17396. }
  17397. if ((isset($plalign) AND ((($plalign == 'C') OR ($plalign == 'J') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
  17398. // calculate shifting amount
  17399. $tw = $w;
  17400. if (($plalign == 'J') AND $this->isRTLTextDir() AND ($this->num_columns > 1)) {
  17401. $tw += $this->cell_padding['R'];
  17402. }
  17403. if ($this->lMargin != $prevlMargin) {
  17404. $tw += ($prevlMargin - $this->lMargin);
  17405. }
  17406. if ($this->rMargin != $prevrMargin) {
  17407. $tw += ($prevrMargin - $this->rMargin);
  17408. }
  17409. $one_space_width = $this->GetStringWidth(chr(32));
  17410. $no = 0; // number of spaces on a line contained on a single block
  17411. if ($this->isRTLTextDir()) { // RTL
  17412. // remove left space if exist
  17413. $pos1 = TCPDF_STATIC::revstrpos($pmid, '[(');
  17414. if ($pos1 > 0) {
  17415. $pos1 = intval($pos1);
  17416. if ($this->isUnicodeFont()) {
  17417. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(0).chr(32)));
  17418. $spacelen = 2;
  17419. } else {
  17420. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(32)));
  17421. $spacelen = 1;
  17422. }
  17423. if ($pos1 == $pos2) {
  17424. $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
  17425. if (substr($pmid, $pos1, 4) == '[()]') {
  17426. $linew -= $one_space_width;
  17427. } elseif ($pos1 == strpos($pmid, '[(')) {
  17428. $no = 1;
  17429. }
  17430. }
  17431. }
  17432. } else { // LTR
  17433. // remove right space if exist
  17434. $pos1 = TCPDF_STATIC::revstrpos($pmid, ')]');
  17435. if ($pos1 > 0) {
  17436. $pos1 = intval($pos1);
  17437. if ($this->isUnicodeFont()) {
  17438. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(0).chr(32).')]')) + 2;
  17439. $spacelen = 2;
  17440. } else {
  17441. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(32).')]')) + 1;
  17442. $spacelen = 1;
  17443. }
  17444. if ($pos1 == $pos2) {
  17445. $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
  17446. $linew -= $one_space_width;
  17447. }
  17448. }
  17449. }
  17450. $mdiff = ($tw - $linew);
  17451. if ($plalign == 'C') {
  17452. if ($this->rtl) {
  17453. $t_x = -($mdiff / 2);
  17454. } else {
  17455. $t_x = ($mdiff / 2);
  17456. }
  17457. } elseif ($plalign == 'R') {
  17458. // right alignment on LTR document
  17459. $t_x = $mdiff;
  17460. } elseif ($plalign == 'L') {
  17461. // left alignment on RTL document
  17462. $t_x = -$mdiff;
  17463. } elseif (($plalign == 'J') AND ($plalign == $lalign)) {
  17464. // Justification
  17465. if ($this->isRTLTextDir()) {
  17466. // align text on the left
  17467. $t_x = -$mdiff;
  17468. }
  17469. $ns = 0; // number of spaces
  17470. $pmidtemp = $pmid;
  17471. // escape special characters
  17472. $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
  17473. $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
  17474. // search spaces
  17475. if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmidtemp, $lnstring, PREG_PATTERN_ORDER)) {
  17476. $spacestr = $this->getSpaceString();
  17477. $maxkk = count($lnstring[1]) - 1;
  17478. for ($kk=0; $kk <= $maxkk; ++$kk) {
  17479. // restore special characters
  17480. $lnstring[1][$kk] = str_replace('#!#OP#!#', '(', $lnstring[1][$kk]);
  17481. $lnstring[1][$kk] = str_replace('#!#CP#!#', ')', $lnstring[1][$kk]);
  17482. // store number of spaces on the strings
  17483. $lnstring[2][$kk] = substr_count($lnstring[1][$kk], $spacestr);
  17484. // count total spaces on line
  17485. $ns += $lnstring[2][$kk];
  17486. $lnstring[3][$kk] = $ns;
  17487. }
  17488. if ($ns == 0) {
  17489. $ns = 1;
  17490. }
  17491. // calculate additional space to add to each existing space
  17492. $spacewidth = ($mdiff / ($ns - $no)) * $this->k;
  17493. if ($this->FontSize <= 0) {
  17494. $this->FontSize = 1;
  17495. }
  17496. $spacewidthu = -1000 * ($mdiff + (($ns + $no) * $one_space_width)) / $ns / $this->FontSize;
  17497. if ($this->font_spacing != 0) {
  17498. // fixed spacing mode
  17499. $osw = -1000 * $this->font_spacing / $this->FontSize;
  17500. $spacewidthu += $osw;
  17501. }
  17502. $nsmax = $ns;
  17503. $ns = 0;
  17504. reset($lnstring);
  17505. $offset = 0;
  17506. $strcount = 0;
  17507. $prev_epsposbeg = 0;
  17508. $textpos = 0;
  17509. if ($this->isRTLTextDir()) {
  17510. $textpos = $this->wPt;
  17511. }
  17512. while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x', $pmid, $strpiece, PREG_OFFSET_CAPTURE, $offset) == 1) {
  17513. // check if we are inside a string section '[( ... )]'
  17514. $stroffset = strpos($pmid, '[(', $offset);
  17515. if (($stroffset !== false) AND ($stroffset <= $strpiece[2][1])) {
  17516. // set offset to the end of string section
  17517. $offset = strpos($pmid, ')]', $stroffset);
  17518. while (($offset !== false) AND ($pmid[($offset - 1)] == '\\')) {
  17519. $offset = strpos($pmid, ')]', ($offset + 1));
  17520. }
  17521. if ($offset === false) {
  17522. $this->Error('HTML Justification: malformed PDF code.');
  17523. }
  17524. continue;
  17525. }
  17526. if ($this->isRTLTextDir()) {
  17527. $spacew = ($spacewidth * ($nsmax - $ns));
  17528. } else {
  17529. $spacew = ($spacewidth * $ns);
  17530. }
  17531. $offset = $strpiece[2][1] + strlen($strpiece[2][0]);
  17532. $epsposend = strpos($pmid, $this->epsmarker.'Q', $offset);
  17533. if ($epsposend !== null) {
  17534. $epsposend += strlen($this->epsmarker.'Q');
  17535. $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, $offset);
  17536. if ($epsposbeg === null) {
  17537. $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, ($prev_epsposbeg - 6));
  17538. $prev_epsposbeg = $epsposbeg;
  17539. }
  17540. if (($epsposbeg > 0) AND ($epsposend > 0) AND ($offset > $epsposbeg) AND ($offset < $epsposend)) {
  17541. // shift EPS images
  17542. $trx = sprintf('1 0 0 1 %F 0 cm', $spacew);
  17543. $pmid_b = substr($pmid, 0, $epsposbeg);
  17544. $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg));
  17545. $pmid_e = substr($pmid, $epsposend);
  17546. $pmid = $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e;
  17547. $offset = $epsposend;
  17548. continue;
  17549. }
  17550. }
  17551. $currentxpos = 0;
  17552. // shift blocks of code
  17553. switch ($strpiece[2][0]) {
  17554. case 'Td':
  17555. case 'cm':
  17556. case 'm':
  17557. case 'l': {
  17558. // get current X position
  17559. preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches);
  17560. if (!isset($xmatches[1])) {
  17561. break;
  17562. }
  17563. $currentxpos = $xmatches[1];
  17564. $textpos = $currentxpos;
  17565. if (($strcount <= $maxkk) AND ($strpiece[2][0] == 'Td')) {
  17566. $ns = $lnstring[3][$strcount];
  17567. if ($this->isRTLTextDir()) {
  17568. $spacew = ($spacewidth * ($nsmax - $ns));
  17569. }
  17570. ++$strcount;
  17571. }
  17572. // justify block
  17573. if (preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $pmatch) == 1) {
  17574. $newpmid = sprintf('%F', (floatval($pmatch[1]) + $spacew)).' '.$pmatch[2].' x*#!#*x'.$pmatch[3].$pmatch[4];
  17575. $pmid = str_replace($pmatch[0], $newpmid, $pmid);
  17576. unset($pmatch, $newpmid);
  17577. }
  17578. break;
  17579. }
  17580. case 're': {
  17581. // justify block
  17582. if (!TCPDF_STATIC::empty_string($this->lispacer)) {
  17583. $this->lispacer = '';
  17584. break;
  17585. }
  17586. preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $xmatches);
  17587. if (!isset($xmatches[1])) {
  17588. break;
  17589. }
  17590. $currentxpos = $xmatches[1];
  17591. $x_diff = 0;
  17592. $w_diff = 0;
  17593. if ($this->isRTLTextDir()) { // RTL
  17594. if ($currentxpos < $textpos) {
  17595. $x_diff = ($spacewidth * ($nsmax - $lnstring[3][$strcount]));
  17596. $w_diff = ($spacewidth * $lnstring[2][$strcount]);
  17597. } else {
  17598. if ($strcount > 0) {
  17599. $x_diff = ($spacewidth * ($nsmax - $lnstring[3][($strcount - 1)]));
  17600. $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
  17601. }
  17602. }
  17603. } else { // LTR
  17604. if ($currentxpos > $textpos) {
  17605. if ($strcount > 0) {
  17606. $x_diff = ($spacewidth * $lnstring[3][($strcount - 1)]);
  17607. }
  17608. $w_diff = ($spacewidth * $lnstring[2][$strcount]);
  17609. } else {
  17610. if ($strcount > 1) {
  17611. $x_diff = ($spacewidth * $lnstring[3][($strcount - 2)]);
  17612. }
  17613. if ($strcount > 0) {
  17614. $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
  17615. }
  17616. }
  17617. }
  17618. if (preg_match('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $pmatch) == 1) {
  17619. $newx = sprintf('%F', (floatval($pmatch[1]) + $x_diff));
  17620. $neww = sprintf('%F', (floatval($pmatch[3]) + $w_diff));
  17621. $newpmid = $newx.' '.$pmatch[2].' '.$neww.' '.$pmatch[4].' x*#!#*x'.$pmatch[5].$pmatch[6];
  17622. $pmid = str_replace($pmatch[0], $newpmid, $pmid);
  17623. unset($pmatch, $newpmid, $newx, $neww);
  17624. }
  17625. break;
  17626. }
  17627. case 'c': {
  17628. // get current X position
  17629. 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);
  17630. if (!isset($xmatches[1])) {
  17631. break;
  17632. }
  17633. $currentxpos = $xmatches[1];
  17634. // justify block
  17635. 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) {
  17636. $newx1 = sprintf('%F', (floatval($pmatch[1]) + $spacew));
  17637. $newx2 = sprintf('%F', (floatval($pmatch[3]) + $spacew));
  17638. $newx3 = sprintf('%F', (floatval($pmatch[5]) + $spacew));
  17639. $newpmid = $newx1.' '.$pmatch[2].' '.$newx2.' '.$pmatch[4].' '.$newx3.' '.$pmatch[6].' x*#!#*x'.$pmatch[7].$pmatch[8];
  17640. $pmid = str_replace($pmatch[0], $newpmid, $pmid);
  17641. unset($pmatch, $newpmid, $newx1, $newx2, $newx3);
  17642. }
  17643. break;
  17644. }
  17645. }
  17646. // shift the annotations and links
  17647. $cxpos = ($currentxpos / $this->k);
  17648. $lmpos = ($this->lMargin + $this->cell_padding['L'] + $this->feps);
  17649. if ($this->inxobj) {
  17650. // we are inside an XObject template
  17651. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  17652. if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
  17653. if ($cxpos > $lmpos) {
  17654. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += ($spacew / $this->k);
  17655. $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17656. } else {
  17657. $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17658. }
  17659. break;
  17660. }
  17661. }
  17662. } elseif (isset($this->PageAnnots[$this->page])) {
  17663. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  17664. if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
  17665. if ($cxpos > $lmpos) {
  17666. $this->PageAnnots[$this->page][$pak]['x'] += ($spacew / $this->k);
  17667. $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17668. } else {
  17669. $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17670. }
  17671. break;
  17672. }
  17673. }
  17674. }
  17675. } // end of while
  17676. // remove markers
  17677. $pmid = str_replace('x*#!#*x', '', $pmid);
  17678. if ($this->isUnicodeFont()) {
  17679. // multibyte characters
  17680. $spacew = $spacewidthu;
  17681. if ($this->font_stretching != 100) {
  17682. // word spacing is affected by stretching
  17683. $spacew /= ($this->font_stretching / 100);
  17684. }
  17685. // escape special characters
  17686. $pos = 0;
  17687. $pmid = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmid);
  17688. $pmid = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmid);
  17689. if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmid, $pamatch) > 0) {
  17690. foreach ($pamatch[0] as $pk => $pmatch) {
  17691. $replace = $pamatch[1][$pk];
  17692. $replace = str_replace('#!#OP#!#', '(', $replace);
  17693. $replace = str_replace('#!#CP#!#', ')', $replace);
  17694. $newpmid = '[('.str_replace(chr(0).chr(32), ') '.sprintf('%F', $spacew).' (', $replace).')]';
  17695. $pos = strpos($pmid, $pmatch, $pos);
  17696. if ($pos !== false) {
  17697. $pmid = substr_replace($pmid, $newpmid, $pos, strlen($pmatch));
  17698. }
  17699. ++$pos;
  17700. }
  17701. unset($pamatch);
  17702. }
  17703. if ($this->inxobj) {
  17704. // we are inside an XObject template
  17705. $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\n".$pend;
  17706. } else {
  17707. $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\n".$pend);
  17708. }
  17709. $endlinepos = strlen($pstart."\n".$pmid."\n");
  17710. } else {
  17711. // non-unicode (single-byte characters)
  17712. if ($this->font_stretching != 100) {
  17713. // word spacing (Tw) is affected by stretching
  17714. $spacewidth /= ($this->font_stretching / 100);
  17715. }
  17716. $rs = sprintf('%F Tw', $spacewidth);
  17717. $pmid = preg_replace("/\[\(/x", $rs.' [(', $pmid);
  17718. if ($this->inxobj) {
  17719. // we are inside an XObject template
  17720. $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend;
  17721. } else {
  17722. $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend);
  17723. }
  17724. $endlinepos = strlen($pstart."\n".$pmid."\nBT 0 Tw ET\n");
  17725. }
  17726. }
  17727. } // end of J
  17728. } // end if $startlinex
  17729. if (($t_x != 0) OR ($yshift < 0)) {
  17730. // shift the line
  17731. $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k), ($yshift * $this->k));
  17732. $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
  17733. $endlinepos = strlen($pstart);
  17734. if ($this->inxobj) {
  17735. // we are inside an XObject template
  17736. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
  17737. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  17738. if ($pak >= $pask) {
  17739. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  17740. $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  17741. }
  17742. }
  17743. } else {
  17744. $this->setPageBuffer($startlinepage, $pstart.$pend);
  17745. // shift the annotations and links
  17746. if (isset($this->PageAnnots[$this->page])) {
  17747. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  17748. if ($pak >= $pask) {
  17749. $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  17750. $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  17751. }
  17752. }
  17753. }
  17754. }
  17755. $this->y -= $yshift;
  17756. }
  17757. }
  17758. $pbrk = $this->checkPageBreak($this->lasth);
  17759. $this->newline = false;
  17760. $startlinex = $this->x;
  17761. $startliney = $this->y;
  17762. if ($dom[$dom[$key]['parent']]['value'] == 'sup') {
  17763. $startliney -= ((0.3 * $this->FontSizePt) / $this->k);
  17764. } elseif ($dom[$dom[$key]['parent']]['value'] == 'sub') {
  17765. $startliney -= (($this->FontSizePt / 0.7) / $this->k);
  17766. } else {
  17767. $minstartliney = $startliney;
  17768. $maxbottomliney = ($this->y + $this->getCellHeight($fontsize / $this->k));
  17769. }
  17770. $startlinepage = $this->page;
  17771. if (isset($endlinepos) AND (!$pbrk)) {
  17772. $startlinepos = $endlinepos;
  17773. } else {
  17774. if ($this->inxobj) {
  17775. // we are inside an XObject template
  17776. $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
  17777. } elseif (!$this->InFooter) {
  17778. if (isset($this->footerlen[$this->page])) {
  17779. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  17780. } else {
  17781. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  17782. }
  17783. $startlinepos = $this->footerpos[$this->page];
  17784. } else {
  17785. $startlinepos = $this->pagelen[$this->page];
  17786. }
  17787. }
  17788. unset($endlinepos);
  17789. $plalign = $lalign;
  17790. if (isset($this->PageAnnots[$this->page])) {
  17791. $pask = count($this->PageAnnots[$this->page]);
  17792. } else {
  17793. $pask = 0;
  17794. }
  17795. if (!($dom[$key]['tag'] AND !$dom[$key]['opening'] AND ($dom[$key]['value'] == 'table')
  17796. AND (isset($this->emptypagemrk[$this->page]))
  17797. AND ($this->emptypagemrk[$this->page] == $this->pagelen[$this->page]))) {
  17798. $this->SetFont($fontname, $fontstyle, $fontsize);
  17799. if ($wfill) {
  17800. $this->SetFillColorArray($this->bgcolor);
  17801. }
  17802. }
  17803. } // end newline
  17804. if (isset($opentagpos)) {
  17805. unset($opentagpos);
  17806. }
  17807. if ($dom[$key]['tag']) {
  17808. if ($dom[$key]['opening']) {
  17809. // get text indentation (if any)
  17810. if (isset($dom[$key]['text-indent']) AND $dom[$key]['block']) {
  17811. $this->textindent = $dom[$key]['text-indent'];
  17812. $this->newline = true;
  17813. }
  17814. // table
  17815. if (($dom[$key]['value'] == 'table') AND isset($dom[$key]['cols']) AND ($dom[$key]['cols'] > 0)) {
  17816. // available page width
  17817. if ($this->rtl) {
  17818. $wtmp = $this->x - $this->lMargin;
  17819. } else {
  17820. $wtmp = $this->w - $this->rMargin - $this->x;
  17821. }
  17822. // get cell spacing
  17823. if (isset($dom[$key]['attribute']['cellspacing'])) {
  17824. $clsp = $this->getHTMLUnitToUnits($dom[$key]['attribute']['cellspacing'], 1, 'px');
  17825. $cellspacing = array('H' => $clsp, 'V' => $clsp);
  17826. } elseif (isset($dom[$key]['border-spacing'])) {
  17827. $cellspacing = $dom[$key]['border-spacing'];
  17828. } else {
  17829. $cellspacing = array('H' => 0, 'V' => 0);
  17830. }
  17831. // table width
  17832. if (isset($dom[$key]['width'])) {
  17833. $table_width = $this->getHTMLUnitToUnits($dom[$key]['width'], $wtmp, 'px');
  17834. } else {
  17835. $table_width = $wtmp;
  17836. }
  17837. $table_width -= (2 * $cellspacing['H']);
  17838. if (!$this->inthead) {
  17839. $this->y += $cellspacing['V'];
  17840. }
  17841. if ($this->rtl) {
  17842. $cellspacingx = -$cellspacing['H'];
  17843. } else {
  17844. $cellspacingx = $cellspacing['H'];
  17845. }
  17846. // total table width without cellspaces
  17847. $table_columns_width = ($table_width - ($cellspacing['H'] * ($dom[$key]['cols'] - 1)));
  17848. // minimum column width
  17849. $table_min_column_width = ($table_columns_width / $dom[$key]['cols']);
  17850. // array of custom column widths
  17851. $table_colwidths = array_fill(0, $dom[$key]['cols'], $table_min_column_width);
  17852. }
  17853. // table row
  17854. if ($dom[$key]['value'] == 'tr') {
  17855. // reset column counter
  17856. $colid = 0;
  17857. }
  17858. // table cell
  17859. if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  17860. $trid = $dom[$key]['parent'];
  17861. $table_el = $dom[$trid]['parent'];
  17862. if (!isset($dom[$table_el]['cols'])) {
  17863. $dom[$table_el]['cols'] = $dom[$trid]['cols'];
  17864. }
  17865. // store border info
  17866. $tdborder = 0;
  17867. if (isset($dom[$key]['border']) AND !empty($dom[$key]['border'])) {
  17868. $tdborder = $dom[$key]['border'];
  17869. }
  17870. $colspan = intval($dom[$key]['attribute']['colspan']);
  17871. if ($colspan <= 0) {
  17872. $colspan = 1;
  17873. }
  17874. $old_cell_padding = $this->cell_padding;
  17875. if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) {
  17876. $crclpd = $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'], 1, 'px');
  17877. $current_cell_padding = array('L' => $crclpd, 'T' => $crclpd, 'R' => $crclpd, 'B' => $crclpd);
  17878. } elseif (isset($dom[($dom[$trid]['parent'])]['padding'])) {
  17879. $current_cell_padding = $dom[($dom[$trid]['parent'])]['padding'];
  17880. } else {
  17881. $current_cell_padding = array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0);
  17882. }
  17883. $this->cell_padding = $current_cell_padding;
  17884. if (isset($dom[$key]['height'])) {
  17885. // minimum cell height
  17886. $cellh = $this->getHTMLUnitToUnits($dom[$key]['height'], 0, 'px');
  17887. } else {
  17888. $cellh = 0;
  17889. }
  17890. if (isset($dom[$key]['content'])) {
  17891. $cell_content = $dom[$key]['content'];
  17892. } else {
  17893. $cell_content = '&nbsp;';
  17894. }
  17895. $tagtype = $dom[$key]['value'];
  17896. $parentid = $key;
  17897. while (($key < $maxel) AND (!(($dom[$key]['tag']) AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == $tagtype) AND ($dom[$key]['parent'] == $parentid)))) {
  17898. // move $key index forward
  17899. ++$key;
  17900. }
  17901. if (!isset($dom[$trid]['startpage'])) {
  17902. $dom[$trid]['startpage'] = $this->page;
  17903. } else {
  17904. $this->setPage($dom[$trid]['startpage']);
  17905. }
  17906. if (!isset($dom[$trid]['startcolumn'])) {
  17907. $dom[$trid]['startcolumn'] = $this->current_column;
  17908. } elseif ($this->current_column != $dom[$trid]['startcolumn']) {
  17909. $tmpx = $this->x;
  17910. $this->selectColumn($dom[$trid]['startcolumn']);
  17911. $this->x = $tmpx;
  17912. }
  17913. if (!isset($dom[$trid]['starty'])) {
  17914. $dom[$trid]['starty'] = $this->y;
  17915. } else {
  17916. $this->y = $dom[$trid]['starty'];
  17917. }
  17918. if (!isset($dom[$trid]['startx'])) {
  17919. $dom[$trid]['startx'] = $this->x;
  17920. $this->x += $cellspacingx;
  17921. } else {
  17922. $this->x += ($cellspacingx / 2);
  17923. }
  17924. if (isset($dom[$parentid]['attribute']['rowspan'])) {
  17925. $rowspan = intval($dom[$parentid]['attribute']['rowspan']);
  17926. } else {
  17927. $rowspan = 1;
  17928. }
  17929. // skip row-spanned cells started on the previous rows
  17930. if (isset($dom[$table_el]['rowspans'])) {
  17931. $rsk = 0;
  17932. $rskmax = count($dom[$table_el]['rowspans']);
  17933. while ($rsk < $rskmax) {
  17934. $trwsp = $dom[$table_el]['rowspans'][$rsk];
  17935. $rsstartx = $trwsp['startx'];
  17936. $rsendx = $trwsp['endx'];
  17937. // account for margin changes
  17938. if ($trwsp['startpage'] < $this->page) {
  17939. if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$trwsp['startpage']]['orm'])) {
  17940. $dl = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$trwsp['startpage']]['orm']);
  17941. $rsstartx -= $dl;
  17942. $rsendx -= $dl;
  17943. } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$trwsp['startpage']]['olm'])) {
  17944. $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$trwsp['startpage']]['olm']);
  17945. $rsstartx += $dl;
  17946. $rsendx += $dl;
  17947. }
  17948. }
  17949. if (($trwsp['rowspan'] > 0)
  17950. AND ($rsstartx > ($this->x - $cellspacing['H'] - $current_cell_padding['L'] - $this->feps))
  17951. AND ($rsstartx < ($this->x + $cellspacing['H'] + $current_cell_padding['R'] + $this->feps))
  17952. AND (($trwsp['starty'] < ($this->y - $this->feps)) OR ($trwsp['startpage'] < $this->page) OR ($trwsp['startcolumn'] < $this->current_column))) {
  17953. // set the starting X position of the current cell
  17954. $this->x = $rsendx + $cellspacingx;
  17955. // increment column indicator
  17956. $colid += $trwsp['colspan'];
  17957. if (($trwsp['rowspan'] == 1)
  17958. AND (isset($dom[$trid]['endy']))
  17959. AND (isset($dom[$trid]['endpage']))
  17960. AND (isset($dom[$trid]['endcolumn']))
  17961. AND ($trwsp['endpage'] == $dom[$trid]['endpage'])
  17962. AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
  17963. // set ending Y position for row
  17964. $dom[$table_el]['rowspans'][$rsk]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  17965. $dom[$trid]['endy'] = $dom[$table_el]['rowspans'][$rsk]['endy'];
  17966. }
  17967. $rsk = 0;
  17968. } else {
  17969. ++$rsk;
  17970. }
  17971. }
  17972. }
  17973. if (isset($dom[$parentid]['width'])) {
  17974. // user specified width
  17975. $cellw = $this->getHTMLUnitToUnits($dom[$parentid]['width'], $table_columns_width, 'px');
  17976. $tmpcw = ($cellw / $colspan);
  17977. for ($i = 0; $i < $colspan; ++$i) {
  17978. $table_colwidths[($colid + $i)] = $tmpcw;
  17979. }
  17980. } else {
  17981. // inherit column width
  17982. $cellw = 0;
  17983. for ($i = 0; $i < $colspan; ++$i) {
  17984. $cellw += (isset($table_colwidths[($colid + $i)]) ? $table_colwidths[($colid + $i)] : 0);
  17985. }
  17986. }
  17987. $cellw += (($colspan - 1) * $cellspacing['H']);
  17988. // increment column indicator
  17989. $colid += $colspan;
  17990. // add rowspan information to table element
  17991. if ($rowspan > 1) {
  17992. $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));
  17993. }
  17994. $cellid = array_push($dom[$trid]['cellpos'], array('startx' => $this->x));
  17995. if ($rowspan > 1) {
  17996. $dom[$trid]['cellpos'][($cellid - 1)]['rowspanid'] = ($trsid - 1);
  17997. }
  17998. // push background colors
  17999. if (isset($dom[$parentid]['bgcolor']) AND ($dom[$parentid]['bgcolor'] !== false)) {
  18000. $dom[$trid]['cellpos'][($cellid - 1)]['bgcolor'] = $dom[$parentid]['bgcolor'];
  18001. }
  18002. // store border info
  18003. if (isset($tdborder) AND !empty($tdborder)) {
  18004. $dom[$trid]['cellpos'][($cellid - 1)]['border'] = $tdborder;
  18005. }
  18006. $prevLastH = $this->lasth;
  18007. // store some info for multicolumn mode
  18008. if ($this->rtl) {
  18009. $this->colxshift['x'] = $this->w - $this->x - $this->rMargin;
  18010. } else {
  18011. $this->colxshift['x'] = $this->x - $this->lMargin;
  18012. }
  18013. $this->colxshift['s'] = $cellspacing;
  18014. $this->colxshift['p'] = $current_cell_padding;
  18015. // ****** write the cell content ******
  18016. $this->MultiCell($cellw, $cellh, $cell_content, false, $lalign, false, 2, '', '', true, 0, true, true, 0, 'T', false);
  18017. // restore some values
  18018. $this->colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  18019. $this->lasth = $prevLastH;
  18020. $this->cell_padding = $old_cell_padding;
  18021. $dom[$trid]['cellpos'][($cellid - 1)]['endx'] = $this->x;
  18022. // update the end of row position
  18023. if ($rowspan <= 1) {
  18024. if (isset($dom[$trid]['endy'])) {
  18025. if (($this->page == $dom[$trid]['endpage']) AND ($this->current_column == $dom[$trid]['endcolumn'])) {
  18026. $dom[$trid]['endy'] = max($this->y, $dom[$trid]['endy']);
  18027. } elseif (($this->page > $dom[$trid]['endpage']) OR ($this->current_column > $dom[$trid]['endcolumn'])) {
  18028. $dom[$trid]['endy'] = $this->y;
  18029. }
  18030. } else {
  18031. $dom[$trid]['endy'] = $this->y;
  18032. }
  18033. if (isset($dom[$trid]['endpage'])) {
  18034. $dom[$trid]['endpage'] = max($this->page, $dom[$trid]['endpage']);
  18035. } else {
  18036. $dom[$trid]['endpage'] = $this->page;
  18037. }
  18038. if (isset($dom[$trid]['endcolumn'])) {
  18039. $dom[$trid]['endcolumn'] = max($this->current_column, $dom[$trid]['endcolumn']);
  18040. } else {
  18041. $dom[$trid]['endcolumn'] = $this->current_column;
  18042. }
  18043. } else {
  18044. // account for row-spanned cells
  18045. $dom[$table_el]['rowspans'][($trsid - 1)]['endx'] = $this->x;
  18046. $dom[$table_el]['rowspans'][($trsid - 1)]['endy'] = $this->y;
  18047. $dom[$table_el]['rowspans'][($trsid - 1)]['endpage'] = $this->page;
  18048. $dom[$table_el]['rowspans'][($trsid - 1)]['endcolumn'] = $this->current_column;
  18049. }
  18050. if (isset($dom[$table_el]['rowspans'])) {
  18051. // update endy and endpage on rowspanned cells
  18052. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  18053. if ($trwsp['rowspan'] > 0) {
  18054. if (isset($dom[$trid]['endpage'])) {
  18055. if (($trwsp['endpage'] == $dom[$trid]['endpage']) AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
  18056. $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  18057. } elseif (($trwsp['endpage'] < $dom[$trid]['endpage']) OR ($trwsp['endcolumn'] < $dom[$trid]['endcolumn'])) {
  18058. $dom[$table_el]['rowspans'][$k]['endy'] = $dom[$trid]['endy'];
  18059. $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[$trid]['endpage'];
  18060. $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[$trid]['endcolumn'];
  18061. } else {
  18062. $dom[$trid]['endy'] = $this->pagedim[$dom[$trid]['endpage']]['hk'] - $this->pagedim[$dom[$trid]['endpage']]['bm'];
  18063. }
  18064. }
  18065. }
  18066. }
  18067. }
  18068. $this->x += ($cellspacingx / 2);
  18069. } else {
  18070. // opening tag (or self-closing tag)
  18071. if (!isset($opentagpos)) {
  18072. if ($this->inxobj) {
  18073. // we are inside an XObject template
  18074. $opentagpos = strlen($this->xobjects[$this->xobjid]['outdata']);
  18075. } elseif (!$this->InFooter) {
  18076. if (isset($this->footerlen[$this->page])) {
  18077. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  18078. } else {
  18079. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  18080. }
  18081. $opentagpos = $this->footerpos[$this->page];
  18082. }
  18083. }
  18084. $dom = $this->openHTMLTagHandler($dom, $key, $cell);
  18085. }
  18086. } else { // closing tag
  18087. $prev_numpages = $this->numpages;
  18088. $old_bordermrk = $this->bordermrk[$this->page];
  18089. $dom = $this->closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney);
  18090. if ($this->bordermrk[$this->page] > $old_bordermrk) {
  18091. $startlinepos += ($this->bordermrk[$this->page] - $old_bordermrk);
  18092. }
  18093. if ($prev_numpages > $this->numpages) {
  18094. $startlinepage = $this->page;
  18095. }
  18096. }
  18097. } elseif (strlen($dom[$key]['value']) > 0) {
  18098. // print list-item
  18099. if (!TCPDF_STATIC::empty_string($this->lispacer) AND ($this->lispacer != '^')) {
  18100. $this->SetFont($pfontname, $pfontstyle, $pfontsize);
  18101. $this->resetLastH();
  18102. $minstartliney = $this->y;
  18103. $maxbottomliney = ($startliney + $this->getCellHeight($this->FontSize));
  18104. if (is_numeric($pfontsize) AND ($pfontsize > 0)) {
  18105. $this->putHtmlListBullet($this->listnum, $this->lispacer, $pfontsize);
  18106. }
  18107. $this->SetFont($curfontname, $curfontstyle, $curfontsize);
  18108. $this->resetLastH();
  18109. if (is_numeric($pfontsize) AND ($pfontsize > 0) AND is_numeric($curfontsize) AND ($curfontsize > 0) AND ($pfontsize != $curfontsize)) {
  18110. $pfontascent = $this->getFontAscent($pfontname, $pfontstyle, $pfontsize);
  18111. $pfontdescent = $this->getFontDescent($pfontname, $pfontstyle, $pfontsize);
  18112. $this->y += ($this->getCellHeight(($pfontsize - $curfontsize) / $this->k) + $pfontascent - $curfontascent - $pfontdescent + $curfontdescent) / 2;
  18113. $minstartliney = min($this->y, $minstartliney);
  18114. $maxbottomliney = max(($this->y + $this->getCellHeight($pfontsize / $this->k)), $maxbottomliney);
  18115. }
  18116. }
  18117. // text
  18118. $this->htmlvspace = 0;
  18119. $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']);
  18120. if ((!$this->premode) AND $this->isRTLTextDir() AND !$isRTLString) {
  18121. // reverse spaces order
  18122. $lsp = ''; // left spaces
  18123. $rsp = ''; // right spaces
  18124. if (preg_match('/^('.$this->re_space['p'].'+)/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
  18125. $lsp = $matches[1];
  18126. }
  18127. if (preg_match('/('.$this->re_space['p'].'+)$/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
  18128. $rsp = $matches[1];
  18129. }
  18130. $dom[$key]['value'] = $rsp.$this->stringTrim($dom[$key]['value']).$lsp;
  18131. }
  18132. if ($newline) {
  18133. if (!$this->premode) {
  18134. $prelen = strlen($dom[$key]['value']);
  18135. if ($this->isRTLTextDir() AND !$isRTLString) {
  18136. // right trim except non-breaking space
  18137. $dom[$key]['value'] = $this->stringRightTrim($dom[$key]['value']);
  18138. } else {
  18139. // left trim except non-breaking space
  18140. $dom[$key]['value'] = $this->stringLeftTrim($dom[$key]['value']);
  18141. }
  18142. $postlen = strlen($dom[$key]['value']);
  18143. if (($postlen == 0) AND ($prelen > 0)) {
  18144. $dom[$key]['trimmed_space'] = true;
  18145. }
  18146. }
  18147. $newline = false;
  18148. $firstblock = true;
  18149. } else {
  18150. $firstblock = false;
  18151. // replace empty multiple spaces string with a single space
  18152. $dom[$key]['value'] = preg_replace('/^'.$this->re_space['p'].'+$/'.$this->re_space['m'], chr(32), $dom[$key]['value']);
  18153. }
  18154. $strrest = '';
  18155. if ($this->rtl) {
  18156. $this->x -= $this->textindent;
  18157. } else {
  18158. $this->x += $this->textindent;
  18159. }
  18160. if (!isset($dom[$key]['trimmed_space']) OR !$dom[$key]['trimmed_space']) {
  18161. $strlinelen = $this->GetStringWidth($dom[$key]['value']);
  18162. if (!empty($this->HREF) AND (isset($this->HREF['url']))) {
  18163. // HTML <a> Link
  18164. $hrefcolor = '';
  18165. if (isset($dom[($dom[$key]['parent'])]['fgcolor']) AND ($dom[($dom[$key]['parent'])]['fgcolor'] !== false)) {
  18166. $hrefcolor = $dom[($dom[$key]['parent'])]['fgcolor'];
  18167. }
  18168. $hrefstyle = -1;
  18169. if (isset($dom[($dom[$key]['parent'])]['fontstyle']) AND ($dom[($dom[$key]['parent'])]['fontstyle'] !== false)) {
  18170. $hrefstyle = $dom[($dom[$key]['parent'])]['fontstyle'];
  18171. }
  18172. $strrest = $this->addHtmlLink($this->HREF['url'], $dom[$key]['value'], $wfill, true, $hrefcolor, $hrefstyle, true);
  18173. } else {
  18174. $wadj = 0; // space to leave for block continuity
  18175. if ($this->rtl) {
  18176. $cwa = ($this->x - $this->lMargin);
  18177. } else {
  18178. $cwa = ($this->w - $this->rMargin - $this->x);
  18179. }
  18180. if (($strlinelen < $cwa) AND (isset($dom[($key + 1)])) AND ($dom[($key + 1)]['tag']) AND (!$dom[($key + 1)]['block'])) {
  18181. // check the next text blocks for continuity
  18182. $nkey = ($key + 1);
  18183. $write_block = true;
  18184. $same_textdir = true;
  18185. $tmp_fontname = $this->FontFamily;
  18186. $tmp_fontstyle = $this->FontStyle;
  18187. $tmp_fontsize = $this->FontSizePt;
  18188. while ($write_block AND isset($dom[$nkey])) {
  18189. if ($dom[$nkey]['tag']) {
  18190. if ($dom[$nkey]['block']) {
  18191. // end of block
  18192. $write_block = false;
  18193. }
  18194. $tmp_fontname = isset($dom[$nkey]['fontname']) ? $dom[$nkey]['fontname'] : $this->FontFamily;
  18195. $tmp_fontstyle = isset($dom[$nkey]['fontstyle']) ? $dom[$nkey]['fontstyle'] : $this->FontStyle;
  18196. $tmp_fontsize = isset($dom[$nkey]['fontsize']) ? $dom[$nkey]['fontsize'] : $this->FontSizePt;
  18197. $same_textdir = ($dom[$nkey]['dir'] == $dom[$key]['dir']);
  18198. } else {
  18199. $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'+/', $this->re_space['m'], $dom[$nkey]['value']);
  18200. if (isset($nextstr[0]) AND $same_textdir) {
  18201. $wadj += $this->GetStringWidth($nextstr[0], $tmp_fontname, $tmp_fontstyle, $tmp_fontsize);
  18202. if (isset($nextstr[1])) {
  18203. $write_block = false;
  18204. }
  18205. }
  18206. }
  18207. ++$nkey;
  18208. }
  18209. }
  18210. if (($wadj > 0) AND (($strlinelen + $wadj) >= $cwa)) {
  18211. $wadj = 0;
  18212. $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'/', $this->re_space['m'], $dom[$key]['value']);
  18213. $numblks = count($nextstr);
  18214. if ($numblks > 1) {
  18215. // try to split on blank spaces
  18216. $wadj = ($cwa - $strlinelen + $this->GetStringWidth($nextstr[($numblks - 1)]));
  18217. } else {
  18218. // set the entire block on new line
  18219. $wadj = $this->GetStringWidth($nextstr[0]);
  18220. }
  18221. }
  18222. // check for reversed text direction
  18223. if (($wadj > 0) AND (($this->rtl AND ($this->tmprtl === 'L')) OR (!$this->rtl AND ($this->tmprtl === 'R')))) {
  18224. // LTR text on RTL direction or RTL text on LTR direction
  18225. $reverse_dir = true;
  18226. $this->rtl = !$this->rtl;
  18227. $revshift = ($strlinelen + $wadj + 0.000001); // add little quantity for rounding problems
  18228. if ($this->rtl) {
  18229. $this->x += $revshift;
  18230. } else {
  18231. $this->x -= $revshift;
  18232. }
  18233. $xws = $this->x;
  18234. }
  18235. // ****** write only until the end of the line and get the rest ******
  18236. $strrest = $this->Write($this->lasth, $dom[$key]['value'], '', $wfill, '', false, 0, true, $firstblock, 0, $wadj);
  18237. // restore default direction
  18238. if ($reverse_dir AND ($wadj == 0)) {
  18239. $this->x = $xws;
  18240. $this->rtl = !$this->rtl;
  18241. $reverse_dir = false;
  18242. }
  18243. }
  18244. }
  18245. $this->textindent = 0;
  18246. if (strlen($strrest) > 0) {
  18247. // store the remaining string on the previous $key position
  18248. $this->newline = true;
  18249. if ($strrest == $dom[$key]['value']) {
  18250. // used to avoid infinite loop
  18251. ++$loop;
  18252. } else {
  18253. $loop = 0;
  18254. }
  18255. $dom[$key]['value'] = $strrest;
  18256. if ($cell) {
  18257. if ($this->rtl) {
  18258. $this->x -= $this->cell_padding['R'];
  18259. } else {
  18260. $this->x += $this->cell_padding['L'];
  18261. }
  18262. }
  18263. if ($loop < 3) {
  18264. --$key;
  18265. }
  18266. } else {
  18267. $loop = 0;
  18268. // add the positive font spacing of the last character (if any)
  18269. if ($this->font_spacing > 0) {
  18270. if ($this->rtl) {
  18271. $this->x -= $this->font_spacing;
  18272. } else {
  18273. $this->x += $this->font_spacing;
  18274. }
  18275. }
  18276. }
  18277. }
  18278. ++$key;
  18279. 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')) {
  18280. // check if we are on a new page or on a new column
  18281. if ((!$undo) AND (($this->y < $this->start_transaction_y) OR (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['endy'] < $this->start_transaction_y)))) {
  18282. // we are on a new page or on a new column and the total object height is less than the available vertical space.
  18283. // restore previous object
  18284. $this->rollbackTransaction(true);
  18285. // restore previous values
  18286. foreach ($this_method_vars as $vkey => $vval) {
  18287. $$vkey = $vval;
  18288. }
  18289. if (!empty($dom[$key]['thead'])) {
  18290. $this->inthead = true;
  18291. }
  18292. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18293. $pre_y = $this->y;
  18294. if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
  18295. $startliney = $this->y;
  18296. }
  18297. $undo = true; // avoid infinite loop
  18298. } else {
  18299. $undo = false;
  18300. }
  18301. }
  18302. } // end for each $key
  18303. // align the last line
  18304. if (isset($startlinex)) {
  18305. $yshift = ($minstartliney - $startliney);
  18306. if (($yshift > 0) OR ($this->page > $startlinepage)) {
  18307. $yshift = 0;
  18308. }
  18309. $t_x = 0;
  18310. // the last line must be shifted to be aligned as requested
  18311. $linew = abs($this->endlinex - $startlinex);
  18312. if ($this->inxobj) {
  18313. // we are inside an XObject template
  18314. $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
  18315. if (isset($opentagpos)) {
  18316. $midpos = $opentagpos;
  18317. } else {
  18318. $midpos = 0;
  18319. }
  18320. if ($midpos > 0) {
  18321. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
  18322. $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  18323. } else {
  18324. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  18325. $pend = '';
  18326. }
  18327. } else {
  18328. $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
  18329. if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  18330. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  18331. $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
  18332. } elseif (isset($opentagpos)) {
  18333. $midpos = $opentagpos;
  18334. } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  18335. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  18336. $midpos = $this->footerpos[$startlinepage];
  18337. } else {
  18338. $midpos = 0;
  18339. }
  18340. if ($midpos > 0) {
  18341. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
  18342. $pend = substr($this->getPageBuffer($startlinepage), $midpos);
  18343. } else {
  18344. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
  18345. $pend = '';
  18346. }
  18347. }
  18348. if ((isset($plalign) AND ((($plalign == 'C') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
  18349. // calculate shifting amount
  18350. $tw = $w;
  18351. if ($this->lMargin != $prevlMargin) {
  18352. $tw += ($prevlMargin - $this->lMargin);
  18353. }
  18354. if ($this->rMargin != $prevrMargin) {
  18355. $tw += ($prevrMargin - $this->rMargin);
  18356. }
  18357. $one_space_width = $this->GetStringWidth(chr(32));
  18358. $no = 0; // number of spaces on a line contained on a single block
  18359. if ($this->isRTLTextDir()) { // RTL
  18360. // remove left space if exist
  18361. $pos1 = TCPDF_STATIC::revstrpos($pmid, '[(');
  18362. if ($pos1 > 0) {
  18363. $pos1 = intval($pos1);
  18364. if ($this->isUnicodeFont()) {
  18365. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(0).chr(32)));
  18366. $spacelen = 2;
  18367. } else {
  18368. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(32)));
  18369. $spacelen = 1;
  18370. }
  18371. if ($pos1 == $pos2) {
  18372. $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
  18373. if (substr($pmid, $pos1, 4) == '[()]') {
  18374. $linew -= $one_space_width;
  18375. } elseif ($pos1 == strpos($pmid, '[(')) {
  18376. $no = 1;
  18377. }
  18378. }
  18379. }
  18380. } else { // LTR
  18381. // remove right space if exist
  18382. $pos1 = TCPDF_STATIC::revstrpos($pmid, ')]');
  18383. if ($pos1 > 0) {
  18384. $pos1 = intval($pos1);
  18385. if ($this->isUnicodeFont()) {
  18386. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(0).chr(32).')]')) + 2;
  18387. $spacelen = 2;
  18388. } else {
  18389. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(32).')]')) + 1;
  18390. $spacelen = 1;
  18391. }
  18392. if ($pos1 == $pos2) {
  18393. $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
  18394. $linew -= $one_space_width;
  18395. }
  18396. }
  18397. }
  18398. $mdiff = ($tw - $linew);
  18399. if ($plalign == 'C') {
  18400. if ($this->rtl) {
  18401. $t_x = -($mdiff / 2);
  18402. } else {
  18403. $t_x = ($mdiff / 2);
  18404. }
  18405. } elseif ($plalign == 'R') {
  18406. // right alignment on LTR document
  18407. $t_x = $mdiff;
  18408. } elseif ($plalign == 'L') {
  18409. // left alignment on RTL document
  18410. $t_x = -$mdiff;
  18411. }
  18412. } // end if startlinex
  18413. if (($t_x != 0) OR ($yshift < 0)) {
  18414. // shift the line
  18415. $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k), ($yshift * $this->k));
  18416. $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
  18417. $endlinepos = strlen($pstart);
  18418. if ($this->inxobj) {
  18419. // we are inside an XObject template
  18420. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
  18421. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  18422. if ($pak >= $pask) {
  18423. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  18424. $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  18425. }
  18426. }
  18427. } else {
  18428. $this->setPageBuffer($startlinepage, $pstart.$pend);
  18429. // shift the annotations and links
  18430. if (isset($this->PageAnnots[$this->page])) {
  18431. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  18432. if ($pak >= $pask) {
  18433. $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  18434. $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  18435. }
  18436. }
  18437. }
  18438. }
  18439. $this->y -= $yshift;
  18440. $yshift = 0;
  18441. }
  18442. }
  18443. // restore previous values
  18444. $this->setGraphicVars($gvars);
  18445. if ($this->num_columns > 1) {
  18446. $this->selectColumn();
  18447. } elseif ($this->page > $prevPage) {
  18448. $this->lMargin = $this->pagedim[$this->page]['olm'];
  18449. $this->rMargin = $this->pagedim[$this->page]['orm'];
  18450. }
  18451. // restore previous list state
  18452. $this->cell_height_ratio = $prev_cell_height_ratio;
  18453. $this->listnum = $prev_listnum;
  18454. $this->listordered = $prev_listordered;
  18455. $this->listcount = $prev_listcount;
  18456. $this->lispacer = $prev_lispacer;
  18457. if ($ln AND (!($cell AND ($dom[$key-1]['value'] == 'table')))) {
  18458. $this->Ln($this->lasth);
  18459. if (($this->y < $maxbottomliney) AND ($startlinepage == $this->page)) {
  18460. $this->y = $maxbottomliney;
  18461. }
  18462. }
  18463. unset($dom);
  18464. }
  18465. /**
  18466. * Process opening tags.
  18467. * @param $dom (array) html dom array
  18468. * @param $key (int) current element id
  18469. * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
  18470. * @return $dom array
  18471. * @protected
  18472. */
  18473. protected function openHTMLTagHandler($dom, $key, $cell)
  18474. {
  18475. $tag = $dom[$key];
  18476. $parent = $dom[($dom[$key]['parent'])];
  18477. $firsttag = ($key == 1);
  18478. // check for text direction attribute
  18479. if (isset($tag['dir'])) {
  18480. $this->setTempRTL($tag['dir']);
  18481. } else {
  18482. $this->tmprtl = false;
  18483. }
  18484. if ($tag['block']) {
  18485. $hbz = 0; // distance from y to line bottom
  18486. $hb = 0; // vertical space between block tags
  18487. // calculate vertical space for block tags
  18488. if (isset($this->tagvspaces[$tag['value']][0]['h']) && !empty($this->tagvspaces[$tag['value']][0]['h']) && ($this->tagvspaces[$tag['value']][0]['h'] >= 0)) {
  18489. $cur_h = $this->tagvspaces[$tag['value']][0]['h'];
  18490. } elseif (isset($tag['fontsize'])) {
  18491. $cur_h = $this->getCellHeight($tag['fontsize'] / $this->k);
  18492. } else {
  18493. $cur_h = $this->getCellHeight($this->FontSize);
  18494. }
  18495. if (isset($this->tagvspaces[$tag['value']][0]['n'])) {
  18496. $on = $this->tagvspaces[$tag['value']][0]['n'];
  18497. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  18498. $on = 0.6;
  18499. } else {
  18500. $on = 1;
  18501. }
  18502. if ((!isset($this->tagvspaces[$tag['value']])) AND (in_array($tag['value'], array('div', 'dt', 'dd', 'li', 'br', 'hr')))) {
  18503. $hb = 0;
  18504. } else {
  18505. $hb = ($on * $cur_h);
  18506. }
  18507. if (($this->htmlvspace <= 0) AND ($on > 0)) {
  18508. if (isset($parent['fontsize'])) {
  18509. $hbz = (($parent['fontsize'] / $this->k) * $this->cell_height_ratio);
  18510. } else {
  18511. $hbz = $this->getCellHeight($this->FontSize);
  18512. }
  18513. }
  18514. if (isset($dom[($key - 1)]) AND ($dom[($key - 1)]['value'] == 'table')) {
  18515. // fix vertical space after table
  18516. $hbz = 0;
  18517. }
  18518. // closing vertical space
  18519. $hbc = 0;
  18520. if (isset($this->tagvspaces[$tag['value']][1]['h']) && !empty($this->tagvspaces[$tag['value']][1]['h']) && ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) {
  18521. $pre_h = $this->tagvspaces[$tag['value']][1]['h'];
  18522. } elseif (isset($parent['fontsize'])) {
  18523. $pre_h = $this->getCellHeight($parent['fontsize'] / $this->k);
  18524. } else {
  18525. $pre_h = $this->getCellHeight($this->FontSize);
  18526. }
  18527. if (isset($this->tagvspaces[$tag['value']][1]['n'])) {
  18528. $cn = $this->tagvspaces[$tag['value']][1]['n'];
  18529. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  18530. $cn = 0.6;
  18531. } else {
  18532. $cn = 1;
  18533. }
  18534. if (isset($this->tagvspaces[$tag['value']][1])) {
  18535. $hbc = ($cn * $pre_h);
  18536. }
  18537. }
  18538. // Opening tag
  18539. switch ($tag['value']) {
  18540. case 'table': {
  18541. $cp = 0;
  18542. $cs = 0;
  18543. $dom[$key]['rowspans'] = array();
  18544. if (!isset($dom[$key]['attribute']['nested']) OR ($dom[$key]['attribute']['nested'] != 'true')) {
  18545. $this->htmlvspace = 0;
  18546. // set table header
  18547. if (!TCPDF_STATIC::empty_string($dom[$key]['thead'])) {
  18548. // set table header
  18549. $this->thead = $dom[$key]['thead'];
  18550. if (!isset($this->theadMargins) OR (empty($this->theadMargins))) {
  18551. $this->theadMargins = array();
  18552. $this->theadMargins['cell_padding'] = $this->cell_padding;
  18553. $this->theadMargins['lmargin'] = $this->lMargin;
  18554. $this->theadMargins['rmargin'] = $this->rMargin;
  18555. $this->theadMargins['page'] = $this->page;
  18556. $this->theadMargins['cell'] = $cell;
  18557. $this->theadMargins['gvars'] = $this->getGraphicVars();
  18558. }
  18559. }
  18560. }
  18561. // store current margins and page
  18562. $dom[$key]['old_cell_padding'] = $this->cell_padding;
  18563. if (isset($tag['attribute']['cellpadding'])) {
  18564. $pad = $this->getHTMLUnitToUnits($tag['attribute']['cellpadding'], 1, 'px');
  18565. $this->SetCellPadding($pad);
  18566. } elseif (isset($tag['padding'])) {
  18567. $this->cell_padding = $tag['padding'];
  18568. }
  18569. if (isset($tag['attribute']['cellspacing'])) {
  18570. $cs = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
  18571. } elseif (isset($tag['border-spacing'])) {
  18572. $cs = $tag['border-spacing']['V'];
  18573. }
  18574. $prev_y = $this->y;
  18575. if ($this->checkPageBreak(((2 * $cp) + (2 * $cs) + $this->lasth), '', false) OR ($this->y < $prev_y)) {
  18576. $this->inthead = true;
  18577. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18578. $this->checkPageBreak($this->PageBreakTrigger + 1);
  18579. }
  18580. break;
  18581. }
  18582. case 'tr': {
  18583. // array of columns positions
  18584. $dom[$key]['cellpos'] = array();
  18585. break;
  18586. }
  18587. case 'hr': {
  18588. if ((isset($tag['height'])) AND ($tag['height'] != '')) {
  18589. $hrHeight = $this->getHTMLUnitToUnits($tag['height'], 1, 'px');
  18590. } else {
  18591. $hrHeight = $this->GetLineWidth();
  18592. }
  18593. $this->addHTMLVertSpace($hbz, max($hb, ($hrHeight / 2)), $cell, $firsttag);
  18594. $x = $this->GetX();
  18595. $y = $this->GetY();
  18596. $wtmp = $this->w - $this->lMargin - $this->rMargin;
  18597. if ($cell) {
  18598. $wtmp -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  18599. }
  18600. if ((isset($tag['width'])) AND ($tag['width'] != '')) {
  18601. $hrWidth = $this->getHTMLUnitToUnits($tag['width'], $wtmp, 'px');
  18602. } else {
  18603. $hrWidth = $wtmp;
  18604. }
  18605. $prevlinewidth = $this->GetLineWidth();
  18606. $this->SetLineWidth($hrHeight);
  18607. $this->Line($x, $y, $x + $hrWidth, $y);
  18608. $this->SetLineWidth($prevlinewidth);
  18609. $this->addHTMLVertSpace(max($hbc, ($hrHeight / 2)), 0, $cell, !isset($dom[($key + 1)]));
  18610. break;
  18611. }
  18612. case 'a': {
  18613. if (array_key_exists('href', $tag['attribute'])) {
  18614. $this->HREF['url'] = $tag['attribute']['href'];
  18615. }
  18616. break;
  18617. }
  18618. case 'img': {
  18619. if (empty($tag['attribute']['src'])) {
  18620. break;
  18621. }
  18622. $imgsrc = $tag['attribute']['src'];
  18623. if ($imgsrc[0] === '@') {
  18624. // data stream
  18625. $imgsrc = '@'.base64_decode(substr($imgsrc, 1));
  18626. $type = '';
  18627. } else {
  18628. // @CHANGE LDR Add support for src="file://..." links
  18629. if (strpos($imgsrc, 'file://') === 0) {
  18630. $imgsrc = str_replace('file://', '/', $imgsrc);
  18631. $imgsrc = urldecode($imgsrc);
  18632. $testscrtype = @parse_url($imgsrc);
  18633. if (empty($testscrtype['query'])) {
  18634. // convert URL to server path
  18635. $imgsrc = str_replace(K_PATH_URL, K_PATH_MAIN, $imgsrc);
  18636. } elseif (preg_match('|^https?://|', $imgsrc) !== 1) {
  18637. // convert URL to server path
  18638. $imgsrc = str_replace(K_PATH_MAIN, K_PATH_URL, $imgsrc);
  18639. }
  18640. } elseif (($imgsrc[0] === '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
  18641. // fix image path
  18642. $findroot = strpos($imgsrc, $_SERVER['DOCUMENT_ROOT']);
  18643. if (($findroot === false) OR ($findroot > 1)) {
  18644. if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
  18645. $imgsrc = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$imgsrc;
  18646. } else {
  18647. $imgsrc = $_SERVER['DOCUMENT_ROOT'].$imgsrc;
  18648. }
  18649. }
  18650. $imgsrc = urldecode($imgsrc);
  18651. $testscrtype = @parse_url($imgsrc);
  18652. if (empty($testscrtype['query'])) {
  18653. // convert URL to server path
  18654. $imgsrc = str_replace(K_PATH_URL, K_PATH_MAIN, $imgsrc);
  18655. } elseif (preg_match('|^https?://|', $imgsrc) !== 1) {
  18656. // convert URL to server path
  18657. $imgsrc = str_replace(K_PATH_MAIN, K_PATH_URL, $imgsrc);
  18658. }
  18659. }
  18660. // get image type
  18661. $type = TCPDF_IMAGES::getImageFileType($imgsrc);
  18662. }
  18663. if (!isset($tag['width'])) {
  18664. $tag['width'] = 0;
  18665. }
  18666. if (!isset($tag['height'])) {
  18667. $tag['height'] = 0;
  18668. }
  18669. //if (!isset($tag['attribute']['align'])) {
  18670. // the only alignment supported is "bottom"
  18671. // further development is required for other modes.
  18672. $tag['attribute']['align'] = 'bottom';
  18673. //}
  18674. switch ($tag['attribute']['align']) {
  18675. case 'top': {
  18676. $align = 'T';
  18677. break;
  18678. }
  18679. case 'middle': {
  18680. $align = 'M';
  18681. break;
  18682. }
  18683. case 'bottom': {
  18684. $align = 'B';
  18685. break;
  18686. }
  18687. default: {
  18688. $align = 'B';
  18689. break;
  18690. }
  18691. }
  18692. $prevy = $this->y;
  18693. $xpos = $this->x;
  18694. $imglink = '';
  18695. if (isset($this->HREF['url']) AND !TCPDF_STATIC::empty_string($this->HREF['url'])) {
  18696. $imglink = $this->HREF['url'];
  18697. if ($imglink[0] == '#') {
  18698. // convert url to internal link
  18699. $lnkdata = explode(',', $imglink);
  18700. if (isset($lnkdata[0])) {
  18701. $page = intval(substr($lnkdata[0], 1));
  18702. if (empty($page) OR ($page <= 0)) {
  18703. $page = $this->page;
  18704. }
  18705. if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
  18706. $lnky = floatval($lnkdata[1]);
  18707. } else {
  18708. $lnky = 0;
  18709. }
  18710. $imglink = $this->AddLink();
  18711. $this->SetLink($imglink, $lnky, $page);
  18712. }
  18713. }
  18714. }
  18715. $border = 0;
  18716. if (isset($tag['border']) AND !empty($tag['border'])) {
  18717. // currently only support 1 (frame) or a combination of 'LTRB'
  18718. $border = $tag['border'];
  18719. }
  18720. $iw = '';
  18721. if (isset($tag['width'])) {
  18722. $iw = $this->getHTMLUnitToUnits($tag['width'], ($tag['fontsize'] / $this->k), 'px', false);
  18723. }
  18724. $ih = '';
  18725. if (isset($tag['height'])) {
  18726. $ih = $this->getHTMLUnitToUnits($tag['height'], ($tag['fontsize'] / $this->k), 'px', false);
  18727. }
  18728. if (($type == 'eps') OR ($type == 'ai')) {
  18729. $this->ImageEps($imgsrc, $xpos, $this->y, $iw, $ih, $imglink, true, $align, '', $border, true);
  18730. } elseif ($type == 'svg') {
  18731. $this->ImageSVG($imgsrc, $xpos, $this->y, $iw, $ih, $imglink, $align, '', $border, true);
  18732. } else {
  18733. $this->Image($imgsrc, $xpos, $this->y, $iw, $ih, '', $imglink, $align, false, 300, '', false, false, $border, false, false, true);
  18734. }
  18735. switch ($align) {
  18736. case 'T': {
  18737. $this->y = $prevy;
  18738. break;
  18739. }
  18740. case 'M': {
  18741. $this->y = (($this->img_rb_y + $prevy - ($this->getCellHeight($tag['fontsize'] / $this->k))) / 2);
  18742. break;
  18743. }
  18744. case 'B': {
  18745. $this->y = $this->img_rb_y - ($this->getCellHeight($tag['fontsize'] / $this->k) - ($this->getFontDescent($tag['fontname'], $tag['fontstyle'], $tag['fontsize']) * $this->cell_height_ratio));
  18746. break;
  18747. }
  18748. }
  18749. break;
  18750. }
  18751. case 'dl': {
  18752. ++$this->listnum;
  18753. if ($this->listnum == 1) {
  18754. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18755. } else {
  18756. $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
  18757. }
  18758. break;
  18759. }
  18760. case 'dt': {
  18761. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18762. break;
  18763. }
  18764. case 'dd': {
  18765. if ($this->rtl) {
  18766. $this->rMargin += $this->listindent;
  18767. } else {
  18768. $this->lMargin += $this->listindent;
  18769. }
  18770. ++$this->listindentlevel;
  18771. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18772. break;
  18773. }
  18774. case 'ul':
  18775. case 'ol': {
  18776. ++$this->listnum;
  18777. if ($tag['value'] == 'ol') {
  18778. $this->listordered[$this->listnum] = true;
  18779. } else {
  18780. $this->listordered[$this->listnum] = false;
  18781. }
  18782. if (isset($tag['attribute']['start'])) {
  18783. $this->listcount[$this->listnum] = intval($tag['attribute']['start']) - 1;
  18784. } else {
  18785. $this->listcount[$this->listnum] = 0;
  18786. }
  18787. if ($this->rtl) {
  18788. $this->rMargin += $this->listindent;
  18789. $this->x -= $this->listindent;
  18790. } else {
  18791. $this->lMargin += $this->listindent;
  18792. $this->x += $this->listindent;
  18793. }
  18794. ++$this->listindentlevel;
  18795. if ($this->listnum == 1) {
  18796. if ($key > 1) {
  18797. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18798. }
  18799. } else {
  18800. $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
  18801. }
  18802. break;
  18803. }
  18804. case 'li': {
  18805. if ($key > 2) {
  18806. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18807. }
  18808. if ($this->listordered[$this->listnum]) {
  18809. // ordered item
  18810. if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) {
  18811. $this->lispacer = $parent['attribute']['type'];
  18812. } elseif (isset($parent['listtype']) AND !TCPDF_STATIC::empty_string($parent['listtype'])) {
  18813. $this->lispacer = $parent['listtype'];
  18814. } elseif (isset($this->lisymbol) AND !TCPDF_STATIC::empty_string($this->lisymbol)) {
  18815. $this->lispacer = $this->lisymbol;
  18816. } else {
  18817. $this->lispacer = '#';
  18818. }
  18819. ++$this->listcount[$this->listnum];
  18820. if (isset($tag['attribute']['value'])) {
  18821. $this->listcount[$this->listnum] = intval($tag['attribute']['value']);
  18822. }
  18823. } else {
  18824. // unordered item
  18825. if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) {
  18826. $this->lispacer = $parent['attribute']['type'];
  18827. } elseif (isset($parent['listtype']) AND !TCPDF_STATIC::empty_string($parent['listtype'])) {
  18828. $this->lispacer = $parent['listtype'];
  18829. } elseif (isset($this->lisymbol) AND !TCPDF_STATIC::empty_string($this->lisymbol)) {
  18830. $this->lispacer = $this->lisymbol;
  18831. } else {
  18832. $this->lispacer = '!';
  18833. }
  18834. }
  18835. break;
  18836. }
  18837. case 'blockquote': {
  18838. if ($this->rtl) {
  18839. $this->rMargin += $this->listindent;
  18840. } else {
  18841. $this->lMargin += $this->listindent;
  18842. }
  18843. ++$this->listindentlevel;
  18844. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18845. break;
  18846. }
  18847. case 'br': {
  18848. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18849. break;
  18850. }
  18851. case 'div': {
  18852. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18853. break;
  18854. }
  18855. case 'p': {
  18856. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18857. break;
  18858. }
  18859. case 'pre': {
  18860. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18861. $this->premode = true;
  18862. break;
  18863. }
  18864. case 'sup': {
  18865. $this->SetXY($this->GetX(), $this->GetY() - ((0.7 * $this->FontSizePt) / $this->k));
  18866. break;
  18867. }
  18868. case 'sub': {
  18869. $this->SetXY($this->GetX(), $this->GetY() + ((0.3 * $this->FontSizePt) / $this->k));
  18870. break;
  18871. }
  18872. case 'h1':
  18873. case 'h2':
  18874. case 'h3':
  18875. case 'h4':
  18876. case 'h5':
  18877. case 'h6': {
  18878. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18879. break;
  18880. }
  18881. // Form fields (since 4.8.000 - 2009-09-07)
  18882. case 'form': {
  18883. if (isset($tag['attribute']['action'])) {
  18884. $this->form_action = $tag['attribute']['action'];
  18885. } else {
  18886. $this->Error('Please explicitly set action attribute path!');
  18887. }
  18888. if (isset($tag['attribute']['enctype'])) {
  18889. $this->form_enctype = $tag['attribute']['enctype'];
  18890. } else {
  18891. $this->form_enctype = 'application/x-www-form-urlencoded';
  18892. }
  18893. if (isset($tag['attribute']['method'])) {
  18894. $this->form_mode = $tag['attribute']['method'];
  18895. } else {
  18896. $this->form_mode = 'post';
  18897. }
  18898. break;
  18899. }
  18900. case 'input': {
  18901. if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18902. $name = $tag['attribute']['name'];
  18903. } else {
  18904. break;
  18905. }
  18906. $prop = array();
  18907. $opt = array();
  18908. if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC::empty_string($tag['attribute']['readonly'])) {
  18909. $prop['readonly'] = true;
  18910. }
  18911. if (isset($tag['attribute']['value']) AND !TCPDF_STATIC::empty_string($tag['attribute']['value'])) {
  18912. $value = $tag['attribute']['value'];
  18913. }
  18914. if (isset($tag['attribute']['maxlength']) AND !TCPDF_STATIC::empty_string($tag['attribute']['maxlength'])) {
  18915. $opt['maxlen'] = intval($tag['attribute']['maxlength']);
  18916. }
  18917. $h = $this->getCellHeight($this->FontSize);
  18918. if (isset($tag['attribute']['size']) AND !TCPDF_STATIC::empty_string($tag['attribute']['size'])) {
  18919. $w = intval($tag['attribute']['size']) * $this->GetStringWidth(chr(32)) * 2;
  18920. } else {
  18921. $w = $h;
  18922. }
  18923. if (isset($tag['attribute']['checked']) AND (($tag['attribute']['checked'] == 'checked') OR ($tag['attribute']['checked'] == 'true'))) {
  18924. $checked = true;
  18925. } else {
  18926. $checked = false;
  18927. }
  18928. if (isset($tag['align'])) {
  18929. switch ($tag['align']) {
  18930. case 'C': {
  18931. $opt['q'] = 1;
  18932. break;
  18933. }
  18934. case 'R': {
  18935. $opt['q'] = 2;
  18936. break;
  18937. }
  18938. case 'L':
  18939. default: {
  18940. break;
  18941. }
  18942. }
  18943. }
  18944. switch ($tag['attribute']['type']) {
  18945. case 'text': {
  18946. if (isset($value)) {
  18947. $opt['v'] = $value;
  18948. }
  18949. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18950. break;
  18951. }
  18952. case 'password': {
  18953. if (isset($value)) {
  18954. $opt['v'] = $value;
  18955. }
  18956. $prop['password'] = 'true';
  18957. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18958. break;
  18959. }
  18960. case 'checkbox': {
  18961. if (!isset($value)) {
  18962. break;
  18963. }
  18964. $this->CheckBox($name, $w, $checked, $prop, $opt, $value, '', '', false);
  18965. break;
  18966. }
  18967. case 'radio': {
  18968. if (!isset($value)) {
  18969. break;
  18970. }
  18971. $this->RadioButton($name, $w, $prop, $opt, $value, $checked, '', '', false);
  18972. break;
  18973. }
  18974. case 'submit': {
  18975. if (!isset($value)) {
  18976. $value = 'submit';
  18977. }
  18978. $w = $this->GetStringWidth($value) * 1.5;
  18979. $h *= 1.6;
  18980. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18981. $action = array();
  18982. $action['S'] = 'SubmitForm';
  18983. $action['F'] = $this->form_action;
  18984. if ($this->form_enctype != 'FDF') {
  18985. $action['Flags'] = array('ExportFormat');
  18986. }
  18987. if ($this->form_mode == 'get') {
  18988. $action['Flags'] = array('GetMethod');
  18989. }
  18990. $this->Button($name, $w, $h, $value, $action, $prop, $opt, '', '', false);
  18991. break;
  18992. }
  18993. case 'reset': {
  18994. if (!isset($value)) {
  18995. $value = 'reset';
  18996. }
  18997. $w = $this->GetStringWidth($value) * 1.5;
  18998. $h *= 1.6;
  18999. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  19000. $this->Button($name, $w, $h, $value, array('S'=>'ResetForm'), $prop, $opt, '', '', false);
  19001. break;
  19002. }
  19003. case 'file': {
  19004. $prop['fileSelect'] = 'true';
  19005. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  19006. if (!isset($value)) {
  19007. $value = '*';
  19008. }
  19009. $w = $this->GetStringWidth($value) * 2;
  19010. $h *= 1.2;
  19011. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  19012. $jsaction = 'var f=this.getField(\''.$name.'\'); f.browseForFileToSubmit();';
  19013. $this->Button('FB_'.$name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  19014. break;
  19015. }
  19016. case 'hidden': {
  19017. if (isset($value)) {
  19018. $opt['v'] = $value;
  19019. }
  19020. $opt['f'] = array('invisible', 'hidden');
  19021. $this->TextField($name, 0, 0, $prop, $opt, '', '', false);
  19022. break;
  19023. }
  19024. case 'image': {
  19025. // THIS TYPE MUST BE FIXED
  19026. if (isset($tag['attribute']['src']) AND !TCPDF_STATIC::empty_string($tag['attribute']['src'])) {
  19027. $img = $tag['attribute']['src'];
  19028. } else {
  19029. break;
  19030. }
  19031. $value = 'img';
  19032. //$opt['mk'] = array('i'=>$img, 'tp'=>1, 'if'=>array('sw'=>'A', 's'=>'A', 'fb'=>false));
  19033. if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
  19034. $jsaction = $tag['attribute']['onclick'];
  19035. } else {
  19036. $jsaction = '';
  19037. }
  19038. $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  19039. break;
  19040. }
  19041. case 'button': {
  19042. if (!isset($value)) {
  19043. $value = ' ';
  19044. }
  19045. $w = $this->GetStringWidth($value) * 1.5;
  19046. $h *= 1.6;
  19047. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  19048. if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
  19049. $jsaction = $tag['attribute']['onclick'];
  19050. } else {
  19051. $jsaction = '';
  19052. }
  19053. $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  19054. break;
  19055. }
  19056. }
  19057. break;
  19058. }
  19059. case 'textarea': {
  19060. $prop = array();
  19061. $opt = array();
  19062. if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC::empty_string($tag['attribute']['readonly'])) {
  19063. $prop['readonly'] = true;
  19064. }
  19065. if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  19066. $name = $tag['attribute']['name'];
  19067. } else {
  19068. break;
  19069. }
  19070. if (isset($tag['attribute']['value']) AND !TCPDF_STATIC::empty_string($tag['attribute']['value'])) {
  19071. $opt['v'] = $tag['attribute']['value'];
  19072. }
  19073. if (isset($tag['attribute']['cols']) AND !TCPDF_STATIC::empty_string($tag['attribute']['cols'])) {
  19074. $w = intval($tag['attribute']['cols']) * $this->GetStringWidth(chr(32)) * 2;
  19075. } else {
  19076. $w = 40;
  19077. }
  19078. if (isset($tag['attribute']['rows']) AND !TCPDF_STATIC::empty_string($tag['attribute']['rows'])) {
  19079. $h = intval($tag['attribute']['rows']) * $this->getCellHeight($this->FontSize);
  19080. } else {
  19081. $h = 10;
  19082. }
  19083. $prop['multiline'] = 'true';
  19084. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  19085. break;
  19086. }
  19087. case 'select': {
  19088. $h = $this->getCellHeight($this->FontSize);
  19089. if (isset($tag['attribute']['size']) AND !TCPDF_STATIC::empty_string($tag['attribute']['size'])) {
  19090. $h *= ($tag['attribute']['size'] + 1);
  19091. }
  19092. $prop = array();
  19093. $opt = array();
  19094. if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  19095. $name = $tag['attribute']['name'];
  19096. } else {
  19097. break;
  19098. }
  19099. $w = 0;
  19100. if (isset($tag['attribute']['opt']) AND !TCPDF_STATIC::empty_string($tag['attribute']['opt'])) {
  19101. $options = explode('#!NwL!#', $tag['attribute']['opt']);
  19102. $values = array();
  19103. foreach ($options as $val) {
  19104. if (strpos($val, '#!TaB!#') !== false) {
  19105. $opts = explode('#!TaB!#', $val);
  19106. $values[] = $opts;
  19107. $w = max($w, $this->GetStringWidth($opts[1]));
  19108. } else {
  19109. $values[] = $val;
  19110. $w = max($w, $this->GetStringWidth($val));
  19111. }
  19112. }
  19113. } else {
  19114. break;
  19115. }
  19116. $w *= 2;
  19117. if (isset($tag['attribute']['multiple']) AND ($tag['attribute']['multiple']='multiple')) {
  19118. $prop['multipleSelection'] = 'true';
  19119. $this->ListBox($name, $w, $h, $values, $prop, $opt, '', '', false);
  19120. } else {
  19121. $this->ComboBox($name, $w, $h, $values, $prop, $opt, '', '', false);
  19122. }
  19123. break;
  19124. }
  19125. case 'tcpdf': {
  19126. if (defined('K_TCPDF_CALLS_IN_HTML') AND (K_TCPDF_CALLS_IN_HTML === true)) {
  19127. // Special tag used to call TCPDF methods
  19128. if (isset($tag['attribute']['method'])) {
  19129. $tcpdf_method = $tag['attribute']['method'];
  19130. if (method_exists($this, $tcpdf_method)) {
  19131. if (isset($tag['attribute']['params']) AND (!empty($tag['attribute']['params']))) {
  19132. $params = $this->unserializeTCPDFtagParameters($tag['attribute']['params']);
  19133. call_user_func_array(array($this, $tcpdf_method), $params);
  19134. } else {
  19135. $this->$tcpdf_method();
  19136. }
  19137. $this->newline = true;
  19138. }
  19139. }
  19140. }
  19141. break;
  19142. }
  19143. default: {
  19144. break;
  19145. }
  19146. }
  19147. // define tags that support borders and background colors
  19148. $bordertags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table');
  19149. if (in_array($tag['value'], $bordertags)) {
  19150. // set border
  19151. $dom[$key]['borderposition'] = $this->getBorderStartPosition();
  19152. }
  19153. if ($dom[$key]['self'] AND isset($dom[$key]['attribute']['pagebreakafter'])) {
  19154. $pba = $dom[$key]['attribute']['pagebreakafter'];
  19155. // check for pagebreak
  19156. if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
  19157. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  19158. $this->checkPageBreak($this->PageBreakTrigger + 1);
  19159. }
  19160. if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  19161. OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  19162. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  19163. $this->checkPageBreak($this->PageBreakTrigger + 1);
  19164. }
  19165. }
  19166. return $dom;
  19167. }
  19168. /**
  19169. * Process closing tags.
  19170. * @param $dom (array) html dom array
  19171. * @param $key (int) current element id
  19172. * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
  19173. * @param $maxbottomliney (int) maximum y value of current line
  19174. * @return $dom array
  19175. * @protected
  19176. */
  19177. protected function closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney = 0)
  19178. {
  19179. $tag = $dom[$key];
  19180. $parent = $dom[($dom[$key]['parent'])];
  19181. $lasttag = ((!isset($dom[($key + 1)])) OR ((!isset($dom[($key + 2)])) AND ($dom[($key + 1)]['value'] == 'marker')));
  19182. $in_table_head = false;
  19183. // maximum x position (used to draw borders)
  19184. if ($this->rtl) {
  19185. $xmax = $this->w;
  19186. } else {
  19187. $xmax = 0;
  19188. }
  19189. if ($tag['block']) {
  19190. $hbz = 0; // distance from y to line bottom
  19191. $hb = 0; // vertical space between block tags
  19192. // calculate vertical space for block tags
  19193. if (isset($this->tagvspaces[$tag['value']][1]['h']) && !empty($this->tagvspaces[$tag['value']][1]['h']) && ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) {
  19194. $pre_h = $this->tagvspaces[$tag['value']][1]['h'];
  19195. } elseif (isset($parent['fontsize'])) {
  19196. $pre_h = $this->getCellHeight($parent['fontsize'] / $this->k);
  19197. } else {
  19198. $pre_h = $this->getCellHeight($this->FontSize);
  19199. }
  19200. if (isset($this->tagvspaces[$tag['value']][1]['n'])) {
  19201. $cn = $this->tagvspaces[$tag['value']][1]['n'];
  19202. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  19203. $cn = 0.6;
  19204. } else {
  19205. $cn = 1;
  19206. }
  19207. if ((!isset($this->tagvspaces[$tag['value']])) AND ($tag['value'] == 'div')) {
  19208. $hb = 0;
  19209. } else {
  19210. $hb = ($cn * $pre_h);
  19211. }
  19212. if ($maxbottomliney > $this->PageBreakTrigger) {
  19213. $hbz = $this->getCellHeight($this->FontSize);
  19214. } elseif ($this->y < $maxbottomliney) {
  19215. $hbz = ($maxbottomliney - $this->y);
  19216. }
  19217. }
  19218. // Closing tag
  19219. switch ($tag['value']) {
  19220. case 'tr': {
  19221. $table_el = $dom[($dom[$key]['parent'])]['parent'];
  19222. if (!isset($parent['endy'])) {
  19223. $dom[($dom[$key]['parent'])]['endy'] = $this->y;
  19224. $parent['endy'] = $this->y;
  19225. }
  19226. if (!isset($parent['endpage'])) {
  19227. $dom[($dom[$key]['parent'])]['endpage'] = $this->page;
  19228. $parent['endpage'] = $this->page;
  19229. }
  19230. if (!isset($parent['endcolumn'])) {
  19231. $dom[($dom[$key]['parent'])]['endcolumn'] = $this->current_column;
  19232. $parent['endcolumn'] = $this->current_column;
  19233. }
  19234. // update row-spanned cells
  19235. if (isset($dom[$table_el]['rowspans'])) {
  19236. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  19237. $dom[$table_el]['rowspans'][$k]['rowspan'] -= 1;
  19238. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  19239. if (($dom[$table_el]['rowspans'][$k]['endpage'] == $parent['endpage']) AND ($dom[$table_el]['rowspans'][$k]['endcolumn'] == $parent['endcolumn'])) {
  19240. $dom[($dom[$key]['parent'])]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $parent['endy']);
  19241. } elseif (($dom[$table_el]['rowspans'][$k]['endpage'] > $parent['endpage']) OR ($dom[$table_el]['rowspans'][$k]['endcolumn'] > $parent['endcolumn'])) {
  19242. $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  19243. $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  19244. $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  19245. }
  19246. }
  19247. }
  19248. // report new endy and endpage to the rowspanned cells
  19249. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  19250. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  19251. $dom[$table_el]['rowspans'][$k]['endpage'] = max($dom[$table_el]['rowspans'][$k]['endpage'], $dom[($dom[$key]['parent'])]['endpage']);
  19252. $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  19253. $dom[$table_el]['rowspans'][$k]['endcolumn'] = max($dom[$table_el]['rowspans'][$k]['endcolumn'], $dom[($dom[$key]['parent'])]['endcolumn']);
  19254. $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  19255. $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $dom[($dom[$key]['parent'])]['endy']);
  19256. $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  19257. }
  19258. }
  19259. // update remaining rowspanned cells
  19260. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  19261. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  19262. $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[($dom[$key]['parent'])]['endpage'];
  19263. $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[($dom[$key]['parent'])]['endcolumn'];
  19264. $dom[$table_el]['rowspans'][$k]['endy'] = $dom[($dom[$key]['parent'])]['endy'];
  19265. }
  19266. }
  19267. }
  19268. $prev_page = $this->page;
  19269. $this->setPage($dom[($dom[$key]['parent'])]['endpage']);
  19270. if ($this->num_columns > 1) {
  19271. if (($prev_page < $this->page)
  19272. AND ((($this->current_column == 0) AND ($dom[($dom[$key]['parent'])]['endcolumn'] == ($this->num_columns - 1)))
  19273. OR ($this->current_column == $dom[($dom[$key]['parent'])]['endcolumn']))) {
  19274. // page jump
  19275. $this->selectColumn(0);
  19276. $dom[($dom[$key]['parent'])]['endcolumn'] = 0;
  19277. $dom[($dom[$key]['parent'])]['endy'] = $this->y;
  19278. } else {
  19279. $this->selectColumn($dom[($dom[$key]['parent'])]['endcolumn']);
  19280. $this->y = $dom[($dom[$key]['parent'])]['endy'];
  19281. }
  19282. } else {
  19283. $this->y = $dom[($dom[$key]['parent'])]['endy'];
  19284. }
  19285. if (isset($dom[$table_el]['attribute']['cellspacing'])) {
  19286. $this->y += $this->getHTMLUnitToUnits($dom[$table_el]['attribute']['cellspacing'], 1, 'px');
  19287. } elseif (isset($dom[$table_el]['border-spacing'])) {
  19288. $this->y += $dom[$table_el]['border-spacing']['V'];
  19289. }
  19290. $this->Ln(0, $cell);
  19291. if ($this->current_column == $parent['startcolumn']) {
  19292. $this->x = $parent['startx'];
  19293. }
  19294. // account for booklet mode
  19295. if ($this->page > $parent['startpage']) {
  19296. if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$parent['startpage']]['orm'])) {
  19297. $this->x -= ($this->pagedim[$this->page]['orm'] - $this->pagedim[$parent['startpage']]['orm']);
  19298. } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$parent['startpage']]['olm'])) {
  19299. $this->x += ($this->pagedim[$this->page]['olm'] - $this->pagedim[$parent['startpage']]['olm']);
  19300. }
  19301. }
  19302. break;
  19303. }
  19304. case 'tablehead':
  19305. // closing tag used for the thead part
  19306. $in_table_head = true;
  19307. $this->inthead = false;
  19308. case 'table': {
  19309. $table_el = $parent;
  19310. // set default border
  19311. if (isset($table_el['attribute']['border']) AND ($table_el['attribute']['border'] > 0)) {
  19312. // set default border
  19313. $border = array('LTRB' => array('width' => $this->getCSSBorderWidth($table_el['attribute']['border']), 'cap'=>'square', 'join'=>'miter', 'dash'=> 0, 'color'=>array(0,0,0)));
  19314. } else {
  19315. $border = 0;
  19316. }
  19317. $default_border = $border;
  19318. // fix bottom line alignment of last line before page break
  19319. foreach ($dom[($dom[$key]['parent'])]['trids'] as $j => $trkey) {
  19320. // update row-spanned cells
  19321. if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  19322. foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
  19323. if (isset($prevtrkey) AND ($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] > 0)) {
  19324. $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] = $trkey;
  19325. }
  19326. if ($dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] == $trkey) {
  19327. $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] -= 1;
  19328. }
  19329. }
  19330. }
  19331. if (isset($prevtrkey) AND ($dom[$trkey]['startpage'] > $dom[$prevtrkey]['endpage'])) {
  19332. $pgendy = $this->pagedim[$dom[$prevtrkey]['endpage']]['hk'] - $this->pagedim[$dom[$prevtrkey]['endpage']]['bm'];
  19333. $dom[$prevtrkey]['endy'] = $pgendy;
  19334. // update row-spanned cells
  19335. if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  19336. foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
  19337. if (($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] >= 0) AND ($trwsp['endpage'] == $dom[$prevtrkey]['endpage'])) {
  19338. $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'] = $pgendy;
  19339. $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] = -1;
  19340. }
  19341. }
  19342. }
  19343. }
  19344. $prevtrkey = $trkey;
  19345. $table_el = $dom[($dom[$key]['parent'])];
  19346. }
  19347. // for each row
  19348. if (count($table_el['trids']) > 0) {
  19349. unset($xmax);
  19350. }
  19351. foreach ($table_el['trids'] as $j => $trkey) {
  19352. $parent = $dom[$trkey];
  19353. if (!isset($xmax)) {
  19354. $xmax = $parent['cellpos'][(count($parent['cellpos']) - 1)]['endx'];
  19355. }
  19356. // for each cell on the row
  19357. foreach ($parent['cellpos'] as $k => $cellpos) {
  19358. if (isset($cellpos['rowspanid']) AND ($cellpos['rowspanid'] >= 0)) {
  19359. $cellpos['startx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['startx'];
  19360. $cellpos['endx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['endx'];
  19361. $endy = $table_el['rowspans'][($cellpos['rowspanid'])]['endy'];
  19362. $startpage = $table_el['rowspans'][($cellpos['rowspanid'])]['startpage'];
  19363. $endpage = $table_el['rowspans'][($cellpos['rowspanid'])]['endpage'];
  19364. $startcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['startcolumn'];
  19365. $endcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['endcolumn'];
  19366. } else {
  19367. $endy = $parent['endy'];
  19368. $startpage = $parent['startpage'];
  19369. $endpage = $parent['endpage'];
  19370. $startcolumn = $parent['startcolumn'];
  19371. $endcolumn = $parent['endcolumn'];
  19372. }
  19373. if ($this->num_columns == 0) {
  19374. $this->num_columns = 1;
  19375. }
  19376. if (isset($cellpos['border'])) {
  19377. $border = $cellpos['border'];
  19378. }
  19379. if (isset($cellpos['bgcolor']) AND ($cellpos['bgcolor']) !== false) {
  19380. $this->SetFillColorArray($cellpos['bgcolor']);
  19381. $fill = true;
  19382. } else {
  19383. $fill = false;
  19384. }
  19385. $x = $cellpos['startx'];
  19386. $y = $parent['starty'];
  19387. $starty = $y;
  19388. $w = abs($cellpos['endx'] - $cellpos['startx']);
  19389. // get border modes
  19390. $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
  19391. $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
  19392. $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  19393. // design borders around HTML cells.
  19394. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  19395. $ccode = '';
  19396. $this->setPage($page);
  19397. if ($this->num_columns < 2) {
  19398. // single-column mode
  19399. $this->x = $x;
  19400. $this->y = $this->tMargin;
  19401. }
  19402. // account for margin changes
  19403. if ($page > $startpage) {
  19404. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  19405. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  19406. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  19407. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  19408. }
  19409. }
  19410. if ($startpage == $endpage) { // single page
  19411. $deltacol = 0;
  19412. $deltath = 0;
  19413. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  19414. $this->selectColumn($column);
  19415. if ($startcolumn == $endcolumn) { // single column
  19416. $cborder = $border;
  19417. $h = $endy - $parent['starty'];
  19418. $this->y = $y;
  19419. $this->x = $x;
  19420. } elseif ($column == $startcolumn) { // first column
  19421. $cborder = $border_start;
  19422. $this->y = $starty;
  19423. $this->x = $x;
  19424. $h = $this->h - $this->y - $this->bMargin;
  19425. if ($this->rtl) {
  19426. $deltacol = $this->x + $this->rMargin - $this->w;
  19427. } else {
  19428. $deltacol = $this->x - $this->lMargin;
  19429. }
  19430. } elseif ($column == $endcolumn) { // end column
  19431. $cborder = $border_end;
  19432. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19433. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19434. }
  19435. $this->x += $deltacol;
  19436. $h = $endy - $this->y;
  19437. } else { // middle column
  19438. $cborder = $border_middle;
  19439. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19440. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19441. }
  19442. $this->x += $deltacol;
  19443. $h = $this->h - $this->y - $this->bMargin;
  19444. }
  19445. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19446. } // end for each column
  19447. } elseif ($page == $startpage) { // first page
  19448. $deltacol = 0;
  19449. $deltath = 0;
  19450. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  19451. $this->selectColumn($column);
  19452. if ($column == $startcolumn) { // first column
  19453. $cborder = $border_start;
  19454. $this->y = $starty;
  19455. $this->x = $x;
  19456. $h = $this->h - $this->y - $this->bMargin;
  19457. if ($this->rtl) {
  19458. $deltacol = $this->x + $this->rMargin - $this->w;
  19459. } else {
  19460. $deltacol = $this->x - $this->lMargin;
  19461. }
  19462. } else { // middle column
  19463. $cborder = $border_middle;
  19464. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19465. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19466. }
  19467. $this->x += $deltacol;
  19468. $h = $this->h - $this->y - $this->bMargin;
  19469. }
  19470. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19471. } // end for each column
  19472. } elseif ($page == $endpage) { // last page
  19473. $deltacol = 0;
  19474. $deltath = 0;
  19475. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  19476. $this->selectColumn($column);
  19477. if ($column == $endcolumn) { // end column
  19478. $cborder = $border_end;
  19479. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19480. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19481. }
  19482. $this->x += $deltacol;
  19483. $h = $endy - $this->y;
  19484. } else { // middle column
  19485. $cborder = $border_middle;
  19486. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19487. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19488. }
  19489. $this->x += $deltacol;
  19490. $h = $this->h - $this->y - $this->bMargin;
  19491. }
  19492. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19493. } // end for each column
  19494. } else { // middle page
  19495. $deltacol = 0;
  19496. $deltath = 0;
  19497. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  19498. $this->selectColumn($column);
  19499. $cborder = $border_middle;
  19500. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19501. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  19502. }
  19503. $this->x += $deltacol;
  19504. $h = $this->h - $this->y - $this->bMargin;
  19505. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19506. } // end for each column
  19507. }
  19508. if (!empty($cborder) OR !empty($fill)) {
  19509. $offsetlen = strlen($ccode);
  19510. // draw border and fill
  19511. if ($this->inxobj) {
  19512. // we are inside an XObject template
  19513. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  19514. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  19515. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  19516. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  19517. } else {
  19518. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  19519. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  19520. }
  19521. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  19522. $pstart = substr($pagebuff, 0, $pagemark);
  19523. $pend = substr($pagebuff, $pagemark);
  19524. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  19525. } else {
  19526. // draw border and fill
  19527. if (end($this->transfmrk[$this->page]) !== false) {
  19528. $pagemarkkey = key($this->transfmrk[$this->page]);
  19529. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  19530. } elseif ($this->InFooter) {
  19531. $pagemark = $this->footerpos[$this->page];
  19532. } else {
  19533. $pagemark = $this->intmrk[$this->page];
  19534. }
  19535. $pagebuff = $this->getPageBuffer($this->page);
  19536. $pstart = substr($pagebuff, 0, $pagemark);
  19537. $pend = substr($pagebuff, $pagemark);
  19538. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  19539. }
  19540. }
  19541. } // end for each page
  19542. // restore default border
  19543. $border = $default_border;
  19544. } // end for each cell on the row
  19545. if (isset($table_el['attribute']['cellspacing'])) {
  19546. $this->y += $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing'], 1, 'px');
  19547. } elseif (isset($table_el['border-spacing'])) {
  19548. $this->y += $table_el['border-spacing']['V'];
  19549. }
  19550. $this->Ln(0, $cell);
  19551. $this->x = $parent['startx'];
  19552. if ($endpage > $startpage) {
  19553. if (($this->rtl) AND ($this->pagedim[$endpage]['orm'] != $this->pagedim[$startpage]['orm'])) {
  19554. $this->x += ($this->pagedim[$endpage]['orm'] - $this->pagedim[$startpage]['orm']);
  19555. } elseif ((!$this->rtl) AND ($this->pagedim[$endpage]['olm'] != $this->pagedim[$startpage]['olm'])) {
  19556. $this->x += ($this->pagedim[$endpage]['olm'] - $this->pagedim[$startpage]['olm']);
  19557. }
  19558. }
  19559. }
  19560. if (!$in_table_head) { // we are not inside a thead section
  19561. $this->cell_padding = $table_el['old_cell_padding'];
  19562. // reset row height
  19563. $this->resetLastH();
  19564. if (($this->page == ($this->numpages - 1)) AND ($this->pageopen[$this->numpages])) {
  19565. $plendiff = ($this->pagelen[$this->numpages] - $this->emptypagemrk[$this->numpages]);
  19566. if (($plendiff > 0) AND ($plendiff < 60)) {
  19567. $pagediff = substr($this->getPageBuffer($this->numpages), $this->emptypagemrk[$this->numpages], $plendiff);
  19568. if (substr($pagediff, 0, 5) == 'BT /F') {
  19569. // the difference is only a font setting
  19570. $plendiff = 0;
  19571. }
  19572. }
  19573. if ($plendiff == 0) {
  19574. // remove last blank page
  19575. $this->deletePage($this->numpages);
  19576. }
  19577. }
  19578. if (isset($this->theadMargins['top'])) {
  19579. // restore top margin
  19580. $this->tMargin = $this->theadMargins['top'];
  19581. }
  19582. if (!isset($table_el['attribute']['nested']) OR ($table_el['attribute']['nested'] != 'true')) {
  19583. // reset main table header
  19584. $this->thead = '';
  19585. $this->theadMargins = array();
  19586. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  19587. }
  19588. }
  19589. $parent = $table_el;
  19590. break;
  19591. }
  19592. case 'a': {
  19593. $this->HREF = array();
  19594. break;
  19595. }
  19596. case 'sup': {
  19597. $this->SetXY($this->GetX(), $this->GetY() + ((0.7 * $parent['fontsize']) / $this->k));
  19598. break;
  19599. }
  19600. case 'sub': {
  19601. $this->SetXY($this->GetX(), $this->GetY() - ((0.3 * $parent['fontsize']) / $this->k));
  19602. break;
  19603. }
  19604. case 'div': {
  19605. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19606. break;
  19607. }
  19608. case 'blockquote': {
  19609. if ($this->rtl) {
  19610. $this->rMargin -= $this->listindent;
  19611. } else {
  19612. $this->lMargin -= $this->listindent;
  19613. }
  19614. --$this->listindentlevel;
  19615. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19616. break;
  19617. }
  19618. case 'p': {
  19619. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19620. break;
  19621. }
  19622. case 'pre': {
  19623. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19624. $this->premode = false;
  19625. break;
  19626. }
  19627. case 'dl': {
  19628. --$this->listnum;
  19629. if ($this->listnum <= 0) {
  19630. $this->listnum = 0;
  19631. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19632. } else {
  19633. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19634. }
  19635. $this->resetLastH();
  19636. break;
  19637. }
  19638. case 'dt': {
  19639. $this->lispacer = '';
  19640. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19641. break;
  19642. }
  19643. case 'dd': {
  19644. $this->lispacer = '';
  19645. if ($this->rtl) {
  19646. $this->rMargin -= $this->listindent;
  19647. } else {
  19648. $this->lMargin -= $this->listindent;
  19649. }
  19650. --$this->listindentlevel;
  19651. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19652. break;
  19653. }
  19654. case 'ul':
  19655. case 'ol': {
  19656. --$this->listnum;
  19657. $this->lispacer = '';
  19658. if ($this->rtl) {
  19659. $this->rMargin -= $this->listindent;
  19660. } else {
  19661. $this->lMargin -= $this->listindent;
  19662. }
  19663. --$this->listindentlevel;
  19664. if ($this->listnum <= 0) {
  19665. $this->listnum = 0;
  19666. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19667. } else {
  19668. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19669. }
  19670. $this->resetLastH();
  19671. break;
  19672. }
  19673. case 'li': {
  19674. $this->lispacer = '';
  19675. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19676. break;
  19677. }
  19678. case 'h1':
  19679. case 'h2':
  19680. case 'h3':
  19681. case 'h4':
  19682. case 'h5':
  19683. case 'h6': {
  19684. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19685. break;
  19686. }
  19687. // Form fields (since 4.8.000 - 2009-09-07)
  19688. case 'form': {
  19689. $this->form_action = '';
  19690. $this->form_enctype = 'application/x-www-form-urlencoded';
  19691. break;
  19692. }
  19693. default : {
  19694. break;
  19695. }
  19696. }
  19697. // draw border and background (if any)
  19698. $this->drawHTMLTagBorder($parent, $xmax);
  19699. if (isset($dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'])) {
  19700. $pba = $dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'];
  19701. // check for pagebreak
  19702. if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
  19703. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  19704. $this->checkPageBreak($this->PageBreakTrigger + 1);
  19705. }
  19706. if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  19707. OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  19708. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  19709. $this->checkPageBreak($this->PageBreakTrigger + 1);
  19710. }
  19711. }
  19712. $this->tmprtl = false;
  19713. return $dom;
  19714. }
  19715. /**
  19716. * Add vertical spaces if needed.
  19717. * @param $hbz (string) Distance between current y and line bottom.
  19718. * @param $hb (string) The height of the break.
  19719. * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
  19720. * @param $firsttag (boolean) set to true when the tag is the first.
  19721. * @param $lasttag (boolean) set to true when the tag is the last.
  19722. * @protected
  19723. */
  19724. protected function addHTMLVertSpace($hbz = 0, $hb = 0, $cell = false, $firsttag = false, $lasttag = false)
  19725. {
  19726. if ($firsttag) {
  19727. $this->Ln(0, $cell);
  19728. $this->htmlvspace = 0;
  19729. return;
  19730. }
  19731. if ($lasttag) {
  19732. $this->Ln($hbz, $cell);
  19733. $this->htmlvspace = 0;
  19734. return;
  19735. }
  19736. if ($hb < $this->htmlvspace) {
  19737. $hd = 0;
  19738. } else {
  19739. $hd = $hb - $this->htmlvspace;
  19740. $this->htmlvspace = $hb;
  19741. }
  19742. $this->Ln(($hbz + $hd), $cell);
  19743. }
  19744. /**
  19745. * Return the starting coordinates to draw an html border
  19746. * @return array containing top-left border coordinates
  19747. * @protected
  19748. * @since 5.7.000 (2010-08-03)
  19749. */
  19750. protected function getBorderStartPosition()
  19751. {
  19752. if ($this->rtl) {
  19753. $xmax = $this->lMargin;
  19754. } else {
  19755. $xmax = $this->w - $this->rMargin;
  19756. }
  19757. return array('page' => $this->page, 'column' => $this->current_column, 'x' => $this->x, 'y' => $this->y, 'xmax' => $xmax);
  19758. }
  19759. /**
  19760. * Draw an HTML block border and fill
  19761. * @param $tag (array) array of tag properties.
  19762. * @param $xmax (int) end X coordinate for border.
  19763. * @protected
  19764. * @since 5.7.000 (2010-08-03)
  19765. */
  19766. protected function drawHTMLTagBorder($tag, $xmax)
  19767. {
  19768. if (!isset($tag['borderposition'])) {
  19769. // nothing to draw
  19770. return;
  19771. }
  19772. $prev_x = $this->x;
  19773. $prev_y = $this->y;
  19774. $prev_lasth = $this->lasth;
  19775. $border = 0;
  19776. $fill = false;
  19777. $this->lasth = 0;
  19778. if (isset($tag['border']) AND !empty($tag['border'])) {
  19779. // get border style
  19780. $border = $tag['border'];
  19781. if (!TCPDF_STATIC::empty_string($this->thead) AND (!$this->inthead)) {
  19782. // border for table header
  19783. $border = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  19784. }
  19785. }
  19786. if (isset($tag['bgcolor']) AND ($tag['bgcolor'] !== false)) {
  19787. // get background color
  19788. $old_bgcolor = $this->bgcolor;
  19789. $this->SetFillColorArray($tag['bgcolor']);
  19790. $fill = true;
  19791. }
  19792. if (!$border AND !$fill) {
  19793. // nothing to draw
  19794. return;
  19795. }
  19796. if (isset($tag['attribute']['cellspacing'])) {
  19797. $clsp = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
  19798. $cellspacing = array('H' => $clsp, 'V' => $clsp);
  19799. } elseif (isset($tag['border-spacing'])) {
  19800. $cellspacing = $tag['border-spacing'];
  19801. } else {
  19802. $cellspacing = array('H' => 0, 'V' => 0);
  19803. }
  19804. if (($tag['value'] != 'table') AND (is_array($border)) AND (!empty($border))) {
  19805. // draw the border externally respect the sqare edge.
  19806. $border['mode'] = 'ext';
  19807. }
  19808. if ($this->rtl) {
  19809. if ($xmax >= $tag['borderposition']['x']) {
  19810. $xmax = $tag['borderposition']['xmax'];
  19811. }
  19812. $w = ($tag['borderposition']['x'] - $xmax);
  19813. } else {
  19814. if ($xmax <= $tag['borderposition']['x']) {
  19815. $xmax = $tag['borderposition']['xmax'];
  19816. }
  19817. $w = ($xmax - $tag['borderposition']['x']);
  19818. }
  19819. if ($w <= 0) {
  19820. return;
  19821. }
  19822. $w += $cellspacing['H'];
  19823. $startpage = $tag['borderposition']['page'];
  19824. $startcolumn = $tag['borderposition']['column'];
  19825. $x = $tag['borderposition']['x'];
  19826. $y = $tag['borderposition']['y'];
  19827. $endpage = $this->page;
  19828. $starty = $tag['borderposition']['y'] - $cellspacing['V'];
  19829. $currentY = $this->y;
  19830. $this->x = $x;
  19831. // get latest column
  19832. $endcolumn = $this->current_column;
  19833. if ($this->num_columns == 0) {
  19834. $this->num_columns = 1;
  19835. }
  19836. // get border modes
  19837. $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
  19838. $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
  19839. $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  19840. // temporary disable page regions
  19841. $temp_page_regions = $this->page_regions;
  19842. $this->page_regions = array();
  19843. // design borders around HTML cells.
  19844. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  19845. $ccode = '';
  19846. $this->setPage($page);
  19847. if ($this->num_columns < 2) {
  19848. // single-column mode
  19849. $this->x = $x;
  19850. $this->y = $this->tMargin;
  19851. }
  19852. // account for margin changes
  19853. if ($page > $startpage) {
  19854. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  19855. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  19856. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  19857. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  19858. }
  19859. }
  19860. if ($startpage == $endpage) {
  19861. // single page
  19862. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  19863. $this->selectColumn($column);
  19864. if ($startcolumn == $endcolumn) { // single column
  19865. $cborder = $border;
  19866. $h = ($currentY - $y) + $cellspacing['V'];
  19867. $this->y = $starty;
  19868. } elseif ($column == $startcolumn) { // first column
  19869. $cborder = $border_start;
  19870. $this->y = $starty;
  19871. $h = $this->h - $this->y - $this->bMargin;
  19872. } elseif ($column == $endcolumn) { // end column
  19873. $cborder = $border_end;
  19874. $h = $currentY - $this->y;
  19875. } else { // middle column
  19876. $cborder = $border_middle;
  19877. $h = $this->h - $this->y - $this->bMargin;
  19878. }
  19879. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19880. } // end for each column
  19881. } elseif ($page == $startpage) { // first page
  19882. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  19883. $this->selectColumn($column);
  19884. if ($column == $startcolumn) { // first column
  19885. $cborder = $border_start;
  19886. $this->y = $starty;
  19887. $h = $this->h - $this->y - $this->bMargin;
  19888. } else { // middle column
  19889. $cborder = $border_middle;
  19890. $h = $this->h - $this->y - $this->bMargin;
  19891. }
  19892. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19893. } // end for each column
  19894. } elseif ($page == $endpage) { // last page
  19895. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  19896. $this->selectColumn($column);
  19897. if ($column == $endcolumn) {
  19898. // end column
  19899. $cborder = $border_end;
  19900. $h = $currentY - $this->y;
  19901. } else {
  19902. // middle column
  19903. $cborder = $border_middle;
  19904. $h = $this->h - $this->y - $this->bMargin;
  19905. }
  19906. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19907. } // end for each column
  19908. } else { // middle page
  19909. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  19910. $this->selectColumn($column);
  19911. $cborder = $border_middle;
  19912. $h = $this->h - $this->y - $this->bMargin;
  19913. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19914. } // end for each column
  19915. }
  19916. if ($cborder OR $fill) {
  19917. $offsetlen = strlen($ccode);
  19918. // draw border and fill
  19919. if ($this->inxobj) {
  19920. // we are inside an XObject template
  19921. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  19922. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  19923. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  19924. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  19925. } else {
  19926. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  19927. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  19928. }
  19929. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  19930. $pstart = substr($pagebuff, 0, $pagemark);
  19931. $pend = substr($pagebuff, $pagemark);
  19932. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  19933. } else {
  19934. if (end($this->transfmrk[$this->page]) !== false) {
  19935. $pagemarkkey = key($this->transfmrk[$this->page]);
  19936. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  19937. } elseif ($this->InFooter) {
  19938. $pagemark = $this->footerpos[$this->page];
  19939. } else {
  19940. $pagemark = $this->intmrk[$this->page];
  19941. }
  19942. $pagebuff = $this->getPageBuffer($this->page);
  19943. $pstart = substr($pagebuff, 0, $pagemark);
  19944. $pend = substr($pagebuff, $pagemark);
  19945. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  19946. $this->bordermrk[$this->page] += $offsetlen;
  19947. $this->cntmrk[$this->page] += $offsetlen;
  19948. }
  19949. }
  19950. } // end for each page
  19951. // restore page regions
  19952. $this->page_regions = $temp_page_regions;
  19953. if (isset($old_bgcolor)) {
  19954. // restore background color
  19955. $this->SetFillColorArray($old_bgcolor);
  19956. }
  19957. // restore pointer position
  19958. $this->x = $prev_x;
  19959. $this->y = $prev_y;
  19960. $this->lasth = $prev_lasth;
  19961. }
  19962. /**
  19963. * Set the default bullet to be used as LI bullet symbol
  19964. * @param $symbol (string) character or string to be used (legal values are: '' = automatic, '!' = auto bullet, '#' = auto numbering, 'disc', 'disc', 'circle', 'square', '1', 'decimal', 'decimal-leading-zero', 'i', 'lower-roman', 'I', 'upper-roman', 'a', 'lower-alpha', 'lower-latin', 'A', 'upper-alpha', 'upper-latin', 'lower-greek', 'img|type|width|height|image.ext')
  19965. * @public
  19966. * @since 4.0.028 (2008-09-26)
  19967. */
  19968. public function setLIsymbol($symbol = '!')
  19969. {
  19970. // check for custom image symbol
  19971. if (substr($symbol, 0, 4) == 'img|') {
  19972. $this->lisymbol = $symbol;
  19973. return;
  19974. }
  19975. $symbol = strtolower($symbol);
  19976. $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');
  19977. if (in_array($symbol, $valid_symbols)) {
  19978. $this->lisymbol = $symbol;
  19979. } else {
  19980. $this->lisymbol = '';
  19981. }
  19982. }
  19983. /**
  19984. * Set the booklet mode for double-sided pages.
  19985. * @param $booklet (boolean) true set the booklet mode on, false otherwise.
  19986. * @param $inner (float) Inner page margin.
  19987. * @param $outer (float) Outer page margin.
  19988. * @public
  19989. * @since 4.2.000 (2008-10-29)
  19990. */
  19991. public function SetBooklet($booklet = true, $inner = -1, $outer = -1)
  19992. {
  19993. $this->booklet = $booklet;
  19994. if ($inner >= 0) {
  19995. $this->lMargin = $inner;
  19996. }
  19997. if ($outer >= 0) {
  19998. $this->rMargin = $outer;
  19999. }
  20000. }
  20001. /**
  20002. * Swap the left and right margins.
  20003. * @param $reverse (boolean) if true swap left and right margins.
  20004. * @protected
  20005. * @since 4.2.000 (2008-10-29)
  20006. */
  20007. protected function swapMargins($reverse = true)
  20008. {
  20009. if ($reverse) {
  20010. // swap left and right margins
  20011. $mtemp = $this->original_lMargin;
  20012. $this->original_lMargin = $this->original_rMargin;
  20013. $this->original_rMargin = $mtemp;
  20014. $deltam = $this->original_lMargin - $this->original_rMargin;
  20015. $this->lMargin += $deltam;
  20016. $this->rMargin -= $deltam;
  20017. }
  20018. }
  20019. /**
  20020. * Set the vertical spaces for HTML tags.
  20021. * The array must have the following structure (example):
  20022. * $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1)));
  20023. * The first array level contains the tag names,
  20024. * the second level contains 0 for opening tags or 1 for closing tags,
  20025. * the third level contains the vertical space unit (h) and the number spaces to add (n).
  20026. * If the h parameter is not specified, default values are used.
  20027. * @param $tagvs (array) array of tags and relative vertical spaces.
  20028. * @public
  20029. * @since 4.2.001 (2008-10-30)
  20030. */
  20031. public function setHtmlVSpace($tagvs)
  20032. {
  20033. $this->tagvspaces = $tagvs;
  20034. }
  20035. /**
  20036. * Set custom width for list indentation.
  20037. * @param $width (float) width of the indentation. Use negative value to disable it.
  20038. * @public
  20039. * @since 4.2.007 (2008-11-12)
  20040. */
  20041. public function setListIndentWidth($width)
  20042. {
  20043. return $this->customlistindent = floatval($width);
  20044. }
  20045. /**
  20046. * Set the top/bottom cell sides to be open or closed when the cell cross the page.
  20047. * @param $isopen (boolean) if true keeps the top/bottom border open for the cell sides that cross the page.
  20048. * @public
  20049. * @since 4.2.010 (2008-11-14)
  20050. */
  20051. public function setOpenCell($isopen)
  20052. {
  20053. $this->opencell = $isopen;
  20054. }
  20055. /**
  20056. * Set the color and font style for HTML links.
  20057. * @param $color (array) RGB array of colors
  20058. * @param $fontstyle (string) additional font styles to add
  20059. * @public
  20060. * @since 4.4.003 (2008-12-09)
  20061. */
  20062. public function setHtmlLinksStyle($color = array(0,0,255), $fontstyle = 'U')
  20063. {
  20064. $this->htmlLinkColorArray = $color;
  20065. $this->htmlLinkFontStyle = $fontstyle;
  20066. }
  20067. /**
  20068. * Convert HTML string containing value and unit of measure to user's units or points.
  20069. * @param $htmlval (string) String containing values and unit.
  20070. * @param $refsize (string) Reference value in points.
  20071. * @param $defaultunit (string) Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  20072. * @param $points (boolean) If true returns points, otherwise returns value in user's units.
  20073. * @return float value in user's unit or point if $points=true
  20074. * @public
  20075. * @since 4.4.004 (2008-12-10)
  20076. */
  20077. public function getHTMLUnitToUnits($htmlval, $refsize = 1, $defaultunit = 'px', $points = false)
  20078. {
  20079. $supportedunits = array('%', 'em', 'ex', 'px', 'in', 'cm', 'mm', 'pc', 'pt');
  20080. $retval = 0;
  20081. $value = 0;
  20082. $unit = 'px';
  20083. if ($points) {
  20084. $k = 1;
  20085. } else {
  20086. $k = $this->k;
  20087. }
  20088. if (in_array($defaultunit, $supportedunits)) {
  20089. $unit = $defaultunit;
  20090. }
  20091. if (is_numeric($htmlval)) {
  20092. $value = floatval($htmlval);
  20093. } elseif (preg_match('/([0-9\.\-\+]+)/', $htmlval, $mnum)) {
  20094. $value = floatval($mnum[1]);
  20095. if (preg_match('/([a-z%]+)/', $htmlval, $munit)) {
  20096. if (in_array($munit[1], $supportedunits)) {
  20097. $unit = $munit[1];
  20098. }
  20099. }
  20100. }
  20101. switch ($unit) {
  20102. // percentage
  20103. case '%': {
  20104. $retval = (($value * $refsize) / 100);
  20105. break;
  20106. }
  20107. // relative-size
  20108. case 'em': {
  20109. $retval = ($value * $refsize);
  20110. break;
  20111. }
  20112. // height of lower case 'x' (about half the font-size)
  20113. case 'ex': {
  20114. $retval = ($value * ($refsize / 2));
  20115. break;
  20116. }
  20117. // absolute-size
  20118. case 'in': {
  20119. $retval = (($value * $this->dpi) / $k);
  20120. break;
  20121. }
  20122. // centimeters
  20123. case 'cm': {
  20124. $retval = (($value / 2.54 * $this->dpi) / $k);
  20125. break;
  20126. }
  20127. // millimeters
  20128. case 'mm': {
  20129. $retval = (($value / 25.4 * $this->dpi) / $k);
  20130. break;
  20131. }
  20132. // one pica is 12 points
  20133. case 'pc': {
  20134. $retval = (($value * 12) / $k);
  20135. break;
  20136. }
  20137. // points
  20138. case 'pt': {
  20139. $retval = ($value / $k);
  20140. break;
  20141. }
  20142. // pixels
  20143. case 'px': {
  20144. $retval = $this->pixelsToUnits($value);
  20145. if ($points) {
  20146. $retval *= $this->k;
  20147. }
  20148. break;
  20149. }
  20150. }
  20151. return $retval;
  20152. }
  20153. /**
  20154. * Output an HTML list bullet or ordered item symbol
  20155. * @param $listdepth (int) list nesting level
  20156. * @param $listtype (string) type of list
  20157. * @param $size (float) current font size
  20158. * @protected
  20159. * @since 4.4.004 (2008-12-10)
  20160. */
  20161. protected function putHtmlListBullet($listdepth, $listtype = '', $size = 10)
  20162. {
  20163. if ($this->state != 2) {
  20164. return;
  20165. }
  20166. $size /= $this->k;
  20167. $fill = '';
  20168. $bgcolor = $this->bgcolor;
  20169. $color = $this->fgcolor;
  20170. $strokecolor = $this->strokecolor;
  20171. $width = 0;
  20172. $textitem = '';
  20173. $tmpx = $this->x;
  20174. $lspace = $this->GetStringWidth(' ');
  20175. if ($listtype == '^') {
  20176. // special symbol used for avoid justification of rect bullet
  20177. $this->lispacer = '';
  20178. return;
  20179. } elseif ($listtype == '!') {
  20180. // set default list type for unordered list
  20181. $deftypes = array('disc', 'circle', 'square');
  20182. $listtype = $deftypes[($listdepth - 1) % 3];
  20183. } elseif ($listtype == '#') {
  20184. // set default list type for ordered list
  20185. $listtype = 'decimal';
  20186. } elseif (substr($listtype, 0, 4) == 'img|') {
  20187. // custom image type ('img|type|width|height|image.ext')
  20188. $img = explode('|', $listtype);
  20189. $listtype = 'img';
  20190. }
  20191. switch ($listtype) {
  20192. // unordered types
  20193. case 'none': {
  20194. break;
  20195. }
  20196. case 'disc': {
  20197. $r = $size / 6;
  20198. $lspace += (2 * $r);
  20199. if ($this->rtl) {
  20200. $this->x += $lspace;
  20201. } else {
  20202. $this->x -= $lspace;
  20203. }
  20204. $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), $r, 0, 360, 'F', array(), $color, 8);
  20205. break;
  20206. }
  20207. case 'circle': {
  20208. $r = $size / 6;
  20209. $lspace += (2 * $r);
  20210. if ($this->rtl) {
  20211. $this->x += $lspace;
  20212. } else {
  20213. $this->x -= $lspace;
  20214. }
  20215. $prev_line_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor;
  20216. $new_line_style = array('width' => ($r / 3), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'phase' => 0, 'color'=>$color);
  20217. $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), ($r * (1 - (1/6))), 0, 360, 'D', $new_line_style, array(), 8);
  20218. $this->_out($prev_line_style); // restore line settings
  20219. break;
  20220. }
  20221. case 'square': {
  20222. $l = $size / 3;
  20223. $lspace += $l;
  20224. if ($this->rtl) {;
  20225. $this->x += $lspace;
  20226. } else {
  20227. $this->x -= $lspace;
  20228. }
  20229. $this->Rect($this->x, ($this->y + (($this->lasth - $l) / 2)), $l, $l, 'F', array(), $color);
  20230. break;
  20231. }
  20232. case 'img': {
  20233. // 1=>type, 2=>width, 3=>height, 4=>image.ext
  20234. $lspace += $img[2];
  20235. if ($this->rtl) {;
  20236. $this->x += $lspace;
  20237. } else {
  20238. $this->x -= $lspace;
  20239. }
  20240. $imgtype = strtolower($img[1]);
  20241. $prev_y = $this->y;
  20242. switch ($imgtype) {
  20243. case 'svg': {
  20244. $this->ImageSVG($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', 'T', '', 0, false);
  20245. break;
  20246. }
  20247. case 'ai':
  20248. case 'eps': {
  20249. $this->ImageEps($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', true, 'T', '', 0, false);
  20250. break;
  20251. }
  20252. default: {
  20253. $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);
  20254. break;
  20255. }
  20256. }
  20257. $this->y = $prev_y;
  20258. break;
  20259. }
  20260. // ordered types
  20261. // $this->listcount[$this->listnum];
  20262. // $textitem
  20263. case '1':
  20264. case 'decimal': {
  20265. $textitem = $this->listcount[$this->listnum];
  20266. break;
  20267. }
  20268. case 'decimal-leading-zero': {
  20269. $textitem = sprintf('%02d', $this->listcount[$this->listnum]);
  20270. break;
  20271. }
  20272. case 'i':
  20273. case 'lower-roman': {
  20274. $textitem = strtolower(TCPDF_STATIC::intToRoman($this->listcount[$this->listnum]));
  20275. break;
  20276. }
  20277. case 'I':
  20278. case 'upper-roman': {
  20279. $textitem = TCPDF_STATIC::intToRoman($this->listcount[$this->listnum]);
  20280. break;
  20281. }
  20282. case 'a':
  20283. case 'lower-alpha':
  20284. case 'lower-latin': {
  20285. $textitem = chr(97 + $this->listcount[$this->listnum] - 1);
  20286. break;
  20287. }
  20288. case 'A':
  20289. case 'upper-alpha':
  20290. case 'upper-latin': {
  20291. $textitem = chr(65 + $this->listcount[$this->listnum] - 1);
  20292. break;
  20293. }
  20294. case 'lower-greek': {
  20295. $textitem = TCPDF_FONTS::unichr((945 + $this->listcount[$this->listnum] - 1), $this->isunicode);
  20296. break;
  20297. }
  20298. /*
  20299. // Types to be implemented (special handling)
  20300. case 'hebrew': {
  20301. break;
  20302. }
  20303. case 'armenian': {
  20304. break;
  20305. }
  20306. case 'georgian': {
  20307. break;
  20308. }
  20309. case 'cjk-ideographic': {
  20310. break;
  20311. }
  20312. case 'hiragana': {
  20313. break;
  20314. }
  20315. case 'katakana': {
  20316. break;
  20317. }
  20318. case 'hiragana-iroha': {
  20319. break;
  20320. }
  20321. case 'katakana-iroha': {
  20322. break;
  20323. }
  20324. */
  20325. default: {
  20326. $textitem = $this->listcount[$this->listnum];
  20327. }
  20328. }
  20329. if (!TCPDF_STATIC::empty_string($textitem)) {
  20330. // Check whether we need a new page or new column
  20331. $prev_y = $this->y;
  20332. $h = $this->getCellHeight($this->FontSize);
  20333. if ($this->checkPageBreak($h) OR ($this->y < $prev_y)) {
  20334. $tmpx = $this->x;
  20335. }
  20336. // print ordered item
  20337. if ($this->rtl) {
  20338. $textitem = '.'.$textitem;
  20339. } else {
  20340. $textitem = $textitem.'.';
  20341. }
  20342. $lspace += $this->GetStringWidth($textitem);
  20343. if ($this->rtl) {
  20344. $this->x += $lspace;
  20345. } else {
  20346. $this->x -= $lspace;
  20347. }
  20348. $this->Write($this->lasth, $textitem, '', false, '', false, 0, false);
  20349. }
  20350. $this->x = $tmpx;
  20351. $this->lispacer = '^';
  20352. // restore colors
  20353. $this->SetFillColorArray($bgcolor);
  20354. $this->SetDrawColorArray($strokecolor);
  20355. $this->SettextColorArray($color);
  20356. }
  20357. /**
  20358. * Returns current graphic variables as array.
  20359. * @return array of graphic variables
  20360. * @protected
  20361. * @since 4.2.010 (2008-11-14)
  20362. */
  20363. protected function getGraphicVars()
  20364. {
  20365. $grapvars = array(
  20366. 'FontFamily' => $this->FontFamily,
  20367. 'FontStyle' => $this->FontStyle,
  20368. 'FontSizePt' => $this->FontSizePt,
  20369. 'rMargin' => $this->rMargin,
  20370. 'lMargin' => $this->lMargin,
  20371. 'cell_padding' => $this->cell_padding,
  20372. 'cell_margin' => $this->cell_margin,
  20373. 'LineWidth' => $this->LineWidth,
  20374. 'linestyleWidth' => $this->linestyleWidth,
  20375. 'linestyleCap' => $this->linestyleCap,
  20376. 'linestyleJoin' => $this->linestyleJoin,
  20377. 'linestyleDash' => $this->linestyleDash,
  20378. 'textrendermode' => $this->textrendermode,
  20379. 'textstrokewidth' => $this->textstrokewidth,
  20380. 'DrawColor' => $this->DrawColor,
  20381. 'FillColor' => $this->FillColor,
  20382. 'TextColor' => $this->TextColor,
  20383. 'ColorFlag' => $this->ColorFlag,
  20384. 'bgcolor' => $this->bgcolor,
  20385. 'fgcolor' => $this->fgcolor,
  20386. 'htmlvspace' => $this->htmlvspace,
  20387. 'listindent' => $this->listindent,
  20388. 'listindentlevel' => $this->listindentlevel,
  20389. 'listnum' => $this->listnum,
  20390. 'listordered' => $this->listordered,
  20391. 'listcount' => $this->listcount,
  20392. 'lispacer' => $this->lispacer,
  20393. 'cell_height_ratio' => $this->cell_height_ratio,
  20394. 'font_stretching' => $this->font_stretching,
  20395. 'font_spacing' => $this->font_spacing,
  20396. 'alpha' => $this->alpha,
  20397. // extended
  20398. 'lasth' => $this->lasth,
  20399. 'tMargin' => $this->tMargin,
  20400. 'bMargin' => $this->bMargin,
  20401. 'AutoPageBreak' => $this->AutoPageBreak,
  20402. 'PageBreakTrigger' => $this->PageBreakTrigger,
  20403. 'x' => $this->x,
  20404. 'y' => $this->y,
  20405. 'w' => $this->w,
  20406. 'h' => $this->h,
  20407. 'wPt' => $this->wPt,
  20408. 'hPt' => $this->hPt,
  20409. 'fwPt' => $this->fwPt,
  20410. 'fhPt' => $this->fhPt,
  20411. 'page' => $this->page,
  20412. 'current_column' => $this->current_column,
  20413. 'num_columns' => $this->num_columns
  20414. );
  20415. return $grapvars;
  20416. }
  20417. /**
  20418. * Set graphic variables.
  20419. * @param $gvars (array) array of graphic variablesto restore
  20420. * @param $extended (boolean) if true restore extended graphic variables
  20421. * @protected
  20422. * @since 4.2.010 (2008-11-14)
  20423. */
  20424. protected function setGraphicVars($gvars, $extended = false)
  20425. {
  20426. if ($this->state != 2) {
  20427. return;
  20428. }
  20429. $this->FontFamily = $gvars['FontFamily'];
  20430. $this->FontStyle = $gvars['FontStyle'];
  20431. $this->FontSizePt = $gvars['FontSizePt'];
  20432. $this->rMargin = $gvars['rMargin'];
  20433. $this->lMargin = $gvars['lMargin'];
  20434. $this->cell_padding = $gvars['cell_padding'];
  20435. $this->cell_margin = $gvars['cell_margin'];
  20436. $this->LineWidth = $gvars['LineWidth'];
  20437. $this->linestyleWidth = $gvars['linestyleWidth'];
  20438. $this->linestyleCap = $gvars['linestyleCap'];
  20439. $this->linestyleJoin = $gvars['linestyleJoin'];
  20440. $this->linestyleDash = $gvars['linestyleDash'];
  20441. $this->textrendermode = $gvars['textrendermode'];
  20442. $this->textstrokewidth = $gvars['textstrokewidth'];
  20443. $this->DrawColor = $gvars['DrawColor'];
  20444. $this->FillColor = $gvars['FillColor'];
  20445. $this->TextColor = $gvars['TextColor'];
  20446. $this->ColorFlag = $gvars['ColorFlag'];
  20447. $this->bgcolor = $gvars['bgcolor'];
  20448. $this->fgcolor = $gvars['fgcolor'];
  20449. $this->htmlvspace = $gvars['htmlvspace'];
  20450. $this->listindent = $gvars['listindent'];
  20451. $this->listindentlevel = $gvars['listindentlevel'];
  20452. $this->listnum = $gvars['listnum'];
  20453. $this->listordered = $gvars['listordered'];
  20454. $this->listcount = $gvars['listcount'];
  20455. $this->lispacer = $gvars['lispacer'];
  20456. $this->cell_height_ratio = $gvars['cell_height_ratio'];
  20457. $this->font_stretching = $gvars['font_stretching'];
  20458. $this->font_spacing = $gvars['font_spacing'];
  20459. $this->alpha = $gvars['alpha'];
  20460. if ($extended) {
  20461. // restore extended values
  20462. $this->lasth = $gvars['lasth'];
  20463. $this->tMargin = $gvars['tMargin'];
  20464. $this->bMargin = $gvars['bMargin'];
  20465. $this->AutoPageBreak = $gvars['AutoPageBreak'];
  20466. $this->PageBreakTrigger = $gvars['PageBreakTrigger'];
  20467. $this->x = $gvars['x'];
  20468. $this->y = $gvars['y'];
  20469. $this->w = $gvars['w'];
  20470. $this->h = $gvars['h'];
  20471. $this->wPt = $gvars['wPt'];
  20472. $this->hPt = $gvars['hPt'];
  20473. $this->fwPt = $gvars['fwPt'];
  20474. $this->fhPt = $gvars['fhPt'];
  20475. $this->page = $gvars['page'];
  20476. $this->current_column = $gvars['current_column'];
  20477. $this->num_columns = $gvars['num_columns'];
  20478. }
  20479. $this->_out(''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor.'');
  20480. if (!TCPDF_STATIC::empty_string($this->FontFamily)) {
  20481. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  20482. }
  20483. }
  20484. /**
  20485. * Outputs the "save graphics state" operator 'q'
  20486. * @protected
  20487. */
  20488. protected function _outSaveGraphicsState()
  20489. {
  20490. $this->_out('q');
  20491. }
  20492. /**
  20493. * Outputs the "restore graphics state" operator 'Q'
  20494. * @protected
  20495. */
  20496. protected function _outRestoreGraphicsState()
  20497. {
  20498. $this->_out('Q');
  20499. }
  20500. /**
  20501. * Set buffer content (always append data).
  20502. * @param $data (string) data
  20503. * @protected
  20504. * @since 4.5.000 (2009-01-02)
  20505. */
  20506. protected function setBuffer($data)
  20507. {
  20508. $this->bufferlen += strlen($data);
  20509. $this->buffer .= $data;
  20510. }
  20511. /**
  20512. * Replace the buffer content
  20513. * @param $data (string) data
  20514. * @protected
  20515. * @since 5.5.000 (2010-06-22)
  20516. */
  20517. protected function replaceBuffer($data)
  20518. {
  20519. $this->bufferlen = strlen($data);
  20520. $this->buffer = $data;
  20521. }
  20522. /**
  20523. * Get buffer content.
  20524. * @return string buffer content
  20525. * @protected
  20526. * @since 4.5.000 (2009-01-02)
  20527. */
  20528. protected function getBuffer()
  20529. {
  20530. return $this->buffer;
  20531. }
  20532. /**
  20533. * Set page buffer content.
  20534. * @param $page (int) page number
  20535. * @param $data (string) page data
  20536. * @param $append (boolean) if true append data, false replace.
  20537. * @protected
  20538. * @since 4.5.000 (2008-12-31)
  20539. */
  20540. protected function setPageBuffer($page, $data, $append = false)
  20541. {
  20542. if ($append) {
  20543. $this->pages[$page] .= $data;
  20544. } else {
  20545. $this->pages[$page] = $data;
  20546. }
  20547. if ($append AND isset($this->pagelen[$page])) {
  20548. $this->pagelen[$page] += strlen($data);
  20549. } else {
  20550. $this->pagelen[$page] = strlen($data);
  20551. }
  20552. }
  20553. /**
  20554. * Get page buffer content.
  20555. * @param $page (int) page number
  20556. * @return string page buffer content or false in case of error
  20557. * @protected
  20558. * @since 4.5.000 (2008-12-31)
  20559. */
  20560. protected function getPageBuffer($page)
  20561. {
  20562. if (isset($this->pages[$page])) {
  20563. return $this->pages[$page];
  20564. }
  20565. return false;
  20566. }
  20567. /**
  20568. * Set image buffer content.
  20569. * @param $image (string) image key
  20570. * @param $data (array) image data
  20571. * @return int image index number
  20572. * @protected
  20573. * @since 4.5.000 (2008-12-31)
  20574. */
  20575. protected function setImageBuffer($image, $data)
  20576. {
  20577. if (($data['i'] = array_search($image, $this->imagekeys)) === false) {
  20578. $this->imagekeys[$this->numimages] = $image;
  20579. $data['i'] = $this->numimages;
  20580. ++$this->numimages;
  20581. }
  20582. $this->images[$image] = $data;
  20583. return $data['i'];
  20584. }
  20585. /**
  20586. * Set image buffer content for a specified sub-key.
  20587. * @param $image (string) image key
  20588. * @param $key (string) image sub-key
  20589. * @param $data (array) image data
  20590. * @protected
  20591. * @since 4.5.000 (2008-12-31)
  20592. */
  20593. protected function setImageSubBuffer($image, $key, $data)
  20594. {
  20595. if (!isset($this->images[$image])) {
  20596. $this->setImageBuffer($image, array());
  20597. }
  20598. $this->images[$image][$key] = $data;
  20599. }
  20600. /**
  20601. * Get image buffer content.
  20602. * @param $image (string) image key
  20603. * @return string image buffer content or false in case of error
  20604. * @protected
  20605. * @since 4.5.000 (2008-12-31)
  20606. */
  20607. protected function getImageBuffer($image)
  20608. {
  20609. if (isset($this->images[$image])) {
  20610. return $this->images[$image];
  20611. }
  20612. return false;
  20613. }
  20614. /**
  20615. * Set font buffer content.
  20616. * @param $font (string) font key
  20617. * @param $data (array) font data
  20618. * @protected
  20619. * @since 4.5.000 (2009-01-02)
  20620. */
  20621. protected function setFontBuffer($font, $data)
  20622. {
  20623. $this->fonts[$font] = $data;
  20624. if (!in_array($font, $this->fontkeys)) {
  20625. $this->fontkeys[] = $font;
  20626. // store object ID for current font
  20627. ++$this->n;
  20628. $this->font_obj_ids[$font] = $this->n;
  20629. $this->setFontSubBuffer($font, 'n', $this->n);
  20630. }
  20631. }
  20632. /**
  20633. * Set font buffer content.
  20634. * @param $font (string) font key
  20635. * @param $key (string) font sub-key
  20636. * @param $data (array) font data
  20637. * @protected
  20638. * @since 4.5.000 (2009-01-02)
  20639. */
  20640. protected function setFontSubBuffer($font, $key, $data)
  20641. {
  20642. if (!isset($this->fonts[$font])) {
  20643. $this->setFontBuffer($font, array());
  20644. }
  20645. $this->fonts[$font][$key] = $data;
  20646. }
  20647. /**
  20648. * Get font buffer content.
  20649. * @param $font (string) font key
  20650. * @return string font buffer content or false in case of error
  20651. * @protected
  20652. * @since 4.5.000 (2009-01-02)
  20653. */
  20654. protected function getFontBuffer($font)
  20655. {
  20656. if (isset($this->fonts[$font])) {
  20657. return $this->fonts[$font];
  20658. }
  20659. return false;
  20660. }
  20661. /**
  20662. * Move a page to a previous position.
  20663. * @param $frompage (int) number of the source page
  20664. * @param $topage (int) number of the destination page (must be less than $frompage)
  20665. * @return true in case of success, false in case of error.
  20666. * @public
  20667. * @since 4.5.000 (2009-01-02)
  20668. */
  20669. public function movePage($frompage, $topage)
  20670. {
  20671. if (($frompage > $this->numpages) OR ($frompage <= $topage)) {
  20672. return false;
  20673. }
  20674. if ($frompage == $this->page) {
  20675. // close the page before moving it
  20676. $this->endPage();
  20677. }
  20678. // move all page-related states
  20679. $tmppage = $this->getPageBuffer($frompage);
  20680. $tmppagedim = $this->pagedim[$frompage];
  20681. $tmppagelen = $this->pagelen[$frompage];
  20682. $tmpintmrk = $this->intmrk[$frompage];
  20683. $tmpbordermrk = $this->bordermrk[$frompage];
  20684. $tmpcntmrk = $this->cntmrk[$frompage];
  20685. $tmppageobjects = $this->pageobjects[$frompage];
  20686. if (isset($this->footerpos[$frompage])) {
  20687. $tmpfooterpos = $this->footerpos[$frompage];
  20688. }
  20689. if (isset($this->footerlen[$frompage])) {
  20690. $tmpfooterlen = $this->footerlen[$frompage];
  20691. }
  20692. if (isset($this->transfmrk[$frompage])) {
  20693. $tmptransfmrk = $this->transfmrk[$frompage];
  20694. }
  20695. if (isset($this->PageAnnots[$frompage])) {
  20696. $tmpannots = $this->PageAnnots[$frompage];
  20697. }
  20698. if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
  20699. for ($i = $frompage; $i > $topage; --$i) {
  20700. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $frompage)) {
  20701. --$this->pagegroups[$this->newpagegroup[$i]];
  20702. break;
  20703. }
  20704. }
  20705. for ($i = $topage; $i > 0; --$i) {
  20706. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $topage)) {
  20707. ++$this->pagegroups[$this->newpagegroup[$i]];
  20708. break;
  20709. }
  20710. }
  20711. }
  20712. for ($i = $frompage; $i > $topage; --$i) {
  20713. $j = $i - 1;
  20714. // shift pages down
  20715. $this->setPageBuffer($i, $this->getPageBuffer($j));
  20716. $this->pagedim[$i] = $this->pagedim[$j];
  20717. $this->pagelen[$i] = $this->pagelen[$j];
  20718. $this->intmrk[$i] = $this->intmrk[$j];
  20719. $this->bordermrk[$i] = $this->bordermrk[$j];
  20720. $this->cntmrk[$i] = $this->cntmrk[$j];
  20721. $this->pageobjects[$i] = $this->pageobjects[$j];
  20722. if (isset($this->footerpos[$j])) {
  20723. $this->footerpos[$i] = $this->footerpos[$j];
  20724. } elseif (isset($this->footerpos[$i])) {
  20725. unset($this->footerpos[$i]);
  20726. }
  20727. if (isset($this->footerlen[$j])) {
  20728. $this->footerlen[$i] = $this->footerlen[$j];
  20729. } elseif (isset($this->footerlen[$i])) {
  20730. unset($this->footerlen[$i]);
  20731. }
  20732. if (isset($this->transfmrk[$j])) {
  20733. $this->transfmrk[$i] = $this->transfmrk[$j];
  20734. } elseif (isset($this->transfmrk[$i])) {
  20735. unset($this->transfmrk[$i]);
  20736. }
  20737. if (isset($this->PageAnnots[$j])) {
  20738. $this->PageAnnots[$i] = $this->PageAnnots[$j];
  20739. } elseif (isset($this->PageAnnots[$i])) {
  20740. unset($this->PageAnnots[$i]);
  20741. }
  20742. if (isset($this->newpagegroup[$j])) {
  20743. $this->newpagegroup[$i] = $this->newpagegroup[$j];
  20744. unset($this->newpagegroup[$j]);
  20745. }
  20746. if ($this->currpagegroup == $j) {
  20747. $this->currpagegroup = $i;
  20748. }
  20749. }
  20750. $this->setPageBuffer($topage, $tmppage);
  20751. $this->pagedim[$topage] = $tmppagedim;
  20752. $this->pagelen[$topage] = $tmppagelen;
  20753. $this->intmrk[$topage] = $tmpintmrk;
  20754. $this->bordermrk[$topage] = $tmpbordermrk;
  20755. $this->cntmrk[$topage] = $tmpcntmrk;
  20756. $this->pageobjects[$topage] = $tmppageobjects;
  20757. if (isset($tmpfooterpos)) {
  20758. $this->footerpos[$topage] = $tmpfooterpos;
  20759. } elseif (isset($this->footerpos[$topage])) {
  20760. unset($this->footerpos[$topage]);
  20761. }
  20762. if (isset($tmpfooterlen)) {
  20763. $this->footerlen[$topage] = $tmpfooterlen;
  20764. } elseif (isset($this->footerlen[$topage])) {
  20765. unset($this->footerlen[$topage]);
  20766. }
  20767. if (isset($tmptransfmrk)) {
  20768. $this->transfmrk[$topage] = $tmptransfmrk;
  20769. } elseif (isset($this->transfmrk[$topage])) {
  20770. unset($this->transfmrk[$topage]);
  20771. }
  20772. if (isset($tmpannots)) {
  20773. $this->PageAnnots[$topage] = $tmpannots;
  20774. } elseif (isset($this->PageAnnots[$topage])) {
  20775. unset($this->PageAnnots[$topage]);
  20776. }
  20777. // adjust outlines
  20778. $tmpoutlines = $this->outlines;
  20779. foreach ($tmpoutlines as $key => $outline) {
  20780. if (!$outline['f']) {
  20781. if (($outline['p'] >= $topage) AND ($outline['p'] < $frompage)) {
  20782. $this->outlines[$key]['p'] = ($outline['p'] + 1);
  20783. } elseif ($outline['p'] == $frompage) {
  20784. $this->outlines[$key]['p'] = $topage;
  20785. }
  20786. }
  20787. }
  20788. // adjust dests
  20789. $tmpdests = $this->dests;
  20790. foreach ($tmpdests as $key => $dest) {
  20791. if (!$dest['f']) {
  20792. if (($dest['p'] >= $topage) AND ($dest['p'] < $frompage)) {
  20793. $this->dests[$key]['p'] = ($dest['p'] + 1);
  20794. } elseif ($dest['p'] == $frompage) {
  20795. $this->dests[$key]['p'] = $topage;
  20796. }
  20797. }
  20798. }
  20799. // adjust links
  20800. $tmplinks = $this->links;
  20801. foreach ($tmplinks as $key => $link) {
  20802. if (!$link['f']) {
  20803. if (($link['p'] >= $topage) AND ($link['p'] < $frompage)) {
  20804. $this->links[$key]['p'] = ($link['p'] + 1);
  20805. } elseif ($link['p'] == $frompage) {
  20806. $this->links[$key]['p'] = $topage;
  20807. }
  20808. }
  20809. }
  20810. // adjust javascript
  20811. $jfrompage = $frompage;
  20812. $jtopage = $topage;
  20813. if (preg_match_all('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', $this->javascript, $pamatch) > 0) {
  20814. foreach ($pamatch[0] as $pk => $pmatch) {
  20815. $pagenum = intval($pamatch[3][$pk]) + 1;
  20816. if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) {
  20817. $newpage = ($pagenum + 1);
  20818. } elseif ($pagenum == $jfrompage) {
  20819. $newpage = $jtopage;
  20820. } else {
  20821. $newpage = $pagenum;
  20822. }
  20823. --$newpage;
  20824. $newjs = "this.addField(\'".$pamatch[1][$pk]."\',\'".$pamatch[2][$pk]."\',".$newpage;
  20825. $this->javascript = str_replace($pmatch, $newjs, $this->javascript);
  20826. }
  20827. unset($pamatch);
  20828. }
  20829. // return to last page
  20830. $this->lastPage(true);
  20831. return true;
  20832. }
  20833. /**
  20834. * Remove the specified page.
  20835. * @param $page (int) page to remove
  20836. * @return true in case of success, false in case of error.
  20837. * @public
  20838. * @since 4.6.004 (2009-04-23)
  20839. */
  20840. public function deletePage($page)
  20841. {
  20842. if (($page < 1) OR ($page > $this->numpages)) {
  20843. return false;
  20844. }
  20845. // delete current page
  20846. unset($this->pages[$page]);
  20847. unset($this->pagedim[$page]);
  20848. unset($this->pagelen[$page]);
  20849. unset($this->intmrk[$page]);
  20850. unset($this->bordermrk[$page]);
  20851. unset($this->cntmrk[$page]);
  20852. foreach ($this->pageobjects[$page] as $oid) {
  20853. if (isset($this->offsets[$oid])) {
  20854. unset($this->offsets[$oid]);
  20855. }
  20856. }
  20857. unset($this->pageobjects[$page]);
  20858. if (isset($this->footerpos[$page])) {
  20859. unset($this->footerpos[$page]);
  20860. }
  20861. if (isset($this->footerlen[$page])) {
  20862. unset($this->footerlen[$page]);
  20863. }
  20864. if (isset($this->transfmrk[$page])) {
  20865. unset($this->transfmrk[$page]);
  20866. }
  20867. if (isset($this->PageAnnots[$page])) {
  20868. unset($this->PageAnnots[$page]);
  20869. }
  20870. if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
  20871. for ($i = $page; $i > 0; --$i) {
  20872. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $page)) {
  20873. --$this->pagegroups[$this->newpagegroup[$i]];
  20874. break;
  20875. }
  20876. }
  20877. }
  20878. if (isset($this->pageopen[$page])) {
  20879. unset($this->pageopen[$page]);
  20880. }
  20881. if ($page < $this->numpages) {
  20882. // update remaining pages
  20883. for ($i = $page; $i < $this->numpages; ++$i) {
  20884. $j = $i + 1;
  20885. // shift pages
  20886. $this->setPageBuffer($i, $this->getPageBuffer($j));
  20887. $this->pagedim[$i] = $this->pagedim[$j];
  20888. $this->pagelen[$i] = $this->pagelen[$j];
  20889. $this->intmrk[$i] = $this->intmrk[$j];
  20890. $this->bordermrk[$i] = $this->bordermrk[$j];
  20891. $this->cntmrk[$i] = $this->cntmrk[$j];
  20892. $this->pageobjects[$i] = $this->pageobjects[$j];
  20893. if (isset($this->footerpos[$j])) {
  20894. $this->footerpos[$i] = $this->footerpos[$j];
  20895. } elseif (isset($this->footerpos[$i])) {
  20896. unset($this->footerpos[$i]);
  20897. }
  20898. if (isset($this->footerlen[$j])) {
  20899. $this->footerlen[$i] = $this->footerlen[$j];
  20900. } elseif (isset($this->footerlen[$i])) {
  20901. unset($this->footerlen[$i]);
  20902. }
  20903. if (isset($this->transfmrk[$j])) {
  20904. $this->transfmrk[$i] = $this->transfmrk[$j];
  20905. } elseif (isset($this->transfmrk[$i])) {
  20906. unset($this->transfmrk[$i]);
  20907. }
  20908. if (isset($this->PageAnnots[$j])) {
  20909. $this->PageAnnots[$i] = $this->PageAnnots[$j];
  20910. } elseif (isset($this->PageAnnots[$i])) {
  20911. unset($this->PageAnnots[$i]);
  20912. }
  20913. if (isset($this->newpagegroup[$j])) {
  20914. $this->newpagegroup[$i] = $this->newpagegroup[$j];
  20915. unset($this->newpagegroup[$j]);
  20916. }
  20917. if ($this->currpagegroup == $j) {
  20918. $this->currpagegroup = $i;
  20919. }
  20920. if (isset($this->pageopen[$j])) {
  20921. $this->pageopen[$i] = $this->pageopen[$j];
  20922. } elseif (isset($this->pageopen[$i])) {
  20923. unset($this->pageopen[$i]);
  20924. }
  20925. }
  20926. // remove last page
  20927. unset($this->pages[$this->numpages]);
  20928. unset($this->pagedim[$this->numpages]);
  20929. unset($this->pagelen[$this->numpages]);
  20930. unset($this->intmrk[$this->numpages]);
  20931. unset($this->bordermrk[$this->numpages]);
  20932. unset($this->cntmrk[$this->numpages]);
  20933. foreach ($this->pageobjects[$this->numpages] as $oid) {
  20934. if (isset($this->offsets[$oid])) {
  20935. unset($this->offsets[$oid]);
  20936. }
  20937. }
  20938. unset($this->pageobjects[$this->numpages]);
  20939. if (isset($this->footerpos[$this->numpages])) {
  20940. unset($this->footerpos[$this->numpages]);
  20941. }
  20942. if (isset($this->footerlen[$this->numpages])) {
  20943. unset($this->footerlen[$this->numpages]);
  20944. }
  20945. if (isset($this->transfmrk[$this->numpages])) {
  20946. unset($this->transfmrk[$this->numpages]);
  20947. }
  20948. if (isset($this->PageAnnots[$this->numpages])) {
  20949. unset($this->PageAnnots[$this->numpages]);
  20950. }
  20951. if (isset($this->newpagegroup[$this->numpages])) {
  20952. unset($this->newpagegroup[$this->numpages]);
  20953. }
  20954. if ($this->currpagegroup == $this->numpages) {
  20955. $this->currpagegroup = ($this->numpages - 1);
  20956. }
  20957. if (isset($this->pagegroups[$this->numpages])) {
  20958. unset($this->pagegroups[$this->numpages]);
  20959. }
  20960. if (isset($this->pageopen[$this->numpages])) {
  20961. unset($this->pageopen[$this->numpages]);
  20962. }
  20963. }
  20964. --$this->numpages;
  20965. $this->page = $this->numpages;
  20966. // adjust outlines
  20967. $tmpoutlines = $this->outlines;
  20968. foreach ($tmpoutlines as $key => $outline) {
  20969. if (!$outline['f']) {
  20970. if ($outline['p'] > $page) {
  20971. $this->outlines[$key]['p'] = $outline['p'] - 1;
  20972. } elseif ($outline['p'] == $page) {
  20973. unset($this->outlines[$key]);
  20974. }
  20975. }
  20976. }
  20977. // adjust dests
  20978. $tmpdests = $this->dests;
  20979. foreach ($tmpdests as $key => $dest) {
  20980. if (!$dest['f']) {
  20981. if ($dest['p'] > $page) {
  20982. $this->dests[$key]['p'] = $dest['p'] - 1;
  20983. } elseif ($dest['p'] == $page) {
  20984. unset($this->dests[$key]);
  20985. }
  20986. }
  20987. }
  20988. // adjust links
  20989. $tmplinks = $this->links;
  20990. foreach ($tmplinks as $key => $link) {
  20991. if (!$link['f']) {
  20992. if ($link['p'] > $page) {
  20993. $this->links[$key]['p'] = $link['p'] - 1;
  20994. } elseif ($link['p'] == $page) {
  20995. unset($this->links[$key]);
  20996. }
  20997. }
  20998. }
  20999. // adjust javascript
  21000. $jpage = $page;
  21001. if (preg_match_all('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', $this->javascript, $pamatch) > 0) {
  21002. foreach ($pamatch[0] as $pk => $pmatch) {
  21003. $pagenum = intval($pamatch[3][$pk]) + 1;
  21004. if ($pagenum >= $jpage) {
  21005. $newpage = ($pagenum - 1);
  21006. } elseif ($pagenum == $jpage) {
  21007. $newpage = 1;
  21008. } else {
  21009. $newpage = $pagenum;
  21010. }
  21011. --$newpage;
  21012. $newjs = "this.addField(\'".$pamatch[1][$pk]."\',\'".$pamatch[2][$pk]."\',".$newpage;
  21013. $this->javascript = str_replace($pmatch, $newjs, $this->javascript);
  21014. }
  21015. unset($pamatch);
  21016. }
  21017. // return to last page
  21018. if ($this->numpages > 0) {
  21019. $this->lastPage(true);
  21020. }
  21021. return true;
  21022. }
  21023. /**
  21024. * Clone the specified page to a new page.
  21025. * @param $page (int) number of page to copy (0 = current page)
  21026. * @return true in case of success, false in case of error.
  21027. * @public
  21028. * @since 4.9.015 (2010-04-20)
  21029. */
  21030. public function copyPage($page = 0)
  21031. {
  21032. if ($page == 0) {
  21033. // default value
  21034. $page = $this->page;
  21035. }
  21036. if (($page < 1) OR ($page > $this->numpages)) {
  21037. return false;
  21038. }
  21039. // close the last page
  21040. $this->endPage();
  21041. // copy all page-related states
  21042. ++$this->numpages;
  21043. $this->page = $this->numpages;
  21044. $this->setPageBuffer($this->page, $this->getPageBuffer($page));
  21045. $this->pagedim[$this->page] = $this->pagedim[$page];
  21046. $this->pagelen[$this->page] = $this->pagelen[$page];
  21047. $this->intmrk[$this->page] = $this->intmrk[$page];
  21048. $this->bordermrk[$this->page] = $this->bordermrk[$page];
  21049. $this->cntmrk[$this->page] = $this->cntmrk[$page];
  21050. $this->pageobjects[$this->page] = $this->pageobjects[$page];
  21051. $this->pageopen[$this->page] = false;
  21052. if (isset($this->footerpos[$page])) {
  21053. $this->footerpos[$this->page] = $this->footerpos[$page];
  21054. }
  21055. if (isset($this->footerlen[$page])) {
  21056. $this->footerlen[$this->page] = $this->footerlen[$page];
  21057. }
  21058. if (isset($this->transfmrk[$page])) {
  21059. $this->transfmrk[$this->page] = $this->transfmrk[$page];
  21060. }
  21061. if (isset($this->PageAnnots[$page])) {
  21062. $this->PageAnnots[$this->page] = $this->PageAnnots[$page];
  21063. }
  21064. if (isset($this->newpagegroup[$page])) {
  21065. // start a new group
  21066. $this->newpagegroup[$this->page] = sizeof($this->newpagegroup) + 1;
  21067. $this->currpagegroup = $this->newpagegroup[$this->page];
  21068. $this->pagegroups[$this->currpagegroup] = 1;
  21069. } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) {
  21070. ++$this->pagegroups[$this->currpagegroup];
  21071. }
  21072. // copy outlines
  21073. $tmpoutlines = $this->outlines;
  21074. foreach ($tmpoutlines as $key => $outline) {
  21075. if ($outline['p'] == $page) {
  21076. $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']);
  21077. }
  21078. }
  21079. // copy links
  21080. $tmplinks = $this->links;
  21081. foreach ($tmplinks as $key => $link) {
  21082. if ($link['p'] == $page) {
  21083. $this->links[] = array('p' => $this->page, 'y' => $link['y'], 'f' => $link['f']);
  21084. }
  21085. }
  21086. // return to last page
  21087. $this->lastPage(true);
  21088. return true;
  21089. }
  21090. /**
  21091. * Output a Table of Content Index (TOC).
  21092. * This method must be called after all Bookmarks were set.
  21093. * Before calling this method you have to open the page using the addTOCPage() method.
  21094. * After calling this method you have to call endTOCPage() to close the TOC page.
  21095. * You can override this method to achieve different styles.
  21096. * @param $page (int) page number where this TOC should be inserted (leave empty for current page).
  21097. * @param $numbersfont (string) set the font for page numbers (please use monospaced font for better alignment).
  21098. * @param $filler (string) string used to fill the space between text and page number.
  21099. * @param $toc_name (string) name to use for TOC bookmark.
  21100. * @param $style (string) Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
  21101. * @param $color (array) RGB color array for bookmark title (values from 0 to 255).
  21102. * @public
  21103. * @author Nicola Asuni
  21104. * @since 4.5.000 (2009-01-02)
  21105. * @see addTOCPage(), endTOCPage(), addHTMLTOC()
  21106. */
  21107. public function addTOC($page = '', $numbersfont = '', $filler = '.', $toc_name = 'TOC', $style = '', $color = array(0,0,0))
  21108. {
  21109. $fontsize = $this->FontSizePt;
  21110. $fontfamily = $this->FontFamily;
  21111. $fontstyle = $this->FontStyle;
  21112. $w = $this->w - $this->lMargin - $this->rMargin;
  21113. $spacer = $this->GetStringWidth(chr(32)) * 4;
  21114. $lmargin = $this->lMargin;
  21115. $rmargin = $this->rMargin;
  21116. $x_start = $this->GetX();
  21117. $page_first = $this->page;
  21118. $current_page = $this->page;
  21119. $page_fill_start = false;
  21120. $page_fill_end = false;
  21121. $current_column = $this->current_column;
  21122. if (TCPDF_STATIC::empty_string($numbersfont)) {
  21123. $numbersfont = $this->default_monospaced_font;
  21124. }
  21125. if (TCPDF_STATIC::empty_string($filler)) {
  21126. $filler = ' ';
  21127. }
  21128. if (TCPDF_STATIC::empty_string($page)) {
  21129. $gap = ' ';
  21130. } else {
  21131. $gap = '';
  21132. if ($page < 1) {
  21133. $page = 1;
  21134. }
  21135. }
  21136. $this->SetFont($numbersfont, $fontstyle, $fontsize);
  21137. $numwidth = $this->GetStringWidth('00000');
  21138. $maxpage = 0; //used for pages on attached documents
  21139. foreach ($this->outlines as $key => $outline) {
  21140. // check for extra pages (used for attachments)
  21141. if (($this->page > $page_first) AND ($outline['p'] >= $this->numpages)) {
  21142. $outline['p'] += ($this->page - $page_first);
  21143. }
  21144. if ($this->rtl) {
  21145. $aligntext = 'R';
  21146. $alignnum = 'L';
  21147. } else {
  21148. $aligntext = 'L';
  21149. $alignnum = 'R';
  21150. }
  21151. if ($outline['l'] == 0) {
  21152. $this->SetFont($fontfamily, $outline['s'].'B', $fontsize);
  21153. } else {
  21154. $this->SetFont($fontfamily, $outline['s'], $fontsize - $outline['l']);
  21155. }
  21156. $this->SetTextColorArray($outline['c']);
  21157. // check for page break
  21158. $this->checkPageBreak(2 * $this->getCellHeight($this->FontSize));
  21159. // set margins and X position
  21160. if (($this->page == $current_page) AND ($this->current_column == $current_column)) {
  21161. $this->lMargin = $lmargin;
  21162. $this->rMargin = $rmargin;
  21163. } else {
  21164. if ($this->current_column != $current_column) {
  21165. if ($this->rtl) {
  21166. $x_start = $this->w - $this->columns[$this->current_column]['x'];
  21167. } else {
  21168. $x_start = $this->columns[$this->current_column]['x'];
  21169. }
  21170. }
  21171. $lmargin = $this->lMargin;
  21172. $rmargin = $this->rMargin;
  21173. $current_page = $this->page;
  21174. $current_column = $this->current_column;
  21175. }
  21176. $this->SetX($x_start);
  21177. $indent = ($spacer * $outline['l']);
  21178. if ($this->rtl) {
  21179. $this->x -= $indent;
  21180. $this->rMargin = $this->w - $this->x;
  21181. } else {
  21182. $this->x += $indent;
  21183. $this->lMargin = $this->x;
  21184. }
  21185. $link = $this->AddLink();
  21186. $this->SetLink($link, $outline['y'], $outline['p']);
  21187. // write the text
  21188. if ($this->rtl) {
  21189. $txt = ' '.$outline['t'];
  21190. } else {
  21191. $txt = $outline['t'].' ';
  21192. }
  21193. $this->Write(0, $txt, $link, false, $aligntext, false, 0, false, false, 0, $numwidth, '');
  21194. if ($this->rtl) {
  21195. $tw = $this->x - $this->lMargin;
  21196. } else {
  21197. $tw = $this->w - $this->rMargin - $this->x;
  21198. }
  21199. $this->SetFont($numbersfont, $fontstyle, $fontsize);
  21200. if (TCPDF_STATIC::empty_string($page)) {
  21201. $pagenum = $outline['p'];
  21202. } else {
  21203. // placemark to be replaced with the correct number
  21204. $pagenum = '{#'.($outline['p']).'}';
  21205. if ($this->isUnicodeFont()) {
  21206. $pagenum = '{'.$pagenum.'}';
  21207. }
  21208. $maxpage = max($maxpage, $outline['p']);
  21209. }
  21210. $fw = ($tw - $this->GetStringWidth($pagenum.$filler));
  21211. $wfiller = $this->GetStringWidth($filler);
  21212. if ($wfiller > 0) {
  21213. $numfills = floor($fw / $wfiller);
  21214. } else {
  21215. $numfills = 0;
  21216. }
  21217. if ($numfills > 0) {
  21218. $rowfill = str_repeat($filler, $numfills);
  21219. } else {
  21220. $rowfill = '';
  21221. }
  21222. if ($this->rtl) {
  21223. $pagenum = $pagenum.$gap.$rowfill;
  21224. } else {
  21225. $pagenum = $rowfill.$gap.$pagenum;
  21226. }
  21227. // write the number
  21228. $this->Cell($tw, 0, $pagenum, 0, 1, $alignnum, 0, $link, 0);
  21229. }
  21230. $page_last = $this->getPage();
  21231. $numpages = ($page_last - $page_first + 1);
  21232. // account for booklet mode
  21233. if ($this->booklet) {
  21234. // check if a blank page is required before TOC
  21235. $page_fill_start = ((($page_first % 2) == 0) XOR (($page % 2) == 0));
  21236. $page_fill_end = (!((($numpages % 2) == 0) XOR ($page_fill_start)));
  21237. if ($page_fill_start) {
  21238. // add a page at the end (to be moved before TOC)
  21239. $this->addPage();
  21240. ++$page_last;
  21241. ++$numpages;
  21242. }
  21243. if ($page_fill_end) {
  21244. // add a page at the end
  21245. $this->addPage();
  21246. ++$page_last;
  21247. ++$numpages;
  21248. }
  21249. }
  21250. $maxpage = max($maxpage, $page_last);
  21251. if (!TCPDF_STATIC::empty_string($page)) {
  21252. for ($p = $page_first; $p <= $page_last; ++$p) {
  21253. // get page data
  21254. $temppage = $this->getPageBuffer($p);
  21255. for ($n = 1; $n <= $maxpage; ++$n) {
  21256. // update page numbers
  21257. $a = '{#'.$n.'}';
  21258. // get page number aliases
  21259. $pnalias = $this->getInternalPageNumberAliases($a);
  21260. // calculate replacement number
  21261. if (($n >= $page) AND ($n <= $this->numpages)) {
  21262. $np = $n + $numpages;
  21263. } else {
  21264. $np = $n;
  21265. }
  21266. $na = TCPDF_STATIC::formatTOCPageNumber(($this->starting_page_number + $np - 1));
  21267. $nu = TCPDF_FONTS::UTF8ToUTF16BE($na, false, $this->isunicode, $this->CurrentFont);
  21268. // replace aliases with numbers
  21269. foreach ($pnalias['u'] as $u) {
  21270. $sfill = str_repeat($filler, max(0, (strlen($u) - strlen($nu.' '))));
  21271. if ($this->rtl) {
  21272. $nr = $nu.TCPDF_FONTS::UTF8ToUTF16BE(' '.$sfill, false, $this->isunicode, $this->CurrentFont);
  21273. } else {
  21274. $nr = TCPDF_FONTS::UTF8ToUTF16BE($sfill.' ', false, $this->isunicode, $this->CurrentFont).$nu;
  21275. }
  21276. $temppage = str_replace($u, $nr, $temppage);
  21277. }
  21278. foreach ($pnalias['a'] as $a) {
  21279. $sfill = str_repeat($filler, max(0, (strlen($a) - strlen($na.' '))));
  21280. if ($this->rtl) {
  21281. $nr = $na.' '.$sfill;
  21282. } else {
  21283. $nr = $sfill.' '.$na;
  21284. }
  21285. $temppage = str_replace($a, $nr, $temppage);
  21286. }
  21287. }
  21288. // save changes
  21289. $this->setPageBuffer($p, $temppage);
  21290. }
  21291. // move pages
  21292. $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
  21293. if ($page_fill_start) {
  21294. $this->movePage($page_last, $page_first);
  21295. }
  21296. for ($i = 0; $i < $numpages; ++$i) {
  21297. $this->movePage($page_last, $page);
  21298. }
  21299. }
  21300. }
  21301. /**
  21302. * Output a Table Of Content Index (TOC) using HTML templates.
  21303. * This method must be called after all Bookmarks were set.
  21304. * Before calling this method you have to open the page using the addTOCPage() method.
  21305. * After calling this method you have to call endTOCPage() to close the TOC page.
  21306. * @param $page (int) page number where this TOC should be inserted (leave empty for current page).
  21307. * @param $toc_name (string) name to use for TOC bookmark.
  21308. * @param $templates (array) array of html templates. Use: "#TOC_DESCRIPTION#" for bookmark title, "#TOC_PAGE_NUMBER#" for page number.
  21309. * @param $correct_align (boolean) if true correct the number alignment (numbers must be in monospaced font like courier and right aligned on LTR, or left aligned on RTL)
  21310. * @param $style (string) Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
  21311. * @param $color (array) RGB color array for title (values from 0 to 255).
  21312. * @public
  21313. * @author Nicola Asuni
  21314. * @since 5.0.001 (2010-05-06)
  21315. * @see addTOCPage(), endTOCPage(), addTOC()
  21316. */
  21317. public function addHTMLTOC($page = '', $toc_name = 'TOC', $templates = array(), $correct_align = true, $style = '', $color = array(0,0,0))
  21318. {
  21319. $filler = ' ';
  21320. $prev_htmlLinkColorArray = $this->htmlLinkColorArray;
  21321. $prev_htmlLinkFontStyle = $this->htmlLinkFontStyle;
  21322. // set new style for link
  21323. $this->htmlLinkColorArray = array();
  21324. $this->htmlLinkFontStyle = '';
  21325. $page_first = $this->getPage();
  21326. $page_fill_start = false;
  21327. $page_fill_end = false;
  21328. // get the font type used for numbers in each template
  21329. $current_font = $this->FontFamily;
  21330. foreach ($templates as $level => $html) {
  21331. $dom = $this->getHtmlDomArray($html);
  21332. foreach ($dom as $key => $value) {
  21333. if ($value['value'] == '#TOC_PAGE_NUMBER#') {
  21334. $this->SetFont($dom[($key - 1)]['fontname']);
  21335. $templates['F'.$level] = $this->isUnicodeFont();
  21336. }
  21337. }
  21338. }
  21339. $this->SetFont($current_font);
  21340. $maxpage = 0; //used for pages on attached documents
  21341. foreach ($this->outlines as $key => $outline) {
  21342. // get HTML template
  21343. $row = $templates[$outline['l']];
  21344. if (TCPDF_STATIC::empty_string($page)) {
  21345. $pagenum = $outline['p'];
  21346. } else {
  21347. // placemark to be replaced with the correct number
  21348. $pagenum = '{#'.($outline['p']).'}';
  21349. if (isset($templates['F'.$outline['l']]) && $templates['F'.$outline['l']]) {
  21350. $pagenum = '{'.$pagenum.'}';
  21351. }
  21352. $maxpage = max($maxpage, $outline['p']);
  21353. }
  21354. // replace templates with current values
  21355. $row = str_replace('#TOC_DESCRIPTION#', $outline['t'], $row);
  21356. $row = str_replace('#TOC_PAGE_NUMBER#', $pagenum, $row);
  21357. // add link to page
  21358. $row = '<a href="#'.$outline['p'].','.$outline['y'].'">'.$row.'</a>';
  21359. // write bookmark entry
  21360. $this->writeHTML($row, false, false, true, false, '');
  21361. }
  21362. // restore link styles
  21363. $this->htmlLinkColorArray = $prev_htmlLinkColorArray;
  21364. $this->htmlLinkFontStyle = $prev_htmlLinkFontStyle;
  21365. // move TOC page and replace numbers
  21366. $page_last = $this->getPage();
  21367. $numpages = ($page_last - $page_first + 1);
  21368. // account for booklet mode
  21369. if ($this->booklet) {
  21370. // check if a blank page is required before TOC
  21371. $page_fill_start = ((($page_first % 2) == 0) XOR (($page % 2) == 0));
  21372. $page_fill_end = (!((($numpages % 2) == 0) XOR ($page_fill_start)));
  21373. if ($page_fill_start) {
  21374. // add a page at the end (to be moved before TOC)
  21375. $this->addPage();
  21376. ++$page_last;
  21377. ++$numpages;
  21378. }
  21379. if ($page_fill_end) {
  21380. // add a page at the end
  21381. $this->addPage();
  21382. ++$page_last;
  21383. ++$numpages;
  21384. }
  21385. }
  21386. $maxpage = max($maxpage, $page_last);
  21387. if (!TCPDF_STATIC::empty_string($page)) {
  21388. for ($p = $page_first; $p <= $page_last; ++$p) {
  21389. // get page data
  21390. $temppage = $this->getPageBuffer($p);
  21391. for ($n = 1; $n <= $maxpage; ++$n) {
  21392. // update page numbers
  21393. $a = '{#'.$n.'}';
  21394. // get page number aliases
  21395. $pnalias = $this->getInternalPageNumberAliases($a);
  21396. // calculate replacement number
  21397. if ($n >= $page) {
  21398. $np = $n + $numpages;
  21399. } else {
  21400. $np = $n;
  21401. }
  21402. $na = TCPDF_STATIC::formatTOCPageNumber(($this->starting_page_number + $np - 1));
  21403. $nu = TCPDF_FONTS::UTF8ToUTF16BE($na, false, $this->isunicode, $this->CurrentFont);
  21404. // replace aliases with numbers
  21405. foreach ($pnalias['u'] as $u) {
  21406. if ($correct_align) {
  21407. $sfill = str_repeat($filler, (strlen($u) - strlen($nu.' ')));
  21408. if ($this->rtl) {
  21409. $nr = $nu.TCPDF_FONTS::UTF8ToUTF16BE(' '.$sfill, false, $this->isunicode, $this->CurrentFont);
  21410. } else {
  21411. $nr = TCPDF_FONTS::UTF8ToUTF16BE($sfill.' ', false, $this->isunicode, $this->CurrentFont).$nu;
  21412. }
  21413. } else {
  21414. $nr = $nu;
  21415. }
  21416. $temppage = str_replace($u, $nr, $temppage);
  21417. }
  21418. foreach ($pnalias['a'] as $a) {
  21419. if ($correct_align) {
  21420. $sfill = str_repeat($filler, (strlen($a) - strlen($na.' ')));
  21421. if ($this->rtl) {
  21422. $nr = $na.' '.$sfill;
  21423. } else {
  21424. $nr = $sfill.' '.$na;
  21425. }
  21426. } else {
  21427. $nr = $na;
  21428. }
  21429. $temppage = str_replace($a, $nr, $temppage);
  21430. }
  21431. }
  21432. // save changes
  21433. $this->setPageBuffer($p, $temppage);
  21434. }
  21435. // move pages
  21436. $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
  21437. if ($page_fill_start) {
  21438. $this->movePage($page_last, $page_first);
  21439. }
  21440. for ($i = 0; $i < $numpages; ++$i) {
  21441. $this->movePage($page_last, $page);
  21442. }
  21443. }
  21444. }
  21445. /**
  21446. * Stores a copy of the current TCPDF object used for undo operation.
  21447. * @public
  21448. * @since 4.5.029 (2009-03-19)
  21449. */
  21450. public function startTransaction()
  21451. {
  21452. if (isset($this->objcopy)) {
  21453. // remove previous copy
  21454. $this->commitTransaction();
  21455. }
  21456. // record current page number and Y position
  21457. $this->start_transaction_page = $this->page;
  21458. $this->start_transaction_y = $this->y;
  21459. // clone current object
  21460. $this->objcopy = TCPDF_STATIC::objclone($this);
  21461. }
  21462. /**
  21463. * Delete the copy of the current TCPDF object used for undo operation.
  21464. * @public
  21465. * @since 4.5.029 (2009-03-19)
  21466. */
  21467. public function commitTransaction()
  21468. {
  21469. if (isset($this->objcopy)) {
  21470. $this->objcopy->_destroy(true, true);
  21471. unset($this->objcopy);
  21472. }
  21473. }
  21474. /**
  21475. * This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction().
  21476. * @param $self (boolean) if true restores current class object to previous state without the need of reassignment via the returned value.
  21477. * @return TCPDF object.
  21478. * @public
  21479. * @since 4.5.029 (2009-03-19)
  21480. */
  21481. public function rollbackTransaction($self = false)
  21482. {
  21483. if (isset($this->objcopy)) {
  21484. $this->_destroy(true, true);
  21485. if ($self) {
  21486. $objvars = get_object_vars($this->objcopy);
  21487. foreach ($objvars as $key => $value) {
  21488. $this->$key = $value;
  21489. }
  21490. }
  21491. return $this->objcopy;
  21492. }
  21493. return $this;
  21494. }
  21495. // --- MULTI COLUMNS METHODS -----------------------
  21496. /**
  21497. * Set multiple columns of the same size
  21498. * @param $numcols (int) number of columns (set to zero to disable columns mode)
  21499. * @param $width (int) column width
  21500. * @param $y (int) column starting Y position (leave empty for current Y position)
  21501. * @public
  21502. * @since 4.9.001 (2010-03-28)
  21503. */
  21504. public function setEqualColumns($numcols = 0, $width = 0, $y = '')
  21505. {
  21506. $this->columns = array();
  21507. if ($numcols < 2) {
  21508. $numcols = 0;
  21509. $this->columns = array();
  21510. } else {
  21511. // maximum column width
  21512. $maxwidth = ($this->w - $this->original_lMargin - $this->original_rMargin) / $numcols;
  21513. if (($width == 0) OR ($width > $maxwidth)) {
  21514. $width = $maxwidth;
  21515. }
  21516. if (TCPDF_STATIC::empty_string($y)) {
  21517. $y = $this->y;
  21518. }
  21519. // space between columns
  21520. $space = (($this->w - $this->original_lMargin - $this->original_rMargin - ($numcols * $width)) / ($numcols - 1));
  21521. // fill the columns array (with, space, starting Y position)
  21522. for ($i = 0; $i < $numcols; ++$i) {
  21523. $this->columns[$i] = array('w' => $width, 's' => $space, 'y' => $y);
  21524. }
  21525. }
  21526. $this->num_columns = $numcols;
  21527. $this->current_column = 0;
  21528. $this->column_start_page = $this->page;
  21529. $this->selectColumn(0);
  21530. }
  21531. /**
  21532. * Remove columns and reset page margins.
  21533. * @public
  21534. * @since 5.9.072 (2011-04-26)
  21535. */
  21536. public function resetColumns()
  21537. {
  21538. $this->lMargin = $this->original_lMargin;
  21539. $this->rMargin = $this->original_rMargin;
  21540. $this->setEqualColumns();
  21541. }
  21542. /**
  21543. * Set columns array.
  21544. * Each column is represented by an array of arrays with the following keys: (w = width, s = space between columns, y = column top position).
  21545. * @param $columns (array)
  21546. * @public
  21547. * @since 4.9.001 (2010-03-28)
  21548. */
  21549. public function setColumnsArray($columns)
  21550. {
  21551. $this->columns = $columns;
  21552. $this->num_columns = count($columns);
  21553. $this->current_column = 0;
  21554. $this->column_start_page = $this->page;
  21555. $this->selectColumn(0);
  21556. }
  21557. /**
  21558. * Set position at a given column
  21559. * @param $col (int) column number (from 0 to getNumberOfColumns()-1); empty string = current column.
  21560. * @public
  21561. * @since 4.9.001 (2010-03-28)
  21562. */
  21563. public function selectColumn($col = '')
  21564. {
  21565. if (is_string($col)) {
  21566. $col = $this->current_column;
  21567. } elseif ($col >= $this->num_columns) {
  21568. $col = 0;
  21569. }
  21570. $xshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  21571. $enable_thead = false;
  21572. if ($this->num_columns > 1) {
  21573. if ($col != $this->current_column) {
  21574. // move Y pointer at the top of the column
  21575. if ($this->column_start_page == $this->page) {
  21576. $this->y = $this->columns[$col]['y'];
  21577. } else {
  21578. $this->y = $this->tMargin;
  21579. }
  21580. // Avoid to write table headers more than once
  21581. if (($this->page > $this->maxselcol['page']) OR (($this->page == $this->maxselcol['page']) AND ($col > $this->maxselcol['column']))) {
  21582. $enable_thead = true;
  21583. $this->maxselcol['page'] = $this->page;
  21584. $this->maxselcol['column'] = $col;
  21585. }
  21586. }
  21587. $xshift = $this->colxshift;
  21588. // set X position of the current column by case
  21589. $listindent = ($this->listindentlevel * $this->listindent);
  21590. // calculate column X position
  21591. $colpos = 0;
  21592. for ($i = 0; $i < $col; ++$i) {
  21593. $colpos += ($this->columns[$i]['w'] + $this->columns[$i]['s']);
  21594. }
  21595. if ($this->rtl) {
  21596. $x = $this->w - $this->original_rMargin - $colpos;
  21597. $this->rMargin = ($this->w - $x + $listindent);
  21598. $this->lMargin = ($x - $this->columns[$col]['w']);
  21599. $this->x = $x - $listindent;
  21600. } else {
  21601. $x = $this->original_lMargin + $colpos;
  21602. $this->lMargin = ($x + $listindent);
  21603. $this->rMargin = ($this->w - $x - $this->columns[$col]['w']);
  21604. $this->x = $x + $listindent;
  21605. }
  21606. $this->columns[$col]['x'] = $x;
  21607. }
  21608. $this->current_column = $col;
  21609. // fix for HTML mode
  21610. $this->newline = true;
  21611. // print HTML table header (if any)
  21612. if ((!TCPDF_STATIC::empty_string($this->thead)) AND (!$this->inthead)) {
  21613. if ($enable_thead) {
  21614. // print table header
  21615. $this->writeHTML($this->thead, false, false, false, false, '');
  21616. $this->y += $xshift['s']['V'];
  21617. // store end of header position
  21618. if (!isset($this->columns[$col]['th'])) {
  21619. $this->columns[$col]['th'] = array();
  21620. }
  21621. $this->columns[$col]['th']['\''.$this->page.'\''] = $this->y;
  21622. $this->lasth = 0;
  21623. } elseif (isset($this->columns[$col]['th']['\''.$this->page.'\''])) {
  21624. $this->y = $this->columns[$col]['th']['\''.$this->page.'\''];
  21625. }
  21626. }
  21627. // account for an html table cell over multiple columns
  21628. if ($this->rtl) {
  21629. $this->rMargin += $xshift['x'];
  21630. $this->x -= ($xshift['x'] + $xshift['p']['R']);
  21631. } else {
  21632. $this->lMargin += $xshift['x'];
  21633. $this->x += $xshift['x'] + $xshift['p']['L'];
  21634. }
  21635. }
  21636. /**
  21637. * Return the current column number
  21638. * @return int current column number
  21639. * @public
  21640. * @since 5.5.011 (2010-07-08)
  21641. */
  21642. public function getColumn()
  21643. {
  21644. return $this->current_column;
  21645. }
  21646. /**
  21647. * Return the current number of columns.
  21648. * @return int number of columns
  21649. * @public
  21650. * @since 5.8.018 (2010-08-25)
  21651. */
  21652. public function getNumberOfColumns()
  21653. {
  21654. return $this->num_columns;
  21655. }
  21656. /**
  21657. * Set Text rendering mode.
  21658. * @param $stroke (int) outline size in user units (0 = disable).
  21659. * @param $fill (boolean) if true fills the text (default).
  21660. * @param $clip (boolean) if true activate clipping mode
  21661. * @public
  21662. * @since 4.9.008 (2009-04-02)
  21663. */
  21664. public function setTextRenderingMode($stroke = 0, $fill = true, $clip = false)
  21665. {
  21666. // Ref.: PDF 32000-1:2008 - 9.3.6 Text Rendering Mode
  21667. // convert text rendering parameters
  21668. if ($stroke < 0) {
  21669. $stroke = 0;
  21670. }
  21671. if ($fill === true) {
  21672. if ($stroke > 0) {
  21673. if ($clip === true) {
  21674. // Fill, then stroke text and add to path for clipping
  21675. $textrendermode = 6;
  21676. } else {
  21677. // Fill, then stroke text
  21678. $textrendermode = 2;
  21679. }
  21680. $textstrokewidth = $stroke;
  21681. } else {
  21682. if ($clip === true) {
  21683. // Fill text and add to path for clipping
  21684. $textrendermode = 4;
  21685. } else {
  21686. // Fill text
  21687. $textrendermode = 0;
  21688. }
  21689. }
  21690. } else {
  21691. if ($stroke > 0) {
  21692. if ($clip === true) {
  21693. // Stroke text and add to path for clipping
  21694. $textrendermode = 5;
  21695. } else {
  21696. // Stroke text
  21697. $textrendermode = 1;
  21698. }
  21699. $textstrokewidth = $stroke;
  21700. } else {
  21701. if ($clip === true) {
  21702. // Add text to path for clipping
  21703. $textrendermode = 7;
  21704. } else {
  21705. // Neither fill nor stroke text (invisible)
  21706. $textrendermode = 3;
  21707. }
  21708. }
  21709. }
  21710. $this->textrendermode = $textrendermode;
  21711. $this->textstrokewidth = $stroke;
  21712. }
  21713. /**
  21714. * Set parameters for drop shadow effect for text.
  21715. * @param $params (array) Array of parameters: enabled (boolean) set to true to enable shadow; depth_w (float) shadow width in user units; depth_h (float) shadow height in user units; color (array) shadow color or false to use the stroke color; opacity (float) Alpha value: real value from 0 (transparent) to 1 (opaque); blend_mode (string) blend mode, one of the following: Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity.
  21716. * @since 5.9.174 (2012-07-25)
  21717. * @public
  21718. */
  21719. public function setTextShadow($params = array('enabled'=>false, 'depth_w'=>0, 'depth_h'=>0, 'color'=>false, 'opacity'=>1, 'blend_mode'=>'Normal'))
  21720. {
  21721. if (isset($params['enabled'])) {
  21722. $this->txtshadow['enabled'] = $params['enabled']?true:false;
  21723. } else {
  21724. $this->txtshadow['enabled'] = false;
  21725. }
  21726. if (isset($params['depth_w'])) {
  21727. $this->txtshadow['depth_w'] = floatval($params['depth_w']);
  21728. } else {
  21729. $this->txtshadow['depth_w'] = 0;
  21730. }
  21731. if (isset($params['depth_h'])) {
  21732. $this->txtshadow['depth_h'] = floatval($params['depth_h']);
  21733. } else {
  21734. $this->txtshadow['depth_h'] = 0;
  21735. }
  21736. if (isset($params['color']) AND ($params['color'] !== false) AND is_array($params['color'])) {
  21737. $this->txtshadow['color'] = $params['color'];
  21738. } else {
  21739. $this->txtshadow['color'] = $this->strokecolor;
  21740. }
  21741. if (isset($params['opacity'])) {
  21742. $this->txtshadow['opacity'] = min(1, max(0, floatval($params['opacity'])));
  21743. } else {
  21744. $this->txtshadow['opacity'] = 1;
  21745. }
  21746. 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'))) {
  21747. $this->txtshadow['blend_mode'] = $params['blend_mode'];
  21748. } else {
  21749. $this->txtshadow['blend_mode'] = 'Normal';
  21750. }
  21751. if ((($this->txtshadow['depth_w'] == 0) AND ($this->txtshadow['depth_h'] == 0)) OR ($this->txtshadow['opacity'] == 0)) {
  21752. $this->txtshadow['enabled'] = false;
  21753. }
  21754. }
  21755. /**
  21756. * Return the text shadow parameters array.
  21757. * @return Array of parameters.
  21758. * @since 5.9.174 (2012-07-25)
  21759. * @public
  21760. */
  21761. public function getTextShadow()
  21762. {
  21763. return $this->txtshadow;
  21764. }
  21765. /**
  21766. * Returns an array of chars containing soft hyphens.
  21767. * @param $word (array) array of chars
  21768. * @param $patterns (array) Array of hypenation patterns.
  21769. * @param $dictionary (array) Array of words to be returned without applying the hyphenation algorithm.
  21770. * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens.
  21771. * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens.
  21772. * @param $charmin (int) Minimum word length to apply the hyphenation algorithm.
  21773. * @param $charmax (int) Maximum length of broken piece of word.
  21774. * @return array text with soft hyphens
  21775. * @author Nicola Asuni
  21776. * @since 4.9.012 (2010-04-12)
  21777. * @protected
  21778. */
  21779. protected function hyphenateWord($word, $patterns, $dictionary = array(), $leftmin = 1, $rightmin = 2, $charmin = 1, $charmax = 8)
  21780. {
  21781. $hyphenword = array(); // hyphens positions
  21782. $numchars = count($word);
  21783. if ($numchars <= $charmin) {
  21784. return $word;
  21785. }
  21786. $word_string = TCPDF_FONTS::UTF8ArrSubString($word, '', '', $this->isunicode);
  21787. // some words will be returned as-is
  21788. $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})(\]?)$/';
  21789. if (preg_match($pattern, $word_string) > 0) {
  21790. // email
  21791. return $word;
  21792. }
  21793. $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})(\]?)$/';
  21794. if (preg_match($pattern, $word_string) > 0) {
  21795. // URL
  21796. return $word;
  21797. }
  21798. if (isset($dictionary[$word_string])) {
  21799. return TCPDF_FONTS::UTF8StringToArray($dictionary[$word_string], $this->isunicode, $this->CurrentFont);
  21800. }
  21801. // surround word with '_' characters
  21802. $tmpword = array_merge(array(46), $word, array(46));
  21803. $tmpnumchars = $numchars + 2;
  21804. $maxpos = $tmpnumchars - 1;
  21805. for ($pos = 0; $pos < $maxpos; ++$pos) {
  21806. $imax = min(($tmpnumchars - $pos), $charmax);
  21807. for ($i = 1; $i <= $imax; ++$i) {
  21808. $subword = strtolower(TCPDF_FONTS::UTF8ArrSubString($tmpword, $pos, ($pos + $i), $this->isunicode));
  21809. if (isset($patterns[$subword])) {
  21810. $pattern = TCPDF_FONTS::UTF8StringToArray($patterns[$subword], $this->isunicode, $this->CurrentFont);
  21811. $pattern_length = count($pattern);
  21812. $digits = 1;
  21813. for ($j = 0; $j < $pattern_length; ++$j) {
  21814. // check if $pattern[$j] is a number = hyphenation level (only numbers from 1 to 5 are valid)
  21815. if (($pattern[$j] >= 48) AND ($pattern[$j] <= 57)) {
  21816. if ($j == 0) {
  21817. $zero = $pos - 1;
  21818. } else {
  21819. $zero = $pos + $j - $digits;
  21820. }
  21821. // get hyphenation level
  21822. $level = ($pattern[$j] - 48);
  21823. // if two levels from two different patterns match at the same point, the higher one is selected.
  21824. if (!isset($hyphenword[$zero]) OR ($hyphenword[$zero] < $level)) {
  21825. $hyphenword[$zero] = $level;
  21826. }
  21827. ++$digits;
  21828. }
  21829. }
  21830. }
  21831. }
  21832. }
  21833. $inserted = 0;
  21834. $maxpos = $numchars - $rightmin;
  21835. for ($i = $leftmin; $i <= $maxpos; ++$i) {
  21836. // only odd levels indicate allowed hyphenation points
  21837. if (isset($hyphenword[$i]) AND (($hyphenword[$i] % 2) != 0)) {
  21838. // 173 = soft hyphen character
  21839. array_splice($word, $i + $inserted, 0, 173);
  21840. ++$inserted;
  21841. }
  21842. }
  21843. return $word;
  21844. }
  21845. /**
  21846. * Returns text with soft hyphens.
  21847. * @param $text (string) text to process
  21848. * @param $patterns (mixed) Array of hypenation patterns or a TEX file containing hypenation patterns. TEX patterns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
  21849. * @param $dictionary (array) Array of words to be returned without applying the hyphenation algorithm.
  21850. * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens.
  21851. * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens.
  21852. * @param $charmin (int) Minimum word length to apply the hyphenation algorithm.
  21853. * @param $charmax (int) Maximum length of broken piece of word.
  21854. * @return array text with soft hyphens
  21855. * @author Nicola Asuni
  21856. * @since 4.9.012 (2010-04-12)
  21857. * @public
  21858. */
  21859. public function hyphenateText($text, $patterns, $dictionary = array(), $leftmin = 1, $rightmin = 2, $charmin = 1, $charmax = 8)
  21860. {
  21861. $text = $this->unhtmlentities($text);
  21862. $word = array(); // last word
  21863. $txtarr = array(); // text to be returned
  21864. $intag = false; // true if we are inside an HTML tag
  21865. $skip = false; // true to skip hyphenation
  21866. if (!is_array($patterns)) {
  21867. $patterns = TCPDF_STATIC::getHyphenPatternsFromTEX($patterns);
  21868. }
  21869. // get array of characters
  21870. $unichars = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont);
  21871. // for each char
  21872. foreach ($unichars as $char) {
  21873. if ((!$intag) AND (!$skip) AND TCPDF_FONT_DATA::$uni_type[$char] == 'L') {
  21874. // letter character
  21875. $word[] = $char;
  21876. } else {
  21877. // other type of character
  21878. if (!TCPDF_STATIC::empty_string($word)) {
  21879. // hypenate the word
  21880. $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
  21881. $word = array();
  21882. }
  21883. $txtarr[] = $char;
  21884. if (chr($char) == '<') {
  21885. // we are inside an HTML tag
  21886. $intag = true;
  21887. } elseif ($intag AND (chr($char) == '>')) {
  21888. // end of HTML tag
  21889. $intag = false;
  21890. // check for style tag
  21891. $expected = array(115, 116, 121, 108, 101); // = 'style'
  21892. $current = array_slice($txtarr, -6, 5); // last 5 chars
  21893. $compare = array_diff($expected, $current);
  21894. if (empty($compare)) {
  21895. // check if it is a closing tag
  21896. $expected = array(47); // = '/'
  21897. $current = array_slice($txtarr, -7, 1);
  21898. $compare = array_diff($expected, $current);
  21899. if (empty($compare)) {
  21900. // closing style tag
  21901. $skip = false;
  21902. } else {
  21903. // opening style tag
  21904. $skip = true;
  21905. }
  21906. }
  21907. }
  21908. }
  21909. }
  21910. if (!TCPDF_STATIC::empty_string($word)) {
  21911. // hypenate the word
  21912. $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
  21913. }
  21914. // convert char array to string and return
  21915. return TCPDF_FONTS::UTF8ArrSubString($txtarr, '', '', $this->isunicode);
  21916. }
  21917. /**
  21918. * Enable/disable rasterization of vector images using ImageMagick library.
  21919. * @param $mode (boolean) if true enable rasterization, false otherwise.
  21920. * @public
  21921. * @since 5.0.000 (2010-04-27)
  21922. */
  21923. public function setRasterizeVectorImages($mode)
  21924. {
  21925. $this->rasterize_vector_images = $mode;
  21926. }
  21927. /**
  21928. * Enable or disable default option for font subsetting.
  21929. * @param $enable (boolean) if true enable font subsetting by default.
  21930. * @author Nicola Asuni
  21931. * @public
  21932. * @since 5.3.002 (2010-06-07)
  21933. */
  21934. public function setFontSubsetting($enable = true)
  21935. {
  21936. if ($this->pdfa_mode) {
  21937. $this->font_subsetting = false;
  21938. } else {
  21939. $this->font_subsetting = $enable ? true : false;
  21940. }
  21941. }
  21942. /**
  21943. * Return the default option for font subsetting.
  21944. * @return boolean default font subsetting state.
  21945. * @author Nicola Asuni
  21946. * @public
  21947. * @since 5.3.002 (2010-06-07)
  21948. */
  21949. public function getFontSubsetting()
  21950. {
  21951. return $this->font_subsetting;
  21952. }
  21953. /**
  21954. * Left trim the input string
  21955. * @param $str (string) string to trim
  21956. * @param $replace (string) string that replace spaces.
  21957. * @return left trimmed string
  21958. * @author Nicola Asuni
  21959. * @public
  21960. * @since 5.8.000 (2010-08-11)
  21961. */
  21962. public function stringLeftTrim($str, $replace = '')
  21963. {
  21964. return preg_replace('/^'.$this->re_space['p'].'+/'.$this->re_space['m'], $replace, $str);
  21965. }
  21966. /**
  21967. * Right trim the input string
  21968. * @param $str (string) string to trim
  21969. * @param $replace (string) string that replace spaces.
  21970. * @return right trimmed string
  21971. * @author Nicola Asuni
  21972. * @public
  21973. * @since 5.8.000 (2010-08-11)
  21974. */
  21975. public function stringRightTrim($str, $replace = '')
  21976. {
  21977. return preg_replace('/'.$this->re_space['p'].'+$/'.$this->re_space['m'], $replace, $str);
  21978. }
  21979. /**
  21980. * Trim the input string
  21981. * @param $str (string) string to trim
  21982. * @param $replace (string) string that replace spaces.
  21983. * @return trimmed string
  21984. * @author Nicola Asuni
  21985. * @public
  21986. * @since 5.8.000 (2010-08-11)
  21987. */
  21988. public function stringTrim($str, $replace = '')
  21989. {
  21990. $str = $this->stringLeftTrim($str, $replace);
  21991. $str = $this->stringRightTrim($str, $replace);
  21992. return $str;
  21993. }
  21994. /**
  21995. * Return true if the current font is unicode type.
  21996. * @return true for unicode font, false otherwise.
  21997. * @author Nicola Asuni
  21998. * @public
  21999. * @since 5.8.002 (2010-08-14)
  22000. */
  22001. public function isUnicodeFont()
  22002. {
  22003. return (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0'));
  22004. }
  22005. /**
  22006. * Return normalized font name
  22007. * @param $fontfamily (string) property string containing font family names
  22008. * @return string normalized font name
  22009. * @author Nicola Asuni
  22010. * @public
  22011. * @since 5.8.004 (2010-08-17)
  22012. */
  22013. public function getFontFamilyName($fontfamily)
  22014. {
  22015. // remove spaces and symbols
  22016. $fontfamily = preg_replace('/[^a-z0-9_\,]/', '', strtolower($fontfamily));
  22017. // extract all font names
  22018. $fontslist = preg_split('/[,]/', $fontfamily);
  22019. // find first valid font name
  22020. foreach ($fontslist as $font) {
  22021. // replace font variations
  22022. $font = preg_replace('/regular$/', '', $font);
  22023. $font = preg_replace('/italic$/', 'I', $font);
  22024. $font = preg_replace('/oblique$/', 'I', $font);
  22025. $font = preg_replace('/bold([I]?)$/', 'B\\1', $font);
  22026. // replace common family names and core fonts
  22027. $pattern = array();
  22028. $replacement = array();
  22029. $pattern[] = '/^serif|^cursive|^fantasy|^timesnewroman/';
  22030. $replacement[] = 'times';
  22031. $pattern[] = '/^sansserif/';
  22032. $replacement[] = 'helvetica';
  22033. $pattern[] = '/^monospace/';
  22034. $replacement[] = 'courier';
  22035. $font = preg_replace($pattern, $replacement, $font);
  22036. if (in_array(strtolower($font), $this->fontlist) OR in_array($font, $this->fontkeys)) {
  22037. return $font;
  22038. }
  22039. }
  22040. // return current font as default
  22041. return $this->CurrentFont['fontkey'];
  22042. }
  22043. /**
  22044. * Start a new XObject Template.
  22045. * 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).
  22046. * 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.
  22047. * Note: X,Y coordinates will be reset to 0,0.
  22048. * @param $w (int) Template width in user units (empty string or zero = page width less margins).
  22049. * @param $h (int) Template height in user units (empty string or zero = page height less margins).
  22050. * @param $group (mixed) Set transparency group. Can be a boolean value or an array specifying optional parameters: 'CS' (solour space name), 'I' (boolean flag to indicate isolated group) and 'K' (boolean flag to indicate knockout group).
  22051. * @return int the XObject Template ID in case of success or false in case of error.
  22052. * @author Nicola Asuni
  22053. * @public
  22054. * @since 5.8.017 (2010-08-24)
  22055. * @see endTemplate(), printTemplate()
  22056. */
  22057. public function startTemplate($w = 0, $h = 0, $group = false)
  22058. {
  22059. if ($this->inxobj) {
  22060. // we are already inside an XObject template
  22061. return false;
  22062. }
  22063. $this->inxobj = true;
  22064. ++$this->n;
  22065. // XObject ID
  22066. $this->xobjid = 'XT'.$this->n;
  22067. // object ID
  22068. $this->xobjects[$this->xobjid] = array('n' => $this->n);
  22069. // store current graphic state
  22070. $this->xobjects[$this->xobjid]['gvars'] = $this->getGraphicVars();
  22071. // initialize data
  22072. $this->xobjects[$this->xobjid]['intmrk'] = 0;
  22073. $this->xobjects[$this->xobjid]['transfmrk'] = array();
  22074. $this->xobjects[$this->xobjid]['outdata'] = '';
  22075. $this->xobjects[$this->xobjid]['xobjects'] = array();
  22076. $this->xobjects[$this->xobjid]['images'] = array();
  22077. $this->xobjects[$this->xobjid]['fonts'] = array();
  22078. $this->xobjects[$this->xobjid]['annotations'] = array();
  22079. $this->xobjects[$this->xobjid]['extgstates'] = array();
  22080. $this->xobjects[$this->xobjid]['gradients'] = array();
  22081. $this->xobjects[$this->xobjid]['spot_colors'] = array();
  22082. // set new environment
  22083. $this->num_columns = 1;
  22084. $this->current_column = 0;
  22085. $this->SetAutoPageBreak(false);
  22086. if (($w === '') OR ($w <= 0)) {
  22087. $w = $this->w - $this->lMargin - $this->rMargin;
  22088. }
  22089. if (($h === '') OR ($h <= 0)) {
  22090. $h = $this->h - $this->tMargin - $this->bMargin;
  22091. }
  22092. $this->xobjects[$this->xobjid]['x'] = 0;
  22093. $this->xobjects[$this->xobjid]['y'] = 0;
  22094. $this->xobjects[$this->xobjid]['w'] = $w;
  22095. $this->xobjects[$this->xobjid]['h'] = $h;
  22096. $this->w = $w;
  22097. $this->h = $h;
  22098. $this->wPt = $this->w * $this->k;
  22099. $this->hPt = $this->h * $this->k;
  22100. $this->fwPt = $this->wPt;
  22101. $this->fhPt = $this->hPt;
  22102. $this->x = 0;
  22103. $this->y = 0;
  22104. $this->lMargin = 0;
  22105. $this->rMargin = 0;
  22106. $this->tMargin = 0;
  22107. $this->bMargin = 0;
  22108. // set group mode
  22109. $this->xobjects[$this->xobjid]['group'] = $group;
  22110. return $this->xobjid;
  22111. }
  22112. /**
  22113. * End the current XObject Template started with startTemplate() and restore the previous graphic state.
  22114. * 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).
  22115. * 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.
  22116. * @return int the XObject Template ID in case of success or false in case of error.
  22117. * @author Nicola Asuni
  22118. * @public
  22119. * @since 5.8.017 (2010-08-24)
  22120. * @see startTemplate(), printTemplate()
  22121. */
  22122. public function endTemplate()
  22123. {
  22124. if (!$this->inxobj) {
  22125. // we are not inside a template
  22126. return false;
  22127. }
  22128. $this->inxobj = false;
  22129. // restore previous graphic state
  22130. $this->setGraphicVars($this->xobjects[$this->xobjid]['gvars'], true);
  22131. return $this->xobjid;
  22132. }
  22133. /**
  22134. * Print an XObject Template.
  22135. * You can print an XObject Template inside the currently opened Template.
  22136. * 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).
  22137. * 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.
  22138. * @param $id (string) The ID of XObject Template to print.
  22139. * @param $x (int) X position in user units (empty string = current x position)
  22140. * @param $y (int) Y position in user units (empty string = current y position)
  22141. * @param $w (int) Width in user units (zero = remaining page width)
  22142. * @param $h (int) Height in user units (zero = remaining page height)
  22143. * @param $align (string) Indicates the alignment of the pointer next to template insertion relative to template height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  22144. * @param $palign (string) Allows to center or align the template on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  22145. * @param $fitonpage (boolean) If true the template is resized to not exceed page dimensions.
  22146. * @author Nicola Asuni
  22147. * @public
  22148. * @since 5.8.017 (2010-08-24)
  22149. * @see startTemplate(), endTemplate()
  22150. */
  22151. public function printTemplate($id, $x = '', $y = '', $w = 0, $h = 0, $align = '', $palign = '', $fitonpage = false)
  22152. {
  22153. if ($this->state != 2) {
  22154. return;
  22155. }
  22156. if (!isset($this->xobjects[$id])) {
  22157. $this->Error('The XObject Template \''.$id.'\' doesn\'t exist!');
  22158. }
  22159. if ($this->inxobj) {
  22160. if ($id == $this->xobjid) {
  22161. // close current template
  22162. $this->endTemplate();
  22163. } else {
  22164. // use the template as resource for the template currently opened
  22165. $this->xobjects[$this->xobjid]['xobjects'][$id] = $this->xobjects[$id];
  22166. }
  22167. }
  22168. // set default values
  22169. if ($x === '') {
  22170. $x = $this->x;
  22171. }
  22172. if ($y === '') {
  22173. $y = $this->y;
  22174. }
  22175. // check page for no-write regions and adapt page margins if necessary
  22176. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  22177. $ow = $this->xobjects[$id]['w'];
  22178. if ($ow <= 0) {
  22179. $ow = 1;
  22180. }
  22181. $oh = $this->xobjects[$id]['h'];
  22182. if ($oh <= 0) {
  22183. $oh = 1;
  22184. }
  22185. // calculate template width and height on document
  22186. if (($w <= 0) AND ($h <= 0)) {
  22187. $w = $ow;
  22188. $h = $oh;
  22189. } elseif ($w <= 0) {
  22190. $w = $h * $ow / $oh;
  22191. } elseif ($h <= 0) {
  22192. $h = $w * $oh / $ow;
  22193. }
  22194. // fit the template on available space
  22195. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  22196. // set page alignment
  22197. $rb_y = $y + $h;
  22198. // set alignment
  22199. if ($this->rtl) {
  22200. if ($palign == 'L') {
  22201. $xt = $this->lMargin;
  22202. } elseif ($palign == 'C') {
  22203. $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  22204. } elseif ($palign == 'R') {
  22205. $xt = $this->w - $this->rMargin - $w;
  22206. } else {
  22207. $xt = $x - $w;
  22208. }
  22209. $rb_x = $xt;
  22210. } else {
  22211. if ($palign == 'L') {
  22212. $xt = $this->lMargin;
  22213. } elseif ($palign == 'C') {
  22214. $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  22215. } elseif ($palign == 'R') {
  22216. $xt = $this->w - $this->rMargin - $w;
  22217. } else {
  22218. $xt = $x;
  22219. }
  22220. $rb_x = $xt + $w;
  22221. }
  22222. // print XObject Template + Transformation matrix
  22223. $this->StartTransform();
  22224. // translate and scale
  22225. $sx = ($w / $ow);
  22226. $sy = ($h / $oh);
  22227. $tm = array();
  22228. $tm[0] = $sx;
  22229. $tm[1] = 0;
  22230. $tm[2] = 0;
  22231. $tm[3] = $sy;
  22232. $tm[4] = $xt * $this->k;
  22233. $tm[5] = ($this->h - $h - $y) * $this->k;
  22234. $this->Transform($tm);
  22235. // set object
  22236. $this->_out('/'.$id.' Do');
  22237. $this->StopTransform();
  22238. // add annotations
  22239. if (!empty($this->xobjects[$id]['annotations'])) {
  22240. foreach ($this->xobjects[$id]['annotations'] as $annot) {
  22241. // transform original coordinates
  22242. $coordlt = TCPDF_STATIC::getTransformationMatrixProduct($tm, array(1, 0, 0, 1, ($annot['x'] * $this->k), (-$annot['y'] * $this->k)));
  22243. $ax = ($coordlt[4] / $this->k);
  22244. $ay = ($this->h - $h - ($coordlt[5] / $this->k));
  22245. $coordrb = TCPDF_STATIC::getTransformationMatrixProduct($tm, array(1, 0, 0, 1, (($annot['x'] + $annot['w']) * $this->k), ((-$annot['y'] - $annot['h']) * $this->k)));
  22246. $aw = ($coordrb[4] / $this->k) - $ax;
  22247. $ah = ($this->h - $h - ($coordrb[5] / $this->k)) - $ay;
  22248. $this->Annotation($ax, $ay, $aw, $ah, $annot['text'], $annot['opt'], $annot['spaces']);
  22249. }
  22250. }
  22251. // set pointer to align the next text/objects
  22252. switch ($align) {
  22253. case 'T': {
  22254. $this->y = $y;
  22255. $this->x = $rb_x;
  22256. break;
  22257. }
  22258. case 'M': {
  22259. $this->y = $y + round($h/2);
  22260. $this->x = $rb_x;
  22261. break;
  22262. }
  22263. case 'B': {
  22264. $this->y = $rb_y;
  22265. $this->x = $rb_x;
  22266. break;
  22267. }
  22268. case 'N': {
  22269. $this->SetY($rb_y);
  22270. break;
  22271. }
  22272. default:{
  22273. break;
  22274. }
  22275. }
  22276. }
  22277. /**
  22278. * Set the percentage of character stretching.
  22279. * @param $perc (int) percentage of stretching (100 = no stretching)
  22280. * @author Nicola Asuni
  22281. * @public
  22282. * @since 5.9.000 (2010-09-29)
  22283. */
  22284. public function setFontStretching($perc = 100)
  22285. {
  22286. $this->font_stretching = $perc;
  22287. }
  22288. /**
  22289. * Get the percentage of character stretching.
  22290. * @return float stretching value
  22291. * @author Nicola Asuni
  22292. * @public
  22293. * @since 5.9.000 (2010-09-29)
  22294. */
  22295. public function getFontStretching()
  22296. {
  22297. return $this->font_stretching;
  22298. }
  22299. /**
  22300. * Set the amount to increase or decrease the space between characters in a text.
  22301. * @param $spacing (float) amount to increase or decrease the space between characters in a text (0 = default spacing)
  22302. * @author Nicola Asuni
  22303. * @public
  22304. * @since 5.9.000 (2010-09-29)
  22305. */
  22306. public function setFontSpacing($spacing = 0)
  22307. {
  22308. $this->font_spacing = $spacing;
  22309. }
  22310. /**
  22311. * Get the amount to increase or decrease the space between characters in a text.
  22312. * @return int font spacing (tracking) value
  22313. * @author Nicola Asuni
  22314. * @public
  22315. * @since 5.9.000 (2010-09-29)
  22316. */
  22317. public function getFontSpacing()
  22318. {
  22319. return $this->font_spacing;
  22320. }
  22321. /**
  22322. * Return an array of no-write page regions
  22323. * @return array of no-write page regions
  22324. * @author Nicola Asuni
  22325. * @public
  22326. * @since 5.9.003 (2010-10-13)
  22327. * @see setPageRegions(), addPageRegion()
  22328. */
  22329. public function getPageRegions()
  22330. {
  22331. return $this->page_regions;
  22332. }
  22333. /**
  22334. * Set no-write regions on page.
  22335. * 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.
  22336. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  22337. * You can set multiple regions for the same page.
  22338. * @param $regions (array) array of no-write regions. For each region you can define an array as follow: ('page' => page number or empy for current page, 'xt' => X top, 'yt' => Y top, 'xb' => X bottom, 'yb' => Y bottom, 'side' => page side 'L' = left or 'R' = right). Omit this parameter to remove all regions.
  22339. * @author Nicola Asuni
  22340. * @public
  22341. * @since 5.9.003 (2010-10-13)
  22342. * @see addPageRegion(), getPageRegions()
  22343. */
  22344. public function setPageRegions($regions = array())
  22345. {
  22346. // empty current regions array
  22347. $this->page_regions = array();
  22348. // add regions
  22349. foreach ($regions as $data) {
  22350. $this->addPageRegion($data);
  22351. }
  22352. }
  22353. /**
  22354. * Add a single no-write region on selected page.
  22355. * 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.
  22356. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  22357. * You can set multiple regions for the same page.
  22358. * @param $region (array) array of a single no-write region array: ('page' => page number or empy for current page, 'xt' => X top, 'yt' => Y top, 'xb' => X bottom, 'yb' => Y bottom, 'side' => page side 'L' = left or 'R' = right).
  22359. * @author Nicola Asuni
  22360. * @public
  22361. * @since 5.9.003 (2010-10-13)
  22362. * @see setPageRegions(), getPageRegions()
  22363. */
  22364. public function addPageRegion($region)
  22365. {
  22366. if (!isset($region['page']) OR empty($region['page'])) {
  22367. $region['page'] = $this->page;
  22368. }
  22369. if (isset($region['xt']) AND isset($region['xb']) AND ($region['xt'] > 0) AND ($region['xb'] > 0)
  22370. AND isset($region['yt']) AND isset($region['yb']) AND ($region['yt'] >= 0) AND ($region['yt'] < $region['yb'])
  22371. AND isset($region['side']) AND (($region['side'] == 'L') OR ($region['side'] == 'R'))) {
  22372. $this->page_regions[] = $region;
  22373. }
  22374. }
  22375. /**
  22376. * Remove a single no-write region.
  22377. * @param $key (int) region key
  22378. * @author Nicola Asuni
  22379. * @public
  22380. * @since 5.9.003 (2010-10-13)
  22381. * @see setPageRegions(), getPageRegions()
  22382. */
  22383. public function removePageRegion($key)
  22384. {
  22385. if (isset($this->page_regions[$key])) {
  22386. unset($this->page_regions[$key]);
  22387. }
  22388. }
  22389. /**
  22390. * Check page for no-write regions and adapt current coordinates and page margins if necessary.
  22391. * 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.
  22392. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  22393. * @param $h (float) height of the text/image/object to print in user units
  22394. * @param $x (float) current X coordinate in user units
  22395. * @param $y (float) current Y coordinate in user units
  22396. * @return array($x, $y)
  22397. * @author Nicola Asuni
  22398. * @protected
  22399. * @since 5.9.003 (2010-10-13)
  22400. */
  22401. protected function checkPageRegions($h, $x, $y)
  22402. {
  22403. // set default values
  22404. if ($x === '') {
  22405. $x = $this->x;
  22406. }
  22407. if ($y === '') {
  22408. $y = $this->y;
  22409. }
  22410. if (!$this->check_page_regions OR empty($this->page_regions)) {
  22411. // no page regions defined
  22412. return array($x, $y);
  22413. }
  22414. if (empty($h)) {
  22415. $h = $this->getCellHeight($this->FontSize);
  22416. }
  22417. // check for page break
  22418. if ($this->checkPageBreak($h, $y)) {
  22419. // the content will be printed on a new page
  22420. $x = $this->x;
  22421. $y = $this->y;
  22422. }
  22423. if ($this->num_columns > 1) {
  22424. if ($this->rtl) {
  22425. $this->lMargin = ($this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']);
  22426. } else {
  22427. $this->rMargin = ($this->w - $this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']);
  22428. }
  22429. } else {
  22430. if ($this->rtl) {
  22431. $this->lMargin = max($this->clMargin, $this->original_lMargin);
  22432. } else {
  22433. $this->rMargin = max($this->crMargin, $this->original_rMargin);
  22434. }
  22435. }
  22436. // adjust coordinates and page margins
  22437. foreach ($this->page_regions as $regid => $regdata) {
  22438. if ($regdata['page'] == $this->page) {
  22439. // check region boundaries
  22440. if (($y > ($regdata['yt'] - $h)) AND ($y <= $regdata['yb'])) {
  22441. // Y is inside the region
  22442. $minv = ($regdata['xb'] - $regdata['xt']) / ($regdata['yb'] - $regdata['yt']); // inverse of angular coefficient
  22443. $yt = max($y, $regdata['yt']);
  22444. $yb = min(($yt + $h), $regdata['yb']);
  22445. $xt = (($yt - $regdata['yt']) * $minv) + $regdata['xt'];
  22446. $xb = (($yb - $regdata['yt']) * $minv) + $regdata['xt'];
  22447. if ($regdata['side'] == 'L') { // left side
  22448. $new_margin = max($xt, $xb);
  22449. if ($this->lMargin < $new_margin) {
  22450. if ($this->rtl) {
  22451. // adjust left page margin
  22452. $this->lMargin = max(0, $new_margin);
  22453. }
  22454. if ($x < $new_margin) {
  22455. // adjust x position
  22456. $x = $new_margin;
  22457. if ($new_margin > ($this->w - $this->rMargin)) {
  22458. // adjust y position
  22459. $y = $regdata['yb'] - $h;
  22460. }
  22461. }
  22462. }
  22463. } elseif ($regdata['side'] == 'R') { // right side
  22464. $new_margin = min($xt, $xb);
  22465. if (($this->w - $this->rMargin) > $new_margin) {
  22466. if (!$this->rtl) {
  22467. // adjust right page margin
  22468. $this->rMargin = max(0, ($this->w - $new_margin));
  22469. }
  22470. if ($x > $new_margin) {
  22471. // adjust x position
  22472. $x = $new_margin;
  22473. if ($new_margin > $this->lMargin) {
  22474. // adjust y position
  22475. $y = $regdata['yb'] - $h;
  22476. }
  22477. }
  22478. }
  22479. }
  22480. }
  22481. }
  22482. }
  22483. return array($x, $y);
  22484. }
  22485. // --- SVG METHODS ---------------------------------------------------------
  22486. /**
  22487. * Embedd a Scalable Vector Graphics (SVG) image.
  22488. * NOTE: SVG standard is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  22489. * @param $file (string) Name of the SVG file or a '@' character followed by the SVG data string.
  22490. * @param $x (float) Abscissa of the upper-left corner.
  22491. * @param $y (float) Ordinate of the upper-left corner.
  22492. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  22493. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  22494. * @param $link (mixed) URL or identifier returned by AddLink().
  22495. * @param $align (string) Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul> If the alignment is an empty string, then the pointer will be restored on the starting SVG position.
  22496. * @param $palign (string) Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  22497. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  22498. * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
  22499. * @author Nicola Asuni
  22500. * @since 5.0.000 (2010-05-02)
  22501. * @public
  22502. */
  22503. public function ImageSVG($file, $x = '', $y = '', $w = 0, $h = 0, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false)
  22504. {
  22505. if ($this->state != 2) {
  22506. return;
  22507. }
  22508. // reset SVG vars
  22509. $this->svggradients = array();
  22510. $this->svggradientid = 0;
  22511. $this->svgdefsmode = false;
  22512. $this->svgdefs = array();
  22513. $this->svgclipmode = false;
  22514. $this->svgclippaths = array();
  22515. $this->svgcliptm = array();
  22516. $this->svgclipid = 0;
  22517. $this->svgtext = '';
  22518. $this->svgtextmode = array();
  22519. if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
  22520. // convert SVG to raster image using GD or ImageMagick libraries
  22521. return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
  22522. }
  22523. if ($file[0] === '@') { // image from string
  22524. $this->svgdir = '';
  22525. $svgdata = substr($file, 1);
  22526. } else { // SVG file
  22527. $this->svgdir = dirname($file);
  22528. $svgdata = TCPDF_STATIC::fileGetContents($file);
  22529. }
  22530. if ($svgdata === false) {
  22531. $this->Error('SVG file not found: '.$file);
  22532. }
  22533. if ($x === '') {
  22534. $x = $this->x;
  22535. }
  22536. if ($y === '') {
  22537. $y = $this->y;
  22538. }
  22539. // check page for no-write regions and adapt page margins if necessary
  22540. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  22541. $k = $this->k;
  22542. $ox = 0;
  22543. $oy = 0;
  22544. $ow = $w;
  22545. $oh = $h;
  22546. $aspect_ratio_align = 'xMidYMid';
  22547. $aspect_ratio_ms = 'meet';
  22548. $regs = array();
  22549. // get original image width and height
  22550. preg_match('/<svg([^\>]*)>/si', $svgdata, $regs);
  22551. if (isset($regs[1]) AND !empty($regs[1])) {
  22552. $tmp = array();
  22553. if (preg_match('/[\s]+x[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22554. $ox = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
  22555. }
  22556. $tmp = array();
  22557. if (preg_match('/[\s]+y[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22558. $oy = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
  22559. }
  22560. $tmp = array();
  22561. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22562. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  22563. }
  22564. $tmp = array();
  22565. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22566. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  22567. }
  22568. $tmp = array();
  22569. $view_box = array();
  22570. if (preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.\-]+)[\s]+([0-9\.\-]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $regs[1], $tmp)) {
  22571. if (count($tmp) == 5) {
  22572. array_shift($tmp);
  22573. foreach ($tmp as $key => $val) {
  22574. $view_box[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
  22575. }
  22576. $ox = $view_box[0];
  22577. $oy = $view_box[1];
  22578. }
  22579. // get aspect ratio
  22580. $tmp = array();
  22581. if (preg_match('/[\s]+preserveAspectRatio[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  22582. $aspect_ratio = preg_split('/[\s]+/si', $tmp[1]);
  22583. switch (count($aspect_ratio)) {
  22584. case 3: {
  22585. $aspect_ratio_align = $aspect_ratio[1];
  22586. $aspect_ratio_ms = $aspect_ratio[2];
  22587. break;
  22588. }
  22589. case 2: {
  22590. $aspect_ratio_align = $aspect_ratio[0];
  22591. $aspect_ratio_ms = $aspect_ratio[1];
  22592. break;
  22593. }
  22594. case 1: {
  22595. $aspect_ratio_align = $aspect_ratio[0];
  22596. $aspect_ratio_ms = 'meet';
  22597. break;
  22598. }
  22599. }
  22600. }
  22601. }
  22602. }
  22603. if ($ow <= 0) {
  22604. $ow = 1;
  22605. }
  22606. if ($oh <= 0) {
  22607. $oh = 1;
  22608. }
  22609. // calculate image width and height on document
  22610. if (($w <= 0) AND ($h <= 0)) {
  22611. // convert image size to document unit
  22612. $w = $ow;
  22613. $h = $oh;
  22614. } elseif ($w <= 0) {
  22615. $w = $h * $ow / $oh;
  22616. } elseif ($h <= 0) {
  22617. $h = $w * $oh / $ow;
  22618. }
  22619. // fit the image on available space
  22620. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  22621. if ($this->rasterize_vector_images) {
  22622. // convert SVG to raster image using GD or ImageMagick libraries
  22623. return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
  22624. }
  22625. // set alignment
  22626. $this->img_rb_y = $y + $h;
  22627. // set alignment
  22628. if ($this->rtl) {
  22629. if ($palign == 'L') {
  22630. $ximg = $this->lMargin;
  22631. } elseif ($palign == 'C') {
  22632. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  22633. } elseif ($palign == 'R') {
  22634. $ximg = $this->w - $this->rMargin - $w;
  22635. } else {
  22636. $ximg = $x - $w;
  22637. }
  22638. $this->img_rb_x = $ximg;
  22639. } else {
  22640. if ($palign == 'L') {
  22641. $ximg = $this->lMargin;
  22642. } elseif ($palign == 'C') {
  22643. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  22644. } elseif ($palign == 'R') {
  22645. $ximg = $this->w - $this->rMargin - $w;
  22646. } else {
  22647. $ximg = $x;
  22648. }
  22649. $this->img_rb_x = $ximg + $w;
  22650. }
  22651. // store current graphic vars
  22652. $gvars = $this->getGraphicVars();
  22653. // store SVG position and scale factors
  22654. $svgoffset_x = ($ximg - $ox) * $this->k;
  22655. $svgoffset_y = -($y - $oy) * $this->k;
  22656. if (isset($view_box[2]) AND ($view_box[2] > 0) AND ($view_box[3] > 0)) {
  22657. $ow = $view_box[2];
  22658. $oh = $view_box[3];
  22659. } else {
  22660. if ($ow <= 0) {
  22661. $ow = $w;
  22662. }
  22663. if ($oh <= 0) {
  22664. $oh = $h;
  22665. }
  22666. }
  22667. $svgscale_x = $w / $ow;
  22668. $svgscale_y = $h / $oh;
  22669. // scaling and alignment
  22670. if ($aspect_ratio_align != 'none') {
  22671. // store current scaling values
  22672. $svgscale_old_x = $svgscale_x;
  22673. $svgscale_old_y = $svgscale_y;
  22674. // force uniform scaling
  22675. if ($aspect_ratio_ms == 'slice') {
  22676. // the entire viewport is covered by the viewBox
  22677. if ($svgscale_x > $svgscale_y) {
  22678. $svgscale_y = $svgscale_x;
  22679. } elseif ($svgscale_x < $svgscale_y) {
  22680. $svgscale_x = $svgscale_y;
  22681. }
  22682. } else { // meet
  22683. // the entire viewBox is visible within the viewport
  22684. if ($svgscale_x < $svgscale_y) {
  22685. $svgscale_y = $svgscale_x;
  22686. } elseif ($svgscale_x > $svgscale_y) {
  22687. $svgscale_x = $svgscale_y;
  22688. }
  22689. }
  22690. // correct X alignment
  22691. switch (substr($aspect_ratio_align, 1, 3)) {
  22692. case 'Min': {
  22693. // do nothing
  22694. break;
  22695. }
  22696. case 'Max': {
  22697. $svgoffset_x += (($w * $this->k) - ($ow * $this->k * $svgscale_x));
  22698. break;
  22699. }
  22700. default:
  22701. case 'Mid': {
  22702. $svgoffset_x += ((($w * $this->k) - ($ow * $this->k * $svgscale_x)) / 2);
  22703. break;
  22704. }
  22705. }
  22706. // correct Y alignment
  22707. switch (substr($aspect_ratio_align, 5)) {
  22708. case 'Min': {
  22709. // do nothing
  22710. break;
  22711. }
  22712. case 'Max': {
  22713. $svgoffset_y -= (($h * $this->k) - ($oh * $this->k * $svgscale_y));
  22714. break;
  22715. }
  22716. default:
  22717. case 'Mid': {
  22718. $svgoffset_y -= ((($h * $this->k) - ($oh * $this->k * $svgscale_y)) / 2);
  22719. break;
  22720. }
  22721. }
  22722. }
  22723. // store current page break mode
  22724. $page_break_mode = $this->AutoPageBreak;
  22725. $page_break_margin = $this->getBreakMargin();
  22726. $cell_padding = $this->cell_padding;
  22727. $this->SetCellPadding(0);
  22728. $this->SetAutoPageBreak(false);
  22729. // save the current graphic state
  22730. $this->_out('q'.$this->epsmarker);
  22731. // set initial clipping mask
  22732. $this->Rect($ximg, $y, $w, $h, 'CNZ', array(), array());
  22733. // scale and translate
  22734. $e = $ox * $this->k * (1 - $svgscale_x);
  22735. $f = ($this->h - $oy) * $this->k * (1 - $svgscale_y);
  22736. $this->_out(sprintf('%F %F %F %F %F %F cm', $svgscale_x, 0, 0, $svgscale_y, ($e + $svgoffset_x), ($f + $svgoffset_y)));
  22737. // creates a new XML parser to be used by the other XML functions
  22738. $this->parser = xml_parser_create('UTF-8');
  22739. // the following function allows to use parser inside object
  22740. xml_set_object($this->parser, $this);
  22741. // disable case-folding for this XML parser
  22742. xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
  22743. // sets the element handler functions for the XML parser
  22744. xml_set_element_handler($this->parser, 'startSVGElementHandler', 'endSVGElementHandler');
  22745. // sets the character data handler function for the XML parser
  22746. xml_set_character_data_handler($this->parser, 'segSVGContentHandler');
  22747. // start parsing an XML document
  22748. if (!xml_parse($this->parser, $svgdata)) {
  22749. $error_message = sprintf('SVG Error: %s at line %d', xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser));
  22750. $this->Error($error_message);
  22751. }
  22752. // free this XML parser
  22753. xml_parser_free($this->parser);
  22754. // restore previous graphic state
  22755. $this->_out($this->epsmarker.'Q');
  22756. // restore graphic vars
  22757. $this->setGraphicVars($gvars);
  22758. $this->lasth = $gvars['lasth'];
  22759. if (!empty($border)) {
  22760. $bx = $this->x;
  22761. $by = $this->y;
  22762. $this->x = $ximg;
  22763. if ($this->rtl) {
  22764. $this->x += $w;
  22765. }
  22766. $this->y = $y;
  22767. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  22768. $this->x = $bx;
  22769. $this->y = $by;
  22770. }
  22771. if ($link) {
  22772. $this->Link($ximg, $y, $w, $h, $link, 0);
  22773. }
  22774. // set pointer to align the next text/objects
  22775. switch ($align) {
  22776. case 'T':{
  22777. $this->y = $y;
  22778. $this->x = $this->img_rb_x;
  22779. break;
  22780. }
  22781. case 'M':{
  22782. $this->y = $y + round($h/2);
  22783. $this->x = $this->img_rb_x;
  22784. break;
  22785. }
  22786. case 'B':{
  22787. $this->y = $this->img_rb_y;
  22788. $this->x = $this->img_rb_x;
  22789. break;
  22790. }
  22791. case 'N':{
  22792. $this->SetY($this->img_rb_y);
  22793. break;
  22794. }
  22795. default:{
  22796. // restore pointer to starting position
  22797. $this->x = $gvars['x'];
  22798. $this->y = $gvars['y'];
  22799. $this->page = $gvars['page'];
  22800. $this->current_column = $gvars['current_column'];
  22801. $this->tMargin = $gvars['tMargin'];
  22802. $this->bMargin = $gvars['bMargin'];
  22803. $this->w = $gvars['w'];
  22804. $this->h = $gvars['h'];
  22805. $this->wPt = $gvars['wPt'];
  22806. $this->hPt = $gvars['hPt'];
  22807. $this->fwPt = $gvars['fwPt'];
  22808. $this->fhPt = $gvars['fhPt'];
  22809. break;
  22810. }
  22811. }
  22812. $this->endlinex = $this->img_rb_x;
  22813. // restore page break
  22814. $this->SetAutoPageBreak($page_break_mode, $page_break_margin);
  22815. $this->cell_padding = $cell_padding;
  22816. }
  22817. /**
  22818. * Convert SVG transformation matrix to PDF.
  22819. * @param $tm (array) original SVG transformation matrix
  22820. * @return array transformation matrix
  22821. * @protected
  22822. * @since 5.0.000 (2010-05-02)
  22823. */
  22824. protected function convertSVGtMatrix($tm)
  22825. {
  22826. $a = $tm[0];
  22827. $b = -$tm[1];
  22828. $c = -$tm[2];
  22829. $d = $tm[3];
  22830. $e = $this->getHTMLUnitToUnits($tm[4], 1, $this->svgunit, false) * $this->k;
  22831. $f = -$this->getHTMLUnitToUnits($tm[5], 1, $this->svgunit, false) * $this->k;
  22832. $x = 0;
  22833. $y = $this->h * $this->k;
  22834. $e = ($x * (1 - $a)) - ($y * $c) + $e;
  22835. $f = ($y * (1 - $d)) - ($x * $b) + $f;
  22836. return array($a, $b, $c, $d, $e, $f);
  22837. }
  22838. /**
  22839. * Apply SVG graphic transformation matrix.
  22840. * @param $tm (array) original SVG transformation matrix
  22841. * @protected
  22842. * @since 5.0.000 (2010-05-02)
  22843. */
  22844. protected function SVGTransform($tm)
  22845. {
  22846. $this->Transform($this->convertSVGtMatrix($tm));
  22847. }
  22848. /**
  22849. * Apply the requested SVG styles (*** TO BE COMPLETED ***)
  22850. * @param $svgstyle (array) array of SVG styles to apply
  22851. * @param $prevsvgstyle (array) array of previous SVG style
  22852. * @param $x (int) X origin of the bounding box
  22853. * @param $y (int) Y origin of the bounding box
  22854. * @param $w (int) width of the bounding box
  22855. * @param $h (int) height of the bounding box
  22856. * @param $clip_function (string) clip function
  22857. * @param $clip_params (array) array of parameters for clipping function
  22858. * @return object style
  22859. * @author Nicola Asuni
  22860. * @since 5.0.000 (2010-05-02)
  22861. * @protected
  22862. */
  22863. protected function setSVGStyles($svgstyle, $prevsvgstyle, $x = 0, $y = 0, $w = 1, $h = 1, $clip_function = '', $clip_params = array())
  22864. {
  22865. if ($this->state != 2) {
  22866. return;
  22867. }
  22868. $objstyle = '';
  22869. $minlen = (0.01 / $this->k); // minimum acceptable length
  22870. if (!isset($svgstyle['opacity'])) {
  22871. return $objstyle;
  22872. }
  22873. // clip-path
  22874. $regs = array();
  22875. if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['clip-path'], $regs)) {
  22876. $clip_path = $this->svgclippaths[$regs[1]];
  22877. foreach ($clip_path as $cp) {
  22878. $this->startSVGElementHandler('clip-path', $cp['name'], $cp['attribs'], $cp['tm']);
  22879. }
  22880. }
  22881. // opacity
  22882. if ($svgstyle['opacity'] != 1) {
  22883. $this->setAlpha($svgstyle['opacity'], 'Normal', $svgstyle['opacity'], false);
  22884. }
  22885. // color
  22886. $fill_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['color'], $this->spot_colors);
  22887. $this->SetFillColorArray($fill_color);
  22888. // text color
  22889. $text_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['text-color'], $this->spot_colors);
  22890. $this->SetTextColorArray($text_color);
  22891. // clip
  22892. if (preg_match('/rect\(([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)\)/si', $svgstyle['clip'], $regs)) {
  22893. $top = (isset($regs[1])?$this->getHTMLUnitToUnits($regs[1], 0, $this->svgunit, false):0);
  22894. $right = (isset($regs[2])?$this->getHTMLUnitToUnits($regs[2], 0, $this->svgunit, false):0);
  22895. $bottom = (isset($regs[3])?$this->getHTMLUnitToUnits($regs[3], 0, $this->svgunit, false):0);
  22896. $left = (isset($regs[4])?$this->getHTMLUnitToUnits($regs[4], 0, $this->svgunit, false):0);
  22897. $cx = $x + $left;
  22898. $cy = $y + $top;
  22899. $cw = $w - $left - $right;
  22900. $ch = $h - $top - $bottom;
  22901. if ($svgstyle['clip-rule'] == 'evenodd') {
  22902. $clip_rule = 'CNZ';
  22903. } else {
  22904. $clip_rule = 'CEO';
  22905. }
  22906. $this->Rect($cx, $cy, $cw, $ch, $clip_rule, array(), array());
  22907. }
  22908. // fill
  22909. $regs = array();
  22910. if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['fill'], $regs)) {
  22911. // gradient
  22912. $gradient = $this->svggradients[$regs[1]];
  22913. if (isset($gradient['xref'])) {
  22914. // reference to another gradient definition
  22915. $newgradient = $this->svggradients[$gradient['xref']];
  22916. $newgradient['coords'] = $gradient['coords'];
  22917. $newgradient['mode'] = $gradient['mode'];
  22918. $newgradient['type'] = $gradient['type'];
  22919. $newgradient['gradientUnits'] = $gradient['gradientUnits'];
  22920. if (isset($gradient['gradientTransform'])) {
  22921. $newgradient['gradientTransform'] = $gradient['gradientTransform'];
  22922. }
  22923. $gradient = $newgradient;
  22924. }
  22925. //save current Graphic State
  22926. $this->_outSaveGraphicsState();
  22927. //set clipping area
  22928. if (!empty($clip_function) AND method_exists($this, $clip_function)) {
  22929. $bbox = call_user_func_array(array($this, $clip_function), $clip_params);
  22930. if ((!isset($gradient['type']) OR ($gradient['type'] != 3)) AND is_array($bbox) AND (count($bbox) == 4)) {
  22931. list($x, $y, $w, $h) = $bbox;
  22932. }
  22933. }
  22934. if ($gradient['mode'] == 'measure') {
  22935. if (!isset($gradient['coords'][4])) {
  22936. $gradient['coords'][4] = 0.5;
  22937. }
  22938. if (isset($gradient['gradientTransform']) AND !empty($gradient['gradientTransform'])) {
  22939. $gtm = $gradient['gradientTransform'];
  22940. // apply transformation matrix
  22941. $xa = ($gtm[0] * $gradient['coords'][0]) + ($gtm[2] * $gradient['coords'][1]) + $gtm[4];
  22942. $ya = ($gtm[1] * $gradient['coords'][0]) + ($gtm[3] * $gradient['coords'][1]) + $gtm[5];
  22943. $xb = ($gtm[0] * $gradient['coords'][2]) + ($gtm[2] * $gradient['coords'][3]) + $gtm[4];
  22944. $yb = ($gtm[1] * $gradient['coords'][2]) + ($gtm[3] * $gradient['coords'][3]) + $gtm[5];
  22945. $r = sqrt(pow(($gtm[0] * $gradient['coords'][4]), 2) + pow(($gtm[1] * $gradient['coords'][4]), 2));
  22946. $gradient['coords'][0] = $xa;
  22947. $gradient['coords'][1] = $ya;
  22948. $gradient['coords'][2] = $xb;
  22949. $gradient['coords'][3] = $yb;
  22950. $gradient['coords'][4] = $r;
  22951. }
  22952. // convert SVG coordinates to user units
  22953. $gradient['coords'][0] = $this->getHTMLUnitToUnits($gradient['coords'][0], 0, $this->svgunit, false);
  22954. $gradient['coords'][1] = $this->getHTMLUnitToUnits($gradient['coords'][1], 0, $this->svgunit, false);
  22955. $gradient['coords'][2] = $this->getHTMLUnitToUnits($gradient['coords'][2], 0, $this->svgunit, false);
  22956. $gradient['coords'][3] = $this->getHTMLUnitToUnits($gradient['coords'][3], 0, $this->svgunit, false);
  22957. $gradient['coords'][4] = $this->getHTMLUnitToUnits($gradient['coords'][4], 0, $this->svgunit, false);
  22958. if ($w <= $minlen) {
  22959. $w = $minlen;
  22960. }
  22961. if ($h <= $minlen) {
  22962. $h = $minlen;
  22963. }
  22964. // shift units
  22965. if ($gradient['gradientUnits'] == 'objectBoundingBox') {
  22966. // convert to SVG coordinate system
  22967. $gradient['coords'][0] += $x;
  22968. $gradient['coords'][1] += $y;
  22969. $gradient['coords'][2] += $x;
  22970. $gradient['coords'][3] += $y;
  22971. }
  22972. // calculate percentages
  22973. $gradient['coords'][0] = (($gradient['coords'][0] - $x) / $w);
  22974. $gradient['coords'][1] = (($gradient['coords'][1] - $y) / $h);
  22975. $gradient['coords'][2] = (($gradient['coords'][2] - $x) / $w);
  22976. $gradient['coords'][3] = (($gradient['coords'][3] - $y) / $h);
  22977. $gradient['coords'][4] /= $w;
  22978. } elseif ($gradient['mode'] == 'percentage') {
  22979. foreach ($gradient['coords'] as $key => $val) {
  22980. $gradient['coords'][$key] = (intval($val) / 100);
  22981. if ($val < 0) {
  22982. $gradient['coords'][$key] = 0;
  22983. } elseif ($val > 1) {
  22984. $gradient['coords'][$key] = 1;
  22985. }
  22986. }
  22987. }
  22988. if (($gradient['type'] == 2) AND ($gradient['coords'][0] == $gradient['coords'][2]) AND ($gradient['coords'][1] == $gradient['coords'][3])) {
  22989. // single color (no shading)
  22990. $gradient['coords'][0] = 1;
  22991. $gradient['coords'][1] = 0;
  22992. $gradient['coords'][2] = 0.999;
  22993. $gradient['coords'][3] = 0;
  22994. }
  22995. // swap Y coordinates
  22996. $tmp = $gradient['coords'][1];
  22997. $gradient['coords'][1] = $gradient['coords'][3];
  22998. $gradient['coords'][3] = $tmp;
  22999. // set transformation map for gradient
  23000. $cy = ($this->h - $y);
  23001. if ($gradient['type'] == 3) {
  23002. // circular gradient
  23003. $cy -= ($gradient['coords'][1] * ($w + $h));
  23004. $h = $w = max($w, $h);
  23005. } else {
  23006. $cy -= $h;
  23007. }
  23008. $this->_out(sprintf('%F 0 0 %F %F %F cm', ($w * $this->k), ($h * $this->k), ($x * $this->k), ($cy * $this->k)));
  23009. if (count($gradient['stops']) > 1) {
  23010. $this->Gradient($gradient['type'], $gradient['coords'], $gradient['stops'], array(), false);
  23011. }
  23012. } elseif ($svgstyle['fill'] != 'none') {
  23013. $fill_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['fill'], $this->spot_colors);
  23014. if ($svgstyle['fill-opacity'] != 1) {
  23015. $this->setAlpha($this->alpha['CA'], 'Normal', $svgstyle['fill-opacity'], false);
  23016. }
  23017. $this->SetFillColorArray($fill_color);
  23018. if ($svgstyle['fill-rule'] == 'evenodd') {
  23019. $objstyle .= 'F*';
  23020. } else {
  23021. $objstyle .= 'F';
  23022. }
  23023. }
  23024. // stroke
  23025. if ($svgstyle['stroke'] != 'none') {
  23026. if ($svgstyle['stroke-opacity'] != 1) {
  23027. $this->setAlpha($svgstyle['stroke-opacity'], 'Normal', $this->alpha['ca'], false);
  23028. } elseif (preg_match('/rgba\(\d+%?,\s*\d+%?,\s*\d+%?,\s*(\d+(?:\.\d+)?)\)/i', $svgstyle['stroke'], $rgba_matches)) {
  23029. $this->setAlpha($rgba_matches[1], 'Normal', $this->alpha['ca'], false);
  23030. }
  23031. $stroke_style = array(
  23032. 'color' => TCPDF_COLORS::convertHTMLColorToDec($svgstyle['stroke'], $this->spot_colors),
  23033. 'width' => $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false),
  23034. 'cap' => $svgstyle['stroke-linecap'],
  23035. 'join' => $svgstyle['stroke-linejoin']
  23036. );
  23037. if (isset($svgstyle['stroke-dasharray']) AND !empty($svgstyle['stroke-dasharray']) AND ($svgstyle['stroke-dasharray'] != 'none')) {
  23038. $stroke_style['dash'] = $svgstyle['stroke-dasharray'];
  23039. }
  23040. $this->SetLineStyle($stroke_style);
  23041. $objstyle .= 'D';
  23042. }
  23043. // font
  23044. $regs = array();
  23045. if (!empty($svgstyle['font'])) {
  23046. if (preg_match('/font-family[\s]*:[\s]*([^\;\"]*)/si', $svgstyle['font'], $regs)) {
  23047. $font_family = $this->getFontFamilyName($regs[1]);
  23048. } else {
  23049. $font_family = $svgstyle['font-family'];
  23050. }
  23051. if (preg_match('/font-size[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  23052. $font_size = trim($regs[1]);
  23053. } else {
  23054. $font_size = $svgstyle['font-size'];
  23055. }
  23056. if (preg_match('/font-style[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  23057. $font_style = trim($regs[1]);
  23058. } else {
  23059. $font_style = $svgstyle['font-style'];
  23060. }
  23061. if (preg_match('/font-weight[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  23062. $font_weight = trim($regs[1]);
  23063. } else {
  23064. $font_weight = $svgstyle['font-weight'];
  23065. }
  23066. if (preg_match('/font-stretch[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  23067. $font_stretch = trim($regs[1]);
  23068. } else {
  23069. $font_stretch = $svgstyle['font-stretch'];
  23070. }
  23071. if (preg_match('/letter-spacing[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  23072. $font_spacing = trim($regs[1]);
  23073. } else {
  23074. $font_spacing = $svgstyle['letter-spacing'];
  23075. }
  23076. } else {
  23077. $font_family = $this->getFontFamilyName($svgstyle['font-family']);
  23078. $font_size = $svgstyle['font-size'];
  23079. $font_style = $svgstyle['font-style'];
  23080. $font_weight = $svgstyle['font-weight'];
  23081. $font_stretch = $svgstyle['font-stretch'];
  23082. $font_spacing = $svgstyle['letter-spacing'];
  23083. }
  23084. $font_size = $this->getHTMLFontUnits($font_size, $this->svgstyles[0]['font-size'], $prevsvgstyle['font-size'], $this->svgunit);
  23085. $font_stretch = $this->getCSSFontStretching($font_stretch, $svgstyle['font-stretch']);
  23086. $font_spacing = $this->getCSSFontSpacing($font_spacing, $svgstyle['letter-spacing']);
  23087. switch ($font_style) {
  23088. case 'italic': {
  23089. $font_style = 'I';
  23090. break;
  23091. }
  23092. case 'oblique': {
  23093. $font_style = 'I';
  23094. break;
  23095. }
  23096. default:
  23097. case 'normal': {
  23098. $font_style = '';
  23099. break;
  23100. }
  23101. }
  23102. switch ($font_weight) {
  23103. case 'bold':
  23104. case 'bolder': {
  23105. $font_style .= 'B';
  23106. break;
  23107. }
  23108. case 'normal': {
  23109. if ((substr($font_family, -1) == 'I') AND (substr($font_family, -2, 1) == 'B')) {
  23110. $font_family = substr($font_family, 0, -2).'I';
  23111. } elseif (substr($font_family, -1) == 'B') {
  23112. $font_family = substr($font_family, 0, -1);
  23113. }
  23114. break;
  23115. }
  23116. }
  23117. switch ($svgstyle['text-decoration']) {
  23118. case 'underline': {
  23119. $font_style .= 'U';
  23120. break;
  23121. }
  23122. case 'overline': {
  23123. $font_style .= 'O';
  23124. break;
  23125. }
  23126. case 'line-through': {
  23127. $font_style .= 'D';
  23128. break;
  23129. }
  23130. default:
  23131. case 'none': {
  23132. break;
  23133. }
  23134. }
  23135. $this->SetFont($font_family, $font_style, $font_size);
  23136. $this->setFontStretching($font_stretch);
  23137. $this->setFontSpacing($font_spacing);
  23138. return $objstyle;
  23139. }
  23140. /**
  23141. * Draws an SVG path
  23142. * @param $d (string) attribute d of the path SVG element
  23143. * @param $style (string) Style of rendering. Possible values are:
  23144. * <ul>
  23145. * <li>D or empty string: Draw (default).</li>
  23146. * <li>F: Fill.</li>
  23147. * <li>F*: Fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  23148. * <li>DF or FD: Draw and fill.</li>
  23149. * <li>DF* or FD*: Draw and fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  23150. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  23151. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  23152. * </ul>
  23153. * @return array of container box measures (x, y, w, h)
  23154. * @author Nicola Asuni
  23155. * @since 5.0.000 (2010-05-02)
  23156. * @protected
  23157. */
  23158. protected function SVGPath($d, $style = '')
  23159. {
  23160. if ($this->state != 2) {
  23161. return;
  23162. }
  23163. // set fill/stroke style
  23164. $op = TCPDF_STATIC::getPathPaintOperator($style, '');
  23165. if (empty($op)) {
  23166. return;
  23167. }
  23168. $paths = array();
  23169. $d = preg_replace('/([0-9ACHLMQSTVZ])([\-\+])/si', '\\1 \\2', $d);
  23170. preg_match_all('/([ACHLMQSTVZ])[\s]*([^ACHLMQSTVZ\"]*)/si', $d, $paths, PREG_SET_ORDER);
  23171. $x = 0;
  23172. $y = 0;
  23173. $x1 = 0;
  23174. $y1 = 0;
  23175. $x2 = 0;
  23176. $y2 = 0;
  23177. $xmin = 2147483647;
  23178. $xmax = 0;
  23179. $ymin = 2147483647;
  23180. $ymax = 0;
  23181. $relcoord = false;
  23182. $minlen = (0.01 / $this->k); // minimum acceptable length (3 point)
  23183. $firstcmd = true; // used to print first point
  23184. // draw curve pieces
  23185. foreach ($paths as $key => $val) {
  23186. // get curve type
  23187. $cmd = trim($val[1]);
  23188. if (strtolower($cmd) == $cmd) {
  23189. // use relative coordinated instead of absolute
  23190. $relcoord = true;
  23191. $xoffset = $x;
  23192. $yoffset = $y;
  23193. } else {
  23194. $relcoord = false;
  23195. $xoffset = 0;
  23196. $yoffset = 0;
  23197. }
  23198. $params = array();
  23199. if (isset($val[2])) {
  23200. // get curve parameters
  23201. $rawparams = preg_split('/([\,\s]+)/si', trim($val[2]));
  23202. $params = array();
  23203. foreach ($rawparams as $ck => $cp) {
  23204. $params[$ck] = $this->getHTMLUnitToUnits($cp, 0, $this->svgunit, false);
  23205. if (abs($params[$ck]) < $minlen) {
  23206. // approximate little values to zero
  23207. $params[$ck] = 0;
  23208. }
  23209. }
  23210. }
  23211. // store current origin point
  23212. $x0 = $x;
  23213. $y0 = $y;
  23214. switch (strtoupper($cmd)) {
  23215. case 'M': { // moveto
  23216. foreach ($params as $ck => $cp) {
  23217. if (($ck % 2) == 0) {
  23218. $x = $cp + $xoffset;
  23219. } else {
  23220. $y = $cp + $yoffset;
  23221. if ($firstcmd OR (abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  23222. if ($ck == 1) {
  23223. $this->_outPoint($x, $y);
  23224. $firstcmd = false;
  23225. } else {
  23226. $this->_outLine($x, $y);
  23227. }
  23228. $x0 = $x;
  23229. $y0 = $y;
  23230. }
  23231. $xmin = min($xmin, $x);
  23232. $ymin = min($ymin, $y);
  23233. $xmax = max($xmax, $x);
  23234. $ymax = max($ymax, $y);
  23235. if ($relcoord) {
  23236. $xoffset = $x;
  23237. $yoffset = $y;
  23238. }
  23239. }
  23240. }
  23241. break;
  23242. }
  23243. case 'L': { // lineto
  23244. foreach ($params as $ck => $cp) {
  23245. if (($ck % 2) == 0) {
  23246. $x = $cp + $xoffset;
  23247. } else {
  23248. $y = $cp + $yoffset;
  23249. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  23250. $this->_outLine($x, $y);
  23251. $x0 = $x;
  23252. $y0 = $y;
  23253. }
  23254. $xmin = min($xmin, $x);
  23255. $ymin = min($ymin, $y);
  23256. $xmax = max($xmax, $x);
  23257. $ymax = max($ymax, $y);
  23258. if ($relcoord) {
  23259. $xoffset = $x;
  23260. $yoffset = $y;
  23261. }
  23262. }
  23263. }
  23264. break;
  23265. }
  23266. case 'H': { // horizontal lineto
  23267. foreach ($params as $ck => $cp) {
  23268. $x = $cp + $xoffset;
  23269. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  23270. $this->_outLine($x, $y);
  23271. $x0 = $x;
  23272. $y0 = $y;
  23273. }
  23274. $xmin = min($xmin, $x);
  23275. $xmax = max($xmax, $x);
  23276. if ($relcoord) {
  23277. $xoffset = $x;
  23278. }
  23279. }
  23280. break;
  23281. }
  23282. case 'V': { // vertical lineto
  23283. foreach ($params as $ck => $cp) {
  23284. $y = $cp + $yoffset;
  23285. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  23286. $this->_outLine($x, $y);
  23287. $x0 = $x;
  23288. $y0 = $y;
  23289. }
  23290. $ymin = min($ymin, $y);
  23291. $ymax = max($ymax, $y);
  23292. if ($relcoord) {
  23293. $yoffset = $y;
  23294. }
  23295. }
  23296. break;
  23297. }
  23298. case 'C': { // curveto
  23299. foreach ($params as $ck => $cp) {
  23300. $params[$ck] = $cp;
  23301. if ((($ck + 1) % 6) == 0) {
  23302. $x1 = $params[($ck - 5)] + $xoffset;
  23303. $y1 = $params[($ck - 4)] + $yoffset;
  23304. $x2 = $params[($ck - 3)] + $xoffset;
  23305. $y2 = $params[($ck - 2)] + $yoffset;
  23306. $x = $params[($ck - 1)] + $xoffset;
  23307. $y = $params[($ck)] + $yoffset;
  23308. $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
  23309. $xmin = min($xmin, $x, $x1, $x2);
  23310. $ymin = min($ymin, $y, $y1, $y2);
  23311. $xmax = max($xmax, $x, $x1, $x2);
  23312. $ymax = max($ymax, $y, $y1, $y2);
  23313. if ($relcoord) {
  23314. $xoffset = $x;
  23315. $yoffset = $y;
  23316. }
  23317. }
  23318. }
  23319. break;
  23320. }
  23321. case 'S': { // shorthand/smooth curveto
  23322. foreach ($params as $ck => $cp) {
  23323. $params[$ck] = $cp;
  23324. if ((($ck + 1) % 4) == 0) {
  23325. if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'C') OR (strtoupper($paths[($key - 1)][1]) == 'S'))) {
  23326. $x1 = (2 * $x) - $x2;
  23327. $y1 = (2 * $y) - $y2;
  23328. } else {
  23329. $x1 = $x;
  23330. $y1 = $y;
  23331. }
  23332. $x2 = $params[($ck - 3)] + $xoffset;
  23333. $y2 = $params[($ck - 2)] + $yoffset;
  23334. $x = $params[($ck - 1)] + $xoffset;
  23335. $y = $params[($ck)] + $yoffset;
  23336. $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
  23337. $xmin = min($xmin, $x, $x1, $x2);
  23338. $ymin = min($ymin, $y, $y1, $y2);
  23339. $xmax = max($xmax, $x, $x1, $x2);
  23340. $ymax = max($ymax, $y, $y1, $y2);
  23341. if ($relcoord) {
  23342. $xoffset = $x;
  23343. $yoffset = $y;
  23344. }
  23345. }
  23346. }
  23347. break;
  23348. }
  23349. case 'Q': { // quadratic Bezier curveto
  23350. foreach ($params as $ck => $cp) {
  23351. $params[$ck] = $cp;
  23352. if ((($ck + 1) % 4) == 0) {
  23353. // convert quadratic points to cubic points
  23354. $x1 = $params[($ck - 3)] + $xoffset;
  23355. $y1 = $params[($ck - 2)] + $yoffset;
  23356. $xa = ($x + (2 * $x1)) / 3;
  23357. $ya = ($y + (2 * $y1)) / 3;
  23358. $x = $params[($ck - 1)] + $xoffset;
  23359. $y = $params[($ck)] + $yoffset;
  23360. $xb = ($x + (2 * $x1)) / 3;
  23361. $yb = ($y + (2 * $y1)) / 3;
  23362. $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
  23363. $xmin = min($xmin, $x, $xa, $xb);
  23364. $ymin = min($ymin, $y, $ya, $yb);
  23365. $xmax = max($xmax, $x, $xa, $xb);
  23366. $ymax = max($ymax, $y, $ya, $yb);
  23367. if ($relcoord) {
  23368. $xoffset = $x;
  23369. $yoffset = $y;
  23370. }
  23371. }
  23372. }
  23373. break;
  23374. }
  23375. case 'T': { // shorthand/smooth quadratic Bezier curveto
  23376. foreach ($params as $ck => $cp) {
  23377. $params[$ck] = $cp;
  23378. if (($ck % 2) != 0) {
  23379. if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'Q') OR (strtoupper($paths[($key - 1)][1]) == 'T'))) {
  23380. $x1 = (2 * $x) - $x1;
  23381. $y1 = (2 * $y) - $y1;
  23382. } else {
  23383. $x1 = $x;
  23384. $y1 = $y;
  23385. }
  23386. // convert quadratic points to cubic points
  23387. $xa = ($x + (2 * $x1)) / 3;
  23388. $ya = ($y + (2 * $y1)) / 3;
  23389. $x = $params[($ck - 1)] + $xoffset;
  23390. $y = $params[($ck)] + $yoffset;
  23391. $xb = ($x + (2 * $x1)) / 3;
  23392. $yb = ($y + (2 * $y1)) / 3;
  23393. $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
  23394. $xmin = min($xmin, $x, $xa, $xb);
  23395. $ymin = min($ymin, $y, $ya, $yb);
  23396. $xmax = max($xmax, $x, $xa, $xb);
  23397. $ymax = max($ymax, $y, $ya, $yb);
  23398. if ($relcoord) {
  23399. $xoffset = $x;
  23400. $yoffset = $y;
  23401. }
  23402. }
  23403. }
  23404. break;
  23405. }
  23406. case 'A': { // elliptical arc
  23407. foreach ($params as $ck => $cp) {
  23408. $params[$ck] = $cp;
  23409. if ((($ck + 1) % 7) == 0) {
  23410. $x0 = $x;
  23411. $y0 = $y;
  23412. $rx = abs($params[($ck - 6)]);
  23413. $ry = abs($params[($ck - 5)]);
  23414. $ang = -$rawparams[($ck - 4)];
  23415. $angle = deg2rad($ang);
  23416. $fa = $rawparams[($ck - 3)]; // large-arc-flag
  23417. $fs = $rawparams[($ck - 2)]; // sweep-flag
  23418. $x = $params[($ck - 1)] + $xoffset;
  23419. $y = $params[$ck] + $yoffset;
  23420. if ((abs($x0 - $x) < $minlen) AND (abs($y0 - $y) < $minlen)) {
  23421. // endpoints are almost identical
  23422. $xmin = min($xmin, $x);
  23423. $ymin = min($ymin, $y);
  23424. $xmax = max($xmax, $x);
  23425. $ymax = max($ymax, $y);
  23426. } else {
  23427. $cos_ang = cos($angle);
  23428. $sin_ang = sin($angle);
  23429. $a = (($x0 - $x) / 2);
  23430. $b = (($y0 - $y) / 2);
  23431. $xa = ($a * $cos_ang) - ($b * $sin_ang);
  23432. $ya = ($a * $sin_ang) + ($b * $cos_ang);
  23433. $rx2 = $rx * $rx;
  23434. $ry2 = $ry * $ry;
  23435. $xa2 = $xa * $xa;
  23436. $ya2 = $ya * $ya;
  23437. $delta = ($xa2 / $rx2) + ($ya2 / $ry2);
  23438. if ($delta > 1) {
  23439. $rx *= sqrt($delta);
  23440. $ry *= sqrt($delta);
  23441. $rx2 = $rx * $rx;
  23442. $ry2 = $ry * $ry;
  23443. }
  23444. $numerator = (($rx2 * $ry2) - ($rx2 * $ya2) - ($ry2 * $xa2));
  23445. if ($numerator < 0) {
  23446. $root = 0;
  23447. } else {
  23448. $root = sqrt($numerator / (($rx2 * $ya2) + ($ry2 * $xa2)));
  23449. }
  23450. if ($fa == $fs) {
  23451. $root *= -1;
  23452. }
  23453. $cax = $root * (($rx * $ya) / $ry);
  23454. $cay = -$root * (($ry * $xa) / $rx);
  23455. // coordinates of ellipse center
  23456. $cx = ($cax * $cos_ang) - ($cay * $sin_ang) + (($x0 + $x) / 2);
  23457. $cy = ($cax * $sin_ang) + ($cay * $cos_ang) + (($y0 + $y) / 2);
  23458. // get angles
  23459. $angs = TCPDF_STATIC::getVectorsAngle(1, 0, (($xa - $cax) / $rx), (($cay - $ya) / $ry));
  23460. $dang = TCPDF_STATIC::getVectorsAngle((($xa - $cax) / $rx), (($ya - $cay) / $ry), ((-$xa - $cax) / $rx), ((-$ya - $cay) / $ry));
  23461. if (($fs == 0) AND ($dang > 0)) {
  23462. $dang -= (2 * M_PI);
  23463. } elseif (($fs == 1) AND ($dang < 0)) {
  23464. $dang += (2 * M_PI);
  23465. }
  23466. $angf = $angs - $dang;
  23467. if ((($fs == 0) AND ($angs > $angf)) OR (($fs == 1) AND ($angs < $angf))) {
  23468. // reverse angles
  23469. $tmp = $angs;
  23470. $angs = $angf;
  23471. $angf = $tmp;
  23472. }
  23473. $angs = round(rad2deg($angs), 6);
  23474. $angf = round(rad2deg($angf), 6);
  23475. // covent angles to positive values
  23476. if (($angs < 0) AND ($angf < 0)) {
  23477. $angs += 360;
  23478. $angf += 360;
  23479. }
  23480. $pie = false;
  23481. if (($key == 0) AND (isset($paths[($key + 1)][1])) AND (trim($paths[($key + 1)][1]) == 'z')) {
  23482. $pie = true;
  23483. }
  23484. list($axmin, $aymin, $axmax, $aymax) = $this->_outellipticalarc($cx, $cy, $rx, $ry, $ang, $angs, $angf, $pie, 2, false, ($fs == 0), true);
  23485. $xmin = min($xmin, $x, $axmin);
  23486. $ymin = min($ymin, $y, $aymin);
  23487. $xmax = max($xmax, $x, $axmax);
  23488. $ymax = max($ymax, $y, $aymax);
  23489. }
  23490. if ($relcoord) {
  23491. $xoffset = $x;
  23492. $yoffset = $y;
  23493. }
  23494. }
  23495. }
  23496. break;
  23497. }
  23498. case 'Z': {
  23499. $this->_out('h');
  23500. break;
  23501. }
  23502. }
  23503. $firstcmd = false;
  23504. } // end foreach
  23505. if (!empty($op)) {
  23506. $this->_out($op);
  23507. }
  23508. return array($xmin, $ymin, ($xmax - $xmin), ($ymax - $ymin));
  23509. }
  23510. /**
  23511. * Return the tag name without the namespace
  23512. * @param $name (string) Tag name
  23513. * @protected
  23514. */
  23515. protected function removeTagNamespace($name)
  23516. {
  23517. if (strpos($name, ':') !== false) {
  23518. $parts = explode(':', $name);
  23519. return $parts[(sizeof($parts) - 1)];
  23520. }
  23521. return $name;
  23522. }
  23523. /**
  23524. * Sets the opening SVG element handler function for the XML parser. (*** TO BE COMPLETED ***)
  23525. * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
  23526. * @param $name (string) The second parameter, name, contains the name of the element for which this handler is called. If case-folding is in effect for this parser, the element name will be in uppercase letters.
  23527. * @param $attribs (array) The third parameter, attribs, contains an associative array with the element's attributes (if any). The keys of this array are the attribute names, the values are the attribute values. Attribute names are case-folded on the same criteria as element names. Attribute values are not case-folded. The original order of the attributes can be retrieved by walking through attribs the normal way, using each(). The first key in the array was the first attribute, and so on.
  23528. * @param $ctm (array) tranformation matrix for clipping mode (starting transformation matrix).
  23529. * @author Nicola Asuni
  23530. * @since 5.0.000 (2010-05-02)
  23531. * @protected
  23532. */
  23533. protected function startSVGElementHandler($parser, $name, $attribs, $ctm = array())
  23534. {
  23535. $name = $this->removeTagNamespace($name);
  23536. // check if we are in clip mode
  23537. if ($this->svgclipmode) {
  23538. $this->svgclippaths[$this->svgclipid][] = array('name' => $name, 'attribs' => $attribs, 'tm' => $this->svgcliptm[$this->svgclipid]);
  23539. return;
  23540. }
  23541. if ($this->svgdefsmode AND !in_array($name, array('clipPath', 'linearGradient', 'radialGradient', 'stop'))) {
  23542. if (isset($attribs['id'])) {
  23543. $attribs['child_elements'] = array();
  23544. $this->svgdefs[$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
  23545. return;
  23546. }
  23547. if (end($this->svgdefs) !== false) {
  23548. $last_svgdefs_id = key($this->svgdefs);
  23549. if (isset($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'])) {
  23550. $attribs['id'] = 'DF_'.(count($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements']) + 1);
  23551. $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
  23552. return;
  23553. }
  23554. }
  23555. return;
  23556. }
  23557. $clipping = false;
  23558. if ($parser == 'clip-path') {
  23559. // set clipping mode
  23560. $clipping = true;
  23561. }
  23562. // get styling properties
  23563. $prev_svgstyle = $this->svgstyles[max(0, (count($this->svgstyles) - 1))]; // previous style
  23564. $svgstyle = $this->svgstyles[0]; // set default style
  23565. if ($clipping AND !isset($attribs['fill']) AND (!isset($attribs['style']) OR (!preg_match('/[;\"\s]{1}fill[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval)))) {
  23566. // default fill attribute for clipping
  23567. $attribs['fill'] = 'none';
  23568. }
  23569. if (isset($attribs['style']) AND !TCPDF_STATIC::empty_string($attribs['style']) AND ($attribs['style'][0] != ';')) {
  23570. // fix style for regular expression
  23571. $attribs['style'] = ';'.$attribs['style'];
  23572. }
  23573. foreach ($prev_svgstyle as $key => $val) {
  23574. if (in_array($key, TCPDF_IMAGES::$svginheritprop)) {
  23575. // inherit previous value
  23576. $svgstyle[$key] = $val;
  23577. }
  23578. if (isset($attribs[$key]) AND !TCPDF_STATIC::empty_string($attribs[$key])) {
  23579. // specific attribute settings
  23580. if ($attribs[$key] == 'inherit') {
  23581. $svgstyle[$key] = $val;
  23582. } else {
  23583. $svgstyle[$key] = $attribs[$key];
  23584. }
  23585. } elseif (isset($attribs['style']) AND !TCPDF_STATIC::empty_string($attribs['style'])) {
  23586. // CSS style syntax
  23587. $attrval = array();
  23588. if (preg_match('/[;\"\s]{1}'.$key.'[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval) AND isset($attrval[1])) {
  23589. if ($attrval[1] == 'inherit') {
  23590. $svgstyle[$key] = $val;
  23591. } else {
  23592. $svgstyle[$key] = $attrval[1];
  23593. }
  23594. }
  23595. }
  23596. }
  23597. // transformation matrix
  23598. if (!empty($ctm)) {
  23599. $tm = $ctm;
  23600. } else {
  23601. $tm = array(1,0,0,1,0,0);
  23602. }
  23603. if (isset($attribs['transform']) AND !empty($attribs['transform'])) {
  23604. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, TCPDF_STATIC::getSVGTransformMatrix($attribs['transform']));
  23605. }
  23606. $svgstyle['transfmatrix'] = $tm;
  23607. $invisible = false;
  23608. if (($svgstyle['visibility'] == 'hidden') OR ($svgstyle['visibility'] == 'collapse') OR ($svgstyle['display'] == 'none')) {
  23609. // the current graphics element is invisible (nothing is painted)
  23610. $invisible = true;
  23611. }
  23612. // process tag
  23613. switch ($name) {
  23614. case 'defs': {
  23615. $this->svgdefsmode = true;
  23616. break;
  23617. }
  23618. // clipPath
  23619. case 'clipPath': {
  23620. if ($invisible) {
  23621. break;
  23622. }
  23623. $this->svgclipmode = true;
  23624. if (!isset($attribs['id'])) {
  23625. $attribs['id'] = 'CP_'.(count($this->svgcliptm) + 1);
  23626. }
  23627. $this->svgclipid = $attribs['id'];
  23628. $this->svgclippaths[$this->svgclipid] = array();
  23629. $this->svgcliptm[$this->svgclipid] = $tm;
  23630. break;
  23631. }
  23632. case 'svg': {
  23633. // start of SVG object
  23634. if (++$this->svg_tag_depth <= 1) {
  23635. break;
  23636. }
  23637. // inner SVG
  23638. array_push($this->svgstyles, $svgstyle);
  23639. $this->StartTransform();
  23640. $svgX = (isset($attribs['x'])?$attribs['x']:0);
  23641. $svgY = (isset($attribs['y'])?$attribs['y']:0);
  23642. $svgW = (isset($attribs['width'])?$attribs['width']:0);
  23643. $svgH = (isset($attribs['height'])?$attribs['height']:0);
  23644. // set x, y position using transform matrix
  23645. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array( 1, 0, 0, 1, $svgX, $svgY));
  23646. $this->SVGTransform($tm);
  23647. // set clipping for width and height
  23648. $x = 0;
  23649. $y = 0;
  23650. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):$this->w);
  23651. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):$this->h);
  23652. // draw clipping rect
  23653. $this->Rect($x, $y, $w, $h, 'CNZ', array(), array());
  23654. // parse viewbox, calculate extra transformation matrix
  23655. if (isset($attribs['viewBox'])) {
  23656. $tmp = array();
  23657. preg_match_all("/[0-9]+/", $attribs['viewBox'], $tmp);
  23658. $tmp = $tmp[0];
  23659. if (sizeof($tmp) == 4) {
  23660. $vx = $tmp[0];
  23661. $vy = $tmp[1];
  23662. $vw = $tmp[2];
  23663. $vh = $tmp[3];
  23664. // get aspect ratio
  23665. $tmp = array();
  23666. $aspectX = 'xMid';
  23667. $aspectY = 'YMid';
  23668. $fit = 'meet';
  23669. if (isset($attribs['preserveAspectRatio'])) {
  23670. if ($attribs['preserveAspectRatio'] == 'none') {
  23671. $fit = 'none';
  23672. } else {
  23673. preg_match_all('/[a-zA-Z]+/', $attribs['preserveAspectRatio'], $tmp);
  23674. $tmp = $tmp[0];
  23675. if ((sizeof($tmp) == 2) AND (strlen($tmp[0]) == 8) AND (in_array($tmp[1], array('meet', 'slice', 'none')))) {
  23676. $aspectX = substr($tmp[0], 0, 4);
  23677. $aspectY = substr($tmp[0], 4, 4);
  23678. $fit = $tmp[1];
  23679. }
  23680. }
  23681. }
  23682. $wr = ($svgW / $vw);
  23683. $hr = ($svgH / $vh);
  23684. $ax = $ay = 0;
  23685. if ((($fit == 'meet') AND ($hr < $wr)) OR (($fit == 'slice') AND ($hr > $wr))) {
  23686. if ($aspectX == 'xMax') {
  23687. $ax = (($vw * ($wr / $hr)) - $vw);
  23688. }
  23689. if ($aspectX == 'xMid') {
  23690. $ax = ((($vw * ($wr / $hr)) - $vw) / 2);
  23691. }
  23692. $wr = $hr;
  23693. } elseif ((($fit == 'meet') AND ($hr > $wr)) OR (($fit == 'slice') AND ($hr < $wr))) {
  23694. if ($aspectY == 'YMax') {
  23695. $ay = (($vh * ($hr / $wr)) - $vh);
  23696. }
  23697. if ($aspectY == 'YMid') {
  23698. $ay = ((($vh * ($hr / $wr)) - $vh) / 2);
  23699. }
  23700. $hr = $wr;
  23701. }
  23702. $newtm = array($wr, 0, 0, $hr, (($wr * ($ax - $vx)) - $svgX), (($hr * ($ay - $vy)) - $svgY));
  23703. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, $newtm);
  23704. $this->SVGTransform($tm);
  23705. }
  23706. }
  23707. $this->setSVGStyles($svgstyle, $prev_svgstyle);
  23708. break;
  23709. }
  23710. case 'g': {
  23711. // group together related graphics elements
  23712. array_push($this->svgstyles, $svgstyle);
  23713. $this->StartTransform();
  23714. $x = (isset($attribs['x'])?$attribs['x']:0);
  23715. $y = (isset($attribs['y'])?$attribs['y']:0);
  23716. $w = 1;//(isset($attribs['width'])?$attribs['width']:1);
  23717. $h = 1;//(isset($attribs['height'])?$attribs['height']:1);
  23718. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array($w, 0, 0, $h, $x, $y));
  23719. $this->SVGTransform($tm);
  23720. $this->setSVGStyles($svgstyle, $prev_svgstyle);
  23721. break;
  23722. }
  23723. case 'linearGradient': {
  23724. if ($this->pdfa_mode) {
  23725. break;
  23726. }
  23727. if (!isset($attribs['id'])) {
  23728. $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
  23729. }
  23730. $this->svggradientid = $attribs['id'];
  23731. $this->svggradients[$this->svggradientid] = array();
  23732. $this->svggradients[$this->svggradientid]['type'] = 2;
  23733. $this->svggradients[$this->svggradientid]['stops'] = array();
  23734. if (isset($attribs['gradientUnits'])) {
  23735. $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  23736. } else {
  23737. $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  23738. }
  23739. //$attribs['spreadMethod']
  23740. if (((!isset($attribs['x1'])) AND (!isset($attribs['y1'])) AND (!isset($attribs['x2'])) AND (!isset($attribs['y2'])))
  23741. OR ((isset($attribs['x1']) AND (substr($attribs['x1'], -1) == '%'))
  23742. OR (isset($attribs['y1']) AND (substr($attribs['y1'], -1) == '%'))
  23743. OR (isset($attribs['x2']) AND (substr($attribs['x2'], -1) == '%'))
  23744. OR (isset($attribs['y2']) AND (substr($attribs['y2'], -1) == '%')))) {
  23745. $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  23746. } else {
  23747. $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  23748. }
  23749. $x1 = (isset($attribs['x1'])?$attribs['x1']:'0');
  23750. $y1 = (isset($attribs['y1'])?$attribs['y1']:'0');
  23751. $x2 = (isset($attribs['x2'])?$attribs['x2']:'100');
  23752. $y2 = (isset($attribs['y2'])?$attribs['y2']:'0');
  23753. if (isset($attribs['gradientTransform'])) {
  23754. $this->svggradients[$this->svggradientid]['gradientTransform'] = TCPDF_STATIC::getSVGTransformMatrix($attribs['gradientTransform']);
  23755. }
  23756. $this->svggradients[$this->svggradientid]['coords'] = array($x1, $y1, $x2, $y2);
  23757. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23758. // gradient is defined on another place
  23759. $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  23760. }
  23761. break;
  23762. }
  23763. case 'radialGradient': {
  23764. if ($this->pdfa_mode) {
  23765. break;
  23766. }
  23767. if (!isset($attribs['id'])) {
  23768. $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
  23769. }
  23770. $this->svggradientid = $attribs['id'];
  23771. $this->svggradients[$this->svggradientid] = array();
  23772. $this->svggradients[$this->svggradientid]['type'] = 3;
  23773. $this->svggradients[$this->svggradientid]['stops'] = array();
  23774. if (isset($attribs['gradientUnits'])) {
  23775. $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  23776. } else {
  23777. $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  23778. }
  23779. //$attribs['spreadMethod']
  23780. if (((!isset($attribs['cx'])) AND (!isset($attribs['cy'])))
  23781. OR ((isset($attribs['cx']) AND (substr($attribs['cx'], -1) == '%'))
  23782. OR (isset($attribs['cy']) AND (substr($attribs['cy'], -1) == '%')))) {
  23783. $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  23784. } elseif (isset($attribs['r']) AND is_numeric($attribs['r']) AND ($attribs['r']) <= 1) {
  23785. $this->svggradients[$this->svggradientid]['mode'] = 'ratio';
  23786. } else {
  23787. $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  23788. }
  23789. $cx = (isset($attribs['cx']) ? $attribs['cx'] : 0.5);
  23790. $cy = (isset($attribs['cy']) ? $attribs['cy'] : 0.5);
  23791. $fx = (isset($attribs['fx']) ? $attribs['fx'] : $cx);
  23792. $fy = (isset($attribs['fy']) ? $attribs['fy'] : $cy);
  23793. $r = (isset($attribs['r']) ? $attribs['r'] : 0.5);
  23794. if (isset($attribs['gradientTransform'])) {
  23795. $this->svggradients[$this->svggradientid]['gradientTransform'] = TCPDF_STATIC::getSVGTransformMatrix($attribs['gradientTransform']);
  23796. }
  23797. $this->svggradients[$this->svggradientid]['coords'] = array($cx, $cy, $fx, $fy, $r);
  23798. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23799. // gradient is defined on another place
  23800. $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  23801. }
  23802. break;
  23803. }
  23804. case 'stop': {
  23805. // gradient stops
  23806. if (substr($attribs['offset'], -1) == '%') {
  23807. $offset = floatval(substr($attribs['offset'], 0, -1)) / 100;
  23808. } else {
  23809. $offset = floatval($attribs['offset']);
  23810. if ($offset > 1) {
  23811. $offset /= 100;
  23812. }
  23813. }
  23814. $stop_color = isset($svgstyle['stop-color'])?TCPDF_COLORS::convertHTMLColorToDec($svgstyle['stop-color'], $this->spot_colors):'black';
  23815. $opacity = isset($svgstyle['stop-opacity'])?$svgstyle['stop-opacity']:1;
  23816. $this->svggradients[$this->svggradientid]['stops'][] = array('offset' => $offset, 'color' => $stop_color, 'opacity' => $opacity);
  23817. break;
  23818. }
  23819. // paths
  23820. case 'path': {
  23821. if ($invisible) {
  23822. break;
  23823. }
  23824. if (isset($attribs['d'])) {
  23825. $d = trim($attribs['d']);
  23826. if (!empty($d)) {
  23827. $x = (isset($attribs['x'])?$attribs['x']:0);
  23828. $y = (isset($attribs['y'])?$attribs['y']:0);
  23829. $w = (isset($attribs['width'])?$attribs['width']:1);
  23830. $h = (isset($attribs['height'])?$attribs['height']:1);
  23831. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array($w, 0, 0, $h, $x, $y));
  23832. if ($clipping) {
  23833. $this->SVGTransform($tm);
  23834. $this->SVGPath($d, 'CNZ');
  23835. } else {
  23836. $this->StartTransform();
  23837. $this->SVGTransform($tm);
  23838. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'SVGPath', array($d, 'CNZ'));
  23839. if (!empty($obstyle)) {
  23840. $this->SVGPath($d, $obstyle);
  23841. }
  23842. $this->StopTransform();
  23843. }
  23844. }
  23845. }
  23846. break;
  23847. }
  23848. // shapes
  23849. case 'rect': {
  23850. if ($invisible) {
  23851. break;
  23852. }
  23853. $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
  23854. $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
  23855. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
  23856. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
  23857. $rx = (isset($attribs['rx'])?$this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false):0);
  23858. $ry = (isset($attribs['ry'])?$this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false):$rx);
  23859. if ($clipping) {
  23860. $this->SVGTransform($tm);
  23861. $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ', array(), array());
  23862. } else {
  23863. $this->StartTransform();
  23864. $this->SVGTransform($tm);
  23865. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'RoundedRectXY', array($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ'));
  23866. if (!empty($obstyle)) {
  23867. $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', $obstyle, array(), array());
  23868. }
  23869. $this->StopTransform();
  23870. }
  23871. break;
  23872. }
  23873. case 'circle': {
  23874. if ($invisible) {
  23875. break;
  23876. }
  23877. $r = (isset($attribs['r']) ? $this->getHTMLUnitToUnits($attribs['r'], 0, $this->svgunit, false) : 0);
  23878. $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false) : (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : 0));
  23879. $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false) : (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : 0));
  23880. $x = ($cx - $r);
  23881. $y = ($cy - $r);
  23882. $w = (2 * $r);
  23883. $h = $w;
  23884. if ($clipping) {
  23885. $this->SVGTransform($tm);
  23886. $this->Circle($cx, $cy, $r, 0, 360, 'CNZ', array(), array(), 8);
  23887. } else {
  23888. $this->StartTransform();
  23889. $this->SVGTransform($tm);
  23890. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Circle', array($cx, $cy, $r, 0, 360, 'CNZ'));
  23891. if (!empty($obstyle)) {
  23892. $this->Circle($cx, $cy, $r, 0, 360, $obstyle, array(), array(), 8);
  23893. }
  23894. $this->StopTransform();
  23895. }
  23896. break;
  23897. }
  23898. case 'ellipse': {
  23899. if ($invisible) {
  23900. break;
  23901. }
  23902. $rx = (isset($attribs['rx']) ? $this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false) : 0);
  23903. $ry = (isset($attribs['ry']) ? $this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false) : 0);
  23904. $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false) : (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : 0));
  23905. $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false) : (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : 0));
  23906. $x = ($cx - $rx);
  23907. $y = ($cy - $ry);
  23908. $w = (2 * $rx);
  23909. $h = (2 * $ry);
  23910. if ($clipping) {
  23911. $this->SVGTransform($tm);
  23912. $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ', array(), array(), 8);
  23913. } else {
  23914. $this->StartTransform();
  23915. $this->SVGTransform($tm);
  23916. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Ellipse', array($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ'));
  23917. if (!empty($obstyle)) {
  23918. $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, $obstyle, array(), array(), 8);
  23919. }
  23920. $this->StopTransform();
  23921. }
  23922. break;
  23923. }
  23924. case 'line': {
  23925. if ($invisible) {
  23926. break;
  23927. }
  23928. $x1 = (isset($attribs['x1'])?$this->getHTMLUnitToUnits($attribs['x1'], 0, $this->svgunit, false):0);
  23929. $y1 = (isset($attribs['y1'])?$this->getHTMLUnitToUnits($attribs['y1'], 0, $this->svgunit, false):0);
  23930. $x2 = (isset($attribs['x2'])?$this->getHTMLUnitToUnits($attribs['x2'], 0, $this->svgunit, false):0);
  23931. $y2 = (isset($attribs['y2'])?$this->getHTMLUnitToUnits($attribs['y2'], 0, $this->svgunit, false):0);
  23932. $x = $x1;
  23933. $y = $y1;
  23934. $w = abs($x2 - $x1);
  23935. $h = abs($y2 - $y1);
  23936. if (!$clipping) {
  23937. $this->StartTransform();
  23938. $this->SVGTransform($tm);
  23939. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Line', array($x1, $y1, $x2, $y2));
  23940. $this->Line($x1, $y1, $x2, $y2);
  23941. $this->StopTransform();
  23942. }
  23943. break;
  23944. }
  23945. case 'polyline':
  23946. case 'polygon': {
  23947. if ($invisible) {
  23948. break;
  23949. }
  23950. $points = (isset($attribs['points'])?$attribs['points']:'0 0');
  23951. $points = trim($points);
  23952. // note that point may use a complex syntax not covered here
  23953. $points = preg_split('/[\,\s]+/si', $points);
  23954. if (count($points) < 4) {
  23955. break;
  23956. }
  23957. $p = array();
  23958. $xmin = 2147483647;
  23959. $xmax = 0;
  23960. $ymin = 2147483647;
  23961. $ymax = 0;
  23962. foreach ($points as $key => $val) {
  23963. $p[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
  23964. if (($key % 2) == 0) {
  23965. // X coordinate
  23966. $xmin = min($xmin, $p[$key]);
  23967. $xmax = max($xmax, $p[$key]);
  23968. } else {
  23969. // Y coordinate
  23970. $ymin = min($ymin, $p[$key]);
  23971. $ymax = max($ymax, $p[$key]);
  23972. }
  23973. }
  23974. $x = $xmin;
  23975. $y = $ymin;
  23976. $w = ($xmax - $xmin);
  23977. $h = ($ymax - $ymin);
  23978. if ($name == 'polyline') {
  23979. $this->StartTransform();
  23980. $this->SVGTransform($tm);
  23981. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'PolyLine', array($p, 'CNZ'));
  23982. if (!empty($obstyle)) {
  23983. $this->PolyLine($p, $obstyle, array(), array());
  23984. }
  23985. $this->StopTransform();
  23986. } else { // polygon
  23987. if ($clipping) {
  23988. $this->SVGTransform($tm);
  23989. $this->Polygon($p, 'CNZ', array(), array(), true);
  23990. } else {
  23991. $this->StartTransform();
  23992. $this->SVGTransform($tm);
  23993. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Polygon', array($p, 'CNZ'));
  23994. if (!empty($obstyle)) {
  23995. $this->Polygon($p, $obstyle, array(), array(), true);
  23996. }
  23997. $this->StopTransform();
  23998. }
  23999. }
  24000. break;
  24001. }
  24002. // image
  24003. case 'image': {
  24004. if ($invisible) {
  24005. break;
  24006. }
  24007. if (!isset($attribs['xlink:href']) OR empty($attribs['xlink:href'])) {
  24008. break;
  24009. }
  24010. $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
  24011. $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
  24012. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
  24013. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
  24014. $img = $attribs['xlink:href'];
  24015. if (!$clipping) {
  24016. $this->StartTransform();
  24017. $this->SVGTransform($tm);
  24018. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h);
  24019. if (preg_match('/^data:image\/[^;]+;base64,/', $img, $m) > 0) {
  24020. // embedded image encoded as base64
  24021. $img = '@'.base64_decode(substr($img, strlen($m[0])));
  24022. } else {
  24023. // fix image path
  24024. if (!TCPDF_STATIC::empty_string($this->svgdir) AND (($img[0] == '.') OR (basename($img) == $img))) {
  24025. // replace relative path with full server path
  24026. $img = $this->svgdir.'/'.$img;
  24027. }
  24028. if (($img[0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
  24029. $findroot = strpos($img, $_SERVER['DOCUMENT_ROOT']);
  24030. if (($findroot === false) OR ($findroot > 1)) {
  24031. if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
  24032. $img = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$img;
  24033. } else {
  24034. $img = $_SERVER['DOCUMENT_ROOT'].$img;
  24035. }
  24036. }
  24037. }
  24038. $img = urldecode($img);
  24039. $testscrtype = @parse_url($img);
  24040. if (empty($testscrtype['query'])) {
  24041. // convert URL to server path
  24042. $img = str_replace(K_PATH_URL, K_PATH_MAIN, $img);
  24043. } elseif (preg_match('|^https?://|', $img) !== 1) {
  24044. // convert server path to URL
  24045. $img = str_replace(K_PATH_MAIN, K_PATH_URL, $img);
  24046. }
  24047. }
  24048. // get image type
  24049. $imgtype = TCPDF_IMAGES::getImageFileType($img);
  24050. if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  24051. $this->ImageEps($img, $x, $y, $w, $h);
  24052. } elseif ($imgtype == 'svg') {
  24053. // store SVG vars
  24054. $svggradients = $this->svggradients;
  24055. $svggradientid = $this->svggradientid;
  24056. $svgdefsmode = $this->svgdefsmode;
  24057. $svgdefs = $this->svgdefs;
  24058. $svgclipmode = $this->svgclipmode;
  24059. $svgclippaths = $this->svgclippaths;
  24060. $svgcliptm = $this->svgcliptm;
  24061. $svgclipid = $this->svgclipid;
  24062. $svgtext = $this->svgtext;
  24063. $svgtextmode = $this->svgtextmode;
  24064. $this->ImageSVG($img, $x, $y, $w, $h);
  24065. // restore SVG vars
  24066. $this->svggradients = $svggradients;
  24067. $this->svggradientid = $svggradientid;
  24068. $this->svgdefsmode = $svgdefsmode;
  24069. $this->svgdefs = $svgdefs;
  24070. $this->svgclipmode = $svgclipmode;
  24071. $this->svgclippaths = $svgclippaths;
  24072. $this->svgcliptm = $svgcliptm;
  24073. $this->svgclipid = $svgclipid;
  24074. $this->svgtext = $svgtext;
  24075. $this->svgtextmode = $svgtextmode;
  24076. } else {
  24077. $this->Image($img, $x, $y, $w, $h);
  24078. }
  24079. $this->StopTransform();
  24080. }
  24081. break;
  24082. }
  24083. // text
  24084. case 'text':
  24085. case 'tspan': {
  24086. if (isset($this->svgtextmode['text-anchor']) AND !empty($this->svgtext)) {
  24087. // @TODO: unsupported feature
  24088. }
  24089. // only basic support - advanced features must be implemented
  24090. $this->svgtextmode['invisible'] = $invisible;
  24091. if ($invisible) {
  24092. break;
  24093. }
  24094. array_push($this->svgstyles, $svgstyle);
  24095. if (isset($attribs['x'])) {
  24096. $x = $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false);
  24097. } elseif ($name == 'tspan') {
  24098. $x = $this->x;
  24099. } else {
  24100. $x = 0;
  24101. }
  24102. if (isset($attribs['dx'])) {
  24103. $x += $this->getHTMLUnitToUnits($attribs['dx'], 0, $this->svgunit, false);
  24104. }
  24105. if (isset($attribs['y'])) {
  24106. $y = $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false);
  24107. } elseif ($name == 'tspan') {
  24108. $y = $this->y;
  24109. } else {
  24110. $y = 0;
  24111. }
  24112. if (isset($attribs['dy'])) {
  24113. $y += $this->getHTMLUnitToUnits($attribs['dy'], 0, $this->svgunit, false);
  24114. }
  24115. $svgstyle['text-color'] = $svgstyle['fill'];
  24116. $this->svgtext = '';
  24117. if (isset($svgstyle['text-anchor'])) {
  24118. $this->svgtextmode['text-anchor'] = $svgstyle['text-anchor'];
  24119. } else {
  24120. $this->svgtextmode['text-anchor'] = 'start';
  24121. }
  24122. if (isset($svgstyle['direction'])) {
  24123. if ($svgstyle['direction'] == 'rtl') {
  24124. $this->svgtextmode['rtl'] = true;
  24125. } else {
  24126. $this->svgtextmode['rtl'] = false;
  24127. }
  24128. } else {
  24129. $this->svgtextmode['rtl'] = false;
  24130. }
  24131. if (isset($svgstyle['stroke']) AND ($svgstyle['stroke'] != 'none') AND isset($svgstyle['stroke-width']) AND ($svgstyle['stroke-width'] > 0)) {
  24132. $this->svgtextmode['stroke'] = $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false);
  24133. } else {
  24134. $this->svgtextmode['stroke'] = false;
  24135. }
  24136. $this->StartTransform();
  24137. $this->SVGTransform($tm);
  24138. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, 1, 1);
  24139. $this->x = $x;
  24140. $this->y = $y;
  24141. break;
  24142. }
  24143. // use
  24144. case 'use': {
  24145. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  24146. $svgdefid = substr($attribs['xlink:href'], 1);
  24147. if (isset($this->svgdefs[$svgdefid])) {
  24148. $use = $this->svgdefs[$svgdefid];
  24149. if (isset($attribs['xlink:href'])) {
  24150. unset($attribs['xlink:href']);
  24151. }
  24152. if (isset($attribs['id'])) {
  24153. unset($attribs['id']);
  24154. }
  24155. if (isset($use['attribs']['x']) AND isset($attribs['x'])) {
  24156. $attribs['x'] += $use['attribs']['x'];
  24157. }
  24158. if (isset($use['attribs']['y']) AND isset($attribs['y'])) {
  24159. $attribs['y'] += $use['attribs']['y'];
  24160. }
  24161. if (empty($attribs['style'])) {
  24162. $attribs['style'] = '';
  24163. }
  24164. if (!empty($use['attribs']['style'])) {
  24165. // merge styles
  24166. $attribs['style'] = str_replace(';;', ';', ';'.$use['attribs']['style'].$attribs['style']);
  24167. }
  24168. $attribs = array_merge($use['attribs'], $attribs);
  24169. $this->startSVGElementHandler($parser, $use['name'], $attribs);
  24170. return;
  24171. }
  24172. }
  24173. break;
  24174. }
  24175. default: {
  24176. break;
  24177. }
  24178. } // end of switch
  24179. // process child elements
  24180. if (!empty($attribs['child_elements'])) {
  24181. $child_elements = $attribs['child_elements'];
  24182. unset($attribs['child_elements']);
  24183. foreach ($child_elements as $child_element) {
  24184. if (empty($child_element['attribs']['closing_tag'])) {
  24185. $this->startSVGElementHandler('child-tag', $child_element['name'], $child_element['attribs']);
  24186. } else {
  24187. if (isset($child_element['attribs']['content'])) {
  24188. $this->svgtext = $child_element['attribs']['content'];
  24189. }
  24190. $this->endSVGElementHandler('child-tag', $child_element['name']);
  24191. }
  24192. }
  24193. }
  24194. }
  24195. /**
  24196. * Sets the closing SVG element handler function for the XML parser.
  24197. * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
  24198. * @param $name (string) The second parameter, name, contains the name of the element for which this handler is called. If case-folding is in effect for this parser, the element name will be in uppercase letters.
  24199. * @author Nicola Asuni
  24200. * @since 5.0.000 (2010-05-02)
  24201. * @protected
  24202. */
  24203. protected function endSVGElementHandler($parser, $name)
  24204. {
  24205. $name = $this->removeTagNamespace($name);
  24206. if ($this->svgdefsmode AND !in_array($name, array('defs', 'clipPath', 'linearGradient', 'radialGradient', 'stop'))) {;
  24207. if (end($this->svgdefs) !== false) {
  24208. $last_svgdefs_id = key($this->svgdefs);
  24209. if (isset($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'])) {
  24210. foreach ($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'] as $child_element) {
  24211. if (isset($child_element['attribs']['id']) AND ($child_element['name'] == $name)) {
  24212. $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$child_element['attribs']['id'].'_CLOSE'] = array('name' => $name, 'attribs' => array('closing_tag' => true, 'content' => $this->svgtext));
  24213. return;
  24214. }
  24215. }
  24216. if ($this->svgdefs[$last_svgdefs_id]['name'] == $name) {
  24217. $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$last_svgdefs_id.'_CLOSE'] = array('name' => $name, 'attribs' => array('closing_tag' => true, 'content' => $this->svgtext));
  24218. return;
  24219. }
  24220. }
  24221. }
  24222. return;
  24223. }
  24224. switch ($name) {
  24225. case 'defs': {
  24226. $this->svgdefsmode = false;
  24227. break;
  24228. }
  24229. // clipPath
  24230. case 'clipPath': {
  24231. $this->svgclipmode = false;
  24232. break;
  24233. }
  24234. case 'svg': {
  24235. if (--$this->svg_tag_depth <= 0) {
  24236. break;
  24237. }
  24238. }
  24239. case 'g': {
  24240. // ungroup: remove last style from array
  24241. array_pop($this->svgstyles);
  24242. $this->StopTransform();
  24243. break;
  24244. }
  24245. case 'text':
  24246. case 'tspan': {
  24247. if ($this->svgtextmode['invisible']) {
  24248. // This implementation must be fixed to following the rule:
  24249. // 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.
  24250. break;
  24251. }
  24252. // print text
  24253. $text = $this->svgtext;
  24254. //$text = $this->stringTrim($text);
  24255. $textlen = $this->GetStringWidth($text);
  24256. if ($this->svgtextmode['text-anchor'] != 'start') {
  24257. // check if string is RTL text
  24258. if ($this->svgtextmode['text-anchor'] == 'end') {
  24259. if ($this->svgtextmode['rtl']) {
  24260. $this->x += $textlen;
  24261. } else {
  24262. $this->x -= $textlen;
  24263. }
  24264. } elseif ($this->svgtextmode['text-anchor'] == 'middle') {
  24265. if ($this->svgtextmode['rtl']) {
  24266. $this->x += ($textlen / 2);
  24267. } else {
  24268. $this->x -= ($textlen / 2);
  24269. }
  24270. }
  24271. }
  24272. $textrendermode = $this->textrendermode;
  24273. $textstrokewidth = $this->textstrokewidth;
  24274. $this->setTextRenderingMode($this->svgtextmode['stroke'], true, false);
  24275. if ($name == 'text') {
  24276. // store current coordinates
  24277. $tmpx = $this->x;
  24278. $tmpy = $this->y;
  24279. }
  24280. // print the text
  24281. $this->Cell($textlen, 0, $text, 0, 0, '', false, '', 0, false, 'L', 'T');
  24282. if ($name == 'text') {
  24283. // restore coordinates
  24284. $this->x = $tmpx;
  24285. $this->y = $tmpy;
  24286. }
  24287. // restore previous rendering mode
  24288. $this->textrendermode = $textrendermode;
  24289. $this->textstrokewidth = $textstrokewidth;
  24290. $this->svgtext = '';
  24291. $this->StopTransform();
  24292. if (!$this->svgdefsmode) {
  24293. array_pop($this->svgstyles);
  24294. }
  24295. break;
  24296. }
  24297. default: {
  24298. break;
  24299. }
  24300. }
  24301. }
  24302. /**
  24303. * Sets the character data handler function for the XML parser.
  24304. * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
  24305. * @param $data (string) The second parameter, data, contains the character data as a string.
  24306. * @author Nicola Asuni
  24307. * @since 5.0.000 (2010-05-02)
  24308. * @protected
  24309. */
  24310. protected function segSVGContentHandler($parser, $data)
  24311. {
  24312. $this->svgtext .= $data;
  24313. }
  24314. // --- END SVG METHODS -----------------------------------------------------
  24315. } // END OF TCPDF CLASS
  24316. //============================================================+
  24317. // END OF FILE
  24318. //============================================================+