tcpdf.php 866 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234
  1. <?php
  2. //============================================================+
  3. // File name : tcpdf.php
  4. // Version : 6.0.052
  5. // Begin : 2002-08-03
  6. // Last Update : 2013-12-12
  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-2013 Nicola Asuni - Tecnick.com LTD
  11. //
  12. // This file is part of TCPDF software library.
  13. //
  14. // TCPDF is free software: you can ioredistribute it and/or modify it
  15. // under the terms of the GNU Lesser General Public License as
  16. // published by the Free Software Foundation, either version 3 of the
  17. // License, or (at your option) any later version.
  18. //
  19. // TCPDF is distributed in the hope that it will be useful, but
  20. // WITHOUT ANY WARRANTY; without even the implied warranty of
  21. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. // See the GNU Lesser General Public License for more details.
  23. //
  24. // You should have received a copy of the License
  25. // along with TCPDF. If not, see
  26. // <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
  27. //
  28. // See LICENSE.TXT file for more information.
  29. // -------------------------------------------------------------------
  30. //
  31. // Description :
  32. // This is a PHP class for generating PDF documents without requiring external extensions.
  33. //
  34. // NOTE:
  35. // This class was originally derived in 2002 from the Public
  36. // Domain FPDF class by Olivier Plathey (http://www.fpdf.org),
  37. // but now is almost entirely rewritten and contains thousands of
  38. // new lines of code and hundreds new features.
  39. //
  40. // Main features:
  41. // * no external libraries are required for the basic functions;
  42. // * all standard page formats, custom page formats, custom margins and units of measure;
  43. // * UTF-8 Unicode and Right-To-Left languages;
  44. // * TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;
  45. // * font subsetting;
  46. // * methods to publish some XHTML + CSS code, Javascript and Forms;
  47. // * images, graphic (geometric figures) and transformation methods;
  48. // * supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick (http://www.imagemagick.org/www/formats.html)
  49. // * 1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;
  50. // * JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  51. // * automatic page header and footer management;
  52. // * document encryption up to 256 bit and digital signature certifications;
  53. // * transactions to UNDO commands;
  54. // * PDF annotations, including links, text and file attachments;
  55. // * text rendering modes (fill, stroke and clipping);
  56. // * multiple columns mode;
  57. // * no-write page regions;
  58. // * bookmarks, named destinations and table of content;
  59. // * text hyphenation;
  60. // * text stretching and spacing (tracking);
  61. // * automatic page break, line break and text alignments including justification;
  62. // * automatic page numbering and page groups;
  63. // * move and delete pages;
  64. // * page compression (requires php-zlib extension);
  65. // * XOBject Templates;
  66. // * Layers and object visibility.
  67. // * PDF/A-1b support
  68. //============================================================+
  69. /**
  70. * @file
  71. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  72. * TCPDF project (http://www.tcpdf.org) was originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
  73. * <h3>TCPDF main features are:</h3>
  74. * <ul>
  75. * <li>no external libraries are required for the basic functions;</li>
  76. * <li>all standard page formats, custom page formats, custom margins and units of measure;</li>
  77. * <li>UTF-8 Unicode and Right-To-Left languages;</li>
  78. * <li>TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;</li>
  79. * <li>font subsetting;</li>
  80. * <li>methods to publish some XHTML + CSS code, Javascript and Forms;</li>
  81. * <li>images, graphic (geometric figures) and transformation methods;
  82. * <li>supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick (http://www.imagemagick.org/www/formats.html)</li>
  83. * <li>1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extention, 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.0.052
  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.0.052
  128. * @author Nicola Asuni - info@tecnick.com
  129. */
  130. class TCPDF {
  131. // Protected properties
  132. /**
  133. * Current page number.
  134. * @protected
  135. */
  136. protected $page;
  137. /**
  138. * Current object number.
  139. * @protected
  140. */
  141. protected $n;
  142. /**
  143. * Array of object offsets.
  144. * @protected
  145. */
  146. protected $offsets = array();
  147. /**
  148. * Array of object IDs for each page.
  149. * @protected
  150. */
  151. protected $pageobjects = array();
  152. /**
  153. * Buffer holding in-memory PDF.
  154. * @protected
  155. */
  156. protected $buffer;
  157. /**
  158. * Array containing pages.
  159. * @protected
  160. */
  161. protected $pages = array();
  162. /**
  163. * Current document state.
  164. * @protected
  165. */
  166. protected $state;
  167. /**
  168. * Compression flag.
  169. * @protected
  170. */
  171. protected $compress;
  172. /**
  173. * Current page orientation (P = Portrait, L = Landscape).
  174. * @protected
  175. */
  176. protected $CurOrientation;
  177. /**
  178. * Page dimensions.
  179. * @protected
  180. */
  181. protected $pagedim = array();
  182. /**
  183. * Scale factor (number of points in user unit).
  184. * @protected
  185. */
  186. protected $k;
  187. /**
  188. * Width of page format in points.
  189. * @protected
  190. */
  191. protected $fwPt;
  192. /**
  193. * Height of page format in points.
  194. * @protected
  195. */
  196. protected $fhPt;
  197. /**
  198. * Current width of page in points.
  199. * @protected
  200. */
  201. protected $wPt;
  202. /**
  203. * Current height of page in points.
  204. * @protected
  205. */
  206. protected $hPt;
  207. /**
  208. * Current width of page in user unit.
  209. * @protected
  210. */
  211. protected $w;
  212. /**
  213. * Current height of page in user unit.
  214. * @protected
  215. */
  216. protected $h;
  217. /**
  218. * Left margin.
  219. * @protected
  220. */
  221. protected $lMargin;
  222. /**
  223. * Right margin.
  224. * @protected
  225. */
  226. protected $rMargin;
  227. /**
  228. * Cell left margin (used by regions).
  229. * @protected
  230. */
  231. protected $clMargin;
  232. /**
  233. * Cell right margin (used by regions).
  234. * @protected
  235. */
  236. protected $crMargin;
  237. /**
  238. * Top margin.
  239. * @protected
  240. */
  241. protected $tMargin;
  242. /**
  243. * Page break margin.
  244. * @protected
  245. */
  246. protected $bMargin;
  247. /**
  248. * Array of cell internal paddings ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
  249. * @since 5.9.000 (2010-10-03)
  250. * @protected
  251. */
  252. protected $cell_padding = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  253. /**
  254. * Array of cell margins ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
  255. * @since 5.9.000 (2010-10-04)
  256. * @protected
  257. */
  258. protected $cell_margin = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  259. /**
  260. * Current horizontal position in user unit for cell positioning.
  261. * @protected
  262. */
  263. protected $x;
  264. /**
  265. * Current vertical position in user unit for cell positioning.
  266. * @protected
  267. */
  268. protected $y;
  269. /**
  270. * Height of last cell printed.
  271. * @protected
  272. */
  273. protected $lasth;
  274. /**
  275. * Line width in user unit.
  276. * @protected
  277. */
  278. protected $LineWidth;
  279. /**
  280. * Array of standard font names.
  281. * @protected
  282. */
  283. protected $CoreFonts;
  284. /**
  285. * Array of used fonts.
  286. * @protected
  287. */
  288. protected $fonts = array();
  289. /**
  290. * Array of font files.
  291. * @protected
  292. */
  293. protected $FontFiles = array();
  294. /**
  295. * Array of encoding differences.
  296. * @protected
  297. */
  298. protected $diffs = array();
  299. /**
  300. * Array of used images.
  301. * @protected
  302. */
  303. protected $images = array();
  304. /**
  305. * Array of cached files.
  306. * @protected
  307. */
  308. protected $cached_files = array();
  309. /**
  310. * Array of Annotations in pages.
  311. * @protected
  312. */
  313. protected $PageAnnots = array();
  314. /**
  315. * Array of internal links.
  316. * @protected
  317. */
  318. protected $links = array();
  319. /**
  320. * Current font family.
  321. * @protected
  322. */
  323. protected $FontFamily;
  324. /**
  325. * Current font style.
  326. * @protected
  327. */
  328. protected $FontStyle;
  329. /**
  330. * Current font ascent (distance between font top and baseline).
  331. * @protected
  332. * @since 2.8.000 (2007-03-29)
  333. */
  334. protected $FontAscent;
  335. /**
  336. * Current font descent (distance between font bottom and baseline).
  337. * @protected
  338. * @since 2.8.000 (2007-03-29)
  339. */
  340. protected $FontDescent;
  341. /**
  342. * Underlining flag.
  343. * @protected
  344. */
  345. protected $underline;
  346. /**
  347. * Overlining flag.
  348. * @protected
  349. */
  350. protected $overline;
  351. /**
  352. * Current font info.
  353. * @protected
  354. */
  355. protected $CurrentFont;
  356. /**
  357. * Current font size in points.
  358. * @protected
  359. */
  360. protected $FontSizePt;
  361. /**
  362. * Current font size in user unit.
  363. * @protected
  364. */
  365. protected $FontSize;
  366. /**
  367. * Commands for drawing color.
  368. * @protected
  369. */
  370. protected $DrawColor;
  371. /**
  372. * Commands for filling color.
  373. * @protected
  374. */
  375. protected $FillColor;
  376. /**
  377. * Commands for text color.
  378. * @protected
  379. */
  380. protected $TextColor;
  381. /**
  382. * Indicates whether fill and text colors are different.
  383. * @protected
  384. */
  385. protected $ColorFlag;
  386. /**
  387. * Automatic page breaking.
  388. * @protected
  389. */
  390. protected $AutoPageBreak;
  391. /**
  392. * Threshold used to trigger page breaks.
  393. * @protected
  394. */
  395. protected $PageBreakTrigger;
  396. /**
  397. * Flag set when processing page header.
  398. * @protected
  399. */
  400. protected $InHeader = false;
  401. /**
  402. * Flag set when processing page footer.
  403. * @protected
  404. */
  405. protected $InFooter = false;
  406. /**
  407. * Zoom display mode.
  408. * @protected
  409. */
  410. protected $ZoomMode;
  411. /**
  412. * Layout display mode.
  413. * @protected
  414. */
  415. protected $LayoutMode;
  416. /**
  417. * If true set the document information dictionary in Unicode.
  418. * @protected
  419. */
  420. protected $docinfounicode = true;
  421. /**
  422. * Document title.
  423. * @protected
  424. */
  425. protected $title = '';
  426. /**
  427. * Document subject.
  428. * @protected
  429. */
  430. protected $subject = '';
  431. /**
  432. * Document author.
  433. * @protected
  434. */
  435. protected $author = '';
  436. /**
  437. * Document keywords.
  438. * @protected
  439. */
  440. protected $keywords = '';
  441. /**
  442. * Document creator.
  443. * @protected
  444. */
  445. protected $creator = '';
  446. /**
  447. * Starting page number.
  448. * @protected
  449. */
  450. protected $starting_page_number = 1;
  451. /**
  452. * The right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image.
  453. * @since 2002-07-31
  454. * @author Nicola Asuni
  455. * @protected
  456. */
  457. protected $img_rb_x;
  458. /**
  459. * The right-bottom corner Y coordinate of last inserted image.
  460. * @since 2002-07-31
  461. * @author Nicola Asuni
  462. * @protected
  463. */
  464. protected $img_rb_y;
  465. /**
  466. * Adjusting factor to convert pixels to user units.
  467. * @since 2004-06-14
  468. * @author Nicola Asuni
  469. * @protected
  470. */
  471. protected $imgscale = 1;
  472. /**
  473. * Boolean flag set to true when the input text is unicode (require unicode fonts).
  474. * @since 2005-01-02
  475. * @author Nicola Asuni
  476. * @protected
  477. */
  478. protected $isunicode = false;
  479. /**
  480. * PDF version.
  481. * @since 1.5.3
  482. * @protected
  483. */
  484. protected $PDFVersion = '1.7';
  485. /**
  486. * ID of the stored default header template (-1 = not set).
  487. * @protected
  488. */
  489. protected $header_xobjid = -1;
  490. /**
  491. * If true reset the Header Xobject template at each page
  492. * @protected
  493. */
  494. protected $header_xobj_autoreset = false;
  495. /**
  496. * Minimum distance between header and top page margin.
  497. * @protected
  498. */
  499. protected $header_margin;
  500. /**
  501. * Minimum distance between footer and bottom page margin.
  502. * @protected
  503. */
  504. protected $footer_margin;
  505. /**
  506. * Original left margin value.
  507. * @protected
  508. * @since 1.53.0.TC013
  509. */
  510. protected $original_lMargin;
  511. /**
  512. * Original right margin value.
  513. * @protected
  514. * @since 1.53.0.TC013
  515. */
  516. protected $original_rMargin;
  517. /**
  518. * Default font used on page header.
  519. * @protected
  520. */
  521. protected $header_font;
  522. /**
  523. * Default font used on page footer.
  524. * @protected
  525. */
  526. protected $footer_font;
  527. /**
  528. * Language templates.
  529. * @protected
  530. */
  531. protected $l;
  532. /**
  533. * Barcode to print on page footer (only if set).
  534. * @protected
  535. */
  536. protected $barcode = false;
  537. /**
  538. * Boolean flag to print/hide page header.
  539. * @protected
  540. */
  541. protected $print_header = true;
  542. /**
  543. * Boolean flag to print/hide page footer.
  544. * @protected
  545. */
  546. protected $print_footer = true;
  547. /**
  548. * Header image logo.
  549. * @protected
  550. */
  551. protected $header_logo = '';
  552. /**
  553. * Width of header image logo in user units.
  554. * @protected
  555. */
  556. protected $header_logo_width = 30;
  557. /**
  558. * Title to be printed on default page header.
  559. * @protected
  560. */
  561. protected $header_title = '';
  562. /**
  563. * String to pring on page header after title.
  564. * @protected
  565. */
  566. protected $header_string = '';
  567. /**
  568. * Color for header text (RGB array).
  569. * @since 5.9.174 (2012-07-25)
  570. * @protected
  571. */
  572. protected $header_text_color = array(0,0,0);
  573. /**
  574. * Color for header line (RGB array).
  575. * @since 5.9.174 (2012-07-25)
  576. * @protected
  577. */
  578. protected $header_line_color = array(0,0,0);
  579. /**
  580. * Color for footer text (RGB array).
  581. * @since 5.9.174 (2012-07-25)
  582. * @protected
  583. */
  584. protected $footer_text_color = array(0,0,0);
  585. /**
  586. * Color for footer line (RGB array).
  587. * @since 5.9.174 (2012-07-25)
  588. * @protected
  589. */
  590. protected $footer_line_color = array(0,0,0);
  591. /**
  592. * Text shadow data array.
  593. * @since 5.9.174 (2012-07-25)
  594. * @protected
  595. */
  596. protected $txtshadow = array('enabled'=>false, 'depth_w'=>0, 'depth_h'=>0, 'color'=>false, 'opacity'=>1, 'blend_mode'=>'Normal');
  597. /**
  598. * Default number of columns for html table.
  599. * @protected
  600. */
  601. protected $default_table_columns = 4;
  602. // variables for html parser
  603. /**
  604. * HTML PARSER: array to store current link and rendering styles.
  605. * @protected
  606. */
  607. protected $HREF = array();
  608. /**
  609. * List of available fonts on filesystem.
  610. * @protected
  611. */
  612. protected $fontlist = array();
  613. /**
  614. * Current foreground color.
  615. * @protected
  616. */
  617. protected $fgcolor;
  618. /**
  619. * HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  620. * @protected
  621. */
  622. protected $listordered = array();
  623. /**
  624. * HTML PARSER: array count list items on nested lists.
  625. * @protected
  626. */
  627. protected $listcount = array();
  628. /**
  629. * HTML PARSER: current list nesting level.
  630. * @protected
  631. */
  632. protected $listnum = 0;
  633. /**
  634. * HTML PARSER: indent amount for lists.
  635. * @protected
  636. */
  637. protected $listindent = 0;
  638. /**
  639. * HTML PARSER: current list indententation level.
  640. * @protected
  641. */
  642. protected $listindentlevel = 0;
  643. /**
  644. * Current background color.
  645. * @protected
  646. */
  647. protected $bgcolor;
  648. /**
  649. * Temporary font size in points.
  650. * @protected
  651. */
  652. protected $tempfontsize = 10;
  653. /**
  654. * Spacer string for LI tags.
  655. * @protected
  656. */
  657. protected $lispacer = '';
  658. /**
  659. * Default encoding.
  660. * @protected
  661. * @since 1.53.0.TC010
  662. */
  663. protected $encoding = 'UTF-8';
  664. /**
  665. * PHP internal encoding.
  666. * @protected
  667. * @since 1.53.0.TC016
  668. */
  669. protected $internal_encoding;
  670. /**
  671. * Boolean flag to indicate if the document language is Right-To-Left.
  672. * @protected
  673. * @since 2.0.000
  674. */
  675. protected $rtl = false;
  676. /**
  677. * Boolean flag used to force RTL or LTR string direction.
  678. * @protected
  679. * @since 2.0.000
  680. */
  681. protected $tmprtl = false;
  682. // --- Variables used for document encryption:
  683. /**
  684. * IBoolean flag indicating whether document is protected.
  685. * @protected
  686. * @since 2.0.000 (2008-01-02)
  687. */
  688. protected $encrypted;
  689. /**
  690. * Array containing encryption settings.
  691. * @protected
  692. * @since 5.0.005 (2010-05-11)
  693. */
  694. protected $encryptdata = array();
  695. /**
  696. * Last RC4 key encrypted (cached for optimisation).
  697. * @protected
  698. * @since 2.0.000 (2008-01-02)
  699. */
  700. protected $last_enc_key;
  701. /**
  702. * Last RC4 computed key.
  703. * @protected
  704. * @since 2.0.000 (2008-01-02)
  705. */
  706. protected $last_enc_key_c;
  707. /**
  708. * File ID (used on document trailer).
  709. * @protected
  710. * @since 5.0.005 (2010-05-12)
  711. */
  712. protected $file_id;
  713. // --- bookmark ---
  714. /**
  715. * Outlines for bookmark.
  716. * @protected
  717. * @since 2.1.002 (2008-02-12)
  718. */
  719. protected $outlines = array();
  720. /**
  721. * Outline root for bookmark.
  722. * @protected
  723. * @since 2.1.002 (2008-02-12)
  724. */
  725. protected $OutlineRoot;
  726. // --- javascript and form ---
  727. /**
  728. * Javascript code.
  729. * @protected
  730. * @since 2.1.002 (2008-02-12)
  731. */
  732. protected $javascript = '';
  733. /**
  734. * Javascript counter.
  735. * @protected
  736. * @since 2.1.002 (2008-02-12)
  737. */
  738. protected $n_js;
  739. /**
  740. * line through state
  741. * @protected
  742. * @since 2.8.000 (2008-03-19)
  743. */
  744. protected $linethrough;
  745. /**
  746. * Array with additional document-wide usage rights for the document.
  747. * @protected
  748. * @since 5.8.014 (2010-08-23)
  749. */
  750. protected $ur = array();
  751. /**
  752. * DPI (Dot Per Inch) Document Resolution (do not change).
  753. * @protected
  754. * @since 3.0.000 (2008-03-27)
  755. */
  756. protected $dpi = 72;
  757. /**
  758. * Array of page numbers were a new page group was started (the page numbers are the keys of the array).
  759. * @protected
  760. * @since 3.0.000 (2008-03-27)
  761. */
  762. protected $newpagegroup = array();
  763. /**
  764. * Array that contains the number of pages in each page group.
  765. * @protected
  766. * @since 3.0.000 (2008-03-27)
  767. */
  768. protected $pagegroups = array();
  769. /**
  770. * Current page group number.
  771. * @protected
  772. * @since 3.0.000 (2008-03-27)
  773. */
  774. protected $currpagegroup = 0;
  775. /**
  776. * Array of transparency objects and parameters.
  777. * @protected
  778. * @since 3.0.000 (2008-03-27)
  779. */
  780. protected $extgstates;
  781. /**
  782. * Set the default JPEG compression quality (1-100).
  783. * @protected
  784. * @since 3.0.000 (2008-03-27)
  785. */
  786. protected $jpeg_quality;
  787. /**
  788. * Default cell height ratio.
  789. * @protected
  790. * @since 3.0.014 (2008-05-23)
  791. */
  792. protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  793. /**
  794. * PDF viewer preferences.
  795. * @protected
  796. * @since 3.1.000 (2008-06-09)
  797. */
  798. protected $viewer_preferences;
  799. /**
  800. * A name object specifying how the document should be displayed when opened.
  801. * @protected
  802. * @since 3.1.000 (2008-06-09)
  803. */
  804. protected $PageMode;
  805. /**
  806. * Array for storing gradient information.
  807. * @protected
  808. * @since 3.1.000 (2008-06-09)
  809. */
  810. protected $gradients = array();
  811. /**
  812. * Array used to store positions inside the pages buffer (keys are the page numbers).
  813. * @protected
  814. * @since 3.2.000 (2008-06-26)
  815. */
  816. protected $intmrk = array();
  817. /**
  818. * Array used to store positions inside the pages buffer (keys are the page numbers).
  819. * @protected
  820. * @since 5.7.000 (2010-08-03)
  821. */
  822. protected $bordermrk = array();
  823. /**
  824. * Array used to store page positions to track empty pages (keys are the page numbers).
  825. * @protected
  826. * @since 5.8.007 (2010-08-18)
  827. */
  828. protected $emptypagemrk = array();
  829. /**
  830. * Array used to store content positions inside the pages buffer (keys are the page numbers).
  831. * @protected
  832. * @since 4.6.021 (2009-07-20)
  833. */
  834. protected $cntmrk = array();
  835. /**
  836. * Array used to store footer positions of each page.
  837. * @protected
  838. * @since 3.2.000 (2008-07-01)
  839. */
  840. protected $footerpos = array();
  841. /**
  842. * Array used to store footer length of each page.
  843. * @protected
  844. * @since 4.0.014 (2008-07-29)
  845. */
  846. protected $footerlen = array();
  847. /**
  848. * Boolean flag to indicate if a new line is created.
  849. * @protected
  850. * @since 3.2.000 (2008-07-01)
  851. */
  852. protected $newline = true;
  853. /**
  854. * End position of the latest inserted line.
  855. * @protected
  856. * @since 3.2.000 (2008-07-01)
  857. */
  858. protected $endlinex = 0;
  859. /**
  860. * PDF string for width value of the last line.
  861. * @protected
  862. * @since 4.0.006 (2008-07-16)
  863. */
  864. protected $linestyleWidth = '';
  865. /**
  866. * PDF string for CAP value of the last line.
  867. * @protected
  868. * @since 4.0.006 (2008-07-16)
  869. */
  870. protected $linestyleCap = '0 J';
  871. /**
  872. * PDF string for join value of the last line.
  873. * @protected
  874. * @since 4.0.006 (2008-07-16)
  875. */
  876. protected $linestyleJoin = '0 j';
  877. /**
  878. * PDF string for dash value of the last line.
  879. * @protected
  880. * @since 4.0.006 (2008-07-16)
  881. */
  882. protected $linestyleDash = '[] 0 d';
  883. /**
  884. * Boolean flag to indicate if marked-content sequence is open.
  885. * @protected
  886. * @since 4.0.013 (2008-07-28)
  887. */
  888. protected $openMarkedContent = false;
  889. /**
  890. * Count the latest inserted vertical spaces on HTML.
  891. * @protected
  892. * @since 4.0.021 (2008-08-24)
  893. */
  894. protected $htmlvspace = 0;
  895. /**
  896. * Array of Spot colors.
  897. * @protected
  898. * @since 4.0.024 (2008-09-12)
  899. */
  900. protected $spot_colors = array();
  901. /**
  902. * Symbol used for HTML unordered list items.
  903. * @protected
  904. * @since 4.0.028 (2008-09-26)
  905. */
  906. protected $lisymbol = '';
  907. /**
  908. * String used to mark the beginning and end of EPS image blocks.
  909. * @protected
  910. * @since 4.1.000 (2008-10-18)
  911. */
  912. protected $epsmarker = 'x#!#EPS#!#x';
  913. /**
  914. * Array of transformation matrix.
  915. * @protected
  916. * @since 4.2.000 (2008-10-29)
  917. */
  918. protected $transfmatrix = array();
  919. /**
  920. * Current key for transformation matrix.
  921. * @protected
  922. * @since 4.8.005 (2009-09-17)
  923. */
  924. protected $transfmatrix_key = 0;
  925. /**
  926. * Booklet mode for double-sided pages.
  927. * @protected
  928. * @since 4.2.000 (2008-10-29)
  929. */
  930. protected $booklet = false;
  931. /**
  932. * Epsilon value used for float calculations.
  933. * @protected
  934. * @since 4.2.000 (2008-10-29)
  935. */
  936. protected $feps = 0.005;
  937. /**
  938. * Array used for custom vertical spaces for HTML tags.
  939. * @protected
  940. * @since 4.2.001 (2008-10-30)
  941. */
  942. protected $tagvspaces = array();
  943. /**
  944. * HTML PARSER: custom indent amount for lists. Negative value means disabled.
  945. * @protected
  946. * @since 4.2.007 (2008-11-12)
  947. */
  948. protected $customlistindent = -1;
  949. /**
  950. * Boolean flag to indicate if the border of the cell sides that cross the page should be removed.
  951. * @protected
  952. * @since 4.2.010 (2008-11-14)
  953. */
  954. protected $opencell = true;
  955. /**
  956. * Array of files to embedd.
  957. * @protected
  958. * @since 4.4.000 (2008-12-07)
  959. */
  960. protected $embeddedfiles = array();
  961. /**
  962. * Boolean flag to indicate if we are inside a PRE tag.
  963. * @protected
  964. * @since 4.4.001 (2008-12-08)
  965. */
  966. protected $premode = false;
  967. /**
  968. * Array used to store positions of graphics transformation blocks inside the page buffer.
  969. * keys are the page numbers
  970. * @protected
  971. * @since 4.4.002 (2008-12-09)
  972. */
  973. protected $transfmrk = array();
  974. /**
  975. * Default color for html links.
  976. * @protected
  977. * @since 4.4.003 (2008-12-09)
  978. */
  979. protected $htmlLinkColorArray = array(0, 0, 255);
  980. /**
  981. * Default font style to add to html links.
  982. * @protected
  983. * @since 4.4.003 (2008-12-09)
  984. */
  985. protected $htmlLinkFontStyle = 'U';
  986. /**
  987. * Counts the number of pages.
  988. * @protected
  989. * @since 4.5.000 (2008-12-31)
  990. */
  991. protected $numpages = 0;
  992. /**
  993. * Array containing page lengths in bytes.
  994. * @protected
  995. * @since 4.5.000 (2008-12-31)
  996. */
  997. protected $pagelen = array();
  998. /**
  999. * Counts the number of pages.
  1000. * @protected
  1001. * @since 4.5.000 (2008-12-31)
  1002. */
  1003. protected $numimages = 0;
  1004. /**
  1005. * Store the image keys.
  1006. * @protected
  1007. * @since 4.5.000 (2008-12-31)
  1008. */
  1009. protected $imagekeys = array();
  1010. /**
  1011. * Length of the buffer in bytes.
  1012. * @protected
  1013. * @since 4.5.000 (2008-12-31)
  1014. */
  1015. protected $bufferlen = 0;
  1016. /**
  1017. * If true enables disk caching.
  1018. * @protected
  1019. * @since 4.5.000 (2008-12-31)
  1020. */
  1021. protected $diskcache = false;
  1022. /**
  1023. * Counts the number of fonts.
  1024. * @protected
  1025. * @since 4.5.000 (2009-01-02)
  1026. */
  1027. protected $numfonts = 0;
  1028. /**
  1029. * Store the font keys.
  1030. * @protected
  1031. * @since 4.5.000 (2009-01-02)
  1032. */
  1033. protected $fontkeys = array();
  1034. /**
  1035. * Store the font object IDs.
  1036. * @protected
  1037. * @since 4.8.001 (2009-09-09)
  1038. */
  1039. protected $font_obj_ids = array();
  1040. /**
  1041. * Store the fage status (true when opened, false when closed).
  1042. * @protected
  1043. * @since 4.5.000 (2009-01-02)
  1044. */
  1045. protected $pageopen = array();
  1046. /**
  1047. * Default monospace font.
  1048. * @protected
  1049. * @since 4.5.025 (2009-03-10)
  1050. */
  1051. protected $default_monospaced_font = 'courier';
  1052. /**
  1053. * Cloned copy of the current class object.
  1054. * @protected
  1055. * @since 4.5.029 (2009-03-19)
  1056. */
  1057. protected $objcopy;
  1058. /**
  1059. * Array used to store the lengths of cache files.
  1060. * @protected
  1061. * @since 4.5.029 (2009-03-19)
  1062. */
  1063. protected $cache_file_length = array();
  1064. /**
  1065. * Table header content to be repeated on each new page.
  1066. * @protected
  1067. * @since 4.5.030 (2009-03-20)
  1068. */
  1069. protected $thead = '';
  1070. /**
  1071. * Margins used for table header.
  1072. * @protected
  1073. * @since 4.5.030 (2009-03-20)
  1074. */
  1075. protected $theadMargins = array();
  1076. /**
  1077. * Boolean flag to enable document digital signature.
  1078. * @protected
  1079. * @since 4.6.005 (2009-04-24)
  1080. */
  1081. protected $sign = false;
  1082. /**
  1083. * Digital signature data.
  1084. * @protected
  1085. * @since 4.6.005 (2009-04-24)
  1086. */
  1087. protected $signature_data = array();
  1088. /**
  1089. * Digital signature max length.
  1090. * @protected
  1091. * @since 4.6.005 (2009-04-24)
  1092. */
  1093. protected $signature_max_length = 11742;
  1094. /**
  1095. * Data for digital signature appearance.
  1096. * @protected
  1097. * @since 5.3.011 (2010-06-16)
  1098. */
  1099. protected $signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
  1100. /**
  1101. * Array of empty digital signature appearances.
  1102. * @protected
  1103. * @since 5.9.101 (2011-07-06)
  1104. */
  1105. protected $empty_signature_appearance = array();
  1106. /**
  1107. * Regular expression used to find blank characters (required for word-wrapping).
  1108. * @protected
  1109. * @since 4.6.006 (2009-04-28)
  1110. */
  1111. protected $re_spaces = '/[^\S\xa0]/';
  1112. /**
  1113. * Array of $re_spaces parts.
  1114. * @protected
  1115. * @since 5.5.011 (2010-07-09)
  1116. */
  1117. protected $re_space = array('p' => '[^\S\xa0]', 'm' => '');
  1118. /**
  1119. * Digital signature object ID.
  1120. * @protected
  1121. * @since 4.6.022 (2009-06-23)
  1122. */
  1123. protected $sig_obj_id = 0;
  1124. /**
  1125. * ID of page objects.
  1126. * @protected
  1127. * @since 4.7.000 (2009-08-29)
  1128. */
  1129. protected $page_obj_id = array();
  1130. /**
  1131. * List of form annotations IDs.
  1132. * @protected
  1133. * @since 4.8.000 (2009-09-07)
  1134. */
  1135. protected $form_obj_id = array();
  1136. /**
  1137. * 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.
  1138. * @protected
  1139. * @since 4.8.000 (2009-09-07)
  1140. */
  1141. protected $default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1142. /**
  1143. * Javascript objects array.
  1144. * @protected
  1145. * @since 4.8.000 (2009-09-07)
  1146. */
  1147. protected $js_objects = array();
  1148. /**
  1149. * Current form action (used during XHTML rendering).
  1150. * @protected
  1151. * @since 4.8.000 (2009-09-07)
  1152. */
  1153. protected $form_action = '';
  1154. /**
  1155. * Current form encryption type (used during XHTML rendering).
  1156. * @protected
  1157. * @since 4.8.000 (2009-09-07)
  1158. */
  1159. protected $form_enctype = 'application/x-www-form-urlencoded';
  1160. /**
  1161. * Current method to submit forms.
  1162. * @protected
  1163. * @since 4.8.000 (2009-09-07)
  1164. */
  1165. protected $form_mode = 'post';
  1166. /**
  1167. * List of fonts used on form fields (fontname => fontkey).
  1168. * @protected
  1169. * @since 4.8.001 (2009-09-09)
  1170. */
  1171. protected $annotation_fonts = array();
  1172. /**
  1173. * List of radio buttons parent objects.
  1174. * @protected
  1175. * @since 4.8.001 (2009-09-09)
  1176. */
  1177. protected $radiobutton_groups = array();
  1178. /**
  1179. * List of radio group objects IDs.
  1180. * @protected
  1181. * @since 4.8.001 (2009-09-09)
  1182. */
  1183. protected $radio_groups = array();
  1184. /**
  1185. * Text indentation value (used for text-indent CSS attribute).
  1186. * @protected
  1187. * @since 4.8.006 (2009-09-23)
  1188. */
  1189. protected $textindent = 0;
  1190. /**
  1191. * Store page number when startTransaction() is called.
  1192. * @protected
  1193. * @since 4.8.006 (2009-09-23)
  1194. */
  1195. protected $start_transaction_page = 0;
  1196. /**
  1197. * Store Y position when startTransaction() is called.
  1198. * @protected
  1199. * @since 4.9.001 (2010-03-28)
  1200. */
  1201. protected $start_transaction_y = 0;
  1202. /**
  1203. * True when we are printing the thead section on a new page.
  1204. * @protected
  1205. * @since 4.8.027 (2010-01-25)
  1206. */
  1207. protected $inthead = false;
  1208. /**
  1209. * Array of column measures (width, space, starting Y position).
  1210. * @protected
  1211. * @since 4.9.001 (2010-03-28)
  1212. */
  1213. protected $columns = array();
  1214. /**
  1215. * Number of colums.
  1216. * @protected
  1217. * @since 4.9.001 (2010-03-28)
  1218. */
  1219. protected $num_columns = 1;
  1220. /**
  1221. * Current column number.
  1222. * @protected
  1223. * @since 4.9.001 (2010-03-28)
  1224. */
  1225. protected $current_column = 0;
  1226. /**
  1227. * Starting page for columns.
  1228. * @protected
  1229. * @since 4.9.001 (2010-03-28)
  1230. */
  1231. protected $column_start_page = 0;
  1232. /**
  1233. * Maximum page and column selected.
  1234. * @protected
  1235. * @since 5.8.000 (2010-08-11)
  1236. */
  1237. protected $maxselcol = array('page' => 0, 'column' => 0);
  1238. /**
  1239. * Array of: X difference between table cell x start and starting page margin, cellspacing, cellpadding.
  1240. * @protected
  1241. * @since 5.8.000 (2010-08-11)
  1242. */
  1243. protected $colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  1244. /**
  1245. * 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.
  1246. * @protected
  1247. * @since 4.9.008 (2010-04-03)
  1248. */
  1249. protected $textrendermode = 0;
  1250. /**
  1251. * Text stroke width in doc units.
  1252. * @protected
  1253. * @since 4.9.008 (2010-04-03)
  1254. */
  1255. protected $textstrokewidth = 0;
  1256. /**
  1257. * Current stroke color.
  1258. * @protected
  1259. * @since 4.9.008 (2010-04-03)
  1260. */
  1261. protected $strokecolor;
  1262. /**
  1263. * Default unit of measure for document.
  1264. * @protected
  1265. * @since 5.0.000 (2010-04-22)
  1266. */
  1267. protected $pdfunit = 'mm';
  1268. /**
  1269. * Boolean flag true when we are on TOC (Table Of Content) page.
  1270. * @protected
  1271. */
  1272. protected $tocpage = false;
  1273. /**
  1274. * Boolean flag: if true convert vector images (SVG, EPS) to raster image using GD or ImageMagick library.
  1275. * @protected
  1276. * @since 5.0.000 (2010-04-26)
  1277. */
  1278. protected $rasterize_vector_images = false;
  1279. /**
  1280. * Boolean flag: if true enables font subsetting by default.
  1281. * @protected
  1282. * @since 5.3.002 (2010-06-07)
  1283. */
  1284. protected $font_subsetting = true;
  1285. /**
  1286. * Array of default graphic settings.
  1287. * @protected
  1288. * @since 5.5.008 (2010-07-02)
  1289. */
  1290. protected $default_graphic_vars = array();
  1291. /**
  1292. * Array of XObjects.
  1293. * @protected
  1294. * @since 5.8.014 (2010-08-23)
  1295. */
  1296. protected $xobjects = array();
  1297. /**
  1298. * Boolean value true when we are inside an XObject.
  1299. * @protected
  1300. * @since 5.8.017 (2010-08-24)
  1301. */
  1302. protected $inxobj = false;
  1303. /**
  1304. * Current XObject ID.
  1305. * @protected
  1306. * @since 5.8.017 (2010-08-24)
  1307. */
  1308. protected $xobjid = '';
  1309. /**
  1310. * Percentage of character stretching.
  1311. * @protected
  1312. * @since 5.9.000 (2010-09-29)
  1313. */
  1314. protected $font_stretching = 100;
  1315. /**
  1316. * Increases or decreases the space between characters in a text by the specified amount (tracking).
  1317. * @protected
  1318. * @since 5.9.000 (2010-09-29)
  1319. */
  1320. protected $font_spacing = 0;
  1321. /**
  1322. * Array of no-write regions.
  1323. * ('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)
  1324. * @protected
  1325. * @since 5.9.003 (2010-10-14)
  1326. */
  1327. protected $page_regions = array();
  1328. /**
  1329. * Boolean value true when page region check is active.
  1330. * @protected
  1331. */
  1332. protected $check_page_regions = true;
  1333. /**
  1334. * Array of PDF layers data.
  1335. * @protected
  1336. * @since 5.9.102 (2011-07-13)
  1337. */
  1338. protected $pdflayers = array();
  1339. /**
  1340. * A dictionary of names and corresponding destinations (Dests key on document Catalog).
  1341. * @protected
  1342. * @since 5.9.097 (2011-06-23)
  1343. */
  1344. protected $dests = array();
  1345. /**
  1346. * Object ID for Named Destinations
  1347. * @protected
  1348. * @since 5.9.097 (2011-06-23)
  1349. */
  1350. protected $n_dests;
  1351. /**
  1352. * Embedded Files Names
  1353. * @protected
  1354. * @since 5.9.204 (2013-01-23)
  1355. */
  1356. protected $efnames = array();
  1357. /**
  1358. * Directory used for the last SVG image.
  1359. * @protected
  1360. * @since 5.0.000 (2010-05-05)
  1361. */
  1362. protected $svgdir = '';
  1363. /**
  1364. * Deafult unit of measure for SVG.
  1365. * @protected
  1366. * @since 5.0.000 (2010-05-02)
  1367. */
  1368. protected $svgunit = 'px';
  1369. /**
  1370. * Array of SVG gradients.
  1371. * @protected
  1372. * @since 5.0.000 (2010-05-02)
  1373. */
  1374. protected $svggradients = array();
  1375. /**
  1376. * ID of last SVG gradient.
  1377. * @protected
  1378. * @since 5.0.000 (2010-05-02)
  1379. */
  1380. protected $svggradientid = 0;
  1381. /**
  1382. * Boolean value true when in SVG defs group.
  1383. * @protected
  1384. * @since 5.0.000 (2010-05-02)
  1385. */
  1386. protected $svgdefsmode = false;
  1387. /**
  1388. * Array of SVG defs.
  1389. * @protected
  1390. * @since 5.0.000 (2010-05-02)
  1391. */
  1392. protected $svgdefs = array();
  1393. /**
  1394. * Boolean value true when in SVG clipPath tag.
  1395. * @protected
  1396. * @since 5.0.000 (2010-04-26)
  1397. */
  1398. protected $svgclipmode = false;
  1399. /**
  1400. * Array of SVG clipPath commands.
  1401. * @protected
  1402. * @since 5.0.000 (2010-05-02)
  1403. */
  1404. protected $svgclippaths = array();
  1405. /**
  1406. * Array of SVG clipPath tranformation matrix.
  1407. * @protected
  1408. * @since 5.8.022 (2010-08-31)
  1409. */
  1410. protected $svgcliptm = array();
  1411. /**
  1412. * ID of last SVG clipPath.
  1413. * @protected
  1414. * @since 5.0.000 (2010-05-02)
  1415. */
  1416. protected $svgclipid = 0;
  1417. /**
  1418. * SVG text.
  1419. * @protected
  1420. * @since 5.0.000 (2010-05-02)
  1421. */
  1422. protected $svgtext = '';
  1423. /**
  1424. * SVG text properties.
  1425. * @protected
  1426. * @since 5.8.013 (2010-08-23)
  1427. */
  1428. protected $svgtextmode = array();
  1429. /**
  1430. * Array of SVG properties.
  1431. * @protected
  1432. * @since 5.0.000 (2010-05-02)
  1433. */
  1434. protected $svgstyles = array(array(
  1435. 'alignment-baseline' => 'auto',
  1436. 'baseline-shift' => 'baseline',
  1437. 'clip' => 'auto',
  1438. 'clip-path' => 'none',
  1439. 'clip-rule' => 'nonzero',
  1440. 'color' => 'black',
  1441. 'color-interpolation' => 'sRGB',
  1442. 'color-interpolation-filters' => 'linearRGB',
  1443. 'color-profile' => 'auto',
  1444. 'color-rendering' => 'auto',
  1445. 'cursor' => 'auto',
  1446. 'direction' => 'ltr',
  1447. 'display' => 'inline',
  1448. 'dominant-baseline' => 'auto',
  1449. 'enable-background' => 'accumulate',
  1450. 'fill' => 'black',
  1451. 'fill-opacity' => 1,
  1452. 'fill-rule' => 'nonzero',
  1453. 'filter' => 'none',
  1454. 'flood-color' => 'black',
  1455. 'flood-opacity' => 1,
  1456. 'font' => '',
  1457. 'font-family' => 'helvetica',
  1458. 'font-size' => 'medium',
  1459. 'font-size-adjust' => 'none',
  1460. 'font-stretch' => 'normal',
  1461. 'font-style' => 'normal',
  1462. 'font-variant' => 'normal',
  1463. 'font-weight' => 'normal',
  1464. 'glyph-orientation-horizontal' => '0deg',
  1465. 'glyph-orientation-vertical' => 'auto',
  1466. 'image-rendering' => 'auto',
  1467. 'kerning' => 'auto',
  1468. 'letter-spacing' => 'normal',
  1469. 'lighting-color' => 'white',
  1470. 'marker' => '',
  1471. 'marker-end' => 'none',
  1472. 'marker-mid' => 'none',
  1473. 'marker-start' => 'none',
  1474. 'mask' => 'none',
  1475. 'opacity' => 1,
  1476. 'overflow' => 'auto',
  1477. 'pointer-events' => 'visiblePainted',
  1478. 'shape-rendering' => 'auto',
  1479. 'stop-color' => 'black',
  1480. 'stop-opacity' => 1,
  1481. 'stroke' => 'none',
  1482. 'stroke-dasharray' => 'none',
  1483. 'stroke-dashoffset' => 0,
  1484. 'stroke-linecap' => 'butt',
  1485. 'stroke-linejoin' => 'miter',
  1486. 'stroke-miterlimit' => 4,
  1487. 'stroke-opacity' => 1,
  1488. 'stroke-width' => 1,
  1489. 'text-anchor' => 'start',
  1490. 'text-decoration' => 'none',
  1491. 'text-rendering' => 'auto',
  1492. 'unicode-bidi' => 'normal',
  1493. 'visibility' => 'visible',
  1494. 'word-spacing' => 'normal',
  1495. 'writing-mode' => 'lr-tb',
  1496. 'text-color' => 'black',
  1497. 'transfmatrix' => array(1, 0, 0, 1, 0, 0)
  1498. ));
  1499. /**
  1500. * If true force sRGB color profile for all document.
  1501. * @protected
  1502. * @since 5.9.121 (2011-09-28)
  1503. */
  1504. protected $force_srgb = false;
  1505. /**
  1506. * If true set the document to PDF/A mode.
  1507. * @protected
  1508. * @since 5.9.121 (2011-09-27)
  1509. */
  1510. protected $pdfa_mode = false;
  1511. /**
  1512. * Document creation date-time
  1513. * @protected
  1514. * @since 5.9.152 (2012-03-22)
  1515. */
  1516. protected $doc_creation_timestamp;
  1517. /**
  1518. * Document modification date-time
  1519. * @protected
  1520. * @since 5.9.152 (2012-03-22)
  1521. */
  1522. protected $doc_modification_timestamp;
  1523. /**
  1524. * Custom XMP data.
  1525. * @protected
  1526. * @since 5.9.128 (2011-10-06)
  1527. */
  1528. protected $custom_xmp = '';
  1529. /**
  1530. * Overprint mode array.
  1531. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  1532. * @protected
  1533. * @since 5.9.152 (2012-03-23)
  1534. */
  1535. protected $overprint = array('OP' => false, 'op' => false, 'OPM' => 0);
  1536. /**
  1537. * Alpha mode array.
  1538. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  1539. * @protected
  1540. * @since 5.9.152 (2012-03-23)
  1541. */
  1542. protected $alpha = array('CA' => 1, 'ca' => 1, 'BM' => '/Normal', 'AIS' => false);
  1543. /**
  1544. * Define the page boundaries boxes to be set on document.
  1545. * @protected
  1546. * @since 5.9.152 (2012-03-23)
  1547. */
  1548. protected $page_boxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  1549. /**
  1550. * If true print TCPDF meta link.
  1551. * @protected
  1552. * @since 5.9.152 (2012-03-23)
  1553. */
  1554. protected $tcpdflink = true;
  1555. /**
  1556. * Cache array for computed GD gamma values.
  1557. * @protected
  1558. * @since 5.9.1632 (2012-06-05)
  1559. */
  1560. protected $gdgammacache = array();
  1561. //------------------------------------------------------------
  1562. // METHODS
  1563. //------------------------------------------------------------
  1564. /**
  1565. * This is the class constructor.
  1566. * It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).
  1567. *
  1568. * 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.
  1569. *
  1570. * @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>
  1571. * @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.
  1572. * @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().
  1573. * @param $unicode (boolean) TRUE means that the input text is unicode (default = true)
  1574. * @param $encoding (string) Charset encoding (used only when converting back html entities); default is UTF-8.
  1575. * @param $diskcache (boolean) If TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
  1576. * @param $pdfa (boolean) If TRUE set the document to PDF/A mode.
  1577. * @public
  1578. * @see getPageSizeFromFormat(), setPageFormat()
  1579. */
  1580. public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false) {
  1581. /* Set internal character encoding to ASCII */
  1582. if (function_exists('mb_internal_encoding') AND mb_internal_encoding()) {
  1583. $this->internal_encoding = mb_internal_encoding();
  1584. mb_internal_encoding('ASCII');
  1585. }
  1586. $this->font_obj_ids = array();
  1587. $this->page_obj_id = array();
  1588. $this->form_obj_id = array();
  1589. // set pdf/a mode
  1590. $this->pdfa_mode = $pdfa;
  1591. $this->force_srgb = false;
  1592. // set disk caching
  1593. $this->diskcache = $diskcache ? true : false;
  1594. // set language direction
  1595. $this->rtl = false;
  1596. $this->tmprtl = false;
  1597. // some checks
  1598. $this->_dochecks();
  1599. // initialization of properties
  1600. $this->isunicode = $unicode;
  1601. $this->page = 0;
  1602. $this->transfmrk[0] = array();
  1603. $this->pagedim = array();
  1604. $this->n = 2;
  1605. $this->buffer = '';
  1606. $this->pages = array();
  1607. $this->state = 0;
  1608. $this->fonts = array();
  1609. $this->FontFiles = array();
  1610. $this->diffs = array();
  1611. $this->images = array();
  1612. $this->links = array();
  1613. $this->gradients = array();
  1614. $this->InFooter = false;
  1615. $this->lasth = 0;
  1616. $this->FontFamily = defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica';
  1617. $this->FontStyle = '';
  1618. $this->FontSizePt = 12;
  1619. $this->underline = false;
  1620. $this->overline = false;
  1621. $this->linethrough = false;
  1622. $this->DrawColor = '0 G';
  1623. $this->FillColor = '0 g';
  1624. $this->TextColor = '0 g';
  1625. $this->ColorFlag = false;
  1626. $this->pdflayers = array();
  1627. // encryption values
  1628. $this->encrypted = false;
  1629. $this->last_enc_key = '';
  1630. // standard Unicode fonts
  1631. $this->CoreFonts = array(
  1632. 'courier'=>'Courier',
  1633. 'courierB'=>'Courier-Bold',
  1634. 'courierI'=>'Courier-Oblique',
  1635. 'courierBI'=>'Courier-BoldOblique',
  1636. 'helvetica'=>'Helvetica',
  1637. 'helveticaB'=>'Helvetica-Bold',
  1638. 'helveticaI'=>'Helvetica-Oblique',
  1639. 'helveticaBI'=>'Helvetica-BoldOblique',
  1640. 'times'=>'Times-Roman',
  1641. 'timesB'=>'Times-Bold',
  1642. 'timesI'=>'Times-Italic',
  1643. 'timesBI'=>'Times-BoldItalic',
  1644. 'symbol'=>'Symbol',
  1645. 'zapfdingbats'=>'ZapfDingbats'
  1646. );
  1647. // set scale factor
  1648. $this->setPageUnit($unit);
  1649. // set page format and orientation
  1650. $this->setPageFormat($format, $orientation);
  1651. // page margins (1 cm)
  1652. $margin = 28.35 / $this->k;
  1653. $this->SetMargins($margin, $margin);
  1654. $this->clMargin = $this->lMargin;
  1655. $this->crMargin = $this->rMargin;
  1656. // internal cell padding
  1657. $cpadding = $margin / 10;
  1658. $this->setCellPaddings($cpadding, 0, $cpadding, 0);
  1659. // cell margins
  1660. $this->setCellMargins(0, 0, 0, 0);
  1661. // line width (0.2 mm)
  1662. $this->LineWidth = 0.57 / $this->k;
  1663. $this->linestyleWidth = sprintf('%F w', ($this->LineWidth * $this->k));
  1664. $this->linestyleCap = '0 J';
  1665. $this->linestyleJoin = '0 j';
  1666. $this->linestyleDash = '[] 0 d';
  1667. // automatic page break
  1668. $this->SetAutoPageBreak(true, (2 * $margin));
  1669. // full width display mode
  1670. $this->SetDisplayMode('fullwidth');
  1671. // compression
  1672. $this->SetCompression();
  1673. // set default PDF version number
  1674. $this->setPDFVersion();
  1675. $this->tcpdflink = true;
  1676. $this->encoding = $encoding;
  1677. $this->HREF = array();
  1678. $this->getFontsList();
  1679. $this->fgcolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1680. $this->strokecolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1681. $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255);
  1682. $this->extgstates = array();
  1683. $this->setTextShadow();
  1684. // user's rights
  1685. $this->sign = false;
  1686. $this->ur['enabled'] = false;
  1687. $this->ur['document'] = '/FullSave';
  1688. $this->ur['annots'] = '/Create/Delete/Modify/Copy/Import/Export';
  1689. $this->ur['form'] = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1690. $this->ur['signature'] = '/Modify';
  1691. $this->ur['ef'] = '/Create/Delete/Modify/Import';
  1692. $this->ur['formex'] = '';
  1693. $this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0', 'name' => 'Signature');
  1694. $this->empty_signature_appearance = array();
  1695. // set default JPEG quality
  1696. $this->jpeg_quality = 75;
  1697. // initialize some settings
  1698. TCPDF_FONTS::utf8Bidi(array(''), '', false, $this->isunicode, $this->CurrentFont);
  1699. // set default font
  1700. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  1701. // check if PCRE Unicode support is enabled
  1702. if ($this->isunicode AND (@preg_match('/\pL/u', 'a') == 1)) {
  1703. // PCRE unicode support is turned ON
  1704. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  1705. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  1706. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  1707. //$this->setSpacesRE('/[^\S\P{Z}\P{Lo}\xa0]/u');
  1708. $this->setSpacesRE('/[^\S\P{Z}\xa0]/u');
  1709. } else {
  1710. // PCRE unicode support is turned OFF
  1711. $this->setSpacesRE('/[^\S\xa0]/');
  1712. }
  1713. $this->default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1714. // set file ID for trailer
  1715. $serformat = (is_array($format) ? serialize($format) : $format);
  1716. $this->file_id = md5(TCPDF_STATIC::getRandomSeed('TCPDF'.$orientation.$unit.$serformat.$encoding));
  1717. // set document creation and modification timestamp
  1718. $this->doc_creation_timestamp = time();
  1719. $this->doc_modification_timestamp = $this->doc_creation_timestamp;
  1720. // get default graphic vars
  1721. $this->default_graphic_vars = $this->getGraphicVars();
  1722. $this->header_xobj_autoreset = false;
  1723. $this->custom_xmp = '';
  1724. }
  1725. /**
  1726. * Default destructor.
  1727. * @public
  1728. * @since 1.53.0.TC016
  1729. */
  1730. public function __destruct() {
  1731. // restore internal encoding
  1732. if (isset($this->internal_encoding) AND !empty($this->internal_encoding)) {
  1733. mb_internal_encoding($this->internal_encoding);
  1734. }
  1735. // unset all class variables
  1736. $this->_destroy(true);
  1737. }
  1738. /**
  1739. * Set the units of measure for the document.
  1740. * @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.
  1741. * @public
  1742. * @since 3.0.015 (2008-06-06)
  1743. */
  1744. public function setPageUnit($unit) {
  1745. $unit = strtolower($unit);
  1746. //Set scale factor
  1747. switch ($unit) {
  1748. // points
  1749. case 'px':
  1750. case 'pt': {
  1751. $this->k = 1;
  1752. break;
  1753. }
  1754. // millimeters
  1755. case 'mm': {
  1756. $this->k = $this->dpi / 25.4;
  1757. break;
  1758. }
  1759. // centimeters
  1760. case 'cm': {
  1761. $this->k = $this->dpi / 2.54;
  1762. break;
  1763. }
  1764. // inches
  1765. case 'in': {
  1766. $this->k = $this->dpi;
  1767. break;
  1768. }
  1769. // unsupported unit
  1770. default : {
  1771. $this->Error('Incorrect unit: '.$unit);
  1772. break;
  1773. }
  1774. }
  1775. $this->pdfunit = $unit;
  1776. if (isset($this->CurOrientation)) {
  1777. $this->setPageOrientation($this->CurOrientation);
  1778. }
  1779. }
  1780. /**
  1781. * Change the format of the current page
  1782. * @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 numners (width, height) or an array containing the following measures and options:<ul>
  1783. * <li>['format'] = page format name (one of the above);</li>
  1784. * <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>
  1785. * <li>['PZ'] : The page's preferred zoom (magnification) factor.</li>
  1786. * <li>['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed:</li>
  1787. * <li>['MediaBox']['llx'] : lower-left x coordinate in points</li>
  1788. * <li>['MediaBox']['lly'] : lower-left y coordinate in points</li>
  1789. * <li>['MediaBox']['urx'] : upper-right x coordinate in points</li>
  1790. * <li>['MediaBox']['ury'] : upper-right y coordinate in points</li>
  1791. * <li>['CropBox'] : the visible region of default user space:</li>
  1792. * <li>['CropBox']['llx'] : lower-left x coordinate in points</li>
  1793. * <li>['CropBox']['lly'] : lower-left y coordinate in points</li>
  1794. * <li>['CropBox']['urx'] : upper-right x coordinate in points</li>
  1795. * <li>['CropBox']['ury'] : upper-right y coordinate in points</li>
  1796. * <li>['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment:</li>
  1797. * <li>['BleedBox']['llx'] : lower-left x coordinate in points</li>
  1798. * <li>['BleedBox']['lly'] : lower-left y coordinate in points</li>
  1799. * <li>['BleedBox']['urx'] : upper-right x coordinate in points</li>
  1800. * <li>['BleedBox']['ury'] : upper-right y coordinate in points</li>
  1801. * <li>['TrimBox'] : the intended dimensions of the finished page after trimming:</li>
  1802. * <li>['TrimBox']['llx'] : lower-left x coordinate in points</li>
  1803. * <li>['TrimBox']['lly'] : lower-left y coordinate in points</li>
  1804. * <li>['TrimBox']['urx'] : upper-right x coordinate in points</li>
  1805. * <li>['TrimBox']['ury'] : upper-right y coordinate in points</li>
  1806. * <li>['ArtBox'] : the extent of the page's meaningful content:</li>
  1807. * <li>['ArtBox']['llx'] : lower-left x coordinate in points</li>
  1808. * <li>['ArtBox']['lly'] : lower-left y coordinate in points</li>
  1809. * <li>['ArtBox']['urx'] : upper-right x coordinate in points</li>
  1810. * <li>['ArtBox']['ury'] : upper-right y coordinate in points</li>
  1811. * <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>
  1812. * <li>['BoxColorInfo'][BOXTYPE]['C'] : an array of three numbers in the range 0-255, representing the components in the DeviceRGB colour space.</li>
  1813. * <li>['BoxColorInfo'][BOXTYPE]['W'] : the guideline width in default user units</li>
  1814. * <li>['BoxColorInfo'][BOXTYPE]['S'] : the guideline style: S = Solid; D = Dashed</li>
  1815. * <li>['BoxColorInfo'][BOXTYPE]['D'] : dash array defining a pattern of dashes and gaps to be used in drawing dashed guidelines</li>
  1816. * <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>
  1817. * <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>
  1818. * <li>['trans']['S'] : transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li>
  1819. * <li>['trans']['D'] : The duration of the transition effect, in seconds.</li>
  1820. * <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>
  1821. * <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>
  1822. * <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>
  1823. * <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>
  1824. * <li>['trans']['B'] : (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li>
  1825. * </ul>
  1826. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul>
  1827. * <li>P or Portrait (default)</li>
  1828. * <li>L or Landscape</li>
  1829. * <li>'' (empty string) for automatic orientation</li>
  1830. * </ul>
  1831. * @protected
  1832. * @since 3.0.015 (2008-06-06)
  1833. * @see getPageSizeFromFormat()
  1834. */
  1835. protected function setPageFormat($format, $orientation='P') {
  1836. if (!empty($format) AND isset($this->pagedim[$this->page])) {
  1837. // remove inherited values
  1838. unset($this->pagedim[$this->page]);
  1839. }
  1840. if (is_string($format)) {
  1841. // get page measures from format name
  1842. $pf = TCPDF_STATIC::getPageSizeFromFormat($format);
  1843. $this->fwPt = $pf[0];
  1844. $this->fhPt = $pf[1];
  1845. } else {
  1846. // the boundaries of the physical medium on which the page shall be displayed or printed
  1847. if (isset($format['MediaBox'])) {
  1848. $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);
  1849. $this->fwPt = (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k);
  1850. $this->fhPt = (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k);
  1851. } else {
  1852. if (isset($format[0]) AND is_numeric($format[0]) AND isset($format[1]) AND is_numeric($format[1])) {
  1853. $pf = array(($format[0] * $this->k), ($format[1] * $this->k));
  1854. } else {
  1855. if (!isset($format['format'])) {
  1856. // default value
  1857. $format['format'] = 'A4';
  1858. }
  1859. $pf = TCPDF_STATIC::getPageSizeFromFormat($format['format']);
  1860. }
  1861. $this->fwPt = $pf[0];
  1862. $this->fhPt = $pf[1];
  1863. $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true, $this->k, $this->pagedim);
  1864. }
  1865. // the visible region of default user space
  1866. if (isset($format['CropBox'])) {
  1867. $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);
  1868. }
  1869. // the region to which the contents of the page shall be clipped when output in a production environment
  1870. if (isset($format['BleedBox'])) {
  1871. $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);
  1872. }
  1873. // the intended dimensions of the finished page after trimming
  1874. if (isset($format['TrimBox'])) {
  1875. $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);
  1876. }
  1877. // the page's meaningful content (including potential white space)
  1878. if (isset($format['ArtBox'])) {
  1879. $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);
  1880. }
  1881. // specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for the various page boundaries
  1882. if (isset($format['BoxColorInfo'])) {
  1883. $this->pagedim[$this->page]['BoxColorInfo'] = $format['BoxColorInfo'];
  1884. }
  1885. if (isset($format['Rotate']) AND (($format['Rotate'] % 90) == 0)) {
  1886. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  1887. $this->pagedim[$this->page]['Rotate'] = intval($format['Rotate']);
  1888. }
  1889. if (isset($format['PZ'])) {
  1890. // The page's preferred zoom (magnification) factor
  1891. $this->pagedim[$this->page]['PZ'] = floatval($format['PZ']);
  1892. }
  1893. if (isset($format['trans'])) {
  1894. // The style and duration of the visual transition to use when moving from another page to the given page during a presentation
  1895. if (isset($format['trans']['Dur'])) {
  1896. // The page's display duration
  1897. $this->pagedim[$this->page]['trans']['Dur'] = floatval($format['trans']['Dur']);
  1898. }
  1899. $stansition_styles = array('Split', 'Blinds', 'Box', 'Wipe', 'Dissolve', 'Glitter', 'R', 'Fly', 'Push', 'Cover', 'Uncover', 'Fade');
  1900. if (isset($format['trans']['S']) AND in_array($format['trans']['S'], $stansition_styles)) {
  1901. // The transition style that shall be used when moving to this page from another during a presentation
  1902. $this->pagedim[$this->page]['trans']['S'] = $format['trans']['S'];
  1903. $valid_effect = array('Split', 'Blinds');
  1904. $valid_vals = array('H', 'V');
  1905. if (isset($format['trans']['Dm']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['Dm'], $valid_vals)) {
  1906. $this->pagedim[$this->page]['trans']['Dm'] = $format['trans']['Dm'];
  1907. }
  1908. $valid_effect = array('Split', 'Box', 'Fly');
  1909. $valid_vals = array('I', 'O');
  1910. if (isset($format['trans']['M']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['M'], $valid_vals)) {
  1911. $this->pagedim[$this->page]['trans']['M'] = $format['trans']['M'];
  1912. }
  1913. $valid_effect = array('Wipe', 'Glitter', 'Fly', 'Cover', 'Uncover', 'Push');
  1914. if (isset($format['trans']['Di']) AND in_array($format['trans']['S'], $valid_effect)) {
  1915. if (((($format['trans']['Di'] == 90) OR ($format['trans']['Di'] == 180)) AND ($format['trans']['S'] == 'Wipe'))
  1916. OR (($format['trans']['Di'] == 315) AND ($format['trans']['S'] == 'Glitter'))
  1917. OR (($format['trans']['Di'] == 0) OR ($format['trans']['Di'] == 270))) {
  1918. $this->pagedim[$this->page]['trans']['Di'] = intval($format['trans']['Di']);
  1919. }
  1920. }
  1921. if (isset($format['trans']['SS']) AND ($format['trans']['S'] == 'Fly')) {
  1922. $this->pagedim[$this->page]['trans']['SS'] = floatval($format['trans']['SS']);
  1923. }
  1924. if (isset($format['trans']['B']) AND ($format['trans']['B'] === true) AND ($format['trans']['S'] == 'Fly')) {
  1925. $this->pagedim[$this->page]['trans']['B'] = 'true';
  1926. }
  1927. } else {
  1928. $this->pagedim[$this->page]['trans']['S'] = 'R';
  1929. }
  1930. if (isset($format['trans']['D'])) {
  1931. // The duration of the transition effect, in seconds
  1932. $this->pagedim[$this->page]['trans']['D'] = floatval($format['trans']['D']);
  1933. } else {
  1934. $this->pagedim[$this->page]['trans']['D'] = 1;
  1935. }
  1936. }
  1937. }
  1938. $this->setPageOrientation($orientation);
  1939. }
  1940. /**
  1941. * Set page orientation.
  1942. * @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>
  1943. * @param $autopagebreak (boolean) Boolean indicating if auto-page-break mode should be on or off.
  1944. * @param $bottommargin (float) bottom margin of the page.
  1945. * @public
  1946. * @since 3.0.015 (2008-06-06)
  1947. */
  1948. public function setPageOrientation($orientation, $autopagebreak='', $bottommargin='') {
  1949. if (!isset($this->pagedim[$this->page]['MediaBox'])) {
  1950. // the boundaries of the physical medium on which the page shall be displayed or printed
  1951. $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true, $this->k, $this->pagedim);
  1952. }
  1953. if (!isset($this->pagedim[$this->page]['CropBox'])) {
  1954. // the visible region of default user space
  1955. $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);
  1956. }
  1957. if (!isset($this->pagedim[$this->page]['BleedBox'])) {
  1958. // the region to which the contents of the page shall be clipped when output in a production environment
  1959. $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);
  1960. }
  1961. if (!isset($this->pagedim[$this->page]['TrimBox'])) {
  1962. // the intended dimensions of the finished page after trimming
  1963. $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);
  1964. }
  1965. if (!isset($this->pagedim[$this->page]['ArtBox'])) {
  1966. // the page's meaningful content (including potential white space)
  1967. $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);
  1968. }
  1969. if (!isset($this->pagedim[$this->page]['Rotate'])) {
  1970. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  1971. $this->pagedim[$this->page]['Rotate'] = 0;
  1972. }
  1973. if (!isset($this->pagedim[$this->page]['PZ'])) {
  1974. // The page's preferred zoom (magnification) factor
  1975. $this->pagedim[$this->page]['PZ'] = 1;
  1976. }
  1977. if ($this->fwPt > $this->fhPt) {
  1978. // landscape
  1979. $default_orientation = 'L';
  1980. } else {
  1981. // portrait
  1982. $default_orientation = 'P';
  1983. }
  1984. $valid_orientations = array('P', 'L');
  1985. if (empty($orientation)) {
  1986. $orientation = $default_orientation;
  1987. } else {
  1988. $orientation = strtoupper($orientation{0});
  1989. }
  1990. if (in_array($orientation, $valid_orientations) AND ($orientation != $default_orientation)) {
  1991. $this->CurOrientation = $orientation;
  1992. $this->wPt = $this->fhPt;
  1993. $this->hPt = $this->fwPt;
  1994. } else {
  1995. $this->CurOrientation = $default_orientation;
  1996. $this->wPt = $this->fwPt;
  1997. $this->hPt = $this->fhPt;
  1998. }
  1999. if ((abs($this->pagedim[$this->page]['MediaBox']['urx'] - $this->hPt) < $this->feps) AND (abs($this->pagedim[$this->page]['MediaBox']['ury'] - $this->wPt) < $this->feps)){
  2000. // swap X and Y coordinates (change page orientation)
  2001. $this->pagedim = TCPDF_STATIC::swapPageBoxCoordinates($this->page, $this->pagedim);
  2002. }
  2003. $this->w = ($this->wPt / $this->k);
  2004. $this->h = ($this->hPt / $this->k);
  2005. if (TCPDF_STATIC::empty_string($autopagebreak)) {
  2006. if (isset($this->AutoPageBreak)) {
  2007. $autopagebreak = $this->AutoPageBreak;
  2008. } else {
  2009. $autopagebreak = true;
  2010. }
  2011. }
  2012. if (TCPDF_STATIC::empty_string($bottommargin)) {
  2013. if (isset($this->bMargin)) {
  2014. $bottommargin = $this->bMargin;
  2015. } else {
  2016. // default value = 2 cm
  2017. $bottommargin = 2 * 28.35 / $this->k;
  2018. }
  2019. }
  2020. $this->SetAutoPageBreak($autopagebreak, $bottommargin);
  2021. // store page dimensions
  2022. $this->pagedim[$this->page]['w'] = $this->wPt;
  2023. $this->pagedim[$this->page]['h'] = $this->hPt;
  2024. $this->pagedim[$this->page]['wk'] = $this->w;
  2025. $this->pagedim[$this->page]['hk'] = $this->h;
  2026. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  2027. $this->pagedim[$this->page]['bm'] = $bottommargin;
  2028. $this->pagedim[$this->page]['lm'] = $this->lMargin;
  2029. $this->pagedim[$this->page]['rm'] = $this->rMargin;
  2030. $this->pagedim[$this->page]['pb'] = $autopagebreak;
  2031. $this->pagedim[$this->page]['or'] = $this->CurOrientation;
  2032. $this->pagedim[$this->page]['olm'] = $this->original_lMargin;
  2033. $this->pagedim[$this->page]['orm'] = $this->original_rMargin;
  2034. }
  2035. /**
  2036. * Set regular expression to detect withespaces or word separators.
  2037. * The pattern delimiter must be the forward-slash character "/".
  2038. * Some example patterns are:
  2039. * <pre>
  2040. * Non-Unicode or missing PCRE unicode support: "/[^\S\xa0]/"
  2041. * Unicode and PCRE unicode support: "/[^\S\P{Z}\xa0]/u"
  2042. * Unicode and PCRE unicode support in Chinese mode: "/[^\S\P{Z}\P{Lo}\xa0]/u"
  2043. * if PCRE unicode support is turned ON ("\P" is the negate class of "\p"):
  2044. * "\p{Z}" or "\p{Separator}": any kind of Unicode whitespace or invisible separator.
  2045. * "\p{Lo}" or "\p{Other_Letter}": a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  2046. * "\p{Lo}" is needed for Chinese characters because are packed next to each other without spaces in between.
  2047. * </pre>
  2048. * @param $re (string) regular expression (leave empty for default).
  2049. * @public
  2050. * @since 4.6.016 (2009-06-15)
  2051. */
  2052. public function setSpacesRE($re='/[^\S\xa0]/') {
  2053. $this->re_spaces = $re;
  2054. $re_parts = explode('/', $re);
  2055. // get pattern parts
  2056. $this->re_space = array();
  2057. if (isset($re_parts[1]) AND !empty($re_parts[1])) {
  2058. $this->re_space['p'] = $re_parts[1];
  2059. } else {
  2060. $this->re_space['p'] = '[\s]';
  2061. }
  2062. // set pattern modifiers
  2063. if (isset($re_parts[2]) AND !empty($re_parts[2])) {
  2064. $this->re_space['m'] = $re_parts[2];
  2065. } else {
  2066. $this->re_space['m'] = '';
  2067. }
  2068. }
  2069. /**
  2070. * Enable or disable Right-To-Left language mode
  2071. * @param $enable (Boolean) if true enable Right-To-Left language mode.
  2072. * @param $resetx (Boolean) if true reset the X position on direction change.
  2073. * @public
  2074. * @since 2.0.000 (2008-01-03)
  2075. */
  2076. public function setRTL($enable, $resetx=true) {
  2077. $enable = $enable ? true : false;
  2078. $resetx = ($resetx AND ($enable != $this->rtl));
  2079. $this->rtl = $enable;
  2080. $this->tmprtl = false;
  2081. if ($resetx) {
  2082. $this->Ln(0);
  2083. }
  2084. }
  2085. /**
  2086. * Return the RTL status
  2087. * @return boolean
  2088. * @public
  2089. * @since 4.0.012 (2008-07-24)
  2090. */
  2091. public function getRTL() {
  2092. return $this->rtl;
  2093. }
  2094. /**
  2095. * Force temporary RTL language direction
  2096. * @param $mode (mixed) can be false, 'L' for LTR or 'R' for RTL
  2097. * @public
  2098. * @since 2.1.000 (2008-01-09)
  2099. */
  2100. public function setTempRTL($mode) {
  2101. $newmode = false;
  2102. switch (strtoupper($mode)) {
  2103. case 'LTR':
  2104. case 'L': {
  2105. if ($this->rtl) {
  2106. $newmode = 'L';
  2107. }
  2108. break;
  2109. }
  2110. case 'RTL':
  2111. case 'R': {
  2112. if (!$this->rtl) {
  2113. $newmode = 'R';
  2114. }
  2115. break;
  2116. }
  2117. case false:
  2118. default: {
  2119. $newmode = false;
  2120. break;
  2121. }
  2122. }
  2123. $this->tmprtl = $newmode;
  2124. }
  2125. /**
  2126. * Return the current temporary RTL status
  2127. * @return boolean
  2128. * @public
  2129. * @since 4.8.014 (2009-11-04)
  2130. */
  2131. public function isRTLTextDir() {
  2132. return ($this->rtl OR ($this->tmprtl == 'R'));
  2133. }
  2134. /**
  2135. * Set the last cell height.
  2136. * @param $h (float) cell height.
  2137. * @author Nicola Asuni
  2138. * @public
  2139. * @since 1.53.0.TC034
  2140. */
  2141. public function setLastH($h) {
  2142. $this->lasth = $h;
  2143. }
  2144. /**
  2145. * Return the cell height
  2146. * @param $fontsize (int) Font size in internal units
  2147. * @public
  2148. */
  2149. public function getCellHeight($fontsize) {
  2150. return round((($fontsize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B']), 3);
  2151. }
  2152. /**
  2153. * Reset the last cell height.
  2154. * @public
  2155. * @since 5.9.000 (2010-10-03)
  2156. */
  2157. public function resetLastH() {
  2158. $this->lasth = $this->getCellHeight($this->FontSize);
  2159. }
  2160. /**
  2161. * Get the last cell height.
  2162. * @return last cell height
  2163. * @public
  2164. * @since 4.0.017 (2008-08-05)
  2165. */
  2166. public function getLastH() {
  2167. return $this->lasth;
  2168. }
  2169. /**
  2170. * Set the adjusting factor to convert pixels to user units.
  2171. * @param $scale (float) adjusting factor to convert pixels to user units.
  2172. * @author Nicola Asuni
  2173. * @public
  2174. * @since 1.5.2
  2175. */
  2176. public function setImageScale($scale) {
  2177. $this->imgscale = $scale;
  2178. }
  2179. /**
  2180. * Returns the adjusting factor to convert pixels to user units.
  2181. * @return float adjusting factor to convert pixels to user units.
  2182. * @author Nicola Asuni
  2183. * @public
  2184. * @since 1.5.2
  2185. */
  2186. public function getImageScale() {
  2187. return $this->imgscale;
  2188. }
  2189. /**
  2190. * Returns an array of page dimensions:
  2191. * <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>
  2192. * @param $pagenum (int) page number (empty = current page)
  2193. * @return array of page dimensions.
  2194. * @author Nicola Asuni
  2195. * @public
  2196. * @since 4.5.027 (2009-03-16)
  2197. */
  2198. public function getPageDimensions($pagenum='') {
  2199. if (empty($pagenum)) {
  2200. $pagenum = $this->page;
  2201. }
  2202. return $this->pagedim[$pagenum];
  2203. }
  2204. /**
  2205. * Returns the page width in units.
  2206. * @param $pagenum (int) page number (empty = current page)
  2207. * @return int page width.
  2208. * @author Nicola Asuni
  2209. * @public
  2210. * @since 1.5.2
  2211. * @see getPageDimensions()
  2212. */
  2213. public function getPageWidth($pagenum='') {
  2214. if (empty($pagenum)) {
  2215. return $this->w;
  2216. }
  2217. return $this->pagedim[$pagenum]['w'];
  2218. }
  2219. /**
  2220. * Returns the page height in units.
  2221. * @param $pagenum (int) page number (empty = current page)
  2222. * @return int page height.
  2223. * @author Nicola Asuni
  2224. * @public
  2225. * @since 1.5.2
  2226. * @see getPageDimensions()
  2227. */
  2228. public function getPageHeight($pagenum='') {
  2229. if (empty($pagenum)) {
  2230. return $this->h;
  2231. }
  2232. return $this->pagedim[$pagenum]['h'];
  2233. }
  2234. /**
  2235. * Returns the page break margin.
  2236. * @param $pagenum (int) page number (empty = current page)
  2237. * @return int page break margin.
  2238. * @author Nicola Asuni
  2239. * @public
  2240. * @since 1.5.2
  2241. * @see getPageDimensions()
  2242. */
  2243. public function getBreakMargin($pagenum='') {
  2244. if (empty($pagenum)) {
  2245. return $this->bMargin;
  2246. }
  2247. return $this->pagedim[$pagenum]['bm'];
  2248. }
  2249. /**
  2250. * Returns the scale factor (number of points in user unit).
  2251. * @return int scale factor.
  2252. * @author Nicola Asuni
  2253. * @public
  2254. * @since 1.5.2
  2255. */
  2256. public function getScaleFactor() {
  2257. return $this->k;
  2258. }
  2259. /**
  2260. * Defines the left, top and right margins.
  2261. * @param $left (float) Left margin.
  2262. * @param $top (float) Top margin.
  2263. * @param $right (float) Right margin. Default value is the left one.
  2264. * @param $keepmargins (boolean) if true overwrites the default page margins
  2265. * @public
  2266. * @since 1.0
  2267. * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  2268. */
  2269. public function SetMargins($left, $top, $right=-1, $keepmargins=false) {
  2270. //Set left, top and right margins
  2271. $this->lMargin = $left;
  2272. $this->tMargin = $top;
  2273. if ($right == -1) {
  2274. $right = $left;
  2275. }
  2276. $this->rMargin = $right;
  2277. if ($keepmargins) {
  2278. // overwrite original values
  2279. $this->original_lMargin = $this->lMargin;
  2280. $this->original_rMargin = $this->rMargin;
  2281. }
  2282. }
  2283. /**
  2284. * 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.
  2285. * @param $margin (float) The margin.
  2286. * @public
  2287. * @since 1.4
  2288. * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2289. */
  2290. public function SetLeftMargin($margin) {
  2291. //Set left margin
  2292. $this->lMargin = $margin;
  2293. if (($this->page > 0) AND ($this->x < $margin)) {
  2294. $this->x = $margin;
  2295. }
  2296. }
  2297. /**
  2298. * Defines the top margin. The method can be called before creating the first page.
  2299. * @param $margin (float) The margin.
  2300. * @public
  2301. * @since 1.5
  2302. * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2303. */
  2304. public function SetTopMargin($margin) {
  2305. //Set top margin
  2306. $this->tMargin = $margin;
  2307. if (($this->page > 0) AND ($this->y < $margin)) {
  2308. $this->y = $margin;
  2309. }
  2310. }
  2311. /**
  2312. * Defines the right margin. The method can be called before creating the first page.
  2313. * @param $margin (float) The margin.
  2314. * @public
  2315. * @since 1.5
  2316. * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  2317. */
  2318. public function SetRightMargin($margin) {
  2319. $this->rMargin = $margin;
  2320. if (($this->page > 0) AND ($this->x > ($this->w - $margin))) {
  2321. $this->x = $this->w - $margin;
  2322. }
  2323. }
  2324. /**
  2325. * Set the same internal Cell padding for top, right, bottom, left-
  2326. * @param $pad (float) internal padding.
  2327. * @public
  2328. * @since 2.1.000 (2008-01-09)
  2329. * @see getCellPaddings(), setCellPaddings()
  2330. */
  2331. public function SetCellPadding($pad) {
  2332. if ($pad >= 0) {
  2333. $this->cell_padding['L'] = $pad;
  2334. $this->cell_padding['T'] = $pad;
  2335. $this->cell_padding['R'] = $pad;
  2336. $this->cell_padding['B'] = $pad;
  2337. }
  2338. }
  2339. /**
  2340. * Set the internal Cell paddings.
  2341. * @param $left (float) left padding
  2342. * @param $top (float) top padding
  2343. * @param $right (float) right padding
  2344. * @param $bottom (float) bottom padding
  2345. * @public
  2346. * @since 5.9.000 (2010-10-03)
  2347. * @see getCellPaddings(), SetCellPadding()
  2348. */
  2349. public function setCellPaddings($left='', $top='', $right='', $bottom='') {
  2350. if (($left !== '') AND ($left >= 0)) {
  2351. $this->cell_padding['L'] = $left;
  2352. }
  2353. if (($top !== '') AND ($top >= 0)) {
  2354. $this->cell_padding['T'] = $top;
  2355. }
  2356. if (($right !== '') AND ($right >= 0)) {
  2357. $this->cell_padding['R'] = $right;
  2358. }
  2359. if (($bottom !== '') AND ($bottom >= 0)) {
  2360. $this->cell_padding['B'] = $bottom;
  2361. }
  2362. }
  2363. /**
  2364. * Get the internal Cell padding array.
  2365. * @return array of padding values
  2366. * @public
  2367. * @since 5.9.000 (2010-10-03)
  2368. * @see setCellPaddings(), SetCellPadding()
  2369. */
  2370. public function getCellPaddings() {
  2371. return $this->cell_padding;
  2372. }
  2373. /**
  2374. * Set the internal Cell margins.
  2375. * @param $left (float) left margin
  2376. * @param $top (float) top margin
  2377. * @param $right (float) right margin
  2378. * @param $bottom (float) bottom margin
  2379. * @public
  2380. * @since 5.9.000 (2010-10-03)
  2381. * @see getCellMargins()
  2382. */
  2383. public function setCellMargins($left='', $top='', $right='', $bottom='') {
  2384. if (($left !== '') AND ($left >= 0)) {
  2385. $this->cell_margin['L'] = $left;
  2386. }
  2387. if (($top !== '') AND ($top >= 0)) {
  2388. $this->cell_margin['T'] = $top;
  2389. }
  2390. if (($right !== '') AND ($right >= 0)) {
  2391. $this->cell_margin['R'] = $right;
  2392. }
  2393. if (($bottom !== '') AND ($bottom >= 0)) {
  2394. $this->cell_margin['B'] = $bottom;
  2395. }
  2396. }
  2397. /**
  2398. * Get the internal Cell margin array.
  2399. * @return array of margin values
  2400. * @public
  2401. * @since 5.9.000 (2010-10-03)
  2402. * @see setCellMargins()
  2403. */
  2404. public function getCellMargins() {
  2405. return $this->cell_margin;
  2406. }
  2407. /**
  2408. * Adjust the internal Cell padding array to take account of the line width.
  2409. * @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)))
  2410. * @return array of adjustments
  2411. * @public
  2412. * @since 5.9.000 (2010-10-03)
  2413. */
  2414. protected function adjustCellPadding($brd=0) {
  2415. if (empty($brd)) {
  2416. return;
  2417. }
  2418. if (is_string($brd)) {
  2419. // convert string to array
  2420. $slen = strlen($brd);
  2421. $newbrd = array();
  2422. for ($i = 0; $i < $slen; ++$i) {
  2423. $newbrd[$brd[$i]] = true;
  2424. }
  2425. $brd = $newbrd;
  2426. } elseif (($brd === 1) OR ($brd === true) OR (is_numeric($brd) AND (intval($brd) > 0))) {
  2427. $brd = array('LRTB' => true);
  2428. }
  2429. if (!is_array($brd)) {
  2430. return;
  2431. }
  2432. // store current cell padding
  2433. $cp = $this->cell_padding;
  2434. // select border mode
  2435. if (isset($brd['mode'])) {
  2436. $mode = $brd['mode'];
  2437. unset($brd['mode']);
  2438. } else {
  2439. $mode = 'normal';
  2440. }
  2441. // process borders
  2442. foreach ($brd as $border => $style) {
  2443. $line_width = $this->LineWidth;
  2444. if (is_array($style) AND isset($style['width'])) {
  2445. // get border width
  2446. $line_width = $style['width'];
  2447. }
  2448. $adj = 0; // line width inside the cell
  2449. switch ($mode) {
  2450. case 'ext': {
  2451. $adj = 0;
  2452. break;
  2453. }
  2454. case 'int': {
  2455. $adj = $line_width;
  2456. break;
  2457. }
  2458. case 'normal':
  2459. default: {
  2460. $adj = ($line_width / 2);
  2461. break;
  2462. }
  2463. }
  2464. // correct internal cell padding if required to avoid overlap between text and lines
  2465. if ((strpos($border,'T') !== false) AND ($this->cell_padding['T'] < $adj)) {
  2466. $this->cell_padding['T'] = $adj;
  2467. }
  2468. if ((strpos($border,'R') !== false) AND ($this->cell_padding['R'] < $adj)) {
  2469. $this->cell_padding['R'] = $adj;
  2470. }
  2471. if ((strpos($border,'B') !== false) AND ($this->cell_padding['B'] < $adj)) {
  2472. $this->cell_padding['B'] = $adj;
  2473. }
  2474. if ((strpos($border,'L') !== false) AND ($this->cell_padding['L'] < $adj)) {
  2475. $this->cell_padding['L'] = $adj;
  2476. }
  2477. }
  2478. 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']));
  2479. }
  2480. /**
  2481. * 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.
  2482. * @param $auto (boolean) Boolean indicating if mode should be on or off.
  2483. * @param $margin (float) Distance from the bottom of the page.
  2484. * @public
  2485. * @since 1.0
  2486. * @see Cell(), MultiCell(), AcceptPageBreak()
  2487. */
  2488. public function SetAutoPageBreak($auto, $margin=0) {
  2489. $this->AutoPageBreak = $auto ? true : false;
  2490. $this->bMargin = $margin;
  2491. $this->PageBreakTrigger = $this->h - $margin;
  2492. }
  2493. /**
  2494. * Return the auto-page-break mode (true or false).
  2495. * @return boolean auto-page-break mode
  2496. * @public
  2497. * @since 5.9.088
  2498. */
  2499. public function getAutoPageBreak() {
  2500. return $this->AutoPageBreak;
  2501. }
  2502. /**
  2503. * Defines the way the document is to be displayed by the viewer.
  2504. * @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>
  2505. * @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>
  2506. * @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>
  2507. * @public
  2508. * @since 1.2
  2509. */
  2510. public function SetDisplayMode($zoom, $layout='SinglePage', $mode='UseNone') {
  2511. if (($zoom == 'fullpage') OR ($zoom == 'fullwidth') OR ($zoom == 'real') OR ($zoom == 'default') OR (!is_string($zoom))) {
  2512. $this->ZoomMode = $zoom;
  2513. } else {
  2514. $this->Error('Incorrect zoom display mode: '.$zoom);
  2515. }
  2516. $this->LayoutMode = TCPDF_STATIC::getPageLayoutMode($layout);
  2517. $this->PageMode = TCPDF_STATIC::getPageMode($mode);
  2518. }
  2519. /**
  2520. * 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.
  2521. * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  2522. * @param $compress (boolean) Boolean indicating if compression must be enabled.
  2523. * @public
  2524. * @since 1.4
  2525. */
  2526. public function SetCompression($compress=true) {
  2527. if (function_exists('gzcompress')) {
  2528. $this->compress = $compress ? true : false;
  2529. } else {
  2530. $this->compress = false;
  2531. }
  2532. }
  2533. /**
  2534. * Set flag to force sRGB_IEC61966-2.1 black scaled ICC color profile for the whole document.
  2535. * @param $mode (boolean) If true force sRGB output intent.
  2536. * @public
  2537. * @since 5.9.121 (2011-09-28)
  2538. */
  2539. public function setSRGBmode($mode=false) {
  2540. $this->force_srgb = $mode ? true : false;
  2541. }
  2542. /**
  2543. * Turn on/off Unicode mode for document information dictionary (meta tags).
  2544. * This has effect only when unicode mode is set to false.
  2545. * @param $unicode (boolean) if true set the meta information in Unicode
  2546. * @since 5.9.027 (2010-12-01)
  2547. * @public
  2548. */
  2549. public function SetDocInfoUnicode($unicode=true) {
  2550. $this->docinfounicode = $unicode ? true : false;
  2551. }
  2552. /**
  2553. * Defines the title of the document.
  2554. * @param $title (string) The title.
  2555. * @public
  2556. * @since 1.2
  2557. * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  2558. */
  2559. public function SetTitle($title) {
  2560. $this->title = $title;
  2561. }
  2562. /**
  2563. * Defines the subject of the document.
  2564. * @param $subject (string) The subject.
  2565. * @public
  2566. * @since 1.2
  2567. * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  2568. */
  2569. public function SetSubject($subject) {
  2570. $this->subject = $subject;
  2571. }
  2572. /**
  2573. * Defines the author of the document.
  2574. * @param $author (string) The name of the author.
  2575. * @public
  2576. * @since 1.2
  2577. * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  2578. */
  2579. public function SetAuthor($author) {
  2580. $this->author = $author;
  2581. }
  2582. /**
  2583. * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  2584. * @param $keywords (string) The list of keywords.
  2585. * @public
  2586. * @since 1.2
  2587. * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  2588. */
  2589. public function SetKeywords($keywords) {
  2590. $this->keywords = $keywords;
  2591. }
  2592. /**
  2593. * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  2594. * @param $creator (string) The name of the creator.
  2595. * @public
  2596. * @since 1.2
  2597. * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  2598. */
  2599. public function SetCreator($creator) {
  2600. $this->creator = $creator;
  2601. }
  2602. /**
  2603. * Throw an exception or print an error message and die if the K_TCPDF_PARSER_THROW_EXCEPTION_ERROR constant is set to true.
  2604. * @param $msg (string) The error message
  2605. * @public
  2606. * @since 1.0
  2607. */
  2608. public function Error($msg) {
  2609. // unset all class variables
  2610. $this->_destroy(true);
  2611. if (defined('K_TCPDF_THROW_EXCEPTION_ERROR') AND !K_TCPDF_THROW_EXCEPTION_ERROR) {
  2612. die('<strong>TCPDF ERROR: </strong>'.$msg);
  2613. } else {
  2614. throw new Exception('TCPDF ERROR: '.$msg);
  2615. }
  2616. }
  2617. /**
  2618. * This method begins the generation of the PDF document.
  2619. * It is not necessary to call it explicitly because AddPage() does it automatically.
  2620. * Note: no page is created by this method
  2621. * @public
  2622. * @since 1.0
  2623. * @see AddPage(), Close()
  2624. */
  2625. public function Open() {
  2626. $this->state = 1;
  2627. }
  2628. /**
  2629. * Terminates the PDF document.
  2630. * It is not necessary to call this method explicitly because Output() does it automatically.
  2631. * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  2632. * @public
  2633. * @since 1.0
  2634. * @see Open(), Output()
  2635. */
  2636. public function Close() {
  2637. if ($this->state == 3) {
  2638. return;
  2639. }
  2640. if ($this->page == 0) {
  2641. $this->AddPage();
  2642. }
  2643. $this->endLayer();
  2644. if ($this->tcpdflink) {
  2645. // save current graphic settings
  2646. $gvars = $this->getGraphicVars();
  2647. $this->setEqualColumns();
  2648. $this->lastpage(true);
  2649. $this->SetAutoPageBreak(false);
  2650. $this->x = 0;
  2651. $this->y = $this->h - (1 / $this->k);
  2652. $this->lMargin = 0;
  2653. $this->_out('q');
  2654. $font = defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica';
  2655. $this->SetFont($font, '', 1);
  2656. $this->setTextRenderingMode(0, false, false);
  2657. $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";
  2658. $lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67";
  2659. $this->Cell(0, 0, $msg, 0, 0, 'L', 0, $lnk, 0, false, 'D', 'B');
  2660. $this->_out('Q');
  2661. // restore graphic settings
  2662. $this->setGraphicVars($gvars);
  2663. }
  2664. // close page
  2665. $this->endPage();
  2666. // close document
  2667. $this->_enddoc();
  2668. // unset all class variables (except critical ones)
  2669. $this->_destroy(false);
  2670. }
  2671. /**
  2672. * Move pointer at the specified document page and update page dimensions.
  2673. * @param $pnum (int) page number (1 ... numpages)
  2674. * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
  2675. * @public
  2676. * @since 2.1.000 (2008-01-07)
  2677. * @see getPage(), lastpage(), getNumPages()
  2678. */
  2679. public function setPage($pnum, $resetmargins=false) {
  2680. if (($pnum == $this->page) AND ($this->state == 2)) {
  2681. return;
  2682. }
  2683. if (($pnum > 0) AND ($pnum <= $this->numpages)) {
  2684. $this->state = 2;
  2685. // save current graphic settings
  2686. //$gvars = $this->getGraphicVars();
  2687. $oldpage = $this->page;
  2688. $this->page = $pnum;
  2689. $this->wPt = $this->pagedim[$this->page]['w'];
  2690. $this->hPt = $this->pagedim[$this->page]['h'];
  2691. $this->w = $this->pagedim[$this->page]['wk'];
  2692. $this->h = $this->pagedim[$this->page]['hk'];
  2693. $this->tMargin = $this->pagedim[$this->page]['tm'];
  2694. $this->bMargin = $this->pagedim[$this->page]['bm'];
  2695. $this->original_lMargin = $this->pagedim[$this->page]['olm'];
  2696. $this->original_rMargin = $this->pagedim[$this->page]['orm'];
  2697. $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
  2698. $this->CurOrientation = $this->pagedim[$this->page]['or'];
  2699. $this->SetAutoPageBreak($this->AutoPageBreak, $this->bMargin);
  2700. // restore graphic settings
  2701. //$this->setGraphicVars($gvars);
  2702. if ($resetmargins) {
  2703. $this->lMargin = $this->pagedim[$this->page]['olm'];
  2704. $this->rMargin = $this->pagedim[$this->page]['orm'];
  2705. $this->SetY($this->tMargin);
  2706. } else {
  2707. // account for booklet mode
  2708. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  2709. $deltam = $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm'];
  2710. $this->lMargin += $deltam;
  2711. $this->rMargin -= $deltam;
  2712. }
  2713. }
  2714. } else {
  2715. $this->Error('Wrong page number on setPage() function: '.$pnum);
  2716. }
  2717. }
  2718. /**
  2719. * Reset pointer to the last document page.
  2720. * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
  2721. * @public
  2722. * @since 2.0.000 (2008-01-04)
  2723. * @see setPage(), getPage(), getNumPages()
  2724. */
  2725. public function lastPage($resetmargins=false) {
  2726. $this->setPage($this->getNumPages(), $resetmargins);
  2727. }
  2728. /**
  2729. * Get current document page number.
  2730. * @return int page number
  2731. * @public
  2732. * @since 2.1.000 (2008-01-07)
  2733. * @see setPage(), lastpage(), getNumPages()
  2734. */
  2735. public function getPage() {
  2736. return $this->page;
  2737. }
  2738. /**
  2739. * Get the total number of insered pages.
  2740. * @return int number of pages
  2741. * @public
  2742. * @since 2.1.000 (2008-01-07)
  2743. * @see setPage(), getPage(), lastpage()
  2744. */
  2745. public function getNumPages() {
  2746. return $this->numpages;
  2747. }
  2748. /**
  2749. * Adds a new TOC (Table Of Content) page to the document.
  2750. * @param $orientation (string) page orientation.
  2751. * @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().
  2752. * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
  2753. * @public
  2754. * @since 5.0.001 (2010-05-06)
  2755. * @see AddPage(), startPage(), endPage(), endTOCPage()
  2756. */
  2757. public function addTOCPage($orientation='', $format='', $keepmargins=false) {
  2758. $this->AddPage($orientation, $format, $keepmargins, true);
  2759. }
  2760. /**
  2761. * Terminate the current TOC (Table Of Content) page
  2762. * @public
  2763. * @since 5.0.001 (2010-05-06)
  2764. * @see AddPage(), startPage(), endPage(), addTOCPage()
  2765. */
  2766. public function endTOCPage() {
  2767. $this->endPage(true);
  2768. }
  2769. /**
  2770. * 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).
  2771. * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
  2772. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2773. * @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().
  2774. * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
  2775. * @param $tocpage (boolean) if true set the tocpage state to true (the added page will be used to display Table Of Content).
  2776. * @public
  2777. * @since 1.0
  2778. * @see startPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  2779. */
  2780. public function AddPage($orientation='', $format='', $keepmargins=false, $tocpage=false) {
  2781. if ($this->inxobj) {
  2782. // we are inside an XObject template
  2783. return;
  2784. }
  2785. if (!isset($this->original_lMargin) OR $keepmargins) {
  2786. $this->original_lMargin = $this->lMargin;
  2787. }
  2788. if (!isset($this->original_rMargin) OR $keepmargins) {
  2789. $this->original_rMargin = $this->rMargin;
  2790. }
  2791. // terminate previous page
  2792. $this->endPage();
  2793. // start new page
  2794. $this->startPage($orientation, $format, $tocpage);
  2795. }
  2796. /**
  2797. * Terminate the current page
  2798. * @param $tocpage (boolean) if true set the tocpage state to false (end the page used to display Table Of Content).
  2799. * @public
  2800. * @since 4.2.010 (2008-11-14)
  2801. * @see AddPage(), startPage(), addTOCPage(), endTOCPage()
  2802. */
  2803. public function endPage($tocpage=false) {
  2804. // check if page is already closed
  2805. if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) {
  2806. return;
  2807. }
  2808. // print page footer
  2809. $this->setFooter();
  2810. // close page
  2811. $this->_endpage();
  2812. // mark page as closed
  2813. $this->pageopen[$this->page] = false;
  2814. if ($tocpage) {
  2815. $this->tocpage = false;
  2816. }
  2817. }
  2818. /**
  2819. * Starts a new page to the document. The page must be closed using the endPage() function.
  2820. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  2821. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2822. * @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().
  2823. * @param $tocpage (boolean) if true the page is designated to contain the Table-Of-Content.
  2824. * @since 4.2.010 (2008-11-14)
  2825. * @see AddPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  2826. * @public
  2827. */
  2828. public function startPage($orientation='', $format='', $tocpage=false) {
  2829. if ($tocpage) {
  2830. $this->tocpage = true;
  2831. }
  2832. // move page numbers of documents to be attached
  2833. if ($this->tocpage) {
  2834. // move reference to unexistent pages (used for page attachments)
  2835. // adjust outlines
  2836. $tmpoutlines = $this->outlines;
  2837. foreach ($tmpoutlines as $key => $outline) {
  2838. if ($outline['p'] > $this->numpages) {
  2839. $this->outlines[$key]['p'] = ($outline['p'] + 1);
  2840. }
  2841. }
  2842. // adjust dests
  2843. $tmpdests = $this->dests;
  2844. foreach ($tmpdests as $key => $dest) {
  2845. if ($dest['p'] > $this->numpages) {
  2846. $this->dests[$key]['p'] = ($dest['p'] + 1);
  2847. }
  2848. }
  2849. // adjust links
  2850. $tmplinks = $this->links;
  2851. foreach ($tmplinks as $key => $link) {
  2852. if ($link[0] > $this->numpages) {
  2853. $this->links[$key][0] = ($link[0] + 1);
  2854. }
  2855. }
  2856. }
  2857. if ($this->numpages > $this->page) {
  2858. // this page has been already added
  2859. $this->setPage($this->page + 1);
  2860. $this->SetY($this->tMargin);
  2861. return;
  2862. }
  2863. // start a new page
  2864. if ($this->state == 0) {
  2865. $this->Open();
  2866. }
  2867. ++$this->numpages;
  2868. $this->swapMargins($this->booklet);
  2869. // save current graphic settings
  2870. $gvars = $this->getGraphicVars();
  2871. // start new page
  2872. $this->_beginpage($orientation, $format);
  2873. // mark page as open
  2874. $this->pageopen[$this->page] = true;
  2875. // restore graphic settings
  2876. $this->setGraphicVars($gvars);
  2877. // mark this point
  2878. $this->setPageMark();
  2879. // print page header
  2880. $this->setHeader();
  2881. // restore graphic settings
  2882. $this->setGraphicVars($gvars);
  2883. // mark this point
  2884. $this->setPageMark();
  2885. // print table header (if any)
  2886. $this->setTableHeader();
  2887. // set mark for empty page check
  2888. $this->emptypagemrk[$this->page]= $this->pagelen[$this->page];
  2889. }
  2890. /**
  2891. * Set start-writing mark on current page stream used to put borders and fills.
  2892. * Borders and fills are always created after content and inserted on the position marked by this method.
  2893. * This function must be called after calling Image() function for a background image.
  2894. * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
  2895. * @public
  2896. * @since 4.0.016 (2008-07-30)
  2897. */
  2898. public function setPageMark() {
  2899. $this->intmrk[$this->page] = $this->pagelen[$this->page];
  2900. $this->bordermrk[$this->page] = $this->intmrk[$this->page];
  2901. $this->setContentMark();
  2902. }
  2903. /**
  2904. * Set start-writing mark on selected page.
  2905. * Borders and fills are always created after content and inserted on the position marked by this method.
  2906. * @param $page (int) page number (default is the current page)
  2907. * @protected
  2908. * @since 4.6.021 (2009-07-20)
  2909. */
  2910. protected function setContentMark($page=0) {
  2911. if ($page <= 0) {
  2912. $page = $this->page;
  2913. }
  2914. if (isset($this->footerlen[$page])) {
  2915. $this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
  2916. } else {
  2917. $this->cntmrk[$page] = $this->pagelen[$page];
  2918. }
  2919. }
  2920. /**
  2921. * Set header data.
  2922. * @param $ln (string) header image logo
  2923. * @param $lw (string) header image logo width in mm
  2924. * @param $ht (string) string to print as title on document header
  2925. * @param $hs (string) string to print on document header
  2926. * @param $tc (array) RGB array color for text.
  2927. * @param $lc (array) RGB array color for line.
  2928. * @public
  2929. */
  2930. public function setHeaderData($ln='', $lw=0, $ht='', $hs='', $tc=array(0,0,0), $lc=array(0,0,0)) {
  2931. $this->header_logo = $ln;
  2932. $this->header_logo_width = $lw;
  2933. $this->header_title = $ht;
  2934. $this->header_string = $hs;
  2935. $this->header_text_color = $tc;
  2936. $this->header_line_color = $lc;
  2937. }
  2938. /**
  2939. * Set footer data.
  2940. * @param $tc (array) RGB array color for text.
  2941. * @param $lc (array) RGB array color for line.
  2942. * @public
  2943. */
  2944. public function setFooterData($tc=array(0,0,0), $lc=array(0,0,0)) {
  2945. $this->footer_text_color = $tc;
  2946. $this->footer_line_color = $lc;
  2947. }
  2948. /**
  2949. * Returns header data:
  2950. * <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>
  2951. * @return array()
  2952. * @public
  2953. * @since 4.0.012 (2008-07-24)
  2954. */
  2955. public function getHeaderData() {
  2956. $ret = array();
  2957. $ret['logo'] = $this->header_logo;
  2958. $ret['logo_width'] = $this->header_logo_width;
  2959. $ret['title'] = $this->header_title;
  2960. $ret['string'] = $this->header_string;
  2961. $ret['text_color'] = $this->header_text_color;
  2962. $ret['line_color'] = $this->header_line_color;
  2963. return $ret;
  2964. }
  2965. /**
  2966. * Set header margin.
  2967. * (minimum distance between header and top page margin)
  2968. * @param $hm (int) distance in user units
  2969. * @public
  2970. */
  2971. public function setHeaderMargin($hm=10) {
  2972. $this->header_margin = $hm;
  2973. }
  2974. /**
  2975. * Returns header margin in user units.
  2976. * @return float
  2977. * @since 4.0.012 (2008-07-24)
  2978. * @public
  2979. */
  2980. public function getHeaderMargin() {
  2981. return $this->header_margin;
  2982. }
  2983. /**
  2984. * Set footer margin.
  2985. * (minimum distance between footer and bottom page margin)
  2986. * @param $fm (int) distance in user units
  2987. * @public
  2988. */
  2989. public function setFooterMargin($fm=10) {
  2990. $this->footer_margin = $fm;
  2991. }
  2992. /**
  2993. * Returns footer margin in user units.
  2994. * @return float
  2995. * @since 4.0.012 (2008-07-24)
  2996. * @public
  2997. */
  2998. public function getFooterMargin() {
  2999. return $this->footer_margin;
  3000. }
  3001. /**
  3002. * Set a flag to print page header.
  3003. * @param $val (boolean) set to true to print the page header (default), false otherwise.
  3004. * @public
  3005. */
  3006. public function setPrintHeader($val=true) {
  3007. $this->print_header = $val ? true : false;
  3008. }
  3009. /**
  3010. * Set a flag to print page footer.
  3011. * @param $val (boolean) set to true to print the page footer (default), false otherwise.
  3012. * @public
  3013. */
  3014. public function setPrintFooter($val=true) {
  3015. $this->print_footer = $val ? true : false;
  3016. }
  3017. /**
  3018. * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
  3019. * @return float
  3020. * @public
  3021. */
  3022. public function getImageRBX() {
  3023. return $this->img_rb_x;
  3024. }
  3025. /**
  3026. * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
  3027. * @return float
  3028. * @public
  3029. */
  3030. public function getImageRBY() {
  3031. return $this->img_rb_y;
  3032. }
  3033. /**
  3034. * Reset the xobject template used by Header() method.
  3035. * @public
  3036. */
  3037. public function resetHeaderTemplate() {
  3038. $this->header_xobjid = -1;
  3039. }
  3040. /**
  3041. * Set a flag to automatically reset the xobject template used by Header() method at each page.
  3042. * @param $val (boolean) set to true to reset Header xobject template at each page, false otherwise.
  3043. * @public
  3044. */
  3045. public function setHeaderTemplateAutoreset($val=true) {
  3046. $this->header_xobj_autoreset = $val ? true : false;
  3047. }
  3048. /**
  3049. * This method is used to render the page header.
  3050. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3051. * @public
  3052. */
  3053. public function Header() {
  3054. if ($this->header_xobjid < 0) {
  3055. // start a new XObject Template
  3056. $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin);
  3057. $headerfont = $this->getHeaderFont();
  3058. $headerdata = $this->getHeaderData();
  3059. $this->y = $this->header_margin;
  3060. if ($this->rtl) {
  3061. $this->x = $this->w - $this->original_rMargin;
  3062. } else {
  3063. $this->x = $this->original_lMargin;
  3064. }
  3065. if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) {
  3066. $imgtype = TCPDF_IMAGES::getImageFileType(K_PATH_IMAGES.$headerdata['logo']);
  3067. if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  3068. $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3069. } elseif ($imgtype == 'svg') {
  3070. $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3071. } else {
  3072. $this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3073. }
  3074. $imgy = $this->getImageRBY();
  3075. } else {
  3076. $imgy = $this->y;
  3077. }
  3078. $cell_height = $this->getCellHeight($headerfont[2] / $this->k);
  3079. // set starting margin for text data cell
  3080. if ($this->getRTL()) {
  3081. $header_x = $this->original_rMargin + ($headerdata['logo_width'] * 1.1);
  3082. } else {
  3083. $header_x = $this->original_lMargin + ($headerdata['logo_width'] * 1.1);
  3084. }
  3085. $cw = $this->w - $this->original_lMargin - $this->original_rMargin - ($headerdata['logo_width'] * 1.1);
  3086. $this->SetTextColorArray($this->header_text_color);
  3087. // header title
  3088. $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1);
  3089. $this->SetX($header_x);
  3090. $this->Cell($cw, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
  3091. // header string
  3092. $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
  3093. $this->SetX($header_x);
  3094. $this->MultiCell($cw, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false, true, 0, 'T', false);
  3095. // print an ending header line
  3096. $this->SetLineStyle(array('width' => 0.85 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $headerdata['line_color']));
  3097. $this->SetY((2.835 / $this->k) + max($imgy, $this->y));
  3098. if ($this->rtl) {
  3099. $this->SetX($this->original_rMargin);
  3100. } else {
  3101. $this->SetX($this->original_lMargin);
  3102. }
  3103. $this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');
  3104. $this->endTemplate();
  3105. }
  3106. // print header template
  3107. $x = 0;
  3108. $dx = 0;
  3109. if (!$this->header_xobj_autoreset AND $this->booklet AND (($this->page % 2) == 0)) {
  3110. // adjust margins for booklet mode
  3111. $dx = ($this->original_lMargin - $this->original_rMargin);
  3112. }
  3113. if ($this->rtl) {
  3114. $x = $this->w + $dx;
  3115. } else {
  3116. $x = 0 + $dx;
  3117. }
  3118. $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false);
  3119. if ($this->header_xobj_autoreset) {
  3120. // reset header xobject template at each page
  3121. $this->header_xobjid = -1;
  3122. }
  3123. }
  3124. /**
  3125. * This method is used to render the page footer.
  3126. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3127. * @public
  3128. */
  3129. public function Footer() {
  3130. $cur_y = $this->y;
  3131. $this->SetTextColorArray($this->footer_text_color);
  3132. //set style for cell border
  3133. $line_width = (0.85 / $this->k);
  3134. $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $this->footer_line_color));
  3135. //print document barcode
  3136. $barcode = $this->getBarcode();
  3137. if (!empty($barcode)) {
  3138. $this->Ln($line_width);
  3139. $barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin) / 3);
  3140. $style = array(
  3141. 'position' => $this->rtl?'R':'L',
  3142. 'align' => $this->rtl?'R':'L',
  3143. 'stretch' => false,
  3144. 'fitwidth' => true,
  3145. 'cellfitalign' => '',
  3146. 'border' => false,
  3147. 'padding' => 0,
  3148. 'fgcolor' => array(0,0,0),
  3149. 'bgcolor' => false,
  3150. 'text' => false
  3151. );
  3152. $this->write1DBarcode($barcode, 'C128', '', $cur_y + $line_width, '', (($this->footer_margin / 3) - $line_width), 0.3, $style, '');
  3153. }
  3154. $w_page = isset($this->l['w_page']) ? $this->l['w_page'].' ' : '';
  3155. if (empty($this->pagegroups)) {
  3156. $pagenumtxt = $w_page.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
  3157. } else {
  3158. $pagenumtxt = $w_page.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
  3159. }
  3160. $this->SetY($cur_y);
  3161. //Print page number
  3162. if ($this->getRTL()) {
  3163. $this->SetX($this->original_rMargin);
  3164. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
  3165. } else {
  3166. $this->SetX($this->original_lMargin);
  3167. $this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');
  3168. }
  3169. }
  3170. /**
  3171. * This method is used to render the page header.
  3172. * @protected
  3173. * @since 4.0.012 (2008-07-24)
  3174. */
  3175. protected function setHeader() {
  3176. if (!$this->print_header OR ($this->state != 2)) {
  3177. return;
  3178. }
  3179. $this->InHeader = true;
  3180. $this->setGraphicVars($this->default_graphic_vars);
  3181. $temp_thead = $this->thead;
  3182. $temp_theadMargins = $this->theadMargins;
  3183. $lasth = $this->lasth;
  3184. $this->_out('q');
  3185. $this->rMargin = $this->original_rMargin;
  3186. $this->lMargin = $this->original_lMargin;
  3187. $this->SetCellPadding(0);
  3188. //set current position
  3189. if ($this->rtl) {
  3190. $this->SetXY($this->original_rMargin, $this->header_margin);
  3191. } else {
  3192. $this->SetXY($this->original_lMargin, $this->header_margin);
  3193. }
  3194. $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
  3195. $this->Header();
  3196. //restore position
  3197. if ($this->rtl) {
  3198. $this->SetXY($this->original_rMargin, $this->tMargin);
  3199. } else {
  3200. $this->SetXY($this->original_lMargin, $this->tMargin);
  3201. }
  3202. $this->_out('Q');
  3203. $this->lasth = $lasth;
  3204. $this->thead = $temp_thead;
  3205. $this->theadMargins = $temp_theadMargins;
  3206. $this->newline = false;
  3207. $this->InHeader = false;
  3208. }
  3209. /**
  3210. * This method is used to render the page footer.
  3211. * @protected
  3212. * @since 4.0.012 (2008-07-24)
  3213. */
  3214. protected function setFooter() {
  3215. if ($this->state != 2) {
  3216. return;
  3217. }
  3218. $this->InFooter = true;
  3219. // save current graphic settings
  3220. $gvars = $this->getGraphicVars();
  3221. // mark this point
  3222. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  3223. $this->_out("\n");
  3224. if ($this->print_footer) {
  3225. $this->setGraphicVars($this->default_graphic_vars);
  3226. $this->current_column = 0;
  3227. $this->num_columns = 1;
  3228. $temp_thead = $this->thead;
  3229. $temp_theadMargins = $this->theadMargins;
  3230. $lasth = $this->lasth;
  3231. $this->_out('q');
  3232. $this->rMargin = $this->original_rMargin;
  3233. $this->lMargin = $this->original_lMargin;
  3234. $this->SetCellPadding(0);
  3235. //set current position
  3236. $footer_y = $this->h - $this->footer_margin;
  3237. if ($this->rtl) {
  3238. $this->SetXY($this->original_rMargin, $footer_y);
  3239. } else {
  3240. $this->SetXY($this->original_lMargin, $footer_y);
  3241. }
  3242. $this->SetFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
  3243. $this->Footer();
  3244. //restore position
  3245. if ($this->rtl) {
  3246. $this->SetXY($this->original_rMargin, $this->tMargin);
  3247. } else {
  3248. $this->SetXY($this->original_lMargin, $this->tMargin);
  3249. }
  3250. $this->_out('Q');
  3251. $this->lasth = $lasth;
  3252. $this->thead = $temp_thead;
  3253. $this->theadMargins = $temp_theadMargins;
  3254. }
  3255. // restore graphic settings
  3256. $this->setGraphicVars($gvars);
  3257. $this->current_column = $gvars['current_column'];
  3258. $this->num_columns = $gvars['num_columns'];
  3259. // calculate footer length
  3260. $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1;
  3261. $this->InFooter = false;
  3262. }
  3263. /**
  3264. * Check if we are on the page body (excluding page header and footer).
  3265. * @return true if we are not in page header nor in page footer, false otherwise.
  3266. * @protected
  3267. * @since 5.9.091 (2011-06-15)
  3268. */
  3269. protected function inPageBody() {
  3270. return (($this->InHeader === false) AND ($this->InFooter === false));
  3271. }
  3272. /**
  3273. * This method is used to render the table header on new page (if any).
  3274. * @protected
  3275. * @since 4.5.030 (2009-03-25)
  3276. */
  3277. protected function setTableHeader() {
  3278. if ($this->num_columns > 1) {
  3279. // multi column mode
  3280. return;
  3281. }
  3282. if (isset($this->theadMargins['top'])) {
  3283. // restore the original top-margin
  3284. $this->tMargin = $this->theadMargins['top'];
  3285. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3286. $this->y = $this->tMargin;
  3287. }
  3288. if (!TCPDF_STATIC::empty_string($this->thead) AND (!$this->inthead)) {
  3289. // set margins
  3290. $prev_lMargin = $this->lMargin;
  3291. $prev_rMargin = $this->rMargin;
  3292. $prev_cell_padding = $this->cell_padding;
  3293. $this->lMargin = $this->theadMargins['lmargin'] + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$this->theadMargins['page']]['olm']);
  3294. $this->rMargin = $this->theadMargins['rmargin'] + ($this->pagedim[$this->page]['orm'] - $this->pagedim[$this->theadMargins['page']]['orm']);
  3295. $this->cell_padding = $this->theadMargins['cell_padding'];
  3296. if ($this->rtl) {
  3297. $this->x = $this->w - $this->rMargin;
  3298. } else {
  3299. $this->x = $this->lMargin;
  3300. }
  3301. // account for special "cell" mode
  3302. if ($this->theadMargins['cell']) {
  3303. if ($this->rtl) {
  3304. $this->x -= $this->cell_padding['R'];
  3305. } else {
  3306. $this->x += $this->cell_padding['L'];
  3307. }
  3308. }
  3309. // print table header
  3310. $this->writeHTML($this->thead, false, false, false, false, '');
  3311. // set new top margin to skip the table headers
  3312. if (!isset($this->theadMargins['top'])) {
  3313. $this->theadMargins['top'] = $this->tMargin;
  3314. }
  3315. // store end of header position
  3316. if (!isset($this->columns[0]['th'])) {
  3317. $this->columns[0]['th'] = array();
  3318. }
  3319. $this->columns[0]['th']['\''.$this->page.'\''] = $this->y;
  3320. $this->tMargin = $this->y;
  3321. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3322. $this->lasth = 0;
  3323. $this->lMargin = $prev_lMargin;
  3324. $this->rMargin = $prev_rMargin;
  3325. $this->cell_padding = $prev_cell_padding;
  3326. }
  3327. }
  3328. /**
  3329. * Returns the current page number.
  3330. * @return int page number
  3331. * @public
  3332. * @since 1.0
  3333. * @see getAliasNbPages()
  3334. */
  3335. public function PageNo() {
  3336. return $this->page;
  3337. }
  3338. /**
  3339. * Returns the array of spot colors.
  3340. * @return (array) Spot colors array.
  3341. * @public
  3342. * @since 6.0.038 (2013-09-30)
  3343. */
  3344. public function getAllSpotColors() {
  3345. return $this->spot_colors;
  3346. }
  3347. /**
  3348. * Defines a new spot color.
  3349. * It can be expressed in RGB components or gray scale.
  3350. * The method can be called before the first page is created and the value is retained from page to page.
  3351. * @param $name (string) Full name of the spot color.
  3352. * @param $c (float) Cyan color for CMYK. Value between 0 and 100.
  3353. * @param $m (float) Magenta color for CMYK. Value between 0 and 100.
  3354. * @param $y (float) Yellow color for CMYK. Value between 0 and 100.
  3355. * @param $k (float) Key (Black) color for CMYK. Value between 0 and 100.
  3356. * @public
  3357. * @since 4.0.024 (2008-09-12)
  3358. * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  3359. */
  3360. public function AddSpotColor($name, $c, $m, $y, $k) {
  3361. if (!isset($this->spot_colors[$name])) {
  3362. $i = (1 + count($this->spot_colors));
  3363. $this->spot_colors[$name] = array('C' => $c, 'M' => $m, 'Y' => $y, 'K' => $k, 'name' => $name, 'i' => $i);
  3364. }
  3365. }
  3366. /**
  3367. * Set the spot color for the specified type ('draw', 'fill', 'text').
  3368. * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  3369. * @param $name (string) Name of the spot color.
  3370. * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3371. * @return (string) PDF color command.
  3372. * @public
  3373. * @since 5.9.125 (2011-10-03)
  3374. */
  3375. public function setSpotColor($type, $name, $tint=100) {
  3376. $spotcolor = TCPDF_COLORS::getSpotColor($name, $this->spot_colors);
  3377. if ($spotcolor === false) {
  3378. $this->Error('Undefined spot color: '.$name.', you must add it using the AddSpotColor() method.');
  3379. }
  3380. $tint = (max(0, min(100, $tint)) / 100);
  3381. $pdfcolor = sprintf('/CS%d ', $this->spot_colors[$name]['i']);
  3382. switch ($type) {
  3383. case 'draw': {
  3384. $pdfcolor .= sprintf('CS %F SCN', $tint);
  3385. $this->DrawColor = $pdfcolor;
  3386. $this->strokecolor = $spotcolor;
  3387. break;
  3388. }
  3389. case 'fill': {
  3390. $pdfcolor .= sprintf('cs %F scn', $tint);
  3391. $this->FillColor = $pdfcolor;
  3392. $this->bgcolor = $spotcolor;
  3393. break;
  3394. }
  3395. case 'text': {
  3396. $pdfcolor .= sprintf('cs %F scn', $tint);
  3397. $this->TextColor = $pdfcolor;
  3398. $this->fgcolor = $spotcolor;
  3399. break;
  3400. }
  3401. }
  3402. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3403. if ($this->state == 2) {
  3404. $this->_out($pdfcolor);
  3405. }
  3406. if ($this->inxobj) {
  3407. // we are inside an XObject template
  3408. $this->xobjects[$this->xobjid]['spot_colors'][$name] = $this->spot_colors[$name];
  3409. }
  3410. return $pdfcolor;
  3411. }
  3412. /**
  3413. * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
  3414. * @param $name (string) Name of the spot color.
  3415. * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3416. * @public
  3417. * @since 4.0.024 (2008-09-12)
  3418. * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  3419. */
  3420. public function SetDrawSpotColor($name, $tint=100) {
  3421. $this->setSpotColor('draw', $name, $tint);
  3422. }
  3423. /**
  3424. * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
  3425. * @param $name (string) Name of the spot color.
  3426. * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3427. * @public
  3428. * @since 4.0.024 (2008-09-12)
  3429. * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
  3430. */
  3431. public function SetFillSpotColor($name, $tint=100) {
  3432. $this->setSpotColor('fill', $name, $tint);
  3433. }
  3434. /**
  3435. * Defines the spot color used for text.
  3436. * @param $name (string) Name of the spot color.
  3437. * @param $tint (int) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3438. * @public
  3439. * @since 4.0.024 (2008-09-12)
  3440. * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
  3441. */
  3442. public function SetTextSpotColor($name, $tint=100) {
  3443. $this->setSpotColor('text', $name, $tint);
  3444. }
  3445. /**
  3446. * Set the color array for the specified type ('draw', 'fill', 'text').
  3447. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3448. * The method can be called before the first page is created and the value is retained from page to page.
  3449. * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  3450. * @param $color (array) Array of colors (1=gray, 3=RGB, 4=CMYK or 5=spotcolor=CMYK+name values).
  3451. * @param $ret (boolean) If true do not send the PDF command.
  3452. * @return (string) The PDF command or empty string.
  3453. * @public
  3454. * @since 3.1.000 (2008-06-11)
  3455. */
  3456. public function setColorArray($type, $color, $ret=false) {
  3457. if (is_array($color)) {
  3458. $color = array_values($color);
  3459. // component: grey, RGB red or CMYK cyan
  3460. $c = isset($color[0]) ? $color[0] : -1;
  3461. // component: RGB green or CMYK magenta
  3462. $m = isset($color[1]) ? $color[1] : -1;
  3463. // component: RGB blue or CMYK yellow
  3464. $y = isset($color[2]) ? $color[2] : -1;
  3465. // component: CMYK black
  3466. $k = isset($color[3]) ? $color[3] : -1;
  3467. // color name
  3468. $name = isset($color[4]) ? $color[4] : '';
  3469. if ($c >= 0) {
  3470. return $this->setColor($type, $c, $m, $y, $k, $ret, $name);
  3471. }
  3472. }
  3473. return '';
  3474. }
  3475. /**
  3476. * Defines the color used for all drawing operations (lines, rectangles and cell borders).
  3477. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3478. * The method can be called before the first page is created and the value is retained from page to page.
  3479. * @param $color (array) Array of colors (1, 3 or 4 values).
  3480. * @param $ret (boolean) If true do not send the PDF command.
  3481. * @return string the PDF command
  3482. * @public
  3483. * @since 3.1.000 (2008-06-11)
  3484. * @see SetDrawColor()
  3485. */
  3486. public function SetDrawColorArray($color, $ret=false) {
  3487. return $this->setColorArray('draw', $color, $ret);
  3488. }
  3489. /**
  3490. * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
  3491. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3492. * The method can be called before the first page is created and the value is retained from page to page.
  3493. * @param $color (array) Array of colors (1, 3 or 4 values).
  3494. * @param $ret (boolean) If true do not send the PDF command.
  3495. * @public
  3496. * @since 3.1.000 (2008-6-11)
  3497. * @see SetFillColor()
  3498. */
  3499. public function SetFillColorArray($color, $ret=false) {
  3500. return $this->setColorArray('fill', $color, $ret);
  3501. }
  3502. /**
  3503. * Defines the color used for text. It can be expressed in RGB components or gray scale.
  3504. * The method can be called before the first page is created and the value is retained from page to page.
  3505. * @param $color (array) Array of colors (1, 3 or 4 values).
  3506. * @param $ret (boolean) If true do not send the PDF command.
  3507. * @public
  3508. * @since 3.1.000 (2008-6-11)
  3509. * @see SetFillColor()
  3510. */
  3511. public function SetTextColorArray($color, $ret=false) {
  3512. return $this->setColorArray('text', $color, $ret);
  3513. }
  3514. /**
  3515. * Defines the color used by the specified type ('draw', 'fill', 'text').
  3516. * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  3517. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3518. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3519. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3520. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  3521. * @param $ret (boolean) If true do not send the command.
  3522. * @param $name (string) spot color name (if any)
  3523. * @return (string) The PDF command or empty string.
  3524. * @public
  3525. * @since 5.9.125 (2011-10-03)
  3526. */
  3527. public function setColor($type, $col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3528. // set default values
  3529. if (!is_numeric($col1)) {
  3530. $col1 = 0;
  3531. }
  3532. if (!is_numeric($col2)) {
  3533. $col2 = -1;
  3534. }
  3535. if (!is_numeric($col3)) {
  3536. $col3 = -1;
  3537. }
  3538. if (!is_numeric($col4)) {
  3539. $col4 = -1;
  3540. }
  3541. // set color by case
  3542. $suffix = '';
  3543. if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
  3544. // Grey scale
  3545. $col1 = max(0, min(255, $col1));
  3546. $intcolor = array('G' => $col1);
  3547. $pdfcolor = sprintf('%F ', ($col1 / 255));
  3548. $suffix = 'g';
  3549. } elseif ($col4 == -1) {
  3550. // RGB
  3551. $col1 = max(0, min(255, $col1));
  3552. $col2 = max(0, min(255, $col2));
  3553. $col3 = max(0, min(255, $col3));
  3554. $intcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  3555. $pdfcolor = sprintf('%F %F %F ', ($col1 / 255), ($col2 / 255), ($col3 / 255));
  3556. $suffix = 'rg';
  3557. } else {
  3558. $col1 = max(0, min(100, $col1));
  3559. $col2 = max(0, min(100, $col2));
  3560. $col3 = max(0, min(100, $col3));
  3561. $col4 = max(0, min(100, $col4));
  3562. if (empty($name)) {
  3563. // CMYK
  3564. $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  3565. $pdfcolor = sprintf('%F %F %F %F ', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
  3566. $suffix = 'k';
  3567. } else {
  3568. // SPOT COLOR
  3569. $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
  3570. $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
  3571. $pdfcolor = $this->setSpotColor($type, $name, 100);
  3572. }
  3573. }
  3574. switch ($type) {
  3575. case 'draw': {
  3576. $pdfcolor .= strtoupper($suffix);
  3577. $this->DrawColor = $pdfcolor;
  3578. $this->strokecolor = $intcolor;
  3579. break;
  3580. }
  3581. case 'fill': {
  3582. $pdfcolor .= $suffix;
  3583. $this->FillColor = $pdfcolor;
  3584. $this->bgcolor = $intcolor;
  3585. break;
  3586. }
  3587. case 'text': {
  3588. $pdfcolor .= $suffix;
  3589. $this->TextColor = $pdfcolor;
  3590. $this->fgcolor = $intcolor;
  3591. break;
  3592. }
  3593. }
  3594. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3595. if (($type != 'text') AND ($this->state == 2)) {
  3596. if (!$ret) {
  3597. $this->_out($pdfcolor);
  3598. }
  3599. return $pdfcolor;
  3600. }
  3601. return '';
  3602. }
  3603. /**
  3604. * 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.
  3605. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3606. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3607. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3608. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  3609. * @param $ret (boolean) If true do not send the command.
  3610. * @param $name (string) spot color name (if any)
  3611. * @return string the PDF command
  3612. * @public
  3613. * @since 1.3
  3614. * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  3615. */
  3616. public function SetDrawColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3617. return $this->setColor('draw', $col1, $col2, $col3, $col4, $ret, $name);
  3618. }
  3619. /**
  3620. * 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.
  3621. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3622. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3623. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3624. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  3625. * @param $ret (boolean) If true do not send the command.
  3626. * @param $name (string) Spot color name (if any).
  3627. * @return (string) The PDF command.
  3628. * @public
  3629. * @since 1.3
  3630. * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  3631. */
  3632. public function SetFillColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3633. return $this->setColor('fill', $col1, $col2, $col3, $col4, $ret, $name);
  3634. }
  3635. /**
  3636. * 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.
  3637. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3638. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3639. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3640. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  3641. * @param $ret (boolean) If true do not send the command.
  3642. * @param $name (string) Spot color name (if any).
  3643. * @return (string) Empty string.
  3644. * @public
  3645. * @since 1.3
  3646. * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  3647. */
  3648. public function SetTextColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3649. return $this->setColor('text', $col1, $col2, $col3, $col4, $ret, $name);
  3650. }
  3651. /**
  3652. * Returns the length of a string in user unit. A font must be selected.<br>
  3653. * @param $s (string) The string whose length is to be computed
  3654. * @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.
  3655. * @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.
  3656. * @param $fontsize (float) Font size in points. The default value is the current size.
  3657. * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
  3658. * @return mixed int total string length or array of characted widths
  3659. * @author Nicola Asuni
  3660. * @public
  3661. * @since 1.2
  3662. */
  3663. public function GetStringWidth($s, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
  3664. 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);
  3665. }
  3666. /**
  3667. * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
  3668. * @param $sa (string) The array of chars whose total length is to be computed
  3669. * @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.
  3670. * @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.
  3671. * @param $fontsize (float) Font size in points. The default value is the current size.
  3672. * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
  3673. * @return mixed int total string length or array of characted widths
  3674. * @author Nicola Asuni
  3675. * @public
  3676. * @since 2.4.000 (2008-03-06)
  3677. */
  3678. public function GetArrStringWidth($sa, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
  3679. // store current values
  3680. if (!TCPDF_STATIC::empty_string($fontname)) {
  3681. $prev_FontFamily = $this->FontFamily;
  3682. $prev_FontStyle = $this->FontStyle;
  3683. $prev_FontSizePt = $this->FontSizePt;
  3684. $this->SetFont($fontname, $fontstyle, $fontsize, '', 'default', false);
  3685. }
  3686. // convert UTF-8 array to Latin1 if required
  3687. if ($this->isunicode AND (!$this->isUnicodeFont())) {
  3688. $sa = TCPDF_FONTS::UTF8ArrToLatin1Arr($sa);
  3689. }
  3690. $w = 0; // total width
  3691. $wa = array(); // array of characters widths
  3692. foreach ($sa as $ck => $char) {
  3693. // character width
  3694. $cw = $this->GetCharWidth($char, isset($sa[($ck + 1)]));
  3695. $wa[] = $cw;
  3696. $w += $cw;
  3697. }
  3698. // restore previous values
  3699. if (!TCPDF_STATIC::empty_string($fontname)) {
  3700. $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt, '', 'default', false);
  3701. }
  3702. if ($getarray) {
  3703. return $wa;
  3704. }
  3705. return $w;
  3706. }
  3707. /**
  3708. * Returns the length of the char in user unit for the current font considering current stretching and spacing (tracking).
  3709. * @param $char (int) The char code whose length is to be returned
  3710. * @param $notlast (boolean) If false ignore the font-spacing.
  3711. * @return float char width
  3712. * @author Nicola Asuni
  3713. * @public
  3714. * @since 2.4.000 (2008-03-06)
  3715. */
  3716. public function GetCharWidth($char, $notlast=true) {
  3717. // get raw width
  3718. $chw = $this->getRawCharWidth($char);
  3719. if (($this->font_spacing < 0) OR (($this->font_spacing > 0) AND $notlast)) {
  3720. // increase/decrease font spacing
  3721. $chw += $this->font_spacing;
  3722. }
  3723. if ($this->font_stretching != 100) {
  3724. // fixed stretching mode
  3725. $chw *= ($this->font_stretching / 100);
  3726. }
  3727. return $chw;
  3728. }
  3729. /**
  3730. * Returns the length of the char in user unit for the current font.
  3731. * @param $char (int) The char code whose length is to be returned
  3732. * @return float char width
  3733. * @author Nicola Asuni
  3734. * @public
  3735. * @since 5.9.000 (2010-09-28)
  3736. */
  3737. public function getRawCharWidth($char) {
  3738. if ($char == 173) {
  3739. // SHY character will not be printed
  3740. return (0);
  3741. }
  3742. if (isset($this->CurrentFont['cw'][$char])) {
  3743. $w = $this->CurrentFont['cw'][$char];
  3744. } elseif (isset($this->CurrentFont['dw'])) {
  3745. // default width
  3746. $w = $this->CurrentFont['dw'];
  3747. } elseif (isset($this->CurrentFont['cw'][32])) {
  3748. // default width
  3749. $w = $this->CurrentFont['cw'][32];
  3750. } else {
  3751. $w = 600;
  3752. }
  3753. return $this->getAbsFontMeasure($w);
  3754. }
  3755. /**
  3756. * Returns the numbero of characters in a string.
  3757. * @param $s (string) The input string.
  3758. * @return int number of characters
  3759. * @public
  3760. * @since 2.0.0001 (2008-01-07)
  3761. */
  3762. public function GetNumChars($s) {
  3763. if ($this->isUnicodeFont()) {
  3764. return count(TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont));
  3765. }
  3766. return strlen($s);
  3767. }
  3768. /**
  3769. * Fill the list of available fonts ($this->fontlist).
  3770. * @protected
  3771. * @since 4.0.013 (2008-07-28)
  3772. */
  3773. protected function getFontsList() {
  3774. if (($fontsdir = opendir(TCPDF_FONTS::_getfontpath())) !== false) {
  3775. while (($file = readdir($fontsdir)) !== false) {
  3776. if (substr($file, -4) == '.php') {
  3777. array_push($this->fontlist, strtolower(basename($file, '.php')));
  3778. }
  3779. }
  3780. closedir($fontsdir);
  3781. }
  3782. }
  3783. /**
  3784. * Returns the unicode caracter specified by the value
  3785. * @param $c (int) UTF-8 value
  3786. * @return Returns the specified character.
  3787. * @since 2.3.000 (2008-03-05)
  3788. * @public
  3789. * @deprecated
  3790. */
  3791. public function unichr($c) {
  3792. return TCPDF_FONTS::unichr($c, $this->isunicode);
  3793. }
  3794. /**
  3795. * Convert and add the selected TrueType or Type1 font to the fonts folder (that must be writeable).
  3796. * @param $fontfile (string) Font file (full path).
  3797. * @param $fonttype (string) Font type. Leave empty for autodetect mode. Valid values are: TrueTypeUnicode, TrueType, Type1, CID0JP = CID-0 Japanese, CID0KR = CID-0 Korean, CID0CS = CID-0 Chinese Simplified, CID0CT = CID-0 Chinese Traditional.
  3798. * @param $enc (string) Name of the encoding table to use. Leave empty for default mode. Omit this parameter for TrueType Unicode and symbolic fonts like Symbol or ZapfDingBats.
  3799. * @param $flags (int) Unsigned 32-bit integer containing flags specifying various characteristics of the font (PDF32000:2008 - 9.8.2 Font Descriptor Flags): +1 for fixed font; +4 for symbol or +32 for non-symbol; +64 for italic. Fixed and Italic mode are generally autodetected so you have to set it to 32 = non-symbolic font (default) or 4 = symbolic font.
  3800. * @param $outpath (string) Output path for generated font files (must be writeable by the web server). Leave empty for default font folder.
  3801. * @param $platid (int) Platform ID for CMAP table to extract (when building a Unicode font for Windows this value should be 3, for Macintosh should be 1).
  3802. * @param $encid (int) Encoding ID for CMAP table to extract (when building a Unicode font for Windows this value should be 1, for Macintosh should be 0). When Platform ID is 3, legal values for Encoding ID are: 0=Symbol, 1=Unicode, 2=ShiftJIS, 3=PRC, 4=Big5, 5=Wansung, 6=Johab, 7=Reserved, 8=Reserved, 9=Reserved, 10=UCS-4.
  3803. * @param $addcbbox (boolean) If true includes the character bounding box information on the php font file.
  3804. * @return (string) TCPDF font name.
  3805. * @author Nicola Asuni
  3806. * @since 5.9.123 (2010-09-30)
  3807. * @public
  3808. * @deprecated
  3809. */
  3810. public function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $outpath='', $platid=3, $encid=1, $addcbbox=false) {
  3811. return TCPDF_FONTS::addTTFfont($fontfile, $fonttype, $enc, $flags, $outpath, $platid, $encid, $addcbbox);
  3812. }
  3813. /**
  3814. * Imports a TrueType, Type1, core, or CID0 font and makes it available.
  3815. * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
  3816. * 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.
  3817. * @param $family (string) Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  3818. * @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>
  3819. * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  3820. * @return array containing the font data, or false in case of error.
  3821. * @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.
  3822. * @public
  3823. * @since 1.5
  3824. * @see SetFont(), setFontSubsetting()
  3825. */
  3826. public function AddFont($family, $style='', $fontfile='', $subset='default') {
  3827. if ($subset === 'default') {
  3828. $subset = $this->font_subsetting;
  3829. }
  3830. if ($this->pdfa_mode) {
  3831. $subset = false;
  3832. }
  3833. if (TCPDF_STATIC::empty_string($family)) {
  3834. if (!TCPDF_STATIC::empty_string($this->FontFamily)) {
  3835. $family = $this->FontFamily;
  3836. } else {
  3837. $this->Error('Empty font family');
  3838. }
  3839. }
  3840. // move embedded styles on $style
  3841. if (substr($family, -1) == 'I') {
  3842. $style .= 'I';
  3843. $family = substr($family, 0, -1);
  3844. }
  3845. if (substr($family, -1) == 'B') {
  3846. $style .= 'B';
  3847. $family = substr($family, 0, -1);
  3848. }
  3849. // normalize family name
  3850. $family = strtolower($family);
  3851. if ((!$this->isunicode) AND ($family == 'arial')) {
  3852. $family = 'helvetica';
  3853. }
  3854. if (($family == 'symbol') OR ($family == 'zapfdingbats')) {
  3855. $style = '';
  3856. }
  3857. if ($this->pdfa_mode AND (isset($this->CoreFonts[$family]))) {
  3858. // all fonts must be embedded
  3859. $family = 'pdfa'.$family;
  3860. }
  3861. $tempstyle = strtoupper($style);
  3862. $style = '';
  3863. // underline
  3864. if (strpos($tempstyle, 'U') !== false) {
  3865. $this->underline = true;
  3866. } else {
  3867. $this->underline = false;
  3868. }
  3869. // line-through (deleted)
  3870. if (strpos($tempstyle, 'D') !== false) {
  3871. $this->linethrough = true;
  3872. } else {
  3873. $this->linethrough = false;
  3874. }
  3875. // overline
  3876. if (strpos($tempstyle, 'O') !== false) {
  3877. $this->overline = true;
  3878. } else {
  3879. $this->overline = false;
  3880. }
  3881. // bold
  3882. if (strpos($tempstyle, 'B') !== false) {
  3883. $style .= 'B';
  3884. }
  3885. // oblique
  3886. if (strpos($tempstyle, 'I') !== false) {
  3887. $style .= 'I';
  3888. }
  3889. $bistyle = $style;
  3890. $fontkey = $family.$style;
  3891. $font_style = $style.($this->underline ? 'U' : '').($this->linethrough ? 'D' : '').($this->overline ? 'O' : '');
  3892. $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style);
  3893. // check if the font has been already added
  3894. $fb = $this->getFontBuffer($fontkey);
  3895. if ($fb !== false) {
  3896. if ($this->inxobj) {
  3897. // we are inside an XObject template
  3898. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $fb['i'];
  3899. }
  3900. return $fontdata;
  3901. }
  3902. // get specified font directory (if any)
  3903. $fontdir = false;
  3904. if (!TCPDF_STATIC::empty_string($fontfile)) {
  3905. $fontdir = dirname($fontfile);
  3906. if (TCPDF_STATIC::empty_string($fontdir) OR ($fontdir == '.')) {
  3907. $fontdir = '';
  3908. } else {
  3909. $fontdir .= '/';
  3910. }
  3911. }
  3912. // true when the font style variation is missing
  3913. $missing_style = false;
  3914. // search and include font file
  3915. if (TCPDF_STATIC::empty_string($fontfile) OR (!@file_exists($fontfile))) {
  3916. // build a standard filenames for specified font
  3917. $tmp_fontfile = str_replace(' ', '', $family).strtolower($style).'.php';
  3918. $fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir);
  3919. if (TCPDF_STATIC::empty_string($fontfile)) {
  3920. $missing_style = true;
  3921. // try to remove the style part
  3922. $tmp_fontfile = str_replace(' ', '', $family).'.php';
  3923. $fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir);
  3924. }
  3925. }
  3926. // include font file
  3927. if (!TCPDF_STATIC::empty_string($fontfile) AND (@file_exists($fontfile))) {
  3928. include($fontfile);
  3929. } else {
  3930. $this->Error('Could not include font definition file: '.$family.'');
  3931. }
  3932. // check font parameters
  3933. if ((!isset($type)) OR (!isset($cw))) {
  3934. $this->Error('The font definition file has a bad format: '.$fontfile.'');
  3935. }
  3936. // SET default parameters
  3937. if (!isset($file) OR TCPDF_STATIC::empty_string($file)) {
  3938. $file = '';
  3939. }
  3940. if (!isset($enc) OR TCPDF_STATIC::empty_string($enc)) {
  3941. $enc = '';
  3942. }
  3943. if (!isset($cidinfo) OR TCPDF_STATIC::empty_string($cidinfo)) {
  3944. $cidinfo = array('Registry'=>'Adobe', 'Ordering'=>'Identity', 'Supplement'=>0);
  3945. $cidinfo['uni2cid'] = array();
  3946. }
  3947. if (!isset($ctg) OR TCPDF_STATIC::empty_string($ctg)) {
  3948. $ctg = '';
  3949. }
  3950. if (!isset($desc) OR TCPDF_STATIC::empty_string($desc)) {
  3951. $desc = array();
  3952. }
  3953. if (!isset($up) OR TCPDF_STATIC::empty_string($up)) {
  3954. $up = -100;
  3955. }
  3956. if (!isset($ut) OR TCPDF_STATIC::empty_string($ut)) {
  3957. $ut = 50;
  3958. }
  3959. if (!isset($cw) OR TCPDF_STATIC::empty_string($cw)) {
  3960. $cw = array();
  3961. }
  3962. if (!isset($dw) OR TCPDF_STATIC::empty_string($dw)) {
  3963. // set default width
  3964. if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) {
  3965. $dw = $desc['MissingWidth'];
  3966. } elseif (isset($cw[32])) {
  3967. $dw = $cw[32];
  3968. } else {
  3969. $dw = 600;
  3970. }
  3971. }
  3972. ++$this->numfonts;
  3973. if ($type == 'core') {
  3974. $name = $this->CoreFonts[$fontkey];
  3975. $subset = false;
  3976. } elseif (($type == 'TrueType') OR ($type == 'Type1')) {
  3977. $subset = false;
  3978. } elseif ($type == 'TrueTypeUnicode') {
  3979. $enc = 'Identity-H';
  3980. } elseif ($type == 'cidfont0') {
  3981. if ($this->pdfa_mode) {
  3982. $this->Error('All fonts must be embedded in PDF/A mode!');
  3983. }
  3984. } else {
  3985. $this->Error('Unknow font type: '.$type.'');
  3986. }
  3987. // set name if unset
  3988. if (!isset($name) OR empty($name)) {
  3989. $name = $fontkey;
  3990. }
  3991. // create artificial font style variations if missing (only works with non-embedded fonts)
  3992. if (($type != 'core') AND $missing_style) {
  3993. // style variations
  3994. $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic');
  3995. $name .= $styles[$bistyle];
  3996. // artificial bold
  3997. if (strpos($bistyle, 'B') !== false) {
  3998. if (isset($desc['StemV'])) {
  3999. // from normal to bold
  4000. $desc['StemV'] = round($desc['StemV'] * 1.75);
  4001. } else {
  4002. // bold
  4003. $desc['StemV'] = 123;
  4004. }
  4005. }
  4006. // artificial italic
  4007. if (strpos($bistyle, 'I') !== false) {
  4008. if (isset($desc['ItalicAngle'])) {
  4009. $desc['ItalicAngle'] -= 11;
  4010. } else {
  4011. $desc['ItalicAngle'] = -11;
  4012. }
  4013. if (isset($desc['Flags'])) {
  4014. $desc['Flags'] |= 64; //bit 7
  4015. } else {
  4016. $desc['Flags'] = 64;
  4017. }
  4018. }
  4019. }
  4020. // check if the array of characters bounding boxes is defined
  4021. if (!isset($cbbox)) {
  4022. $cbbox = array();
  4023. }
  4024. // initialize subsetchars
  4025. $subsetchars = array_fill(0, 255, true);
  4026. $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));
  4027. if ($this->inxobj) {
  4028. // we are inside an XObject template
  4029. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts;
  4030. }
  4031. if (isset($diff) AND (!empty($diff))) {
  4032. //Search existing encodings
  4033. $d = 0;
  4034. $nb = count($this->diffs);
  4035. for ($i=1; $i <= $nb; ++$i) {
  4036. if ($this->diffs[$i] == $diff) {
  4037. $d = $i;
  4038. break;
  4039. }
  4040. }
  4041. if ($d == 0) {
  4042. $d = $nb + 1;
  4043. $this->diffs[$d] = $diff;
  4044. }
  4045. $this->setFontSubBuffer($fontkey, 'diff', $d);
  4046. }
  4047. if (!TCPDF_STATIC::empty_string($file)) {
  4048. if (!isset($this->FontFiles[$file])) {
  4049. if ((strcasecmp($type,'TrueType') == 0) OR (strcasecmp($type, 'TrueTypeUnicode') == 0)) {
  4050. $this->FontFiles[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  4051. } elseif ($type != 'core') {
  4052. $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  4053. }
  4054. } else {
  4055. // update fontkeys that are sharing this font file
  4056. $this->FontFiles[$file]['subset'] = ($this->FontFiles[$file]['subset'] AND $subset);
  4057. if (!in_array($fontkey, $this->FontFiles[$file]['fontkeys'])) {
  4058. $this->FontFiles[$file]['fontkeys'][] = $fontkey;
  4059. }
  4060. }
  4061. }
  4062. return $fontdata;
  4063. }
  4064. /**
  4065. * Sets the font used to print character strings.
  4066. * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  4067. * The method can be called before the first page is created and the font is retained from page to page.
  4068. * If you just wish to change the current font size, it is simpler to call SetFontSize().
  4069. * 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 />
  4070. * @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.
  4071. * @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.
  4072. * @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
  4073. * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  4074. * @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.
  4075. * @param $out (boolean) if true output the font size command, otherwise only set the font properties.
  4076. * @author Nicola Asuni
  4077. * @public
  4078. * @since 1.0
  4079. * @see AddFont(), SetFontSize()
  4080. */
  4081. public function SetFont($family, $style='', $size=null, $fontfile='', $subset='default', $out=true) {
  4082. //Select a font; size given in points
  4083. if ($size === null) {
  4084. $size = $this->FontSizePt;
  4085. }
  4086. if ($size < 0) {
  4087. $size = 0;
  4088. }
  4089. // try to add font (if not already added)
  4090. $fontdata = $this->AddFont($family, $style, $fontfile, $subset);
  4091. $this->FontFamily = $fontdata['family'];
  4092. $this->FontStyle = $fontdata['style'];
  4093. if (isset($this->CurrentFont['fontkey']) AND isset($this->CurrentFont['subsetchars'])) {
  4094. // save subset chars of the previous font
  4095. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  4096. }
  4097. $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
  4098. $this->SetFontSize($size, $out);
  4099. }
  4100. /**
  4101. * Defines the size of the current font.
  4102. * @param $size (float) The font size in points.
  4103. * @param $out (boolean) if true output the font size command, otherwise only set the font properties.
  4104. * @public
  4105. * @since 1.0
  4106. * @see SetFont()
  4107. */
  4108. public function SetFontSize($size, $out=true) {
  4109. // font size in points
  4110. $this->FontSizePt = $size;
  4111. // font size in user units
  4112. $this->FontSize = $size / $this->k;
  4113. // calculate some font metrics
  4114. if (isset($this->CurrentFont['desc']['FontBBox'])) {
  4115. $bbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  4116. $font_height = ((intval($bbox[3]) - intval($bbox[1])) * $size / 1000);
  4117. } else {
  4118. $font_height = $size * 1.219;
  4119. }
  4120. if (isset($this->CurrentFont['desc']['Ascent']) AND ($this->CurrentFont['desc']['Ascent'] > 0)) {
  4121. $font_ascent = ($this->CurrentFont['desc']['Ascent'] * $size / 1000);
  4122. }
  4123. if (isset($this->CurrentFont['desc']['Descent']) AND ($this->CurrentFont['desc']['Descent'] <= 0)) {
  4124. $font_descent = (- $this->CurrentFont['desc']['Descent'] * $size / 1000);
  4125. }
  4126. if (!isset($font_ascent) AND !isset($font_descent)) {
  4127. // core font
  4128. $font_ascent = 0.76 * $font_height;
  4129. $font_descent = $font_height - $font_ascent;
  4130. } elseif (!isset($font_descent)) {
  4131. $font_descent = $font_height - $font_ascent;
  4132. } elseif (!isset($font_ascent)) {
  4133. $font_ascent = $font_height - $font_descent;
  4134. }
  4135. $this->FontAscent = ($font_ascent / $this->k);
  4136. $this->FontDescent = ($font_descent / $this->k);
  4137. if ($out AND ($this->page > 0) AND (isset($this->CurrentFont['i'])) AND ($this->state == 2)) {
  4138. $this->_out(sprintf('BT /F%d %F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  4139. }
  4140. }
  4141. /**
  4142. * Returns the bounding box of the current font in user units.
  4143. * @return array
  4144. * @public
  4145. * @since 5.9.152 (2012-03-23)
  4146. */
  4147. public function getFontBBox() {
  4148. $fbbox = array();
  4149. if (isset($this->CurrentFont['desc']['FontBBox'])) {
  4150. $tmpbbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  4151. $fbbox = array_map(array($this,'getAbsFontMeasure'), $tmpbbox);
  4152. } else {
  4153. // Find max width
  4154. if (isset($this->CurrentFont['desc']['MaxWidth'])) {
  4155. $maxw = $this->getAbsFontMeasure(intval($this->CurrentFont['desc']['MaxWidth']));
  4156. } else {
  4157. $maxw = 0;
  4158. if (isset($this->CurrentFont['desc']['MissingWidth'])) {
  4159. $maxw = max($maxw, $this->CurrentFont['desc']['MissingWidth']);
  4160. }
  4161. if (isset($this->CurrentFont['desc']['AvgWidth'])) {
  4162. $maxw = max($maxw, $this->CurrentFont['desc']['AvgWidth']);
  4163. }
  4164. if (isset($this->CurrentFont['dw'])) {
  4165. $maxw = max($maxw, $this->CurrentFont['dw']);
  4166. }
  4167. foreach ($this->CurrentFont['cw'] as $char => $w) {
  4168. $maxw = max($maxw, $w);
  4169. }
  4170. if ($maxw == 0) {
  4171. $maxw = 600;
  4172. }
  4173. $maxw = $this->getAbsFontMeasure($maxw);
  4174. }
  4175. $fbbox = array(0, (0 - $this->FontDescent), $maxw, $this->FontAscent);
  4176. }
  4177. return $fbbox;
  4178. }
  4179. /**
  4180. * Convert a relative font measure into absolute value.
  4181. * @param $s (int) Font measure.
  4182. * @return float Absolute measure.
  4183. * @since 5.9.186 (2012-09-13)
  4184. */
  4185. public function getAbsFontMeasure($s) {
  4186. return ($s * $this->FontSize / 1000);
  4187. }
  4188. /**
  4189. * Returns the glyph bounding box of the specified character in the current font in user units.
  4190. * @param $char (int) Input character code.
  4191. * @return mixed array(xMin, yMin, xMax, yMax) or FALSE if not defined.
  4192. * @since 5.9.186 (2012-09-13)
  4193. */
  4194. public function getCharBBox($char) {
  4195. if (isset($this->CurrentFont['cbbox'][$char])) {
  4196. return array_map(array($this,'getAbsFontMeasure'), $this->CurrentFont['cbbox'][intval($char)]);
  4197. }
  4198. return false;
  4199. }
  4200. /**
  4201. * Return the font descent value
  4202. * @param $font (string) font name
  4203. * @param $style (string) font style
  4204. * @param $size (float) The size (in points)
  4205. * @return int font descent
  4206. * @public
  4207. * @author Nicola Asuni
  4208. * @since 4.9.003 (2010-03-30)
  4209. */
  4210. public function getFontDescent($font, $style='', $size=0) {
  4211. $fontdata = $this->AddFont($font, $style);
  4212. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4213. if (isset($fontinfo['desc']['Descent']) AND ($fontinfo['desc']['Descent'] <= 0)) {
  4214. $descent = (- $fontinfo['desc']['Descent'] * $size / 1000);
  4215. } else {
  4216. $descent = (1.219 * 0.24 * $size);
  4217. }
  4218. return ($descent / $this->k);
  4219. }
  4220. /**
  4221. * Return the font ascent value.
  4222. * @param $font (string) font name
  4223. * @param $style (string) font style
  4224. * @param $size (float) The size (in points)
  4225. * @return int font ascent
  4226. * @public
  4227. * @author Nicola Asuni
  4228. * @since 4.9.003 (2010-03-30)
  4229. */
  4230. public function getFontAscent($font, $style='', $size=0) {
  4231. $fontdata = $this->AddFont($font, $style);
  4232. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4233. if (isset($fontinfo['desc']['Ascent']) AND ($fontinfo['desc']['Ascent'] > 0)) {
  4234. $ascent = ($fontinfo['desc']['Ascent'] * $size / 1000);
  4235. } else {
  4236. $ascent = 1.219 * 0.76 * $size;
  4237. }
  4238. return ($ascent / $this->k);
  4239. }
  4240. /**
  4241. * Return true in the character is present in the specified font.
  4242. * @param $char (mixed) Character to check (integer value or string)
  4243. * @param $font (string) Font name (family name).
  4244. * @param $style (string) Font style.
  4245. * @return (boolean) true if the char is defined, false otherwise.
  4246. * @public
  4247. * @since 5.9.153 (2012-03-28)
  4248. */
  4249. public function isCharDefined($char, $font='', $style='') {
  4250. if (is_string($char)) {
  4251. // get character code
  4252. $char = TCPDF_FONTS::UTF8StringToArray($char, $this->isunicode, $this->CurrentFont);
  4253. $char = $char[0];
  4254. }
  4255. if (TCPDF_STATIC::empty_string($font)) {
  4256. if (TCPDF_STATIC::empty_string($style)) {
  4257. return (isset($this->CurrentFont['cw'][intval($char)]));
  4258. }
  4259. $font = $this->FontFamily;
  4260. }
  4261. $fontdata = $this->AddFont($font, $style);
  4262. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4263. return (isset($fontinfo['cw'][intval($char)]));
  4264. }
  4265. /**
  4266. * Replace missing font characters on selected font with specified substitutions.
  4267. * @param $text (string) Text to process.
  4268. * @param $font (string) Font name (family name).
  4269. * @param $style (string) Font style.
  4270. * @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.
  4271. * @return (string) Processed text.
  4272. * @public
  4273. * @since 5.9.153 (2012-03-28)
  4274. */
  4275. public function replaceMissingChars($text, $font='', $style='', $subs=array()) {
  4276. if (empty($subs)) {
  4277. return $text;
  4278. }
  4279. if (TCPDF_STATIC::empty_string($font)) {
  4280. $font = $this->FontFamily;
  4281. }
  4282. $fontdata = $this->AddFont($font, $style);
  4283. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4284. $uniarr = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont);
  4285. foreach ($uniarr as $k => $chr) {
  4286. if (!isset($fontinfo['cw'][$chr])) {
  4287. // this character is missing on the selected font
  4288. if (isset($subs[$chr])) {
  4289. // we have available substitutions
  4290. if (is_array($subs[$chr])) {
  4291. foreach($subs[$chr] as $s) {
  4292. if (isset($fontinfo['cw'][$s])) {
  4293. $uniarr[$k] = $s;
  4294. break;
  4295. }
  4296. }
  4297. } elseif (isset($fontinfo['cw'][$subs[$chr]])) {
  4298. $uniarr[$k] = $subs[$chr];
  4299. }
  4300. }
  4301. }
  4302. }
  4303. return TCPDF_FONTS::UniArrSubString(TCPDF_FONTS::UTF8ArrayToUniArray($uniarr, $this->isunicode));
  4304. }
  4305. /**
  4306. * Defines the default monospaced font.
  4307. * @param $font (string) Font name.
  4308. * @public
  4309. * @since 4.5.025
  4310. */
  4311. public function SetDefaultMonospacedFont($font) {
  4312. $this->default_monospaced_font = $font;
  4313. }
  4314. /**
  4315. * 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 />
  4316. * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  4317. * @public
  4318. * @since 1.5
  4319. * @see Cell(), Write(), Image(), Link(), SetLink()
  4320. */
  4321. public function AddLink() {
  4322. //Create a new internal link
  4323. $n = count($this->links) + 1;
  4324. $this->links[$n] = array(0, 0);
  4325. return $n;
  4326. }
  4327. /**
  4328. * Defines the page and position a link points to.
  4329. * @param $link (int) The link identifier returned by AddLink()
  4330. * @param $y (float) Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  4331. * @param $page (int) Number of target page; -1 indicates the current page. This is the default value
  4332. * @public
  4333. * @since 1.5
  4334. * @see AddLink()
  4335. */
  4336. public function SetLink($link, $y=0, $page=-1) {
  4337. if ($y == -1) {
  4338. $y = $this->y;
  4339. }
  4340. if ($page == -1) {
  4341. $page = $this->page;
  4342. }
  4343. $this->links[$link] = array($page, $y);
  4344. }
  4345. /**
  4346. * Puts a link on a rectangular area of the page.
  4347. * 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.
  4348. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  4349. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  4350. * @param $w (float) Width of the rectangle
  4351. * @param $h (float) Height of the rectangle
  4352. * @param $link (mixed) URL or identifier returned by AddLink()
  4353. * @param $spaces (int) number of spaces on the text to link
  4354. * @public
  4355. * @since 1.5
  4356. * @see AddLink(), Annotation(), Cell(), Write(), Image()
  4357. */
  4358. public function Link($x, $y, $w, $h, $link, $spaces=0) {
  4359. $this->Annotation($x, $y, $w, $h, $link, array('Subtype'=>'Link'), $spaces);
  4360. }
  4361. /**
  4362. * Puts a markup annotation on a rectangular area of the page.
  4363. * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
  4364. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  4365. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  4366. * @param $w (float) Width of the rectangle
  4367. * @param $h (float) Height of the rectangle
  4368. * @param $text (string) annotation text or alternate content
  4369. * @param $opt (array) array of options (see section 8.4 of PDF reference 1.7).
  4370. * @param $spaces (int) number of spaces on the text to link
  4371. * @public
  4372. * @since 4.0.018 (2008-08-06)
  4373. */
  4374. public function Annotation($x, $y, $w, $h, $text, $opt=array('Subtype'=>'Text'), $spaces=0) {
  4375. if ($this->inxobj) {
  4376. // store parameters for later use on template
  4377. $this->xobjects[$this->xobjid]['annotations'][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'text' => $text, 'opt' => $opt, 'spaces' => $spaces);
  4378. return;
  4379. }
  4380. if ($x === '') {
  4381. $x = $this->x;
  4382. }
  4383. if ($y === '') {
  4384. $y = $this->y;
  4385. }
  4386. // check page for no-write regions and adapt page margins if necessary
  4387. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  4388. // recalculate coordinates to account for graphic transformations
  4389. if (isset($this->transfmatrix) AND !empty($this->transfmatrix)) {
  4390. for ($i=$this->transfmatrix_key; $i > 0; --$i) {
  4391. $maxid = count($this->transfmatrix[$i]) - 1;
  4392. for ($j=$maxid; $j >= 0; --$j) {
  4393. $ctm = $this->transfmatrix[$i][$j];
  4394. if (isset($ctm['a'])) {
  4395. $x = $x * $this->k;
  4396. $y = ($this->h - $y) * $this->k;
  4397. $w = $w * $this->k;
  4398. $h = $h * $this->k;
  4399. // top left
  4400. $xt = $x;
  4401. $yt = $y;
  4402. $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4403. $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4404. // top right
  4405. $xt = $x + $w;
  4406. $yt = $y;
  4407. $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4408. $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4409. // bottom left
  4410. $xt = $x;
  4411. $yt = $y - $h;
  4412. $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4413. $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4414. // bottom right
  4415. $xt = $x + $w;
  4416. $yt = $y - $h;
  4417. $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4418. $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4419. // new coordinates (rectangle area)
  4420. $x = min($x1, $x2, $x3, $x4);
  4421. $y = max($y1, $y2, $y3, $y4);
  4422. $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k;
  4423. $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k;
  4424. $x = $x / $this->k;
  4425. $y = $this->h - ($y / $this->k);
  4426. }
  4427. }
  4428. }
  4429. }
  4430. if ($this->page <= 0) {
  4431. $page = 1;
  4432. } else {
  4433. $page = $this->page;
  4434. }
  4435. if (!isset($this->PageAnnots[$page])) {
  4436. $this->PageAnnots[$page] = array();
  4437. }
  4438. $this->PageAnnots[$page][] = array('n' => ++$this->n, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces);
  4439. if (!$this->pdfa_mode) {
  4440. if ((($opt['Subtype'] == 'FileAttachment') OR ($opt['Subtype'] == 'Sound')) AND (!TCPDF_STATIC::empty_string($opt['FS']))
  4441. AND (@file_exists($opt['FS']) OR TCPDF_STATIC::isValidURL($opt['FS']))
  4442. AND (!isset($this->embeddedfiles[basename($opt['FS'])]))) {
  4443. $this->embeddedfiles[basename($opt['FS'])] = array('f' => ++$this->n, 'n' => ++$this->n, 'file' => $opt['FS']);
  4444. }
  4445. }
  4446. // Add widgets annotation's icons
  4447. if (isset($opt['mk']['i']) AND @file_exists($opt['mk']['i'])) {
  4448. $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
  4449. }
  4450. if (isset($opt['mk']['ri']) AND @file_exists($opt['mk']['ri'])) {
  4451. $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  4452. }
  4453. if (isset($opt['mk']['ix']) AND @file_exists($opt['mk']['ix'])) {
  4454. $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  4455. }
  4456. }
  4457. /**
  4458. * Embedd the attached files.
  4459. * @since 4.4.000 (2008-12-07)
  4460. * @protected
  4461. * @see Annotation()
  4462. */
  4463. protected function _putEmbeddedFiles() {
  4464. if ($this->pdfa_mode) {
  4465. // embedded files are not allowed in PDF/A mode
  4466. return;
  4467. }
  4468. reset($this->embeddedfiles);
  4469. foreach ($this->embeddedfiles as $filename => $filedata) {
  4470. $data = TCPDF_STATIC::fileGetContents($filedata['file']);
  4471. if ($data !== FALSE) {
  4472. $rawsize = strlen($data);
  4473. if ($rawsize > 0) {
  4474. // update name tree
  4475. $this->efnames[$filename] = $filedata['f'].' 0 R';
  4476. // embedded file specification object
  4477. $out = $this->_getobj($filedata['f'])."\n";
  4478. $out .= '<</Type /Filespec /F '.$this->_datastring($filename, $filedata['f']).' /EF <</F '.$filedata['n'].' 0 R>> >>';
  4479. $out .= "\n".'endobj';
  4480. $this->_out($out);
  4481. // embedded file object
  4482. $filter = '';
  4483. if ($this->compress) {
  4484. $data = gzcompress($data);
  4485. $filter = ' /Filter /FlateDecode';
  4486. }
  4487. $stream = $this->_getrawstream($data, $filedata['n']);
  4488. $out = $this->_getobj($filedata['n'])."\n";
  4489. $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' /Params <</Size '.$rawsize.'>> >>';
  4490. $out .= ' stream'."\n".$stream."\n".'endstream';
  4491. $out .= "\n".'endobj';
  4492. $this->_out($out);
  4493. }
  4494. }
  4495. }
  4496. }
  4497. /**
  4498. * Prints a text cell at the specified position.
  4499. * This method allows to place a string precisely on the page.
  4500. * @param $x (float) Abscissa of the cell origin
  4501. * @param $y (float) Ordinate of the cell origin
  4502. * @param $txt (string) String to print
  4503. * @param $fstroke (int) outline size in user units (false = disable)
  4504. * @param $fclip (boolean) if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
  4505. * @param $ffill (boolean) if true fills the text
  4506. * @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)))
  4507. * @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.
  4508. * @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>
  4509. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  4510. * @param $link (mixed) URL or identifier returned by AddLink().
  4511. * @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.
  4512. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  4513. * @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>
  4514. * @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>
  4515. * @param $rtloff (boolean) if true uses the page top-left corner as origin of axis for $x and $y initial position.
  4516. * @public
  4517. * @since 1.0
  4518. * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
  4519. */
  4520. 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) {
  4521. $textrendermode = $this->textrendermode;
  4522. $textstrokewidth = $this->textstrokewidth;
  4523. $this->setTextRenderingMode($fstroke, $ffill, $fclip);
  4524. $this->SetXY($x, $y, $rtloff);
  4525. $this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
  4526. // restore previous rendering mode
  4527. $this->textrendermode = $textrendermode;
  4528. $this->textstrokewidth = $textstrokewidth;
  4529. }
  4530. /**
  4531. * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
  4532. * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  4533. * This method is called automatically and should not be called directly by the application.
  4534. * @return boolean
  4535. * @public
  4536. * @since 1.4
  4537. * @see SetAutoPageBreak()
  4538. */
  4539. public function AcceptPageBreak() {
  4540. if ($this->num_columns > 1) {
  4541. // multi column mode
  4542. if ($this->current_column < ($this->num_columns - 1)) {
  4543. // go to next column
  4544. $this->selectColumn($this->current_column + 1);
  4545. } elseif ($this->AutoPageBreak) {
  4546. // add a new page
  4547. $this->AddPage();
  4548. // set first column
  4549. $this->selectColumn(0);
  4550. }
  4551. // avoid page breaking from checkPageBreak()
  4552. return false;
  4553. }
  4554. return $this->AutoPageBreak;
  4555. }
  4556. /**
  4557. * Add page if needed.
  4558. * @param $h (float) Cell height. Default value: 0.
  4559. * @param $y (mixed) starting y position, leave empty for current position.
  4560. * @param $addpage (boolean) if true add a page, otherwise only return the true/false state
  4561. * @return boolean true in case of page break, false otherwise.
  4562. * @since 3.2.000 (2008-07-01)
  4563. * @protected
  4564. */
  4565. protected function checkPageBreak($h=0, $y='', $addpage=true) {
  4566. if (TCPDF_STATIC::empty_string($y)) {
  4567. $y = $this->y;
  4568. }
  4569. $current_page = $this->page;
  4570. if ((($y + $h) > $this->PageBreakTrigger) AND ($this->inPageBody()) AND ($this->AcceptPageBreak())) {
  4571. if ($addpage) {
  4572. //Automatic page break
  4573. $x = $this->x;
  4574. $this->AddPage($this->CurOrientation);
  4575. $this->y = $this->tMargin;
  4576. $oldpage = $this->page - 1;
  4577. if ($this->rtl) {
  4578. if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm']) {
  4579. $this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']);
  4580. } else {
  4581. $this->x = $x;
  4582. }
  4583. } else {
  4584. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  4585. $this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']);
  4586. } else {
  4587. $this->x = $x;
  4588. }
  4589. }
  4590. }
  4591. return true;
  4592. }
  4593. if ($current_page != $this->page) {
  4594. // account for columns mode
  4595. return true;
  4596. }
  4597. return false;
  4598. }
  4599. /**
  4600. * 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 />
  4601. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  4602. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  4603. * @param $h (float) Cell height. Default value: 0.
  4604. * @param $txt (string) String to print. Default value: empty string.
  4605. * @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)))
  4606. * @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.
  4607. * @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>
  4608. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  4609. * @param $link (mixed) URL or identifier returned by AddLink().
  4610. * @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.
  4611. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  4612. * @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>
  4613. * @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>
  4614. * @public
  4615. * @since 1.0
  4616. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  4617. */
  4618. 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') {
  4619. $prev_cell_margin = $this->cell_margin;
  4620. $prev_cell_padding = $this->cell_padding;
  4621. $this->adjustCellPadding($border);
  4622. if (!$ignore_min_height) {
  4623. $min_cell_height = $this->getCellHeight($this->FontSize);
  4624. if ($h < $min_cell_height) {
  4625. $h = $min_cell_height;
  4626. }
  4627. }
  4628. $this->checkPageBreak($h + $this->cell_margin['T'] + $this->cell_margin['B']);
  4629. // apply text shadow if enabled
  4630. if ($this->txtshadow['enabled']) {
  4631. // save data
  4632. $x = $this->x;
  4633. $y = $this->y;
  4634. $bc = $this->bgcolor;
  4635. $fc = $this->fgcolor;
  4636. $sc = $this->strokecolor;
  4637. $alpha = $this->alpha;
  4638. // print shadow
  4639. $this->x += $this->txtshadow['depth_w'];
  4640. $this->y += $this->txtshadow['depth_h'];
  4641. $this->SetFillColorArray($this->txtshadow['color']);
  4642. $this->SetTextColorArray($this->txtshadow['color']);
  4643. $this->SetDrawColorArray($this->txtshadow['color']);
  4644. if ($this->txtshadow['opacity'] != $alpha['CA']) {
  4645. $this->setAlpha($this->txtshadow['opacity'], $this->txtshadow['blend_mode']);
  4646. }
  4647. if ($this->state == 2) {
  4648. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  4649. }
  4650. //restore data
  4651. $this->x = $x;
  4652. $this->y = $y;
  4653. $this->SetFillColorArray($bc);
  4654. $this->SetTextColorArray($fc);
  4655. $this->SetDrawColorArray($sc);
  4656. if ($this->txtshadow['opacity'] != $alpha['CA']) {
  4657. $this->setAlpha($alpha['CA'], $alpha['BM'], $alpha['ca'], $alpha['AIS']);
  4658. }
  4659. }
  4660. if ($this->state == 2) {
  4661. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  4662. }
  4663. $this->cell_padding = $prev_cell_padding;
  4664. $this->cell_margin = $prev_cell_margin;
  4665. }
  4666. /**
  4667. * 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 />
  4668. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  4669. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  4670. * @param $h (float) Cell height. Default value: 0.
  4671. * @param $txt (string) String to print. Default value: empty string.
  4672. * @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)))
  4673. * @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.
  4674. * @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>
  4675. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  4676. * @param $link (mixed) URL or identifier returned by AddLink().
  4677. * @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.
  4678. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  4679. * @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>
  4680. * @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>
  4681. * @return string containing cell code
  4682. * @protected
  4683. * @since 1.0
  4684. * @see Cell()
  4685. */
  4686. 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') {
  4687. // replace 'NO-BREAK SPACE' (U+00A0) character with a simple space
  4688. $txt = str_replace(TCPDF_FONTS::unichr(160, $this->isunicode), ' ', $txt);
  4689. $prev_cell_margin = $this->cell_margin;
  4690. $prev_cell_padding = $this->cell_padding;
  4691. $txt = TCPDF_STATIC::removeSHY($txt, $this->isunicode);
  4692. $rs = ''; //string to be returned
  4693. $this->adjustCellPadding($border);
  4694. if (!$ignore_min_height) {
  4695. $min_cell_height = $this->getCellHeight($this->FontSize);
  4696. if ($h < $min_cell_height) {
  4697. $h = $min_cell_height;
  4698. }
  4699. }
  4700. $k = $this->k;
  4701. // check page for no-write regions and adapt page margins if necessary
  4702. list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
  4703. if ($this->rtl) {
  4704. $x = $this->x - $this->cell_margin['R'];
  4705. } else {
  4706. $x = $this->x + $this->cell_margin['L'];
  4707. }
  4708. $y = $this->y + $this->cell_margin['T'];
  4709. $prev_font_stretching = $this->font_stretching;
  4710. $prev_font_spacing = $this->font_spacing;
  4711. // cell vertical alignment
  4712. switch ($calign) {
  4713. case 'A': {
  4714. // font top
  4715. switch ($valign) {
  4716. case 'T': {
  4717. // top
  4718. $y -= $this->cell_padding['T'];
  4719. break;
  4720. }
  4721. case 'B': {
  4722. // bottom
  4723. $y -= ($h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent);
  4724. break;
  4725. }
  4726. default:
  4727. case 'C':
  4728. case 'M': {
  4729. // center
  4730. $y -= (($h - $this->FontAscent - $this->FontDescent) / 2);
  4731. break;
  4732. }
  4733. }
  4734. break;
  4735. }
  4736. case 'L': {
  4737. // font baseline
  4738. switch ($valign) {
  4739. case 'T': {
  4740. // top
  4741. $y -= ($this->cell_padding['T'] + $this->FontAscent);
  4742. break;
  4743. }
  4744. case 'B': {
  4745. // bottom
  4746. $y -= ($h - $this->cell_padding['B'] - $this->FontDescent);
  4747. break;
  4748. }
  4749. default:
  4750. case 'C':
  4751. case 'M': {
  4752. // center
  4753. $y -= (($h + $this->FontAscent - $this->FontDescent) / 2);
  4754. break;
  4755. }
  4756. }
  4757. break;
  4758. }
  4759. case 'D': {
  4760. // font bottom
  4761. switch ($valign) {
  4762. case 'T': {
  4763. // top
  4764. $y -= ($this->cell_padding['T'] + $this->FontAscent + $this->FontDescent);
  4765. break;
  4766. }
  4767. case 'B': {
  4768. // bottom
  4769. $y -= ($h - $this->cell_padding['B']);
  4770. break;
  4771. }
  4772. default:
  4773. case 'C':
  4774. case 'M': {
  4775. // center
  4776. $y -= (($h + $this->FontAscent + $this->FontDescent) / 2);
  4777. break;
  4778. }
  4779. }
  4780. break;
  4781. }
  4782. case 'B': {
  4783. // cell bottom
  4784. $y -= $h;
  4785. break;
  4786. }
  4787. case 'C':
  4788. case 'M': {
  4789. // cell center
  4790. $y -= ($h / 2);
  4791. break;
  4792. }
  4793. default:
  4794. case 'T': {
  4795. // cell top
  4796. break;
  4797. }
  4798. }
  4799. // text vertical alignment
  4800. switch ($valign) {
  4801. case 'T': {
  4802. // top
  4803. $yt = $y + $this->cell_padding['T'];
  4804. break;
  4805. }
  4806. case 'B': {
  4807. // bottom
  4808. $yt = $y + $h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent;
  4809. break;
  4810. }
  4811. default:
  4812. case 'C':
  4813. case 'M': {
  4814. // center
  4815. $yt = $y + (($h - $this->FontAscent - $this->FontDescent) / 2);
  4816. break;
  4817. }
  4818. }
  4819. $basefonty = $yt + $this->FontAscent;
  4820. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  4821. if ($this->rtl) {
  4822. $w = $x - $this->lMargin;
  4823. } else {
  4824. $w = $this->w - $this->rMargin - $x;
  4825. }
  4826. }
  4827. $s = '';
  4828. // fill and borders
  4829. if (is_string($border) AND (strlen($border) == 4)) {
  4830. // full border
  4831. $border = 1;
  4832. }
  4833. if ($fill OR ($border == 1)) {
  4834. if ($fill) {
  4835. $op = ($border == 1) ? 'B' : 'f';
  4836. } else {
  4837. $op = 'S';
  4838. }
  4839. if ($this->rtl) {
  4840. $xk = (($x - $w) * $k);
  4841. } else {
  4842. $xk = ($x * $k);
  4843. }
  4844. $s .= sprintf('%F %F %F %F re %s ', $xk, (($this->h - $y) * $k), ($w * $k), (-$h * $k), $op);
  4845. }
  4846. // draw borders
  4847. $s .= $this->getCellBorder($x, $y, $w, $h, $border);
  4848. if ($txt != '') {
  4849. $txt2 = $txt;
  4850. if ($this->isunicode) {
  4851. if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
  4852. $txt2 = TCPDF_FONTS::UTF8ToLatin1($txt2, $this->isunicode, $this->CurrentFont);
  4853. } else {
  4854. $unicode = TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont); // array of UTF-8 unicode values
  4855. $unicode = TCPDF_FONTS::utf8Bidi($unicode, '', $this->tmprtl, $this->isunicode, $this->CurrentFont);
  4856. // replace thai chars (if any)
  4857. if (defined('K_THAI_TOPCHARS') AND (K_THAI_TOPCHARS == true)) {
  4858. // number of chars
  4859. $numchars = count($unicode);
  4860. // po pla, for far, for fan
  4861. $longtail = array(0x0e1b, 0x0e1d, 0x0e1f);
  4862. // do chada, to patak
  4863. $lowtail = array(0x0e0e, 0x0e0f);
  4864. // mai hun arkad, sara i, sara ii, sara ue, sara uee
  4865. $upvowel = array(0x0e31, 0x0e34, 0x0e35, 0x0e36, 0x0e37);
  4866. // mai ek, mai tho, mai tri, mai chattawa, karan
  4867. $tonemark = array(0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c);
  4868. // sara u, sara uu, pinthu
  4869. $lowvowel = array(0x0e38, 0x0e39, 0x0e3a);
  4870. $output = array();
  4871. for ($i = 0; $i < $numchars; $i++) {
  4872. if (($unicode[$i] >= 0x0e00) && ($unicode[$i] <= 0x0e5b)) {
  4873. $ch0 = $unicode[$i];
  4874. $ch1 = ($i > 0) ? $unicode[($i - 1)] : 0;
  4875. $ch2 = ($i > 1) ? $unicode[($i - 2)] : 0;
  4876. $chn = ($i < ($numchars - 1)) ? $unicode[($i + 1)] : 0;
  4877. if (in_array($ch0, $tonemark)) {
  4878. if ($chn == 0x0e33) {
  4879. // sara um
  4880. if (in_array($ch1, $longtail)) {
  4881. // tonemark at upper left
  4882. $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
  4883. } else {
  4884. // tonemark at upper right (normal position)
  4885. $output[] = $ch0;
  4886. }
  4887. } elseif (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $lowvowel))) {
  4888. // tonemark at lower left
  4889. $output[] = $this->replaceChar($ch0, (0xf705 + $ch0 - 0x0e48));
  4890. } elseif (in_array($ch1, $upvowel)) {
  4891. if (in_array($ch2, $longtail)) {
  4892. // tonemark at upper left
  4893. $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
  4894. } else {
  4895. // tonemark at upper right (normal position)
  4896. $output[] = $ch0;
  4897. }
  4898. } else {
  4899. // tonemark at lower right
  4900. $output[] = $this->replaceChar($ch0, (0xf70a + $ch0 - 0x0e48));
  4901. }
  4902. } elseif (($ch0 == 0x0e33) AND (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $tonemark)))) {
  4903. // add lower left nikhahit and sara aa
  4904. if ($this->isCharDefined(0xf711) AND $this->isCharDefined(0x0e32)) {
  4905. $output[] = 0xf711;
  4906. $this->CurrentFont['subsetchars'][0xf711] = true;
  4907. $output[] = 0x0e32;
  4908. $this->CurrentFont['subsetchars'][0x0e32] = true;
  4909. } else {
  4910. $output[] = $ch0;
  4911. }
  4912. } elseif (in_array($ch1, $longtail)) {
  4913. if ($ch0 == 0x0e31) {
  4914. // lower left mai hun arkad
  4915. $output[] = $this->replaceChar($ch0, 0xf710);
  4916. } elseif (in_array($ch0, $upvowel)) {
  4917. // lower left
  4918. $output[] = $this->replaceChar($ch0, (0xf701 + $ch0 - 0x0e34));
  4919. } elseif ($ch0 == 0x0e47) {
  4920. // lower left mai tai koo
  4921. $output[] = $this->replaceChar($ch0, 0xf712);
  4922. } else {
  4923. // normal character
  4924. $output[] = $ch0;
  4925. }
  4926. } elseif (in_array($ch1, $lowtail) AND in_array($ch0, $lowvowel)) {
  4927. // lower vowel
  4928. $output[] = $this->replaceChar($ch0, (0xf718 + $ch0 - 0x0e38));
  4929. } elseif (($ch0 == 0x0e0d) AND in_array($chn, $lowvowel)) {
  4930. // yo ying without lower part
  4931. $output[] = $this->replaceChar($ch0, 0xf70f);
  4932. } elseif (($ch0 == 0x0e10) AND in_array($chn, $lowvowel)) {
  4933. // tho santan without lower part
  4934. $output[] = $this->replaceChar($ch0, 0xf700);
  4935. } else {
  4936. $output[] = $ch0;
  4937. }
  4938. } else {
  4939. // non-thai character
  4940. $output[] = $unicode[$i];
  4941. }
  4942. }
  4943. $unicode = $output;
  4944. // update font subsetchars
  4945. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  4946. } // end of K_THAI_TOPCHARS
  4947. $txt2 = TCPDF_FONTS::arrUTF8ToUTF16BE($unicode, false);
  4948. }
  4949. }
  4950. $txt2 = TCPDF_STATIC::_escape($txt2);
  4951. // get current text width (considering general font stretching and spacing)
  4952. $txwidth = $this->GetStringWidth($txt);
  4953. $width = $txwidth;
  4954. // check for stretch mode
  4955. if ($stretch > 0) {
  4956. // calculate ratio between cell width and text width
  4957. if ($width <= 0) {
  4958. $ratio = 1;
  4959. } else {
  4960. $ratio = (($w - $this->cell_padding['L'] - $this->cell_padding['R']) / $width);
  4961. }
  4962. // check if stretching is required
  4963. if (($ratio < 1) OR (($ratio > 1) AND (($stretch % 2) == 0))) {
  4964. // the text will be stretched to fit cell width
  4965. if ($stretch > 2) {
  4966. // set new character spacing
  4967. $this->font_spacing += ($w - $this->cell_padding['L'] - $this->cell_padding['R'] - $width) / (max(($this->GetNumChars($txt) - 1), 1) * ($this->font_stretching / 100));
  4968. } else {
  4969. // set new horizontal stretching
  4970. $this->font_stretching *= $ratio;
  4971. }
  4972. // recalculate text width (the text fills the entire cell)
  4973. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  4974. // reset alignment
  4975. $align = '';
  4976. }
  4977. }
  4978. if ($this->font_stretching != 100) {
  4979. // apply font stretching
  4980. $rs .= sprintf('BT %F Tz ET ', $this->font_stretching);
  4981. }
  4982. if ($this->font_spacing != 0) {
  4983. // increase/decrease font spacing
  4984. $rs .= sprintf('BT %F Tc ET ', ($this->font_spacing * $this->k));
  4985. }
  4986. if ($this->ColorFlag AND ($this->textrendermode < 4)) {
  4987. $s .= 'q '.$this->TextColor.' ';
  4988. }
  4989. // rendering mode
  4990. $s .= sprintf('BT %d Tr %F w ET ', $this->textrendermode, ($this->textstrokewidth * $this->k));
  4991. // count number of spaces
  4992. $ns = substr_count($txt, chr(32));
  4993. // Justification
  4994. $spacewidth = 0;
  4995. if (($align == 'J') AND ($ns > 0)) {
  4996. if ($this->isUnicodeFont()) {
  4997. // get string width without spaces
  4998. $width = $this->GetStringWidth(str_replace(' ', '', $txt));
  4999. // calculate average space width
  5000. $spacewidth = -1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1) / ($this->FontSize?$this->FontSize:1);
  5001. if ($this->font_stretching != 100) {
  5002. // word spacing is affected by stretching
  5003. $spacewidth /= ($this->font_stretching / 100);
  5004. }
  5005. // set word position to be used with TJ operator
  5006. $txt2 = str_replace(chr(0).chr(32), ') '.sprintf('%F', $spacewidth).' (', $txt2);
  5007. $unicode_justification = true;
  5008. } else {
  5009. // get string width
  5010. $width = $txwidth;
  5011. // new space width
  5012. $spacewidth = (($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1)) * $this->k;
  5013. if ($this->font_stretching != 100) {
  5014. // word spacing (Tw) is affected by stretching
  5015. $spacewidth /= ($this->font_stretching / 100);
  5016. }
  5017. // set word spacing
  5018. $rs .= sprintf('BT %F Tw ET ', $spacewidth);
  5019. }
  5020. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5021. }
  5022. // replace carriage return characters
  5023. $txt2 = str_replace("\r", ' ', $txt2);
  5024. switch ($align) {
  5025. case 'C': {
  5026. $dx = ($w - $width) / 2;
  5027. break;
  5028. }
  5029. case 'R': {
  5030. if ($this->rtl) {
  5031. $dx = $this->cell_padding['R'];
  5032. } else {
  5033. $dx = $w - $width - $this->cell_padding['R'];
  5034. }
  5035. break;
  5036. }
  5037. case 'L': {
  5038. if ($this->rtl) {
  5039. $dx = $w - $width - $this->cell_padding['L'];
  5040. } else {
  5041. $dx = $this->cell_padding['L'];
  5042. }
  5043. break;
  5044. }
  5045. case 'J':
  5046. default: {
  5047. if ($this->rtl) {
  5048. $dx = $this->cell_padding['R'];
  5049. } else {
  5050. $dx = $this->cell_padding['L'];
  5051. }
  5052. break;
  5053. }
  5054. }
  5055. if ($this->rtl) {
  5056. $xdx = $x - $dx - $width;
  5057. } else {
  5058. $xdx = $x + $dx;
  5059. }
  5060. $xdk = $xdx * $k;
  5061. // print text
  5062. $s .= sprintf('BT %F %F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
  5063. if (isset($uniblock)) {
  5064. // print overlapping characters as separate string
  5065. $xshift = 0; // horizontal shift
  5066. $ty = (($this->h - $basefonty + (0.2 * $this->FontSize)) * $k);
  5067. $spw = (($w - $txwidth - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1));
  5068. foreach ($uniblock as $uk => $uniarr) {
  5069. if (($uk % 2) == 0) {
  5070. // x space to skip
  5071. if ($spacewidth != 0) {
  5072. // justification shift
  5073. $xshift += (count(array_keys($uniarr, 32)) * $spw);
  5074. }
  5075. $xshift += $this->GetArrStringWidth($uniarr); // + shift justification
  5076. } else {
  5077. // character to print
  5078. $topchr = TCPDF_FONTS::arrUTF8ToUTF16BE($uniarr, false);
  5079. $topchr = TCPDF_STATIC::_escape($topchr);
  5080. $s .= sprintf(' BT %F %F Td [(%s)] TJ ET', ($xdk + ($xshift * $k)), $ty, $topchr);
  5081. }
  5082. }
  5083. }
  5084. if ($this->underline) {
  5085. $s .= ' '.$this->_dounderlinew($xdx, $basefonty, $width);
  5086. }
  5087. if ($this->linethrough) {
  5088. $s .= ' '.$this->_dolinethroughw($xdx, $basefonty, $width);
  5089. }
  5090. if ($this->overline) {
  5091. $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width);
  5092. }
  5093. if ($this->ColorFlag AND ($this->textrendermode < 4)) {
  5094. $s .= ' Q';
  5095. }
  5096. if ($link) {
  5097. $this->Link($xdx, $yt, $width, ($this->FontAscent + $this->FontDescent), $link, $ns);
  5098. }
  5099. }
  5100. // output cell
  5101. if ($s) {
  5102. // output cell
  5103. $rs .= $s;
  5104. if ($this->font_spacing != 0) {
  5105. // reset font spacing mode
  5106. $rs .= ' BT 0 Tc ET';
  5107. }
  5108. if ($this->font_stretching != 100) {
  5109. // reset font stretching mode
  5110. $rs .= ' BT 100 Tz ET';
  5111. }
  5112. }
  5113. // reset word spacing
  5114. if (!$this->isUnicodeFont() AND ($align == 'J')) {
  5115. $rs .= ' BT 0 Tw ET';
  5116. }
  5117. // reset stretching and spacing
  5118. $this->font_stretching = $prev_font_stretching;
  5119. $this->font_spacing = $prev_font_spacing;
  5120. $this->lasth = $h;
  5121. if ($ln > 0) {
  5122. //Go to the beginning of the next line
  5123. $this->y = $y + $h + $this->cell_margin['B'];
  5124. if ($ln == 1) {
  5125. if ($this->rtl) {
  5126. $this->x = $this->w - $this->rMargin;
  5127. } else {
  5128. $this->x = $this->lMargin;
  5129. }
  5130. }
  5131. } else {
  5132. // go left or right by case
  5133. if ($this->rtl) {
  5134. $this->x = $x - $w - $this->cell_margin['L'];
  5135. } else {
  5136. $this->x = $x + $w + $this->cell_margin['R'];
  5137. }
  5138. }
  5139. $gstyles = ''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor."\n";
  5140. $rs = $gstyles.$rs;
  5141. $this->cell_padding = $prev_cell_padding;
  5142. $this->cell_margin = $prev_cell_margin;
  5143. return $rs;
  5144. }
  5145. /**
  5146. * Replace a char if is defined on the current font.
  5147. * @param $oldchar (int) Integer code (unicode) of the character to replace.
  5148. * @param $newchar (int) Integer code (unicode) of the new character.
  5149. * @return int the replaced char or the old char in case the new char i not defined
  5150. * @protected
  5151. * @since 5.9.167 (2012-06-22)
  5152. */
  5153. protected function replaceChar($oldchar, $newchar) {
  5154. if ($this->isCharDefined($newchar)) {
  5155. // add the new char on the subset list
  5156. $this->CurrentFont['subsetchars'][$newchar] = true;
  5157. // return the new character
  5158. return $newchar;
  5159. }
  5160. // return the old char
  5161. return $oldchar;
  5162. }
  5163. /**
  5164. * Returns the code to draw the cell border
  5165. * @param $x (float) X coordinate.
  5166. * @param $y (float) Y coordinate.
  5167. * @param $w (float) Cell width.
  5168. * @param $h (float) Cell height.
  5169. * @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)))
  5170. * @return string containing cell border code
  5171. * @protected
  5172. * @see SetLineStyle()
  5173. * @since 5.7.000 (2010-08-02)
  5174. */
  5175. protected function getCellBorder($x, $y, $w, $h, $brd) {
  5176. $s = ''; // string to be returned
  5177. if (empty($brd)) {
  5178. return $s;
  5179. }
  5180. if ($brd == 1) {
  5181. $brd = array('LRTB' => true);
  5182. }
  5183. // calculate coordinates for border
  5184. $k = $this->k;
  5185. if ($this->rtl) {
  5186. $xeL = ($x - $w) * $k;
  5187. $xeR = $x * $k;
  5188. } else {
  5189. $xeL = $x * $k;
  5190. $xeR = ($x + $w) * $k;
  5191. }
  5192. $yeL = (($this->h - ($y + $h)) * $k);
  5193. $yeT = (($this->h - $y) * $k);
  5194. $xeT = $xeL;
  5195. $xeB = $xeR;
  5196. $yeR = $yeT;
  5197. $yeB = $yeL;
  5198. if (is_string($brd)) {
  5199. // convert string to array
  5200. $slen = strlen($brd);
  5201. $newbrd = array();
  5202. for ($i = 0; $i < $slen; ++$i) {
  5203. $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
  5204. }
  5205. $brd = $newbrd;
  5206. }
  5207. if (isset($brd['mode'])) {
  5208. $mode = $brd['mode'];
  5209. unset($brd['mode']);
  5210. } else {
  5211. $mode = 'normal';
  5212. }
  5213. foreach ($brd as $border => $style) {
  5214. if (is_array($style) AND !empty($style)) {
  5215. // apply border style
  5216. $prev_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' ';
  5217. $s .= $this->SetLineStyle($style, true)."\n";
  5218. }
  5219. switch ($mode) {
  5220. case 'ext': {
  5221. $off = (($this->LineWidth / 2) * $k);
  5222. $xL = $xeL - $off;
  5223. $xR = $xeR + $off;
  5224. $yT = $yeT + $off;
  5225. $yL = $yeL - $off;
  5226. $xT = $xL;
  5227. $xB = $xR;
  5228. $yR = $yT;
  5229. $yB = $yL;
  5230. $w += $this->LineWidth;
  5231. $h += $this->LineWidth;
  5232. break;
  5233. }
  5234. case 'int': {
  5235. $off = ($this->LineWidth / 2) * $k;
  5236. $xL = $xeL + $off;
  5237. $xR = $xeR - $off;
  5238. $yT = $yeT - $off;
  5239. $yL = $yeL + $off;
  5240. $xT = $xL;
  5241. $xB = $xR;
  5242. $yR = $yT;
  5243. $yB = $yL;
  5244. $w -= $this->LineWidth;
  5245. $h -= $this->LineWidth;
  5246. break;
  5247. }
  5248. case 'normal':
  5249. default: {
  5250. $xL = $xeL;
  5251. $xT = $xeT;
  5252. $xB = $xeB;
  5253. $xR = $xeR;
  5254. $yL = $yeL;
  5255. $yT = $yeT;
  5256. $yB = $yeB;
  5257. $yR = $yeR;
  5258. break;
  5259. }
  5260. }
  5261. // draw borders by case
  5262. if (strlen($border) == 4) {
  5263. $s .= sprintf('%F %F %F %F re S ', $xT, $yT, ($w * $k), (-$h * $k));
  5264. } elseif (strlen($border) == 3) {
  5265. if (strpos($border,'B') === false) { // LTR
  5266. $s .= sprintf('%F %F m ', $xL, $yL);
  5267. $s .= sprintf('%F %F l ', $xT, $yT);
  5268. $s .= sprintf('%F %F l ', $xR, $yR);
  5269. $s .= sprintf('%F %F l ', $xB, $yB);
  5270. $s .= 'S ';
  5271. } elseif (strpos($border,'L') === false) { // TRB
  5272. $s .= sprintf('%F %F m ', $xT, $yT);
  5273. $s .= sprintf('%F %F l ', $xR, $yR);
  5274. $s .= sprintf('%F %F l ', $xB, $yB);
  5275. $s .= sprintf('%F %F l ', $xL, $yL);
  5276. $s .= 'S ';
  5277. } elseif (strpos($border,'T') === false) { // RBL
  5278. $s .= sprintf('%F %F m ', $xR, $yR);
  5279. $s .= sprintf('%F %F l ', $xB, $yB);
  5280. $s .= sprintf('%F %F l ', $xL, $yL);
  5281. $s .= sprintf('%F %F l ', $xT, $yT);
  5282. $s .= 'S ';
  5283. } elseif (strpos($border,'R') === false) { // BLT
  5284. $s .= sprintf('%F %F m ', $xB, $yB);
  5285. $s .= sprintf('%F %F l ', $xL, $yL);
  5286. $s .= sprintf('%F %F l ', $xT, $yT);
  5287. $s .= sprintf('%F %F l ', $xR, $yR);
  5288. $s .= 'S ';
  5289. }
  5290. } elseif (strlen($border) == 2) {
  5291. if ((strpos($border,'L') !== false) AND (strpos($border,'T') !== false)) { // LT
  5292. $s .= sprintf('%F %F m ', $xL, $yL);
  5293. $s .= sprintf('%F %F l ', $xT, $yT);
  5294. $s .= sprintf('%F %F l ', $xR, $yR);
  5295. $s .= 'S ';
  5296. } elseif ((strpos($border,'T') !== false) AND (strpos($border,'R') !== false)) { // TR
  5297. $s .= sprintf('%F %F m ', $xT, $yT);
  5298. $s .= sprintf('%F %F l ', $xR, $yR);
  5299. $s .= sprintf('%F %F l ', $xB, $yB);
  5300. $s .= 'S ';
  5301. } elseif ((strpos($border,'R') !== false) AND (strpos($border,'B') !== false)) { // RB
  5302. $s .= sprintf('%F %F m ', $xR, $yR);
  5303. $s .= sprintf('%F %F l ', $xB, $yB);
  5304. $s .= sprintf('%F %F l ', $xL, $yL);
  5305. $s .= 'S ';
  5306. } elseif ((strpos($border,'B') !== false) AND (strpos($border,'L') !== false)) { // BL
  5307. $s .= sprintf('%F %F m ', $xB, $yB);
  5308. $s .= sprintf('%F %F l ', $xL, $yL);
  5309. $s .= sprintf('%F %F l ', $xT, $yT);
  5310. $s .= 'S ';
  5311. } elseif ((strpos($border,'L') !== false) AND (strpos($border,'R') !== false)) { // LR
  5312. $s .= sprintf('%F %F m ', $xL, $yL);
  5313. $s .= sprintf('%F %F l ', $xT, $yT);
  5314. $s .= 'S ';
  5315. $s .= sprintf('%F %F m ', $xR, $yR);
  5316. $s .= sprintf('%F %F l ', $xB, $yB);
  5317. $s .= 'S ';
  5318. } elseif ((strpos($border,'T') !== false) AND (strpos($border,'B') !== false)) { // TB
  5319. $s .= sprintf('%F %F m ', $xT, $yT);
  5320. $s .= sprintf('%F %F l ', $xR, $yR);
  5321. $s .= 'S ';
  5322. $s .= sprintf('%F %F m ', $xB, $yB);
  5323. $s .= sprintf('%F %F l ', $xL, $yL);
  5324. $s .= 'S ';
  5325. }
  5326. } else { // strlen($border) == 1
  5327. if (strpos($border,'L') !== false) { // L
  5328. $s .= sprintf('%F %F m ', $xL, $yL);
  5329. $s .= sprintf('%F %F l ', $xT, $yT);
  5330. $s .= 'S ';
  5331. } elseif (strpos($border,'T') !== false) { // T
  5332. $s .= sprintf('%F %F m ', $xT, $yT);
  5333. $s .= sprintf('%F %F l ', $xR, $yR);
  5334. $s .= 'S ';
  5335. } elseif (strpos($border,'R') !== false) { // R
  5336. $s .= sprintf('%F %F m ', $xR, $yR);
  5337. $s .= sprintf('%F %F l ', $xB, $yB);
  5338. $s .= 'S ';
  5339. } elseif (strpos($border,'B') !== false) { // B
  5340. $s .= sprintf('%F %F m ', $xB, $yB);
  5341. $s .= sprintf('%F %F l ', $xL, $yL);
  5342. $s .= 'S ';
  5343. }
  5344. }
  5345. if (is_array($style) AND !empty($style)) {
  5346. // reset border style to previous value
  5347. $s .= "\n".$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor."\n";
  5348. }
  5349. }
  5350. return $s;
  5351. }
  5352. /**
  5353. * This method allows printing text with line breaks.
  5354. * 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 />
  5355. * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  5356. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  5357. * @param $h (float) Cell minimum height. The cell extends automatically if needed.
  5358. * @param $txt (string) String to print
  5359. * @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)))
  5360. * @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>
  5361. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  5362. * @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>
  5363. * @param $x (float) x position in user units
  5364. * @param $y (float) y position in user units
  5365. * @param $reseth (boolean) if true reset the last cell height (default true).
  5366. * @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.
  5367. * @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.
  5368. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width.
  5369. * @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.
  5370. * @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.
  5371. * @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).
  5372. * @return int Return the number of cells or 1 for html mode.
  5373. * @public
  5374. * @since 1.3
  5375. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  5376. */
  5377. 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) {
  5378. $prev_cell_margin = $this->cell_margin;
  5379. $prev_cell_padding = $this->cell_padding;
  5380. // adjust internal padding
  5381. $this->adjustCellPadding($border);
  5382. $mc_padding = $this->cell_padding;
  5383. $mc_margin = $this->cell_margin;
  5384. $this->cell_padding['T'] = 0;
  5385. $this->cell_padding['B'] = 0;
  5386. $this->setCellMargins(0, 0, 0, 0);
  5387. if (TCPDF_STATIC::empty_string($this->lasth) OR $reseth) {
  5388. // reset row height
  5389. $this->resetLastH();
  5390. }
  5391. if (!TCPDF_STATIC::empty_string($y)) {
  5392. $this->SetY($y);
  5393. } else {
  5394. $y = $this->GetY();
  5395. }
  5396. $resth = 0;
  5397. if (($h > 0) AND $this->inPageBody() AND (($y + $h + $mc_margin['T'] + $mc_margin['B']) > $this->PageBreakTrigger)) {
  5398. // spit cell in more pages/columns
  5399. $newh = ($this->PageBreakTrigger - $y);
  5400. $resth = ($h - $newh); // cell to be printed on the next page/column
  5401. $h = $newh;
  5402. }
  5403. // get current page number
  5404. $startpage = $this->page;
  5405. // get current column
  5406. $startcolumn = $this->current_column;
  5407. if (!TCPDF_STATIC::empty_string($x)) {
  5408. $this->SetX($x);
  5409. } else {
  5410. $x = $this->GetX();
  5411. }
  5412. // check page for no-write regions and adapt page margins if necessary
  5413. list($x, $y) = $this->checkPageRegions(0, $x, $y);
  5414. // apply margins
  5415. $oy = $y + $mc_margin['T'];
  5416. if ($this->rtl) {
  5417. $ox = ($this->w - $x - $mc_margin['R']);
  5418. } else {
  5419. $ox = ($x + $mc_margin['L']);
  5420. }
  5421. $this->x = $ox;
  5422. $this->y = $oy;
  5423. // set width
  5424. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  5425. if ($this->rtl) {
  5426. $w = ($this->x - $this->lMargin - $mc_margin['L']);
  5427. } else {
  5428. $w = ($this->w - $this->x - $this->rMargin - $mc_margin['R']);
  5429. }
  5430. }
  5431. // store original margin values
  5432. $lMargin = $this->lMargin;
  5433. $rMargin = $this->rMargin;
  5434. if ($this->rtl) {
  5435. $this->rMargin = ($this->w - $this->x);
  5436. $this->lMargin = ($this->x - $w);
  5437. } else {
  5438. $this->lMargin = ($this->x);
  5439. $this->rMargin = ($this->w - $this->x - $w);
  5440. }
  5441. $this->clMargin = $this->lMargin;
  5442. $this->crMargin = $this->rMargin;
  5443. if ($autopadding) {
  5444. // add top padding
  5445. $this->y += $mc_padding['T'];
  5446. }
  5447. if ($ishtml) { // ******* Write HTML text
  5448. $this->writeHTML($txt, true, false, $reseth, true, $align);
  5449. $nl = 1;
  5450. } else { // ******* Write simple text
  5451. $prev_FontSizePt = $this->FontSizePt;
  5452. // vertical alignment
  5453. if ($maxh > 0) {
  5454. // get text height
  5455. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5456. if ($fitcell) {
  5457. // try to reduce font size to fit text on cell (use a quick search algorithm)
  5458. $fmin = 1;
  5459. $fmax = $this->FontSizePt;
  5460. $prev_text_height = $text_height;
  5461. $maxit = 100; // max number of iterations
  5462. while ($maxit > 0) {
  5463. $fmid = (($fmax + $fmin) / 2);
  5464. $this->SetFontSize($fmid, false);
  5465. $this->resetLastH();
  5466. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5467. if (($text_height == $maxh) OR (($text_height < $maxh) AND ($fmin >= ($fmax - 0.01)))) {
  5468. break;
  5469. } elseif ($text_height < $maxh) {
  5470. $fmin = $fmid;
  5471. } else {
  5472. $fmax = $fmid;
  5473. }
  5474. --$maxit;
  5475. }
  5476. $this->SetFontSize($this->FontSizePt);
  5477. }
  5478. if ($text_height < $maxh) {
  5479. if ($valign == 'M') {
  5480. // text vertically centered
  5481. $this->y += (($maxh - $text_height) / 2);
  5482. } elseif ($valign == 'B') {
  5483. // text vertically aligned on bottom
  5484. $this->y += ($maxh - $text_height);
  5485. }
  5486. }
  5487. }
  5488. $nl = $this->Write($this->lasth, $txt, '', 0, $align, true, $stretch, false, true, $maxh, 0, $mc_margin);
  5489. if ($fitcell) {
  5490. // restore font size
  5491. $this->SetFontSize($prev_FontSizePt);
  5492. }
  5493. }
  5494. if ($autopadding) {
  5495. // add bottom padding
  5496. $this->y += $mc_padding['B'];
  5497. }
  5498. // Get end-of-text Y position
  5499. $currentY = $this->y;
  5500. // get latest page number
  5501. $endpage = $this->page;
  5502. if ($resth > 0) {
  5503. $skip = ($endpage - $startpage);
  5504. $tmpresth = $resth;
  5505. while ($tmpresth > 0) {
  5506. if ($skip <= 0) {
  5507. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  5508. $this->checkPageBreak($this->PageBreakTrigger + 1);
  5509. }
  5510. if ($this->num_columns > 1) {
  5511. $tmpresth -= ($this->h - $this->y - $this->bMargin);
  5512. } else {
  5513. $tmpresth -= ($this->h - $this->tMargin - $this->bMargin);
  5514. }
  5515. --$skip;
  5516. }
  5517. $currentY = $this->y;
  5518. $endpage = $this->page;
  5519. }
  5520. // get latest column
  5521. $endcolumn = $this->current_column;
  5522. if ($this->num_columns == 0) {
  5523. $this->num_columns = 1;
  5524. }
  5525. // disable page regions check
  5526. $check_page_regions = $this->check_page_regions;
  5527. $this->check_page_regions = false;
  5528. // get border modes
  5529. $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
  5530. $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
  5531. $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  5532. // design borders around HTML cells.
  5533. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  5534. $ccode = '';
  5535. $this->setPage($page);
  5536. if ($this->num_columns < 2) {
  5537. // single-column mode
  5538. $this->SetX($x);
  5539. $this->y = $this->tMargin;
  5540. }
  5541. // account for margin changes
  5542. if ($page > $startpage) {
  5543. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  5544. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  5545. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  5546. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  5547. }
  5548. }
  5549. if ($startpage == $endpage) {
  5550. // single page
  5551. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  5552. $this->selectColumn($column);
  5553. if ($this->rtl) {
  5554. $this->x -= $mc_margin['R'];
  5555. } else {
  5556. $this->x += $mc_margin['L'];
  5557. }
  5558. if ($startcolumn == $endcolumn) { // single column
  5559. $cborder = $border;
  5560. $h = max($h, ($currentY - $oy));
  5561. $this->y = $oy;
  5562. } elseif ($column == $startcolumn) { // first column
  5563. $cborder = $border_start;
  5564. $this->y = $oy;
  5565. $h = $this->h - $this->y - $this->bMargin;
  5566. } elseif ($column == $endcolumn) { // end column
  5567. $cborder = $border_end;
  5568. $h = $currentY - $this->y;
  5569. if ($resth > $h) {
  5570. $h = $resth;
  5571. }
  5572. } else { // middle column
  5573. $cborder = $border_middle;
  5574. $h = $this->h - $this->y - $this->bMargin;
  5575. $resth -= $h;
  5576. }
  5577. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5578. } // end for each column
  5579. } elseif ($page == $startpage) { // first page
  5580. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  5581. $this->selectColumn($column);
  5582. if ($this->rtl) {
  5583. $this->x -= $mc_margin['R'];
  5584. } else {
  5585. $this->x += $mc_margin['L'];
  5586. }
  5587. if ($column == $startcolumn) { // first column
  5588. $cborder = $border_start;
  5589. $this->y = $oy;
  5590. $h = $this->h - $this->y - $this->bMargin;
  5591. } else { // middle column
  5592. $cborder = $border_middle;
  5593. $h = $this->h - $this->y - $this->bMargin;
  5594. $resth -= $h;
  5595. }
  5596. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5597. } // end for each column
  5598. } elseif ($page == $endpage) { // last page
  5599. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  5600. $this->selectColumn($column);
  5601. if ($this->rtl) {
  5602. $this->x -= $mc_margin['R'];
  5603. } else {
  5604. $this->x += $mc_margin['L'];
  5605. }
  5606. if ($column == $endcolumn) {
  5607. // end column
  5608. $cborder = $border_end;
  5609. $h = $currentY - $this->y;
  5610. if ($resth > $h) {
  5611. $h = $resth;
  5612. }
  5613. } else {
  5614. // middle column
  5615. $cborder = $border_middle;
  5616. $h = $this->h - $this->y - $this->bMargin;
  5617. $resth -= $h;
  5618. }
  5619. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5620. } // end for each column
  5621. } else { // middle page
  5622. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  5623. $this->selectColumn($column);
  5624. if ($this->rtl) {
  5625. $this->x -= $mc_margin['R'];
  5626. } else {
  5627. $this->x += $mc_margin['L'];
  5628. }
  5629. $cborder = $border_middle;
  5630. $h = $this->h - $this->y - $this->bMargin;
  5631. $resth -= $h;
  5632. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5633. } // end for each column
  5634. }
  5635. if ($cborder OR $fill) {
  5636. $offsetlen = strlen($ccode);
  5637. // draw border and fill
  5638. if ($this->inxobj) {
  5639. // we are inside an XObject template
  5640. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  5641. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  5642. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  5643. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  5644. } else {
  5645. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  5646. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  5647. }
  5648. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  5649. $pstart = substr($pagebuff, 0, $pagemark);
  5650. $pend = substr($pagebuff, $pagemark);
  5651. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  5652. } else {
  5653. if (end($this->transfmrk[$this->page]) !== false) {
  5654. $pagemarkkey = key($this->transfmrk[$this->page]);
  5655. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  5656. $this->transfmrk[$this->page][$pagemarkkey] += $offsetlen;
  5657. } elseif ($this->InFooter) {
  5658. $pagemark = $this->footerpos[$this->page];
  5659. $this->footerpos[$this->page] += $offsetlen;
  5660. } else {
  5661. $pagemark = $this->intmrk[$this->page];
  5662. $this->intmrk[$this->page] += $offsetlen;
  5663. }
  5664. $pagebuff = $this->getPageBuffer($this->page);
  5665. $pstart = substr($pagebuff, 0, $pagemark);
  5666. $pend = substr($pagebuff, $pagemark);
  5667. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  5668. }
  5669. }
  5670. } // end for each page
  5671. // restore page regions check
  5672. $this->check_page_regions = $check_page_regions;
  5673. // Get end-of-cell Y position
  5674. $currentY = $this->GetY();
  5675. // restore previous values
  5676. if ($this->num_columns > 1) {
  5677. $this->selectColumn();
  5678. } else {
  5679. // restore original margins
  5680. $this->lMargin = $lMargin;
  5681. $this->rMargin = $rMargin;
  5682. if ($this->page > $startpage) {
  5683. // check for margin variations between pages (i.e. booklet mode)
  5684. $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$startpage]['olm']);
  5685. $dr = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$startpage]['orm']);
  5686. if (($dl != 0) OR ($dr != 0)) {
  5687. $this->lMargin += $dl;
  5688. $this->rMargin += $dr;
  5689. }
  5690. }
  5691. }
  5692. if ($ln > 0) {
  5693. //Go to the beginning of the next line
  5694. $this->SetY($currentY + $mc_margin['B']);
  5695. if ($ln == 2) {
  5696. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  5697. }
  5698. } else {
  5699. // go left or right by case
  5700. $this->setPage($startpage);
  5701. $this->y = $y;
  5702. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  5703. }
  5704. $this->setContentMark();
  5705. $this->cell_padding = $prev_cell_padding;
  5706. $this->cell_margin = $prev_cell_margin;
  5707. $this->clMargin = $this->lMargin;
  5708. $this->crMargin = $this->rMargin;
  5709. return $nl;
  5710. }
  5711. /**
  5712. * This method return the estimated number of lines for print a simple text string using Multicell() method.
  5713. * @param $txt (string) String for calculating his height
  5714. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  5715. * @param $reseth (boolean) if true reset the last cell height (default false).
  5716. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
  5717. * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
  5718. * @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)))
  5719. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  5720. * @author Alexander Escalona Fern\E1ndez, Nicola Asuni
  5721. * @public
  5722. * @since 4.5.011
  5723. */
  5724. public function getNumLines($txt, $w=0, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
  5725. if ($txt === NULL) {
  5726. return 0;
  5727. }
  5728. if ($txt === '') {
  5729. // empty string
  5730. return 1;
  5731. }
  5732. // adjust internal padding
  5733. $prev_cell_padding = $this->cell_padding;
  5734. $prev_lasth = $this->lasth;
  5735. if (is_array($cellpadding)) {
  5736. $this->cell_padding = $cellpadding;
  5737. }
  5738. $this->adjustCellPadding($border);
  5739. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  5740. if ($this->rtl) {
  5741. $w = $this->x - $this->lMargin;
  5742. } else {
  5743. $w = $this->w - $this->rMargin - $this->x;
  5744. }
  5745. }
  5746. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5747. if ($reseth) {
  5748. // reset row height
  5749. $this->resetLastH();
  5750. }
  5751. $lines = 1;
  5752. $sum = 0;
  5753. $chars = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont), $txt, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  5754. $charsWidth = $this->GetArrStringWidth($chars, '', '', 0, true);
  5755. $length = count($chars);
  5756. $lastSeparator = -1;
  5757. for ($i = 0; $i < $length; ++$i) {
  5758. $c = $chars[$i];
  5759. $charWidth = $charsWidth[$i];
  5760. if (($c != 160)
  5761. AND (($c == 173)
  5762. OR preg_match($this->re_spaces, TCPDF_FONTS::unichr($c, $this->isunicode))
  5763. OR (($c == 45)
  5764. AND ($i > 0) AND ($i < ($length - 1))
  5765. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i - 1)], $this->isunicode))
  5766. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i + 1)], $this->isunicode))
  5767. )
  5768. )
  5769. ) {
  5770. $lastSeparator = $i;
  5771. }
  5772. if ((($sum + $charWidth) > $wmax) OR ($c == 10)) {
  5773. ++$lines;
  5774. if ($c == 10) {
  5775. $lastSeparator = -1;
  5776. $sum = 0;
  5777. } elseif ($lastSeparator != -1) {
  5778. $i = $lastSeparator;
  5779. $lastSeparator = -1;
  5780. $sum = 0;
  5781. } else {
  5782. $sum = $charWidth;
  5783. }
  5784. } else {
  5785. $sum += $charWidth;
  5786. }
  5787. }
  5788. if ($chars[($length - 1)] == 10) {
  5789. --$lines;
  5790. }
  5791. $this->cell_padding = $prev_cell_padding;
  5792. $this->lasth = $prev_lasth;
  5793. return $lines;
  5794. }
  5795. /**
  5796. * This method return the estimated height needed for printing a simple text string using the Multicell() method.
  5797. * Generally, if you want to know the exact height for a block of content you can use the following alternative technique:
  5798. * @pre
  5799. * // store current object
  5800. * $pdf->startTransaction();
  5801. * // store starting values
  5802. * $start_y = $pdf->GetY();
  5803. * $start_page = $pdf->getPage();
  5804. * // call your printing functions with your parameters
  5805. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5806. * $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);
  5807. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5808. * // get the new Y
  5809. * $end_y = $pdf->GetY();
  5810. * $end_page = $pdf->getPage();
  5811. * // calculate height
  5812. * $height = 0;
  5813. * if ($end_page == $start_page) {
  5814. * $height = $end_y - $start_y;
  5815. * } else {
  5816. * for ($page=$start_page; $page <= $end_page; ++$page) {
  5817. * $this->setPage($page);
  5818. * if ($page == $start_page) {
  5819. * // first page
  5820. * $height = $this->h - $start_y - $this->bMargin;
  5821. * } elseif ($page == $end_page) {
  5822. * // last page
  5823. * $height = $end_y - $this->tMargin;
  5824. * } else {
  5825. * $height = $this->h - $this->tMargin - $this->bMargin;
  5826. * }
  5827. * }
  5828. * }
  5829. * // restore previous object
  5830. * $pdf = $pdf->rollbackTransaction();
  5831. *
  5832. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  5833. * @param $txt (string) String for calculating his height
  5834. * @param $reseth (boolean) if true reset the last cell height (default false).
  5835. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
  5836. * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
  5837. * @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)))
  5838. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  5839. * @author Nicola Asuni, Alexander Escalona Fern\E1ndez
  5840. * @public
  5841. */
  5842. public function getStringHeight($w, $txt, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
  5843. // adjust internal padding
  5844. $prev_cell_padding = $this->cell_padding;
  5845. $prev_lasth = $this->lasth;
  5846. if (is_array($cellpadding)) {
  5847. $this->cell_padding = $cellpadding;
  5848. }
  5849. $this->adjustCellPadding($border);
  5850. $lines = $this->getNumLines($txt, $w, $reseth, $autopadding, $cellpadding, $border);
  5851. $height = $lines * $this->getCellHeight($this->FontSize);
  5852. if ($autopadding) {
  5853. // add top and bottom padding
  5854. $height += ($this->cell_padding['T'] + $this->cell_padding['B']);
  5855. }
  5856. $this->cell_padding = $prev_cell_padding;
  5857. $this->lasth = $prev_lasth;
  5858. return $height;
  5859. }
  5860. /**
  5861. * This method prints text from the current position.<br />
  5862. * @param $h (float) Line height
  5863. * @param $txt (string) String to print
  5864. * @param $link (mixed) URL or identifier returned by AddLink()
  5865. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  5866. * @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>
  5867. * @param $ln (boolean) if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
  5868. * @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.
  5869. * @param $firstline (boolean) if true prints only the first line and return the remaining string.
  5870. * @param $firstblock (boolean) if true the string is the starting of a line.
  5871. * @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.
  5872. * @param $wadj (float) first line width will be reduced by this amount (used in HTML mode).
  5873. * @param $margin (array) margin array of the parent container
  5874. * @return mixed Return the number of cells or the remaining string if $firstline = true.
  5875. * @public
  5876. * @since 1.5
  5877. */
  5878. public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $stretch=0, $firstline=false, $firstblock=false, $maxh=0, $wadj=0, $margin='') {
  5879. // check page for no-write regions and adapt page margins if necessary
  5880. list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
  5881. if (strlen($txt) == 0) {
  5882. // fix empty text
  5883. $txt = ' ';
  5884. }
  5885. if ($margin === '') {
  5886. // set default margins
  5887. $margin = $this->cell_margin;
  5888. }
  5889. // remove carriage returns
  5890. $s = str_replace("\r", '', $txt);
  5891. // check if string contains arabic text
  5892. if (preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_ARABIC, $s)) {
  5893. $arabic = true;
  5894. } else {
  5895. $arabic = false;
  5896. }
  5897. // check if string contains RTL text
  5898. if ($arabic OR ($this->tmprtl == 'R') OR preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_RTL, $s)) {
  5899. $rtlmode = true;
  5900. } else {
  5901. $rtlmode = false;
  5902. }
  5903. // get a char width
  5904. $chrwidth = $this->GetCharWidth(46); // dot character
  5905. // get array of unicode values
  5906. $chars = TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont);
  5907. // calculate maximum width for a single character on string
  5908. $chrw = $this->GetArrStringWidth($chars, '', '', 0, true);
  5909. array_walk($chrw, array($this, 'getRawCharWidth'));
  5910. $maxchwidth = max($chrw);
  5911. // get array of chars
  5912. $uchars = TCPDF_FONTS::UTF8ArrayToUniArray($chars, $this->isunicode);
  5913. // get the number of characters
  5914. $nb = count($chars);
  5915. // replacement for SHY character (minus symbol)
  5916. $shy_replacement = 45;
  5917. $shy_replacement_char = TCPDF_FONTS::unichr($shy_replacement, $this->isunicode);
  5918. // widht for SHY replacement
  5919. $shy_replacement_width = $this->GetCharWidth($shy_replacement);
  5920. // max Y
  5921. $maxy = $this->y + $maxh - $h - $this->cell_padding['T'] - $this->cell_padding['B'];
  5922. // page width
  5923. $pw = $w = $this->w - $this->lMargin - $this->rMargin;
  5924. // calculate remaining line width ($w)
  5925. if ($this->rtl) {
  5926. $w = $this->x - $this->lMargin;
  5927. } else {
  5928. $w = $this->w - $this->rMargin - $this->x;
  5929. }
  5930. // max column width
  5931. $wmax = ($w - $wadj);
  5932. if (!$firstline) {
  5933. $wmax -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  5934. }
  5935. if ((!$firstline) AND (($chrwidth > $wmax) OR ($maxchwidth > $wmax))) {
  5936. // the maximum width character do not fit on column
  5937. return '';
  5938. }
  5939. // minimum row height
  5940. $row_height = max($h, $this->getCellHeight($this->FontSize));
  5941. $start_page = $this->page;
  5942. $i = 0; // character position
  5943. $j = 0; // current starting position
  5944. $sep = -1; // position of the last blank space
  5945. $shy = false; // true if the last blank is a soft hypen (SHY)
  5946. $l = 0; // current string length
  5947. $nl = 0; //number of lines
  5948. $linebreak = false;
  5949. $pc = 0; // previous character
  5950. // for each character
  5951. while ($i < $nb) {
  5952. if (($maxh > 0) AND ($this->y >= $maxy) ) {
  5953. break;
  5954. }
  5955. //Get the current character
  5956. $c = $chars[$i];
  5957. if ($c == 10) { // 10 = "\n" = new line
  5958. //Explicit line break
  5959. if ($align == 'J') {
  5960. if ($this->rtl) {
  5961. $talign = 'R';
  5962. } else {
  5963. $talign = 'L';
  5964. }
  5965. } else {
  5966. $talign = $align;
  5967. }
  5968. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
  5969. if ($firstline) {
  5970. $startx = $this->x;
  5971. $tmparr = array_slice($chars, $j, ($i - $j));
  5972. if ($rtlmode) {
  5973. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  5974. }
  5975. $linew = $this->GetArrStringWidth($tmparr);
  5976. unset($tmparr);
  5977. if ($this->rtl) {
  5978. $this->endlinex = $startx - $linew;
  5979. } else {
  5980. $this->endlinex = $startx + $linew;
  5981. }
  5982. $w = $linew;
  5983. $tmpcellpadding = $this->cell_padding;
  5984. if ($maxh == 0) {
  5985. $this->SetCellPadding(0);
  5986. }
  5987. }
  5988. if ($firstblock AND $this->isRTLTextDir()) {
  5989. $tmpstr = $this->stringRightTrim($tmpstr);
  5990. }
  5991. // Skip newlines at the begining of a page or column
  5992. if (!empty($tmpstr) OR ($this->y < ($this->PageBreakTrigger - $row_height))) {
  5993. $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
  5994. }
  5995. unset($tmpstr);
  5996. if ($firstline) {
  5997. $this->cell_padding = $tmpcellpadding;
  5998. return (TCPDF_FONTS::UniArrSubString($uchars, $i));
  5999. }
  6000. ++$nl;
  6001. $j = $i + 1;
  6002. $l = 0;
  6003. $sep = -1;
  6004. $shy = false;
  6005. // account for margin changes
  6006. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
  6007. $this->AcceptPageBreak();
  6008. if ($this->rtl) {
  6009. $this->x -= $margin['R'];
  6010. } else {
  6011. $this->x += $margin['L'];
  6012. }
  6013. $this->lMargin += $margin['L'];
  6014. $this->rMargin += $margin['R'];
  6015. }
  6016. $w = $this->getRemainingWidth();
  6017. $wmax = ($w - $this->cell_padding['L'] - $this->cell_padding['R']);
  6018. } else {
  6019. // 160 is the non-breaking space.
  6020. // 173 is SHY (Soft Hypen).
  6021. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  6022. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  6023. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  6024. if (($c != 160)
  6025. AND (($c == 173)
  6026. OR preg_match($this->re_spaces, TCPDF_FONTS::unichr($c, $this->isunicode))
  6027. OR (($c == 45)
  6028. AND ($i < ($nb - 1))
  6029. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($pc, $this->isunicode))
  6030. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i + 1)], $this->isunicode))
  6031. )
  6032. )
  6033. ) {
  6034. // update last blank space position
  6035. $sep = $i;
  6036. // check if is a SHY
  6037. if (($c == 173) OR ($c == 45)) {
  6038. $shy = true;
  6039. if ($pc == 45) {
  6040. $tmp_shy_replacement_width = 0;
  6041. $tmp_shy_replacement_char = '';
  6042. } else {
  6043. $tmp_shy_replacement_width = $shy_replacement_width;
  6044. $tmp_shy_replacement_char = $shy_replacement_char;
  6045. }
  6046. } else {
  6047. $shy = false;
  6048. }
  6049. }
  6050. // update string length
  6051. if ($this->isUnicodeFont() AND ($arabic)) {
  6052. // with bidirectional algorithm some chars may be changed affecting the line length
  6053. // *** very slow ***
  6054. $l = $this->GetArrStringWidth(TCPDF_FONTS::utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl, $this->isunicode, $this->CurrentFont));
  6055. } else {
  6056. $l += $this->GetCharWidth($c);
  6057. }
  6058. if (($l > $wmax) OR (($c == 173) AND (($l + $tmp_shy_replacement_width) > $wmax)) ) {
  6059. // we have reached the end of column
  6060. if ($sep == -1) {
  6061. // check if the line was already started
  6062. if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $this->cell_padding['R'] - $margin['R'] - $chrwidth)))
  6063. OR ((!$this->rtl) AND ($this->x >= ($this->lMargin + $this->cell_padding['L'] + $margin['L'] + $chrwidth)))) {
  6064. // print a void cell and go to next line
  6065. $this->Cell($w, $h, '', 0, 1);
  6066. $linebreak = true;
  6067. if ($firstline) {
  6068. return (TCPDF_FONTS::UniArrSubString($uchars, $j));
  6069. }
  6070. } else {
  6071. // truncate the word because do not fit on column
  6072. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
  6073. if ($firstline) {
  6074. $startx = $this->x;
  6075. $tmparr = array_slice($chars, $j, ($i - $j));
  6076. if ($rtlmode) {
  6077. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6078. }
  6079. $linew = $this->GetArrStringWidth($tmparr);
  6080. unset($tmparr);
  6081. if ($this->rtl) {
  6082. $this->endlinex = $startx - $linew;
  6083. } else {
  6084. $this->endlinex = $startx + $linew;
  6085. }
  6086. $w = $linew;
  6087. $tmpcellpadding = $this->cell_padding;
  6088. if ($maxh == 0) {
  6089. $this->SetCellPadding(0);
  6090. }
  6091. }
  6092. if ($firstblock AND $this->isRTLTextDir()) {
  6093. $tmpstr = $this->stringRightTrim($tmpstr);
  6094. }
  6095. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  6096. unset($tmpstr);
  6097. if ($firstline) {
  6098. $this->cell_padding = $tmpcellpadding;
  6099. return (TCPDF_FONTS::UniArrSubString($uchars, $i));
  6100. }
  6101. $j = $i;
  6102. --$i;
  6103. }
  6104. } else {
  6105. // word wrapping
  6106. if ($this->rtl AND (!$firstblock) AND ($sep < $i)) {
  6107. $endspace = 1;
  6108. } else {
  6109. $endspace = 0;
  6110. }
  6111. // check the length of the next string
  6112. $strrest = TCPDF_FONTS::UniArrSubString($uchars, ($sep + $endspace));
  6113. $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'/', $this->re_space['m'], $this->stringTrim($strrest));
  6114. if (isset($nextstr[0]) AND ($this->GetStringWidth($nextstr[0]) > $pw)) {
  6115. // truncate the word because do not fit on a full page width
  6116. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
  6117. if ($firstline) {
  6118. $startx = $this->x;
  6119. $tmparr = array_slice($chars, $j, ($i - $j));
  6120. if ($rtlmode) {
  6121. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6122. }
  6123. $linew = $this->GetArrStringWidth($tmparr);
  6124. unset($tmparr);
  6125. if ($this->rtl) {
  6126. $this->endlinex = ($startx - $linew);
  6127. } else {
  6128. $this->endlinex = ($startx + $linew);
  6129. }
  6130. $w = $linew;
  6131. $tmpcellpadding = $this->cell_padding;
  6132. if ($maxh == 0) {
  6133. $this->SetCellPadding(0);
  6134. }
  6135. }
  6136. if ($firstblock AND $this->isRTLTextDir()) {
  6137. $tmpstr = $this->stringRightTrim($tmpstr);
  6138. }
  6139. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  6140. unset($tmpstr);
  6141. if ($firstline) {
  6142. $this->cell_padding = $tmpcellpadding;
  6143. return (TCPDF_FONTS::UniArrSubString($uchars, $i));
  6144. }
  6145. $j = $i;
  6146. --$i;
  6147. } else {
  6148. // word wrapping
  6149. if ($shy) {
  6150. // add hypen (minus symbol) at the end of the line
  6151. $shy_width = $tmp_shy_replacement_width;
  6152. if ($this->rtl) {
  6153. $shy_char_left = $tmp_shy_replacement_char;
  6154. $shy_char_right = '';
  6155. } else {
  6156. $shy_char_left = '';
  6157. $shy_char_right = $tmp_shy_replacement_char;
  6158. }
  6159. } else {
  6160. $shy_width = 0;
  6161. $shy_char_left = '';
  6162. $shy_char_right = '';
  6163. }
  6164. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, ($sep + $endspace));
  6165. if ($firstline) {
  6166. $startx = $this->x;
  6167. $tmparr = array_slice($chars, $j, (($sep + $endspace) - $j));
  6168. if ($rtlmode) {
  6169. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6170. }
  6171. $linew = $this->GetArrStringWidth($tmparr);
  6172. unset($tmparr);
  6173. if ($this->rtl) {
  6174. $this->endlinex = $startx - $linew - $shy_width;
  6175. } else {
  6176. $this->endlinex = $startx + $linew + $shy_width;
  6177. }
  6178. $w = $linew;
  6179. $tmpcellpadding = $this->cell_padding;
  6180. if ($maxh == 0) {
  6181. $this->SetCellPadding(0);
  6182. }
  6183. }
  6184. // print the line
  6185. if ($firstblock AND $this->isRTLTextDir()) {
  6186. $tmpstr = $this->stringRightTrim($tmpstr);
  6187. }
  6188. $this->Cell($w, $h, $shy_char_left.$tmpstr.$shy_char_right, 0, 1, $align, $fill, $link, $stretch);
  6189. unset($tmpstr);
  6190. if ($firstline) {
  6191. if ($chars[$sep] == 45) {
  6192. $endspace += 1;
  6193. }
  6194. // return the remaining text
  6195. $this->cell_padding = $tmpcellpadding;
  6196. return (TCPDF_FONTS::UniArrSubString($uchars, ($sep + $endspace)));
  6197. }
  6198. $i = $sep;
  6199. $sep = -1;
  6200. $shy = false;
  6201. $j = ($i + 1);
  6202. }
  6203. }
  6204. // account for margin changes
  6205. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
  6206. $this->AcceptPageBreak();
  6207. if ($this->rtl) {
  6208. $this->x -= $margin['R'];
  6209. } else {
  6210. $this->x += $margin['L'];
  6211. }
  6212. $this->lMargin += $margin['L'];
  6213. $this->rMargin += $margin['R'];
  6214. }
  6215. $w = $this->getRemainingWidth();
  6216. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6217. if ($linebreak) {
  6218. $linebreak = false;
  6219. } else {
  6220. ++$nl;
  6221. $l = 0;
  6222. }
  6223. }
  6224. }
  6225. // save last character
  6226. $pc = $c;
  6227. ++$i;
  6228. } // end while i < nb
  6229. // print last substring (if any)
  6230. if ($l > 0) {
  6231. switch ($align) {
  6232. case 'J':
  6233. case 'C': {
  6234. $w = $w;
  6235. break;
  6236. }
  6237. case 'L': {
  6238. if ($this->rtl) {
  6239. $w = $w;
  6240. } else {
  6241. $w = $l;
  6242. }
  6243. break;
  6244. }
  6245. case 'R': {
  6246. if ($this->rtl) {
  6247. $w = $l;
  6248. } else {
  6249. $w = $w;
  6250. }
  6251. break;
  6252. }
  6253. default: {
  6254. $w = $l;
  6255. break;
  6256. }
  6257. }
  6258. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $nb);
  6259. if ($firstline) {
  6260. $startx = $this->x;
  6261. $tmparr = array_slice($chars, $j, ($nb - $j));
  6262. if ($rtlmode) {
  6263. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6264. }
  6265. $linew = $this->GetArrStringWidth($tmparr);
  6266. unset($tmparr);
  6267. if ($this->rtl) {
  6268. $this->endlinex = $startx - $linew;
  6269. } else {
  6270. $this->endlinex = $startx + $linew;
  6271. }
  6272. $w = $linew;
  6273. $tmpcellpadding = $this->cell_padding;
  6274. if ($maxh == 0) {
  6275. $this->SetCellPadding(0);
  6276. }
  6277. }
  6278. if ($firstblock AND $this->isRTLTextDir()) {
  6279. $tmpstr = $this->stringRightTrim($tmpstr);
  6280. }
  6281. $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
  6282. unset($tmpstr);
  6283. if ($firstline) {
  6284. $this->cell_padding = $tmpcellpadding;
  6285. return (TCPDF_FONTS::UniArrSubString($uchars, $nb));
  6286. }
  6287. ++$nl;
  6288. }
  6289. if ($firstline) {
  6290. return '';
  6291. }
  6292. return $nl;
  6293. }
  6294. /**
  6295. * Returns the remaining width between the current position and margins.
  6296. * @return int Return the remaining width
  6297. * @protected
  6298. */
  6299. protected function getRemainingWidth() {
  6300. list($this->x, $this->y) = $this->checkPageRegions(0, $this->x, $this->y);
  6301. if ($this->rtl) {
  6302. return ($this->x - $this->lMargin);
  6303. } else {
  6304. return ($this->w - $this->rMargin - $this->x);
  6305. }
  6306. }
  6307. /**
  6308. * Set the block dimensions accounting for page breaks and page/column fitting
  6309. * @param $w (float) width
  6310. * @param $h (float) height
  6311. * @param $x (float) X coordinate
  6312. * @param $y (float) Y coodiante
  6313. * @param $fitonpage (boolean) if true the block is resized to not exceed page dimensions.
  6314. * @return array($w, $h, $x, $y)
  6315. * @protected
  6316. * @since 5.5.009 (2010-07-05)
  6317. */
  6318. protected function fitBlock($w, $h, $x, $y, $fitonpage=false) {
  6319. if ($w <= 0) {
  6320. // set maximum width
  6321. $w = ($this->w - $this->lMargin - $this->rMargin);
  6322. if ($w <= 0) {
  6323. $w = 1;
  6324. }
  6325. }
  6326. if ($h <= 0) {
  6327. // set maximum height
  6328. $h = ($this->PageBreakTrigger - $this->tMargin);
  6329. if ($h <= 0) {
  6330. $h = 1;
  6331. }
  6332. }
  6333. // resize the block to be vertically contained on a single page or single column
  6334. if ($fitonpage OR $this->AutoPageBreak) {
  6335. $ratio_wh = ($w / $h);
  6336. if ($h > ($this->PageBreakTrigger - $this->tMargin)) {
  6337. $h = $this->PageBreakTrigger - $this->tMargin;
  6338. $w = ($h * $ratio_wh);
  6339. }
  6340. // resize the block to be horizontally contained on a single page or single column
  6341. if ($fitonpage) {
  6342. $maxw = ($this->w - $this->lMargin - $this->rMargin);
  6343. if ($w > $maxw) {
  6344. $w = $maxw;
  6345. $h = ($w / $ratio_wh);
  6346. }
  6347. }
  6348. }
  6349. // Check whether we need a new page or new column first as this does not fit
  6350. $prev_x = $this->x;
  6351. $prev_y = $this->y;
  6352. if ($this->checkPageBreak($h, $y) OR ($this->y < $prev_y)) {
  6353. $y = $this->y;
  6354. if ($this->rtl) {
  6355. $x += ($prev_x - $this->x);
  6356. } else {
  6357. $x += ($this->x - $prev_x);
  6358. }
  6359. $this->newline = true;
  6360. }
  6361. // resize the block to be contained on the remaining available page or column space
  6362. if ($fitonpage) {
  6363. $ratio_wh = ($w / $h);
  6364. if (($y + $h) > $this->PageBreakTrigger) {
  6365. $h = $this->PageBreakTrigger - $y;
  6366. $w = ($h * $ratio_wh);
  6367. }
  6368. if ((!$this->rtl) AND (($x + $w) > ($this->w - $this->rMargin))) {
  6369. $w = $this->w - $this->rMargin - $x;
  6370. $h = ($w / $ratio_wh);
  6371. } elseif (($this->rtl) AND (($x - $w) < ($this->lMargin))) {
  6372. $w = $x - $this->lMargin;
  6373. $h = ($w / $ratio_wh);
  6374. }
  6375. }
  6376. return array($w, $h, $x, $y);
  6377. }
  6378. /**
  6379. * Puts an image in the page.
  6380. * The upper-left corner must be given.
  6381. * The dimensions can be specified in different ways:<ul>
  6382. * <li>explicit width and height (expressed in user unit)</li>
  6383. * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
  6384. * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  6385. * 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;
  6386. * The format can be specified explicitly or inferred from the file extension.<br />
  6387. * It is possible to put a link on the image.<br />
  6388. * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  6389. * @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').
  6390. * @param $x (float) Abscissa of the upper-left corner (LTR) or upper-right corner (RTL).
  6391. * @param $y (float) Ordinate of the upper-left corner (LTR) or upper-right corner (RTL).
  6392. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6393. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6394. * @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.
  6395. * @param $link (mixed) URL or identifier returned by AddLink().
  6396. * @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>
  6397. * @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).
  6398. * @param $dpi (int) dot-per-inch resolution used on resize
  6399. * @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>
  6400. * @param $ismask (boolean) true if this image is a mask, false otherwise
  6401. * @param $imgmask (mixed) image object returned by this function or false
  6402. * @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)))
  6403. * @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).
  6404. * @param $hidden (boolean) If true do not display the image.
  6405. * @param $fitonpage (boolean) If true the image is resized to not exceed page dimensions.
  6406. * @param $alt (boolean) If true the image will be added as alternative and not directly printed (the ID of the image will be returned).
  6407. * @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.
  6408. * @return image information
  6409. * @public
  6410. * @since 1.1
  6411. */
  6412. 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()) {
  6413. if ($this->state != 2) {
  6414. return;
  6415. }
  6416. if ($x === '') {
  6417. $x = $this->x;
  6418. }
  6419. if ($y === '') {
  6420. $y = $this->y;
  6421. }
  6422. // check page for no-write regions and adapt page margins if necessary
  6423. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  6424. $exurl = ''; // external streams
  6425. $imsize = FALSE;
  6426. // check if we are passing an image as file or string
  6427. if ($file[0] === '@') {
  6428. // image from string
  6429. $imgdata = substr($file, 1);
  6430. } else { // image file
  6431. if ($file{0} === '*') {
  6432. // image as external stream
  6433. $file = substr($file, 1);
  6434. $exurl = $file;
  6435. }
  6436. // check if is local file
  6437. if (!@file_exists($file)) {
  6438. // encode spaces on filename (file is probably an URL)
  6439. $file = str_replace(' ', '%20', $file);
  6440. }
  6441. if (@file_exists($file)) {
  6442. // get image dimensions
  6443. $imsize = @getimagesize($file);
  6444. }
  6445. if ($imsize === FALSE) {
  6446. $imgdata = TCPDF_STATIC::fileGetContents($file);
  6447. }
  6448. }
  6449. if (isset($imgdata) AND ($imgdata !== FALSE) AND (strpos($file, '__tcpdf_img') === FALSE)) {
  6450. // copy image to cache
  6451. $original_file = $file;
  6452. $file = TCPDF_STATIC::getObjFilename('img');
  6453. $fp = fopen($file, 'w');
  6454. fwrite($fp, $imgdata);
  6455. fclose($fp);
  6456. unset($imgdata);
  6457. $imsize = @getimagesize($file);
  6458. if ($imsize === FALSE) {
  6459. unlink($file);
  6460. $file = $original_file;
  6461. } else {
  6462. $this->cached_files[] = $file;
  6463. }
  6464. }
  6465. if ($imsize === FALSE) {
  6466. if (($w > 0) AND ($h > 0)) {
  6467. // get measures from specified data
  6468. $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  6469. $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  6470. $imsize = array($pw, $ph);
  6471. } else {
  6472. $this->Error('[Image] Unable to get the size of the image: '.$file);
  6473. }
  6474. }
  6475. // file hash
  6476. $filehash = md5($this->file_id.$file);
  6477. // get original image width and height in pixels
  6478. list($pixw, $pixh) = $imsize;
  6479. // calculate image width and height on document
  6480. if (($w <= 0) AND ($h <= 0)) {
  6481. // convert image size to document unit
  6482. $w = $this->pixelsToUnits($pixw);
  6483. $h = $this->pixelsToUnits($pixh);
  6484. } elseif ($w <= 0) {
  6485. $w = $h * $pixw / $pixh;
  6486. } elseif ($h <= 0) {
  6487. $h = $w * $pixh / $pixw;
  6488. } elseif (($fitbox !== false) AND ($w > 0) AND ($h > 0)) {
  6489. if (strlen($fitbox) !== 2) {
  6490. // set default alignment
  6491. $fitbox = '--';
  6492. }
  6493. // scale image dimensions proportionally to fit within the ($w, $h) box
  6494. if ((($w * $pixh) / ($h * $pixw)) < 1) {
  6495. // store current height
  6496. $oldh = $h;
  6497. // calculate new height
  6498. $h = $w * $pixh / $pixw;
  6499. // height difference
  6500. $hdiff = ($oldh - $h);
  6501. // vertical alignment
  6502. switch (strtoupper($fitbox{1})) {
  6503. case 'T': {
  6504. break;
  6505. }
  6506. case 'M': {
  6507. $y += ($hdiff / 2);
  6508. break;
  6509. }
  6510. case 'B': {
  6511. $y += $hdiff;
  6512. break;
  6513. }
  6514. }
  6515. } else {
  6516. // store current width
  6517. $oldw = $w;
  6518. // calculate new width
  6519. $w = $h * $pixw / $pixh;
  6520. // width difference
  6521. $wdiff = ($oldw - $w);
  6522. // horizontal alignment
  6523. switch (strtoupper($fitbox{0})) {
  6524. case 'L': {
  6525. if ($this->rtl) {
  6526. $x -= $wdiff;
  6527. }
  6528. break;
  6529. }
  6530. case 'C': {
  6531. if ($this->rtl) {
  6532. $x -= ($wdiff / 2);
  6533. } else {
  6534. $x += ($wdiff / 2);
  6535. }
  6536. break;
  6537. }
  6538. case 'R': {
  6539. if (!$this->rtl) {
  6540. $x += $wdiff;
  6541. }
  6542. break;
  6543. }
  6544. }
  6545. }
  6546. }
  6547. // fit the image on available space
  6548. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  6549. // calculate new minimum dimensions in pixels
  6550. $neww = round($w * $this->k * $dpi / $this->dpi);
  6551. $newh = round($h * $this->k * $dpi / $this->dpi);
  6552. // check if resize is necessary (resize is used only to reduce the image)
  6553. $newsize = ($neww * $newh);
  6554. $pixsize = ($pixw * $pixh);
  6555. if (intval($resize) == 2) {
  6556. $resize = true;
  6557. } elseif ($newsize >= $pixsize) {
  6558. $resize = false;
  6559. }
  6560. // check if image has been already added on document
  6561. $newimage = true;
  6562. if (in_array($file, $this->imagekeys)) {
  6563. $newimage = false;
  6564. // get existing image data
  6565. $info = $this->getImageBuffer($file);
  6566. if (strpos($file, '__tcpdf_imgmask_') === FALSE) {
  6567. // check if the newer image is larger
  6568. $oldsize = ($info['w'] * $info['h']);
  6569. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  6570. $newimage = true;
  6571. }
  6572. }
  6573. } elseif (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_imgmask_') === FALSE)) {
  6574. // create temp image file (without alpha channel)
  6575. $tempfile_plain = K_PATH_CACHE.'__tcpdf_imgmask_plain_'.$filehash;
  6576. // create temp alpha file
  6577. $tempfile_alpha = K_PATH_CACHE.'__tcpdf_imgmask_alpha_'.$filehash;
  6578. // check for cached images
  6579. if (in_array($tempfile_plain, $this->imagekeys)) {
  6580. // get existing image data
  6581. $info = $this->getImageBuffer($tempfile_plain);
  6582. // check if the newer image is larger
  6583. $oldsize = ($info['w'] * $info['h']);
  6584. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  6585. $newimage = true;
  6586. } else {
  6587. $newimage = false;
  6588. // embed mask image
  6589. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  6590. // embed image, masked with previously embedded mask
  6591. return $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  6592. }
  6593. }
  6594. }
  6595. if ($newimage) {
  6596. //First use of image, get info
  6597. $type = strtolower($type);
  6598. if ($type == '') {
  6599. $type = TCPDF_IMAGES::getImageFileType($file, $imsize);
  6600. } elseif ($type == 'jpg') {
  6601. $type = 'jpeg';
  6602. }
  6603. $mqr = TCPDF_STATIC::get_mqr();
  6604. TCPDF_STATIC::set_mqr(false);
  6605. // Specific image handlers (defined on TCPDF_IMAGES CLASS)
  6606. $mtd = '_parse'.$type;
  6607. // GD image handler function
  6608. $gdfunction = 'imagecreatefrom'.$type;
  6609. $info = false;
  6610. if ((method_exists('TCPDF_IMAGES', $mtd)) AND (!($resize AND (function_exists($gdfunction) OR extension_loaded('imagick'))))) {
  6611. // TCPDF image functions
  6612. $info = TCPDF_IMAGES::$mtd($file);
  6613. if (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_imgmask_') === FALSE)
  6614. AND (($info === 'pngalpha') OR (isset($info['trns']) AND !empty($info['trns'])))) {
  6615. return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign, $filehash);
  6616. }
  6617. }
  6618. if (($info === false) AND function_exists($gdfunction)) {
  6619. try {
  6620. // GD library
  6621. $img = $gdfunction($file);
  6622. if ($img !== false) {
  6623. if ($resize) {
  6624. $imgr = imagecreatetruecolor($neww, $newh);
  6625. if (($type == 'gif') OR ($type == 'png')) {
  6626. $imgr = TCPDF_IMAGES::setGDImageTransparency($imgr, $img);
  6627. }
  6628. imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
  6629. if (($type == 'gif') OR ($type == 'png')) {
  6630. $info = TCPDF_IMAGES::_toPNG($imgr);
  6631. } else {
  6632. $info = TCPDF_IMAGES::_toJPEG($imgr, $this->jpeg_quality);
  6633. }
  6634. } else {
  6635. if (($type == 'gif') OR ($type == 'png')) {
  6636. $info = TCPDF_IMAGES::_toPNG($img);
  6637. } else {
  6638. $info = TCPDF_IMAGES::_toJPEG($img, $this->jpeg_quality);
  6639. }
  6640. }
  6641. }
  6642. } catch(Exception $e) {
  6643. $info = false;
  6644. }
  6645. }
  6646. if (($info === false) AND extension_loaded('imagick')) {
  6647. try {
  6648. // ImageMagick library
  6649. $img = new Imagick();
  6650. if ($type == 'SVG') {
  6651. // get SVG file content
  6652. $svgimg = TCPDF_STATIC::fileGetContents($file);
  6653. if ($svgimg !== FALSE) {
  6654. // get width and height
  6655. $regs = array();
  6656. if (preg_match('/<svg([^\>]*)>/si', $svgimg, $regs)) {
  6657. $svgtag = $regs[1];
  6658. $tmp = array();
  6659. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  6660. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  6661. $owu = sprintf('%F', ($ow * $dpi / 72)).$this->pdfunit;
  6662. $svgtag = preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si', ' width="'.$owu.'"', $svgtag, 1);
  6663. } else {
  6664. $ow = $w;
  6665. }
  6666. $tmp = array();
  6667. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  6668. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  6669. $ohu = sprintf('%F', ($oh * $dpi / 72)).$this->pdfunit;
  6670. $svgtag = preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si', ' height="'.$ohu.'"', $svgtag, 1);
  6671. } else {
  6672. $oh = $h;
  6673. }
  6674. $tmp = array();
  6675. if (!preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $svgtag, $tmp)) {
  6676. $vbw = ($ow * $this->imgscale * $this->k);
  6677. $vbh = ($oh * $this->imgscale * $this->k);
  6678. $vbox = sprintf(' viewBox="0 0 %F %F" ', $vbw, $vbh);
  6679. $svgtag = $vbox.$svgtag;
  6680. }
  6681. $svgimg = preg_replace('/<svg([^\>]*)>/si', '<svg'.$svgtag.'>', $svgimg, 1);
  6682. }
  6683. $img->readImageBlob($svgimg);
  6684. }
  6685. } else {
  6686. $img->readImage($file);
  6687. }
  6688. if ($resize) {
  6689. $img->resizeImage($neww, $newh, 10, 1, false);
  6690. }
  6691. $img->setCompressionQuality($this->jpeg_quality);
  6692. $img->setImageFormat('jpeg');
  6693. $tempname = TCPDF_STATIC::getObjFilename('img');
  6694. $img->writeImage($tempname);
  6695. $info = TCPDF_IMAGES::_parsejpeg($tempname);
  6696. unlink($tempname);
  6697. $img->destroy();
  6698. } catch(Exception $e) {
  6699. $info = false;
  6700. }
  6701. }
  6702. if ($info === false) {
  6703. // unable to process image
  6704. return;
  6705. }
  6706. TCPDF_STATIC::set_mqr($mqr);
  6707. if ($ismask) {
  6708. // force grayscale
  6709. $info['cs'] = 'DeviceGray';
  6710. }
  6711. if ($imgmask !== false) {
  6712. $info['masked'] = $imgmask;
  6713. }
  6714. if (!empty($exurl)) {
  6715. $info['exurl'] = $exurl;
  6716. }
  6717. // array of alternative images
  6718. $info['altimgs'] = $altimgs;
  6719. // add image to document
  6720. $info['i'] = $this->setImageBuffer($file, $info);
  6721. }
  6722. // set alignment
  6723. $this->img_rb_y = $y + $h;
  6724. // set alignment
  6725. if ($this->rtl) {
  6726. if ($palign == 'L') {
  6727. $ximg = $this->lMargin;
  6728. } elseif ($palign == 'C') {
  6729. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  6730. } elseif ($palign == 'R') {
  6731. $ximg = $this->w - $this->rMargin - $w;
  6732. } else {
  6733. $ximg = $x - $w;
  6734. }
  6735. $this->img_rb_x = $ximg;
  6736. } else {
  6737. if ($palign == 'L') {
  6738. $ximg = $this->lMargin;
  6739. } elseif ($palign == 'C') {
  6740. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  6741. } elseif ($palign == 'R') {
  6742. $ximg = $this->w - $this->rMargin - $w;
  6743. } else {
  6744. $ximg = $x;
  6745. }
  6746. $this->img_rb_x = $ximg + $w;
  6747. }
  6748. if ($ismask OR $hidden) {
  6749. // image is not displayed
  6750. return $info['i'];
  6751. }
  6752. $xkimg = $ximg * $this->k;
  6753. if (!$alt) {
  6754. // only non-alternative immages will be set
  6755. $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']));
  6756. }
  6757. if (!empty($border)) {
  6758. $bx = $this->x;
  6759. $by = $this->y;
  6760. $this->x = $ximg;
  6761. if ($this->rtl) {
  6762. $this->x += $w;
  6763. }
  6764. $this->y = $y;
  6765. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  6766. $this->x = $bx;
  6767. $this->y = $by;
  6768. }
  6769. if ($link) {
  6770. $this->Link($ximg, $y, $w, $h, $link, 0);
  6771. }
  6772. // set pointer to align the next text/objects
  6773. switch($align) {
  6774. case 'T': {
  6775. $this->y = $y;
  6776. $this->x = $this->img_rb_x;
  6777. break;
  6778. }
  6779. case 'M': {
  6780. $this->y = $y + round($h/2);
  6781. $this->x = $this->img_rb_x;
  6782. break;
  6783. }
  6784. case 'B': {
  6785. $this->y = $this->img_rb_y;
  6786. $this->x = $this->img_rb_x;
  6787. break;
  6788. }
  6789. case 'N': {
  6790. $this->SetY($this->img_rb_y);
  6791. break;
  6792. }
  6793. default:{
  6794. break;
  6795. }
  6796. }
  6797. $this->endlinex = $this->img_rb_x;
  6798. if ($this->inxobj) {
  6799. // we are inside an XObject template
  6800. $this->xobjects[$this->xobjid]['images'][] = $info['i'];
  6801. }
  6802. return $info['i'];
  6803. }
  6804. /**
  6805. * Extract info from a PNG image with alpha channel using the Imagick or GD library.
  6806. * @param $file (string) Name of the file containing the image.
  6807. * @param $x (float) Abscissa of the upper-left corner.
  6808. * @param $y (float) Ordinate of the upper-left corner.
  6809. * @param $wpx (float) Original width of the image in pixels.
  6810. * @param $hpx (float) original height of the image in pixels.
  6811. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6812. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6813. * @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.
  6814. * @param $link (mixed) URL or identifier returned by AddLink().
  6815. * @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>
  6816. * @param $resize (boolean) If true resize (reduce) the image to fit $w and $h (requires GD library).
  6817. * @param $dpi (int) dot-per-inch resolution used on resize
  6818. * @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>
  6819. * @param $filehash (string) File hash used to build unique file names.
  6820. * @author Nicola Asuni
  6821. * @protected
  6822. * @since 4.3.007 (2008-12-04)
  6823. * @see Image()
  6824. */
  6825. protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $filehash='') {
  6826. // create temp images
  6827. if (empty($filehash)) {
  6828. $filehash = md5($this->file_id.$file);
  6829. }
  6830. // create temp image file (without alpha channel)
  6831. $tempfile_plain = K_PATH_CACHE.'__tcpdf_imgmask_plain_'.$filehash;
  6832. // create temp alpha file
  6833. $tempfile_alpha = K_PATH_CACHE.'__tcpdf_imgmask_alpha_'.$filehash;
  6834. $parsed = false;
  6835. $parse_error = '';
  6836. // ImageMagick extension
  6837. if (($parsed === false) AND extension_loaded('imagick')) {
  6838. try {
  6839. // ImageMagick library
  6840. $img = new Imagick();
  6841. $img->readImage($file);
  6842. // clone image object
  6843. $imga = TCPDF_STATIC::objclone($img);
  6844. // extract alpha channel
  6845. if (method_exists($img, 'setImageAlphaChannel') AND defined('Imagick::ALPHACHANNEL_EXTRACT')) {
  6846. $img->setImageAlphaChannel(Imagick::ALPHACHANNEL_EXTRACT);
  6847. } else {
  6848. $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE);
  6849. $img->negateImage(true);
  6850. }
  6851. $img->setImageFormat('png');
  6852. $img->writeImage($tempfile_alpha);
  6853. // remove alpha channel
  6854. if (method_exists($imga, 'setImageMatte')) {
  6855. $imga->setImageMatte(false);
  6856. } else {
  6857. $imga->separateImageChannel(39); // 39 = (imagick::CHANNEL_ALL & ~(imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE));
  6858. }
  6859. $imga->setImageFormat('png');
  6860. $imga->writeImage($tempfile_plain);
  6861. $parsed = true;
  6862. } catch (Exception $e) {
  6863. // Imagemagick fails, try with GD
  6864. $parse_error = 'Imagick library error: '.$e->getMessage();
  6865. }
  6866. }
  6867. // GD extension
  6868. if (($parsed === false) AND function_exists('imagecreatefrompng')) {
  6869. try {
  6870. // generate images
  6871. $img = imagecreatefrompng($file);
  6872. $imgalpha = imagecreate($wpx, $hpx);
  6873. // generate gray scale palette (0 -> 255)
  6874. for ($c = 0; $c < 256; ++$c) {
  6875. ImageColorAllocate($imgalpha, $c, $c, $c);
  6876. }
  6877. // extract alpha channel
  6878. for ($xpx = 0; $xpx < $wpx; ++$xpx) {
  6879. for ($ypx = 0; $ypx < $hpx; ++$ypx) {
  6880. $color = imagecolorat($img, $xpx, $ypx);
  6881. // get and correct gamma color
  6882. $alpha = $this->getGDgamma($img, $color);
  6883. imagesetpixel($imgalpha, $xpx, $ypx, $alpha);
  6884. }
  6885. }
  6886. imagepng($imgalpha, $tempfile_alpha);
  6887. imagedestroy($imgalpha);
  6888. // extract image without alpha channel
  6889. $imgplain = imagecreatetruecolor($wpx, $hpx);
  6890. imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
  6891. imagepng($imgplain, $tempfile_plain);
  6892. imagedestroy($imgplain);
  6893. $parsed = true;
  6894. } catch (Exception $e) {
  6895. // GD fails
  6896. $parse_error = 'GD library error: '.$e->getMessage();
  6897. }
  6898. }
  6899. if ($parsed === false) {
  6900. if (empty($parse_error)) {
  6901. $this->Error('TCPDF requires the Imagick or GD extension to handle PNG images with alpha channel.');
  6902. } else {
  6903. $this->Error($parse_error);
  6904. }
  6905. }
  6906. // embed mask image
  6907. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  6908. // embed image, masked with previously embedded mask
  6909. $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  6910. // remove temp files
  6911. unlink($tempfile_alpha);
  6912. unlink($tempfile_plain);
  6913. }
  6914. /**
  6915. * Get the GD-corrected PNG gamma value from alpha color
  6916. * @param $img (int) GD image Resource ID.
  6917. * @param $c (int) alpha color
  6918. * @protected
  6919. * @since 4.3.007 (2008-12-04)
  6920. */
  6921. protected function getGDgamma($img, $c) {
  6922. if (!isset($this->gdgammacache['#'.$c])) {
  6923. $colors = imagecolorsforindex($img, $c);
  6924. // GD alpha is only 7 bit (0 -> 127)
  6925. $this->gdgammacache['#'.$c] = (((127 - $colors['alpha']) / 127) * 255);
  6926. // correct gamma
  6927. $this->gdgammacache['#'.$c] = (pow(($this->gdgammacache['#'.$c] / 255), 2.2) * 255);
  6928. // store the latest values on cache to improve performances
  6929. if (count($this->gdgammacache) > 8) {
  6930. // remove one element from the cache array
  6931. array_shift($this->gdgammacache);
  6932. }
  6933. }
  6934. return $this->gdgammacache['#'.$c];
  6935. }
  6936. /**
  6937. * Performs a line break.
  6938. * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  6939. * @param $h (float) The height of the break. By default, the value equals the height of the last printed cell.
  6940. * @param $cell (boolean) if true add the current left (or right o for RTL) padding to the X coordinate
  6941. * @public
  6942. * @since 1.0
  6943. * @see Cell()
  6944. */
  6945. public function Ln($h='', $cell=false) {
  6946. 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'])) {
  6947. // revove vertical space from the top of the column
  6948. return;
  6949. }
  6950. if ($cell) {
  6951. if ($this->rtl) {
  6952. $cellpadding = $this->cell_padding['R'];
  6953. } else {
  6954. $cellpadding = $this->cell_padding['L'];
  6955. }
  6956. } else {
  6957. $cellpadding = 0;
  6958. }
  6959. if ($this->rtl) {
  6960. $this->x = $this->w - $this->rMargin - $cellpadding;
  6961. } else {
  6962. $this->x = $this->lMargin + $cellpadding;
  6963. }
  6964. if (is_string($h)) {
  6965. $this->y += $this->lasth;
  6966. } else {
  6967. $this->y += $h;
  6968. }
  6969. $this->newline = true;
  6970. }
  6971. /**
  6972. * Returns the relative X value of current position.
  6973. * The value is relative to the left border for LTR languages and to the right border for RTL languages.
  6974. * @return float
  6975. * @public
  6976. * @since 1.2
  6977. * @see SetX(), GetY(), SetY()
  6978. */
  6979. public function GetX() {
  6980. //Get x position
  6981. if ($this->rtl) {
  6982. return ($this->w - $this->x);
  6983. } else {
  6984. return $this->x;
  6985. }
  6986. }
  6987. /**
  6988. * Returns the absolute X value of current position.
  6989. * @return float
  6990. * @public
  6991. * @since 1.2
  6992. * @see SetX(), GetY(), SetY()
  6993. */
  6994. public function GetAbsX() {
  6995. return $this->x;
  6996. }
  6997. /**
  6998. * Returns the ordinate of the current position.
  6999. * @return float
  7000. * @public
  7001. * @since 1.0
  7002. * @see SetY(), GetX(), SetX()
  7003. */
  7004. public function GetY() {
  7005. return $this->y;
  7006. }
  7007. /**
  7008. * Defines the abscissa of the current position.
  7009. * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
  7010. * @param $x (float) The value of the abscissa in user units.
  7011. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  7012. * @public
  7013. * @since 1.2
  7014. * @see GetX(), GetY(), SetY(), SetXY()
  7015. */
  7016. public function SetX($x, $rtloff=false) {
  7017. $x = floatval($x);
  7018. if (!$rtloff AND $this->rtl) {
  7019. if ($x >= 0) {
  7020. $this->x = $this->w - $x;
  7021. } else {
  7022. $this->x = abs($x);
  7023. }
  7024. } else {
  7025. if ($x >= 0) {
  7026. $this->x = $x;
  7027. } else {
  7028. $this->x = $this->w + $x;
  7029. }
  7030. }
  7031. if ($this->x < 0) {
  7032. $this->x = 0;
  7033. }
  7034. if ($this->x > $this->w) {
  7035. $this->x = $this->w;
  7036. }
  7037. }
  7038. /**
  7039. * Moves the current abscissa back to the left margin and sets the ordinate.
  7040. * If the passed value is negative, it is relative to the bottom of the page.
  7041. * @param $y (float) The value of the ordinate in user units.
  7042. * @param $resetx (bool) if true (default) reset the X position.
  7043. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  7044. * @public
  7045. * @since 1.0
  7046. * @see GetX(), GetY(), SetY(), SetXY()
  7047. */
  7048. public function SetY($y, $resetx=true, $rtloff=false) {
  7049. $y = floatval($y);
  7050. if ($resetx) {
  7051. //reset x
  7052. if (!$rtloff AND $this->rtl) {
  7053. $this->x = $this->w - $this->rMargin;
  7054. } else {
  7055. $this->x = $this->lMargin;
  7056. }
  7057. }
  7058. if ($y >= 0) {
  7059. $this->y = $y;
  7060. } else {
  7061. $this->y = $this->h + $y;
  7062. }
  7063. if ($this->y < 0) {
  7064. $this->y = 0;
  7065. }
  7066. if ($this->y > $this->h) {
  7067. $this->y = $this->h;
  7068. }
  7069. }
  7070. /**
  7071. * Defines the abscissa and ordinate of the current position.
  7072. * If the passed values are negative, they are relative respectively to the right and bottom of the page.
  7073. * @param $x (float) The value of the abscissa.
  7074. * @param $y (float) The value of the ordinate.
  7075. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  7076. * @public
  7077. * @since 1.2
  7078. * @see SetX(), SetY()
  7079. */
  7080. public function SetXY($x, $y, $rtloff=false) {
  7081. $this->SetY($y, false, $rtloff);
  7082. $this->SetX($x, $rtloff);
  7083. }
  7084. /**
  7085. * Set the absolute X coordinate of the current pointer.
  7086. * @param $x (float) The value of the abscissa in user units.
  7087. * @public
  7088. * @since 5.9.186 (2012-09-13)
  7089. * @see setAbsX(), setAbsY(), SetAbsXY()
  7090. */
  7091. public function SetAbsX($x) {
  7092. $this->x = floatval($x);
  7093. }
  7094. /**
  7095. * Set the absolute Y coordinate of the current pointer.
  7096. * @param $y (float) (float) The value of the ordinate in user units.
  7097. * @public
  7098. * @since 5.9.186 (2012-09-13)
  7099. * @see setAbsX(), setAbsY(), SetAbsXY()
  7100. */
  7101. public function SetAbsY($y) {
  7102. $this->y = floatval($y);
  7103. }
  7104. /**
  7105. * Set the absolute X and Y coordinates of the current pointer.
  7106. * @param $x (float) The value of the abscissa in user units.
  7107. * @param $y (float) (float) The value of the ordinate in user units.
  7108. * @public
  7109. * @since 5.9.186 (2012-09-13)
  7110. * @see setAbsX(), setAbsY(), SetAbsXY()
  7111. */
  7112. public function SetAbsXY($x, $y) {
  7113. $this->SetAbsX($x);
  7114. $this->SetAbsY($y);
  7115. }
  7116. /**
  7117. * Send the document to a given destination: string, local file or browser.
  7118. * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  7119. * The method first calls Close() if necessary to terminate the document.
  7120. * @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.
  7121. * @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>
  7122. * @public
  7123. * @since 1.0
  7124. * @see Close()
  7125. */
  7126. public function Output($name='doc.pdf', $dest='I') {
  7127. //Output PDF to some destination
  7128. //Finish document if necessary
  7129. if ($this->state < 3) {
  7130. $this->Close();
  7131. }
  7132. //Normalize parameters
  7133. if (is_bool($dest)) {
  7134. $dest = $dest ? 'D' : 'F';
  7135. }
  7136. $dest = strtoupper($dest);
  7137. if ($dest{0} != 'F') {
  7138. $name = preg_replace('/[\s]+/', '_', $name);
  7139. $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name);
  7140. }
  7141. if ($this->sign) {
  7142. // *** apply digital signature to the document ***
  7143. // get the document content
  7144. $pdfdoc = $this->getBuffer();
  7145. // remove last newline
  7146. $pdfdoc = substr($pdfdoc, 0, -1);
  7147. // Remove the original buffer
  7148. if (isset($this->diskcache) AND $this->diskcache) {
  7149. // remove buffer file from cache
  7150. unlink($this->buffer);
  7151. }
  7152. unset($this->buffer);
  7153. // remove filler space
  7154. $byterange_string_len = strlen(TCPDF_STATIC::$byterange_string);
  7155. // define the ByteRange
  7156. $byte_range = array();
  7157. $byte_range[0] = 0;
  7158. $byte_range[1] = strpos($pdfdoc, TCPDF_STATIC::$byterange_string) + $byterange_string_len + 10;
  7159. $byte_range[2] = $byte_range[1] + $this->signature_max_length + 2;
  7160. $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
  7161. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).substr($pdfdoc, $byte_range[2]);
  7162. // replace the ByteRange
  7163. $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]);
  7164. $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
  7165. $pdfdoc = str_replace(TCPDF_STATIC::$byterange_string, $byterange, $pdfdoc);
  7166. // write the document to a temporary folder
  7167. $tempdoc = TCPDF_STATIC::getObjFilename('doc');
  7168. $f = fopen($tempdoc, 'wb');
  7169. if (!$f) {
  7170. $this->Error('Unable to create temporary file: '.$tempdoc);
  7171. }
  7172. $pdfdoc_length = strlen($pdfdoc);
  7173. fwrite($f, $pdfdoc, $pdfdoc_length);
  7174. fclose($f);
  7175. // get digital signature via openssl library
  7176. $tempsign = TCPDF_STATIC::getObjFilename('sig');
  7177. if (empty($this->signature_data['extracerts'])) {
  7178. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED);
  7179. } else {
  7180. 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']);
  7181. }
  7182. unlink($tempdoc);
  7183. // read signature
  7184. $signature = file_get_contents($tempsign);
  7185. unlink($tempsign);
  7186. // extract signature
  7187. $signature = substr($signature, $pdfdoc_length);
  7188. $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13));
  7189. $tmparr = explode("\n\n", $signature);
  7190. $signature = $tmparr[1];
  7191. unset($tmparr);
  7192. // decode signature
  7193. $signature = base64_decode(trim($signature));
  7194. // convert signature to hex
  7195. $signature = current(unpack('H*', $signature));
  7196. $signature = str_pad($signature, $this->signature_max_length, '0');
  7197. // disable disk caching
  7198. $this->diskcache = false;
  7199. // Add signature to the document
  7200. $this->buffer = substr($pdfdoc, 0, $byte_range[1]).'<'.$signature.'>'.substr($pdfdoc, $byte_range[1]);
  7201. $this->bufferlen = strlen($this->buffer);
  7202. }
  7203. switch($dest) {
  7204. case 'I': {
  7205. // Send PDF to the standard output
  7206. if (ob_get_contents()) {
  7207. $this->Error('Some data has already been output, can\'t send PDF file');
  7208. }
  7209. if (php_sapi_name() != 'cli') {
  7210. // send output to a browser
  7211. header('Content-Type: application/pdf');
  7212. if (headers_sent()) {
  7213. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7214. }
  7215. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7216. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7217. header('Pragma: public');
  7218. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7219. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7220. header('Content-Disposition: inline; filename="'.basename($name).'"');
  7221. TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
  7222. } else {
  7223. echo $this->getBuffer();
  7224. }
  7225. break;
  7226. }
  7227. case 'D': {
  7228. // download PDF as file
  7229. if (ob_get_contents()) {
  7230. $this->Error('Some data has already been output, can\'t send PDF file');
  7231. }
  7232. header('Content-Description: File Transfer');
  7233. if (headers_sent()) {
  7234. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7235. }
  7236. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7237. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7238. header('Pragma: public');
  7239. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7240. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7241. // force download dialog
  7242. if (strpos(php_sapi_name(), 'cgi') === false) {
  7243. header('Content-Type: application/force-download');
  7244. header('Content-Type: application/octet-stream', false);
  7245. header('Content-Type: application/download', false);
  7246. header('Content-Type: application/pdf', false);
  7247. } else {
  7248. header('Content-Type: application/pdf');
  7249. }
  7250. // use the Content-Disposition header to supply a recommended filename
  7251. header('Content-Disposition: attachment; filename="'.basename($name).'"');
  7252. header('Content-Transfer-Encoding: binary');
  7253. TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
  7254. break;
  7255. }
  7256. case 'F':
  7257. case 'FI':
  7258. case 'FD': {
  7259. // save PDF to a local file
  7260. if ($this->diskcache) {
  7261. copy($this->buffer, $name);
  7262. } else {
  7263. $f = fopen($name, 'wb');
  7264. if (!$f) {
  7265. $this->Error('Unable to create output file: '.$name);
  7266. }
  7267. fwrite($f, $this->getBuffer(), $this->bufferlen);
  7268. fclose($f);
  7269. }
  7270. if ($dest == 'FI') {
  7271. // send headers to browser
  7272. header('Content-Type: application/pdf');
  7273. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7274. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7275. header('Pragma: public');
  7276. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7277. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7278. header('Content-Disposition: inline; filename="'.basename($name).'"');
  7279. TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name));
  7280. } elseif ($dest == 'FD') {
  7281. // send headers to browser
  7282. if (ob_get_contents()) {
  7283. $this->Error('Some data has already been output, can\'t send PDF file');
  7284. }
  7285. header('Content-Description: File Transfer');
  7286. if (headers_sent()) {
  7287. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7288. }
  7289. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7290. header('Pragma: public');
  7291. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7292. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7293. // force download dialog
  7294. if (strpos(php_sapi_name(), 'cgi') === false) {
  7295. header('Content-Type: application/force-download');
  7296. header('Content-Type: application/octet-stream', false);
  7297. header('Content-Type: application/download', false);
  7298. header('Content-Type: application/pdf', false);
  7299. } else {
  7300. header('Content-Type: application/pdf');
  7301. }
  7302. // use the Content-Disposition header to supply a recommended filename
  7303. header('Content-Disposition: attachment; filename="'.basename($name).'"');
  7304. header('Content-Transfer-Encoding: binary');
  7305. TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name));
  7306. }
  7307. break;
  7308. }
  7309. case 'E': {
  7310. // return PDF as base64 mime multi-part email attachment (RFC 2045)
  7311. $retval = 'Content-Type: application/pdf;'."\r\n";
  7312. $retval .= ' name="'.$name.'"'."\r\n";
  7313. $retval .= 'Content-Transfer-Encoding: base64'."\r\n";
  7314. $retval .= 'Content-Disposition: attachment;'."\r\n";
  7315. $retval .= ' filename="'.$name.'"'."\r\n\r\n";
  7316. $retval .= chunk_split(base64_encode($this->getBuffer()), 76, "\r\n");
  7317. return $retval;
  7318. }
  7319. case 'S': {
  7320. // returns PDF as a string
  7321. return $this->getBuffer();
  7322. }
  7323. default: {
  7324. $this->Error('Incorrect output destination: '.$dest);
  7325. }
  7326. }
  7327. return '';
  7328. }
  7329. /**
  7330. * Unset all class variables except the following critical variables.
  7331. * @param $destroyall (boolean) if true destroys all class variables, otherwise preserves critical variables.
  7332. * @param $preserve_objcopy (boolean) if true preserves the objcopy variable
  7333. * @public
  7334. * @since 4.5.016 (2009-02-24)
  7335. */
  7336. public function _destroy($destroyall=false, $preserve_objcopy=false) {
  7337. if ($destroyall AND isset($this->diskcache) AND $this->diskcache AND (!$preserve_objcopy) AND (!TCPDF_STATIC::empty_string($this->buffer))) {
  7338. // remove buffer file from cache
  7339. unlink($this->buffer);
  7340. }
  7341. if ($destroyall AND isset($this->cached_files) AND !empty($this->cached_files)) {
  7342. // remove cached files
  7343. foreach ($this->cached_files as $cachefile) {
  7344. if (is_file($cachefile)) {
  7345. unlink($cachefile);
  7346. }
  7347. }
  7348. unset($this->cached_files);
  7349. }
  7350. foreach (array_keys(get_object_vars($this)) as $val) {
  7351. if ($destroyall OR (
  7352. ($val != 'internal_encoding')
  7353. AND ($val != 'state')
  7354. AND ($val != 'bufferlen')
  7355. AND ($val != 'buffer')
  7356. AND ($val != 'diskcache')
  7357. AND ($val != 'cached_files')
  7358. AND ($val != 'sign')
  7359. AND ($val != 'signature_data')
  7360. AND ($val != 'signature_max_length')
  7361. AND ($val != 'byterange_string')
  7362. )) {
  7363. if ((!$preserve_objcopy OR ($val != 'objcopy')) AND isset($this->$val)) {
  7364. unset($this->$val);
  7365. }
  7366. }
  7367. }
  7368. }
  7369. /**
  7370. * Check for locale-related bug
  7371. * @protected
  7372. */
  7373. protected function _dochecks() {
  7374. //Check for locale-related bug
  7375. if (1.1 == 1) {
  7376. $this->Error('Don\'t alter the locale before including class file');
  7377. }
  7378. //Check for decimal separator
  7379. if (sprintf('%.1F', 1.0) != '1.0') {
  7380. setlocale(LC_NUMERIC, 'C');
  7381. }
  7382. }
  7383. /**
  7384. * Return an array containing variations for the basic page number alias.
  7385. * @param $a (string) Base alias.
  7386. * @return array of page number aliases
  7387. * @protected
  7388. */
  7389. protected function getInternalPageNumberAliases($a= '') {
  7390. $alias = array();
  7391. // build array of Unicode + ASCII variants (the order is important)
  7392. $alias = array('u' => array(), 'a' => array());
  7393. $u = '{'.$a.'}';
  7394. $alias['u'][] = TCPDF_STATIC::_escape($u);
  7395. if ($this->isunicode) {
  7396. $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($u, $this->isunicode, $this->CurrentFont));
  7397. $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($u, false, $this->tmprtl, $this->isunicode, $this->CurrentFont));
  7398. $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($a, $this->isunicode, $this->CurrentFont));
  7399. $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($a, false, $this->tmprtl, $this->isunicode, $this->CurrentFont));
  7400. }
  7401. $alias['a'][] = TCPDF_STATIC::_escape($a);
  7402. return $alias;
  7403. }
  7404. /**
  7405. * Return an array containing all internal page aliases.
  7406. * @return array of page number aliases
  7407. * @protected
  7408. */
  7409. protected function getAllInternalPageNumberAliases() {
  7410. $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);
  7411. $pnalias = array();
  7412. foreach($basic_alias as $k => $a) {
  7413. $pnalias[$k] = $this->getInternalPageNumberAliases($a);
  7414. }
  7415. return $pnalias;
  7416. }
  7417. /**
  7418. * Replace right shift page number aliases with spaces to correct right alignment.
  7419. * This works perfectly only when using monospaced fonts.
  7420. * @param $page (string) Page content.
  7421. * @param $aliases (array) Array of page aliases.
  7422. * @param $diff (int) initial difference to add.
  7423. * @return replaced page content.
  7424. * @protected
  7425. */
  7426. protected function replaceRightShiftPageNumAliases($page, $aliases, $diff) {
  7427. foreach ($aliases as $type => $alias) {
  7428. foreach ($alias as $a) {
  7429. // find position of compensation factor
  7430. $startnum = (strpos($a, ':') + 1);
  7431. $a = substr($a, 0, $startnum);
  7432. if (($pos = strpos($page, $a)) !== false) {
  7433. // end of alias
  7434. $endnum = strpos($page, '}', $pos);
  7435. // string to be replaced
  7436. $aa = substr($page, $pos, ($endnum - $pos + 1));
  7437. // get compensation factor
  7438. $ratio = substr($page, ($pos + $startnum), ($endnum - $pos - $startnum));
  7439. $ratio = preg_replace('/[^0-9\.]/', '', $ratio);
  7440. $ratio = floatval($ratio);
  7441. if ($type == 'u') {
  7442. $chrdiff = floor(($diff + 12) * $ratio);
  7443. $shift = str_repeat(' ', $chrdiff);
  7444. $shift = TCPDF_FONTS::UTF8ToUTF16BE($shift, false, $this->isunicode, $this->CurrentFont);
  7445. } else {
  7446. $chrdiff = floor(($diff + 11) * $ratio);
  7447. $shift = str_repeat(' ', $chrdiff);
  7448. }
  7449. $page = str_replace($aa, $shift, $page);
  7450. }
  7451. }
  7452. }
  7453. return $page;
  7454. }
  7455. /**
  7456. * Set page boxes to be included on page descriptions.
  7457. * @param $boxes (array) Array of page boxes to set on document: ('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox').
  7458. * @protected
  7459. */
  7460. protected function setPageBoxTypes($boxes) {
  7461. $this->page_boxes = array();
  7462. foreach ($boxes as $box) {
  7463. if (in_array($box, TCPDF_STATIC::$pageboxes)) {
  7464. $this->page_boxes[] = $box;
  7465. }
  7466. }
  7467. }
  7468. /**
  7469. * Output pages (and replace page number aliases).
  7470. * @protected
  7471. */
  7472. protected function _putpages() {
  7473. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  7474. // get internal aliases for page numbers
  7475. $pnalias = $this->getAllInternalPageNumberAliases();
  7476. $num_pages = $this->numpages;
  7477. $ptpa = TCPDF_STATIC::formatPageNumber(($this->starting_page_number + $num_pages - 1));
  7478. $ptpu = TCPDF_FONTS::UTF8ToUTF16BE($ptpa, false, $this->isunicode, $this->CurrentFont);
  7479. $ptp_num_chars = $this->GetNumChars($ptpa);
  7480. $pagegroupnum = 0;
  7481. $groupnum = 0;
  7482. $ptgu = 1;
  7483. $ptga = 1;
  7484. $ptg_num_chars = 1;
  7485. for ($n = 1; $n <= $num_pages; ++$n) {
  7486. // get current page
  7487. $temppage = $this->getPageBuffer($n);
  7488. $pagelen = strlen($temppage);
  7489. // set replacements for total pages number
  7490. $pnpa = TCPDF_STATIC::formatPageNumber(($this->starting_page_number + $n - 1));
  7491. $pnpu = TCPDF_FONTS::UTF8ToUTF16BE($pnpa, false, $this->isunicode, $this->CurrentFont);
  7492. $pnp_num_chars = $this->GetNumChars($pnpa);
  7493. $pdiff = 0; // difference used for right shift alignment of page numbers
  7494. $gdiff = 0; // difference used for right shift alignment of page group numbers
  7495. if (!empty($this->pagegroups)) {
  7496. if (isset($this->newpagegroup[$n])) {
  7497. $pagegroupnum = 0;
  7498. ++$groupnum;
  7499. $ptga = TCPDF_STATIC::formatPageNumber($this->pagegroups[$groupnum]);
  7500. $ptgu = TCPDF_FONTS::UTF8ToUTF16BE($ptga, false, $this->isunicode, $this->CurrentFont);
  7501. $ptg_num_chars = $this->GetNumChars($ptga);
  7502. }
  7503. ++$pagegroupnum;
  7504. $pnga = TCPDF_STATIC::formatPageNumber($pagegroupnum);
  7505. $pngu = TCPDF_FONTS::UTF8ToUTF16BE($pnga, false, $this->isunicode, $this->CurrentFont);
  7506. $png_num_chars = $this->GetNumChars($pnga);
  7507. // replace page numbers
  7508. $replace = array();
  7509. $replace[] = array($ptgu, $ptg_num_chars, 9, $pnalias[2]['u']);
  7510. $replace[] = array($ptga, $ptg_num_chars, 7, $pnalias[2]['a']);
  7511. $replace[] = array($pngu, $png_num_chars, 9, $pnalias[3]['u']);
  7512. $replace[] = array($pnga, $png_num_chars, 7, $pnalias[3]['a']);
  7513. list($temppage, $gdiff) = TCPDF_STATIC::replacePageNumAliases($temppage, $replace, $gdiff);
  7514. }
  7515. // replace page numbers
  7516. $replace = array();
  7517. $replace[] = array($ptpu, $ptp_num_chars, 9, $pnalias[0]['u']);
  7518. $replace[] = array($ptpa, $ptp_num_chars, 7, $pnalias[0]['a']);
  7519. $replace[] = array($pnpu, $pnp_num_chars, 9, $pnalias[1]['u']);
  7520. $replace[] = array($pnpa, $pnp_num_chars, 7, $pnalias[1]['a']);
  7521. list($temppage, $pdiff) = TCPDF_STATIC::replacePageNumAliases($temppage, $replace, $pdiff);
  7522. // replace right shift alias
  7523. $temppage = $this->replaceRightShiftPageNumAliases($temppage, $pnalias[4], max($pdiff, $gdiff));
  7524. // replace EPS marker
  7525. $temppage = str_replace($this->epsmarker, '', $temppage);
  7526. //Page
  7527. $this->page_obj_id[$n] = $this->_newobj();
  7528. $out = '<<';
  7529. $out .= ' /Type /Page';
  7530. $out .= ' /Parent 1 0 R';
  7531. $out .= ' /LastModified '.$this->_datestring(0, $this->doc_modification_timestamp);
  7532. $out .= ' /Resources 2 0 R';
  7533. foreach ($this->page_boxes as $box) {
  7534. $out .= ' /'.$box;
  7535. $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']);
  7536. }
  7537. if (isset($this->pagedim[$n]['BoxColorInfo']) AND !empty($this->pagedim[$n]['BoxColorInfo'])) {
  7538. $out .= ' /BoxColorInfo <<';
  7539. foreach ($this->page_boxes as $box) {
  7540. if (isset($this->pagedim[$n]['BoxColorInfo'][$box])) {
  7541. $out .= ' /'.$box.' <<';
  7542. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['C'])) {
  7543. $color = $this->pagedim[$n]['BoxColorInfo'][$box]['C'];
  7544. $out .= ' /C [';
  7545. $out .= sprintf(' %F %F %F', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
  7546. $out .= ' ]';
  7547. }
  7548. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['W'])) {
  7549. $out .= ' /W '.($this->pagedim[$n]['BoxColorInfo'][$box]['W'] * $this->k);
  7550. }
  7551. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['S'])) {
  7552. $out .= ' /S /'.$this->pagedim[$n]['BoxColorInfo'][$box]['S'];
  7553. }
  7554. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['D'])) {
  7555. $dashes = $this->pagedim[$n]['BoxColorInfo'][$box]['D'];
  7556. $out .= ' /D [';
  7557. foreach ($dashes as $dash) {
  7558. $out .= sprintf(' %F', ($dash * $this->k));
  7559. }
  7560. $out .= ' ]';
  7561. }
  7562. $out .= ' >>';
  7563. }
  7564. }
  7565. $out .= ' >>';
  7566. }
  7567. $out .= ' /Contents '.($this->n + 1).' 0 R';
  7568. $out .= ' /Rotate '.$this->pagedim[$n]['Rotate'];
  7569. if (!$this->pdfa_mode) {
  7570. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceRGB >>';
  7571. }
  7572. if (isset($this->pagedim[$n]['trans']) AND !empty($this->pagedim[$n]['trans'])) {
  7573. // page transitions
  7574. if (isset($this->pagedim[$n]['trans']['Dur'])) {
  7575. $out .= ' /Dur '.$this->pagedim[$n]['trans']['Dur'];
  7576. }
  7577. $out .= ' /Trans <<';
  7578. $out .= ' /Type /Trans';
  7579. if (isset($this->pagedim[$n]['trans']['S'])) {
  7580. $out .= ' /S /'.$this->pagedim[$n]['trans']['S'];
  7581. }
  7582. if (isset($this->pagedim[$n]['trans']['D'])) {
  7583. $out .= ' /D '.$this->pagedim[$n]['trans']['D'];
  7584. }
  7585. if (isset($this->pagedim[$n]['trans']['Dm'])) {
  7586. $out .= ' /Dm /'.$this->pagedim[$n]['trans']['Dm'];
  7587. }
  7588. if (isset($this->pagedim[$n]['trans']['M'])) {
  7589. $out .= ' /M /'.$this->pagedim[$n]['trans']['M'];
  7590. }
  7591. if (isset($this->pagedim[$n]['trans']['Di'])) {
  7592. $out .= ' /Di '.$this->pagedim[$n]['trans']['Di'];
  7593. }
  7594. if (isset($this->pagedim[$n]['trans']['SS'])) {
  7595. $out .= ' /SS '.$this->pagedim[$n]['trans']['SS'];
  7596. }
  7597. if (isset($this->pagedim[$n]['trans']['B'])) {
  7598. $out .= ' /B '.$this->pagedim[$n]['trans']['B'];
  7599. }
  7600. $out .= ' >>';
  7601. }
  7602. $out .= $this->_getannotsrefs($n);
  7603. $out .= ' /PZ '.$this->pagedim[$n]['PZ'];
  7604. $out .= ' >>';
  7605. $out .= "\n".'endobj';
  7606. $this->_out($out);
  7607. //Page content
  7608. $p = ($this->compress) ? gzcompress($temppage) : $temppage;
  7609. $this->_newobj();
  7610. $p = $this->_getrawstream($p);
  7611. $this->_out('<<'.$filter.'/Length '.strlen($p).'>> stream'."\n".$p."\n".'endstream'."\n".'endobj');
  7612. if ($this->diskcache) {
  7613. // remove temporary files
  7614. unlink($this->pages[$n]);
  7615. }
  7616. }
  7617. //Pages root
  7618. $out = $this->_getobj(1)."\n";
  7619. $out .= '<< /Type /Pages /Kids [';
  7620. foreach($this->page_obj_id as $page_obj) {
  7621. $out .= ' '.$page_obj.' 0 R';
  7622. }
  7623. $out .= ' ] /Count '.$num_pages.' >>';
  7624. $out .= "\n".'endobj';
  7625. $this->_out($out);
  7626. }
  7627. /**
  7628. * Output references to page annotations
  7629. * @param $n (int) page number
  7630. * @protected
  7631. * @author Nicola Asuni
  7632. * @since 4.7.000 (2008-08-29)
  7633. * @deprecated
  7634. */
  7635. protected function _putannotsrefs($n) {
  7636. $this->_out($this->_getannotsrefs($n));
  7637. }
  7638. /**
  7639. * Get references to page annotations.
  7640. * @param $n (int) page number
  7641. * @return string
  7642. * @protected
  7643. * @author Nicola Asuni
  7644. * @since 5.0.010 (2010-05-17)
  7645. */
  7646. protected function _getannotsrefs($n) {
  7647. if (!(isset($this->PageAnnots[$n]) OR ($this->sign AND isset($this->signature_data['cert_type'])))) {
  7648. return '';
  7649. }
  7650. $out = ' /Annots [';
  7651. if (isset($this->PageAnnots[$n])) {
  7652. foreach ($this->PageAnnots[$n] as $key => $val) {
  7653. if (!in_array($val['n'], $this->radio_groups)) {
  7654. $out .= ' '.$val['n'].' 0 R';
  7655. }
  7656. }
  7657. // add radiobutton groups
  7658. if (isset($this->radiobutton_groups[$n])) {
  7659. foreach ($this->radiobutton_groups[$n] as $key => $data) {
  7660. if (isset($data['n'])) {
  7661. $out .= ' '.$data['n'].' 0 R';
  7662. }
  7663. }
  7664. }
  7665. }
  7666. if ($this->sign AND ($n == $this->signature_appearance['page']) AND isset($this->signature_data['cert_type'])) {
  7667. // set reference for signature object
  7668. $out .= ' '.$this->sig_obj_id.' 0 R';
  7669. }
  7670. if (!empty($this->empty_signature_appearance)) {
  7671. foreach ($this->empty_signature_appearance as $esa) {
  7672. if ($esa['page'] == $n) {
  7673. // set reference for empty signature objects
  7674. $out .= ' '.$esa['objid'].' 0 R';
  7675. }
  7676. }
  7677. }
  7678. $out .= ' ]';
  7679. return $out;
  7680. }
  7681. /**
  7682. * Output annotations objects for all pages.
  7683. * !!! THIS METHOD IS NOT YET COMPLETED !!!
  7684. * See section 12.5 of PDF 32000_2008 reference.
  7685. * @protected
  7686. * @author Nicola Asuni
  7687. * @since 4.0.018 (2008-08-06)
  7688. */
  7689. protected function _putannotsobjs() {
  7690. // reset object counter
  7691. for ($n=1; $n <= $this->numpages; ++$n) {
  7692. if (isset($this->PageAnnots[$n])) {
  7693. // set page annotations
  7694. foreach ($this->PageAnnots[$n] as $key => $pl) {
  7695. $annot_obj_id = $this->PageAnnots[$n][$key]['n'];
  7696. // create annotation object for grouping radiobuttons
  7697. if (isset($this->radiobutton_groups[$n][$pl['txt']]) AND is_array($this->radiobutton_groups[$n][$pl['txt']])) {
  7698. $radio_button_obj_id = $this->radiobutton_groups[$n][$pl['txt']]['n'];
  7699. $annots = '<<';
  7700. $annots .= ' /Type /Annot';
  7701. $annots .= ' /Subtype /Widget';
  7702. $annots .= ' /Rect [0 0 0 0]';
  7703. if ($this->radiobutton_groups[$n][$pl['txt']]['#readonly#']) {
  7704. // read only
  7705. $annots .= ' /F 68';
  7706. $annots .= ' /Ff 49153';
  7707. } else {
  7708. $annots .= ' /F 4'; // default print for PDF/A
  7709. $annots .= ' /Ff 49152';
  7710. }
  7711. $annots .= ' /T '.$this->_datastring($pl['txt'], $radio_button_obj_id);
  7712. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  7713. $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $radio_button_obj_id);
  7714. }
  7715. $annots .= ' /FT /Btn';
  7716. $annots .= ' /Kids [';
  7717. $defval = '';
  7718. foreach ($this->radiobutton_groups[$n][$pl['txt']] as $key => $data) {
  7719. if (isset($data['kid'])) {
  7720. $annots .= ' '.$data['kid'].' 0 R';
  7721. if ($data['def'] !== 'Off') {
  7722. $defval = $data['def'];
  7723. }
  7724. }
  7725. }
  7726. $annots .= ' ]';
  7727. if (!empty($defval)) {
  7728. $annots .= ' /V /'.$defval;
  7729. }
  7730. $annots .= ' >>';
  7731. $this->_out($this->_getobj($radio_button_obj_id)."\n".$annots."\n".'endobj');
  7732. $this->form_obj_id[] = $radio_button_obj_id;
  7733. // store object id to be used on Parent entry of Kids
  7734. $this->radiobutton_groups[$n][$pl['txt']] = $radio_button_obj_id;
  7735. }
  7736. $formfield = false;
  7737. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  7738. $a = $pl['x'] * $this->k;
  7739. $b = $this->pagedim[$n]['h'] - (($pl['y'] + $pl['h']) * $this->k);
  7740. $c = $pl['w'] * $this->k;
  7741. $d = $pl['h'] * $this->k;
  7742. $rect = sprintf('%F %F %F %F', $a, $b, $a+$c, $b+$d);
  7743. // create new annotation object
  7744. $annots = '<</Type /Annot';
  7745. $annots .= ' /Subtype /'.$pl['opt']['subtype'];
  7746. $annots .= ' /Rect ['.$rect.']';
  7747. $ft = array('Btn', 'Tx', 'Ch', 'Sig');
  7748. if (isset($pl['opt']['ft']) AND in_array($pl['opt']['ft'], $ft)) {
  7749. $annots .= ' /FT /'.$pl['opt']['ft'];
  7750. $formfield = true;
  7751. }
  7752. $annots .= ' /Contents '.$this->_textstring($pl['txt'], $annot_obj_id);
  7753. $annots .= ' /P '.$this->page_obj_id[$n].' 0 R';
  7754. $annots .= ' /NM '.$this->_datastring(sprintf('%04u-%04u', $n, $key), $annot_obj_id);
  7755. $annots .= ' /M '.$this->_datestring($annot_obj_id, $this->doc_modification_timestamp);
  7756. if (isset($pl['opt']['f'])) {
  7757. $fval = 0;
  7758. if (is_array($pl['opt']['f'])) {
  7759. foreach ($pl['opt']['f'] as $f) {
  7760. switch (strtolower($f)) {
  7761. case 'invisible': {
  7762. $fval += 1 << 0;
  7763. break;
  7764. }
  7765. case 'hidden': {
  7766. $fval += 1 << 1;
  7767. break;
  7768. }
  7769. case 'print': {
  7770. $fval += 1 << 2;
  7771. break;
  7772. }
  7773. case 'nozoom': {
  7774. $fval += 1 << 3;
  7775. break;
  7776. }
  7777. case 'norotate': {
  7778. $fval += 1 << 4;
  7779. break;
  7780. }
  7781. case 'noview': {
  7782. $fval += 1 << 5;
  7783. break;
  7784. }
  7785. case 'readonly': {
  7786. $fval += 1 << 6;
  7787. break;
  7788. }
  7789. case 'locked': {
  7790. $fval += 1 << 8;
  7791. break;
  7792. }
  7793. case 'togglenoview': {
  7794. $fval += 1 << 9;
  7795. break;
  7796. }
  7797. case 'lockedcontents': {
  7798. $fval += 1 << 10;
  7799. break;
  7800. }
  7801. default: {
  7802. break;
  7803. }
  7804. }
  7805. }
  7806. } else {
  7807. $fval = intval($pl['opt']['f']);
  7808. }
  7809. } else {
  7810. $fval = 4;
  7811. }
  7812. if ($this->pdfa_mode) {
  7813. // force print flag for PDF/A mode
  7814. $fval |= 4;
  7815. }
  7816. $annots .= ' /F '.intval($fval);
  7817. if (isset($pl['opt']['as']) AND is_string($pl['opt']['as'])) {
  7818. $annots .= ' /AS /'.$pl['opt']['as'];
  7819. }
  7820. if (isset($pl['opt']['ap'])) {
  7821. // appearance stream
  7822. $annots .= ' /AP <<';
  7823. if (is_array($pl['opt']['ap'])) {
  7824. foreach ($pl['opt']['ap'] as $apmode => $apdef) {
  7825. // $apmode can be: n = normal; r = rollover; d = down;
  7826. $annots .= ' /'.strtoupper($apmode);
  7827. if (is_array($apdef)) {
  7828. $annots .= ' <<';
  7829. foreach ($apdef as $apstate => $stream) {
  7830. // reference to XObject that define the appearance for this mode-state
  7831. $apsobjid = $this->_putAPXObject($c, $d, $stream);
  7832. $annots .= ' /'.$apstate.' '.$apsobjid.' 0 R';
  7833. }
  7834. $annots .= ' >>';
  7835. } else {
  7836. // reference to XObject that define the appearance for this mode
  7837. $apsobjid = $this->_putAPXObject($c, $d, $apdef);
  7838. $annots .= ' '.$apsobjid.' 0 R';
  7839. }
  7840. }
  7841. } else {
  7842. $annots .= $pl['opt']['ap'];
  7843. }
  7844. $annots .= ' >>';
  7845. }
  7846. if (isset($pl['opt']['bs']) AND (is_array($pl['opt']['bs']))) {
  7847. $annots .= ' /BS <<';
  7848. $annots .= ' /Type /Border';
  7849. if (isset($pl['opt']['bs']['w'])) {
  7850. $annots .= ' /W '.intval($pl['opt']['bs']['w']);
  7851. }
  7852. $bstyles = array('S', 'D', 'B', 'I', 'U');
  7853. if (isset($pl['opt']['bs']['s']) AND in_array($pl['opt']['bs']['s'], $bstyles)) {
  7854. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  7855. }
  7856. if (isset($pl['opt']['bs']['d']) AND (is_array($pl['opt']['bs']['d']))) {
  7857. $annots .= ' /D [';
  7858. foreach ($pl['opt']['bs']['d'] as $cord) {
  7859. $annots .= ' '.intval($cord);
  7860. }
  7861. $annots .= ']';
  7862. }
  7863. $annots .= ' >>';
  7864. } else {
  7865. $annots .= ' /Border [';
  7866. if (isset($pl['opt']['border']) AND (count($pl['opt']['border']) >= 3)) {
  7867. $annots .= intval($pl['opt']['border'][0]).' ';
  7868. $annots .= intval($pl['opt']['border'][1]).' ';
  7869. $annots .= intval($pl['opt']['border'][2]);
  7870. if (isset($pl['opt']['border'][3]) AND is_array($pl['opt']['border'][3])) {
  7871. $annots .= ' [';
  7872. foreach ($pl['opt']['border'][3] as $dash) {
  7873. $annots .= intval($dash).' ';
  7874. }
  7875. $annots .= ']';
  7876. }
  7877. } else {
  7878. $annots .= '0 0 0';
  7879. }
  7880. $annots .= ']';
  7881. }
  7882. if (isset($pl['opt']['be']) AND (is_array($pl['opt']['be']))) {
  7883. $annots .= ' /BE <<';
  7884. $bstyles = array('S', 'C');
  7885. if (isset($pl['opt']['be']['s']) AND in_array($pl['opt']['be']['s'], $bstyles)) {
  7886. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  7887. } else {
  7888. $annots .= ' /S /S';
  7889. }
  7890. if (isset($pl['opt']['be']['i']) AND ($pl['opt']['be']['i'] >= 0) AND ($pl['opt']['be']['i'] <= 2)) {
  7891. $annots .= ' /I '.sprintf(' %F', $pl['opt']['be']['i']);
  7892. }
  7893. $annots .= '>>';
  7894. }
  7895. if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) {
  7896. $annots .= ' /C '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['c']);
  7897. }
  7898. //$annots .= ' /StructParent ';
  7899. //$annots .= ' /OC ';
  7900. $markups = array('text', 'freetext', 'line', 'square', 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp', 'caret', 'ink', 'fileattachment', 'sound');
  7901. if (in_array(strtolower($pl['opt']['subtype']), $markups)) {
  7902. // this is a markup type
  7903. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  7904. $annots .= ' /T '.$this->_textstring($pl['opt']['t'], $annot_obj_id);
  7905. }
  7906. //$annots .= ' /Popup ';
  7907. if (isset($pl['opt']['ca'])) {
  7908. $annots .= ' /CA '.sprintf('%F', floatval($pl['opt']['ca']));
  7909. }
  7910. if (isset($pl['opt']['rc'])) {
  7911. $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  7912. }
  7913. $annots .= ' /CreationDate '.$this->_datestring($annot_obj_id, $this->doc_creation_timestamp);
  7914. //$annots .= ' /IRT ';
  7915. if (isset($pl['opt']['subj'])) {
  7916. $annots .= ' /Subj '.$this->_textstring($pl['opt']['subj'], $annot_obj_id);
  7917. }
  7918. //$annots .= ' /RT ';
  7919. //$annots .= ' /IT ';
  7920. //$annots .= ' /ExData ';
  7921. }
  7922. $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt', 'ROpenArrow', 'RClosedArrow', 'Slash');
  7923. // Annotation types
  7924. switch (strtolower($pl['opt']['subtype'])) {
  7925. case 'text': {
  7926. if (isset($pl['opt']['open'])) {
  7927. $annots .= ' /Open '. (strtolower($pl['opt']['open']) == 'true' ? 'true' : 'false');
  7928. }
  7929. $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph');
  7930. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  7931. $annots .= ' /Name /'.$pl['opt']['name'];
  7932. } else {
  7933. $annots .= ' /Name /Note';
  7934. }
  7935. $statemodels = array('Marked', 'Review');
  7936. if (isset($pl['opt']['statemodel']) AND in_array($pl['opt']['statemodel'], $statemodels)) {
  7937. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  7938. } else {
  7939. $pl['opt']['statemodel'] = 'Marked';
  7940. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  7941. }
  7942. if ($pl['opt']['statemodel'] == 'Marked') {
  7943. $states = array('Accepted', 'Unmarked');
  7944. } else {
  7945. $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None');
  7946. }
  7947. if (isset($pl['opt']['state']) AND in_array($pl['opt']['state'], $states)) {
  7948. $annots .= ' /State /'.$pl['opt']['state'];
  7949. } else {
  7950. if ($pl['opt']['statemodel'] == 'Marked') {
  7951. $annots .= ' /State /Unmarked';
  7952. } else {
  7953. $annots .= ' /State /None';
  7954. }
  7955. }
  7956. break;
  7957. }
  7958. case 'link': {
  7959. if (is_string($pl['txt'])) {
  7960. if ($pl['txt'][0] == '#') {
  7961. // internal destination
  7962. $annots .= ' /Dest /'.TCPDF_STATIC::encodeNameObject(substr($pl['txt'], 1));
  7963. } elseif ($pl['txt'][0] == '%') {
  7964. // embedded PDF file
  7965. $filename = basename(substr($pl['txt'], 1));
  7966. $annots .= ' /A << /S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($n - 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>';
  7967. } elseif ($pl['txt'][0] == '*') {
  7968. // embedded generic file
  7969. $filename = basename(substr($pl['txt'], 1));
  7970. $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});';
  7971. $annots .= ' /A << /S /JavaScript /JS '.$this->_textstring($jsa, $annot_obj_id).'>>';
  7972. } else {
  7973. // external URI link
  7974. $annots .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>';
  7975. }
  7976. } elseif (isset($this->links[$pl['txt']])) {
  7977. // internal link ID
  7978. $l = $this->links[$pl['txt']];
  7979. if (isset($this->page_obj_id[($l[0])])) {
  7980. $annots .= sprintf(' /Dest [%u 0 R /XYZ 0 %F null]', $this->page_obj_id[($l[0])], ($this->pagedim[$l[0]]['h'] - ($l[1] * $this->k)));
  7981. }
  7982. }
  7983. $hmodes = array('N', 'I', 'O', 'P');
  7984. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmodes)) {
  7985. $annots .= ' /H /'.$pl['opt']['h'];
  7986. } else {
  7987. $annots .= ' /H /I';
  7988. }
  7989. //$annots .= ' /PA ';
  7990. //$annots .= ' /Quadpoints ';
  7991. break;
  7992. }
  7993. case 'freetext': {
  7994. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  7995. $annots .= ' /DA ('.$pl['opt']['da'].')';
  7996. }
  7997. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  7998. $annots .= ' /Q '.intval($pl['opt']['q']);
  7999. }
  8000. if (isset($pl['opt']['rc'])) {
  8001. $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  8002. }
  8003. if (isset($pl['opt']['ds'])) {
  8004. $annots .= ' /DS '.$this->_textstring($pl['opt']['ds'], $annot_obj_id);
  8005. }
  8006. if (isset($pl['opt']['cl']) AND is_array($pl['opt']['cl'])) {
  8007. $annots .= ' /CL [';
  8008. foreach ($pl['opt']['cl'] as $cl) {
  8009. $annots .= sprintf('%F ', $cl * $this->k);
  8010. }
  8011. $annots .= ']';
  8012. }
  8013. $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter');
  8014. if (isset($pl['opt']['it']) AND in_array($pl['opt']['it'], $tfit)) {
  8015. $annots .= ' /IT /'.$pl['opt']['it'];
  8016. }
  8017. if (isset($pl['opt']['rd']) AND is_array($pl['opt']['rd'])) {
  8018. $l = $pl['opt']['rd'][0] * $this->k;
  8019. $r = $pl['opt']['rd'][1] * $this->k;
  8020. $t = $pl['opt']['rd'][2] * $this->k;
  8021. $b = $pl['opt']['rd'][3] * $this->k;
  8022. $annots .= ' /RD ['.sprintf('%F %F %F %F', $l, $r, $t, $b).']';
  8023. }
  8024. if (isset($pl['opt']['le']) AND in_array($pl['opt']['le'], $lineendings)) {
  8025. $annots .= ' /LE /'.$pl['opt']['le'];
  8026. }
  8027. break;
  8028. }
  8029. case 'line': {
  8030. break;
  8031. }
  8032. case 'square': {
  8033. break;
  8034. }
  8035. case 'circle': {
  8036. break;
  8037. }
  8038. case 'polygon': {
  8039. break;
  8040. }
  8041. case 'polyline': {
  8042. break;
  8043. }
  8044. case 'highlight': {
  8045. break;
  8046. }
  8047. case 'underline': {
  8048. break;
  8049. }
  8050. case 'squiggly': {
  8051. break;
  8052. }
  8053. case 'strikeout': {
  8054. break;
  8055. }
  8056. case 'stamp': {
  8057. break;
  8058. }
  8059. case 'caret': {
  8060. break;
  8061. }
  8062. case 'ink': {
  8063. break;
  8064. }
  8065. case 'popup': {
  8066. break;
  8067. }
  8068. case 'fileattachment': {
  8069. if ($this->pdfa_mode) {
  8070. // embedded files are not allowed in PDF/A mode
  8071. break;
  8072. }
  8073. if (!isset($pl['opt']['fs'])) {
  8074. break;
  8075. }
  8076. $filename = basename($pl['opt']['fs']);
  8077. if (isset($this->embeddedfiles[$filename]['f'])) {
  8078. $annots .= ' /FS '.$this->embeddedfiles[$filename]['f'].' 0 R';
  8079. $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag');
  8080. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8081. $annots .= ' /Name /'.$pl['opt']['name'];
  8082. } else {
  8083. $annots .= ' /Name /PushPin';
  8084. }
  8085. // index (zero-based) of the annotation in the Annots array of this page
  8086. $this->embeddedfiles[$filename]['a'] = $key;
  8087. }
  8088. break;
  8089. }
  8090. case 'sound': {
  8091. if (!isset($pl['opt']['fs'])) {
  8092. break;
  8093. }
  8094. $filename = basename($pl['opt']['fs']);
  8095. if (isset($this->embeddedfiles[$filename]['f'])) {
  8096. // ... TO BE COMPLETED ...
  8097. // /R /C /B /E /CO /CP
  8098. $annots .= ' /Sound '.$this->embeddedfiles[$filename]['f'].' 0 R';
  8099. $iconsapp = array('Speaker', 'Mic');
  8100. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8101. $annots .= ' /Name /'.$pl['opt']['name'];
  8102. } else {
  8103. $annots .= ' /Name /Speaker';
  8104. }
  8105. }
  8106. break;
  8107. }
  8108. case 'movie': {
  8109. break;
  8110. }
  8111. case 'widget': {
  8112. $hmode = array('N', 'I', 'O', 'P', 'T');
  8113. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmode)) {
  8114. $annots .= ' /H /'.$pl['opt']['h'];
  8115. }
  8116. if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) {
  8117. $annots .= ' /MK <<';
  8118. if (isset($pl['opt']['mk']['r'])) {
  8119. $annots .= ' /R '.$pl['opt']['mk']['r'];
  8120. }
  8121. if (isset($pl['opt']['mk']['bc']) AND (is_array($pl['opt']['mk']['bc']))) {
  8122. $annots .= ' /BC '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['mk']['bc']);
  8123. }
  8124. if (isset($pl['opt']['mk']['bg']) AND (is_array($pl['opt']['mk']['bg']))) {
  8125. $annots .= ' /BG '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['mk']['bg']);
  8126. }
  8127. if (isset($pl['opt']['mk']['ca'])) {
  8128. $annots .= ' /CA '.$pl['opt']['mk']['ca'];
  8129. }
  8130. if (isset($pl['opt']['mk']['rc'])) {
  8131. $annots .= ' /RC '.$pl['opt']['mk']['rc'];
  8132. }
  8133. if (isset($pl['opt']['mk']['ac'])) {
  8134. $annots .= ' /AC '.$pl['opt']['mk']['ac'];
  8135. }
  8136. if (isset($pl['opt']['mk']['i'])) {
  8137. $info = $this->getImageBuffer($pl['opt']['mk']['i']);
  8138. if ($info !== false) {
  8139. $annots .= ' /I '.$info['n'].' 0 R';
  8140. }
  8141. }
  8142. if (isset($pl['opt']['mk']['ri'])) {
  8143. $info = $this->getImageBuffer($pl['opt']['mk']['ri']);
  8144. if ($info !== false) {
  8145. $annots .= ' /RI '.$info['n'].' 0 R';
  8146. }
  8147. }
  8148. if (isset($pl['opt']['mk']['ix'])) {
  8149. $info = $this->getImageBuffer($pl['opt']['mk']['ix']);
  8150. if ($info !== false) {
  8151. $annots .= ' /IX '.$info['n'].' 0 R';
  8152. }
  8153. }
  8154. if (isset($pl['opt']['mk']['if']) AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) {
  8155. $annots .= ' /IF <<';
  8156. $if_sw = array('A', 'B', 'S', 'N');
  8157. if (isset($pl['opt']['mk']['if']['sw']) AND in_array($pl['opt']['mk']['if']['sw'], $if_sw)) {
  8158. $annots .= ' /SW /'.$pl['opt']['mk']['if']['sw'];
  8159. }
  8160. $if_s = array('A', 'P');
  8161. if (isset($pl['opt']['mk']['if']['s']) AND in_array($pl['opt']['mk']['if']['s'], $if_s)) {
  8162. $annots .= ' /S /'.$pl['opt']['mk']['if']['s'];
  8163. }
  8164. if (isset($pl['opt']['mk']['if']['a']) AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) {
  8165. $annots .= sprintf(' /A [%F %F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]);
  8166. }
  8167. if (isset($pl['opt']['mk']['if']['fb']) AND ($pl['opt']['mk']['if']['fb'])) {
  8168. $annots .= ' /FB true';
  8169. }
  8170. $annots .= '>>';
  8171. }
  8172. if (isset($pl['opt']['mk']['tp']) AND ($pl['opt']['mk']['tp'] >= 0) AND ($pl['opt']['mk']['tp'] <= 6)) {
  8173. $annots .= ' /TP '.intval($pl['opt']['mk']['tp']);
  8174. }
  8175. $annots .= '>>';
  8176. } // end MK
  8177. // --- Entries for field dictionaries ---
  8178. if (isset($this->radiobutton_groups[$n][$pl['txt']])) {
  8179. // set parent
  8180. $annots .= ' /Parent '.$this->radiobutton_groups[$n][$pl['txt']].' 0 R';
  8181. }
  8182. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  8183. $annots .= ' /T '.$this->_datastring($pl['opt']['t'], $annot_obj_id);
  8184. }
  8185. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  8186. $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $annot_obj_id);
  8187. }
  8188. if (isset($pl['opt']['tm']) AND is_string($pl['opt']['tm'])) {
  8189. $annots .= ' /TM '.$this->_datastring($pl['opt']['tm'], $annot_obj_id);
  8190. }
  8191. if (isset($pl['opt']['ff'])) {
  8192. if (is_array($pl['opt']['ff'])) {
  8193. // array of bit settings
  8194. $flag = 0;
  8195. foreach($pl['opt']['ff'] as $val) {
  8196. $flag += 1 << ($val - 1);
  8197. }
  8198. } else {
  8199. $flag = intval($pl['opt']['ff']);
  8200. }
  8201. $annots .= ' /Ff '.$flag;
  8202. }
  8203. if (isset($pl['opt']['maxlen'])) {
  8204. $annots .= ' /MaxLen '.intval($pl['opt']['maxlen']);
  8205. }
  8206. if (isset($pl['opt']['v'])) {
  8207. $annots .= ' /V';
  8208. if (is_array($pl['opt']['v'])) {
  8209. foreach ($pl['opt']['v'] AS $optval) {
  8210. if (is_float($optval)) {
  8211. $optval = sprintf('%F', $optval);
  8212. }
  8213. $annots .= ' '.$optval;
  8214. }
  8215. } else {
  8216. $annots .= ' '.$this->_textstring($pl['opt']['v'], $annot_obj_id);
  8217. }
  8218. }
  8219. if (isset($pl['opt']['dv'])) {
  8220. $annots .= ' /DV';
  8221. if (is_array($pl['opt']['dv'])) {
  8222. foreach ($pl['opt']['dv'] AS $optval) {
  8223. if (is_float($optval)) {
  8224. $optval = sprintf('%F', $optval);
  8225. }
  8226. $annots .= ' '.$optval;
  8227. }
  8228. } else {
  8229. $annots .= ' '.$this->_textstring($pl['opt']['dv'], $annot_obj_id);
  8230. }
  8231. }
  8232. if (isset($pl['opt']['rv'])) {
  8233. $annots .= ' /RV';
  8234. if (is_array($pl['opt']['rv'])) {
  8235. foreach ($pl['opt']['rv'] AS $optval) {
  8236. if (is_float($optval)) {
  8237. $optval = sprintf('%F', $optval);
  8238. }
  8239. $annots .= ' '.$optval;
  8240. }
  8241. } else {
  8242. $annots .= ' '.$this->_textstring($pl['opt']['rv'], $annot_obj_id);
  8243. }
  8244. }
  8245. if (isset($pl['opt']['a']) AND !empty($pl['opt']['a'])) {
  8246. $annots .= ' /A << '.$pl['opt']['a'].' >>';
  8247. }
  8248. if (isset($pl['opt']['aa']) AND !empty($pl['opt']['aa'])) {
  8249. $annots .= ' /AA << '.$pl['opt']['aa'].' >>';
  8250. }
  8251. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  8252. $annots .= ' /DA ('.$pl['opt']['da'].')';
  8253. }
  8254. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  8255. $annots .= ' /Q '.intval($pl['opt']['q']);
  8256. }
  8257. if (isset($pl['opt']['opt']) AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) {
  8258. $annots .= ' /Opt [';
  8259. foreach($pl['opt']['opt'] AS $copt) {
  8260. if (is_array($copt)) {
  8261. $annots .= ' ['.$this->_textstring($copt[0], $annot_obj_id).' '.$this->_textstring($copt[1], $annot_obj_id).']';
  8262. } else {
  8263. $annots .= ' '.$this->_textstring($copt, $annot_obj_id);
  8264. }
  8265. }
  8266. $annots .= ']';
  8267. }
  8268. if (isset($pl['opt']['ti'])) {
  8269. $annots .= ' /TI '.intval($pl['opt']['ti']);
  8270. }
  8271. if (isset($pl['opt']['i']) AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) {
  8272. $annots .= ' /I [';
  8273. foreach($pl['opt']['i'] AS $copt) {
  8274. $annots .= intval($copt).' ';
  8275. }
  8276. $annots .= ']';
  8277. }
  8278. break;
  8279. }
  8280. case 'screen': {
  8281. break;
  8282. }
  8283. case 'printermark': {
  8284. break;
  8285. }
  8286. case 'trapnet': {
  8287. break;
  8288. }
  8289. case 'watermark': {
  8290. break;
  8291. }
  8292. case '3d': {
  8293. break;
  8294. }
  8295. default: {
  8296. break;
  8297. }
  8298. }
  8299. $annots .= '>>';
  8300. // create new annotation object
  8301. $this->_out($this->_getobj($annot_obj_id)."\n".$annots."\n".'endobj');
  8302. if ($formfield AND !isset($this->radiobutton_groups[$n][$pl['txt']])) {
  8303. // store reference of form object
  8304. $this->form_obj_id[] = $annot_obj_id;
  8305. }
  8306. }
  8307. }
  8308. } // end for each page
  8309. }
  8310. /**
  8311. * Put appearance streams XObject used to define annotation's appearance states.
  8312. * @param $w (int) annotation width
  8313. * @param $h (int) annotation height
  8314. * @param $stream (string) appearance stream
  8315. * @return int object ID
  8316. * @protected
  8317. * @since 4.8.001 (2009-09-09)
  8318. */
  8319. protected function _putAPXObject($w=0, $h=0, $stream='') {
  8320. $stream = trim($stream);
  8321. $out = $this->_getobj()."\n";
  8322. $this->xobjects['AX'.$this->n] = array('n' => $this->n);
  8323. $out .= '<<';
  8324. $out .= ' /Type /XObject';
  8325. $out .= ' /Subtype /Form';
  8326. $out .= ' /FormType 1';
  8327. if ($this->compress) {
  8328. $stream = gzcompress($stream);
  8329. $out .= ' /Filter /FlateDecode';
  8330. }
  8331. $rect = sprintf('%F %F', $w, $h);
  8332. $out .= ' /BBox [0 0 '.$rect.']';
  8333. $out .= ' /Matrix [1 0 0 1 0 0]';
  8334. $out .= ' /Resources 2 0 R';
  8335. $stream = $this->_getrawstream($stream);
  8336. $out .= ' /Length '.strlen($stream);
  8337. $out .= ' >>';
  8338. $out .= ' stream'."\n".$stream."\n".'endstream';
  8339. $out .= "\n".'endobj';
  8340. $this->_out($out);
  8341. return $this->n;
  8342. }
  8343. /**
  8344. * Output fonts.
  8345. * @author Nicola Asuni
  8346. * @protected
  8347. */
  8348. protected function _putfonts() {
  8349. $nf = $this->n;
  8350. foreach ($this->diffs as $diff) {
  8351. //Encodings
  8352. $this->_newobj();
  8353. $this->_out('<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.'] >>'."\n".'endobj');
  8354. }
  8355. $mqr = TCPDF_STATIC::get_mqr();
  8356. TCPDF_STATIC::set_mqr(false);
  8357. foreach ($this->FontFiles as $file => $info) {
  8358. // search and get font file to embedd
  8359. $fontfile = TCPDF_FONTS::getFontFullPath($file, $info['fontdir']);
  8360. if (!TCPDF_STATIC::empty_string($fontfile)) {
  8361. $font = file_get_contents($fontfile);
  8362. $compressed = (substr($file, -2) == '.z');
  8363. if ((!$compressed) AND (isset($info['length2']))) {
  8364. $header = (ord($font{0}) == 128);
  8365. if ($header) {
  8366. // strip first binary header
  8367. $font = substr($font, 6);
  8368. }
  8369. if ($header AND (ord($font[$info['length1']]) == 128)) {
  8370. // strip second binary header
  8371. $font = substr($font, 0, $info['length1']).substr($font, ($info['length1'] + 6));
  8372. }
  8373. } elseif ($info['subset'] AND ((!$compressed) OR ($compressed AND function_exists('gzcompress')))) {
  8374. if ($compressed) {
  8375. // uncompress font
  8376. $font = gzuncompress($font);
  8377. }
  8378. // merge subset characters
  8379. $subsetchars = array(); // used chars
  8380. foreach ($info['fontkeys'] as $fontkey) {
  8381. $fontinfo = $this->getFontBuffer($fontkey);
  8382. $subsetchars += $fontinfo['subsetchars'];
  8383. }
  8384. // rebuild a font subset
  8385. $font = TCPDF_FONTS::_getTrueTypeFontSubset($font, $subsetchars);
  8386. // calculate new font length
  8387. $info['length1'] = strlen($font);
  8388. if ($compressed) {
  8389. // recompress font
  8390. $font = gzcompress($font);
  8391. }
  8392. }
  8393. $this->_newobj();
  8394. $this->FontFiles[$file]['n'] = $this->n;
  8395. $stream = $this->_getrawstream($font);
  8396. $out = '<< /Length '.strlen($stream);
  8397. if ($compressed) {
  8398. $out .= ' /Filter /FlateDecode';
  8399. }
  8400. $out .= ' /Length1 '.$info['length1'];
  8401. if (isset($info['length2'])) {
  8402. $out .= ' /Length2 '.$info['length2'].' /Length3 0';
  8403. }
  8404. $out .= ' >>';
  8405. $out .= ' stream'."\n".$stream."\n".'endstream';
  8406. $out .= "\n".'endobj';
  8407. $this->_out($out);
  8408. }
  8409. }
  8410. TCPDF_STATIC::set_mqr($mqr);
  8411. foreach ($this->fontkeys as $k) {
  8412. //Font objects
  8413. $font = $this->getFontBuffer($k);
  8414. $type = $font['type'];
  8415. $name = $font['name'];
  8416. if ($type == 'core') {
  8417. // standard core font
  8418. $out = $this->_getobj($this->font_obj_ids[$k])."\n";
  8419. $out .= '<</Type /Font';
  8420. $out .= ' /Subtype /Type1';
  8421. $out .= ' /BaseFont /'.$name;
  8422. $out .= ' /Name /F'.$font['i'];
  8423. if ((strtolower($name) != 'symbol') AND (strtolower($name) != 'zapfdingbats')) {
  8424. $out .= ' /Encoding /WinAnsiEncoding';
  8425. }
  8426. if ($k == 'helvetica') {
  8427. // add default font for annotations
  8428. $this->annotation_fonts[$k] = $font['i'];
  8429. }
  8430. $out .= ' >>';
  8431. $out .= "\n".'endobj';
  8432. $this->_out($out);
  8433. } elseif (($type == 'Type1') OR ($type == 'TrueType')) {
  8434. // additional Type1 or TrueType font
  8435. $out = $this->_getobj($this->font_obj_ids[$k])."\n";
  8436. $out .= '<</Type /Font';
  8437. $out .= ' /Subtype /'.$type;
  8438. $out .= ' /BaseFont /'.$name;
  8439. $out .= ' /Name /F'.$font['i'];
  8440. $out .= ' /FirstChar 32 /LastChar 255';
  8441. $out .= ' /Widths '.($this->n + 1).' 0 R';
  8442. $out .= ' /FontDescriptor '.($this->n + 2).' 0 R';
  8443. if ($font['enc']) {
  8444. if (isset($font['diff'])) {
  8445. $out .= ' /Encoding '.($nf + $font['diff']).' 0 R';
  8446. } else {
  8447. $out .= ' /Encoding /WinAnsiEncoding';
  8448. }
  8449. }
  8450. $out .= ' >>';
  8451. $out .= "\n".'endobj';
  8452. $this->_out($out);
  8453. // Widths
  8454. $this->_newobj();
  8455. $s = '[';
  8456. for ($i = 32; $i < 256; ++$i) {
  8457. if (isset($font['cw'][$i])) {
  8458. $s .= $font['cw'][$i].' ';
  8459. } else {
  8460. $s .= $font['dw'].' ';
  8461. }
  8462. }
  8463. $s .= ']';
  8464. $s .= "\n".'endobj';
  8465. $this->_out($s);
  8466. //Descriptor
  8467. $this->_newobj();
  8468. $s = '<</Type /FontDescriptor /FontName /'.$name;
  8469. foreach ($font['desc'] as $fdk => $fdv) {
  8470. if (is_float($fdv)) {
  8471. $fdv = sprintf('%F', $fdv);
  8472. }
  8473. $s .= ' /'.$fdk.' '.$fdv.'';
  8474. }
  8475. if (!TCPDF_STATIC::empty_string($font['file'])) {
  8476. $s .= ' /FontFile'.($type == 'Type1' ? '' : '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R';
  8477. }
  8478. $s .= '>>';
  8479. $s .= "\n".'endobj';
  8480. $this->_out($s);
  8481. } else {
  8482. // additional types
  8483. $mtd = '_put'.strtolower($type);
  8484. if (!method_exists($this, $mtd)) {
  8485. $this->Error('Unsupported font type: '.$type);
  8486. }
  8487. $this->$mtd($font);
  8488. }
  8489. }
  8490. }
  8491. /**
  8492. * Adds unicode fonts.<br>
  8493. * Based on PDF Reference 1.3 (section 5)
  8494. * @param $font (array) font data
  8495. * @protected
  8496. * @author Nicola Asuni
  8497. * @since 1.52.0.TC005 (2005-01-05)
  8498. */
  8499. protected function _puttruetypeunicode($font) {
  8500. $fontname = '';
  8501. if ($font['subset']) {
  8502. // change name for font subsetting
  8503. $subtag = sprintf('%06u', $font['i']);
  8504. $subtag = strtr($subtag, '0123456789', 'ABCDEFGHIJ');
  8505. $fontname .= $subtag.'+';
  8506. }
  8507. $fontname .= $font['name'];
  8508. // Type0 Font
  8509. // A composite font composed of other fonts, organized hierarchically
  8510. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  8511. $out .= '<< /Type /Font';
  8512. $out .= ' /Subtype /Type0';
  8513. $out .= ' /BaseFont /'.$fontname;
  8514. $out .= ' /Name /F'.$font['i'];
  8515. $out .= ' /Encoding /'.$font['enc'];
  8516. $out .= ' /ToUnicode '.($this->n + 1).' 0 R';
  8517. $out .= ' /DescendantFonts ['.($this->n + 2).' 0 R]';
  8518. $out .= ' >>';
  8519. $out .= "\n".'endobj';
  8520. $this->_out($out);
  8521. // ToUnicode map for Identity-H
  8522. $stream = TCPDF_FONT_DATA::$uni_identity_h;
  8523. // ToUnicode Object
  8524. $this->_newobj();
  8525. $stream = ($this->compress) ? gzcompress($stream) : $stream;
  8526. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  8527. $stream = $this->_getrawstream($stream);
  8528. $this->_out('<<'.$filter.'/Length '.strlen($stream).'>> stream'."\n".$stream."\n".'endstream'."\n".'endobj');
  8529. // CIDFontType2
  8530. // A CIDFont whose glyph descriptions are based on TrueType font technology
  8531. $oid = $this->_newobj();
  8532. $out = '<< /Type /Font';
  8533. $out .= ' /Subtype /CIDFontType2';
  8534. $out .= ' /BaseFont /'.$fontname;
  8535. // A dictionary containing entries that define the character collection of the CIDFont.
  8536. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  8537. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  8538. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  8539. $out .= ' /CIDSystemInfo << '.$cidinfo.' >>';
  8540. $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
  8541. $out .= ' /DW '.$font['dw']; // default width
  8542. $out .= "\n".TCPDF_FONTS::_putfontwidths($font, 0);
  8543. if (isset($font['ctg']) AND (!TCPDF_STATIC::empty_string($font['ctg']))) {
  8544. $out .= "\n".'/CIDToGIDMap '.($this->n + 2).' 0 R';
  8545. }
  8546. $out .= ' >>';
  8547. $out .= "\n".'endobj';
  8548. $this->_out($out);
  8549. // Font descriptor
  8550. // A font descriptor describing the CIDFont default metrics other than its glyph widths
  8551. $this->_newobj();
  8552. $out = '<< /Type /FontDescriptor';
  8553. $out .= ' /FontName /'.$fontname;
  8554. foreach ($font['desc'] as $key => $value) {
  8555. if (is_float($value)) {
  8556. $value = sprintf('%F', $value);
  8557. }
  8558. $out .= ' /'.$key.' '.$value;
  8559. }
  8560. $fontdir = false;
  8561. if (!TCPDF_STATIC::empty_string($font['file'])) {
  8562. // A stream containing a TrueType font
  8563. $out .= ' /FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R';
  8564. $fontdir = $this->FontFiles[$font['file']]['fontdir'];
  8565. }
  8566. $out .= ' >>';
  8567. $out .= "\n".'endobj';
  8568. $this->_out($out);
  8569. if (isset($font['ctg']) AND (!TCPDF_STATIC::empty_string($font['ctg']))) {
  8570. $this->_newobj();
  8571. // Embed CIDToGIDMap
  8572. // A specification of the mapping from CIDs to glyph indices
  8573. // search and get CTG font file to embedd
  8574. $ctgfile = strtolower($font['ctg']);
  8575. // search and get ctg font file to embedd
  8576. $fontfile = TCPDF_FONTS::getFontFullPath($ctgfile, $fontdir);
  8577. if (TCPDF_STATIC::empty_string($fontfile)) {
  8578. $this->Error('Font file not found: '.$ctgfile);
  8579. }
  8580. $stream = $this->_getrawstream(file_get_contents($fontfile));
  8581. $out = '<< /Length '.strlen($stream).'';
  8582. if (substr($fontfile, -2) == '.z') { // check file extension
  8583. // Decompresses data encoded using the public-domain
  8584. // zlib/deflate compression method, reproducing the
  8585. // original text or binary data
  8586. $out .= ' /Filter /FlateDecode';
  8587. }
  8588. $out .= ' >>';
  8589. $out .= ' stream'."\n".$stream."\n".'endstream';
  8590. $out .= "\n".'endobj';
  8591. $this->_out($out);
  8592. }
  8593. }
  8594. /**
  8595. * Output CID-0 fonts.
  8596. * A Type 0 CIDFont contains glyph descriptions based on the Adobe Type 1 font format
  8597. * @param $font (array) font data
  8598. * @protected
  8599. * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
  8600. * @since 3.2.000 (2008-06-23)
  8601. */
  8602. protected function _putcidfont0($font) {
  8603. $cidoffset = 0;
  8604. if (!isset($font['cw'][1])) {
  8605. $cidoffset = 31;
  8606. }
  8607. if (isset($font['cidinfo']['uni2cid'])) {
  8608. // convert unicode to cid.
  8609. $uni2cid = $font['cidinfo']['uni2cid'];
  8610. $cw = array();
  8611. foreach ($font['cw'] as $uni => $width) {
  8612. if (isset($uni2cid[$uni])) {
  8613. $cw[($uni2cid[$uni] + $cidoffset)] = $width;
  8614. } elseif ($uni < 256) {
  8615. $cw[$uni] = $width;
  8616. } // else unknown character
  8617. }
  8618. $font = array_merge($font, array('cw' => $cw));
  8619. }
  8620. $name = $font['name'];
  8621. $enc = $font['enc'];
  8622. if ($enc) {
  8623. $longname = $name.'-'.$enc;
  8624. } else {
  8625. $longname = $name;
  8626. }
  8627. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  8628. $out .= '<</Type /Font';
  8629. $out .= ' /Subtype /Type0';
  8630. $out .= ' /BaseFont /'.$longname;
  8631. $out .= ' /Name /F'.$font['i'];
  8632. if ($enc) {
  8633. $out .= ' /Encoding /'.$enc;
  8634. }
  8635. $out .= ' /DescendantFonts ['.($this->n + 1).' 0 R]';
  8636. $out .= ' >>';
  8637. $out .= "\n".'endobj';
  8638. $this->_out($out);
  8639. $oid = $this->_newobj();
  8640. $out = '<</Type /Font';
  8641. $out .= ' /Subtype /CIDFontType0';
  8642. $out .= ' /BaseFont /'.$name;
  8643. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  8644. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  8645. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  8646. $out .= ' /CIDSystemInfo <<'.$cidinfo.'>>';
  8647. $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
  8648. $out .= ' /DW '.$font['dw'];
  8649. $out .= "\n".TCPDF_FONTS::_putfontwidths($font, $cidoffset);
  8650. $out .= ' >>';
  8651. $out .= "\n".'endobj';
  8652. $this->_out($out);
  8653. $this->_newobj();
  8654. $s = '<</Type /FontDescriptor /FontName /'.$name;
  8655. foreach ($font['desc'] as $k => $v) {
  8656. if ($k != 'Style') {
  8657. if (is_float($v)) {
  8658. $v = sprintf('%F', $v);
  8659. }
  8660. $s .= ' /'.$k.' '.$v.'';
  8661. }
  8662. }
  8663. $s .= '>>';
  8664. $s .= "\n".'endobj';
  8665. $this->_out($s);
  8666. }
  8667. /**
  8668. * Output images.
  8669. * @protected
  8670. */
  8671. protected function _putimages() {
  8672. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  8673. foreach ($this->imagekeys as $file) {
  8674. $info = $this->getImageBuffer($file);
  8675. // set object for alternate images array
  8676. if ((!$this->pdfa_mode) AND isset($info['altimgs']) AND !empty($info['altimgs'])) {
  8677. $altoid = $this->_newobj();
  8678. $out = '[';
  8679. foreach ($info['altimgs'] as $altimage) {
  8680. if (isset($this->xobjects['I'.$altimage[0]]['n'])) {
  8681. $out .= ' << /Image '.$this->xobjects['I'.$altimage[0]]['n'].' 0 R';
  8682. $out .= ' /DefaultForPrinting';
  8683. if ($altimage[1] === true) {
  8684. $out .= ' true';
  8685. } else {
  8686. $out .= ' false';
  8687. }
  8688. $out .= ' >>';
  8689. }
  8690. }
  8691. $out .= ' ]';
  8692. $out .= "\n".'endobj';
  8693. $this->_out($out);
  8694. }
  8695. // set image object
  8696. $oid = $this->_newobj();
  8697. $this->xobjects['I'.$info['i']] = array('n' => $oid);
  8698. $this->setImageSubBuffer($file, 'n', $this->n);
  8699. $out = '<</Type /XObject';
  8700. $out .= ' /Subtype /Image';
  8701. $out .= ' /Width '.$info['w'];
  8702. $out .= ' /Height '.$info['h'];
  8703. if (array_key_exists('masked', $info)) {
  8704. $out .= ' /SMask '.($this->n - 1).' 0 R';
  8705. }
  8706. // set color space
  8707. $icc = false;
  8708. if (isset($info['icc']) AND ($info['icc'] !== false)) {
  8709. // ICC Colour Space
  8710. $icc = true;
  8711. $out .= ' /ColorSpace [/ICCBased '.($this->n + 1).' 0 R]';
  8712. } elseif ($info['cs'] == 'Indexed') {
  8713. // Indexed Colour Space
  8714. $out .= ' /ColorSpace [/Indexed /DeviceRGB '.((strlen($info['pal']) / 3) - 1).' '.($this->n + 1).' 0 R]';
  8715. } else {
  8716. // Device Colour Space
  8717. $out .= ' /ColorSpace /'.$info['cs'];
  8718. }
  8719. if ($info['cs'] == 'DeviceCMYK') {
  8720. $out .= ' /Decode [1 0 1 0 1 0 1 0]';
  8721. }
  8722. $out .= ' /BitsPerComponent '.$info['bpc'];
  8723. if (isset($altoid) AND ($altoid > 0)) {
  8724. // reference to alternate images dictionary
  8725. $out .= ' /Alternates '.$altoid.' 0 R';
  8726. }
  8727. if (isset($info['exurl']) AND !empty($info['exurl'])) {
  8728. // external stream
  8729. $out .= ' /Length 0';
  8730. $out .= ' /F << /FS /URL /F '.$this->_datastring($info['exurl'], $oid).' >>';
  8731. if (isset($info['f'])) {
  8732. $out .= ' /FFilter /'.$info['f'];
  8733. }
  8734. $out .= ' >>';
  8735. $out .= ' stream'."\n".'endstream';
  8736. } else {
  8737. if (isset($info['f'])) {
  8738. $out .= ' /Filter /'.$info['f'];
  8739. }
  8740. if (isset($info['parms'])) {
  8741. $out .= ' '.$info['parms'];
  8742. }
  8743. if (isset($info['trns']) AND is_array($info['trns'])) {
  8744. $trns = '';
  8745. $count_info = count($info['trns']);
  8746. for ($i=0; $i < $count_info; ++$i) {
  8747. $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
  8748. }
  8749. $out .= ' /Mask ['.$trns.']';
  8750. }
  8751. $stream = $this->_getrawstream($info['data']);
  8752. $out .= ' /Length '.strlen($stream).' >>';
  8753. $out .= ' stream'."\n".$stream."\n".'endstream';
  8754. }
  8755. $out .= "\n".'endobj';
  8756. $this->_out($out);
  8757. if ($icc) {
  8758. // ICC colour profile
  8759. $this->_newobj();
  8760. $icc = ($this->compress) ? gzcompress($info['icc']) : $info['icc'];
  8761. $icc = $this->_getrawstream($icc);
  8762. $this->_out('<</N '.$info['ch'].' /Alternate /'.$info['cs'].' '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
  8763. } elseif ($info['cs'] == 'Indexed') {
  8764. // colour palette
  8765. $this->_newobj();
  8766. $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  8767. $pal = $this->_getrawstream($pal);
  8768. $this->_out('<<'.$filter.'/Length '.strlen($pal).'>> stream'."\n".$pal."\n".'endstream'."\n".'endobj');
  8769. }
  8770. }
  8771. }
  8772. /**
  8773. * Output Form XObjects Templates.
  8774. * @author Nicola Asuni
  8775. * @since 5.8.017 (2010-08-24)
  8776. * @protected
  8777. * @see startTemplate(), endTemplate(), printTemplate()
  8778. */
  8779. protected function _putxobjects() {
  8780. foreach ($this->xobjects as $key => $data) {
  8781. if (isset($data['outdata'])) {
  8782. $stream = str_replace($this->epsmarker, '', trim($data['outdata']));
  8783. $out = $this->_getobj($data['n'])."\n";
  8784. $out .= '<<';
  8785. $out .= ' /Type /XObject';
  8786. $out .= ' /Subtype /Form';
  8787. $out .= ' /FormType 1';
  8788. if ($this->compress) {
  8789. $stream = gzcompress($stream);
  8790. $out .= ' /Filter /FlateDecode';
  8791. }
  8792. $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));
  8793. $out .= ' /Matrix [1 0 0 1 0 0]';
  8794. $out .= ' /Resources <<';
  8795. $out .= ' /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  8796. if (!$this->pdfa_mode) {
  8797. // transparency
  8798. if (isset($data['extgstates']) AND !empty($data['extgstates'])) {
  8799. $out .= ' /ExtGState <<';
  8800. foreach ($data['extgstates'] as $k => $extgstate) {
  8801. if (isset($this->extgstates[$k]['name'])) {
  8802. $out .= ' /'.$this->extgstates[$k]['name'];
  8803. } else {
  8804. $out .= ' /GS'.$k;
  8805. }
  8806. $out .= ' '.$this->extgstates[$k]['n'].' 0 R';
  8807. }
  8808. $out .= ' >>';
  8809. }
  8810. if (isset($data['gradients']) AND !empty($data['gradients'])) {
  8811. $gp = '';
  8812. $gs = '';
  8813. foreach ($data['gradients'] as $id => $grad) {
  8814. // gradient patterns
  8815. $gp .= ' /p'.$id.' '.$this->gradients[$id]['pattern'].' 0 R';
  8816. // gradient shadings
  8817. $gs .= ' /Sh'.$id.' '.$this->gradients[$id]['id'].' 0 R';
  8818. }
  8819. $out .= ' /Pattern <<'.$gp.' >>';
  8820. $out .= ' /Shading <<'.$gs.' >>';
  8821. }
  8822. }
  8823. // spot colors
  8824. if (isset($data['spot_colors']) AND !empty($data['spot_colors'])) {
  8825. $out .= ' /ColorSpace <<';
  8826. foreach ($data['spot_colors'] as $name => $color) {
  8827. $out .= ' /CS'.$color['i'].' '.$this->spot_colors[$name]['n'].' 0 R';
  8828. }
  8829. $out .= ' >>';
  8830. }
  8831. // fonts
  8832. if (!empty($data['fonts'])) {
  8833. $out .= ' /Font <<';
  8834. foreach ($data['fonts'] as $fontkey => $fontid) {
  8835. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  8836. }
  8837. $out .= ' >>';
  8838. }
  8839. // images or nested xobjects
  8840. if (!empty($data['images']) OR !empty($data['xobjects'])) {
  8841. $out .= ' /XObject <<';
  8842. foreach ($data['images'] as $imgid) {
  8843. $out .= ' /I'.$imgid.' '.$this->xobjects['I'.$imgid]['n'].' 0 R';
  8844. }
  8845. foreach ($data['xobjects'] as $sub_id => $sub_objid) {
  8846. $out .= ' /'.$sub_id.' '.$sub_objid['n'].' 0 R';
  8847. }
  8848. $out .= ' >>';
  8849. }
  8850. $out .= ' >>'; //end resources
  8851. if (isset($data['group']) AND ($data['group'] !== false)) {
  8852. // set transparency group
  8853. $out .= ' /Group << /Type /Group /S /Transparency';
  8854. if (is_array($data['group'])) {
  8855. if (isset($data['group']['CS']) AND !empty($data['group']['CS'])) {
  8856. $out .= ' /CS /'.$data['group']['CS'];
  8857. }
  8858. if (isset($data['group']['I'])) {
  8859. $out .= ' /I /'.($data['group']['I']===true?'true':'false');
  8860. }
  8861. if (isset($data['group']['K'])) {
  8862. $out .= ' /K /'.($data['group']['K']===true?'true':'false');
  8863. }
  8864. }
  8865. $out .= ' >>';
  8866. }
  8867. $stream = $this->_getrawstream($stream, $data['n']);
  8868. $out .= ' /Length '.strlen($stream);
  8869. $out .= ' >>';
  8870. $out .= ' stream'."\n".$stream."\n".'endstream';
  8871. $out .= "\n".'endobj';
  8872. $this->_out($out);
  8873. }
  8874. }
  8875. }
  8876. /**
  8877. * Output Spot Colors Resources.
  8878. * @protected
  8879. * @since 4.0.024 (2008-09-12)
  8880. */
  8881. protected function _putspotcolors() {
  8882. foreach ($this->spot_colors as $name => $color) {
  8883. $this->_newobj();
  8884. $this->spot_colors[$name]['n'] = $this->n;
  8885. $out = '[/Separation /'.str_replace(' ', '#20', $name);
  8886. $out .= ' /DeviceCMYK <<';
  8887. $out .= ' /Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0]';
  8888. $out .= ' '.sprintf('/C1 [%F %F %F %F] ', ($color['C'] / 100), ($color['M'] / 100), ($color['Y'] / 100), ($color['K'] / 100));
  8889. $out .= ' /FunctionType 2 /Domain [0 1] /N 1>>]';
  8890. $out .= "\n".'endobj';
  8891. $this->_out($out);
  8892. }
  8893. }
  8894. /**
  8895. * Return XObjects Dictionary.
  8896. * @return string XObjects dictionary
  8897. * @protected
  8898. * @since 5.8.014 (2010-08-23)
  8899. */
  8900. protected function _getxobjectdict() {
  8901. $out = '';
  8902. foreach ($this->xobjects as $id => $objid) {
  8903. $out .= ' /'.$id.' '.$objid['n'].' 0 R';
  8904. }
  8905. return $out;
  8906. }
  8907. /**
  8908. * Output Resources Dictionary.
  8909. * @protected
  8910. */
  8911. protected function _putresourcedict() {
  8912. $out = $this->_getobj(2)."\n";
  8913. $out .= '<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  8914. $out .= ' /Font <<';
  8915. foreach ($this->fontkeys as $fontkey) {
  8916. $font = $this->getFontBuffer($fontkey);
  8917. $out .= ' /F'.$font['i'].' '.$font['n'].' 0 R';
  8918. }
  8919. $out .= ' >>';
  8920. $out .= ' /XObject <<';
  8921. $out .= $this->_getxobjectdict();
  8922. $out .= ' >>';
  8923. // layers
  8924. if (!empty($this->pdflayers)) {
  8925. $out .= ' /Properties <<';
  8926. foreach ($this->pdflayers as $layer) {
  8927. $out .= ' /'.$layer['layer'].' '.$layer['objid'].' 0 R';
  8928. }
  8929. $out .= ' >>';
  8930. }
  8931. if (!$this->pdfa_mode) {
  8932. // transparency
  8933. if (isset($this->extgstates) AND !empty($this->extgstates)) {
  8934. $out .= ' /ExtGState <<';
  8935. foreach ($this->extgstates as $k => $extgstate) {
  8936. if (isset($extgstate['name'])) {
  8937. $out .= ' /'.$extgstate['name'];
  8938. } else {
  8939. $out .= ' /GS'.$k;
  8940. }
  8941. $out .= ' '.$extgstate['n'].' 0 R';
  8942. }
  8943. $out .= ' >>';
  8944. }
  8945. if (isset($this->gradients) AND !empty($this->gradients)) {
  8946. $gp = '';
  8947. $gs = '';
  8948. foreach ($this->gradients as $id => $grad) {
  8949. // gradient patterns
  8950. $gp .= ' /p'.$id.' '.$grad['pattern'].' 0 R';
  8951. // gradient shadings
  8952. $gs .= ' /Sh'.$id.' '.$grad['id'].' 0 R';
  8953. }
  8954. $out .= ' /Pattern <<'.$gp.' >>';
  8955. $out .= ' /Shading <<'.$gs.' >>';
  8956. }
  8957. }
  8958. // spot colors
  8959. if (isset($this->spot_colors) AND !empty($this->spot_colors)) {
  8960. $out .= ' /ColorSpace <<';
  8961. foreach ($this->spot_colors as $color) {
  8962. $out .= ' /CS'.$color['i'].' '.$color['n'].' 0 R';
  8963. }
  8964. $out .= ' >>';
  8965. }
  8966. $out .= ' >>';
  8967. $out .= "\n".'endobj';
  8968. $this->_out($out);
  8969. }
  8970. /**
  8971. * Output Resources.
  8972. * @protected
  8973. */
  8974. protected function _putresources() {
  8975. $this->_putextgstates();
  8976. $this->_putocg();
  8977. $this->_putfonts();
  8978. $this->_putimages();
  8979. $this->_putspotcolors();
  8980. $this->_putshaders();
  8981. $this->_putxobjects();
  8982. $this->_putresourcedict();
  8983. $this->_putdests();
  8984. $this->_putEmbeddedFiles();
  8985. $this->_putannotsobjs();
  8986. $this->_putjavascript();
  8987. $this->_putbookmarks();
  8988. $this->_putencryption();
  8989. }
  8990. /**
  8991. * Adds some Metadata information (Document Information Dictionary)
  8992. * (see Chapter 14.3.3 Document Information Dictionary of PDF32000_2008.pdf Reference)
  8993. * @return int object id
  8994. * @protected
  8995. */
  8996. protected function _putinfo() {
  8997. $oid = $this->_newobj();
  8998. $out = '<<';
  8999. // store current isunicode value
  9000. $prev_isunicode = $this->isunicode;
  9001. if ($this->docinfounicode) {
  9002. $this->isunicode = true;
  9003. }
  9004. if (!TCPDF_STATIC::empty_string($this->title)) {
  9005. // The document's title.
  9006. $out .= ' /Title '.$this->_textstring($this->title, $oid);
  9007. }
  9008. if (!TCPDF_STATIC::empty_string($this->author)) {
  9009. // The name of the person who created the document.
  9010. $out .= ' /Author '.$this->_textstring($this->author, $oid);
  9011. }
  9012. if (!TCPDF_STATIC::empty_string($this->subject)) {
  9013. // The subject of the document.
  9014. $out .= ' /Subject '.$this->_textstring($this->subject, $oid);
  9015. }
  9016. if (!TCPDF_STATIC::empty_string($this->keywords)) {
  9017. // Keywords associated with the document.
  9018. $out .= ' /Keywords '.$this->_textstring($this->keywords, $oid);
  9019. }
  9020. if (!TCPDF_STATIC::empty_string($this->creator)) {
  9021. // 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.
  9022. $out .= ' /Creator '.$this->_textstring($this->creator, $oid);
  9023. }
  9024. // restore previous isunicode value
  9025. $this->isunicode = $prev_isunicode;
  9026. // default producer
  9027. $out .= ' /Producer '.$this->_textstring(TCPDF_STATIC::getTCPDFProducer(), $oid);
  9028. // The date and time the document was created, in human-readable form
  9029. $out .= ' /CreationDate '.$this->_datestring(0, $this->doc_creation_timestamp);
  9030. // The date and time the document was most recently modified, in human-readable form
  9031. $out .= ' /ModDate '.$this->_datestring(0, $this->doc_modification_timestamp);
  9032. // A name object indicating whether the document has been modified to include trapping information
  9033. $out .= ' /Trapped /False';
  9034. $out .= ' >>';
  9035. $out .= "\n".'endobj';
  9036. $this->_out($out);
  9037. return $oid;
  9038. }
  9039. /**
  9040. * Set additional XMP data to be added on the default XMP data just before the end of "x:xmpmeta" tag.
  9041. * IMPORTANT: This data is added as-is without controls, so you have to validate your data before using this method!
  9042. * @param $xmp (string) Custom XMP data.
  9043. * @since 5.9.128 (2011-10-06)
  9044. * @public
  9045. */
  9046. public function setExtraXMP($xmp) {
  9047. $this->custom_xmp = $xmp;
  9048. }
  9049. /**
  9050. * Put XMP data object and return ID.
  9051. * @return (int) The object ID.
  9052. * @since 5.9.121 (2011-09-28)
  9053. * @protected
  9054. */
  9055. protected function _putXMP() {
  9056. $oid = $this->_newobj();
  9057. // store current isunicode value
  9058. $prev_isunicode = $this->isunicode;
  9059. $this->isunicode = true;
  9060. $prev_encrypted = $this->encrypted;
  9061. $this->encrypted = false;
  9062. // set XMP data
  9063. $xmp = '<?xpacket begin="'.TCPDF_FONTS::unichr(0xfeff, $this->isunicode).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n";
  9064. $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";
  9065. $xmp .= "\t".'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n";
  9066. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
  9067. $xmp .= "\t\t\t".'<dc:format>application/pdf</dc:format>'."\n";
  9068. $xmp .= "\t\t\t".'<dc:title>'."\n";
  9069. $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
  9070. $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.TCPDF_STATIC::_escapeXML($this->title).'</rdf:li>'."\n";
  9071. $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
  9072. $xmp .= "\t\t\t".'</dc:title>'."\n";
  9073. $xmp .= "\t\t\t".'<dc:creator>'."\n";
  9074. $xmp .= "\t\t\t\t".'<rdf:Seq>'."\n";
  9075. $xmp .= "\t\t\t\t\t".'<rdf:li>'.TCPDF_STATIC::_escapeXML($this->author).'</rdf:li>'."\n";
  9076. $xmp .= "\t\t\t\t".'</rdf:Seq>'."\n";
  9077. $xmp .= "\t\t\t".'</dc:creator>'."\n";
  9078. $xmp .= "\t\t\t".'<dc:description>'."\n";
  9079. $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
  9080. $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.TCPDF_STATIC::_escapeXML($this->subject).'</rdf:li>'."\n";
  9081. $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
  9082. $xmp .= "\t\t\t".'</dc:description>'."\n";
  9083. $xmp .= "\t\t\t".'<dc:subject>'."\n";
  9084. $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
  9085. $xmp .= "\t\t\t\t\t".'<rdf:li>'.TCPDF_STATIC::_escapeXML($this->keywords).'</rdf:li>'."\n";
  9086. $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
  9087. $xmp .= "\t\t\t".'</dc:subject>'."\n";
  9088. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9089. // convert doc creation date format
  9090. $dcdate = TCPDF_STATIC::getFormattedDate($this->doc_creation_timestamp);
  9091. $doccreationdate = substr($dcdate, 0, 4).'-'.substr($dcdate, 4, 2).'-'.substr($dcdate, 6, 2);
  9092. $doccreationdate .= 'T'.substr($dcdate, 8, 2).':'.substr($dcdate, 10, 2).':'.substr($dcdate, 12, 2);
  9093. $doccreationdate .= '+'.substr($dcdate, 15, 2).':'.substr($dcdate, 18, 2);
  9094. $doccreationdate = TCPDF_STATIC::_escapeXML($doccreationdate);
  9095. // convert doc modification date format
  9096. $dmdate = TCPDF_STATIC::getFormattedDate($this->doc_modification_timestamp);
  9097. $docmoddate = substr($dmdate, 0, 4).'-'.substr($dmdate, 4, 2).'-'.substr($dmdate, 6, 2);
  9098. $docmoddate .= 'T'.substr($dmdate, 8, 2).':'.substr($dmdate, 10, 2).':'.substr($dmdate, 12, 2);
  9099. $docmoddate .= '+'.substr($dmdate, 15, 2).':'.substr($dmdate, 18, 2);
  9100. $docmoddate = TCPDF_STATIC::_escapeXML($docmoddate);
  9101. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n";
  9102. $xmp .= "\t\t\t".'<xmp:CreateDate>'.$doccreationdate.'</xmp:CreateDate>'."\n";
  9103. $xmp .= "\t\t\t".'<xmp:CreatorTool>'.$this->creator.'</xmp:CreatorTool>'."\n";
  9104. $xmp .= "\t\t\t".'<xmp:ModifyDate>'.$docmoddate.'</xmp:ModifyDate>'."\n";
  9105. $xmp .= "\t\t\t".'<xmp:MetadataDate>'.$doccreationdate.'</xmp:MetadataDate>'."\n";
  9106. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9107. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n";
  9108. $xmp .= "\t\t\t".'<pdf:Keywords>'.TCPDF_STATIC::_escapeXML($this->keywords).'</pdf:Keywords>'."\n";
  9109. $xmp .= "\t\t\t".'<pdf:Producer>'.TCPDF_STATIC::_escapeXML(TCPDF_STATIC::getTCPDFProducer()).'</pdf:Producer>'."\n";
  9110. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9111. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n";
  9112. $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);
  9113. $xmp .= "\t\t\t".'<xmpMM:DocumentID>'.$uuid.'</xmpMM:DocumentID>'."\n";
  9114. $xmp .= "\t\t\t".'<xmpMM:InstanceID>'.$uuid.'</xmpMM:InstanceID>'."\n";
  9115. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9116. if ($this->pdfa_mode) {
  9117. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">'."\n";
  9118. $xmp .= "\t\t\t".'<pdfaid:part>1</pdfaid:part>'."\n";
  9119. $xmp .= "\t\t\t".'<pdfaid:conformance>B</pdfaid:conformance>'."\n";
  9120. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9121. }
  9122. // XMP extension schemas
  9123. $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";
  9124. $xmp .= "\t\t\t".'<pdfaExtension:schemas>'."\n";
  9125. $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
  9126. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9127. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/pdf/1.3/</pdfaSchema:namespaceURI>'."\n";
  9128. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdf</pdfaSchema:prefix>'."\n";
  9129. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>Adobe PDF Schema</pdfaSchema:schema>'."\n";
  9130. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9131. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9132. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/xap/1.0/mm/</pdfaSchema:namespaceURI>'."\n";
  9133. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>xmpMM</pdfaSchema:prefix>'."\n";
  9134. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>XMP Media Management Schema</pdfaSchema:schema>'."\n";
  9135. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  9136. $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  9137. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9138. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9139. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>UUID based identifier for specific incarnation of a document</pdfaProperty:description>'."\n";
  9140. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>InstanceID</pdfaProperty:name>'."\n";
  9141. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>URI</pdfaProperty:valueType>'."\n";
  9142. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9143. $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  9144. $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  9145. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9146. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9147. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://www.aiim.org/pdfa/ns/id/</pdfaSchema:namespaceURI>'."\n";
  9148. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdfaid</pdfaSchema:prefix>'."\n";
  9149. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>PDF/A ID Schema</pdfaSchema:schema>'."\n";
  9150. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  9151. $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  9152. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9153. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9154. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Part of PDF/A standard</pdfaProperty:description>'."\n";
  9155. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>part</pdfaProperty:name>'."\n";
  9156. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Integer</pdfaProperty:valueType>'."\n";
  9157. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9158. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9159. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9160. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Amendment of PDF/A standard</pdfaProperty:description>'."\n";
  9161. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>amd</pdfaProperty:name>'."\n";
  9162. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
  9163. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9164. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9165. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9166. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Conformance level of PDF/A standard</pdfaProperty:description>'."\n";
  9167. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>conformance</pdfaProperty:name>'."\n";
  9168. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
  9169. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9170. $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  9171. $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  9172. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9173. $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
  9174. $xmp .= "\t\t\t".'</pdfaExtension:schemas>'."\n";
  9175. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9176. $xmp .= "\t".'</rdf:RDF>'."\n";
  9177. $xmp .= $this->custom_xmp;
  9178. $xmp .= '</x:xmpmeta>'."\n";
  9179. $xmp .= '<?xpacket end="w"?>';
  9180. $out = '<< /Type /Metadata /Subtype /XML /Length '.strlen($xmp).' >> stream'."\n".$xmp."\n".'endstream'."\n".'endobj';
  9181. // restore previous isunicode value
  9182. $this->isunicode = $prev_isunicode;
  9183. $this->encrypted = $prev_encrypted;
  9184. $this->_out($out);
  9185. return $oid;
  9186. }
  9187. /**
  9188. * Output Catalog.
  9189. * @return int object id
  9190. * @protected
  9191. */
  9192. protected function _putcatalog() {
  9193. // put XMP
  9194. $xmpobj = $this->_putXMP();
  9195. // if required, add standard sRGB_IEC61966-2.1 blackscaled ICC colour profile
  9196. if ($this->pdfa_mode OR $this->force_srgb) {
  9197. $iccobj = $this->_newobj();
  9198. $icc = file_get_contents(dirname(__FILE__).'/include/sRGB.icc');
  9199. $filter = '';
  9200. if ($this->compress) {
  9201. $filter = ' /Filter /FlateDecode';
  9202. $icc = gzcompress($icc);
  9203. }
  9204. $icc = $this->_getrawstream($icc);
  9205. $this->_out('<</N 3 '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
  9206. }
  9207. // start catalog
  9208. $oid = $this->_newobj();
  9209. $out = '<< /Type /Catalog';
  9210. $out .= ' /Version /'.$this->PDFVersion;
  9211. //$out .= ' /Extensions <<>>';
  9212. $out .= ' /Pages 1 0 R';
  9213. //$out .= ' /PageLabels ' //...;
  9214. $out .= ' /Names <<';
  9215. if ((!$this->pdfa_mode) AND !empty($this->n_js)) {
  9216. $out .= ' /JavaScript '.$this->n_js;
  9217. }
  9218. if (!empty($this->efnames)) {
  9219. $out .= ' /EmbeddedFiles <</Names [';
  9220. foreach ($this->efnames AS $fn => $fref) {
  9221. $out .= ' '.$this->_datastring($fn).' '.$fref;
  9222. }
  9223. $out .= ' ]>>';
  9224. }
  9225. $out .= ' >>';
  9226. if (!empty($this->dests)) {
  9227. $out .= ' /Dests '.($this->n_dests).' 0 R';
  9228. }
  9229. $out .= $this->_putviewerpreferences();
  9230. if (isset($this->LayoutMode) AND (!TCPDF_STATIC::empty_string($this->LayoutMode))) {
  9231. $out .= ' /PageLayout /'.$this->LayoutMode;
  9232. }
  9233. if (isset($this->PageMode) AND (!TCPDF_STATIC::empty_string($this->PageMode))) {
  9234. $out .= ' /PageMode /'.$this->PageMode;
  9235. }
  9236. if (count($this->outlines) > 0) {
  9237. $out .= ' /Outlines '.$this->OutlineRoot.' 0 R';
  9238. $out .= ' /PageMode /UseOutlines';
  9239. }
  9240. //$out .= ' /Threads []';
  9241. if ($this->ZoomMode == 'fullpage') {
  9242. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /Fit]';
  9243. } elseif ($this->ZoomMode == 'fullwidth') {
  9244. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /FitH null]';
  9245. } elseif ($this->ZoomMode == 'real') {
  9246. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null 1]';
  9247. } elseif (!is_string($this->ZoomMode)) {
  9248. $out .= sprintf(' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null %F]', ($this->ZoomMode / 100));
  9249. }
  9250. //$out .= ' /AA <<>>';
  9251. //$out .= ' /URI <<>>';
  9252. $out .= ' /Metadata '.$xmpobj.' 0 R';
  9253. //$out .= ' /StructTreeRoot <<>>';
  9254. //$out .= ' /MarkInfo <<>>';
  9255. if (isset($this->l['a_meta_language'])) {
  9256. $out .= ' /Lang '.$this->_textstring($this->l['a_meta_language'], $oid);
  9257. }
  9258. //$out .= ' /SpiderInfo <<>>';
  9259. // set OutputIntent to sRGB IEC61966-2.1 if required
  9260. if ($this->pdfa_mode OR $this->force_srgb) {
  9261. $out .= ' /OutputIntents [<<';
  9262. $out .= ' /Type /OutputIntent';
  9263. $out .= ' /S /GTS_PDFA1';
  9264. $out .= ' /OutputCondition '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  9265. $out .= ' /OutputConditionIdentifier '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  9266. $out .= ' /RegistryName '.$this->_textstring('http://www.color.org', $oid);
  9267. $out .= ' /Info '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  9268. $out .= ' /DestOutputProfile '.$iccobj.' 0 R';
  9269. $out .= ' >>]';
  9270. }
  9271. //$out .= ' /PieceInfo <<>>';
  9272. if (!empty($this->pdflayers)) {
  9273. $lyrobjs = '';
  9274. $lyrobjs_print = '';
  9275. $lyrobjs_view = '';
  9276. foreach ($this->pdflayers as $layer) {
  9277. $lyrobjs .= ' '.$layer['objid'].' 0 R';
  9278. if ($layer['print']) {
  9279. $lyrobjs_print .= ' '.$layer['objid'].' 0 R';
  9280. }
  9281. if ($layer['view']) {
  9282. $lyrobjs_view .= ' '.$layer['objid'].' 0 R';
  9283. }
  9284. }
  9285. $out .= ' /OCProperties << /OCGs ['.$lyrobjs.']';
  9286. $out .= ' /D <<';
  9287. $out .= ' /Name '.$this->_textstring('Layers', $oid);
  9288. $out .= ' /Creator '.$this->_textstring('TCPDF', $oid);
  9289. $out .= ' /BaseState /ON';
  9290. $out .= ' /ON ['.$lyrobjs_print.']';
  9291. $out .= ' /OFF ['.$lyrobjs_view.']';
  9292. $out .= ' /Intent /View';
  9293. $out .= ' /AS [';
  9294. $out .= ' << /Event /Print /OCGs ['.$lyrobjs.'] /Category [/Print] >>';
  9295. $out .= ' << /Event /View /OCGs ['.$lyrobjs.'] /Category [/View] >>';
  9296. $out .= ' ]';
  9297. $out .= ' /Order ['.$lyrobjs.']';
  9298. $out .= ' /ListMode /AllPages';
  9299. //$out .= ' /RBGroups ['..']';
  9300. //$out .= ' /Locked ['..']';
  9301. $out .= ' >>';
  9302. $out .= ' >>';
  9303. }
  9304. // AcroForm
  9305. if (!empty($this->form_obj_id)
  9306. OR ($this->sign AND isset($this->signature_data['cert_type']))
  9307. OR !empty($this->empty_signature_appearance)) {
  9308. $out .= ' /AcroForm <<';
  9309. $objrefs = '';
  9310. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9311. // set reference for signature object
  9312. $objrefs .= $this->sig_obj_id.' 0 R';
  9313. }
  9314. if (!empty($this->empty_signature_appearance)) {
  9315. foreach ($this->empty_signature_appearance as $esa) {
  9316. // set reference for empty signature objects
  9317. $objrefs .= ' '.$esa['objid'].' 0 R';
  9318. }
  9319. }
  9320. if (!empty($this->form_obj_id)) {
  9321. foreach($this->form_obj_id as $objid) {
  9322. $objrefs .= ' '.$objid.' 0 R';
  9323. }
  9324. }
  9325. $out .= ' /Fields ['.$objrefs.']';
  9326. // It's better to turn off this value and set the appearance stream for each annotation (/AP) to avoid conflicts with signature fields.
  9327. $out .= ' /NeedAppearances false';
  9328. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9329. if ($this->signature_data['cert_type'] > 0) {
  9330. $out .= ' /SigFlags 3';
  9331. } else {
  9332. $out .= ' /SigFlags 1';
  9333. }
  9334. }
  9335. //$out .= ' /CO ';
  9336. if (isset($this->annotation_fonts) AND !empty($this->annotation_fonts)) {
  9337. $out .= ' /DR <<';
  9338. $out .= ' /Font <<';
  9339. foreach ($this->annotation_fonts as $fontkey => $fontid) {
  9340. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  9341. }
  9342. $out .= ' >> >>';
  9343. }
  9344. $font = $this->getFontBuffer('helvetica');
  9345. $out .= ' /DA (/F'.$font['i'].' 0 Tf 0 g)';
  9346. $out .= ' /Q '.(($this->rtl)?'2':'0');
  9347. //$out .= ' /XFA ';
  9348. $out .= ' >>';
  9349. // signatures
  9350. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9351. if ($this->signature_data['cert_type'] > 0) {
  9352. $out .= ' /Perms << /DocMDP '.($this->sig_obj_id + 1).' 0 R >>';
  9353. } else {
  9354. $out .= ' /Perms << /UR3 '.($this->sig_obj_id + 1).' 0 R >>';
  9355. }
  9356. }
  9357. }
  9358. //$out .= ' /Legal <<>>';
  9359. //$out .= ' /Requirements []';
  9360. //$out .= ' /Collection <<>>';
  9361. //$out .= ' /NeedsRendering true';
  9362. $out .= ' >>';
  9363. $out .= "\n".'endobj';
  9364. $this->_out($out);
  9365. return $oid;
  9366. }
  9367. /**
  9368. * Output viewer preferences.
  9369. * @return string for viewer preferences
  9370. * @author Nicola asuni
  9371. * @since 3.1.000 (2008-06-09)
  9372. * @protected
  9373. */
  9374. protected function _putviewerpreferences() {
  9375. $vp = $this->viewer_preferences;
  9376. $out = ' /ViewerPreferences <<';
  9377. if ($this->rtl) {
  9378. $out .= ' /Direction /R2L';
  9379. } else {
  9380. $out .= ' /Direction /L2R';
  9381. }
  9382. if (isset($vp['HideToolbar']) AND ($vp['HideToolbar'])) {
  9383. $out .= ' /HideToolbar true';
  9384. }
  9385. if (isset($vp['HideMenubar']) AND ($vp['HideMenubar'])) {
  9386. $out .= ' /HideMenubar true';
  9387. }
  9388. if (isset($vp['HideWindowUI']) AND ($vp['HideWindowUI'])) {
  9389. $out .= ' /HideWindowUI true';
  9390. }
  9391. if (isset($vp['FitWindow']) AND ($vp['FitWindow'])) {
  9392. $out .= ' /FitWindow true';
  9393. }
  9394. if (isset($vp['CenterWindow']) AND ($vp['CenterWindow'])) {
  9395. $out .= ' /CenterWindow true';
  9396. }
  9397. if (isset($vp['DisplayDocTitle']) AND ($vp['DisplayDocTitle'])) {
  9398. $out .= ' /DisplayDocTitle true';
  9399. }
  9400. if (isset($vp['NonFullScreenPageMode'])) {
  9401. $out .= ' /NonFullScreenPageMode /'.$vp['NonFullScreenPageMode'];
  9402. }
  9403. if (isset($vp['ViewArea'])) {
  9404. $out .= ' /ViewArea /'.$vp['ViewArea'];
  9405. }
  9406. if (isset($vp['ViewClip'])) {
  9407. $out .= ' /ViewClip /'.$vp['ViewClip'];
  9408. }
  9409. if (isset($vp['PrintArea'])) {
  9410. $out .= ' /PrintArea /'.$vp['PrintArea'];
  9411. }
  9412. if (isset($vp['PrintClip'])) {
  9413. $out .= ' /PrintClip /'.$vp['PrintClip'];
  9414. }
  9415. if (isset($vp['PrintScaling'])) {
  9416. $out .= ' /PrintScaling /'.$vp['PrintScaling'];
  9417. }
  9418. if (isset($vp['Duplex']) AND (!TCPDF_STATIC::empty_string($vp['Duplex']))) {
  9419. $out .= ' /Duplex /'.$vp['Duplex'];
  9420. }
  9421. if (isset($vp['PickTrayByPDFSize'])) {
  9422. if ($vp['PickTrayByPDFSize']) {
  9423. $out .= ' /PickTrayByPDFSize true';
  9424. } else {
  9425. $out .= ' /PickTrayByPDFSize false';
  9426. }
  9427. }
  9428. if (isset($vp['PrintPageRange'])) {
  9429. $PrintPageRangeNum = '';
  9430. foreach ($vp['PrintPageRange'] as $k => $v) {
  9431. $PrintPageRangeNum .= ' '.($v - 1).'';
  9432. }
  9433. $out .= ' /PrintPageRange ['.substr($PrintPageRangeNum,1).']';
  9434. }
  9435. if (isset($vp['NumCopies'])) {
  9436. $out .= ' /NumCopies '.intval($vp['NumCopies']);
  9437. }
  9438. $out .= ' >>';
  9439. return $out;
  9440. }
  9441. /**
  9442. * Output PDF File Header (7.5.2).
  9443. * @protected
  9444. */
  9445. protected function _putheader() {
  9446. $this->_out('%PDF-'.$this->PDFVersion);
  9447. $this->_out('%'.chr(0xe2).chr(0xe3).chr(0xcf).chr(0xd3));
  9448. }
  9449. /**
  9450. * Output end of document (EOF).
  9451. * @protected
  9452. */
  9453. protected function _enddoc() {
  9454. if (isset($this->CurrentFont['fontkey']) AND isset($this->CurrentFont['subsetchars'])) {
  9455. // save subset chars of the previous font
  9456. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  9457. }
  9458. $this->state = 1;
  9459. $this->_putheader();
  9460. $this->_putpages();
  9461. $this->_putresources();
  9462. // empty signature fields
  9463. if (!empty($this->empty_signature_appearance)) {
  9464. foreach ($this->empty_signature_appearance as $key => $esa) {
  9465. // widget annotation for empty signature
  9466. $out = $this->_getobj($esa['objid'])."\n";
  9467. $out .= '<< /Type /Annot';
  9468. $out .= ' /Subtype /Widget';
  9469. $out .= ' /Rect ['.$esa['rect'].']';
  9470. $out .= ' /P '.$this->page_obj_id[($esa['page'])].' 0 R'; // link to signature appearance page
  9471. $out .= ' /F 4';
  9472. $out .= ' /FT /Sig';
  9473. $signame = $esa['name'].sprintf(' [%03d]', ($key + 1));
  9474. $out .= ' /T '.$this->_textstring($signame, $esa['objid']);
  9475. $out .= ' /Ff 0';
  9476. $out .= ' >>';
  9477. $out .= "\n".'endobj';
  9478. $this->_out($out);
  9479. }
  9480. }
  9481. // Signature
  9482. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9483. // widget annotation for signature
  9484. $out = $this->_getobj($this->sig_obj_id)."\n";
  9485. $out .= '<< /Type /Annot';
  9486. $out .= ' /Subtype /Widget';
  9487. $out .= ' /Rect ['.$this->signature_appearance['rect'].']';
  9488. $out .= ' /P '.$this->page_obj_id[($this->signature_appearance['page'])].' 0 R'; // link to signature appearance page
  9489. $out .= ' /F 4';
  9490. $out .= ' /FT /Sig';
  9491. $out .= ' /T '.$this->_textstring($this->signature_appearance['name'], $this->sig_obj_id);
  9492. $out .= ' /Ff 0';
  9493. $out .= ' /V '.($this->sig_obj_id + 1).' 0 R';
  9494. $out .= ' >>';
  9495. $out .= "\n".'endobj';
  9496. $this->_out($out);
  9497. // signature
  9498. $this->_putsignature();
  9499. }
  9500. // Info
  9501. $objid_info = $this->_putinfo();
  9502. // Catalog
  9503. $objid_catalog = $this->_putcatalog();
  9504. // Cross-ref
  9505. $o = $this->bufferlen;
  9506. // XREF section
  9507. $this->_out('xref');
  9508. $this->_out('0 '.($this->n + 1));
  9509. $this->_out('0000000000 65535 f ');
  9510. $freegen = ($this->n + 2);
  9511. for ($i=1; $i <= $this->n; ++$i) {
  9512. if (!isset($this->offsets[$i]) AND ($i > 1)) {
  9513. $this->_out(sprintf('0000000000 %05d f ', $freegen));
  9514. ++$freegen;
  9515. } else {
  9516. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
  9517. }
  9518. }
  9519. // TRAILER
  9520. $out = 'trailer'."\n";
  9521. $out .= '<<';
  9522. $out .= ' /Size '.($this->n + 1);
  9523. $out .= ' /Root '.$objid_catalog.' 0 R';
  9524. $out .= ' /Info '.$objid_info.' 0 R';
  9525. if ($this->encrypted) {
  9526. $out .= ' /Encrypt '.$this->encryptdata['objid'].' 0 R';
  9527. }
  9528. $out .= ' /ID [ <'.$this->file_id.'> <'.$this->file_id.'> ]';
  9529. $out .= ' >>';
  9530. $this->_out($out);
  9531. $this->_out('startxref');
  9532. $this->_out($o);
  9533. $this->_out('%%EOF');
  9534. $this->state = 3; // end-of-doc
  9535. if ($this->diskcache) {
  9536. // remove temporary files used for images
  9537. foreach ($this->imagekeys as $key) {
  9538. // remove temporary files
  9539. unlink($this->images[$key]);
  9540. }
  9541. foreach ($this->fontkeys as $key) {
  9542. // remove temporary files
  9543. unlink($this->fonts[$key]);
  9544. }
  9545. }
  9546. }
  9547. /**
  9548. * Initialize a new page.
  9549. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  9550. * @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().
  9551. * @protected
  9552. * @see getPageSizeFromFormat(), setPageFormat()
  9553. */
  9554. protected function _beginpage($orientation='', $format='') {
  9555. ++$this->page;
  9556. $this->pageobjects[$this->page] = array();
  9557. $this->setPageBuffer($this->page, '');
  9558. // initialize array for graphics tranformation positions inside a page buffer
  9559. $this->transfmrk[$this->page] = array();
  9560. $this->state = 2;
  9561. if (TCPDF_STATIC::empty_string($orientation)) {
  9562. if (isset($this->CurOrientation)) {
  9563. $orientation = $this->CurOrientation;
  9564. } elseif ($this->fwPt > $this->fhPt) {
  9565. // landscape
  9566. $orientation = 'L';
  9567. } else {
  9568. // portrait
  9569. $orientation = 'P';
  9570. }
  9571. }
  9572. if (TCPDF_STATIC::empty_string($format)) {
  9573. $this->pagedim[$this->page] = $this->pagedim[($this->page - 1)];
  9574. $this->setPageOrientation($orientation);
  9575. } else {
  9576. $this->setPageFormat($format, $orientation);
  9577. }
  9578. if ($this->rtl) {
  9579. $this->x = $this->w - $this->rMargin;
  9580. } else {
  9581. $this->x = $this->lMargin;
  9582. }
  9583. $this->y = $this->tMargin;
  9584. if (isset($this->newpagegroup[$this->page])) {
  9585. // start a new group
  9586. $this->currpagegroup = $this->newpagegroup[$this->page];
  9587. $this->pagegroups[$this->currpagegroup] = 1;
  9588. } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) {
  9589. ++$this->pagegroups[$this->currpagegroup];
  9590. }
  9591. }
  9592. /**
  9593. * Mark end of page.
  9594. * @protected
  9595. */
  9596. protected function _endpage() {
  9597. $this->setVisibility('all');
  9598. $this->state = 1;
  9599. }
  9600. /**
  9601. * Begin a new object and return the object number.
  9602. * @return int object number
  9603. * @protected
  9604. */
  9605. protected function _newobj() {
  9606. $this->_out($this->_getobj());
  9607. return $this->n;
  9608. }
  9609. /**
  9610. * Return the starting object string for the selected object ID.
  9611. * @param $objid (int) Object ID (leave empty to get a new ID).
  9612. * @return string the starting object string
  9613. * @protected
  9614. * @since 5.8.009 (2010-08-20)
  9615. */
  9616. protected function _getobj($objid='') {
  9617. if ($objid === '') {
  9618. ++$this->n;
  9619. $objid = $this->n;
  9620. }
  9621. $this->offsets[$objid] = $this->bufferlen;
  9622. $this->pageobjects[$this->page][] = $objid;
  9623. return $objid.' 0 obj';
  9624. }
  9625. /**
  9626. * Underline text.
  9627. * @param $x (int) X coordinate
  9628. * @param $y (int) Y coordinate
  9629. * @param $txt (string) text to underline
  9630. * @protected
  9631. */
  9632. protected function _dounderline($x, $y, $txt) {
  9633. $w = $this->GetStringWidth($txt);
  9634. return $this->_dounderlinew($x, $y, $w);
  9635. }
  9636. /**
  9637. * Underline for rectangular text area.
  9638. * @param $x (int) X coordinate
  9639. * @param $y (int) Y coordinate
  9640. * @param $w (int) width to underline
  9641. * @protected
  9642. * @since 4.8.008 (2009-09-29)
  9643. */
  9644. protected function _dounderlinew($x, $y, $w) {
  9645. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  9646. return sprintf('%F %F %F %F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew), $w * $this->k, $linew);
  9647. }
  9648. /**
  9649. * Line through text.
  9650. * @param $x (int) X coordinate
  9651. * @param $y (int) Y coordinate
  9652. * @param $txt (string) text to linethrough
  9653. * @protected
  9654. */
  9655. protected function _dolinethrough($x, $y, $txt) {
  9656. $w = $this->GetStringWidth($txt);
  9657. return $this->_dolinethroughw($x, $y, $w);
  9658. }
  9659. /**
  9660. * Line through for rectangular text area.
  9661. * @param $x (int) X coordinate
  9662. * @param $y (int) Y coordinate
  9663. * @param $w (int) line length (width)
  9664. * @protected
  9665. * @since 4.9.008 (2009-09-29)
  9666. */
  9667. protected function _dolinethroughw($x, $y, $w) {
  9668. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  9669. return sprintf('%F %F %F %F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew + ($this->FontSizePt / 3)), $w * $this->k, $linew);
  9670. }
  9671. /**
  9672. * Overline text.
  9673. * @param $x (int) X coordinate
  9674. * @param $y (int) Y coordinate
  9675. * @param $txt (string) text to overline
  9676. * @protected
  9677. * @since 4.9.015 (2010-04-19)
  9678. */
  9679. protected function _dooverline($x, $y, $txt) {
  9680. $w = $this->GetStringWidth($txt);
  9681. return $this->_dooverlinew($x, $y, $w);
  9682. }
  9683. /**
  9684. * Overline for rectangular text area.
  9685. * @param $x (int) X coordinate
  9686. * @param $y (int) Y coordinate
  9687. * @param $w (int) width to overline
  9688. * @protected
  9689. * @since 4.9.015 (2010-04-19)
  9690. */
  9691. protected function _dooverlinew($x, $y, $w) {
  9692. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  9693. return sprintf('%F %F %F %F re f', $x * $this->k, (($this->h - $y + $this->FontAscent) * $this->k) - $linew, $w * $this->k, $linew);
  9694. }
  9695. /**
  9696. * Format a data string for meta information
  9697. * @param $s (string) data string to escape.
  9698. * @param $n (int) object ID
  9699. * @return string escaped string.
  9700. * @protected
  9701. */
  9702. protected function _datastring($s, $n=0) {
  9703. if ($n == 0) {
  9704. $n = $this->n;
  9705. }
  9706. $s = $this->_encrypt_data($n, $s);
  9707. return '('. TCPDF_STATIC::_escape($s).')';
  9708. }
  9709. /**
  9710. * Set the document creation timestamp
  9711. * @param $time (mixed) Document creation timestamp in seconds or date-time string.
  9712. * @public
  9713. * @since 5.9.152 (2012-03-23)
  9714. */
  9715. public function setDocCreationTimestamp($time) {
  9716. if (is_string($time)) {
  9717. $time = TCPDF_STATIC::getTimestamp($time);
  9718. }
  9719. $this->doc_creation_timestamp = intval($time);
  9720. }
  9721. /**
  9722. * Set the document modification timestamp
  9723. * @param $time (mixed) Document modification timestamp in seconds or date-time string.
  9724. * @public
  9725. * @since 5.9.152 (2012-03-23)
  9726. */
  9727. public function setDocModificationTimestamp($time) {
  9728. if (is_string($time)) {
  9729. $time = TCPDF_STATIC::getTimestamp($time);
  9730. }
  9731. $this->doc_modification_timestamp = intval($time);
  9732. }
  9733. /**
  9734. * Returns document creation timestamp in seconds.
  9735. * @return (int) Creation timestamp in seconds.
  9736. * @public
  9737. * @since 5.9.152 (2012-03-23)
  9738. */
  9739. public function getDocCreationTimestamp() {
  9740. return $this->doc_creation_timestamp;
  9741. }
  9742. /**
  9743. * Returns document modification timestamp in seconds.
  9744. * @return (int) Modfication timestamp in seconds.
  9745. * @public
  9746. * @since 5.9.152 (2012-03-23)
  9747. */
  9748. public function getDocModificationTimestamp() {
  9749. return $this->doc_modification_timestamp;
  9750. }
  9751. /**
  9752. * Returns a formatted date for meta information
  9753. * @param $n (int) Object ID.
  9754. * @param $timestamp (int) Timestamp to convert.
  9755. * @return string escaped date string.
  9756. * @protected
  9757. * @since 4.6.028 (2009-08-25)
  9758. */
  9759. protected function _datestring($n=0, $timestamp=0) {
  9760. if ((empty($timestamp)) OR ($timestamp < 0)) {
  9761. $timestamp = $this->doc_creation_timestamp;
  9762. }
  9763. return $this->_datastring('D:'.TCPDF_STATIC::getFormattedDate($timestamp), $n);
  9764. }
  9765. /**
  9766. * Format a text string for meta information
  9767. * @param $s (string) string to escape.
  9768. * @param $n (int) object ID
  9769. * @return string escaped string.
  9770. * @protected
  9771. */
  9772. protected function _textstring($s, $n=0) {
  9773. if ($this->isunicode) {
  9774. //Convert string to UTF-16BE
  9775. $s = TCPDF_FONTS::UTF8ToUTF16BE($s, true, $this->isunicode, $this->CurrentFont);
  9776. }
  9777. return $this->_datastring($s, $n);
  9778. }
  9779. /**
  9780. * THIS METHOD IS DEPRECATED
  9781. * Format a text string
  9782. * @param $s (string) string to escape.
  9783. * @return string escaped string.
  9784. * @protected
  9785. * @deprecated
  9786. */
  9787. protected function _escapetext($s) {
  9788. if ($this->isunicode) {
  9789. if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
  9790. $s = TCPDF_FONTS::UTF8ToLatin1($s, $this->isunicode, $this->CurrentFont);
  9791. } else {
  9792. //Convert string to UTF-16BE and reverse RTL language
  9793. $s = TCPDF_FONTS::utf8StrRev($s, false, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  9794. }
  9795. }
  9796. return TCPDF_STATIC::_escape($s);
  9797. }
  9798. /**
  9799. * get raw output stream.
  9800. * @param $s (string) string to output.
  9801. * @param $n (int) object reference for encryption mode
  9802. * @protected
  9803. * @author Nicola Asuni
  9804. * @since 5.5.000 (2010-06-22)
  9805. */
  9806. protected function _getrawstream($s, $n=0) {
  9807. if ($n <= 0) {
  9808. // default to current object
  9809. $n = $this->n;
  9810. }
  9811. return $this->_encrypt_data($n, $s);
  9812. }
  9813. /**
  9814. * Format output stream (DEPRECATED).
  9815. * @param $s (string) string to output.
  9816. * @param $n (int) object reference for encryption mode
  9817. * @protected
  9818. * @deprecated
  9819. */
  9820. protected function _getstream($s, $n=0) {
  9821. return 'stream'."\n".$this->_getrawstream($s, $n)."\n".'endstream';
  9822. }
  9823. /**
  9824. * Output a stream (DEPRECATED).
  9825. * @param $s (string) string to output.
  9826. * @param $n (int) object reference for encryption mode
  9827. * @protected
  9828. * @deprecated
  9829. */
  9830. protected function _putstream($s, $n=0) {
  9831. $this->_out($this->_getstream($s, $n));
  9832. }
  9833. /**
  9834. * Output a string to the document.
  9835. * @param $s (string) string to output.
  9836. * @protected
  9837. */
  9838. protected function _out($s) {
  9839. if ($this->state == 2) {
  9840. if ($this->inxobj) {
  9841. // we are inside an XObject template
  9842. $this->xobjects[$this->xobjid]['outdata'] .= $s."\n";
  9843. } elseif ((!$this->InFooter) AND isset($this->footerlen[$this->page]) AND ($this->footerlen[$this->page] > 0)) {
  9844. // puts data before page footer
  9845. $pagebuff = $this->getPageBuffer($this->page);
  9846. $page = substr($pagebuff, 0, -$this->footerlen[$this->page]);
  9847. $footer = substr($pagebuff, -$this->footerlen[$this->page]);
  9848. $this->setPageBuffer($this->page, $page.$s."\n".$footer);
  9849. // update footer position
  9850. $this->footerpos[$this->page] += strlen($s."\n");
  9851. } else {
  9852. // set page data
  9853. $this->setPageBuffer($this->page, $s."\n", true);
  9854. }
  9855. } elseif ($this->state > 0) {
  9856. // set general data
  9857. $this->setBuffer($s."\n");
  9858. }
  9859. }
  9860. /**
  9861. * Set header font.
  9862. * @param $font (array) font
  9863. * @public
  9864. * @since 1.1
  9865. */
  9866. public function setHeaderFont($font) {
  9867. $this->header_font = $font;
  9868. }
  9869. /**
  9870. * Get header font.
  9871. * @return array()
  9872. * @public
  9873. * @since 4.0.012 (2008-07-24)
  9874. */
  9875. public function getHeaderFont() {
  9876. return $this->header_font;
  9877. }
  9878. /**
  9879. * Set footer font.
  9880. * @param $font (array) font
  9881. * @public
  9882. * @since 1.1
  9883. */
  9884. public function setFooterFont($font) {
  9885. $this->footer_font = $font;
  9886. }
  9887. /**
  9888. * Get Footer font.
  9889. * @return array()
  9890. * @public
  9891. * @since 4.0.012 (2008-07-24)
  9892. */
  9893. public function getFooterFont() {
  9894. return $this->footer_font;
  9895. }
  9896. /**
  9897. * Set language array.
  9898. * @param $language (array)
  9899. * @public
  9900. * @since 1.1
  9901. */
  9902. public function setLanguageArray($language) {
  9903. $this->l = $language;
  9904. if (isset($this->l['a_meta_dir'])) {
  9905. $this->rtl = $this->l['a_meta_dir']=='rtl' ? true : false;
  9906. } else {
  9907. $this->rtl = false;
  9908. }
  9909. }
  9910. /**
  9911. * Returns the PDF data.
  9912. * @public
  9913. */
  9914. public function getPDFData() {
  9915. if ($this->state < 3) {
  9916. $this->Close();
  9917. }
  9918. return $this->buffer;
  9919. }
  9920. /**
  9921. * Output anchor link.
  9922. * @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;)
  9923. * @param $name (string) link name
  9924. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  9925. * @param $firstline (boolean) if true prints only the first line and return the remaining string.
  9926. * @param $color (array) array of RGB text color
  9927. * @param $style (string) font style (U, D, B, I)
  9928. * @param $firstblock (boolean) if true the string is the starting of a line.
  9929. * @return the number of cells used or the remaining text if $firstline = true;
  9930. * @public
  9931. */
  9932. public function addHtmlLink($url, $name, $fill=false, $firstline=false, $color='', $style=-1, $firstblock=false) {
  9933. if (isset($url[1]) AND ($url[0] == '#') AND is_numeric($url[1])) {
  9934. // convert url to internal link
  9935. $lnkdata = explode(',', $url);
  9936. if (isset($lnkdata[0])) {
  9937. $page = intval(substr($lnkdata[0], 1));
  9938. if (empty($page) OR ($page <= 0)) {
  9939. $page = $this->page;
  9940. }
  9941. if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
  9942. $lnky = floatval($lnkdata[1]);
  9943. } else {
  9944. $lnky = 0;
  9945. }
  9946. $url = $this->AddLink();
  9947. $this->SetLink($url, $lnky, $page);
  9948. }
  9949. }
  9950. // store current settings
  9951. $prevcolor = $this->fgcolor;
  9952. $prevstyle = $this->FontStyle;
  9953. if (empty($color)) {
  9954. $this->SetTextColorArray($this->htmlLinkColorArray);
  9955. } else {
  9956. $this->SetTextColorArray($color);
  9957. }
  9958. if ($style == -1) {
  9959. $this->SetFont('', $this->FontStyle.$this->htmlLinkFontStyle);
  9960. } else {
  9961. $this->SetFont('', $this->FontStyle.$style);
  9962. }
  9963. $ret = $this->Write($this->lasth, $name, $url, $fill, '', false, 0, $firstline, $firstblock, 0);
  9964. // restore settings
  9965. $this->SetFont('', $prevstyle);
  9966. $this->SetTextColorArray($prevcolor);
  9967. return $ret;
  9968. }
  9969. /**
  9970. * Converts pixels to User's Units.
  9971. * @param $px (int) pixels
  9972. * @return float value in user's unit
  9973. * @public
  9974. * @see setImageScale(), getImageScale()
  9975. */
  9976. public function pixelsToUnits($px) {
  9977. return ($px / ($this->imgscale * $this->k));
  9978. }
  9979. /**
  9980. * Reverse function for htmlentities.
  9981. * Convert entities in UTF-8.
  9982. * @param $text_to_convert (string) Text to convert.
  9983. * @return string converted text string
  9984. * @public
  9985. */
  9986. public function unhtmlentities($text_to_convert) {
  9987. return @html_entity_decode($text_to_convert, ENT_QUOTES, $this->encoding);
  9988. }
  9989. // ENCRYPTION METHODS ----------------------------------
  9990. /**
  9991. * Compute encryption key depending on object number where the encrypted data is stored.
  9992. * This is used for all strings and streams without crypt filter specifier.
  9993. * @param $n (int) object number
  9994. * @return int object key
  9995. * @protected
  9996. * @author Nicola Asuni
  9997. * @since 2.0.000 (2008-01-02)
  9998. */
  9999. protected function _objectkey($n) {
  10000. $objkey = $this->encryptdata['key'].pack('VXxx', $n);
  10001. if ($this->encryptdata['mode'] == 2) { // AES-128
  10002. // AES padding
  10003. $objkey .= "\x73\x41\x6C\x54"; // sAlT
  10004. }
  10005. $objkey = substr(TCPDF_STATIC::_md5_16($objkey), 0, (($this->encryptdata['Length'] / 8) + 5));
  10006. $objkey = substr($objkey, 0, 16);
  10007. return $objkey;
  10008. }
  10009. /**
  10010. * Encrypt the input string.
  10011. * @param $n (int) object number
  10012. * @param $s (string) data string to encrypt
  10013. * @return encrypted string
  10014. * @protected
  10015. * @author Nicola Asuni
  10016. * @since 5.0.005 (2010-05-11)
  10017. */
  10018. protected function _encrypt_data($n, $s) {
  10019. if (!$this->encrypted) {
  10020. return $s;
  10021. }
  10022. switch ($this->encryptdata['mode']) {
  10023. case 0: // RC4-40
  10024. case 1: { // RC4-128
  10025. $s = TCPDF_STATIC::_RC4($this->_objectkey($n), $s, $this->last_enc_key, $this->last_enc_key_c);
  10026. break;
  10027. }
  10028. case 2: { // AES-128
  10029. $s = TCPDF_STATIC::_AES($this->_objectkey($n), $s);
  10030. break;
  10031. }
  10032. case 3: { // AES-256
  10033. $s = TCPDF_STATIC::_AES($this->encryptdata['key'], $s);
  10034. break;
  10035. }
  10036. }
  10037. return $s;
  10038. }
  10039. /**
  10040. * Put encryption on PDF document.
  10041. * @protected
  10042. * @author Nicola Asuni
  10043. * @since 2.0.000 (2008-01-02)
  10044. */
  10045. protected function _putencryption() {
  10046. if (!$this->encrypted) {
  10047. return;
  10048. }
  10049. $this->encryptdata['objid'] = $this->_newobj();
  10050. $out = '<<';
  10051. if (!isset($this->encryptdata['Filter']) OR empty($this->encryptdata['Filter'])) {
  10052. $this->encryptdata['Filter'] = 'Standard';
  10053. }
  10054. $out .= ' /Filter /'.$this->encryptdata['Filter'];
  10055. if (isset($this->encryptdata['SubFilter']) AND !empty($this->encryptdata['SubFilter'])) {
  10056. $out .= ' /SubFilter /'.$this->encryptdata['SubFilter'];
  10057. }
  10058. if (!isset($this->encryptdata['V']) OR empty($this->encryptdata['V'])) {
  10059. $this->encryptdata['V'] = 1;
  10060. }
  10061. // V is a code specifying the algorithm to be used in encrypting and decrypting the document
  10062. $out .= ' /V '.$this->encryptdata['V'];
  10063. if (isset($this->encryptdata['Length']) AND !empty($this->encryptdata['Length'])) {
  10064. // The length of the encryption key, in bits. The value shall be a multiple of 8, in the range 40 to 256
  10065. $out .= ' /Length '.$this->encryptdata['Length'];
  10066. } else {
  10067. $out .= ' /Length 40';
  10068. }
  10069. if ($this->encryptdata['V'] >= 4) {
  10070. if (!isset($this->encryptdata['StmF']) OR empty($this->encryptdata['StmF'])) {
  10071. $this->encryptdata['StmF'] = 'Identity';
  10072. }
  10073. if (!isset($this->encryptdata['StrF']) OR empty($this->encryptdata['StrF'])) {
  10074. // The name of the crypt filter that shall be used when decrypting all strings in the document.
  10075. $this->encryptdata['StrF'] = 'Identity';
  10076. }
  10077. // A dictionary whose keys shall be crypt filter names and whose values shall be the corresponding crypt filter dictionaries.
  10078. if (isset($this->encryptdata['CF']) AND !empty($this->encryptdata['CF'])) {
  10079. $out .= ' /CF <<';
  10080. $out .= ' /'.$this->encryptdata['StmF'].' <<';
  10081. $out .= ' /Type /CryptFilter';
  10082. if (isset($this->encryptdata['CF']['CFM']) AND !empty($this->encryptdata['CF']['CFM'])) {
  10083. // The method used
  10084. $out .= ' /CFM /'.$this->encryptdata['CF']['CFM'];
  10085. if ($this->encryptdata['pubkey']) {
  10086. $out .= ' /Recipients [';
  10087. foreach ($this->encryptdata['Recipients'] as $rec) {
  10088. $out .= ' <'.$rec.'>';
  10089. }
  10090. $out .= ' ]';
  10091. if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) {
  10092. $out .= ' /EncryptMetadata false';
  10093. } else {
  10094. $out .= ' /EncryptMetadata true';
  10095. }
  10096. }
  10097. } else {
  10098. $out .= ' /CFM /None';
  10099. }
  10100. if (isset($this->encryptdata['CF']['AuthEvent']) AND !empty($this->encryptdata['CF']['AuthEvent'])) {
  10101. // The event to be used to trigger the authorization that is required to access encryption keys used by this filter.
  10102. $out .= ' /AuthEvent /'.$this->encryptdata['CF']['AuthEvent'];
  10103. } else {
  10104. $out .= ' /AuthEvent /DocOpen';
  10105. }
  10106. if (isset($this->encryptdata['CF']['Length']) AND !empty($this->encryptdata['CF']['Length'])) {
  10107. // The bit length of the encryption key.
  10108. $out .= ' /Length '.$this->encryptdata['CF']['Length'];
  10109. }
  10110. $out .= ' >> >>';
  10111. }
  10112. // The name of the crypt filter that shall be used by default when decrypting streams.
  10113. $out .= ' /StmF /'.$this->encryptdata['StmF'];
  10114. // The name of the crypt filter that shall be used when decrypting all strings in the document.
  10115. $out .= ' /StrF /'.$this->encryptdata['StrF'];
  10116. if (isset($this->encryptdata['EFF']) AND !empty($this->encryptdata['EFF'])) {
  10117. // The name of the crypt filter that shall be used when encrypting embedded file streams that do not have their own crypt filter specifier.
  10118. $out .= ' /EFF /'.$this->encryptdata[''];
  10119. }
  10120. }
  10121. // Additional encryption dictionary entries for the standard security handler
  10122. if ($this->encryptdata['pubkey']) {
  10123. if (($this->encryptdata['V'] < 4) AND isset($this->encryptdata['Recipients']) AND !empty($this->encryptdata['Recipients'])) {
  10124. $out .= ' /Recipients [';
  10125. foreach ($this->encryptdata['Recipients'] as $rec) {
  10126. $out .= ' <'.$rec.'>';
  10127. }
  10128. $out .= ' ]';
  10129. }
  10130. } else {
  10131. $out .= ' /R';
  10132. if ($this->encryptdata['V'] == 5) { // AES-256
  10133. $out .= ' 5';
  10134. $out .= ' /OE ('.TCPDF_STATIC::_escape($this->encryptdata['OE']).')';
  10135. $out .= ' /UE ('.TCPDF_STATIC::_escape($this->encryptdata['UE']).')';
  10136. $out .= ' /Perms ('.TCPDF_STATIC::_escape($this->encryptdata['perms']).')';
  10137. } elseif ($this->encryptdata['V'] == 4) { // AES-128
  10138. $out .= ' 4';
  10139. } elseif ($this->encryptdata['V'] < 2) { // RC-40
  10140. $out .= ' 2';
  10141. } else { // RC-128
  10142. $out .= ' 3';
  10143. }
  10144. $out .= ' /O ('.TCPDF_STATIC::_escape($this->encryptdata['O']).')';
  10145. $out .= ' /U ('.TCPDF_STATIC::_escape($this->encryptdata['U']).')';
  10146. $out .= ' /P '.$this->encryptdata['P'];
  10147. if (isset($this->encryptdata['EncryptMetadata']) AND (!$this->encryptdata['EncryptMetadata'])) {
  10148. $out .= ' /EncryptMetadata false';
  10149. } else {
  10150. $out .= ' /EncryptMetadata true';
  10151. }
  10152. }
  10153. $out .= ' >>';
  10154. $out .= "\n".'endobj';
  10155. $this->_out($out);
  10156. }
  10157. /**
  10158. * Compute U value (used for encryption)
  10159. * @return string U value
  10160. * @protected
  10161. * @since 2.0.000 (2008-01-02)
  10162. * @author Nicola Asuni
  10163. */
  10164. protected function _Uvalue() {
  10165. if ($this->encryptdata['mode'] == 0) { // RC4-40
  10166. return TCPDF_STATIC::_RC4($this->encryptdata['key'], TCPDF_STATIC::$enc_padding, $this->last_enc_key, $this->last_enc_key_c);
  10167. } elseif ($this->encryptdata['mode'] < 3) { // RC4-128, AES-128
  10168. $tmp = TCPDF_STATIC::_md5_16(TCPDF_STATIC::$enc_padding.$this->encryptdata['fileid']);
  10169. $enc = TCPDF_STATIC::_RC4($this->encryptdata['key'], $tmp, $this->last_enc_key, $this->last_enc_key_c);
  10170. $len = strlen($tmp);
  10171. for ($i = 1; $i <= 19; ++$i) {
  10172. $ek = '';
  10173. for ($j = 0; $j < $len; ++$j) {
  10174. $ek .= chr(ord($this->encryptdata['key'][$j]) ^ $i);
  10175. }
  10176. $enc = TCPDF_STATIC::_RC4($ek, $enc, $this->last_enc_key, $this->last_enc_key_c);
  10177. }
  10178. $enc .= str_repeat("\x00", 16);
  10179. return substr($enc, 0, 32);
  10180. } elseif ($this->encryptdata['mode'] == 3) { // AES-256
  10181. $seed = TCPDF_STATIC::_md5_16(TCPDF_STATIC::getRandomSeed());
  10182. // User Validation Salt
  10183. $this->encryptdata['UVS'] = substr($seed, 0, 8);
  10184. // User Key Salt
  10185. $this->encryptdata['UKS'] = substr($seed, 8, 16);
  10186. return hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UVS'], true).$this->encryptdata['UVS'].$this->encryptdata['UKS'];
  10187. }
  10188. }
  10189. /**
  10190. * Compute UE value (used for encryption)
  10191. * @return string UE value
  10192. * @protected
  10193. * @since 5.9.006 (2010-10-19)
  10194. * @author Nicola Asuni
  10195. */
  10196. protected function _UEvalue() {
  10197. $hashkey = hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UKS'], true);
  10198. $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
  10199. return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $hashkey, $this->encryptdata['key'], MCRYPT_MODE_CBC, $iv);
  10200. }
  10201. /**
  10202. * Compute O value (used for encryption)
  10203. * @return string O value
  10204. * @protected
  10205. * @since 2.0.000 (2008-01-02)
  10206. * @author Nicola Asuni
  10207. */
  10208. protected function _Ovalue() {
  10209. if ($this->encryptdata['mode'] < 3) { // RC4-40, RC4-128, AES-128
  10210. $tmp = TCPDF_STATIC::_md5_16($this->encryptdata['owner_password']);
  10211. if ($this->encryptdata['mode'] > 0) {
  10212. for ($i = 0; $i < 50; ++$i) {
  10213. $tmp = TCPDF_STATIC::_md5_16($tmp);
  10214. }
  10215. }
  10216. $owner_key = substr($tmp, 0, ($this->encryptdata['Length'] / 8));
  10217. $enc = TCPDF_STATIC::_RC4($owner_key, $this->encryptdata['user_password'], $this->last_enc_key, $this->last_enc_key_c);
  10218. if ($this->encryptdata['mode'] > 0) {
  10219. $len = strlen($owner_key);
  10220. for ($i = 1; $i <= 19; ++$i) {
  10221. $ek = '';
  10222. for ($j = 0; $j < $len; ++$j) {
  10223. $ek .= chr(ord($owner_key[$j]) ^ $i);
  10224. }
  10225. $enc = TCPDF_STATIC::_RC4($ek, $enc, $this->last_enc_key, $this->last_enc_key_c);
  10226. }
  10227. }
  10228. return $enc;
  10229. } elseif ($this->encryptdata['mode'] == 3) { // AES-256
  10230. $seed = TCPDF_STATIC::_md5_16(TCPDF_STATIC::getRandomSeed());
  10231. // Owner Validation Salt
  10232. $this->encryptdata['OVS'] = substr($seed, 0, 8);
  10233. // Owner Key Salt
  10234. $this->encryptdata['OKS'] = substr($seed, 8, 16);
  10235. return hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OVS'].$this->encryptdata['U'], true).$this->encryptdata['OVS'].$this->encryptdata['OKS'];
  10236. }
  10237. }
  10238. /**
  10239. * Compute OE value (used for encryption)
  10240. * @return string OE value
  10241. * @protected
  10242. * @since 5.9.006 (2010-10-19)
  10243. * @author Nicola Asuni
  10244. */
  10245. protected function _OEvalue() {
  10246. $hashkey = hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OKS'].$this->encryptdata['U'], true);
  10247. $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
  10248. return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $hashkey, $this->encryptdata['key'], MCRYPT_MODE_CBC, $iv);
  10249. }
  10250. /**
  10251. * Convert password for AES-256 encryption mode
  10252. * @param $password (string) password
  10253. * @return string password
  10254. * @protected
  10255. * @since 5.9.006 (2010-10-19)
  10256. * @author Nicola Asuni
  10257. */
  10258. protected function _fixAES256Password($password) {
  10259. $psw = ''; // password to be returned
  10260. $psw_array = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($password, $this->isunicode, $this->CurrentFont), $password, $this->rtl, $this->isunicode, $this->CurrentFont);
  10261. foreach ($psw_array as $c) {
  10262. $psw .= TCPDF_FONTS::unichr($c, $this->isunicode);
  10263. }
  10264. return substr($psw, 0, 127);
  10265. }
  10266. /**
  10267. * Compute encryption key
  10268. * @protected
  10269. * @since 2.0.000 (2008-01-02)
  10270. * @author Nicola Asuni
  10271. */
  10272. protected function _generateencryptionkey() {
  10273. $keybytelen = ($this->encryptdata['Length'] / 8);
  10274. if (!$this->encryptdata['pubkey']) { // standard mode
  10275. if ($this->encryptdata['mode'] == 3) { // AES-256
  10276. // generate 256 bit random key
  10277. $this->encryptdata['key'] = substr(hash('sha256', TCPDF_STATIC::getRandomSeed(), true), 0, $keybytelen);
  10278. // truncate passwords
  10279. $this->encryptdata['user_password'] = $this->_fixAES256Password($this->encryptdata['user_password']);
  10280. $this->encryptdata['owner_password'] = $this->_fixAES256Password($this->encryptdata['owner_password']);
  10281. // Compute U value
  10282. $this->encryptdata['U'] = $this->_Uvalue();
  10283. // Compute UE value
  10284. $this->encryptdata['UE'] = $this->_UEvalue();
  10285. // Compute O value
  10286. $this->encryptdata['O'] = $this->_Ovalue();
  10287. // Compute OE value
  10288. $this->encryptdata['OE'] = $this->_OEvalue();
  10289. // Compute P value
  10290. $this->encryptdata['P'] = $this->encryptdata['protection'];
  10291. // Computing the encryption dictionary's Perms (permissions) value
  10292. $perms = TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']); // bytes 0-3
  10293. $perms .= chr(255).chr(255).chr(255).chr(255); // bytes 4-7
  10294. if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) { // byte 8
  10295. $perms .= 'F';
  10296. } else {
  10297. $perms .= 'T';
  10298. }
  10299. $perms .= 'adb'; // bytes 9-11
  10300. $perms .= 'nick'; // bytes 12-15
  10301. $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB));
  10302. $this->encryptdata['perms'] = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->encryptdata['key'], $perms, MCRYPT_MODE_ECB, $iv);
  10303. } else { // RC4-40, RC4-128, AES-128
  10304. // Pad passwords
  10305. $this->encryptdata['user_password'] = substr($this->encryptdata['user_password'].TCPDF_STATIC::$enc_padding, 0, 32);
  10306. $this->encryptdata['owner_password'] = substr($this->encryptdata['owner_password'].TCPDF_STATIC::$enc_padding, 0, 32);
  10307. // Compute O value
  10308. $this->encryptdata['O'] = $this->_Ovalue();
  10309. // get default permissions (reverse byte order)
  10310. $permissions = TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']);
  10311. // Compute encryption key
  10312. $tmp = TCPDF_STATIC::_md5_16($this->encryptdata['user_password'].$this->encryptdata['O'].$permissions.$this->encryptdata['fileid']);
  10313. if ($this->encryptdata['mode'] > 0) {
  10314. for ($i = 0; $i < 50; ++$i) {
  10315. $tmp = TCPDF_STATIC::_md5_16(substr($tmp, 0, $keybytelen));
  10316. }
  10317. }
  10318. $this->encryptdata['key'] = substr($tmp, 0, $keybytelen);
  10319. // Compute U value
  10320. $this->encryptdata['U'] = $this->_Uvalue();
  10321. // Compute P value
  10322. $this->encryptdata['P'] = $this->encryptdata['protection'];
  10323. }
  10324. } else { // Public-Key mode
  10325. // random 20-byte seed
  10326. $seed = sha1(TCPDF_STATIC::getRandomSeed(), true);
  10327. $recipient_bytes = '';
  10328. foreach ($this->encryptdata['pubkeys'] as $pubkey) {
  10329. // for each public certificate
  10330. if (isset($pubkey['p'])) {
  10331. $pkprotection = TCPDF_STATIC::getUserPermissionCode($pubkey['p'], $this->encryptdata['mode']);
  10332. } else {
  10333. $pkprotection = $this->encryptdata['protection'];
  10334. }
  10335. // get default permissions (reverse byte order)
  10336. $pkpermissions = TCPDF_STATIC::getEncPermissionsString($pkprotection);
  10337. // envelope data
  10338. $envelope = $seed.$pkpermissions;
  10339. // write the envelope data to a temporary file
  10340. $tempkeyfile = TCPDF_STATIC::getObjFilename('key');
  10341. $f = fopen($tempkeyfile, 'wb');
  10342. if (!$f) {
  10343. $this->Error('Unable to create temporary key file: '.$tempkeyfile);
  10344. }
  10345. $envelope_length = strlen($envelope);
  10346. fwrite($f, $envelope, $envelope_length);
  10347. fclose($f);
  10348. $tempencfile = TCPDF_STATIC::getObjFilename('enc');
  10349. if (!openssl_pkcs7_encrypt($tempkeyfile, $tempencfile, $pubkey['c'], array(), PKCS7_BINARY | PKCS7_DETACHED)) {
  10350. $this->Error('Unable to encrypt the file: '.$tempkeyfile);
  10351. }
  10352. unlink($tempkeyfile);
  10353. // read encryption signature
  10354. $signature = file_get_contents($tempencfile, false, null, $envelope_length);
  10355. unlink($tempencfile);
  10356. // extract signature
  10357. $signature = substr($signature, strpos($signature, 'Content-Disposition'));
  10358. $tmparr = explode("\n\n", $signature);
  10359. $signature = trim($tmparr[1]);
  10360. unset($tmparr);
  10361. // decode signature
  10362. $signature = base64_decode($signature);
  10363. // convert signature to hex
  10364. $hexsignature = current(unpack('H*', $signature));
  10365. // store signature on recipients array
  10366. $this->encryptdata['Recipients'][] = $hexsignature;
  10367. // The bytes of each item in the Recipients array of PKCS#7 objects in the order in which they appear in the array
  10368. $recipient_bytes .= $signature;
  10369. }
  10370. // calculate encryption key
  10371. if ($this->encryptdata['mode'] == 3) { // AES-256
  10372. $this->encryptdata['key'] = substr(hash('sha256', $seed.$recipient_bytes, true), 0, $keybytelen);
  10373. } else { // RC4-40, RC4-128, AES-128
  10374. $this->encryptdata['key'] = substr(sha1($seed.$recipient_bytes, true), 0, $keybytelen);
  10375. }
  10376. }
  10377. }
  10378. /**
  10379. * Set document protection
  10380. * Remark: the protection against modification is for people who have the full Acrobat product.
  10381. * 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.
  10382. * 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.
  10383. * @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>
  10384. * @param $user_pass (String) user password. Empty by default.
  10385. * @param $owner_pass (String) owner password. If not specified, a random value is used.
  10386. * @param $mode (int) encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
  10387. * @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')))
  10388. * @public
  10389. * @since 2.0.000 (2008-01-02)
  10390. * @author Nicola Asuni
  10391. */
  10392. 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) {
  10393. if ($this->pdfa_mode) {
  10394. // encryption is not allowed in PDF/A mode
  10395. return;
  10396. }
  10397. $this->encryptdata['protection'] = TCPDF_STATIC::getUserPermissionCode($permissions, $mode);
  10398. if (($pubkeys !== null) AND (is_array($pubkeys))) {
  10399. // public-key mode
  10400. $this->encryptdata['pubkeys'] = $pubkeys;
  10401. if ($mode == 0) {
  10402. // public-Key Security requires at least 128 bit
  10403. $mode = 1;
  10404. }
  10405. if (!function_exists('openssl_pkcs7_encrypt')) {
  10406. $this->Error('Public-Key Security requires openssl library.');
  10407. }
  10408. // Set Public-Key filter (availabe are: Entrust.PPKEF, Adobe.PPKLite, Adobe.PubSec)
  10409. $this->encryptdata['pubkey'] = true;
  10410. $this->encryptdata['Filter'] = 'Adobe.PubSec';
  10411. $this->encryptdata['StmF'] = 'DefaultCryptFilter';
  10412. $this->encryptdata['StrF'] = 'DefaultCryptFilter';
  10413. } else {
  10414. // standard mode (password mode)
  10415. $this->encryptdata['pubkey'] = false;
  10416. $this->encryptdata['Filter'] = 'Standard';
  10417. $this->encryptdata['StmF'] = 'StdCF';
  10418. $this->encryptdata['StrF'] = 'StdCF';
  10419. }
  10420. if ($mode > 1) { // AES
  10421. if (!extension_loaded('mcrypt')) {
  10422. $this->Error('AES encryption requires mcrypt library (http://www.php.net/manual/en/mcrypt.requirements.php).');
  10423. }
  10424. if (mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128) === false) {
  10425. $this->Error('AES encryption requires MCRYPT_RIJNDAEL_128 cypher.');
  10426. }
  10427. if (($mode == 3) AND !function_exists('hash')) {
  10428. // the Hash extension requires no external libraries and is enabled by default as of PHP 5.1.2.
  10429. $this->Error('AES 256 encryption requires HASH Message Digest Framework (http://www.php.net/manual/en/book.hash.php).');
  10430. }
  10431. }
  10432. if ($owner_pass === null) {
  10433. $owner_pass = md5(TCPDF_STATIC::getRandomSeed());
  10434. }
  10435. $this->encryptdata['user_password'] = $user_pass;
  10436. $this->encryptdata['owner_password'] = $owner_pass;
  10437. $this->encryptdata['mode'] = $mode;
  10438. switch ($mode) {
  10439. case 0: { // RC4 40 bit
  10440. $this->encryptdata['V'] = 1;
  10441. $this->encryptdata['Length'] = 40;
  10442. $this->encryptdata['CF']['CFM'] = 'V2';
  10443. break;
  10444. }
  10445. case 1: { // RC4 128 bit
  10446. $this->encryptdata['V'] = 2;
  10447. $this->encryptdata['Length'] = 128;
  10448. $this->encryptdata['CF']['CFM'] = 'V2';
  10449. if ($this->encryptdata['pubkey']) {
  10450. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s4';
  10451. $this->encryptdata['Recipients'] = array();
  10452. }
  10453. break;
  10454. }
  10455. case 2: { // AES 128 bit
  10456. $this->encryptdata['V'] = 4;
  10457. $this->encryptdata['Length'] = 128;
  10458. $this->encryptdata['CF']['CFM'] = 'AESV2';
  10459. $this->encryptdata['CF']['Length'] = 128;
  10460. if ($this->encryptdata['pubkey']) {
  10461. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  10462. $this->encryptdata['Recipients'] = array();
  10463. }
  10464. break;
  10465. }
  10466. case 3: { // AES 256 bit
  10467. $this->encryptdata['V'] = 5;
  10468. $this->encryptdata['Length'] = 256;
  10469. $this->encryptdata['CF']['CFM'] = 'AESV3';
  10470. $this->encryptdata['CF']['Length'] = 256;
  10471. if ($this->encryptdata['pubkey']) {
  10472. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  10473. $this->encryptdata['Recipients'] = array();
  10474. }
  10475. break;
  10476. }
  10477. }
  10478. $this->encrypted = true;
  10479. $this->encryptdata['fileid'] = TCPDF_STATIC::convertHexStringToString($this->file_id);
  10480. $this->_generateencryptionkey();
  10481. }
  10482. // END OF ENCRYPTION FUNCTIONS -------------------------
  10483. // START TRANSFORMATIONS SECTION -----------------------
  10484. /**
  10485. * Starts a 2D tranformation saving current graphic state.
  10486. * This function must be called before scaling, mirroring, translation, rotation and skewing.
  10487. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  10488. * @public
  10489. * @since 2.1.000 (2008-01-07)
  10490. * @see StartTransform(), StopTransform()
  10491. */
  10492. public function StartTransform() {
  10493. if ($this->state != 2) {
  10494. return;
  10495. }
  10496. $this->_out('q');
  10497. if ($this->inxobj) {
  10498. // we are inside an XObject template
  10499. $this->xobjects[$this->xobjid]['transfmrk'][] = strlen($this->xobjects[$this->xobjid]['outdata']);
  10500. } else {
  10501. $this->transfmrk[$this->page][] = $this->pagelen[$this->page];
  10502. }
  10503. ++$this->transfmatrix_key;
  10504. $this->transfmatrix[$this->transfmatrix_key] = array();
  10505. }
  10506. /**
  10507. * Stops a 2D tranformation restoring previous graphic state.
  10508. * This function must be called after scaling, mirroring, translation, rotation and skewing.
  10509. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  10510. * @public
  10511. * @since 2.1.000 (2008-01-07)
  10512. * @see StartTransform(), StopTransform()
  10513. */
  10514. public function StopTransform() {
  10515. if ($this->state != 2) {
  10516. return;
  10517. }
  10518. $this->_out('Q');
  10519. if (isset($this->transfmatrix[$this->transfmatrix_key])) {
  10520. array_pop($this->transfmatrix[$this->transfmatrix_key]);
  10521. --$this->transfmatrix_key;
  10522. }
  10523. if ($this->inxobj) {
  10524. // we are inside an XObject template
  10525. array_pop($this->xobjects[$this->xobjid]['transfmrk']);
  10526. } else {
  10527. array_pop($this->transfmrk[$this->page]);
  10528. }
  10529. }
  10530. /**
  10531. * Horizontal Scaling.
  10532. * @param $s_x (float) scaling factor for width as percent. 0 is not allowed.
  10533. * @param $x (int) abscissa of the scaling center. Default is current x position
  10534. * @param $y (int) ordinate of the scaling center. Default is current y position
  10535. * @public
  10536. * @since 2.1.000 (2008-01-07)
  10537. * @see StartTransform(), StopTransform()
  10538. */
  10539. public function ScaleX($s_x, $x='', $y='') {
  10540. $this->Scale($s_x, 100, $x, $y);
  10541. }
  10542. /**
  10543. * Vertical Scaling.
  10544. * @param $s_y (float) scaling factor for height as percent. 0 is not allowed.
  10545. * @param $x (int) abscissa of the scaling center. Default is current x position
  10546. * @param $y (int) ordinate of the scaling center. Default is current y position
  10547. * @public
  10548. * @since 2.1.000 (2008-01-07)
  10549. * @see StartTransform(), StopTransform()
  10550. */
  10551. public function ScaleY($s_y, $x='', $y='') {
  10552. $this->Scale(100, $s_y, $x, $y);
  10553. }
  10554. /**
  10555. * Vertical and horizontal proportional Scaling.
  10556. * @param $s (float) scaling factor for width and height as percent. 0 is not allowed.
  10557. * @param $x (int) abscissa of the scaling center. Default is current x position
  10558. * @param $y (int) ordinate of the scaling center. Default is current y position
  10559. * @public
  10560. * @since 2.1.000 (2008-01-07)
  10561. * @see StartTransform(), StopTransform()
  10562. */
  10563. public function ScaleXY($s, $x='', $y='') {
  10564. $this->Scale($s, $s, $x, $y);
  10565. }
  10566. /**
  10567. * Vertical and horizontal non-proportional Scaling.
  10568. * @param $s_x (float) scaling factor for width as percent. 0 is not allowed.
  10569. * @param $s_y (float) scaling factor for height as percent. 0 is not allowed.
  10570. * @param $x (int) abscissa of the scaling center. Default is current x position
  10571. * @param $y (int) ordinate of the scaling center. Default is current y position
  10572. * @public
  10573. * @since 2.1.000 (2008-01-07)
  10574. * @see StartTransform(), StopTransform()
  10575. */
  10576. public function Scale($s_x, $s_y, $x='', $y='') {
  10577. if ($x === '') {
  10578. $x = $this->x;
  10579. }
  10580. if ($y === '') {
  10581. $y = $this->y;
  10582. }
  10583. if (($s_x == 0) OR ($s_y == 0)) {
  10584. $this->Error('Please do not use values equal to zero for scaling');
  10585. }
  10586. $y = ($this->h - $y) * $this->k;
  10587. $x *= $this->k;
  10588. //calculate elements of transformation matrix
  10589. $s_x /= 100;
  10590. $s_y /= 100;
  10591. $tm = array();
  10592. $tm[0] = $s_x;
  10593. $tm[1] = 0;
  10594. $tm[2] = 0;
  10595. $tm[3] = $s_y;
  10596. $tm[4] = $x * (1 - $s_x);
  10597. $tm[5] = $y * (1 - $s_y);
  10598. //scale the coordinate system
  10599. $this->Transform($tm);
  10600. }
  10601. /**
  10602. * Horizontal Mirroring.
  10603. * @param $x (int) abscissa of the point. Default is current x position
  10604. * @public
  10605. * @since 2.1.000 (2008-01-07)
  10606. * @see StartTransform(), StopTransform()
  10607. */
  10608. public function MirrorH($x='') {
  10609. $this->Scale(-100, 100, $x);
  10610. }
  10611. /**
  10612. * Verical Mirroring.
  10613. * @param $y (int) ordinate of the point. Default is current y position
  10614. * @public
  10615. * @since 2.1.000 (2008-01-07)
  10616. * @see StartTransform(), StopTransform()
  10617. */
  10618. public function MirrorV($y='') {
  10619. $this->Scale(100, -100, '', $y);
  10620. }
  10621. /**
  10622. * Point reflection mirroring.
  10623. * @param $x (int) abscissa of the point. Default is current x position
  10624. * @param $y (int) ordinate of the point. Default is current y position
  10625. * @public
  10626. * @since 2.1.000 (2008-01-07)
  10627. * @see StartTransform(), StopTransform()
  10628. */
  10629. public function MirrorP($x='',$y='') {
  10630. $this->Scale(-100, -100, $x, $y);
  10631. }
  10632. /**
  10633. * Reflection against a straight line through point (x, y) with the gradient angle (angle).
  10634. * @param $angle (float) gradient angle of the straight line. Default is 0 (horizontal line).
  10635. * @param $x (int) abscissa of the point. Default is current x position
  10636. * @param $y (int) ordinate of the point. Default is current y position
  10637. * @public
  10638. * @since 2.1.000 (2008-01-07)
  10639. * @see StartTransform(), StopTransform()
  10640. */
  10641. public function MirrorL($angle=0, $x='',$y='') {
  10642. $this->Scale(-100, 100, $x, $y);
  10643. $this->Rotate(-2*($angle-90), $x, $y);
  10644. }
  10645. /**
  10646. * Translate graphic object horizontally.
  10647. * @param $t_x (int) movement to the right (or left for RTL)
  10648. * @public
  10649. * @since 2.1.000 (2008-01-07)
  10650. * @see StartTransform(), StopTransform()
  10651. */
  10652. public function TranslateX($t_x) {
  10653. $this->Translate($t_x, 0);
  10654. }
  10655. /**
  10656. * Translate graphic object vertically.
  10657. * @param $t_y (int) movement to the bottom
  10658. * @public
  10659. * @since 2.1.000 (2008-01-07)
  10660. * @see StartTransform(), StopTransform()
  10661. */
  10662. public function TranslateY($t_y) {
  10663. $this->Translate(0, $t_y);
  10664. }
  10665. /**
  10666. * Translate graphic object horizontally and vertically.
  10667. * @param $t_x (int) movement to the right
  10668. * @param $t_y (int) movement to the bottom
  10669. * @public
  10670. * @since 2.1.000 (2008-01-07)
  10671. * @see StartTransform(), StopTransform()
  10672. */
  10673. public function Translate($t_x, $t_y) {
  10674. //calculate elements of transformation matrix
  10675. $tm = array();
  10676. $tm[0] = 1;
  10677. $tm[1] = 0;
  10678. $tm[2] = 0;
  10679. $tm[3] = 1;
  10680. $tm[4] = $t_x * $this->k;
  10681. $tm[5] = -$t_y * $this->k;
  10682. //translate the coordinate system
  10683. $this->Transform($tm);
  10684. }
  10685. /**
  10686. * Rotate object.
  10687. * @param $angle (float) angle in degrees for counter-clockwise rotation
  10688. * @param $x (int) abscissa of the rotation center. Default is current x position
  10689. * @param $y (int) ordinate of the rotation center. Default is current y position
  10690. * @public
  10691. * @since 2.1.000 (2008-01-07)
  10692. * @see StartTransform(), StopTransform()
  10693. */
  10694. public function Rotate($angle, $x='', $y='') {
  10695. if ($x === '') {
  10696. $x = $this->x;
  10697. }
  10698. if ($y === '') {
  10699. $y = $this->y;
  10700. }
  10701. $y = ($this->h - $y) * $this->k;
  10702. $x *= $this->k;
  10703. //calculate elements of transformation matrix
  10704. $tm = array();
  10705. $tm[0] = cos(deg2rad($angle));
  10706. $tm[1] = sin(deg2rad($angle));
  10707. $tm[2] = -$tm[1];
  10708. $tm[3] = $tm[0];
  10709. $tm[4] = $x + ($tm[1] * $y) - ($tm[0] * $x);
  10710. $tm[5] = $y - ($tm[0] * $y) - ($tm[1] * $x);
  10711. //rotate the coordinate system around ($x,$y)
  10712. $this->Transform($tm);
  10713. }
  10714. /**
  10715. * Skew horizontally.
  10716. * @param $angle_x (float) angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  10717. * @param $x (int) abscissa of the skewing center. default is current x position
  10718. * @param $y (int) ordinate of the skewing center. default is current y position
  10719. * @public
  10720. * @since 2.1.000 (2008-01-07)
  10721. * @see StartTransform(), StopTransform()
  10722. */
  10723. public function SkewX($angle_x, $x='', $y='') {
  10724. $this->Skew($angle_x, 0, $x, $y);
  10725. }
  10726. /**
  10727. * Skew vertically.
  10728. * @param $angle_y (float) angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  10729. * @param $x (int) abscissa of the skewing center. default is current x position
  10730. * @param $y (int) ordinate of the skewing center. default is current y position
  10731. * @public
  10732. * @since 2.1.000 (2008-01-07)
  10733. * @see StartTransform(), StopTransform()
  10734. */
  10735. public function SkewY($angle_y, $x='', $y='') {
  10736. $this->Skew(0, $angle_y, $x, $y);
  10737. }
  10738. /**
  10739. * Skew.
  10740. * @param $angle_x (float) angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  10741. * @param $angle_y (float) angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  10742. * @param $x (int) abscissa of the skewing center. default is current x position
  10743. * @param $y (int) ordinate of the skewing center. default is current y position
  10744. * @public
  10745. * @since 2.1.000 (2008-01-07)
  10746. * @see StartTransform(), StopTransform()
  10747. */
  10748. public function Skew($angle_x, $angle_y, $x='', $y='') {
  10749. if ($x === '') {
  10750. $x = $this->x;
  10751. }
  10752. if ($y === '') {
  10753. $y = $this->y;
  10754. }
  10755. if (($angle_x <= -90) OR ($angle_x >= 90) OR ($angle_y <= -90) OR ($angle_y >= 90)) {
  10756. $this->Error('Please use values between -90 and +90 degrees for Skewing.');
  10757. }
  10758. $x *= $this->k;
  10759. $y = ($this->h - $y) * $this->k;
  10760. //calculate elements of transformation matrix
  10761. $tm = array();
  10762. $tm[0] = 1;
  10763. $tm[1] = tan(deg2rad($angle_y));
  10764. $tm[2] = tan(deg2rad($angle_x));
  10765. $tm[3] = 1;
  10766. $tm[4] = -$tm[2] * $y;
  10767. $tm[5] = -$tm[1] * $x;
  10768. //skew the coordinate system
  10769. $this->Transform($tm);
  10770. }
  10771. /**
  10772. * Apply graphic transformations.
  10773. * @param $tm (array) transformation matrix
  10774. * @protected
  10775. * @since 2.1.000 (2008-01-07)
  10776. * @see StartTransform(), StopTransform()
  10777. */
  10778. protected function Transform($tm) {
  10779. if ($this->state != 2) {
  10780. return;
  10781. }
  10782. $this->_out(sprintf('%F %F %F %F %F %F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
  10783. // add tranformation matrix
  10784. $this->transfmatrix[$this->transfmatrix_key][] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]);
  10785. // update transformation mark
  10786. if ($this->inxobj) {
  10787. // we are inside an XObject template
  10788. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  10789. $key = key($this->xobjects[$this->xobjid]['transfmrk']);
  10790. $this->xobjects[$this->xobjid]['transfmrk'][$key] = strlen($this->xobjects[$this->xobjid]['outdata']);
  10791. }
  10792. } elseif (end($this->transfmrk[$this->page]) !== false) {
  10793. $key = key($this->transfmrk[$this->page]);
  10794. $this->transfmrk[$this->page][$key] = $this->pagelen[$this->page];
  10795. }
  10796. }
  10797. // END TRANSFORMATIONS SECTION -------------------------
  10798. // START GRAPHIC FUNCTIONS SECTION ---------------------
  10799. // The following section is based on the code provided by David Hernandez Sanz
  10800. /**
  10801. * 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.
  10802. * @param $width (float) The width.
  10803. * @public
  10804. * @since 1.0
  10805. * @see Line(), Rect(), Cell(), MultiCell()
  10806. */
  10807. public function SetLineWidth($width) {
  10808. //Set line width
  10809. $this->LineWidth = $width;
  10810. $this->linestyleWidth = sprintf('%F w', ($width * $this->k));
  10811. if ($this->state == 2) {
  10812. $this->_out($this->linestyleWidth);
  10813. }
  10814. }
  10815. /**
  10816. * Returns the current the line width.
  10817. * @return int Line width
  10818. * @public
  10819. * @since 2.1.000 (2008-01-07)
  10820. * @see Line(), SetLineWidth()
  10821. */
  10822. public function GetLineWidth() {
  10823. return $this->LineWidth;
  10824. }
  10825. /**
  10826. * Set line style.
  10827. * @param $style (array) Line style. Array with keys among the following:
  10828. * <ul>
  10829. * <li>width (float): Width of the line in user units.</li>
  10830. * <li>cap (string): Type of cap to put on the line. Possible values are:
  10831. * butt, round, square. The difference between "square" and "butt" is that
  10832. * "square" projects a flat end past the end of the line.</li>
  10833. * <li>join (string): Type of join. Possible values are: miter, round,
  10834. * bevel.</li>
  10835. * <li>dash (mixed): Dash pattern. Is 0 (without dash) or string with
  10836. * series of length values, which are the lengths of the on and off dashes.
  10837. * For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
  10838. * 1 off, 2 on, 1 off, ...</li>
  10839. * <li>phase (integer): Modifier on the dash pattern which is used to shift
  10840. * the point at which the pattern starts.</li>
  10841. * <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>
  10842. * </ul>
  10843. * @param $ret (boolean) if true do not send the command.
  10844. * @return string the PDF command
  10845. * @public
  10846. * @since 2.1.000 (2008-01-08)
  10847. */
  10848. public function SetLineStyle($style, $ret=false) {
  10849. $s = ''; // string to be returned
  10850. if (!is_array($style)) {
  10851. return;
  10852. }
  10853. if (isset($style['width'])) {
  10854. $this->LineWidth = $style['width'];
  10855. $this->linestyleWidth = sprintf('%F w', ($style['width'] * $this->k));
  10856. $s .= $this->linestyleWidth.' ';
  10857. }
  10858. if (isset($style['cap'])) {
  10859. $ca = array('butt' => 0, 'round'=> 1, 'square' => 2);
  10860. if (isset($ca[$style['cap']])) {
  10861. $this->linestyleCap = $ca[$style['cap']].' J';
  10862. $s .= $this->linestyleCap.' ';
  10863. }
  10864. }
  10865. if (isset($style['join'])) {
  10866. $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2);
  10867. if (isset($ja[$style['join']])) {
  10868. $this->linestyleJoin = $ja[$style['join']].' j';
  10869. $s .= $this->linestyleJoin.' ';
  10870. }
  10871. }
  10872. if (isset($style['dash'])) {
  10873. $dash_string = '';
  10874. if ($style['dash']) {
  10875. if (preg_match('/^.+,/', $style['dash']) > 0) {
  10876. $tab = explode(',', $style['dash']);
  10877. } else {
  10878. $tab = array($style['dash']);
  10879. }
  10880. $dash_string = '';
  10881. foreach ($tab as $i => $v) {
  10882. if ($i) {
  10883. $dash_string .= ' ';
  10884. }
  10885. $dash_string .= sprintf('%F', $v);
  10886. }
  10887. }
  10888. if (!isset($style['phase']) OR !$style['dash']) {
  10889. $style['phase'] = 0;
  10890. }
  10891. $this->linestyleDash = sprintf('[%s] %F d', $dash_string, $style['phase']);
  10892. $s .= $this->linestyleDash.' ';
  10893. }
  10894. if (isset($style['color'])) {
  10895. $s .= $this->SetDrawColorArray($style['color'], true).' ';
  10896. }
  10897. if (!$ret AND ($this->state == 2)) {
  10898. $this->_out($s);
  10899. }
  10900. return $s;
  10901. }
  10902. /**
  10903. * Begin a new subpath by moving the current point to coordinates (x, y), omitting any connecting line segment.
  10904. * @param $x (float) Abscissa of point.
  10905. * @param $y (float) Ordinate of point.
  10906. * @protected
  10907. * @since 2.1.000 (2008-01-08)
  10908. */
  10909. protected function _outPoint($x, $y) {
  10910. if ($this->state == 2) {
  10911. $this->_out(sprintf('%F %F m', ($x * $this->k), (($this->h - $y) * $this->k)));
  10912. }
  10913. }
  10914. /**
  10915. * Append a straight line segment from the current point to the point (x, y).
  10916. * The new current point shall be (x, y).
  10917. * @param $x (float) Abscissa of end point.
  10918. * @param $y (float) Ordinate of end point.
  10919. * @protected
  10920. * @since 2.1.000 (2008-01-08)
  10921. */
  10922. protected function _outLine($x, $y) {
  10923. if ($this->state == 2) {
  10924. $this->_out(sprintf('%F %F l', ($x * $this->k), (($this->h - $y) * $this->k)));
  10925. }
  10926. }
  10927. /**
  10928. * Append a rectangle to the current path as a complete subpath, with lower-left corner (x, y) and dimensions widthand height in user space.
  10929. * @param $x (float) Abscissa of upper-left corner.
  10930. * @param $y (float) Ordinate of upper-left corner.
  10931. * @param $w (float) Width.
  10932. * @param $h (float) Height.
  10933. * @param $op (string) options
  10934. * @protected
  10935. * @since 2.1.000 (2008-01-08)
  10936. */
  10937. protected function _outRect($x, $y, $w, $h, $op) {
  10938. if ($this->state == 2) {
  10939. $this->_out(sprintf('%F %F %F %F re %s', ($x * $this->k), (($this->h - $y) * $this->k), ($w * $this->k), (-$h * $this->k), $op));
  10940. }
  10941. }
  10942. /**
  10943. * Append a cubic B\E9zier 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 B\E9zier control points.
  10944. * The new current point shall be (x3, y3).
  10945. * @param $x1 (float) Abscissa of control point 1.
  10946. * @param $y1 (float) Ordinate of control point 1.
  10947. * @param $x2 (float) Abscissa of control point 2.
  10948. * @param $y2 (float) Ordinate of control point 2.
  10949. * @param $x3 (float) Abscissa of end point.
  10950. * @param $y3 (float) Ordinate of end point.
  10951. * @protected
  10952. * @since 2.1.000 (2008-01-08)
  10953. */
  10954. protected function _outCurve($x1, $y1, $x2, $y2, $x3, $y3) {
  10955. if ($this->state == 2) {
  10956. $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)));
  10957. }
  10958. }
  10959. /**
  10960. * Append a cubic B\E9zier 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 B\E9zier control points.
  10961. * The new current point shall be (x3, y3).
  10962. * @param $x2 (float) Abscissa of control point 2.
  10963. * @param $y2 (float) Ordinate of control point 2.
  10964. * @param $x3 (float) Abscissa of end point.
  10965. * @param $y3 (float) Ordinate of end point.
  10966. * @protected
  10967. * @since 4.9.019 (2010-04-26)
  10968. */
  10969. protected function _outCurveV($x2, $y2, $x3, $y3) {
  10970. if ($this->state == 2) {
  10971. $this->_out(sprintf('%F %F %F %F v', ($x2 * $this->k), (($this->h - $y2) * $this->k), ($x3 * $this->k), (($this->h - $y3) * $this->k)));
  10972. }
  10973. }
  10974. /**
  10975. * Append a cubic B\E9zier 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 B\E9zier control points.
  10976. * The new current point shall be (x3, y3).
  10977. * @param $x1 (float) Abscissa of control point 1.
  10978. * @param $y1 (float) Ordinate of control point 1.
  10979. * @param $x3 (float) Abscissa of end point.
  10980. * @param $y3 (float) Ordinate of end point.
  10981. * @protected
  10982. * @since 2.1.000 (2008-01-08)
  10983. */
  10984. protected function _outCurveY($x1, $y1, $x3, $y3) {
  10985. if ($this->state == 2) {
  10986. $this->_out(sprintf('%F %F %F %F y', ($x1 * $this->k), (($this->h - $y1) * $this->k), ($x3 * $this->k), (($this->h - $y3) * $this->k)));
  10987. }
  10988. }
  10989. /**
  10990. * Draws a line between two points.
  10991. * @param $x1 (float) Abscissa of first point.
  10992. * @param $y1 (float) Ordinate of first point.
  10993. * @param $x2 (float) Abscissa of second point.
  10994. * @param $y2 (float) Ordinate of second point.
  10995. * @param $style (array) Line style. Array like for SetLineStyle(). Default value: default line style (empty array).
  10996. * @public
  10997. * @since 1.0
  10998. * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
  10999. */
  11000. public function Line($x1, $y1, $x2, $y2, $style=array()) {
  11001. if ($this->state != 2) {
  11002. return;
  11003. }
  11004. if (is_array($style)) {
  11005. $this->SetLineStyle($style);
  11006. }
  11007. $this->_outPoint($x1, $y1);
  11008. $this->_outLine($x2, $y2);
  11009. $this->_out('S');
  11010. }
  11011. /**
  11012. * Draws a rectangle.
  11013. * @param $x (float) Abscissa of upper-left corner.
  11014. * @param $y (float) Ordinate of upper-left corner.
  11015. * @param $w (float) Width.
  11016. * @param $h (float) Height.
  11017. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11018. * @param $border_style (array) Border style of rectangle. Array with keys among the following:
  11019. * <ul>
  11020. * <li>all: Line style of all borders. Array like for SetLineStyle().</li>
  11021. * <li>L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for SetLineStyle().</li>
  11022. * </ul>
  11023. * If a key is not present or is null, the correspondent border is not drawn. Default value: default line style (empty array).
  11024. * @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).
  11025. * @public
  11026. * @since 1.0
  11027. * @see SetLineStyle()
  11028. */
  11029. public function Rect($x, $y, $w, $h, $style='', $border_style=array(), $fill_color=array()) {
  11030. if ($this->state != 2) {
  11031. return;
  11032. }
  11033. if (empty($style)) {
  11034. $style = 'S';
  11035. }
  11036. if (!(strpos($style, 'F') === false) AND !empty($fill_color)) {
  11037. // set background color
  11038. $this->SetFillColorArray($fill_color);
  11039. }
  11040. if (!empty($border_style)) {
  11041. if (isset($border_style['all']) AND !empty($border_style['all'])) {
  11042. //set global style for border
  11043. $this->SetLineStyle($border_style['all']);
  11044. $border_style = array();
  11045. } else {
  11046. // remove stroke operator from style
  11047. $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*' );
  11048. if (isset($opnostroke[$style])) {
  11049. $style = $opnostroke[$style];
  11050. }
  11051. }
  11052. }
  11053. if (!empty($style)) {
  11054. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11055. $this->_outRect($x, $y, $w, $h, $op);
  11056. }
  11057. if (!empty($border_style)) {
  11058. $border_style2 = array();
  11059. foreach ($border_style as $line => $value) {
  11060. $length = strlen($line);
  11061. for ($i = 0; $i < $length; ++$i) {
  11062. $border_style2[$line[$i]] = $value;
  11063. }
  11064. }
  11065. $border_style = $border_style2;
  11066. if (isset($border_style['L']) AND $border_style['L']) {
  11067. $this->Line($x, $y, $x, $y + $h, $border_style['L']);
  11068. }
  11069. if (isset($border_style['T']) AND $border_style['T']) {
  11070. $this->Line($x, $y, $x + $w, $y, $border_style['T']);
  11071. }
  11072. if (isset($border_style['R']) AND $border_style['R']) {
  11073. $this->Line($x + $w, $y, $x + $w, $y + $h, $border_style['R']);
  11074. }
  11075. if (isset($border_style['B']) AND $border_style['B']) {
  11076. $this->Line($x, $y + $h, $x + $w, $y + $h, $border_style['B']);
  11077. }
  11078. }
  11079. }
  11080. /**
  11081. * Draws a Bezier curve.
  11082. * The Bezier curve is a tangent to the line between the control points at
  11083. * either end of the curve.
  11084. * @param $x0 (float) Abscissa of start point.
  11085. * @param $y0 (float) Ordinate of start point.
  11086. * @param $x1 (float) Abscissa of control point 1.
  11087. * @param $y1 (float) Ordinate of control point 1.
  11088. * @param $x2 (float) Abscissa of control point 2.
  11089. * @param $y2 (float) Ordinate of control point 2.
  11090. * @param $x3 (float) Abscissa of end point.
  11091. * @param $y3 (float) Ordinate of end point.
  11092. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11093. * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
  11094. * @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).
  11095. * @public
  11096. * @see SetLineStyle()
  11097. * @since 2.1.000 (2008-01-08)
  11098. */
  11099. public function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style='', $line_style=array(), $fill_color=array()) {
  11100. if ($this->state != 2) {
  11101. return;
  11102. }
  11103. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11104. $this->SetFillColorArray($fill_color);
  11105. }
  11106. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11107. if ($line_style) {
  11108. $this->SetLineStyle($line_style);
  11109. }
  11110. $this->_outPoint($x0, $y0);
  11111. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  11112. $this->_out($op);
  11113. }
  11114. /**
  11115. * Draws a poly-Bezier curve.
  11116. * Each Bezier curve segment is a tangent to the line between the control points at
  11117. * either end of the curve.
  11118. * @param $x0 (float) Abscissa of start point.
  11119. * @param $y0 (float) Ordinate of start point.
  11120. * @param $segments (float) An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
  11121. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11122. * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
  11123. * @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).
  11124. * @public
  11125. * @see SetLineStyle()
  11126. * @since 3.0008 (2008-05-12)
  11127. */
  11128. public function Polycurve($x0, $y0, $segments, $style='', $line_style=array(), $fill_color=array()) {
  11129. if ($this->state != 2) {
  11130. return;
  11131. }
  11132. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11133. $this->SetFillColorArray($fill_color);
  11134. }
  11135. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11136. if ($op == 'f') {
  11137. $line_style = array();
  11138. }
  11139. if ($line_style) {
  11140. $this->SetLineStyle($line_style);
  11141. }
  11142. $this->_outPoint($x0, $y0);
  11143. foreach ($segments as $segment) {
  11144. list($x1, $y1, $x2, $y2, $x3, $y3) = $segment;
  11145. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  11146. }
  11147. $this->_out($op);
  11148. }
  11149. /**
  11150. * Draws an ellipse.
  11151. * An ellipse is formed from n Bezier curves.
  11152. * @param $x0 (float) Abscissa of center point.
  11153. * @param $y0 (float) Ordinate of center point.
  11154. * @param $rx (float) Horizontal radius.
  11155. * @param $ry (float) Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
  11156. * @param $angle: (float) Angle oriented (anti-clockwise). Default value: 0.
  11157. * @param $astart: (float) Angle start of draw line. Default value: 0.
  11158. * @param $afinish: (float) Angle finish of draw line. Default value: 360.
  11159. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11160. * @param $line_style (array) Line style of ellipse. Array like for SetLineStyle(). Default value: default line style (empty array).
  11161. * @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).
  11162. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse.
  11163. * @author Nicola Asuni
  11164. * @public
  11165. * @since 2.1.000 (2008-01-08)
  11166. */
  11167. public function Ellipse($x0, $y0, $rx, $ry='', $angle=0, $astart=0, $afinish=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
  11168. if ($this->state != 2) {
  11169. return;
  11170. }
  11171. if (TCPDF_STATIC::empty_string($ry) OR ($ry == 0)) {
  11172. $ry = $rx;
  11173. }
  11174. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11175. $this->SetFillColorArray($fill_color);
  11176. }
  11177. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11178. if ($op == 'f') {
  11179. $line_style = array();
  11180. }
  11181. if ($line_style) {
  11182. $this->SetLineStyle($line_style);
  11183. }
  11184. $this->_outellipticalarc($x0, $y0, $rx, $ry, $angle, $astart, $afinish, false, $nc, true, true, false);
  11185. $this->_out($op);
  11186. }
  11187. /**
  11188. * Append an elliptical arc to the current path.
  11189. * An ellipse is formed from n Bezier curves.
  11190. * @param $xc (float) Abscissa of center point.
  11191. * @param $yc (float) Ordinate of center point.
  11192. * @param $rx (float) Horizontal radius.
  11193. * @param $ry (float) Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
  11194. * @param $xang: (float) Angle between the X-axis and the major axis of the ellipse. Default value: 0.
  11195. * @param $angs: (float) Angle start of draw line. Default value: 0.
  11196. * @param $angf: (float) Angle finish of draw line. Default value: 360.
  11197. * @param $pie (boolean) if true do not mark the border point (used to draw pie sectors).
  11198. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse.
  11199. * @param $startpoint (boolean) if true output a starting point.
  11200. * @param $ccw (boolean) if true draws in counter-clockwise.
  11201. * @param $svg (boolean) if true the angles are in svg mode (already calculated).
  11202. * @return array bounding box coordinates (x min, y min, x max, y max)
  11203. * @author Nicola Asuni
  11204. * @protected
  11205. * @since 4.9.019 (2010-04-26)
  11206. */
  11207. protected function _outellipticalarc($xc, $yc, $rx, $ry, $xang=0, $angs=0, $angf=360, $pie=false, $nc=2, $startpoint=true, $ccw=true, $svg=false) {
  11208. if (($rx <= 0) OR ($ry < 0)) {
  11209. return;
  11210. }
  11211. $k = $this->k;
  11212. if ($nc < 2) {
  11213. $nc = 2;
  11214. }
  11215. $xmin = 2147483647;
  11216. $ymin = 2147483647;
  11217. $xmax = 0;
  11218. $ymax = 0;
  11219. if ($pie) {
  11220. // center of the arc
  11221. $this->_outPoint($xc, $yc);
  11222. }
  11223. $xang = deg2rad((float) $xang);
  11224. $angs = deg2rad((float) $angs);
  11225. $angf = deg2rad((float) $angf);
  11226. if ($svg) {
  11227. $as = $angs;
  11228. $af = $angf;
  11229. } else {
  11230. $as = atan2((sin($angs) / $ry), (cos($angs) / $rx));
  11231. $af = atan2((sin($angf) / $ry), (cos($angf) / $rx));
  11232. }
  11233. if ($as < 0) {
  11234. $as += (2 * M_PI);
  11235. }
  11236. if ($af < 0) {
  11237. $af += (2 * M_PI);
  11238. }
  11239. if ($ccw AND ($as > $af)) {
  11240. // reverse rotation
  11241. $as -= (2 * M_PI);
  11242. } elseif (!$ccw AND ($as < $af)) {
  11243. // reverse rotation
  11244. $af -= (2 * M_PI);
  11245. }
  11246. $total_angle = ($af - $as);
  11247. if ($nc < 2) {
  11248. $nc = 2;
  11249. }
  11250. // total arcs to draw
  11251. $nc *= (2 * abs($total_angle) / M_PI);
  11252. $nc = round($nc) + 1;
  11253. // angle of each arc
  11254. $arcang = ($total_angle / $nc);
  11255. // center point in PDF coordinates
  11256. $x0 = $xc;
  11257. $y0 = ($this->h - $yc);
  11258. // starting angle
  11259. $ang = $as;
  11260. $alpha = sin($arcang) * ((sqrt(4 + (3 * pow(tan(($arcang) / 2), 2))) - 1) / 3);
  11261. $cos_xang = cos($xang);
  11262. $sin_xang = sin($xang);
  11263. $cos_ang = cos($ang);
  11264. $sin_ang = sin($ang);
  11265. // first arc point
  11266. $px1 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
  11267. $py1 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
  11268. // first Bezier control point
  11269. $qx1 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
  11270. $qy1 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
  11271. if ($pie) {
  11272. // line from center to arc starting point
  11273. $this->_outLine($px1, $this->h - $py1);
  11274. } elseif ($startpoint) {
  11275. // arc starting point
  11276. $this->_outPoint($px1, $this->h - $py1);
  11277. }
  11278. // draw arcs
  11279. for ($i = 1; $i <= $nc; ++$i) {
  11280. // starting angle
  11281. $ang = $as + ($i * $arcang);
  11282. if ($i == $nc) {
  11283. $ang = $af;
  11284. }
  11285. $cos_ang = cos($ang);
  11286. $sin_ang = sin($ang);
  11287. // second arc point
  11288. $px2 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
  11289. $py2 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
  11290. // second Bezier control point
  11291. $qx2 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
  11292. $qy2 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
  11293. // draw arc
  11294. $cx1 = ($px1 + $qx1);
  11295. $cy1 = ($this->h - ($py1 + $qy1));
  11296. $cx2 = ($px2 - $qx2);
  11297. $cy2 = ($this->h - ($py2 - $qy2));
  11298. $cx3 = $px2;
  11299. $cy3 = ($this->h - $py2);
  11300. $this->_outCurve($cx1, $cy1, $cx2, $cy2, $cx3, $cy3);
  11301. // get bounding box coordinates
  11302. $xmin = min($xmin, $cx1, $cx2, $cx3);
  11303. $ymin = min($ymin, $cy1, $cy2, $cy3);
  11304. $xmax = max($xmax, $cx1, $cx2, $cx3);
  11305. $ymax = max($ymax, $cy1, $cy2, $cy3);
  11306. // move to next point
  11307. $px1 = $px2;
  11308. $py1 = $py2;
  11309. $qx1 = $qx2;
  11310. $qy1 = $qy2;
  11311. }
  11312. if ($pie) {
  11313. $this->_outLine($xc, $yc);
  11314. // get bounding box coordinates
  11315. $xmin = min($xmin, $xc);
  11316. $ymin = min($ymin, $yc);
  11317. $xmax = max($xmax, $xc);
  11318. $ymax = max($ymax, $yc);
  11319. }
  11320. return array($xmin, $ymin, $xmax, $ymax);
  11321. }
  11322. /**
  11323. * Draws a circle.
  11324. * A circle is formed from n Bezier curves.
  11325. * @param $x0 (float) Abscissa of center point.
  11326. * @param $y0 (float) Ordinate of center point.
  11327. * @param $r (float) Radius.
  11328. * @param $angstr: (float) Angle start of draw line. Default value: 0.
  11329. * @param $angend: (float) Angle finish of draw line. Default value: 360.
  11330. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11331. * @param $line_style (array) Line style of circle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11332. * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11333. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of circle.
  11334. * @public
  11335. * @since 2.1.000 (2008-01-08)
  11336. */
  11337. public function Circle($x0, $y0, $r, $angstr=0, $angend=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
  11338. $this->Ellipse($x0, $y0, $r, $r, 0, $angstr, $angend, $style, $line_style, $fill_color, $nc);
  11339. }
  11340. /**
  11341. * Draws a polygonal line
  11342. * @param $p (array) Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  11343. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11344. * @param $line_style (array) Line style of polygon. Array with keys among the following:
  11345. * <ul>
  11346. * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
  11347. * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
  11348. * </ul>
  11349. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  11350. * @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).
  11351. * @since 4.8.003 (2009-09-15)
  11352. * @public
  11353. */
  11354. public function PolyLine($p, $style='', $line_style=array(), $fill_color=array()) {
  11355. $this->Polygon($p, $style, $line_style, $fill_color, false);
  11356. }
  11357. /**
  11358. * Draws a polygon.
  11359. * @param $p (array) Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  11360. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11361. * @param $line_style (array) Line style of polygon. Array with keys among the following:
  11362. * <ul>
  11363. * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
  11364. * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
  11365. * </ul>
  11366. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  11367. * @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).
  11368. * @param $closed (boolean) if true the polygon is closes, otherwise will remain open
  11369. * @public
  11370. * @since 2.1.000 (2008-01-08)
  11371. */
  11372. public function Polygon($p, $style='', $line_style=array(), $fill_color=array(), $closed=true) {
  11373. if ($this->state != 2) {
  11374. return;
  11375. }
  11376. $nc = count($p); // number of coordinates
  11377. $np = $nc / 2; // number of points
  11378. if ($closed) {
  11379. // close polygon by adding the first 2 points at the end (one line)
  11380. for ($i = 0; $i < 4; ++$i) {
  11381. $p[$nc + $i] = $p[$i];
  11382. }
  11383. // copy style for the last added line
  11384. if (isset($line_style[0])) {
  11385. $line_style[$np] = $line_style[0];
  11386. }
  11387. $nc += 4;
  11388. }
  11389. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11390. $this->SetFillColorArray($fill_color);
  11391. }
  11392. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11393. if ($op == 'f') {
  11394. $line_style = array();
  11395. }
  11396. $draw = true;
  11397. if ($line_style) {
  11398. if (isset($line_style['all'])) {
  11399. $this->SetLineStyle($line_style['all']);
  11400. } else {
  11401. $draw = false;
  11402. if ($op == 'B') {
  11403. // draw fill
  11404. $op = 'f';
  11405. $this->_outPoint($p[0], $p[1]);
  11406. for ($i = 2; $i < $nc; $i = $i + 2) {
  11407. $this->_outLine($p[$i], $p[$i + 1]);
  11408. }
  11409. $this->_out($op);
  11410. }
  11411. // draw outline
  11412. $this->_outPoint($p[0], $p[1]);
  11413. for ($i = 2; $i < $nc; $i = $i + 2) {
  11414. $line_num = ($i / 2) - 1;
  11415. if (isset($line_style[$line_num])) {
  11416. if ($line_style[$line_num] != 0) {
  11417. if (is_array($line_style[$line_num])) {
  11418. $this->_out('S');
  11419. $this->SetLineStyle($line_style[$line_num]);
  11420. $this->_outPoint($p[$i - 2], $p[$i - 1]);
  11421. $this->_outLine($p[$i], $p[$i + 1]);
  11422. $this->_out('S');
  11423. $this->_outPoint($p[$i], $p[$i + 1]);
  11424. } else {
  11425. $this->_outLine($p[$i], $p[$i + 1]);
  11426. }
  11427. }
  11428. } else {
  11429. $this->_outLine($p[$i], $p[$i + 1]);
  11430. }
  11431. }
  11432. $this->_out($op);
  11433. }
  11434. }
  11435. if ($draw) {
  11436. $this->_outPoint($p[0], $p[1]);
  11437. for ($i = 2; $i < $nc; $i = $i + 2) {
  11438. $this->_outLine($p[$i], $p[$i + 1]);
  11439. }
  11440. $this->_out($op);
  11441. }
  11442. }
  11443. /**
  11444. * Draws a regular polygon.
  11445. * @param $x0 (float) Abscissa of center point.
  11446. * @param $y0 (float) Ordinate of center point.
  11447. * @param $r: (float) Radius of inscribed circle.
  11448. * @param $ns (integer) Number of sides.
  11449. * @param $angle (float) Angle oriented (anti-clockwise). Default value: 0.
  11450. * @param $draw_circle (boolean) Draw inscribed circle or not. Default value: false.
  11451. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11452. * @param $line_style (array) Line style of polygon sides. Array with keys among the following:
  11453. * <ul>
  11454. * <li>all: Line style of all sides. Array like for SetLineStyle().</li>
  11455. * <li>0 to ($ns - 1): Line style of each side. Array like for SetLineStyle().</li>
  11456. * </ul>
  11457. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  11458. * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11459. * @param $circle_style (string) Style of rendering of inscribed circle (if draws). Possible values are:
  11460. * <ul>
  11461. * <li>D or empty string: Draw (default).</li>
  11462. * <li>F: Fill.</li>
  11463. * <li>DF or FD: Draw and fill.</li>
  11464. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  11465. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  11466. * </ul>
  11467. * @param $circle_outLine_style (array) Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
  11468. * @param $circle_fill_color (array) Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  11469. * @public
  11470. * @since 2.1.000 (2008-01-08)
  11471. */
  11472. 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()) {
  11473. if (3 > $ns) {
  11474. $ns = 3;
  11475. }
  11476. if ($draw_circle) {
  11477. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  11478. }
  11479. $p = array();
  11480. for ($i = 0; $i < $ns; ++$i) {
  11481. $a = $angle + ($i * 360 / $ns);
  11482. $a_rad = deg2rad((float) $a);
  11483. $p[] = $x0 + ($r * sin($a_rad));
  11484. $p[] = $y0 + ($r * cos($a_rad));
  11485. }
  11486. $this->Polygon($p, $style, $line_style, $fill_color);
  11487. }
  11488. /**
  11489. * Draws a star polygon
  11490. * @param $x0 (float) Abscissa of center point.
  11491. * @param $y0 (float) Ordinate of center point.
  11492. * @param $r (float) Radius of inscribed circle.
  11493. * @param $nv (integer) Number of vertices.
  11494. * @param $ng (integer) Number of gap (if ($ng % $nv = 1) then is a regular polygon).
  11495. * @param $angle: (float) Angle oriented (anti-clockwise). Default value: 0.
  11496. * @param $draw_circle: (boolean) Draw inscribed circle or not. Default value is false.
  11497. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11498. * @param $line_style (array) Line style of polygon sides. Array with keys among the following:
  11499. * <ul>
  11500. * <li>all: Line style of all sides. Array like for
  11501. * SetLineStyle().</li>
  11502. * <li>0 to (n - 1): Line style of each side. Array like for SetLineStyle().</li>
  11503. * </ul>
  11504. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  11505. * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11506. * @param $circle_style (string) Style of rendering of inscribed circle (if draws). Possible values are:
  11507. * <ul>
  11508. * <li>D or empty string: Draw (default).</li>
  11509. * <li>F: Fill.</li>
  11510. * <li>DF or FD: Draw and fill.</li>
  11511. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  11512. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  11513. * </ul>
  11514. * @param $circle_outLine_style (array) Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
  11515. * @param $circle_fill_color (array) Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  11516. * @public
  11517. * @since 2.1.000 (2008-01-08)
  11518. */
  11519. 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()) {
  11520. if ($nv < 2) {
  11521. $nv = 2;
  11522. }
  11523. if ($draw_circle) {
  11524. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  11525. }
  11526. $p2 = array();
  11527. $visited = array();
  11528. for ($i = 0; $i < $nv; ++$i) {
  11529. $a = $angle + ($i * 360 / $nv);
  11530. $a_rad = deg2rad((float) $a);
  11531. $p2[] = $x0 + ($r * sin($a_rad));
  11532. $p2[] = $y0 + ($r * cos($a_rad));
  11533. $visited[] = false;
  11534. }
  11535. $p = array();
  11536. $i = 0;
  11537. do {
  11538. $p[] = $p2[$i * 2];
  11539. $p[] = $p2[($i * 2) + 1];
  11540. $visited[$i] = true;
  11541. $i += $ng;
  11542. $i %= $nv;
  11543. } while (!$visited[$i]);
  11544. $this->Polygon($p, $style, $line_style, $fill_color);
  11545. }
  11546. /**
  11547. * Draws a rounded rectangle.
  11548. * @param $x (float) Abscissa of upper-left corner.
  11549. * @param $y (float) Ordinate of upper-left corner.
  11550. * @param $w (float) Width.
  11551. * @param $h (float) Height.
  11552. * @param $r (float) the radius of the circle used to round off the corners of the rectangle.
  11553. * @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").
  11554. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11555. * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11556. * @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).
  11557. * @public
  11558. * @since 2.1.000 (2008-01-08)
  11559. */
  11560. public function RoundedRect($x, $y, $w, $h, $r, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
  11561. $this->RoundedRectXY($x, $y, $w, $h, $r, $r, $round_corner, $style, $border_style, $fill_color);
  11562. }
  11563. /**
  11564. * Draws a rounded rectangle.
  11565. * @param $x (float) Abscissa of upper-left corner.
  11566. * @param $y (float) Ordinate of upper-left corner.
  11567. * @param $w (float) Width.
  11568. * @param $h (float) Height.
  11569. * @param $rx (float) the x-axis radius of the ellipse used to round off the corners of the rectangle.
  11570. * @param $ry (float) the y-axis radius of the ellipse used to round off the corners of the rectangle.
  11571. * @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").
  11572. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11573. * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11574. * @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).
  11575. * @public
  11576. * @since 4.9.019 (2010-04-22)
  11577. */
  11578. public function RoundedRectXY($x, $y, $w, $h, $rx, $ry, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
  11579. if ($this->state != 2) {
  11580. return;
  11581. }
  11582. if (($round_corner == '0000') OR (($rx == $ry) AND ($rx == 0))) {
  11583. // Not rounded
  11584. $this->Rect($x, $y, $w, $h, $style, $border_style, $fill_color);
  11585. return;
  11586. }
  11587. // Rounded
  11588. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11589. $this->SetFillColorArray($fill_color);
  11590. }
  11591. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11592. if ($op == 'f') {
  11593. $border_style = array();
  11594. }
  11595. if ($border_style) {
  11596. $this->SetLineStyle($border_style);
  11597. }
  11598. $MyArc = 4 / 3 * (sqrt(2) - 1);
  11599. $this->_outPoint($x + $rx, $y);
  11600. $xc = $x + $w - $rx;
  11601. $yc = $y + $ry;
  11602. $this->_outLine($xc, $y);
  11603. if ($round_corner[0]) {
  11604. $this->_outCurve($xc + ($rx * $MyArc), $yc - $ry, $xc + $rx, $yc - ($ry * $MyArc), $xc + $rx, $yc);
  11605. } else {
  11606. $this->_outLine($x + $w, $y);
  11607. }
  11608. $xc = $x + $w - $rx;
  11609. $yc = $y + $h - $ry;
  11610. $this->_outLine($x + $w, $yc);
  11611. if ($round_corner[1]) {
  11612. $this->_outCurve($xc + $rx, $yc + ($ry * $MyArc), $xc + ($rx * $MyArc), $yc + $ry, $xc, $yc + $ry);
  11613. } else {
  11614. $this->_outLine($x + $w, $y + $h);
  11615. }
  11616. $xc = $x + $rx;
  11617. $yc = $y + $h - $ry;
  11618. $this->_outLine($xc, $y + $h);
  11619. if ($round_corner[2]) {
  11620. $this->_outCurve($xc - ($rx * $MyArc), $yc + $ry, $xc - $rx, $yc + ($ry * $MyArc), $xc - $rx, $yc);
  11621. } else {
  11622. $this->_outLine($x, $y + $h);
  11623. }
  11624. $xc = $x + $rx;
  11625. $yc = $y + $ry;
  11626. $this->_outLine($x, $yc);
  11627. if ($round_corner[3]) {
  11628. $this->_outCurve($xc - $rx, $yc - ($ry * $MyArc), $xc - ($rx * $MyArc), $yc - $ry, $xc, $yc - $ry);
  11629. } else {
  11630. $this->_outLine($x, $y);
  11631. $this->_outLine($x + $rx, $y);
  11632. }
  11633. $this->_out($op);
  11634. }
  11635. /**
  11636. * Draws a grahic arrow.
  11637. * @param $x0 (float) Abscissa of first point.
  11638. * @param $y0 (float) Ordinate of first point.
  11639. * @param $x1 (float) Abscissa of second point.
  11640. * @param $y1 (float) Ordinate of second point.
  11641. * @param $head_style (int) (0 = draw only arrowhead arms, 1 = draw closed arrowhead, but no fill, 2 = closed and filled arrowhead, 3 = filled arrowhead)
  11642. * @param $arm_size (float) length of arrowhead arms
  11643. * @param $arm_angle (int) angle between an arm and the shaft
  11644. * @author Piotr Galecki, Nicola Asuni, Andy Meier
  11645. * @since 4.6.018 (2009-07-10)
  11646. */
  11647. public function Arrow($x0, $y0, $x1, $y1, $head_style=0, $arm_size=5, $arm_angle=15) {
  11648. // getting arrow direction angle
  11649. // 0 deg angle is when both arms go along X axis. angle grows clockwise.
  11650. $dir_angle = atan2(($y0 - $y1), ($x0 - $x1));
  11651. if ($dir_angle < 0) {
  11652. $dir_angle += (2 * M_PI);
  11653. }
  11654. $arm_angle = deg2rad($arm_angle);
  11655. $sx1 = $x1;
  11656. $sy1 = $y1;
  11657. if ($head_style > 0) {
  11658. // calculate the stopping point for the arrow shaft
  11659. $sx1 = $x1 + (($arm_size - $this->LineWidth) * cos($dir_angle));
  11660. $sy1 = $y1 + (($arm_size - $this->LineWidth) * sin($dir_angle));
  11661. }
  11662. // main arrow line / shaft
  11663. $this->Line($x0, $y0, $sx1, $sy1);
  11664. // left arrowhead arm tip
  11665. $x2L = $x1 + ($arm_size * cos($dir_angle + $arm_angle));
  11666. $y2L = $y1 + ($arm_size * sin($dir_angle + $arm_angle));
  11667. // right arrowhead arm tip
  11668. $x2R = $x1 + ($arm_size * cos($dir_angle - $arm_angle));
  11669. $y2R = $y1 + ($arm_size * sin($dir_angle - $arm_angle));
  11670. $mode = 'D';
  11671. $style = array();
  11672. switch ($head_style) {
  11673. case 0: {
  11674. // draw only arrowhead arms
  11675. $mode = 'D';
  11676. $style = array(1, 1, 0);
  11677. break;
  11678. }
  11679. case 1: {
  11680. // draw closed arrowhead, but no fill
  11681. $mode = 'D';
  11682. break;
  11683. }
  11684. case 2: {
  11685. // closed and filled arrowhead
  11686. $mode = 'DF';
  11687. break;
  11688. }
  11689. case 3: {
  11690. // filled arrowhead
  11691. $mode = 'F';
  11692. break;
  11693. }
  11694. }
  11695. $this->Polygon(array($x2L, $y2L, $x1, $y1, $x2R, $y2R), $mode, $style, array());
  11696. }
  11697. // END GRAPHIC FUNCTIONS SECTION -----------------------
  11698. /**
  11699. * Add a Named Destination.
  11700. * NOTE: destination names are unique, so only last entry will be saved.
  11701. * @param $name (string) Destination name.
  11702. * @param $y (float) Y position in user units of the destiantion on the selected page (default = -1 = current position; 0 = page start;).
  11703. * @param $page (int) Target page number (leave empty for current page).
  11704. * @param $x (float) X position in user units of the destiantion on the selected page (default = -1 = current position;).
  11705. * @return (string) Stripped named destination identifier or false in case of error.
  11706. * @public
  11707. * @author Christian Deligant, Nicola Asuni
  11708. * @since 5.9.097 (2011-06-23)
  11709. */
  11710. public function setDestination($name, $y=-1, $page='', $x=-1) {
  11711. // remove unsupported characters
  11712. $name = TCPDF_STATIC::encodeNameObject($name);
  11713. if (TCPDF_STATIC::empty_string($name)) {
  11714. return false;
  11715. }
  11716. if ($y == -1) {
  11717. $y = $this->GetY();
  11718. } elseif ($y < 0) {
  11719. $y = 0;
  11720. } elseif ($y > $this->h) {
  11721. $y = $this->h;
  11722. }
  11723. if ($x == -1) {
  11724. $x = $this->GetX();
  11725. } elseif ($x < 0) {
  11726. $x = 0;
  11727. } elseif ($x > $this->w) {
  11728. $x = $this->w;
  11729. }
  11730. if (empty($page)) {
  11731. $page = $this->PageNo();
  11732. if (empty($page)) {
  11733. return;
  11734. }
  11735. }
  11736. $this->dests[$name] = array('x' => $x, 'y' => $y, 'p' => $page);
  11737. return $name;
  11738. }
  11739. /**
  11740. * Return the Named Destination array.
  11741. * @return (array) Named Destination array.
  11742. * @public
  11743. * @author Nicola Asuni
  11744. * @since 5.9.097 (2011-06-23)
  11745. */
  11746. public function getDestination() {
  11747. return $this->dests;
  11748. }
  11749. /**
  11750. * Insert Named Destinations.
  11751. * @protected
  11752. * @author Johannes G\FCntert, Nicola Asuni
  11753. * @since 5.9.098 (2011-06-23)
  11754. */
  11755. protected function _putdests() {
  11756. if (empty($this->dests)) {
  11757. return;
  11758. }
  11759. $this->n_dests = $this->_newobj();
  11760. $out = ' <<';
  11761. foreach($this->dests as $name => $o) {
  11762. $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)));
  11763. }
  11764. $out .= ' >>';
  11765. $out .= "\n".'endobj';
  11766. $this->_out($out);
  11767. }
  11768. /**
  11769. * Adds a bookmark - alias for Bookmark().
  11770. * @param $txt (string) Bookmark description.
  11771. * @param $level (int) Bookmark level (minimum value is 0).
  11772. * @param $y (float) Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
  11773. * @param $page (int) Target page number (leave empty for current page).
  11774. * @param $style (string) Font style: B = Bold, I = Italic, BI = Bold + Italic.
  11775. * @param $color (array) RGB color array (values from 0 to 255).
  11776. * @param $x (float) X position in user units of the bookmark on the selected page (default = -1 = current position;).
  11777. * @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).
  11778. * @public
  11779. */
  11780. public function setBookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='') {
  11781. $this->Bookmark($txt, $level, $y, $page, $style, $color, $x, $link);
  11782. }
  11783. /**
  11784. * Adds a bookmark.
  11785. * @param $txt (string) Bookmark description.
  11786. * @param $level (int) Bookmark level (minimum value is 0).
  11787. * @param $y (float) Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
  11788. * @param $page (int) Target page number (leave empty for current page).
  11789. * @param $style (string) Font style: B = Bold, I = Italic, BI = Bold + Italic.
  11790. * @param $color (array) RGB color array (values from 0 to 255).
  11791. * @param $x (float) X position in user units of the bookmark on the selected page (default = -1 = current position;).
  11792. * @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).
  11793. * @public
  11794. * @since 2.1.002 (2008-02-12)
  11795. */
  11796. public function Bookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='') {
  11797. if ($level < 0) {
  11798. $level = 0;
  11799. }
  11800. if (isset($this->outlines[0])) {
  11801. $lastoutline = end($this->outlines);
  11802. $maxlevel = $lastoutline['l'] + 1;
  11803. } else {
  11804. $maxlevel = 0;
  11805. }
  11806. if ($level > $maxlevel) {
  11807. $level = $maxlevel;
  11808. }
  11809. if ($y == -1) {
  11810. $y = $this->GetY();
  11811. } elseif ($y < 0) {
  11812. $y = 0;
  11813. } elseif ($y > $this->h) {
  11814. $y = $this->h;
  11815. }
  11816. if ($x == -1) {
  11817. $x = $this->GetX();
  11818. } elseif ($x < 0) {
  11819. $x = 0;
  11820. } elseif ($x > $this->w) {
  11821. $x = $this->w;
  11822. }
  11823. if (empty($page)) {
  11824. $page = $this->PageNo();
  11825. if (empty($page)) {
  11826. return;
  11827. }
  11828. }
  11829. $this->outlines[] = array('t' => $txt, 'l' => $level, 'x' => $x, 'y' => $y, 'p' => $page, 's' => strtoupper($style), 'c' => $color, 'u' => $link);
  11830. }
  11831. /**
  11832. * Sort bookmarks for page and key.
  11833. * @protected
  11834. * @since 5.9.119 (2011-09-19)
  11835. */
  11836. protected function sortBookmarks() {
  11837. // get sorting columns
  11838. $outline_p = array();
  11839. $outline_y = array();
  11840. foreach ($this->outlines as $key => $row) {
  11841. $outline_p[$key] = $row['p'];
  11842. $outline_k[$key] = $key;
  11843. }
  11844. // sort outlines by page and original position
  11845. array_multisort($outline_p, SORT_NUMERIC, SORT_ASC, $outline_k, SORT_NUMERIC, SORT_ASC, $this->outlines);
  11846. }
  11847. /**
  11848. * Create a bookmark PDF string.
  11849. * @protected
  11850. * @author Olivier Plathey, Nicola Asuni
  11851. * @since 2.1.002 (2008-02-12)
  11852. */
  11853. protected function _putbookmarks() {
  11854. $nb = count($this->outlines);
  11855. if ($nb == 0) {
  11856. return;
  11857. }
  11858. // sort bookmarks
  11859. $this->sortBookmarks();
  11860. $lru = array();
  11861. $level = 0;
  11862. foreach ($this->outlines as $i => $o) {
  11863. if ($o['l'] > 0) {
  11864. $parent = $lru[($o['l'] - 1)];
  11865. //Set parent and last pointers
  11866. $this->outlines[$i]['parent'] = $parent;
  11867. $this->outlines[$parent]['last'] = $i;
  11868. if ($o['l'] > $level) {
  11869. //Level increasing: set first pointer
  11870. $this->outlines[$parent]['first'] = $i;
  11871. }
  11872. } else {
  11873. $this->outlines[$i]['parent'] = $nb;
  11874. }
  11875. if (($o['l'] <= $level) AND ($i > 0)) {
  11876. //Set prev and next pointers
  11877. $prev = $lru[$o['l']];
  11878. $this->outlines[$prev]['next'] = $i;
  11879. $this->outlines[$i]['prev'] = $prev;
  11880. }
  11881. $lru[$o['l']] = $i;
  11882. $level = $o['l'];
  11883. }
  11884. //Outline items
  11885. $n = $this->n + 1;
  11886. $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';
  11887. foreach ($this->outlines as $i => $o) {
  11888. $oid = $this->_newobj();
  11889. // covert HTML title to string
  11890. $title = preg_replace($nltags, "\n", $o['t']);
  11891. $title = preg_replace("/[\r]+/si", '', $title);
  11892. $title = preg_replace("/[\n]+/si", "\n", $title);
  11893. $title = strip_tags($title);
  11894. $title = $this->stringTrim($title);
  11895. $out = '<</Title '.$this->_textstring($title, $oid);
  11896. $out .= ' /Parent '.($n + $o['parent']).' 0 R';
  11897. if (isset($o['prev'])) {
  11898. $out .= ' /Prev '.($n + $o['prev']).' 0 R';
  11899. }
  11900. if (isset($o['next'])) {
  11901. $out .= ' /Next '.($n + $o['next']).' 0 R';
  11902. }
  11903. if (isset($o['first'])) {
  11904. $out .= ' /First '.($n + $o['first']).' 0 R';
  11905. }
  11906. if (isset($o['last'])) {
  11907. $out .= ' /Last '.($n + $o['last']).' 0 R';
  11908. }
  11909. if (isset($o['u']) AND !empty($o['u'])) {
  11910. // link
  11911. if (is_string($o['u'])) {
  11912. if ($o['u'][0] == '#') {
  11913. // internal destination
  11914. $out .= ' /Dest /'.TCPDF_STATIC::encodeNameObject(substr($o['u'], 1));
  11915. } elseif ($o['u'][0] == '%') {
  11916. // embedded PDF file
  11917. $filename = basename(substr($o['u'], 1));
  11918. $out .= ' /A <</S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($o['p'] - 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>';
  11919. } elseif ($o['u'][0] == '*') {
  11920. // embedded generic file
  11921. $filename = basename(substr($o['u'], 1));
  11922. $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});';
  11923. $out .= ' /A <</S /JavaScript /JS '.$this->_textstring($jsa, $oid).'>>';
  11924. } else {
  11925. // external URI link
  11926. $out .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($o['u']), $oid).'>>';
  11927. }
  11928. } elseif (isset($this->links[$o['u']])) {
  11929. // internal link ID
  11930. $l = $this->links[$o['u']];
  11931. if (isset($this->page_obj_id[($l[0])])) {
  11932. $out .= sprintf(' /Dest [%u 0 R /XYZ 0 %F null]', $this->page_obj_id[($l[0])], ($this->pagedim[$l[0]]['h'] - ($l[1] * $this->k)));
  11933. }
  11934. }
  11935. } elseif (isset($this->page_obj_id[($o['p'])])) {
  11936. // link to a page
  11937. $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)));
  11938. }
  11939. // set font style
  11940. $style = 0;
  11941. if (!empty($o['s'])) {
  11942. // bold
  11943. if (strpos($o['s'], 'B') !== false) {
  11944. $style |= 2;
  11945. }
  11946. // oblique
  11947. if (strpos($o['s'], 'I') !== false) {
  11948. $style |= 1;
  11949. }
  11950. }
  11951. $out .= sprintf(' /F %d', $style);
  11952. // set bookmark color
  11953. if (isset($o['c']) AND is_array($o['c']) AND (count($o['c']) == 3)) {
  11954. $color = array_values($o['c']);
  11955. $out .= sprintf(' /C [%F %F %F]', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
  11956. } else {
  11957. // black
  11958. $out .= ' /C [0.0 0.0 0.0]';
  11959. }
  11960. $out .= ' /Count 0'; // normally closed item
  11961. $out .= ' >>';
  11962. $out .= "\n".'endobj';
  11963. $this->_out($out);
  11964. }
  11965. //Outline root
  11966. $this->OutlineRoot = $this->_newobj();
  11967. $this->_out('<< /Type /Outlines /First '.$n.' 0 R /Last '.($n + $lru[0]).' 0 R >>'."\n".'endobj');
  11968. }
  11969. // --- JAVASCRIPT ------------------------------------------------------
  11970. /**
  11971. * Adds a javascript
  11972. * @param $script (string) Javascript code
  11973. * @public
  11974. * @author Johannes G\FCntert, Nicola Asuni
  11975. * @since 2.1.002 (2008-02-12)
  11976. */
  11977. public function IncludeJS($script) {
  11978. $this->javascript .= $script;
  11979. }
  11980. /**
  11981. * Adds a javascript object and return object ID
  11982. * @param $script (string) Javascript code
  11983. * @param $onload (boolean) if true executes this object when opening the document
  11984. * @return int internal object ID
  11985. * @public
  11986. * @author Nicola Asuni
  11987. * @since 4.8.000 (2009-09-07)
  11988. */
  11989. public function addJavascriptObject($script, $onload=false) {
  11990. if ($this->pdfa_mode) {
  11991. // javascript is not allowed in PDF/A mode
  11992. return false;
  11993. }
  11994. ++$this->n;
  11995. $this->js_objects[$this->n] = array('n' => $this->n, 'js' => $script, 'onload' => $onload);
  11996. return $this->n;
  11997. }
  11998. /**
  11999. * Create a javascript PDF string.
  12000. * @protected
  12001. * @author Johannes G\FCntert, Nicola Asuni
  12002. * @since 2.1.002 (2008-02-12)
  12003. */
  12004. protected function _putjavascript() {
  12005. if ($this->pdfa_mode OR (empty($this->javascript) AND empty($this->js_objects))) {
  12006. return;
  12007. }
  12008. if (strpos($this->javascript, 'this.addField') > 0) {
  12009. if (!$this->ur['enabled']) {
  12010. //$this->setUserRights();
  12011. }
  12012. // the following two lines are used to avoid form fields duplication after saving
  12013. // The addField method only works when releasing user rights (UR3)
  12014. $jsa = sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%F,%F,%F,%F]);", 'tcpdfdocsaved', 'text', 0, 0, 1, 0, 1);
  12015. $jsb = "getField('tcpdfdocsaved').value='saved';";
  12016. $this->javascript = $jsa."\n".$this->javascript."\n".$jsb;
  12017. }
  12018. // name tree for javascript
  12019. $this->n_js = '<< /Names [';
  12020. if (!empty($this->javascript)) {
  12021. $this->n_js .= ' (EmbeddedJS) '.($this->n + 1).' 0 R';
  12022. }
  12023. if (!empty($this->js_objects)) {
  12024. foreach ($this->js_objects as $key => $val) {
  12025. if ($val['onload']) {
  12026. $this->n_js .= ' (JS'.$key.') '.$key.' 0 R';
  12027. }
  12028. }
  12029. }
  12030. $this->n_js .= ' ] >>';
  12031. // default Javascript object
  12032. if (!empty($this->javascript)) {
  12033. $obj_id = $this->_newobj();
  12034. $out = '<< /S /JavaScript';
  12035. $out .= ' /JS '.$this->_textstring($this->javascript, $obj_id);
  12036. $out .= ' >>';
  12037. $out .= "\n".'endobj';
  12038. $this->_out($out);
  12039. }
  12040. // additional Javascript objects
  12041. if (!empty($this->js_objects)) {
  12042. foreach ($this->js_objects as $key => $val) {
  12043. $out = $this->_getobj($key)."\n".' << /S /JavaScript /JS '.$this->_textstring($val['js'], $key).' >>'."\n".'endobj';
  12044. $this->_out($out);
  12045. }
  12046. }
  12047. }
  12048. /**
  12049. * Adds a javascript form field.
  12050. * @param $type (string) field type
  12051. * @param $name (string) field name
  12052. * @param $x (int) horizontal position
  12053. * @param $y (int) vertical position
  12054. * @param $w (int) width
  12055. * @param $h (int) height
  12056. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12057. * @protected
  12058. * @author Denis Van Nuffelen, Nicola Asuni
  12059. * @since 2.1.002 (2008-02-12)
  12060. */
  12061. protected function _addfield($type, $name, $x, $y, $w, $h, $prop) {
  12062. if ($this->rtl) {
  12063. $x = $x - $w;
  12064. }
  12065. // the followind avoid fields duplication after saving the document
  12066. $this->javascript .= "if (getField('tcpdfdocsaved').value != 'saved') {";
  12067. $k = $this->k;
  12068. $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";
  12069. $this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n";
  12070. while (list($key, $val) = each($prop)) {
  12071. if (strcmp(substr($key, -5), 'Color') == 0) {
  12072. $val = TCPDF_COLORS::_JScolor($val);
  12073. } else {
  12074. $val = "'".$val."'";
  12075. }
  12076. $this->javascript .= 'f'.$name.'.'.$key.'='.$val.";\n";
  12077. }
  12078. if ($this->rtl) {
  12079. $this->x -= $w;
  12080. } else {
  12081. $this->x += $w;
  12082. }
  12083. $this->javascript .= '}';
  12084. }
  12085. // --- FORM FIELDS -----------------------------------------------------
  12086. /**
  12087. * Set default properties for form fields.
  12088. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12089. * @public
  12090. * @author Nicola Asuni
  12091. * @since 4.8.000 (2009-09-06)
  12092. */
  12093. public function setFormDefaultProp($prop=array()) {
  12094. $this->default_form_prop = $prop;
  12095. }
  12096. /**
  12097. * Return the default properties for form fields.
  12098. * @return array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12099. * @public
  12100. * @author Nicola Asuni
  12101. * @since 4.8.000 (2009-09-06)
  12102. */
  12103. public function getFormDefaultProp() {
  12104. return $this->default_form_prop;
  12105. }
  12106. /**
  12107. * Creates a text field
  12108. * @param $name (string) field name
  12109. * @param $w (float) Width of the rectangle
  12110. * @param $h (float) Height of the rectangle
  12111. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12112. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12113. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12114. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12115. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12116. * @public
  12117. * @author Nicola Asuni
  12118. * @since 4.8.000 (2009-09-07)
  12119. */
  12120. public function TextField($name, $w, $h, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  12121. if ($x === '') {
  12122. $x = $this->x;
  12123. }
  12124. if ($y === '') {
  12125. $y = $this->y;
  12126. }
  12127. // check page for no-write regions and adapt page margins if necessary
  12128. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12129. if ($js) {
  12130. $this->_addfield('text', $name, $x, $y, $w, $h, $prop);
  12131. return;
  12132. }
  12133. // get default style
  12134. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12135. // get annotation data
  12136. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12137. // set default appearance stream
  12138. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12139. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12140. $popt['da'] = $fontstyle;
  12141. // build appearance stream
  12142. $popt['ap'] = array();
  12143. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12144. $text = '';
  12145. if (isset($prop['value']) AND !empty($prop['value'])) {
  12146. $text = $prop['value'];
  12147. } elseif (isset($opt['v']) AND !empty($opt['v'])) {
  12148. $text = $opt['v'];
  12149. }
  12150. $tmpid = $this->startTemplate($w, $h, false);
  12151. $align = '';
  12152. if (isset($popt['q'])) {
  12153. switch ($popt['q']) {
  12154. case 0: {
  12155. $align = 'L';
  12156. break;
  12157. }
  12158. case 1: {
  12159. $align = 'C';
  12160. break;
  12161. }
  12162. case 2: {
  12163. $align = 'R';
  12164. break;
  12165. }
  12166. default: {
  12167. $align = '';
  12168. break;
  12169. }
  12170. }
  12171. }
  12172. $this->MultiCell($w, $h, $text, 0, $align, false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  12173. $this->endTemplate();
  12174. --$this->n;
  12175. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12176. unset($this->xobjects[$tmpid]);
  12177. $popt['ap']['n'] .= 'Q EMC';
  12178. // merge options
  12179. $opt = array_merge($popt, $opt);
  12180. // remove some conflicting options
  12181. unset($opt['bs']);
  12182. // set remaining annotation data
  12183. $opt['Subtype'] = 'Widget';
  12184. $opt['ft'] = 'Tx';
  12185. $opt['t'] = $name;
  12186. // Additional annotation's parameters (check _putannotsobj() method):
  12187. //$opt['f']
  12188. //$opt['as']
  12189. //$opt['bs']
  12190. //$opt['be']
  12191. //$opt['c']
  12192. //$opt['border']
  12193. //$opt['h']
  12194. //$opt['mk'];
  12195. //$opt['mk']['r']
  12196. //$opt['mk']['bc'];
  12197. //$opt['mk']['bg'];
  12198. unset($opt['mk']['ca']);
  12199. unset($opt['mk']['rc']);
  12200. unset($opt['mk']['ac']);
  12201. unset($opt['mk']['i']);
  12202. unset($opt['mk']['ri']);
  12203. unset($opt['mk']['ix']);
  12204. unset($opt['mk']['if']);
  12205. //$opt['mk']['if']['sw'];
  12206. //$opt['mk']['if']['s'];
  12207. //$opt['mk']['if']['a'];
  12208. //$opt['mk']['if']['fb'];
  12209. unset($opt['mk']['tp']);
  12210. //$opt['tu']
  12211. //$opt['tm']
  12212. //$opt['ff']
  12213. //$opt['v']
  12214. //$opt['dv']
  12215. //$opt['a']
  12216. //$opt['aa']
  12217. //$opt['q']
  12218. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12219. if ($this->rtl) {
  12220. $this->x -= $w;
  12221. } else {
  12222. $this->x += $w;
  12223. }
  12224. }
  12225. /**
  12226. * Creates a RadioButton field.
  12227. * @param $name (string) Field name.
  12228. * @param $w (int) Width of the radio button.
  12229. * @param $prop (array) Javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12230. * @param $opt (array) Annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12231. * @param $onvalue (string) Value to be returned if selected.
  12232. * @param $checked (boolean) Define the initial state.
  12233. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12234. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12235. * @param $js (boolean) If true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12236. * @public
  12237. * @author Nicola Asuni
  12238. * @since 4.8.000 (2009-09-07)
  12239. */
  12240. public function RadioButton($name, $w, $prop=array(), $opt=array(), $onvalue='On', $checked=false, $x='', $y='', $js=false) {
  12241. if ($x === '') {
  12242. $x = $this->x;
  12243. }
  12244. if ($y === '') {
  12245. $y = $this->y;
  12246. }
  12247. // check page for no-write regions and adapt page margins if necessary
  12248. list($x, $y) = $this->checkPageRegions($w, $x, $y);
  12249. if ($js) {
  12250. $this->_addfield('radiobutton', $name, $x, $y, $w, $w, $prop);
  12251. return;
  12252. }
  12253. if (TCPDF_STATIC::empty_string($onvalue)) {
  12254. $onvalue = 'On';
  12255. }
  12256. if ($checked) {
  12257. $defval = $onvalue;
  12258. } else {
  12259. $defval = 'Off';
  12260. }
  12261. // set font
  12262. $font = 'zapfdingbats';
  12263. if ($this->pdfa_mode) {
  12264. // all fonts must be embedded
  12265. $font = 'pdfa'.$font;
  12266. }
  12267. $this->AddFont($font);
  12268. $tmpfont = $this->getFontBuffer($font);
  12269. // set data for parent group
  12270. if (!isset($this->radiobutton_groups[$this->page])) {
  12271. $this->radiobutton_groups[$this->page] = array();
  12272. }
  12273. if (!isset($this->radiobutton_groups[$this->page][$name])) {
  12274. $this->radiobutton_groups[$this->page][$name] = array();
  12275. ++$this->n;
  12276. $this->radiobutton_groups[$this->page][$name]['n'] = $this->n;
  12277. $this->radio_groups[] = $this->n;
  12278. }
  12279. $kid = ($this->n + 1);
  12280. // save object ID to be added on Kids entry on parent object
  12281. $this->radiobutton_groups[$this->page][$name][] = array('kid' => $kid, 'def' => $defval);
  12282. // get default style
  12283. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12284. $prop['NoToggleToOff'] = 'true';
  12285. $prop['Radio'] = 'true';
  12286. $prop['borderStyle'] = 'inset';
  12287. // get annotation data
  12288. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12289. // set additional default options
  12290. $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  12291. $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
  12292. $popt['da'] = $fontstyle;
  12293. // build appearance stream
  12294. $popt['ap'] = array();
  12295. $popt['ap']['n'] = array();
  12296. $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][108])) / 2) * $this->k);
  12297. $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k);
  12298. $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);
  12299. $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);
  12300. if (!isset($popt['mk'])) {
  12301. $popt['mk'] = array();
  12302. }
  12303. $popt['mk']['ca'] = '(l)';
  12304. // merge options
  12305. $opt = array_merge($popt, $opt);
  12306. // set remaining annotation data
  12307. $opt['Subtype'] = 'Widget';
  12308. $opt['ft'] = 'Btn';
  12309. if ($checked) {
  12310. $opt['v'] = array('/'.$onvalue);
  12311. $opt['as'] = $onvalue;
  12312. } else {
  12313. $opt['as'] = 'Off';
  12314. }
  12315. // store readonly flag
  12316. if (!isset($this->radiobutton_groups[$this->page][$name]['#readonly#'])) {
  12317. $this->radiobutton_groups[$this->page][$name]['#readonly#'] = false;
  12318. }
  12319. $this->radiobutton_groups[$this->page][$name]['#readonly#'] |= ($opt['f'] & 64);
  12320. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  12321. if ($this->rtl) {
  12322. $this->x -= $w;
  12323. } else {
  12324. $this->x += $w;
  12325. }
  12326. }
  12327. /**
  12328. * Creates a List-box field
  12329. * @param $name (string) field name
  12330. * @param $w (int) width
  12331. * @param $h (int) height
  12332. * @param $values (array) array containing the list of values.
  12333. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12334. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12335. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12336. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12337. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12338. * @public
  12339. * @author Nicola Asuni
  12340. * @since 4.8.000 (2009-09-07)
  12341. */
  12342. public function ListBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  12343. if ($x === '') {
  12344. $x = $this->x;
  12345. }
  12346. if ($y === '') {
  12347. $y = $this->y;
  12348. }
  12349. // check page for no-write regions and adapt page margins if necessary
  12350. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12351. if ($js) {
  12352. $this->_addfield('listbox', $name, $x, $y, $w, $h, $prop);
  12353. $s = '';
  12354. foreach ($values as $value) {
  12355. if (is_array($value)) {
  12356. $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
  12357. } else {
  12358. $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
  12359. }
  12360. }
  12361. $this->javascript .= 'f'.$name.'.setItems('.substr($s, 1).');'."\n";
  12362. return;
  12363. }
  12364. // get default style
  12365. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12366. // get annotation data
  12367. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12368. // set additional default values
  12369. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12370. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12371. $popt['da'] = $fontstyle;
  12372. // build appearance stream
  12373. $popt['ap'] = array();
  12374. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12375. $text = '';
  12376. foreach($values as $item) {
  12377. if (is_array($item)) {
  12378. $text .= $item[1]."\n";
  12379. } else {
  12380. $text .= $item."\n";
  12381. }
  12382. }
  12383. $tmpid = $this->startTemplate($w, $h, false);
  12384. $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  12385. $this->endTemplate();
  12386. --$this->n;
  12387. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12388. unset($this->xobjects[$tmpid]);
  12389. $popt['ap']['n'] .= 'Q EMC';
  12390. // merge options
  12391. $opt = array_merge($popt, $opt);
  12392. // set remaining annotation data
  12393. $opt['Subtype'] = 'Widget';
  12394. $opt['ft'] = 'Ch';
  12395. $opt['t'] = $name;
  12396. $opt['opt'] = $values;
  12397. unset($opt['mk']['ca']);
  12398. unset($opt['mk']['rc']);
  12399. unset($opt['mk']['ac']);
  12400. unset($opt['mk']['i']);
  12401. unset($opt['mk']['ri']);
  12402. unset($opt['mk']['ix']);
  12403. unset($opt['mk']['if']);
  12404. unset($opt['mk']['tp']);
  12405. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12406. if ($this->rtl) {
  12407. $this->x -= $w;
  12408. } else {
  12409. $this->x += $w;
  12410. }
  12411. }
  12412. /**
  12413. * Creates a Combo-box field
  12414. * @param $name (string) field name
  12415. * @param $w (int) width
  12416. * @param $h (int) height
  12417. * @param $values (array) array containing the list of values.
  12418. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12419. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12420. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12421. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12422. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12423. * @public
  12424. * @author Nicola Asuni
  12425. * @since 4.8.000 (2009-09-07)
  12426. */
  12427. public function ComboBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  12428. if ($x === '') {
  12429. $x = $this->x;
  12430. }
  12431. if ($y === '') {
  12432. $y = $this->y;
  12433. }
  12434. // check page for no-write regions and adapt page margins if necessary
  12435. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12436. if ($js) {
  12437. $this->_addfield('combobox', $name, $x, $y, $w, $h, $prop);
  12438. $s = '';
  12439. foreach ($values as $value) {
  12440. if (is_array($value)) {
  12441. $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
  12442. } else {
  12443. $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
  12444. }
  12445. }
  12446. $this->javascript .= 'f'.$name.'.setItems('.substr($s, 1).');'."\n";
  12447. return;
  12448. }
  12449. // get default style
  12450. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12451. $prop['Combo'] = true;
  12452. // get annotation data
  12453. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12454. // set additional default options
  12455. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12456. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12457. $popt['da'] = $fontstyle;
  12458. // build appearance stream
  12459. $popt['ap'] = array();
  12460. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12461. $text = '';
  12462. foreach($values as $item) {
  12463. if (is_array($item)) {
  12464. $text .= $item[1]."\n";
  12465. } else {
  12466. $text .= $item."\n";
  12467. }
  12468. }
  12469. $tmpid = $this->startTemplate($w, $h, false);
  12470. $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  12471. $this->endTemplate();
  12472. --$this->n;
  12473. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12474. unset($this->xobjects[$tmpid]);
  12475. $popt['ap']['n'] .= 'Q EMC';
  12476. // merge options
  12477. $opt = array_merge($popt, $opt);
  12478. // set remaining annotation data
  12479. $opt['Subtype'] = 'Widget';
  12480. $opt['ft'] = 'Ch';
  12481. $opt['t'] = $name;
  12482. $opt['opt'] = $values;
  12483. unset($opt['mk']['ca']);
  12484. unset($opt['mk']['rc']);
  12485. unset($opt['mk']['ac']);
  12486. unset($opt['mk']['i']);
  12487. unset($opt['mk']['ri']);
  12488. unset($opt['mk']['ix']);
  12489. unset($opt['mk']['if']);
  12490. unset($opt['mk']['tp']);
  12491. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12492. if ($this->rtl) {
  12493. $this->x -= $w;
  12494. } else {
  12495. $this->x += $w;
  12496. }
  12497. }
  12498. /**
  12499. * Creates a CheckBox field
  12500. * @param $name (string) field name
  12501. * @param $w (int) width
  12502. * @param $checked (boolean) define the initial state.
  12503. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12504. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12505. * @param $onvalue (string) value to be returned if selected.
  12506. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12507. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12508. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12509. * @public
  12510. * @author Nicola Asuni
  12511. * @since 4.8.000 (2009-09-07)
  12512. */
  12513. public function CheckBox($name, $w, $checked=false, $prop=array(), $opt=array(), $onvalue='Yes', $x='', $y='', $js=false) {
  12514. if ($x === '') {
  12515. $x = $this->x;
  12516. }
  12517. if ($y === '') {
  12518. $y = $this->y;
  12519. }
  12520. // check page for no-write regions and adapt page margins if necessary
  12521. list($x, $y) = $this->checkPageRegions($w, $x, $y);
  12522. if ($js) {
  12523. $this->_addfield('checkbox', $name, $x, $y, $w, $w, $prop);
  12524. return;
  12525. }
  12526. if (!isset($prop['value'])) {
  12527. $prop['value'] = array('Yes');
  12528. }
  12529. // get default style
  12530. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12531. $prop['borderStyle'] = 'inset';
  12532. // get annotation data
  12533. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12534. // set additional default options
  12535. $font = 'zapfdingbats';
  12536. if ($this->pdfa_mode) {
  12537. // all fonts must be embedded
  12538. $font = 'pdfa'.$font;
  12539. }
  12540. $this->AddFont($font);
  12541. $tmpfont = $this->getFontBuffer($font);
  12542. $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  12543. $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
  12544. $popt['da'] = $fontstyle;
  12545. // build appearance stream
  12546. $popt['ap'] = array();
  12547. $popt['ap']['n'] = array();
  12548. $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][110])) / 2) * $this->k);
  12549. $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k);
  12550. $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);
  12551. $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);
  12552. // merge options
  12553. $opt = array_merge($popt, $opt);
  12554. // set remaining annotation data
  12555. $opt['Subtype'] = 'Widget';
  12556. $opt['ft'] = 'Btn';
  12557. $opt['t'] = $name;
  12558. if (TCPDF_STATIC::empty_string($onvalue)) {
  12559. $onvalue = 'Yes';
  12560. }
  12561. $opt['opt'] = array($onvalue);
  12562. if ($checked) {
  12563. $opt['v'] = array('/Yes');
  12564. $opt['as'] = 'Yes';
  12565. } else {
  12566. $opt['v'] = array('/Off');
  12567. $opt['as'] = 'Off';
  12568. }
  12569. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  12570. if ($this->rtl) {
  12571. $this->x -= $w;
  12572. } else {
  12573. $this->x += $w;
  12574. }
  12575. }
  12576. /**
  12577. * Creates a button field
  12578. * @param $name (string) field name
  12579. * @param $w (int) width
  12580. * @param $h (int) height
  12581. * @param $caption (string) caption.
  12582. * @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.
  12583. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12584. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12585. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12586. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12587. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12588. * @public
  12589. * @author Nicola Asuni
  12590. * @since 4.8.000 (2009-09-07)
  12591. */
  12592. public function Button($name, $w, $h, $caption, $action, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  12593. if ($x === '') {
  12594. $x = $this->x;
  12595. }
  12596. if ($y === '') {
  12597. $y = $this->y;
  12598. }
  12599. // check page for no-write regions and adapt page margins if necessary
  12600. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12601. if ($js) {
  12602. $this->_addfield('button', $name, $this->x, $this->y, $w, $h, $prop);
  12603. $this->javascript .= 'f'.$name.".buttonSetCaption('".addslashes($caption)."');\n";
  12604. $this->javascript .= 'f'.$name.".setAction('MouseUp','".addslashes($action)."');\n";
  12605. $this->javascript .= 'f'.$name.".highlight='push';\n";
  12606. $this->javascript .= 'f'.$name.".print=false;\n";
  12607. return;
  12608. }
  12609. // get default style
  12610. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12611. $prop['Pushbutton'] = 'true';
  12612. $prop['highlight'] = 'push';
  12613. $prop['display'] = 'display.noPrint';
  12614. // get annotation data
  12615. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12616. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12617. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12618. $popt['da'] = $fontstyle;
  12619. // build appearance stream
  12620. $popt['ap'] = array();
  12621. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12622. $tmpid = $this->startTemplate($w, $h, false);
  12623. $bw = (2 / $this->k); // border width
  12624. $border = array(
  12625. 'L' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
  12626. 'R' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)),
  12627. 'T' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
  12628. 'B' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)));
  12629. $this->SetFillColor(204);
  12630. $this->Cell($w, $h, $caption, $border, 0, 'C', true, '', 1, false, 'T', 'M');
  12631. $this->endTemplate();
  12632. --$this->n;
  12633. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12634. unset($this->xobjects[$tmpid]);
  12635. $popt['ap']['n'] .= 'Q EMC';
  12636. // set additional default options
  12637. if (!isset($popt['mk'])) {
  12638. $popt['mk'] = array();
  12639. }
  12640. $ann_obj_id = ($this->n + 1);
  12641. if (!empty($action) AND !is_array($action)) {
  12642. $ann_obj_id = ($this->n + 2);
  12643. }
  12644. $popt['mk']['ca'] = $this->_textstring($caption, $ann_obj_id);
  12645. $popt['mk']['rc'] = $this->_textstring($caption, $ann_obj_id);
  12646. $popt['mk']['ac'] = $this->_textstring($caption, $ann_obj_id);
  12647. // merge options
  12648. $opt = array_merge($popt, $opt);
  12649. // set remaining annotation data
  12650. $opt['Subtype'] = 'Widget';
  12651. $opt['ft'] = 'Btn';
  12652. $opt['t'] = $caption;
  12653. $opt['v'] = $name;
  12654. if (!empty($action)) {
  12655. if (is_array($action)) {
  12656. // form action options as on section 12.7.5 of PDF32000_2008.
  12657. $opt['aa'] = '/D <<';
  12658. $bmode = array('SubmitForm', 'ResetForm', 'ImportData');
  12659. foreach ($action AS $key => $val) {
  12660. if (($key == 'S') AND in_array($val, $bmode)) {
  12661. $opt['aa'] .= ' /S /'.$val;
  12662. } elseif (($key == 'F') AND (!empty($val))) {
  12663. $opt['aa'] .= ' /F '.$this->_datastring($val, $ann_obj_id);
  12664. } elseif (($key == 'Fields') AND is_array($val) AND !empty($val)) {
  12665. $opt['aa'] .= ' /Fields [';
  12666. foreach ($val AS $field) {
  12667. $opt['aa'] .= ' '.$this->_textstring($field, $ann_obj_id);
  12668. }
  12669. $opt['aa'] .= ']';
  12670. } elseif (($key == 'Flags')) {
  12671. $ff = 0;
  12672. if (is_array($val)) {
  12673. foreach ($val AS $flag) {
  12674. switch ($flag) {
  12675. case 'Include/Exclude': {
  12676. $ff += 1 << 0;
  12677. break;
  12678. }
  12679. case 'IncludeNoValueFields': {
  12680. $ff += 1 << 1;
  12681. break;
  12682. }
  12683. case 'ExportFormat': {
  12684. $ff += 1 << 2;
  12685. break;
  12686. }
  12687. case 'GetMethod': {
  12688. $ff += 1 << 3;
  12689. break;
  12690. }
  12691. case 'SubmitCoordinates': {
  12692. $ff += 1 << 4;
  12693. break;
  12694. }
  12695. case 'XFDF': {
  12696. $ff += 1 << 5;
  12697. break;
  12698. }
  12699. case 'IncludeAppendSaves': {
  12700. $ff += 1 << 6;
  12701. break;
  12702. }
  12703. case 'IncludeAnnotations': {
  12704. $ff += 1 << 7;
  12705. break;
  12706. }
  12707. case 'SubmitPDF': {
  12708. $ff += 1 << 8;
  12709. break;
  12710. }
  12711. case 'CanonicalFormat': {
  12712. $ff += 1 << 9;
  12713. break;
  12714. }
  12715. case 'ExclNonUserAnnots': {
  12716. $ff += 1 << 10;
  12717. break;
  12718. }
  12719. case 'ExclFKey': {
  12720. $ff += 1 << 11;
  12721. break;
  12722. }
  12723. case 'EmbedForm': {
  12724. $ff += 1 << 13;
  12725. break;
  12726. }
  12727. }
  12728. }
  12729. } else {
  12730. $ff = intval($val);
  12731. }
  12732. $opt['aa'] .= ' /Flags '.$ff;
  12733. }
  12734. }
  12735. $opt['aa'] .= ' >>';
  12736. } else {
  12737. // Javascript action or raw action command
  12738. $js_obj_id = $this->addJavascriptObject($action);
  12739. $opt['aa'] = '/D '.$js_obj_id.' 0 R';
  12740. }
  12741. }
  12742. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12743. if ($this->rtl) {
  12744. $this->x -= $w;
  12745. } else {
  12746. $this->x += $w;
  12747. }
  12748. }
  12749. // --- END FORMS FIELDS ------------------------------------------------
  12750. /**
  12751. * Add certification signature (DocMDP or UR3)
  12752. * You can set only one signature type
  12753. * @protected
  12754. * @author Nicola Asuni
  12755. * @since 4.6.008 (2009-05-07)
  12756. */
  12757. protected function _putsignature() {
  12758. if ((!$this->sign) OR (!isset($this->signature_data['cert_type']))) {
  12759. return;
  12760. }
  12761. $sigobjid = ($this->sig_obj_id + 1);
  12762. $out = $this->_getobj($sigobjid)."\n";
  12763. $out .= '<< /Type /Sig';
  12764. $out .= ' /Filter /Adobe.PPKLite';
  12765. $out .= ' /SubFilter /adbe.pkcs7.detached';
  12766. $out .= ' '.TCPDF_STATIC::$byterange_string;
  12767. $out .= ' /Contents<'.str_repeat('0', $this->signature_max_length).'>';
  12768. $out .= ' /Reference ['; // array of signature reference dictionaries
  12769. $out .= ' << /Type /SigRef';
  12770. if ($this->signature_data['cert_type'] > 0) {
  12771. $out .= ' /TransformMethod /DocMDP';
  12772. $out .= ' /TransformParams <<';
  12773. $out .= ' /Type /TransformParams';
  12774. $out .= ' /P '.$this->signature_data['cert_type'];
  12775. $out .= ' /V /1.2';
  12776. } else {
  12777. $out .= ' /TransformMethod /UR3';
  12778. $out .= ' /TransformParams <<';
  12779. $out .= ' /Type /TransformParams';
  12780. $out .= ' /V /2.2';
  12781. if (!TCPDF_STATIC::empty_string($this->ur['document'])) {
  12782. $out .= ' /Document['.$this->ur['document'].']';
  12783. }
  12784. if (!TCPDF_STATIC::empty_string($this->ur['form'])) {
  12785. $out .= ' /Form['.$this->ur['form'].']';
  12786. }
  12787. if (!TCPDF_STATIC::empty_string($this->ur['signature'])) {
  12788. $out .= ' /Signature['.$this->ur['signature'].']';
  12789. }
  12790. if (!TCPDF_STATIC::empty_string($this->ur['annots'])) {
  12791. $out .= ' /Annots['.$this->ur['annots'].']';
  12792. }
  12793. if (!TCPDF_STATIC::empty_string($this->ur['ef'])) {
  12794. $out .= ' /EF['.$this->ur['ef'].']';
  12795. }
  12796. if (!TCPDF_STATIC::empty_string($this->ur['formex'])) {
  12797. $out .= ' /FormEX['.$this->ur['formex'].']';
  12798. }
  12799. }
  12800. $out .= ' >>'; // close TransformParams
  12801. // optional digest data (values must be calculated and replaced later)
  12802. //$out .= ' /Data ********** 0 R';
  12803. //$out .= ' /DigestMethod/MD5';
  12804. //$out .= ' /DigestLocation[********** 34]';
  12805. //$out .= ' /DigestValue<********************************>';
  12806. $out .= ' >>';
  12807. $out .= ' ]'; // end of reference
  12808. if (isset($this->signature_data['info']['Name']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Name'])) {
  12809. $out .= ' /Name '.$this->_textstring($this->signature_data['info']['Name'], $sigobjid);
  12810. }
  12811. if (isset($this->signature_data['info']['Location']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Location'])) {
  12812. $out .= ' /Location '.$this->_textstring($this->signature_data['info']['Location'], $sigobjid);
  12813. }
  12814. if (isset($this->signature_data['info']['Reason']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Reason'])) {
  12815. $out .= ' /Reason '.$this->_textstring($this->signature_data['info']['Reason'], $sigobjid);
  12816. }
  12817. if (isset($this->signature_data['info']['ContactInfo']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['ContactInfo'])) {
  12818. $out .= ' /ContactInfo '.$this->_textstring($this->signature_data['info']['ContactInfo'], $sigobjid);
  12819. }
  12820. $out .= ' /M '.$this->_datestring($sigobjid, $this->doc_modification_timestamp);
  12821. $out .= ' >>';
  12822. $out .= "\n".'endobj';
  12823. $this->_out($out);
  12824. }
  12825. /**
  12826. * Set User's Rights for PDF Reader
  12827. * WARNING: This is experimental and currently do not work.
  12828. * Check the PDF Reference 8.7.1 Transform Methods,
  12829. * Table 8.105 Entries in the UR transform parameters dictionary
  12830. * @param $enable (boolean) if true enable user's rights on PDF reader
  12831. * @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.
  12832. * @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.
  12833. * @param $form (string) Names specifying additional form-field-related usage rights for the document. Valid names are: /Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate
  12834. * @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.
  12835. * @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
  12836. Names specifying additional embedded-files-related usage rights for the document.
  12837. * @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.
  12838. * @public
  12839. * @author Nicola Asuni
  12840. * @since 2.9.000 (2008-03-26)
  12841. */
  12842. public function setUserRights(
  12843. $enable=true,
  12844. $document='/FullSave',
  12845. $annots='/Create/Delete/Modify/Copy/Import/Export',
  12846. $form='/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate',
  12847. $signature='/Modify',
  12848. $ef='/Create/Delete/Modify/Import',
  12849. $formex='') {
  12850. $this->ur['enabled'] = $enable;
  12851. $this->ur['document'] = $document;
  12852. $this->ur['annots'] = $annots;
  12853. $this->ur['form'] = $form;
  12854. $this->ur['signature'] = $signature;
  12855. $this->ur['ef'] = $ef;
  12856. $this->ur['formex'] = $formex;
  12857. if (!$this->sign) {
  12858. $this->setSignature('', '', '', '', 0, array());
  12859. }
  12860. }
  12861. /**
  12862. * Enable document signature (requires the OpenSSL Library).
  12863. * The digital signature improve document authenticity and integrity and allows o enable extra features on Acrobat Reader.
  12864. * To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  12865. * To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  12866. * To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
  12867. * @param $signing_cert (mixed) signing certificate (string or filename prefixed with 'file://')
  12868. * @param $private_key (mixed) private key (string or filename prefixed with 'file://')
  12869. * @param $private_key_password (string) password
  12870. * @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.
  12871. * @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.
  12872. * @param $info (array) array of option information: Name, Location, Reason, ContactInfo.
  12873. * @public
  12874. * @author Nicola Asuni
  12875. * @since 4.6.005 (2009-04-24)
  12876. */
  12877. public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array()) {
  12878. // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  12879. // to export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  12880. // to convert pfx certificate to pem: openssl
  12881. // OpenSSL> pkcs12 -in <cert.pfx> -out <cert.crt> -nodes
  12882. $this->sign = true;
  12883. ++$this->n;
  12884. $this->sig_obj_id = $this->n; // signature widget
  12885. ++$this->n; // signature object ($this->sig_obj_id + 1)
  12886. $this->signature_data = array();
  12887. if (strlen($signing_cert) == 0) {
  12888. $this->Error('Please provide a certificate file and password!');
  12889. }
  12890. if (strlen($private_key) == 0) {
  12891. $private_key = $signing_cert;
  12892. }
  12893. $this->signature_data['signcert'] = $signing_cert;
  12894. $this->signature_data['privkey'] = $private_key;
  12895. $this->signature_data['password'] = $private_key_password;
  12896. $this->signature_data['extracerts'] = $extracerts;
  12897. $this->signature_data['cert_type'] = $cert_type;
  12898. $this->signature_data['info'] = $info;
  12899. }
  12900. /**
  12901. * Set the digital signature appearance (a cliccable rectangle area to get signature properties)
  12902. * @param $x (float) Abscissa of the upper-left corner.
  12903. * @param $y (float) Ordinate of the upper-left corner.
  12904. * @param $w (float) Width of the signature area.
  12905. * @param $h (float) Height of the signature area.
  12906. * @param $page (int) option page number (if < 0 the current page is used).
  12907. * @param $name (string) Name of the signature.
  12908. * @public
  12909. * @author Nicola Asuni
  12910. * @since 5.3.011 (2010-06-17)
  12911. */
  12912. public function setSignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
  12913. $this->signature_appearance = $this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name);
  12914. }
  12915. /**
  12916. * Add an empty digital signature appearance (a cliccable rectangle area to get signature properties)
  12917. * @param $x (float) Abscissa of the upper-left corner.
  12918. * @param $y (float) Ordinate of the upper-left corner.
  12919. * @param $w (float) Width of the signature area.
  12920. * @param $h (float) Height of the signature area.
  12921. * @param $page (int) option page number (if < 0 the current page is used).
  12922. * @param $name (string) Name of the signature.
  12923. * @public
  12924. * @author Nicola Asuni
  12925. * @since 5.9.101 (2011-07-06)
  12926. */
  12927. public function addEmptySignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
  12928. ++$this->n;
  12929. $this->empty_signature_appearance[] = array('objid' => $this->n) + $this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name);
  12930. }
  12931. /**
  12932. * Get the array that defines the signature appearance (page and rectangle coordinates).
  12933. * @param $x (float) Abscissa of the upper-left corner.
  12934. * @param $y (float) Ordinate of the upper-left corner.
  12935. * @param $w (float) Width of the signature area.
  12936. * @param $h (float) Height of the signature area.
  12937. * @param $page (int) option page number (if < 0 the current page is used).
  12938. * @param $name (string) Name of the signature.
  12939. * @return (array) Array defining page and rectangle coordinates of signature appearance.
  12940. * @protected
  12941. * @author Nicola Asuni
  12942. * @since 5.9.101 (2011-07-06)
  12943. */
  12944. protected function getSignatureAppearanceArray($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
  12945. $sigapp = array();
  12946. if (($page < 1) OR ($page > $this->numpages)) {
  12947. $sigapp['page'] = $this->page;
  12948. } else {
  12949. $sigapp['page'] = intval($page);
  12950. }
  12951. if (empty($name)) {
  12952. $sigapp['name'] = 'Signature';
  12953. } else {
  12954. $sigapp['name'] = $name;
  12955. }
  12956. $a = $x * $this->k;
  12957. $b = $this->pagedim[($sigapp['page'])]['h'] - (($y + $h) * $this->k);
  12958. $c = $w * $this->k;
  12959. $d = $h * $this->k;
  12960. $sigapp['rect'] = sprintf('%F %F %F %F', $a, $b, ($a + $c), ($b + $d));
  12961. return $sigapp;
  12962. }
  12963. /**
  12964. * Create a new page group.
  12965. * NOTE: call this function before calling AddPage()
  12966. * @param $page (int) starting group page (leave empty for next page).
  12967. * @public
  12968. * @since 3.0.000 (2008-03-27)
  12969. */
  12970. public function startPageGroup($page='') {
  12971. if (empty($page)) {
  12972. $page = $this->page + 1;
  12973. }
  12974. $this->newpagegroup[$page] = sizeof($this->newpagegroup) + 1;
  12975. }
  12976. /**
  12977. * Set the starting page number.
  12978. * @param $num (int) Starting page number.
  12979. * @since 5.9.093 (2011-06-16)
  12980. * @public
  12981. */
  12982. public function setStartingPageNumber($num=1) {
  12983. $this->starting_page_number = max(0, intval($num));
  12984. }
  12985. /**
  12986. * Returns the string alias used right align page numbers.
  12987. * If the current font is unicode type, the returned string wil contain an additional open curly brace.
  12988. * @return string
  12989. * @since 5.9.099 (2011-06-27)
  12990. * @public
  12991. */
  12992. public function getAliasRightShift() {
  12993. // calculate aproximatively the ratio between widths of aliases and replacements.
  12994. $ref = '{'.TCPDF_STATIC::$alias_right_shift.'}{'.TCPDF_STATIC::$alias_tot_pages.'}{'.TCPDF_STATIC::$alias_num_page.'}';
  12995. $rep = str_repeat(' ', $this->GetNumChars($ref));
  12996. $wrep = $this->GetStringWidth($rep);
  12997. if ($wrep > 0) {
  12998. $wdiff = max(1, ($this->GetStringWidth($ref) / $wrep));
  12999. } else {
  13000. $wdiff = 1;
  13001. }
  13002. $sdiff = sprintf('%F', $wdiff);
  13003. $alias = TCPDF_STATIC::$alias_right_shift.$sdiff.'}';
  13004. if ($this->isUnicodeFont()) {
  13005. $alias = '{'.$alias;
  13006. }
  13007. return $alias;
  13008. }
  13009. /**
  13010. * Returns the string alias used for the total number of pages.
  13011. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13012. * This alias will be replaced by the total number of pages in the document.
  13013. * @return string
  13014. * @since 4.0.018 (2008-08-08)
  13015. * @public
  13016. */
  13017. public function getAliasNbPages() {
  13018. if ($this->isUnicodeFont()) {
  13019. return '{'.TCPDF_STATIC::$alias_tot_pages.'}';
  13020. }
  13021. return TCPDF_STATIC::$alias_tot_pages;
  13022. }
  13023. /**
  13024. * Returns the string alias used for the page number.
  13025. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13026. * This alias will be replaced by the page number.
  13027. * @return string
  13028. * @since 4.5.000 (2009-01-02)
  13029. * @public
  13030. */
  13031. public function getAliasNumPage() {
  13032. if ($this->isUnicodeFont()) {
  13033. return '{'.TCPDF_STATIC::$alias_num_page.'}';
  13034. }
  13035. return TCPDF_STATIC::$alias_num_page;
  13036. }
  13037. /**
  13038. * Return the alias for the total number of pages in the current page group.
  13039. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13040. * This alias will be replaced by the total number of pages in this group.
  13041. * @return alias of the current page group
  13042. * @public
  13043. * @since 3.0.000 (2008-03-27)
  13044. */
  13045. public function getPageGroupAlias() {
  13046. if ($this->isUnicodeFont()) {
  13047. return '{'.TCPDF_STATIC::$alias_group_tot_pages.'}';
  13048. }
  13049. return TCPDF_STATIC::$alias_group_tot_pages;
  13050. }
  13051. /**
  13052. * Return the alias for the page number on the current page group.
  13053. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13054. * This alias will be replaced by the page number (relative to the belonging group).
  13055. * @return alias of the current page group
  13056. * @public
  13057. * @since 4.5.000 (2009-01-02)
  13058. */
  13059. public function getPageNumGroupAlias() {
  13060. if ($this->isUnicodeFont()) {
  13061. return '{'.TCPDF_STATIC::$alias_group_num_page.'}';
  13062. }
  13063. return TCPDF_STATIC::$alias_group_num_page;
  13064. }
  13065. /**
  13066. * Return the current page in the group.
  13067. * @return current page in the group
  13068. * @public
  13069. * @since 3.0.000 (2008-03-27)
  13070. */
  13071. public function getGroupPageNo() {
  13072. return $this->pagegroups[$this->currpagegroup];
  13073. }
  13074. /**
  13075. * Returns the current group page number formatted as a string.
  13076. * @public
  13077. * @since 4.3.003 (2008-11-18)
  13078. * @see PaneNo(), formatPageNumber()
  13079. */
  13080. public function getGroupPageNoFormatted() {
  13081. return TCPDF_STATIC::formatPageNumber($this->getGroupPageNo());
  13082. }
  13083. /**
  13084. * Returns the current page number formatted as a string.
  13085. * @public
  13086. * @since 4.2.005 (2008-11-06)
  13087. * @see PaneNo(), formatPageNumber()
  13088. */
  13089. public function PageNoFormatted() {
  13090. return TCPDF_STATIC::formatPageNumber($this->PageNo());
  13091. }
  13092. /**
  13093. * Put pdf layers.
  13094. * @protected
  13095. * @since 3.0.000 (2008-03-27)
  13096. */
  13097. protected function _putocg() {
  13098. if (empty($this->pdflayers)) {
  13099. return;
  13100. }
  13101. foreach ($this->pdflayers as $key => $layer) {
  13102. $this->pdflayers[$key]['objid'] = $this->_newobj();
  13103. $out = '<< /Type /OCG';
  13104. $out .= ' /Name '.$this->_textstring($layer['name'], $this->pdflayers[$key]['objid']);
  13105. $out .= ' /Usage <<';
  13106. $out .= ' /Print <</PrintState /'.($layer['print']?'ON':'OFF').'>>';
  13107. $out .= ' /View <</ViewState /'.($layer['view']?'ON':'OFF').'>>';
  13108. $out .= ' >> >>';
  13109. $out .= "\n".'endobj';
  13110. $this->_out($out);
  13111. }
  13112. }
  13113. /**
  13114. * Start a new pdf layer.
  13115. * @param $name (string) Layer name (only a-z letters and numbers). Leave empty for automatic name.
  13116. * @param $print (boolean) Set to true to print this layer.
  13117. * @param $view (boolean) Set to true to view this layer.
  13118. * @public
  13119. * @since 5.9.102 (2011-07-13)
  13120. */
  13121. public function startLayer($name='', $print=true, $view=true) {
  13122. if ($this->state != 2) {
  13123. return;
  13124. }
  13125. $layer = sprintf('LYR%03d', (count($this->pdflayers) + 1));
  13126. if (empty($name)) {
  13127. $name = $layer;
  13128. } else {
  13129. $name = preg_replace('/[^a-zA-Z0-9_\-]/', '', $name);
  13130. }
  13131. $this->pdflayers[] = array('layer' => $layer, 'name' => $name, 'print' => $print, 'view' => $view);
  13132. $this->openMarkedContent = true;
  13133. $this->_out('/OC /'.$layer.' BDC');
  13134. }
  13135. /**
  13136. * End the current PDF layer.
  13137. * @public
  13138. * @since 5.9.102 (2011-07-13)
  13139. */
  13140. public function endLayer() {
  13141. if ($this->state != 2) {
  13142. return;
  13143. }
  13144. if ($this->openMarkedContent) {
  13145. // close existing open marked-content layer
  13146. $this->_out('EMC');
  13147. $this->openMarkedContent = false;
  13148. }
  13149. }
  13150. /**
  13151. * Set the visibility of the successive elements.
  13152. * This can be useful, for instance, to put a background
  13153. * image or color that will show on screen but won't print.
  13154. * @param $v (string) visibility mode. Legal values are: all, print, screen or view.
  13155. * @public
  13156. * @since 3.0.000 (2008-03-27)
  13157. */
  13158. public function setVisibility($v) {
  13159. if ($this->state != 2) {
  13160. return;
  13161. }
  13162. $this->endLayer();
  13163. switch($v) {
  13164. case 'print': {
  13165. $this->startLayer('Print', true, false);
  13166. break;
  13167. }
  13168. case 'view':
  13169. case 'screen': {
  13170. $this->startLayer('View', false, true);
  13171. break;
  13172. }
  13173. case 'all': {
  13174. $this->_out('');
  13175. break;
  13176. }
  13177. default: {
  13178. $this->Error('Incorrect visibility: '.$v);
  13179. break;
  13180. }
  13181. }
  13182. }
  13183. /**
  13184. * Add transparency parameters to the current extgstate
  13185. * @param $parms (array) parameters
  13186. * @return the number of extgstates
  13187. * @protected
  13188. * @since 3.0.000 (2008-03-27)
  13189. */
  13190. protected function addExtGState($parms) {
  13191. if ($this->pdfa_mode) {
  13192. // transparencies are not allowed in PDF/A mode
  13193. return;
  13194. }
  13195. // check if this ExtGState already exist
  13196. foreach ($this->extgstates as $i => $ext) {
  13197. if ($ext['parms'] == $parms) {
  13198. if ($this->inxobj) {
  13199. // we are inside an XObject template
  13200. $this->xobjects[$this->xobjid]['extgstates'][$i] = $ext;
  13201. }
  13202. // return reference to existing ExtGState
  13203. return $i;
  13204. }
  13205. }
  13206. $n = (count($this->extgstates) + 1);
  13207. $this->extgstates[$n] = array('parms' => $parms);
  13208. if ($this->inxobj) {
  13209. // we are inside an XObject template
  13210. $this->xobjects[$this->xobjid]['extgstates'][$n] = $this->extgstates[$n];
  13211. }
  13212. return $n;
  13213. }
  13214. /**
  13215. * Add an extgstate
  13216. * @param $gs (array) extgstate
  13217. * @protected
  13218. * @since 3.0.000 (2008-03-27)
  13219. */
  13220. protected function setExtGState($gs) {
  13221. if ($this->pdfa_mode OR ($this->state != 2)) {
  13222. // transparency is not allowed in PDF/A mode
  13223. return;
  13224. }
  13225. $this->_out(sprintf('/GS%d gs', $gs));
  13226. }
  13227. /**
  13228. * Put extgstates for object transparency
  13229. * @protected
  13230. * @since 3.0.000 (2008-03-27)
  13231. */
  13232. protected function _putextgstates() {
  13233. foreach ($this->extgstates as $i => $ext) {
  13234. $this->extgstates[$i]['n'] = $this->_newobj();
  13235. $out = '<< /Type /ExtGState';
  13236. foreach ($ext['parms'] as $k => $v) {
  13237. if (is_float($v)) {
  13238. $v = sprintf('%F', $v);
  13239. } elseif ($v === true) {
  13240. $v = 'true';
  13241. } elseif ($v === false) {
  13242. $v = 'false';
  13243. }
  13244. $out .= ' /'.$k.' '.$v;
  13245. }
  13246. $out .= ' >>';
  13247. $out .= "\n".'endobj';
  13248. $this->_out($out);
  13249. }
  13250. }
  13251. /**
  13252. * Set overprint mode for stroking (OP) and non-stroking (op) painting operations.
  13253. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13254. * @param $stroking (boolean) If true apply overprint for stroking operations.
  13255. * @param $nonstroking (boolean) If true apply overprint for painting operations other than stroking.
  13256. * @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).
  13257. * @public
  13258. * @since 5.9.152 (2012-03-23)
  13259. */
  13260. public function setOverprint($stroking=true, $nonstroking='', $mode=0) {
  13261. if ($this->state != 2) {
  13262. return;
  13263. }
  13264. $stroking = $stroking ? true : false;
  13265. if (TCPDF_STATIC::empty_string($nonstroking)) {
  13266. // default value if not set
  13267. $nonstroking = $stroking;
  13268. } else {
  13269. $nonstroking = $nonstroking ? true : false;
  13270. }
  13271. if (($mode != 0) AND ($mode != 1)) {
  13272. $mode = 0;
  13273. }
  13274. $this->overprint = array('OP' => $stroking, 'op' => $nonstroking, 'OPM' => $mode);
  13275. $gs = $this->addExtGState($this->overprint);
  13276. $this->setExtGState($gs);
  13277. }
  13278. /**
  13279. * Get the overprint mode array (OP, op, OPM).
  13280. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13281. * @return array.
  13282. * @public
  13283. * @since 5.9.152 (2012-03-23)
  13284. */
  13285. public function getOverprint() {
  13286. return $this->overprint;
  13287. }
  13288. /**
  13289. * Set alpha for stroking (CA) and non-stroking (ca) operations.
  13290. * @param $stroking (float) Alpha value for stroking operations: real value from 0 (transparent) to 1 (opaque).
  13291. * @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
  13292. * @param $nonstroking (float) Alpha value for non-stroking operations: real value from 0 (transparent) to 1 (opaque).
  13293. * @param $ais (boolean)
  13294. * @public
  13295. * @since 3.0.000 (2008-03-27)
  13296. */
  13297. public function setAlpha($stroking=1, $bm='Normal', $nonstroking='', $ais=false) {
  13298. if ($this->pdfa_mode) {
  13299. // transparency is not allowed in PDF/A mode
  13300. return;
  13301. }
  13302. $stroking = floatval($stroking);
  13303. if (TCPDF_STATIC::empty_string($nonstroking)) {
  13304. // default value if not set
  13305. $nonstroking = $stroking;
  13306. } else {
  13307. $nonstroking = floatval($nonstroking);
  13308. }
  13309. if ($bm[0] == '/') {
  13310. // remove trailing slash
  13311. $bm = substr($bm, 1);
  13312. }
  13313. if (!in_array($bm, array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge', 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion', 'Hue', 'Saturation', 'Color', 'Luminosity'))) {
  13314. $bm = 'Normal';
  13315. }
  13316. $ais = $ais ? true : false;
  13317. $this->alpha = array('CA' => $stroking, 'ca' => $nonstroking, 'BM' => '/'.$bm, 'AIS' => $ais);
  13318. $gs = $this->addExtGState($this->alpha);
  13319. $this->setExtGState($gs);
  13320. }
  13321. /**
  13322. * Get the alpha mode array (CA, ca, BM, AIS).
  13323. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13324. * @return array.
  13325. * @public
  13326. * @since 5.9.152 (2012-03-23)
  13327. */
  13328. public function getAlpha() {
  13329. return $this->alpha;
  13330. }
  13331. /**
  13332. * Set the default JPEG compression quality (1-100)
  13333. * @param $quality (int) JPEG quality, integer between 1 and 100
  13334. * @public
  13335. * @since 3.0.000 (2008-03-27)
  13336. */
  13337. public function setJPEGQuality($quality) {
  13338. if (($quality < 1) OR ($quality > 100)) {
  13339. $quality = 75;
  13340. }
  13341. $this->jpeg_quality = intval($quality);
  13342. }
  13343. /**
  13344. * Set the default number of columns in a row for HTML tables.
  13345. * @param $cols (int) number of columns
  13346. * @public
  13347. * @since 3.0.014 (2008-06-04)
  13348. */
  13349. public function setDefaultTableColumns($cols=4) {
  13350. $this->default_table_columns = intval($cols);
  13351. }
  13352. /**
  13353. * Set the height of the cell (line height) respect the font height.
  13354. * @param $h (int) cell proportion respect font height (typical value = 1.25).
  13355. * @public
  13356. * @since 3.0.014 (2008-06-04)
  13357. */
  13358. public function setCellHeightRatio($h) {
  13359. $this->cell_height_ratio = $h;
  13360. }
  13361. /**
  13362. * return the height of cell repect font height.
  13363. * @public
  13364. * @since 4.0.012 (2008-07-24)
  13365. */
  13366. public function getCellHeightRatio() {
  13367. return $this->cell_height_ratio;
  13368. }
  13369. /**
  13370. * Set the PDF version (check PDF reference for valid values).
  13371. * @param $version (string) PDF document version.
  13372. * @public
  13373. * @since 3.1.000 (2008-06-09)
  13374. */
  13375. public function setPDFVersion($version='1.7') {
  13376. if ($this->pdfa_mode) {
  13377. // PDF/A mode
  13378. $this->PDFVersion = '1.4';
  13379. } else {
  13380. $this->PDFVersion = $version;
  13381. }
  13382. }
  13383. /**
  13384. * Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
  13385. * (see Section 8.1 of PDF reference, "Viewer Preferences").
  13386. * <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>
  13387. * @param $preferences (array) array of options.
  13388. * @author Nicola Asuni
  13389. * @public
  13390. * @since 3.1.000 (2008-06-09)
  13391. */
  13392. public function setViewerPreferences($preferences) {
  13393. $this->viewer_preferences = $preferences;
  13394. }
  13395. /**
  13396. * Paints color transition registration bars
  13397. * @param $x (float) abscissa of the top left corner of the rectangle.
  13398. * @param $y (float) ordinate of the top left corner of the rectangle.
  13399. * @param $w (float) width of the rectangle.
  13400. * @param $h (float) height of the rectangle.
  13401. * @param $transition (boolean) if true prints tcolor transitions to white.
  13402. * @param $vertical (boolean) if true prints bar vertically.
  13403. * @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.
  13404. * @author Nicola Asuni
  13405. * @since 4.9.000 (2010-03-26)
  13406. * @public
  13407. */
  13408. public function colorRegistrationBar($x, $y, $w, $h, $transition=true, $vertical=false, $colors='A,R,G,B,C,M,Y,K') {
  13409. if (strpos($colors, 'ALLSPOT') !== false) {
  13410. // expand spot colors
  13411. $spot_colors = '';
  13412. foreach ($this->spot_colors as $spot_color_name => $v) {
  13413. $spot_colors .= ','.$spot_color_name;
  13414. }
  13415. if (!empty($spot_colors)) {
  13416. $spot_colors = substr($spot_colors, 1);
  13417. $colors = str_replace('ALLSPOT', $spot_colors, $colors);
  13418. } else {
  13419. $colors = str_replace('ALLSPOT', 'NONE', $colors);
  13420. }
  13421. }
  13422. $bars = explode(',', $colors);
  13423. $numbars = count($bars); // number of bars to print
  13424. if ($numbars <= 0) {
  13425. return;
  13426. }
  13427. // set bar measures
  13428. if ($vertical) {
  13429. $coords = array(0, 0, 0, 1);
  13430. $wb = $w / $numbars; // bar width
  13431. $hb = $h; // bar height
  13432. $xd = $wb; // delta x
  13433. $yd = 0; // delta y
  13434. } else {
  13435. $coords = array(1, 0, 0, 0);
  13436. $wb = $w; // bar width
  13437. $hb = $h / $numbars; // bar height
  13438. $xd = 0; // delta x
  13439. $yd = $hb; // delta y
  13440. }
  13441. $xb = $x;
  13442. $yb = $y;
  13443. foreach ($bars as $col) {
  13444. switch ($col) {
  13445. // set transition colors
  13446. case 'A': { // BLACK (GRAYSCALE)
  13447. $col_a = array(255);
  13448. $col_b = array(0);
  13449. break;
  13450. }
  13451. case 'W': { // WHITE (GRAYSCALE)
  13452. $col_a = array(0);
  13453. $col_b = array(255);
  13454. break;
  13455. }
  13456. case 'R': { // RED (RGB)
  13457. $col_a = array(255,255,255);
  13458. $col_b = array(255,0,0);
  13459. break;
  13460. }
  13461. case 'G': { // GREEN (RGB)
  13462. $col_a = array(255,255,255);
  13463. $col_b = array(0,255,0);
  13464. break;
  13465. }
  13466. case 'B': { // BLUE (RGB)
  13467. $col_a = array(255,255,255);
  13468. $col_b = array(0,0,255);
  13469. break;
  13470. }
  13471. case 'C': { // CYAN (CMYK)
  13472. $col_a = array(0,0,0,0);
  13473. $col_b = array(100,0,0,0);
  13474. break;
  13475. }
  13476. case 'M': { // MAGENTA (CMYK)
  13477. $col_a = array(0,0,0,0);
  13478. $col_b = array(0,100,0,0);
  13479. break;
  13480. }
  13481. case 'Y': { // YELLOW (CMYK)
  13482. $col_a = array(0,0,0,0);
  13483. $col_b = array(0,0,100,0);
  13484. break;
  13485. }
  13486. case 'K': { // KEY - BLACK (CMYK)
  13487. $col_a = array(0,0,0,0);
  13488. $col_b = array(0,0,0,100);
  13489. break;
  13490. }
  13491. case 'RGB': { // BLACK REGISTRATION (RGB)
  13492. $col_a = array(255,255,255);
  13493. $col_b = array(0,0,0);
  13494. break;
  13495. }
  13496. case 'CMYK': { // BLACK REGISTRATION (CMYK)
  13497. $col_a = array(0,0,0,0);
  13498. $col_b = array(100,100,100,100);
  13499. break;
  13500. }
  13501. case 'ALL': { // SPOT COLOR REGISTRATION
  13502. $col_a = array(0,0,0,0,'None');
  13503. $col_b = array(100,100,100,100,'All');
  13504. break;
  13505. }
  13506. case 'NONE': { // SKIP THIS COLOR
  13507. $col_a = array(0,0,0,0,'None');
  13508. $col_b = array(0,0,0,0,'None');
  13509. break;
  13510. }
  13511. default: { // SPECIFIC SPOT COLOR NAME
  13512. $col_a = array(0,0,0,0,'None');
  13513. $col_b = TCPDF_COLORS::getSpotColor($col, $this->spot_colors);
  13514. if ($col_b === false) {
  13515. // in case of error defaults to the registration color
  13516. $col_b = array(100,100,100,100,'All');
  13517. }
  13518. break;
  13519. }
  13520. }
  13521. if ($col != 'NONE') {
  13522. if ($transition) {
  13523. // color gradient
  13524. $this->LinearGradient($xb, $yb, $wb, $hb, $col_a, $col_b, $coords);
  13525. } else {
  13526. $this->SetFillColorArray($col_b);
  13527. // colored rectangle
  13528. $this->Rect($xb, $yb, $wb, $hb, 'F', array());
  13529. }
  13530. $xb += $xd;
  13531. $yb += $yd;
  13532. }
  13533. }
  13534. }
  13535. /**
  13536. * Paints crop marks.
  13537. * @param $x (float) abscissa of the crop mark center.
  13538. * @param $y (float) ordinate of the crop mark center.
  13539. * @param $w (float) width of the crop mark.
  13540. * @param $h (float) height of the crop mark.
  13541. * @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.
  13542. * @param $color (array) crop mark color (default spot registration color).
  13543. * @author Nicola Asuni
  13544. * @since 4.9.000 (2010-03-26)
  13545. * @public
  13546. */
  13547. public function cropMark($x, $y, $w, $h, $type='T,R,B,L', $color=array(100,100,100,100,'All')) {
  13548. $this->SetLineStyle(array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $color));
  13549. $type = strtoupper($type);
  13550. $type = preg_replace('/[^A-Z\-\,]*/', '', $type);
  13551. // split type in single components
  13552. $type = str_replace('-', ',', $type);
  13553. $type = str_replace('TL', 'T,L', $type);
  13554. $type = str_replace('TR', 'T,R', $type);
  13555. $type = str_replace('BL', 'F,L', $type);
  13556. $type = str_replace('BR', 'F,R', $type);
  13557. $type = str_replace('A', 'T,L', $type);
  13558. $type = str_replace('B', 'T,R', $type);
  13559. $type = str_replace('T,RO', 'BO', $type);
  13560. $type = str_replace('C', 'F,L', $type);
  13561. $type = str_replace('D', 'F,R', $type);
  13562. $crops = explode(',', strtoupper($type));
  13563. // remove duplicates
  13564. $crops = array_unique($crops);
  13565. $dw = ($w / 4); // horizontal space to leave before the intersection point
  13566. $dh = ($h / 4); // vertical space to leave before the intersection point
  13567. foreach ($crops as $crop) {
  13568. switch ($crop) {
  13569. case 'T':
  13570. case 'TOP': {
  13571. $x1 = $x;
  13572. $y1 = ($y - $h);
  13573. $x2 = $x;
  13574. $y2 = ($y - $dh);
  13575. break;
  13576. }
  13577. case 'F':
  13578. case 'BOTTOM': {
  13579. $x1 = $x;
  13580. $y1 = ($y + $dh);
  13581. $x2 = $x;
  13582. $y2 = ($y + $h);
  13583. break;
  13584. }
  13585. case 'L':
  13586. case 'LEFT': {
  13587. $x1 = ($x - $w);
  13588. $y1 = $y;
  13589. $x2 = ($x - $dw);
  13590. $y2 = $y;
  13591. break;
  13592. }
  13593. case 'R':
  13594. case 'RIGHT': {
  13595. $x1 = ($x + $dw);
  13596. $y1 = $y;
  13597. $x2 = ($x + $w);
  13598. $y2 = $y;
  13599. break;
  13600. }
  13601. }
  13602. $this->Line($x1, $y1, $x2, $y2);
  13603. }
  13604. }
  13605. /**
  13606. * Paints a registration mark
  13607. * @param $x (float) abscissa of the registration mark center.
  13608. * @param $y (float) ordinate of the registration mark center.
  13609. * @param $r (float) radius of the crop mark.
  13610. * @param $double (boolean) if true print two concentric crop marks.
  13611. * @param $cola (array) crop mark color (default spot registration color 'All').
  13612. * @param $colb (array) second crop mark color (default spot registration color 'None').
  13613. * @author Nicola Asuni
  13614. * @since 4.9.000 (2010-03-26)
  13615. * @public
  13616. */
  13617. public function registrationMark($x, $y, $r, $double=false, $cola=array(100,100,100,100,'All'), $colb=array(0,0,0,0,'None')) {
  13618. $line_style = array('width' => max((0.5 / $this->k),($r / 30)), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $cola);
  13619. $this->SetFillColorArray($cola);
  13620. $this->PieSector($x, $y, $r, 90, 180, 'F');
  13621. $this->PieSector($x, $y, $r, 270, 360, 'F');
  13622. $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
  13623. if ($double) {
  13624. $ri = $r * 0.5;
  13625. $this->SetFillColorArray($colb);
  13626. $this->PieSector($x, $y, $ri, 90, 180, 'F');
  13627. $this->PieSector($x, $y, $ri, 270, 360, 'F');
  13628. $this->SetFillColorArray($cola);
  13629. $this->PieSector($x, $y, $ri, 0, 90, 'F');
  13630. $this->PieSector($x, $y, $ri, 180, 270, 'F');
  13631. $this->Circle($x, $y, $ri, 0, 360, 'C', $line_style, array(), 8);
  13632. }
  13633. }
  13634. /**
  13635. * Paints a CMYK registration mark
  13636. * @param $x (float) abscissa of the registration mark center.
  13637. * @param $y (float) ordinate of the registration mark center.
  13638. * @param $r (float) radius of the crop mark.
  13639. * @author Nicola Asuni
  13640. * @since 6.0.038 (2013-09-30)
  13641. * @public
  13642. */
  13643. public function registrationMarkCMYK($x, $y, $r) {
  13644. // line width
  13645. $lw = max((0.5 / $this->k),($r / 8));
  13646. // internal radius
  13647. $ri = ($r * 0.6);
  13648. // external radius
  13649. $re = ($r * 1.3);
  13650. // Cyan
  13651. $this->SetFillColorArray(array(100,0,0,0));
  13652. $this->PieSector($x, $y, $ri, 270, 360, 'F');
  13653. // Magenta
  13654. $this->SetFillColorArray(array(0,100,0,0));
  13655. $this->PieSector($x, $y, $ri, 0, 90, 'F');
  13656. // Yellow
  13657. $this->SetFillColorArray(array(0,0,100,0));
  13658. $this->PieSector($x, $y, $ri, 90, 180, 'F');
  13659. // Key - black
  13660. $this->SetFillColorArray(array(0,0,0,100));
  13661. $this->PieSector($x, $y, $ri, 180, 270, 'F');
  13662. // registration color
  13663. $line_style = array('width' => $lw, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(100,100,100,100,'All'));
  13664. $this->SetFillColorArray(array(100,100,100,100,'All'));
  13665. // external circle
  13666. $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
  13667. // cross lines
  13668. $this->Line($x, ($y - $re), $x, ($y - $ri));
  13669. $this->Line($x, ($y + $ri), $x, ($y + $re));
  13670. $this->Line(($x - $re), $y, ($x - $ri), $y);
  13671. $this->Line(($x + $ri), $y, ($x + $re), $y);
  13672. }
  13673. /**
  13674. * Paints a linear colour gradient.
  13675. * @param $x (float) abscissa of the top left corner of the rectangle.
  13676. * @param $y (float) ordinate of the top left corner of the rectangle.
  13677. * @param $w (float) width of the rectangle.
  13678. * @param $h (float) height of the rectangle.
  13679. * @param $col1 (array) first color (Grayscale, RGB or CMYK components).
  13680. * @param $col2 (array) second color (Grayscale, RGB or CMYK components).
  13681. * @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).
  13682. * @author Andreas W\FCrmser, Nicola Asuni
  13683. * @since 3.1.000 (2008-06-09)
  13684. * @public
  13685. */
  13686. public function LinearGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0,0,1,0)) {
  13687. $this->Clip($x, $y, $w, $h);
  13688. $this->Gradient(2, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
  13689. }
  13690. /**
  13691. * Paints a radial colour gradient.
  13692. * @param $x (float) abscissa of the top left corner of the rectangle.
  13693. * @param $y (float) ordinate of the top left corner of the rectangle.
  13694. * @param $w (float) width of the rectangle.
  13695. * @param $h (float) height of the rectangle.
  13696. * @param $col1 (array) first color (Grayscale, RGB or CMYK components).
  13697. * @param $col2 (array) second color (Grayscale, RGB or CMYK components).
  13698. * @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.
  13699. * @author Andreas W\FCrmser, Nicola Asuni
  13700. * @since 3.1.000 (2008-06-09)
  13701. * @public
  13702. */
  13703. public function RadialGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0.5,0.5,0.5,0.5,1)) {
  13704. $this->Clip($x, $y, $w, $h);
  13705. $this->Gradient(3, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
  13706. }
  13707. /**
  13708. * Paints a coons patch mesh.
  13709. * @param $x (float) abscissa of the top left corner of the rectangle.
  13710. * @param $y (float) ordinate of the top left corner of the rectangle.
  13711. * @param $w (float) width of the rectangle.
  13712. * @param $h (float) height of the rectangle.
  13713. * @param $col1 (array) first color (lower left corner) (RGB components).
  13714. * @param $col2 (array) second color (lower right corner) (RGB components).
  13715. * @param $col3 (array) third color (upper right corner) (RGB components).
  13716. * @param $col4 (array) fourth color (upper left corner) (RGB components).
  13717. * @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>
  13718. * @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
  13719. * @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
  13720. * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  13721. * @author Andreas W\FCrmser, Nicola Asuni
  13722. * @since 3.1.000 (2008-06-09)
  13723. * @public
  13724. */
  13725. 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) {
  13726. if ($this->pdfa_mode OR ($this->state != 2)) {
  13727. return;
  13728. }
  13729. $this->Clip($x, $y, $w, $h);
  13730. $n = count($this->gradients) + 1;
  13731. $this->gradients[$n] = array();
  13732. $this->gradients[$n]['type'] = 6; //coons patch mesh
  13733. $this->gradients[$n]['coords'] = array();
  13734. $this->gradients[$n]['antialias'] = $antialias;
  13735. $this->gradients[$n]['colors'] = array();
  13736. $this->gradients[$n]['transparency'] = false;
  13737. //check the coords array if it is the simple array or the multi patch array
  13738. if (!isset($coords[0]['f'])) {
  13739. //simple array -> convert to multi patch array
  13740. if (!isset($col1[1])) {
  13741. $col1[1] = $col1[2] = $col1[0];
  13742. }
  13743. if (!isset($col2[1])) {
  13744. $col2[1] = $col2[2] = $col2[0];
  13745. }
  13746. if (!isset($col3[1])) {
  13747. $col3[1] = $col3[2] = $col3[0];
  13748. }
  13749. if (!isset($col4[1])) {
  13750. $col4[1] = $col4[2] = $col4[0];
  13751. }
  13752. $patch_array[0]['f'] = 0;
  13753. $patch_array[0]['points'] = $coords;
  13754. $patch_array[0]['colors'][0]['r'] = $col1[0];
  13755. $patch_array[0]['colors'][0]['g'] = $col1[1];
  13756. $patch_array[0]['colors'][0]['b'] = $col1[2];
  13757. $patch_array[0]['colors'][1]['r'] = $col2[0];
  13758. $patch_array[0]['colors'][1]['g'] = $col2[1];
  13759. $patch_array[0]['colors'][1]['b'] = $col2[2];
  13760. $patch_array[0]['colors'][2]['r'] = $col3[0];
  13761. $patch_array[0]['colors'][2]['g'] = $col3[1];
  13762. $patch_array[0]['colors'][2]['b'] = $col3[2];
  13763. $patch_array[0]['colors'][3]['r'] = $col4[0];
  13764. $patch_array[0]['colors'][3]['g'] = $col4[1];
  13765. $patch_array[0]['colors'][3]['b'] = $col4[2];
  13766. } else {
  13767. //multi patch array
  13768. $patch_array = $coords;
  13769. }
  13770. $bpcd = 65535; //16 bits per coordinate
  13771. //build the data stream
  13772. $this->gradients[$n]['stream'] = '';
  13773. $count_patch = count($patch_array);
  13774. for ($i=0; $i < $count_patch; ++$i) {
  13775. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['f']); //start with the edge flag as 8 bit
  13776. $count_points = count($patch_array[$i]['points']);
  13777. for ($j=0; $j < $count_points; ++$j) {
  13778. //each point as 16 bit
  13779. $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $coords_min) / ($coords_max - $coords_min)) * $bpcd;
  13780. if ($patch_array[$i]['points'][$j] < 0) {
  13781. $patch_array[$i]['points'][$j] = 0;
  13782. }
  13783. if ($patch_array[$i]['points'][$j] > $bpcd) {
  13784. $patch_array[$i]['points'][$j] = $bpcd;
  13785. }
  13786. $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] / 256));
  13787. $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] % 256));
  13788. }
  13789. $count_cols = count($patch_array[$i]['colors']);
  13790. for ($j=0; $j < $count_cols; ++$j) {
  13791. //each color component as 8 bit
  13792. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['r']);
  13793. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['g']);
  13794. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['b']);
  13795. }
  13796. }
  13797. //paint the gradient
  13798. $this->_out('/Sh'.$n.' sh');
  13799. //restore previous Graphic State
  13800. $this->_out('Q');
  13801. if ($this->inxobj) {
  13802. // we are inside an XObject template
  13803. $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
  13804. }
  13805. }
  13806. /**
  13807. * Set a rectangular clipping area.
  13808. * @param $x (float) abscissa of the top left corner of the rectangle (or top right corner for RTL mode).
  13809. * @param $y (float) ordinate of the top left corner of the rectangle.
  13810. * @param $w (float) width of the rectangle.
  13811. * @param $h (float) height of the rectangle.
  13812. * @author Andreas W\FCrmser, Nicola Asuni
  13813. * @since 3.1.000 (2008-06-09)
  13814. * @protected
  13815. */
  13816. protected function Clip($x, $y, $w, $h) {
  13817. if ($this->state != 2) {
  13818. return;
  13819. }
  13820. if ($this->rtl) {
  13821. $x = $this->w - $x - $w;
  13822. }
  13823. //save current Graphic State
  13824. $s = 'q';
  13825. //set clipping area
  13826. $s .= sprintf(' %F %F %F %F re W n', $x*$this->k, ($this->h-$y)*$this->k, $w*$this->k, -$h*$this->k);
  13827. //set up transformation matrix for gradient
  13828. $s .= sprintf(' %F 0 0 %F %F %F cm', $w*$this->k, $h*$this->k, $x*$this->k, ($this->h-($y+$h))*$this->k);
  13829. $this->_out($s);
  13830. }
  13831. /**
  13832. * Output gradient.
  13833. * @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)
  13834. * @param $coords (array) array of coordinates.
  13835. * @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).
  13836. * @param $background (array) An array of colour components appropriate to the colour space, specifying a single background colour value.
  13837. * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  13838. * @author Nicola Asuni
  13839. * @since 3.1.000 (2008-06-09)
  13840. * @public
  13841. */
  13842. public function Gradient($type, $coords, $stops, $background=array(), $antialias=false) {
  13843. if ($this->pdfa_mode OR ($this->state != 2)) {
  13844. return;
  13845. }
  13846. $n = count($this->gradients) + 1;
  13847. $this->gradients[$n] = array();
  13848. $this->gradients[$n]['type'] = $type;
  13849. $this->gradients[$n]['coords'] = $coords;
  13850. $this->gradients[$n]['antialias'] = $antialias;
  13851. $this->gradients[$n]['colors'] = array();
  13852. $this->gradients[$n]['transparency'] = false;
  13853. // color space
  13854. $numcolspace = count($stops[0]['color']);
  13855. $bcolor = array_values($background);
  13856. switch($numcolspace) {
  13857. case 5: // SPOT
  13858. case 4: { // CMYK
  13859. $this->gradients[$n]['colspace'] = 'DeviceCMYK';
  13860. if (!empty($background)) {
  13861. $this->gradients[$n]['background'] = sprintf('%F %F %F %F', $bcolor[0]/100, $bcolor[1]/100, $bcolor[2]/100, $bcolor[3]/100);
  13862. }
  13863. break;
  13864. }
  13865. case 3: { // RGB
  13866. $this->gradients[$n]['colspace'] = 'DeviceRGB';
  13867. if (!empty($background)) {
  13868. $this->gradients[$n]['background'] = sprintf('%F %F %F', $bcolor[0]/255, $bcolor[1]/255, $bcolor[2]/255);
  13869. }
  13870. break;
  13871. }
  13872. case 1: { // GRAY SCALE
  13873. $this->gradients[$n]['colspace'] = 'DeviceGray';
  13874. if (!empty($background)) {
  13875. $this->gradients[$n]['background'] = sprintf('%F', $bcolor[0]/255);
  13876. }
  13877. break;
  13878. }
  13879. }
  13880. $num_stops = count($stops);
  13881. $last_stop_id = $num_stops - 1;
  13882. foreach ($stops as $key => $stop) {
  13883. $this->gradients[$n]['colors'][$key] = array();
  13884. // offset represents a location along the gradient vector
  13885. if (isset($stop['offset'])) {
  13886. $this->gradients[$n]['colors'][$key]['offset'] = $stop['offset'];
  13887. } else {
  13888. if ($key == 0) {
  13889. $this->gradients[$n]['colors'][$key]['offset'] = 0;
  13890. } elseif ($key == $last_stop_id) {
  13891. $this->gradients[$n]['colors'][$key]['offset'] = 1;
  13892. } else {
  13893. $offsetstep = (1 - $this->gradients[$n]['colors'][($key - 1)]['offset']) / ($num_stops - $key);
  13894. $this->gradients[$n]['colors'][$key]['offset'] = $this->gradients[$n]['colors'][($key - 1)]['offset'] + $offsetstep;
  13895. }
  13896. }
  13897. if (isset($stop['opacity'])) {
  13898. $this->gradients[$n]['colors'][$key]['opacity'] = $stop['opacity'];
  13899. if ((!$this->pdfa_mode) AND ($stop['opacity'] < 1)) {
  13900. $this->gradients[$n]['transparency'] = true;
  13901. }
  13902. } else {
  13903. $this->gradients[$n]['colors'][$key]['opacity'] = 1;
  13904. }
  13905. // exponent for the exponential interpolation function
  13906. if (isset($stop['exponent'])) {
  13907. $this->gradients[$n]['colors'][$key]['exponent'] = $stop['exponent'];
  13908. } else {
  13909. $this->gradients[$n]['colors'][$key]['exponent'] = 1;
  13910. }
  13911. // set colors
  13912. $color = array_values($stop['color']);
  13913. switch($numcolspace) {
  13914. case 5: // SPOT
  13915. case 4: { // CMYK
  13916. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F %F', $color[0]/100, $color[1]/100, $color[2]/100, $color[3]/100);
  13917. break;
  13918. }
  13919. case 3: { // RGB
  13920. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F', $color[0]/255, $color[1]/255, $color[2]/255);
  13921. break;
  13922. }
  13923. case 1: { // GRAY SCALE
  13924. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F', $color[0]/255);
  13925. break;
  13926. }
  13927. }
  13928. }
  13929. if ($this->gradients[$n]['transparency']) {
  13930. // paint luminosity gradient
  13931. $this->_out('/TGS'.$n.' gs');
  13932. }
  13933. //paint the gradient
  13934. $this->_out('/Sh'.$n.' sh');
  13935. //restore previous Graphic State
  13936. $this->_out('Q');
  13937. if ($this->inxobj) {
  13938. // we are inside an XObject template
  13939. $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
  13940. }
  13941. }
  13942. /**
  13943. * Output gradient shaders.
  13944. * @author Nicola Asuni
  13945. * @since 3.1.000 (2008-06-09)
  13946. * @protected
  13947. */
  13948. function _putshaders() {
  13949. if ($this->pdfa_mode) {
  13950. return;
  13951. }
  13952. $idt = count($this->gradients); //index for transparency gradients
  13953. foreach ($this->gradients as $id => $grad) {
  13954. if (($grad['type'] == 2) OR ($grad['type'] == 3)) {
  13955. $fc = $this->_newobj();
  13956. $out = '<<';
  13957. $out .= ' /FunctionType 3';
  13958. $out .= ' /Domain [0 1]';
  13959. $functions = '';
  13960. $bounds = '';
  13961. $encode = '';
  13962. $i = 1;
  13963. $num_cols = count($grad['colors']);
  13964. $lastcols = $num_cols - 1;
  13965. for ($i = 1; $i < $num_cols; ++$i) {
  13966. $functions .= ($fc + $i).' 0 R ';
  13967. if ($i < $lastcols) {
  13968. $bounds .= sprintf('%F ', $grad['colors'][$i]['offset']);
  13969. }
  13970. $encode .= '0 1 ';
  13971. }
  13972. $out .= ' /Functions ['.trim($functions).']';
  13973. $out .= ' /Bounds ['.trim($bounds).']';
  13974. $out .= ' /Encode ['.trim($encode).']';
  13975. $out .= ' >>';
  13976. $out .= "\n".'endobj';
  13977. $this->_out($out);
  13978. for ($i = 1; $i < $num_cols; ++$i) {
  13979. $this->_newobj();
  13980. $out = '<<';
  13981. $out .= ' /FunctionType 2';
  13982. $out .= ' /Domain [0 1]';
  13983. $out .= ' /C0 ['.$grad['colors'][($i - 1)]['color'].']';
  13984. $out .= ' /C1 ['.$grad['colors'][$i]['color'].']';
  13985. $out .= ' /N '.$grad['colors'][$i]['exponent'];
  13986. $out .= ' >>';
  13987. $out .= "\n".'endobj';
  13988. $this->_out($out);
  13989. }
  13990. // set transparency fuctions
  13991. if ($grad['transparency']) {
  13992. $ft = $this->_newobj();
  13993. $out = '<<';
  13994. $out .= ' /FunctionType 3';
  13995. $out .= ' /Domain [0 1]';
  13996. $functions = '';
  13997. $i = 1;
  13998. $num_cols = count($grad['colors']);
  13999. for ($i = 1; $i < $num_cols; ++$i) {
  14000. $functions .= ($ft + $i).' 0 R ';
  14001. }
  14002. $out .= ' /Functions ['.trim($functions).']';
  14003. $out .= ' /Bounds ['.trim($bounds).']';
  14004. $out .= ' /Encode ['.trim($encode).']';
  14005. $out .= ' >>';
  14006. $out .= "\n".'endobj';
  14007. $this->_out($out);
  14008. for ($i = 1; $i < $num_cols; ++$i) {
  14009. $this->_newobj();
  14010. $out = '<<';
  14011. $out .= ' /FunctionType 2';
  14012. $out .= ' /Domain [0 1]';
  14013. $out .= ' /C0 ['.$grad['colors'][($i - 1)]['opacity'].']';
  14014. $out .= ' /C1 ['.$grad['colors'][$i]['opacity'].']';
  14015. $out .= ' /N '.$grad['colors'][$i]['exponent'];
  14016. $out .= ' >>';
  14017. $out .= "\n".'endobj';
  14018. $this->_out($out);
  14019. }
  14020. }
  14021. }
  14022. // set shading object
  14023. $this->_newobj();
  14024. $out = '<< /ShadingType '.$grad['type'];
  14025. if (isset($grad['colspace'])) {
  14026. $out .= ' /ColorSpace /'.$grad['colspace'];
  14027. } else {
  14028. $out .= ' /ColorSpace /DeviceRGB';
  14029. }
  14030. if (isset($grad['background']) AND !empty($grad['background'])) {
  14031. $out .= ' /Background ['.$grad['background'].']';
  14032. }
  14033. if (isset($grad['antialias']) AND ($grad['antialias'] === true)) {
  14034. $out .= ' /AntiAlias true';
  14035. }
  14036. if ($grad['type'] == 2) {
  14037. $out .= ' '.sprintf('/Coords [%F %F %F %F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]);
  14038. $out .= ' /Domain [0 1]';
  14039. $out .= ' /Function '.$fc.' 0 R';
  14040. $out .= ' /Extend [true true]';
  14041. $out .= ' >>';
  14042. } elseif ($grad['type'] == 3) {
  14043. //x0, y0, r0, x1, y1, r1
  14044. //at this this time radius of inner circle is 0
  14045. $out .= ' '.sprintf('/Coords [%F %F 0 %F %F %F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]);
  14046. $out .= ' /Domain [0 1]';
  14047. $out .= ' /Function '.$fc.' 0 R';
  14048. $out .= ' /Extend [true true]';
  14049. $out .= ' >>';
  14050. } elseif ($grad['type'] == 6) {
  14051. $out .= ' /BitsPerCoordinate 16';
  14052. $out .= ' /BitsPerComponent 8';
  14053. $out .= ' /Decode[0 1 0 1 0 1 0 1 0 1]';
  14054. $out .= ' /BitsPerFlag 8';
  14055. $stream = $this->_getrawstream($grad['stream']);
  14056. $out .= ' /Length '.strlen($stream);
  14057. $out .= ' >>';
  14058. $out .= ' stream'."\n".$stream."\n".'endstream';
  14059. }
  14060. $out .= "\n".'endobj';
  14061. $this->_out($out);
  14062. if ($grad['transparency']) {
  14063. $shading_transparency = preg_replace('/\/ColorSpace \/[^\s]+/si', '/ColorSpace /DeviceGray', $out);
  14064. $shading_transparency = preg_replace('/\/Function [0-9]+ /si', '/Function '.$ft.' ', $shading_transparency);
  14065. }
  14066. $this->gradients[$id]['id'] = $this->n;
  14067. // set pattern object
  14068. $this->_newobj();
  14069. $out = '<< /Type /Pattern /PatternType 2';
  14070. $out .= ' /Shading '.$this->gradients[$id]['id'].' 0 R';
  14071. $out .= ' >>';
  14072. $out .= "\n".'endobj';
  14073. $this->_out($out);
  14074. $this->gradients[$id]['pattern'] = $this->n;
  14075. // set shading and pattern for transparency mask
  14076. if ($grad['transparency']) {
  14077. // luminosity pattern
  14078. $idgs = $id + $idt;
  14079. $this->_newobj();
  14080. $this->_out($shading_transparency);
  14081. $this->gradients[$idgs]['id'] = $this->n;
  14082. $this->_newobj();
  14083. $out = '<< /Type /Pattern /PatternType 2';
  14084. $out .= ' /Shading '.$this->gradients[$idgs]['id'].' 0 R';
  14085. $out .= ' >>';
  14086. $out .= "\n".'endobj';
  14087. $this->_out($out);
  14088. $this->gradients[$idgs]['pattern'] = $this->n;
  14089. // luminosity XObject
  14090. $oid = $this->_newobj();
  14091. $this->xobjects['LX'.$oid] = array('n' => $oid);
  14092. $filter = '';
  14093. $stream = 'q /a0 gs /Pattern cs /p'.$idgs.' scn 0 0 '.$this->wPt.' '.$this->hPt.' re f Q';
  14094. if ($this->compress) {
  14095. $filter = ' /Filter /FlateDecode';
  14096. $stream = gzcompress($stream);
  14097. }
  14098. $stream = $this->_getrawstream($stream);
  14099. $out = '<< /Type /XObject /Subtype /Form /FormType 1'.$filter;
  14100. $out .= ' /Length '.strlen($stream);
  14101. $rect = sprintf('%F %F', $this->wPt, $this->hPt);
  14102. $out .= ' /BBox [0 0 '.$rect.']';
  14103. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceGray >>';
  14104. $out .= ' /Resources <<';
  14105. $out .= ' /ExtGState << /a0 << /ca 1 /CA 1 >> >>';
  14106. $out .= ' /Pattern << /p'.$idgs.' '.$this->gradients[$idgs]['pattern'].' 0 R >>';
  14107. $out .= ' >>';
  14108. $out .= ' >> ';
  14109. $out .= ' stream'."\n".$stream."\n".'endstream';
  14110. $out .= "\n".'endobj';
  14111. $this->_out($out);
  14112. // SMask
  14113. $this->_newobj();
  14114. $out = '<< /Type /Mask /S /Luminosity /G '.($this->n - 1).' 0 R >>'."\n".'endobj';
  14115. $this->_out($out);
  14116. // ExtGState
  14117. $this->_newobj();
  14118. $out = '<< /Type /ExtGState /SMask '.($this->n - 1).' 0 R /AIS false >>'."\n".'endobj';
  14119. $this->_out($out);
  14120. $this->extgstates[] = array('n' => $this->n, 'name' => 'TGS'.$id);
  14121. }
  14122. }
  14123. }
  14124. /**
  14125. * Draw the sector of a circle.
  14126. * It can be used for instance to render pie charts.
  14127. * @param $xc (float) abscissa of the center.
  14128. * @param $yc (float) ordinate of the center.
  14129. * @param $r (float) radius.
  14130. * @param $a (float) start angle (in degrees).
  14131. * @param $b (float) end angle (in degrees).
  14132. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  14133. * @param $cw: (float) indicates whether to go clockwise (default: true).
  14134. * @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.
  14135. * @author Maxime Delorme, Nicola Asuni
  14136. * @since 3.1.000 (2008-06-09)
  14137. * @public
  14138. */
  14139. public function PieSector($xc, $yc, $r, $a, $b, $style='FD', $cw=true, $o=90) {
  14140. $this->PieSectorXY($xc, $yc, $r, $r, $a, $b, $style, $cw, $o);
  14141. }
  14142. /**
  14143. * Draw the sector of an ellipse.
  14144. * It can be used for instance to render pie charts.
  14145. * @param $xc (float) abscissa of the center.
  14146. * @param $yc (float) ordinate of the center.
  14147. * @param $rx (float) the x-axis radius.
  14148. * @param $ry (float) the y-axis radius.
  14149. * @param $a (float) start angle (in degrees).
  14150. * @param $b (float) end angle (in degrees).
  14151. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  14152. * @param $cw: (float) indicates whether to go clockwise.
  14153. * @param $o: (float) origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock).
  14154. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of arc.
  14155. * @author Maxime Delorme, Nicola Asuni
  14156. * @since 3.1.000 (2008-06-09)
  14157. * @public
  14158. */
  14159. public function PieSectorXY($xc, $yc, $rx, $ry, $a, $b, $style='FD', $cw=false, $o=0, $nc=2) {
  14160. if ($this->state != 2) {
  14161. return;
  14162. }
  14163. if ($this->rtl) {
  14164. $xc = ($this->w - $xc);
  14165. }
  14166. $op = TCPDF_STATIC::getPathPaintOperator($style);
  14167. if ($op == 'f') {
  14168. $line_style = array();
  14169. }
  14170. if ($cw) {
  14171. $d = $b;
  14172. $b = (360 - $a + $o);
  14173. $a = (360 - $d + $o);
  14174. } else {
  14175. $b += $o;
  14176. $a += $o;
  14177. }
  14178. $this->_outellipticalarc($xc, $yc, $rx, $ry, 0, $a, $b, true, $nc);
  14179. $this->_out($op);
  14180. }
  14181. /**
  14182. * Embed vector-based Adobe Illustrator (AI) or AI-compatible EPS files.
  14183. * NOTE: EPS is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  14184. * Only vector drawing is supported, not text or bitmap.
  14185. * 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).
  14186. * @param $file (string) Name of the file containing the image or a '@' character followed by the EPS/AI data string.
  14187. * @param $x (float) Abscissa of the upper-left corner.
  14188. * @param $y (float) Ordinate of the upper-left corner.
  14189. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  14190. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  14191. * @param $link (mixed) URL or identifier returned by AddLink().
  14192. * @param $useBoundingBox (boolean) specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true.
  14193. * @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>
  14194. * @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>
  14195. * @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)))
  14196. * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
  14197. * @param $fixoutvals (boolean) if true remove values outside the bounding box.
  14198. * @author Valentin Schmidt, Nicola Asuni
  14199. * @since 3.1.000 (2008-06-09)
  14200. * @public
  14201. */
  14202. public function ImageEps($file, $x='', $y='', $w=0, $h=0, $link='', $useBoundingBox=true, $align='', $palign='', $border=0, $fitonpage=false, $fixoutvals=false) {
  14203. if ($this->state != 2) {
  14204. return;
  14205. }
  14206. if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
  14207. // convert EPS to raster image using GD or ImageMagick libraries
  14208. return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
  14209. }
  14210. if ($x === '') {
  14211. $x = $this->x;
  14212. }
  14213. if ($y === '') {
  14214. $y = $this->y;
  14215. }
  14216. // check page for no-write regions and adapt page margins if necessary
  14217. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  14218. $k = $this->k;
  14219. if ($file{0} === '@') { // image from string
  14220. $data = substr($file, 1);
  14221. } else { // EPS/AI file
  14222. $data = TCPDF_STATIC::fileGetContents($file);
  14223. }
  14224. if ($data === FALSE) {
  14225. $this->Error('EPS file not found: '.$file);
  14226. }
  14227. $regs = array();
  14228. // EPS/AI compatibility check (only checks files created by Adobe Illustrator!)
  14229. preg_match("/%%Creator:([^\r\n]+)/", $data, $regs); # find Creator
  14230. if (count($regs) > 1) {
  14231. $version_str = trim($regs[1]); # e.g. "Adobe Illustrator(R) 8.0"
  14232. if (strpos($version_str, 'Adobe Illustrator') !== false) {
  14233. $versexp = explode(' ', $version_str);
  14234. $version = (float)array_pop($versexp);
  14235. if ($version >= 9) {
  14236. $this->Error('This version of Adobe Illustrator file is not supported: '.$file);
  14237. }
  14238. }
  14239. }
  14240. // strip binary bytes in front of PS-header
  14241. $start = strpos($data, '%!PS-Adobe');
  14242. if ($start > 0) {
  14243. $data = substr($data, $start);
  14244. }
  14245. // find BoundingBox params
  14246. preg_match("/%%BoundingBox:([^\r\n]+)/", $data, $regs);
  14247. if (count($regs) > 1) {
  14248. list($x1, $y1, $x2, $y2) = explode(' ', trim($regs[1]));
  14249. } else {
  14250. $this->Error('No BoundingBox found in EPS/AI file: '.$file);
  14251. }
  14252. $start = strpos($data, '%%EndSetup');
  14253. if ($start === false) {
  14254. $start = strpos($data, '%%EndProlog');
  14255. }
  14256. if ($start === false) {
  14257. $start = strpos($data, '%%BoundingBox');
  14258. }
  14259. $data = substr($data, $start);
  14260. $end = strpos($data, '%%PageTrailer');
  14261. if ($end===false) {
  14262. $end = strpos($data, 'showpage');
  14263. }
  14264. if ($end) {
  14265. $data = substr($data, 0, $end);
  14266. }
  14267. // calculate image width and height on document
  14268. if (($w <= 0) AND ($h <= 0)) {
  14269. $w = ($x2 - $x1) / $k;
  14270. $h = ($y2 - $y1) / $k;
  14271. } elseif ($w <= 0) {
  14272. $w = ($x2-$x1) / $k * ($h / (($y2 - $y1) / $k));
  14273. } elseif ($h <= 0) {
  14274. $h = ($y2 - $y1) / $k * ($w / (($x2 - $x1) / $k));
  14275. }
  14276. // fit the image on available space
  14277. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  14278. if ($this->rasterize_vector_images) {
  14279. // convert EPS to raster image using GD or ImageMagick libraries
  14280. return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
  14281. }
  14282. // set scaling factors
  14283. $scale_x = $w / (($x2 - $x1) / $k);
  14284. $scale_y = $h / (($y2 - $y1) / $k);
  14285. // set alignment
  14286. $this->img_rb_y = $y + $h;
  14287. // set alignment
  14288. if ($this->rtl) {
  14289. if ($palign == 'L') {
  14290. $ximg = $this->lMargin;
  14291. } elseif ($palign == 'C') {
  14292. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14293. } elseif ($palign == 'R') {
  14294. $ximg = $this->w - $this->rMargin - $w;
  14295. } else {
  14296. $ximg = $x - $w;
  14297. }
  14298. $this->img_rb_x = $ximg;
  14299. } else {
  14300. if ($palign == 'L') {
  14301. $ximg = $this->lMargin;
  14302. } elseif ($palign == 'C') {
  14303. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14304. } elseif ($palign == 'R') {
  14305. $ximg = $this->w - $this->rMargin - $w;
  14306. } else {
  14307. $ximg = $x;
  14308. }
  14309. $this->img_rb_x = $ximg + $w;
  14310. }
  14311. if ($useBoundingBox) {
  14312. $dx = $ximg * $k - $x1;
  14313. $dy = $y * $k - $y1;
  14314. } else {
  14315. $dx = $ximg * $k;
  14316. $dy = $y * $k;
  14317. }
  14318. // save the current graphic state
  14319. $this->_out('q'.$this->epsmarker);
  14320. // translate
  14321. $this->_out(sprintf('%F %F %F %F %F %F cm', 1, 0, 0, 1, $dx, $dy + ($this->hPt - (2 * $y * $k) - ($y2 - $y1))));
  14322. // scale
  14323. if (isset($scale_x)) {
  14324. $this->_out(sprintf('%F %F %F %F %F %F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y)));
  14325. }
  14326. // handle pc/unix/mac line endings
  14327. $lines = preg_split('/[\r\n]+/si', $data, -1, PREG_SPLIT_NO_EMPTY);
  14328. $u=0;
  14329. $cnt = count($lines);
  14330. for ($i=0; $i < $cnt; ++$i) {
  14331. $line = $lines[$i];
  14332. if (($line == '') OR ($line{0} == '%')) {
  14333. continue;
  14334. }
  14335. $len = strlen($line);
  14336. // check for spot color names
  14337. $color_name = '';
  14338. if (strcasecmp('x', substr(trim($line), -1)) == 0) {
  14339. if (preg_match('/\([^\)]*\)/', $line, $matches) > 0) {
  14340. // extract spot color name
  14341. $color_name = $matches[0];
  14342. // remove color name from string
  14343. $line = str_replace(' '.$color_name, '', $line);
  14344. // remove pharentesis from color name
  14345. $color_name = substr($color_name, 1, -1);
  14346. }
  14347. }
  14348. $chunks = explode(' ', $line);
  14349. $cmd = trim(array_pop($chunks));
  14350. // RGB
  14351. if (($cmd == 'Xa') OR ($cmd == 'XA')) {
  14352. $b = array_pop($chunks);
  14353. $g = array_pop($chunks);
  14354. $r = array_pop($chunks);
  14355. $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!
  14356. continue;
  14357. }
  14358. $skip = false;
  14359. if ($fixoutvals) {
  14360. // check for values outside the bounding box
  14361. switch ($cmd) {
  14362. case 'm':
  14363. case 'l':
  14364. case 'L': {
  14365. // skip values outside bounding box
  14366. foreach ($chunks as $key => $val) {
  14367. if ((($key % 2) == 0) AND (($val < $x1) OR ($val > $x2))) {
  14368. $skip = true;
  14369. } elseif ((($key % 2) != 0) AND (($val < $y1) OR ($val > $y2))) {
  14370. $skip = true;
  14371. }
  14372. }
  14373. }
  14374. }
  14375. }
  14376. switch ($cmd) {
  14377. case 'm':
  14378. case 'l':
  14379. case 'v':
  14380. case 'y':
  14381. case 'c':
  14382. case 'k':
  14383. case 'K':
  14384. case 'g':
  14385. case 'G':
  14386. case 's':
  14387. case 'S':
  14388. case 'J':
  14389. case 'j':
  14390. case 'w':
  14391. case 'M':
  14392. case 'd':
  14393. case 'n': {
  14394. if ($skip) {
  14395. break;
  14396. }
  14397. $this->_out($line);
  14398. break;
  14399. }
  14400. case 'x': {// custom fill color
  14401. if (empty($color_name)) {
  14402. // CMYK color
  14403. list($col_c, $col_m, $col_y, $col_k) = $chunks;
  14404. $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' k');
  14405. } else {
  14406. // Spot Color (CMYK + tint)
  14407. list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
  14408. $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
  14409. $color_cmd = sprintf('/CS%d cs %F scn', $this->spot_colors[$color_name]['i'], (1 - $col_t));
  14410. $this->_out($color_cmd);
  14411. }
  14412. break;
  14413. }
  14414. case 'X': { // custom stroke color
  14415. if (empty($color_name)) {
  14416. // CMYK color
  14417. list($col_c, $col_m, $col_y, $col_k) = $chunks;
  14418. $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' K');
  14419. } else {
  14420. // Spot Color (CMYK + tint)
  14421. list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
  14422. $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
  14423. $color_cmd = sprintf('/CS%d CS %F SCN', $this->spot_colors[$color_name]['i'], (1 - $col_t));
  14424. $this->_out($color_cmd);
  14425. }
  14426. break;
  14427. }
  14428. case 'Y':
  14429. case 'N':
  14430. case 'V':
  14431. case 'L':
  14432. case 'C': {
  14433. if ($skip) {
  14434. break;
  14435. }
  14436. $line[($len - 1)] = strtolower($cmd);
  14437. $this->_out($line);
  14438. break;
  14439. }
  14440. case 'b':
  14441. case 'B': {
  14442. $this->_out($cmd . '*');
  14443. break;
  14444. }
  14445. case 'f':
  14446. case 'F': {
  14447. if ($u > 0) {
  14448. $isU = false;
  14449. $max = min(($i + 5), $cnt);
  14450. for ($j = ($i + 1); $j < $max; ++$j) {
  14451. $isU = ($isU OR (($lines[$j] == 'U') OR ($lines[$j] == '*U')));
  14452. }
  14453. if ($isU) {
  14454. $this->_out('f*');
  14455. }
  14456. } else {
  14457. $this->_out('f*');
  14458. }
  14459. break;
  14460. }
  14461. case '*u': {
  14462. ++$u;
  14463. break;
  14464. }
  14465. case '*U': {
  14466. --$u;
  14467. break;
  14468. }
  14469. }
  14470. }
  14471. // restore previous graphic state
  14472. $this->_out($this->epsmarker.'Q');
  14473. if (!empty($border)) {
  14474. $bx = $this->x;
  14475. $by = $this->y;
  14476. $this->x = $ximg;
  14477. if ($this->rtl) {
  14478. $this->x += $w;
  14479. }
  14480. $this->y = $y;
  14481. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  14482. $this->x = $bx;
  14483. $this->y = $by;
  14484. }
  14485. if ($link) {
  14486. $this->Link($ximg, $y, $w, $h, $link, 0);
  14487. }
  14488. // set pointer to align the next text/objects
  14489. switch($align) {
  14490. case 'T':{
  14491. $this->y = $y;
  14492. $this->x = $this->img_rb_x;
  14493. break;
  14494. }
  14495. case 'M':{
  14496. $this->y = $y + round($h/2);
  14497. $this->x = $this->img_rb_x;
  14498. break;
  14499. }
  14500. case 'B':{
  14501. $this->y = $this->img_rb_y;
  14502. $this->x = $this->img_rb_x;
  14503. break;
  14504. }
  14505. case 'N':{
  14506. $this->SetY($this->img_rb_y);
  14507. break;
  14508. }
  14509. default:{
  14510. break;
  14511. }
  14512. }
  14513. $this->endlinex = $this->img_rb_x;
  14514. }
  14515. /**
  14516. * Set document barcode.
  14517. * @param $bc (string) barcode
  14518. * @public
  14519. */
  14520. public function setBarcode($bc='') {
  14521. $this->barcode = $bc;
  14522. }
  14523. /**
  14524. * Get current barcode.
  14525. * @return string
  14526. * @public
  14527. * @since 4.0.012 (2008-07-24)
  14528. */
  14529. public function getBarcode() {
  14530. return $this->barcode;
  14531. }
  14532. /**
  14533. * Print a Linear Barcode.
  14534. * @param $code (string) code to print
  14535. * @param $type (string) type of barcode (see tcpdf_barcodes_1d.php for supported formats).
  14536. * @param $x (int) x position in user units (empty string = current x position)
  14537. * @param $y (int) y position in user units (empty string = current y position)
  14538. * @param $w (int) width in user units (empty string = remaining page width)
  14539. * @param $h (int) height in user units (empty string = remaining page height)
  14540. * @param $xres (float) width of the smallest bar in user units (empty string = default value = 0.4mm)
  14541. * @param $style (array) array of options:<ul>
  14542. * <li>boolean $style['border'] if true prints a border</li>
  14543. * <li>int $style['padding'] padding to leave around the barcode in user units (set to 'auto' for automatic padding)</li>
  14544. * <li>int $style['hpadding'] horizontal padding in user units (set to 'auto' for automatic padding)</li>
  14545. * <li>int $style['vpadding'] vertical padding in user units (set to 'auto' for automatic padding)</li>
  14546. * <li>array $style['fgcolor'] color array for bars and text</li>
  14547. * <li>mixed $style['bgcolor'] color array for background (set to false for transparent)</li>
  14548. * <li>boolean $style['text'] if true prints text below the barcode</li>
  14549. * <li>string $style['label'] override default label</li>
  14550. * <li>string $style['font'] font name for text</li><li>int $style['fontsize'] font size for text</li>
  14551. * <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>
  14552. * <li>string $style['position'] horizontal position of the containing barcode cell on the page: L = left margin; C = center; R = right margin.</li>
  14553. * <li>string $style['align'] horizontal position of the barcode on the containing rectangle: L = left; C = center; R = right.</li>
  14554. * <li>string $style['stretch'] if true stretch the barcode to best fit the available width, otherwise uses $xres resolution for a single bar.</li>
  14555. * <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>
  14556. * <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>
  14557. * @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>
  14558. * @author Nicola Asuni
  14559. * @since 3.1.000 (2008-06-09)
  14560. * @public
  14561. */
  14562. public function write1DBarcode($code, $type, $x='', $y='', $w='', $h='', $xres='', $style='', $align='') {
  14563. if (TCPDF_STATIC::empty_string(trim($code))) {
  14564. return;
  14565. }
  14566. require_once(dirname(__FILE__).'/tcpdf_barcodes_1d.php');
  14567. // save current graphic settings
  14568. $gvars = $this->getGraphicVars();
  14569. // create new barcode object
  14570. $barcodeobj = new TCPDFBarcode($code, $type);
  14571. $arrcode = $barcodeobj->getBarcodeArray();
  14572. if (($arrcode === false) OR empty($arrcode) OR ($arrcode['maxw'] <= 0)) {
  14573. $this->Error('Error in 1D barcode string');
  14574. }
  14575. if ($arrcode['maxh'] <= 0) {
  14576. $arrcode['maxh'] = 1;
  14577. }
  14578. // set default values
  14579. if (!isset($style['position'])) {
  14580. $style['position'] = '';
  14581. } elseif ($style['position'] == 'S') {
  14582. // keep this for backward compatibility
  14583. $style['position'] = '';
  14584. $style['stretch'] = true;
  14585. }
  14586. if (!isset($style['fitwidth'])) {
  14587. if (!isset($style['stretch'])) {
  14588. $style['fitwidth'] = true;
  14589. } else {
  14590. $style['fitwidth'] = false;
  14591. }
  14592. }
  14593. if ($style['fitwidth']) {
  14594. // disable stretch
  14595. $style['stretch'] = false;
  14596. }
  14597. if (!isset($style['stretch'])) {
  14598. if (($w === '') OR ($w <= 0)) {
  14599. $style['stretch'] = false;
  14600. } else {
  14601. $style['stretch'] = true;
  14602. }
  14603. }
  14604. if (!isset($style['fgcolor'])) {
  14605. $style['fgcolor'] = array(0,0,0); // default black
  14606. }
  14607. if (!isset($style['bgcolor'])) {
  14608. $style['bgcolor'] = false; // default transparent
  14609. }
  14610. if (!isset($style['border'])) {
  14611. $style['border'] = false;
  14612. }
  14613. $fontsize = 0;
  14614. if (!isset($style['text'])) {
  14615. $style['text'] = false;
  14616. }
  14617. if ($style['text'] AND isset($style['font'])) {
  14618. if (isset($style['fontsize'])) {
  14619. $fontsize = $style['fontsize'];
  14620. }
  14621. $this->SetFont($style['font'], '', $fontsize);
  14622. }
  14623. if (!isset($style['stretchtext'])) {
  14624. $style['stretchtext'] = 4;
  14625. }
  14626. if ($x === '') {
  14627. $x = $this->x;
  14628. }
  14629. if ($y === '') {
  14630. $y = $this->y;
  14631. }
  14632. // check page for no-write regions and adapt page margins if necessary
  14633. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  14634. if (($w === '') OR ($w <= 0)) {
  14635. if ($this->rtl) {
  14636. $w = $x - $this->lMargin;
  14637. } else {
  14638. $w = $this->w - $this->rMargin - $x;
  14639. }
  14640. }
  14641. // padding
  14642. if (!isset($style['padding'])) {
  14643. $padding = 0;
  14644. } elseif ($style['padding'] === 'auto') {
  14645. $padding = 10 * ($w / ($arrcode['maxw'] + 20));
  14646. } else {
  14647. $padding = floatval($style['padding']);
  14648. }
  14649. // horizontal padding
  14650. if (!isset($style['hpadding'])) {
  14651. $hpadding = $padding;
  14652. } elseif ($style['hpadding'] === 'auto') {
  14653. $hpadding = 10 * ($w / ($arrcode['maxw'] + 20));
  14654. } else {
  14655. $hpadding = floatval($style['hpadding']);
  14656. }
  14657. // vertical padding
  14658. if (!isset($style['vpadding'])) {
  14659. $vpadding = $padding;
  14660. } elseif ($style['vpadding'] === 'auto') {
  14661. $vpadding = ($hpadding / 2);
  14662. } else {
  14663. $vpadding = floatval($style['vpadding']);
  14664. }
  14665. // calculate xres (single bar width)
  14666. $max_xres = ($w - (2 * $hpadding)) / $arrcode['maxw'];
  14667. if ($style['stretch']) {
  14668. $xres = $max_xres;
  14669. } else {
  14670. if (TCPDF_STATIC::empty_string($xres)) {
  14671. $xres = (0.141 * $this->k); // default bar width = 0.4 mm
  14672. }
  14673. if ($xres > $max_xres) {
  14674. // correct xres to fit on $w
  14675. $xres = $max_xres;
  14676. }
  14677. if ((isset($style['padding']) AND ($style['padding'] === 'auto'))
  14678. OR (isset($style['hpadding']) AND ($style['hpadding'] === 'auto'))) {
  14679. $hpadding = 10 * $xres;
  14680. if (isset($style['vpadding']) AND ($style['vpadding'] === 'auto')) {
  14681. $vpadding = ($hpadding / 2);
  14682. }
  14683. }
  14684. }
  14685. if ($style['fitwidth']) {
  14686. $wold = $w;
  14687. $w = (($arrcode['maxw'] * $xres) + (2 * $hpadding));
  14688. if (isset($style['cellfitalign'])) {
  14689. switch ($style['cellfitalign']) {
  14690. case 'L': {
  14691. if ($this->rtl) {
  14692. $x -= ($wold - $w);
  14693. }
  14694. break;
  14695. }
  14696. case 'R': {
  14697. if (!$this->rtl) {
  14698. $x += ($wold - $w);
  14699. }
  14700. break;
  14701. }
  14702. case 'C': {
  14703. if ($this->rtl) {
  14704. $x -= (($wold - $w) / 2);
  14705. } else {
  14706. $x += (($wold - $w) / 2);
  14707. }
  14708. break;
  14709. }
  14710. default : {
  14711. break;
  14712. }
  14713. }
  14714. }
  14715. }
  14716. $text_height = $this->getCellHeight($fontsize / $this->k);
  14717. // height
  14718. if (($h === '') OR ($h <= 0)) {
  14719. // set default height
  14720. $h = (($arrcode['maxw'] * $xres) / 3) + (2 * $vpadding) + $text_height;
  14721. }
  14722. $barh = $h - $text_height - (2 * $vpadding);
  14723. if ($barh <=0) {
  14724. // try to reduce font or padding to fit barcode on available height
  14725. if ($text_height > $h) {
  14726. $fontsize = (($h * $this->k) / (4 * $this->cell_height_ratio));
  14727. $text_height = $this->getCellHeight($fontsize / $this->k);
  14728. $this->SetFont($style['font'], '', $fontsize);
  14729. }
  14730. if ($vpadding > 0) {
  14731. $vpadding = (($h - $text_height) / 4);
  14732. }
  14733. $barh = $h - $text_height - (2 * $vpadding);
  14734. }
  14735. // fit the barcode on available space
  14736. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
  14737. // set alignment
  14738. $this->img_rb_y = $y + $h;
  14739. // set alignment
  14740. if ($this->rtl) {
  14741. if ($style['position'] == 'L') {
  14742. $xpos = $this->lMargin;
  14743. } elseif ($style['position'] == 'C') {
  14744. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14745. } elseif ($style['position'] == 'R') {
  14746. $xpos = $this->w - $this->rMargin - $w;
  14747. } else {
  14748. $xpos = $x - $w;
  14749. }
  14750. $this->img_rb_x = $xpos;
  14751. } else {
  14752. if ($style['position'] == 'L') {
  14753. $xpos = $this->lMargin;
  14754. } elseif ($style['position'] == 'C') {
  14755. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14756. } elseif ($style['position'] == 'R') {
  14757. $xpos = $this->w - $this->rMargin - $w;
  14758. } else {
  14759. $xpos = $x;
  14760. }
  14761. $this->img_rb_x = $xpos + $w;
  14762. }
  14763. $xpos_rect = $xpos;
  14764. if (!isset($style['align'])) {
  14765. $style['align'] = 'C';
  14766. }
  14767. switch ($style['align']) {
  14768. case 'L': {
  14769. $xpos = $xpos_rect + $hpadding;
  14770. break;
  14771. }
  14772. case 'R': {
  14773. $xpos = $xpos_rect + ($w - ($arrcode['maxw'] * $xres)) - $hpadding;
  14774. break;
  14775. }
  14776. case 'C':
  14777. default : {
  14778. $xpos = $xpos_rect + (($w - ($arrcode['maxw'] * $xres)) / 2);
  14779. break;
  14780. }
  14781. }
  14782. $xpos_text = $xpos;
  14783. // barcode is always printed in LTR direction
  14784. $tempRTL = $this->rtl;
  14785. $this->rtl = false;
  14786. // print background color
  14787. if ($style['bgcolor']) {
  14788. $this->Rect($xpos_rect, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  14789. } elseif ($style['border']) {
  14790. $this->Rect($xpos_rect, $y, $w, $h, 'D');
  14791. }
  14792. // set foreground color
  14793. $this->SetDrawColorArray($style['fgcolor']);
  14794. $this->SetTextColorArray($style['fgcolor']);
  14795. // print bars
  14796. foreach ($arrcode['bcode'] as $k => $v) {
  14797. $bw = ($v['w'] * $xres);
  14798. if ($v['t']) {
  14799. // draw a vertical bar
  14800. $ypos = $y + $vpadding + ($v['p'] * $barh / $arrcode['maxh']);
  14801. $this->Rect($xpos, $ypos, $bw, ($v['h'] * $barh / $arrcode['maxh']), 'F', array(), $style['fgcolor']);
  14802. }
  14803. $xpos += $bw;
  14804. }
  14805. // print text
  14806. if ($style['text']) {
  14807. if (isset($style['label']) AND !TCPDF_STATIC::empty_string($style['label'])) {
  14808. $label = $style['label'];
  14809. } else {
  14810. $label = $code;
  14811. }
  14812. $txtwidth = ($arrcode['maxw'] * $xres);
  14813. if ($this->GetStringWidth($label) > $txtwidth) {
  14814. $style['stretchtext'] = 2;
  14815. }
  14816. // print text
  14817. $this->x = $xpos_text;
  14818. $this->y = $y + $vpadding + $barh;
  14819. $cellpadding = $this->cell_padding;
  14820. $this->SetCellPadding(0);
  14821. $this->Cell($txtwidth, '', $label, 0, 0, 'C', false, '', $style['stretchtext'], false, 'T', 'T');
  14822. $this->cell_padding = $cellpadding;
  14823. }
  14824. // restore original direction
  14825. $this->rtl = $tempRTL;
  14826. // restore previous settings
  14827. $this->setGraphicVars($gvars);
  14828. // set pointer to align the next text/objects
  14829. switch($align) {
  14830. case 'T':{
  14831. $this->y = $y;
  14832. $this->x = $this->img_rb_x;
  14833. break;
  14834. }
  14835. case 'M':{
  14836. $this->y = $y + round($h / 2);
  14837. $this->x = $this->img_rb_x;
  14838. break;
  14839. }
  14840. case 'B':{
  14841. $this->y = $this->img_rb_y;
  14842. $this->x = $this->img_rb_x;
  14843. break;
  14844. }
  14845. case 'N':{
  14846. $this->SetY($this->img_rb_y);
  14847. break;
  14848. }
  14849. default:{
  14850. break;
  14851. }
  14852. }
  14853. $this->endlinex = $this->img_rb_x;
  14854. }
  14855. /**
  14856. * Print 2D Barcode.
  14857. * @param $code (string) code to print
  14858. * @param $type (string) type of barcode (see tcpdf_barcodes_2d.php for supported formats).
  14859. * @param $x (int) x position in user units
  14860. * @param $y (int) y position in user units
  14861. * @param $w (int) width in user units
  14862. * @param $h (int) height in user units
  14863. * @param $style (array) array of options:<ul>
  14864. * <li>boolean $style['border'] if true prints a border around the barcode</li>
  14865. * <li>int $style['padding'] padding to leave around the barcode in barcode units (set to 'auto' for automatic padding)</li>
  14866. * <li>int $style['hpadding'] horizontal padding in barcode units (set to 'auto' for automatic padding)</li>
  14867. * <li>int $style['vpadding'] vertical padding in barcode units (set to 'auto' for automatic padding)</li>
  14868. * <li>int $style['module_width'] width of a single module in points</li>
  14869. * <li>int $style['module_height'] height of a single module in points</li>
  14870. * <li>array $style['fgcolor'] color array for bars and text</li>
  14871. * <li>mixed $style['bgcolor'] color array for background or false for transparent</li>
  14872. * <li>string $style['position'] barcode position on the page: L = left margin; C = center; R = right margin; S = stretch</li><li>$style['module_width'] width of a single module in points</li>
  14873. * <li>$style['module_height'] height of a single module in points</li></ul>
  14874. * @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>
  14875. * @param $distort (boolean) if true distort the barcode to fit width and height, otherwise preserve aspect ratio
  14876. * @author Nicola Asuni
  14877. * @since 4.5.037 (2009-04-07)
  14878. * @public
  14879. */
  14880. public function write2DBarcode($code, $type, $x='', $y='', $w='', $h='', $style='', $align='', $distort=false) {
  14881. if (TCPDF_STATIC::empty_string(trim($code))) {
  14882. return;
  14883. }
  14884. require_once(dirname(__FILE__).'/tcpdf_barcodes_2d.php');
  14885. // save current graphic settings
  14886. $gvars = $this->getGraphicVars();
  14887. // create new barcode object
  14888. $barcodeobj = new TCPDF2DBarcode($code, $type);
  14889. $arrcode = $barcodeobj->getBarcodeArray();
  14890. 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)) {
  14891. $this->Error('Error in 2D barcode string');
  14892. }
  14893. // set default values
  14894. if (!isset($style['position'])) {
  14895. $style['position'] = '';
  14896. }
  14897. if (!isset($style['fgcolor'])) {
  14898. $style['fgcolor'] = array(0,0,0); // default black
  14899. }
  14900. if (!isset($style['bgcolor'])) {
  14901. $style['bgcolor'] = false; // default transparent
  14902. }
  14903. if (!isset($style['border'])) {
  14904. $style['border'] = false;
  14905. }
  14906. // padding
  14907. if (!isset($style['padding'])) {
  14908. $style['padding'] = 0;
  14909. } elseif ($style['padding'] === 'auto') {
  14910. $style['padding'] = 4;
  14911. }
  14912. if (!isset($style['hpadding'])) {
  14913. $style['hpadding'] = $style['padding'];
  14914. } elseif ($style['hpadding'] === 'auto') {
  14915. $style['hpadding'] = 4;
  14916. }
  14917. if (!isset($style['vpadding'])) {
  14918. $style['vpadding'] = $style['padding'];
  14919. } elseif ($style['vpadding'] === 'auto') {
  14920. $style['vpadding'] = 4;
  14921. }
  14922. $hpad = (2 * $style['hpadding']);
  14923. $vpad = (2 * $style['vpadding']);
  14924. // cell (module) dimension
  14925. if (!isset($style['module_width'])) {
  14926. $style['module_width'] = 1; // width of a single module in points
  14927. }
  14928. if (!isset($style['module_height'])) {
  14929. $style['module_height'] = 1; // height of a single module in points
  14930. }
  14931. if ($x === '') {
  14932. $x = $this->x;
  14933. }
  14934. if ($y === '') {
  14935. $y = $this->y;
  14936. }
  14937. // check page for no-write regions and adapt page margins if necessary
  14938. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  14939. // number of barcode columns and rows
  14940. $rows = $arrcode['num_rows'];
  14941. $cols = $arrcode['num_cols'];
  14942. if (($rows <= 0) || ($cols <= 0)){
  14943. $this->Error('Error in 2D barcode string');
  14944. }
  14945. // module width and height
  14946. $mw = $style['module_width'];
  14947. $mh = $style['module_height'];
  14948. if (($mw <= 0) OR ($mh <= 0)) {
  14949. $this->Error('Error in 2D barcode string');
  14950. }
  14951. // get max dimensions
  14952. if ($this->rtl) {
  14953. $maxw = $x - $this->lMargin;
  14954. } else {
  14955. $maxw = $this->w - $this->rMargin - $x;
  14956. }
  14957. $maxh = ($this->h - $this->tMargin - $this->bMargin);
  14958. $ratioHW = ((($rows * $mh) + $hpad) / (($cols * $mw) + $vpad));
  14959. $ratioWH = ((($cols * $mw) + $vpad) / (($rows * $mh) + $hpad));
  14960. if (!$distort) {
  14961. if (($maxw * $ratioHW) > $maxh) {
  14962. $maxw = $maxh * $ratioWH;
  14963. }
  14964. if (($maxh * $ratioWH) > $maxw) {
  14965. $maxh = $maxw * $ratioHW;
  14966. }
  14967. }
  14968. // set maximum dimesions
  14969. if ($w > $maxw) {
  14970. $w = $maxw;
  14971. }
  14972. if ($h > $maxh) {
  14973. $h = $maxh;
  14974. }
  14975. // set dimensions
  14976. if ((($w === '') OR ($w <= 0)) AND (($h === '') OR ($h <= 0))) {
  14977. $w = ($cols + $hpad) * ($mw / $this->k);
  14978. $h = ($rows + $vpad) * ($mh / $this->k);
  14979. } elseif (($w === '') OR ($w <= 0)) {
  14980. $w = $h * $ratioWH;
  14981. } elseif (($h === '') OR ($h <= 0)) {
  14982. $h = $w * $ratioHW;
  14983. }
  14984. // barcode size (excluding padding)
  14985. $bw = ($w * $cols) / ($cols + $hpad);
  14986. $bh = ($h * $rows) / ($rows + $vpad);
  14987. // dimension of single barcode cell unit
  14988. $cw = $bw / $cols;
  14989. $ch = $bh / $rows;
  14990. if (!$distort) {
  14991. if (($cw / $ch) > ($mw / $mh)) {
  14992. // correct horizontal distortion
  14993. $cw = $ch * $mw / $mh;
  14994. $bw = $cw * $cols;
  14995. $style['hpadding'] = ($w - $bw) / (2 * $cw);
  14996. } else {
  14997. // correct vertical distortion
  14998. $ch = $cw * $mh / $mw;
  14999. $bh = $ch * $rows;
  15000. $style['vpadding'] = ($h - $bh) / (2 * $ch);
  15001. }
  15002. }
  15003. // fit the barcode on available space
  15004. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
  15005. // set alignment
  15006. $this->img_rb_y = $y + $h;
  15007. // set alignment
  15008. if ($this->rtl) {
  15009. if ($style['position'] == 'L') {
  15010. $xpos = $this->lMargin;
  15011. } elseif ($style['position'] == 'C') {
  15012. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  15013. } elseif ($style['position'] == 'R') {
  15014. $xpos = $this->w - $this->rMargin - $w;
  15015. } else {
  15016. $xpos = $x - $w;
  15017. }
  15018. $this->img_rb_x = $xpos;
  15019. } else {
  15020. if ($style['position'] == 'L') {
  15021. $xpos = $this->lMargin;
  15022. } elseif ($style['position'] == 'C') {
  15023. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  15024. } elseif ($style['position'] == 'R') {
  15025. $xpos = $this->w - $this->rMargin - $w;
  15026. } else {
  15027. $xpos = $x;
  15028. }
  15029. $this->img_rb_x = $xpos + $w;
  15030. }
  15031. $xstart = $xpos + ($style['hpadding'] * $cw);
  15032. $ystart = $y + ($style['vpadding'] * $ch);
  15033. // barcode is always printed in LTR direction
  15034. $tempRTL = $this->rtl;
  15035. $this->rtl = false;
  15036. // print background color
  15037. if ($style['bgcolor']) {
  15038. $this->Rect($xpos, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  15039. } elseif ($style['border']) {
  15040. $this->Rect($xpos, $y, $w, $h, 'D');
  15041. }
  15042. // set foreground color
  15043. $this->SetDrawColorArray($style['fgcolor']);
  15044. // print barcode cells
  15045. // for each row
  15046. for ($r = 0; $r < $rows; ++$r) {
  15047. $xr = $xstart;
  15048. // for each column
  15049. for ($c = 0; $c < $cols; ++$c) {
  15050. if ($arrcode['bcode'][$r][$c] == 1) {
  15051. // draw a single barcode cell
  15052. $this->Rect($xr, $ystart, $cw, $ch, 'F', array(), $style['fgcolor']);
  15053. }
  15054. $xr += $cw;
  15055. }
  15056. $ystart += $ch;
  15057. }
  15058. // restore original direction
  15059. $this->rtl = $tempRTL;
  15060. // restore previous settings
  15061. $this->setGraphicVars($gvars);
  15062. // set pointer to align the next text/objects
  15063. switch($align) {
  15064. case 'T':{
  15065. $this->y = $y;
  15066. $this->x = $this->img_rb_x;
  15067. break;
  15068. }
  15069. case 'M':{
  15070. $this->y = $y + round($h/2);
  15071. $this->x = $this->img_rb_x;
  15072. break;
  15073. }
  15074. case 'B':{
  15075. $this->y = $this->img_rb_y;
  15076. $this->x = $this->img_rb_x;
  15077. break;
  15078. }
  15079. case 'N':{
  15080. $this->SetY($this->img_rb_y);
  15081. break;
  15082. }
  15083. default:{
  15084. break;
  15085. }
  15086. }
  15087. $this->endlinex = $this->img_rb_x;
  15088. }
  15089. /**
  15090. * Returns an array containing current margins:
  15091. * <ul>
  15092. <li>$ret['left'] = left margin</li>
  15093. <li>$ret['right'] = right margin</li>
  15094. <li>$ret['top'] = top margin</li>
  15095. <li>$ret['bottom'] = bottom margin</li>
  15096. <li>$ret['header'] = header margin</li>
  15097. <li>$ret['footer'] = footer margin</li>
  15098. <li>$ret['cell'] = cell padding array</li>
  15099. <li>$ret['padding_left'] = cell left padding</li>
  15100. <li>$ret['padding_top'] = cell top padding</li>
  15101. <li>$ret['padding_right'] = cell right padding</li>
  15102. <li>$ret['padding_bottom'] = cell bottom padding</li>
  15103. * </ul>
  15104. * @return array containing all margins measures
  15105. * @public
  15106. * @since 3.2.000 (2008-06-23)
  15107. */
  15108. public function getMargins() {
  15109. $ret = array(
  15110. 'left' => $this->lMargin,
  15111. 'right' => $this->rMargin,
  15112. 'top' => $this->tMargin,
  15113. 'bottom' => $this->bMargin,
  15114. 'header' => $this->header_margin,
  15115. 'footer' => $this->footer_margin,
  15116. 'cell' => $this->cell_padding,
  15117. 'padding_left' => $this->cell_padding['L'],
  15118. 'padding_top' => $this->cell_padding['T'],
  15119. 'padding_right' => $this->cell_padding['R'],
  15120. 'padding_bottom' => $this->cell_padding['B']
  15121. );
  15122. return $ret;
  15123. }
  15124. /**
  15125. * Returns an array containing original margins:
  15126. * <ul>
  15127. <li>$ret['left'] = left margin</li>
  15128. <li>$ret['right'] = right margin</li>
  15129. * </ul>
  15130. * @return array containing all margins measures
  15131. * @public
  15132. * @since 4.0.012 (2008-07-24)
  15133. */
  15134. public function getOriginalMargins() {
  15135. $ret = array(
  15136. 'left' => $this->original_lMargin,
  15137. 'right' => $this->original_rMargin
  15138. );
  15139. return $ret;
  15140. }
  15141. /**
  15142. * Returns the current font size.
  15143. * @return current font size
  15144. * @public
  15145. * @since 3.2.000 (2008-06-23)
  15146. */
  15147. public function getFontSize() {
  15148. return $this->FontSize;
  15149. }
  15150. /**
  15151. * Returns the current font size in points unit.
  15152. * @return current font size in points unit
  15153. * @public
  15154. * @since 3.2.000 (2008-06-23)
  15155. */
  15156. public function getFontSizePt() {
  15157. return $this->FontSizePt;
  15158. }
  15159. /**
  15160. * Returns the current font family name.
  15161. * @return string current font family name
  15162. * @public
  15163. * @since 4.3.008 (2008-12-05)
  15164. */
  15165. public function getFontFamily() {
  15166. return $this->FontFamily;
  15167. }
  15168. /**
  15169. * Returns the current font style.
  15170. * @return string current font style
  15171. * @public
  15172. * @since 4.3.008 (2008-12-05)
  15173. */
  15174. public function getFontStyle() {
  15175. return $this->FontStyle;
  15176. }
  15177. /**
  15178. * Cleanup HTML code (requires HTML Tidy library).
  15179. * @param $html (string) htmlcode to fix
  15180. * @param $default_css (string) CSS commands to add
  15181. * @param $tagvs (array) parameters for setHtmlVSpace method
  15182. * @param $tidy_options (array) options for tidy_parse_string function
  15183. * @return string XHTML code cleaned up
  15184. * @author Nicola Asuni
  15185. * @public
  15186. * @since 5.9.017 (2010-11-16)
  15187. * @see setHtmlVSpace()
  15188. */
  15189. public function fixHTMLCode($html, $default_css='', $tagvs='', $tidy_options='') {
  15190. return TCPDF_STATIC::fixHTMLCode($html, $default_css, $tagvs, $tidy_options, $this->tagvspaces);
  15191. }
  15192. /**
  15193. * Returns the border width from CSS property
  15194. * @param $width (string) border width
  15195. * @return int with in user units
  15196. * @protected
  15197. * @since 5.7.000 (2010-08-02)
  15198. */
  15199. protected function getCSSBorderWidth($width) {
  15200. if ($width == 'thin') {
  15201. $width = (2 / $this->k);
  15202. } elseif ($width == 'medium') {
  15203. $width = (4 / $this->k);
  15204. } elseif ($width == 'thick') {
  15205. $width = (6 / $this->k);
  15206. } else {
  15207. $width = $this->getHTMLUnitToUnits($width, 1, 'px', false);
  15208. }
  15209. return $width;
  15210. }
  15211. /**
  15212. * Returns the border dash style from CSS property
  15213. * @param $style (string) border style to convert
  15214. * @return int sash style (return -1 in case of none or hidden border)
  15215. * @protected
  15216. * @since 5.7.000 (2010-08-02)
  15217. */
  15218. protected function getCSSBorderDashStyle($style) {
  15219. switch (strtolower($style)) {
  15220. case 'none':
  15221. case 'hidden': {
  15222. $dash = -1;
  15223. break;
  15224. }
  15225. case 'dotted': {
  15226. $dash = 1;
  15227. break;
  15228. }
  15229. case 'dashed': {
  15230. $dash = 3;
  15231. break;
  15232. }
  15233. case 'double':
  15234. case 'groove':
  15235. case 'ridge':
  15236. case 'inset':
  15237. case 'outset':
  15238. case 'solid':
  15239. default: {
  15240. $dash = 0;
  15241. break;
  15242. }
  15243. }
  15244. return $dash;
  15245. }
  15246. /**
  15247. * Returns the border style array from CSS border properties
  15248. * @param $cssborder (string) border properties
  15249. * @return array containing border properties
  15250. * @protected
  15251. * @since 5.7.000 (2010-08-02)
  15252. */
  15253. protected function getCSSBorderStyle($cssborder) {
  15254. $bprop = preg_split('/[\s]+/', trim($cssborder));
  15255. $border = array(); // value to be returned
  15256. switch (count($bprop)) {
  15257. case 3: {
  15258. $width = $bprop[0];
  15259. $style = $bprop[1];
  15260. $color = $bprop[2];
  15261. break;
  15262. }
  15263. case 2: {
  15264. $width = 'medium';
  15265. $style = $bprop[0];
  15266. $color = $bprop[1];
  15267. break;
  15268. }
  15269. case 1: {
  15270. $width = 'medium';
  15271. $style = $bprop[0];
  15272. $color = 'black';
  15273. break;
  15274. }
  15275. default: {
  15276. $width = 'medium';
  15277. $style = 'solid';
  15278. $color = 'black';
  15279. break;
  15280. }
  15281. }
  15282. if ($style == 'none') {
  15283. return array();
  15284. }
  15285. $border['cap'] = 'square';
  15286. $border['join'] = 'miter';
  15287. $border['dash'] = $this->getCSSBorderDashStyle($style);
  15288. if ($border['dash'] < 0) {
  15289. return array();
  15290. }
  15291. $border['width'] = $this->getCSSBorderWidth($width);
  15292. $border['color'] = TCPDF_COLORS::convertHTMLColorToDec($color, $this->spot_colors);
  15293. return $border;
  15294. }
  15295. /**
  15296. * Get the internal Cell padding from CSS attribute.
  15297. * @param $csspadding (string) padding properties
  15298. * @param $width (float) width of the containing element
  15299. * @return array of cell paddings
  15300. * @public
  15301. * @since 5.9.000 (2010-10-04)
  15302. */
  15303. public function getCSSPadding($csspadding, $width=0) {
  15304. $padding = preg_split('/[\s]+/', trim($csspadding));
  15305. $cell_padding = array(); // value to be returned
  15306. switch (count($padding)) {
  15307. case 4: {
  15308. $cell_padding['T'] = $padding[0];
  15309. $cell_padding['R'] = $padding[1];
  15310. $cell_padding['B'] = $padding[2];
  15311. $cell_padding['L'] = $padding[3];
  15312. break;
  15313. }
  15314. case 3: {
  15315. $cell_padding['T'] = $padding[0];
  15316. $cell_padding['R'] = $padding[1];
  15317. $cell_padding['B'] = $padding[2];
  15318. $cell_padding['L'] = $padding[1];
  15319. break;
  15320. }
  15321. case 2: {
  15322. $cell_padding['T'] = $padding[0];
  15323. $cell_padding['R'] = $padding[1];
  15324. $cell_padding['B'] = $padding[0];
  15325. $cell_padding['L'] = $padding[1];
  15326. break;
  15327. }
  15328. case 1: {
  15329. $cell_padding['T'] = $padding[0];
  15330. $cell_padding['R'] = $padding[0];
  15331. $cell_padding['B'] = $padding[0];
  15332. $cell_padding['L'] = $padding[0];
  15333. break;
  15334. }
  15335. default: {
  15336. return $this->cell_padding;
  15337. }
  15338. }
  15339. if ($width == 0) {
  15340. $width = $this->w - $this->lMargin - $this->rMargin;
  15341. }
  15342. $cell_padding['T'] = $this->getHTMLUnitToUnits($cell_padding['T'], $width, 'px', false);
  15343. $cell_padding['R'] = $this->getHTMLUnitToUnits($cell_padding['R'], $width, 'px', false);
  15344. $cell_padding['B'] = $this->getHTMLUnitToUnits($cell_padding['B'], $width, 'px', false);
  15345. $cell_padding['L'] = $this->getHTMLUnitToUnits($cell_padding['L'], $width, 'px', false);
  15346. return $cell_padding;
  15347. }
  15348. /**
  15349. * Get the internal Cell margin from CSS attribute.
  15350. * @param $cssmargin (string) margin properties
  15351. * @param $width (float) width of the containing element
  15352. * @return array of cell margins
  15353. * @public
  15354. * @since 5.9.000 (2010-10-04)
  15355. */
  15356. public function getCSSMargin($cssmargin, $width=0) {
  15357. $margin = preg_split('/[\s]+/', trim($cssmargin));
  15358. $cell_margin = array(); // value to be returned
  15359. switch (count($margin)) {
  15360. case 4: {
  15361. $cell_margin['T'] = $margin[0];
  15362. $cell_margin['R'] = $margin[1];
  15363. $cell_margin['B'] = $margin[2];
  15364. $cell_margin['L'] = $margin[3];
  15365. break;
  15366. }
  15367. case 3: {
  15368. $cell_margin['T'] = $margin[0];
  15369. $cell_margin['R'] = $margin[1];
  15370. $cell_margin['B'] = $margin[2];
  15371. $cell_margin['L'] = $margin[1];
  15372. break;
  15373. }
  15374. case 2: {
  15375. $cell_margin['T'] = $margin[0];
  15376. $cell_margin['R'] = $margin[1];
  15377. $cell_margin['B'] = $margin[0];
  15378. $cell_margin['L'] = $margin[1];
  15379. break;
  15380. }
  15381. case 1: {
  15382. $cell_margin['T'] = $margin[0];
  15383. $cell_margin['R'] = $margin[0];
  15384. $cell_margin['B'] = $margin[0];
  15385. $cell_margin['L'] = $margin[0];
  15386. break;
  15387. }
  15388. default: {
  15389. return $this->cell_margin;
  15390. }
  15391. }
  15392. if ($width == 0) {
  15393. $width = $this->w - $this->lMargin - $this->rMargin;
  15394. }
  15395. $cell_margin['T'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['T']), $width, 'px', false);
  15396. $cell_margin['R'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['R']), $width, 'px', false);
  15397. $cell_margin['B'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['B']), $width, 'px', false);
  15398. $cell_margin['L'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['L']), $width, 'px', false);
  15399. return $cell_margin;
  15400. }
  15401. /**
  15402. * Get the border-spacing from CSS attribute.
  15403. * @param $cssbspace (string) border-spacing CSS properties
  15404. * @param $width (float) width of the containing element
  15405. * @return array of border spacings
  15406. * @public
  15407. * @since 5.9.010 (2010-10-27)
  15408. */
  15409. public function getCSSBorderMargin($cssbspace, $width=0) {
  15410. $space = preg_split('/[\s]+/', trim($cssbspace));
  15411. $border_spacing = array(); // value to be returned
  15412. switch (count($space)) {
  15413. case 2: {
  15414. $border_spacing['H'] = $space[0];
  15415. $border_spacing['V'] = $space[1];
  15416. break;
  15417. }
  15418. case 1: {
  15419. $border_spacing['H'] = $space[0];
  15420. $border_spacing['V'] = $space[0];
  15421. break;
  15422. }
  15423. default: {
  15424. return array('H' => 0, 'V' => 0);
  15425. }
  15426. }
  15427. if ($width == 0) {
  15428. $width = $this->w - $this->lMargin - $this->rMargin;
  15429. }
  15430. $border_spacing['H'] = $this->getHTMLUnitToUnits($border_spacing['H'], $width, 'px', false);
  15431. $border_spacing['V'] = $this->getHTMLUnitToUnits($border_spacing['V'], $width, 'px', false);
  15432. return $border_spacing;
  15433. }
  15434. /**
  15435. * Returns the letter-spacing value from CSS value
  15436. * @param $spacing (string) letter-spacing value
  15437. * @param $parent (float) font spacing (tracking) value of the parent element
  15438. * @return float quantity to increases or decreases the space between characters in a text.
  15439. * @protected
  15440. * @since 5.9.000 (2010-10-02)
  15441. */
  15442. protected function getCSSFontSpacing($spacing, $parent=0) {
  15443. $val = 0; // value to be returned
  15444. $spacing = trim($spacing);
  15445. switch ($spacing) {
  15446. case 'normal': {
  15447. $val = 0;
  15448. break;
  15449. }
  15450. case 'inherit': {
  15451. if ($parent == 'normal') {
  15452. $val = 0;
  15453. } else {
  15454. $val = $parent;
  15455. }
  15456. break;
  15457. }
  15458. default: {
  15459. $val = $this->getHTMLUnitToUnits($spacing, 0, 'px', false);
  15460. }
  15461. }
  15462. return $val;
  15463. }
  15464. /**
  15465. * Returns the percentage of font stretching from CSS value
  15466. * @param $stretch (string) stretch mode
  15467. * @param $parent (float) stretch value of the parent element
  15468. * @return float font stretching percentage
  15469. * @protected
  15470. * @since 5.9.000 (2010-10-02)
  15471. */
  15472. protected function getCSSFontStretching($stretch, $parent=100) {
  15473. $val = 100; // value to be returned
  15474. $stretch = trim($stretch);
  15475. switch ($stretch) {
  15476. case 'ultra-condensed': {
  15477. $val = 40;
  15478. break;
  15479. }
  15480. case 'extra-condensed': {
  15481. $val = 55;
  15482. break;
  15483. }
  15484. case 'condensed': {
  15485. $val = 70;
  15486. break;
  15487. }
  15488. case 'semi-condensed': {
  15489. $val = 85;
  15490. break;
  15491. }
  15492. case 'normal': {
  15493. $val = 100;
  15494. break;
  15495. }
  15496. case 'semi-expanded': {
  15497. $val = 115;
  15498. break;
  15499. }
  15500. case 'expanded': {
  15501. $val = 130;
  15502. break;
  15503. }
  15504. case 'extra-expanded': {
  15505. $val = 145;
  15506. break;
  15507. }
  15508. case 'ultra-expanded': {
  15509. $val = 160;
  15510. break;
  15511. }
  15512. case 'wider': {
  15513. $val = ($parent + 10);
  15514. break;
  15515. }
  15516. case 'narrower': {
  15517. $val = ($parent - 10);
  15518. break;
  15519. }
  15520. case 'inherit': {
  15521. if ($parent == 'normal') {
  15522. $val = 100;
  15523. } else {
  15524. $val = $parent;
  15525. }
  15526. break;
  15527. }
  15528. default: {
  15529. $val = $this->getHTMLUnitToUnits($stretch, 100, '%', false);
  15530. }
  15531. }
  15532. return $val;
  15533. }
  15534. /**
  15535. * Convert HTML string containing font size value to points
  15536. * @param $val (string) String containing font size value and unit.
  15537. * @param $refsize (float) Reference font size in points.
  15538. * @param $parent_size (float) Parent font size in points.
  15539. * @param $defaultunit (string) Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  15540. * @return float value in points
  15541. * @public
  15542. */
  15543. public function getHTMLFontUnits($val, $refsize=12, $parent_size=12, $defaultunit='pt') {
  15544. $refsize = TCPDF_FONTS::getFontRefSize($refsize);
  15545. $parent_size = TCPDF_FONTS::getFontRefSize($parent_size, $refsize);
  15546. switch ($val) {
  15547. case 'xx-small': {
  15548. $size = ($refsize - 4);
  15549. break;
  15550. }
  15551. case 'x-small': {
  15552. $size = ($refsize - 3);
  15553. break;
  15554. }
  15555. case 'small': {
  15556. $size = ($refsize - 2);
  15557. break;
  15558. }
  15559. case 'medium': {
  15560. $size = $refsize;
  15561. break;
  15562. }
  15563. case 'large': {
  15564. $size = ($refsize + 2);
  15565. break;
  15566. }
  15567. case 'x-large': {
  15568. $size = ($refsize + 4);
  15569. break;
  15570. }
  15571. case 'xx-large': {
  15572. $size = ($refsize + 6);
  15573. break;
  15574. }
  15575. case 'smaller': {
  15576. $size = ($parent_size - 3);
  15577. break;
  15578. }
  15579. case 'larger': {
  15580. $size = ($parent_size + 3);
  15581. break;
  15582. }
  15583. default: {
  15584. $size = $this->getHTMLUnitToUnits($val, $parent_size, $defaultunit, true);
  15585. }
  15586. }
  15587. return $size;
  15588. }
  15589. /**
  15590. * Returns the HTML DOM array.
  15591. * @param $html (string) html code
  15592. * @return array
  15593. * @protected
  15594. * @since 3.2.000 (2008-06-20)
  15595. */
  15596. protected function getHtmlDomArray($html) {
  15597. // array of CSS styles ( selector => properties).
  15598. $css = array();
  15599. // get CSS array defined at previous call
  15600. $matches = array();
  15601. if (preg_match_all('/<cssarray>([^\<]*)<\/cssarray>/isU', $html, $matches) > 0) {
  15602. if (isset($matches[1][0])) {
  15603. $css = array_merge($css, unserialize($this->unhtmlentities($matches[1][0])));
  15604. }
  15605. $html = preg_replace('/<cssarray>(.*?)<\/cssarray>/isU', '', $html);
  15606. }
  15607. // extract external CSS files
  15608. $matches = array();
  15609. if (preg_match_all('/<link([^\>]*)>/isU', $html, $matches) > 0) {
  15610. foreach ($matches[1] as $key => $link) {
  15611. $type = array();
  15612. if (preg_match('/type[\s]*=[\s]*"text\/css"/', $link, $type)) {
  15613. $type = array();
  15614. preg_match('/media[\s]*=[\s]*"([^"]*)"/', $link, $type);
  15615. // get 'all' and 'print' media, other media types are discarded
  15616. // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  15617. if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
  15618. $type = array();
  15619. if (preg_match('/href[\s]*=[\s]*"([^"]*)"/', $link, $type) > 0) {
  15620. // read CSS data file
  15621. $cssdata = TCPDF_STATIC::fileGetContents(trim($type[1]));
  15622. if (($cssdata !== FALSE) AND (strlen($cssdata) > 0)) {
  15623. $css = array_merge($css, TCPDF_STATIC::extractCSSproperties($cssdata));
  15624. }
  15625. }
  15626. }
  15627. }
  15628. }
  15629. }
  15630. // extract style tags
  15631. $matches = array();
  15632. if (preg_match_all('/<style([^\>]*)>([^\<]*)<\/style>/isU', $html, $matches) > 0) {
  15633. foreach ($matches[1] as $key => $media) {
  15634. $type = array();
  15635. preg_match('/media[\s]*=[\s]*"([^"]*)"/', $media, $type);
  15636. // get 'all' and 'print' media, other media types are discarded
  15637. // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  15638. if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
  15639. $cssdata = $matches[2][$key];
  15640. $css = array_merge($css, TCPDF_STATIC::extractCSSproperties($cssdata));
  15641. }
  15642. }
  15643. }
  15644. // create a special tag to contain the CSS array (used for table content)
  15645. $csstagarray = '<cssarray>'.htmlentities(serialize($css)).'</cssarray>';
  15646. // remove head and style blocks
  15647. $html = preg_replace('/<head([^\>]*)>(.*?)<\/head>/siU', '', $html);
  15648. $html = preg_replace('/<style([^\>]*)>([^\<]*)<\/style>/isU', '', $html);
  15649. // define block tags
  15650. $blocktags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table','tr','td');
  15651. // define self-closing tags
  15652. $selfclosingtags = array('area','base','basefont','br','hr','input','img','link','meta');
  15653. // remove all unsupported tags (the line below lists all supported tags)
  15654. $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>');
  15655. //replace some blank characters
  15656. $html = preg_replace('/<pre/', '<xre', $html); // preserve pre tag
  15657. $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);
  15658. $html = preg_replace('@(\r\n|\r)@', "\n", $html);
  15659. $repTable = array("\t" => ' ', "\0" => ' ', "\x0B" => ' ', "\\" => "\\\\");
  15660. $html = strtr($html, $repTable);
  15661. $offset = 0;
  15662. while (($offset < strlen($html)) AND ($pos = strpos($html, '</pre>', $offset)) !== false) {
  15663. $html_a = substr($html, 0, $offset);
  15664. $html_b = substr($html, $offset, ($pos - $offset + 6));
  15665. while (preg_match("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", $html_b)) {
  15666. // preserve newlines on <pre> tag
  15667. $html_b = preg_replace("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", "<xre\\1>\\2<br />\\3</pre>", $html_b);
  15668. }
  15669. while (preg_match("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], $html_b)) {
  15670. // preserve spaces on <pre> tag
  15671. $html_b = preg_replace("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], "<xre\\1>\\2&nbsp;\\3</pre>", $html_b);
  15672. }
  15673. $html = $html_a.$html_b.substr($html, $pos + 6);
  15674. $offset = strlen($html_a.$html_b);
  15675. }
  15676. $offset = 0;
  15677. while (($offset < strlen($html)) AND ($pos = strpos($html, '</textarea>', $offset)) !== false) {
  15678. $html_a = substr($html, 0, $offset);
  15679. $html_b = substr($html, $offset, ($pos - $offset + 11));
  15680. while (preg_match("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", $html_b)) {
  15681. // preserve newlines on <textarea> tag
  15682. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", "<textarea\\1>\\2<TBR>\\3</textarea>", $html_b);
  15683. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)[\"](.*?)</textarea>'si", "<textarea\\1>\\2''\\3</textarea>", $html_b);
  15684. }
  15685. $html = $html_a.$html_b.substr($html, $pos + 11);
  15686. $offset = strlen($html_a.$html_b);
  15687. }
  15688. $html = preg_replace('/([\s]*)<option/si', '<option', $html);
  15689. $html = preg_replace('/<\/option>([\s]*)/si', '</option>', $html);
  15690. $offset = 0;
  15691. while (($offset < strlen($html)) AND ($pos = strpos($html, '</option>', $offset)) !== false) {
  15692. $html_a = substr($html, 0, $offset);
  15693. $html_b = substr($html, $offset, ($pos - $offset + 9));
  15694. while (preg_match("'<option([^\>]*)>(.*?)</option>'si", $html_b)) {
  15695. $html_b = preg_replace("'<option([\s]+)value=\"([^\"]*)\"([^\>]*)>(.*?)</option>'si", "\\2#!TaB!#\\4#!NwL!#", $html_b);
  15696. $html_b = preg_replace("'<option([^\>]*)>(.*?)</option>'si", "\\2#!NwL!#", $html_b);
  15697. }
  15698. $html = $html_a.$html_b.substr($html, $pos + 9);
  15699. $offset = strlen($html_a.$html_b);
  15700. }
  15701. if (preg_match("'</select'si", $html)) {
  15702. $html = preg_replace("'<select([^\>]*)>'si", "<select\\1 opt=\"", $html);
  15703. $html = preg_replace("'#!NwL!#</select>'si", "\" />", $html);
  15704. }
  15705. $html = str_replace("\n", ' ', $html);
  15706. // restore textarea newlines
  15707. $html = str_replace('<TBR>', "\n", $html);
  15708. // remove extra spaces from code
  15709. $html = preg_replace('/[\s]+<\/(table|tr|ul|ol|dl)>/', '</\\1>', $html);
  15710. $html = preg_replace('/'.$this->re_space['p'].'+<\/(td|th|li|dt|dd)>/'.$this->re_space['m'], '</\\1>', $html);
  15711. $html = preg_replace('/[\s]+<(tr|td|th|li|dt|dd)/', '<\\1', $html);
  15712. $html = preg_replace('/'.$this->re_space['p'].'+<(ul|ol|dl|br)/'.$this->re_space['m'], '<\\1', $html);
  15713. $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);
  15714. $html = preg_replace('/<\/(td|th)>/', '<marker style="font-size:0"/></\\1>', $html);
  15715. $html = preg_replace('/<\/table>([\s]*)<marker style="font-size:0"\/>/', '</table>', $html);
  15716. $html = preg_replace('/'.$this->re_space['p'].'+<img/'.$this->re_space['m'], chr(32).'<img', $html);
  15717. $html = preg_replace('/<img([^\>]*)>[\s]+([^\<])/xi', '<img\\1>&nbsp;\\2', $html);
  15718. $html = preg_replace('/<img([^\>]*)>/xi', '<img\\1><span><marker style="font-size:0"/></span>', $html);
  15719. $html = preg_replace('/<xre/', '<pre', $html); // restore pre tag
  15720. $html = preg_replace('/<textarea([^\>]*)>([^\<]*)<\/textarea>/xi', '<textarea\\1 value="\\2" />', $html);
  15721. $html = preg_replace('/<li([^\>]*)><\/li>/', '<li\\1>&nbsp;</li>', $html);
  15722. $html = preg_replace('/<li([^\>]*)>'.$this->re_space['p'].'*<img/'.$this->re_space['m'], '<li\\1><font size="1">&nbsp;</font><img', $html);
  15723. $html = preg_replace('/<([^\>\/]*)>[\s]/', '<\\1>&nbsp;', $html); // preserve some spaces
  15724. $html = preg_replace('/[\s]<\/([^\>]*)>/', '&nbsp;</\\1>', $html); // preserve some spaces
  15725. $html = preg_replace('/<su([bp])/', '<zws/><su\\1', $html); // fix sub/sup alignment
  15726. $html = preg_replace('/<\/su([bp])>/', '</su\\1><zws/>', $html); // fix sub/sup alignment
  15727. $html = preg_replace('/'.$this->re_space['p'].'+/'.$this->re_space['m'], chr(32), $html); // replace multiple spaces with a single space
  15728. // trim string
  15729. $html = $this->stringTrim($html);
  15730. // fix br tag after li
  15731. $html = preg_replace('/<li><br([^\>]*)>/', '<li> <br\\1>', $html);
  15732. // fix first image tag alignment
  15733. $html = preg_replace('/^<img/', '<span style="font-size:0"><br /></span> <img', $html, 1);
  15734. // pattern for generic tag
  15735. $tagpattern = '/(<[^>]+>)/';
  15736. // explodes the string
  15737. $a = preg_split($tagpattern, $html, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  15738. // count elements
  15739. $maxel = count($a);
  15740. $elkey = 0;
  15741. $key = 0;
  15742. // create an array of elements
  15743. $dom = array();
  15744. $dom[$key] = array();
  15745. // set inheritable properties fot the first void element
  15746. // 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
  15747. $dom[$key]['tag'] = false;
  15748. $dom[$key]['block'] = false;
  15749. $dom[$key]['value'] = '';
  15750. $dom[$key]['parent'] = 0;
  15751. $dom[$key]['hide'] = false;
  15752. $dom[$key]['fontname'] = $this->FontFamily;
  15753. $dom[$key]['fontstyle'] = $this->FontStyle;
  15754. $dom[$key]['fontsize'] = $this->FontSizePt;
  15755. $dom[$key]['font-stretch'] = $this->font_stretching;
  15756. $dom[$key]['letter-spacing'] = $this->font_spacing;
  15757. $dom[$key]['stroke'] = $this->textstrokewidth;
  15758. $dom[$key]['fill'] = (($this->textrendermode % 2) == 0);
  15759. $dom[$key]['clip'] = ($this->textrendermode > 3);
  15760. $dom[$key]['line-height'] = $this->cell_height_ratio;
  15761. $dom[$key]['bgcolor'] = false;
  15762. $dom[$key]['fgcolor'] = $this->fgcolor; // color
  15763. $dom[$key]['strokecolor'] = $this->strokecolor;
  15764. $dom[$key]['align'] = '';
  15765. $dom[$key]['listtype'] = '';
  15766. $dom[$key]['text-indent'] = 0;
  15767. $dom[$key]['border'] = array();
  15768. $dom[$key]['dir'] = $this->rtl?'rtl':'ltr';
  15769. $thead = false; // true when we are inside the THEAD tag
  15770. ++$key;
  15771. $level = array();
  15772. array_push($level, 0); // root
  15773. while ($elkey < $maxel) {
  15774. $dom[$key] = array();
  15775. $element = $a[$elkey];
  15776. $dom[$key]['elkey'] = $elkey;
  15777. if (preg_match($tagpattern, $element)) {
  15778. // html tag
  15779. $element = substr($element, 1, -1);
  15780. // get tag name
  15781. preg_match('/[\/]?([a-zA-Z0-9]*)/', $element, $tag);
  15782. $tagname = strtolower($tag[1]);
  15783. // check if we are inside a table header
  15784. if ($tagname == 'thead') {
  15785. if ($element{0} == '/') {
  15786. $thead = false;
  15787. } else {
  15788. $thead = true;
  15789. }
  15790. ++$elkey;
  15791. continue;
  15792. }
  15793. $dom[$key]['tag'] = true;
  15794. $dom[$key]['value'] = $tagname;
  15795. if (in_array($dom[$key]['value'], $blocktags)) {
  15796. $dom[$key]['block'] = true;
  15797. } else {
  15798. $dom[$key]['block'] = false;
  15799. }
  15800. if ($element{0} == '/') {
  15801. // *** closing html tag
  15802. $dom[$key]['opening'] = false;
  15803. $dom[$key]['parent'] = end($level);
  15804. array_pop($level);
  15805. $dom[$key]['hide'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['hide'];
  15806. $dom[$key]['fontname'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontname'];
  15807. $dom[$key]['fontstyle'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontstyle'];
  15808. $dom[$key]['fontsize'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize'];
  15809. $dom[$key]['font-stretch'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['font-stretch'];
  15810. $dom[$key]['letter-spacing'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['letter-spacing'];
  15811. $dom[$key]['stroke'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['stroke'];
  15812. $dom[$key]['fill'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fill'];
  15813. $dom[$key]['clip'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['clip'];
  15814. $dom[$key]['line-height'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['line-height'];
  15815. $dom[$key]['bgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor'];
  15816. $dom[$key]['fgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor'];
  15817. $dom[$key]['strokecolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['strokecolor'];
  15818. $dom[$key]['align'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['align'];
  15819. $dom[$key]['dir'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['dir'];
  15820. if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) {
  15821. $dom[$key]['listtype'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'];
  15822. }
  15823. // set the number of columns in table tag
  15824. if (($dom[$key]['value'] == 'tr') AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) {
  15825. $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'] = $dom[($dom[$key]['parent'])]['cols'];
  15826. }
  15827. if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  15828. $dom[($dom[$key]['parent'])]['content'] = $csstagarray;
  15829. for ($i = ($dom[$key]['parent'] + 1); $i < $key; ++$i) {
  15830. $dom[($dom[$key]['parent'])]['content'] .= $a[$dom[$i]['elkey']];
  15831. }
  15832. $key = $i;
  15833. // mark nested tables
  15834. $dom[($dom[$key]['parent'])]['content'] = str_replace('<table', '<table nested="true"', $dom[($dom[$key]['parent'])]['content']);
  15835. // remove thead sections from nested tables
  15836. $dom[($dom[$key]['parent'])]['content'] = str_replace('<thead>', '', $dom[($dom[$key]['parent'])]['content']);
  15837. $dom[($dom[$key]['parent'])]['content'] = str_replace('</thead>', '', $dom[($dom[$key]['parent'])]['content']);
  15838. }
  15839. // store header rows on a new table
  15840. if (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['thead'] === true)) {
  15841. if (TCPDF_STATIC::empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) {
  15842. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] = $csstagarray.$a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']];
  15843. }
  15844. for ($i = $dom[$key]['parent']; $i <= $key; ++$i) {
  15845. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] .= $a[$dom[$i]['elkey']];
  15846. }
  15847. if (!isset($dom[($dom[$key]['parent'])]['attribute'])) {
  15848. $dom[($dom[$key]['parent'])]['attribute'] = array();
  15849. }
  15850. // header elements must be always contained in a single page
  15851. $dom[($dom[$key]['parent'])]['attribute']['nobr'] = 'true';
  15852. }
  15853. if (($dom[$key]['value'] == 'table') AND (!TCPDF_STATIC::empty_string($dom[($dom[$key]['parent'])]['thead']))) {
  15854. // remove the nobr attributes from the table header
  15855. $dom[($dom[$key]['parent'])]['thead'] = str_replace(' nobr="true"', '', $dom[($dom[$key]['parent'])]['thead']);
  15856. $dom[($dom[$key]['parent'])]['thead'] .= '</tablehead>';
  15857. }
  15858. } else {
  15859. // *** opening or self-closing html tag
  15860. $dom[$key]['opening'] = true;
  15861. $dom[$key]['parent'] = end($level);
  15862. if ((substr($element, -1, 1) == '/') OR (in_array($dom[$key]['value'], $selfclosingtags))) {
  15863. // self-closing tag
  15864. $dom[$key]['self'] = true;
  15865. } else {
  15866. // opening tag
  15867. array_push($level, $key);
  15868. $dom[$key]['self'] = false;
  15869. }
  15870. // copy some values from parent
  15871. $parentkey = 0;
  15872. if ($key > 0) {
  15873. $parentkey = $dom[$key]['parent'];
  15874. $dom[$key]['hide'] = $dom[$parentkey]['hide'];
  15875. $dom[$key]['fontname'] = $dom[$parentkey]['fontname'];
  15876. $dom[$key]['fontstyle'] = $dom[$parentkey]['fontstyle'];
  15877. $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'];
  15878. $dom[$key]['font-stretch'] = $dom[$parentkey]['font-stretch'];
  15879. $dom[$key]['letter-spacing'] = $dom[$parentkey]['letter-spacing'];
  15880. $dom[$key]['stroke'] = $dom[$parentkey]['stroke'];
  15881. $dom[$key]['fill'] = $dom[$parentkey]['fill'];
  15882. $dom[$key]['clip'] = $dom[$parentkey]['clip'];
  15883. $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
  15884. $dom[$key]['bgcolor'] = $dom[$parentkey]['bgcolor'];
  15885. $dom[$key]['fgcolor'] = $dom[$parentkey]['fgcolor'];
  15886. $dom[$key]['strokecolor'] = $dom[$parentkey]['strokecolor'];
  15887. $dom[$key]['align'] = $dom[$parentkey]['align'];
  15888. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  15889. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  15890. $dom[$key]['border'] = array();
  15891. $dom[$key]['dir'] = $dom[$parentkey]['dir'];
  15892. }
  15893. // get attributes
  15894. preg_match_all('/([^=\s]*)[\s]*=[\s]*"([^"]*)"/', $element, $attr_array, PREG_PATTERN_ORDER);
  15895. $dom[$key]['attribute'] = array(); // reset attribute array
  15896. while (list($id, $name) = each($attr_array[1])) {
  15897. $dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id];
  15898. }
  15899. if (!empty($css)) {
  15900. // merge CSS style to current style
  15901. list($dom[$key]['csssel'], $dom[$key]['cssdata']) = TCPDF_STATIC::getCSSdataArray($dom, $key, $css);
  15902. $dom[$key]['attribute']['style'] = TCPDF_STATIC::getTagStyleFromCSSarray($dom[$key]['cssdata']);
  15903. }
  15904. // split style attributes
  15905. if (isset($dom[$key]['attribute']['style']) AND !empty($dom[$key]['attribute']['style'])) {
  15906. // get style attributes
  15907. preg_match_all('/([^;:\s]*):([^;]*)/', $dom[$key]['attribute']['style'], $style_array, PREG_PATTERN_ORDER);
  15908. $dom[$key]['style'] = array(); // reset style attribute array
  15909. while (list($id, $name) = each($style_array[1])) {
  15910. // in case of duplicate attribute the last replace the previous
  15911. $dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]);
  15912. }
  15913. // --- get some style attributes ---
  15914. // text direction
  15915. if (isset($dom[$key]['style']['direction'])) {
  15916. $dom[$key]['dir'] = $dom[$key]['style']['direction'];
  15917. }
  15918. // display
  15919. if (isset($dom[$key]['style']['display'])) {
  15920. $dom[$key]['hide'] = (trim(strtolower($dom[$key]['style']['display'])) == 'none');
  15921. }
  15922. // font family
  15923. if (isset($dom[$key]['style']['font-family'])) {
  15924. $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['style']['font-family']);
  15925. }
  15926. // list-style-type
  15927. if (isset($dom[$key]['style']['list-style-type'])) {
  15928. $dom[$key]['listtype'] = trim(strtolower($dom[$key]['style']['list-style-type']));
  15929. if ($dom[$key]['listtype'] == 'inherit') {
  15930. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  15931. }
  15932. }
  15933. // text-indent
  15934. if (isset($dom[$key]['style']['text-indent'])) {
  15935. $dom[$key]['text-indent'] = $this->getHTMLUnitToUnits($dom[$key]['style']['text-indent']);
  15936. if ($dom[$key]['text-indent'] == 'inherit') {
  15937. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  15938. }
  15939. }
  15940. // font size
  15941. if (isset($dom[$key]['style']['font-size'])) {
  15942. $fsize = trim($dom[$key]['style']['font-size']);
  15943. $dom[$key]['fontsize'] = $this->getHTMLFontUnits($fsize, $dom[0]['fontsize'], $dom[$parentkey]['fontsize'], 'pt');
  15944. }
  15945. // font-stretch
  15946. if (isset($dom[$key]['style']['font-stretch'])) {
  15947. $dom[$key]['font-stretch'] = $this->getCSSFontStretching($dom[$key]['style']['font-stretch'], $dom[$parentkey]['font-stretch']);
  15948. }
  15949. // letter-spacing
  15950. if (isset($dom[$key]['style']['letter-spacing'])) {
  15951. $dom[$key]['letter-spacing'] = $this->getCSSFontSpacing($dom[$key]['style']['letter-spacing'], $dom[$parentkey]['letter-spacing']);
  15952. }
  15953. // line-height (internally is the cell height ratio)
  15954. if (isset($dom[$key]['style']['line-height'])) {
  15955. $lineheight = trim($dom[$key]['style']['line-height']);
  15956. switch ($lineheight) {
  15957. // A normal line height. This is default
  15958. case 'normal': {
  15959. $dom[$key]['line-height'] = $dom[0]['line-height'];
  15960. break;
  15961. }
  15962. case 'inherit': {
  15963. $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
  15964. }
  15965. default: {
  15966. if (is_numeric($lineheight)) {
  15967. // convert to percentage of font height
  15968. $lineheight = ($lineheight * 100).'%';
  15969. }
  15970. $dom[$key]['line-height'] = $this->getHTMLUnitToUnits($lineheight, 1, '%', true);
  15971. if (substr($lineheight, -1) !== '%') {
  15972. $dom[$key]['line-height'] = (($dom[$key]['line-height'] - $this->cell_padding['T'] - $this->cell_padding['B']) / $dom[$key]['fontsize']);
  15973. }
  15974. }
  15975. }
  15976. }
  15977. // font style
  15978. if (isset($dom[$key]['style']['font-weight'])) {
  15979. if (strtolower($dom[$key]['style']['font-weight']{0}) == 'n') {
  15980. if (strpos($dom[$key]['fontstyle'], 'B') !== false) {
  15981. $dom[$key]['fontstyle'] = str_replace('B', '', $dom[$key]['fontstyle']);
  15982. }
  15983. } elseif (strtolower($dom[$key]['style']['font-weight']{0}) == 'b') {
  15984. $dom[$key]['fontstyle'] .= 'B';
  15985. }
  15986. }
  15987. if (isset($dom[$key]['style']['font-style']) AND (strtolower($dom[$key]['style']['font-style']{0}) == 'i')) {
  15988. $dom[$key]['fontstyle'] .= 'I';
  15989. }
  15990. // font color
  15991. if (isset($dom[$key]['style']['color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['style']['color']))) {
  15992. $dom[$key]['fgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['color'], $this->spot_colors);
  15993. } elseif ($dom[$key]['value'] == 'a') {
  15994. $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  15995. }
  15996. // background color
  15997. if (isset($dom[$key]['style']['background-color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['style']['background-color']))) {
  15998. $dom[$key]['bgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['background-color'], $this->spot_colors);
  15999. }
  16000. // text-decoration
  16001. if (isset($dom[$key]['style']['text-decoration'])) {
  16002. $decors = explode(' ', strtolower($dom[$key]['style']['text-decoration']));
  16003. foreach ($decors as $dec) {
  16004. $dec = trim($dec);
  16005. if (!TCPDF_STATIC::empty_string($dec)) {
  16006. if ($dec{0} == 'u') {
  16007. // underline
  16008. $dom[$key]['fontstyle'] .= 'U';
  16009. } elseif ($dec{0} == 'l') {
  16010. // line-through
  16011. $dom[$key]['fontstyle'] .= 'D';
  16012. } elseif ($dec{0} == 'o') {
  16013. // overline
  16014. $dom[$key]['fontstyle'] .= 'O';
  16015. }
  16016. }
  16017. }
  16018. } elseif ($dom[$key]['value'] == 'a') {
  16019. $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  16020. }
  16021. // check for width attribute
  16022. if (isset($dom[$key]['style']['width'])) {
  16023. $dom[$key]['width'] = $dom[$key]['style']['width'];
  16024. }
  16025. // check for height attribute
  16026. if (isset($dom[$key]['style']['height'])) {
  16027. $dom[$key]['height'] = $dom[$key]['style']['height'];
  16028. }
  16029. // check for text alignment
  16030. if (isset($dom[$key]['style']['text-align'])) {
  16031. $dom[$key]['align'] = strtoupper($dom[$key]['style']['text-align']{0});
  16032. }
  16033. // check for CSS border properties
  16034. if (isset($dom[$key]['style']['border'])) {
  16035. $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border']);
  16036. if (!empty($borderstyle)) {
  16037. $dom[$key]['border']['LTRB'] = $borderstyle;
  16038. }
  16039. }
  16040. if (isset($dom[$key]['style']['border-color'])) {
  16041. $brd_colors = preg_split('/[\s]+/', trim($dom[$key]['style']['border-color']));
  16042. if (isset($brd_colors[3])) {
  16043. $dom[$key]['border']['L']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[3], $this->spot_colors);
  16044. }
  16045. if (isset($brd_colors[1])) {
  16046. $dom[$key]['border']['R']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[1], $this->spot_colors);
  16047. }
  16048. if (isset($brd_colors[0])) {
  16049. $dom[$key]['border']['T']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[0], $this->spot_colors);
  16050. }
  16051. if (isset($brd_colors[2])) {
  16052. $dom[$key]['border']['B']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[2], $this->spot_colors);
  16053. }
  16054. }
  16055. if (isset($dom[$key]['style']['border-width'])) {
  16056. $brd_widths = preg_split('/[\s]+/', trim($dom[$key]['style']['border-width']));
  16057. if (isset($brd_widths[3])) {
  16058. $dom[$key]['border']['L']['width'] = $this->getCSSBorderWidth($brd_widths[3]);
  16059. }
  16060. if (isset($brd_widths[1])) {
  16061. $dom[$key]['border']['R']['width'] = $this->getCSSBorderWidth($brd_widths[1]);
  16062. }
  16063. if (isset($brd_widths[0])) {
  16064. $dom[$key]['border']['T']['width'] = $this->getCSSBorderWidth($brd_widths[0]);
  16065. }
  16066. if (isset($brd_widths[2])) {
  16067. $dom[$key]['border']['B']['width'] = $this->getCSSBorderWidth($brd_widths[2]);
  16068. }
  16069. }
  16070. if (isset($dom[$key]['style']['border-style'])) {
  16071. $brd_styles = preg_split('/[\s]+/', trim($dom[$key]['style']['border-style']));
  16072. if (isset($brd_styles[3]) AND ($brd_styles[3]!='none')) {
  16073. $dom[$key]['border']['L']['cap'] = 'square';
  16074. $dom[$key]['border']['L']['join'] = 'miter';
  16075. $dom[$key]['border']['L']['dash'] = $this->getCSSBorderDashStyle($brd_styles[3]);
  16076. if ($dom[$key]['border']['L']['dash'] < 0) {
  16077. $dom[$key]['border']['L'] = array();
  16078. }
  16079. }
  16080. if (isset($brd_styles[1])) {
  16081. $dom[$key]['border']['R']['cap'] = 'square';
  16082. $dom[$key]['border']['R']['join'] = 'miter';
  16083. $dom[$key]['border']['R']['dash'] = $this->getCSSBorderDashStyle($brd_styles[1]);
  16084. if ($dom[$key]['border']['R']['dash'] < 0) {
  16085. $dom[$key]['border']['R'] = array();
  16086. }
  16087. }
  16088. if (isset($brd_styles[0])) {
  16089. $dom[$key]['border']['T']['cap'] = 'square';
  16090. $dom[$key]['border']['T']['join'] = 'miter';
  16091. $dom[$key]['border']['T']['dash'] = $this->getCSSBorderDashStyle($brd_styles[0]);
  16092. if ($dom[$key]['border']['T']['dash'] < 0) {
  16093. $dom[$key]['border']['T'] = array();
  16094. }
  16095. }
  16096. if (isset($brd_styles[2])) {
  16097. $dom[$key]['border']['B']['cap'] = 'square';
  16098. $dom[$key]['border']['B']['join'] = 'miter';
  16099. $dom[$key]['border']['B']['dash'] = $this->getCSSBorderDashStyle($brd_styles[2]);
  16100. if ($dom[$key]['border']['B']['dash'] < 0) {
  16101. $dom[$key]['border']['B'] = array();
  16102. }
  16103. }
  16104. }
  16105. $cellside = array('L' => 'left', 'R' => 'right', 'T' => 'top', 'B' => 'bottom');
  16106. foreach ($cellside as $bsk => $bsv) {
  16107. if (isset($dom[$key]['style']['border-'.$bsv])) {
  16108. $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border-'.$bsv]);
  16109. if (!empty($borderstyle)) {
  16110. $dom[$key]['border'][$bsk] = $borderstyle;
  16111. }
  16112. }
  16113. if (isset($dom[$key]['style']['border-'.$bsv.'-color'])) {
  16114. $dom[$key]['border'][$bsk]['color'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['border-'.$bsv.'-color'], $this->spot_colors);
  16115. }
  16116. if (isset($dom[$key]['style']['border-'.$bsv.'-width'])) {
  16117. $dom[$key]['border'][$bsk]['width'] = $this->getCSSBorderWidth($dom[$key]['style']['border-'.$bsv.'-width']);
  16118. }
  16119. if (isset($dom[$key]['style']['border-'.$bsv.'-style'])) {
  16120. $dom[$key]['border'][$bsk]['dash'] = $this->getCSSBorderDashStyle($dom[$key]['style']['border-'.$bsv.'-style']);
  16121. if ($dom[$key]['border'][$bsk]['dash'] < 0) {
  16122. $dom[$key]['border'][$bsk] = array();
  16123. }
  16124. }
  16125. }
  16126. // check for CSS padding properties
  16127. if (isset($dom[$key]['style']['padding'])) {
  16128. $dom[$key]['padding'] = $this->getCSSPadding($dom[$key]['style']['padding']);
  16129. } else {
  16130. $dom[$key]['padding'] = $this->cell_padding;
  16131. }
  16132. foreach ($cellside as $psk => $psv) {
  16133. if (isset($dom[$key]['style']['padding-'.$psv])) {
  16134. $dom[$key]['padding'][$psk] = $this->getHTMLUnitToUnits($dom[$key]['style']['padding-'.$psv], 0, 'px', false);
  16135. }
  16136. }
  16137. // check for CSS margin properties
  16138. if (isset($dom[$key]['style']['margin'])) {
  16139. $dom[$key]['margin'] = $this->getCSSMargin($dom[$key]['style']['margin']);
  16140. } else {
  16141. $dom[$key]['margin'] = $this->cell_margin;
  16142. }
  16143. foreach ($cellside as $psk => $psv) {
  16144. if (isset($dom[$key]['style']['margin-'.$psv])) {
  16145. $dom[$key]['margin'][$psk] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $dom[$key]['style']['margin-'.$psv]), 0, 'px', false);
  16146. }
  16147. }
  16148. // check for CSS border-spacing properties
  16149. if (isset($dom[$key]['style']['border-spacing'])) {
  16150. $dom[$key]['border-spacing'] = $this->getCSSBorderMargin($dom[$key]['style']['border-spacing']);
  16151. }
  16152. // page-break-inside
  16153. if (isset($dom[$key]['style']['page-break-inside']) AND ($dom[$key]['style']['page-break-inside'] == 'avoid')) {
  16154. $dom[$key]['attribute']['nobr'] = 'true';
  16155. }
  16156. // page-break-before
  16157. if (isset($dom[$key]['style']['page-break-before'])) {
  16158. if ($dom[$key]['style']['page-break-before'] == 'always') {
  16159. $dom[$key]['attribute']['pagebreak'] = 'true';
  16160. } elseif ($dom[$key]['style']['page-break-before'] == 'left') {
  16161. $dom[$key]['attribute']['pagebreak'] = 'left';
  16162. } elseif ($dom[$key]['style']['page-break-before'] == 'right') {
  16163. $dom[$key]['attribute']['pagebreak'] = 'right';
  16164. }
  16165. }
  16166. // page-break-after
  16167. if (isset($dom[$key]['style']['page-break-after'])) {
  16168. if ($dom[$key]['style']['page-break-after'] == 'always') {
  16169. $dom[$key]['attribute']['pagebreakafter'] = 'true';
  16170. } elseif ($dom[$key]['style']['page-break-after'] == 'left') {
  16171. $dom[$key]['attribute']['pagebreakafter'] = 'left';
  16172. } elseif ($dom[$key]['style']['page-break-after'] == 'right') {
  16173. $dom[$key]['attribute']['pagebreakafter'] = 'right';
  16174. }
  16175. }
  16176. }
  16177. if (isset($dom[$key]['attribute']['display'])) {
  16178. $dom[$key]['hide'] = (trim(strtolower($dom[$key]['attribute']['display'])) == 'none');
  16179. }
  16180. if (isset($dom[$key]['attribute']['border']) AND ($dom[$key]['attribute']['border'] != 0)) {
  16181. $borderstyle = $this->getCSSBorderStyle($dom[$key]['attribute']['border'].' solid black');
  16182. if (!empty($borderstyle)) {
  16183. $dom[$key]['border']['LTRB'] = $borderstyle;
  16184. }
  16185. }
  16186. // check for font tag
  16187. if ($dom[$key]['value'] == 'font') {
  16188. // font family
  16189. if (isset($dom[$key]['attribute']['face'])) {
  16190. $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['attribute']['face']);
  16191. }
  16192. // font size
  16193. if (isset($dom[$key]['attribute']['size'])) {
  16194. if ($key > 0) {
  16195. if ($dom[$key]['attribute']['size']{0} == '+') {
  16196. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] + intval(substr($dom[$key]['attribute']['size'], 1));
  16197. } elseif ($dom[$key]['attribute']['size']{0} == '-') {
  16198. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] - intval(substr($dom[$key]['attribute']['size'], 1));
  16199. } else {
  16200. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  16201. }
  16202. } else {
  16203. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  16204. }
  16205. }
  16206. }
  16207. // force natural alignment for lists
  16208. if ((($dom[$key]['value'] == 'ul') OR ($dom[$key]['value'] == 'ol') OR ($dom[$key]['value'] == 'dl'))
  16209. AND (!isset($dom[$key]['align']) OR TCPDF_STATIC::empty_string($dom[$key]['align']) OR ($dom[$key]['align'] != 'J'))) {
  16210. if ($this->rtl) {
  16211. $dom[$key]['align'] = 'R';
  16212. } else {
  16213. $dom[$key]['align'] = 'L';
  16214. }
  16215. }
  16216. if (($dom[$key]['value'] == 'small') OR ($dom[$key]['value'] == 'sup') OR ($dom[$key]['value'] == 'sub')) {
  16217. if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
  16218. $dom[$key]['fontsize'] = $dom[$key]['fontsize'] * K_SMALL_RATIO;
  16219. }
  16220. }
  16221. if (($dom[$key]['value'] == 'strong') OR ($dom[$key]['value'] == 'b')) {
  16222. $dom[$key]['fontstyle'] .= 'B';
  16223. }
  16224. if (($dom[$key]['value'] == 'em') OR ($dom[$key]['value'] == 'i')) {
  16225. $dom[$key]['fontstyle'] .= 'I';
  16226. }
  16227. if ($dom[$key]['value'] == 'u') {
  16228. $dom[$key]['fontstyle'] .= 'U';
  16229. }
  16230. if (($dom[$key]['value'] == 'del') OR ($dom[$key]['value'] == 's') OR ($dom[$key]['value'] == 'strike')) {
  16231. $dom[$key]['fontstyle'] .= 'D';
  16232. }
  16233. if (!isset($dom[$key]['style']['text-decoration']) AND ($dom[$key]['value'] == 'a')) {
  16234. $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  16235. }
  16236. if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) {
  16237. $dom[$key]['fontname'] = $this->default_monospaced_font;
  16238. }
  16239. if (($dom[$key]['value']{0} == 'h') AND (intval($dom[$key]['value']{1}) > 0) AND (intval($dom[$key]['value']{1}) < 7)) {
  16240. // headings h1, h2, h3, h4, h5, h6
  16241. if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
  16242. $headsize = (4 - intval($dom[$key]['value']{1})) * 2;
  16243. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + $headsize;
  16244. }
  16245. if (!isset($dom[$key]['style']['font-weight'])) {
  16246. $dom[$key]['fontstyle'] .= 'B';
  16247. }
  16248. }
  16249. if (($dom[$key]['value'] == 'table')) {
  16250. $dom[$key]['rows'] = 0; // number of rows
  16251. $dom[$key]['trids'] = array(); // IDs of TR elements
  16252. $dom[$key]['thead'] = ''; // table header rows
  16253. }
  16254. if (($dom[$key]['value'] == 'tr')) {
  16255. $dom[$key]['cols'] = 0;
  16256. if ($thead) {
  16257. $dom[$key]['thead'] = true;
  16258. // rows on thead block are printed as a separate table
  16259. } else {
  16260. $dom[$key]['thead'] = false;
  16261. // store the number of rows on table element
  16262. ++$dom[($dom[$key]['parent'])]['rows'];
  16263. // store the TR elements IDs on table element
  16264. array_push($dom[($dom[$key]['parent'])]['trids'], $key);
  16265. }
  16266. }
  16267. if (($dom[$key]['value'] == 'th') OR ($dom[$key]['value'] == 'td')) {
  16268. if (isset($dom[$key]['attribute']['colspan'])) {
  16269. $colspan = intval($dom[$key]['attribute']['colspan']);
  16270. } else {
  16271. $colspan = 1;
  16272. }
  16273. $dom[$key]['attribute']['colspan'] = $colspan;
  16274. $dom[($dom[$key]['parent'])]['cols'] += $colspan;
  16275. }
  16276. // text direction
  16277. if (isset($dom[$key]['attribute']['dir'])) {
  16278. $dom[$key]['dir'] = $dom[$key]['attribute']['dir'];
  16279. }
  16280. // set foreground color attribute
  16281. if (isset($dom[$key]['attribute']['color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['color']))) {
  16282. $dom[$key]['fgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['color'], $this->spot_colors);
  16283. } elseif (!isset($dom[$key]['style']['color']) AND ($dom[$key]['value'] == 'a')) {
  16284. $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  16285. }
  16286. // set background color attribute
  16287. if (isset($dom[$key]['attribute']['bgcolor']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['bgcolor']))) {
  16288. $dom[$key]['bgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['bgcolor'], $this->spot_colors);
  16289. }
  16290. // set stroke color attribute
  16291. if (isset($dom[$key]['attribute']['strokecolor']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['strokecolor']))) {
  16292. $dom[$key]['strokecolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['strokecolor'], $this->spot_colors);
  16293. }
  16294. // check for width attribute
  16295. if (isset($dom[$key]['attribute']['width'])) {
  16296. $dom[$key]['width'] = $dom[$key]['attribute']['width'];
  16297. }
  16298. // check for height attribute
  16299. if (isset($dom[$key]['attribute']['height'])) {
  16300. $dom[$key]['height'] = $dom[$key]['attribute']['height'];
  16301. }
  16302. // check for text alignment
  16303. if (isset($dom[$key]['attribute']['align']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['align'])) AND ($dom[$key]['value'] !== 'img')) {
  16304. $dom[$key]['align'] = strtoupper($dom[$key]['attribute']['align']{0});
  16305. }
  16306. // check for text rendering mode (the following attributes do not exist in HTML)
  16307. if (isset($dom[$key]['attribute']['stroke'])) {
  16308. // font stroke width
  16309. $dom[$key]['stroke'] = $this->getHTMLUnitToUnits($dom[$key]['attribute']['stroke'], $dom[$key]['fontsize'], 'pt', true);
  16310. }
  16311. if (isset($dom[$key]['attribute']['fill'])) {
  16312. // font fill
  16313. if ($dom[$key]['attribute']['fill'] == 'true') {
  16314. $dom[$key]['fill'] = true;
  16315. } else {
  16316. $dom[$key]['fill'] = false;
  16317. }
  16318. }
  16319. if (isset($dom[$key]['attribute']['clip'])) {
  16320. // clipping mode
  16321. if ($dom[$key]['attribute']['clip'] == 'true') {
  16322. $dom[$key]['clip'] = true;
  16323. } else {
  16324. $dom[$key]['clip'] = false;
  16325. }
  16326. }
  16327. } // end opening tag
  16328. } else {
  16329. // text
  16330. $dom[$key]['tag'] = false;
  16331. $dom[$key]['block'] = false;
  16332. //$element = str_replace('&nbsp;', TCPDF_FONTS::unichr(160, $this->isunicode), $element);
  16333. $dom[$key]['value'] = stripslashes($this->unhtmlentities($element));
  16334. $dom[$key]['parent'] = end($level);
  16335. $dom[$key]['dir'] = $dom[$dom[$key]['parent']]['dir'];
  16336. }
  16337. ++$elkey;
  16338. ++$key;
  16339. }
  16340. return $dom;
  16341. }
  16342. /**
  16343. * Returns the string used to find spaces
  16344. * @return string
  16345. * @protected
  16346. * @author Nicola Asuni
  16347. * @since 4.8.024 (2010-01-15)
  16348. */
  16349. protected function getSpaceString() {
  16350. $spacestr = chr(32);
  16351. if ($this->isUnicodeFont()) {
  16352. $spacestr = chr(0).chr(32);
  16353. }
  16354. return $spacestr;
  16355. }
  16356. /**
  16357. * Serialize an array of parameters to be used with TCPDF tag in HTML code.
  16358. * @param $pararray (array) parameters array
  16359. * @return sting containing serialized data
  16360. * @since 4.9.006 (2010-04-02)
  16361. * @public
  16362. * @deprecated
  16363. */
  16364. public function serializeTCPDFtagParameters($pararray) {
  16365. return TCPDF_STATIC::serializeTCPDFtagParameters($pararray);
  16366. }
  16367. /**
  16368. * Prints a cell (rectangular area) with optional borders, background color and html text string.
  16369. * 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 />
  16370. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  16371. * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  16372. * 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
  16373. * NOTE: all the HTML attributes must be enclosed in double-quote.
  16374. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  16375. * @param $h (float) Cell minimum height. The cell extends automatically if needed.
  16376. * @param $x (float) upper-left corner X coordinate
  16377. * @param $y (float) upper-left corner Y coordinate
  16378. * @param $html (string) html text to print. Default value: empty string.
  16379. * @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)))
  16380. * @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>
  16381. Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  16382. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  16383. * @param $reseth (boolean) if true reset the last cell height (default true).
  16384. * @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>
  16385. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width.
  16386. * @see Multicell(), writeHTML()
  16387. * @public
  16388. */
  16389. public function writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true) {
  16390. return $this->MultiCell($w, $h, $html, $border, $align, $fill, $ln, $x, $y, $reseth, 0, true, $autopadding, 0, 'T', false);
  16391. }
  16392. /**
  16393. * Allows to preserve some HTML formatting (limited support).<br />
  16394. * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  16395. * 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
  16396. * NOTE: all the HTML attributes must be enclosed in double-quote.
  16397. * @param $html (string) text to display
  16398. * @param $ln (boolean) if true add a new line after text (default = true)
  16399. * @param $fill (boolean) Indicates if the background must be painted (true) or transparent (false).
  16400. * @param $reseth (boolean) if true reset the last cell height (default false).
  16401. * @param $cell (boolean) if true add the current left (or right for RTL) padding to each Write (default false).
  16402. * @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>
  16403. * @public
  16404. */
  16405. public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='') {
  16406. $gvars = $this->getGraphicVars();
  16407. // store current values
  16408. $prev_cell_margin = $this->cell_margin;
  16409. $prev_cell_padding = $this->cell_padding;
  16410. $prevPage = $this->page;
  16411. $prevlMargin = $this->lMargin;
  16412. $prevrMargin = $this->rMargin;
  16413. $curfontname = $this->FontFamily;
  16414. $curfontstyle = $this->FontStyle;
  16415. $curfontsize = $this->FontSizePt;
  16416. $curfontascent = $this->getFontAscent($curfontname, $curfontstyle, $curfontsize);
  16417. $curfontdescent = $this->getFontDescent($curfontname, $curfontstyle, $curfontsize);
  16418. $curfontstretcing = $this->font_stretching;
  16419. $curfonttracking = $this->font_spacing;
  16420. $this->newline = true;
  16421. $newline = true;
  16422. $startlinepage = $this->page;
  16423. $minstartliney = $this->y;
  16424. $maxbottomliney = 0;
  16425. $startlinex = $this->x;
  16426. $startliney = $this->y;
  16427. $yshift = 0;
  16428. $loop = 0;
  16429. $curpos = 0;
  16430. $this_method_vars = array();
  16431. $undo = false;
  16432. $fontaligned = false;
  16433. $reverse_dir = false; // true when the text direction is reversed
  16434. $this->premode = false;
  16435. if ($this->inxobj) {
  16436. // we are inside an XObject template
  16437. $pask = count($this->xobjects[$this->xobjid]['annotations']);
  16438. } elseif (isset($this->PageAnnots[$this->page])) {
  16439. $pask = count($this->PageAnnots[$this->page]);
  16440. } else {
  16441. $pask = 0;
  16442. }
  16443. if ($this->inxobj) {
  16444. // we are inside an XObject template
  16445. $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
  16446. } elseif (!$this->InFooter) {
  16447. if (isset($this->footerlen[$this->page])) {
  16448. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  16449. } else {
  16450. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  16451. }
  16452. $startlinepos = $this->footerpos[$this->page];
  16453. } else {
  16454. // we are inside the footer
  16455. $startlinepos = $this->pagelen[$this->page];
  16456. }
  16457. $lalign = $align;
  16458. $plalign = $align;
  16459. if ($this->rtl) {
  16460. $w = $this->x - $this->lMargin;
  16461. } else {
  16462. $w = $this->w - $this->rMargin - $this->x;
  16463. }
  16464. $w -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  16465. if ($cell) {
  16466. if ($this->rtl) {
  16467. $this->x -= $this->cell_padding['R'];
  16468. $this->lMargin += $this->cell_padding['R'];
  16469. } else {
  16470. $this->x += $this->cell_padding['L'];
  16471. $this->rMargin += $this->cell_padding['L'];
  16472. }
  16473. }
  16474. if ($this->customlistindent >= 0) {
  16475. $this->listindent = $this->customlistindent;
  16476. } else {
  16477. $this->listindent = $this->GetStringWidth('000000');
  16478. }
  16479. $this->listindentlevel = 0;
  16480. // save previous states
  16481. $prev_cell_height_ratio = $this->cell_height_ratio;
  16482. $prev_listnum = $this->listnum;
  16483. $prev_listordered = $this->listordered;
  16484. $prev_listcount = $this->listcount;
  16485. $prev_lispacer = $this->lispacer;
  16486. $this->listnum = 0;
  16487. $this->listordered = array();
  16488. $this->listcount = array();
  16489. $this->lispacer = '';
  16490. if ((TCPDF_STATIC::empty_string($this->lasth)) OR ($reseth)) {
  16491. // reset row height
  16492. $this->resetLastH();
  16493. }
  16494. $dom = $this->getHtmlDomArray($html);
  16495. $maxel = count($dom);
  16496. $key = 0;
  16497. while ($key < $maxel) {
  16498. if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND $dom[$key]['hide']) {
  16499. // store the node key
  16500. $hidden_node_key = $key;
  16501. if ($dom[$key]['self']) {
  16502. // skip just this self-closing tag
  16503. ++$key;
  16504. } else {
  16505. // skip this and all children tags
  16506. while (($key < $maxel) AND (!$dom[$key]['tag'] OR $dom[$key]['opening'] OR ($dom[$key]['parent'] != $hidden_node_key))) {
  16507. // skip hidden objects
  16508. ++$key;
  16509. }
  16510. ++$key;
  16511. }
  16512. }
  16513. if ($dom[$key]['tag'] AND isset($dom[$key]['attribute']['pagebreak'])) {
  16514. // check for pagebreak
  16515. if (($dom[$key]['attribute']['pagebreak'] == 'true') OR ($dom[$key]['attribute']['pagebreak'] == 'left') OR ($dom[$key]['attribute']['pagebreak'] == 'right')) {
  16516. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  16517. $this->checkPageBreak($this->PageBreakTrigger + 1);
  16518. $this->htmlvspace = ($this->PageBreakTrigger + 1);
  16519. }
  16520. if ((($dom[$key]['attribute']['pagebreak'] == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  16521. OR (($dom[$key]['attribute']['pagebreak'] == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  16522. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  16523. $this->checkPageBreak($this->PageBreakTrigger + 1);
  16524. $this->htmlvspace = ($this->PageBreakTrigger + 1);
  16525. }
  16526. }
  16527. if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND isset($dom[$key]['attribute']['nobr']) AND ($dom[$key]['attribute']['nobr'] == 'true')) {
  16528. if (isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) {
  16529. $dom[$key]['attribute']['nobr'] = false;
  16530. } else {
  16531. // store current object
  16532. $this->startTransaction();
  16533. // save this method vars
  16534. $this_method_vars['html'] = $html;
  16535. $this_method_vars['ln'] = $ln;
  16536. $this_method_vars['fill'] = $fill;
  16537. $this_method_vars['reseth'] = $reseth;
  16538. $this_method_vars['cell'] = $cell;
  16539. $this_method_vars['align'] = $align;
  16540. $this_method_vars['gvars'] = $gvars;
  16541. $this_method_vars['prevPage'] = $prevPage;
  16542. $this_method_vars['prev_cell_margin'] = $prev_cell_margin;
  16543. $this_method_vars['prev_cell_padding'] = $prev_cell_padding;
  16544. $this_method_vars['prevlMargin'] = $prevlMargin;
  16545. $this_method_vars['prevrMargin'] = $prevrMargin;
  16546. $this_method_vars['curfontname'] = $curfontname;
  16547. $this_method_vars['curfontstyle'] = $curfontstyle;
  16548. $this_method_vars['curfontsize'] = $curfontsize;
  16549. $this_method_vars['curfontascent'] = $curfontascent;
  16550. $this_method_vars['curfontdescent'] = $curfontdescent;
  16551. $this_method_vars['curfontstretcing'] = $curfontstretcing;
  16552. $this_method_vars['curfonttracking'] = $curfonttracking;
  16553. $this_method_vars['minstartliney'] = $minstartliney;
  16554. $this_method_vars['maxbottomliney'] = $maxbottomliney;
  16555. $this_method_vars['yshift'] = $yshift;
  16556. $this_method_vars['startlinepage'] = $startlinepage;
  16557. $this_method_vars['startlinepos'] = $startlinepos;
  16558. $this_method_vars['startlinex'] = $startlinex;
  16559. $this_method_vars['startliney'] = $startliney;
  16560. $this_method_vars['newline'] = $newline;
  16561. $this_method_vars['loop'] = $loop;
  16562. $this_method_vars['curpos'] = $curpos;
  16563. $this_method_vars['pask'] = $pask;
  16564. $this_method_vars['lalign'] = $lalign;
  16565. $this_method_vars['plalign'] = $plalign;
  16566. $this_method_vars['w'] = $w;
  16567. $this_method_vars['prev_cell_height_ratio'] = $prev_cell_height_ratio;
  16568. $this_method_vars['prev_listnum'] = $prev_listnum;
  16569. $this_method_vars['prev_listordered'] = $prev_listordered;
  16570. $this_method_vars['prev_listcount'] = $prev_listcount;
  16571. $this_method_vars['prev_lispacer'] = $prev_lispacer;
  16572. $this_method_vars['fontaligned'] = $fontaligned;
  16573. $this_method_vars['key'] = $key;
  16574. $this_method_vars['dom'] = $dom;
  16575. }
  16576. }
  16577. // print THEAD block
  16578. if (($dom[$key]['value'] == 'tr') AND isset($dom[$key]['thead']) AND $dom[$key]['thead']) {
  16579. if (isset($dom[$key]['parent']) AND isset($dom[$dom[$key]['parent']]['thead']) AND !TCPDF_STATIC::empty_string($dom[$dom[$key]['parent']]['thead'])) {
  16580. $this->inthead = true;
  16581. // print table header (thead)
  16582. $this->writeHTML($this->thead, false, false, false, false, '');
  16583. // check if we are on a new page or on a new column
  16584. if (($this->y < $this->start_transaction_y) OR ($this->checkPageBreak($this->lasth, '', false))) {
  16585. // we are on a new page or on a new column and the total object height is less than the available vertical space.
  16586. // restore previous object
  16587. $this->rollbackTransaction(true);
  16588. // restore previous values
  16589. foreach ($this_method_vars as $vkey => $vval) {
  16590. $$vkey = $vval;
  16591. }
  16592. // disable table header
  16593. $tmp_thead = $this->thead;
  16594. $this->thead = '';
  16595. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  16596. $pre_y = $this->y;
  16597. if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
  16598. // fix for multicolumn mode
  16599. $startliney = $this->y;
  16600. }
  16601. $this->start_transaction_page = $this->page;
  16602. $this->start_transaction_y = $this->y;
  16603. // restore table header
  16604. $this->thead = $tmp_thead;
  16605. // fix table border properties
  16606. if (isset($dom[$dom[$key]['parent']]['attribute']['cellspacing'])) {
  16607. $tmp_cellspacing = $this->getHTMLUnitToUnits($dom[$dom[$key]['parent']]['attribute']['cellspacing'], 1, 'px');
  16608. } elseif (isset($dom[$dom[$key]['parent']]['border-spacing'])) {
  16609. $tmp_cellspacing = $dom[$dom[$key]['parent']]['border-spacing']['V'];
  16610. } else {
  16611. $tmp_cellspacing = 0;
  16612. }
  16613. $dom[$dom[$key]['parent']]['borderposition']['page'] = $this->page;
  16614. $dom[$dom[$key]['parent']]['borderposition']['column'] = $this->current_column;
  16615. $dom[$dom[$key]['parent']]['borderposition']['y'] = $this->y + $tmp_cellspacing;
  16616. $xoffset = ($this->x - $dom[$dom[$key]['parent']]['borderposition']['x']);
  16617. $dom[$dom[$key]['parent']]['borderposition']['x'] += $xoffset;
  16618. $dom[$dom[$key]['parent']]['borderposition']['xmax'] += $xoffset;
  16619. // print table header (thead)
  16620. $this->writeHTML($this->thead, false, false, false, false, '');
  16621. }
  16622. }
  16623. // move $key index forward to skip THEAD block
  16624. while ( ($key < $maxel) AND (!(
  16625. ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'tr') AND (!isset($dom[$key]['thead']) OR !$dom[$key]['thead']))
  16626. OR ($dom[$key]['tag'] AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == 'table'))) )) {
  16627. ++$key;
  16628. }
  16629. }
  16630. if ($dom[$key]['tag'] OR ($key == 0)) {
  16631. if ((($dom[$key]['value'] == 'table') OR ($dom[$key]['value'] == 'tr')) AND (isset($dom[$key]['align']))) {
  16632. $dom[$key]['align'] = ($this->rtl) ? 'R' : 'L';
  16633. }
  16634. // vertically align image in line
  16635. if ((!$this->newline) AND ($dom[$key]['value'] == 'img') AND (isset($dom[$key]['height'])) AND ($dom[$key]['height'] > 0)) {
  16636. // get image height
  16637. $imgh = $this->getHTMLUnitToUnits($dom[$key]['height'], $this->lasth, 'px');
  16638. $autolinebreak = false;
  16639. if (isset($dom[$key]['width']) AND ($dom[$key]['width'] > 0)) {
  16640. $imgw = $this->getHTMLUnitToUnits($dom[$key]['width'], 1, 'px', false);
  16641. if (($imgw <= ($this->w - $this->lMargin - $this->rMargin - $this->cell_padding['L'] - $this->cell_padding['R']))
  16642. AND ((($this->rtl) AND (($this->x - $imgw) < ($this->lMargin + $this->cell_padding['L'])))
  16643. OR ((!$this->rtl) AND (($this->x + $imgw) > ($this->w - $this->rMargin - $this->cell_padding['R']))))) {
  16644. // add automatic line break
  16645. $autolinebreak = true;
  16646. $this->Ln('', $cell);
  16647. if ((!$dom[($key-1)]['tag']) AND ($dom[($key-1)]['value'] == ' ')) {
  16648. // go back to evaluate this line break
  16649. --$key;
  16650. }
  16651. }
  16652. }
  16653. if (!$autolinebreak) {
  16654. if ($this->inPageBody()) {
  16655. $pre_y = $this->y;
  16656. // check for page break
  16657. if ((!$this->checkPageBreak($imgh)) AND ($this->y < $pre_y)) {
  16658. // fix for multicolumn mode
  16659. $startliney = $this->y;
  16660. }
  16661. }
  16662. if ($this->page > $startlinepage) {
  16663. // fix line splitted over two pages
  16664. if (isset($this->footerlen[$startlinepage])) {
  16665. $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  16666. }
  16667. // line to be moved one page forward
  16668. $pagebuff = $this->getPageBuffer($startlinepage);
  16669. $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
  16670. $tstart = substr($pagebuff, 0, $startlinepos);
  16671. $tend = substr($this->getPageBuffer($startlinepage), $curpos);
  16672. // remove line from previous page
  16673. $this->setPageBuffer($startlinepage, $tstart.''.$tend);
  16674. $pagebuff = $this->getPageBuffer($this->page);
  16675. $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
  16676. $tend = substr($pagebuff, $this->cntmrk[$this->page]);
  16677. // add line start to current page
  16678. $yshift = ($minstartliney - $this->y);
  16679. if ($fontaligned) {
  16680. $yshift += ($curfontsize / $this->k);
  16681. }
  16682. $try = sprintf('1 0 0 1 0 %F cm', ($yshift * $this->k));
  16683. $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  16684. // shift the annotations and links
  16685. if (isset($this->PageAnnots[$this->page])) {
  16686. $next_pask = count($this->PageAnnots[$this->page]);
  16687. } else {
  16688. $next_pask = 0;
  16689. }
  16690. if (isset($this->PageAnnots[$startlinepage])) {
  16691. foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
  16692. if ($pak >= $pask) {
  16693. $this->PageAnnots[$this->page][] = $pac;
  16694. unset($this->PageAnnots[$startlinepage][$pak]);
  16695. $npak = count($this->PageAnnots[$this->page]) - 1;
  16696. $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  16697. }
  16698. }
  16699. }
  16700. $pask = $next_pask;
  16701. $startlinepos = $this->cntmrk[$this->page];
  16702. $startlinepage = $this->page;
  16703. $startliney = $this->y;
  16704. $this->newline = false;
  16705. }
  16706. $this->y += (($this->getCellHeight($curfontsize / $this->k) + $curfontascent - $curfontdescent) / 2) - $imgh;
  16707. $minstartliney = min($this->y, $minstartliney);
  16708. $maxbottomliney = ($startliney + $this->getCellHeight($this->FontSize));
  16709. }
  16710. } elseif (isset($dom[$key]['fontname']) OR isset($dom[$key]['fontstyle']) OR isset($dom[$key]['fontsize']) OR isset($dom[$key]['line-height'])) {
  16711. // account for different font size
  16712. $pfontname = $curfontname;
  16713. $pfontstyle = $curfontstyle;
  16714. $pfontsize = $curfontsize;
  16715. $fontname = (isset($dom[$key]['fontname']) ? $dom[$key]['fontname'] : $curfontname);
  16716. $fontstyle = (isset($dom[$key]['fontstyle']) ? $dom[$key]['fontstyle'] : $curfontstyle);
  16717. $fontsize = (isset($dom[$key]['fontsize']) ? $dom[$key]['fontsize'] : $curfontsize);
  16718. $fontascent = $this->getFontAscent($fontname, $fontstyle, $fontsize);
  16719. $fontdescent = $this->getFontDescent($fontname, $fontstyle, $fontsize);
  16720. if (($fontname != $curfontname) OR ($fontstyle != $curfontstyle) OR ($fontsize != $curfontsize)
  16721. OR ($this->cell_height_ratio != $dom[$key]['line-height'])
  16722. OR ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li')) ) {
  16723. if (($key < ($maxel - 1)) AND (
  16724. ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li'))
  16725. OR ($this->cell_height_ratio != $dom[$key]['line-height'])
  16726. OR (!$this->newline AND is_numeric($fontsize) AND is_numeric($curfontsize) AND ($fontsize >= 0) AND ($curfontsize >= 0) AND ($fontsize != $curfontsize))
  16727. )) {
  16728. if ($this->page > $startlinepage) {
  16729. // fix lines splitted over two pages
  16730. if (isset($this->footerlen[$startlinepage])) {
  16731. $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  16732. }
  16733. // line to be moved one page forward
  16734. $pagebuff = $this->getPageBuffer($startlinepage);
  16735. $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
  16736. $tstart = substr($pagebuff, 0, $startlinepos);
  16737. $tend = substr($this->getPageBuffer($startlinepage), $curpos);
  16738. // remove line start from previous page
  16739. $this->setPageBuffer($startlinepage, $tstart.''.$tend);
  16740. $pagebuff = $this->getPageBuffer($this->page);
  16741. $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
  16742. $tend = substr($pagebuff, $this->cntmrk[$this->page]);
  16743. // add line start to current page
  16744. $yshift = ($minstartliney - $this->y);
  16745. $try = sprintf('1 0 0 1 0 %F cm', ($yshift * $this->k));
  16746. $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  16747. // shift the annotations and links
  16748. if (isset($this->PageAnnots[$this->page])) {
  16749. $next_pask = count($this->PageAnnots[$this->page]);
  16750. } else {
  16751. $next_pask = 0;
  16752. }
  16753. if (isset($this->PageAnnots[$startlinepage])) {
  16754. foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
  16755. if ($pak >= $pask) {
  16756. $this->PageAnnots[$this->page][] = $pac;
  16757. unset($this->PageAnnots[$startlinepage][$pak]);
  16758. $npak = count($this->PageAnnots[$this->page]) - 1;
  16759. $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  16760. }
  16761. }
  16762. }
  16763. $pask = $next_pask;
  16764. $startlinepos = $this->cntmrk[$this->page];
  16765. $startlinepage = $this->page;
  16766. $startliney = $this->y;
  16767. }
  16768. if (!isset($dom[$key]['line-height'])) {
  16769. $dom[$key]['line-height'] = $this->cell_height_ratio;
  16770. }
  16771. if (!$dom[$key]['block']) {
  16772. 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']))) {
  16773. $this->y += (((($curfontsize * $this->cell_height_ratio) - ($fontsize * $dom[$key]['line-height'])) / $this->k) + $curfontascent - $fontascent - $curfontdescent + $fontdescent) / 2;
  16774. }
  16775. if (($dom[$key]['value'] != 'sup') AND ($dom[$key]['value'] != 'sub')) {
  16776. $current_line_align_data = array($key, $minstartliney, $maxbottomliney);
  16777. 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)))) {
  16778. $minstartliney = min($this->y, $line_align_data[1]);
  16779. $maxbottomliney = max(($this->y + $this->getCellHeight($fontsize / $this->k)), $line_align_data[2]);
  16780. } else {
  16781. $minstartliney = min($this->y, $minstartliney);
  16782. $maxbottomliney = max(($this->y + $this->getCellHeight($fontsize / $this->k)), $maxbottomliney);
  16783. }
  16784. $line_align_data = $current_line_align_data;
  16785. }
  16786. }
  16787. $this->cell_height_ratio = $dom[$key]['line-height'];
  16788. $fontaligned = true;
  16789. }
  16790. $this->SetFont($fontname, $fontstyle, $fontsize);
  16791. // reset row height
  16792. $this->resetLastH();
  16793. $curfontname = $fontname;
  16794. $curfontstyle = $fontstyle;
  16795. $curfontsize = $fontsize;
  16796. $curfontascent = $fontascent;
  16797. $curfontdescent = $fontdescent;
  16798. }
  16799. }
  16800. // set text rendering mode
  16801. $textstroke = isset($dom[$key]['stroke']) ? $dom[$key]['stroke'] : $this->textstrokewidth;
  16802. $textfill = isset($dom[$key]['fill']) ? $dom[$key]['fill'] : (($this->textrendermode % 2) == 0);
  16803. $textclip = isset($dom[$key]['clip']) ? $dom[$key]['clip'] : ($this->textrendermode > 3);
  16804. $this->setTextRenderingMode($textstroke, $textfill, $textclip);
  16805. if (isset($dom[$key]['font-stretch']) AND ($dom[$key]['font-stretch'] !== false)) {
  16806. $this->setFontStretching($dom[$key]['font-stretch']);
  16807. }
  16808. if (isset($dom[$key]['letter-spacing']) AND ($dom[$key]['letter-spacing'] !== false)) {
  16809. $this->setFontSpacing($dom[$key]['letter-spacing']);
  16810. }
  16811. if (($plalign == 'J') AND $dom[$key]['block']) {
  16812. $plalign = '';
  16813. }
  16814. // get current position on page buffer
  16815. $curpos = $this->pagelen[$startlinepage];
  16816. if (isset($dom[$key]['bgcolor']) AND ($dom[$key]['bgcolor'] !== false)) {
  16817. $this->SetFillColorArray($dom[$key]['bgcolor']);
  16818. $wfill = true;
  16819. } else {
  16820. $wfill = $fill | false;
  16821. }
  16822. if (isset($dom[$key]['fgcolor']) AND ($dom[$key]['fgcolor'] !== false)) {
  16823. $this->SetTextColorArray($dom[$key]['fgcolor']);
  16824. }
  16825. if (isset($dom[$key]['strokecolor']) AND ($dom[$key]['strokecolor'] !== false)) {
  16826. $this->SetDrawColorArray($dom[$key]['strokecolor']);
  16827. }
  16828. if (isset($dom[$key]['align'])) {
  16829. $lalign = $dom[$key]['align'];
  16830. }
  16831. if (TCPDF_STATIC::empty_string($lalign)) {
  16832. $lalign = $align;
  16833. }
  16834. }
  16835. // align lines
  16836. if ($this->newline AND (strlen($dom[$key]['value']) > 0) AND ($dom[$key]['value'] != 'td') AND ($dom[$key]['value'] != 'th')) {
  16837. $newline = true;
  16838. $fontaligned = false;
  16839. // we are at the beginning of a new line
  16840. if (isset($startlinex)) {
  16841. $yshift = ($minstartliney - $startliney);
  16842. if (($yshift > 0) OR ($this->page > $startlinepage)) {
  16843. $yshift = 0;
  16844. }
  16845. $t_x = 0;
  16846. // the last line must be shifted to be aligned as requested
  16847. $linew = abs($this->endlinex - $startlinex);
  16848. if ($this->inxobj) {
  16849. // we are inside an XObject template
  16850. $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
  16851. if (isset($opentagpos)) {
  16852. $midpos = $opentagpos;
  16853. } else {
  16854. $midpos = 0;
  16855. }
  16856. if ($midpos > 0) {
  16857. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
  16858. $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  16859. } else {
  16860. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  16861. $pend = '';
  16862. }
  16863. } else {
  16864. $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
  16865. if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  16866. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  16867. $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
  16868. } elseif (isset($opentagpos)) {
  16869. $midpos = $opentagpos;
  16870. } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  16871. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  16872. $midpos = $this->footerpos[$startlinepage];
  16873. } else {
  16874. $midpos = 0;
  16875. }
  16876. if ($midpos > 0) {
  16877. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
  16878. $pend = substr($this->getPageBuffer($startlinepage), $midpos);
  16879. } else {
  16880. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
  16881. $pend = '';
  16882. }
  16883. }
  16884. if ((isset($plalign) AND ((($plalign == 'C') OR ($plalign == 'J') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
  16885. // calculate shifting amount
  16886. $tw = $w;
  16887. if (($plalign == 'J') AND $this->isRTLTextDir() AND ($this->num_columns > 1)) {
  16888. $tw += $this->cell_padding['R'];
  16889. }
  16890. if ($this->lMargin != $prevlMargin) {
  16891. $tw += ($prevlMargin - $this->lMargin);
  16892. }
  16893. if ($this->rMargin != $prevrMargin) {
  16894. $tw += ($prevrMargin - $this->rMargin);
  16895. }
  16896. $one_space_width = $this->GetStringWidth(chr(32));
  16897. $no = 0; // number of spaces on a line contained on a single block
  16898. if ($this->isRTLTextDir()) { // RTL
  16899. // remove left space if exist
  16900. $pos1 = TCPDF_STATIC::revstrpos($pmid, '[(');
  16901. if ($pos1 > 0) {
  16902. $pos1 = intval($pos1);
  16903. if ($this->isUnicodeFont()) {
  16904. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(0).chr(32)));
  16905. $spacelen = 2;
  16906. } else {
  16907. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(32)));
  16908. $spacelen = 1;
  16909. }
  16910. if ($pos1 == $pos2) {
  16911. $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
  16912. if (substr($pmid, $pos1, 4) == '[()]') {
  16913. $linew -= $one_space_width;
  16914. } elseif ($pos1 == strpos($pmid, '[(')) {
  16915. $no = 1;
  16916. }
  16917. }
  16918. }
  16919. } else { // LTR
  16920. // remove right space if exist
  16921. $pos1 = TCPDF_STATIC::revstrpos($pmid, ')]');
  16922. if ($pos1 > 0) {
  16923. $pos1 = intval($pos1);
  16924. if ($this->isUnicodeFont()) {
  16925. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(0).chr(32).')]')) + 2;
  16926. $spacelen = 2;
  16927. } else {
  16928. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(32).')]')) + 1;
  16929. $spacelen = 1;
  16930. }
  16931. if ($pos1 == $pos2) {
  16932. $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
  16933. $linew -= $one_space_width;
  16934. }
  16935. }
  16936. }
  16937. $mdiff = ($tw - $linew);
  16938. if ($plalign == 'C') {
  16939. if ($this->rtl) {
  16940. $t_x = -($mdiff / 2);
  16941. } else {
  16942. $t_x = ($mdiff / 2);
  16943. }
  16944. } elseif ($plalign == 'R') {
  16945. // right alignment on LTR document
  16946. $t_x = $mdiff;
  16947. } elseif ($plalign == 'L') {
  16948. // left alignment on RTL document
  16949. $t_x = -$mdiff;
  16950. } elseif (($plalign == 'J') AND ($plalign == $lalign)) {
  16951. // Justification
  16952. if ($this->isRTLTextDir()) {
  16953. // align text on the left
  16954. $t_x = -$mdiff;
  16955. }
  16956. $ns = 0; // number of spaces
  16957. $pmidtemp = $pmid;
  16958. // escape special characters
  16959. $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
  16960. $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
  16961. // search spaces
  16962. if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmidtemp, $lnstring, PREG_PATTERN_ORDER)) {
  16963. $spacestr = $this->getSpaceString();
  16964. $maxkk = count($lnstring[1]) - 1;
  16965. for ($kk=0; $kk <= $maxkk; ++$kk) {
  16966. // restore special characters
  16967. $lnstring[1][$kk] = str_replace('#!#OP#!#', '(', $lnstring[1][$kk]);
  16968. $lnstring[1][$kk] = str_replace('#!#CP#!#', ')', $lnstring[1][$kk]);
  16969. // store number of spaces on the strings
  16970. $lnstring[2][$kk] = substr_count($lnstring[1][$kk], $spacestr);
  16971. // count total spaces on line
  16972. $ns += $lnstring[2][$kk];
  16973. $lnstring[3][$kk] = $ns;
  16974. }
  16975. if ($ns == 0) {
  16976. $ns = 1;
  16977. }
  16978. // calculate additional space to add to each existing space
  16979. $spacewidth = ($mdiff / ($ns - $no)) * $this->k;
  16980. if ($this->FontSize <= 0) {
  16981. $this->FontSize = 1;
  16982. }
  16983. $spacewidthu = -1000 * ($mdiff + (($ns + $no) * $one_space_width)) / $ns / $this->FontSize;
  16984. if ($this->font_spacing != 0) {
  16985. // fixed spacing mode
  16986. $osw = -1000 * $this->font_spacing / $this->FontSize;
  16987. $spacewidthu += $osw;
  16988. }
  16989. $nsmax = $ns;
  16990. $ns = 0;
  16991. reset($lnstring);
  16992. $offset = 0;
  16993. $strcount = 0;
  16994. $prev_epsposbeg = 0;
  16995. $textpos = 0;
  16996. if ($this->isRTLTextDir()) {
  16997. $textpos = $this->wPt;
  16998. }
  16999. while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x', $pmid, $strpiece, PREG_OFFSET_CAPTURE, $offset) == 1) {
  17000. // check if we are inside a string section '[( ... )]'
  17001. $stroffset = strpos($pmid, '[(', $offset);
  17002. if (($stroffset !== false) AND ($stroffset <= $strpiece[2][1])) {
  17003. // set offset to the end of string section
  17004. $offset = strpos($pmid, ')]', $stroffset);
  17005. while (($offset !== false) AND ($pmid[($offset - 1)] == '\\')) {
  17006. $offset = strpos($pmid, ')]', ($offset + 1));
  17007. }
  17008. if ($offset === false) {
  17009. $this->Error('HTML Justification: malformed PDF code.');
  17010. }
  17011. continue;
  17012. }
  17013. if ($this->isRTLTextDir()) {
  17014. $spacew = ($spacewidth * ($nsmax - $ns));
  17015. } else {
  17016. $spacew = ($spacewidth * $ns);
  17017. }
  17018. $offset = $strpiece[2][1] + strlen($strpiece[2][0]);
  17019. $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, $offset);
  17020. $epsposend = strpos($pmid, $this->epsmarker.'Q', $offset) + strlen($this->epsmarker.'Q');
  17021. if ((($epsposbeg > 0) AND ($epsposend > 0) AND ($offset > $epsposbeg) AND ($offset < $epsposend))
  17022. OR (($epsposbeg === false) AND ($epsposend > 0) AND ($offset < $epsposend))) {
  17023. // shift EPS images
  17024. $trx = sprintf('1 0 0 1 %F 0 cm', $spacew);
  17025. $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, ($prev_epsposbeg - 6));
  17026. $pmid_b = substr($pmid, 0, $epsposbeg);
  17027. $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg));
  17028. $pmid_e = substr($pmid, $epsposend);
  17029. $pmid = $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e;
  17030. $offset = $epsposend;
  17031. continue;
  17032. }
  17033. $prev_epsposbeg = $epsposbeg;
  17034. $currentxpos = 0;
  17035. // shift blocks of code
  17036. switch ($strpiece[2][0]) {
  17037. case 'Td':
  17038. case 'cm':
  17039. case 'm':
  17040. case 'l': {
  17041. // get current X position
  17042. preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches);
  17043. if (!isset($xmatches[1])) {
  17044. break;
  17045. }
  17046. $currentxpos = $xmatches[1];
  17047. $textpos = $currentxpos;
  17048. if (($strcount <= $maxkk) AND ($strpiece[2][0] == 'Td')) {
  17049. $ns = $lnstring[3][$strcount];
  17050. if ($this->isRTLTextDir()) {
  17051. $spacew = ($spacewidth * ($nsmax - $ns));
  17052. }
  17053. ++$strcount;
  17054. }
  17055. // justify block
  17056. if (preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $pmatch) == 1) {
  17057. $newpmid = sprintf('%F',(floatval($pmatch[1]) + $spacew)).' '.$pmatch[2].' x*#!#*x'.$pmatch[3].$pmatch[4];
  17058. $pmid = str_replace($pmatch[0], $newpmid, $pmid);
  17059. unset($pmatch, $newpmid);
  17060. }
  17061. break;
  17062. }
  17063. case 're': {
  17064. // justify block
  17065. if (!TCPDF_STATIC::empty_string($this->lispacer)) {
  17066. $this->lispacer = '';
  17067. continue;
  17068. }
  17069. preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $xmatches);
  17070. if (!isset($xmatches[1])) {
  17071. break;
  17072. }
  17073. $currentxpos = $xmatches[1];
  17074. $x_diff = 0;
  17075. $w_diff = 0;
  17076. if ($this->isRTLTextDir()) { // RTL
  17077. if ($currentxpos < $textpos) {
  17078. $x_diff = ($spacewidth * ($nsmax - $lnstring[3][$strcount]));
  17079. $w_diff = ($spacewidth * $lnstring[2][$strcount]);
  17080. } else {
  17081. if ($strcount > 0) {
  17082. $x_diff = ($spacewidth * ($nsmax - $lnstring[3][($strcount - 1)]));
  17083. $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
  17084. }
  17085. }
  17086. } else { // LTR
  17087. if ($currentxpos > $textpos) {
  17088. if ($strcount > 0) {
  17089. $x_diff = ($spacewidth * $lnstring[3][($strcount - 1)]);
  17090. }
  17091. $w_diff = ($spacewidth * $lnstring[2][$strcount]);
  17092. } else {
  17093. if ($strcount > 1) {
  17094. $x_diff = ($spacewidth * $lnstring[3][($strcount - 2)]);
  17095. }
  17096. if ($strcount > 0) {
  17097. $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
  17098. }
  17099. }
  17100. }
  17101. if (preg_match('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $pmatch) == 1) {
  17102. $newx = sprintf('%F',(floatval($pmatch[1]) + $x_diff));
  17103. $neww = sprintf('%F',(floatval($pmatch[3]) + $w_diff));
  17104. $newpmid = $newx.' '.$pmatch[2].' '.$neww.' '.$pmatch[4].' x*#!#*x'.$pmatch[5].$pmatch[6];
  17105. $pmid = str_replace($pmatch[0], $newpmid, $pmid);
  17106. unset($pmatch, $newpmid, $newx, $neww);
  17107. }
  17108. break;
  17109. }
  17110. case 'c': {
  17111. // get current X position
  17112. 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);
  17113. if (!isset($xmatches[1])) {
  17114. break;
  17115. }
  17116. $currentxpos = $xmatches[1];
  17117. // justify block
  17118. 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) {
  17119. $newx1 = sprintf('%F',(floatval($pmatch[1]) + $spacew));
  17120. $newx2 = sprintf('%F',(floatval($pmatch[3]) + $spacew));
  17121. $newx3 = sprintf('%F',(floatval($pmatch[5]) + $spacew));
  17122. $newpmid = $newx1.' '.$pmatch[2].' '.$newx2.' '.$pmatch[4].' '.$newx3.' '.$pmatch[6].' x*#!#*x'.$pmatch[7].$pmatch[8];
  17123. $pmid = str_replace($pmatch[0], $newpmid, $pmid);
  17124. unset($pmatch, $newpmid, $newx1, $newx2, $newx3);
  17125. }
  17126. break;
  17127. }
  17128. }
  17129. // shift the annotations and links
  17130. $cxpos = ($currentxpos / $this->k);
  17131. $lmpos = ($this->lMargin + $this->cell_padding['L'] + $this->feps);
  17132. if ($this->inxobj) {
  17133. // we are inside an XObject template
  17134. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  17135. if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
  17136. if ($cxpos > $lmpos) {
  17137. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += ($spacew / $this->k);
  17138. $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17139. } else {
  17140. $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17141. }
  17142. break;
  17143. }
  17144. }
  17145. } elseif (isset($this->PageAnnots[$this->page])) {
  17146. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  17147. if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
  17148. if ($cxpos > $lmpos) {
  17149. $this->PageAnnots[$this->page][$pak]['x'] += ($spacew / $this->k);
  17150. $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17151. } else {
  17152. $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17153. }
  17154. break;
  17155. }
  17156. }
  17157. }
  17158. } // end of while
  17159. // remove markers
  17160. $pmid = str_replace('x*#!#*x', '', $pmid);
  17161. if ($this->isUnicodeFont()) {
  17162. // multibyte characters
  17163. $spacew = $spacewidthu;
  17164. if ($this->font_stretching != 100) {
  17165. // word spacing is affected by stretching
  17166. $spacew /= ($this->font_stretching / 100);
  17167. }
  17168. // escape special characters
  17169. $pmid = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmid);
  17170. $pmid = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmid);
  17171. if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmid, $pamatch) > 0) {
  17172. foreach($pamatch[0] as $pk => $pmatch) {
  17173. $pmatch = str_replace('#!#OP#!#', '(', $pmatch);
  17174. $pmatch = str_replace('#!#CP#!#', ')', $pmatch);
  17175. $newpmid = '[('.str_replace(chr(0).chr(32), ') '.sprintf('%F', $spacew).' (', $pamatch[1][$pk]).')]';
  17176. $pmid = str_replace($pmatch, $newpmid, $pmid);
  17177. }
  17178. unset($pamatch);
  17179. }
  17180. if ($this->inxobj) {
  17181. // we are inside an XObject template
  17182. $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\n".$pend;
  17183. } else {
  17184. $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\n".$pend);
  17185. }
  17186. $endlinepos = strlen($pstart."\n".$pmid."\n");
  17187. } else {
  17188. // non-unicode (single-byte characters)
  17189. if ($this->font_stretching != 100) {
  17190. // word spacing (Tw) is affected by stretching
  17191. $spacewidth /= ($this->font_stretching / 100);
  17192. }
  17193. $rs = sprintf('%F Tw', $spacewidth);
  17194. $pmid = preg_replace("/\[\(/x", $rs.' [(', $pmid);
  17195. if ($this->inxobj) {
  17196. // we are inside an XObject template
  17197. $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend;
  17198. } else {
  17199. $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend);
  17200. }
  17201. $endlinepos = strlen($pstart."\n".$pmid."\nBT 0 Tw ET\n");
  17202. }
  17203. }
  17204. } // end of J
  17205. } // end if $startlinex
  17206. if (($t_x != 0) OR ($yshift < 0)) {
  17207. // shift the line
  17208. $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k), ($yshift * $this->k));
  17209. $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
  17210. $endlinepos = strlen($pstart);
  17211. if ($this->inxobj) {
  17212. // we are inside an XObject template
  17213. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
  17214. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  17215. if ($pak >= $pask) {
  17216. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  17217. $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  17218. }
  17219. }
  17220. } else {
  17221. $this->setPageBuffer($startlinepage, $pstart.$pend);
  17222. // shift the annotations and links
  17223. if (isset($this->PageAnnots[$this->page])) {
  17224. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  17225. if ($pak >= $pask) {
  17226. $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  17227. $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  17228. }
  17229. }
  17230. }
  17231. }
  17232. $this->y -= $yshift;
  17233. }
  17234. }
  17235. $pbrk = $this->checkPageBreak($this->lasth);
  17236. $this->newline = false;
  17237. $startlinex = $this->x;
  17238. $startliney = $this->y;
  17239. if ($dom[$dom[$key]['parent']]['value'] == 'sup') {
  17240. $startliney -= ((0.3 * $this->FontSizePt) / $this->k);
  17241. } elseif ($dom[$dom[$key]['parent']]['value'] == 'sub') {
  17242. $startliney -= (($this->FontSizePt / 0.7) / $this->k);
  17243. } else {
  17244. $minstartliney = $startliney;
  17245. $maxbottomliney = ($this->y + $this->getCellHeight($fontsize / $this->k));
  17246. }
  17247. $startlinepage = $this->page;
  17248. if (isset($endlinepos) AND (!$pbrk)) {
  17249. $startlinepos = $endlinepos;
  17250. } else {
  17251. if ($this->inxobj) {
  17252. // we are inside an XObject template
  17253. $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
  17254. } elseif (!$this->InFooter) {
  17255. if (isset($this->footerlen[$this->page])) {
  17256. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  17257. } else {
  17258. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  17259. }
  17260. $startlinepos = $this->footerpos[$this->page];
  17261. } else {
  17262. $startlinepos = $this->pagelen[$this->page];
  17263. }
  17264. }
  17265. unset($endlinepos);
  17266. $plalign = $lalign;
  17267. if (isset($this->PageAnnots[$this->page])) {
  17268. $pask = count($this->PageAnnots[$this->page]);
  17269. } else {
  17270. $pask = 0;
  17271. }
  17272. if (!($dom[$key]['tag'] AND !$dom[$key]['opening'] AND ($dom[$key]['value'] == 'table')
  17273. AND (isset($this->emptypagemrk[$this->page]))
  17274. AND ($this->emptypagemrk[$this->page] == $this->pagelen[$this->page]))) {
  17275. $this->SetFont($fontname, $fontstyle, $fontsize);
  17276. if ($wfill) {
  17277. $this->SetFillColorArray($this->bgcolor);
  17278. }
  17279. }
  17280. } // end newline
  17281. if (isset($opentagpos)) {
  17282. unset($opentagpos);
  17283. }
  17284. if ($dom[$key]['tag']) {
  17285. if ($dom[$key]['opening']) {
  17286. // get text indentation (if any)
  17287. if (isset($dom[$key]['text-indent']) AND $dom[$key]['block']) {
  17288. $this->textindent = $dom[$key]['text-indent'];
  17289. $this->newline = true;
  17290. }
  17291. // table
  17292. if (($dom[$key]['value'] == 'table') AND isset($dom[$key]['cols']) AND ($dom[$key]['cols'] > 0)) {
  17293. // available page width
  17294. if ($this->rtl) {
  17295. $wtmp = $this->x - $this->lMargin;
  17296. } else {
  17297. $wtmp = $this->w - $this->rMargin - $this->x;
  17298. }
  17299. // get cell spacing
  17300. if (isset($dom[$key]['attribute']['cellspacing'])) {
  17301. $clsp = $this->getHTMLUnitToUnits($dom[$key]['attribute']['cellspacing'], 1, 'px');
  17302. $cellspacing = array('H' => $clsp, 'V' => $clsp);
  17303. } elseif (isset($dom[$key]['border-spacing'])) {
  17304. $cellspacing = $dom[$key]['border-spacing'];
  17305. } else {
  17306. $cellspacing = array('H' => 0, 'V' => 0);
  17307. }
  17308. // table width
  17309. if (isset($dom[$key]['width'])) {
  17310. $table_width = $this->getHTMLUnitToUnits($dom[$key]['width'], $wtmp, 'px');
  17311. } else {
  17312. $table_width = $wtmp;
  17313. }
  17314. $table_width -= (2 * $cellspacing['H']);
  17315. if (!$this->inthead) {
  17316. $this->y += $cellspacing['V'];
  17317. }
  17318. if ($this->rtl) {
  17319. $cellspacingx = -$cellspacing['H'];
  17320. } else {
  17321. $cellspacingx = $cellspacing['H'];
  17322. }
  17323. // total table width without cellspaces
  17324. $table_columns_width = ($table_width - ($cellspacing['H'] * ($dom[$key]['cols'] - 1)));
  17325. // minimum column width
  17326. $table_min_column_width = ($table_columns_width / $dom[$key]['cols']);
  17327. // array of custom column widths
  17328. $table_colwidths = array_fill(0, $dom[$key]['cols'], $table_min_column_width);
  17329. }
  17330. // table row
  17331. if ($dom[$key]['value'] == 'tr') {
  17332. // reset column counter
  17333. $colid = 0;
  17334. }
  17335. // table cell
  17336. if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  17337. $trid = $dom[$key]['parent'];
  17338. $table_el = $dom[$trid]['parent'];
  17339. if (!isset($dom[$table_el]['cols'])) {
  17340. $dom[$table_el]['cols'] = $dom[$trid]['cols'];
  17341. }
  17342. // store border info
  17343. $tdborder = 0;
  17344. if (isset($dom[$key]['border']) AND !empty($dom[$key]['border'])) {
  17345. $tdborder = $dom[$key]['border'];
  17346. }
  17347. $colspan = intval($dom[$key]['attribute']['colspan']);
  17348. if ($colspan <= 0) {
  17349. $colspan = 1;
  17350. }
  17351. $old_cell_padding = $this->cell_padding;
  17352. if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) {
  17353. $crclpd = $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'], 1, 'px');
  17354. $current_cell_padding = array('L' => $crclpd, 'T' => $crclpd, 'R' => $crclpd, 'B' => $crclpd);
  17355. } elseif (isset($dom[($dom[$trid]['parent'])]['padding'])) {
  17356. $current_cell_padding = $dom[($dom[$trid]['parent'])]['padding'];
  17357. } else {
  17358. $current_cell_padding = array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0);
  17359. }
  17360. $this->cell_padding = $current_cell_padding;
  17361. if (isset($dom[$key]['height'])) {
  17362. // minimum cell height
  17363. $cellh = $this->getHTMLUnitToUnits($dom[$key]['height'], 0, 'px');
  17364. } else {
  17365. $cellh = 0;
  17366. }
  17367. if (isset($dom[$key]['content'])) {
  17368. $cell_content = stripslashes($dom[$key]['content']);
  17369. } else {
  17370. $cell_content = '&nbsp;';
  17371. }
  17372. $tagtype = $dom[$key]['value'];
  17373. $parentid = $key;
  17374. while (($key < $maxel) AND (!(($dom[$key]['tag']) AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == $tagtype) AND ($dom[$key]['parent'] == $parentid)))) {
  17375. // move $key index forward
  17376. ++$key;
  17377. }
  17378. if (!isset($dom[$trid]['startpage'])) {
  17379. $dom[$trid]['startpage'] = $this->page;
  17380. } else {
  17381. $this->setPage($dom[$trid]['startpage']);
  17382. }
  17383. if (!isset($dom[$trid]['startcolumn'])) {
  17384. $dom[$trid]['startcolumn'] = $this->current_column;
  17385. } elseif ($this->current_column != $dom[$trid]['startcolumn']) {
  17386. $tmpx = $this->x;
  17387. $this->selectColumn($dom[$trid]['startcolumn']);
  17388. $this->x = $tmpx;
  17389. }
  17390. if (!isset($dom[$trid]['starty'])) {
  17391. $dom[$trid]['starty'] = $this->y;
  17392. } else {
  17393. $this->y = $dom[$trid]['starty'];
  17394. }
  17395. if (!isset($dom[$trid]['startx'])) {
  17396. $dom[$trid]['startx'] = $this->x;
  17397. $this->x += $cellspacingx;
  17398. } else {
  17399. $this->x += ($cellspacingx / 2);
  17400. }
  17401. if (isset($dom[$parentid]['attribute']['rowspan'])) {
  17402. $rowspan = intval($dom[$parentid]['attribute']['rowspan']);
  17403. } else {
  17404. $rowspan = 1;
  17405. }
  17406. // skip row-spanned cells started on the previous rows
  17407. if (isset($dom[$table_el]['rowspans'])) {
  17408. $rsk = 0;
  17409. $rskmax = count($dom[$table_el]['rowspans']);
  17410. while ($rsk < $rskmax) {
  17411. $trwsp = $dom[$table_el]['rowspans'][$rsk];
  17412. $rsstartx = $trwsp['startx'];
  17413. $rsendx = $trwsp['endx'];
  17414. // account for margin changes
  17415. if ($trwsp['startpage'] < $this->page) {
  17416. if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$trwsp['startpage']]['orm'])) {
  17417. $dl = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$trwsp['startpage']]['orm']);
  17418. $rsstartx -= $dl;
  17419. $rsendx -= $dl;
  17420. } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$trwsp['startpage']]['olm'])) {
  17421. $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$trwsp['startpage']]['olm']);
  17422. $rsstartx += $dl;
  17423. $rsendx += $dl;
  17424. }
  17425. }
  17426. if (($trwsp['rowspan'] > 0)
  17427. AND ($rsstartx > ($this->x - $cellspacing['H'] - $current_cell_padding['L'] - $this->feps))
  17428. AND ($rsstartx < ($this->x + $cellspacing['H'] + $current_cell_padding['R'] + $this->feps))
  17429. AND (($trwsp['starty'] < ($this->y - $this->feps)) OR ($trwsp['startpage'] < $this->page) OR ($trwsp['startcolumn'] < $this->current_column))) {
  17430. // set the starting X position of the current cell
  17431. $this->x = $rsendx + $cellspacingx;
  17432. // increment column indicator
  17433. $colid += $trwsp['colspan'];
  17434. if (($trwsp['rowspan'] == 1)
  17435. AND (isset($dom[$trid]['endy']))
  17436. AND (isset($dom[$trid]['endpage']))
  17437. AND (isset($dom[$trid]['endcolumn']))
  17438. AND ($trwsp['endpage'] == $dom[$trid]['endpage'])
  17439. AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
  17440. // set ending Y position for row
  17441. $dom[$table_el]['rowspans'][$rsk]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  17442. $dom[$trid]['endy'] = $dom[$table_el]['rowspans'][$rsk]['endy'];
  17443. }
  17444. $rsk = 0;
  17445. } else {
  17446. ++$rsk;
  17447. }
  17448. }
  17449. }
  17450. if (isset($dom[$parentid]['width'])) {
  17451. // user specified width
  17452. $cellw = $this->getHTMLUnitToUnits($dom[$parentid]['width'], $table_columns_width, 'px');
  17453. $tmpcw = ($cellw / $colspan);
  17454. for ($i = 0; $i < $colspan; ++$i) {
  17455. $table_colwidths[($colid + $i)] = $tmpcw;
  17456. }
  17457. } else {
  17458. // inherit column width
  17459. $cellw = 0;
  17460. for ($i = 0; $i < $colspan; ++$i) {
  17461. $cellw += $table_colwidths[($colid + $i)];
  17462. }
  17463. }
  17464. $cellw += (($colspan - 1) * $cellspacing['H']);
  17465. // increment column indicator
  17466. $colid += $colspan;
  17467. // add rowspan information to table element
  17468. if ($rowspan > 1) {
  17469. $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));
  17470. }
  17471. $cellid = array_push($dom[$trid]['cellpos'], array('startx' => $this->x));
  17472. if ($rowspan > 1) {
  17473. $dom[$trid]['cellpos'][($cellid - 1)]['rowspanid'] = ($trsid - 1);
  17474. }
  17475. // push background colors
  17476. if (isset($dom[$parentid]['bgcolor']) AND ($dom[$parentid]['bgcolor'] !== false)) {
  17477. $dom[$trid]['cellpos'][($cellid - 1)]['bgcolor'] = $dom[$parentid]['bgcolor'];
  17478. }
  17479. // store border info
  17480. if (isset($tdborder) AND !empty($tdborder)) {
  17481. $dom[$trid]['cellpos'][($cellid - 1)]['border'] = $tdborder;
  17482. }
  17483. $prevLastH = $this->lasth;
  17484. // store some info for multicolumn mode
  17485. if ($this->rtl) {
  17486. $this->colxshift['x'] = $this->w - $this->x - $this->rMargin;
  17487. } else {
  17488. $this->colxshift['x'] = $this->x - $this->lMargin;
  17489. }
  17490. $this->colxshift['s'] = $cellspacing;
  17491. $this->colxshift['p'] = $current_cell_padding;
  17492. // ****** write the cell content ******
  17493. $this->MultiCell($cellw, $cellh, $cell_content, false, $lalign, false, 2, '', '', true, 0, true, true, 0, 'T', false);
  17494. // restore some values
  17495. $this->colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  17496. $this->lasth = $prevLastH;
  17497. $this->cell_padding = $old_cell_padding;
  17498. $dom[$trid]['cellpos'][($cellid - 1)]['endx'] = $this->x;
  17499. // update the end of row position
  17500. if ($rowspan <= 1) {
  17501. if (isset($dom[$trid]['endy'])) {
  17502. if (($this->page == $dom[$trid]['endpage']) AND ($this->current_column == $dom[$trid]['endcolumn'])) {
  17503. $dom[$trid]['endy'] = max($this->y, $dom[$trid]['endy']);
  17504. } elseif (($this->page > $dom[$trid]['endpage']) OR ($this->current_column > $dom[$trid]['endcolumn'])) {
  17505. $dom[$trid]['endy'] = $this->y;
  17506. }
  17507. } else {
  17508. $dom[$trid]['endy'] = $this->y;
  17509. }
  17510. if (isset($dom[$trid]['endpage'])) {
  17511. $dom[$trid]['endpage'] = max($this->page, $dom[$trid]['endpage']);
  17512. } else {
  17513. $dom[$trid]['endpage'] = $this->page;
  17514. }
  17515. if (isset($dom[$trid]['endcolumn'])) {
  17516. $dom[$trid]['endcolumn'] = max($this->current_column, $dom[$trid]['endcolumn']);
  17517. } else {
  17518. $dom[$trid]['endcolumn'] = $this->current_column;
  17519. }
  17520. } else {
  17521. // account for row-spanned cells
  17522. $dom[$table_el]['rowspans'][($trsid - 1)]['endx'] = $this->x;
  17523. $dom[$table_el]['rowspans'][($trsid - 1)]['endy'] = $this->y;
  17524. $dom[$table_el]['rowspans'][($trsid - 1)]['endpage'] = $this->page;
  17525. $dom[$table_el]['rowspans'][($trsid - 1)]['endcolumn'] = $this->current_column;
  17526. }
  17527. if (isset($dom[$table_el]['rowspans'])) {
  17528. // update endy and endpage on rowspanned cells
  17529. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  17530. if ($trwsp['rowspan'] > 0) {
  17531. if (isset($dom[$trid]['endpage'])) {
  17532. if (($trwsp['endpage'] == $dom[$trid]['endpage']) AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
  17533. $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  17534. } elseif (($trwsp['endpage'] < $dom[$trid]['endpage']) OR ($trwsp['endcolumn'] < $dom[$trid]['endcolumn'])) {
  17535. $dom[$table_el]['rowspans'][$k]['endy'] = $dom[$trid]['endy'];
  17536. $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[$trid]['endpage'];
  17537. $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[$trid]['endcolumn'];
  17538. } else {
  17539. $dom[$trid]['endy'] = $this->pagedim[$dom[$trid]['endpage']]['hk'] - $this->pagedim[$dom[$trid]['endpage']]['bm'];
  17540. }
  17541. }
  17542. }
  17543. }
  17544. }
  17545. $this->x += ($cellspacingx / 2);
  17546. } else {
  17547. // opening tag (or self-closing tag)
  17548. if (!isset($opentagpos)) {
  17549. if ($this->inxobj) {
  17550. // we are inside an XObject template
  17551. $opentagpos = strlen($this->xobjects[$this->xobjid]['outdata']);
  17552. } elseif (!$this->InFooter) {
  17553. if (isset($this->footerlen[$this->page])) {
  17554. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  17555. } else {
  17556. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  17557. }
  17558. $opentagpos = $this->footerpos[$this->page];
  17559. }
  17560. }
  17561. $dom = $this->openHTMLTagHandler($dom, $key, $cell);
  17562. }
  17563. } else { // closing tag
  17564. $prev_numpages = $this->numpages;
  17565. $old_bordermrk = $this->bordermrk[$this->page];
  17566. $dom = $this->closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney);
  17567. if ($this->bordermrk[$this->page] > $old_bordermrk) {
  17568. $startlinepos += ($this->bordermrk[$this->page] - $old_bordermrk);
  17569. }
  17570. if ($prev_numpages > $this->numpages) {
  17571. $startlinepage = $this->page;
  17572. }
  17573. }
  17574. } elseif (strlen($dom[$key]['value']) > 0) {
  17575. // print list-item
  17576. if (!TCPDF_STATIC::empty_string($this->lispacer) AND ($this->lispacer != '^')) {
  17577. $this->SetFont($pfontname, $pfontstyle, $pfontsize);
  17578. $this->resetLastH();
  17579. $minstartliney = $this->y;
  17580. $maxbottomliney = ($startliney + $this->getCellHeight($this->FontSize));
  17581. if (is_numeric($pfontsize) AND ($pfontsize > 0)) {
  17582. $this->putHtmlListBullet($this->listnum, $this->lispacer, $pfontsize);
  17583. }
  17584. $this->SetFont($curfontname, $curfontstyle, $curfontsize);
  17585. $this->resetLastH();
  17586. if (is_numeric($pfontsize) AND ($pfontsize > 0) AND is_numeric($curfontsize) AND ($curfontsize > 0) AND ($pfontsize != $curfontsize)) {
  17587. $pfontascent = $this->getFontAscent($pfontname, $pfontstyle, $pfontsize);
  17588. $pfontdescent = $this->getFontDescent($pfontname, $pfontstyle, $pfontsize);
  17589. $this->y += ($this->getCellHeight(($pfontsize - $curfontsize) / $this->k) + $pfontascent - $curfontascent - $pfontdescent + $curfontdescent) / 2;
  17590. $minstartliney = min($this->y, $minstartliney);
  17591. $maxbottomliney = max(($this->y + $this->getCellHeight($pfontsize / $this->k)), $maxbottomliney);
  17592. }
  17593. }
  17594. // text
  17595. $this->htmlvspace = 0;
  17596. if ((!$this->premode) AND $this->isRTLTextDir()) {
  17597. // reverse spaces order
  17598. $lsp = ''; // left spaces
  17599. $rsp = ''; // right spaces
  17600. if (preg_match('/^('.$this->re_space['p'].'+)/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
  17601. $lsp = $matches[1];
  17602. }
  17603. if (preg_match('/('.$this->re_space['p'].'+)$/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
  17604. $rsp = $matches[1];
  17605. }
  17606. $dom[$key]['value'] = $rsp.$this->stringTrim($dom[$key]['value']).$lsp;
  17607. }
  17608. if ($newline) {
  17609. if (!$this->premode) {
  17610. $prelen = strlen($dom[$key]['value']);
  17611. if ($this->isRTLTextDir()) {
  17612. // right trim except non-breaking space
  17613. $dom[$key]['value'] = $this->stringRightTrim($dom[$key]['value']);
  17614. } else {
  17615. // left trim except non-breaking space
  17616. $dom[$key]['value'] = $this->stringLeftTrim($dom[$key]['value']);
  17617. }
  17618. $postlen = strlen($dom[$key]['value']);
  17619. if (($postlen == 0) AND ($prelen > 0)) {
  17620. $dom[$key]['trimmed_space'] = true;
  17621. }
  17622. }
  17623. $newline = false;
  17624. $firstblock = true;
  17625. } else {
  17626. $firstblock = false;
  17627. // replace empty multiple spaces string with a single space
  17628. $dom[$key]['value'] = preg_replace('/^'.$this->re_space['p'].'+$/'.$this->re_space['m'], chr(32), $dom[$key]['value']);
  17629. }
  17630. $strrest = '';
  17631. if ($this->rtl) {
  17632. $this->x -= $this->textindent;
  17633. } else {
  17634. $this->x += $this->textindent;
  17635. }
  17636. if (!isset($dom[$key]['trimmed_space']) OR !$dom[$key]['trimmed_space']) {
  17637. $strlinelen = $this->GetStringWidth($dom[$key]['value']);
  17638. if (!empty($this->HREF) AND (isset($this->HREF['url']))) {
  17639. // HTML <a> Link
  17640. $hrefcolor = '';
  17641. if (isset($dom[($dom[$key]['parent'])]['fgcolor']) AND ($dom[($dom[$key]['parent'])]['fgcolor'] !== false)) {
  17642. $hrefcolor = $dom[($dom[$key]['parent'])]['fgcolor'];
  17643. }
  17644. $hrefstyle = -1;
  17645. if (isset($dom[($dom[$key]['parent'])]['fontstyle']) AND ($dom[($dom[$key]['parent'])]['fontstyle'] !== false)) {
  17646. $hrefstyle = $dom[($dom[$key]['parent'])]['fontstyle'];
  17647. }
  17648. $strrest = $this->addHtmlLink($this->HREF['url'], $dom[$key]['value'], $wfill, true, $hrefcolor, $hrefstyle, true);
  17649. } else {
  17650. $wadj = 0; // space to leave for block continuity
  17651. if ($this->rtl) {
  17652. $cwa = ($this->x - $this->lMargin);
  17653. } else {
  17654. $cwa = ($this->w - $this->rMargin - $this->x);
  17655. }
  17656. if (($strlinelen < $cwa) AND (isset($dom[($key + 1)])) AND ($dom[($key + 1)]['tag']) AND (!$dom[($key + 1)]['block'])) {
  17657. // check the next text blocks for continuity
  17658. $nkey = ($key + 1);
  17659. $write_block = true;
  17660. $same_textdir = true;
  17661. $tmp_fontname = $this->FontFamily;
  17662. $tmp_fontstyle = $this->FontStyle;
  17663. $tmp_fontsize = $this->FontSizePt;
  17664. while ($write_block AND isset($dom[$nkey])) {
  17665. if ($dom[$nkey]['tag']) {
  17666. if ($dom[$nkey]['block']) {
  17667. // end of block
  17668. $write_block = false;
  17669. }
  17670. $tmp_fontname = isset($dom[$nkey]['fontname']) ? $dom[$nkey]['fontname'] : $this->FontFamily;
  17671. $tmp_fontstyle = isset($dom[$nkey]['fontstyle']) ? $dom[$nkey]['fontstyle'] : $this->FontStyle;
  17672. $tmp_fontsize = isset($dom[$nkey]['fontsize']) ? $dom[$nkey]['fontsize'] : $this->FontSizePt;
  17673. $same_textdir = ($dom[$nkey]['dir'] == $dom[$key]['dir']);
  17674. } else {
  17675. $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'+/', $this->re_space['m'], $dom[$nkey]['value']);
  17676. if (isset($nextstr[0]) AND $same_textdir) {
  17677. $wadj += $this->GetStringWidth($nextstr[0], $tmp_fontname, $tmp_fontstyle, $tmp_fontsize);
  17678. if (isset($nextstr[1])) {
  17679. $write_block = false;
  17680. }
  17681. }
  17682. }
  17683. ++$nkey;
  17684. }
  17685. }
  17686. if (($wadj > 0) AND (($strlinelen + $wadj) >= $cwa)) {
  17687. $wadj = 0;
  17688. $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'/', $this->re_space['m'], $dom[$key]['value']);
  17689. $numblks = count($nextstr);
  17690. if ($numblks > 1) {
  17691. // try to split on blank spaces
  17692. $wadj = ($cwa - $strlinelen + $this->GetStringWidth($nextstr[($numblks - 1)]));
  17693. } else {
  17694. // set the entire block on new line
  17695. $wadj = $this->GetStringWidth($nextstr[0]);
  17696. }
  17697. }
  17698. // check for reversed text direction
  17699. if (($wadj > 0) AND (($this->rtl AND ($this->tmprtl === 'L')) OR (!$this->rtl AND ($this->tmprtl === 'R')))) {
  17700. // LTR text on RTL direction or RTL text on LTR direction
  17701. $reverse_dir = true;
  17702. $this->rtl = !$this->rtl;
  17703. $revshift = ($strlinelen + $wadj + 0.000001); // add little quantity for rounding problems
  17704. if ($this->rtl) {
  17705. $this->x += $revshift;
  17706. } else {
  17707. $this->x -= $revshift;
  17708. }
  17709. $xws = $this->x;
  17710. }
  17711. // ****** write only until the end of the line and get the rest ******
  17712. $strrest = $this->Write($this->lasth, $dom[$key]['value'], '', $wfill, '', false, 0, true, $firstblock, 0, $wadj);
  17713. // restore default direction
  17714. if ($reverse_dir AND ($wadj == 0)) {
  17715. $this->x = $xws;
  17716. $this->rtl = !$this->rtl;
  17717. $reverse_dir = false;
  17718. }
  17719. }
  17720. }
  17721. $this->textindent = 0;
  17722. if (strlen($strrest) > 0) {
  17723. // store the remaining string on the previous $key position
  17724. $this->newline = true;
  17725. if ($strrest == $dom[$key]['value']) {
  17726. // used to avoid infinite loop
  17727. ++$loop;
  17728. } else {
  17729. $loop = 0;
  17730. }
  17731. $dom[$key]['value'] = $strrest;
  17732. if ($cell) {
  17733. if ($this->rtl) {
  17734. $this->x -= $this->cell_padding['R'];
  17735. } else {
  17736. $this->x += $this->cell_padding['L'];
  17737. }
  17738. }
  17739. if ($loop < 3) {
  17740. --$key;
  17741. }
  17742. } else {
  17743. $loop = 0;
  17744. // add the positive font spacing of the last character (if any)
  17745. if ($this->font_spacing > 0) {
  17746. if ($this->rtl) {
  17747. $this->x -= $this->font_spacing;
  17748. } else {
  17749. $this->x += $this->font_spacing;
  17750. }
  17751. }
  17752. }
  17753. }
  17754. ++$key;
  17755. 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')) {
  17756. // check if we are on a new page or on a new column
  17757. if ((!$undo) AND (($this->y < $this->start_transaction_y) OR (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['endy'] < $this->start_transaction_y)))) {
  17758. // we are on a new page or on a new column and the total object height is less than the available vertical space.
  17759. // restore previous object
  17760. $this->rollbackTransaction(true);
  17761. // restore previous values
  17762. foreach ($this_method_vars as $vkey => $vval) {
  17763. $$vkey = $vval;
  17764. }
  17765. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  17766. $pre_y = $this->y;
  17767. if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
  17768. $startliney = $this->y;
  17769. }
  17770. $undo = true; // avoid infinite loop
  17771. } else {
  17772. $undo = false;
  17773. }
  17774. }
  17775. } // end for each $key
  17776. // align the last line
  17777. if (isset($startlinex)) {
  17778. $yshift = ($minstartliney - $startliney);
  17779. if (($yshift > 0) OR ($this->page > $startlinepage)) {
  17780. $yshift = 0;
  17781. }
  17782. $t_x = 0;
  17783. // the last line must be shifted to be aligned as requested
  17784. $linew = abs($this->endlinex - $startlinex);
  17785. if ($this->inxobj) {
  17786. // we are inside an XObject template
  17787. $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
  17788. if (isset($opentagpos)) {
  17789. $midpos = $opentagpos;
  17790. } else {
  17791. $midpos = 0;
  17792. }
  17793. if ($midpos > 0) {
  17794. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
  17795. $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  17796. } else {
  17797. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  17798. $pend = '';
  17799. }
  17800. } else {
  17801. $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
  17802. if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  17803. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  17804. $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
  17805. } elseif (isset($opentagpos)) {
  17806. $midpos = $opentagpos;
  17807. } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  17808. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  17809. $midpos = $this->footerpos[$startlinepage];
  17810. } else {
  17811. $midpos = 0;
  17812. }
  17813. if ($midpos > 0) {
  17814. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
  17815. $pend = substr($this->getPageBuffer($startlinepage), $midpos);
  17816. } else {
  17817. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
  17818. $pend = '';
  17819. }
  17820. }
  17821. if ((isset($plalign) AND ((($plalign == 'C') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
  17822. // calculate shifting amount
  17823. $tw = $w;
  17824. if ($this->lMargin != $prevlMargin) {
  17825. $tw += ($prevlMargin - $this->lMargin);
  17826. }
  17827. if ($this->rMargin != $prevrMargin) {
  17828. $tw += ($prevrMargin - $this->rMargin);
  17829. }
  17830. $one_space_width = $this->GetStringWidth(chr(32));
  17831. $no = 0; // number of spaces on a line contained on a single block
  17832. if ($this->isRTLTextDir()) { // RTL
  17833. // remove left space if exist
  17834. $pos1 = TCPDF_STATIC::revstrpos($pmid, '[(');
  17835. if ($pos1 > 0) {
  17836. $pos1 = intval($pos1);
  17837. if ($this->isUnicodeFont()) {
  17838. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(0).chr(32)));
  17839. $spacelen = 2;
  17840. } else {
  17841. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(32)));
  17842. $spacelen = 1;
  17843. }
  17844. if ($pos1 == $pos2) {
  17845. $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
  17846. if (substr($pmid, $pos1, 4) == '[()]') {
  17847. $linew -= $one_space_width;
  17848. } elseif ($pos1 == strpos($pmid, '[(')) {
  17849. $no = 1;
  17850. }
  17851. }
  17852. }
  17853. } else { // LTR
  17854. // remove right space if exist
  17855. $pos1 = TCPDF_STATIC::revstrpos($pmid, ')]');
  17856. if ($pos1 > 0) {
  17857. $pos1 = intval($pos1);
  17858. if ($this->isUnicodeFont()) {
  17859. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(0).chr(32).')]')) + 2;
  17860. $spacelen = 2;
  17861. } else {
  17862. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(32).')]')) + 1;
  17863. $spacelen = 1;
  17864. }
  17865. if ($pos1 == $pos2) {
  17866. $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
  17867. $linew -= $one_space_width;
  17868. }
  17869. }
  17870. }
  17871. $mdiff = ($tw - $linew);
  17872. if ($plalign == 'C') {
  17873. if ($this->rtl) {
  17874. $t_x = -($mdiff / 2);
  17875. } else {
  17876. $t_x = ($mdiff / 2);
  17877. }
  17878. } elseif ($plalign == 'R') {
  17879. // right alignment on LTR document
  17880. $t_x = $mdiff;
  17881. } elseif ($plalign == 'L') {
  17882. // left alignment on RTL document
  17883. $t_x = -$mdiff;
  17884. }
  17885. } // end if startlinex
  17886. if (($t_x != 0) OR ($yshift < 0)) {
  17887. // shift the line
  17888. $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k), ($yshift * $this->k));
  17889. $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
  17890. $endlinepos = strlen($pstart);
  17891. if ($this->inxobj) {
  17892. // we are inside an XObject template
  17893. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
  17894. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  17895. if ($pak >= $pask) {
  17896. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  17897. $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  17898. }
  17899. }
  17900. } else {
  17901. $this->setPageBuffer($startlinepage, $pstart.$pend);
  17902. // shift the annotations and links
  17903. if (isset($this->PageAnnots[$this->page])) {
  17904. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  17905. if ($pak >= $pask) {
  17906. $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  17907. $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  17908. }
  17909. }
  17910. }
  17911. }
  17912. $this->y -= $yshift;
  17913. $yshift = 0;
  17914. }
  17915. }
  17916. // restore previous values
  17917. $this->setGraphicVars($gvars);
  17918. if ($this->num_columns > 1) {
  17919. $this->selectColumn();
  17920. } elseif ($this->page > $prevPage) {
  17921. $this->lMargin = $this->pagedim[$this->page]['olm'];
  17922. $this->rMargin = $this->pagedim[$this->page]['orm'];
  17923. }
  17924. // restore previous list state
  17925. $this->cell_height_ratio = $prev_cell_height_ratio;
  17926. $this->listnum = $prev_listnum;
  17927. $this->listordered = $prev_listordered;
  17928. $this->listcount = $prev_listcount;
  17929. $this->lispacer = $prev_lispacer;
  17930. if ($ln AND (!($cell AND ($dom[$key-1]['value'] == 'table')))) {
  17931. $this->Ln($this->lasth);
  17932. if ($this->y < $maxbottomliney) {
  17933. $this->y = $maxbottomliney;
  17934. }
  17935. }
  17936. unset($dom);
  17937. }
  17938. /**
  17939. * Process opening tags.
  17940. * @param $dom (array) html dom array
  17941. * @param $key (int) current element id
  17942. * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
  17943. * @return $dom array
  17944. * @protected
  17945. */
  17946. protected function openHTMLTagHandler($dom, $key, $cell) {
  17947. $tag = $dom[$key];
  17948. $parent = $dom[($dom[$key]['parent'])];
  17949. $firsttag = ($key == 1);
  17950. // check for text direction attribute
  17951. if (isset($tag['dir'])) {
  17952. $this->setTempRTL($tag['dir']);
  17953. } else {
  17954. $this->tmprtl = false;
  17955. }
  17956. if ($tag['block']) {
  17957. $hbz = 0; // distance from y to line bottom
  17958. $hb = 0; // vertical space between block tags
  17959. // calculate vertical space for block tags
  17960. if (isset($this->tagvspaces[$tag['value']][0]['h']) AND ($this->tagvspaces[$tag['value']][0]['h'] >= 0)) {
  17961. $cur_h = $this->tagvspaces[$tag['value']][0]['h'];
  17962. } elseif (isset($tag['fontsize'])) {
  17963. $cur_h = $this->getCellHeight($tag['fontsize'] / $this->k);
  17964. } else {
  17965. $cur_h = $this->getCellHeight($this->FontSize);
  17966. }
  17967. if (isset($this->tagvspaces[$tag['value']][0]['n'])) {
  17968. $n = $this->tagvspaces[$tag['value']][0]['n'];
  17969. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  17970. $n = 0.6;
  17971. } else {
  17972. $n = 1;
  17973. }
  17974. if ((!isset($this->tagvspaces[$tag['value']])) AND (in_array($tag['value'], array('div', 'dt', 'dd', 'li', 'br')))) {
  17975. $hb = 0;
  17976. } else {
  17977. $hb = ($n * $cur_h);
  17978. }
  17979. if (($this->htmlvspace <= 0) AND ($n > 0)) {
  17980. if (isset($parent['fontsize'])) {
  17981. $hbz = $this->getCellHeight($tag['fontsize'] / $this->k);
  17982. } else {
  17983. $hbz = $this->getCellHeight($this->FontSize);
  17984. }
  17985. }
  17986. if (isset($dom[($key - 1)]) AND ($dom[($key - 1)]['value'] == 'table')) {
  17987. // fix vertical space after table
  17988. $hbz = 0;
  17989. }
  17990. }
  17991. // Opening tag
  17992. switch($tag['value']) {
  17993. case 'table': {
  17994. $cp = 0;
  17995. $cs = 0;
  17996. $dom[$key]['rowspans'] = array();
  17997. if (!isset($dom[$key]['attribute']['nested']) OR ($dom[$key]['attribute']['nested'] != 'true')) {
  17998. $this->htmlvspace = 0;
  17999. // set table header
  18000. if (!TCPDF_STATIC::empty_string($dom[$key]['thead'])) {
  18001. // set table header
  18002. $this->thead = $dom[$key]['thead'];
  18003. if (!isset($this->theadMargins) OR (empty($this->theadMargins))) {
  18004. $this->theadMargins = array();
  18005. $this->theadMargins['cell_padding'] = $this->cell_padding;
  18006. $this->theadMargins['lmargin'] = $this->lMargin;
  18007. $this->theadMargins['rmargin'] = $this->rMargin;
  18008. $this->theadMargins['page'] = $this->page;
  18009. $this->theadMargins['cell'] = $cell;
  18010. }
  18011. }
  18012. }
  18013. // store current margins and page
  18014. $dom[$key]['old_cell_padding'] = $this->cell_padding;
  18015. if (isset($tag['attribute']['cellpadding'])) {
  18016. $pad = $this->getHTMLUnitToUnits($tag['attribute']['cellpadding'], 1, 'px');
  18017. $this->SetCellPadding($pad);
  18018. } elseif (isset($tag['padding'])) {
  18019. $this->cell_padding = $tag['padding'];
  18020. }
  18021. if (isset($tag['attribute']['cellspacing'])) {
  18022. $cs = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
  18023. } elseif (isset($tag['border-spacing'])) {
  18024. $cs = $tag['border-spacing']['V'];
  18025. }
  18026. $prev_y = $this->y;
  18027. if ($this->checkPageBreak(((2 * $cp) + (2 * $cs) + $this->lasth), '', false) OR ($this->y < $prev_y)) {
  18028. $this->inthead = true;
  18029. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18030. $this->checkPageBreak($this->PageBreakTrigger + 1);
  18031. }
  18032. break;
  18033. }
  18034. case 'tr': {
  18035. // array of columns positions
  18036. $dom[$key]['cellpos'] = array();
  18037. break;
  18038. }
  18039. case 'hr': {
  18040. if ((isset($tag['height'])) AND ($tag['height'] != '')) {
  18041. $hrHeight = $this->getHTMLUnitToUnits($tag['height'], 1, 'px');
  18042. } else {
  18043. $hrHeight = $this->GetLineWidth();
  18044. }
  18045. $this->addHTMLVertSpace($hbz, ($hrHeight / 2), $cell, $firsttag);
  18046. $x = $this->GetX();
  18047. $y = $this->GetY();
  18048. $wtmp = $this->w - $this->lMargin - $this->rMargin;
  18049. if ($cell) {
  18050. $wtmp -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  18051. }
  18052. if ((isset($tag['width'])) AND ($tag['width'] != '')) {
  18053. $hrWidth = $this->getHTMLUnitToUnits($tag['width'], $wtmp, 'px');
  18054. } else {
  18055. $hrWidth = $wtmp;
  18056. }
  18057. $prevlinewidth = $this->GetLineWidth();
  18058. $this->SetLineWidth($hrHeight);
  18059. $this->Line($x, $y, $x + $hrWidth, $y);
  18060. $this->SetLineWidth($prevlinewidth);
  18061. $this->addHTMLVertSpace(($hrHeight / 2), 0, $cell, !isset($dom[($key + 1)]));
  18062. break;
  18063. }
  18064. case 'a': {
  18065. if (array_key_exists('href', $tag['attribute'])) {
  18066. $this->HREF['url'] = $tag['attribute']['href'];
  18067. }
  18068. break;
  18069. }
  18070. case 'img': {
  18071. if (isset($tag['attribute']['src'])) {
  18072. if ($tag['attribute']['src']{0} === '@') {
  18073. // data stream
  18074. $tag['attribute']['src'] = '@'.base64_decode(substr($tag['attribute']['src'], 1));
  18075. $type = '';
  18076. } else {
  18077. // get image type
  18078. $type = TCPDF_IMAGES::getImageFileType($tag['attribute']['src']);
  18079. }
  18080. if (!isset($tag['width'])) {
  18081. $tag['width'] = 0;
  18082. }
  18083. if (!isset($tag['height'])) {
  18084. $tag['height'] = 0;
  18085. }
  18086. //if (!isset($tag['attribute']['align'])) {
  18087. // the only alignment supported is "bottom"
  18088. // further development is required for other modes.
  18089. $tag['attribute']['align'] = 'bottom';
  18090. //}
  18091. switch($tag['attribute']['align']) {
  18092. case 'top': {
  18093. $align = 'T';
  18094. break;
  18095. }
  18096. case 'middle': {
  18097. $align = 'M';
  18098. break;
  18099. }
  18100. case 'bottom': {
  18101. $align = 'B';
  18102. break;
  18103. }
  18104. default: {
  18105. $align = 'B';
  18106. break;
  18107. }
  18108. }
  18109. $prevy = $this->y;
  18110. $xpos = $this->x;
  18111. $imglink = '';
  18112. if (isset($this->HREF['url']) AND !TCPDF_STATIC::empty_string($this->HREF['url'])) {
  18113. $imglink = $this->HREF['url'];
  18114. if ($imglink{0} == '#') {
  18115. // convert url to internal link
  18116. $lnkdata = explode(',', $imglink);
  18117. if (isset($lnkdata[0])) {
  18118. $page = intval(substr($lnkdata[0], 1));
  18119. if (empty($page) OR ($page <= 0)) {
  18120. $page = $this->page;
  18121. }
  18122. if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
  18123. $lnky = floatval($lnkdata[1]);
  18124. } else {
  18125. $lnky = 0;
  18126. }
  18127. $imglink = $this->AddLink();
  18128. $this->SetLink($imglink, $lnky, $page);
  18129. }
  18130. }
  18131. }
  18132. $border = 0;
  18133. if (isset($tag['border']) AND !empty($tag['border'])) {
  18134. // currently only support 1 (frame) or a combination of 'LTRB'
  18135. $border = $tag['border'];
  18136. }
  18137. $iw = '';
  18138. if (isset($tag['width'])) {
  18139. $iw = $this->getHTMLUnitToUnits($tag['width'], 1, 'px', false);
  18140. }
  18141. $ih = '';
  18142. if (isset($tag['height'])) {
  18143. $ih = $this->getHTMLUnitToUnits($tag['height'], 1, 'px', false);
  18144. }
  18145. if (($type == 'eps') OR ($type == 'ai')) {
  18146. $this->ImageEps($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, $imglink, true, $align, '', $border, true);
  18147. } elseif ($type == 'svg') {
  18148. $this->ImageSVG($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, $imglink, $align, '', $border, true);
  18149. } else {
  18150. $this->Image($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, '', $imglink, $align, false, 300, '', false, false, $border, false, false, true);
  18151. }
  18152. switch($align) {
  18153. case 'T': {
  18154. $this->y = $prevy;
  18155. break;
  18156. }
  18157. case 'M': {
  18158. $this->y = (($this->img_rb_y + $prevy - ($tag['fontsize'] / $this->k)) / 2) ;
  18159. break;
  18160. }
  18161. case 'B': {
  18162. $this->y = $this->img_rb_y - ($tag['fontsize'] / $this->k);
  18163. break;
  18164. }
  18165. }
  18166. }
  18167. break;
  18168. }
  18169. case 'dl': {
  18170. ++$this->listnum;
  18171. if ($this->listnum == 1) {
  18172. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18173. } else {
  18174. $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
  18175. }
  18176. break;
  18177. }
  18178. case 'dt': {
  18179. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18180. break;
  18181. }
  18182. case 'dd': {
  18183. if ($this->rtl) {
  18184. $this->rMargin += $this->listindent;
  18185. } else {
  18186. $this->lMargin += $this->listindent;
  18187. }
  18188. ++$this->listindentlevel;
  18189. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18190. break;
  18191. }
  18192. case 'ul':
  18193. case 'ol': {
  18194. ++$this->listnum;
  18195. if ($tag['value'] == 'ol') {
  18196. $this->listordered[$this->listnum] = true;
  18197. } else {
  18198. $this->listordered[$this->listnum] = false;
  18199. }
  18200. if (isset($tag['attribute']['start'])) {
  18201. $this->listcount[$this->listnum] = intval($tag['attribute']['start']) - 1;
  18202. } else {
  18203. $this->listcount[$this->listnum] = 0;
  18204. }
  18205. if ($this->rtl) {
  18206. $this->rMargin += $this->listindent;
  18207. $this->x -= $this->listindent;
  18208. } else {
  18209. $this->lMargin += $this->listindent;
  18210. $this->x += $this->listindent;
  18211. }
  18212. ++$this->listindentlevel;
  18213. if ($this->listnum == 1) {
  18214. if ($key > 1) {
  18215. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18216. }
  18217. } else {
  18218. $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
  18219. }
  18220. break;
  18221. }
  18222. case 'li': {
  18223. if ($key > 2) {
  18224. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18225. }
  18226. if ($this->listordered[$this->listnum]) {
  18227. // ordered item
  18228. if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) {
  18229. $this->lispacer = $parent['attribute']['type'];
  18230. } elseif (isset($parent['listtype']) AND !TCPDF_STATIC::empty_string($parent['listtype'])) {
  18231. $this->lispacer = $parent['listtype'];
  18232. } elseif (isset($this->lisymbol) AND !TCPDF_STATIC::empty_string($this->lisymbol)) {
  18233. $this->lispacer = $this->lisymbol;
  18234. } else {
  18235. $this->lispacer = '#';
  18236. }
  18237. ++$this->listcount[$this->listnum];
  18238. if (isset($tag['attribute']['value'])) {
  18239. $this->listcount[$this->listnum] = intval($tag['attribute']['value']);
  18240. }
  18241. } else {
  18242. // unordered item
  18243. if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) {
  18244. $this->lispacer = $parent['attribute']['type'];
  18245. } elseif (isset($parent['listtype']) AND !TCPDF_STATIC::empty_string($parent['listtype'])) {
  18246. $this->lispacer = $parent['listtype'];
  18247. } elseif (isset($this->lisymbol) AND !TCPDF_STATIC::empty_string($this->lisymbol)) {
  18248. $this->lispacer = $this->lisymbol;
  18249. } else {
  18250. $this->lispacer = '!';
  18251. }
  18252. }
  18253. break;
  18254. }
  18255. case 'blockquote': {
  18256. if ($this->rtl) {
  18257. $this->rMargin += $this->listindent;
  18258. } else {
  18259. $this->lMargin += $this->listindent;
  18260. }
  18261. ++$this->listindentlevel;
  18262. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18263. break;
  18264. }
  18265. case 'br': {
  18266. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18267. break;
  18268. }
  18269. case 'div': {
  18270. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18271. break;
  18272. }
  18273. case 'p': {
  18274. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18275. break;
  18276. }
  18277. case 'pre': {
  18278. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18279. $this->premode = true;
  18280. break;
  18281. }
  18282. case 'sup': {
  18283. $this->SetXY($this->GetX(), $this->GetY() - ((0.7 * $this->FontSizePt) / $this->k));
  18284. break;
  18285. }
  18286. case 'sub': {
  18287. $this->SetXY($this->GetX(), $this->GetY() + ((0.3 * $this->FontSizePt) / $this->k));
  18288. break;
  18289. }
  18290. case 'h1':
  18291. case 'h2':
  18292. case 'h3':
  18293. case 'h4':
  18294. case 'h5':
  18295. case 'h6': {
  18296. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18297. break;
  18298. }
  18299. // Form fields (since 4.8.000 - 2009-09-07)
  18300. case 'form': {
  18301. if (isset($tag['attribute']['action'])) {
  18302. $this->form_action = $tag['attribute']['action'];
  18303. } else {
  18304. $this->Error('Please explicitly set action attribute path!');
  18305. }
  18306. if (isset($tag['attribute']['enctype'])) {
  18307. $this->form_enctype = $tag['attribute']['enctype'];
  18308. } else {
  18309. $this->form_enctype = 'application/x-www-form-urlencoded';
  18310. }
  18311. if (isset($tag['attribute']['method'])) {
  18312. $this->form_mode = $tag['attribute']['method'];
  18313. } else {
  18314. $this->form_mode = 'post';
  18315. }
  18316. break;
  18317. }
  18318. case 'input': {
  18319. if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18320. $name = $tag['attribute']['name'];
  18321. } else {
  18322. break;
  18323. }
  18324. $prop = array();
  18325. $opt = array();
  18326. if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC::empty_string($tag['attribute']['readonly'])) {
  18327. $prop['readonly'] = true;
  18328. }
  18329. if (isset($tag['attribute']['value']) AND !TCPDF_STATIC::empty_string($tag['attribute']['value'])) {
  18330. $value = $tag['attribute']['value'];
  18331. }
  18332. if (isset($tag['attribute']['maxlength']) AND !TCPDF_STATIC::empty_string($tag['attribute']['maxlength'])) {
  18333. $opt['maxlen'] = intval($tag['attribute']['maxlength']);
  18334. }
  18335. $h = $this->getCellHeight($this->FontSize);
  18336. if (isset($tag['attribute']['size']) AND !TCPDF_STATIC::empty_string($tag['attribute']['size'])) {
  18337. $w = intval($tag['attribute']['size']) * $this->GetStringWidth(chr(32)) * 2;
  18338. } else {
  18339. $w = $h;
  18340. }
  18341. if (isset($tag['attribute']['checked']) AND (($tag['attribute']['checked'] == 'checked') OR ($tag['attribute']['checked'] == 'true'))) {
  18342. $checked = true;
  18343. } else {
  18344. $checked = false;
  18345. }
  18346. if (isset($tag['align'])) {
  18347. switch ($tag['align']) {
  18348. case 'C': {
  18349. $opt['q'] = 1;
  18350. break;
  18351. }
  18352. case 'R': {
  18353. $opt['q'] = 2;
  18354. break;
  18355. }
  18356. case 'L':
  18357. default: {
  18358. break;
  18359. }
  18360. }
  18361. }
  18362. switch ($tag['attribute']['type']) {
  18363. case 'text': {
  18364. if (isset($value)) {
  18365. $opt['v'] = $value;
  18366. }
  18367. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18368. break;
  18369. }
  18370. case 'password': {
  18371. if (isset($value)) {
  18372. $opt['v'] = $value;
  18373. }
  18374. $prop['password'] = 'true';
  18375. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18376. break;
  18377. }
  18378. case 'checkbox': {
  18379. if (!isset($value)) {
  18380. break;
  18381. }
  18382. $this->CheckBox($name, $w, $checked, $prop, $opt, $value, '', '', false);
  18383. break;
  18384. }
  18385. case 'radio': {
  18386. if (!isset($value)) {
  18387. break;
  18388. }
  18389. $this->RadioButton($name, $w, $prop, $opt, $value, $checked, '', '', false);
  18390. break;
  18391. }
  18392. case 'submit': {
  18393. if (!isset($value)) {
  18394. $value = 'submit';
  18395. }
  18396. $w = $this->GetStringWidth($value) * 1.5;
  18397. $h *= 1.6;
  18398. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18399. $action = array();
  18400. $action['S'] = 'SubmitForm';
  18401. $action['F'] = $this->form_action;
  18402. if ($this->form_enctype != 'FDF') {
  18403. $action['Flags'] = array('ExportFormat');
  18404. }
  18405. if ($this->form_mode == 'get') {
  18406. $action['Flags'] = array('GetMethod');
  18407. }
  18408. $this->Button($name, $w, $h, $value, $action, $prop, $opt, '', '', false);
  18409. break;
  18410. }
  18411. case 'reset': {
  18412. if (!isset($value)) {
  18413. $value = 'reset';
  18414. }
  18415. $w = $this->GetStringWidth($value) * 1.5;
  18416. $h *= 1.6;
  18417. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18418. $this->Button($name, $w, $h, $value, array('S'=>'ResetForm'), $prop, $opt, '', '', false);
  18419. break;
  18420. }
  18421. case 'file': {
  18422. $prop['fileSelect'] = 'true';
  18423. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18424. if (!isset($value)) {
  18425. $value = '*';
  18426. }
  18427. $w = $this->GetStringWidth($value) * 2;
  18428. $h *= 1.2;
  18429. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18430. $jsaction = 'var f=this.getField(\''.$name.'\'); f.browseForFileToSubmit();';
  18431. $this->Button('FB_'.$name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  18432. break;
  18433. }
  18434. case 'hidden': {
  18435. if (isset($value)) {
  18436. $opt['v'] = $value;
  18437. }
  18438. $opt['f'] = array('invisible', 'hidden');
  18439. $this->TextField($name, 0, 0, $prop, $opt, '', '', false);
  18440. break;
  18441. }
  18442. case 'image': {
  18443. // THIS TYPE MUST BE FIXED
  18444. if (isset($tag['attribute']['src']) AND !TCPDF_STATIC::empty_string($tag['attribute']['src'])) {
  18445. $img = $tag['attribute']['src'];
  18446. } else {
  18447. break;
  18448. }
  18449. $value = 'img';
  18450. //$opt['mk'] = array('i'=>$img, 'tp'=>1, 'if'=>array('sw'=>'A', 's'=>'A', 'fb'=>false));
  18451. if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
  18452. $jsaction = $tag['attribute']['onclick'];
  18453. } else {
  18454. $jsaction = '';
  18455. }
  18456. $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  18457. break;
  18458. }
  18459. case 'button': {
  18460. if (!isset($value)) {
  18461. $value = ' ';
  18462. }
  18463. $w = $this->GetStringWidth($value) * 1.5;
  18464. $h *= 1.6;
  18465. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18466. if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
  18467. $jsaction = $tag['attribute']['onclick'];
  18468. } else {
  18469. $jsaction = '';
  18470. }
  18471. $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  18472. break;
  18473. }
  18474. }
  18475. break;
  18476. }
  18477. case 'textarea': {
  18478. $prop = array();
  18479. $opt = array();
  18480. if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC::empty_string($tag['attribute']['readonly'])) {
  18481. $prop['readonly'] = true;
  18482. }
  18483. if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18484. $name = $tag['attribute']['name'];
  18485. } else {
  18486. break;
  18487. }
  18488. if (isset($tag['attribute']['value']) AND !TCPDF_STATIC::empty_string($tag['attribute']['value'])) {
  18489. $opt['v'] = $tag['attribute']['value'];
  18490. }
  18491. if (isset($tag['attribute']['cols']) AND !TCPDF_STATIC::empty_string($tag['attribute']['cols'])) {
  18492. $w = intval($tag['attribute']['cols']) * $this->GetStringWidth(chr(32)) * 2;
  18493. } else {
  18494. $w = 40;
  18495. }
  18496. if (isset($tag['attribute']['rows']) AND !TCPDF_STATIC::empty_string($tag['attribute']['rows'])) {
  18497. $h = intval($tag['attribute']['rows']) * $this->getCellHeight($this->FontSize);
  18498. } else {
  18499. $h = 10;
  18500. }
  18501. $prop['multiline'] = 'true';
  18502. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18503. break;
  18504. }
  18505. case 'select': {
  18506. $h = $this->getCellHeight($this->FontSize);
  18507. if (isset($tag['attribute']['size']) AND !TCPDF_STATIC::empty_string($tag['attribute']['size'])) {
  18508. $h *= ($tag['attribute']['size'] + 1);
  18509. }
  18510. $prop = array();
  18511. $opt = array();
  18512. if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18513. $name = $tag['attribute']['name'];
  18514. } else {
  18515. break;
  18516. }
  18517. $w = 0;
  18518. if (isset($tag['attribute']['opt']) AND !TCPDF_STATIC::empty_string($tag['attribute']['opt'])) {
  18519. $options = explode('#!NwL!#', $tag['attribute']['opt']);
  18520. $values = array();
  18521. foreach ($options as $val) {
  18522. if (strpos($val, '#!TaB!#') !== false) {
  18523. $opts = explode('#!TaB!#', $val);
  18524. $values[] = $opts;
  18525. $w = max($w, $this->GetStringWidth($opts[1]));
  18526. } else {
  18527. $values[] = $val;
  18528. $w = max($w, $this->GetStringWidth($val));
  18529. }
  18530. }
  18531. } else {
  18532. break;
  18533. }
  18534. $w *= 2;
  18535. if (isset($tag['attribute']['multiple']) AND ($tag['attribute']['multiple']='multiple')) {
  18536. $prop['multipleSelection'] = 'true';
  18537. $this->ListBox($name, $w, $h, $values, $prop, $opt, '', '', false);
  18538. } else {
  18539. $this->ComboBox($name, $w, $h, $values, $prop, $opt, '', '', false);
  18540. }
  18541. break;
  18542. }
  18543. case 'tcpdf': {
  18544. if (defined('K_TCPDF_CALLS_IN_HTML') AND (K_TCPDF_CALLS_IN_HTML === true)) {
  18545. // Special tag used to call TCPDF methods
  18546. if (isset($tag['attribute']['method'])) {
  18547. $tcpdf_method = $tag['attribute']['method'];
  18548. if (method_exists($this, $tcpdf_method)) {
  18549. if (isset($tag['attribute']['params']) AND (!empty($tag['attribute']['params']))) {
  18550. $params = unserialize(urldecode($tag['attribute']['params']));
  18551. call_user_func_array(array($this, $tcpdf_method), $params);
  18552. } else {
  18553. $this->$tcpdf_method();
  18554. }
  18555. $this->newline = true;
  18556. }
  18557. }
  18558. }
  18559. break;
  18560. }
  18561. default: {
  18562. break;
  18563. }
  18564. }
  18565. // define tags that support borders and background colors
  18566. $bordertags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table');
  18567. if (in_array($tag['value'], $bordertags)) {
  18568. // set border
  18569. $dom[$key]['borderposition'] = $this->getBorderStartPosition();
  18570. }
  18571. if ($dom[$key]['self'] AND isset($dom[$key]['attribute']['pagebreakafter'])) {
  18572. $pba = $dom[$key]['attribute']['pagebreakafter'];
  18573. // check for pagebreak
  18574. if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
  18575. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18576. $this->checkPageBreak($this->PageBreakTrigger + 1);
  18577. }
  18578. if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  18579. OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  18580. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18581. $this->checkPageBreak($this->PageBreakTrigger + 1);
  18582. }
  18583. }
  18584. return $dom;
  18585. }
  18586. /**
  18587. * Process closing tags.
  18588. * @param $dom (array) html dom array
  18589. * @param $key (int) current element id
  18590. * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
  18591. * @param $maxbottomliney (int) maximum y value of current line
  18592. * @return $dom array
  18593. * @protected
  18594. */
  18595. protected function closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney=0) {
  18596. $tag = $dom[$key];
  18597. $parent = $dom[($dom[$key]['parent'])];
  18598. $lasttag = ((!isset($dom[($key + 1)])) OR ((!isset($dom[($key + 2)])) AND ($dom[($key + 1)]['value'] == 'marker')));
  18599. $in_table_head = false;
  18600. // maximum x position (used to draw borders)
  18601. if ($this->rtl) {
  18602. $xmax = $this->w;
  18603. } else {
  18604. $xmax = 0;
  18605. }
  18606. if ($tag['block']) {
  18607. $hbz = 0; // distance from y to line bottom
  18608. $hb = 0; // vertical space between block tags
  18609. // calculate vertical space for block tags
  18610. if (isset($this->tagvspaces[$tag['value']][1]['h']) AND ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) {
  18611. $pre_h = $this->tagvspaces[$tag['value']][1]['h'];
  18612. } elseif (isset($parent['fontsize'])) {
  18613. $pre_h = $this->getCellHeight($parent['fontsize'] / $this->k);
  18614. } else {
  18615. $pre_h = $this->getCellHeight($this->FontSize);
  18616. }
  18617. if (isset($this->tagvspaces[$tag['value']][1]['n'])) {
  18618. $n = $this->tagvspaces[$tag['value']][1]['n'];
  18619. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  18620. $n = 0.6;
  18621. } else {
  18622. $n = 1;
  18623. }
  18624. if ((!isset($this->tagvspaces[$tag['value']])) AND ($tag['value'] == 'div')) {
  18625. $hb = 0;
  18626. } else {
  18627. $hb = ($n * $pre_h);
  18628. }
  18629. if ($maxbottomliney > $this->PageBreakTrigger) {
  18630. $hbz = $this->getCellHeight($this->FontSize);
  18631. } elseif ($this->y < $maxbottomliney) {
  18632. $hbz = ($maxbottomliney - $this->y);
  18633. }
  18634. }
  18635. // Closing tag
  18636. switch($tag['value']) {
  18637. case 'tr': {
  18638. $table_el = $dom[($dom[$key]['parent'])]['parent'];
  18639. if (!isset($parent['endy'])) {
  18640. $dom[($dom[$key]['parent'])]['endy'] = $this->y;
  18641. $parent['endy'] = $this->y;
  18642. }
  18643. if (!isset($parent['endpage'])) {
  18644. $dom[($dom[$key]['parent'])]['endpage'] = $this->page;
  18645. $parent['endpage'] = $this->page;
  18646. }
  18647. if (!isset($parent['endcolumn'])) {
  18648. $dom[($dom[$key]['parent'])]['endcolumn'] = $this->current_column;
  18649. $parent['endcolumn'] = $this->current_column;
  18650. }
  18651. // update row-spanned cells
  18652. if (isset($dom[$table_el]['rowspans'])) {
  18653. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  18654. $dom[$table_el]['rowspans'][$k]['rowspan'] -= 1;
  18655. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  18656. if (($dom[$table_el]['rowspans'][$k]['endpage'] == $parent['endpage']) AND ($dom[$table_el]['rowspans'][$k]['endcolumn'] == $parent['endcolumn'])) {
  18657. $dom[($dom[$key]['parent'])]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $parent['endy']);
  18658. } elseif (($dom[$table_el]['rowspans'][$k]['endpage'] > $parent['endpage']) OR ($dom[$table_el]['rowspans'][$k]['endcolumn'] > $parent['endcolumn'])) {
  18659. $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  18660. $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  18661. $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  18662. }
  18663. }
  18664. }
  18665. // report new endy and endpage to the rowspanned cells
  18666. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  18667. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  18668. $dom[$table_el]['rowspans'][$k]['endpage'] = max($dom[$table_el]['rowspans'][$k]['endpage'], $dom[($dom[$key]['parent'])]['endpage']);
  18669. $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  18670. $dom[$table_el]['rowspans'][$k]['endcolumn'] = max($dom[$table_el]['rowspans'][$k]['endcolumn'], $dom[($dom[$key]['parent'])]['endcolumn']);
  18671. $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  18672. $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $dom[($dom[$key]['parent'])]['endy']);
  18673. $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  18674. }
  18675. }
  18676. // update remaining rowspanned cells
  18677. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  18678. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  18679. $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[($dom[$key]['parent'])]['endpage'];
  18680. $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[($dom[$key]['parent'])]['endcolumn'];
  18681. $dom[$table_el]['rowspans'][$k]['endy'] = $dom[($dom[$key]['parent'])]['endy'];
  18682. }
  18683. }
  18684. }
  18685. $this->setPage($dom[($dom[$key]['parent'])]['endpage']);
  18686. if ($this->num_columns > 1) {
  18687. $this->selectColumn($dom[($dom[$key]['parent'])]['endcolumn']);
  18688. }
  18689. $this->y = $dom[($dom[$key]['parent'])]['endy'];
  18690. if (isset($dom[$table_el]['attribute']['cellspacing'])) {
  18691. $this->y += $this->getHTMLUnitToUnits($dom[$table_el]['attribute']['cellspacing'], 1, 'px');
  18692. } elseif (isset($dom[$table_el]['border-spacing'])) {
  18693. $this->y += $dom[$table_el]['border-spacing']['V'];
  18694. }
  18695. $this->Ln(0, $cell);
  18696. if ($this->current_column == $parent['startcolumn']) {
  18697. $this->x = $parent['startx'];
  18698. }
  18699. // account for booklet mode
  18700. if ($this->page > $parent['startpage']) {
  18701. if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$parent['startpage']]['orm'])) {
  18702. $this->x -= ($this->pagedim[$this->page]['orm'] - $this->pagedim[$parent['startpage']]['orm']);
  18703. } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$parent['startpage']]['olm'])) {
  18704. $this->x += ($this->pagedim[$this->page]['olm'] - $this->pagedim[$parent['startpage']]['olm']);
  18705. }
  18706. }
  18707. break;
  18708. }
  18709. case 'tablehead':
  18710. // closing tag used for the thead part
  18711. $in_table_head = true;
  18712. $this->inthead = false;
  18713. case 'table': {
  18714. $table_el = $parent;
  18715. // set default border
  18716. if (isset($table_el['attribute']['border']) AND ($table_el['attribute']['border'] > 0)) {
  18717. // set default border
  18718. $border = array('LTRB' => array('width' => $this->getCSSBorderWidth($table_el['attribute']['border']), 'cap'=>'square', 'join'=>'miter', 'dash'=> 0, 'color'=>array(0,0,0)));
  18719. } else {
  18720. $border = 0;
  18721. }
  18722. $default_border = $border;
  18723. // fix bottom line alignment of last line before page break
  18724. foreach ($dom[($dom[$key]['parent'])]['trids'] as $j => $trkey) {
  18725. // update row-spanned cells
  18726. if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  18727. foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
  18728. if (isset($prevtrkey) AND ($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] > 0)) {
  18729. $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] = $trkey;
  18730. }
  18731. if ($dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] == $trkey) {
  18732. $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] -= 1;
  18733. }
  18734. }
  18735. }
  18736. if (isset($prevtrkey) AND ($dom[$trkey]['startpage'] > $dom[$prevtrkey]['endpage'])) {
  18737. $pgendy = $this->pagedim[$dom[$prevtrkey]['endpage']]['hk'] - $this->pagedim[$dom[$prevtrkey]['endpage']]['bm'];
  18738. $dom[$prevtrkey]['endy'] = $pgendy;
  18739. // update row-spanned cells
  18740. if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  18741. foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
  18742. if (($trwsp['trid'] == $trkey) AND ($trwsp['mrowspan'] > 1) AND ($trwsp['endpage'] == $dom[$prevtrkey]['endpage'])) {
  18743. $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'] = $pgendy;
  18744. $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] = -1;
  18745. }
  18746. }
  18747. }
  18748. }
  18749. $prevtrkey = $trkey;
  18750. $table_el = $dom[($dom[$key]['parent'])];
  18751. }
  18752. // for each row
  18753. if (count($table_el['trids']) > 0) {
  18754. unset($xmax);
  18755. }
  18756. foreach ($table_el['trids'] as $j => $trkey) {
  18757. $parent = $dom[$trkey];
  18758. if (!isset($xmax)) {
  18759. $xmax = $parent['cellpos'][(count($parent['cellpos']) - 1)]['endx'];
  18760. }
  18761. // for each cell on the row
  18762. foreach ($parent['cellpos'] as $k => $cellpos) {
  18763. if (isset($cellpos['rowspanid']) AND ($cellpos['rowspanid'] >= 0)) {
  18764. $cellpos['startx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['startx'];
  18765. $cellpos['endx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['endx'];
  18766. $endy = $table_el['rowspans'][($cellpos['rowspanid'])]['endy'];
  18767. $startpage = $table_el['rowspans'][($cellpos['rowspanid'])]['startpage'];
  18768. $endpage = $table_el['rowspans'][($cellpos['rowspanid'])]['endpage'];
  18769. $startcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['startcolumn'];
  18770. $endcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['endcolumn'];
  18771. } else {
  18772. $endy = $parent['endy'];
  18773. $startpage = $parent['startpage'];
  18774. $endpage = $parent['endpage'];
  18775. $startcolumn = $parent['startcolumn'];
  18776. $endcolumn = $parent['endcolumn'];
  18777. }
  18778. if ($this->num_columns == 0) {
  18779. $this->num_columns = 1;
  18780. }
  18781. if (isset($cellpos['border'])) {
  18782. $border = $cellpos['border'];
  18783. }
  18784. if (isset($cellpos['bgcolor']) AND ($cellpos['bgcolor']) !== false) {
  18785. $this->SetFillColorArray($cellpos['bgcolor']);
  18786. $fill = true;
  18787. } else {
  18788. $fill = false;
  18789. }
  18790. $x = $cellpos['startx'];
  18791. $y = $parent['starty'];
  18792. $starty = $y;
  18793. $w = abs($cellpos['endx'] - $cellpos['startx']);
  18794. // get border modes
  18795. $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
  18796. $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
  18797. $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  18798. // design borders around HTML cells.
  18799. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  18800. $ccode = '';
  18801. $this->setPage($page);
  18802. if ($this->num_columns < 2) {
  18803. // single-column mode
  18804. $this->x = $x;
  18805. $this->y = $this->tMargin;
  18806. }
  18807. // account for margin changes
  18808. if ($page > $startpage) {
  18809. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  18810. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  18811. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  18812. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  18813. }
  18814. }
  18815. if ($startpage == $endpage) { // single page
  18816. $deltacol = 0;
  18817. $deltath = 0;
  18818. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  18819. $this->selectColumn($column);
  18820. if ($startcolumn == $endcolumn) { // single column
  18821. $cborder = $border;
  18822. $h = $endy - $parent['starty'];
  18823. $this->y = $y;
  18824. $this->x = $x;
  18825. } elseif ($column == $startcolumn) { // first column
  18826. $cborder = $border_start;
  18827. $this->y = $starty;
  18828. $this->x = $x;
  18829. $h = $this->h - $this->y - $this->bMargin;
  18830. if ($this->rtl) {
  18831. $deltacol = $this->x + $this->rMargin - $this->w;
  18832. } else {
  18833. $deltacol = $this->x - $this->lMargin;
  18834. }
  18835. } elseif ($column == $endcolumn) { // end column
  18836. $cborder = $border_end;
  18837. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  18838. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  18839. }
  18840. $this->x += $deltacol;
  18841. $h = $endy - $this->y;
  18842. } else { // middle column
  18843. $cborder = $border_middle;
  18844. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  18845. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  18846. }
  18847. $this->x += $deltacol;
  18848. $h = $this->h - $this->y - $this->bMargin;
  18849. }
  18850. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  18851. } // end for each column
  18852. } elseif ($page == $startpage) { // first page
  18853. $deltacol = 0;
  18854. $deltath = 0;
  18855. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  18856. $this->selectColumn($column);
  18857. if ($column == $startcolumn) { // first column
  18858. $cborder = $border_start;
  18859. $this->y = $starty;
  18860. $this->x = $x;
  18861. $h = $this->h - $this->y - $this->bMargin;
  18862. if ($this->rtl) {
  18863. $deltacol = $this->x + $this->rMargin - $this->w;
  18864. } else {
  18865. $deltacol = $this->x - $this->lMargin;
  18866. }
  18867. } else { // middle column
  18868. $cborder = $border_middle;
  18869. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  18870. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  18871. }
  18872. $this->x += $deltacol;
  18873. $h = $this->h - $this->y - $this->bMargin;
  18874. }
  18875. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  18876. } // end for each column
  18877. } elseif ($page == $endpage) { // last page
  18878. $deltacol = 0;
  18879. $deltath = 0;
  18880. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  18881. $this->selectColumn($column);
  18882. if ($column == $endcolumn) { // end column
  18883. $cborder = $border_end;
  18884. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  18885. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  18886. }
  18887. $this->x += $deltacol;
  18888. $h = $endy - $this->y;
  18889. } else { // middle column
  18890. $cborder = $border_middle;
  18891. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  18892. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  18893. }
  18894. $this->x += $deltacol;
  18895. $h = $this->h - $this->y - $this->bMargin;
  18896. }
  18897. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  18898. } // end for each column
  18899. } else { // middle page
  18900. $deltacol = 0;
  18901. $deltath = 0;
  18902. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  18903. $this->selectColumn($column);
  18904. $cborder = $border_middle;
  18905. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  18906. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  18907. }
  18908. $this->x += $deltacol;
  18909. $h = $this->h - $this->y - $this->bMargin;
  18910. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  18911. } // end for each column
  18912. }
  18913. if ($cborder OR $fill) {
  18914. $offsetlen = strlen($ccode);
  18915. // draw border and fill
  18916. if ($this->inxobj) {
  18917. // we are inside an XObject template
  18918. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  18919. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  18920. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  18921. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  18922. } else {
  18923. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  18924. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  18925. }
  18926. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  18927. $pstart = substr($pagebuff, 0, $pagemark);
  18928. $pend = substr($pagebuff, $pagemark);
  18929. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  18930. } else {
  18931. // draw border and fill
  18932. if (end($this->transfmrk[$this->page]) !== false) {
  18933. $pagemarkkey = key($this->transfmrk[$this->page]);
  18934. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  18935. } elseif ($this->InFooter) {
  18936. $pagemark = $this->footerpos[$this->page];
  18937. } else {
  18938. $pagemark = $this->intmrk[$this->page];
  18939. }
  18940. $pagebuff = $this->getPageBuffer($this->page);
  18941. $pstart = substr($pagebuff, 0, $pagemark);
  18942. $pend = substr($pagebuff, $pagemark);
  18943. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  18944. }
  18945. }
  18946. } // end for each page
  18947. // restore default border
  18948. $border = $default_border;
  18949. } // end for each cell on the row
  18950. if (isset($table_el['attribute']['cellspacing'])) {
  18951. $this->y += $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing'], 1, 'px');
  18952. } elseif (isset($table_el['border-spacing'])) {
  18953. $this->y += $table_el['border-spacing']['V'];
  18954. }
  18955. $this->Ln(0, $cell);
  18956. $this->x = $parent['startx'];
  18957. if ($endpage > $startpage) {
  18958. if (($this->rtl) AND ($this->pagedim[$endpage]['orm'] != $this->pagedim[$startpage]['orm'])) {
  18959. $this->x += ($this->pagedim[$endpage]['orm'] - $this->pagedim[$startpage]['orm']);
  18960. } elseif ((!$this->rtl) AND ($this->pagedim[$endpage]['olm'] != $this->pagedim[$startpage]['olm'])) {
  18961. $this->x += ($this->pagedim[$endpage]['olm'] - $this->pagedim[$startpage]['olm']);
  18962. }
  18963. }
  18964. }
  18965. if (!$in_table_head) { // we are not inside a thead section
  18966. $this->cell_padding = $table_el['old_cell_padding'];
  18967. // reset row height
  18968. $this->resetLastH();
  18969. if (($this->page == ($this->numpages - 1)) AND ($this->pageopen[$this->numpages])) {
  18970. $plendiff = ($this->pagelen[$this->numpages] - $this->emptypagemrk[$this->numpages]);
  18971. if (($plendiff > 0) AND ($plendiff < 60)) {
  18972. $pagediff = substr($this->getPageBuffer($this->numpages), $this->emptypagemrk[$this->numpages], $plendiff);
  18973. if (substr($pagediff, 0, 5) == 'BT /F') {
  18974. // the difference is only a font setting
  18975. $plendiff = 0;
  18976. }
  18977. }
  18978. if ($plendiff == 0) {
  18979. // remove last blank page
  18980. $this->deletePage($this->numpages);
  18981. }
  18982. }
  18983. if (isset($this->theadMargins['top'])) {
  18984. // restore top margin
  18985. $this->tMargin = $this->theadMargins['top'];
  18986. }
  18987. if (!isset($table_el['attribute']['nested']) OR ($table_el['attribute']['nested'] != 'true')) {
  18988. // reset main table header
  18989. $this->thead = '';
  18990. $this->theadMargins = array();
  18991. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  18992. }
  18993. }
  18994. $parent = $table_el;
  18995. break;
  18996. }
  18997. case 'a': {
  18998. $this->HREF = '';
  18999. break;
  19000. }
  19001. case 'sup': {
  19002. $this->SetXY($this->GetX(), $this->GetY() + ((0.7 * $parent['fontsize']) / $this->k));
  19003. break;
  19004. }
  19005. case 'sub': {
  19006. $this->SetXY($this->GetX(), $this->GetY() - ((0.3 * $parent['fontsize']) / $this->k));
  19007. break;
  19008. }
  19009. case 'div': {
  19010. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19011. break;
  19012. }
  19013. case 'blockquote': {
  19014. if ($this->rtl) {
  19015. $this->rMargin -= $this->listindent;
  19016. } else {
  19017. $this->lMargin -= $this->listindent;
  19018. }
  19019. --$this->listindentlevel;
  19020. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19021. break;
  19022. }
  19023. case 'p': {
  19024. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19025. break;
  19026. }
  19027. case 'pre': {
  19028. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19029. $this->premode = false;
  19030. break;
  19031. }
  19032. case 'dl': {
  19033. --$this->listnum;
  19034. if ($this->listnum <= 0) {
  19035. $this->listnum = 0;
  19036. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19037. } else {
  19038. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19039. }
  19040. $this->resetLastH();
  19041. break;
  19042. }
  19043. case 'dt': {
  19044. $this->lispacer = '';
  19045. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19046. break;
  19047. }
  19048. case 'dd': {
  19049. $this->lispacer = '';
  19050. if ($this->rtl) {
  19051. $this->rMargin -= $this->listindent;
  19052. } else {
  19053. $this->lMargin -= $this->listindent;
  19054. }
  19055. --$this->listindentlevel;
  19056. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19057. break;
  19058. }
  19059. case 'ul':
  19060. case 'ol': {
  19061. --$this->listnum;
  19062. $this->lispacer = '';
  19063. if ($this->rtl) {
  19064. $this->rMargin -= $this->listindent;
  19065. } else {
  19066. $this->lMargin -= $this->listindent;
  19067. }
  19068. --$this->listindentlevel;
  19069. if ($this->listnum <= 0) {
  19070. $this->listnum = 0;
  19071. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19072. } else {
  19073. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19074. }
  19075. $this->resetLastH();
  19076. break;
  19077. }
  19078. case 'li': {
  19079. $this->lispacer = '';
  19080. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19081. break;
  19082. }
  19083. case 'h1':
  19084. case 'h2':
  19085. case 'h3':
  19086. case 'h4':
  19087. case 'h5':
  19088. case 'h6': {
  19089. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19090. break;
  19091. }
  19092. // Form fields (since 4.8.000 - 2009-09-07)
  19093. case 'form': {
  19094. $this->form_action = '';
  19095. $this->form_enctype = 'application/x-www-form-urlencoded';
  19096. break;
  19097. }
  19098. default : {
  19099. break;
  19100. }
  19101. }
  19102. // draw border and background (if any)
  19103. $this->drawHTMLTagBorder($parent, $xmax);
  19104. if (isset($dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'])) {
  19105. $pba = $dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'];
  19106. // check for pagebreak
  19107. if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
  19108. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  19109. $this->checkPageBreak($this->PageBreakTrigger + 1);
  19110. }
  19111. if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  19112. OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  19113. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  19114. $this->checkPageBreak($this->PageBreakTrigger + 1);
  19115. }
  19116. }
  19117. $this->tmprtl = false;
  19118. return $dom;
  19119. }
  19120. /**
  19121. * Add vertical spaces if needed.
  19122. * @param $hbz (string) Distance between current y and line bottom.
  19123. * @param $hb (string) The height of the break.
  19124. * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
  19125. * @param $firsttag (boolean) set to true when the tag is the first.
  19126. * @param $lasttag (boolean) set to true when the tag is the last.
  19127. * @protected
  19128. */
  19129. protected function addHTMLVertSpace($hbz=0, $hb=0, $cell=false, $firsttag=false, $lasttag=false) {
  19130. if ($firsttag) {
  19131. $this->Ln(0, $cell);
  19132. $this->htmlvspace = 0;
  19133. return;
  19134. }
  19135. if ($lasttag) {
  19136. $this->Ln($hbz, $cell);
  19137. $this->htmlvspace = 0;
  19138. return;
  19139. }
  19140. if ($hb < $this->htmlvspace) {
  19141. $hd = 0;
  19142. } else {
  19143. $hd = $hb - $this->htmlvspace;
  19144. $this->htmlvspace = $hb;
  19145. }
  19146. $this->Ln(($hbz + $hd), $cell);
  19147. }
  19148. /**
  19149. * Return the starting coordinates to draw an html border
  19150. * @return array containing top-left border coordinates
  19151. * @protected
  19152. * @since 5.7.000 (2010-08-03)
  19153. */
  19154. protected function getBorderStartPosition() {
  19155. if ($this->rtl) {
  19156. $xmax = $this->lMargin;
  19157. } else {
  19158. $xmax = $this->w - $this->rMargin;
  19159. }
  19160. return array('page' => $this->page, 'column' => $this->current_column, 'x' => $this->x, 'y' => $this->y, 'xmax' => $xmax);
  19161. }
  19162. /**
  19163. * Draw an HTML block border and fill
  19164. * @param $tag (array) array of tag properties.
  19165. * @param $xmax (int) end X coordinate for border.
  19166. * @protected
  19167. * @since 5.7.000 (2010-08-03)
  19168. */
  19169. protected function drawHTMLTagBorder($tag, $xmax) {
  19170. if (!isset($tag['borderposition'])) {
  19171. // nothing to draw
  19172. return;
  19173. }
  19174. $prev_x = $this->x;
  19175. $prev_y = $this->y;
  19176. $prev_lasth = $this->lasth;
  19177. $border = 0;
  19178. $fill = false;
  19179. $this->lasth = 0;
  19180. if (isset($tag['border']) AND !empty($tag['border'])) {
  19181. // get border style
  19182. $border = $tag['border'];
  19183. if (!TCPDF_STATIC::empty_string($this->thead) AND (!$this->inthead)) {
  19184. // border for table header
  19185. $border = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  19186. }
  19187. }
  19188. if (isset($tag['bgcolor']) AND ($tag['bgcolor'] !== false)) {
  19189. // get background color
  19190. $old_bgcolor = $this->bgcolor;
  19191. $this->SetFillColorArray($tag['bgcolor']);
  19192. $fill = true;
  19193. }
  19194. if (!$border AND !$fill) {
  19195. // nothing to draw
  19196. return;
  19197. }
  19198. if (isset($tag['attribute']['cellspacing'])) {
  19199. $clsp = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
  19200. $cellspacing = array('H' => $clsp, 'V' => $clsp);
  19201. } elseif (isset($tag['border-spacing'])) {
  19202. $cellspacing = $tag['border-spacing'];
  19203. } else {
  19204. $cellspacing = array('H' => 0, 'V' => 0);
  19205. }
  19206. if (($tag['value'] != 'table') AND (is_array($border)) AND (!empty($border))) {
  19207. // draw the border externally respect the sqare edge.
  19208. $border['mode'] = 'ext';
  19209. }
  19210. if ($this->rtl) {
  19211. if ($xmax >= $tag['borderposition']['x']) {
  19212. $xmax = $tag['borderposition']['xmax'];
  19213. }
  19214. $w = ($tag['borderposition']['x'] - $xmax);
  19215. } else {
  19216. if ($xmax <= $tag['borderposition']['x']) {
  19217. $xmax = $tag['borderposition']['xmax'];
  19218. }
  19219. $w = ($xmax - $tag['borderposition']['x']);
  19220. }
  19221. if ($w <= 0) {
  19222. return;
  19223. }
  19224. $w += $cellspacing['H'];
  19225. $startpage = $tag['borderposition']['page'];
  19226. $startcolumn = $tag['borderposition']['column'];
  19227. $x = $tag['borderposition']['x'];
  19228. $y = $tag['borderposition']['y'];
  19229. $endpage = $this->page;
  19230. $starty = $tag['borderposition']['y'] - $cellspacing['V'];
  19231. $currentY = $this->y;
  19232. $this->x = $x;
  19233. // get latest column
  19234. $endcolumn = $this->current_column;
  19235. if ($this->num_columns == 0) {
  19236. $this->num_columns = 1;
  19237. }
  19238. // get border modes
  19239. $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
  19240. $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
  19241. $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  19242. // temporary disable page regions
  19243. $temp_page_regions = $this->page_regions;
  19244. $this->page_regions = array();
  19245. // design borders around HTML cells.
  19246. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  19247. $ccode = '';
  19248. $this->setPage($page);
  19249. if ($this->num_columns < 2) {
  19250. // single-column mode
  19251. $this->x = $x;
  19252. $this->y = $this->tMargin;
  19253. }
  19254. // account for margin changes
  19255. if ($page > $startpage) {
  19256. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  19257. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  19258. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  19259. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  19260. }
  19261. }
  19262. if ($startpage == $endpage) {
  19263. // single page
  19264. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  19265. $this->selectColumn($column);
  19266. if ($startcolumn == $endcolumn) { // single column
  19267. $cborder = $border;
  19268. $h = ($currentY - $y) + $cellspacing['V'];
  19269. $this->y = $starty;
  19270. } elseif ($column == $startcolumn) { // first column
  19271. $cborder = $border_start;
  19272. $this->y = $starty;
  19273. $h = $this->h - $this->y - $this->bMargin;
  19274. } elseif ($column == $endcolumn) { // end column
  19275. $cborder = $border_end;
  19276. $h = $currentY - $this->y;
  19277. } else { // middle column
  19278. $cborder = $border_middle;
  19279. $h = $this->h - $this->y - $this->bMargin;
  19280. }
  19281. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19282. } // end for each column
  19283. } elseif ($page == $startpage) { // first page
  19284. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  19285. $this->selectColumn($column);
  19286. if ($column == $startcolumn) { // first column
  19287. $cborder = $border_start;
  19288. $this->y = $starty;
  19289. $h = $this->h - $this->y - $this->bMargin;
  19290. } else { // middle column
  19291. $cborder = $border_middle;
  19292. $h = $this->h - $this->y - $this->bMargin;
  19293. }
  19294. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19295. } // end for each column
  19296. } elseif ($page == $endpage) { // last page
  19297. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  19298. $this->selectColumn($column);
  19299. if ($column == $endcolumn) {
  19300. // end column
  19301. $cborder = $border_end;
  19302. $h = $currentY - $this->y;
  19303. } else {
  19304. // middle column
  19305. $cborder = $border_middle;
  19306. $h = $this->h - $this->y - $this->bMargin;
  19307. }
  19308. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19309. } // end for each column
  19310. } else { // middle page
  19311. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  19312. $this->selectColumn($column);
  19313. $cborder = $border_middle;
  19314. $h = $this->h - $this->y - $this->bMargin;
  19315. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19316. } // end for each column
  19317. }
  19318. if ($cborder OR $fill) {
  19319. $offsetlen = strlen($ccode);
  19320. // draw border and fill
  19321. if ($this->inxobj) {
  19322. // we are inside an XObject template
  19323. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  19324. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  19325. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  19326. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  19327. } else {
  19328. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  19329. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  19330. }
  19331. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  19332. $pstart = substr($pagebuff, 0, $pagemark);
  19333. $pend = substr($pagebuff, $pagemark);
  19334. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  19335. } else {
  19336. if (end($this->transfmrk[$this->page]) !== false) {
  19337. $pagemarkkey = key($this->transfmrk[$this->page]);
  19338. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  19339. } elseif ($this->InFooter) {
  19340. $pagemark = $this->footerpos[$this->page];
  19341. } else {
  19342. $pagemark = $this->intmrk[$this->page];
  19343. }
  19344. $pagebuff = $this->getPageBuffer($this->page);
  19345. $pstart = substr($pagebuff, 0, $pagemark);
  19346. $pend = substr($pagebuff, $pagemark);
  19347. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  19348. $this->bordermrk[$this->page] += $offsetlen;
  19349. $this->cntmrk[$this->page] += $offsetlen;
  19350. }
  19351. }
  19352. } // end for each page
  19353. // restore page regions
  19354. $this->page_regions = $temp_page_regions;
  19355. if (isset($old_bgcolor)) {
  19356. // restore background color
  19357. $this->SetFillColorArray($old_bgcolor);
  19358. }
  19359. // restore pointer position
  19360. $this->x = $prev_x;
  19361. $this->y = $prev_y;
  19362. $this->lasth = $prev_lasth;
  19363. }
  19364. /**
  19365. * Set the default bullet to be used as LI bullet symbol
  19366. * @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')
  19367. * @public
  19368. * @since 4.0.028 (2008-09-26)
  19369. */
  19370. public function setLIsymbol($symbol='!') {
  19371. // check for custom image symbol
  19372. if (substr($symbol, 0, 4) == 'img|') {
  19373. $this->lisymbol = $symbol;
  19374. return;
  19375. }
  19376. $symbol = strtolower($symbol);
  19377. $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');
  19378. if (in_array($symbol, $valid_symbols)) {
  19379. $this->lisymbol = $symbol;
  19380. } else {
  19381. $this->lisymbol = '';
  19382. }
  19383. }
  19384. /**
  19385. * Set the booklet mode for double-sided pages.
  19386. * @param $booklet (boolean) true set the booklet mode on, false otherwise.
  19387. * @param $inner (float) Inner page margin.
  19388. * @param $outer (float) Outer page margin.
  19389. * @public
  19390. * @since 4.2.000 (2008-10-29)
  19391. */
  19392. public function SetBooklet($booklet=true, $inner=-1, $outer=-1) {
  19393. $this->booklet = $booklet;
  19394. if ($inner >= 0) {
  19395. $this->lMargin = $inner;
  19396. }
  19397. if ($outer >= 0) {
  19398. $this->rMargin = $outer;
  19399. }
  19400. }
  19401. /**
  19402. * Swap the left and right margins.
  19403. * @param $reverse (boolean) if true swap left and right margins.
  19404. * @protected
  19405. * @since 4.2.000 (2008-10-29)
  19406. */
  19407. protected function swapMargins($reverse=true) {
  19408. if ($reverse) {
  19409. // swap left and right margins
  19410. $mtemp = $this->original_lMargin;
  19411. $this->original_lMargin = $this->original_rMargin;
  19412. $this->original_rMargin = $mtemp;
  19413. $deltam = $this->original_lMargin - $this->original_rMargin;
  19414. $this->lMargin += $deltam;
  19415. $this->rMargin -= $deltam;
  19416. }
  19417. }
  19418. /**
  19419. * Set the vertical spaces for HTML tags.
  19420. * The array must have the following structure (example):
  19421. * $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1)));
  19422. * The first array level contains the tag names,
  19423. * the second level contains 0 for opening tags or 1 for closing tags,
  19424. * the third level contains the vertical space unit (h) and the number spaces to add (n).
  19425. * If the h parameter is not specified, default values are used.
  19426. * @param $tagvs (array) array of tags and relative vertical spaces.
  19427. * @public
  19428. * @since 4.2.001 (2008-10-30)
  19429. */
  19430. public function setHtmlVSpace($tagvs) {
  19431. $this->tagvspaces = $tagvs;
  19432. }
  19433. /**
  19434. * Set custom width for list indentation.
  19435. * @param $width (float) width of the indentation. Use negative value to disable it.
  19436. * @public
  19437. * @since 4.2.007 (2008-11-12)
  19438. */
  19439. public function setListIndentWidth($width) {
  19440. return $this->customlistindent = floatval($width);
  19441. }
  19442. /**
  19443. * Set the top/bottom cell sides to be open or closed when the cell cross the page.
  19444. * @param $isopen (boolean) if true keeps the top/bottom border open for the cell sides that cross the page.
  19445. * @public
  19446. * @since 4.2.010 (2008-11-14)
  19447. */
  19448. public function setOpenCell($isopen) {
  19449. $this->opencell = $isopen;
  19450. }
  19451. /**
  19452. * Set the color and font style for HTML links.
  19453. * @param $color (array) RGB array of colors
  19454. * @param $fontstyle (string) additional font styles to add
  19455. * @public
  19456. * @since 4.4.003 (2008-12-09)
  19457. */
  19458. public function setHtmlLinksStyle($color=array(0,0,255), $fontstyle='U') {
  19459. $this->htmlLinkColorArray = $color;
  19460. $this->htmlLinkFontStyle = $fontstyle;
  19461. }
  19462. /**
  19463. * Convert HTML string containing value and unit of measure to user's units or points.
  19464. * @param $htmlval (string) String containing values and unit.
  19465. * @param $refsize (string) Reference value in points.
  19466. * @param $defaultunit (string) Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  19467. * @param $points (boolean) If true returns points, otherwise returns value in user's units.
  19468. * @return float value in user's unit or point if $points=true
  19469. * @public
  19470. * @since 4.4.004 (2008-12-10)
  19471. */
  19472. public function getHTMLUnitToUnits($htmlval, $refsize=1, $defaultunit='px', $points=false) {
  19473. $supportedunits = array('%', 'em', 'ex', 'px', 'in', 'cm', 'mm', 'pc', 'pt');
  19474. $retval = 0;
  19475. $value = 0;
  19476. $unit = 'px';
  19477. if ($points) {
  19478. $k = 1;
  19479. } else {
  19480. $k = $this->k;
  19481. }
  19482. if (in_array($defaultunit, $supportedunits)) {
  19483. $unit = $defaultunit;
  19484. }
  19485. if (is_numeric($htmlval)) {
  19486. $value = floatval($htmlval);
  19487. } elseif (preg_match('/([0-9\.\-\+]+)/', $htmlval, $mnum)) {
  19488. $value = floatval($mnum[1]);
  19489. if (preg_match('/([a-z%]+)/', $htmlval, $munit)) {
  19490. if (in_array($munit[1], $supportedunits)) {
  19491. $unit = $munit[1];
  19492. }
  19493. }
  19494. }
  19495. switch ($unit) {
  19496. // percentage
  19497. case '%': {
  19498. $retval = (($value * $refsize) / 100);
  19499. break;
  19500. }
  19501. // relative-size
  19502. case 'em': {
  19503. $retval = ($value * $refsize);
  19504. break;
  19505. }
  19506. // height of lower case 'x' (about half the font-size)
  19507. case 'ex': {
  19508. $retval = ($value * ($refsize / 2));
  19509. break;
  19510. }
  19511. // absolute-size
  19512. case 'in': {
  19513. $retval = (($value * $this->dpi) / $k);
  19514. break;
  19515. }
  19516. // centimeters
  19517. case 'cm': {
  19518. $retval = (($value / 2.54 * $this->dpi) / $k);
  19519. break;
  19520. }
  19521. // millimeters
  19522. case 'mm': {
  19523. $retval = (($value / 25.4 * $this->dpi) / $k);
  19524. break;
  19525. }
  19526. // one pica is 12 points
  19527. case 'pc': {
  19528. $retval = (($value * 12) / $k);
  19529. break;
  19530. }
  19531. // points
  19532. case 'pt': {
  19533. $retval = ($value / $k);
  19534. break;
  19535. }
  19536. // pixels
  19537. case 'px': {
  19538. $retval = $this->pixelsToUnits($value);
  19539. if ($points) {
  19540. $retval *= $this->k;
  19541. }
  19542. break;
  19543. }
  19544. }
  19545. return $retval;
  19546. }
  19547. /**
  19548. * Output an HTML list bullet or ordered item symbol
  19549. * @param $listdepth (int) list nesting level
  19550. * @param $listtype (string) type of list
  19551. * @param $size (float) current font size
  19552. * @protected
  19553. * @since 4.4.004 (2008-12-10)
  19554. */
  19555. protected function putHtmlListBullet($listdepth, $listtype='', $size=10) {
  19556. if ($this->state != 2) {
  19557. return;
  19558. }
  19559. $size /= $this->k;
  19560. $fill = '';
  19561. $bgcolor = $this->bgcolor;
  19562. $color = $this->fgcolor;
  19563. $strokecolor = $this->strokecolor;
  19564. $width = 0;
  19565. $textitem = '';
  19566. $tmpx = $this->x;
  19567. $lspace = $this->GetStringWidth(' ');
  19568. if ($listtype == '^') {
  19569. // special symbol used for avoid justification of rect bullet
  19570. $this->lispacer = '';
  19571. return;
  19572. } elseif ($listtype == '!') {
  19573. // set default list type for unordered list
  19574. $deftypes = array('disc', 'circle', 'square');
  19575. $listtype = $deftypes[($listdepth - 1) % 3];
  19576. } elseif ($listtype == '#') {
  19577. // set default list type for ordered list
  19578. $listtype = 'decimal';
  19579. } elseif (substr($listtype, 0, 4) == 'img|') {
  19580. // custom image type ('img|type|width|height|image.ext')
  19581. $img = explode('|', $listtype);
  19582. $listtype = 'img';
  19583. }
  19584. switch ($listtype) {
  19585. // unordered types
  19586. case 'none': {
  19587. break;
  19588. }
  19589. case 'disc': {
  19590. $r = $size / 6;
  19591. $lspace += (2 * $r);
  19592. if ($this->rtl) {
  19593. $this->x += $lspace;
  19594. } else {
  19595. $this->x -= $lspace;
  19596. }
  19597. $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), $r, 0, 360, 'F', array(), $color, 8);
  19598. break;
  19599. }
  19600. case 'circle': {
  19601. $r = $size / 6;
  19602. $lspace += (2 * $r);
  19603. if ($this->rtl) {
  19604. $this->x += $lspace;
  19605. } else {
  19606. $this->x -= $lspace;
  19607. }
  19608. $prev_line_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor;
  19609. $new_line_style = array('width' => ($r / 3), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'phase' => 0, 'color'=>$color);
  19610. $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), ($r * (1 - (1/6))), 0, 360, 'D', $new_line_style, array(), 8);
  19611. $this->_out($prev_line_style); // restore line settings
  19612. break;
  19613. }
  19614. case 'square': {
  19615. $l = $size / 3;
  19616. $lspace += $l;
  19617. if ($this->rtl) {;
  19618. $this->x += $lspace;
  19619. } else {
  19620. $this->x -= $lspace;
  19621. }
  19622. $this->Rect($this->x, ($this->y + (($this->lasth - $l) / 2)), $l, $l, 'F', array(), $color);
  19623. break;
  19624. }
  19625. case 'img': {
  19626. // 1=>type, 2=>width, 3=>height, 4=>image.ext
  19627. $lspace += $img[2];
  19628. if ($this->rtl) {;
  19629. $this->x += $lspace;
  19630. } else {
  19631. $this->x -= $lspace;
  19632. }
  19633. $imgtype = strtolower($img[1]);
  19634. $prev_y = $this->y;
  19635. switch ($imgtype) {
  19636. case 'svg': {
  19637. $this->ImageSVG($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', 'T', '', 0, false);
  19638. break;
  19639. }
  19640. case 'ai':
  19641. case 'eps': {
  19642. $this->ImageEps($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', true, 'T', '', 0, false);
  19643. break;
  19644. }
  19645. default: {
  19646. $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);
  19647. break;
  19648. }
  19649. }
  19650. $this->y = $prev_y;
  19651. break;
  19652. }
  19653. // ordered types
  19654. // $this->listcount[$this->listnum];
  19655. // $textitem
  19656. case '1':
  19657. case 'decimal': {
  19658. $textitem = $this->listcount[$this->listnum];
  19659. break;
  19660. }
  19661. case 'decimal-leading-zero': {
  19662. $textitem = sprintf('%02d', $this->listcount[$this->listnum]);
  19663. break;
  19664. }
  19665. case 'i':
  19666. case 'lower-roman': {
  19667. $textitem = strtolower(TCPDF_STATIC::intToRoman($this->listcount[$this->listnum]));
  19668. break;
  19669. }
  19670. case 'I':
  19671. case 'upper-roman': {
  19672. $textitem = TCPDF_STATIC::intToRoman($this->listcount[$this->listnum]);
  19673. break;
  19674. }
  19675. case 'a':
  19676. case 'lower-alpha':
  19677. case 'lower-latin': {
  19678. $textitem = chr(97 + $this->listcount[$this->listnum] - 1);
  19679. break;
  19680. }
  19681. case 'A':
  19682. case 'upper-alpha':
  19683. case 'upper-latin': {
  19684. $textitem = chr(65 + $this->listcount[$this->listnum] - 1);
  19685. break;
  19686. }
  19687. case 'lower-greek': {
  19688. $textitem = TCPDF_FONTS::unichr((945 + $this->listcount[$this->listnum] - 1), $this->isunicode);
  19689. break;
  19690. }
  19691. /*
  19692. // Types to be implemented (special handling)
  19693. case 'hebrew': {
  19694. break;
  19695. }
  19696. case 'armenian': {
  19697. break;
  19698. }
  19699. case 'georgian': {
  19700. break;
  19701. }
  19702. case 'cjk-ideographic': {
  19703. break;
  19704. }
  19705. case 'hiragana': {
  19706. break;
  19707. }
  19708. case 'katakana': {
  19709. break;
  19710. }
  19711. case 'hiragana-iroha': {
  19712. break;
  19713. }
  19714. case 'katakana-iroha': {
  19715. break;
  19716. }
  19717. */
  19718. default: {
  19719. $textitem = $this->listcount[$this->listnum];
  19720. }
  19721. }
  19722. if (!TCPDF_STATIC::empty_string($textitem)) {
  19723. // Check whether we need a new page or new column
  19724. $prev_y = $this->y;
  19725. $h = $this->getCellHeight($this->FontSize);
  19726. if ($this->checkPageBreak($h) OR ($this->y < $prev_y)) {
  19727. $tmpx = $this->x;
  19728. }
  19729. // print ordered item
  19730. if ($this->rtl) {
  19731. $textitem = '.'.$textitem;
  19732. } else {
  19733. $textitem = $textitem.'.';
  19734. }
  19735. $lspace += $this->GetStringWidth($textitem);
  19736. if ($this->rtl) {
  19737. $this->x += $lspace;
  19738. } else {
  19739. $this->x -= $lspace;
  19740. }
  19741. $this->Write($this->lasth, $textitem, '', false, '', false, 0, false);
  19742. }
  19743. $this->x = $tmpx;
  19744. $this->lispacer = '^';
  19745. // restore colors
  19746. $this->SetFillColorArray($bgcolor);
  19747. $this->SetDrawColorArray($strokecolor);
  19748. $this->SettextColorArray($color);
  19749. }
  19750. /**
  19751. * Returns current graphic variables as array.
  19752. * @return array of graphic variables
  19753. * @protected
  19754. * @since 4.2.010 (2008-11-14)
  19755. */
  19756. protected function getGraphicVars() {
  19757. $grapvars = array(
  19758. 'FontFamily' => $this->FontFamily,
  19759. 'FontStyle' => $this->FontStyle,
  19760. 'FontSizePt' => $this->FontSizePt,
  19761. 'rMargin' => $this->rMargin,
  19762. 'lMargin' => $this->lMargin,
  19763. 'cell_padding' => $this->cell_padding,
  19764. 'cell_margin' => $this->cell_margin,
  19765. 'LineWidth' => $this->LineWidth,
  19766. 'linestyleWidth' => $this->linestyleWidth,
  19767. 'linestyleCap' => $this->linestyleCap,
  19768. 'linestyleJoin' => $this->linestyleJoin,
  19769. 'linestyleDash' => $this->linestyleDash,
  19770. 'textrendermode' => $this->textrendermode,
  19771. 'textstrokewidth' => $this->textstrokewidth,
  19772. 'DrawColor' => $this->DrawColor,
  19773. 'FillColor' => $this->FillColor,
  19774. 'TextColor' => $this->TextColor,
  19775. 'ColorFlag' => $this->ColorFlag,
  19776. 'bgcolor' => $this->bgcolor,
  19777. 'fgcolor' => $this->fgcolor,
  19778. 'htmlvspace' => $this->htmlvspace,
  19779. 'listindent' => $this->listindent,
  19780. 'listindentlevel' => $this->listindentlevel,
  19781. 'listnum' => $this->listnum,
  19782. 'listordered' => $this->listordered,
  19783. 'listcount' => $this->listcount,
  19784. 'lispacer' => $this->lispacer,
  19785. 'cell_height_ratio' => $this->cell_height_ratio,
  19786. 'font_stretching' => $this->font_stretching,
  19787. 'font_spacing' => $this->font_spacing,
  19788. 'alpha' => $this->alpha,
  19789. // extended
  19790. 'lasth' => $this->lasth,
  19791. 'tMargin' => $this->tMargin,
  19792. 'bMargin' => $this->bMargin,
  19793. 'AutoPageBreak' => $this->AutoPageBreak,
  19794. 'PageBreakTrigger' => $this->PageBreakTrigger,
  19795. 'x' => $this->x,
  19796. 'y' => $this->y,
  19797. 'w' => $this->w,
  19798. 'h' => $this->h,
  19799. 'wPt' => $this->wPt,
  19800. 'hPt' => $this->hPt,
  19801. 'fwPt' => $this->fwPt,
  19802. 'fhPt' => $this->fhPt,
  19803. 'page' => $this->page,
  19804. 'current_column' => $this->current_column,
  19805. 'num_columns' => $this->num_columns
  19806. );
  19807. return $grapvars;
  19808. }
  19809. /**
  19810. * Set graphic variables.
  19811. * @param $gvars (array) array of graphic variablesto restore
  19812. * @param $extended (boolean) if true restore extended graphic variables
  19813. * @protected
  19814. * @since 4.2.010 (2008-11-14)
  19815. */
  19816. protected function setGraphicVars($gvars, $extended=false) {
  19817. if ($this->state != 2) {
  19818. return;
  19819. }
  19820. $this->FontFamily = $gvars['FontFamily'];
  19821. $this->FontStyle = $gvars['FontStyle'];
  19822. $this->FontSizePt = $gvars['FontSizePt'];
  19823. $this->rMargin = $gvars['rMargin'];
  19824. $this->lMargin = $gvars['lMargin'];
  19825. $this->cell_padding = $gvars['cell_padding'];
  19826. $this->cell_margin = $gvars['cell_margin'];
  19827. $this->LineWidth = $gvars['LineWidth'];
  19828. $this->linestyleWidth = $gvars['linestyleWidth'];
  19829. $this->linestyleCap = $gvars['linestyleCap'];
  19830. $this->linestyleJoin = $gvars['linestyleJoin'];
  19831. $this->linestyleDash = $gvars['linestyleDash'];
  19832. $this->textrendermode = $gvars['textrendermode'];
  19833. $this->textstrokewidth = $gvars['textstrokewidth'];
  19834. $this->DrawColor = $gvars['DrawColor'];
  19835. $this->FillColor = $gvars['FillColor'];
  19836. $this->TextColor = $gvars['TextColor'];
  19837. $this->ColorFlag = $gvars['ColorFlag'];
  19838. $this->bgcolor = $gvars['bgcolor'];
  19839. $this->fgcolor = $gvars['fgcolor'];
  19840. $this->htmlvspace = $gvars['htmlvspace'];
  19841. $this->listindent = $gvars['listindent'];
  19842. $this->listindentlevel = $gvars['listindentlevel'];
  19843. $this->listnum = $gvars['listnum'];
  19844. $this->listordered = $gvars['listordered'];
  19845. $this->listcount = $gvars['listcount'];
  19846. $this->lispacer = $gvars['lispacer'];
  19847. $this->cell_height_ratio = $gvars['cell_height_ratio'];
  19848. $this->font_stretching = $gvars['font_stretching'];
  19849. $this->font_spacing = $gvars['font_spacing'];
  19850. $this->alpha = $gvars['alpha'];
  19851. if ($extended) {
  19852. // restore extended values
  19853. $this->lasth = $gvars['lasth'];
  19854. $this->tMargin = $gvars['tMargin'];
  19855. $this->bMargin = $gvars['bMargin'];
  19856. $this->AutoPageBreak = $gvars['AutoPageBreak'];
  19857. $this->PageBreakTrigger = $gvars['PageBreakTrigger'];
  19858. $this->x = $gvars['x'];
  19859. $this->y = $gvars['y'];
  19860. $this->w = $gvars['w'];
  19861. $this->h = $gvars['h'];
  19862. $this->wPt = $gvars['wPt'];
  19863. $this->hPt = $gvars['hPt'];
  19864. $this->fwPt = $gvars['fwPt'];
  19865. $this->fhPt = $gvars['fhPt'];
  19866. $this->page = $gvars['page'];
  19867. $this->current_column = $gvars['current_column'];
  19868. $this->num_columns = $gvars['num_columns'];
  19869. }
  19870. $this->_out(''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor.'');
  19871. if (!TCPDF_STATIC::empty_string($this->FontFamily)) {
  19872. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  19873. }
  19874. }
  19875. /**
  19876. * Writes data to a temporary file on filesystem.
  19877. * @param $filename (string) file name
  19878. * @param $data (mixed) data to write on file
  19879. * @param $append (boolean) if true append data, false replace.
  19880. * @since 4.5.000 (2008-12-31)
  19881. * @protected
  19882. */
  19883. protected function writeDiskCache($filename, $data, $append=false) {
  19884. if ($append) {
  19885. $fmode = 'ab+';
  19886. } else {
  19887. $fmode = 'wb+';
  19888. }
  19889. $f = @fopen($filename, $fmode);
  19890. if (!$f) {
  19891. $this->Error('Unable to write cache file: '.$filename);
  19892. } else {
  19893. fwrite($f, $data);
  19894. fclose($f);
  19895. }
  19896. // update file length (needed for transactions)
  19897. if (!isset($this->cache_file_length['_'.$filename])) {
  19898. $this->cache_file_length['_'.$filename] = strlen($data);
  19899. } else {
  19900. $this->cache_file_length['_'.$filename] += strlen($data);
  19901. }
  19902. }
  19903. /**
  19904. * Read data from a temporary file on filesystem.
  19905. * @param $filename (string) file name
  19906. * @return mixed retrieved data
  19907. * @since 4.5.000 (2008-12-31)
  19908. * @protected
  19909. */
  19910. protected function readDiskCache($filename) {
  19911. return file_get_contents($filename);
  19912. }
  19913. /**
  19914. * Set buffer content (always append data).
  19915. * @param $data (string) data
  19916. * @protected
  19917. * @since 4.5.000 (2009-01-02)
  19918. */
  19919. protected function setBuffer($data) {
  19920. $this->bufferlen += strlen($data);
  19921. if ($this->diskcache) {
  19922. if (!isset($this->buffer) OR TCPDF_STATIC::empty_string($this->buffer)) {
  19923. $this->buffer = TCPDF_STATIC::getObjFilename('buf');
  19924. }
  19925. $this->writeDiskCache($this->buffer, $data, true);
  19926. } else {
  19927. $this->buffer .= $data;
  19928. }
  19929. }
  19930. /**
  19931. * Replace the buffer content
  19932. * @param $data (string) data
  19933. * @protected
  19934. * @since 5.5.000 (2010-06-22)
  19935. */
  19936. protected function replaceBuffer($data) {
  19937. $this->bufferlen = strlen($data);
  19938. if ($this->diskcache) {
  19939. if (!isset($this->buffer) OR TCPDF_STATIC::empty_string($this->buffer)) {
  19940. $this->buffer = TCPDF_STATIC::getObjFilename('buf');
  19941. }
  19942. $this->writeDiskCache($this->buffer, $data, false);
  19943. } else {
  19944. $this->buffer = $data;
  19945. }
  19946. }
  19947. /**
  19948. * Get buffer content.
  19949. * @return string buffer content
  19950. * @protected
  19951. * @since 4.5.000 (2009-01-02)
  19952. */
  19953. protected function getBuffer() {
  19954. if ($this->diskcache) {
  19955. return $this->readDiskCache($this->buffer);
  19956. } else {
  19957. return $this->buffer;
  19958. }
  19959. }
  19960. /**
  19961. * Set page buffer content.
  19962. * @param $page (int) page number
  19963. * @param $data (string) page data
  19964. * @param $append (boolean) if true append data, false replace.
  19965. * @protected
  19966. * @since 4.5.000 (2008-12-31)
  19967. */
  19968. protected function setPageBuffer($page, $data, $append=false) {
  19969. if ($this->diskcache) {
  19970. if (!isset($this->pages[$page])) {
  19971. $this->pages[$page] = TCPDF_STATIC::getObjFilename('page');
  19972. }
  19973. $this->writeDiskCache($this->pages[$page], $data, $append);
  19974. } else {
  19975. if ($append) {
  19976. $this->pages[$page] .= $data;
  19977. } else {
  19978. $this->pages[$page] = $data;
  19979. }
  19980. }
  19981. if ($append AND isset($this->pagelen[$page])) {
  19982. $this->pagelen[$page] += strlen($data);
  19983. } else {
  19984. $this->pagelen[$page] = strlen($data);
  19985. }
  19986. }
  19987. /**
  19988. * Get page buffer content.
  19989. * @param $page (int) page number
  19990. * @return string page buffer content or false in case of error
  19991. * @protected
  19992. * @since 4.5.000 (2008-12-31)
  19993. */
  19994. protected function getPageBuffer($page) {
  19995. if ($this->diskcache) {
  19996. return $this->readDiskCache($this->pages[$page]);
  19997. } elseif (isset($this->pages[$page])) {
  19998. return $this->pages[$page];
  19999. }
  20000. return false;
  20001. }
  20002. /**
  20003. * Set image buffer content.
  20004. * @param $image (string) image key
  20005. * @param $data (array) image data
  20006. * @return int image index number
  20007. * @protected
  20008. * @since 4.5.000 (2008-12-31)
  20009. */
  20010. protected function setImageBuffer($image, $data) {
  20011. if (($data['i'] = array_search($image, $this->imagekeys)) === FALSE) {
  20012. $this->imagekeys[$this->numimages] = $image;
  20013. $data['i'] = $this->numimages;
  20014. ++$this->numimages;
  20015. }
  20016. if ($this->diskcache) {
  20017. if (!isset($this->images[$image])) {
  20018. $this->images[$image] = TCPDF_STATIC::getObjFilename('img');
  20019. }
  20020. $this->writeDiskCache($this->images[$image], serialize($data));
  20021. } else {
  20022. $this->images[$image] = $data;
  20023. }
  20024. return $data['i'];
  20025. }
  20026. /**
  20027. * Set image buffer content for a specified sub-key.
  20028. * @param $image (string) image key
  20029. * @param $key (string) image sub-key
  20030. * @param $data (array) image data
  20031. * @protected
  20032. * @since 4.5.000 (2008-12-31)
  20033. */
  20034. protected function setImageSubBuffer($image, $key, $data) {
  20035. if (!isset($this->images[$image])) {
  20036. $this->setImageBuffer($image, array());
  20037. }
  20038. if ($this->diskcache) {
  20039. $tmpimg = $this->getImageBuffer($image);
  20040. $tmpimg[$key] = $data;
  20041. $this->writeDiskCache($this->images[$image], serialize($tmpimg));
  20042. } else {
  20043. $this->images[$image][$key] = $data;
  20044. }
  20045. }
  20046. /**
  20047. * Get image buffer content.
  20048. * @param $image (string) image key
  20049. * @return string image buffer content or false in case of error
  20050. * @protected
  20051. * @since 4.5.000 (2008-12-31)
  20052. */
  20053. protected function getImageBuffer($image) {
  20054. if ($this->diskcache AND isset($this->images[$image])) {
  20055. return unserialize($this->readDiskCache($this->images[$image]));
  20056. } elseif (isset($this->images[$image])) {
  20057. return $this->images[$image];
  20058. }
  20059. return false;
  20060. }
  20061. /**
  20062. * Set font buffer content.
  20063. * @param $font (string) font key
  20064. * @param $data (array) font data
  20065. * @protected
  20066. * @since 4.5.000 (2009-01-02)
  20067. */
  20068. protected function setFontBuffer($font, $data) {
  20069. if ($this->diskcache) {
  20070. if (!isset($this->fonts[$font])) {
  20071. $this->fonts[$font] = TCPDF_STATIC::getObjFilename('font');
  20072. }
  20073. $this->writeDiskCache($this->fonts[$font], serialize($data));
  20074. } else {
  20075. $this->fonts[$font] = $data;
  20076. }
  20077. if (!in_array($font, $this->fontkeys)) {
  20078. $this->fontkeys[] = $font;
  20079. // store object ID for current font
  20080. ++$this->n;
  20081. $this->font_obj_ids[$font] = $this->n;
  20082. $this->setFontSubBuffer($font, 'n', $this->n);
  20083. }
  20084. }
  20085. /**
  20086. * Set font buffer content.
  20087. * @param $font (string) font key
  20088. * @param $key (string) font sub-key
  20089. * @param $data (array) font data
  20090. * @protected
  20091. * @since 4.5.000 (2009-01-02)
  20092. */
  20093. protected function setFontSubBuffer($font, $key, $data) {
  20094. if (!isset($this->fonts[$font])) {
  20095. $this->setFontBuffer($font, array());
  20096. }
  20097. if ($this->diskcache) {
  20098. $tmpfont = $this->getFontBuffer($font);
  20099. $tmpfont[$key] = $data;
  20100. $this->writeDiskCache($this->fonts[$font], serialize($tmpfont));
  20101. } else {
  20102. $this->fonts[$font][$key] = $data;
  20103. }
  20104. }
  20105. /**
  20106. * Get font buffer content.
  20107. * @param $font (string) font key
  20108. * @return string font buffer content or false in case of error
  20109. * @protected
  20110. * @since 4.5.000 (2009-01-02)
  20111. */
  20112. protected function getFontBuffer($font) {
  20113. if ($this->diskcache AND isset($this->fonts[$font])) {
  20114. return unserialize($this->readDiskCache($this->fonts[$font]));
  20115. } elseif (isset($this->fonts[$font])) {
  20116. return $this->fonts[$font];
  20117. }
  20118. return false;
  20119. }
  20120. /**
  20121. * Move a page to a previous position.
  20122. * @param $frompage (int) number of the source page
  20123. * @param $topage (int) number of the destination page (must be less than $frompage)
  20124. * @return true in case of success, false in case of error.
  20125. * @public
  20126. * @since 4.5.000 (2009-01-02)
  20127. */
  20128. public function movePage($frompage, $topage) {
  20129. if (($frompage > $this->numpages) OR ($frompage <= $topage)) {
  20130. return false;
  20131. }
  20132. if ($frompage == $this->page) {
  20133. // close the page before moving it
  20134. $this->endPage();
  20135. }
  20136. // move all page-related states
  20137. $tmppage = $this->getPageBuffer($frompage);
  20138. $tmppagedim = $this->pagedim[$frompage];
  20139. $tmppagelen = $this->pagelen[$frompage];
  20140. $tmpintmrk = $this->intmrk[$frompage];
  20141. $tmpbordermrk = $this->bordermrk[$frompage];
  20142. $tmpcntmrk = $this->cntmrk[$frompage];
  20143. $tmppageobjects = $this->pageobjects[$frompage];
  20144. if (isset($this->footerpos[$frompage])) {
  20145. $tmpfooterpos = $this->footerpos[$frompage];
  20146. }
  20147. if (isset($this->footerlen[$frompage])) {
  20148. $tmpfooterlen = $this->footerlen[$frompage];
  20149. }
  20150. if (isset($this->transfmrk[$frompage])) {
  20151. $tmptransfmrk = $this->transfmrk[$frompage];
  20152. }
  20153. if (isset($this->PageAnnots[$frompage])) {
  20154. $tmpannots = $this->PageAnnots[$frompage];
  20155. }
  20156. if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
  20157. for ($i = $frompage; $i > $topage; --$i) {
  20158. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $frompage)) {
  20159. --$this->pagegroups[$this->newpagegroup[$i]];
  20160. break;
  20161. }
  20162. }
  20163. for ($i = $topage; $i > 0; --$i) {
  20164. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $topage)) {
  20165. ++$this->pagegroups[$this->newpagegroup[$i]];
  20166. break;
  20167. }
  20168. }
  20169. }
  20170. for ($i = $frompage; $i > $topage; --$i) {
  20171. $j = $i - 1;
  20172. // shift pages down
  20173. $this->setPageBuffer($i, $this->getPageBuffer($j));
  20174. $this->pagedim[$i] = $this->pagedim[$j];
  20175. $this->pagelen[$i] = $this->pagelen[$j];
  20176. $this->intmrk[$i] = $this->intmrk[$j];
  20177. $this->bordermrk[$i] = $this->bordermrk[$j];
  20178. $this->cntmrk[$i] = $this->cntmrk[$j];
  20179. $this->pageobjects[$i] = $this->pageobjects[$j];
  20180. if (isset($this->footerpos[$j])) {
  20181. $this->footerpos[$i] = $this->footerpos[$j];
  20182. } elseif (isset($this->footerpos[$i])) {
  20183. unset($this->footerpos[$i]);
  20184. }
  20185. if (isset($this->footerlen[$j])) {
  20186. $this->footerlen[$i] = $this->footerlen[$j];
  20187. } elseif (isset($this->footerlen[$i])) {
  20188. unset($this->footerlen[$i]);
  20189. }
  20190. if (isset($this->transfmrk[$j])) {
  20191. $this->transfmrk[$i] = $this->transfmrk[$j];
  20192. } elseif (isset($this->transfmrk[$i])) {
  20193. unset($this->transfmrk[$i]);
  20194. }
  20195. if (isset($this->PageAnnots[$j])) {
  20196. $this->PageAnnots[$i] = $this->PageAnnots[$j];
  20197. } elseif (isset($this->PageAnnots[$i])) {
  20198. unset($this->PageAnnots[$i]);
  20199. }
  20200. if (isset($this->newpagegroup[$j])) {
  20201. $this->newpagegroup[$i] = $this->newpagegroup[$j];
  20202. unset($this->newpagegroup[$j]);
  20203. }
  20204. if ($this->currpagegroup == $j) {
  20205. $this->currpagegroup = $i;
  20206. }
  20207. }
  20208. $this->setPageBuffer($topage, $tmppage);
  20209. $this->pagedim[$topage] = $tmppagedim;
  20210. $this->pagelen[$topage] = $tmppagelen;
  20211. $this->intmrk[$topage] = $tmpintmrk;
  20212. $this->bordermrk[$topage] = $tmpbordermrk;
  20213. $this->cntmrk[$topage] = $tmpcntmrk;
  20214. $this->pageobjects[$topage] = $tmppageobjects;
  20215. if (isset($tmpfooterpos)) {
  20216. $this->footerpos[$topage] = $tmpfooterpos;
  20217. } elseif (isset($this->footerpos[$topage])) {
  20218. unset($this->footerpos[$topage]);
  20219. }
  20220. if (isset($tmpfooterlen)) {
  20221. $this->footerlen[$topage] = $tmpfooterlen;
  20222. } elseif (isset($this->footerlen[$topage])) {
  20223. unset($this->footerlen[$topage]);
  20224. }
  20225. if (isset($tmptransfmrk)) {
  20226. $this->transfmrk[$topage] = $tmptransfmrk;
  20227. } elseif (isset($this->transfmrk[$topage])) {
  20228. unset($this->transfmrk[$topage]);
  20229. }
  20230. if (isset($tmpannots)) {
  20231. $this->PageAnnots[$topage] = $tmpannots;
  20232. } elseif (isset($this->PageAnnots[$topage])) {
  20233. unset($this->PageAnnots[$topage]);
  20234. }
  20235. // adjust outlines
  20236. $tmpoutlines = $this->outlines;
  20237. foreach ($tmpoutlines as $key => $outline) {
  20238. if (($outline['p'] >= $topage) AND ($outline['p'] < $frompage)) {
  20239. $this->outlines[$key]['p'] = ($outline['p'] + 1);
  20240. } elseif ($outline['p'] == $frompage) {
  20241. $this->outlines[$key]['p'] = $topage;
  20242. }
  20243. }
  20244. // adjust dests
  20245. $tmpdests = $this->dests;
  20246. foreach ($tmpdests as $key => $dest) {
  20247. if (($dest['p'] >= $topage) AND ($dest['p'] < $frompage)) {
  20248. $this->dests[$key]['p'] = ($dest['p'] + 1);
  20249. } elseif ($dest['p'] == $frompage) {
  20250. $this->dests[$key]['p'] = $topage;
  20251. }
  20252. }
  20253. // adjust links
  20254. $tmplinks = $this->links;
  20255. foreach ($tmplinks as $key => $link) {
  20256. if (($link[0] >= $topage) AND ($link[0] < $frompage)) {
  20257. $this->links[$key][0] = ($link[0] + 1);
  20258. } elseif ($link[0] == $frompage) {
  20259. $this->links[$key][0] = $topage;
  20260. }
  20261. }
  20262. // adjust javascript
  20263. $jfrompage = $frompage;
  20264. $jtopage = $topage;
  20265. if (preg_match_all('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', $this->javascript, $pamatch) > 0) {
  20266. foreach($pamatch[0] as $pk => $pmatch) {
  20267. $pagenum = intval($pamatch[3][$pk]) + 1;
  20268. if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) {
  20269. $newpage = ($pagenum + 1);
  20270. } elseif ($pagenum == $jfrompage) {
  20271. $newpage = $jtopage;
  20272. } else {
  20273. $newpage = $pagenum;
  20274. }
  20275. --$newpage;
  20276. $newjs = "this.addField(\'".$pamatch[1][$pk]."\',\'".$pamatch[2][$pk]."\',".$newpage;
  20277. $this->javascript = str_replace($pmatch, $newjs, $this->javascript);
  20278. }
  20279. unset($pamatch);
  20280. }
  20281. // return to last page
  20282. $this->lastPage(true);
  20283. return true;
  20284. }
  20285. /**
  20286. * Remove the specified page.
  20287. * @param $page (int) page to remove
  20288. * @return true in case of success, false in case of error.
  20289. * @public
  20290. * @since 4.6.004 (2009-04-23)
  20291. */
  20292. public function deletePage($page) {
  20293. if (($page < 1) OR ($page > $this->numpages)) {
  20294. return false;
  20295. }
  20296. // delete current page
  20297. unset($this->pages[$page]);
  20298. unset($this->pagedim[$page]);
  20299. unset($this->pagelen[$page]);
  20300. unset($this->intmrk[$page]);
  20301. unset($this->bordermrk[$page]);
  20302. unset($this->cntmrk[$page]);
  20303. foreach ($this->pageobjects[$page] as $oid) {
  20304. if (isset($this->offsets[$oid])){
  20305. unset($this->offsets[$oid]);
  20306. }
  20307. }
  20308. unset($this->pageobjects[$page]);
  20309. if (isset($this->footerpos[$page])) {
  20310. unset($this->footerpos[$page]);
  20311. }
  20312. if (isset($this->footerlen[$page])) {
  20313. unset($this->footerlen[$page]);
  20314. }
  20315. if (isset($this->transfmrk[$page])) {
  20316. unset($this->transfmrk[$page]);
  20317. }
  20318. if (isset($this->PageAnnots[$page])) {
  20319. unset($this->PageAnnots[$page]);
  20320. }
  20321. if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
  20322. for ($i = $page; $i > 0; --$i) {
  20323. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $page)) {
  20324. --$this->pagegroups[$this->newpagegroup[$i]];
  20325. break;
  20326. }
  20327. }
  20328. }
  20329. if (isset($this->pageopen[$page])) {
  20330. unset($this->pageopen[$page]);
  20331. }
  20332. if ($page < $this->numpages) {
  20333. // update remaining pages
  20334. for ($i = $page; $i < $this->numpages; ++$i) {
  20335. $j = $i + 1;
  20336. // shift pages
  20337. $this->setPageBuffer($i, $this->getPageBuffer($j));
  20338. $this->pagedim[$i] = $this->pagedim[$j];
  20339. $this->pagelen[$i] = $this->pagelen[$j];
  20340. $this->intmrk[$i] = $this->intmrk[$j];
  20341. $this->bordermrk[$i] = $this->bordermrk[$j];
  20342. $this->cntmrk[$i] = $this->cntmrk[$j];
  20343. $this->pageobjects[$i] = $this->pageobjects[$j];
  20344. if (isset($this->footerpos[$j])) {
  20345. $this->footerpos[$i] = $this->footerpos[$j];
  20346. } elseif (isset($this->footerpos[$i])) {
  20347. unset($this->footerpos[$i]);
  20348. }
  20349. if (isset($this->footerlen[$j])) {
  20350. $this->footerlen[$i] = $this->footerlen[$j];
  20351. } elseif (isset($this->footerlen[$i])) {
  20352. unset($this->footerlen[$i]);
  20353. }
  20354. if (isset($this->transfmrk[$j])) {
  20355. $this->transfmrk[$i] = $this->transfmrk[$j];
  20356. } elseif (isset($this->transfmrk[$i])) {
  20357. unset($this->transfmrk[$i]);
  20358. }
  20359. if (isset($this->PageAnnots[$j])) {
  20360. $this->PageAnnots[$i] = $this->PageAnnots[$j];
  20361. } elseif (isset($this->PageAnnots[$i])) {
  20362. unset($this->PageAnnots[$i]);
  20363. }
  20364. if (isset($this->newpagegroup[$j])) {
  20365. $this->newpagegroup[$i] = $this->newpagegroup[$j];
  20366. unset($this->newpagegroup[$j]);
  20367. }
  20368. if ($this->currpagegroup == $j) {
  20369. $this->currpagegroup = $i;
  20370. }
  20371. if (isset($this->pageopen[$j])) {
  20372. $this->pageopen[$i] = $this->pageopen[$j];
  20373. } elseif (isset($this->pageopen[$i])) {
  20374. unset($this->pageopen[$i]);
  20375. }
  20376. }
  20377. // remove last page
  20378. unset($this->pages[$this->numpages]);
  20379. unset($this->pagedim[$this->numpages]);
  20380. unset($this->pagelen[$this->numpages]);
  20381. unset($this->intmrk[$this->numpages]);
  20382. unset($this->bordermrk[$this->numpages]);
  20383. unset($this->cntmrk[$this->numpages]);
  20384. foreach ($this->pageobjects[$this->numpages] as $oid) {
  20385. if (isset($this->offsets[$oid])){
  20386. unset($this->offsets[$oid]);
  20387. }
  20388. }
  20389. unset($this->pageobjects[$this->numpages]);
  20390. if (isset($this->footerpos[$this->numpages])) {
  20391. unset($this->footerpos[$this->numpages]);
  20392. }
  20393. if (isset($this->footerlen[$this->numpages])) {
  20394. unset($this->footerlen[$this->numpages]);
  20395. }
  20396. if (isset($this->transfmrk[$this->numpages])) {
  20397. unset($this->transfmrk[$this->numpages]);
  20398. }
  20399. if (isset($this->PageAnnots[$this->numpages])) {
  20400. unset($this->PageAnnots[$this->numpages]);
  20401. }
  20402. if (isset($this->newpagegroup[$this->numpages])) {
  20403. unset($this->newpagegroup[$this->numpages]);
  20404. }
  20405. if ($this->currpagegroup == $this->numpages) {
  20406. $this->currpagegroup = ($this->numpages - 1);
  20407. }
  20408. if (isset($this->pagegroups[$this->numpages])) {
  20409. unset($this->pagegroups[$this->numpages]);
  20410. }
  20411. if (isset($this->pageopen[$this->numpages])) {
  20412. unset($this->pageopen[$this->numpages]);
  20413. }
  20414. }
  20415. --$this->numpages;
  20416. $this->page = $this->numpages;
  20417. // adjust outlines
  20418. $tmpoutlines = $this->outlines;
  20419. foreach ($tmpoutlines as $key => $outline) {
  20420. if ($outline['p'] > $page) {
  20421. $this->outlines[$key]['p'] = $outline['p'] - 1;
  20422. } elseif ($outline['p'] == $page) {
  20423. unset($this->outlines[$key]);
  20424. }
  20425. }
  20426. // adjust dests
  20427. $tmpdests = $this->dests;
  20428. foreach ($tmpdests as $key => $dest) {
  20429. if ($dest['p'] > $page) {
  20430. $this->dests[$key]['p'] = $dest['p'] - 1;
  20431. } elseif ($dest['p'] == $page) {
  20432. unset($this->dests[$key]);
  20433. }
  20434. }
  20435. // adjust links
  20436. $tmplinks = $this->links;
  20437. foreach ($tmplinks as $key => $link) {
  20438. if ($link[0] > $page) {
  20439. $this->links[$key][0] = $link[0] - 1;
  20440. } elseif ($link[0] == $page) {
  20441. unset($this->links[$key]);
  20442. }
  20443. }
  20444. // adjust javascript
  20445. $jpage = $page;
  20446. if (preg_match_all('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', $this->javascript, $pamatch) > 0) {
  20447. foreach($pamatch[0] as $pk => $pmatch) {
  20448. $pagenum = intval($pamatch[3][$pk]) + 1;
  20449. if ($pagenum >= $jpage) {
  20450. $newpage = ($pagenum - 1);
  20451. } elseif ($pagenum == $jpage) {
  20452. $newpage = 1;
  20453. } else {
  20454. $newpage = $pagenum;
  20455. }
  20456. --$newpage;
  20457. $newjs = "this.addField(\'".$pamatch[1][$pk]."\',\'".$pamatch[2][$pk]."\',".$newpage;
  20458. $this->javascript = str_replace($pmatch, $newjs, $this->javascript);
  20459. }
  20460. unset($pamatch);
  20461. }
  20462. // return to last page
  20463. if ($this->numpages > 0) {
  20464. $this->lastPage(true);
  20465. }
  20466. return true;
  20467. }
  20468. /**
  20469. * Clone the specified page to a new page.
  20470. * @param $page (int) number of page to copy (0 = current page)
  20471. * @return true in case of success, false in case of error.
  20472. * @public
  20473. * @since 4.9.015 (2010-04-20)
  20474. */
  20475. public function copyPage($page=0) {
  20476. if ($page == 0) {
  20477. // default value
  20478. $page = $this->page;
  20479. }
  20480. if (($page < 1) OR ($page > $this->numpages)) {
  20481. return false;
  20482. }
  20483. // close the last page
  20484. $this->endPage();
  20485. // copy all page-related states
  20486. ++$this->numpages;
  20487. $this->page = $this->numpages;
  20488. $this->setPageBuffer($this->page, $this->getPageBuffer($page));
  20489. $this->pagedim[$this->page] = $this->pagedim[$page];
  20490. $this->pagelen[$this->page] = $this->pagelen[$page];
  20491. $this->intmrk[$this->page] = $this->intmrk[$page];
  20492. $this->bordermrk[$this->page] = $this->bordermrk[$page];
  20493. $this->cntmrk[$this->page] = $this->cntmrk[$page];
  20494. $this->pageobjects[$this->page] = $this->pageobjects[$page];
  20495. $this->pageopen[$this->page] = false;
  20496. if (isset($this->footerpos[$page])) {
  20497. $this->footerpos[$this->page] = $this->footerpos[$page];
  20498. }
  20499. if (isset($this->footerlen[$page])) {
  20500. $this->footerlen[$this->page] = $this->footerlen[$page];
  20501. }
  20502. if (isset($this->transfmrk[$page])) {
  20503. $this->transfmrk[$this->page] = $this->transfmrk[$page];
  20504. }
  20505. if (isset($this->PageAnnots[$page])) {
  20506. $this->PageAnnots[$this->page] = $this->PageAnnots[$page];
  20507. }
  20508. if (isset($this->newpagegroup[$page])) {
  20509. // start a new group
  20510. $this->newpagegroup[$this->page] = sizeof($this->newpagegroup) + 1;
  20511. $this->currpagegroup = $this->newpagegroup[$this->page];
  20512. $this->pagegroups[$this->currpagegroup] = 1;
  20513. } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) {
  20514. ++$this->pagegroups[$this->currpagegroup];
  20515. }
  20516. // copy outlines
  20517. $tmpoutlines = $this->outlines;
  20518. foreach ($tmpoutlines as $key => $outline) {
  20519. if ($outline['p'] == $page) {
  20520. $this->outlines[] = array('t' => $outline['t'], 'l' => $outline['l'], 'x' => $outline['x'], 'y' => $outline['y'], 'p' => $this->page, 's' => $outline['s'], 'c' => $outline['c']);
  20521. }
  20522. }
  20523. // copy links
  20524. $tmplinks = $this->links;
  20525. foreach ($tmplinks as $key => $link) {
  20526. if ($link[0] == $page) {
  20527. $this->links[] = array($this->page, $link[1]);
  20528. }
  20529. }
  20530. // return to last page
  20531. $this->lastPage(true);
  20532. return true;
  20533. }
  20534. /**
  20535. * Output a Table of Content Index (TOC).
  20536. * This method must be called after all Bookmarks were set.
  20537. * Before calling this method you have to open the page using the addTOCPage() method.
  20538. * After calling this method you have to call endTOCPage() to close the TOC page.
  20539. * You can override this method to achieve different styles.
  20540. * @param $page (int) page number where this TOC should be inserted (leave empty for current page).
  20541. * @param $numbersfont (string) set the font for page numbers (please use monospaced font for better alignment).
  20542. * @param $filler (string) string used to fill the space between text and page number.
  20543. * @param $toc_name (string) name to use for TOC bookmark.
  20544. * @param $style (string) Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
  20545. * @param $color (array) RGB color array for bookmark title (values from 0 to 255).
  20546. * @public
  20547. * @author Nicola Asuni
  20548. * @since 4.5.000 (2009-01-02)
  20549. * @see addTOCPage(), endTOCPage(), addHTMLTOC()
  20550. */
  20551. public function addTOC($page='', $numbersfont='', $filler='.', $toc_name='TOC', $style='', $color=array(0,0,0)) {
  20552. $fontsize = $this->FontSizePt;
  20553. $fontfamily = $this->FontFamily;
  20554. $fontstyle = $this->FontStyle;
  20555. $w = $this->w - $this->lMargin - $this->rMargin;
  20556. $spacer = $this->GetStringWidth(chr(32)) * 4;
  20557. $lmargin = $this->lMargin;
  20558. $rmargin = $this->rMargin;
  20559. $x_start = $this->GetX();
  20560. $page_first = $this->page;
  20561. $current_page = $this->page;
  20562. $page_fill_start = false;
  20563. $page_fill_end = false;
  20564. $current_column = $this->current_column;
  20565. if (TCPDF_STATIC::empty_string($numbersfont)) {
  20566. $numbersfont = $this->default_monospaced_font;
  20567. }
  20568. if (TCPDF_STATIC::empty_string($filler)) {
  20569. $filler = ' ';
  20570. }
  20571. if (TCPDF_STATIC::empty_string($page)) {
  20572. $gap = ' ';
  20573. } else {
  20574. $gap = '';
  20575. if ($page < 1) {
  20576. $page = 1;
  20577. }
  20578. }
  20579. $this->SetFont($numbersfont, $fontstyle, $fontsize);
  20580. $numwidth = $this->GetStringWidth('00000');
  20581. $maxpage = 0; //used for pages on attached documents
  20582. foreach ($this->outlines as $key => $outline) {
  20583. // check for extra pages (used for attachments)
  20584. if (($this->page > $page_first) AND ($outline['p'] >= $this->numpages)) {
  20585. $outline['p'] += ($this->page - $page_first);
  20586. }
  20587. if ($this->rtl) {
  20588. $aligntext = 'R';
  20589. $alignnum = 'L';
  20590. } else {
  20591. $aligntext = 'L';
  20592. $alignnum = 'R';
  20593. }
  20594. if ($outline['l'] == 0) {
  20595. $this->SetFont($fontfamily, $outline['s'].'B', $fontsize);
  20596. } else {
  20597. $this->SetFont($fontfamily, $outline['s'], $fontsize - $outline['l']);
  20598. }
  20599. $this->SetTextColorArray($outline['c']);
  20600. // check for page break
  20601. $this->checkPageBreak(2 * $this->getCellHeight($this->FontSize));
  20602. // set margins and X position
  20603. if (($this->page == $current_page) AND ($this->current_column == $current_column)) {
  20604. $this->lMargin = $lmargin;
  20605. $this->rMargin = $rmargin;
  20606. } else {
  20607. if ($this->current_column != $current_column) {
  20608. if ($this->rtl) {
  20609. $x_start = $this->w - $this->columns[$this->current_column]['x'];
  20610. } else {
  20611. $x_start = $this->columns[$this->current_column]['x'];
  20612. }
  20613. }
  20614. $lmargin = $this->lMargin;
  20615. $rmargin = $this->rMargin;
  20616. $current_page = $this->page;
  20617. $current_column = $this->current_column;
  20618. }
  20619. $this->SetX($x_start);
  20620. $indent = ($spacer * $outline['l']);
  20621. if ($this->rtl) {
  20622. $this->x -= $indent;
  20623. $this->rMargin = $this->w - $this->x;
  20624. } else {
  20625. $this->x += $indent;
  20626. $this->lMargin = $this->x;
  20627. }
  20628. $link = $this->AddLink();
  20629. $this->SetLink($link, $outline['y'], $outline['p']);
  20630. // write the text
  20631. if ($this->rtl) {
  20632. $txt = ' '.$outline['t'];
  20633. } else {
  20634. $txt = $outline['t'].' ';
  20635. }
  20636. $this->Write(0, $txt, $link, false, $aligntext, false, 0, false, false, 0, $numwidth, '');
  20637. if ($this->rtl) {
  20638. $tw = $this->x - $this->lMargin;
  20639. } else {
  20640. $tw = $this->w - $this->rMargin - $this->x;
  20641. }
  20642. $this->SetFont($numbersfont, $fontstyle, $fontsize);
  20643. if (TCPDF_STATIC::empty_string($page)) {
  20644. $pagenum = $outline['p'];
  20645. } else {
  20646. // placemark to be replaced with the correct number
  20647. $pagenum = '{#'.($outline['p']).'}';
  20648. if ($this->isUnicodeFont()) {
  20649. $pagenum = '{'.$pagenum.'}';
  20650. }
  20651. $maxpage = max($maxpage, $outline['p']);
  20652. }
  20653. $fw = ($tw - $this->GetStringWidth($pagenum.$filler));
  20654. $wfiller = $this->GetStringWidth($filler);
  20655. if ($wfiller > 0) {
  20656. $numfills = floor($fw / $wfiller);
  20657. } else {
  20658. $numfills = 0;
  20659. }
  20660. if ($numfills > 0) {
  20661. $rowfill = str_repeat($filler, $numfills);
  20662. } else {
  20663. $rowfill = '';
  20664. }
  20665. if ($this->rtl) {
  20666. $pagenum = $pagenum.$gap.$rowfill;
  20667. } else {
  20668. $pagenum = $rowfill.$gap.$pagenum;
  20669. }
  20670. // write the number
  20671. $this->Cell($tw, 0, $pagenum, 0, 1, $alignnum, 0, $link, 0);
  20672. }
  20673. $page_last = $this->getPage();
  20674. $numpages = ($page_last - $page_first + 1);
  20675. // account for booklet mode
  20676. if ($this->booklet) {
  20677. // check if a blank page is required before TOC
  20678. $page_fill_start = ((($page_first % 2) == 0) XOR (($page % 2) == 0));
  20679. $page_fill_end = (!((($numpages % 2) == 0) XOR ($page_fill_start)));
  20680. if ($page_fill_start) {
  20681. // add a page at the end (to be moved before TOC)
  20682. $this->addPage();
  20683. ++$page_last;
  20684. ++$numpages;
  20685. }
  20686. if ($page_fill_end) {
  20687. // add a page at the end
  20688. $this->addPage();
  20689. ++$page_last;
  20690. ++$numpages;
  20691. }
  20692. }
  20693. $maxpage = max($maxpage, $page_last);
  20694. if (!TCPDF_STATIC::empty_string($page)) {
  20695. for ($p = $page_first; $p <= $page_last; ++$p) {
  20696. // get page data
  20697. $temppage = $this->getPageBuffer($p);
  20698. for ($n = 1; $n <= $maxpage; ++$n) {
  20699. // update page numbers
  20700. $a = '{#'.$n.'}';
  20701. // get page number aliases
  20702. $pnalias = $this->getInternalPageNumberAliases($a);
  20703. // calculate replacement number
  20704. if (($n >= $page) AND ($n <= $this->numpages)) {
  20705. $np = $n + $numpages;
  20706. } else {
  20707. $np = $n;
  20708. }
  20709. $na = TCPDF_STATIC::formatTOCPageNumber(($this->starting_page_number + $np - 1));
  20710. $nu = TCPDF_FONTS::UTF8ToUTF16BE($na, false, $this->isunicode, $this->CurrentFont);
  20711. // replace aliases with numbers
  20712. foreach ($pnalias['u'] as $u) {
  20713. $sfill = str_repeat($filler, max(0, (strlen($u) - strlen($nu.' '))));
  20714. if ($this->rtl) {
  20715. $nr = $nu.TCPDF_FONTS::UTF8ToUTF16BE(' '.$sfill, false, $this->isunicode, $this->CurrentFont);
  20716. } else {
  20717. $nr = TCPDF_FONTS::UTF8ToUTF16BE($sfill.' ', false, $this->isunicode, $this->CurrentFont).$nu;
  20718. }
  20719. $temppage = str_replace($u, $nr, $temppage);
  20720. }
  20721. foreach ($pnalias['a'] as $a) {
  20722. $sfill = str_repeat($filler, max(0, (strlen($a) - strlen($na.' '))));
  20723. if ($this->rtl) {
  20724. $nr = $na.' '.$sfill;
  20725. } else {
  20726. $nr = $sfill.' '.$na;
  20727. }
  20728. $temppage = str_replace($a, $nr, $temppage);
  20729. }
  20730. }
  20731. // save changes
  20732. $this->setPageBuffer($p, $temppage);
  20733. }
  20734. // move pages
  20735. $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
  20736. if ($page_fill_start) {
  20737. $this->movePage($page_last, $page_first);
  20738. }
  20739. for ($i = 0; $i < $numpages; ++$i) {
  20740. $this->movePage($page_last, $page);
  20741. }
  20742. }
  20743. }
  20744. /**
  20745. * Output a Table Of Content Index (TOC) using HTML templates.
  20746. * This method must be called after all Bookmarks were set.
  20747. * Before calling this method you have to open the page using the addTOCPage() method.
  20748. * After calling this method you have to call endTOCPage() to close the TOC page.
  20749. * @param $page (int) page number where this TOC should be inserted (leave empty for current page).
  20750. * @param $toc_name (string) name to use for TOC bookmark.
  20751. * @param $templates (array) array of html templates. Use: "#TOC_DESCRIPTION#" for bookmark title, "#TOC_PAGE_NUMBER#" for page number.
  20752. * @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)
  20753. * @param $style (string) Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
  20754. * @param $color (array) RGB color array for title (values from 0 to 255).
  20755. * @public
  20756. * @author Nicola Asuni
  20757. * @since 5.0.001 (2010-05-06)
  20758. * @see addTOCPage(), endTOCPage(), addTOC()
  20759. */
  20760. public function addHTMLTOC($page='', $toc_name='TOC', $templates=array(), $correct_align=true, $style='', $color=array(0,0,0)) {
  20761. $filler = ' ';
  20762. $prev_htmlLinkColorArray = $this->htmlLinkColorArray;
  20763. $prev_htmlLinkFontStyle = $this->htmlLinkFontStyle;
  20764. // set new style for link
  20765. $this->htmlLinkColorArray = array();
  20766. $this->htmlLinkFontStyle = '';
  20767. $page_first = $this->getPage();
  20768. $page_fill_start = false;
  20769. $page_fill_end = false;
  20770. // get the font type used for numbers in each template
  20771. $current_font = $this->FontFamily;
  20772. foreach ($templates as $level => $html) {
  20773. $dom = $this->getHtmlDomArray($html);
  20774. foreach ($dom as $key => $value) {
  20775. if ($value['value'] == '#TOC_PAGE_NUMBER#') {
  20776. $this->SetFont($dom[($key - 1)]['fontname']);
  20777. $templates['F'.$level] = $this->isUnicodeFont();
  20778. }
  20779. }
  20780. }
  20781. $this->SetFont($current_font);
  20782. $maxpage = 0; //used for pages on attached documents
  20783. foreach ($this->outlines as $key => $outline) {
  20784. // get HTML template
  20785. $row = $templates[$outline['l']];
  20786. if (TCPDF_STATIC::empty_string($page)) {
  20787. $pagenum = $outline['p'];
  20788. } else {
  20789. // placemark to be replaced with the correct number
  20790. $pagenum = '{#'.($outline['p']).'}';
  20791. if ($templates['F'.$outline['l']]) {
  20792. $pagenum = '{'.$pagenum.'}';
  20793. }
  20794. $maxpage = max($maxpage, $outline['p']);
  20795. }
  20796. // replace templates with current values
  20797. $row = str_replace('#TOC_DESCRIPTION#', $outline['t'], $row);
  20798. $row = str_replace('#TOC_PAGE_NUMBER#', $pagenum, $row);
  20799. // add link to page
  20800. $row = '<a href="#'.$outline['p'].','.$outline['y'].'">'.$row.'</a>';
  20801. // write bookmark entry
  20802. $this->writeHTML($row, false, false, true, false, '');
  20803. }
  20804. // restore link styles
  20805. $this->htmlLinkColorArray = $prev_htmlLinkColorArray;
  20806. $this->htmlLinkFontStyle = $prev_htmlLinkFontStyle;
  20807. // move TOC page and replace numbers
  20808. $page_last = $this->getPage();
  20809. $numpages = ($page_last - $page_first + 1);
  20810. // account for booklet mode
  20811. if ($this->booklet) {
  20812. // check if a blank page is required before TOC
  20813. $page_fill_start = ((($page_first % 2) == 0) XOR (($page % 2) == 0));
  20814. $page_fill_end = (!((($numpages % 2) == 0) XOR ($page_fill_start)));
  20815. if ($page_fill_start) {
  20816. // add a page at the end (to be moved before TOC)
  20817. $this->addPage();
  20818. ++$page_last;
  20819. ++$numpages;
  20820. }
  20821. if ($page_fill_end) {
  20822. // add a page at the end
  20823. $this->addPage();
  20824. ++$page_last;
  20825. ++$numpages;
  20826. }
  20827. }
  20828. $maxpage = max($maxpage, $page_last);
  20829. if (!TCPDF_STATIC::empty_string($page)) {
  20830. for ($p = $page_first; $p <= $page_last; ++$p) {
  20831. // get page data
  20832. $temppage = $this->getPageBuffer($p);
  20833. for ($n = 1; $n <= $maxpage; ++$n) {
  20834. // update page numbers
  20835. $a = '{#'.$n.'}';
  20836. // get page number aliases
  20837. $pnalias = $this->getInternalPageNumberAliases($a);
  20838. // calculate replacement number
  20839. if ($n >= $page) {
  20840. $np = $n + $numpages;
  20841. } else {
  20842. $np = $n;
  20843. }
  20844. $na = TCPDF_STATIC::formatTOCPageNumber(($this->starting_page_number + $np - 1));
  20845. $nu = TCPDF_FONTS::UTF8ToUTF16BE($na, false, $this->isunicode, $this->CurrentFont);
  20846. // replace aliases with numbers
  20847. foreach ($pnalias['u'] as $u) {
  20848. if ($correct_align) {
  20849. $sfill = str_repeat($filler, (strlen($u) - strlen($nu.' ')));
  20850. if ($this->rtl) {
  20851. $nr = $nu.TCPDF_FONTS::UTF8ToUTF16BE(' '.$sfill, false, $this->isunicode, $this->CurrentFont);
  20852. } else {
  20853. $nr = TCPDF_FONTS::UTF8ToUTF16BE($sfill.' ', false, $this->isunicode, $this->CurrentFont).$nu;
  20854. }
  20855. } else {
  20856. $nr = $nu;
  20857. }
  20858. $temppage = str_replace($u, $nr, $temppage);
  20859. }
  20860. foreach ($pnalias['a'] as $a) {
  20861. if ($correct_align) {
  20862. $sfill = str_repeat($filler, (strlen($a) - strlen($na.' ')));
  20863. if ($this->rtl) {
  20864. $nr = $na.' '.$sfill;
  20865. } else {
  20866. $nr = $sfill.' '.$na;
  20867. }
  20868. } else {
  20869. $nr = $na;
  20870. }
  20871. $temppage = str_replace($a, $nr, $temppage);
  20872. }
  20873. }
  20874. // save changes
  20875. $this->setPageBuffer($p, $temppage);
  20876. }
  20877. // move pages
  20878. $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
  20879. if ($page_fill_start) {
  20880. $this->movePage($page_last, $page_first);
  20881. }
  20882. for ($i = 0; $i < $numpages; ++$i) {
  20883. $this->movePage($page_last, $page);
  20884. }
  20885. }
  20886. }
  20887. /**
  20888. * Stores a copy of the current TCPDF object used for undo operation.
  20889. * @public
  20890. * @since 4.5.029 (2009-03-19)
  20891. */
  20892. public function startTransaction() {
  20893. if (isset($this->objcopy)) {
  20894. // remove previous copy
  20895. $this->commitTransaction();
  20896. }
  20897. // record current page number and Y position
  20898. $this->start_transaction_page = $this->page;
  20899. $this->start_transaction_y = $this->y;
  20900. // clone current object
  20901. $this->objcopy = TCPDF_STATIC::objclone($this);
  20902. }
  20903. /**
  20904. * Delete the copy of the current TCPDF object used for undo operation.
  20905. * @public
  20906. * @since 4.5.029 (2009-03-19)
  20907. */
  20908. public function commitTransaction() {
  20909. if (isset($this->objcopy)) {
  20910. $this->objcopy->_destroy(true, true);
  20911. unset($this->objcopy);
  20912. }
  20913. }
  20914. /**
  20915. * This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction().
  20916. * @param $self (boolean) if true restores current class object to previous state without the need of reassignment via the returned value.
  20917. * @return TCPDF object.
  20918. * @public
  20919. * @since 4.5.029 (2009-03-19)
  20920. */
  20921. public function rollbackTransaction($self=false) {
  20922. if (isset($this->objcopy)) {
  20923. if (isset($this->objcopy->diskcache) AND $this->objcopy->diskcache) {
  20924. // truncate files to previous values
  20925. foreach ($this->objcopy->cache_file_length as $file => $length) {
  20926. $file = substr($file, 1);
  20927. $handle = fopen($file, 'r+');
  20928. ftruncate($handle, $length);
  20929. }
  20930. }
  20931. $this->_destroy(true, true);
  20932. if ($self) {
  20933. $objvars = get_object_vars($this->objcopy);
  20934. foreach ($objvars as $key => $value) {
  20935. $this->$key = $value;
  20936. }
  20937. }
  20938. return $this->objcopy;
  20939. }
  20940. return $this;
  20941. }
  20942. // --- MULTI COLUMNS METHODS -----------------------
  20943. /**
  20944. * Set multiple columns of the same size
  20945. * @param $numcols (int) number of columns (set to zero to disable columns mode)
  20946. * @param $width (int) column width
  20947. * @param $y (int) column starting Y position (leave empty for current Y position)
  20948. * @public
  20949. * @since 4.9.001 (2010-03-28)
  20950. */
  20951. public function setEqualColumns($numcols=0, $width=0, $y='') {
  20952. $this->columns = array();
  20953. if ($numcols < 2) {
  20954. $numcols = 0;
  20955. $this->columns = array();
  20956. } else {
  20957. // maximum column width
  20958. $maxwidth = ($this->w - $this->original_lMargin - $this->original_rMargin) / $numcols;
  20959. if (($width == 0) OR ($width > $maxwidth)) {
  20960. $width = $maxwidth;
  20961. }
  20962. if (TCPDF_STATIC::empty_string($y)) {
  20963. $y = $this->y;
  20964. }
  20965. // space between columns
  20966. $space = (($this->w - $this->original_lMargin - $this->original_rMargin - ($numcols * $width)) / ($numcols - 1));
  20967. // fill the columns array (with, space, starting Y position)
  20968. for ($i = 0; $i < $numcols; ++$i) {
  20969. $this->columns[$i] = array('w' => $width, 's' => $space, 'y' => $y);
  20970. }
  20971. }
  20972. $this->num_columns = $numcols;
  20973. $this->current_column = 0;
  20974. $this->column_start_page = $this->page;
  20975. $this->selectColumn(0);
  20976. }
  20977. /**
  20978. * Remove columns and reset page margins.
  20979. * @public
  20980. * @since 5.9.072 (2011-04-26)
  20981. */
  20982. public function resetColumns() {
  20983. $this->lMargin = $this->original_lMargin;
  20984. $this->rMargin = $this->original_rMargin;
  20985. $this->setEqualColumns();
  20986. }
  20987. /**
  20988. * Set columns array.
  20989. * Each column is represented by an array of arrays with the following keys: (w = width, s = space between columns, y = column top position).
  20990. * @param $columns (array)
  20991. * @public
  20992. * @since 4.9.001 (2010-03-28)
  20993. */
  20994. public function setColumnsArray($columns) {
  20995. $this->columns = $columns;
  20996. $this->num_columns = count($columns);
  20997. $this->current_column = 0;
  20998. $this->column_start_page = $this->page;
  20999. $this->selectColumn(0);
  21000. }
  21001. /**
  21002. * Set position at a given column
  21003. * @param $col (int) column number (from 0 to getNumberOfColumns()-1); empty string = current column.
  21004. * @public
  21005. * @since 4.9.001 (2010-03-28)
  21006. */
  21007. public function selectColumn($col='') {
  21008. if (is_string($col)) {
  21009. $col = $this->current_column;
  21010. } elseif ($col >= $this->num_columns) {
  21011. $col = 0;
  21012. }
  21013. $xshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  21014. $enable_thead = false;
  21015. if ($this->num_columns > 1) {
  21016. if ($col != $this->current_column) {
  21017. // move Y pointer at the top of the column
  21018. if ($this->column_start_page == $this->page) {
  21019. $this->y = $this->columns[$col]['y'];
  21020. } else {
  21021. $this->y = $this->tMargin;
  21022. }
  21023. // Avoid to write table headers more than once
  21024. if (($this->page > $this->maxselcol['page']) OR (($this->page == $this->maxselcol['page']) AND ($col > $this->maxselcol['column']))) {
  21025. $enable_thead = true;
  21026. $this->maxselcol['page'] = $this->page;
  21027. $this->maxselcol['column'] = $col;
  21028. }
  21029. }
  21030. $xshift = $this->colxshift;
  21031. // set X position of the current column by case
  21032. $listindent = ($this->listindentlevel * $this->listindent);
  21033. // calculate column X position
  21034. $colpos = 0;
  21035. for ($i = 0; $i < $col; ++$i) {
  21036. $colpos += ($this->columns[$i]['w'] + $this->columns[$i]['s']);
  21037. }
  21038. if ($this->rtl) {
  21039. $x = $this->w - $this->original_rMargin - $colpos;
  21040. $this->rMargin = ($this->w - $x + $listindent);
  21041. $this->lMargin = ($x - $this->columns[$col]['w']);
  21042. $this->x = $x - $listindent;
  21043. } else {
  21044. $x = $this->original_lMargin + $colpos;
  21045. $this->lMargin = ($x + $listindent);
  21046. $this->rMargin = ($this->w - $x - $this->columns[$col]['w']);
  21047. $this->x = $x + $listindent;
  21048. }
  21049. $this->columns[$col]['x'] = $x;
  21050. }
  21051. $this->current_column = $col;
  21052. // fix for HTML mode
  21053. $this->newline = true;
  21054. // print HTML table header (if any)
  21055. if ((!TCPDF_STATIC::empty_string($this->thead)) AND (!$this->inthead)) {
  21056. if ($enable_thead) {
  21057. // print table header
  21058. $this->writeHTML($this->thead, false, false, false, false, '');
  21059. $this->y += $xshift['s']['V'];
  21060. // store end of header position
  21061. if (!isset($this->columns[$col]['th'])) {
  21062. $this->columns[$col]['th'] = array();
  21063. }
  21064. $this->columns[$col]['th']['\''.$this->page.'\''] = $this->y;
  21065. $this->lasth = 0;
  21066. } elseif (isset($this->columns[$col]['th']['\''.$this->page.'\''])) {
  21067. $this->y = $this->columns[$col]['th']['\''.$this->page.'\''];
  21068. }
  21069. }
  21070. // account for an html table cell over multiple columns
  21071. if ($this->rtl) {
  21072. $this->rMargin += $xshift['x'];
  21073. $this->x -= ($xshift['x'] + $xshift['p']['R']);
  21074. } else {
  21075. $this->lMargin += $xshift['x'];
  21076. $this->x += $xshift['x'] + $xshift['p']['L'];
  21077. }
  21078. }
  21079. /**
  21080. * Return the current column number
  21081. * @return int current column number
  21082. * @public
  21083. * @since 5.5.011 (2010-07-08)
  21084. */
  21085. public function getColumn() {
  21086. return $this->current_column;
  21087. }
  21088. /**
  21089. * Return the current number of columns.
  21090. * @return int number of columns
  21091. * @public
  21092. * @since 5.8.018 (2010-08-25)
  21093. */
  21094. public function getNumberOfColumns() {
  21095. return $this->num_columns;
  21096. }
  21097. /**
  21098. * Set Text rendering mode.
  21099. * @param $stroke (int) outline size in user units (0 = disable).
  21100. * @param $fill (boolean) if true fills the text (default).
  21101. * @param $clip (boolean) if true activate clipping mode
  21102. * @public
  21103. * @since 4.9.008 (2009-04-02)
  21104. */
  21105. public function setTextRenderingMode($stroke=0, $fill=true, $clip=false) {
  21106. // Ref.: PDF 32000-1:2008 - 9.3.6 Text Rendering Mode
  21107. // convert text rendering parameters
  21108. if ($stroke < 0) {
  21109. $stroke = 0;
  21110. }
  21111. if ($fill === true) {
  21112. if ($stroke > 0) {
  21113. if ($clip === true) {
  21114. // Fill, then stroke text and add to path for clipping
  21115. $textrendermode = 6;
  21116. } else {
  21117. // Fill, then stroke text
  21118. $textrendermode = 2;
  21119. }
  21120. $textstrokewidth = $stroke;
  21121. } else {
  21122. if ($clip === true) {
  21123. // Fill text and add to path for clipping
  21124. $textrendermode = 4;
  21125. } else {
  21126. // Fill text
  21127. $textrendermode = 0;
  21128. }
  21129. }
  21130. } else {
  21131. if ($stroke > 0) {
  21132. if ($clip === true) {
  21133. // Stroke text and add to path for clipping
  21134. $textrendermode = 5;
  21135. } else {
  21136. // Stroke text
  21137. $textrendermode = 1;
  21138. }
  21139. $textstrokewidth = $stroke;
  21140. } else {
  21141. if ($clip === true) {
  21142. // Add text to path for clipping
  21143. $textrendermode = 7;
  21144. } else {
  21145. // Neither fill nor stroke text (invisible)
  21146. $textrendermode = 3;
  21147. }
  21148. }
  21149. }
  21150. $this->textrendermode = $textrendermode;
  21151. $this->textstrokewidth = $stroke;
  21152. }
  21153. /**
  21154. * Set parameters for drop shadow effect for text.
  21155. * @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.
  21156. * @since 5.9.174 (2012-07-25)
  21157. * @public
  21158. */
  21159. public function setTextShadow($params=array('enabled'=>false, 'depth_w'=>0, 'depth_h'=>0, 'color'=>false, 'opacity'=>1, 'blend_mode'=>'Normal')) {
  21160. if (isset($params['enabled'])) {
  21161. $this->txtshadow['enabled'] = $params['enabled']?true:false;
  21162. } else {
  21163. $this->txtshadow['enabled'] = false;
  21164. }
  21165. if (isset($params['depth_w'])) {
  21166. $this->txtshadow['depth_w'] = floatval($params['depth_w']);
  21167. } else {
  21168. $this->txtshadow['depth_w'] = 0;
  21169. }
  21170. if (isset($params['depth_h'])) {
  21171. $this->txtshadow['depth_h'] = floatval($params['depth_h']);
  21172. } else {
  21173. $this->txtshadow['depth_h'] = 0;
  21174. }
  21175. if (isset($params['color']) AND ($params['color'] !== false) AND is_array($params['color'])) {
  21176. $this->txtshadow['color'] = $params['color'];
  21177. } else {
  21178. $this->txtshadow['color'] = $this->strokecolor;
  21179. }
  21180. if (isset($params['opacity'])) {
  21181. $this->txtshadow['opacity'] = min(1, max(0, floatval($params['opacity'])));
  21182. } else {
  21183. $this->txtshadow['opacity'] = 1;
  21184. }
  21185. 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'))) {
  21186. $this->txtshadow['blend_mode'] = $params['blend_mode'];
  21187. } else {
  21188. $this->txtshadow['blend_mode'] = 'Normal';
  21189. }
  21190. if ((($this->txtshadow['depth_w'] == 0) AND ($this->txtshadow['depth_h'] == 0)) OR ($this->txtshadow['opacity'] == 0)) {
  21191. $this->txtshadow['enabled'] = false;
  21192. }
  21193. }
  21194. /**
  21195. * Return the text shadow parameters array.
  21196. * @return Array of parameters.
  21197. * @since 5.9.174 (2012-07-25)
  21198. * @public
  21199. */
  21200. public function getTextShadow() {
  21201. return $this->txtshadow;
  21202. }
  21203. /**
  21204. * Returns an array of chars containing soft hyphens.
  21205. * @param $word (array) array of chars
  21206. * @param $patterns (array) Array of hypenation patterns.
  21207. * @param $dictionary (array) Array of words to be returned without applying the hyphenation algoritm.
  21208. * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens.
  21209. * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens.
  21210. * @param $charmin (int) Minimum word length to apply the hyphenation algoritm.
  21211. * @param $charmax (int) Maximum length of broken piece of word.
  21212. * @return array text with soft hyphens
  21213. * @author Nicola Asuni
  21214. * @since 4.9.012 (2010-04-12)
  21215. * @protected
  21216. */
  21217. protected function hyphenateWord($word, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
  21218. $hyphenword = array(); // hyphens positions
  21219. $numchars = count($word);
  21220. if ($numchars <= $charmin) {
  21221. return $word;
  21222. }
  21223. $word_string = TCPDF_FONTS::UTF8ArrSubString($word, '', '', $this->isunicode);
  21224. // some words will be returned as-is
  21225. $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})(\]?)$/';
  21226. if (preg_match($pattern, $word_string) > 0) {
  21227. // email
  21228. return $word;
  21229. }
  21230. $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})(\]?)$/';
  21231. if (preg_match($pattern, $word_string) > 0) {
  21232. // URL
  21233. return $word;
  21234. }
  21235. if (isset($dictionary[$word_string])) {
  21236. return TCPDF_FONTS::UTF8StringToArray($dictionary[$word_string], $this->isunicode, $this->CurrentFont);
  21237. }
  21238. // suround word with '_' characters
  21239. $tmpword = array_merge(array(95), $word, array(95));
  21240. $tmpnumchars = $numchars + 2;
  21241. $maxpos = $tmpnumchars - $charmin;
  21242. for ($pos = 0; $pos < $maxpos; ++$pos) {
  21243. $imax = min(($tmpnumchars - $pos), $charmax);
  21244. for ($i = $charmin; $i <= $imax; ++$i) {
  21245. $subword = strtolower(TCPDF_FONTS::UTF8ArrSubString($tmpword, $pos, ($pos + $i), $this->isunicode));
  21246. if (isset($patterns[$subword])) {
  21247. $pattern = TCPDF_FONTS::UTF8StringToArray($patterns[$subword], $this->isunicode, $this->CurrentFont);
  21248. $pattern_length = count($pattern);
  21249. $digits = 1;
  21250. for ($j = 0; $j < $pattern_length; ++$j) {
  21251. // check if $pattern[$j] is a number
  21252. if (($pattern[$j] >= 48) AND ($pattern[$j] <= 57)) {
  21253. if ($j == 0) {
  21254. $zero = $pos - 1;
  21255. } else {
  21256. $zero = $pos + $j - $digits;
  21257. }
  21258. if (!isset($hyphenword[$zero]) OR ($hyphenword[$zero] != $pattern[$j])) {
  21259. $hyphenword[$zero] = TCPDF_FONTS::unichr($pattern[$j], $this->isunicode);
  21260. }
  21261. ++$digits;
  21262. }
  21263. }
  21264. }
  21265. }
  21266. }
  21267. $inserted = 0;
  21268. $maxpos = $numchars - $rightmin;
  21269. for ($i = $leftmin; $i <= $maxpos; ++$i) {
  21270. if (isset($hyphenword[$i]) AND (($hyphenword[$i] % 2) != 0)) {
  21271. // 173 = soft hyphen character
  21272. array_splice($word, $i + $inserted, 0, 173);
  21273. ++$inserted;
  21274. }
  21275. }
  21276. return $word;
  21277. }
  21278. /**
  21279. * Returns text with soft hyphens.
  21280. * @param $text (string) text to process
  21281. * @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/
  21282. * @param $dictionary (array) Array of words to be returned without applying the hyphenation algoritm.
  21283. * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens.
  21284. * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens.
  21285. * @param $charmin (int) Minimum word length to apply the hyphenation algoritm.
  21286. * @param $charmax (int) Maximum length of broken piece of word.
  21287. * @return array text with soft hyphens
  21288. * @author Nicola Asuni
  21289. * @since 4.9.012 (2010-04-12)
  21290. * @public
  21291. */
  21292. public function hyphenateText($text, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
  21293. $text = $this->unhtmlentities($text);
  21294. $word = array(); // last word
  21295. $txtarr = array(); // text to be returned
  21296. $intag = false; // true if we are inside an HTML tag
  21297. if (!is_array($patterns)) {
  21298. $patterns = TCPDF_STATIC::getHyphenPatternsFromTEX($patterns);
  21299. }
  21300. // get array of characters
  21301. $unichars = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont);
  21302. // for each char
  21303. foreach ($unichars as $char) {
  21304. if ((!$intag) AND TCPDF_FONT_DATA::$uni_type[$char] == 'L') {
  21305. // letter character
  21306. $word[] = $char;
  21307. } else {
  21308. // other type of character
  21309. if (!TCPDF_STATIC::empty_string($word)) {
  21310. // hypenate the word
  21311. $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
  21312. $word = array();
  21313. }
  21314. $txtarr[] = $char;
  21315. if (chr($char) == '<') {
  21316. // we are inside an HTML tag
  21317. $intag = true;
  21318. } elseif ($intag AND (chr($char) == '>')) {
  21319. // end of HTML tag
  21320. $intag = false;
  21321. }
  21322. }
  21323. }
  21324. if (!TCPDF_STATIC::empty_string($word)) {
  21325. // hypenate the word
  21326. $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
  21327. }
  21328. // convert char array to string and return
  21329. return TCPDF_FONTS::UTF8ArrSubString($txtarr, '', '', $this->isunicode);
  21330. }
  21331. /**
  21332. * Enable/disable rasterization of vector images using ImageMagick library.
  21333. * @param $mode (boolean) if true enable rasterization, false otherwise.
  21334. * @public
  21335. * @since 5.0.000 (2010-04-27)
  21336. */
  21337. public function setRasterizeVectorImages($mode) {
  21338. $this->rasterize_vector_images = $mode;
  21339. }
  21340. /**
  21341. * Enable or disable default option for font subsetting.
  21342. * @param $enable (boolean) if true enable font subsetting by default.
  21343. * @author Nicola Asuni
  21344. * @public
  21345. * @since 5.3.002 (2010-06-07)
  21346. */
  21347. public function setFontSubsetting($enable=true) {
  21348. if ($this->pdfa_mode) {
  21349. $this->font_subsetting = false;
  21350. } else {
  21351. $this->font_subsetting = $enable ? true : false;
  21352. }
  21353. }
  21354. /**
  21355. * Return the default option for font subsetting.
  21356. * @return boolean default font subsetting state.
  21357. * @author Nicola Asuni
  21358. * @public
  21359. * @since 5.3.002 (2010-06-07)
  21360. */
  21361. public function getFontSubsetting() {
  21362. return $this->font_subsetting;
  21363. }
  21364. /**
  21365. * Left trim the input string
  21366. * @param $str (string) string to trim
  21367. * @param $replace (string) string that replace spaces.
  21368. * @return left trimmed string
  21369. * @author Nicola Asuni
  21370. * @public
  21371. * @since 5.8.000 (2010-08-11)
  21372. */
  21373. public function stringLeftTrim($str, $replace='') {
  21374. return preg_replace('/^'.$this->re_space['p'].'+/'.$this->re_space['m'], $replace, $str);
  21375. }
  21376. /**
  21377. * Right trim the input string
  21378. * @param $str (string) string to trim
  21379. * @param $replace (string) string that replace spaces.
  21380. * @return right trimmed string
  21381. * @author Nicola Asuni
  21382. * @public
  21383. * @since 5.8.000 (2010-08-11)
  21384. */
  21385. public function stringRightTrim($str, $replace='') {
  21386. return preg_replace('/'.$this->re_space['p'].'+$/'.$this->re_space['m'], $replace, $str);
  21387. }
  21388. /**
  21389. * Trim the input string
  21390. * @param $str (string) string to trim
  21391. * @param $replace (string) string that replace spaces.
  21392. * @return trimmed string
  21393. * @author Nicola Asuni
  21394. * @public
  21395. * @since 5.8.000 (2010-08-11)
  21396. */
  21397. public function stringTrim($str, $replace='') {
  21398. $str = $this->stringLeftTrim($str, $replace);
  21399. $str = $this->stringRightTrim($str, $replace);
  21400. return $str;
  21401. }
  21402. /**
  21403. * Return true if the current font is unicode type.
  21404. * @return true for unicode font, false otherwise.
  21405. * @author Nicola Asuni
  21406. * @public
  21407. * @since 5.8.002 (2010-08-14)
  21408. */
  21409. public function isUnicodeFont() {
  21410. return (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0'));
  21411. }
  21412. /**
  21413. * Return normalized font name
  21414. * @param $fontfamily (string) property string containing font family names
  21415. * @return string normalized font name
  21416. * @author Nicola Asuni
  21417. * @public
  21418. * @since 5.8.004 (2010-08-17)
  21419. */
  21420. public function getFontFamilyName($fontfamily) {
  21421. // remove spaces and symbols
  21422. $fontfamily = preg_replace('/[^a-z0-9_\,]/', '', strtolower($fontfamily));
  21423. // extract all font names
  21424. $fontslist = preg_split('/[,]/', $fontfamily);
  21425. // find first valid font name
  21426. foreach ($fontslist as $font) {
  21427. // replace font variations
  21428. $font = preg_replace('/italic$/', 'I', $font);
  21429. $font = preg_replace('/oblique$/', 'I', $font);
  21430. $font = preg_replace('/bold([I]?)$/', 'B\\1', $font);
  21431. // replace common family names and core fonts
  21432. $pattern = array();
  21433. $replacement = array();
  21434. $pattern[] = '/^serif|^cursive|^fantasy|^timesnewroman/';
  21435. $replacement[] = 'times';
  21436. $pattern[] = '/^sansserif/';
  21437. $replacement[] = 'helvetica';
  21438. $pattern[] = '/^monospace/';
  21439. $replacement[] = 'courier';
  21440. $font = preg_replace($pattern, $replacement, $font);
  21441. if (in_array(strtolower($font), $this->fontlist) OR in_array($font, $this->fontkeys)) {
  21442. return $font;
  21443. }
  21444. }
  21445. // return current font as default
  21446. return $this->CurrentFont['fontkey'];
  21447. }
  21448. /**
  21449. * Start a new XObject Template.
  21450. * 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).
  21451. * 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.
  21452. * Note: X,Y coordinates will be reset to 0,0.
  21453. * @param $w (int) Template width in user units (empty string or zero = page width less margins).
  21454. * @param $h (int) Template height in user units (empty string or zero = page height less margins).
  21455. * @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).
  21456. * @return int the XObject Template ID in case of success or false in case of error.
  21457. * @author Nicola Asuni
  21458. * @public
  21459. * @since 5.8.017 (2010-08-24)
  21460. * @see endTemplate(), printTemplate()
  21461. */
  21462. public function startTemplate($w=0, $h=0, $group=false) {
  21463. if ($this->inxobj) {
  21464. // we are already inside an XObject template
  21465. return false;
  21466. }
  21467. $this->inxobj = true;
  21468. ++$this->n;
  21469. // XObject ID
  21470. $this->xobjid = 'XT'.$this->n;
  21471. // object ID
  21472. $this->xobjects[$this->xobjid] = array('n' => $this->n);
  21473. // store current graphic state
  21474. $this->xobjects[$this->xobjid]['gvars'] = $this->getGraphicVars();
  21475. // initialize data
  21476. $this->xobjects[$this->xobjid]['intmrk'] = 0;
  21477. $this->xobjects[$this->xobjid]['transfmrk'] = array();
  21478. $this->xobjects[$this->xobjid]['outdata'] = '';
  21479. $this->xobjects[$this->xobjid]['xobjects'] = array();
  21480. $this->xobjects[$this->xobjid]['images'] = array();
  21481. $this->xobjects[$this->xobjid]['fonts'] = array();
  21482. $this->xobjects[$this->xobjid]['annotations'] = array();
  21483. $this->xobjects[$this->xobjid]['extgstates'] = array();
  21484. $this->xobjects[$this->xobjid]['gradients'] = array();
  21485. $this->xobjects[$this->xobjid]['spot_colors'] = array();
  21486. // set new environment
  21487. $this->num_columns = 1;
  21488. $this->current_column = 0;
  21489. $this->SetAutoPageBreak(false);
  21490. if (($w === '') OR ($w <= 0)) {
  21491. $w = $this->w - $this->lMargin - $this->rMargin;
  21492. }
  21493. if (($h === '') OR ($h <= 0)) {
  21494. $h = $this->h - $this->tMargin - $this->bMargin;
  21495. }
  21496. $this->xobjects[$this->xobjid]['x'] = 0;
  21497. $this->xobjects[$this->xobjid]['y'] = 0;
  21498. $this->xobjects[$this->xobjid]['w'] = $w;
  21499. $this->xobjects[$this->xobjid]['h'] = $h;
  21500. $this->w = $w;
  21501. $this->h = $h;
  21502. $this->wPt = $this->w * $this->k;
  21503. $this->hPt = $this->h * $this->k;
  21504. $this->fwPt = $this->wPt;
  21505. $this->fhPt = $this->hPt;
  21506. $this->x = 0;
  21507. $this->y = 0;
  21508. $this->lMargin = 0;
  21509. $this->rMargin = 0;
  21510. $this->tMargin = 0;
  21511. $this->bMargin = 0;
  21512. // set group mode
  21513. $this->xobjects[$this->xobjid]['group'] = $group;
  21514. return $this->xobjid;
  21515. }
  21516. /**
  21517. * End the current XObject Template started with startTemplate() and restore the previous graphic state.
  21518. * 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).
  21519. * 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.
  21520. * @return int the XObject Template ID in case of success or false in case of error.
  21521. * @author Nicola Asuni
  21522. * @public
  21523. * @since 5.8.017 (2010-08-24)
  21524. * @see startTemplate(), printTemplate()
  21525. */
  21526. public function endTemplate() {
  21527. if (!$this->inxobj) {
  21528. // we are not inside a template
  21529. return false;
  21530. }
  21531. $this->inxobj = false;
  21532. // restore previous graphic state
  21533. $this->setGraphicVars($this->xobjects[$this->xobjid]['gvars'], true);
  21534. return $this->xobjid;
  21535. }
  21536. /**
  21537. * Print an XObject Template.
  21538. * You can print an XObject Template inside the currently opened Template.
  21539. * 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).
  21540. * 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.
  21541. * @param $id (string) The ID of XObject Template to print.
  21542. * @param $x (int) X position in user units (empty string = current x position)
  21543. * @param $y (int) Y position in user units (empty string = current y position)
  21544. * @param $w (int) Width in user units (zero = remaining page width)
  21545. * @param $h (int) Height in user units (zero = remaining page height)
  21546. * @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>
  21547. * @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>
  21548. * @param $fitonpage (boolean) If true the template is resized to not exceed page dimensions.
  21549. * @author Nicola Asuni
  21550. * @public
  21551. * @since 5.8.017 (2010-08-24)
  21552. * @see startTemplate(), endTemplate()
  21553. */
  21554. public function printTemplate($id, $x='', $y='', $w=0, $h=0, $align='', $palign='', $fitonpage=false) {
  21555. if ($this->state != 2) {
  21556. return;
  21557. }
  21558. if (!isset($this->xobjects[$id])) {
  21559. $this->Error('The XObject Template \''.$id.'\' doesn\'t exist!');
  21560. }
  21561. if ($this->inxobj) {
  21562. if ($id == $this->xobjid) {
  21563. // close current template
  21564. $this->endTemplate();
  21565. } else {
  21566. // use the template as resource for the template currently opened
  21567. $this->xobjects[$this->xobjid]['xobjects'][$id] = $this->xobjects[$id];
  21568. }
  21569. }
  21570. // set default values
  21571. if ($x === '') {
  21572. $x = $this->x;
  21573. }
  21574. if ($y === '') {
  21575. $y = $this->y;
  21576. }
  21577. // check page for no-write regions and adapt page margins if necessary
  21578. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  21579. $ow = $this->xobjects[$id]['w'];
  21580. if ($ow <= 0) {
  21581. $ow = 1;
  21582. }
  21583. $oh = $this->xobjects[$id]['h'];
  21584. if ($oh <= 0) {
  21585. $oh = 1;
  21586. }
  21587. // calculate template width and height on document
  21588. if (($w <= 0) AND ($h <= 0)) {
  21589. $w = $ow;
  21590. $h = $oh;
  21591. } elseif ($w <= 0) {
  21592. $w = $h * $ow / $oh;
  21593. } elseif ($h <= 0) {
  21594. $h = $w * $oh / $ow;
  21595. }
  21596. // fit the template on available space
  21597. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  21598. // set page alignment
  21599. $rb_y = $y + $h;
  21600. // set alignment
  21601. if ($this->rtl) {
  21602. if ($palign == 'L') {
  21603. $xt = $this->lMargin;
  21604. } elseif ($palign == 'C') {
  21605. $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  21606. } elseif ($palign == 'R') {
  21607. $xt = $this->w - $this->rMargin - $w;
  21608. } else {
  21609. $xt = $x - $w;
  21610. }
  21611. $rb_x = $xt;
  21612. } else {
  21613. if ($palign == 'L') {
  21614. $xt = $this->lMargin;
  21615. } elseif ($palign == 'C') {
  21616. $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  21617. } elseif ($palign == 'R') {
  21618. $xt = $this->w - $this->rMargin - $w;
  21619. } else {
  21620. $xt = $x;
  21621. }
  21622. $rb_x = $xt + $w;
  21623. }
  21624. // print XObject Template + Transformation matrix
  21625. $this->StartTransform();
  21626. // translate and scale
  21627. $sx = ($w / $ow);
  21628. $sy = ($h / $oh);
  21629. $tm = array();
  21630. $tm[0] = $sx;
  21631. $tm[1] = 0;
  21632. $tm[2] = 0;
  21633. $tm[3] = $sy;
  21634. $tm[4] = $xt * $this->k;
  21635. $tm[5] = ($this->h - $h - $y) * $this->k;
  21636. $this->Transform($tm);
  21637. // set object
  21638. $this->_out('/'.$id.' Do');
  21639. $this->StopTransform();
  21640. // add annotations
  21641. if (!empty($this->xobjects[$id]['annotations'])) {
  21642. foreach ($this->xobjects[$id]['annotations'] as $annot) {
  21643. // transform original coordinates
  21644. $coordlt = TCPDF_STATIC::getTransformationMatrixProduct($tm, array(1, 0, 0, 1, ($annot['x'] * $this->k), (-$annot['y'] * $this->k)));
  21645. $ax = ($coordlt[4] / $this->k);
  21646. $ay = ($this->h - $h - ($coordlt[5] / $this->k));
  21647. $coordrb = TCPDF_STATIC::getTransformationMatrixProduct($tm, array(1, 0, 0, 1, (($annot['x'] + $annot['w']) * $this->k), ((-$annot['y'] - $annot['h']) * $this->k)));
  21648. $aw = ($coordrb[4] / $this->k) - $ax;
  21649. $ah = ($this->h - $h - ($coordrb[5] / $this->k)) - $ay;
  21650. $this->Annotation($ax, $ay, $aw, $ah, $annot['text'], $annot['opt'], $annot['spaces']);
  21651. }
  21652. }
  21653. // set pointer to align the next text/objects
  21654. switch($align) {
  21655. case 'T': {
  21656. $this->y = $y;
  21657. $this->x = $rb_x;
  21658. break;
  21659. }
  21660. case 'M': {
  21661. $this->y = $y + round($h/2);
  21662. $this->x = $rb_x;
  21663. break;
  21664. }
  21665. case 'B': {
  21666. $this->y = $rb_y;
  21667. $this->x = $rb_x;
  21668. break;
  21669. }
  21670. case 'N': {
  21671. $this->SetY($rb_y);
  21672. break;
  21673. }
  21674. default:{
  21675. break;
  21676. }
  21677. }
  21678. }
  21679. /**
  21680. * Set the percentage of character stretching.
  21681. * @param $perc (int) percentage of stretching (100 = no stretching)
  21682. * @author Nicola Asuni
  21683. * @public
  21684. * @since 5.9.000 (2010-09-29)
  21685. */
  21686. public function setFontStretching($perc=100) {
  21687. $this->font_stretching = $perc;
  21688. }
  21689. /**
  21690. * Get the percentage of character stretching.
  21691. * @return float stretching value
  21692. * @author Nicola Asuni
  21693. * @public
  21694. * @since 5.9.000 (2010-09-29)
  21695. */
  21696. public function getFontStretching() {
  21697. return $this->font_stretching;
  21698. }
  21699. /**
  21700. * Set the amount to increase or decrease the space between characters in a text.
  21701. * @param $spacing (float) amount to increase or decrease the space between characters in a text (0 = default spacing)
  21702. * @author Nicola Asuni
  21703. * @public
  21704. * @since 5.9.000 (2010-09-29)
  21705. */
  21706. public function setFontSpacing($spacing=0) {
  21707. $this->font_spacing = $spacing;
  21708. }
  21709. /**
  21710. * Get the amount to increase or decrease the space between characters in a text.
  21711. * @return int font spacing (tracking) value
  21712. * @author Nicola Asuni
  21713. * @public
  21714. * @since 5.9.000 (2010-09-29)
  21715. */
  21716. public function getFontSpacing() {
  21717. return $this->font_spacing;
  21718. }
  21719. /**
  21720. * Return an array of no-write page regions
  21721. * @return array of no-write page regions
  21722. * @author Nicola Asuni
  21723. * @public
  21724. * @since 5.9.003 (2010-10-13)
  21725. * @see setPageRegions(), addPageRegion()
  21726. */
  21727. public function getPageRegions() {
  21728. return $this->page_regions;
  21729. }
  21730. /**
  21731. * Set no-write regions on page.
  21732. * 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.
  21733. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  21734. * You can set multiple regions for the same page.
  21735. * @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.
  21736. * @author Nicola Asuni
  21737. * @public
  21738. * @since 5.9.003 (2010-10-13)
  21739. * @see addPageRegion(), getPageRegions()
  21740. */
  21741. public function setPageRegions($regions=array()) {
  21742. // empty current regions array
  21743. $this->page_regions = array();
  21744. // add regions
  21745. foreach ($regions as $data) {
  21746. $this->addPageRegion($data);
  21747. }
  21748. }
  21749. /**
  21750. * Add a single no-write region on selected page.
  21751. * 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.
  21752. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  21753. * You can set multiple regions for the same page.
  21754. * @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).
  21755. * @author Nicola Asuni
  21756. * @public
  21757. * @since 5.9.003 (2010-10-13)
  21758. * @see setPageRegions(), getPageRegions()
  21759. */
  21760. public function addPageRegion($region) {
  21761. if (!isset($region['page']) OR empty($region['page'])) {
  21762. $region['page'] = $this->page;
  21763. }
  21764. if (isset($region['xt']) AND isset($region['xb']) AND ($region['xt'] > 0) AND ($region['xb'] > 0)
  21765. AND isset($region['yt']) AND isset($region['yb']) AND ($region['yt'] >= 0) AND ($region['yt'] < $region['yb'])
  21766. AND isset($region['side']) AND (($region['side'] == 'L') OR ($region['side'] == 'R'))) {
  21767. $this->page_regions[] = $region;
  21768. }
  21769. }
  21770. /**
  21771. * Remove a single no-write region.
  21772. * @param $key (int) region key
  21773. * @author Nicola Asuni
  21774. * @public
  21775. * @since 5.9.003 (2010-10-13)
  21776. * @see setPageRegions(), getPageRegions()
  21777. */
  21778. public function removePageRegion($key) {
  21779. if (isset($this->page_regions[$key])) {
  21780. unset($this->page_regions[$key]);
  21781. }
  21782. }
  21783. /**
  21784. * Check page for no-write regions and adapt current coordinates and page margins if necessary.
  21785. * 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.
  21786. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  21787. * @param $h (float) height of the text/image/object to print in user units
  21788. * @param $x (float) current X coordinate in user units
  21789. * @param $y (float) current Y coordinate in user units
  21790. * @return array($x, $y)
  21791. * @author Nicola Asuni
  21792. * @protected
  21793. * @since 5.9.003 (2010-10-13)
  21794. */
  21795. protected function checkPageRegions($h, $x, $y) {
  21796. // set default values
  21797. if ($x === '') {
  21798. $x = $this->x;
  21799. }
  21800. if ($y === '') {
  21801. $y = $this->y;
  21802. }
  21803. if (!$this->check_page_regions OR empty($this->page_regions)) {
  21804. // no page regions defined
  21805. return array($x, $y);
  21806. }
  21807. if (empty($h)) {
  21808. $h = $this->getCellHeight($this->FontSize);
  21809. }
  21810. // check for page break
  21811. if ($this->checkPageBreak($h, $y)) {
  21812. // the content will be printed on a new page
  21813. $x = $this->x;
  21814. $y = $this->y;
  21815. }
  21816. if ($this->num_columns > 1) {
  21817. if ($this->rtl) {
  21818. $this->lMargin = ($this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']);
  21819. } else {
  21820. $this->rMargin = ($this->w - $this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']);
  21821. }
  21822. } else {
  21823. if ($this->rtl) {
  21824. $this->lMargin = max($this->clMargin, $this->original_lMargin);
  21825. } else {
  21826. $this->rMargin = max($this->crMargin, $this->original_rMargin);
  21827. }
  21828. }
  21829. // adjust coordinates and page margins
  21830. foreach ($this->page_regions as $regid => $regdata) {
  21831. if ($regdata['page'] == $this->page) {
  21832. // check region boundaries
  21833. if (($y > ($regdata['yt'] - $h)) AND ($y <= $regdata['yb'])) {
  21834. // Y is inside the region
  21835. $minv = ($regdata['xb'] - $regdata['xt']) / ($regdata['yb'] - $regdata['yt']); // inverse of angular coefficient
  21836. $yt = max($y, $regdata['yt']);
  21837. $yb = min(($yt + $h), $regdata['yb']);
  21838. $xt = (($yt - $regdata['yt']) * $minv) + $regdata['xt'];
  21839. $xb = (($yb - $regdata['yt']) * $minv) + $regdata['xt'];
  21840. if ($regdata['side'] == 'L') { // left side
  21841. $new_margin = max($xt, $xb);
  21842. if ($this->lMargin < $new_margin) {
  21843. if ($this->rtl) {
  21844. // adjust left page margin
  21845. $this->lMargin = max(0, $new_margin);
  21846. }
  21847. if ($x < $new_margin) {
  21848. // adjust x position
  21849. $x = $new_margin;
  21850. if ($new_margin > ($this->w - $this->rMargin)) {
  21851. // adjust y position
  21852. $y = $regdata['yb'] - $h;
  21853. }
  21854. }
  21855. }
  21856. } elseif ($regdata['side'] == 'R') { // right side
  21857. $new_margin = min($xt, $xb);
  21858. if (($this->w - $this->rMargin) > $new_margin) {
  21859. if (!$this->rtl) {
  21860. // adjust right page margin
  21861. $this->rMargin = max(0, ($this->w - $new_margin));
  21862. }
  21863. if ($x > $new_margin) {
  21864. // adjust x position
  21865. $x = $new_margin;
  21866. if ($new_margin > $this->lMargin) {
  21867. // adjust y position
  21868. $y = $regdata['yb'] - $h;
  21869. }
  21870. }
  21871. }
  21872. }
  21873. }
  21874. }
  21875. }
  21876. return array($x, $y);
  21877. }
  21878. // --- SVG METHODS ---------------------------------------------------------
  21879. /**
  21880. * Embedd a Scalable Vector Graphics (SVG) image.
  21881. * NOTE: SVG standard is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  21882. * @param $file (string) Name of the SVG file or a '@' character followed by the SVG data string.
  21883. * @param $x (float) Abscissa of the upper-left corner.
  21884. * @param $y (float) Ordinate of the upper-left corner.
  21885. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  21886. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  21887. * @param $link (mixed) URL or identifier returned by AddLink().
  21888. * @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.
  21889. * @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>
  21890. * @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)))
  21891. * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
  21892. * @author Nicola Asuni
  21893. * @since 5.0.000 (2010-05-02)
  21894. * @public
  21895. */
  21896. public function ImageSVG($file, $x='', $y='', $w=0, $h=0, $link='', $align='', $palign='', $border=0, $fitonpage=false) {
  21897. if ($this->state != 2) {
  21898. return;
  21899. }
  21900. // reseet SVG vars
  21901. $this->svggradients = array();
  21902. $this->svggradientid = 0;
  21903. $this->svgdefsmode = false;
  21904. $this->svgdefs = array();
  21905. $this->svgclipmode = false;
  21906. $this->svgclippaths = array();
  21907. $this->svgcliptm = array();
  21908. $this->svgclipid = 0;
  21909. $this->svgtext = '';
  21910. $this->svgtextmode = array();
  21911. if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
  21912. // convert SVG to raster image using GD or ImageMagick libraries
  21913. return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
  21914. }
  21915. if ($file{0} === '@') { // image from string
  21916. $this->svgdir = '';
  21917. $svgdata = substr($file, 1);
  21918. } else { // SVG file
  21919. $this->svgdir = dirname($file);
  21920. $svgdata = TCPDF_STATIC::fileGetContents($file);
  21921. }
  21922. if ($svgdata === FALSE) {
  21923. $this->Error('SVG file not found: '.$file);
  21924. }
  21925. if ($x === '') {
  21926. $x = $this->x;
  21927. }
  21928. if ($y === '') {
  21929. $y = $this->y;
  21930. }
  21931. // check page for no-write regions and adapt page margins if necessary
  21932. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  21933. $k = $this->k;
  21934. $ox = 0;
  21935. $oy = 0;
  21936. $ow = $w;
  21937. $oh = $h;
  21938. $aspect_ratio_align = 'xMidYMid';
  21939. $aspect_ratio_ms = 'meet';
  21940. $regs = array();
  21941. // get original image width and height
  21942. preg_match('/<svg([^\>]*)>/si', $svgdata, $regs);
  21943. if (isset($regs[1]) AND !empty($regs[1])) {
  21944. $tmp = array();
  21945. if (preg_match('/[\s]+x[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  21946. $ox = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
  21947. }
  21948. $tmp = array();
  21949. if (preg_match('/[\s]+y[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  21950. $oy = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
  21951. }
  21952. $tmp = array();
  21953. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  21954. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  21955. }
  21956. $tmp = array();
  21957. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  21958. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  21959. }
  21960. $tmp = array();
  21961. $view_box = array();
  21962. if (preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.\-]+)[\s]+([0-9\.\-]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $regs[1], $tmp)) {
  21963. if (count($tmp) == 5) {
  21964. array_shift($tmp);
  21965. foreach ($tmp as $key => $val) {
  21966. $view_box[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
  21967. }
  21968. $ox = $view_box[0];
  21969. $oy = $view_box[1];
  21970. }
  21971. // get aspect ratio
  21972. $tmp = array();
  21973. if (preg_match('/[\s]+preserveAspectRatio[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  21974. $aspect_ratio = preg_split('/[\s]+/si', $tmp[1]);
  21975. switch (count($aspect_ratio)) {
  21976. case 3: {
  21977. $aspect_ratio_align = $aspect_ratio[1];
  21978. $aspect_ratio_ms = $aspect_ratio[2];
  21979. break;
  21980. }
  21981. case 2: {
  21982. $aspect_ratio_align = $aspect_ratio[0];
  21983. $aspect_ratio_ms = $aspect_ratio[1];
  21984. break;
  21985. }
  21986. case 1: {
  21987. $aspect_ratio_align = $aspect_ratio[0];
  21988. $aspect_ratio_ms = 'meet';
  21989. break;
  21990. }
  21991. }
  21992. }
  21993. }
  21994. }
  21995. if ($ow <= 0) {
  21996. $ow = 1;
  21997. }
  21998. if ($oh <= 0) {
  21999. $oh = 1;
  22000. }
  22001. // calculate image width and height on document
  22002. if (($w <= 0) AND ($h <= 0)) {
  22003. // convert image size to document unit
  22004. $w = $ow;
  22005. $h = $oh;
  22006. } elseif ($w <= 0) {
  22007. $w = $h * $ow / $oh;
  22008. } elseif ($h <= 0) {
  22009. $h = $w * $oh / $ow;
  22010. }
  22011. // fit the image on available space
  22012. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  22013. if ($this->rasterize_vector_images) {
  22014. // convert SVG to raster image using GD or ImageMagick libraries
  22015. return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
  22016. }
  22017. // set alignment
  22018. $this->img_rb_y = $y + $h;
  22019. // set alignment
  22020. if ($this->rtl) {
  22021. if ($palign == 'L') {
  22022. $ximg = $this->lMargin;
  22023. } elseif ($palign == 'C') {
  22024. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  22025. } elseif ($palign == 'R') {
  22026. $ximg = $this->w - $this->rMargin - $w;
  22027. } else {
  22028. $ximg = $x - $w;
  22029. }
  22030. $this->img_rb_x = $ximg;
  22031. } else {
  22032. if ($palign == 'L') {
  22033. $ximg = $this->lMargin;
  22034. } elseif ($palign == 'C') {
  22035. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  22036. } elseif ($palign == 'R') {
  22037. $ximg = $this->w - $this->rMargin - $w;
  22038. } else {
  22039. $ximg = $x;
  22040. }
  22041. $this->img_rb_x = $ximg + $w;
  22042. }
  22043. // store current graphic vars
  22044. $gvars = $this->getGraphicVars();
  22045. // store SVG position and scale factors
  22046. $svgoffset_x = ($ximg - $ox) * $this->k;
  22047. $svgoffset_y = -($y - $oy) * $this->k;
  22048. if (isset($view_box[2]) AND ($view_box[2] > 0) AND ($view_box[3] > 0)) {
  22049. $ow = $view_box[2];
  22050. $oh = $view_box[3];
  22051. } else {
  22052. if ($ow <= 0) {
  22053. $ow = $w;
  22054. }
  22055. if ($oh <= 0) {
  22056. $oh = $h;
  22057. }
  22058. }
  22059. $svgscale_x = $w / $ow;
  22060. $svgscale_y = $h / $oh;
  22061. // scaling and alignment
  22062. if ($aspect_ratio_align != 'none') {
  22063. // store current scaling values
  22064. $svgscale_old_x = $svgscale_x;
  22065. $svgscale_old_y = $svgscale_y;
  22066. // force uniform scaling
  22067. if ($aspect_ratio_ms == 'slice') {
  22068. // the entire viewport is covered by the viewBox
  22069. if ($svgscale_x > $svgscale_y) {
  22070. $svgscale_y = $svgscale_x;
  22071. } elseif ($svgscale_x < $svgscale_y) {
  22072. $svgscale_x = $svgscale_y;
  22073. }
  22074. } else { // meet
  22075. // the entire viewBox is visible within the viewport
  22076. if ($svgscale_x < $svgscale_y) {
  22077. $svgscale_y = $svgscale_x;
  22078. } elseif ($svgscale_x > $svgscale_y) {
  22079. $svgscale_x = $svgscale_y;
  22080. }
  22081. }
  22082. // correct X alignment
  22083. switch (substr($aspect_ratio_align, 1, 3)) {
  22084. case 'Min': {
  22085. // do nothing
  22086. break;
  22087. }
  22088. case 'Max': {
  22089. $svgoffset_x += (($w * $this->k) - ($ow * $this->k * $svgscale_x));
  22090. break;
  22091. }
  22092. default:
  22093. case 'Mid': {
  22094. $svgoffset_x += ((($w * $this->k) - ($ow * $this->k * $svgscale_x)) / 2);
  22095. break;
  22096. }
  22097. }
  22098. // correct Y alignment
  22099. switch (substr($aspect_ratio_align, 5)) {
  22100. case 'Min': {
  22101. // do nothing
  22102. break;
  22103. }
  22104. case 'Max': {
  22105. $svgoffset_y -= (($h * $this->k) - ($oh * $this->k * $svgscale_y));
  22106. break;
  22107. }
  22108. default:
  22109. case 'Mid': {
  22110. $svgoffset_y -= ((($h * $this->k) - ($oh * $this->k * $svgscale_y)) / 2);
  22111. break;
  22112. }
  22113. }
  22114. }
  22115. // store current page break mode
  22116. $page_break_mode = $this->AutoPageBreak;
  22117. $page_break_margin = $this->getBreakMargin();
  22118. $cell_padding = $this->cell_padding;
  22119. $this->SetCellPadding(0);
  22120. $this->SetAutoPageBreak(false);
  22121. // save the current graphic state
  22122. $this->_out('q'.$this->epsmarker);
  22123. // set initial clipping mask
  22124. $this->Rect($x, $y, $w, $h, 'CNZ', array(), array());
  22125. // scale and translate
  22126. $e = $ox * $this->k * (1 - $svgscale_x);
  22127. $f = ($this->h - $oy) * $this->k * (1 - $svgscale_y);
  22128. $this->_out(sprintf('%F %F %F %F %F %F cm', $svgscale_x, 0, 0, $svgscale_y, ($e + $svgoffset_x), ($f + $svgoffset_y)));
  22129. // creates a new XML parser to be used by the other XML functions
  22130. $this->parser = xml_parser_create('UTF-8');
  22131. // the following function allows to use parser inside object
  22132. xml_set_object($this->parser, $this);
  22133. // disable case-folding for this XML parser
  22134. xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
  22135. // sets the element handler functions for the XML parser
  22136. xml_set_element_handler($this->parser, 'startSVGElementHandler', 'endSVGElementHandler');
  22137. // sets the character data handler function for the XML parser
  22138. xml_set_character_data_handler($this->parser, 'segSVGContentHandler');
  22139. // start parsing an XML document
  22140. if (!xml_parse($this->parser, $svgdata)) {
  22141. $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));
  22142. $this->Error($error_message);
  22143. }
  22144. // free this XML parser
  22145. xml_parser_free($this->parser);
  22146. // restore previous graphic state
  22147. $this->_out($this->epsmarker.'Q');
  22148. // restore graphic vars
  22149. $this->setGraphicVars($gvars);
  22150. $this->lasth = $gvars['lasth'];
  22151. if (!empty($border)) {
  22152. $bx = $this->x;
  22153. $by = $this->y;
  22154. $this->x = $ximg;
  22155. if ($this->rtl) {
  22156. $this->x += $w;
  22157. }
  22158. $this->y = $y;
  22159. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  22160. $this->x = $bx;
  22161. $this->y = $by;
  22162. }
  22163. if ($link) {
  22164. $this->Link($ximg, $y, $w, $h, $link, 0);
  22165. }
  22166. // set pointer to align the next text/objects
  22167. switch($align) {
  22168. case 'T':{
  22169. $this->y = $y;
  22170. $this->x = $this->img_rb_x;
  22171. break;
  22172. }
  22173. case 'M':{
  22174. $this->y = $y + round($h/2);
  22175. $this->x = $this->img_rb_x;
  22176. break;
  22177. }
  22178. case 'B':{
  22179. $this->y = $this->img_rb_y;
  22180. $this->x = $this->img_rb_x;
  22181. break;
  22182. }
  22183. case 'N':{
  22184. $this->SetY($this->img_rb_y);
  22185. break;
  22186. }
  22187. default:{
  22188. // restore pointer to starting position
  22189. $this->x = $gvars['x'];
  22190. $this->y = $gvars['y'];
  22191. $this->page = $gvars['page'];
  22192. $this->current_column = $gvars['current_column'];
  22193. $this->tMargin = $gvars['tMargin'];
  22194. $this->bMargin = $gvars['bMargin'];
  22195. $this->w = $gvars['w'];
  22196. $this->h = $gvars['h'];
  22197. $this->wPt = $gvars['wPt'];
  22198. $this->hPt = $gvars['hPt'];
  22199. $this->fwPt = $gvars['fwPt'];
  22200. $this->fhPt = $gvars['fhPt'];
  22201. break;
  22202. }
  22203. }
  22204. $this->endlinex = $this->img_rb_x;
  22205. // restore page break
  22206. $this->SetAutoPageBreak($page_break_mode, $page_break_margin);
  22207. $this->cell_padding = $cell_padding;
  22208. }
  22209. /**
  22210. * Convert SVG transformation matrix to PDF.
  22211. * @param $tm (array) original SVG transformation matrix
  22212. * @return array transformation matrix
  22213. * @protected
  22214. * @since 5.0.000 (2010-05-02)
  22215. */
  22216. protected function convertSVGtMatrix($tm) {
  22217. $a = $tm[0];
  22218. $b = -$tm[1];
  22219. $c = -$tm[2];
  22220. $d = $tm[3];
  22221. $e = $this->getHTMLUnitToUnits($tm[4], 1, $this->svgunit, false) * $this->k;
  22222. $f = -$this->getHTMLUnitToUnits($tm[5], 1, $this->svgunit, false) * $this->k;
  22223. $x = 0;
  22224. $y = $this->h * $this->k;
  22225. $e = ($x * (1 - $a)) - ($y * $c) + $e;
  22226. $f = ($y * (1 - $d)) - ($x * $b) + $f;
  22227. return array($a, $b, $c, $d, $e, $f);
  22228. }
  22229. /**
  22230. * Apply SVG graphic transformation matrix.
  22231. * @param $tm (array) original SVG transformation matrix
  22232. * @protected
  22233. * @since 5.0.000 (2010-05-02)
  22234. */
  22235. protected function SVGTransform($tm) {
  22236. $this->Transform($this->convertSVGtMatrix($tm));
  22237. }
  22238. /**
  22239. * Apply the requested SVG styles (*** TO BE COMPLETED ***)
  22240. * @param $svgstyle (array) array of SVG styles to apply
  22241. * @param $prevsvgstyle (array) array of previous SVG style
  22242. * @param $x (int) X origin of the bounding box
  22243. * @param $y (int) Y origin of the bounding box
  22244. * @param $w (int) width of the bounding box
  22245. * @param $h (int) height of the bounding box
  22246. * @param $clip_function (string) clip function
  22247. * @param $clip_params (array) array of parameters for clipping function
  22248. * @return object style
  22249. * @author Nicola Asuni
  22250. * @since 5.0.000 (2010-05-02)
  22251. * @protected
  22252. */
  22253. protected function setSVGStyles($svgstyle, $prevsvgstyle, $x=0, $y=0, $w=1, $h=1, $clip_function='', $clip_params=array()) {
  22254. if ($this->state != 2) {
  22255. return;
  22256. }
  22257. $objstyle = '';
  22258. $minlen = (0.01 / $this->k); // minimum acceptable length (3 point)
  22259. if (!isset($svgstyle['opacity'])) {
  22260. return $objstyle;
  22261. }
  22262. // clip-path
  22263. $regs = array();
  22264. if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['clip-path'], $regs)) {
  22265. $clip_path = $this->svgclippaths[$regs[1]];
  22266. foreach ($clip_path as $cp) {
  22267. $this->startSVGElementHandler('clip-path', $cp['name'], $cp['attribs'], $cp['tm']);
  22268. }
  22269. }
  22270. // opacity
  22271. if ($svgstyle['opacity'] != 1) {
  22272. $this->setAlpha($svgstyle['opacity'], 'Normal', $svgstyle['opacity'], false);
  22273. }
  22274. // color
  22275. $fill_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['color'], $this->spot_colors);
  22276. $this->SetFillColorArray($fill_color);
  22277. // text color
  22278. $text_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['text-color'], $this->spot_colors);
  22279. $this->SetTextColorArray($text_color);
  22280. // clip
  22281. if (preg_match('/rect\(([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)\)/si', $svgstyle['clip'], $regs)) {
  22282. $top = (isset($regs[1])?$this->getHTMLUnitToUnits($regs[1], 0, $this->svgunit, false):0);
  22283. $right = (isset($regs[2])?$this->getHTMLUnitToUnits($regs[2], 0, $this->svgunit, false):0);
  22284. $bottom = (isset($regs[3])?$this->getHTMLUnitToUnits($regs[3], 0, $this->svgunit, false):0);
  22285. $left = (isset($regs[4])?$this->getHTMLUnitToUnits($regs[4], 0, $this->svgunit, false):0);
  22286. $cx = $x + $left;
  22287. $cy = $y + $top;
  22288. $cw = $w - $left - $right;
  22289. $ch = $h - $top - $bottom;
  22290. if ($svgstyle['clip-rule'] == 'evenodd') {
  22291. $clip_rule = 'CNZ';
  22292. } else {
  22293. $clip_rule = 'CEO';
  22294. }
  22295. $this->Rect($cx, $cy, $cw, $ch, $clip_rule, array(), array());
  22296. }
  22297. // fill
  22298. $regs = array();
  22299. if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['fill'], $regs)) {
  22300. // gradient
  22301. $gradient = $this->svggradients[$regs[1]];
  22302. if (isset($gradient['xref'])) {
  22303. // reference to another gradient definition
  22304. $newgradient = $this->svggradients[$gradient['xref']];
  22305. $newgradient['coords'] = $gradient['coords'];
  22306. $newgradient['mode'] = $gradient['mode'];
  22307. $newgradient['gradientUnits'] = $gradient['gradientUnits'];
  22308. if (isset($gradient['gradientTransform'])) {
  22309. $newgradient['gradientTransform'] = $gradient['gradientTransform'];
  22310. }
  22311. $gradient = $newgradient;
  22312. }
  22313. //save current Graphic State
  22314. $this->_out('q');
  22315. //set clipping area
  22316. if (!empty($clip_function) AND method_exists($this, $clip_function)) {
  22317. $bbox = call_user_func_array(array($this, $clip_function), $clip_params);
  22318. if (is_array($bbox) AND (count($bbox) == 4)) {
  22319. list($x, $y, $w, $h) = $bbox;
  22320. }
  22321. }
  22322. if ($gradient['mode'] == 'measure') {
  22323. if (isset($gradient['gradientTransform']) AND !empty($gradient['gradientTransform'])) {
  22324. $gtm = $gradient['gradientTransform'];
  22325. // apply transformation matrix
  22326. $xa = ($gtm[0] * $gradient['coords'][0]) + ($gtm[2] * $gradient['coords'][1]) + $gtm[4];
  22327. $ya = ($gtm[1] * $gradient['coords'][0]) + ($gtm[3] * $gradient['coords'][1]) + $gtm[5];
  22328. $xb = ($gtm[0] * $gradient['coords'][2]) + ($gtm[2] * $gradient['coords'][3]) + $gtm[4];
  22329. $yb = ($gtm[1] * $gradient['coords'][2]) + ($gtm[3] * $gradient['coords'][3]) + $gtm[5];
  22330. if (isset($gradient['coords'][4])) {
  22331. $gradient['coords'][4] = sqrt(pow(($gtm[0] * $gradient['coords'][4]), 2) + pow(($gtm[1] * $gradient['coords'][4]), 2));
  22332. }
  22333. $gradient['coords'][0] = $xa;
  22334. $gradient['coords'][1] = $ya;
  22335. $gradient['coords'][2] = $xb;
  22336. $gradient['coords'][3] = $yb;
  22337. }
  22338. // convert SVG coordinates to user units
  22339. $gradient['coords'][0] = $this->getHTMLUnitToUnits($gradient['coords'][0], 0, $this->svgunit, false);
  22340. $gradient['coords'][1] = $this->getHTMLUnitToUnits($gradient['coords'][1], 0, $this->svgunit, false);
  22341. $gradient['coords'][2] = $this->getHTMLUnitToUnits($gradient['coords'][2], 0, $this->svgunit, false);
  22342. $gradient['coords'][3] = $this->getHTMLUnitToUnits($gradient['coords'][3], 0, $this->svgunit, false);
  22343. if (isset($gradient['coords'][4])) {
  22344. $gradient['coords'][4] = $this->getHTMLUnitToUnits($gradient['coords'][4], 0, $this->svgunit, false);
  22345. }
  22346. if ($w <= $minlen) {
  22347. $w = $minlen;
  22348. }
  22349. if ($h <= $minlen) {
  22350. $h = $minlen;
  22351. }
  22352. // shift units
  22353. if ($gradient['gradientUnits'] == 'objectBoundingBox') {
  22354. // convert to SVG coordinate system
  22355. $gradient['coords'][0] += $x;
  22356. $gradient['coords'][1] += $y;
  22357. $gradient['coords'][2] += $x;
  22358. $gradient['coords'][3] += $y;
  22359. }
  22360. // calculate percentages
  22361. $gradient['coords'][0] = (($gradient['coords'][0] - $x) / $w);
  22362. $gradient['coords'][1] = (($gradient['coords'][1] - $y) / $h);
  22363. $gradient['coords'][2] = (($gradient['coords'][2] - $x) / $w);
  22364. $gradient['coords'][3] = (($gradient['coords'][3] - $y) / $h);
  22365. if (isset($gradient['coords'][4])) {
  22366. $gradient['coords'][4] /= $w;
  22367. }
  22368. } elseif ($gradient['mode'] == 'percentage') {
  22369. foreach($gradient['coords'] as $key => $val) {
  22370. $gradient['coords'][$key] = (intval($val) / 100);
  22371. if ($val < 0) {
  22372. $gradient['coords'][$key] = 0;
  22373. } elseif ($val > 1) {
  22374. $gradient['coords'][$key] = 1;
  22375. }
  22376. }
  22377. }
  22378. if (($gradient['type'] == 2) AND ($gradient['coords'][0] == $gradient['coords'][2]) AND ($gradient['coords'][1] == $gradient['coords'][3])) {
  22379. // single color (no shading)
  22380. $gradient['coords'][0] = 1;
  22381. $gradient['coords'][1] = 0;
  22382. $gradient['coords'][2] = 0.999;
  22383. $gradient['coords'][3] = 0;
  22384. }
  22385. // swap Y coordinates
  22386. $tmp = $gradient['coords'][1];
  22387. $gradient['coords'][1] = $gradient['coords'][3];
  22388. $gradient['coords'][3] = $tmp;
  22389. // set transformation map for gradient
  22390. if ($gradient['type'] == 3) {
  22391. // circular gradient
  22392. $cy = $this->h - $y - ($gradient['coords'][1] * ($w + $h));
  22393. $this->_out(sprintf('%F 0 0 %F %F %F cm', ($w * $this->k), ($w * $this->k), ($x * $this->k), ($cy * $this->k)));
  22394. } else {
  22395. $this->_out(sprintf('%F 0 0 %F %F %F cm', ($w * $this->k), ($h * $this->k), ($x * $this->k), (($this->h - ($y + $h)) * $this->k)));
  22396. }
  22397. if (count($gradient['stops']) > 1) {
  22398. $this->Gradient($gradient['type'], $gradient['coords'], $gradient['stops'], array(), false);
  22399. }
  22400. } elseif ($svgstyle['fill'] != 'none') {
  22401. $fill_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['fill'], $this->spot_colors);
  22402. if ($svgstyle['fill-opacity'] != 1) {
  22403. $this->setAlpha($this->alpha['CA'], 'Normal', $svgstyle['fill-opacity'], false);
  22404. }
  22405. $this->SetFillColorArray($fill_color);
  22406. if ($svgstyle['fill-rule'] == 'evenodd') {
  22407. $objstyle .= 'F*';
  22408. } else {
  22409. $objstyle .= 'F';
  22410. }
  22411. }
  22412. // stroke
  22413. if ($svgstyle['stroke'] != 'none') {
  22414. if ($svgstyle['stroke-opacity'] != 1) {
  22415. $this->setAlpha($svgstyle['stroke-opacity'], 'Normal', $this->alpha['ca'], false);
  22416. }
  22417. $stroke_style = array(
  22418. 'color' => TCPDF_COLORS::convertHTMLColorToDec($svgstyle['stroke'], $this->spot_colors),
  22419. 'width' => $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false),
  22420. 'cap' => $svgstyle['stroke-linecap'],
  22421. 'join' => $svgstyle['stroke-linejoin']
  22422. );
  22423. if (isset($svgstyle['stroke-dasharray']) AND !empty($svgstyle['stroke-dasharray']) AND ($svgstyle['stroke-dasharray'] != 'none')) {
  22424. $stroke_style['dash'] = $svgstyle['stroke-dasharray'];
  22425. }
  22426. $this->SetLineStyle($stroke_style);
  22427. $objstyle .= 'D';
  22428. }
  22429. // font
  22430. $regs = array();
  22431. if (!empty($svgstyle['font'])) {
  22432. if (preg_match('/font-family[\s]*:[\s]*([^\;\"]*)/si', $svgstyle['font'], $regs)) {
  22433. $font_family = $this->getFontFamilyName($regs[1]);
  22434. } else {
  22435. $font_family = $svgstyle['font-family'];
  22436. }
  22437. if (preg_match('/font-size[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22438. $font_size = trim($regs[1]);
  22439. } else {
  22440. $font_size = $svgstyle['font-size'];
  22441. }
  22442. if (preg_match('/font-style[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22443. $font_style = trim($regs[1]);
  22444. } else {
  22445. $font_style = $svgstyle['font-style'];
  22446. }
  22447. if (preg_match('/font-weight[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22448. $font_weight = trim($regs[1]);
  22449. } else {
  22450. $font_weight = $svgstyle['font-weight'];
  22451. }
  22452. if (preg_match('/font-stretch[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22453. $font_stretch = trim($regs[1]);
  22454. } else {
  22455. $font_stretch = $svgstyle['font-stretch'];
  22456. }
  22457. if (preg_match('/letter-spacing[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22458. $font_spacing = trim($regs[1]);
  22459. } else {
  22460. $font_spacing = $svgstyle['letter-spacing'];
  22461. }
  22462. } else {
  22463. $font_family = $this->getFontFamilyName($svgstyle['font-family']);
  22464. $font_size = $svgstyle['font-size'];
  22465. $font_style = $svgstyle['font-style'];
  22466. $font_weight = $svgstyle['font-weight'];
  22467. $font_stretch = $svgstyle['font-stretch'];
  22468. $font_spacing = $svgstyle['letter-spacing'];
  22469. }
  22470. $font_size = $this->getHTMLFontUnits($font_size, $this->svgstyles[0]['font-size'], $prevsvgstyle['font-size'], $this->svgunit);
  22471. $font_stretch = $this->getCSSFontStretching($font_stretch, $svgstyle['font-stretch']);
  22472. $font_spacing = $this->getCSSFontSpacing($font_spacing, $svgstyle['letter-spacing']);
  22473. switch ($font_style) {
  22474. case 'italic': {
  22475. $font_style = 'I';
  22476. break;
  22477. }
  22478. case 'oblique': {
  22479. $font_style = 'I';
  22480. break;
  22481. }
  22482. default:
  22483. case 'normal': {
  22484. $font_style = '';
  22485. break;
  22486. }
  22487. }
  22488. switch ($font_weight) {
  22489. case 'bold':
  22490. case 'bolder': {
  22491. $font_style .= 'B';
  22492. break;
  22493. }
  22494. }
  22495. switch ($svgstyle['text-decoration']) {
  22496. case 'underline': {
  22497. $font_style .= 'U';
  22498. break;
  22499. }
  22500. case 'overline': {
  22501. $font_style .= 'O';
  22502. break;
  22503. }
  22504. case 'line-through': {
  22505. $font_style .= 'D';
  22506. break;
  22507. }
  22508. default:
  22509. case 'none': {
  22510. break;
  22511. }
  22512. }
  22513. $this->SetFont($font_family, $font_style, $font_size);
  22514. $this->setFontStretching($font_stretch);
  22515. $this->setFontSpacing($font_spacing);
  22516. return $objstyle;
  22517. }
  22518. /**
  22519. * Draws an SVG path
  22520. * @param $d (string) attribute d of the path SVG element
  22521. * @param $style (string) Style of rendering. Possible values are:
  22522. * <ul>
  22523. * <li>D or empty string: Draw (default).</li>
  22524. * <li>F: Fill.</li>
  22525. * <li>F*: Fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  22526. * <li>DF or FD: Draw and fill.</li>
  22527. * <li>DF* or FD*: Draw and fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  22528. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  22529. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  22530. * </ul>
  22531. * @return array of container box measures (x, y, w, h)
  22532. * @author Nicola Asuni
  22533. * @since 5.0.000 (2010-05-02)
  22534. * @protected
  22535. */
  22536. protected function SVGPath($d, $style='') {
  22537. if ($this->state != 2) {
  22538. return;
  22539. }
  22540. // set fill/stroke style
  22541. $op = TCPDF_STATIC::getPathPaintOperator($style, '');
  22542. if (empty($op)) {
  22543. return;
  22544. }
  22545. $paths = array();
  22546. $d = preg_replace('/([0-9ACHLMQSTVZ])([\-\+])/si', '\\1 \\2', $d);
  22547. preg_match_all('/([ACHLMQSTVZ])[\s]*([^ACHLMQSTVZ\"]*)/si', $d, $paths, PREG_SET_ORDER);
  22548. $x = 0;
  22549. $y = 0;
  22550. $x1 = 0;
  22551. $y1 = 0;
  22552. $x2 = 0;
  22553. $y2 = 0;
  22554. $xmin = 2147483647;
  22555. $xmax = 0;
  22556. $ymin = 2147483647;
  22557. $ymax = 0;
  22558. $relcoord = false;
  22559. $minlen = (0.01 / $this->k); // minimum acceptable length (3 point)
  22560. $firstcmd = true; // used to print first point
  22561. // draw curve pieces
  22562. foreach ($paths as $key => $val) {
  22563. // get curve type
  22564. $cmd = trim($val[1]);
  22565. if (strtolower($cmd) == $cmd) {
  22566. // use relative coordinated instead of absolute
  22567. $relcoord = true;
  22568. $xoffset = $x;
  22569. $yoffset = $y;
  22570. } else {
  22571. $relcoord = false;
  22572. $xoffset = 0;
  22573. $yoffset = 0;
  22574. }
  22575. $params = array();
  22576. if (isset($val[2])) {
  22577. // get curve parameters
  22578. $rawparams = preg_split('/([\,\s]+)/si', trim($val[2]));
  22579. $params = array();
  22580. foreach ($rawparams as $ck => $cp) {
  22581. $params[$ck] = $this->getHTMLUnitToUnits($cp, 0, $this->svgunit, false);
  22582. if (abs($params[$ck]) < $minlen) {
  22583. // aproximate little values to zero
  22584. $params[$ck] = 0;
  22585. }
  22586. }
  22587. }
  22588. // store current origin point
  22589. $x0 = $x;
  22590. $y0 = $y;
  22591. switch (strtoupper($cmd)) {
  22592. case 'M': { // moveto
  22593. foreach ($params as $ck => $cp) {
  22594. if (($ck % 2) == 0) {
  22595. $x = $cp + $xoffset;
  22596. } else {
  22597. $y = $cp + $yoffset;
  22598. if ($firstcmd OR (abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  22599. if ($ck == 1) {
  22600. $this->_outPoint($x, $y);
  22601. $firstcmd = false;
  22602. } else {
  22603. $this->_outLine($x, $y);
  22604. }
  22605. $x0 = $x;
  22606. $y0 = $y;
  22607. }
  22608. $xmin = min($xmin, $x);
  22609. $ymin = min($ymin, $y);
  22610. $xmax = max($xmax, $x);
  22611. $ymax = max($ymax, $y);
  22612. if ($relcoord) {
  22613. $xoffset = $x;
  22614. $yoffset = $y;
  22615. }
  22616. }
  22617. }
  22618. break;
  22619. }
  22620. case 'L': { // lineto
  22621. foreach ($params as $ck => $cp) {
  22622. if (($ck % 2) == 0) {
  22623. $x = $cp + $xoffset;
  22624. } else {
  22625. $y = $cp + $yoffset;
  22626. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  22627. $this->_outLine($x, $y);
  22628. $x0 = $x;
  22629. $y0 = $y;
  22630. }
  22631. $xmin = min($xmin, $x);
  22632. $ymin = min($ymin, $y);
  22633. $xmax = max($xmax, $x);
  22634. $ymax = max($ymax, $y);
  22635. if ($relcoord) {
  22636. $xoffset = $x;
  22637. $yoffset = $y;
  22638. }
  22639. }
  22640. }
  22641. break;
  22642. }
  22643. case 'H': { // horizontal lineto
  22644. foreach ($params as $ck => $cp) {
  22645. $x = $cp + $xoffset;
  22646. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  22647. $this->_outLine($x, $y);
  22648. $x0 = $x;
  22649. $y0 = $y;
  22650. }
  22651. $xmin = min($xmin, $x);
  22652. $xmax = max($xmax, $x);
  22653. if ($relcoord) {
  22654. $xoffset = $x;
  22655. }
  22656. }
  22657. break;
  22658. }
  22659. case 'V': { // vertical lineto
  22660. foreach ($params as $ck => $cp) {
  22661. $y = $cp + $yoffset;
  22662. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  22663. $this->_outLine($x, $y);
  22664. $x0 = $x;
  22665. $y0 = $y;
  22666. }
  22667. $ymin = min($ymin, $y);
  22668. $ymax = max($ymax, $y);
  22669. if ($relcoord) {
  22670. $yoffset = $y;
  22671. }
  22672. }
  22673. break;
  22674. }
  22675. case 'C': { // curveto
  22676. foreach ($params as $ck => $cp) {
  22677. $params[$ck] = $cp;
  22678. if ((($ck + 1) % 6) == 0) {
  22679. $x1 = $params[($ck - 5)] + $xoffset;
  22680. $y1 = $params[($ck - 4)] + $yoffset;
  22681. $x2 = $params[($ck - 3)] + $xoffset;
  22682. $y2 = $params[($ck - 2)] + $yoffset;
  22683. $x = $params[($ck - 1)] + $xoffset;
  22684. $y = $params[($ck)] + $yoffset;
  22685. $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
  22686. $xmin = min($xmin, $x, $x1, $x2);
  22687. $ymin = min($ymin, $y, $y1, $y2);
  22688. $xmax = max($xmax, $x, $x1, $x2);
  22689. $ymax = max($ymax, $y, $y1, $y2);
  22690. if ($relcoord) {
  22691. $xoffset = $x;
  22692. $yoffset = $y;
  22693. }
  22694. }
  22695. }
  22696. break;
  22697. }
  22698. case 'S': { // shorthand/smooth curveto
  22699. foreach ($params as $ck => $cp) {
  22700. $params[$ck] = $cp;
  22701. if ((($ck + 1) % 4) == 0) {
  22702. if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'C') OR (strtoupper($paths[($key - 1)][1]) == 'S'))) {
  22703. $x1 = (2 * $x) - $x2;
  22704. $y1 = (2 * $y) - $y2;
  22705. } else {
  22706. $x1 = $x;
  22707. $y1 = $y;
  22708. }
  22709. $x2 = $params[($ck - 3)] + $xoffset;
  22710. $y2 = $params[($ck - 2)] + $yoffset;
  22711. $x = $params[($ck - 1)] + $xoffset;
  22712. $y = $params[($ck)] + $yoffset;
  22713. $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
  22714. $xmin = min($xmin, $x, $x1, $x2);
  22715. $ymin = min($ymin, $y, $y1, $y2);
  22716. $xmax = max($xmax, $x, $x1, $x2);
  22717. $ymax = max($ymax, $y, $y1, $y2);
  22718. if ($relcoord) {
  22719. $xoffset = $x;
  22720. $yoffset = $y;
  22721. }
  22722. }
  22723. }
  22724. break;
  22725. }
  22726. case 'Q': { // quadratic B\E9zier curveto
  22727. foreach ($params as $ck => $cp) {
  22728. $params[$ck] = $cp;
  22729. if ((($ck + 1) % 4) == 0) {
  22730. // convert quadratic points to cubic points
  22731. $x1 = $params[($ck - 3)] + $xoffset;
  22732. $y1 = $params[($ck - 2)] + $yoffset;
  22733. $xa = ($x + (2 * $x1)) / 3;
  22734. $ya = ($y + (2 * $y1)) / 3;
  22735. $x = $params[($ck - 1)] + $xoffset;
  22736. $y = $params[($ck)] + $yoffset;
  22737. $xb = ($x + (2 * $x1)) / 3;
  22738. $yb = ($y + (2 * $y1)) / 3;
  22739. $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
  22740. $xmin = min($xmin, $x, $xa, $xb);
  22741. $ymin = min($ymin, $y, $ya, $yb);
  22742. $xmax = max($xmax, $x, $xa, $xb);
  22743. $ymax = max($ymax, $y, $ya, $yb);
  22744. if ($relcoord) {
  22745. $xoffset = $x;
  22746. $yoffset = $y;
  22747. }
  22748. }
  22749. }
  22750. break;
  22751. }
  22752. case 'T': { // shorthand/smooth quadratic B\E9zier curveto
  22753. foreach ($params as $ck => $cp) {
  22754. $params[$ck] = $cp;
  22755. if (($ck % 2) != 0) {
  22756. if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'Q') OR (strtoupper($paths[($key - 1)][1]) == 'T'))) {
  22757. $x1 = (2 * $x) - $x1;
  22758. $y1 = (2 * $y) - $y1;
  22759. } else {
  22760. $x1 = $x;
  22761. $y1 = $y;
  22762. }
  22763. // convert quadratic points to cubic points
  22764. $xa = ($x + (2 * $x1)) / 3;
  22765. $ya = ($y + (2 * $y1)) / 3;
  22766. $x = $params[($ck - 1)] + $xoffset;
  22767. $y = $params[($ck)] + $yoffset;
  22768. $xb = ($x + (2 * $x1)) / 3;
  22769. $yb = ($y + (2 * $y1)) / 3;
  22770. $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
  22771. $xmin = min($xmin, $x, $xa, $xb);
  22772. $ymin = min($ymin, $y, $ya, $yb);
  22773. $xmax = max($xmax, $x, $xa, $xb);
  22774. $ymax = max($ymax, $y, $ya, $yb);
  22775. if ($relcoord) {
  22776. $xoffset = $x;
  22777. $yoffset = $y;
  22778. }
  22779. }
  22780. }
  22781. break;
  22782. }
  22783. case 'A': { // elliptical arc
  22784. foreach ($params as $ck => $cp) {
  22785. $params[$ck] = $cp;
  22786. if ((($ck + 1) % 7) == 0) {
  22787. $x0 = $x;
  22788. $y0 = $y;
  22789. $rx = abs($params[($ck - 6)]);
  22790. $ry = abs($params[($ck - 5)]);
  22791. $ang = -$rawparams[($ck - 4)];
  22792. $angle = deg2rad($ang);
  22793. $fa = $rawparams[($ck - 3)]; // large-arc-flag
  22794. $fs = $rawparams[($ck - 2)]; // sweep-flag
  22795. $x = $params[($ck - 1)] + $xoffset;
  22796. $y = $params[$ck] + $yoffset;
  22797. if ((abs($x0 - $x) < $minlen) AND (abs($y0 - $y) < $minlen)) {
  22798. // endpoints are almost identical
  22799. $xmin = min($xmin, $x);
  22800. $ymin = min($ymin, $y);
  22801. $xmax = max($xmax, $x);
  22802. $ymax = max($ymax, $y);
  22803. } else {
  22804. $cos_ang = cos($angle);
  22805. $sin_ang = sin($angle);
  22806. $a = (($x0 - $x) / 2);
  22807. $b = (($y0 - $y) / 2);
  22808. $xa = ($a * $cos_ang) - ($b * $sin_ang);
  22809. $ya = ($a * $sin_ang) + ($b * $cos_ang);
  22810. $rx2 = $rx * $rx;
  22811. $ry2 = $ry * $ry;
  22812. $xa2 = $xa * $xa;
  22813. $ya2 = $ya * $ya;
  22814. $delta = ($xa2 / $rx2) + ($ya2 / $ry2);
  22815. if ($delta > 1) {
  22816. $rx *= sqrt($delta);
  22817. $ry *= sqrt($delta);
  22818. $rx2 = $rx * $rx;
  22819. $ry2 = $ry * $ry;
  22820. }
  22821. $numerator = (($rx2 * $ry2) - ($rx2 * $ya2) - ($ry2 * $xa2));
  22822. if ($numerator < 0) {
  22823. $root = 0;
  22824. } else {
  22825. $root = sqrt($numerator / (($rx2 * $ya2) + ($ry2 * $xa2)));
  22826. }
  22827. if ($fa == $fs){
  22828. $root *= -1;
  22829. }
  22830. $cax = $root * (($rx * $ya) / $ry);
  22831. $cay = -$root * (($ry * $xa) / $rx);
  22832. // coordinates of ellipse center
  22833. $cx = ($cax * $cos_ang) - ($cay * $sin_ang) + (($x0 + $x) / 2);
  22834. $cy = ($cax * $sin_ang) + ($cay * $cos_ang) + (($y0 + $y) / 2);
  22835. // get angles
  22836. $angs = TCPDF_STATIC::getVectorsAngle(1, 0, (($xa - $cax) / $rx), (($cay - $ya) / $ry));
  22837. $dang = TCPDF_STATIC::getVectorsAngle((($xa - $cax) / $rx), (($ya - $cay) / $ry), ((-$xa - $cax) / $rx), ((-$ya - $cay) / $ry));
  22838. if (($fs == 0) AND ($dang > 0)) {
  22839. $dang -= (2 * M_PI);
  22840. } elseif (($fs == 1) AND ($dang < 0)) {
  22841. $dang += (2 * M_PI);
  22842. }
  22843. $angf = $angs - $dang;
  22844. if ((($fs == 0) AND ($angs > $angf)) OR (($fs == 1) AND ($angs < $angf))) {
  22845. // reverse angles
  22846. $tmp = $angs;
  22847. $angs = $angf;
  22848. $angf = $tmp;
  22849. }
  22850. $angs = round(rad2deg($angs), 6);
  22851. $angf = round(rad2deg($angf), 6);
  22852. // covent angles to positive values
  22853. if (($angs < 0) AND ($angf < 0)) {
  22854. $angs += 360;
  22855. $angf += 360;
  22856. }
  22857. $pie = false;
  22858. if (($key == 0) AND (isset($paths[($key + 1)][1])) AND (trim($paths[($key + 1)][1]) == 'z')) {
  22859. $pie = true;
  22860. }
  22861. list($axmin, $aymin, $axmax, $aymax) = $this->_outellipticalarc($cx, $cy, $rx, $ry, $ang, $angs, $angf, $pie, 2, false, ($fs == 0), true);
  22862. $xmin = min($xmin, $x, $axmin);
  22863. $ymin = min($ymin, $y, $aymin);
  22864. $xmax = max($xmax, $x, $axmax);
  22865. $ymax = max($ymax, $y, $aymax);
  22866. }
  22867. if ($relcoord) {
  22868. $xoffset = $x;
  22869. $yoffset = $y;
  22870. }
  22871. }
  22872. }
  22873. break;
  22874. }
  22875. case 'Z': {
  22876. $this->_out('h');
  22877. break;
  22878. }
  22879. }
  22880. $firstcmd = false;
  22881. } // end foreach
  22882. if (!empty($op)) {
  22883. $this->_out($op);
  22884. }
  22885. return array($xmin, $ymin, ($xmax - $xmin), ($ymax - $ymin));
  22886. }
  22887. /**
  22888. * Sets the opening SVG element handler function for the XML parser. (*** TO BE COMPLETED ***)
  22889. * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
  22890. * @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.
  22891. * @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.
  22892. * @param $ctm (array) tranformation matrix for clipping mode (starting transformation matrix).
  22893. * @author Nicola Asuni
  22894. * @since 5.0.000 (2010-05-02)
  22895. * @protected
  22896. */
  22897. protected function startSVGElementHandler($parser, $name, $attribs, $ctm=array()) {
  22898. // check if we are in clip mode
  22899. if ($this->svgclipmode) {
  22900. $this->svgclippaths[$this->svgclipid][] = array('name' => $name, 'attribs' => $attribs, 'tm' => $this->svgcliptm[$this->svgclipid]);
  22901. return;
  22902. }
  22903. if ($this->svgdefsmode AND !in_array($name, array('clipPath', 'linearGradient', 'radialGradient', 'stop'))) {
  22904. if (isset($attribs['id'])) {
  22905. $attribs['child_elements'] = array();
  22906. $this->svgdefs[$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
  22907. return;
  22908. }
  22909. if (end($this->svgdefs) !== FALSE) {
  22910. $last_svgdefs_id = key($this->svgdefs);
  22911. if (isset($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'])) {
  22912. $attribs['id'] = 'DF_'.(count($this->svgdefs) + 1);
  22913. $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
  22914. return;
  22915. }
  22916. }
  22917. return;
  22918. }
  22919. $clipping = false;
  22920. if ($parser == 'clip-path') {
  22921. // set clipping mode
  22922. $clipping = true;
  22923. }
  22924. // get styling properties
  22925. $prev_svgstyle = $this->svgstyles[max(0,(count($this->svgstyles) - 1))]; // previous style
  22926. $svgstyle = $this->svgstyles[0]; // set default style
  22927. if ($clipping AND !isset($attribs['fill']) AND (!isset($attribs['style']) OR (!preg_match('/[;\"\s]{1}fill[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval)))) {
  22928. // default fill attribute for clipping
  22929. $attribs['fill'] = 'none';
  22930. }
  22931. if (isset($attribs['style']) AND !TCPDF_STATIC::empty_string($attribs['style'])) {
  22932. // fix style for regular expression
  22933. $attribs['style'] = ';'.$attribs['style'];
  22934. }
  22935. foreach ($prev_svgstyle as $key => $val) {
  22936. if (in_array($key, TCPDF_IMAGES::$svginheritprop)) {
  22937. // inherit previous value
  22938. $svgstyle[$key] = $val;
  22939. }
  22940. if (isset($attribs[$key]) AND !TCPDF_STATIC::empty_string($attribs[$key])) {
  22941. // specific attribute settings
  22942. if ($attribs[$key] == 'inherit') {
  22943. $svgstyle[$key] = $val;
  22944. } else {
  22945. $svgstyle[$key] = $attribs[$key];
  22946. }
  22947. } elseif (isset($attribs['style']) AND !TCPDF_STATIC::empty_string($attribs['style'])) {
  22948. // CSS style syntax
  22949. $attrval = array();
  22950. if (preg_match('/[;\"\s]{1}'.$key.'[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval) AND isset($attrval[1])) {
  22951. if ($attrval[1] == 'inherit') {
  22952. $svgstyle[$key] = $val;
  22953. } else {
  22954. $svgstyle[$key] = $attrval[1];
  22955. }
  22956. }
  22957. }
  22958. }
  22959. // transformation matrix
  22960. if (!empty($ctm)) {
  22961. $tm = $ctm;
  22962. } else {
  22963. $tm = array(1,0,0,1,0,0);
  22964. }
  22965. if (isset($attribs['transform']) AND !empty($attribs['transform'])) {
  22966. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, TCPDF_STATIC::getSVGTransformMatrix($attribs['transform']));
  22967. }
  22968. $svgstyle['transfmatrix'] = $tm;
  22969. $invisible = false;
  22970. if (($svgstyle['visibility'] == 'hidden') OR ($svgstyle['visibility'] == 'collapse') OR ($svgstyle['display'] == 'none')) {
  22971. // the current graphics element is invisible (nothing is painted)
  22972. $invisible = true;
  22973. }
  22974. // process tag
  22975. switch($name) {
  22976. case 'defs': {
  22977. $this->svgdefsmode = true;
  22978. break;
  22979. }
  22980. // clipPath
  22981. case 'clipPath': {
  22982. if ($invisible) {
  22983. break;
  22984. }
  22985. $this->svgclipmode = true;
  22986. if (!isset($attribs['id'])) {
  22987. $attribs['id'] = 'CP_'.(count($this->svgcliptm) + 1);
  22988. }
  22989. $this->svgclipid = $attribs['id'];
  22990. $this->svgclippaths[$this->svgclipid] = array();
  22991. $this->svgcliptm[$this->svgclipid] = $tm;
  22992. break;
  22993. }
  22994. case 'svg': {
  22995. // start of SVG object
  22996. break;
  22997. }
  22998. case 'g': {
  22999. // group together related graphics elements
  23000. array_push($this->svgstyles, $svgstyle);
  23001. $this->StartTransform();
  23002. $this->SVGTransform($tm);
  23003. $this->setSVGStyles($svgstyle, $prev_svgstyle);
  23004. break;
  23005. }
  23006. case 'linearGradient': {
  23007. if ($this->pdfa_mode) {
  23008. break;
  23009. }
  23010. if (!isset($attribs['id'])) {
  23011. $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
  23012. }
  23013. $this->svggradientid = $attribs['id'];
  23014. $this->svggradients[$this->svggradientid] = array();
  23015. $this->svggradients[$this->svggradientid]['type'] = 2;
  23016. $this->svggradients[$this->svggradientid]['stops'] = array();
  23017. if (isset($attribs['gradientUnits'])) {
  23018. $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  23019. } else {
  23020. $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  23021. }
  23022. //$attribs['spreadMethod']
  23023. if (((!isset($attribs['x1'])) AND (!isset($attribs['y1'])) AND (!isset($attribs['x2'])) AND (!isset($attribs['y2'])))
  23024. OR ((isset($attribs['x1']) AND (substr($attribs['x1'], -1) == '%'))
  23025. OR (isset($attribs['y1']) AND (substr($attribs['y1'], -1) == '%'))
  23026. OR (isset($attribs['x2']) AND (substr($attribs['x2'], -1) == '%'))
  23027. OR (isset($attribs['y2']) AND (substr($attribs['y2'], -1) == '%')))) {
  23028. $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  23029. } else {
  23030. $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  23031. }
  23032. $x1 = (isset($attribs['x1'])?$attribs['x1']:'0');
  23033. $y1 = (isset($attribs['y1'])?$attribs['y1']:'0');
  23034. $x2 = (isset($attribs['x2'])?$attribs['x2']:'100');
  23035. $y2 = (isset($attribs['y2'])?$attribs['y2']:'0');
  23036. if (isset($attribs['gradientTransform'])) {
  23037. $this->svggradients[$this->svggradientid]['gradientTransform'] = TCPDF_STATIC::getSVGTransformMatrix($attribs['gradientTransform']);
  23038. }
  23039. $this->svggradients[$this->svggradientid]['coords'] = array($x1, $y1, $x2, $y2);
  23040. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23041. // gradient is defined on another place
  23042. $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  23043. }
  23044. break;
  23045. }
  23046. case 'radialGradient': {
  23047. if ($this->pdfa_mode) {
  23048. break;
  23049. }
  23050. if (!isset($attribs['id'])) {
  23051. $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
  23052. }
  23053. $this->svggradientid = $attribs['id'];
  23054. $this->svggradients[$this->svggradientid] = array();
  23055. $this->svggradients[$this->svggradientid]['type'] = 3;
  23056. $this->svggradients[$this->svggradientid]['stops'] = array();
  23057. if (isset($attribs['gradientUnits'])) {
  23058. $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  23059. } else {
  23060. $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  23061. }
  23062. //$attribs['spreadMethod']
  23063. if (((!isset($attribs['cx'])) AND (!isset($attribs['cy'])))
  23064. OR ((isset($attribs['cx']) AND (substr($attribs['cx'], -1) == '%'))
  23065. OR (isset($attribs['cy']) AND (substr($attribs['cy'], -1) == '%')) )) {
  23066. $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  23067. } else {
  23068. $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  23069. }
  23070. $cx = (isset($attribs['cx']) ? $attribs['cx'] : 0.5);
  23071. $cy = (isset($attribs['cy']) ? $attribs['cy'] : 0.5);
  23072. $fx = (isset($attribs['fx']) ? $attribs['fx'] : $cx);
  23073. $fy = (isset($attribs['fy']) ? $attribs['fy'] : $cy);
  23074. $r = (isset($attribs['r']) ? $attribs['r'] : 0.5);
  23075. if (isset($attribs['gradientTransform'])) {
  23076. $this->svggradients[$this->svggradientid]['gradientTransform'] = TCPDF_STATIC::getSVGTransformMatrix($attribs['gradientTransform']);
  23077. }
  23078. $this->svggradients[$this->svggradientid]['coords'] = array($cx, $cy, $fx, $fy, $r);
  23079. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23080. // gradient is defined on another place
  23081. $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  23082. }
  23083. break;
  23084. }
  23085. case 'stop': {
  23086. // gradient stops
  23087. if (substr($attribs['offset'], -1) == '%') {
  23088. $offset = floatval(substr($attribs['offset'], -1)) / 100;
  23089. } else {
  23090. $offset = floatval($attribs['offset']);
  23091. if ($offset > 1) {
  23092. $offset /= 100;
  23093. }
  23094. }
  23095. $stop_color = isset($svgstyle['stop-color'])?TCPDF_COLORS::convertHTMLColorToDec($svgstyle['stop-color'], $this->spot_colors):'black';
  23096. $opacity = isset($svgstyle['stop-opacity'])?$svgstyle['stop-opacity']:1;
  23097. $this->svggradients[$this->svggradientid]['stops'][] = array('offset' => $offset, 'color' => $stop_color, 'opacity' => $opacity);
  23098. break;
  23099. }
  23100. // paths
  23101. case 'path': {
  23102. if ($invisible) {
  23103. break;
  23104. }
  23105. if (isset($attribs['d'])) {
  23106. $d = trim($attribs['d']);
  23107. if (!empty($d)) {
  23108. $x = (isset($attribs['x'])?$attribs['x']:0);
  23109. $y = (isset($attribs['y'])?$attribs['y']:0);
  23110. $w = (isset($attribs['width'])?$attribs['width']:1);
  23111. $h = (isset($attribs['height'])?$attribs['height']:1);
  23112. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array($w, 0, 0, $h, $x, $y));
  23113. if ($clipping) {
  23114. $this->SVGTransform($tm);
  23115. $this->SVGPath($d, 'CNZ');
  23116. } else {
  23117. $this->StartTransform();
  23118. $this->SVGTransform($tm);
  23119. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'SVGPath', array($d, 'CNZ'));
  23120. if (!empty($obstyle)) {
  23121. $this->SVGPath($d, $obstyle);
  23122. }
  23123. $this->StopTransform();
  23124. }
  23125. }
  23126. }
  23127. break;
  23128. }
  23129. // shapes
  23130. case 'rect': {
  23131. if ($invisible) {
  23132. break;
  23133. }
  23134. $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
  23135. $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
  23136. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
  23137. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
  23138. $rx = (isset($attribs['rx'])?$this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false):0);
  23139. $ry = (isset($attribs['ry'])?$this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false):$rx);
  23140. if ($clipping) {
  23141. $this->SVGTransform($tm);
  23142. $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ', array(), array());
  23143. } else {
  23144. $this->StartTransform();
  23145. $this->SVGTransform($tm);
  23146. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'RoundedRectXY', array($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ'));
  23147. if (!empty($obstyle)) {
  23148. $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', $obstyle, array(), array());
  23149. }
  23150. $this->StopTransform();
  23151. }
  23152. break;
  23153. }
  23154. case 'circle': {
  23155. if ($invisible) {
  23156. break;
  23157. }
  23158. $r = (isset($attribs['r']) ? $this->getHTMLUnitToUnits($attribs['r'], 0, $this->svgunit, false) : 0);
  23159. $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false) : (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : 0));
  23160. $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false) : (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : 0));
  23161. $x = ($cx - $r);
  23162. $y = ($cy - $r);
  23163. $w = (2 * $r);
  23164. $h = $w;
  23165. if ($clipping) {
  23166. $this->SVGTransform($tm);
  23167. $this->Circle($cx, $cy, $r, 0, 360, 'CNZ', array(), array(), 8);
  23168. } else {
  23169. $this->StartTransform();
  23170. $this->SVGTransform($tm);
  23171. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Circle', array($cx, $cy, $r, 0, 360, 'CNZ'));
  23172. if (!empty($obstyle)) {
  23173. $this->Circle($cx, $cy, $r, 0, 360, $obstyle, array(), array(), 8);
  23174. }
  23175. $this->StopTransform();
  23176. }
  23177. break;
  23178. }
  23179. case 'ellipse': {
  23180. if ($invisible) {
  23181. break;
  23182. }
  23183. $rx = (isset($attribs['rx']) ? $this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false) : 0);
  23184. $ry = (isset($attribs['ry']) ? $this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false) : 0);
  23185. $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false) : (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : 0));
  23186. $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false) : (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : 0));
  23187. $x = ($cx - $rx);
  23188. $y = ($cy - $ry);
  23189. $w = (2 * $rx);
  23190. $h = (2 * $ry);
  23191. if ($clipping) {
  23192. $this->SVGTransform($tm);
  23193. $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ', array(), array(), 8);
  23194. } else {
  23195. $this->StartTransform();
  23196. $this->SVGTransform($tm);
  23197. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Ellipse', array($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ'));
  23198. if (!empty($obstyle)) {
  23199. $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, $obstyle, array(), array(), 8);
  23200. }
  23201. $this->StopTransform();
  23202. }
  23203. break;
  23204. }
  23205. case 'line': {
  23206. if ($invisible) {
  23207. break;
  23208. }
  23209. $x1 = (isset($attribs['x1'])?$this->getHTMLUnitToUnits($attribs['x1'], 0, $this->svgunit, false):0);
  23210. $y1 = (isset($attribs['y1'])?$this->getHTMLUnitToUnits($attribs['y1'], 0, $this->svgunit, false):0);
  23211. $x2 = (isset($attribs['x2'])?$this->getHTMLUnitToUnits($attribs['x2'], 0, $this->svgunit, false):0);
  23212. $y2 = (isset($attribs['y2'])?$this->getHTMLUnitToUnits($attribs['y2'], 0, $this->svgunit, false):0);
  23213. $x = $x1;
  23214. $y = $y1;
  23215. $w = abs($x2 - $x1);
  23216. $h = abs($y2 - $y1);
  23217. if (!$clipping) {
  23218. $this->StartTransform();
  23219. $this->SVGTransform($tm);
  23220. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Line', array($x1, $y1, $x2, $y2));
  23221. $this->Line($x1, $y1, $x2, $y2);
  23222. $this->StopTransform();
  23223. }
  23224. break;
  23225. }
  23226. case 'polyline':
  23227. case 'polygon': {
  23228. if ($invisible) {
  23229. break;
  23230. }
  23231. $points = (isset($attribs['points'])?$attribs['points']:'0 0');
  23232. $points = trim($points);
  23233. // note that point may use a complex syntax not covered here
  23234. $points = preg_split('/[\,\s]+/si', $points);
  23235. if (count($points) < 4) {
  23236. break;
  23237. }
  23238. $p = array();
  23239. $xmin = 2147483647;
  23240. $xmax = 0;
  23241. $ymin = 2147483647;
  23242. $ymax = 0;
  23243. foreach ($points as $key => $val) {
  23244. $p[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
  23245. if (($key % 2) == 0) {
  23246. // X coordinate
  23247. $xmin = min($xmin, $p[$key]);
  23248. $xmax = max($xmax, $p[$key]);
  23249. } else {
  23250. // Y coordinate
  23251. $ymin = min($ymin, $p[$key]);
  23252. $ymax = max($ymax, $p[$key]);
  23253. }
  23254. }
  23255. $x = $xmin;
  23256. $y = $ymin;
  23257. $w = ($xmax - $xmin);
  23258. $h = ($ymax - $ymin);
  23259. if ($name == 'polyline') {
  23260. $this->StartTransform();
  23261. $this->SVGTransform($tm);
  23262. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'PolyLine', array($p, 'CNZ'));
  23263. if (!empty($obstyle)) {
  23264. $this->PolyLine($p, $obstyle, array(), array());
  23265. }
  23266. $this->StopTransform();
  23267. } else { // polygon
  23268. if ($clipping) {
  23269. $this->SVGTransform($tm);
  23270. $this->Polygon($p, 'CNZ', array(), array(), true);
  23271. } else {
  23272. $this->StartTransform();
  23273. $this->SVGTransform($tm);
  23274. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Polygon', array($p, 'CNZ'));
  23275. if (!empty($obstyle)) {
  23276. $this->Polygon($p, $obstyle, array(), array(), true);
  23277. }
  23278. $this->StopTransform();
  23279. }
  23280. }
  23281. break;
  23282. }
  23283. // image
  23284. case 'image': {
  23285. if ($invisible) {
  23286. break;
  23287. }
  23288. if (!isset($attribs['xlink:href']) OR empty($attribs['xlink:href'])) {
  23289. break;
  23290. }
  23291. $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
  23292. $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
  23293. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
  23294. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
  23295. $img = $attribs['xlink:href'];
  23296. if (!$clipping) {
  23297. $this->StartTransform();
  23298. $this->SVGTransform($tm);
  23299. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h);
  23300. if (preg_match('/^data:image\/[^;]+;base64,/', $img, $m) > 0) {
  23301. // embedded image encoded as base64
  23302. $img = '@'.base64_decode(substr($img, strlen($m[0])));
  23303. } else {
  23304. // fix image path
  23305. if (!TCPDF_STATIC::empty_string($this->svgdir) AND (($img{0} == '.') OR (basename($img) == $img))) {
  23306. // replace relative path with full server path
  23307. $img = $this->svgdir.'/'.$img;
  23308. }
  23309. if (($img[0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
  23310. $findroot = strpos($img, $_SERVER['DOCUMENT_ROOT']);
  23311. if (($findroot === false) OR ($findroot > 1)) {
  23312. if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
  23313. $img = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$img;
  23314. } else {
  23315. $img = $_SERVER['DOCUMENT_ROOT'].$img;
  23316. }
  23317. }
  23318. }
  23319. $img = urldecode($img);
  23320. $testscrtype = @parse_url($img);
  23321. if (!isset($testscrtype['query']) OR empty($testscrtype['query'])) {
  23322. // convert URL to server path
  23323. $img = str_replace(K_PATH_URL, K_PATH_MAIN, $img);
  23324. }
  23325. }
  23326. // get image type
  23327. $imgtype = TCPDF_IMAGES::getImageFileType($img);
  23328. if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  23329. $this->ImageEps($img, $x, $y, $w, $h);
  23330. } elseif ($imgtype == 'svg') {
  23331. $this->ImageSVG($img, $x, $y, $w, $h);
  23332. } else {
  23333. $this->Image($img, $x, $y, $w, $h);
  23334. }
  23335. $this->StopTransform();
  23336. }
  23337. break;
  23338. }
  23339. // text
  23340. case 'text':
  23341. case 'tspan': {
  23342. // only basic support - advanced features must be implemented
  23343. $this->svgtextmode['invisible'] = $invisible;
  23344. if ($invisible) {
  23345. break;
  23346. }
  23347. array_push($this->svgstyles, $svgstyle);
  23348. if (isset($attribs['x'])) {
  23349. $x = $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false);
  23350. } elseif ($name == 'tspan') {
  23351. $x = $this->x;
  23352. } else {
  23353. $x = 0;
  23354. }
  23355. if (isset($attribs['dx'])) {
  23356. $x += $this->getHTMLUnitToUnits($attribs['dx'], 0, $this->svgunit, false);
  23357. }
  23358. if (isset($attribs['y'])) {
  23359. $y = $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false);
  23360. } elseif ($name == 'tspan') {
  23361. $y = $this->y;
  23362. } else {
  23363. $y = 0;
  23364. }
  23365. if (isset($attribs['dy'])) {
  23366. $y += $this->getHTMLUnitToUnits($attribs['dy'], 0, $this->svgunit, false);
  23367. }
  23368. $svgstyle['text-color'] = $svgstyle['fill'];
  23369. $this->svgtext = '';
  23370. if (isset($svgstyle['text-anchor'])) {
  23371. $this->svgtextmode['text-anchor'] = $svgstyle['text-anchor'];
  23372. } else {
  23373. $this->svgtextmode['text-anchor'] = 'start';
  23374. }
  23375. if (isset($svgstyle['direction'])) {
  23376. if ($svgstyle['direction'] == 'rtl') {
  23377. $this->svgtextmode['rtl'] = true;
  23378. } else {
  23379. $this->svgtextmode['rtl'] = false;
  23380. }
  23381. } else {
  23382. $this->svgtextmode['rtl'] = false;
  23383. }
  23384. if (isset($svgstyle['stroke']) AND ($svgstyle['stroke'] != 'none') AND isset($svgstyle['stroke-width']) AND ($svgstyle['stroke-width'] > 0)) {
  23385. $this->svgtextmode['stroke'] = $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false);
  23386. } else {
  23387. $this->svgtextmode['stroke'] = false;
  23388. }
  23389. $this->StartTransform();
  23390. $this->SVGTransform($tm);
  23391. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, 1, 1);
  23392. $this->x = $x;
  23393. $this->y = $y;
  23394. break;
  23395. }
  23396. // use
  23397. case 'use': {
  23398. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23399. $svgdefid = substr($attribs['xlink:href'], 1);
  23400. if (isset($this->svgdefs[$svgdefid])) {
  23401. $use = $this->svgdefs[$svgdefid];
  23402. if (isset($attribs['xlink:href'])) {
  23403. unset($attribs['xlink:href']);
  23404. }
  23405. if (isset($attribs['id'])) {
  23406. unset($attribs['id']);
  23407. }
  23408. if (isset($use['attribs']['x']) AND isset($attribs['x'])) {
  23409. $attribs['x'] += $use['attribs']['x'];
  23410. }
  23411. if (isset($use['attribs']['y']) AND isset($attribs['y'])) {
  23412. $attribs['y'] += $use['attribs']['y'];
  23413. }
  23414. $attribs = array_merge($use['attribs'], $attribs);
  23415. $this->startSVGElementHandler('use-tag', $use['name'], $attribs);
  23416. return;
  23417. }
  23418. }
  23419. break;
  23420. }
  23421. default: {
  23422. break;
  23423. }
  23424. } // end of switch
  23425. // process child elements
  23426. if (!empty($attribs['child_elements'])) {
  23427. $child_elements = $attribs['child_elements'];
  23428. unset($attribs['child_elements']);
  23429. foreach($child_elements as $child_element) {
  23430. if (empty($child_element['attribs']['closing_tag'])) {
  23431. $this->startSVGElementHandler('child-tag', $child_element['name'], $child_element['attribs']);
  23432. } else {
  23433. $this->endSVGElementHandler('child-tag', $child_element['name']);
  23434. }
  23435. }
  23436. }
  23437. }
  23438. /**
  23439. * Sets the closing SVG element handler function for the XML parser.
  23440. * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
  23441. * @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.
  23442. * @author Nicola Asuni
  23443. * @since 5.0.000 (2010-05-02)
  23444. * @protected
  23445. */
  23446. protected function endSVGElementHandler($parser, $name) {
  23447. if ($this->svgdefsmode AND !in_array($name, array('defs', 'clipPath', 'linearGradient', 'radialGradient', 'stop'))) {;
  23448. if (end($this->svgdefs) !== FALSE) {
  23449. $last_svgdefs_id = key($this->svgdefs);
  23450. if (isset($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'])) {
  23451. foreach($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'] as $child_element) {
  23452. if (isset($child_element['attribs']['id']) AND ($child_element['name'] == $name)) {
  23453. $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$child_element['attribs']['id'].'_CLOSE'] = array('name' => $name, 'attribs' => array('closing_tag' => TRUE));
  23454. return;
  23455. }
  23456. }
  23457. if ($this->svgdefs[$last_svgdefs_id]['name'] == $name) {
  23458. $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$last_svgdefs_id.'_CLOSE'] = array('name' => $name, 'attribs' => array('closing_tag' => TRUE));
  23459. return;
  23460. }
  23461. }
  23462. }
  23463. return;
  23464. }
  23465. switch($name) {
  23466. case 'defs': {
  23467. $this->svgdefsmode = false;
  23468. break;
  23469. }
  23470. // clipPath
  23471. case 'clipPath': {
  23472. $this->svgclipmode = false;
  23473. break;
  23474. }
  23475. case 'g': {
  23476. // ungroup: remove last style from array
  23477. array_pop($this->svgstyles);
  23478. $this->StopTransform();
  23479. break;
  23480. }
  23481. case 'text':
  23482. case 'tspan': {
  23483. if ($this->svgtextmode['invisible']) {
  23484. // This implementation must be fixed to following the rule:
  23485. // 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.
  23486. break;
  23487. }
  23488. // print text
  23489. $text = $this->svgtext;
  23490. //$text = $this->stringTrim($text);
  23491. $textlen = $this->GetStringWidth($text);
  23492. if ($this->svgtextmode['text-anchor'] != 'start') {
  23493. // check if string is RTL text
  23494. if ($this->svgtextmode['text-anchor'] == 'end') {
  23495. if ($this->svgtextmode['rtl']) {
  23496. $this->x += $textlen;
  23497. } else {
  23498. $this->x -= $textlen;
  23499. }
  23500. } elseif ($this->svgtextmode['text-anchor'] == 'middle') {
  23501. if ($this->svgtextmode['rtl']) {
  23502. $this->x += ($textlen / 2);
  23503. } else {
  23504. $this->x -= ($textlen / 2);
  23505. }
  23506. }
  23507. }
  23508. $textrendermode = $this->textrendermode;
  23509. $textstrokewidth = $this->textstrokewidth;
  23510. $this->setTextRenderingMode($this->svgtextmode['stroke'], true, false);
  23511. if ($name == 'text') {
  23512. // store current coordinates
  23513. $tmpx = $this->x;
  23514. $tmpy = $this->y;
  23515. }
  23516. $this->Cell($textlen, 0, $text, 0, 0, '', false, '', 0, false, 'L', 'T');
  23517. if ($name == 'text') {
  23518. // restore coordinates
  23519. $this->x = $tmpx;
  23520. $this->y = $tmpy;
  23521. }
  23522. // restore previous rendering mode
  23523. $this->textrendermode = $textrendermode;
  23524. $this->textstrokewidth = $textstrokewidth;
  23525. $this->svgtext = '';
  23526. $this->StopTransform();
  23527. if (!$this->svgdefsmode) {
  23528. array_pop($this->svgstyles);
  23529. }
  23530. break;
  23531. }
  23532. default: {
  23533. break;
  23534. }
  23535. }
  23536. }
  23537. /**
  23538. * Sets the character data handler function for the XML parser.
  23539. * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
  23540. * @param $data (string) The second parameter, data, contains the character data as a string.
  23541. * @author Nicola Asuni
  23542. * @since 5.0.000 (2010-05-02)
  23543. * @protected
  23544. */
  23545. protected function segSVGContentHandler($parser, $data) {
  23546. $this->svgtext .= $data;
  23547. }
  23548. // --- END SVG METHODS -----------------------------------------------------
  23549. } // END OF TCPDF CLASS
  23550. //============================================================+
  23551. // END OF FILE
  23552. //============================================================+