tcpdf.php 932 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183
  1. <?php
  2. //============================================================+
  3. // File name : tcpdf.php
  4. // Version : 5.9.046
  5. // Begin : 2002-08-03
  6. // Last Update : 2011-01-18
  7. // Author : Nicola Asuni - Tecnick.com S.r.l - Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
  8. // License : http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT GNU-LGPLv3 + YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE GENERATED PDF DOCUMENTS.
  9. // -------------------------------------------------------------------
  10. // Copyright (C) 2002-2011 Nicola Asuni - Tecnick.com S.r.l.
  11. //
  12. // This file is part of TCPDF software library.
  13. //
  14. // TCPDF is free software: you can redistribute it and/or modify it
  15. // under the terms of the GNU Lesser General Public License as
  16. // published by the Free Software Foundation, either version 3 of the
  17. // License, or (at your option) any later version. Additionally,
  18. // YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE
  19. // GENERATED PDF DOCUMENTS.
  20. //
  21. // TCPDF is distributed in the hope that it will be useful, but
  22. // WITHOUT ANY WARRANTY; without even the implied warranty of
  23. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  24. // See the GNU Lesser General Public License for more details.
  25. //
  26. // You should have received a copy of the License
  27. // along with TCPDF. If not, see
  28. // <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
  29. //
  30. // See LICENSE.TXT file for more information.
  31. // -------------------------------------------------------------------
  32. //
  33. // Description : This is a PHP class for generating PDF documents without
  34. // requiring external extensions.
  35. //
  36. // NOTE:
  37. // This class was originally derived in 2002 from the Public
  38. // Domain FPDF class by Olivier Plathey (http://www.fpdf.org),
  39. // but now is almost entirely rewritten and contains thousands of
  40. // new lines of code and hundreds new features.
  41. //
  42. // Main features:
  43. // * no external libraries are required for the basic functions;
  44. // * all standard page formats, custom page formats, custom margins and units of measure;
  45. // * UTF-8 Unicode and Right-To-Left languages;
  46. // * TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;
  47. // * font subsetting;
  48. // * methods to publish some XHTML + CSS code, Javascript and Forms;
  49. // * images, graphic (geometric figures) and transformation methods;
  50. // * 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)
  51. // * 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, QR-Code, PDF417;
  52. // * Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  53. // * automatic page header and footer management;
  54. // * document encryption up to 256 bit and digital signature certifications;
  55. // * transactions to UNDO commands;
  56. // * PDF annotations, including links, text and file attachments;
  57. // * text rendering modes (fill, stroke and clipping);
  58. // * multiple columns mode;
  59. // * no-write page regions;
  60. // * bookmarks and table of content;
  61. // * text hyphenation;
  62. // * text stretching and spacing (tracking/kerning);
  63. // * automatic page break, line break and text alignments including justification;
  64. // * automatic page numbering and page groups;
  65. // * move and delete pages;
  66. // * page compression (requires php-zlib extension);
  67. // * XOBject Templates;
  68. //
  69. // -----------------------------------------------------------
  70. // THANKS TO:
  71. //
  72. // Olivier Plathey (http://www.fpdf.org) for original FPDF.
  73. // Efthimios Mavrogeorgiadis (emavro@yahoo.com) for suggestions on RTL language support.
  74. // Klemen Vodopivec (http://www.fpdf.de/downloads/addons/37/) for Encryption algorithm.
  75. // Warren Sherliker (wsherliker@gmail.com) for better image handling.
  76. // dullus for text Justification.
  77. // Bob Vincent (pillarsdotnet@users.sourceforge.net) for <li> value attribute.
  78. // Patrick Benny for text stretch suggestion on Cell().
  79. // Johannes Güntert for JavaScript support.
  80. // Denis Van Nuffelen for Dynamic Form.
  81. // Jacek Czekaj for multibyte justification
  82. // Anthony Ferrara for the reintroduction of legacy image methods.
  83. // Sourceforge user 1707880 (hucste) for line-trough mode.
  84. // Larry Stanbery for page groups.
  85. // Martin Hall-May for transparency.
  86. // Aaron C. Spike for Polycurve method.
  87. // Mohamad Ali Golkar, Saleh AlMatrafe, Charles Abbott for Arabic and Persian support.
  88. // Moritz Wagner and Andreas Wurmser for graphic functions.
  89. // Andrew Whitehead for core fonts support.
  90. // Esteban Joël Marín for OpenType font conversion.
  91. // Teus Hagen for several suggestions and fixes.
  92. // Yukihiro Nakadaira for CID-0 CJK fonts fixes.
  93. // Kosmas Papachristos for some CSS improvements.
  94. // Marcel Partap for some fixes.
  95. // Won Kyu Park for several suggestions, fixes and patches.
  96. // Dominik Dzienia for QR-code support.
  97. // Laurent Minguet for some suggestions.
  98. // Christian Deligant for some suggestions and fixes.
  99. // Anyone that has reported a bug or sent a suggestion.
  100. //============================================================+
  101. /**
  102. * @file
  103. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  104. * 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>
  105. * <h3>TCPDF main features are:</h3>
  106. * <ul>
  107. * <li>no external libraries are required for the basic functions;</li>
  108. * <li>all standard page formats, custom page formats, custom margins and units of measure;</li>
  109. * <li>UTF-8 Unicode and Right-To-Left languages;</li>
  110. * <li>TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;</li>
  111. * <li>font subsetting;</li>
  112. * <li>methods to publish some XHTML + CSS code, Javascript and Forms;</li>
  113. * <li>images, graphic (geometric figures) and transformation methods;
  114. * <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>
  115. * <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, QR-Code, PDF417;</li>
  116. * <li>Grayscale, RGB, CMYK, Spot Colors and Transparencies;</li>
  117. * <li>automatic page header and footer management;</li>
  118. * <li>document encryption up to 256 bit and digital signature certifications;</li>
  119. * <li>transactions to UNDO commands;</li>
  120. * <li>PDF annotations, including links, text and file attachments;</li>
  121. * <li>text rendering modes (fill, stroke and clipping);</li>
  122. * <li>multiple columns mode;</li>
  123. * <li>no-write page regions;</li>
  124. * <li>bookmarks and table of content;</li>
  125. * <li>text hyphenation;</li>
  126. * <li>text stretching and spacing (tracking/kerning);</li>
  127. * <li>automatic page break, line break and text alignments including justification;</li>
  128. * <li>automatic page numbering and page groups;</li>
  129. * <li>move and delete pages;</li>
  130. * <li>page compression (requires php-zlib extension);</li>
  131. * <li>XOBject Templates;</li>
  132. * </ul>
  133. * Tools to encode your unicode fonts are on fonts/utils directory.</p>
  134. * @package com.tecnick.tcpdf
  135. * @author Nicola Asuni
  136. * @version 5.9.046
  137. */
  138. // Main configuration file. Define the K_TCPDF_EXTERNAL_CONFIG constant to skip this file.
  139. require_once(dirname(__FILE__).'/config/tcpdf_config.php');
  140. /**
  141. * @class TCPDF
  142. * PHP class for generating PDF documents without requiring external extensions.
  143. * 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>
  144. * @package com.tecnick.tcpdf
  145. * @brief PHP class for generating PDF documents without requiring external extensions.
  146. * @version 5.9.046
  147. * @author Nicola Asuni - info@tecnick.com
  148. */
  149. class TCPDF {
  150. // private properties
  151. /**
  152. * Current TCPDF version.
  153. * @private
  154. */
  155. private $tcpdf_version = '5.9.046';
  156. // Protected properties
  157. /**
  158. * Current page number.
  159. * @protected
  160. */
  161. protected $page;
  162. /**
  163. * Current object number.
  164. * @protected
  165. */
  166. protected $n;
  167. /**
  168. * Array of object offsets.
  169. * @protected
  170. */
  171. protected $offsets;
  172. /**
  173. * Buffer holding in-memory PDF.
  174. * @protected
  175. */
  176. protected $buffer;
  177. /**
  178. * Array containing pages.
  179. * @protected
  180. */
  181. protected $pages = array();
  182. /**
  183. * Current document state.
  184. * @protected
  185. */
  186. protected $state;
  187. /**
  188. * Compression flag.
  189. * @protected
  190. */
  191. protected $compress;
  192. /**
  193. * Current page orientation (P = Portrait, L = Landscape).
  194. * @protected
  195. */
  196. protected $CurOrientation;
  197. /**
  198. * Page dimensions.
  199. * @protected
  200. */
  201. protected $pagedim = array();
  202. /**
  203. * Scale factor (number of points in user unit).
  204. * @protected
  205. */
  206. protected $k;
  207. /**
  208. * Width of page format in points.
  209. * @protected
  210. */
  211. protected $fwPt;
  212. /**
  213. * Height of page format in points.
  214. * @protected
  215. */
  216. protected $fhPt;
  217. /**
  218. * Current width of page in points.
  219. * @protected
  220. */
  221. protected $wPt;
  222. /**
  223. * Current height of page in points.
  224. * @protected
  225. */
  226. protected $hPt;
  227. /**
  228. * Current width of page in user unit.
  229. * @protected
  230. */
  231. protected $w;
  232. /**
  233. * Current height of page in user unit.
  234. * @protected
  235. */
  236. protected $h;
  237. /**
  238. * Left margin.
  239. * @protected
  240. */
  241. protected $lMargin;
  242. /**
  243. * Top margin.
  244. * @protected
  245. */
  246. protected $tMargin;
  247. /**
  248. * Right margin.
  249. * @protected
  250. */
  251. protected $rMargin;
  252. /**
  253. * Page break margin.
  254. * @protected
  255. */
  256. protected $bMargin;
  257. /**
  258. * Array of cell internal paddings ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
  259. * @since 5.9.000 (2010-10-03)
  260. * @protected
  261. */
  262. protected $cell_padding = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  263. /**
  264. * Array of cell margins ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
  265. * @since 5.9.000 (2010-10-04)
  266. * @protected
  267. */
  268. protected $cell_margin = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  269. /**
  270. * Current horizontal position in user unit for cell positioning.
  271. * @protected
  272. */
  273. protected $x;
  274. /**
  275. * Current vertical position in user unit for cell positioning.
  276. * @protected
  277. */
  278. protected $y;
  279. /**
  280. * Height of last cell printed.
  281. * @protected
  282. */
  283. protected $lasth;
  284. /**
  285. * Line width in user unit.
  286. * @protected
  287. */
  288. protected $LineWidth;
  289. /**
  290. * Array of standard font names.
  291. * @protected
  292. */
  293. protected $CoreFonts;
  294. /**
  295. * Array of used fonts.
  296. * @protected
  297. */
  298. protected $fonts = array();
  299. /**
  300. * Array of font files.
  301. * @protected
  302. */
  303. protected $FontFiles = array();
  304. /**
  305. * Array of encoding differences.
  306. * @protected
  307. */
  308. protected $diffs = array();
  309. /**
  310. * Array of used images.
  311. * @protected
  312. */
  313. protected $images = array();
  314. /**
  315. * Array of Annotations in pages.
  316. * @protected
  317. */
  318. protected $PageAnnots = array();
  319. /**
  320. * Array of internal links.
  321. * @protected
  322. */
  323. protected $links = array();
  324. /**
  325. * Current font family.
  326. * @protected
  327. */
  328. protected $FontFamily;
  329. /**
  330. * Current font style.
  331. * @protected
  332. */
  333. protected $FontStyle;
  334. /**
  335. * Current font ascent (distance between font top and baseline).
  336. * @protected
  337. * @since 2.8.000 (2007-03-29)
  338. */
  339. protected $FontAscent;
  340. /**
  341. * Current font descent (distance between font bottom and baseline).
  342. * @protected
  343. * @since 2.8.000 (2007-03-29)
  344. */
  345. protected $FontDescent;
  346. /**
  347. * Underlining flag.
  348. * @protected
  349. */
  350. protected $underline;
  351. /**
  352. * Overlining flag.
  353. * @protected
  354. */
  355. protected $overline;
  356. /**
  357. * Current font info.
  358. * @protected
  359. */
  360. protected $CurrentFont;
  361. /**
  362. * Current font size in points.
  363. * @protected
  364. */
  365. protected $FontSizePt;
  366. /**
  367. * Current font size in user unit.
  368. * @protected
  369. */
  370. protected $FontSize;
  371. /**
  372. * Commands for drawing color.
  373. * @protected
  374. */
  375. protected $DrawColor;
  376. /**
  377. * Commands for filling color.
  378. * @protected
  379. */
  380. protected $FillColor;
  381. /**
  382. * Commands for text color.
  383. * @protected
  384. */
  385. protected $TextColor;
  386. /**
  387. * Indicates whether fill and text colors are different.
  388. * @protected
  389. */
  390. protected $ColorFlag;
  391. /**
  392. * Automatic page breaking.
  393. * @protected
  394. */
  395. protected $AutoPageBreak;
  396. /**
  397. * Threshold used to trigger page breaks.
  398. * @protected
  399. */
  400. protected $PageBreakTrigger;
  401. /**
  402. * Flag set when processing 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. * String alias for total number of pages.
  448. * @protected
  449. */
  450. protected $AliasNbPages = '{nb}';
  451. /**
  452. * String alias for page number.
  453. * @protected
  454. */
  455. protected $AliasNumPage = '{pnb}';
  456. /**
  457. * The right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image.
  458. * @since 2002-07-31
  459. * @author Nicola Asuni
  460. * @protected
  461. */
  462. protected $img_rb_x;
  463. /**
  464. * The right-bottom corner Y coordinate of last inserted image.
  465. * @since 2002-07-31
  466. * @author Nicola Asuni
  467. * @protected
  468. */
  469. protected $img_rb_y;
  470. /**
  471. * Adjusting factor to convert pixels to user units.
  472. * @since 2004-06-14
  473. * @author Nicola Asuni
  474. * @protected
  475. */
  476. protected $imgscale = 1;
  477. /**
  478. * Boolean flag set to true when the input text is unicode (require unicode fonts).
  479. * @since 2005-01-02
  480. * @author Nicola Asuni
  481. * @protected
  482. */
  483. protected $isunicode = false;
  484. /**
  485. * Object containing unicode data.
  486. * @since 5.9.004 (2010-10-18)
  487. * @author Nicola Asuni
  488. * @protected
  489. */
  490. protected $unicode;
  491. /**
  492. * PDF version.
  493. * @since 1.5.3
  494. * @protected
  495. */
  496. protected $PDFVersion = '1.7';
  497. /**
  498. * Minimum distance between header and top page margin.
  499. * @protected
  500. */
  501. protected $header_margin;
  502. /**
  503. * Minimum distance between footer and bottom page margin.
  504. * @protected
  505. */
  506. protected $footer_margin;
  507. /**
  508. * Original left margin value.
  509. * @protected
  510. * @since 1.53.0.TC013
  511. */
  512. protected $original_lMargin;
  513. /**
  514. * Original right margin value.
  515. * @protected
  516. * @since 1.53.0.TC013
  517. */
  518. protected $original_rMargin;
  519. /**
  520. * Default font used on page header.
  521. * @protected
  522. */
  523. protected $header_font;
  524. /**
  525. * Default font used on page footer.
  526. * @protected
  527. */
  528. protected $footer_font;
  529. /**
  530. * Language templates.
  531. * @protected
  532. */
  533. protected $l;
  534. /**
  535. * Barcode to print on page footer (only if set).
  536. * @protected
  537. */
  538. protected $barcode = false;
  539. /**
  540. * Boolean flag to print/hide page header.
  541. * @protected
  542. */
  543. protected $print_header = true;
  544. /**
  545. * Boolean flag to print/hide page footer.
  546. * @protected
  547. */
  548. protected $print_footer = true;
  549. /**
  550. * Header image logo.
  551. * @protected
  552. */
  553. protected $header_logo = '';
  554. /**
  555. * Width of header image logo in user units.
  556. * @protected
  557. */
  558. protected $header_logo_width = 30;
  559. /**
  560. * Title to be printed on default page header.
  561. * @protected
  562. */
  563. protected $header_title = '';
  564. /**
  565. * String to pring on page header after title.
  566. * @protected
  567. */
  568. protected $header_string = '';
  569. /**
  570. * Default number of columns for html table.
  571. * @protected
  572. */
  573. protected $default_table_columns = 4;
  574. // variables for html parser
  575. /**
  576. * HTML PARSER: array to store current link and rendering styles.
  577. * @protected
  578. */
  579. protected $HREF = array();
  580. /**
  581. * List of available fonts on filesystem.
  582. * @protected
  583. */
  584. protected $fontlist = array();
  585. /**
  586. * Current foreground color.
  587. * @protected
  588. */
  589. protected $fgcolor;
  590. /**
  591. * HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  592. * @protected
  593. */
  594. protected $listordered = array();
  595. /**
  596. * HTML PARSER: array count list items on nested lists.
  597. * @protected
  598. */
  599. protected $listcount = array();
  600. /**
  601. * HTML PARSER: current list nesting level.
  602. * @protected
  603. */
  604. protected $listnum = 0;
  605. /**
  606. * HTML PARSER: indent amount for lists.
  607. * @protected
  608. */
  609. protected $listindent = 0;
  610. /**
  611. * HTML PARSER: current list indententation level.
  612. * @protected
  613. */
  614. protected $listindentlevel = 0;
  615. /**
  616. * Current background color.
  617. * @protected
  618. */
  619. protected $bgcolor;
  620. /**
  621. * Temporary font size in points.
  622. * @protected
  623. */
  624. protected $tempfontsize = 10;
  625. /**
  626. * Spacer string for LI tags.
  627. * @protected
  628. */
  629. protected $lispacer = '';
  630. /**
  631. * Default encoding.
  632. * @protected
  633. * @since 1.53.0.TC010
  634. */
  635. protected $encoding = 'UTF-8';
  636. /**
  637. * PHP internal encoding.
  638. * @protected
  639. * @since 1.53.0.TC016
  640. */
  641. protected $internal_encoding;
  642. /**
  643. * Boolean flag to indicate if the document language is Right-To-Left.
  644. * @protected
  645. * @since 2.0.000
  646. */
  647. protected $rtl = false;
  648. /**
  649. * Boolean flag used to force RTL or LTR string direction.
  650. * @protected
  651. * @since 2.0.000
  652. */
  653. protected $tmprtl = false;
  654. // --- Variables used for document encryption:
  655. /**
  656. * IBoolean flag indicating whether document is protected.
  657. * @protected
  658. * @since 2.0.000 (2008-01-02)
  659. */
  660. protected $encrypted;
  661. /**
  662. * Array containing encryption settings.
  663. * @protected
  664. * @since 5.0.005 (2010-05-11)
  665. */
  666. protected $encryptdata = array();
  667. /**
  668. * Last RC4 key encrypted (cached for optimisation).
  669. * @protected
  670. * @since 2.0.000 (2008-01-02)
  671. */
  672. protected $last_enc_key;
  673. /**
  674. * Last RC4 computed key.
  675. * @protected
  676. * @since 2.0.000 (2008-01-02)
  677. */
  678. protected $last_enc_key_c;
  679. /**
  680. * Encryption padding string.
  681. * @protected
  682. */
  683. protected $enc_padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
  684. /**
  685. * File ID (used on document trailer).
  686. * @protected
  687. * @since 5.0.005 (2010-05-12)
  688. */
  689. protected $file_id;
  690. // --- bookmark ---
  691. /**
  692. * Outlines for bookmark.
  693. * @protected
  694. * @since 2.1.002 (2008-02-12)
  695. */
  696. protected $outlines = array();
  697. /**
  698. * Outline root for bookmark.
  699. * @protected
  700. * @since 2.1.002 (2008-02-12)
  701. */
  702. protected $OutlineRoot;
  703. // --- javascript and form ---
  704. /**
  705. * Javascript code.
  706. * @protected
  707. * @since 2.1.002 (2008-02-12)
  708. */
  709. protected $javascript = '';
  710. /**
  711. * Javascript counter.
  712. * @protected
  713. * @since 2.1.002 (2008-02-12)
  714. */
  715. protected $n_js;
  716. /**
  717. * line trough state
  718. * @protected
  719. * @since 2.8.000 (2008-03-19)
  720. */
  721. protected $linethrough;
  722. /**
  723. * Array with additional document-wide usage rights for the document.
  724. * @protected
  725. * @since 5.8.014 (2010-08-23)
  726. */
  727. protected $ur = array();
  728. /**
  729. * DPI (Dot Per Inch) Document Resolution (do not change).
  730. * @protected
  731. * @since 3.0.000 (2008-03-27)
  732. */
  733. protected $dpi = 72;
  734. /**
  735. * Array of page numbers were a new page group was started.
  736. * @protected
  737. * @since 3.0.000 (2008-03-27)
  738. */
  739. protected $newpagegroup = array();
  740. /**
  741. * Contains the number of pages of the groups.
  742. * @protected
  743. * @since 3.0.000 (2008-03-27)
  744. */
  745. protected $pagegroups;
  746. /**
  747. * Contains the alias of the current page group.
  748. * @protected
  749. * @since 3.0.000 (2008-03-27)
  750. */
  751. protected $currpagegroup;
  752. /**
  753. * Restrict the rendering of some elements to screen or printout.
  754. * @protected
  755. * @since 3.0.000 (2008-03-27)
  756. */
  757. protected $visibility = 'all';
  758. /**
  759. * Print visibility.
  760. * @protected
  761. * @since 3.0.000 (2008-03-27)
  762. */
  763. protected $n_ocg_print;
  764. /**
  765. * View visibility.
  766. * @protected
  767. * @since 3.0.000 (2008-03-27)
  768. */
  769. protected $n_ocg_view;
  770. /**
  771. * Array of transparency objects and parameters.
  772. * @protected
  773. * @since 3.0.000 (2008-03-27)
  774. */
  775. protected $extgstates;
  776. /**
  777. * Set the default JPEG compression quality (1-100).
  778. * @protected
  779. * @since 3.0.000 (2008-03-27)
  780. */
  781. protected $jpeg_quality;
  782. /**
  783. * Default cell height ratio.
  784. * @protected
  785. * @since 3.0.014 (2008-05-23)
  786. */
  787. protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  788. /**
  789. * PDF viewer preferences.
  790. * @protected
  791. * @since 3.1.000 (2008-06-09)
  792. */
  793. protected $viewer_preferences;
  794. /**
  795. * A name object specifying how the document should be displayed when opened.
  796. * @protected
  797. * @since 3.1.000 (2008-06-09)
  798. */
  799. protected $PageMode;
  800. /**
  801. * Array for storing gradient information.
  802. * @protected
  803. * @since 3.1.000 (2008-06-09)
  804. */
  805. protected $gradients = array();
  806. /**
  807. * Array used to store positions inside the pages buffer (keys are the page numbers).
  808. * @protected
  809. * @since 3.2.000 (2008-06-26)
  810. */
  811. protected $intmrk = array();
  812. /**
  813. * Array used to store positions inside the pages buffer (keys are the page numbers).
  814. * @protected
  815. * @since 5.7.000 (2010-08-03)
  816. */
  817. protected $bordermrk = array();
  818. /**
  819. * Array used to store page positions to track empty pages (keys are the page numbers).
  820. * @protected
  821. * @since 5.8.007 (2010-08-18)
  822. */
  823. protected $emptypagemrk = array();
  824. /**
  825. * Array used to store content positions inside the pages buffer (keys are the page numbers).
  826. * @protected
  827. * @since 4.6.021 (2009-07-20)
  828. */
  829. protected $cntmrk = array();
  830. /**
  831. * Array used to store footer positions of each page.
  832. * @protected
  833. * @since 3.2.000 (2008-07-01)
  834. */
  835. protected $footerpos = array();
  836. /**
  837. * Array used to store footer length of each page.
  838. * @protected
  839. * @since 4.0.014 (2008-07-29)
  840. */
  841. protected $footerlen = array();
  842. /**
  843. * Boolean flag to indicate if a new line is created.
  844. * @protected
  845. * @since 3.2.000 (2008-07-01)
  846. */
  847. protected $newline = true;
  848. /**
  849. * End position of the latest inserted line.
  850. * @protected
  851. * @since 3.2.000 (2008-07-01)
  852. */
  853. protected $endlinex = 0;
  854. /**
  855. * PDF string for width value of the last line.
  856. * @protected
  857. * @since 4.0.006 (2008-07-16)
  858. */
  859. protected $linestyleWidth = '';
  860. /**
  861. * PDF string for CAP value of the last line.
  862. * @protected
  863. * @since 4.0.006 (2008-07-16)
  864. */
  865. protected $linestyleCap = '0 J';
  866. /**
  867. * PDF string for join value of the last line.
  868. * @protected
  869. * @since 4.0.006 (2008-07-16)
  870. */
  871. protected $linestyleJoin = '0 j';
  872. /**
  873. * PDF string for dash value of the last line.
  874. * @protected
  875. * @since 4.0.006 (2008-07-16)
  876. */
  877. protected $linestyleDash = '[] 0 d';
  878. /**
  879. * Boolean flag to indicate if marked-content sequence is open.
  880. * @protected
  881. * @since 4.0.013 (2008-07-28)
  882. */
  883. protected $openMarkedContent = false;
  884. /**
  885. * Count the latest inserted vertical spaces on HTML.
  886. * @protected
  887. * @since 4.0.021 (2008-08-24)
  888. */
  889. protected $htmlvspace = 0;
  890. /**
  891. * Array of Spot colors.
  892. * @protected
  893. * @since 4.0.024 (2008-09-12)
  894. */
  895. protected $spot_colors = array();
  896. /**
  897. * Symbol used for HTML unordered list items.
  898. * @protected
  899. * @since 4.0.028 (2008-09-26)
  900. */
  901. protected $lisymbol = '';
  902. /**
  903. * String used to mark the beginning and end of EPS image blocks.
  904. * @protected
  905. * @since 4.1.000 (2008-10-18)
  906. */
  907. protected $epsmarker = 'x#!#EPS#!#x';
  908. /**
  909. * Array of transformation matrix.
  910. * @protected
  911. * @since 4.2.000 (2008-10-29)
  912. */
  913. protected $transfmatrix = array();
  914. /**
  915. * Current key for transformation matrix.
  916. * @protected
  917. * @since 4.8.005 (2009-09-17)
  918. */
  919. protected $transfmatrix_key = 0;
  920. /**
  921. * Booklet mode for double-sided pages.
  922. * @protected
  923. * @since 4.2.000 (2008-10-29)
  924. */
  925. protected $booklet = false;
  926. /**
  927. * Epsilon value used for float calculations.
  928. * @protected
  929. * @since 4.2.000 (2008-10-29)
  930. */
  931. protected $feps = 0.005;
  932. /**
  933. * Array used for custom vertical spaces for HTML tags.
  934. * @protected
  935. * @since 4.2.001 (2008-10-30)
  936. */
  937. protected $tagvspaces = array();
  938. /**
  939. * HTML PARSER: custom indent amount for lists. Negative value means disabled.
  940. * @protected
  941. * @since 4.2.007 (2008-11-12)
  942. */
  943. protected $customlistindent = -1;
  944. /**
  945. * Boolean flag to indicate if the border of the cell sides that cross the page should be removed.
  946. * @protected
  947. * @since 4.2.010 (2008-11-14)
  948. */
  949. protected $opencell = true;
  950. /**
  951. * Array of files to embedd.
  952. * @protected
  953. * @since 4.4.000 (2008-12-07)
  954. */
  955. protected $embeddedfiles = array();
  956. /**
  957. * Boolean flag to indicate if we are inside a PRE tag.
  958. * @protected
  959. * @since 4.4.001 (2008-12-08)
  960. */
  961. protected $premode = false;
  962. /**
  963. * Array used to store positions of graphics transformation blocks inside the page buffer.
  964. * keys are the page numbers
  965. * @protected
  966. * @since 4.4.002 (2008-12-09)
  967. */
  968. protected $transfmrk = array();
  969. /**
  970. * Default color for html links.
  971. * @protected
  972. * @since 4.4.003 (2008-12-09)
  973. */
  974. protected $htmlLinkColorArray = array(0, 0, 255);
  975. /**
  976. * Default font style to add to html links.
  977. * @protected
  978. * @since 4.4.003 (2008-12-09)
  979. */
  980. protected $htmlLinkFontStyle = 'U';
  981. /**
  982. * Counts the number of pages.
  983. * @protected
  984. * @since 4.5.000 (2008-12-31)
  985. */
  986. protected $numpages = 0;
  987. /**
  988. * Array containing page lengths in bytes.
  989. * @protected
  990. * @since 4.5.000 (2008-12-31)
  991. */
  992. protected $pagelen = array();
  993. /**
  994. * Counts the number of pages.
  995. * @protected
  996. * @since 4.5.000 (2008-12-31)
  997. */
  998. protected $numimages = 0;
  999. /**
  1000. * Store the image keys.
  1001. * @protected
  1002. * @since 4.5.000 (2008-12-31)
  1003. */
  1004. protected $imagekeys = array();
  1005. /**
  1006. * Length of the buffer in bytes.
  1007. * @protected
  1008. * @since 4.5.000 (2008-12-31)
  1009. */
  1010. protected $bufferlen = 0;
  1011. /**
  1012. * If true enables disk caching.
  1013. * @protected
  1014. * @since 4.5.000 (2008-12-31)
  1015. */
  1016. protected $diskcache = false;
  1017. /**
  1018. * Counts the number of fonts.
  1019. * @protected
  1020. * @since 4.5.000 (2009-01-02)
  1021. */
  1022. protected $numfonts = 0;
  1023. /**
  1024. * Store the font keys.
  1025. * @protected
  1026. * @since 4.5.000 (2009-01-02)
  1027. */
  1028. protected $fontkeys = array();
  1029. /**
  1030. * Store the font object IDs.
  1031. * @protected
  1032. * @since 4.8.001 (2009-09-09)
  1033. */
  1034. protected $font_obj_ids = array();
  1035. /**
  1036. * Store the fage status (true when opened, false when closed).
  1037. * @protected
  1038. * @since 4.5.000 (2009-01-02)
  1039. */
  1040. protected $pageopen = array();
  1041. /**
  1042. * Default monospace font.
  1043. * @protected
  1044. * @since 4.5.025 (2009-03-10)
  1045. */
  1046. protected $default_monospaced_font = 'courier';
  1047. /**
  1048. * Cloned copy of the current class object.
  1049. * @protected
  1050. * @since 4.5.029 (2009-03-19)
  1051. */
  1052. protected $objcopy;
  1053. /**
  1054. * Array used to store the lengths of cache files.
  1055. * @protected
  1056. * @since 4.5.029 (2009-03-19)
  1057. */
  1058. protected $cache_file_length = array();
  1059. /**
  1060. * Table header content to be repeated on each new page.
  1061. * @protected
  1062. * @since 4.5.030 (2009-03-20)
  1063. */
  1064. protected $thead = '';
  1065. /**
  1066. * Margins used for table header.
  1067. * @protected
  1068. * @since 4.5.030 (2009-03-20)
  1069. */
  1070. protected $theadMargins = array();
  1071. /**
  1072. * Cache array for UTF8StringToArray() method.
  1073. * @protected
  1074. * @since 4.5.037 (2009-04-07)
  1075. */
  1076. protected $cache_UTF8StringToArray = array();
  1077. /**
  1078. * Maximum size of cache array used for UTF8StringToArray() method.
  1079. * @protected
  1080. * @since 4.5.037 (2009-04-07)
  1081. */
  1082. protected $cache_maxsize_UTF8StringToArray = 8;
  1083. /**
  1084. * Current size of cache array used for UTF8StringToArray() method.
  1085. * @protected
  1086. * @since 4.5.037 (2009-04-07)
  1087. */
  1088. protected $cache_size_UTF8StringToArray = 0;
  1089. /**
  1090. * Boolean flag to enable document digital signature.
  1091. * @protected
  1092. * @since 4.6.005 (2009-04-24)
  1093. */
  1094. protected $sign = false;
  1095. /**
  1096. * Digital signature data.
  1097. * @protected
  1098. * @since 4.6.005 (2009-04-24)
  1099. */
  1100. protected $signature_data = array();
  1101. /**
  1102. * Digital signature max length.
  1103. * @protected
  1104. * @since 4.6.005 (2009-04-24)
  1105. */
  1106. protected $signature_max_length = 11742;
  1107. /**
  1108. * Data for digital signature appearance.
  1109. * @protected
  1110. * @since 5.3.011 (2010-06-16)
  1111. */
  1112. protected $signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
  1113. /**
  1114. * Regular expression used to find blank characters (required for word-wrapping).
  1115. * @protected
  1116. * @since 4.6.006 (2009-04-28)
  1117. */
  1118. protected $re_spaces = '/[^\S\xa0]/';
  1119. /**
  1120. * Array of $re_spaces parts.
  1121. * @protected
  1122. * @since 5.5.011 (2010-07-09)
  1123. */
  1124. protected $re_space = array('p' => '[^\S\xa0]', 'm' => '');
  1125. /**
  1126. * Digital signature object ID.
  1127. * @protected
  1128. * @since 4.6.022 (2009-06-23)
  1129. */
  1130. protected $sig_obj_id = 0;
  1131. /**
  1132. * ByteRange placemark used during digital signature process.
  1133. * @protected
  1134. * @since 4.6.028 (2009-08-25)
  1135. */
  1136. protected $byterange_string = '/ByteRange[0 ********** ********** **********]';
  1137. /**
  1138. * Placemark used during digital signature process.
  1139. * @protected
  1140. * @since 4.6.028 (2009-08-25)
  1141. */
  1142. protected $sig_annot_ref = '***SIGANNREF*** 0 R';
  1143. /**
  1144. * ID of page objects.
  1145. * @protected
  1146. * @since 4.7.000 (2009-08-29)
  1147. */
  1148. protected $page_obj_id = array();
  1149. /**
  1150. * List of form annotations IDs.
  1151. * @protected
  1152. * @since 4.8.000 (2009-09-07)
  1153. */
  1154. protected $form_obj_id = array();
  1155. /**
  1156. * 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.
  1157. * @protected
  1158. * @since 4.8.000 (2009-09-07)
  1159. */
  1160. protected $default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1161. /**
  1162. * Javascript objects array.
  1163. * @protected
  1164. * @since 4.8.000 (2009-09-07)
  1165. */
  1166. protected $js_objects = array();
  1167. /**
  1168. * Current form action (used during XHTML rendering).
  1169. * @protected
  1170. * @since 4.8.000 (2009-09-07)
  1171. */
  1172. protected $form_action = '';
  1173. /**
  1174. * Current form encryption type (used during XHTML rendering).
  1175. * @protected
  1176. * @since 4.8.000 (2009-09-07)
  1177. */
  1178. protected $form_enctype = 'application/x-www-form-urlencoded';
  1179. /**
  1180. * Current method to submit forms.
  1181. * @protected
  1182. * @since 4.8.000 (2009-09-07)
  1183. */
  1184. protected $form_mode = 'post';
  1185. /**
  1186. * List of fonts used on form fields (fontname => fontkey).
  1187. * @protected
  1188. * @since 4.8.001 (2009-09-09)
  1189. */
  1190. protected $annotation_fonts = array();
  1191. /**
  1192. * List of radio buttons parent objects.
  1193. * @protected
  1194. * @since 4.8.001 (2009-09-09)
  1195. */
  1196. protected $radiobutton_groups = array();
  1197. /**
  1198. * List of radio group objects IDs.
  1199. * @protected
  1200. * @since 4.8.001 (2009-09-09)
  1201. */
  1202. protected $radio_groups = array();
  1203. /**
  1204. * Text indentation value (used for text-indent CSS attribute).
  1205. * @protected
  1206. * @since 4.8.006 (2009-09-23)
  1207. */
  1208. protected $textindent = 0;
  1209. /**
  1210. * Store page number when startTransaction() is called.
  1211. * @protected
  1212. * @since 4.8.006 (2009-09-23)
  1213. */
  1214. protected $start_transaction_page = 0;
  1215. /**
  1216. * Store Y position when startTransaction() is called.
  1217. * @protected
  1218. * @since 4.9.001 (2010-03-28)
  1219. */
  1220. protected $start_transaction_y = 0;
  1221. /**
  1222. * True when we are printing the thead section on a new page.
  1223. * @protected
  1224. * @since 4.8.027 (2010-01-25)
  1225. */
  1226. protected $inthead = false;
  1227. /**
  1228. * Array of column measures (width, space, starting Y position).
  1229. * @protected
  1230. * @since 4.9.001 (2010-03-28)
  1231. */
  1232. protected $columns = array();
  1233. /**
  1234. * Number of colums.
  1235. * @protected
  1236. * @since 4.9.001 (2010-03-28)
  1237. */
  1238. protected $num_columns = 1;
  1239. /**
  1240. * Current column number.
  1241. * @protected
  1242. * @since 4.9.001 (2010-03-28)
  1243. */
  1244. protected $current_column = 0;
  1245. /**
  1246. * Starting page for columns.
  1247. * @protected
  1248. * @since 4.9.001 (2010-03-28)
  1249. */
  1250. protected $column_start_page = 0;
  1251. /**
  1252. * Maximum page and column selected.
  1253. * @protected
  1254. * @since 5.8.000 (2010-08-11)
  1255. */
  1256. protected $maxselcol = array('page' => 0, 'column' => 0);
  1257. /**
  1258. * Array of: X difference between table cell x start and starting page margin, cellspacing, cellpadding.
  1259. * @protected
  1260. * @since 5.8.000 (2010-08-11)
  1261. */
  1262. protected $colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  1263. /**
  1264. * 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.
  1265. * @protected
  1266. * @since 4.9.008 (2010-04-03)
  1267. */
  1268. protected $textrendermode = 0;
  1269. /**
  1270. * Text stroke width in doc units.
  1271. * @protected
  1272. * @since 4.9.008 (2010-04-03)
  1273. */
  1274. protected $textstrokewidth = 0;
  1275. /**
  1276. * Current stroke color.
  1277. * @protected
  1278. * @since 4.9.008 (2010-04-03)
  1279. */
  1280. protected $strokecolor;
  1281. /**
  1282. * Default unit of measure for document.
  1283. * @protected
  1284. * @since 5.0.000 (2010-04-22)
  1285. */
  1286. protected $pdfunit = 'mm';
  1287. /**
  1288. * Boolean flag true when we are on TOC (Table Of Content) page.
  1289. * @protected
  1290. */
  1291. protected $tocpage = false;
  1292. /**
  1293. * Boolean flag: if true convert vector images (SVG, EPS) to raster image using GD or ImageMagick library.
  1294. * @protected
  1295. * @since 5.0.000 (2010-04-26)
  1296. */
  1297. protected $rasterize_vector_images = false;
  1298. /**
  1299. * Boolean flag: if true enables font subsetting by default.
  1300. * @protected
  1301. * @since 5.3.002 (2010-06-07)
  1302. */
  1303. protected $font_subsetting = true;
  1304. /**
  1305. * Array of default graphic settings.
  1306. * @protected
  1307. * @since 5.5.008 (2010-07-02)
  1308. */
  1309. protected $default_graphic_vars = array();
  1310. /**
  1311. * Array of XObjects.
  1312. * @protected
  1313. * @since 5.8.014 (2010-08-23)
  1314. */
  1315. protected $xobjects = array();
  1316. /**
  1317. * Boolean value true when we are inside an XObject.
  1318. * @protected
  1319. * @since 5.8.017 (2010-08-24)
  1320. */
  1321. protected $inxobj = false;
  1322. /**
  1323. * Current XObject ID.
  1324. * @protected
  1325. * @since 5.8.017 (2010-08-24)
  1326. */
  1327. protected $xobjid = '';
  1328. /**
  1329. * Percentage of character stretching.
  1330. * @protected
  1331. * @since 5.9.000 (2010-09-29)
  1332. */
  1333. protected $font_stretching = 100;
  1334. /**
  1335. * Increases or decreases the space between characters in a text by the specified amount (tracking/kerning).
  1336. * @protected
  1337. * @since 5.9.000 (2010-09-29)
  1338. */
  1339. protected $font_spacing = 0;
  1340. /**
  1341. * Array of no-write regions.
  1342. * ('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)
  1343. * @protected
  1344. * @since 5.9.003 (2010-10-14)
  1345. */
  1346. protected $page_regions = array();
  1347. /**
  1348. * Array containing HTML color names and values.
  1349. * @protected
  1350. * @since 5.9.004 (2010-10-18)
  1351. */
  1352. protected $webcolor = array();
  1353. /**
  1354. * Array containing spot color names and values.
  1355. * @protected
  1356. * @since 5.9.012 (2010-11-11)
  1357. */
  1358. protected $spotcolor = array();
  1359. /**
  1360. * Boolean value true when PDF layers are used.
  1361. * @protected
  1362. * @since 5.9.046 (2011-01-18)
  1363. */
  1364. protected $pdflayers = false;
  1365. /**
  1366. * Directory used for the last SVG image.
  1367. * @protected
  1368. * @since 5.0.000 (2010-05-05)
  1369. */
  1370. protected $svgdir = '';
  1371. /**
  1372. * Deafult unit of measure for SVG.
  1373. * @protected
  1374. * @since 5.0.000 (2010-05-02)
  1375. */
  1376. protected $svgunit = 'px';
  1377. /**
  1378. * Array of SVG gradients.
  1379. * @protected
  1380. * @since 5.0.000 (2010-05-02)
  1381. */
  1382. protected $svggradients = array();
  1383. /**
  1384. * ID of last SVG gradient.
  1385. * @protected
  1386. * @since 5.0.000 (2010-05-02)
  1387. */
  1388. protected $svggradientid = 0;
  1389. /**
  1390. * Boolean value true when in SVG defs group.
  1391. * @protected
  1392. * @since 5.0.000 (2010-05-02)
  1393. */
  1394. protected $svgdefsmode = false;
  1395. /**
  1396. * Array of SVG defs.
  1397. * @protected
  1398. * @since 5.0.000 (2010-05-02)
  1399. */
  1400. protected $svgdefs = array();
  1401. /**
  1402. * Boolean value true when in SVG clipPath tag.
  1403. * @protected
  1404. * @since 5.0.000 (2010-04-26)
  1405. */
  1406. protected $svgclipmode = false;
  1407. /**
  1408. * Array of SVG clipPath commands.
  1409. * @protected
  1410. * @since 5.0.000 (2010-05-02)
  1411. */
  1412. protected $svgclippaths = array();
  1413. /**
  1414. * Array of SVG clipPath tranformation matrix.
  1415. * @protected
  1416. * @since 5.8.022 (2010-08-31)
  1417. */
  1418. protected $svgcliptm = array();
  1419. /**
  1420. * ID of last SVG clipPath.
  1421. * @protected
  1422. * @since 5.0.000 (2010-05-02)
  1423. */
  1424. protected $svgclipid = 0;
  1425. /**
  1426. * SVG text.
  1427. * @protected
  1428. * @since 5.0.000 (2010-05-02)
  1429. */
  1430. protected $svgtext = '';
  1431. /**
  1432. * SVG text properties.
  1433. * @protected
  1434. * @since 5.8.013 (2010-08-23)
  1435. */
  1436. protected $svgtextmode = array();
  1437. /**
  1438. * Array of hinheritable SVG properties.
  1439. * @protected
  1440. * @since 5.0.000 (2010-05-02)
  1441. */
  1442. protected $svginheritprop = array('clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cursor', 'direction', 'fill', 'fill-opacity', 'fill-rule', 'font', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'image-rendering', 'kerning', 'letter-spacing', 'marker', 'marker-end', 'marker-mid', 'marker-start', 'pointer-events', 'shape-rendering', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-rendering', 'visibility', 'word-spacing', 'writing-mode');
  1443. /**
  1444. * Array of SVG properties.
  1445. * @protected
  1446. * @since 5.0.000 (2010-05-02)
  1447. */
  1448. protected $svgstyles = array(array(
  1449. 'alignment-baseline' => 'auto',
  1450. 'baseline-shift' => 'baseline',
  1451. 'clip' => 'auto',
  1452. 'clip-path' => 'none',
  1453. 'clip-rule' => 'nonzero',
  1454. 'color' => 'black',
  1455. 'color-interpolation' => 'sRGB',
  1456. 'color-interpolation-filters' => 'linearRGB',
  1457. 'color-profile' => 'auto',
  1458. 'color-rendering' => 'auto',
  1459. 'cursor' => 'auto',
  1460. 'direction' => 'ltr',
  1461. 'display' => 'inline',
  1462. 'dominant-baseline' => 'auto',
  1463. 'enable-background' => 'accumulate',
  1464. 'fill' => 'black',
  1465. 'fill-opacity' => 1,
  1466. 'fill-rule' => 'nonzero',
  1467. 'filter' => 'none',
  1468. 'flood-color' => 'black',
  1469. 'flood-opacity' => 1,
  1470. 'font' => '',
  1471. 'font-family' => 'helvetica',
  1472. 'font-size' => 'medium',
  1473. 'font-size-adjust' => 'none',
  1474. 'font-stretch' => 'normal',
  1475. 'font-style' => 'normal',
  1476. 'font-variant' => 'normal',
  1477. 'font-weight' => 'normal',
  1478. 'glyph-orientation-horizontal' => '0deg',
  1479. 'glyph-orientation-vertical' => 'auto',
  1480. 'image-rendering' => 'auto',
  1481. 'kerning' => 'auto',
  1482. 'letter-spacing' => 'normal',
  1483. 'lighting-color' => 'white',
  1484. 'marker' => '',
  1485. 'marker-end' => 'none',
  1486. 'marker-mid' => 'none',
  1487. 'marker-start' => 'none',
  1488. 'mask' => 'none',
  1489. 'opacity' => 1,
  1490. 'overflow' => 'auto',
  1491. 'pointer-events' => 'visiblePainted',
  1492. 'shape-rendering' => 'auto',
  1493. 'stop-color' => 'black',
  1494. 'stop-opacity' => 1,
  1495. 'stroke' => 'none',
  1496. 'stroke-dasharray' => 'none',
  1497. 'stroke-dashoffset' => 0,
  1498. 'stroke-linecap' => 'butt',
  1499. 'stroke-linejoin' => 'miter',
  1500. 'stroke-miterlimit' => 4,
  1501. 'stroke-opacity' => 1,
  1502. 'stroke-width' => 1,
  1503. 'text-anchor' => 'start',
  1504. 'text-decoration' => 'none',
  1505. 'text-rendering' => 'auto',
  1506. 'unicode-bidi' => 'normal',
  1507. 'visibility' => 'visible',
  1508. 'word-spacing' => 'normal',
  1509. 'writing-mode' => 'lr-tb',
  1510. 'text-color' => 'black',
  1511. 'transfmatrix' => array(1, 0, 0, 1, 0, 0)
  1512. ));
  1513. //------------------------------------------------------------
  1514. // METHODS
  1515. //------------------------------------------------------------
  1516. /**
  1517. * This is the class constructor.
  1518. * It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).
  1519. * @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>
  1520. * @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.
  1521. * @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().
  1522. * @param $unicode (boolean) TRUE means that the input text is unicode (default = true)
  1523. * @param $diskcache (boolean) if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
  1524. * @param $encoding (string) charset encoding; default is UTF-8
  1525. * @public
  1526. * @see getPageSizeFromFormat(), setPageFormat()
  1527. */
  1528. public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false) {
  1529. /* Set internal character encoding to ASCII */
  1530. if (function_exists('mb_internal_encoding') AND mb_internal_encoding()) {
  1531. $this->internal_encoding = mb_internal_encoding();
  1532. mb_internal_encoding('ASCII');
  1533. }
  1534. // get array of HTML colors
  1535. require(dirname(__FILE__).'/htmlcolors.php');
  1536. $this->webcolor = $webcolor;
  1537. // get array of custom spot colors
  1538. if (file_exists(dirname(__FILE__).'/spotcolors.php')) {
  1539. require(dirname(__FILE__).'/spotcolors.php');
  1540. $this->spotcolor = $spotcolor;
  1541. } else {
  1542. $this->spotcolor = array();
  1543. }
  1544. require_once(dirname(__FILE__).'/unicode_data.php');
  1545. $this->unicode = new TCPDF_UNICODE_DATA();
  1546. $this->font_obj_ids = array();
  1547. $this->page_obj_id = array();
  1548. $this->form_obj_id = array();
  1549. // set disk caching
  1550. $this->diskcache = $diskcache ? true : false;
  1551. // set language direction
  1552. $this->rtl = false;
  1553. $this->tmprtl = false;
  1554. // some checks
  1555. $this->_dochecks();
  1556. // initialization of properties
  1557. $this->isunicode = $unicode;
  1558. $this->page = 0;
  1559. $this->transfmrk[0] = array();
  1560. $this->pagedim = array();
  1561. $this->n = 2;
  1562. $this->buffer = '';
  1563. $this->pages = array();
  1564. $this->state = 0;
  1565. $this->fonts = array();
  1566. $this->FontFiles = array();
  1567. $this->diffs = array();
  1568. $this->images = array();
  1569. $this->links = array();
  1570. $this->gradients = array();
  1571. $this->InFooter = false;
  1572. $this->lasth = 0;
  1573. $this->FontFamily = 'helvetica';
  1574. $this->FontStyle = '';
  1575. $this->FontSizePt = 12;
  1576. $this->underline = false;
  1577. $this->overline = false;
  1578. $this->linethrough = false;
  1579. $this->DrawColor = '0 G';
  1580. $this->FillColor = '0 g';
  1581. $this->TextColor = '0 g';
  1582. $this->ColorFlag = false;
  1583. $this->pdflayers = false;
  1584. // encryption values
  1585. $this->encrypted = false;
  1586. $this->last_enc_key = '';
  1587. // standard Unicode fonts
  1588. $this->CoreFonts = array(
  1589. 'courier'=>'Courier',
  1590. 'courierB'=>'Courier-Bold',
  1591. 'courierI'=>'Courier-Oblique',
  1592. 'courierBI'=>'Courier-BoldOblique',
  1593. 'helvetica'=>'Helvetica',
  1594. 'helveticaB'=>'Helvetica-Bold',
  1595. 'helveticaI'=>'Helvetica-Oblique',
  1596. 'helveticaBI'=>'Helvetica-BoldOblique',
  1597. 'times'=>'Times-Roman',
  1598. 'timesB'=>'Times-Bold',
  1599. 'timesI'=>'Times-Italic',
  1600. 'timesBI'=>'Times-BoldItalic',
  1601. 'symbol'=>'Symbol',
  1602. 'zapfdingbats'=>'ZapfDingbats'
  1603. );
  1604. // set scale factor
  1605. $this->setPageUnit($unit);
  1606. // set page format and orientation
  1607. $this->setPageFormat($format, $orientation);
  1608. // page margins (1 cm)
  1609. $margin = 28.35 / $this->k;
  1610. $this->SetMargins($margin, $margin);
  1611. // internal cell padding
  1612. $cpadding = $margin / 10;
  1613. $this->setCellPaddings($cpadding, 0, $cpadding, 0);
  1614. // cell margins
  1615. $this->setCellMargins(0, 0, 0, 0);
  1616. // line width (0.2 mm)
  1617. $this->LineWidth = 0.57 / $this->k;
  1618. $this->linestyleWidth = sprintf('%.2F w', ($this->LineWidth * $this->k));
  1619. $this->linestyleCap = '0 J';
  1620. $this->linestyleJoin = '0 j';
  1621. $this->linestyleDash = '[] 0 d';
  1622. // automatic page break
  1623. $this->SetAutoPageBreak(true, (2 * $margin));
  1624. // full width display mode
  1625. $this->SetDisplayMode('fullwidth');
  1626. // compression
  1627. $this->SetCompression(true);
  1628. // set default PDF version number
  1629. $this->PDFVersion = '1.7';
  1630. $this->encoding = $encoding;
  1631. $this->HREF = array();
  1632. $this->getFontsList();
  1633. $this->fgcolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1634. $this->strokecolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1635. $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255);
  1636. $this->extgstates = array();
  1637. // user's rights
  1638. $this->sign = false;
  1639. $this->ur['enabled'] = false;
  1640. $this->ur['document'] = '/FullSave';
  1641. $this->ur['annots'] = '/Create/Delete/Modify/Copy/Import/Export';
  1642. $this->ur['form'] = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1643. $this->ur['signature'] = '/Modify';
  1644. $this->ur['ef'] = '/Create/Delete/Modify/Import';
  1645. $this->ur['formex'] = '';
  1646. $this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
  1647. // set default JPEG quality
  1648. $this->jpeg_quality = 75;
  1649. // initialize some settings
  1650. $this->utf8Bidi(array(''), '');
  1651. // set default font
  1652. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  1653. // check if PCRE Unicode support is enabled
  1654. if ($this->isunicode AND (@preg_match('/\pL/u', 'a') == 1)) {
  1655. // PCRE unicode support is turned ON
  1656. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  1657. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  1658. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  1659. //$this->setSpacesRE('/[^\S\P{Z}\P{Lo}\xa0]/u');
  1660. $this->setSpacesRE('/[^\S\P{Z}\xa0]/u');
  1661. } else {
  1662. // PCRE unicode support is turned OFF
  1663. $this->setSpacesRE('/[^\S\xa0]/');
  1664. }
  1665. $this->default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1666. // set file ID for trailer
  1667. $this->file_id = md5($this->getRandomSeed('TCPDF'.$orientation.$unit.$format.$encoding));
  1668. // get default graphic vars
  1669. $this->default_graphic_vars = $this->getGraphicVars();
  1670. }
  1671. /**
  1672. * Default destructor.
  1673. * @public
  1674. * @since 1.53.0.TC016
  1675. */
  1676. public function __destruct() {
  1677. // restore internal encoding
  1678. if (isset($this->internal_encoding) AND !empty($this->internal_encoding)) {
  1679. mb_internal_encoding($this->internal_encoding);
  1680. }
  1681. // unset all class variables
  1682. $this->_destroy(true);
  1683. }
  1684. /**
  1685. * Return the current TCPDF version.
  1686. * @return TCPDF version string
  1687. * @public
  1688. * @since 5.9.012 (2010-11-10)
  1689. */
  1690. public function getTCPDFVersion() {
  1691. return $this->tcpdf_version;
  1692. }
  1693. /**
  1694. * Set the units of measure for the document.
  1695. * @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.
  1696. * @public
  1697. * @since 3.0.015 (2008-06-06)
  1698. */
  1699. public function setPageUnit($unit) {
  1700. $unit = strtolower($unit);
  1701. //Set scale factor
  1702. switch ($unit) {
  1703. // points
  1704. case 'px':
  1705. case 'pt': {
  1706. $this->k = 1;
  1707. break;
  1708. }
  1709. // millimeters
  1710. case 'mm': {
  1711. $this->k = $this->dpi / 25.4;
  1712. break;
  1713. }
  1714. // centimeters
  1715. case 'cm': {
  1716. $this->k = $this->dpi / 2.54;
  1717. break;
  1718. }
  1719. // inches
  1720. case 'in': {
  1721. $this->k = $this->dpi;
  1722. break;
  1723. }
  1724. // unsupported unit
  1725. default : {
  1726. $this->Error('Incorrect unit: '.$unit);
  1727. break;
  1728. }
  1729. }
  1730. $this->pdfunit = $unit;
  1731. if (isset($this->CurOrientation)) {
  1732. $this->setPageOrientation($this->CurOrientation);
  1733. }
  1734. }
  1735. /**
  1736. * Get page dimensions from format name.
  1737. * @param $format (mixed) The format name. It can be: <ul>
  1738. * <li><b>ISO 216 A Series + 2 SIS 014711 extensions</b></li>
  1739. * <li>A0 (841x1189 mm ; 33.11x46.81 in)</li>
  1740. * <li>A1 (594x841 mm ; 23.39x33.11 in)</li>
  1741. * <li>A2 (420x594 mm ; 16.54x23.39 in)</li>
  1742. * <li>A3 (297x420 mm ; 11.69x16.54 in)</li>
  1743. * <li>A4 (210x297 mm ; 8.27x11.69 in)</li>
  1744. * <li>A5 (148x210 mm ; 5.83x8.27 in)</li>
  1745. * <li>A6 (105x148 mm ; 4.13x5.83 in)</li>
  1746. * <li>A7 (74x105 mm ; 2.91x4.13 in)</li>
  1747. * <li>A8 (52x74 mm ; 2.05x2.91 in)</li>
  1748. * <li>A9 (37x52 mm ; 1.46x2.05 in)</li>
  1749. * <li>A10 (26x37 mm ; 1.02x1.46 in)</li>
  1750. * <li>A11 (18x26 mm ; 0.71x1.02 in)</li>
  1751. * <li>A12 (13x18 mm ; 0.51x0.71 in)</li>
  1752. * <li><b>ISO 216 B Series + 2 SIS 014711 extensions</b></li>
  1753. * <li>B0 (1000x1414 mm ; 39.37x55.67 in)</li>
  1754. * <li>B1 (707x1000 mm ; 27.83x39.37 in)</li>
  1755. * <li>B2 (500x707 mm ; 19.69x27.83 in)</li>
  1756. * <li>B3 (353x500 mm ; 13.90x19.69 in)</li>
  1757. * <li>B4 (250x353 mm ; 9.84x13.90 in)</li>
  1758. * <li>B5 (176x250 mm ; 6.93x9.84 in)</li>
  1759. * <li>B6 (125x176 mm ; 4.92x6.93 in)</li>
  1760. * <li>B7 (88x125 mm ; 3.46x4.92 in)</li>
  1761. * <li>B8 (62x88 mm ; 2.44x3.46 in)</li>
  1762. * <li>B9 (44x62 mm ; 1.73x2.44 in)</li>
  1763. * <li>B10 (31x44 mm ; 1.22x1.73 in)</li>
  1764. * <li>B11 (22x31 mm ; 0.87x1.22 in)</li>
  1765. * <li>B12 (15x22 mm ; 0.59x0.87 in)</li>
  1766. * <li><b>ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION</b></li>
  1767. * <li>C0 (917x1297 mm ; 36.10x51.06 in)</li>
  1768. * <li>C1 (648x917 mm ; 25.51x36.10 in)</li>
  1769. * <li>C2 (458x648 mm ; 18.03x25.51 in)</li>
  1770. * <li>C3 (324x458 mm ; 12.76x18.03 in)</li>
  1771. * <li>C4 (229x324 mm ; 9.02x12.76 in)</li>
  1772. * <li>C5 (162x229 mm ; 6.38x9.02 in)</li>
  1773. * <li>C6 (114x162 mm ; 4.49x6.38 in)</li>
  1774. * <li>C7 (81x114 mm ; 3.19x4.49 in)</li>
  1775. * <li>C8 (57x81 mm ; 2.24x3.19 in)</li>
  1776. * <li>C9 (40x57 mm ; 1.57x2.24 in)</li>
  1777. * <li>C10 (28x40 mm ; 1.10x1.57 in)</li>
  1778. * <li>C11 (20x28 mm ; 0.79x1.10 in)</li>
  1779. * <li>C12 (14x20 mm ; 0.55x0.79 in)</li>
  1780. * <li>C76 (81x162 mm ; 3.19x6.38 in)</li>
  1781. * <li>DL (110x220 mm ; 4.33x8.66 in)</li>
  1782. * <li><b>SIS 014711 E Series</b></li>
  1783. * <li>E0 (879x1241 mm ; 34.61x48.86 in)</li>
  1784. * <li>E1 (620x879 mm ; 24.41x34.61 in)</li>
  1785. * <li>E2 (440x620 mm ; 17.32x24.41 in)</li>
  1786. * <li>E3 (310x440 mm ; 12.20x17.32 in)</li>
  1787. * <li>E4 (220x310 mm ; 8.66x12.20 in)</li>
  1788. * <li>E5 (155x220 mm ; 6.10x8.66 in)</li>
  1789. * <li>E6 (110x155 mm ; 4.33x6.10 in)</li>
  1790. * <li>E7 (78x110 mm ; 3.07x4.33 in)</li>
  1791. * <li>E8 (55x78 mm ; 2.17x3.07 in)</li>
  1792. * <li>E9 (39x55 mm ; 1.54x2.17 in)</li>
  1793. * <li>E10 (27x39 mm ; 1.06x1.54 in)</li>
  1794. * <li>E11 (19x27 mm ; 0.75x1.06 in)</li>
  1795. * <li>E12 (13x19 mm ; 0.51x0.75 in)</li>
  1796. * <li><b>SIS 014711 G Series</b></li>
  1797. * <li>G0 (958x1354 mm ; 37.72x53.31 in)</li>
  1798. * <li>G1 (677x958 mm ; 26.65x37.72 in)</li>
  1799. * <li>G2 (479x677 mm ; 18.86x26.65 in)</li>
  1800. * <li>G3 (338x479 mm ; 13.31x18.86 in)</li>
  1801. * <li>G4 (239x338 mm ; 9.41x13.31 in)</li>
  1802. * <li>G5 (169x239 mm ; 6.65x9.41 in)</li>
  1803. * <li>G6 (119x169 mm ; 4.69x6.65 in)</li>
  1804. * <li>G7 (84x119 mm ; 3.31x4.69 in)</li>
  1805. * <li>G8 (59x84 mm ; 2.32x3.31 in)</li>
  1806. * <li>G9 (42x59 mm ; 1.65x2.32 in)</li>
  1807. * <li>G10 (29x42 mm ; 1.14x1.65 in)</li>
  1808. * <li>G11 (21x29 mm ; 0.83x1.14 in)</li>
  1809. * <li>G12 (14x21 mm ; 0.55x0.83 in)</li>
  1810. * <li><b>ISO Press</b></li>
  1811. * <li>RA0 (860x1220 mm ; 33.86x48.03 in)</li>
  1812. * <li>RA1 (610x860 mm ; 24.02x33.86 in)</li>
  1813. * <li>RA2 (430x610 mm ; 16.93x24.02 in)</li>
  1814. * <li>RA3 (305x430 mm ; 12.01x16.93 in)</li>
  1815. * <li>RA4 (215x305 mm ; 8.46x12.01 in)</li>
  1816. * <li>SRA0 (900x1280 mm ; 35.43x50.39 in)</li>
  1817. * <li>SRA1 (640x900 mm ; 25.20x35.43 in)</li>
  1818. * <li>SRA2 (450x640 mm ; 17.72x25.20 in)</li>
  1819. * <li>SRA3 (320x450 mm ; 12.60x17.72 in)</li>
  1820. * <li>SRA4 (225x320 mm ; 8.86x12.60 in)</li>
  1821. * <li><b>German DIN 476</b></li>
  1822. * <li>4A0 (1682x2378 mm ; 66.22x93.62 in)</li>
  1823. * <li>2A0 (1189x1682 mm ; 46.81x66.22 in)</li>
  1824. * <li><b>Variations on the ISO Standard</b></li>
  1825. * <li>A2_EXTRA (445x619 mm ; 17.52x24.37 in)</li>
  1826. * <li>A3+ (329x483 mm ; 12.95x19.02 in)</li>
  1827. * <li>A3_EXTRA (322x445 mm ; 12.68x17.52 in)</li>
  1828. * <li>A3_SUPER (305x508 mm ; 12.01x20.00 in)</li>
  1829. * <li>SUPER_A3 (305x487 mm ; 12.01x19.17 in)</li>
  1830. * <li>A4_EXTRA (235x322 mm ; 9.25x12.68 in)</li>
  1831. * <li>A4_SUPER (229x322 mm ; 9.02x12.68 in)</li>
  1832. * <li>SUPER_A4 (227x356 mm ; 8.94x14.02 in)</li>
  1833. * <li>A4_LONG (210x348 mm ; 8.27x13.70 in)</li>
  1834. * <li>F4 (210x330 mm ; 8.27x12.99 in)</li>
  1835. * <li>SO_B5_EXTRA (202x276 mm ; 7.95x10.87 in)</li>
  1836. * <li>A5_EXTRA (173x235 mm ; 6.81x9.25 in)</li>
  1837. * <li><b>ANSI Series</b></li>
  1838. * <li>ANSI_E (864x1118 mm ; 34.00x44.00 in)</li>
  1839. * <li>ANSI_D (559x864 mm ; 22.00x34.00 in)</li>
  1840. * <li>ANSI_C (432x559 mm ; 17.00x22.00 in)</li>
  1841. * <li>ANSI_B (279x432 mm ; 11.00x17.00 in)</li>
  1842. * <li>ANSI_A (216x279 mm ; 8.50x11.00 in)</li>
  1843. * <li><b>Traditional 'Loose' North American Paper Sizes</b></li>
  1844. * <li>LEDGER, USLEDGER (432x279 mm ; 17.00x11.00 in)</li>
  1845. * <li>TABLOID, USTABLOID, BIBLE, ORGANIZERK (279x432 mm ; 11.00x17.00 in)</li>
  1846. * <li>LETTER, USLETTER, ORGANIZERM (216x279 mm ; 8.50x11.00 in)</li>
  1847. * <li>LEGAL, USLEGAL (216x356 mm ; 8.50x14.00 in)</li>
  1848. * <li>GLETTER, GOVERNMENTLETTER (203x267 mm ; 8.00x10.50 in)</li>
  1849. * <li>JLEGAL, JUNIORLEGAL (203x127 mm ; 8.00x5.00 in)</li>
  1850. * <li><b>Other North American Paper Sizes</b></li>
  1851. * <li>QUADDEMY (889x1143 mm ; 35.00x45.00 in)</li>
  1852. * <li>SUPER_B (330x483 mm ; 13.00x19.00 in)</li>
  1853. * <li>QUARTO (229x279 mm ; 9.00x11.00 in)</li>
  1854. * <li>FOLIO, GOVERNMENTLEGAL (216x330 mm ; 8.50x13.00 in)</li>
  1855. * <li>EXECUTIVE, MONARCH (184x267 mm ; 7.25x10.50 in)</li>
  1856. * <li>MEMO, STATEMENT, ORGANIZERL (140x216 mm ; 5.50x8.50 in)</li>
  1857. * <li>FOOLSCAP (210x330 mm ; 8.27x13.00 in)</li>
  1858. * <li>COMPACT (108x171 mm ; 4.25x6.75 in)</li>
  1859. * <li>ORGANIZERJ (70x127 mm ; 2.75x5.00 in)</li>
  1860. * <li><b>Canadian standard CAN 2-9.60M</b></li>
  1861. * <li>P1 (560x860 mm ; 22.05x33.86 in)</li>
  1862. * <li>P2 (430x560 mm ; 16.93x22.05 in)</li>
  1863. * <li>P3 (280x430 mm ; 11.02x16.93 in)</li>
  1864. * <li>P4 (215x280 mm ; 8.46x11.02 in)</li>
  1865. * <li>P5 (140x215 mm ; 5.51x8.46 in)</li>
  1866. * <li>P6 (107x140 mm ; 4.21x5.51 in)</li>
  1867. * <li><b>North American Architectural Sizes</b></li>
  1868. * <li>ARCH_E (914x1219 mm ; 36.00x48.00 in)</li>
  1869. * <li>ARCH_E1 (762x1067 mm ; 30.00x42.00 in)</li>
  1870. * <li>ARCH_D (610x914 mm ; 24.00x36.00 in)</li>
  1871. * <li>ARCH_C, BROADSHEET (457x610 mm ; 18.00x24.00 in)</li>
  1872. * <li>ARCH_B (305x457 mm ; 12.00x18.00 in)</li>
  1873. * <li>ARCH_A (229x305 mm ; 9.00x12.00 in)</li>
  1874. * <li><b>Announcement Envelopes</b></li>
  1875. * <li>ANNENV_A2 (111x146 mm ; 4.37x5.75 in)</li>
  1876. * <li>ANNENV_A6 (121x165 mm ; 4.75x6.50 in)</li>
  1877. * <li>ANNENV_A7 (133x184 mm ; 5.25x7.25 in)</li>
  1878. * <li>ANNENV_A8 (140x206 mm ; 5.50x8.12 in)</li>
  1879. * <li>ANNENV_A10 (159x244 mm ; 6.25x9.62 in)</li>
  1880. * <li>ANNENV_SLIM (98x225 mm ; 3.87x8.87 in)</li>
  1881. * <li><b>Commercial Envelopes</b></li>
  1882. * <li>COMMENV_N6_1/4 (89x152 mm ; 3.50x6.00 in)</li>
  1883. * <li>COMMENV_N6_3/4 (92x165 mm ; 3.62x6.50 in)</li>
  1884. * <li>COMMENV_N8 (98x191 mm ; 3.87x7.50 in)</li>
  1885. * <li>COMMENV_N9 (98x225 mm ; 3.87x8.87 in)</li>
  1886. * <li>COMMENV_N10 (105x241 mm ; 4.12x9.50 in)</li>
  1887. * <li>COMMENV_N11 (114x263 mm ; 4.50x10.37 in)</li>
  1888. * <li>COMMENV_N12 (121x279 mm ; 4.75x11.00 in)</li>
  1889. * <li>COMMENV_N14 (127x292 mm ; 5.00x11.50 in)</li>
  1890. * <li><b>Catalogue Envelopes</b></li>
  1891. * <li>CATENV_N1 (152x229 mm ; 6.00x9.00 in)</li>
  1892. * <li>CATENV_N1_3/4 (165x241 mm ; 6.50x9.50 in)</li>
  1893. * <li>CATENV_N2 (165x254 mm ; 6.50x10.00 in)</li>
  1894. * <li>CATENV_N3 (178x254 mm ; 7.00x10.00 in)</li>
  1895. * <li>CATENV_N6 (191x267 mm ; 7.50x10.50 in)</li>
  1896. * <li>CATENV_N7 (203x279 mm ; 8.00x11.00 in)</li>
  1897. * <li>CATENV_N8 (210x286 mm ; 8.25x11.25 in)</li>
  1898. * <li>CATENV_N9_1/2 (216x267 mm ; 8.50x10.50 in)</li>
  1899. * <li>CATENV_N9_3/4 (222x286 mm ; 8.75x11.25 in)</li>
  1900. * <li>CATENV_N10_1/2 (229x305 mm ; 9.00x12.00 in)</li>
  1901. * <li>CATENV_N12_1/2 (241x318 mm ; 9.50x12.50 in)</li>
  1902. * <li>CATENV_N13_1/2 (254x330 mm ; 10.00x13.00 in)</li>
  1903. * <li>CATENV_N14_1/4 (286x311 mm ; 11.25x12.25 in)</li>
  1904. * <li>CATENV_N14_1/2 (292x368 mm ; 11.50x14.50 in)</li>
  1905. * <li><b>Japanese (JIS P 0138-61) Standard B-Series</b></li>
  1906. * <li>JIS_B0 (1030x1456 mm ; 40.55x57.32 in)</li>
  1907. * <li>JIS_B1 (728x1030 mm ; 28.66x40.55 in)</li>
  1908. * <li>JIS_B2 (515x728 mm ; 20.28x28.66 in)</li>
  1909. * <li>JIS_B3 (364x515 mm ; 14.33x20.28 in)</li>
  1910. * <li>JIS_B4 (257x364 mm ; 10.12x14.33 in)</li>
  1911. * <li>JIS_B5 (182x257 mm ; 7.17x10.12 in)</li>
  1912. * <li>JIS_B6 (128x182 mm ; 5.04x7.17 in)</li>
  1913. * <li>JIS_B7 (91x128 mm ; 3.58x5.04 in)</li>
  1914. * <li>JIS_B8 (64x91 mm ; 2.52x3.58 in)</li>
  1915. * <li>JIS_B9 (45x64 mm ; 1.77x2.52 in)</li>
  1916. * <li>JIS_B10 (32x45 mm ; 1.26x1.77 in)</li>
  1917. * <li>JIS_B11 (22x32 mm ; 0.87x1.26 in)</li>
  1918. * <li>JIS_B12 (16x22 mm ; 0.63x0.87 in)</li>
  1919. * <li><b>PA Series</b></li>
  1920. * <li>PA0 (840x1120 mm ; 33.07x44.09 in)</li>
  1921. * <li>PA1 (560x840 mm ; 22.05x33.07 in)</li>
  1922. * <li>PA2 (420x560 mm ; 16.54x22.05 in)</li>
  1923. * <li>PA3 (280x420 mm ; 11.02x16.54 in)</li>
  1924. * <li>PA4 (210x280 mm ; 8.27x11.02 in)</li>
  1925. * <li>PA5 (140x210 mm ; 5.51x8.27 in)</li>
  1926. * <li>PA6 (105x140 mm ; 4.13x5.51 in)</li>
  1927. * <li>PA7 (70x105 mm ; 2.76x4.13 in)</li>
  1928. * <li>PA8 (52x70 mm ; 2.05x2.76 in)</li>
  1929. * <li>PA9 (35x52 mm ; 1.38x2.05 in)</li>
  1930. * <li>PA10 (26x35 mm ; 1.02x1.38 in)</li>
  1931. * <li><b>Standard Photographic Print Sizes</b></li>
  1932. * <li>PASSPORT_PHOTO (35x45 mm ; 1.38x1.77 in)</li>
  1933. * <li>E (82x120 mm ; 3.25x4.72 in)</li>
  1934. * <li>3R, L (89x127 mm ; 3.50x5.00 in)</li>
  1935. * <li>4R, KG (102x152 mm ; 4.02x5.98 in)</li>
  1936. * <li>4D (120x152 mm ; 4.72x5.98 in)</li>
  1937. * <li>5R, 2L (127x178 mm ; 5.00x7.01 in)</li>
  1938. * <li>6R, 8P (152x203 mm ; 5.98x7.99 in)</li>
  1939. * <li>8R, 6P (203x254 mm ; 7.99x10.00 in)</li>
  1940. * <li>S8R, 6PW (203x305 mm ; 7.99x12.01 in)</li>
  1941. * <li>10R, 4P (254x305 mm ; 10.00x12.01 in)</li>
  1942. * <li>S10R, 4PW (254x381 mm ; 10.00x15.00 in)</li>
  1943. * <li>11R (279x356 mm ; 10.98x14.02 in)</li>
  1944. * <li>S11R (279x432 mm ; 10.98x17.01 in)</li>
  1945. * <li>12R (305x381 mm ; 12.01x15.00 in)</li>
  1946. * <li>S12R (305x456 mm ; 12.01x17.95 in)</li>
  1947. * <li><b>Common Newspaper Sizes</b></li>
  1948. * <li>NEWSPAPER_BROADSHEET (750x600 mm ; 29.53x23.62 in)</li>
  1949. * <li>NEWSPAPER_BERLINER (470x315 mm ; 18.50x12.40 in)</li>
  1950. * <li>NEWSPAPER_COMPACT, NEWSPAPER_TABLOID (430x280 mm ; 16.93x11.02 in)</li>
  1951. * <li><b>Business Cards</b></li>
  1952. * <li>CREDIT_CARD, BUSINESS_CARD, BUSINESS_CARD_ISO7810 (54x86 mm ; 2.13x3.37 in)</li>
  1953. * <li>BUSINESS_CARD_ISO216 (52x74 mm ; 2.05x2.91 in)</li>
  1954. * <li>BUSINESS_CARD_IT, BUSINESS_CARD_UK, BUSINESS_CARD_FR, BUSINESS_CARD_DE, BUSINESS_CARD_ES (55x85 mm ; 2.17x3.35 in)</li>
  1955. * <li>BUSINESS_CARD_US, BUSINESS_CARD_CA (51x89 mm ; 2.01x3.50 in)</li>
  1956. * <li>BUSINESS_CARD_JP (55x91 mm ; 2.17x3.58 in)</li>
  1957. * <li>BUSINESS_CARD_HK (54x90 mm ; 2.13x3.54 in)</li>
  1958. * <li>BUSINESS_CARD_AU, BUSINESS_CARD_DK, BUSINESS_CARD_SE (55x90 mm ; 2.17x3.54 in)</li>
  1959. * <li>BUSINESS_CARD_RU, BUSINESS_CARD_CZ, BUSINESS_CARD_FI, BUSINESS_CARD_HU, BUSINESS_CARD_IL (50x90 mm ; 1.97x3.54 in)</li>
  1960. * <li><b>Billboards</b></li>
  1961. * <li>4SHEET (1016x1524 mm ; 40.00x60.00 in)</li>
  1962. * <li>6SHEET (1200x1800 mm ; 47.24x70.87 in)</li>
  1963. * <li>12SHEET (3048x1524 mm ; 120.00x60.00 in)</li>
  1964. * <li>16SHEET (2032x3048 mm ; 80.00x120.00 in)</li>
  1965. * <li>32SHEET (4064x3048 mm ; 160.00x120.00 in)</li>
  1966. * <li>48SHEET (6096x3048 mm ; 240.00x120.00 in)</li>
  1967. * <li>64SHEET (8128x3048 mm ; 320.00x120.00 in)</li>
  1968. * <li>96SHEET (12192x3048 mm ; 480.00x120.00 in)</li>
  1969. * <li><b>Old Imperial English (some are still used in USA)</b></li>
  1970. * <li>EN_EMPEROR (1219x1829 mm ; 48.00x72.00 in)</li>
  1971. * <li>EN_ANTIQUARIAN (787x1346 mm ; 31.00x53.00 in)</li>
  1972. * <li>EN_GRAND_EAGLE (730x1067 mm ; 28.75x42.00 in)</li>
  1973. * <li>EN_DOUBLE_ELEPHANT (679x1016 mm ; 26.75x40.00 in)</li>
  1974. * <li>EN_ATLAS (660x864 mm ; 26.00x34.00 in)</li>
  1975. * <li>EN_COLOMBIER (597x876 mm ; 23.50x34.50 in)</li>
  1976. * <li>EN_ELEPHANT (584x711 mm ; 23.00x28.00 in)</li>
  1977. * <li>EN_DOUBLE_DEMY (572x902 mm ; 22.50x35.50 in)</li>
  1978. * <li>EN_IMPERIAL (559x762 mm ; 22.00x30.00 in)</li>
  1979. * <li>EN_PRINCESS (546x711 mm ; 21.50x28.00 in)</li>
  1980. * <li>EN_CARTRIDGE (533x660 mm ; 21.00x26.00 in)</li>
  1981. * <li>EN_DOUBLE_LARGE_POST (533x838 mm ; 21.00x33.00 in)</li>
  1982. * <li>EN_ROYAL (508x635 mm ; 20.00x25.00 in)</li>
  1983. * <li>EN_SHEET, EN_HALF_POST (495x597 mm ; 19.50x23.50 in)</li>
  1984. * <li>EN_SUPER_ROYAL (483x686 mm ; 19.00x27.00 in)</li>
  1985. * <li>EN_DOUBLE_POST (483x775 mm ; 19.00x30.50 in)</li>
  1986. * <li>EN_MEDIUM (445x584 mm ; 17.50x23.00 in)</li>
  1987. * <li>EN_DEMY (445x572 mm ; 17.50x22.50 in)</li>
  1988. * <li>EN_LARGE_POST (419x533 mm ; 16.50x21.00 in)</li>
  1989. * <li>EN_COPY_DRAUGHT (406x508 mm ; 16.00x20.00 in)</li>
  1990. * <li>EN_POST (394x489 mm ; 15.50x19.25 in)</li>
  1991. * <li>EN_CROWN (381x508 mm ; 15.00x20.00 in)</li>
  1992. * <li>EN_PINCHED_POST (375x470 mm ; 14.75x18.50 in)</li>
  1993. * <li>EN_BRIEF (343x406 mm ; 13.50x16.00 in)</li>
  1994. * <li>EN_FOOLSCAP (343x432 mm ; 13.50x17.00 in)</li>
  1995. * <li>EN_SMALL_FOOLSCAP (337x419 mm ; 13.25x16.50 in)</li>
  1996. * <li>EN_POTT (318x381 mm ; 12.50x15.00 in)</li>
  1997. * <li><b>Old Imperial Belgian</b></li>
  1998. * <li>BE_GRAND_AIGLE (700x1040 mm ; 27.56x40.94 in)</li>
  1999. * <li>BE_COLOMBIER (620x850 mm ; 24.41x33.46 in)</li>
  2000. * <li>BE_DOUBLE_CARRE (620x920 mm ; 24.41x36.22 in)</li>
  2001. * <li>BE_ELEPHANT (616x770 mm ; 24.25x30.31 in)</li>
  2002. * <li>BE_PETIT_AIGLE (600x840 mm ; 23.62x33.07 in)</li>
  2003. * <li>BE_GRAND_JESUS (550x730 mm ; 21.65x28.74 in)</li>
  2004. * <li>BE_JESUS (540x730 mm ; 21.26x28.74 in)</li>
  2005. * <li>BE_RAISIN (500x650 mm ; 19.69x25.59 in)</li>
  2006. * <li>BE_GRAND_MEDIAN (460x605 mm ; 18.11x23.82 in)</li>
  2007. * <li>BE_DOUBLE_POSTE (435x565 mm ; 17.13x22.24 in)</li>
  2008. * <li>BE_COQUILLE (430x560 mm ; 16.93x22.05 in)</li>
  2009. * <li>BE_PETIT_MEDIAN (415x530 mm ; 16.34x20.87 in)</li>
  2010. * <li>BE_RUCHE (360x460 mm ; 14.17x18.11 in)</li>
  2011. * <li>BE_PROPATRIA (345x430 mm ; 13.58x16.93 in)</li>
  2012. * <li>BE_LYS (317x397 mm ; 12.48x15.63 in)</li>
  2013. * <li>BE_POT (307x384 mm ; 12.09x15.12 in)</li>
  2014. * <li>BE_ROSETTE (270x347 mm ; 10.63x13.66 in)</li>
  2015. * <li><b>Old Imperial French</b></li>
  2016. * <li>FR_UNIVERS (1000x1300 mm ; 39.37x51.18 in)</li>
  2017. * <li>FR_DOUBLE_COLOMBIER (900x1260 mm ; 35.43x49.61 in)</li>
  2018. * <li>FR_GRANDE_MONDE (900x1260 mm ; 35.43x49.61 in)</li>
  2019. * <li>FR_DOUBLE_SOLEIL (800x1200 mm ; 31.50x47.24 in)</li>
  2020. * <li>FR_DOUBLE_JESUS (760x1120 mm ; 29.92x44.09 in)</li>
  2021. * <li>FR_GRAND_AIGLE (750x1060 mm ; 29.53x41.73 in)</li>
  2022. * <li>FR_PETIT_AIGLE (700x940 mm ; 27.56x37.01 in)</li>
  2023. * <li>FR_DOUBLE_RAISIN (650x1000 mm ; 25.59x39.37 in)</li>
  2024. * <li>FR_JOURNAL (650x940 mm ; 25.59x37.01 in)</li>
  2025. * <li>FR_COLOMBIER_AFFICHE (630x900 mm ; 24.80x35.43 in)</li>
  2026. * <li>FR_DOUBLE_CAVALIER (620x920 mm ; 24.41x36.22 in)</li>
  2027. * <li>FR_CLOCHE (600x800 mm ; 23.62x31.50 in)</li>
  2028. * <li>FR_SOLEIL (600x800 mm ; 23.62x31.50 in)</li>
  2029. * <li>FR_DOUBLE_CARRE (560x900 mm ; 22.05x35.43 in)</li>
  2030. * <li>FR_DOUBLE_COQUILLE (560x880 mm ; 22.05x34.65 in)</li>
  2031. * <li>FR_JESUS (560x760 mm ; 22.05x29.92 in)</li>
  2032. * <li>FR_RAISIN (500x650 mm ; 19.69x25.59 in)</li>
  2033. * <li>FR_CAVALIER (460x620 mm ; 18.11x24.41 in)</li>
  2034. * <li>FR_DOUBLE_COURONNE (460x720 mm ; 18.11x28.35 in)</li>
  2035. * <li>FR_CARRE (450x560 mm ; 17.72x22.05 in)</li>
  2036. * <li>FR_COQUILLE (440x560 mm ; 17.32x22.05 in)</li>
  2037. * <li>FR_DOUBLE_TELLIERE (440x680 mm ; 17.32x26.77 in)</li>
  2038. * <li>FR_DOUBLE_CLOCHE (400x600 mm ; 15.75x23.62 in)</li>
  2039. * <li>FR_DOUBLE_POT (400x620 mm ; 15.75x24.41 in)</li>
  2040. * <li>FR_ECU (400x520 mm ; 15.75x20.47 in)</li>
  2041. * <li>FR_COURONNE (360x460 mm ; 14.17x18.11 in)</li>
  2042. * <li>FR_TELLIERE (340x440 mm ; 13.39x17.32 in)</li>
  2043. * <li>FR_POT (310x400 mm ; 12.20x15.75 in)</li>
  2044. * </ul>
  2045. * @return array containing page width and height in points
  2046. * @public
  2047. * @since 5.0.010 (2010-05-17)
  2048. */
  2049. public function getPageSizeFromFormat($format) {
  2050. // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 25.4 mm)
  2051. switch (strtoupper($format)) {
  2052. // ISO 216 A Series + 2 SIS 014711 extensions
  2053. case 'A0' : {$pf = array( 2383.937, 3370.394); break;}
  2054. case 'A1' : {$pf = array( 1683.780, 2383.937); break;}
  2055. case 'A2' : {$pf = array( 1190.551, 1683.780); break;}
  2056. case 'A3' : {$pf = array( 841.890, 1190.551); break;}
  2057. case 'A4' : {$pf = array( 595.276, 841.890); break;}
  2058. case 'A5' : {$pf = array( 419.528, 595.276); break;}
  2059. case 'A6' : {$pf = array( 297.638, 419.528); break;}
  2060. case 'A7' : {$pf = array( 209.764, 297.638); break;}
  2061. case 'A8' : {$pf = array( 147.402, 209.764); break;}
  2062. case 'A9' : {$pf = array( 104.882, 147.402); break;}
  2063. case 'A10': {$pf = array( 73.701, 104.882); break;}
  2064. case 'A11': {$pf = array( 51.024, 73.701); break;}
  2065. case 'A12': {$pf = array( 36.850, 51.024); break;}
  2066. // ISO 216 B Series + 2 SIS 014711 extensions
  2067. case 'B0' : {$pf = array( 2834.646, 4008.189); break;}
  2068. case 'B1' : {$pf = array( 2004.094, 2834.646); break;}
  2069. case 'B2' : {$pf = array( 1417.323, 2004.094); break;}
  2070. case 'B3' : {$pf = array( 1000.630, 1417.323); break;}
  2071. case 'B4' : {$pf = array( 708.661, 1000.630); break;}
  2072. case 'B5' : {$pf = array( 498.898, 708.661); break;}
  2073. case 'B6' : {$pf = array( 354.331, 498.898); break;}
  2074. case 'B7' : {$pf = array( 249.449, 354.331); break;}
  2075. case 'B8' : {$pf = array( 175.748, 249.449); break;}
  2076. case 'B9' : {$pf = array( 124.724, 175.748); break;}
  2077. case 'B10': {$pf = array( 87.874, 124.724); break;}
  2078. case 'B11': {$pf = array( 62.362, 87.874); break;}
  2079. case 'B12': {$pf = array( 42.520, 62.362); break;}
  2080. // ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION
  2081. case 'C0' : {$pf = array( 2599.370, 3676.535); break;}
  2082. case 'C1' : {$pf = array( 1836.850, 2599.370); break;}
  2083. case 'C2' : {$pf = array( 1298.268, 1836.850); break;}
  2084. case 'C3' : {$pf = array( 918.425, 1298.268); break;}
  2085. case 'C4' : {$pf = array( 649.134, 918.425); break;}
  2086. case 'C5' : {$pf = array( 459.213, 649.134); break;}
  2087. case 'C6' : {$pf = array( 323.150, 459.213); break;}
  2088. case 'C7' : {$pf = array( 229.606, 323.150); break;}
  2089. case 'C8' : {$pf = array( 161.575, 229.606); break;}
  2090. case 'C9' : {$pf = array( 113.386, 161.575); break;}
  2091. case 'C10': {$pf = array( 79.370, 113.386); break;}
  2092. case 'C11': {$pf = array( 56.693, 79.370); break;}
  2093. case 'C12': {$pf = array( 39.685, 56.693); break;}
  2094. case 'C76': {$pf = array( 229.606, 459.213); break;}
  2095. case 'DL' : {$pf = array( 311.811, 623.622); break;}
  2096. // SIS 014711 E Series
  2097. case 'E0' : {$pf = array( 2491.654, 3517.795); break;}
  2098. case 'E1' : {$pf = array( 1757.480, 2491.654); break;}
  2099. case 'E2' : {$pf = array( 1247.244, 1757.480); break;}
  2100. case 'E3' : {$pf = array( 878.740, 1247.244); break;}
  2101. case 'E4' : {$pf = array( 623.622, 878.740); break;}
  2102. case 'E5' : {$pf = array( 439.370, 623.622); break;}
  2103. case 'E6' : {$pf = array( 311.811, 439.370); break;}
  2104. case 'E7' : {$pf = array( 221.102, 311.811); break;}
  2105. case 'E8' : {$pf = array( 155.906, 221.102); break;}
  2106. case 'E9' : {$pf = array( 110.551, 155.906); break;}
  2107. case 'E10': {$pf = array( 76.535, 110.551); break;}
  2108. case 'E11': {$pf = array( 53.858, 76.535); break;}
  2109. case 'E12': {$pf = array( 36.850, 53.858); break;}
  2110. // SIS 014711 G Series
  2111. case 'G0' : {$pf = array( 2715.591, 3838.110); break;}
  2112. case 'G1' : {$pf = array( 1919.055, 2715.591); break;}
  2113. case 'G2' : {$pf = array( 1357.795, 1919.055); break;}
  2114. case 'G3' : {$pf = array( 958.110, 1357.795); break;}
  2115. case 'G4' : {$pf = array( 677.480, 958.110); break;}
  2116. case 'G5' : {$pf = array( 479.055, 677.480); break;}
  2117. case 'G6' : {$pf = array( 337.323, 479.055); break;}
  2118. case 'G7' : {$pf = array( 238.110, 337.323); break;}
  2119. case 'G8' : {$pf = array( 167.244, 238.110); break;}
  2120. case 'G9' : {$pf = array( 119.055, 167.244); break;}
  2121. case 'G10': {$pf = array( 82.205, 119.055); break;}
  2122. case 'G11': {$pf = array( 59.528, 82.205); break;}
  2123. case 'G12': {$pf = array( 39.685, 59.528); break;}
  2124. // ISO Press
  2125. case 'RA0': {$pf = array( 2437.795, 3458.268); break;}
  2126. case 'RA1': {$pf = array( 1729.134, 2437.795); break;}
  2127. case 'RA2': {$pf = array( 1218.898, 1729.134); break;}
  2128. case 'RA3': {$pf = array( 864.567, 1218.898); break;}
  2129. case 'RA4': {$pf = array( 609.449, 864.567); break;}
  2130. case 'SRA0': {$pf = array( 2551.181, 3628.346); break;}
  2131. case 'SRA1': {$pf = array( 1814.173, 2551.181); break;}
  2132. case 'SRA2': {$pf = array( 1275.591, 1814.173); break;}
  2133. case 'SRA3': {$pf = array( 907.087, 1275.591); break;}
  2134. case 'SRA4': {$pf = array( 637.795, 907.087); break;}
  2135. // German DIN 476
  2136. case '4A0': {$pf = array( 4767.874, 6740.787); break;}
  2137. case '2A0': {$pf = array( 3370.394, 4767.874); break;}
  2138. // Variations on the ISO Standard
  2139. case 'A2_EXTRA' : {$pf = array( 1261.417, 1754.646); break;}
  2140. case 'A3+' : {$pf = array( 932.598, 1369.134); break;}
  2141. case 'A3_EXTRA' : {$pf = array( 912.756, 1261.417); break;}
  2142. case 'A3_SUPER' : {$pf = array( 864.567, 1440.000); break;}
  2143. case 'SUPER_A3' : {$pf = array( 864.567, 1380.472); break;}
  2144. case 'A4_EXTRA' : {$pf = array( 666.142, 912.756); break;}
  2145. case 'A4_SUPER' : {$pf = array( 649.134, 912.756); break;}
  2146. case 'SUPER_A4' : {$pf = array( 643.465, 1009.134); break;}
  2147. case 'A4_LONG' : {$pf = array( 595.276, 986.457); break;}
  2148. case 'F4' : {$pf = array( 595.276, 935.433); break;}
  2149. case 'SO_B5_EXTRA': {$pf = array( 572.598, 782.362); break;}
  2150. case 'A5_EXTRA' : {$pf = array( 490.394, 666.142); break;}
  2151. // ANSI Series
  2152. case 'ANSI_E': {$pf = array( 2448.000, 3168.000); break;}
  2153. case 'ANSI_D': {$pf = array( 1584.000, 2448.000); break;}
  2154. case 'ANSI_C': {$pf = array( 1224.000, 1584.000); break;}
  2155. case 'ANSI_B': {$pf = array( 792.000, 1224.000); break;}
  2156. case 'ANSI_A': {$pf = array( 612.000, 792.000); break;}
  2157. // Traditional 'Loose' North American Paper Sizes
  2158. case 'USLEDGER':
  2159. case 'LEDGER' : {$pf = array( 1224.000, 792.000); break;}
  2160. case 'ORGANIZERK':
  2161. case 'BIBLE':
  2162. case 'USTABLOID':
  2163. case 'TABLOID': {$pf = array( 792.000, 1224.000); break;}
  2164. case 'ORGANIZERM':
  2165. case 'USLETTER':
  2166. case 'LETTER' : {$pf = array( 612.000, 792.000); break;}
  2167. case 'USLEGAL':
  2168. case 'LEGAL' : {$pf = array( 612.000, 1008.000); break;}
  2169. case 'GOVERNMENTLETTER':
  2170. case 'GLETTER': {$pf = array( 576.000, 756.000); break;}
  2171. case 'JUNIORLEGAL':
  2172. case 'JLEGAL' : {$pf = array( 576.000, 360.000); break;}
  2173. // Other North American Paper Sizes
  2174. case 'QUADDEMY': {$pf = array( 2520.000, 3240.000); break;}
  2175. case 'SUPER_B': {$pf = array( 936.000, 1368.000); break;}
  2176. case 'QUARTO': {$pf = array( 648.000, 792.000); break;}
  2177. case 'GOVERNMENTLEGAL':
  2178. case 'FOLIO': {$pf = array( 612.000, 936.000); break;}
  2179. case 'MONARCH':
  2180. case 'EXECUTIVE': {$pf = array( 522.000, 756.000); break;}
  2181. case 'ORGANIZERL':
  2182. case 'STATEMENT':
  2183. case 'MEMO': {$pf = array( 396.000, 612.000); break;}
  2184. case 'FOOLSCAP': {$pf = array( 595.440, 936.000); break;}
  2185. case 'COMPACT': {$pf = array( 306.000, 486.000); break;}
  2186. case 'ORGANIZERJ': {$pf = array( 198.000, 360.000); break;}
  2187. // Canadian standard CAN 2-9.60M
  2188. case 'P1': {$pf = array( 1587.402, 2437.795); break;}
  2189. case 'P2': {$pf = array( 1218.898, 1587.402); break;}
  2190. case 'P3': {$pf = array( 793.701, 1218.898); break;}
  2191. case 'P4': {$pf = array( 609.449, 793.701); break;}
  2192. case 'P5': {$pf = array( 396.850, 609.449); break;}
  2193. case 'P6': {$pf = array( 303.307, 396.850); break;}
  2194. // North American Architectural Sizes
  2195. case 'ARCH_E' : {$pf = array( 2592.000, 3456.000); break;}
  2196. case 'ARCH_E1': {$pf = array( 2160.000, 3024.000); break;}
  2197. case 'ARCH_D' : {$pf = array( 1728.000, 2592.000); break;}
  2198. case 'BROADSHEET':
  2199. case 'ARCH_C' : {$pf = array( 1296.000, 1728.000); break;}
  2200. case 'ARCH_B' : {$pf = array( 864.000, 1296.000); break;}
  2201. case 'ARCH_A' : {$pf = array( 648.000, 864.000); break;}
  2202. // --- North American Envelope Sizes ---
  2203. // - Announcement Envelopes
  2204. case 'ANNENV_A2' : {$pf = array( 314.640, 414.000); break;}
  2205. case 'ANNENV_A6' : {$pf = array( 342.000, 468.000); break;}
  2206. case 'ANNENV_A7' : {$pf = array( 378.000, 522.000); break;}
  2207. case 'ANNENV_A8' : {$pf = array( 396.000, 584.640); break;}
  2208. case 'ANNENV_A10' : {$pf = array( 450.000, 692.640); break;}
  2209. case 'ANNENV_SLIM': {$pf = array( 278.640, 638.640); break;}
  2210. // - Commercial Envelopes
  2211. case 'COMMENV_N6_1/4': {$pf = array( 252.000, 432.000); break;}
  2212. case 'COMMENV_N6_3/4': {$pf = array( 260.640, 468.000); break;}
  2213. case 'COMMENV_N8' : {$pf = array( 278.640, 540.000); break;}
  2214. case 'COMMENV_N9' : {$pf = array( 278.640, 638.640); break;}
  2215. case 'COMMENV_N10' : {$pf = array( 296.640, 684.000); break;}
  2216. case 'COMMENV_N11' : {$pf = array( 324.000, 746.640); break;}
  2217. case 'COMMENV_N12' : {$pf = array( 342.000, 792.000); break;}
  2218. case 'COMMENV_N14' : {$pf = array( 360.000, 828.000); break;}
  2219. // - Catalogue Envelopes
  2220. case 'CATENV_N1' : {$pf = array( 432.000, 648.000); break;}
  2221. case 'CATENV_N1_3/4' : {$pf = array( 468.000, 684.000); break;}
  2222. case 'CATENV_N2' : {$pf = array( 468.000, 720.000); break;}
  2223. case 'CATENV_N3' : {$pf = array( 504.000, 720.000); break;}
  2224. case 'CATENV_N6' : {$pf = array( 540.000, 756.000); break;}
  2225. case 'CATENV_N7' : {$pf = array( 576.000, 792.000); break;}
  2226. case 'CATENV_N8' : {$pf = array( 594.000, 810.000); break;}
  2227. case 'CATENV_N9_1/2' : {$pf = array( 612.000, 756.000); break;}
  2228. case 'CATENV_N9_3/4' : {$pf = array( 630.000, 810.000); break;}
  2229. case 'CATENV_N10_1/2': {$pf = array( 648.000, 864.000); break;}
  2230. case 'CATENV_N12_1/2': {$pf = array( 684.000, 900.000); break;}
  2231. case 'CATENV_N13_1/2': {$pf = array( 720.000, 936.000); break;}
  2232. case 'CATENV_N14_1/4': {$pf = array( 810.000, 882.000); break;}
  2233. case 'CATENV_N14_1/2': {$pf = array( 828.000, 1044.000); break;}
  2234. // Japanese (JIS P 0138-61) Standard B-Series
  2235. case 'JIS_B0' : {$pf = array( 2919.685, 4127.244); break;}
  2236. case 'JIS_B1' : {$pf = array( 2063.622, 2919.685); break;}
  2237. case 'JIS_B2' : {$pf = array( 1459.843, 2063.622); break;}
  2238. case 'JIS_B3' : {$pf = array( 1031.811, 1459.843); break;}
  2239. case 'JIS_B4' : {$pf = array( 728.504, 1031.811); break;}
  2240. case 'JIS_B5' : {$pf = array( 515.906, 728.504); break;}
  2241. case 'JIS_B6' : {$pf = array( 362.835, 515.906); break;}
  2242. case 'JIS_B7' : {$pf = array( 257.953, 362.835); break;}
  2243. case 'JIS_B8' : {$pf = array( 181.417, 257.953); break;}
  2244. case 'JIS_B9' : {$pf = array( 127.559, 181.417); break;}
  2245. case 'JIS_B10': {$pf = array( 90.709, 127.559); break;}
  2246. case 'JIS_B11': {$pf = array( 62.362, 90.709); break;}
  2247. case 'JIS_B12': {$pf = array( 45.354, 62.362); break;}
  2248. // PA Series
  2249. case 'PA0' : {$pf = array( 2381.102, 3174.803,); break;}
  2250. case 'PA1' : {$pf = array( 1587.402, 2381.102); break;}
  2251. case 'PA2' : {$pf = array( 1190.551, 1587.402); break;}
  2252. case 'PA3' : {$pf = array( 793.701, 1190.551); break;}
  2253. case 'PA4' : {$pf = array( 595.276, 793.701); break;}
  2254. case 'PA5' : {$pf = array( 396.850, 595.276); break;}
  2255. case 'PA6' : {$pf = array( 297.638, 396.850); break;}
  2256. case 'PA7' : {$pf = array( 198.425, 297.638); break;}
  2257. case 'PA8' : {$pf = array( 147.402, 198.425); break;}
  2258. case 'PA9' : {$pf = array( 99.213, 147.402); break;}
  2259. case 'PA10': {$pf = array( 73.701, 99.213); break;}
  2260. // Standard Photographic Print Sizes
  2261. case 'PASSPORT_PHOTO': {$pf = array( 99.213, 127.559); break;}
  2262. case 'E' : {$pf = array( 233.858, 340.157); break;}
  2263. case 'L':
  2264. case '3R' : {$pf = array( 252.283, 360.000); break;}
  2265. case 'KG':
  2266. case '4R' : {$pf = array( 289.134, 430.866); break;}
  2267. case '4D' : {$pf = array( 340.157, 430.866); break;}
  2268. case '2L':
  2269. case '5R' : {$pf = array( 360.000, 504.567); break;}
  2270. case '8P':
  2271. case '6R' : {$pf = array( 430.866, 575.433); break;}
  2272. case '6P':
  2273. case '8R' : {$pf = array( 575.433, 720.000); break;}
  2274. case '6PW':
  2275. case 'S8R' : {$pf = array( 575.433, 864.567); break;}
  2276. case '4P':
  2277. case '10R' : {$pf = array( 720.000, 864.567); break;}
  2278. case '4PW':
  2279. case 'S10R': {$pf = array( 720.000, 1080.000); break;}
  2280. case '11R' : {$pf = array( 790.866, 1009.134); break;}
  2281. case 'S11R': {$pf = array( 790.866, 1224.567); break;}
  2282. case '12R' : {$pf = array( 864.567, 1080.000); break;}
  2283. case 'S12R': {$pf = array( 864.567, 1292.598); break;}
  2284. // Common Newspaper Sizes
  2285. case 'NEWSPAPER_BROADSHEET': {$pf = array( 2125.984, 1700.787); break;}
  2286. case 'NEWSPAPER_BERLINER' : {$pf = array( 1332.283, 892.913); break;}
  2287. case 'NEWSPAPER_TABLOID':
  2288. case 'NEWSPAPER_COMPACT' : {$pf = array( 1218.898, 793.701); break;}
  2289. // Business Cards
  2290. case 'CREDIT_CARD':
  2291. case 'BUSINESS_CARD':
  2292. case 'BUSINESS_CARD_ISO7810': {$pf = array( 153.014, 242.646); break;}
  2293. case 'BUSINESS_CARD_ISO216' : {$pf = array( 147.402, 209.764); break;}
  2294. case 'BUSINESS_CARD_IT':
  2295. case 'BUSINESS_CARD_UK':
  2296. case 'BUSINESS_CARD_FR':
  2297. case 'BUSINESS_CARD_DE':
  2298. case 'BUSINESS_CARD_ES' : {$pf = array( 155.906, 240.945); break;}
  2299. case 'BUSINESS_CARD_CA':
  2300. case 'BUSINESS_CARD_US' : {$pf = array( 144.567, 252.283); break;}
  2301. case 'BUSINESS_CARD_JP' : {$pf = array( 155.906, 257.953); break;}
  2302. case 'BUSINESS_CARD_HK' : {$pf = array( 153.071, 255.118); break;}
  2303. case 'BUSINESS_CARD_AU':
  2304. case 'BUSINESS_CARD_DK':
  2305. case 'BUSINESS_CARD_SE' : {$pf = array( 155.906, 255.118); break;}
  2306. case 'BUSINESS_CARD_RU':
  2307. case 'BUSINESS_CARD_CZ':
  2308. case 'BUSINESS_CARD_FI':
  2309. case 'BUSINESS_CARD_HU':
  2310. case 'BUSINESS_CARD_IL' : {$pf = array( 141.732, 255.118); break;}
  2311. // Billboards
  2312. case '4SHEET' : {$pf = array( 2880.000, 4320.000); break;}
  2313. case '6SHEET' : {$pf = array( 3401.575, 5102.362); break;}
  2314. case '12SHEET': {$pf = array( 8640.000, 4320.000); break;}
  2315. case '16SHEET': {$pf = array( 5760.000, 8640.000); break;}
  2316. case '32SHEET': {$pf = array(11520.000, 8640.000); break;}
  2317. case '48SHEET': {$pf = array(17280.000, 8640.000); break;}
  2318. case '64SHEET': {$pf = array(23040.000, 8640.000); break;}
  2319. case '96SHEET': {$pf = array(34560.000, 8640.000); break;}
  2320. // Old European Sizes
  2321. // - Old Imperial English Sizes
  2322. case 'EN_EMPEROR' : {$pf = array( 3456.000, 5184.000); break;}
  2323. case 'EN_ANTIQUARIAN' : {$pf = array( 2232.000, 3816.000); break;}
  2324. case 'EN_GRAND_EAGLE' : {$pf = array( 2070.000, 3024.000); break;}
  2325. case 'EN_DOUBLE_ELEPHANT' : {$pf = array( 1926.000, 2880.000); break;}
  2326. case 'EN_ATLAS' : {$pf = array( 1872.000, 2448.000); break;}
  2327. case 'EN_COLOMBIER' : {$pf = array( 1692.000, 2484.000); break;}
  2328. case 'EN_ELEPHANT' : {$pf = array( 1656.000, 2016.000); break;}
  2329. case 'EN_DOUBLE_DEMY' : {$pf = array( 1620.000, 2556.000); break;}
  2330. case 'EN_IMPERIAL' : {$pf = array( 1584.000, 2160.000); break;}
  2331. case 'EN_PRINCESS' : {$pf = array( 1548.000, 2016.000); break;}
  2332. case 'EN_CARTRIDGE' : {$pf = array( 1512.000, 1872.000); break;}
  2333. case 'EN_DOUBLE_LARGE_POST': {$pf = array( 1512.000, 2376.000); break;}
  2334. case 'EN_ROYAL' : {$pf = array( 1440.000, 1800.000); break;}
  2335. case 'EN_SHEET':
  2336. case 'EN_HALF_POST' : {$pf = array( 1404.000, 1692.000); break;}
  2337. case 'EN_SUPER_ROYAL' : {$pf = array( 1368.000, 1944.000); break;}
  2338. case 'EN_DOUBLE_POST' : {$pf = array( 1368.000, 2196.000); break;}
  2339. case 'EN_MEDIUM' : {$pf = array( 1260.000, 1656.000); break;}
  2340. case 'EN_DEMY' : {$pf = array( 1260.000, 1620.000); break;}
  2341. case 'EN_LARGE_POST' : {$pf = array( 1188.000, 1512.000); break;}
  2342. case 'EN_COPY_DRAUGHT' : {$pf = array( 1152.000, 1440.000); break;}
  2343. case 'EN_POST' : {$pf = array( 1116.000, 1386.000); break;}
  2344. case 'EN_CROWN' : {$pf = array( 1080.000, 1440.000); break;}
  2345. case 'EN_PINCHED_POST' : {$pf = array( 1062.000, 1332.000); break;}
  2346. case 'EN_BRIEF' : {$pf = array( 972.000, 1152.000); break;}
  2347. case 'EN_FOOLSCAP' : {$pf = array( 972.000, 1224.000); break;}
  2348. case 'EN_SMALL_FOOLSCAP' : {$pf = array( 954.000, 1188.000); break;}
  2349. case 'EN_POTT' : {$pf = array( 900.000, 1080.000); break;}
  2350. // - Old Imperial Belgian Sizes
  2351. case 'BE_GRAND_AIGLE' : {$pf = array( 1984.252, 2948.031); break;}
  2352. case 'BE_COLOMBIER' : {$pf = array( 1757.480, 2409.449); break;}
  2353. case 'BE_DOUBLE_CARRE': {$pf = array( 1757.480, 2607.874); break;}
  2354. case 'BE_ELEPHANT' : {$pf = array( 1746.142, 2182.677); break;}
  2355. case 'BE_PETIT_AIGLE' : {$pf = array( 1700.787, 2381.102); break;}
  2356. case 'BE_GRAND_JESUS' : {$pf = array( 1559.055, 2069.291); break;}
  2357. case 'BE_JESUS' : {$pf = array( 1530.709, 2069.291); break;}
  2358. case 'BE_RAISIN' : {$pf = array( 1417.323, 1842.520); break;}
  2359. case 'BE_GRAND_MEDIAN': {$pf = array( 1303.937, 1714.961); break;}
  2360. case 'BE_DOUBLE_POSTE': {$pf = array( 1233.071, 1601.575); break;}
  2361. case 'BE_COQUILLE' : {$pf = array( 1218.898, 1587.402); break;}
  2362. case 'BE_PETIT_MEDIAN': {$pf = array( 1176.378, 1502.362); break;}
  2363. case 'BE_RUCHE' : {$pf = array( 1020.472, 1303.937); break;}
  2364. case 'BE_PROPATRIA' : {$pf = array( 977.953, 1218.898); break;}
  2365. case 'BE_LYS' : {$pf = array( 898.583, 1125.354); break;}
  2366. case 'BE_POT' : {$pf = array( 870.236, 1088.504); break;}
  2367. case 'BE_ROSETTE' : {$pf = array( 765.354, 983.622); break;}
  2368. // - Old Imperial French Sizes
  2369. case 'FR_UNIVERS' : {$pf = array( 2834.646, 3685.039); break;}
  2370. case 'FR_DOUBLE_COLOMBIER' : {$pf = array( 2551.181, 3571.654); break;}
  2371. case 'FR_GRANDE_MONDE' : {$pf = array( 2551.181, 3571.654); break;}
  2372. case 'FR_DOUBLE_SOLEIL' : {$pf = array( 2267.717, 3401.575); break;}
  2373. case 'FR_DOUBLE_JESUS' : {$pf = array( 2154.331, 3174.803); break;}
  2374. case 'FR_GRAND_AIGLE' : {$pf = array( 2125.984, 3004.724); break;}
  2375. case 'FR_PETIT_AIGLE' : {$pf = array( 1984.252, 2664.567); break;}
  2376. case 'FR_DOUBLE_RAISIN' : {$pf = array( 1842.520, 2834.646); break;}
  2377. case 'FR_JOURNAL' : {$pf = array( 1842.520, 2664.567); break;}
  2378. case 'FR_COLOMBIER_AFFICHE': {$pf = array( 1785.827, 2551.181); break;}
  2379. case 'FR_DOUBLE_CAVALIER' : {$pf = array( 1757.480, 2607.874); break;}
  2380. case 'FR_CLOCHE' : {$pf = array( 1700.787, 2267.717); break;}
  2381. case 'FR_SOLEIL' : {$pf = array( 1700.787, 2267.717); break;}
  2382. case 'FR_DOUBLE_CARRE' : {$pf = array( 1587.402, 2551.181); break;}
  2383. case 'FR_DOUBLE_COQUILLE' : {$pf = array( 1587.402, 2494.488); break;}
  2384. case 'FR_JESUS' : {$pf = array( 1587.402, 2154.331); break;}
  2385. case 'FR_RAISIN' : {$pf = array( 1417.323, 1842.520); break;}
  2386. case 'FR_CAVALIER' : {$pf = array( 1303.937, 1757.480); break;}
  2387. case 'FR_DOUBLE_COURONNE' : {$pf = array( 1303.937, 2040.945); break;}
  2388. case 'FR_CARRE' : {$pf = array( 1275.591, 1587.402); break;}
  2389. case 'FR_COQUILLE' : {$pf = array( 1247.244, 1587.402); break;}
  2390. case 'FR_DOUBLE_TELLIERE' : {$pf = array( 1247.244, 1927.559); break;}
  2391. case 'FR_DOUBLE_CLOCHE' : {$pf = array( 1133.858, 1700.787); break;}
  2392. case 'FR_DOUBLE_POT' : {$pf = array( 1133.858, 1757.480); break;}
  2393. case 'FR_ECU' : {$pf = array( 1133.858, 1474.016); break;}
  2394. case 'FR_COURONNE' : {$pf = array( 1020.472, 1303.937); break;}
  2395. case 'FR_TELLIERE' : {$pf = array( 963.780, 1247.244); break;}
  2396. case 'FR_POT' : {$pf = array( 878.740, 1133.858); break;}
  2397. // DEFAULT ISO A4
  2398. default: {$pf = array( 595.276, 841.890); break;}
  2399. }
  2400. return $pf;
  2401. }
  2402. /**
  2403. * Change the format of the current page
  2404. * @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>
  2405. * <li>['format'] = page format name (one of the above);</li>
  2406. * <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>
  2407. * <li>['PZ'] : The page's preferred zoom (magnification) factor.</li>
  2408. * <li>['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed:</li>
  2409. * <li>['MediaBox']['llx'] : lower-left x coordinate in points</li>
  2410. * <li>['MediaBox']['lly'] : lower-left y coordinate in points</li>
  2411. * <li>['MediaBox']['urx'] : upper-right x coordinate in points</li>
  2412. * <li>['MediaBox']['ury'] : upper-right y coordinate in points</li>
  2413. * <li>['CropBox'] : the visible region of default user space:</li>
  2414. * <li>['CropBox']['llx'] : lower-left x coordinate in points</li>
  2415. * <li>['CropBox']['lly'] : lower-left y coordinate in points</li>
  2416. * <li>['CropBox']['urx'] : upper-right x coordinate in points</li>
  2417. * <li>['CropBox']['ury'] : upper-right y coordinate in points</li>
  2418. * <li>['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment:</li>
  2419. * <li>['BleedBox']['llx'] : lower-left x coordinate in points</li>
  2420. * <li>['BleedBox']['lly'] : lower-left y coordinate in points</li>
  2421. * <li>['BleedBox']['urx'] : upper-right x coordinate in points</li>
  2422. * <li>['BleedBox']['ury'] : upper-right y coordinate in points</li>
  2423. * <li>['TrimBox'] : the intended dimensions of the finished page after trimming:</li>
  2424. * <li>['TrimBox']['llx'] : lower-left x coordinate in points</li>
  2425. * <li>['TrimBox']['lly'] : lower-left y coordinate in points</li>
  2426. * <li>['TrimBox']['urx'] : upper-right x coordinate in points</li>
  2427. * <li>['TrimBox']['ury'] : upper-right y coordinate in points</li>
  2428. * <li>['ArtBox'] : the extent of the page's meaningful content:</li>
  2429. * <li>['ArtBox']['llx'] : lower-left x coordinate in points</li>
  2430. * <li>['ArtBox']['lly'] : lower-left y coordinate in points</li>
  2431. * <li>['ArtBox']['urx'] : upper-right x coordinate in points</li>
  2432. * <li>['ArtBox']['ury'] : upper-right y coordinate in points</li>
  2433. * <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>
  2434. * <li>['BoxColorInfo'][BOXTYPE]['C'] : an array of three numbers in the range 0-255, representing the components in the DeviceRGB colour space.</li>
  2435. * <li>['BoxColorInfo'][BOXTYPE]['W'] : the guideline width in default user units</li>
  2436. * <li>['BoxColorInfo'][BOXTYPE]['S'] : the guideline style: S = Solid; D = Dashed</li>
  2437. * <li>['BoxColorInfo'][BOXTYPE]['D'] : dash array defining a pattern of dashes and gaps to be used in drawing dashed guidelines</li>
  2438. * <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>
  2439. * <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>
  2440. * <li>['trans']['S'] : transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li>
  2441. * <li>['trans']['D'] : The duration of the transition effect, in seconds.</li>
  2442. * <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>
  2443. * <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>
  2444. * <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>
  2445. * <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>
  2446. * <li>['trans']['B'] : (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li>
  2447. * </ul>
  2448. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul>
  2449. * <li>P or Portrait (default)</li>
  2450. * <li>L or Landscape</li>
  2451. * <li>'' (empty string) for automatic orientation</li>
  2452. * </ul>
  2453. * @protected
  2454. * @since 3.0.015 (2008-06-06)
  2455. * @see getPageSizeFromFormat()
  2456. */
  2457. protected function setPageFormat($format, $orientation='P') {
  2458. if (!empty($format) AND isset($this->pagedim[$this->page])) {
  2459. // remove inherited values
  2460. unset($this->pagedim[$this->page]);
  2461. }
  2462. if (is_string($format)) {
  2463. // get page measures from format name
  2464. $pf = $this->getPageSizeFromFormat($format);
  2465. $this->fwPt = $pf[0];
  2466. $this->fhPt = $pf[1];
  2467. } else {
  2468. // the boundaries of the physical medium on which the page shall be displayed or printed
  2469. if (isset($format['MediaBox'])) {
  2470. $this->setPageBoxes($this->page, 'MediaBox', $format['MediaBox']['llx'], $format['MediaBox']['lly'], $format['MediaBox']['urx'], $format['MediaBox']['ury'], false);
  2471. $this->fwPt = (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k);
  2472. $this->fhPt = (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k);
  2473. } else {
  2474. if (isset($format[0]) AND is_numeric($format[0]) AND isset($format[1]) AND is_numeric($format[1])) {
  2475. $pf = array(($format[0] * $this->k), ($format[1] * $this->k));
  2476. } else {
  2477. if (!isset($format['format'])) {
  2478. // default value
  2479. $format['format'] = 'A4';
  2480. }
  2481. $pf = $this->getPageSizeFromFormat($format['format']);
  2482. }
  2483. $this->fwPt = $pf[0];
  2484. $this->fhPt = $pf[1];
  2485. $this->setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true);
  2486. }
  2487. // the visible region of default user space
  2488. if (isset($format['CropBox'])) {
  2489. $this->setPageBoxes($this->page, 'CropBox', $format['CropBox']['llx'], $format['CropBox']['lly'], $format['CropBox']['urx'], $format['CropBox']['ury'], false);
  2490. }
  2491. // the region to which the contents of the page shall be clipped when output in a production environment
  2492. if (isset($format['BleedBox'])) {
  2493. $this->setPageBoxes($this->page, 'BleedBox', $format['BleedBox']['llx'], $format['BleedBox']['lly'], $format['BleedBox']['urx'], $format['BleedBox']['ury'], false);
  2494. }
  2495. // the intended dimensions of the finished page after trimming
  2496. if (isset($format['TrimBox'])) {
  2497. $this->setPageBoxes($this->page, 'TrimBox', $format['TrimBox']['llx'], $format['TrimBox']['lly'], $format['TrimBox']['urx'], $format['TrimBox']['ury'], false);
  2498. }
  2499. // the page's meaningful content (including potential white space)
  2500. if (isset($format['ArtBox'])) {
  2501. $this->setPageBoxes($this->page, 'ArtBox', $format['ArtBox']['llx'], $format['ArtBox']['lly'], $format['ArtBox']['urx'], $format['ArtBox']['ury'], false);
  2502. }
  2503. // specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for the various page boundaries
  2504. if (isset($format['BoxColorInfo'])) {
  2505. $this->pagedim[$this->page]['BoxColorInfo'] = $format['BoxColorInfo'];
  2506. }
  2507. if (isset($format['Rotate']) AND (($format['Rotate'] % 90) == 0)) {
  2508. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  2509. $this->pagedim[$this->page]['Rotate'] = intval($format['Rotate']);
  2510. }
  2511. if (isset($format['PZ'])) {
  2512. // The page's preferred zoom (magnification) factor
  2513. $this->pagedim[$this->page]['PZ'] = floatval($format['PZ']);
  2514. }
  2515. if (isset($format['trans'])) {
  2516. // The style and duration of the visual transition to use when moving from another page to the given page during a presentation
  2517. if (isset($format['trans']['Dur'])) {
  2518. // The page's display duration
  2519. $this->pagedim[$this->page]['trans']['Dur'] = floatval($format['trans']['Dur']);
  2520. }
  2521. $stansition_styles = array('Split', 'Blinds', 'Box', 'Wipe', 'Dissolve', 'Glitter', 'R', 'Fly', 'Push', 'Cover', 'Uncover', 'Fade');
  2522. if (isset($format['trans']['S']) AND in_array($format['trans']['S'], $stansition_styles)) {
  2523. // The transition style that shall be used when moving to this page from another during a presentation
  2524. $this->pagedim[$this->page]['trans']['S'] = $format['trans']['S'];
  2525. $valid_effect = array('Split', 'Blinds');
  2526. $valid_vals = array('H', 'V');
  2527. if (isset($format['trans']['Dm']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['Dm'], $valid_vals)) {
  2528. $this->pagedim[$this->page]['trans']['Dm'] = $format['trans']['Dm'];
  2529. }
  2530. $valid_effect = array('Split', 'Box', 'Fly');
  2531. $valid_vals = array('I', 'O');
  2532. if (isset($format['trans']['M']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['M'], $valid_vals)) {
  2533. $this->pagedim[$this->page]['trans']['M'] = $format['trans']['M'];
  2534. }
  2535. $valid_effect = array('Wipe', 'Glitter', 'Fly', 'Cover', 'Uncover', 'Push');
  2536. if (isset($format['trans']['Di']) AND in_array($format['trans']['S'], $valid_effect)) {
  2537. if (((($format['trans']['Di'] == 90) OR ($format['trans']['Di'] == 180)) AND ($format['trans']['S'] == 'Wipe'))
  2538. OR (($format['trans']['Di'] == 315) AND ($format['trans']['S'] == 'Glitter'))
  2539. OR (($format['trans']['Di'] == 0) OR ($format['trans']['Di'] == 270))) {
  2540. $this->pagedim[$this->page]['trans']['Di'] = intval($format['trans']['Di']);
  2541. }
  2542. }
  2543. if (isset($format['trans']['SS']) AND ($format['trans']['S'] == 'Fly')) {
  2544. $this->pagedim[$this->page]['trans']['SS'] = floatval($format['trans']['SS']);
  2545. }
  2546. if (isset($format['trans']['B']) AND ($format['trans']['B'] === true) AND ($format['trans']['S'] == 'Fly')) {
  2547. $this->pagedim[$this->page]['trans']['B'] = 'true';
  2548. }
  2549. } else {
  2550. $this->pagedim[$this->page]['trans']['S'] = 'R';
  2551. }
  2552. if (isset($format['trans']['D'])) {
  2553. // The duration of the transition effect, in seconds
  2554. $this->pagedim[$this->page]['trans']['D'] = floatval($format['trans']['D']);
  2555. } else {
  2556. $this->pagedim[$this->page]['trans']['D'] = 1;
  2557. }
  2558. }
  2559. }
  2560. $this->setPageOrientation($orientation);
  2561. }
  2562. /**
  2563. * Set page boundaries.
  2564. * @param $page (int) page number
  2565. * @param $type (string) valid values are: <ul><li>'MediaBox' : the boundaries of the physical medium on which the page shall be displayed or printed;</li><li>'CropBox' : the visible region of default user space;</li><li>'BleedBox' : the region to which the contents of the page shall be clipped when output in a production environment;</li><li>'TrimBox' : the intended dimensions of the finished page after trimming;</li><li>'ArtBox' : the page's meaningful content (including potential white space).</li></ul>
  2566. * @param $llx (float) lower-left x coordinate in user units
  2567. * @param $lly (float) lower-left y coordinate in user units
  2568. * @param $urx (float) upper-right x coordinate in user units
  2569. * @param $ury (float) upper-right y coordinate in user units
  2570. * @param $points (boolean) if true uses user units as unit of measure, otherwise uses PDF points
  2571. * @public
  2572. * @since 5.0.010 (2010-05-17)
  2573. */
  2574. public function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points=false) {
  2575. if (!isset($this->pagedim[$page])) {
  2576. // initialize array
  2577. $this->pagedim[$page] = array();
  2578. }
  2579. $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  2580. if (!in_array($type, $pageboxes)) {
  2581. return;
  2582. }
  2583. if ($points) {
  2584. $k = 1;
  2585. } else {
  2586. $k = $this->k;
  2587. }
  2588. $this->pagedim[$page][$type]['llx'] = ($llx * $k);
  2589. $this->pagedim[$page][$type]['lly'] = ($lly * $k);
  2590. $this->pagedim[$page][$type]['urx'] = ($urx * $k);
  2591. $this->pagedim[$page][$type]['ury'] = ($ury * $k);
  2592. }
  2593. /**
  2594. * Swap X and Y coordinates of page boxes (change page boxes orientation).
  2595. * @param $page (int) page number
  2596. * @protected
  2597. * @since 5.0.010 (2010-05-17)
  2598. */
  2599. protected function swapPageBoxCoordinates($page) {
  2600. $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  2601. foreach ($pageboxes as $type) {
  2602. // swap X and Y coordinates
  2603. if (isset($this->pagedim[$page][$type])) {
  2604. $tmp = $this->pagedim[$page][$type]['llx'];
  2605. $this->pagedim[$page][$type]['llx'] = $this->pagedim[$page][$type]['lly'];
  2606. $this->pagedim[$page][$type]['lly'] = $tmp;
  2607. $tmp = $this->pagedim[$page][$type]['urx'];
  2608. $this->pagedim[$page][$type]['urx'] = $this->pagedim[$page][$type]['ury'];
  2609. $this->pagedim[$page][$type]['ury'] = $tmp;
  2610. }
  2611. }
  2612. }
  2613. /**
  2614. * Set page orientation.
  2615. * @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>
  2616. * @param $autopagebreak (boolean) Boolean indicating if auto-page-break mode should be on or off.
  2617. * @param $bottommargin (float) bottom margin of the page.
  2618. * @public
  2619. * @since 3.0.015 (2008-06-06)
  2620. */
  2621. public function setPageOrientation($orientation, $autopagebreak='', $bottommargin='') {
  2622. if (!isset($this->pagedim[$this->page]['MediaBox'])) {
  2623. // the boundaries of the physical medium on which the page shall be displayed or printed
  2624. $this->setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true);
  2625. }
  2626. if (!isset($this->pagedim[$this->page]['CropBox'])) {
  2627. // the visible region of default user space
  2628. $this->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);
  2629. }
  2630. if (!isset($this->pagedim[$this->page]['BleedBox'])) {
  2631. // the region to which the contents of the page shall be clipped when output in a production environment
  2632. $this->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);
  2633. }
  2634. if (!isset($this->pagedim[$this->page]['TrimBox'])) {
  2635. // the intended dimensions of the finished page after trimming
  2636. $this->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);
  2637. }
  2638. if (!isset($this->pagedim[$this->page]['ArtBox'])) {
  2639. // the page's meaningful content (including potential white space)
  2640. $this->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);
  2641. }
  2642. if (!isset($this->pagedim[$this->page]['Rotate'])) {
  2643. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  2644. $this->pagedim[$this->page]['Rotate'] = 0;
  2645. }
  2646. if (!isset($this->pagedim[$this->page]['PZ'])) {
  2647. // The page's preferred zoom (magnification) factor
  2648. $this->pagedim[$this->page]['PZ'] = 1;
  2649. }
  2650. if ($this->fwPt > $this->fhPt) {
  2651. // landscape
  2652. $default_orientation = 'L';
  2653. } else {
  2654. // portrait
  2655. $default_orientation = 'P';
  2656. }
  2657. $valid_orientations = array('P', 'L');
  2658. if (empty($orientation)) {
  2659. $orientation = $default_orientation;
  2660. } else {
  2661. $orientation = strtoupper($orientation{0});
  2662. }
  2663. if (in_array($orientation, $valid_orientations) AND ($orientation != $default_orientation)) {
  2664. $this->CurOrientation = $orientation;
  2665. $this->wPt = $this->fhPt;
  2666. $this->hPt = $this->fwPt;
  2667. } else {
  2668. $this->CurOrientation = $default_orientation;
  2669. $this->wPt = $this->fwPt;
  2670. $this->hPt = $this->fhPt;
  2671. }
  2672. if ((abs($this->pagedim[$this->page]['MediaBox']['urx'] - $this->hPt) < $this->feps) AND (abs($this->pagedim[$this->page]['MediaBox']['ury'] - $this->wPt) < $this->feps)){
  2673. // swap X and Y coordinates (change page orientation)
  2674. $this->swapPageBoxCoordinates($this->page);
  2675. }
  2676. $this->w = $this->wPt / $this->k;
  2677. $this->h = $this->hPt / $this->k;
  2678. if ($this->empty_string($autopagebreak)) {
  2679. if (isset($this->AutoPageBreak)) {
  2680. $autopagebreak = $this->AutoPageBreak;
  2681. } else {
  2682. $autopagebreak = true;
  2683. }
  2684. }
  2685. if ($this->empty_string($bottommargin)) {
  2686. if (isset($this->bMargin)) {
  2687. $bottommargin = $this->bMargin;
  2688. } else {
  2689. // default value = 2 cm
  2690. $bottommargin = 2 * 28.35 / $this->k;
  2691. }
  2692. }
  2693. $this->SetAutoPageBreak($autopagebreak, $bottommargin);
  2694. // store page dimensions
  2695. $this->pagedim[$this->page]['w'] = $this->wPt;
  2696. $this->pagedim[$this->page]['h'] = $this->hPt;
  2697. $this->pagedim[$this->page]['wk'] = $this->w;
  2698. $this->pagedim[$this->page]['hk'] = $this->h;
  2699. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  2700. $this->pagedim[$this->page]['bm'] = $bottommargin;
  2701. $this->pagedim[$this->page]['lm'] = $this->lMargin;
  2702. $this->pagedim[$this->page]['rm'] = $this->rMargin;
  2703. $this->pagedim[$this->page]['pb'] = $autopagebreak;
  2704. $this->pagedim[$this->page]['or'] = $this->CurOrientation;
  2705. $this->pagedim[$this->page]['olm'] = $this->original_lMargin;
  2706. $this->pagedim[$this->page]['orm'] = $this->original_rMargin;
  2707. }
  2708. /**
  2709. * Set regular expression to detect withespaces or word separators.
  2710. * The pattern delimiter must be the forward-slash character "/".
  2711. * Some example patterns are:
  2712. * <pre>
  2713. * Non-Unicode or missing PCRE unicode support: "/[^\S\xa0]/"
  2714. * Unicode and PCRE unicode support: "/[^\S\P{Z}\xa0]/u"
  2715. * Unicode and PCRE unicode support in Chinese mode: "/[^\S\P{Z}\P{Lo}\xa0]/u"
  2716. * if PCRE unicode support is turned ON ("\P" is the negate class of "\p"):
  2717. * "\p{Z}" or "\p{Separator}": any kind of Unicode whitespace or invisible separator.
  2718. * "\p{Lo}" or "\p{Other_Letter}": a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  2719. * "\p{Lo}" is needed for Chinese characters because are packed next to each other without spaces in between.
  2720. * </pre>
  2721. * @param $re (string) regular expression (leave empty for default).
  2722. * @public
  2723. * @since 4.6.016 (2009-06-15)
  2724. */
  2725. public function setSpacesRE($re='/[^\S\xa0]/') {
  2726. $this->re_spaces = $re;
  2727. $re_parts = explode('/', $re);
  2728. // get pattern parts
  2729. $this->re_space = array();
  2730. if (isset($re_parts[1]) AND !empty($re_parts[1])) {
  2731. $this->re_space['p'] = $re_parts[1];
  2732. } else {
  2733. $this->re_space['p'] = '[\s]';
  2734. }
  2735. // set pattern modifiers
  2736. if (isset($re_parts[2]) AND !empty($re_parts[2])) {
  2737. $this->re_space['m'] = $re_parts[2];
  2738. } else {
  2739. $this->re_space['m'] = '';
  2740. }
  2741. }
  2742. /**
  2743. * Enable or disable Right-To-Left language mode
  2744. * @param $enable (Boolean) if true enable Right-To-Left language mode.
  2745. * @param $resetx (Boolean) if true reset the X position on direction change.
  2746. * @public
  2747. * @since 2.0.000 (2008-01-03)
  2748. */
  2749. public function setRTL($enable, $resetx=true) {
  2750. $enable = $enable ? true : false;
  2751. $resetx = ($resetx AND ($enable != $this->rtl));
  2752. $this->rtl = $enable;
  2753. $this->tmprtl = false;
  2754. if ($resetx) {
  2755. $this->Ln(0);
  2756. }
  2757. }
  2758. /**
  2759. * Return the RTL status
  2760. * @return boolean
  2761. * @public
  2762. * @since 4.0.012 (2008-07-24)
  2763. */
  2764. public function getRTL() {
  2765. return $this->rtl;
  2766. }
  2767. /**
  2768. * Force temporary RTL language direction
  2769. * @param $mode (mixed) can be false, 'L' for LTR or 'R' for RTL
  2770. * @public
  2771. * @since 2.1.000 (2008-01-09)
  2772. */
  2773. public function setTempRTL($mode) {
  2774. $newmode = false;
  2775. switch (strtoupper($mode)) {
  2776. case 'LTR':
  2777. case 'L': {
  2778. if ($this->rtl) {
  2779. $newmode = 'L';
  2780. }
  2781. break;
  2782. }
  2783. case 'RTL':
  2784. case 'R': {
  2785. if (!$this->rtl) {
  2786. $newmode = 'R';
  2787. }
  2788. break;
  2789. }
  2790. case false:
  2791. default: {
  2792. $newmode = false;
  2793. break;
  2794. }
  2795. }
  2796. $this->tmprtl = $newmode;
  2797. }
  2798. /**
  2799. * Return the current temporary RTL status
  2800. * @return boolean
  2801. * @public
  2802. * @since 4.8.014 (2009-11-04)
  2803. */
  2804. public function isRTLTextDir() {
  2805. return ($this->rtl OR ($this->tmprtl == 'R'));
  2806. }
  2807. /**
  2808. * Set the last cell height.
  2809. * @param $h (float) cell height.
  2810. * @author Nicola Asuni
  2811. * @public
  2812. * @since 1.53.0.TC034
  2813. */
  2814. public function setLastH($h) {
  2815. $this->lasth = $h;
  2816. }
  2817. /**
  2818. * Reset the last cell height.
  2819. * @public
  2820. * @since 5.9.000 (2010-10-03)
  2821. */
  2822. public function resetLastH() {
  2823. $this->lasth = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  2824. }
  2825. /**
  2826. * Get the last cell height.
  2827. * @return last cell height
  2828. * @public
  2829. * @since 4.0.017 (2008-08-05)
  2830. */
  2831. public function getLastH() {
  2832. return $this->lasth;
  2833. }
  2834. /**
  2835. * Set the adjusting factor to convert pixels to user units.
  2836. * @param $scale (float) adjusting factor to convert pixels to user units.
  2837. * @author Nicola Asuni
  2838. * @public
  2839. * @since 1.5.2
  2840. */
  2841. public function setImageScale($scale) {
  2842. $this->imgscale = $scale;
  2843. }
  2844. /**
  2845. * Returns the adjusting factor to convert pixels to user units.
  2846. * @return float adjusting factor to convert pixels to user units.
  2847. * @author Nicola Asuni
  2848. * @public
  2849. * @since 1.5.2
  2850. */
  2851. public function getImageScale() {
  2852. return $this->imgscale;
  2853. }
  2854. /**
  2855. * Returns an array of page dimensions:
  2856. * <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>
  2857. * @param $pagenum (int) page number (empty = current page)
  2858. * @return array of page dimensions.
  2859. * @author Nicola Asuni
  2860. * @public
  2861. * @since 4.5.027 (2009-03-16)
  2862. */
  2863. public function getPageDimensions($pagenum='') {
  2864. if (empty($pagenum)) {
  2865. $pagenum = $this->page;
  2866. }
  2867. return $this->pagedim[$pagenum];
  2868. }
  2869. /**
  2870. * Returns the page width in units.
  2871. * @param $pagenum (int) page number (empty = current page)
  2872. * @return int page width.
  2873. * @author Nicola Asuni
  2874. * @public
  2875. * @since 1.5.2
  2876. * @see getPageDimensions()
  2877. */
  2878. public function getPageWidth($pagenum='') {
  2879. if (empty($pagenum)) {
  2880. return $this->w;
  2881. }
  2882. return $this->pagedim[$pagenum]['w'];
  2883. }
  2884. /**
  2885. * Returns the page height in units.
  2886. * @param $pagenum (int) page number (empty = current page)
  2887. * @return int page height.
  2888. * @author Nicola Asuni
  2889. * @public
  2890. * @since 1.5.2
  2891. * @see getPageDimensions()
  2892. */
  2893. public function getPageHeight($pagenum='') {
  2894. if (empty($pagenum)) {
  2895. return $this->h;
  2896. }
  2897. return $this->pagedim[$pagenum]['h'];
  2898. }
  2899. /**
  2900. * Returns the page break margin.
  2901. * @param $pagenum (int) page number (empty = current page)
  2902. * @return int page break margin.
  2903. * @author Nicola Asuni
  2904. * @public
  2905. * @since 1.5.2
  2906. * @see getPageDimensions()
  2907. */
  2908. public function getBreakMargin($pagenum='') {
  2909. if (empty($pagenum)) {
  2910. return $this->bMargin;
  2911. }
  2912. return $this->pagedim[$pagenum]['bm'];
  2913. }
  2914. /**
  2915. * Returns the scale factor (number of points in user unit).
  2916. * @return int scale factor.
  2917. * @author Nicola Asuni
  2918. * @public
  2919. * @since 1.5.2
  2920. */
  2921. public function getScaleFactor() {
  2922. return $this->k;
  2923. }
  2924. /**
  2925. * Defines the left, top and right margins.
  2926. * @param $left (float) Left margin.
  2927. * @param $top (float) Top margin.
  2928. * @param $right (float) Right margin. Default value is the left one.
  2929. * @param $keepmargins (boolean) if true overwrites the default page margins
  2930. * @public
  2931. * @since 1.0
  2932. * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  2933. */
  2934. public function SetMargins($left, $top, $right=-1, $keepmargins=false) {
  2935. //Set left, top and right margins
  2936. $this->lMargin = $left;
  2937. $this->tMargin = $top;
  2938. if ($right == -1) {
  2939. $right = $left;
  2940. }
  2941. $this->rMargin = $right;
  2942. if ($keepmargins) {
  2943. // overwrite original values
  2944. $this->original_lMargin = $this->lMargin;
  2945. $this->original_rMargin = $this->rMargin;
  2946. }
  2947. }
  2948. /**
  2949. * 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.
  2950. * @param $margin (float) The margin.
  2951. * @public
  2952. * @since 1.4
  2953. * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2954. */
  2955. public function SetLeftMargin($margin) {
  2956. //Set left margin
  2957. $this->lMargin = $margin;
  2958. if (($this->page > 0) AND ($this->x < $margin)) {
  2959. $this->x = $margin;
  2960. }
  2961. }
  2962. /**
  2963. * Defines the top margin. The method can be called before creating the first page.
  2964. * @param $margin (float) The margin.
  2965. * @public
  2966. * @since 1.5
  2967. * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2968. */
  2969. public function SetTopMargin($margin) {
  2970. //Set top margin
  2971. $this->tMargin = $margin;
  2972. if (($this->page > 0) AND ($this->y < $margin)) {
  2973. $this->y = $margin;
  2974. }
  2975. }
  2976. /**
  2977. * Defines the right margin. The method can be called before creating the first page.
  2978. * @param $margin (float) The margin.
  2979. * @public
  2980. * @since 1.5
  2981. * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  2982. */
  2983. public function SetRightMargin($margin) {
  2984. $this->rMargin = $margin;
  2985. if (($this->page > 0) AND ($this->x > ($this->w - $margin))) {
  2986. $this->x = $this->w - $margin;
  2987. }
  2988. }
  2989. /**
  2990. * Set the same internal Cell padding for top, right, bottom, left-
  2991. * @param $pad (float) internal padding.
  2992. * @public
  2993. * @since 2.1.000 (2008-01-09)
  2994. * @see getCellPaddings(), setCellPaddings()
  2995. */
  2996. public function SetCellPadding($pad) {
  2997. if ($pad >= 0) {
  2998. $this->cell_padding['L'] = $pad;
  2999. $this->cell_padding['T'] = $pad;
  3000. $this->cell_padding['R'] = $pad;
  3001. $this->cell_padding['B'] = $pad;
  3002. }
  3003. }
  3004. /**
  3005. * Set the internal Cell paddings.
  3006. * @param $left (float) left padding
  3007. * @param $top (float) top padding
  3008. * @param $right (float) right padding
  3009. * @param $bottom (float) bottom padding
  3010. * @public
  3011. * @since 5.9.000 (2010-10-03)
  3012. * @see getCellPaddings(), SetCellPadding()
  3013. */
  3014. public function setCellPaddings($left='', $top='', $right='', $bottom='') {
  3015. if (($left !== '') AND ($left >= 0)) {
  3016. $this->cell_padding['L'] = $left;
  3017. }
  3018. if (($top !== '') AND ($top >= 0)) {
  3019. $this->cell_padding['T'] = $top;
  3020. }
  3021. if (($right !== '') AND ($right >= 0)) {
  3022. $this->cell_padding['R'] = $right;
  3023. }
  3024. if (($bottom !== '') AND ($bottom >= 0)) {
  3025. $this->cell_padding['B'] = $bottom;
  3026. }
  3027. }
  3028. /**
  3029. * Get the internal Cell padding array.
  3030. * @return array of padding values
  3031. * @public
  3032. * @since 5.9.000 (2010-10-03)
  3033. * @see setCellPaddings(), SetCellPadding()
  3034. */
  3035. public function getCellPaddings() {
  3036. return $this->cell_padding;
  3037. }
  3038. /**
  3039. * Set the internal Cell margins.
  3040. * @param $left (float) left margin
  3041. * @param $top (float) top margin
  3042. * @param $right (float) right margin
  3043. * @param $bottom (float) bottom margin
  3044. * @public
  3045. * @since 5.9.000 (2010-10-03)
  3046. * @see getCellMargins()
  3047. */
  3048. public function setCellMargins($left='', $top='', $right='', $bottom='') {
  3049. if (($left !== '') AND ($left >= 0)) {
  3050. $this->cell_margin['L'] = $left;
  3051. }
  3052. if (($top !== '') AND ($top >= 0)) {
  3053. $this->cell_margin['T'] = $top;
  3054. }
  3055. if (($right !== '') AND ($right >= 0)) {
  3056. $this->cell_margin['R'] = $right;
  3057. }
  3058. if (($bottom !== '') AND ($bottom >= 0)) {
  3059. $this->cell_margin['B'] = $bottom;
  3060. }
  3061. }
  3062. /**
  3063. * Get the internal Cell margin array.
  3064. * @return array of margin values
  3065. * @public
  3066. * @since 5.9.000 (2010-10-03)
  3067. * @see setCellMargins()
  3068. */
  3069. public function getCellMargins() {
  3070. return $this->cell_margin;
  3071. }
  3072. /**
  3073. * Adjust the internal Cell padding array to take account of the line width.
  3074. * @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)))
  3075. * @return array of adjustments
  3076. * @public
  3077. * @since 5.9.000 (2010-10-03)
  3078. */
  3079. protected function adjustCellPadding($brd=0) {
  3080. if (empty($brd)) {
  3081. return;
  3082. }
  3083. if (is_string($brd)) {
  3084. // convert string to array
  3085. $slen = strlen($brd);
  3086. $newbrd = array();
  3087. for ($i = 0; $i < $slen; ++$i) {
  3088. $newbrd[$brd{$i}] = true;
  3089. }
  3090. $brd = $newbrd;
  3091. } elseif (($brd === 1) OR ($brd === true) OR (is_numeric($brd) AND (intval($brd) > 0))) {
  3092. $brd = array('LRTB' => true);
  3093. }
  3094. if (!is_array($brd)) {
  3095. return;
  3096. }
  3097. // store current cell padding
  3098. $cp = $this->cell_padding;
  3099. // select border mode
  3100. if (isset($brd['mode'])) {
  3101. $mode = $brd['mode'];
  3102. unset($brd['mode']);
  3103. } else {
  3104. $mode = 'normal';
  3105. }
  3106. // process borders
  3107. foreach ($brd as $border => $style) {
  3108. $line_width = $this->LineWidth;
  3109. if (is_array($style) AND isset($style['width'])) {
  3110. // get border width
  3111. $line_width = $style['width'];
  3112. }
  3113. $adj = 0; // line width inside the cell
  3114. switch ($mode) {
  3115. case 'ext': {
  3116. $adj = 0;
  3117. break;
  3118. }
  3119. case 'int': {
  3120. $adj = $line_width;
  3121. break;
  3122. }
  3123. case 'normal':
  3124. default: {
  3125. $adj = ($line_width / 2);
  3126. break;
  3127. }
  3128. }
  3129. // correct internal cell padding if required to avoid overlap between text and lines
  3130. if ((strpos($border,'T') !== false) AND ($this->cell_padding['T'] < $adj)) {
  3131. $this->cell_padding['T'] = $adj;
  3132. }
  3133. if ((strpos($border,'R') !== false) AND ($this->cell_padding['R'] < $adj)) {
  3134. $this->cell_padding['R'] = $adj;
  3135. }
  3136. if ((strpos($border,'B') !== false) AND ($this->cell_padding['B'] < $adj)) {
  3137. $this->cell_padding['B'] = $adj;
  3138. }
  3139. if ((strpos($border,'L') !== false) AND ($this->cell_padding['L'] < $adj)) {
  3140. $this->cell_padding['L'] = $adj;
  3141. }
  3142. }
  3143. 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']));
  3144. }
  3145. /**
  3146. * 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.
  3147. * @param $auto (boolean) Boolean indicating if mode should be on or off.
  3148. * @param $margin (float) Distance from the bottom of the page.
  3149. * @public
  3150. * @since 1.0
  3151. * @see Cell(), MultiCell(), AcceptPageBreak()
  3152. */
  3153. public function SetAutoPageBreak($auto, $margin=0) {
  3154. $this->AutoPageBreak = $auto;
  3155. $this->bMargin = $margin;
  3156. $this->PageBreakTrigger = $this->h - $margin;
  3157. }
  3158. /**
  3159. * Defines the way the document is to be displayed by the viewer.
  3160. * @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>
  3161. * @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>
  3162. * @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>
  3163. * @public
  3164. * @since 1.2
  3165. */
  3166. public function SetDisplayMode($zoom, $layout='SinglePage', $mode='UseNone') {
  3167. if (($zoom == 'fullpage') OR ($zoom == 'fullwidth') OR ($zoom == 'real') OR ($zoom == 'default') OR (!is_string($zoom))) {
  3168. $this->ZoomMode = $zoom;
  3169. } else {
  3170. $this->Error('Incorrect zoom display mode: '.$zoom);
  3171. }
  3172. switch ($layout) {
  3173. case 'default':
  3174. case 'single':
  3175. case 'SinglePage': {
  3176. $this->LayoutMode = 'SinglePage';
  3177. break;
  3178. }
  3179. case 'continuous':
  3180. case 'OneColumn': {
  3181. $this->LayoutMode = 'OneColumn';
  3182. break;
  3183. }
  3184. case 'two':
  3185. case 'TwoColumnLeft': {
  3186. $this->LayoutMode = 'TwoColumnLeft';
  3187. break;
  3188. }
  3189. case 'TwoColumnRight': {
  3190. $this->LayoutMode = 'TwoColumnRight';
  3191. break;
  3192. }
  3193. case 'TwoPageLeft': {
  3194. $this->LayoutMode = 'TwoPageLeft';
  3195. break;
  3196. }
  3197. case 'TwoPageRight': {
  3198. $this->LayoutMode = 'TwoPageRight';
  3199. break;
  3200. }
  3201. default: {
  3202. $this->LayoutMode = 'SinglePage';
  3203. }
  3204. }
  3205. switch ($mode) {
  3206. case 'UseNone': {
  3207. $this->PageMode = 'UseNone';
  3208. break;
  3209. }
  3210. case 'UseOutlines': {
  3211. $this->PageMode = 'UseOutlines';
  3212. break;
  3213. }
  3214. case 'UseThumbs': {
  3215. $this->PageMode = 'UseThumbs';
  3216. break;
  3217. }
  3218. case 'FullScreen': {
  3219. $this->PageMode = 'FullScreen';
  3220. break;
  3221. }
  3222. case 'UseOC': {
  3223. $this->PageMode = 'UseOC';
  3224. break;
  3225. }
  3226. case '': {
  3227. $this->PageMode = 'UseAttachments';
  3228. break;
  3229. }
  3230. default: {
  3231. $this->PageMode = 'UseNone';
  3232. }
  3233. }
  3234. }
  3235. /**
  3236. * 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.
  3237. * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  3238. * @param $compress (boolean) Boolean indicating if compression must be enabled.
  3239. * @public
  3240. * @since 1.4
  3241. */
  3242. public function SetCompression($compress) {
  3243. if (function_exists('gzcompress')) {
  3244. $this->compress = $compress ? true : false;
  3245. } else {
  3246. $this->compress = false;
  3247. }
  3248. }
  3249. /**
  3250. * Turn on/off Unicode mode for document information dictionary (meta tags).
  3251. * This has effect only when unicode mode is set to false.
  3252. * @param $unicode (boolean) if true set the meta information in Unicode
  3253. * @since 5.9.027 (2010-12-01)
  3254. * @public
  3255. */
  3256. public function SetDocInfoUnicode($unicode=true) {
  3257. $this->docinfounicode = $unicode ? true : false;
  3258. }
  3259. /**
  3260. * Defines the title of the document.
  3261. * @param $title (string) The title.
  3262. * @public
  3263. * @since 1.2
  3264. * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  3265. */
  3266. public function SetTitle($title) {
  3267. $this->title = $title;
  3268. }
  3269. /**
  3270. * Defines the subject of the document.
  3271. * @param $subject (string) The subject.
  3272. * @public
  3273. * @since 1.2
  3274. * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  3275. */
  3276. public function SetSubject($subject) {
  3277. $this->subject = $subject;
  3278. }
  3279. /**
  3280. * Defines the author of the document.
  3281. * @param $author (string) The name of the author.
  3282. * @public
  3283. * @since 1.2
  3284. * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  3285. */
  3286. public function SetAuthor($author) {
  3287. $this->author = $author;
  3288. }
  3289. /**
  3290. * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  3291. * @param $keywords (string) The list of keywords.
  3292. * @public
  3293. * @since 1.2
  3294. * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  3295. */
  3296. public function SetKeywords($keywords) {
  3297. $this->keywords = $keywords;
  3298. }
  3299. /**
  3300. * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  3301. * @param $creator (string) The name of the creator.
  3302. * @public
  3303. * @since 1.2
  3304. * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  3305. */
  3306. public function SetCreator($creator) {
  3307. $this->creator = $creator;
  3308. }
  3309. /**
  3310. * This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script, or the resulting document would probably be invalid.
  3311. * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
  3312. * @param $msg (string) The error message
  3313. * @public
  3314. * @since 1.0
  3315. */
  3316. public function Error($msg) {
  3317. // unset all class variables
  3318. $this->_destroy(true);
  3319. // exit program and print error
  3320. die('<strong>TCPDF ERROR: </strong>'.$msg);
  3321. }
  3322. /**
  3323. * This method begins the generation of the PDF document.
  3324. * It is not necessary to call it explicitly because AddPage() does it automatically.
  3325. * Note: no page is created by this method
  3326. * @public
  3327. * @since 1.0
  3328. * @see AddPage(), Close()
  3329. */
  3330. public function Open() {
  3331. $this->state = 1;
  3332. }
  3333. /**
  3334. * Terminates the PDF document.
  3335. * It is not necessary to call this method explicitly because Output() does it automatically.
  3336. * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  3337. * @public
  3338. * @since 1.0
  3339. * @see Open(), Output()
  3340. */
  3341. public function Close() {
  3342. if ($this->state == 3) {
  3343. return;
  3344. }
  3345. if ($this->page == 0) {
  3346. $this->AddPage();
  3347. }
  3348. // save current graphic settings
  3349. $gvars = $this->getGraphicVars();
  3350. $this->setEqualColumns();
  3351. $this->lastpage(true);
  3352. $this->SetAutoPageBreak(false);
  3353. $this->x = 0;
  3354. $this->y = $this->h - (1 / $this->k);
  3355. $this->lMargin = 0;
  3356. $this->_out('q');
  3357. $this->SetFont('helvetica', '', 1);
  3358. $this->setTextRenderingMode(0, false, false);
  3359. $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";
  3360. $lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67";
  3361. $this->Cell(0, 0, $msg, 0, 0, 'L', 0, $lnk, 0, false, 'D', 'B');
  3362. $this->_out('Q');
  3363. // restore graphic settings
  3364. $this->setGraphicVars($gvars);
  3365. // close page
  3366. $this->endPage();
  3367. // close document
  3368. $this->_enddoc();
  3369. // unset all class variables (except critical ones)
  3370. $this->_destroy(false);
  3371. }
  3372. /**
  3373. * Move pointer at the specified document page and update page dimensions.
  3374. * @param $pnum (int) page number (1 ... numpages)
  3375. * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
  3376. * @public
  3377. * @since 2.1.000 (2008-01-07)
  3378. * @see getPage(), lastpage(), getNumPages()
  3379. */
  3380. public function setPage($pnum, $resetmargins=false) {
  3381. if (($pnum == $this->page) AND ($this->state == 2)) {
  3382. return;
  3383. }
  3384. if (($pnum > 0) AND ($pnum <= $this->numpages)) {
  3385. $this->state = 2;
  3386. // save current graphic settings
  3387. //$gvars = $this->getGraphicVars();
  3388. $oldpage = $this->page;
  3389. $this->page = $pnum;
  3390. $this->wPt = $this->pagedim[$this->page]['w'];
  3391. $this->hPt = $this->pagedim[$this->page]['h'];
  3392. $this->w = $this->pagedim[$this->page]['wk'];
  3393. $this->h = $this->pagedim[$this->page]['hk'];
  3394. $this->tMargin = $this->pagedim[$this->page]['tm'];
  3395. $this->bMargin = $this->pagedim[$this->page]['bm'];
  3396. $this->original_lMargin = $this->pagedim[$this->page]['olm'];
  3397. $this->original_rMargin = $this->pagedim[$this->page]['orm'];
  3398. $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
  3399. $this->CurOrientation = $this->pagedim[$this->page]['or'];
  3400. $this->SetAutoPageBreak($this->AutoPageBreak, $this->bMargin);
  3401. // restore graphic settings
  3402. //$this->setGraphicVars($gvars);
  3403. if ($resetmargins) {
  3404. $this->lMargin = $this->pagedim[$this->page]['olm'];
  3405. $this->rMargin = $this->pagedim[$this->page]['orm'];
  3406. $this->SetY($this->tMargin);
  3407. } else {
  3408. // account for booklet mode
  3409. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  3410. $deltam = $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm'];
  3411. $this->lMargin += $deltam;
  3412. $this->rMargin -= $deltam;
  3413. }
  3414. }
  3415. } else {
  3416. $this->Error('Wrong page number on setPage() function: '.$pnum);
  3417. }
  3418. }
  3419. /**
  3420. * Reset pointer to the last document page.
  3421. * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
  3422. * @public
  3423. * @since 2.0.000 (2008-01-04)
  3424. * @see setPage(), getPage(), getNumPages()
  3425. */
  3426. public function lastPage($resetmargins=false) {
  3427. $this->setPage($this->getNumPages(), $resetmargins);
  3428. }
  3429. /**
  3430. * Get current document page number.
  3431. * @return int page number
  3432. * @public
  3433. * @since 2.1.000 (2008-01-07)
  3434. * @see setPage(), lastpage(), getNumPages()
  3435. */
  3436. public function getPage() {
  3437. return $this->page;
  3438. }
  3439. /**
  3440. * Get the total number of insered pages.
  3441. * @return int number of pages
  3442. * @public
  3443. * @since 2.1.000 (2008-01-07)
  3444. * @see setPage(), getPage(), lastpage()
  3445. */
  3446. public function getNumPages() {
  3447. return $this->numpages;
  3448. }
  3449. /**
  3450. * Adds a new TOC (Table Of Content) page to the document.
  3451. * @param $orientation (string) page orientation.
  3452. * @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().
  3453. * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
  3454. * @public
  3455. * @since 5.0.001 (2010-05-06)
  3456. * @see AddPage(), startPage(), endPage(), endTOCPage()
  3457. */
  3458. public function addTOCPage($orientation='', $format='', $keepmargins=false) {
  3459. $this->AddPage($orientation, $format, $keepmargins, true);
  3460. }
  3461. /**
  3462. * Terminate the current TOC (Table Of Content) page
  3463. * @public
  3464. * @since 5.0.001 (2010-05-06)
  3465. * @see AddPage(), startPage(), endPage(), addTOCPage()
  3466. */
  3467. public function endTOCPage() {
  3468. $this->endPage(true);
  3469. }
  3470. /**
  3471. * 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).
  3472. * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
  3473. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  3474. * @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().
  3475. * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
  3476. * @param $tocpage (boolean) if true set the tocpage state to true (the added page will be used to display Table Of Content).
  3477. * @public
  3478. * @since 1.0
  3479. * @see startPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  3480. */
  3481. public function AddPage($orientation='', $format='', $keepmargins=false, $tocpage=false) {
  3482. if ($this->inxobj) {
  3483. // we are inside an XObject template
  3484. return;
  3485. }
  3486. if (!isset($this->original_lMargin) OR $keepmargins) {
  3487. $this->original_lMargin = $this->lMargin;
  3488. }
  3489. if (!isset($this->original_rMargin) OR $keepmargins) {
  3490. $this->original_rMargin = $this->rMargin;
  3491. }
  3492. // terminate previous page
  3493. $this->endPage();
  3494. // start new page
  3495. $this->startPage($orientation, $format, $tocpage);
  3496. }
  3497. /**
  3498. * Terminate the current page
  3499. * @param $tocpage (boolean) if true set the tocpage state to false (end the page used to display Table Of Content).
  3500. * @public
  3501. * @since 4.2.010 (2008-11-14)
  3502. * @see AddPage(), startPage(), addTOCPage(), endTOCPage()
  3503. */
  3504. public function endPage($tocpage=false) {
  3505. // check if page is already closed
  3506. if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) {
  3507. return;
  3508. }
  3509. $this->InFooter = true;
  3510. // print page footer
  3511. $this->setFooter();
  3512. // close page
  3513. $this->_endpage();
  3514. // mark page as closed
  3515. $this->pageopen[$this->page] = false;
  3516. $this->InFooter = false;
  3517. if ($tocpage) {
  3518. $this->tocpage = false;
  3519. }
  3520. }
  3521. /**
  3522. * Starts a new page to the document. The page must be closed using the endPage() function.
  3523. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  3524. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  3525. * @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().
  3526. * @param $tocpage (boolean) if true the page is designated to contain the Table-Of-Content.
  3527. * @since 4.2.010 (2008-11-14)
  3528. * @see AddPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  3529. * @public
  3530. */
  3531. public function startPage($orientation='', $format='', $tocpage=false) {
  3532. if ($tocpage) {
  3533. $this->tocpage = true;
  3534. }
  3535. if ($this->numpages > $this->page) {
  3536. // this page has been already added
  3537. $this->setPage($this->page + 1);
  3538. $this->SetY($this->tMargin);
  3539. return;
  3540. }
  3541. // start a new page
  3542. if ($this->state == 0) {
  3543. $this->Open();
  3544. }
  3545. ++$this->numpages;
  3546. $this->swapMargins($this->booklet);
  3547. // save current graphic settings
  3548. $gvars = $this->getGraphicVars();
  3549. // start new page
  3550. $this->_beginpage($orientation, $format);
  3551. // mark page as open
  3552. $this->pageopen[$this->page] = true;
  3553. // restore graphic settings
  3554. $this->setGraphicVars($gvars);
  3555. // mark this point
  3556. $this->setPageMark();
  3557. // print page header
  3558. $this->setHeader();
  3559. // restore graphic settings
  3560. $this->setGraphicVars($gvars);
  3561. // mark this point
  3562. $this->setPageMark();
  3563. // print table header (if any)
  3564. $this->setTableHeader();
  3565. // set mark for empty page check
  3566. $this->emptypagemrk[$this->page]= $this->pagelen[$this->page];
  3567. }
  3568. /**
  3569. * Set start-writing mark on current page stream used to put borders and fills.
  3570. * Borders and fills are always created after content and inserted on the position marked by this method.
  3571. * This function must be called after calling Image() function for a background image.
  3572. * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
  3573. * @public
  3574. * @since 4.0.016 (2008-07-30)
  3575. */
  3576. public function setPageMark() {
  3577. $this->intmrk[$this->page] = $this->pagelen[$this->page];
  3578. $this->bordermrk[$this->page] = $this->intmrk[$this->page];
  3579. $this->setContentMark();
  3580. }
  3581. /**
  3582. * Set start-writing mark on selected page.
  3583. * Borders and fills are always created after content and inserted on the position marked by this method.
  3584. * @param $page (int) page number (default is the current page)
  3585. * @protected
  3586. * @since 4.6.021 (2009-07-20)
  3587. */
  3588. protected function setContentMark($page=0) {
  3589. if ($page <= 0) {
  3590. $page = $this->page;
  3591. }
  3592. if (isset($this->footerlen[$page])) {
  3593. $this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
  3594. } else {
  3595. $this->cntmrk[$page] = $this->pagelen[$page];
  3596. }
  3597. }
  3598. /**
  3599. * Set header data.
  3600. * @param $ln (string) header image logo
  3601. * @param $lw (string) header image logo width in mm
  3602. * @param $ht (string) string to print as title on document header
  3603. * @param $hs (string) string to print on document header
  3604. * @public
  3605. */
  3606. public function setHeaderData($ln='', $lw=0, $ht='', $hs='') {
  3607. $this->header_logo = $ln;
  3608. $this->header_logo_width = $lw;
  3609. $this->header_title = $ht;
  3610. $this->header_string = $hs;
  3611. }
  3612. /**
  3613. * Returns header data:
  3614. * <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>
  3615. * @return array()
  3616. * @public
  3617. * @since 4.0.012 (2008-07-24)
  3618. */
  3619. public function getHeaderData() {
  3620. $ret = array();
  3621. $ret['logo'] = $this->header_logo;
  3622. $ret['logo_width'] = $this->header_logo_width;
  3623. $ret['title'] = $this->header_title;
  3624. $ret['string'] = $this->header_string;
  3625. return $ret;
  3626. }
  3627. /**
  3628. * Set header margin.
  3629. * (minimum distance between header and top page margin)
  3630. * @param $hm (int) distance in user units
  3631. * @public
  3632. */
  3633. public function setHeaderMargin($hm=10) {
  3634. $this->header_margin = $hm;
  3635. }
  3636. /**
  3637. * Returns header margin in user units.
  3638. * @return float
  3639. * @since 4.0.012 (2008-07-24)
  3640. * @public
  3641. */
  3642. public function getHeaderMargin() {
  3643. return $this->header_margin;
  3644. }
  3645. /**
  3646. * Set footer margin.
  3647. * (minimum distance between footer and bottom page margin)
  3648. * @param $fm (int) distance in user units
  3649. * @public
  3650. */
  3651. public function setFooterMargin($fm=10) {
  3652. $this->footer_margin = $fm;
  3653. }
  3654. /**
  3655. * Returns footer margin in user units.
  3656. * @return float
  3657. * @since 4.0.012 (2008-07-24)
  3658. * @public
  3659. */
  3660. public function getFooterMargin() {
  3661. return $this->footer_margin;
  3662. }
  3663. /**
  3664. * Set a flag to print page header.
  3665. * @param $val (boolean) set to true to print the page header (default), false otherwise.
  3666. * @public
  3667. */
  3668. public function setPrintHeader($val=true) {
  3669. $this->print_header = $val;
  3670. }
  3671. /**
  3672. * Set a flag to print page footer.
  3673. * @param $val (boolean) set to true to print the page footer (default), false otherwise.
  3674. * @public
  3675. */
  3676. public function setPrintFooter($val=true) {
  3677. $this->print_footer = $val;
  3678. }
  3679. /**
  3680. * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
  3681. * @return float
  3682. * @public
  3683. */
  3684. public function getImageRBX() {
  3685. return $this->img_rb_x;
  3686. }
  3687. /**
  3688. * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
  3689. * @return float
  3690. * @public
  3691. */
  3692. public function getImageRBY() {
  3693. return $this->img_rb_y;
  3694. }
  3695. /**
  3696. * This method is used to render the page header.
  3697. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3698. * @public
  3699. */
  3700. public function Header() {
  3701. $ormargins = $this->getOriginalMargins();
  3702. $headerfont = $this->getHeaderFont();
  3703. $headerdata = $this->getHeaderData();
  3704. if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) {
  3705. $imgtype = $this->getImageFileType(K_PATH_IMAGES.$headerdata['logo']);
  3706. if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  3707. $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3708. } elseif ($imgtype == 'svg') {
  3709. $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3710. } else {
  3711. $this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3712. }
  3713. $imgy = $this->getImageRBY();
  3714. } else {
  3715. $imgy = $this->GetY();
  3716. }
  3717. $cell_height = round(($this->getCellHeightRatio() * $headerfont[2]) / $this->getScaleFactor(), 2);
  3718. // set starting margin for text data cell
  3719. if ($this->getRTL()) {
  3720. $header_x = $ormargins['right'] + ($headerdata['logo_width'] * 1.1);
  3721. } else {
  3722. $header_x = $ormargins['left'] + ($headerdata['logo_width'] * 1.1);
  3723. }
  3724. $this->SetTextColor(0, 0, 0);
  3725. // header title
  3726. $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1);
  3727. $this->SetX($header_x);
  3728. $this->Cell(0, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
  3729. // header string
  3730. $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
  3731. $this->SetX($header_x);
  3732. $this->MultiCell(0, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false);
  3733. // print an ending header line
  3734. $this->SetLineStyle(array('width' => 0.85 / $this->getScaleFactor(), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
  3735. $this->SetY((2.835 / $this->getScaleFactor()) + max($imgy, $this->GetY()));
  3736. if ($this->getRTL()) {
  3737. $this->SetX($ormargins['right']);
  3738. } else {
  3739. $this->SetX($ormargins['left']);
  3740. }
  3741. $this->Cell(0, 0, '', 'T', 0, 'C');
  3742. }
  3743. /**
  3744. * This method is used to render the page footer.
  3745. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3746. * @public
  3747. */
  3748. public function Footer() {
  3749. $cur_y = $this->GetY();
  3750. $ormargins = $this->getOriginalMargins();
  3751. $this->SetTextColor(0, 0, 0);
  3752. //set style for cell border
  3753. $line_width = 0.85 / $this->getScaleFactor();
  3754. $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
  3755. //print document barcode
  3756. $barcode = $this->getBarcode();
  3757. if (!empty($barcode)) {
  3758. $this->Ln($line_width);
  3759. $barcode_width = round(($this->getPageWidth() - $ormargins['left'] - $ormargins['right']) / 3);
  3760. $style = array(
  3761. 'position' => $this->rtl?'R':'L',
  3762. 'align' => $this->rtl?'R':'L',
  3763. 'stretch' => false,
  3764. 'fitwidth' => true,
  3765. 'cellfitalign' => '',
  3766. 'border' => false,
  3767. 'padding' => 0,
  3768. 'fgcolor' => array(0,0,0),
  3769. 'bgcolor' => false,
  3770. 'text' => false
  3771. );
  3772. $this->write1DBarcode($barcode, 'C128B', '', $cur_y + $line_width, '', (($this->getFooterMargin() / 3) - $line_width), 0.3, $style, '');
  3773. }
  3774. if (empty($this->pagegroups)) {
  3775. $pagenumtxt = $this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
  3776. } else {
  3777. $pagenumtxt = $this->l['w_page'].' '.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
  3778. }
  3779. $this->SetY($cur_y);
  3780. //Print page number
  3781. if ($this->getRTL()) {
  3782. $this->SetX($ormargins['right']);
  3783. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
  3784. } else {
  3785. $this->SetX($ormargins['left']);
  3786. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'R');
  3787. }
  3788. }
  3789. /**
  3790. * This method is used to render the page header.
  3791. * @protected
  3792. * @since 4.0.012 (2008-07-24)
  3793. */
  3794. protected function setHeader() {
  3795. if ($this->print_header) {
  3796. $this->setGraphicVars($this->default_graphic_vars);
  3797. $temp_thead = $this->thead;
  3798. $temp_theadMargins = $this->theadMargins;
  3799. $lasth = $this->lasth;
  3800. $this->_out('q');
  3801. $this->rMargin = $this->original_rMargin;
  3802. $this->lMargin = $this->original_lMargin;
  3803. $this->SetCellPadding(0);
  3804. //set current position
  3805. if ($this->rtl) {
  3806. $this->SetXY($this->original_rMargin, $this->header_margin);
  3807. } else {
  3808. $this->SetXY($this->original_lMargin, $this->header_margin);
  3809. }
  3810. $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
  3811. $this->Header();
  3812. //restore position
  3813. if ($this->rtl) {
  3814. $this->SetXY($this->original_rMargin, $this->tMargin);
  3815. } else {
  3816. $this->SetXY($this->original_lMargin, $this->tMargin);
  3817. }
  3818. $this->_out('Q');
  3819. $this->lasth = $lasth;
  3820. $this->thead = $temp_thead;
  3821. $this->theadMargins = $temp_theadMargins;
  3822. $this->newline = false;
  3823. }
  3824. }
  3825. /**
  3826. * This method is used to render the page footer.
  3827. * @protected
  3828. * @since 4.0.012 (2008-07-24)
  3829. */
  3830. protected function setFooter() {
  3831. //Page footer
  3832. // save current graphic settings
  3833. $gvars = $this->getGraphicVars();
  3834. // mark this point
  3835. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  3836. $this->_out("\n");
  3837. if ($this->print_footer) {
  3838. $this->setGraphicVars($this->default_graphic_vars);
  3839. $this->current_column = 0;
  3840. $this->num_columns = 1;
  3841. $temp_thead = $this->thead;
  3842. $temp_theadMargins = $this->theadMargins;
  3843. $lasth = $this->lasth;
  3844. $this->_out('q');
  3845. $this->rMargin = $this->original_rMargin;
  3846. $this->lMargin = $this->original_lMargin;
  3847. $this->SetCellPadding(0);
  3848. //set current position
  3849. $footer_y = $this->h - $this->footer_margin;
  3850. if ($this->rtl) {
  3851. $this->SetXY($this->original_rMargin, $footer_y);
  3852. } else {
  3853. $this->SetXY($this->original_lMargin, $footer_y);
  3854. }
  3855. $this->SetFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
  3856. $this->Footer();
  3857. //restore position
  3858. if ($this->rtl) {
  3859. $this->SetXY($this->original_rMargin, $this->tMargin);
  3860. } else {
  3861. $this->SetXY($this->original_lMargin, $this->tMargin);
  3862. }
  3863. $this->_out('Q');
  3864. $this->lasth = $lasth;
  3865. $this->thead = $temp_thead;
  3866. $this->theadMargins = $temp_theadMargins;
  3867. }
  3868. // restore graphic settings
  3869. $this->setGraphicVars($gvars);
  3870. $this->current_column = $gvars['current_column'];
  3871. $this->num_columns = $gvars['num_columns'];
  3872. // calculate footer length
  3873. $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1;
  3874. }
  3875. /**
  3876. * This method is used to render the table header on new page (if any).
  3877. * @protected
  3878. * @since 4.5.030 (2009-03-25)
  3879. */
  3880. protected function setTableHeader() {
  3881. if ($this->num_columns > 1) {
  3882. // multi column mode
  3883. return;
  3884. }
  3885. if (isset($this->theadMargins['top'])) {
  3886. // restore the original top-margin
  3887. $this->tMargin = $this->theadMargins['top'];
  3888. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3889. $this->y = $this->tMargin;
  3890. }
  3891. if (!$this->empty_string($this->thead) AND (!$this->inthead)) {
  3892. // set margins
  3893. $prev_lMargin = $this->lMargin;
  3894. $prev_rMargin = $this->rMargin;
  3895. $prev_cell_padding = $this->cell_padding;
  3896. $this->lMargin = $this->theadMargins['lmargin'] + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$this->theadMargins['page']]['olm']);
  3897. $this->rMargin = $this->theadMargins['rmargin'] + ($this->pagedim[$this->page]['orm'] - $this->pagedim[$this->theadMargins['page']]['orm']);
  3898. $this->cell_padding = $this->theadMargins['cell_padding'];
  3899. if ($this->rtl) {
  3900. $this->x = $this->w - $this->rMargin;
  3901. } else {
  3902. $this->x = $this->lMargin;
  3903. }
  3904. // print table header
  3905. $this->writeHTML($this->thead, false, false, false, false, '');
  3906. // set new top margin to skip the table headers
  3907. if (!isset($this->theadMargins['top'])) {
  3908. $this->theadMargins['top'] = $this->tMargin;
  3909. }
  3910. // store end of header position
  3911. if (!isset($this->columns[0]['th'])) {
  3912. $this->columns[0]['th'] = array();
  3913. }
  3914. $this->columns[0]['th']['\''.$this->page.'\''] = $this->y;
  3915. $this->tMargin = $this->y;
  3916. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3917. $this->lasth = 0;
  3918. $this->lMargin = $prev_lMargin;
  3919. $this->rMargin = $prev_rMargin;
  3920. $this->cell_padding = $prev_cell_padding;
  3921. }
  3922. }
  3923. /**
  3924. * Returns the current page number.
  3925. * @return int page number
  3926. * @public
  3927. * @since 1.0
  3928. * @see AliasNbPages(), getAliasNbPages()
  3929. */
  3930. public function PageNo() {
  3931. return $this->page;
  3932. }
  3933. /**
  3934. * Defines a new spot color.
  3935. * It can be expressed in RGB components or gray scale.
  3936. * The method can be called before the first page is created and the value is retained from page to page.
  3937. * @param $name (string) name of the spot color
  3938. * @param $c (int) Cyan color for CMYK. Value between 0 and 100
  3939. * @param $m (int) Magenta color for CMYK. Value between 0 and 100
  3940. * @param $y (int) Yellow color for CMYK. Value between 0 and 100
  3941. * @param $k (int) Key (Black) color for CMYK. Value between 0 and 100
  3942. * @public
  3943. * @since 4.0.024 (2008-09-12)
  3944. * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  3945. */
  3946. public function AddSpotColor($name, $c, $m, $y, $k) {
  3947. if (!isset($this->spot_colors[$name])) {
  3948. $i = 1 + count($this->spot_colors);
  3949. $this->spot_colors[$name] = array('i' => $i, 'c' => $c, 'm' => $m, 'y' => $y, 'k' => $k);
  3950. }
  3951. $color = preg_replace('/[\s]*/', '', $name); // remove extra spaces
  3952. $color = strtolower($color);
  3953. if (!isset($this->spotcolor[$color])) {
  3954. $this->spotcolor[$color] = array($c, $m, $y, $k, $name);
  3955. }
  3956. }
  3957. /**
  3958. * Defines the color used for all drawing operations (lines, rectangles and cell borders).
  3959. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3960. * The method can be called before the first page is created and the value is retained from page to page.
  3961. * @param $color (array) array of colors
  3962. * @param $ret (boolean) if true do not send the PDF command.
  3963. * @return string the PDF command
  3964. * @public
  3965. * @since 3.1.000 (2008-06-11)
  3966. * @see SetDrawColor()
  3967. */
  3968. public function SetDrawColorArray($color, $ret=false) {
  3969. if (is_array($color)) {
  3970. $color = array_values($color);
  3971. $r = isset($color[0]) ? $color[0] : -1;
  3972. $g = isset($color[1]) ? $color[1] : -1;
  3973. $b = isset($color[2]) ? $color[2] : -1;
  3974. $k = isset($color[3]) ? $color[3] : -1;
  3975. $name = isset($color[4]) ? $color[4] : ''; // spot color name
  3976. if ($r >= 0) {
  3977. return $this->SetDrawColor($r, $g, $b, $k, $ret, $name);
  3978. }
  3979. }
  3980. return '';
  3981. }
  3982. /**
  3983. * 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.
  3984. * @param $col1 (int) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3985. * @param $col2 (int) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3986. * @param $col3 (int) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3987. * @param $col4 (int) KEY (BLACK) color for CMYK (0-100).
  3988. * @param $ret (boolean) if true do not send the command.
  3989. * @param $name (string) spot color name (if any)
  3990. * @return string the PDF command
  3991. * @public
  3992. * @since 1.3
  3993. * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  3994. */
  3995. public function SetDrawColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3996. // set default values
  3997. if (!is_numeric($col1)) {
  3998. $col1 = 0;
  3999. }
  4000. if (!is_numeric($col2)) {
  4001. $col2 = -1;
  4002. }
  4003. if (!is_numeric($col3)) {
  4004. $col3 = -1;
  4005. }
  4006. if (!is_numeric($col4)) {
  4007. $col4 = -1;
  4008. }
  4009. //Set color for all stroking operations
  4010. if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
  4011. // Grey scale
  4012. $this->DrawColor = sprintf('%.3F G', ($col1 / 255));
  4013. $this->strokecolor = array('G' => $col1);
  4014. } elseif ($col4 == -1) {
  4015. // RGB
  4016. $this->DrawColor = sprintf('%.3F %.3F %.3F RG', ($col1 / 255), ($col2 / 255), ($col3 / 255));
  4017. $this->strokecolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  4018. } elseif (empty($name)) {
  4019. // CMYK
  4020. $this->DrawColor = sprintf('%.3F %.3F %.3F %.3F K', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
  4021. $this->strokecolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  4022. } else {
  4023. // SPOT COLOR
  4024. $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
  4025. $this->DrawColor = sprintf('/CS%d CS %.3F SCN', $this->spot_colors[$name]['i'], 1);
  4026. $this->strokecolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
  4027. }
  4028. if ($this->page > 0) {
  4029. if (!$ret) {
  4030. $this->_out($this->DrawColor);
  4031. }
  4032. return $this->DrawColor;
  4033. }
  4034. return '';
  4035. }
  4036. /**
  4037. * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
  4038. * @param $name (string) name of the spot color
  4039. * @param $tint (int) the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  4040. * @public
  4041. * @since 4.0.024 (2008-09-12)
  4042. * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  4043. */
  4044. public function SetDrawSpotColor($name, $tint=100) {
  4045. if (!isset($this->spot_colors[$name])) {
  4046. $this->Error('Undefined spot color: '.$name);
  4047. }
  4048. $this->DrawColor = sprintf('/CS%d CS %.3F SCN', $this->spot_colors[$name]['i'], ($tint / 100));
  4049. $this->strokecolor = array('C' => $this->spot_colors[$name]['c'], 'M' => $this->spot_colors[$name]['m'], 'Y' => $this->spot_colors[$name]['y'], 'K' => $this->spot_colors[$name]['k'], 'name' => $name);
  4050. if ($this->page > 0) {
  4051. $this->_out($this->DrawColor);
  4052. }
  4053. }
  4054. /**
  4055. * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
  4056. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  4057. * The method can be called before the first page is created and the value is retained from page to page.
  4058. * @param $color (array) array of colors
  4059. * @param $ret (boolean) if true do not send the PDF command.
  4060. * @public
  4061. * @since 3.1.000 (2008-6-11)
  4062. * @see SetFillColor()
  4063. */
  4064. public function SetFillColorArray($color, $ret=false) {
  4065. if (is_array($color)) {
  4066. $color = array_values($color);
  4067. $r = isset($color[0]) ? $color[0] : -1;
  4068. $g = isset($color[1]) ? $color[1] : -1;
  4069. $b = isset($color[2]) ? $color[2] : -1;
  4070. $k = isset($color[3]) ? $color[3] : -1;
  4071. $name = isset($color[4]) ? $color[4] : ''; // spot color name
  4072. if ($r >= 0) {
  4073. $this->SetFillColor($r, $g, $b, $k, $ret, $name);
  4074. }
  4075. }
  4076. }
  4077. /**
  4078. * 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.
  4079. * @param $col1 (int) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  4080. * @param $col2 (int) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  4081. * @param $col3 (int) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  4082. * @param $col4 (int) KEY (BLACK) color for CMYK (0-100).
  4083. * @param $ret (boolean) if true do not send the command.
  4084. * @param $name (string) spot color name (if any)
  4085. * @return string the PDF command
  4086. * @public
  4087. * @since 1.3
  4088. * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  4089. */
  4090. public function SetFillColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  4091. // set default values
  4092. if (!is_numeric($col1)) {
  4093. $col1 = 0;
  4094. }
  4095. if (!is_numeric($col2)) {
  4096. $col2 = -1;
  4097. }
  4098. if (!is_numeric($col3)) {
  4099. $col3 = -1;
  4100. }
  4101. if (!is_numeric($col4)) {
  4102. $col4 = -1;
  4103. }
  4104. //Set color for all filling operations
  4105. if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
  4106. // Grey scale
  4107. $this->FillColor = sprintf('%.3F g', ($col1 / 255));
  4108. $this->bgcolor = array('G' => $col1);
  4109. } elseif ($col4 == -1) {
  4110. // RGB
  4111. $this->FillColor = sprintf('%.3F %.3F %.3F rg', ($col1 / 255), ($col2 / 255), ($col3 / 255));
  4112. $this->bgcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  4113. } elseif (empty($name)) {
  4114. // CMYK
  4115. $this->FillColor = sprintf('%.3F %.3F %.3F %.3F k', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
  4116. $this->bgcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  4117. } else {
  4118. // SPOT COLOR
  4119. $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
  4120. $this->FillColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], 1);
  4121. $this->bgcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
  4122. }
  4123. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  4124. if ($this->page > 0) {
  4125. if (!$ret) {
  4126. $this->_out($this->FillColor);
  4127. }
  4128. return $this->FillColor;
  4129. }
  4130. return '';
  4131. }
  4132. /**
  4133. * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
  4134. * @param $name (string) name of the spot color
  4135. * @param $tint (int) the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  4136. * @public
  4137. * @since 4.0.024 (2008-09-12)
  4138. * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
  4139. */
  4140. public function SetFillSpotColor($name, $tint=100) {
  4141. if (!isset($this->spot_colors[$name])) {
  4142. $this->Error('Undefined spot color: '.$name);
  4143. }
  4144. $this->FillColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], ($tint / 100));
  4145. $this->bgcolor = array('C' => $this->spot_colors[$name]['c'], 'M' => $this->spot_colors[$name]['m'], 'Y' => $this->spot_colors[$name]['y'], 'K' => $this->spot_colors[$name]['k'], 'name' => $name);
  4146. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  4147. if ($this->page > 0) {
  4148. $this->_out($this->FillColor);
  4149. }
  4150. }
  4151. /**
  4152. * Defines the color used for text. It can be expressed in RGB components or gray scale.
  4153. * The method can be called before the first page is created and the value is retained from page to page.
  4154. * @param $color (array) array of colors
  4155. * @param $ret (boolean) if true do not send the PDF command.
  4156. * @public
  4157. * @since 3.1.000 (2008-6-11)
  4158. * @see SetFillColor()
  4159. */
  4160. public function SetTextColorArray($color, $ret=false) {
  4161. if (is_array($color)) {
  4162. $color = array_values($color);
  4163. $r = isset($color[0]) ? $color[0] : -1;
  4164. $g = isset($color[1]) ? $color[1] : -1;
  4165. $b = isset($color[2]) ? $color[2] : -1;
  4166. $k = isset($color[3]) ? $color[3] : -1;
  4167. $name = isset($color[4]) ? $color[4] : ''; // spot color name
  4168. if ($r >= 0) {
  4169. $this->SetTextColor($r, $g, $b, $k, $ret, $name);
  4170. }
  4171. }
  4172. }
  4173. /**
  4174. * 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.
  4175. * @param $col1 (int) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  4176. * @param $col2 (int) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  4177. * @param $col3 (int) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  4178. * @param $col4 (int) KEY (BLACK) color for CMYK (0-100).
  4179. * @param $ret (boolean) if true do not send the command.
  4180. * @param $name (string) spot color name (if any)
  4181. * @public
  4182. * @since 1.3
  4183. * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  4184. */
  4185. public function SetTextColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  4186. // set default values
  4187. if (!is_numeric($col1)) {
  4188. $col1 = 0;
  4189. }
  4190. if (!is_numeric($col2)) {
  4191. $col2 = -1;
  4192. }
  4193. if (!is_numeric($col3)) {
  4194. $col3 = -1;
  4195. }
  4196. if (!is_numeric($col4)) {
  4197. $col4 = -1;
  4198. }
  4199. //Set color for text
  4200. if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
  4201. // Grey scale
  4202. $this->TextColor = sprintf('%.3F g', ($col1 / 255));
  4203. $this->fgcolor = array('G' => $col1);
  4204. } elseif ($col4 == -1) {
  4205. // RGB
  4206. $this->TextColor = sprintf('%.3F %.3F %.3F rg', ($col1 / 255), ($col2 / 255), ($col3 / 255));
  4207. $this->fgcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  4208. } elseif (empty($name)) {
  4209. // CMYK
  4210. $this->TextColor = sprintf('%.3F %.3F %.3F %.3F k', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
  4211. $this->fgcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  4212. } else {
  4213. // SPOT COLOR
  4214. $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
  4215. $this->TextColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], 1);
  4216. $this->fgcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
  4217. }
  4218. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  4219. }
  4220. /**
  4221. * Defines the spot color used for text.
  4222. * @param $name (string) name of the spot color
  4223. * @param $tint (int) the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  4224. * @public
  4225. * @since 4.0.024 (2008-09-12)
  4226. * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
  4227. */
  4228. public function SetTextSpotColor($name, $tint=100) {
  4229. if (!isset($this->spot_colors[$name])) {
  4230. $this->Error('Undefined spot color: '.$name);
  4231. }
  4232. $this->TextColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], ($tint / 100));
  4233. $this->fgcolor = array('C' => $this->spot_colors[$name]['c'], 'M' => $this->spot_colors[$name]['m'], 'Y' => $this->spot_colors[$name]['y'], 'K' => $this->spot_colors[$name]['k'], 'name' => $name);
  4234. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  4235. if ($this->page > 0) {
  4236. $this->_out($this->TextColor);
  4237. }
  4238. }
  4239. /**
  4240. * Returns the length of a string in user unit. A font must be selected.<br>
  4241. * @param $s (string) The string whose length is to be computed
  4242. * @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.
  4243. * @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-trough</li><li>O: overline</li></ul> or any combination. The default value is regular.
  4244. * @param $fontsize (float) Font size in points. The default value is the current size.
  4245. * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
  4246. * @return mixed int total string length or array of characted widths
  4247. * @author Nicola Asuni
  4248. * @public
  4249. * @since 1.2
  4250. */
  4251. public function GetStringWidth($s, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
  4252. return $this->GetArrStringWidth($this->utf8Bidi($this->UTF8StringToArray($s), $s, $this->tmprtl), $fontname, $fontstyle, $fontsize, $getarray);
  4253. }
  4254. /**
  4255. * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
  4256. * @param $sa (string) The array of chars whose total length is to be computed
  4257. * @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.
  4258. * @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 trough</li><li>O: overline</li></ul> or any combination. The default value is regular.
  4259. * @param $fontsize (float) Font size in points. The default value is the current size.
  4260. * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
  4261. * @return mixed int total string length or array of characted widths
  4262. * @author Nicola Asuni
  4263. * @public
  4264. * @since 2.4.000 (2008-03-06)
  4265. */
  4266. public function GetArrStringWidth($sa, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
  4267. // store current values
  4268. if (!$this->empty_string($fontname)) {
  4269. $prev_FontFamily = $this->FontFamily;
  4270. $prev_FontStyle = $this->FontStyle;
  4271. $prev_FontSizePt = $this->FontSizePt;
  4272. $this->SetFont($fontname, $fontstyle, $fontsize);
  4273. }
  4274. // convert UTF-8 array to Latin1 if required
  4275. $sa = $this->UTF8ArrToLatin1($sa);
  4276. $w = 0; // total width
  4277. $wa = array(); // array of characters widths
  4278. foreach ($sa as $ck => $char) {
  4279. // character width
  4280. $cw = $this->GetCharWidth($char, isset($sa[($ck + 1)]));
  4281. $wa[] = $cw;
  4282. $w += $cw;
  4283. }
  4284. // restore previous values
  4285. if (!$this->empty_string($fontname)) {
  4286. $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt);
  4287. }
  4288. if ($getarray) {
  4289. return $wa;
  4290. }
  4291. return $w;
  4292. }
  4293. /**
  4294. * Returns the length of the char in user unit for the current font considering current stretching and spacing (tracking/kerning).
  4295. * @param $char (int) The char code whose length is to be returned
  4296. * @param $notlast (boolean) set to false for the latest character on string, true otherwise (default)
  4297. * @return float char width
  4298. * @author Nicola Asuni
  4299. * @public
  4300. * @since 2.4.000 (2008-03-06)
  4301. */
  4302. public function GetCharWidth($char, $notlast=true) {
  4303. // get raw width
  4304. $chw = $this->getRawCharWidth($char);
  4305. if (($this->font_spacing != 0) AND $notlast) {
  4306. // increase/decrease font spacing
  4307. $chw += $this->font_spacing;
  4308. }
  4309. if ($this->font_stretching != 100) {
  4310. // fixed stretching mode
  4311. $chw *= ($this->font_stretching / 100);
  4312. }
  4313. return $chw;
  4314. }
  4315. /**
  4316. * Returns the length of the char in user unit for the current font.
  4317. * @param $char (int) The char code whose length is to be returned
  4318. * @return float char width
  4319. * @author Nicola Asuni
  4320. * @public
  4321. * @since 5.9.000 (2010-09-28)
  4322. */
  4323. public function getRawCharWidth($char) {
  4324. if ($char == 173) {
  4325. // SHY character will not be printed
  4326. return (0);
  4327. }
  4328. $cw = &$this->CurrentFont['cw'];
  4329. if (isset($cw[$char])) {
  4330. $w = $cw[$char];
  4331. } elseif (isset($this->CurrentFont['dw'])) {
  4332. // default width
  4333. $w = $this->CurrentFont['dw'];
  4334. } elseif (isset($cw[32])) {
  4335. // default width
  4336. $w = $cw[32];
  4337. } else {
  4338. $w = 600;
  4339. }
  4340. return ($w * $this->FontSize / 1000);
  4341. }
  4342. /**
  4343. * Returns the numbero of characters in a string.
  4344. * @param $s (string) The input string.
  4345. * @return int number of characters
  4346. * @public
  4347. * @since 2.0.0001 (2008-01-07)
  4348. */
  4349. public function GetNumChars($s) {
  4350. if ($this->isUnicodeFont()) {
  4351. return count($this->UTF8StringToArray($s));
  4352. }
  4353. return strlen($s);
  4354. }
  4355. /**
  4356. * Fill the list of available fonts ($this->fontlist).
  4357. * @protected
  4358. * @since 4.0.013 (2008-07-28)
  4359. */
  4360. protected function getFontsList() {
  4361. $fontsdir = opendir($this->_getfontpath());
  4362. while (($file = readdir($fontsdir)) !== false) {
  4363. if (substr($file, -4) == '.php') {
  4364. array_push($this->fontlist, strtolower(basename($file, '.php')));
  4365. }
  4366. }
  4367. closedir($fontsdir);
  4368. }
  4369. /**
  4370. * Imports a TrueType, Type1, core, or CID0 font and makes it available.
  4371. * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
  4372. * 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.
  4373. * @param $family (string) Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  4374. * @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>
  4375. * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  4376. * @return array containing the font data, or false in case of error.
  4377. * @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.
  4378. * @public
  4379. * @since 1.5
  4380. * @see SetFont(), setFontSubsetting()
  4381. */
  4382. public function AddFont($family, $style='', $fontfile='', $subset='default') {
  4383. if ($subset === 'default') {
  4384. $subset = $this->font_subsetting;
  4385. }
  4386. if ($this->empty_string($family)) {
  4387. if (!$this->empty_string($this->FontFamily)) {
  4388. $family = $this->FontFamily;
  4389. } else {
  4390. $this->Error('Empty font family');
  4391. }
  4392. }
  4393. // move embedded styles on $style
  4394. if (substr($family, -1) == 'I') {
  4395. $style .= 'I';
  4396. $family = substr($family, 0, -1);
  4397. }
  4398. if (substr($family, -1) == 'B') {
  4399. $style .= 'B';
  4400. $family = substr($family, 0, -1);
  4401. }
  4402. // normalize family name
  4403. $family = strtolower($family);
  4404. if ((!$this->isunicode) AND ($family == 'arial')) {
  4405. $family = 'helvetica';
  4406. }
  4407. if (($family == 'symbol') OR ($family == 'zapfdingbats')) {
  4408. $style = '';
  4409. }
  4410. $tempstyle = strtoupper($style);
  4411. $style = '';
  4412. // underline
  4413. if (strpos($tempstyle, 'U') !== false) {
  4414. $this->underline = true;
  4415. } else {
  4416. $this->underline = false;
  4417. }
  4418. // line-through (deleted)
  4419. if (strpos($tempstyle, 'D') !== false) {
  4420. $this->linethrough = true;
  4421. } else {
  4422. $this->linethrough = false;
  4423. }
  4424. // overline
  4425. if (strpos($tempstyle, 'O') !== false) {
  4426. $this->overline = true;
  4427. } else {
  4428. $this->overline = false;
  4429. }
  4430. // bold
  4431. if (strpos($tempstyle, 'B') !== false) {
  4432. $style .= 'B';
  4433. }
  4434. // oblique
  4435. if (strpos($tempstyle, 'I') !== false) {
  4436. $style .= 'I';
  4437. }
  4438. $bistyle = $style;
  4439. $fontkey = $family.$style;
  4440. $font_style = $style.($this->underline ? 'U' : '').($this->linethrough ? 'D' : '').($this->overline ? 'O' : '');
  4441. $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style);
  4442. // check if the font has been already added
  4443. $fb = $this->getFontBuffer($fontkey);
  4444. if ($fb !== false) {
  4445. if ($this->inxobj) {
  4446. // we are inside an XObject template
  4447. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $fb['i'];
  4448. }
  4449. return $fontdata;
  4450. }
  4451. if (isset($type)) {
  4452. unset($type);
  4453. }
  4454. if (isset($cw)) {
  4455. unset($cw);
  4456. }
  4457. // get specified font directory (if any)
  4458. $fontdir = false;
  4459. if (!$this->empty_string($fontfile)) {
  4460. $fontdir = dirname($fontfile);
  4461. if ($this->empty_string($fontdir) OR ($fontdir == '.')) {
  4462. $fontdir = '';
  4463. } else {
  4464. $fontdir .= '/';
  4465. }
  4466. }
  4467. // search and include font file
  4468. if ($this->empty_string($fontfile) OR (!file_exists($fontfile))) {
  4469. // build a standard filenames for specified font
  4470. $fontfile1 = str_replace(' ', '', $family).strtolower($style).'.php';
  4471. $fontfile2 = str_replace(' ', '', $family).'.php';
  4472. // search files on various directories
  4473. if (($fontdir !== false) AND file_exists($fontdir.$fontfile1)) {
  4474. $fontfile = $fontdir.$fontfile1;
  4475. } elseif (file_exists($this->_getfontpath().$fontfile1)) {
  4476. $fontfile = $this->_getfontpath().$fontfile1;
  4477. } elseif (file_exists($fontfile1)) {
  4478. $fontfile = $fontfile1;
  4479. } elseif (($fontdir !== false) AND file_exists($fontdir.$fontfile2)) {
  4480. $fontfile = $fontdir.$fontfile2;
  4481. } elseif (file_exists($this->_getfontpath().$fontfile2)) {
  4482. $fontfile = $this->_getfontpath().$fontfile2;
  4483. } else {
  4484. $fontfile = $fontfile2;
  4485. }
  4486. }
  4487. // include font file
  4488. if (file_exists($fontfile)) {
  4489. include($fontfile);
  4490. } else {
  4491. $this->Error('Could not include font definition file: '.$family.'');
  4492. }
  4493. // check font parameters
  4494. if ((!isset($type)) OR (!isset($cw))) {
  4495. $this->Error('The font definition file has a bad format: '.$fontfile.'');
  4496. }
  4497. // SET default parameters
  4498. if (!isset($file) OR $this->empty_string($file)) {
  4499. $file = '';
  4500. }
  4501. if (!isset($enc) OR $this->empty_string($enc)) {
  4502. $enc = '';
  4503. }
  4504. if (!isset($cidinfo) OR $this->empty_string($cidinfo)) {
  4505. $cidinfo = array('Registry'=>'Adobe','Ordering'=>'Identity','Supplement'=>0);
  4506. $cidinfo['uni2cid'] = array();
  4507. }
  4508. if (!isset($ctg) OR $this->empty_string($ctg)) {
  4509. $ctg = '';
  4510. }
  4511. if (!isset($desc) OR $this->empty_string($desc)) {
  4512. $desc = array();
  4513. }
  4514. if (!isset($up) OR $this->empty_string($up)) {
  4515. $up = -100;
  4516. }
  4517. if (!isset($ut) OR $this->empty_string($ut)) {
  4518. $ut = 50;
  4519. }
  4520. if (!isset($cw) OR $this->empty_string($cw)) {
  4521. $cw = array();
  4522. }
  4523. if (!isset($dw) OR $this->empty_string($dw)) {
  4524. // set default width
  4525. if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) {
  4526. $dw = $desc['MissingWidth'];
  4527. } elseif (isset($cw[32])) {
  4528. $dw = $cw[32];
  4529. } else {
  4530. $dw = 600;
  4531. }
  4532. }
  4533. ++$this->numfonts;
  4534. if ($type == 'cidfont0') {
  4535. // register CID font (all styles at once)
  4536. $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic');
  4537. $sname = $name.$styles[$bistyle];
  4538. // artificial bold
  4539. if (strpos($bistyle, 'B') !== false) {
  4540. if (isset($desc['StemV'])) {
  4541. $desc['StemV'] *= 2;
  4542. } else {
  4543. $desc['StemV'] = 120;
  4544. }
  4545. }
  4546. // artificial italic
  4547. if (strpos($bistyle, 'I') !== false) {
  4548. if (isset($desc['ItalicAngle'])) {
  4549. $desc['ItalicAngle'] -= 11;
  4550. } else {
  4551. $desc['ItalicAngle'] = -11;
  4552. }
  4553. }
  4554. } elseif ($type == 'core') {
  4555. $name = $this->CoreFonts[$fontkey];
  4556. $subset = false;
  4557. } elseif (($type == 'TrueType') OR ($type == 'Type1')) {
  4558. $subset = false;
  4559. } elseif ($type == 'TrueTypeUnicode') {
  4560. $enc = 'Identity-H';
  4561. } else {
  4562. $this->Error('Unknow font type: '.$type.'');
  4563. }
  4564. // initialize subsetchars to contain default ASCII values (0-255)
  4565. $subsetchars = array_fill(0, 256, true);
  4566. $this->setFontBuffer($fontkey, array('fontkey' => $fontkey, 'i' => $this->numfonts, 'type' => $type, 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'dw' => $dw, 'enc' => $enc, 'cidinfo' => $cidinfo, 'file' => $file, 'ctg' => $ctg, 'subset' => $subset, 'subsetchars' => $subsetchars));
  4567. if ($this->inxobj) {
  4568. // we are inside an XObject template
  4569. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts;
  4570. }
  4571. if (isset($diff) AND (!empty($diff))) {
  4572. //Search existing encodings
  4573. $d = 0;
  4574. $nb = count($this->diffs);
  4575. for ($i=1; $i <= $nb; ++$i) {
  4576. if ($this->diffs[$i] == $diff) {
  4577. $d = $i;
  4578. break;
  4579. }
  4580. }
  4581. if ($d == 0) {
  4582. $d = $nb + 1;
  4583. $this->diffs[$d] = $diff;
  4584. }
  4585. $this->setFontSubBuffer($fontkey, 'diff', $d);
  4586. }
  4587. if (!$this->empty_string($file)) {
  4588. if (!isset($this->FontFiles[$file])) {
  4589. if ((strcasecmp($type,'TrueType') == 0) OR (strcasecmp($type, 'TrueTypeUnicode') == 0)) {
  4590. $this->FontFiles[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  4591. } elseif ($type != 'core') {
  4592. $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  4593. }
  4594. } else {
  4595. // update fontkeys that are sharing this font file
  4596. $this->FontFiles[$file]['subset'] = ($this->FontFiles[$file]['subset'] AND $subset);
  4597. if (!in_array($fontkey, $this->FontFiles[$file]['fontkeys'])) {
  4598. $this->FontFiles[$file]['fontkeys'][] = $fontkey;
  4599. }
  4600. }
  4601. }
  4602. return $fontdata;
  4603. }
  4604. /**
  4605. * Sets the font used to print character strings.
  4606. * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  4607. * The method can be called before the first page is created and the font is retained from page to page.
  4608. * If you just wish to change the current font size, it is simpler to call SetFontSize().
  4609. * 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 />
  4610. * @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.
  4611. * @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 trough</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.
  4612. * @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
  4613. * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  4614. * @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.
  4615. * @author Nicola Asuni
  4616. * @public
  4617. * @since 1.0
  4618. * @see AddFont(), SetFontSize()
  4619. */
  4620. public function SetFont($family, $style='', $size=0, $fontfile='', $subset='default') {
  4621. //Select a font; size given in points
  4622. if ($size == 0) {
  4623. $size = $this->FontSizePt;
  4624. }
  4625. // try to add font (if not already added)
  4626. $fontdata = $this->AddFont($family, $style, $fontfile, $subset);
  4627. $this->FontFamily = $fontdata['family'];
  4628. $this->FontStyle = $fontdata['style'];
  4629. $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
  4630. $this->SetFontSize($size);
  4631. }
  4632. /**
  4633. * Defines the size of the current font.
  4634. * @param $size (float) The size (in points)
  4635. * @param $out (boolean) if true output the font size command, otherwise only set the font properties.
  4636. * @public
  4637. * @since 1.0
  4638. * @see SetFont()
  4639. */
  4640. public function SetFontSize($size, $out=true) {
  4641. // font size in points
  4642. $this->FontSizePt = $size;
  4643. // font size in user units
  4644. $this->FontSize = $size / $this->k;
  4645. // calculate some font metrics
  4646. if (isset($this->CurrentFont['desc']['FontBBox'])) {
  4647. $bbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  4648. $font_height = ((intval($bbox[3]) - intval($bbox[1])) * $size / 1000);
  4649. } else {
  4650. $font_height = $size * 1.219;
  4651. }
  4652. if (isset($this->CurrentFont['desc']['Ascent']) AND ($this->CurrentFont['desc']['Ascent'] > 0)) {
  4653. $font_ascent = ($this->CurrentFont['desc']['Ascent'] * $size / 1000);
  4654. }
  4655. if (isset($this->CurrentFont['desc']['Descent']) AND ($this->CurrentFont['desc']['Descent'] <= 0)) {
  4656. $font_descent = (- $this->CurrentFont['desc']['Descent'] * $size / 1000);
  4657. }
  4658. if (!isset($font_ascent) AND !isset($font_descent)) {
  4659. // core font
  4660. $font_ascent = 0.76 * $font_height;
  4661. $font_descent = $font_height - $font_ascent;
  4662. } elseif (!isset($font_descent)) {
  4663. $font_descent = $font_height - $font_ascent;
  4664. } elseif (!isset($font_ascent)) {
  4665. $font_ascent = $font_height - $font_descent;
  4666. }
  4667. $this->FontAscent = $font_ascent / $this->k;
  4668. $this->FontDescent = $font_descent / $this->k;
  4669. if ($out AND ($this->page > 0) AND (isset($this->CurrentFont['i']))) {
  4670. $this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  4671. }
  4672. }
  4673. /**
  4674. * Return the font descent value
  4675. * @param $font (string) font name
  4676. * @param $style (string) font style
  4677. * @param $size (float) The size (in points)
  4678. * @return int font descent
  4679. * @public
  4680. * @author Nicola Asuni
  4681. * @since 4.9.003 (2010-03-30)
  4682. */
  4683. public function getFontDescent($font, $style='', $size=0) {
  4684. $fontdata = $this->AddFont($font, $style);
  4685. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4686. if (isset($fontinfo['desc']['Descent']) AND ($fontinfo['desc']['Descent'] <= 0)) {
  4687. $descent = (- $fontinfo['desc']['Descent'] * $size / 1000);
  4688. } else {
  4689. $descent = 1.219 * 0.24 * $size;
  4690. }
  4691. return ($descent / $this->k);
  4692. }
  4693. /**
  4694. * Return the font ascent value
  4695. * @param $font (string) font name
  4696. * @param $style (string) font style
  4697. * @param $size (float) The size (in points)
  4698. * @return int font ascent
  4699. * @public
  4700. * @author Nicola Asuni
  4701. * @since 4.9.003 (2010-03-30)
  4702. */
  4703. public function getFontAscent($font, $style='', $size=0) {
  4704. $fontdata = $this->AddFont($font, $style);
  4705. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4706. if (isset($fontinfo['desc']['Ascent']) AND ($fontinfo['desc']['Ascent'] > 0)) {
  4707. $ascent = ($fontinfo['desc']['Ascent'] * $size / 1000);
  4708. } else {
  4709. $ascent = 1.219 * 0.76 * $size;
  4710. }
  4711. return ($ascent / $this->k);
  4712. }
  4713. /**
  4714. * Defines the default monospaced font.
  4715. * @param $font (string) Font name.
  4716. * @public
  4717. * @since 4.5.025
  4718. */
  4719. public function SetDefaultMonospacedFont($font) {
  4720. $this->default_monospaced_font = $font;
  4721. }
  4722. /**
  4723. * 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 />
  4724. * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  4725. * @public
  4726. * @since 1.5
  4727. * @see Cell(), Write(), Image(), Link(), SetLink()
  4728. */
  4729. public function AddLink() {
  4730. //Create a new internal link
  4731. $n = count($this->links) + 1;
  4732. $this->links[$n] = array(0, 0);
  4733. return $n;
  4734. }
  4735. /**
  4736. * Defines the page and position a link points to.
  4737. * @param $link (int) The link identifier returned by AddLink()
  4738. * @param $y (float) Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  4739. * @param $page (int) Number of target page; -1 indicates the current page. This is the default value
  4740. * @public
  4741. * @since 1.5
  4742. * @see AddLink()
  4743. */
  4744. public function SetLink($link, $y=0, $page=-1) {
  4745. if ($y == -1) {
  4746. $y = $this->y;
  4747. }
  4748. if ($page == -1) {
  4749. $page = $this->page;
  4750. }
  4751. $this->links[$link] = array($page, $y);
  4752. }
  4753. /**
  4754. * Puts a link on a rectangular area of the page.
  4755. * 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.
  4756. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  4757. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  4758. * @param $w (float) Width of the rectangle
  4759. * @param $h (float) Height of the rectangle
  4760. * @param $link (mixed) URL or identifier returned by AddLink()
  4761. * @param $spaces (int) number of spaces on the text to link
  4762. * @public
  4763. * @since 1.5
  4764. * @see AddLink(), Annotation(), Cell(), Write(), Image()
  4765. */
  4766. public function Link($x, $y, $w, $h, $link, $spaces=0) {
  4767. $this->Annotation($x, $y, $w, $h, $link, array('Subtype'=>'Link'), $spaces);
  4768. }
  4769. /**
  4770. * Puts a markup annotation on a rectangular area of the page.
  4771. * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
  4772. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  4773. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  4774. * @param $w (float) Width of the rectangle
  4775. * @param $h (float) Height of the rectangle
  4776. * @param $text (string) annotation text or alternate content
  4777. * @param $opt (array) array of options (see section 8.4 of PDF reference 1.7).
  4778. * @param $spaces (int) number of spaces on the text to link
  4779. * @public
  4780. * @since 4.0.018 (2008-08-06)
  4781. */
  4782. public function Annotation($x, $y, $w, $h, $text, $opt=array('Subtype'=>'Text'), $spaces=0) {
  4783. if ($this->inxobj) {
  4784. // store parameters for later use on template
  4785. $this->xobjects[$this->xobjid]['annotations'][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'text' => $text, 'opt' => $opt, 'spaces' => $spaces);
  4786. return;
  4787. }
  4788. if ($x === '') {
  4789. $x = $this->x;
  4790. }
  4791. if ($y === '') {
  4792. $y = $this->y;
  4793. }
  4794. // check page for no-write regions and adapt page margins if necessary
  4795. $this->checkPageRegions($h, $x, $y);
  4796. // recalculate coordinates to account for graphic transformations
  4797. if (isset($this->transfmatrix) AND !empty($this->transfmatrix)) {
  4798. for ($i=$this->transfmatrix_key; $i > 0; --$i) {
  4799. $maxid = count($this->transfmatrix[$i]) - 1;
  4800. for ($j=$maxid; $j >= 0; --$j) {
  4801. $ctm = $this->transfmatrix[$i][$j];
  4802. if (isset($ctm['a'])) {
  4803. $x = $x * $this->k;
  4804. $y = ($this->h - $y) * $this->k;
  4805. $w = $w * $this->k;
  4806. $h = $h * $this->k;
  4807. // top left
  4808. $xt = $x;
  4809. $yt = $y;
  4810. $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4811. $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4812. // top right
  4813. $xt = $x + $w;
  4814. $yt = $y;
  4815. $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4816. $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4817. // bottom left
  4818. $xt = $x;
  4819. $yt = $y - $h;
  4820. $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4821. $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4822. // bottom right
  4823. $xt = $x + $w;
  4824. $yt = $y - $h;
  4825. $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4826. $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4827. // new coordinates (rectangle area)
  4828. $x = min($x1, $x2, $x3, $x4);
  4829. $y = max($y1, $y2, $y3, $y4);
  4830. $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k;
  4831. $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k;
  4832. $x = $x / $this->k;
  4833. $y = $this->h - ($y / $this->k);
  4834. }
  4835. }
  4836. }
  4837. }
  4838. if ($this->page <= 0) {
  4839. $page = 1;
  4840. } else {
  4841. $page = $this->page;
  4842. }
  4843. if (!isset($this->PageAnnots[$page])) {
  4844. $this->PageAnnots[$page] = array();
  4845. }
  4846. ++$this->n;
  4847. $this->PageAnnots[$page][] = array('n' => $this->n, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces);
  4848. if ((($opt['Subtype'] == 'FileAttachment') OR ($opt['Subtype'] == 'Sound')) AND (!$this->empty_string($opt['FS'])) AND file_exists($opt['FS']) AND (!isset($this->embeddedfiles[basename($opt['FS'])]))) {
  4849. ++$this->n;
  4850. $this->embeddedfiles[basename($opt['FS'])] = array('n' => $this->n, 'file' => $opt['FS']);
  4851. }
  4852. // Add widgets annotation's icons
  4853. if (isset($opt['mk']['i']) AND file_exists($opt['mk']['i'])) {
  4854. $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
  4855. }
  4856. if (isset($opt['mk']['ri']) AND file_exists($opt['mk']['ri'])) {
  4857. $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  4858. }
  4859. if (isset($opt['mk']['ix']) AND file_exists($opt['mk']['ix'])) {
  4860. $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  4861. }
  4862. }
  4863. /**
  4864. * Embedd the attached files.
  4865. * @since 4.4.000 (2008-12-07)
  4866. * @protected
  4867. * @see Annotation()
  4868. */
  4869. protected function _putEmbeddedFiles() {
  4870. reset($this->embeddedfiles);
  4871. foreach ($this->embeddedfiles as $filename => $filedata) {
  4872. $data = file_get_contents($filedata['file']);
  4873. $filter = '';
  4874. if ($this->compress) {
  4875. $data = gzcompress($data);
  4876. $filter = ' /Filter /FlateDecode';
  4877. }
  4878. $stream = $this->_getrawstream($data, $filedata['n']);
  4879. $out = $this->_getobj($filedata['n'])."\n";
  4880. $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' >>';
  4881. $out .= ' stream'."\n".$stream."\n".'endstream';
  4882. $out .= "\n".'endobj';
  4883. $this->_out($out);
  4884. }
  4885. }
  4886. /**
  4887. * Prints a text cell at the specified position.
  4888. * This method allows to place a string precisely on the page.
  4889. * @param $x (float) Abscissa of the cell origin
  4890. * @param $y (float) Ordinate of the cell origin
  4891. * @param $txt (string) String to print
  4892. * @param $fstroke (int) outline size in user units (false = disable)
  4893. * @param $fclip (boolean) if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
  4894. * @param $ffill (boolean) if true fills the text
  4895. * @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)))
  4896. * @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.
  4897. * @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>
  4898. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  4899. * @param $link (mixed) URL or identifier returned by AddLink().
  4900. * @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.
  4901. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  4902. * @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>
  4903. * @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>
  4904. * @param $rtloff (boolean) if true uses the page top-left corner as origin of axis for $x and $y initial position.
  4905. * @public
  4906. * @since 1.0
  4907. * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
  4908. */
  4909. 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) {
  4910. $textrendermode = $this->textrendermode;
  4911. $textstrokewidth = $this->textstrokewidth;
  4912. $this->setTextRenderingMode($fstroke, $ffill, $fclip);
  4913. $this->SetXY($x, $y, $rtloff);
  4914. $this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
  4915. // restore previous rendering mode
  4916. $this->textrendermode = $textrendermode;
  4917. $this->textstrokewidth = $textstrokewidth;
  4918. }
  4919. /**
  4920. * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
  4921. * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  4922. * This method is called automatically and should not be called directly by the application.
  4923. * @return boolean
  4924. * @public
  4925. * @since 1.4
  4926. * @see SetAutoPageBreak()
  4927. */
  4928. public function AcceptPageBreak() {
  4929. if ($this->num_columns > 1) {
  4930. // multi column mode
  4931. if($this->current_column < ($this->num_columns - 1)) {
  4932. // go to next column
  4933. $this->selectColumn($this->current_column + 1);
  4934. } else {
  4935. // add a new page
  4936. $this->AddPage();
  4937. // set first column
  4938. $this->selectColumn(0);
  4939. }
  4940. // avoid page breaking from checkPageBreak()
  4941. return false;
  4942. }
  4943. return $this->AutoPageBreak;
  4944. }
  4945. /**
  4946. * Add page if needed.
  4947. * @param $h (float) Cell height. Default value: 0.
  4948. * @param $y (mixed) starting y position, leave empty for current position.
  4949. * @param $addpage (boolean) if true add a page, otherwise only return the true/false state
  4950. * @return boolean true in case of page break, false otherwise.
  4951. * @since 3.2.000 (2008-07-01)
  4952. * @protected
  4953. */
  4954. protected function checkPageBreak($h=0, $y='', $addpage=true) {
  4955. if ($this->empty_string($y)) {
  4956. $y = $this->y;
  4957. }
  4958. $current_page = $this->page;
  4959. if ((($y + $h) > $this->PageBreakTrigger) AND (!$this->InFooter) AND ($this->AcceptPageBreak())) {
  4960. if ($addpage) {
  4961. //Automatic page break
  4962. $x = $this->x;
  4963. $this->AddPage($this->CurOrientation);
  4964. $this->y = $this->tMargin;
  4965. $oldpage = $this->page - 1;
  4966. if ($this->rtl) {
  4967. if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm']) {
  4968. $this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']);
  4969. } else {
  4970. $this->x = $x;
  4971. }
  4972. } else {
  4973. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  4974. $this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']);
  4975. } else {
  4976. $this->x = $x;
  4977. }
  4978. }
  4979. }
  4980. return true;
  4981. }
  4982. if ($current_page != $this->page) {
  4983. // account for columns mode
  4984. return true;
  4985. }
  4986. return false;
  4987. }
  4988. /**
  4989. * Removes SHY characters from text.
  4990. * Unicode Data:<ul>
  4991. * <li>Name : SOFT HYPHEN, commonly abbreviated as SHY</li>
  4992. * <li>HTML Entity (decimal): "&amp;#173;"</li>
  4993. * <li>HTML Entity (hex): "&amp;#xad;"</li>
  4994. * <li>HTML Entity (named): "&amp;shy;"</li>
  4995. * <li>How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]</li>
  4996. * <li>UTF-8 (hex): 0xC2 0xAD (c2ad)</li>
  4997. * <li>UTF-8 character: chr(194).chr(173)</li>
  4998. * </ul>
  4999. * @param $txt (string) input string
  5000. * @return string without SHY characters.
  5001. * @public
  5002. * @since (4.5.019) 2009-02-28
  5003. */
  5004. public function removeSHY($txt='') {
  5005. $txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt);
  5006. if (!$this->isunicode) {
  5007. $txt = preg_replace('/([\\xad]{1})/', '', $txt);
  5008. }
  5009. return $txt;
  5010. }
  5011. /**
  5012. * 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 />
  5013. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  5014. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  5015. * @param $h (float) Cell height. Default value: 0.
  5016. * @param $txt (string) String to print. Default value: empty string.
  5017. * @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)))
  5018. * @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.
  5019. * @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>
  5020. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  5021. * @param $link (mixed) URL or identifier returned by AddLink().
  5022. * @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.
  5023. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  5024. * @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>
  5025. * @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>
  5026. * @public
  5027. * @since 1.0
  5028. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  5029. */
  5030. 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') {
  5031. $prev_cell_margin = $this->cell_margin;
  5032. $prev_cell_padding = $this->cell_padding;
  5033. $this->adjustCellPadding($border);
  5034. if (!$ignore_min_height) {
  5035. $min_cell_height = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  5036. if ($h < $min_cell_height) {
  5037. $h = $min_cell_height;
  5038. }
  5039. }
  5040. $this->checkPageBreak($h + $this->cell_margin['T'] + $this->cell_margin['B']);
  5041. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  5042. $this->cell_padding = $prev_cell_padding;
  5043. $this->cell_margin = $prev_cell_margin;
  5044. }
  5045. /**
  5046. * 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 />
  5047. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  5048. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  5049. * @param $h (float) Cell height. Default value: 0.
  5050. * @param $txt (string) String to print. Default value: empty string.
  5051. * @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)))
  5052. * @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.
  5053. * @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>
  5054. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  5055. * @param $link (mixed) URL or identifier returned by AddLink().
  5056. * @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.
  5057. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  5058. * @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>
  5059. * @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>
  5060. * @return string containing cell code
  5061. * @protected
  5062. * @since 1.0
  5063. * @see Cell()
  5064. */
  5065. 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') {
  5066. $prev_cell_margin = $this->cell_margin;
  5067. $prev_cell_padding = $this->cell_padding;
  5068. $txt = $this->removeSHY($txt);
  5069. $rs = ''; //string to be returned
  5070. $this->adjustCellPadding($border);
  5071. if (!$ignore_min_height) {
  5072. $min_cell_height = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  5073. if ($h < $min_cell_height) {
  5074. $h = $min_cell_height;
  5075. }
  5076. }
  5077. $k = $this->k;
  5078. // check page for no-write regions and adapt page margins if necessary
  5079. $this->checkPageRegions($h, $this->x, $this->y);
  5080. if ($this->rtl) {
  5081. $x = $this->x - $this->cell_margin['R'];
  5082. } else {
  5083. $x = $this->x + $this->cell_margin['L'];
  5084. }
  5085. $y = $this->y + $this->cell_margin['T'];
  5086. $prev_font_stretching = $this->font_stretching;
  5087. $prev_font_spacing = $this->font_spacing;
  5088. // cell vertical alignment
  5089. switch ($calign) {
  5090. case 'A': {
  5091. // font top
  5092. switch ($valign) {
  5093. case 'T': {
  5094. // top
  5095. $y -= $this->cell_padding['T'];
  5096. break;
  5097. }
  5098. case 'B': {
  5099. // bottom
  5100. $y -= ($h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent);
  5101. break;
  5102. }
  5103. default:
  5104. case 'C':
  5105. case 'M': {
  5106. // center
  5107. $y -= (($h - $this->FontAscent - $this->FontDescent) / 2);
  5108. break;
  5109. }
  5110. }
  5111. break;
  5112. }
  5113. case 'L': {
  5114. // font baseline
  5115. switch ($valign) {
  5116. case 'T': {
  5117. // top
  5118. $y -= ($this->cell_padding['T'] + $this->FontAscent);
  5119. break;
  5120. }
  5121. case 'B': {
  5122. // bottom
  5123. $y -= ($h - $this->cell_padding['B'] - $this->FontDescent);
  5124. break;
  5125. }
  5126. default:
  5127. case 'C':
  5128. case 'M': {
  5129. // center
  5130. $y -= (($h + $this->FontAscent - $this->FontDescent) / 2);
  5131. break;
  5132. }
  5133. }
  5134. break;
  5135. }
  5136. case 'D': {
  5137. // font bottom
  5138. switch ($valign) {
  5139. case 'T': {
  5140. // top
  5141. $y -= ($this->cell_padding['T'] + $this->FontAscent + $this->FontDescent);
  5142. break;
  5143. }
  5144. case 'B': {
  5145. // bottom
  5146. $y -= ($h - $this->cell_padding['B']);
  5147. break;
  5148. }
  5149. default:
  5150. case 'C':
  5151. case 'M': {
  5152. // center
  5153. $y -= (($h + $this->FontAscent + $this->FontDescent) / 2);
  5154. break;
  5155. }
  5156. }
  5157. break;
  5158. }
  5159. case 'B': {
  5160. // cell bottom
  5161. $y -= $h;
  5162. break;
  5163. }
  5164. case 'C':
  5165. case 'M': {
  5166. // cell center
  5167. $y -= ($h / 2);
  5168. break;
  5169. }
  5170. default:
  5171. case 'T': {
  5172. // cell top
  5173. break;
  5174. }
  5175. }
  5176. // text vertical alignment
  5177. switch ($valign) {
  5178. case 'T': {
  5179. // top
  5180. $yt = $y + $this->cell_padding['T'];
  5181. break;
  5182. }
  5183. case 'B': {
  5184. // bottom
  5185. $yt = $y + $h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent;
  5186. break;
  5187. }
  5188. default:
  5189. case 'C':
  5190. case 'M': {
  5191. // center
  5192. $yt = $y + (($h - $this->FontAscent - $this->FontDescent) / 2);
  5193. break;
  5194. }
  5195. }
  5196. $basefonty = $yt + $this->FontAscent;
  5197. if ($this->empty_string($w) OR ($w <= 0)) {
  5198. if ($this->rtl) {
  5199. $w = $x - $this->lMargin;
  5200. } else {
  5201. $w = $this->w - $this->rMargin - $x;
  5202. }
  5203. }
  5204. $s = '';
  5205. // fill and borders
  5206. if (is_string($border) AND (strlen($border) == 4)) {
  5207. // full border
  5208. $border = 1;
  5209. }
  5210. if ($fill OR ($border == 1)) {
  5211. if ($fill) {
  5212. $op = ($border == 1) ? 'B' : 'f';
  5213. } else {
  5214. $op = 'S';
  5215. }
  5216. if ($this->rtl) {
  5217. $xk = (($x - $w) * $k);
  5218. } else {
  5219. $xk = ($x * $k);
  5220. }
  5221. $s .= sprintf('%.2F %.2F %.2F %.2F re %s ', $xk, (($this->h - $y) * $k), ($w * $k), (-$h * $k), $op);
  5222. }
  5223. // draw borders
  5224. $s .= $this->getCellBorder($x, $y, $w, $h, $border);
  5225. if ($txt != '') {
  5226. $txt2 = $txt;
  5227. if ($this->isunicode) {
  5228. if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
  5229. $txt2 = $this->UTF8ToLatin1($txt2);
  5230. } else {
  5231. $unicode = $this->UTF8StringToArray($txt); // array of UTF-8 unicode values
  5232. $unicode = $this->utf8Bidi($unicode, '', $this->tmprtl);
  5233. if (defined('K_THAI_TOPCHARS') AND (K_THAI_TOPCHARS == true)) {
  5234. // ---- Fix for bug #2977340 "Incorrect Thai characters position arrangement" ----
  5235. // NOTE: this doesn't work with HTML justification
  5236. // Symbols that could overlap on the font top (only works in LTR)
  5237. $topchar = array(3611, 3613, 3615, 3650, 3651, 3652); // chars that extends on top
  5238. $topsym = array(3633, 3636, 3637, 3638, 3639, 3655, 3656, 3657, 3658, 3659, 3660, 3661, 3662); // symbols with top position
  5239. $numchars = count($unicode); // number of chars
  5240. $unik = 0;
  5241. $uniblock = array();
  5242. $uniblock[$unik] = array();
  5243. $uniblock[$unik][] = $unicode[0];
  5244. // resolve overlapping conflicts by splitting the string in several parts
  5245. for ($i = 1; $i < $numchars; ++$i) {
  5246. // check if symbols overlaps at top
  5247. if (in_array($unicode[$i], $topsym) AND (in_array($unicode[($i - 1)], $topsym) OR in_array($unicode[($i - 1)], $topchar))) {
  5248. // move symbols to another array
  5249. ++$unik;
  5250. $uniblock[$unik] = array();
  5251. $uniblock[$unik][] = $unicode[$i];
  5252. ++$unik;
  5253. $uniblock[$unik] = array();
  5254. $unicode[$i] = 0x200b; // Unicode Character 'ZERO WIDTH SPACE' (DEC:8203, U+200B)
  5255. } else {
  5256. $uniblock[$unik][] = $unicode[$i];
  5257. }
  5258. }
  5259. // ---- END OF Fix for bug #2977340
  5260. }
  5261. $txt2 = $this->arrUTF8ToUTF16BE($unicode, false);
  5262. }
  5263. }
  5264. $txt2 = $this->_escape($txt2);
  5265. // get current text width (considering general font stretching and spacing)
  5266. $txwidth = $this->GetStringWidth($txt);
  5267. $width = $txwidth;
  5268. // check for stretch mode
  5269. if ($stretch > 0) {
  5270. // calculate ratio between cell width and text width
  5271. if ($width <= 0) {
  5272. $ratio = 1;
  5273. } else {
  5274. $ratio = (($w - $this->cell_padding['L'] - $this->cell_padding['R']) / $width);
  5275. }
  5276. // check if stretching is required
  5277. if (($ratio < 1) OR (($ratio > 1) AND (($stretch % 2) == 0))) {
  5278. // the text will be stretched to fit cell width
  5279. if ($stretch > 2) {
  5280. // set new character spacing
  5281. $this->font_spacing += ($w - $this->cell_padding['L'] - $this->cell_padding['R'] - $width) / (max(($this->GetNumChars($txt) - 1), 1) * ($this->font_stretching / 100));
  5282. } else {
  5283. // set new horizontal stretching
  5284. $this->font_stretching *= $ratio;
  5285. }
  5286. // recalculate text width (the text fills the entire cell)
  5287. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5288. // reset alignment
  5289. $align = '';
  5290. }
  5291. }
  5292. if ($this->font_stretching != 100) {
  5293. // apply font stretching
  5294. $rs .= sprintf('BT %.2F Tz ET ', $this->font_stretching);
  5295. }
  5296. if ($this->font_spacing != 0) {
  5297. // increase/decrease font spacing
  5298. $rs .= sprintf('BT %.2F Tc ET ', ($this->font_spacing * $this->k));
  5299. }
  5300. if ($this->ColorFlag) {
  5301. $s .= 'q '.$this->TextColor.' ';
  5302. }
  5303. // rendering mode
  5304. $s .= sprintf('BT %d Tr %.2F w ET ', $this->textrendermode, $this->textstrokewidth);
  5305. // count number of spaces
  5306. $ns = substr_count($txt, chr(32));
  5307. // Justification
  5308. $spacewidth = 0;
  5309. if (($align == 'J') AND ($ns > 0)) {
  5310. if ($this->isUnicodeFont()) {
  5311. // get string width without spaces
  5312. $width = $this->GetStringWidth(str_replace(' ', '', $txt));
  5313. // calculate average space width
  5314. $spacewidth = -1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1) / $this->FontSize;
  5315. if ($this->font_stretching != 100) {
  5316. // word spacing is affected by stretching
  5317. $spacewidth /= ($this->font_stretching / 100);
  5318. }
  5319. // set word position to be used with TJ operator
  5320. $txt2 = str_replace(chr(0).chr(32), ') '.sprintf('%.3F', $spacewidth).' (', $txt2);
  5321. $unicode_justification = true;
  5322. } else {
  5323. // get string width
  5324. $width = $txwidth;
  5325. // new space width
  5326. $spacewidth = (($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1)) * $this->k;
  5327. if ($this->font_stretching != 100) {
  5328. // word spacing (Tw) is affected by stretching
  5329. $spacewidth /= ($this->font_stretching / 100);
  5330. }
  5331. // set word spacing
  5332. $rs .= sprintf('BT %.3F Tw ET ', $spacewidth);
  5333. }
  5334. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5335. }
  5336. // replace carriage return characters
  5337. $txt2 = str_replace("\r", ' ', $txt2);
  5338. switch ($align) {
  5339. case 'C': {
  5340. $dx = ($w - $width) / 2;
  5341. break;
  5342. }
  5343. case 'R': {
  5344. if ($this->rtl) {
  5345. $dx = $this->cell_padding['R'];
  5346. } else {
  5347. $dx = $w - $width - $this->cell_padding['R'];
  5348. }
  5349. break;
  5350. }
  5351. case 'L': {
  5352. if ($this->rtl) {
  5353. $dx = $w - $width - $this->cell_padding['L'];
  5354. } else {
  5355. $dx = $this->cell_padding['L'];
  5356. }
  5357. break;
  5358. }
  5359. case 'J':
  5360. default: {
  5361. if ($this->rtl) {
  5362. $dx = $this->cell_padding['R'];
  5363. } else {
  5364. $dx = $this->cell_padding['L'];
  5365. }
  5366. break;
  5367. }
  5368. }
  5369. if ($this->rtl) {
  5370. $xdx = $x - $dx - $width;
  5371. } else {
  5372. $xdx = $x + $dx;
  5373. }
  5374. $xdk = $xdx * $k;
  5375. // print text
  5376. $s .= sprintf('BT %.2F %.2F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
  5377. if (isset($uniblock)) {
  5378. // print overlapping characters as separate string
  5379. $xshift = 0; // horizontal shift
  5380. $ty = (($this->h - $basefonty + (0.2 * $this->FontSize)) * $k);
  5381. $spw = (($w - $txwidth - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1));
  5382. foreach ($uniblock as $uk => $uniarr) {
  5383. if (($uk % 2) == 0) {
  5384. // x space to skip
  5385. if ($spacewidth != 0) {
  5386. // justification shift
  5387. $xshift += (count(array_keys($uniarr, 32)) * $spw);
  5388. }
  5389. $xshift += $this->GetArrStringWidth($uniarr); // + shift justification
  5390. } else {
  5391. // character to print
  5392. $topchr = $this->arrUTF8ToUTF16BE($uniarr, false);
  5393. $topchr = $this->_escape($topchr);
  5394. $s .= sprintf(' BT %.2F %.2F Td [(%s)] TJ ET', ($xdk + ($xshift * $k)), $ty, $topchr);
  5395. }
  5396. }
  5397. }
  5398. if ($this->underline) {
  5399. $s .= ' '.$this->_dounderlinew($xdx, $basefonty, $width);
  5400. }
  5401. if ($this->linethrough) {
  5402. $s .= ' '.$this->_dolinethroughw($xdx, $basefonty, $width);
  5403. }
  5404. if ($this->overline) {
  5405. $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width);
  5406. }
  5407. if ($this->ColorFlag) {
  5408. $s .= ' Q';
  5409. }
  5410. if ($link) {
  5411. $this->Link($xdx, $yt, $width, ($this->FontAscent + $this->FontDescent), $link, $ns);
  5412. }
  5413. }
  5414. // output cell
  5415. if ($s) {
  5416. // output cell
  5417. $rs .= $s;
  5418. if ($this->font_spacing != 0) {
  5419. // reset font spacing mode
  5420. $rs .= ' BT 0 Tc ET';
  5421. }
  5422. if ($this->font_stretching != 100) {
  5423. // reset font stretching mode
  5424. $rs .= ' BT 100 Tz ET';
  5425. }
  5426. }
  5427. // reset word spacing
  5428. if (!$this->isUnicodeFont() AND ($align == 'J')) {
  5429. $rs .= ' BT 0 Tw ET';
  5430. }
  5431. // reset stretching and spacing
  5432. $this->font_stretching = $prev_font_stretching;
  5433. $this->font_spacing = $prev_font_spacing;
  5434. $this->lasth = $h;
  5435. if ($ln > 0) {
  5436. //Go to the beginning of the next line
  5437. $this->y = $y + $h + $this->cell_margin['B'];
  5438. if ($ln == 1) {
  5439. if ($this->rtl) {
  5440. $this->x = $this->w - $this->rMargin;
  5441. } else {
  5442. $this->x = $this->lMargin;
  5443. }
  5444. }
  5445. } else {
  5446. // go left or right by case
  5447. if ($this->rtl) {
  5448. $this->x = $x - $w - $this->cell_margin['L'];
  5449. } else {
  5450. $this->x = $x + $w + $this->cell_margin['R'];
  5451. }
  5452. }
  5453. $gstyles = ''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor."\n";
  5454. $rs = $gstyles.$rs;
  5455. $this->cell_padding = $prev_cell_padding;
  5456. $this->cell_margin = $prev_cell_margin;
  5457. return $rs;
  5458. }
  5459. /**
  5460. * Returns the code to draw the cell border
  5461. * @param $x (float) X coordinate.
  5462. * @param $y (float) Y coordinate.
  5463. * @param $w (float) Cell width.
  5464. * @param $h (float) Cell height.
  5465. * @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)))
  5466. * @return string containing cell border code
  5467. * @protected
  5468. * @see SetLineStyle()
  5469. * @since 5.7.000 (2010-08-02)
  5470. */
  5471. protected function getCellBorder($x, $y, $w, $h, $brd) {
  5472. $s = ''; // string to be returned
  5473. if (empty($brd)) {
  5474. return $s;
  5475. }
  5476. if ($brd == 1) {
  5477. $brd = array('LRTB' => true);
  5478. }
  5479. // calculate coordinates for border
  5480. $k = $this->k;
  5481. if ($this->rtl) {
  5482. $xeL = ($x - $w) * $k;
  5483. $xeR = $x * $k;
  5484. } else {
  5485. $xeL = $x * $k;
  5486. $xeR = ($x + $w) * $k;
  5487. }
  5488. $yeL = (($this->h - ($y + $h)) * $k);
  5489. $yeT = (($this->h - $y) * $k);
  5490. $xeT = $xeL;
  5491. $xeB = $xeR;
  5492. $yeR = $yeT;
  5493. $yeB = $yeL;
  5494. if (is_string($brd)) {
  5495. // convert string to array
  5496. $slen = strlen($brd);
  5497. $newbrd = array();
  5498. for ($i = 0; $i < $slen; ++$i) {
  5499. $newbrd[$brd{$i}] = array('cap' => 'square', 'join' => 'miter');
  5500. }
  5501. $brd = $newbrd;
  5502. }
  5503. if (isset($brd['mode'])) {
  5504. $mode = $brd['mode'];
  5505. unset($brd['mode']);
  5506. } else {
  5507. $mode = 'normal';
  5508. }
  5509. foreach ($brd as $border => $style) {
  5510. if (is_array($style) AND !empty($style)) {
  5511. // apply border style
  5512. $prev_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' ';
  5513. $s .= $this->SetLineStyle($style, true)."\n";
  5514. }
  5515. switch ($mode) {
  5516. case 'ext': {
  5517. $off = (($this->LineWidth / 2) * $k);
  5518. $xL = $xeL - $off;
  5519. $xR = $xeR + $off;
  5520. $yT = $yeT + $off;
  5521. $yL = $yeL - $off;
  5522. $xT = $xL;
  5523. $xB = $xR;
  5524. $yR = $yT;
  5525. $yB = $yL;
  5526. $w += $this->LineWidth;
  5527. $h += $this->LineWidth;
  5528. break;
  5529. }
  5530. case 'int': {
  5531. $off = ($this->LineWidth / 2) * $k;
  5532. $xL = $xeL + $off;
  5533. $xR = $xeR - $off;
  5534. $yT = $yeT - $off;
  5535. $yL = $yeL + $off;
  5536. $xT = $xL;
  5537. $xB = $xR;
  5538. $yR = $yT;
  5539. $yB = $yL;
  5540. $w -= $this->LineWidth;
  5541. $h -= $this->LineWidth;
  5542. break;
  5543. }
  5544. case 'normal':
  5545. default: {
  5546. $xL = $xeL;
  5547. $xT = $xeT;
  5548. $xB = $xeB;
  5549. $xR = $xeR;
  5550. $yL = $yeL;
  5551. $yT = $yeT;
  5552. $yB = $yeB;
  5553. $yR = $yeR;
  5554. break;
  5555. }
  5556. }
  5557. // draw borders by case
  5558. if (strlen($border) == 4) {
  5559. $s .= sprintf('%.2F %.2F %.2F %.2F re S ', $xT, $yT, ($w * $k), (-$h * $k));
  5560. } elseif (strlen($border) == 3) {
  5561. if (strpos($border,'B') === false) { // LTR
  5562. $s .= sprintf('%.2F %.2F m ', $xL, $yL);
  5563. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  5564. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  5565. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  5566. $s .= 'S ';
  5567. } elseif (strpos($border,'L') === false) { // TRB
  5568. $s .= sprintf('%.2F %.2F m ', $xT, $yT);
  5569. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  5570. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  5571. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  5572. $s .= 'S ';
  5573. } elseif (strpos($border,'T') === false) { // RBL
  5574. $s .= sprintf('%.2F %.2F m ', $xR, $yR);
  5575. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  5576. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  5577. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  5578. $s .= 'S ';
  5579. } elseif (strpos($border,'R') === false) { // BLT
  5580. $s .= sprintf('%.2F %.2F m ', $xB, $yB);
  5581. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  5582. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  5583. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  5584. $s .= 'S ';
  5585. }
  5586. } elseif (strlen($border) == 2) {
  5587. if ((strpos($border,'L') !== false) AND (strpos($border,'T') !== false)) { // LT
  5588. $s .= sprintf('%.2F %.2F m ', $xL, $yL);
  5589. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  5590. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  5591. $s .= 'S ';
  5592. } elseif ((strpos($border,'T') !== false) AND (strpos($border,'R') !== false)) { // TR
  5593. $s .= sprintf('%.2F %.2F m ', $xT, $yT);
  5594. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  5595. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  5596. $s .= 'S ';
  5597. } elseif ((strpos($border,'R') !== false) AND (strpos($border,'B') !== false)) { // RB
  5598. $s .= sprintf('%.2F %.2F m ', $xR, $yR);
  5599. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  5600. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  5601. $s .= 'S ';
  5602. } elseif ((strpos($border,'B') !== false) AND (strpos($border,'L') !== false)) { // BL
  5603. $s .= sprintf('%.2F %.2F m ', $xB, $yB);
  5604. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  5605. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  5606. $s .= 'S ';
  5607. } elseif ((strpos($border,'L') !== false) AND (strpos($border,'R') !== false)) { // LR
  5608. $s .= sprintf('%.2F %.2F m ', $xL, $yL);
  5609. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  5610. $s .= 'S ';
  5611. $s .= sprintf('%.2F %.2F m ', $xR, $yR);
  5612. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  5613. $s .= 'S ';
  5614. } elseif ((strpos($border,'T') !== false) AND (strpos($border,'B') !== false)) { // TB
  5615. $s .= sprintf('%.2F %.2F m ', $xT, $yT);
  5616. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  5617. $s .= 'S ';
  5618. $s .= sprintf('%.2F %.2F m ', $xB, $yB);
  5619. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  5620. $s .= 'S ';
  5621. }
  5622. } else { // strlen($border) == 1
  5623. if (strpos($border,'L') !== false) { // L
  5624. $s .= sprintf('%.2F %.2F m ', $xL, $yL);
  5625. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  5626. $s .= 'S ';
  5627. } elseif (strpos($border,'T') !== false) { // T
  5628. $s .= sprintf('%.2F %.2F m ', $xT, $yT);
  5629. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  5630. $s .= 'S ';
  5631. } elseif (strpos($border,'R') !== false) { // R
  5632. $s .= sprintf('%.2F %.2F m ', $xR, $yR);
  5633. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  5634. $s .= 'S ';
  5635. } elseif (strpos($border,'B') !== false) { // B
  5636. $s .= sprintf('%.2F %.2F m ', $xB, $yB);
  5637. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  5638. $s .= 'S ';
  5639. }
  5640. }
  5641. if (is_array($style) AND !empty($style)) {
  5642. // reset border style to previous value
  5643. $s .= "\n".$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor."\n";
  5644. }
  5645. }
  5646. return $s;
  5647. }
  5648. /**
  5649. * This method allows printing text with line breaks.
  5650. * 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 />
  5651. * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  5652. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  5653. * @param $h (float) Cell minimum height. The cell extends automatically if needed.
  5654. * @param $txt (string) String to print
  5655. * @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)))
  5656. * @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>
  5657. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  5658. * @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>
  5659. * @param $x (float) x position in user units
  5660. * @param $y (float) y position in user units
  5661. * @param $reseth (boolean) if true reset the last cell height (default true).
  5662. * @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.
  5663. * @param $ishtml (boolean) set to true if $txt is HTML content (default = false).
  5664. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width.
  5665. * @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.
  5666. * @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.
  5667. * @param $fitcell (boolean) if true attempt to fit all the text within the cell by reducing the font size.
  5668. * @return int Return the number of cells or 1 for html mode.
  5669. * @public
  5670. * @since 1.3
  5671. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  5672. */
  5673. 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) {
  5674. $prev_cell_margin = $this->cell_margin;
  5675. $prev_cell_padding = $this->cell_padding;
  5676. // adjust internal padding
  5677. $this->adjustCellPadding($border);
  5678. $mc_padding = $this->cell_padding;
  5679. $mc_margin = $this->cell_margin;
  5680. $this->cell_padding['T'] = 0;
  5681. $this->cell_padding['B'] = 0;
  5682. $this->setCellMargins(0, 0, 0, 0);
  5683. if ($this->empty_string($this->lasth) OR $reseth) {
  5684. // reset row height
  5685. $this->resetLastH();
  5686. }
  5687. if (!$this->empty_string($y)) {
  5688. $this->SetY($y);
  5689. } else {
  5690. $y = $this->GetY();
  5691. }
  5692. $resth = 0;
  5693. if ((!$this->InFooter) AND (($y + $h + $mc_margin['T'] + $mc_margin['B']) > $this->PageBreakTrigger)) {
  5694. // spit cell in more pages/columns
  5695. $newh = $this->PageBreakTrigger - $y;
  5696. $resth = $h - $newh; // cell to be printed on the next page/column
  5697. $h = $newh;
  5698. }
  5699. // get current page number
  5700. $startpage = $this->page;
  5701. // get current column
  5702. $startcolumn = $this->current_column;
  5703. if (!$this->empty_string($x)) {
  5704. $this->SetX($x);
  5705. } else {
  5706. $x = $this->GetX();
  5707. }
  5708. // check page for no-write regions and adapt page margins if necessary
  5709. $this->checkPageRegions(0, $x, $y);
  5710. // apply margins
  5711. $oy = $y + $mc_margin['T'];
  5712. if ($this->rtl) {
  5713. $ox = $this->w - $x - $mc_margin['R'];
  5714. } else {
  5715. $ox = $x + $mc_margin['L'];
  5716. }
  5717. $this->x = $ox;
  5718. $this->y = $oy;
  5719. // set width
  5720. if ($this->empty_string($w) OR ($w <= 0)) {
  5721. if ($this->rtl) {
  5722. $w = $this->x - $this->lMargin - $mc_margin['L'];
  5723. } else {
  5724. $w = $this->w - $this->x - $this->rMargin - $mc_margin['R'];
  5725. }
  5726. }
  5727. // store original margin values
  5728. $lMargin = $this->lMargin;
  5729. $rMargin = $this->rMargin;
  5730. if ($this->rtl) {
  5731. $this->rMargin = $this->w - $this->x;
  5732. $this->lMargin = $this->x - $w;
  5733. } else {
  5734. $this->lMargin = $this->x;
  5735. $this->rMargin = $this->w - $this->x - $w;
  5736. }
  5737. if ($autopadding) {
  5738. // add top padding
  5739. $this->y += $mc_padding['T'];
  5740. }
  5741. if ($ishtml) { // ******* Write HTML text
  5742. $this->writeHTML($txt, true, 0, $reseth, true, $align);
  5743. $nl = 1;
  5744. } else { // ******* Write simple text
  5745. $prev_FontSizePt = $this->FontSizePt;
  5746. // vertical alignment
  5747. if ($maxh > 0) {
  5748. // get text height
  5749. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5750. if ($fitcell) {
  5751. // try to reduce font size to fit text on cell (use a quick search algorithm)
  5752. $fmin = 1;
  5753. $fmax = $this->FontSizePt;
  5754. $prev_text_height = $text_height;
  5755. $maxit = 100; // max number of iterations
  5756. while ($maxit > 0) {
  5757. $fmid = (($fmax + $fmin) / 2);
  5758. $this->SetFontSize($fmid, false);
  5759. $this->resetLastH();
  5760. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5761. if (($text_height == $maxh) OR (($text_height < $maxh) AND ($fmin >= ($fmax - 0.01)))) {
  5762. break;
  5763. } elseif ($text_height < $maxh) {
  5764. $fmin = $fmid;
  5765. } else {
  5766. $fmax = $fmid;
  5767. }
  5768. --$maxit;
  5769. }
  5770. $this->SetFontSize($this->FontSizePt);
  5771. }
  5772. if ($text_height < $maxh) {
  5773. if ($valign == 'M') {
  5774. // text vertically centered
  5775. $this->y += (($maxh - $text_height) / 2);
  5776. } elseif ($valign == 'B') {
  5777. // text vertically aligned on bottom
  5778. $this->y += ($maxh - $text_height);
  5779. }
  5780. }
  5781. }
  5782. $nl = $this->Write($this->lasth, $txt, '', 0, $align, true, $stretch, false, true, $maxh, 0, $mc_margin);
  5783. if ($fitcell) {
  5784. // restore font size
  5785. $this->SetFontSize($prev_FontSizePt);
  5786. }
  5787. }
  5788. if ($autopadding) {
  5789. // add bottom padding
  5790. $this->y += $mc_padding['B'];
  5791. }
  5792. // Get end-of-text Y position
  5793. $currentY = $this->y;
  5794. // get latest page number
  5795. $endpage = $this->page;
  5796. if ($resth > 0) {
  5797. $skip = ($endpage - $startpage);
  5798. $tmpresth = $resth;
  5799. while ($tmpresth > 0) {
  5800. if ($skip <= 0) {
  5801. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  5802. $this->checkPageBreak($this->PageBreakTrigger + 1);
  5803. }
  5804. if ($this->num_columns > 1) {
  5805. $tmpresth -= ($this->h - $this->y - $this->bMargin);
  5806. } else {
  5807. $tmpresth -= ($this->h - $this->tMargin - $this->bMargin);
  5808. }
  5809. --$skip;
  5810. }
  5811. $currentY = $this->y;
  5812. $endpage = $this->page;
  5813. }
  5814. // get latest column
  5815. $endcolumn = $this->current_column;
  5816. if ($this->num_columns == 0) {
  5817. $this->num_columns = 1;
  5818. }
  5819. // get border modes
  5820. $border_start = $this->getBorderMode($border, $position='start');
  5821. $border_end = $this->getBorderMode($border, $position='end');
  5822. $border_middle = $this->getBorderMode($border, $position='middle');
  5823. // design borders around HTML cells.
  5824. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  5825. $ccode = '';
  5826. $this->setPage($page);
  5827. if ($this->num_columns < 2) {
  5828. // single-column mode
  5829. $this->SetX($x);
  5830. $this->y = $this->tMargin;
  5831. }
  5832. // account for margin changes
  5833. if ($page > $startpage) {
  5834. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  5835. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  5836. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  5837. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  5838. }
  5839. }
  5840. if ($startpage == $endpage) {
  5841. // single page
  5842. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  5843. $this->selectColumn($column);
  5844. if ($this->rtl) {
  5845. $this->x -= $mc_margin['R'];
  5846. } else {
  5847. $this->x += $mc_margin['L'];
  5848. }
  5849. if ($startcolumn == $endcolumn) { // single column
  5850. $cborder = $border;
  5851. $h = max($h, ($currentY - $oy));
  5852. $this->y = $oy;
  5853. } elseif ($column == $startcolumn) { // first column
  5854. $cborder = $border_start;
  5855. $this->y = $oy;
  5856. $h = $this->h - $this->y - $this->bMargin;
  5857. } elseif ($column == $endcolumn) { // end column
  5858. $cborder = $border_end;
  5859. $h = $currentY - $this->y;
  5860. if ($resth > $h) {
  5861. $h = $resth;
  5862. }
  5863. } else { // middle column
  5864. $cborder = $border_middle;
  5865. $h = $this->h - $this->y - $this->bMargin;
  5866. $resth -= $h;
  5867. }
  5868. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5869. } // end for each column
  5870. } elseif ($page == $startpage) { // first page
  5871. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  5872. $this->selectColumn($column);
  5873. if ($this->rtl) {
  5874. $this->x -= $mc_margin['R'];
  5875. } else {
  5876. $this->x += $mc_margin['L'];
  5877. }
  5878. if ($column == $startcolumn) { // first column
  5879. $cborder = $border_start;
  5880. $this->y = $oy;
  5881. $h = $this->h - $this->y - $this->bMargin;
  5882. } else { // middle column
  5883. $cborder = $border_middle;
  5884. $h = $this->h - $this->y - $this->bMargin;
  5885. $resth -= $h;
  5886. }
  5887. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5888. } // end for each column
  5889. } elseif ($page == $endpage) { // last page
  5890. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  5891. $this->selectColumn($column);
  5892. if ($this->rtl) {
  5893. $this->x -= $mc_margin['R'];
  5894. } else {
  5895. $this->x += $mc_margin['L'];
  5896. }
  5897. if ($column == $endcolumn) {
  5898. // end column
  5899. $cborder = $border_end;
  5900. $h = $currentY - $this->y;
  5901. if ($resth > $h) {
  5902. $h = $resth;
  5903. }
  5904. } else {
  5905. // middle column
  5906. $cborder = $border_middle;
  5907. $h = $this->h - $this->y - $this->bMargin;
  5908. $resth -= $h;
  5909. }
  5910. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5911. } // end for each column
  5912. } else { // middle page
  5913. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  5914. $this->selectColumn($column);
  5915. if ($this->rtl) {
  5916. $this->x -= $mc_margin['R'];
  5917. } else {
  5918. $this->x += $mc_margin['L'];
  5919. }
  5920. $cborder = $border_middle;
  5921. $h = $this->h - $this->y - $this->bMargin;
  5922. $resth -= $h;
  5923. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5924. } // end for each column
  5925. }
  5926. if ($cborder OR $fill) {
  5927. // draw border and fill
  5928. if ($this->inxobj) {
  5929. // we are inside an XObject template
  5930. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  5931. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  5932. $pagemark = &$this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  5933. } else {
  5934. $pagemark = &$this->xobjects[$this->xobjid]['intmrk'];
  5935. }
  5936. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  5937. $pstart = substr($pagebuff, 0, $pagemark);
  5938. $pend = substr($pagebuff, $pagemark);
  5939. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  5940. $pagemark += strlen($ccode);
  5941. } else {
  5942. if (end($this->transfmrk[$this->page]) !== false) {
  5943. $pagemarkkey = key($this->transfmrk[$this->page]);
  5944. $pagemark = &$this->transfmrk[$this->page][$pagemarkkey];
  5945. } elseif ($this->InFooter) {
  5946. $pagemark = &$this->footerpos[$this->page];
  5947. } else {
  5948. $pagemark = &$this->intmrk[$this->page];
  5949. }
  5950. $pagebuff = $this->getPageBuffer($this->page);
  5951. $pstart = substr($pagebuff, 0, $pagemark);
  5952. $pend = substr($pagebuff, $pagemark);
  5953. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  5954. $pagemark += strlen($ccode);
  5955. }
  5956. }
  5957. } // end for each page
  5958. // Get end-of-cell Y position
  5959. $currentY = $this->GetY();
  5960. // restore original margin values
  5961. $this->SetLeftMargin($lMargin);
  5962. $this->SetRightMargin($rMargin);
  5963. if ($ln > 0) {
  5964. //Go to the beginning of the next line
  5965. $this->SetY($currentY + $mc_margin['B']);
  5966. if ($ln == 2) {
  5967. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  5968. }
  5969. } else {
  5970. // go left or right by case
  5971. $this->setPage($startpage);
  5972. $this->y = $y;
  5973. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  5974. }
  5975. $this->setContentMark();
  5976. $this->cell_padding = $prev_cell_padding;
  5977. $this->cell_margin = $prev_cell_margin;
  5978. return $nl;
  5979. }
  5980. /**
  5981. * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages)
  5982. * @param $brd (mixed) Indicates if borders must be drawn around the cell block. 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: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  5983. * @param $position (string) multicell position: 'start', 'middle', 'end'
  5984. * @return border mode array
  5985. * @protected
  5986. * @since 4.4.002 (2008-12-09)
  5987. */
  5988. protected function getBorderMode($brd, $position='start') {
  5989. if ((!$this->opencell) OR empty($brd)) {
  5990. return $brd;
  5991. }
  5992. if ($brd == 1) {
  5993. $brd = 'LTRB';
  5994. }
  5995. if (is_string($brd)) {
  5996. // convert string to array
  5997. $slen = strlen($brd);
  5998. $newbrd = array();
  5999. for ($i = 0; $i < $slen; ++$i) {
  6000. $newbrd[$brd{$i}] = array('cap' => 'square', 'join' => 'miter');
  6001. }
  6002. $brd = $newbrd;
  6003. }
  6004. foreach ($brd as $border => $style) {
  6005. switch ($position) {
  6006. case 'start': {
  6007. if (strpos($border, 'B') !== false) {
  6008. // remove bottom line
  6009. $newkey = str_replace('B', '', $border);
  6010. if (strlen($newkey) > 0) {
  6011. $brd[$newkey] = $style;
  6012. }
  6013. unset($brd[$border]);
  6014. }
  6015. break;
  6016. }
  6017. case 'middle': {
  6018. if (strpos($border, 'B') !== false) {
  6019. // remove bottom line
  6020. $newkey = str_replace('B', '', $border);
  6021. if (strlen($newkey) > 0) {
  6022. $brd[$newkey] = $style;
  6023. }
  6024. unset($brd[$border]);
  6025. $border = $newkey;
  6026. }
  6027. if (strpos($border, 'T') !== false) {
  6028. // remove bottom line
  6029. $newkey = str_replace('T', '', $border);
  6030. if (strlen($newkey) > 0) {
  6031. $brd[$newkey] = $style;
  6032. }
  6033. unset($brd[$border]);
  6034. }
  6035. break;
  6036. }
  6037. case 'end': {
  6038. if (strpos($border, 'T') !== false) {
  6039. // remove bottom line
  6040. $newkey = str_replace('T', '', $border);
  6041. if (strlen($newkey) > 0) {
  6042. $brd[$newkey] = $style;
  6043. }
  6044. unset($brd[$border]);
  6045. }
  6046. break;
  6047. }
  6048. }
  6049. }
  6050. return $brd;
  6051. }
  6052. /**
  6053. * This method return the estimated number of lines for print a simple text string using Multicell() method.
  6054. * @param $txt (string) String for calculating his height
  6055. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  6056. * @param $reseth (boolean) if true reset the last cell height (default false).
  6057. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
  6058. * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
  6059. * @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)))
  6060. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  6061. * @author Alexander Escalona Fernández, Nicola Asuni
  6062. * @public
  6063. * @since 4.5.011
  6064. */
  6065. public function getNumLines($txt, $w=0, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
  6066. if ($txt === '') {
  6067. // empty string
  6068. return 1;
  6069. }
  6070. // adjust internal padding
  6071. $prev_cell_padding = $this->cell_padding;
  6072. $prev_lasth = $this->lasth;
  6073. if (is_array($cellpadding)) {
  6074. $this->cell_padding = $cellpadding;
  6075. }
  6076. $this->adjustCellPadding($border);
  6077. if ($this->empty_string($w) OR ($w <= 0)) {
  6078. if ($this->rtl) {
  6079. $w = $this->x - $this->lMargin;
  6080. } else {
  6081. $w = $this->w - $this->rMargin - $this->x;
  6082. }
  6083. }
  6084. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6085. if ($reseth) {
  6086. // reset row height
  6087. $this->resetLastH();
  6088. }
  6089. $lines = 1;
  6090. $sum = 0;
  6091. $chars = $this->utf8Bidi($this->UTF8StringToArray($txt), $txt, $this->tmprtl);
  6092. $charsWidth = $this->GetArrStringWidth($chars, '', '', 0, true);
  6093. $length = count($chars);
  6094. $lastSeparator = -1;
  6095. for ($i = 0; $i < $length; ++$i) {
  6096. $charWidth = $charsWidth[$i];
  6097. if (preg_match($this->re_spaces, $this->unichr($chars[$i]))) {
  6098. $lastSeparator = $i;
  6099. }
  6100. if ((($sum + $charWidth) > $wmax) OR ($chars[$i] == 10)) {
  6101. ++$lines;
  6102. if ($lastSeparator != -1) {
  6103. $i = $lastSeparator;
  6104. $lastSeparator = -1;
  6105. $sum = 0;
  6106. } else {
  6107. $sum = $charWidth;
  6108. }
  6109. } else {
  6110. $sum += $charWidth;
  6111. }
  6112. }
  6113. if ($chars[($length - 1)] == 10) {
  6114. --$lines;
  6115. }
  6116. $this->cell_padding = $prev_cell_padding;
  6117. $this->lasth = $prev_lasth;
  6118. return $lines;
  6119. }
  6120. /**
  6121. * This method return the estimated needed height for print a simple text string in Multicell() method.
  6122. * Generally, if you want to know the exact height for a block of content you can use the following alternative technique:
  6123. * @pre
  6124. * // store current object
  6125. * $pdf->startTransaction();
  6126. * // store starting values
  6127. * $start_y = $pdf->GetY();
  6128. * $start_page = $pdf->getPage();
  6129. * // call your printing functions with your parameters
  6130. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6131. * $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);
  6132. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6133. * // get the new Y
  6134. * $end_y = $pdf->GetY();
  6135. * $end_page = $pdf->getPage();
  6136. * // calculate height
  6137. * $height = 0;
  6138. * if ($end_page == $start_page) {
  6139. * $height = $end_y - $start_y;
  6140. * } else {
  6141. * for ($page=$start_page; $page <= $end_page; ++$page) {
  6142. * $this->setPage($page);
  6143. * if ($page == $start_page) {
  6144. * // first page
  6145. * $height = $this->h - $start_y - $this->bMargin;
  6146. * } elseif ($page == $end_page) {
  6147. * // last page
  6148. * $height = $end_y - $this->tMargin;
  6149. * } else {
  6150. * $height = $this->h - $this->tMargin - $this->bMargin;
  6151. * }
  6152. * }
  6153. * }
  6154. * // restore previous object
  6155. * $pdf = $pdf->rollbackTransaction();
  6156. *
  6157. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  6158. * @param $txt (string) String for calculating his height
  6159. * @param $reseth (boolean) if true reset the last cell height (default false).
  6160. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
  6161. * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
  6162. * @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)))
  6163. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  6164. * @author Nicola Asuni, Alexander Escalona Fernández
  6165. * @public
  6166. */
  6167. public function getStringHeight($w, $txt, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
  6168. // adjust internal padding
  6169. $prev_cell_padding = $this->cell_padding;
  6170. $prev_lasth = $this->lasth;
  6171. if (is_array($cellpadding)) {
  6172. $this->cell_padding = $cellpadding;
  6173. }
  6174. $this->adjustCellPadding($border);
  6175. $lines = $this->getNumLines($txt, $w, $reseth, $autopadding, $cellpadding, $border);
  6176. $height = $lines * ($this->FontSize * $this->cell_height_ratio);
  6177. if ($autopadding) {
  6178. // add top and bottom padding
  6179. $height += ($this->cell_padding['T'] + $this->cell_padding['B']);
  6180. }
  6181. $this->cell_padding = $prev_cell_padding;
  6182. $this->lasth = $prev_lasth;
  6183. return $height;
  6184. }
  6185. /**
  6186. * This method prints text from the current position.<br />
  6187. * @param $h (float) Line height
  6188. * @param $txt (string) String to print
  6189. * @param $link (mixed) URL or identifier returned by AddLink()
  6190. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  6191. * @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>
  6192. * @param $ln (boolean) if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
  6193. * @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.
  6194. * @param $firstline (boolean) if true prints only the first line and return the remaining string.
  6195. * @param $firstblock (boolean) if true the string is the starting of a line.
  6196. * @param $maxh (float) maximum height. The remaining unprinted text will be returned. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature.
  6197. * @param $wadj (float) first line width will be reduced by this amount (used in HTML mode).
  6198. * @param $margin (array) margin array of the parent container
  6199. * @return mixed Return the number of cells or the remaining string if $firstline = true.
  6200. * @public
  6201. * @since 1.5
  6202. */
  6203. public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $stretch=0, $firstline=false, $firstblock=false, $maxh=0, $wadj=0, $margin='') {
  6204. // check page for no-write regions and adapt page margins if necessary
  6205. $this->checkPageRegions($h, $this->x, $this->y);
  6206. if (strlen($txt) == 0) {
  6207. // fix empty text
  6208. $txt = ' ';
  6209. }
  6210. if ($margin === '') {
  6211. // set default margins
  6212. $margin = $this->cell_margin;
  6213. }
  6214. // remove carriage returns
  6215. $s = str_replace("\r", '', $txt);
  6216. // check if string contains arabic text
  6217. if (preg_match($this->unicode->uni_RE_PATTERN_ARABIC, $s)) {
  6218. $arabic = true;
  6219. } else {
  6220. $arabic = false;
  6221. }
  6222. // check if string contains RTL text
  6223. if ($arabic OR ($this->tmprtl == 'R') OR preg_match($this->unicode->uni_RE_PATTERN_RTL, $s)) {
  6224. $rtlmode = true;
  6225. } else {
  6226. $rtlmode = false;
  6227. }
  6228. // get a char width
  6229. $chrwidth = $this->GetCharWidth('.');
  6230. // get array of unicode values
  6231. $chars = $this->UTF8StringToArray($s);
  6232. // get array of chars
  6233. $uchars = $this->UTF8ArrayToUniArray($chars);
  6234. // get the number of characters
  6235. $nb = count($chars);
  6236. // replacement for SHY character (minus symbol)
  6237. $shy_replacement = 45;
  6238. $shy_replacement_char = $this->unichr($shy_replacement);
  6239. // widht for SHY replacement
  6240. $shy_replacement_width = $this->GetCharWidth($shy_replacement);
  6241. // max Y
  6242. $maxy = $this->y + $maxh - $h - $this->cell_padding['T'] - $this->cell_padding['B'];
  6243. // calculate remaining line width ($w)
  6244. if ($this->rtl) {
  6245. $w = $this->x - $this->lMargin;
  6246. } else {
  6247. $w = $this->w - $this->rMargin - $this->x;
  6248. }
  6249. // max column width
  6250. $wmax = $w - $wadj;
  6251. if (!$firstline) {
  6252. $wmax -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  6253. }
  6254. if ((!$firstline) AND (($chrwidth > $wmax) OR ($this->GetCharWidth($chars[0]) > $wmax))) {
  6255. // a single character do not fit on column
  6256. return '';
  6257. }
  6258. // minimum row height
  6259. $row_height = max($h, $this->FontSize * $this->cell_height_ratio);
  6260. $start_page = $this->page;
  6261. $i = 0; // character position
  6262. $j = 0; // current starting position
  6263. $sep = -1; // position of the last blank space
  6264. $shy = false; // true if the last blank is a soft hypen (SHY)
  6265. $l = 0; // current string length
  6266. $nl = 0; //number of lines
  6267. $linebreak = false;
  6268. $pc = 0; // previous character
  6269. // for each character
  6270. while ($i < $nb) {
  6271. if (($maxh > 0) AND ($this->y >= $maxy) ) {
  6272. break;
  6273. }
  6274. //Get the current character
  6275. $c = $chars[$i];
  6276. if ($c == 10) { // 10 = "\n" = new line
  6277. //Explicit line break
  6278. if ($align == 'J') {
  6279. if ($this->rtl) {
  6280. $talign = 'R';
  6281. } else {
  6282. $talign = 'L';
  6283. }
  6284. } else {
  6285. $talign = $align;
  6286. }
  6287. $tmpstr = $this->UniArrSubString($uchars, $j, $i);
  6288. if ($firstline) {
  6289. $startx = $this->x;
  6290. $tmparr = array_slice($chars, $j, ($i - $j));
  6291. if ($rtlmode) {
  6292. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  6293. }
  6294. $linew = $this->GetArrStringWidth($tmparr);
  6295. unset($tmparr);
  6296. if ($this->rtl) {
  6297. $this->endlinex = $startx - $linew;
  6298. } else {
  6299. $this->endlinex = $startx + $linew;
  6300. }
  6301. $w = $linew;
  6302. $tmpcellpadding = $this->cell_padding;
  6303. if ($maxh == 0) {
  6304. $this->SetCellPadding(0);
  6305. }
  6306. }
  6307. if ($firstblock AND $this->isRTLTextDir()) {
  6308. $tmpstr = $this->stringRightTrim($tmpstr);
  6309. }
  6310. // Skip newlines at the begining of a page or column
  6311. if (!empty($tmpstr) OR ($this->y < ($this->PageBreakTrigger - $row_height))) {
  6312. $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
  6313. }
  6314. unset($tmpstr);
  6315. if ($firstline) {
  6316. $this->cell_padding = $tmpcellpadding;
  6317. return ($this->UniArrSubString($uchars, $i));
  6318. }
  6319. ++$nl;
  6320. $j = $i + 1;
  6321. $l = 0;
  6322. $sep = -1;
  6323. $shy = false;
  6324. // account for margin changes
  6325. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND (!$this->InFooter)) {
  6326. $this->AcceptPageBreak();
  6327. if ($this->rtl) {
  6328. $this->x -= $margin['R'];
  6329. } else {
  6330. $this->x += $margin['L'];
  6331. }
  6332. $this->lMargin += $margin['L'];
  6333. $this->rMargin += $margin['R'];
  6334. }
  6335. $w = $this->getRemainingWidth();
  6336. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6337. } else {
  6338. // 160 is the non-breaking space.
  6339. // 173 is SHY (Soft Hypen).
  6340. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  6341. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  6342. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  6343. if (($c != 160) AND (($c == 173) OR preg_match($this->re_spaces, $this->unichr($c)))) {
  6344. // update last blank space position
  6345. $sep = $i;
  6346. // check if is a SHY
  6347. if ($c == 173) {
  6348. $shy = true;
  6349. if ($pc == 45) {
  6350. $tmp_shy_replacement_width = 0;
  6351. $tmp_shy_replacement_char = '';
  6352. } else {
  6353. $tmp_shy_replacement_width = $shy_replacement_width;
  6354. $tmp_shy_replacement_char = $shy_replacement_char;
  6355. }
  6356. } else {
  6357. $shy = false;
  6358. }
  6359. }
  6360. // update string length
  6361. if ($this->isUnicodeFont() AND ($arabic)) {
  6362. // with bidirectional algorithm some chars may be changed affecting the line length
  6363. // *** very slow ***
  6364. $l = $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl));
  6365. } else {
  6366. $l += $this->GetCharWidth($c);
  6367. }
  6368. if (($l > $wmax) OR (($c == 173) AND (($l + $tmp_shy_replacement_width) > $wmax)) ) {
  6369. // we have reached the end of column
  6370. if ($sep == -1) {
  6371. // check if the line was already started
  6372. if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $chrwidth)))
  6373. OR ((!$this->rtl) AND ($this->x >= ($this->lMargin + $chrwidth)))) {
  6374. // print a void cell and go to next line
  6375. $this->Cell($w, $h, '', 0, 1);
  6376. $linebreak = true;
  6377. if ($firstline) {
  6378. return ($this->UniArrSubString($uchars, $j));
  6379. }
  6380. } else {
  6381. // truncate the word because do not fit on column
  6382. $tmpstr = $this->UniArrSubString($uchars, $j, $i);
  6383. if ($firstline) {
  6384. $startx = $this->x;
  6385. $tmparr = array_slice($chars, $j, ($i - $j));
  6386. if ($rtlmode) {
  6387. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  6388. }
  6389. $linew = $this->GetArrStringWidth($tmparr);
  6390. unset($tmparr);
  6391. if ($this->rtl) {
  6392. $this->endlinex = $startx - $linew;
  6393. } else {
  6394. $this->endlinex = $startx + $linew;
  6395. }
  6396. $w = $linew;
  6397. $tmpcellpadding = $this->cell_padding;
  6398. if ($maxh == 0) {
  6399. $this->SetCellPadding(0);
  6400. }
  6401. }
  6402. if ($firstblock AND $this->isRTLTextDir()) {
  6403. $tmpstr = $this->stringRightTrim($tmpstr);
  6404. }
  6405. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  6406. unset($tmpstr);
  6407. if ($firstline) {
  6408. $this->cell_padding = $tmpcellpadding;
  6409. return ($this->UniArrSubString($uchars, $i));
  6410. }
  6411. $j = $i;
  6412. --$i;
  6413. }
  6414. } else {
  6415. // word wrapping
  6416. if ($this->rtl AND (!$firstblock) AND ($sep < $i)) {
  6417. $endspace = 1;
  6418. } else {
  6419. $endspace = 0;
  6420. }
  6421. if ($shy) {
  6422. // add hypen (minus symbol) at the end of the line
  6423. $shy_width = $tmp_shy_replacement_width;
  6424. if ($this->rtl) {
  6425. $shy_char_left = $tmp_shy_replacement_char;
  6426. $shy_char_right = '';
  6427. } else {
  6428. $shy_char_left = '';
  6429. $shy_char_right = $tmp_shy_replacement_char;
  6430. }
  6431. } else {
  6432. $shy_width = 0;
  6433. $shy_char_left = '';
  6434. $shy_char_right = '';
  6435. }
  6436. $tmpstr = $this->UniArrSubString($uchars, $j, ($sep + $endspace));
  6437. if ($firstline) {
  6438. $startx = $this->x;
  6439. $tmparr = array_slice($chars, $j, (($sep + $endspace) - $j));
  6440. if ($rtlmode) {
  6441. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  6442. }
  6443. $linew = $this->GetArrStringWidth($tmparr);
  6444. unset($tmparr);
  6445. if ($this->rtl) {
  6446. $this->endlinex = $startx - $linew - $shy_width;
  6447. } else {
  6448. $this->endlinex = $startx + $linew + $shy_width;
  6449. }
  6450. $w = $linew;
  6451. $tmpcellpadding = $this->cell_padding;
  6452. if ($maxh == 0) {
  6453. $this->SetCellPadding(0);
  6454. }
  6455. }
  6456. // print the line
  6457. if ($firstblock AND $this->isRTLTextDir()) {
  6458. $tmpstr = $this->stringRightTrim($tmpstr);
  6459. }
  6460. $this->Cell($w, $h, $shy_char_left.$tmpstr.$shy_char_right, 0, 1, $align, $fill, $link, $stretch);
  6461. unset($tmpstr);
  6462. if ($firstline) {
  6463. // return the remaining text
  6464. $this->cell_padding = $tmpcellpadding;
  6465. return ($this->UniArrSubString($uchars, ($sep + $endspace)));
  6466. }
  6467. $i = $sep;
  6468. $sep = -1;
  6469. $shy = false;
  6470. $j = ($i+1);
  6471. }
  6472. // account for margin changes
  6473. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND (!$this->InFooter)) {
  6474. $this->AcceptPageBreak();
  6475. if ($this->rtl) {
  6476. $this->x -= $margin['R'];
  6477. } else {
  6478. $this->x += $margin['L'];
  6479. }
  6480. $this->lMargin += $margin['L'];
  6481. $this->rMargin += $margin['R'];
  6482. }
  6483. $w = $this->getRemainingWidth();
  6484. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6485. if ($linebreak) {
  6486. $linebreak = false;
  6487. } else {
  6488. ++$nl;
  6489. $l = 0;
  6490. }
  6491. }
  6492. }
  6493. // save last character
  6494. $pc = $c;
  6495. ++$i;
  6496. } // end while i < nb
  6497. // print last substring (if any)
  6498. if ($l > 0) {
  6499. switch ($align) {
  6500. case 'J':
  6501. case 'C': {
  6502. $w = $w;
  6503. break;
  6504. }
  6505. case 'L': {
  6506. if ($this->rtl) {
  6507. $w = $w;
  6508. } else {
  6509. $w = $l;
  6510. }
  6511. break;
  6512. }
  6513. case 'R': {
  6514. if ($this->rtl) {
  6515. $w = $l;
  6516. } else {
  6517. $w = $w;
  6518. }
  6519. break;
  6520. }
  6521. default: {
  6522. $w = $l;
  6523. break;
  6524. }
  6525. }
  6526. $tmpstr = $this->UniArrSubString($uchars, $j, $nb);
  6527. if ($firstline) {
  6528. $startx = $this->x;
  6529. $tmparr = array_slice($chars, $j, ($nb - $j));
  6530. if ($rtlmode) {
  6531. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  6532. }
  6533. $linew = $this->GetArrStringWidth($tmparr);
  6534. unset($tmparr);
  6535. if ($this->rtl) {
  6536. $this->endlinex = $startx - $linew;
  6537. } else {
  6538. $this->endlinex = $startx + $linew;
  6539. }
  6540. $w = $linew;
  6541. $tmpcellpadding = $this->cell_padding;
  6542. if ($maxh == 0) {
  6543. $this->SetCellPadding(0);
  6544. }
  6545. }
  6546. if ($firstblock AND $this->isRTLTextDir()) {
  6547. $tmpstr = $this->stringRightTrim($tmpstr);
  6548. }
  6549. $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
  6550. unset($tmpstr);
  6551. if ($firstline) {
  6552. $this->cell_padding = $tmpcellpadding;
  6553. return ($this->UniArrSubString($uchars, $nb));
  6554. }
  6555. ++$nl;
  6556. }
  6557. if ($firstline) {
  6558. return '';
  6559. }
  6560. return $nl;
  6561. }
  6562. /**
  6563. * Returns the remaining width between the current position and margins.
  6564. * @return int Return the remaining width
  6565. * @protected
  6566. */
  6567. protected function getRemainingWidth() {
  6568. $this->checkPageRegions(0, $this->x, $this->y);
  6569. if ($this->rtl) {
  6570. return ($this->x - $this->lMargin);
  6571. } else {
  6572. return ($this->w - $this->rMargin - $this->x);
  6573. }
  6574. }
  6575. /**
  6576. * Extract a slice of the $strarr array and return it as string.
  6577. * @param $strarr (string) The input array of characters.
  6578. * @param $start (int) the starting element of $strarr.
  6579. * @param $end (int) first element that will not be returned.
  6580. * @return Return part of a string
  6581. * @public
  6582. */
  6583. public function UTF8ArrSubString($strarr, $start='', $end='') {
  6584. if (strlen($start) == 0) {
  6585. $start = 0;
  6586. }
  6587. if (strlen($end) == 0) {
  6588. $end = count($strarr);
  6589. }
  6590. $string = '';
  6591. for ($i=$start; $i < $end; ++$i) {
  6592. $string .= $this->unichr($strarr[$i]);
  6593. }
  6594. return $string;
  6595. }
  6596. /**
  6597. * Extract a slice of the $uniarr array and return it as string.
  6598. * @param $uniarr (string) The input array of characters.
  6599. * @param $start (int) the starting element of $strarr.
  6600. * @param $end (int) first element that will not be returned.
  6601. * @return Return part of a string
  6602. * @public
  6603. * @since 4.5.037 (2009-04-07)
  6604. */
  6605. public function UniArrSubString($uniarr, $start='', $end='') {
  6606. if (strlen($start) == 0) {
  6607. $start = 0;
  6608. }
  6609. if (strlen($end) == 0) {
  6610. $end = count($uniarr);
  6611. }
  6612. $string = '';
  6613. for ($i=$start; $i < $end; ++$i) {
  6614. $string .= $uniarr[$i];
  6615. }
  6616. return $string;
  6617. }
  6618. /**
  6619. * Convert an array of UTF8 values to array of unicode characters
  6620. * @param $ta (string) The input array of UTF8 values.
  6621. * @return Return array of unicode characters
  6622. * @public
  6623. * @since 4.5.037 (2009-04-07)
  6624. */
  6625. public function UTF8ArrayToUniArray($ta) {
  6626. return array_map(array($this, 'unichr'), $ta);
  6627. }
  6628. /**
  6629. * Returns the unicode caracter specified by UTF-8 value
  6630. * @param $c (int) UTF-8 value
  6631. * @return Returns the specified character.
  6632. * @author Miguel Perez, Nicola Asuni
  6633. * @public
  6634. * @since 2.3.000 (2008-03-05)
  6635. */
  6636. public function unichr($c) {
  6637. if (!$this->isunicode) {
  6638. return chr($c);
  6639. } elseif ($c <= 0x7F) {
  6640. // one byte
  6641. return chr($c);
  6642. } elseif ($c <= 0x7FF) {
  6643. // two bytes
  6644. return chr(0xC0 | $c >> 6).chr(0x80 | $c & 0x3F);
  6645. } elseif ($c <= 0xFFFF) {
  6646. // three bytes
  6647. return chr(0xE0 | $c >> 12).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F);
  6648. } elseif ($c <= 0x10FFFF) {
  6649. // four bytes
  6650. return chr(0xF0 | $c >> 18).chr(0x80 | $c >> 12 & 0x3F).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F);
  6651. } else {
  6652. return '';
  6653. }
  6654. }
  6655. /**
  6656. * Return the image type given the file name or array returned by getimagesize() function.
  6657. * @param $imgfile (string) image file name
  6658. * @param $iminfo (array) array of image information returned by getimagesize() function.
  6659. * @return string image type
  6660. * @since 4.8.017 (2009-11-27)
  6661. */
  6662. public function getImageFileType($imgfile, $iminfo=array()) {
  6663. $type = '';
  6664. if (isset($iminfo['mime']) AND !empty($iminfo['mime'])) {
  6665. $mime = explode('/', $iminfo['mime']);
  6666. if ((count($mime) > 1) AND ($mime[0] == 'image') AND (!empty($mime[1]))) {
  6667. $type = strtolower(trim($mime[1]));
  6668. }
  6669. }
  6670. if (empty($type)) {
  6671. $fileinfo = pathinfo($imgfile);
  6672. if (isset($fileinfo['extension']) AND (!$this->empty_string($fileinfo['extension']))) {
  6673. $type = strtolower(trim($fileinfo['extension']));
  6674. }
  6675. }
  6676. if ($type == 'jpg') {
  6677. $type = 'jpeg';
  6678. }
  6679. return $type;
  6680. }
  6681. /**
  6682. * Set the block dimensions accounting for page breaks and page/column fitting
  6683. * @param $w (float) width
  6684. * @param $h (float) height
  6685. * @param $x (float) X coordinate
  6686. * @param $y (float) Y coodiante
  6687. * @param $fitonpage (boolean) if true the block is resized to not exceed page dimensions.
  6688. * @protected
  6689. * @since 5.5.009 (2010-07-05)
  6690. */
  6691. protected function fitBlock(&$w, &$h, &$x, &$y, $fitonpage=false) {
  6692. if ($w <= 0) {
  6693. // set maximum width
  6694. $w = ($this->w - $this->lMargin - $this->rMargin);
  6695. }
  6696. if ($h <= 0) {
  6697. // set maximum height
  6698. $h = ($this->PageBreakTrigger - $this->tMargin);
  6699. }
  6700. // resize the block to be vertically contained on a single page or single column
  6701. if ($fitonpage OR $this->AutoPageBreak) {
  6702. $ratio_wh = ($w / $h);
  6703. if ($h > ($this->PageBreakTrigger - $this->tMargin)) {
  6704. $h = $this->PageBreakTrigger - $this->tMargin;
  6705. $w = ($h * $ratio_wh);
  6706. }
  6707. // resize the block to be horizontally contained on a single page or single column
  6708. if ($fitonpage) {
  6709. $maxw = ($this->w - $this->lMargin - $this->rMargin);
  6710. if ($w > $maxw) {
  6711. $w = $maxw;
  6712. $h = ($w / $ratio_wh);
  6713. }
  6714. }
  6715. }
  6716. // Check whether we need a new page or new column first as this does not fit
  6717. $prev_x = $this->x;
  6718. $prev_y = $this->y;
  6719. if ($this->checkPageBreak($h, $y) OR ($this->y < $prev_y)) {
  6720. $y = $this->y;
  6721. if ($this->rtl) {
  6722. $x += ($prev_x - $this->x);
  6723. } else {
  6724. $x += ($this->x - $prev_x);
  6725. }
  6726. }
  6727. // resize the block to be contained on the remaining available page or column space
  6728. if ($fitonpage) {
  6729. $ratio_wh = ($w / $h);
  6730. if (($y + $h) > $this->PageBreakTrigger) {
  6731. $h = $this->PageBreakTrigger - $y;
  6732. $w = ($h * $ratio_wh);
  6733. }
  6734. if ((!$this->rtl) AND (($x + $w) > ($this->w - $this->rMargin))) {
  6735. $w = $this->w - $this->rMargin - $x;
  6736. $h = ($w / $ratio_wh);
  6737. } elseif (($this->rtl) AND (($x - $w) < ($this->lMargin))) {
  6738. $w = $x - $this->lMargin;
  6739. $h = ($w / $ratio_wh);
  6740. }
  6741. }
  6742. }
  6743. /**
  6744. * Puts an image in the page.
  6745. * The upper-left corner must be given.
  6746. * The dimensions can be specified in different ways:<ul>
  6747. * <li>explicit width and height (expressed in user unit)</li>
  6748. * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
  6749. * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  6750. * 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;
  6751. * The format can be specified explicitly or inferred from the file extension.<br />
  6752. * It is possible to put a link on the image.<br />
  6753. * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  6754. * @param $file (string) Name of the file containing the image or a '@' character followed by the image data string.
  6755. * @param $x (float) Abscissa of the upper-left corner (LTR) or upper-right corner (RTL).
  6756. * @param $y (float) Ordinate of the upper-left corner (LTR) or upper-right corner (RTL).
  6757. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6758. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6759. * @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.
  6760. * @param $link (mixed) URL or identifier returned by AddLink().
  6761. * @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>
  6762. * @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).
  6763. * @param $dpi (int) dot-per-inch resolution used on resize
  6764. * @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>
  6765. * @param $ismask (boolean) true if this image is a mask, false otherwise
  6766. * @param $imgmask (mixed) image object returned by this function or false
  6767. * @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)))
  6768. * @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).
  6769. * @param $hidden (boolean) if true do not display the image.
  6770. * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
  6771. * @return image information
  6772. * @public
  6773. * @since 1.1
  6774. */
  6775. 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) {
  6776. if ($x === '') {
  6777. $x = $this->x;
  6778. }
  6779. if ($y === '') {
  6780. $y = $this->y;
  6781. }
  6782. // check page for no-write regions and adapt page margins if necessary
  6783. $this->checkPageRegions($h, $x, $y);
  6784. $cached_file = false; // true when the file is cached
  6785. // check if we are passing an image as file or string
  6786. if ($file{0} === '@') { // image from string
  6787. $imgdata = substr($file, 1);
  6788. $file = tempnam(K_PATH_CACHE, 'img_');
  6789. $fp = fopen($file, 'w');
  6790. fwrite($fp, $imgdata);
  6791. fclose($fp);
  6792. unset($imgdata);
  6793. $cached_file = true;
  6794. $imsize = @getimagesize($file);
  6795. if ($imsize === FALSE) {
  6796. unlink($file);
  6797. $cached_file = false;
  6798. }
  6799. } else { // image file
  6800. // check if is local file
  6801. if (!@file_exists($file)) {
  6802. // encode spaces on filename (file is probably an URL)
  6803. $file = str_replace(' ', '%20', $file);
  6804. }
  6805. // get image dimensions
  6806. $imsize = @getimagesize($file);
  6807. if ($imsize === FALSE) {
  6808. if (function_exists('curl_init')) {
  6809. // try to get remote file data using cURL
  6810. $cs = curl_init(); // curl session
  6811. curl_setopt($cs, CURLOPT_URL, $file);
  6812. curl_setopt($cs, CURLOPT_BINARYTRANSFER, true);
  6813. curl_setopt($cs, CURLOPT_FAILONERROR, true);
  6814. curl_setopt($cs, CURLOPT_RETURNTRANSFER, true);
  6815. curl_setopt($cs, CURLOPT_CONNECTTIMEOUT, 5);
  6816. curl_setopt($cs, CURLOPT_TIMEOUT, 30);
  6817. $imgdata = curl_exec($cs);
  6818. curl_close($cs);
  6819. if($imgdata !== FALSE) {
  6820. // copy image to cache
  6821. $file = tempnam(K_PATH_CACHE, 'img_');
  6822. $fp = fopen($file, 'w');
  6823. fwrite($fp, $imgdata);
  6824. fclose($fp);
  6825. unset($imgdata);
  6826. $cached_file = true;
  6827. $imsize = @getimagesize($file);
  6828. if ($imsize === FALSE) {
  6829. unlink($file);
  6830. $cached_file = false;
  6831. }
  6832. }
  6833. } elseif (($w > 0) AND ($h > 0)) {
  6834. // get measures from specified data
  6835. $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  6836. $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  6837. $imsize = array($pw, $ph);
  6838. }
  6839. }
  6840. }
  6841. if ($imsize === FALSE) {
  6842. $this->Error('[Image] Unable to get image: '.$file);
  6843. }
  6844. // get original image width and height in pixels
  6845. list($pixw, $pixh) = $imsize;
  6846. // calculate image width and height on document
  6847. if (($w <= 0) AND ($h <= 0)) {
  6848. // convert image size to document unit
  6849. $w = $this->pixelsToUnits($pixw);
  6850. $h = $this->pixelsToUnits($pixh);
  6851. } elseif ($w <= 0) {
  6852. $w = $h * $pixw / $pixh;
  6853. } elseif ($h <= 0) {
  6854. $h = $w * $pixh / $pixw;
  6855. } elseif (($fitbox !== false) AND ($w > 0) AND ($h > 0)) {
  6856. if (strlen($fitbox) !== 2) {
  6857. // set default alignment
  6858. $fitbox = '--';
  6859. }
  6860. // scale image dimensions proportionally to fit within the ($w, $h) box
  6861. if ((($w * $pixh) / ($h * $pixw)) < 1) {
  6862. // store current height
  6863. $oldh = $h;
  6864. // calculate new height
  6865. $h = $w * $pixh / $pixw;
  6866. // height difference
  6867. $hdiff = ($oldh - $h);
  6868. // vertical alignment
  6869. switch (strtoupper($fitbox{1})) {
  6870. case 'T': {
  6871. break;
  6872. }
  6873. case 'M': {
  6874. $y += ($hdiff / 2);
  6875. break;
  6876. }
  6877. case 'B': {
  6878. $y += $hdiff;
  6879. break;
  6880. }
  6881. }
  6882. } else {
  6883. // store current width
  6884. $oldw = $w;
  6885. // calculate new width
  6886. $w = $h * $pixw / $pixh;
  6887. // width difference
  6888. $wdiff = ($oldw - $w);
  6889. // horizontal alignment
  6890. switch (strtoupper($fitbox{0})) {
  6891. case 'L': {
  6892. if ($this->rtl) {
  6893. $x -= $wdiff;
  6894. }
  6895. break;
  6896. }
  6897. case 'C': {
  6898. if ($this->rtl) {
  6899. $x -= ($wdiff / 2);
  6900. } else {
  6901. $x += ($wdiff / 2);
  6902. }
  6903. break;
  6904. }
  6905. case 'R': {
  6906. if (!$this->rtl) {
  6907. $x += $wdiff;
  6908. }
  6909. break;
  6910. }
  6911. }
  6912. }
  6913. }
  6914. // fit the image on available space
  6915. $this->fitBlock($w, $h, $x, $y, $fitonpage);
  6916. // calculate new minimum dimensions in pixels
  6917. $neww = round($w * $this->k * $dpi / $this->dpi);
  6918. $newh = round($h * $this->k * $dpi / $this->dpi);
  6919. // check if resize is necessary (resize is used only to reduce the image)
  6920. $newsize = ($neww * $newh);
  6921. $pixsize = ($pixw * $pixh);
  6922. if (intval($resize) == 2) {
  6923. $resize = true;
  6924. } elseif ($newsize >= $pixsize) {
  6925. $resize = false;
  6926. }
  6927. // check if image has been already added on document
  6928. $newimage = true;
  6929. if (in_array($file, $this->imagekeys)) {
  6930. $newimage = false;
  6931. // get existing image data
  6932. $info = $this->getImageBuffer($file);
  6933. // check if the newer image is larger
  6934. $oldsize = ($info['w'] * $info['h']);
  6935. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  6936. $newimage = true;
  6937. }
  6938. }
  6939. if ($newimage) {
  6940. //First use of image, get info
  6941. $type = strtolower($type);
  6942. if ($type == '') {
  6943. $type = $this->getImageFileType($file, $imsize);
  6944. } elseif ($type == 'jpg') {
  6945. $type = 'jpeg';
  6946. }
  6947. $mqr = $this->get_mqr();
  6948. $this->set_mqr(false);
  6949. // Specific image handlers
  6950. $mtd = '_parse'.$type;
  6951. // GD image handler function
  6952. $gdfunction = 'imagecreatefrom'.$type;
  6953. $info = false;
  6954. if ((method_exists($this, $mtd)) AND (!($resize AND function_exists($gdfunction)))) {
  6955. // TCPDF image functions
  6956. $info = $this->$mtd($file);
  6957. if ($info == 'pngalpha') {
  6958. return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign);
  6959. }
  6960. }
  6961. if (!$info) {
  6962. if (function_exists($gdfunction)) {
  6963. // GD library
  6964. $img = $gdfunction($file);
  6965. if ($resize) {
  6966. $imgr = imagecreatetruecolor($neww, $newh);
  6967. if (($type == 'gif') OR ($type == 'png')) {
  6968. $imgr = $this->_setGDImageTransparency($imgr, $img);
  6969. }
  6970. imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
  6971. if (($type == 'gif') OR ($type == 'png')) {
  6972. $info = $this->_toPNG($imgr);
  6973. } else {
  6974. $info = $this->_toJPEG($imgr);
  6975. }
  6976. } else {
  6977. if (($type == 'gif') OR ($type == 'png')) {
  6978. $info = $this->_toPNG($img);
  6979. } else {
  6980. $info = $this->_toJPEG($img);
  6981. }
  6982. }
  6983. } elseif (extension_loaded('imagick')) {
  6984. // ImageMagick library
  6985. $img = new Imagick();
  6986. if ($type == 'SVG') {
  6987. // get SVG file content
  6988. $svgimg = file_get_contents($file);
  6989. // get width and height
  6990. $regs = array();
  6991. if (preg_match('/<svg([^\>]*)>/si', $svgimg, $regs)) {
  6992. $svgtag = $regs[1];
  6993. $tmp = array();
  6994. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  6995. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  6996. $owu = sprintf('%.3F', ($ow * $dpi / 72)).$this->pdfunit;
  6997. $svgtag = preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si', ' width="'.$owu.'"', $svgtag, 1);
  6998. } else {
  6999. $ow = $w;
  7000. }
  7001. $tmp = array();
  7002. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  7003. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  7004. $ohu = sprintf('%.3F', ($oh * $dpi / 72)).$this->pdfunit;
  7005. $svgtag = preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si', ' height="'.$ohu.'"', $svgtag, 1);
  7006. } else {
  7007. $oh = $h;
  7008. }
  7009. $tmp = array();
  7010. if (!preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $svgtag, $tmp)) {
  7011. $vbw = ($ow * $this->imgscale * $this->k);
  7012. $vbh = ($oh * $this->imgscale * $this->k);
  7013. $vbox = sprintf(' viewBox="0 0 %.3F %.3F" ', $vbw, $vbh);
  7014. $svgtag = $vbox.$svgtag;
  7015. }
  7016. $svgimg = preg_replace('/<svg([^\>]*)>/si', '<svg'.$svgtag.'>', $svgimg, 1);
  7017. }
  7018. $img->readImageBlob($svgimg);
  7019. } else {
  7020. $img->readImage($file);
  7021. }
  7022. if ($resize) {
  7023. $img->resizeImage($neww, $newh, 10, 1, false);
  7024. }
  7025. $img->setCompressionQuality($this->jpeg_quality);
  7026. $img->setImageFormat('jpeg');
  7027. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  7028. $img->writeImage($tempname);
  7029. $info = $this->_parsejpeg($tempname);
  7030. unlink($tempname);
  7031. $img->destroy();
  7032. } else {
  7033. return;
  7034. }
  7035. }
  7036. if ($info === false) {
  7037. //If false, we cannot process image
  7038. return;
  7039. }
  7040. $this->set_mqr($mqr);
  7041. if ($ismask) {
  7042. // force grayscale
  7043. $info['cs'] = 'DeviceGray';
  7044. }
  7045. $info['i'] = $this->numimages;
  7046. if (!in_array($file, $this->imagekeys)) {
  7047. ++$info['i'];
  7048. }
  7049. if ($imgmask !== false) {
  7050. $info['masked'] = $imgmask;
  7051. }
  7052. // add image to document
  7053. $this->setImageBuffer($file, $info);
  7054. }
  7055. if ($cached_file) {
  7056. // remove cached file
  7057. unlink($file);
  7058. }
  7059. // set alignment
  7060. $this->img_rb_y = $y + $h;
  7061. // set alignment
  7062. if ($this->rtl) {
  7063. if ($palign == 'L') {
  7064. $ximg = $this->lMargin;
  7065. } elseif ($palign == 'C') {
  7066. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  7067. } elseif ($palign == 'R') {
  7068. $ximg = $this->w - $this->rMargin - $w;
  7069. } else {
  7070. $ximg = $x - $w;
  7071. }
  7072. $this->img_rb_x = $ximg;
  7073. } else {
  7074. if ($palign == 'L') {
  7075. $ximg = $this->lMargin;
  7076. } elseif ($palign == 'C') {
  7077. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  7078. } elseif ($palign == 'R') {
  7079. $ximg = $this->w - $this->rMargin - $w;
  7080. } else {
  7081. $ximg = $x;
  7082. }
  7083. $this->img_rb_x = $ximg + $w;
  7084. }
  7085. if ($ismask OR $hidden) {
  7086. // image is not displayed
  7087. return $info['i'];
  7088. }
  7089. $xkimg = $ximg * $this->k;
  7090. $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%u Do Q', ($w * $this->k), ($h * $this->k), $xkimg, (($this->h - ($y + $h)) * $this->k), $info['i']));
  7091. if (!empty($border)) {
  7092. $bx = $this->x;
  7093. $by = $this->y;
  7094. $this->x = $ximg;
  7095. if ($this->rtl) {
  7096. $this->x += $w;
  7097. }
  7098. $this->y = $y;
  7099. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  7100. $this->x = $bx;
  7101. $this->y = $by;
  7102. }
  7103. if ($link) {
  7104. $this->Link($ximg, $y, $w, $h, $link, 0);
  7105. }
  7106. // set pointer to align the next text/objects
  7107. switch($align) {
  7108. case 'T': {
  7109. $this->y = $y;
  7110. $this->x = $this->img_rb_x;
  7111. break;
  7112. }
  7113. case 'M': {
  7114. $this->y = $y + round($h/2);
  7115. $this->x = $this->img_rb_x;
  7116. break;
  7117. }
  7118. case 'B': {
  7119. $this->y = $this->img_rb_y;
  7120. $this->x = $this->img_rb_x;
  7121. break;
  7122. }
  7123. case 'N': {
  7124. $this->SetY($this->img_rb_y);
  7125. break;
  7126. }
  7127. default:{
  7128. break;
  7129. }
  7130. }
  7131. $this->endlinex = $this->img_rb_x;
  7132. if ($this->inxobj) {
  7133. // we are inside an XObject template
  7134. $this->xobjects[$this->xobjid]['images'][] = $info['i'];
  7135. }
  7136. return $info['i'];
  7137. }
  7138. /**
  7139. * Sets the current active configuration setting of magic_quotes_runtime (if the set_magic_quotes_runtime function exist)
  7140. * @param $mqr (boolean) FALSE for off, TRUE for on.
  7141. * @since 4.6.025 (2009-08-17)
  7142. */
  7143. public function set_mqr($mqr) {
  7144. if(!defined('PHP_VERSION_ID')) {
  7145. $version = PHP_VERSION;
  7146. define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
  7147. }
  7148. if (PHP_VERSION_ID < 50300) {
  7149. @set_magic_quotes_runtime($mqr);
  7150. }
  7151. }
  7152. /**
  7153. * Gets the current active configuration setting of magic_quotes_runtime (if the get_magic_quotes_runtime function exist)
  7154. * @return Returns 0 if magic quotes runtime is off or get_magic_quotes_runtime doesn't exist, 1 otherwise.
  7155. * @since 4.6.025 (2009-08-17)
  7156. */
  7157. public function get_mqr() {
  7158. if(!defined('PHP_VERSION_ID')) {
  7159. $version = PHP_VERSION;
  7160. define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
  7161. }
  7162. if (PHP_VERSION_ID < 50300) {
  7163. return @get_magic_quotes_runtime();
  7164. }
  7165. return 0;
  7166. }
  7167. /**
  7168. * Convert the loaded image to a JPEG and then return a structure for the PDF creator.
  7169. * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
  7170. * @param $image (image) Image object.
  7171. * return image JPEG image object.
  7172. * @protected
  7173. */
  7174. protected function _toJPEG($image) {
  7175. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  7176. imagejpeg($image, $tempname, $this->jpeg_quality);
  7177. imagedestroy($image);
  7178. $retvars = $this->_parsejpeg($tempname);
  7179. // tidy up by removing temporary image
  7180. unlink($tempname);
  7181. return $retvars;
  7182. }
  7183. /**
  7184. * Convert the loaded image to a PNG and then return a structure for the PDF creator.
  7185. * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
  7186. * @param $image (image) Image object.
  7187. * return image PNG image object.
  7188. * @protected
  7189. * @since 4.9.016 (2010-04-20)
  7190. */
  7191. protected function _toPNG($image) {
  7192. // set temporary image file name
  7193. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  7194. // turn off interlaced mode
  7195. imageinterlace($image, 0);
  7196. // create temporary PNG image
  7197. imagepng($image, $tempname);
  7198. // remove image from memory
  7199. imagedestroy($image);
  7200. // get PNG image data
  7201. $retvars = $this->_parsepng($tempname);
  7202. // tidy up by removing temporary image
  7203. unlink($tempname);
  7204. return $retvars;
  7205. }
  7206. /**
  7207. * Set the transparency for the given GD image.
  7208. * @param $new_image (image) GD image object
  7209. * @param $image (image) GD image object.
  7210. * return GD image object.
  7211. * @protected
  7212. * @since 4.9.016 (2010-04-20)
  7213. */
  7214. protected function _setGDImageTransparency($new_image, $image) {
  7215. // transparency index
  7216. $tid = imagecolortransparent($image);
  7217. // default transparency color
  7218. $tcol = array('red' => 255, 'green' => 255, 'blue' => 255);
  7219. if ($tid >= 0) {
  7220. // get the colors for the transparency index
  7221. $tcol = imagecolorsforindex($image, $tid);
  7222. }
  7223. $tid = imagecolorallocate($new_image, $tcol['red'], $tcol['green'], $tcol['blue']);
  7224. imagefill($new_image, 0, 0, $tid);
  7225. imagecolortransparent($new_image, $tid);
  7226. return $new_image;
  7227. }
  7228. /**
  7229. * Extract info from a JPEG file without using the GD library.
  7230. * @param $file (string) image file to parse
  7231. * @return array structure containing the image data
  7232. * @protected
  7233. */
  7234. protected function _parsejpeg($file) {
  7235. $a = getimagesize($file);
  7236. if (empty($a)) {
  7237. $this->Error('Missing or incorrect image file: '.$file);
  7238. }
  7239. if ($a[2] != 2) {
  7240. $this->Error('Not a JPEG file: '.$file);
  7241. }
  7242. if ((!isset($a['channels'])) OR ($a['channels'] == 3)) {
  7243. $colspace = 'DeviceRGB';
  7244. } elseif ($a['channels'] == 4) {
  7245. $colspace = 'DeviceCMYK';
  7246. } else {
  7247. $colspace = 'DeviceGray';
  7248. }
  7249. $bpc = isset($a['bits']) ? $a['bits'] : 8;
  7250. $data = file_get_contents($file);
  7251. return array('w' => $a[0], 'h' => $a[1], 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data);
  7252. }
  7253. /**
  7254. * Extract info from a PNG file without using the GD library.
  7255. * @param $file (string) image file to parse
  7256. * @return array structure containing the image data
  7257. * @protected
  7258. */
  7259. protected function _parsepng($file) {
  7260. $f = fopen($file, 'rb');
  7261. if ($f === false) {
  7262. $this->Error('Can\'t open image file: '.$file);
  7263. }
  7264. //Check signature
  7265. if (fread($f, 8) != chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
  7266. $this->Error('Not a PNG file: '.$file);
  7267. }
  7268. //Read header chunk
  7269. fread($f, 4);
  7270. if (fread($f, 4) != 'IHDR') {
  7271. $this->Error('Incorrect PNG file: '.$file);
  7272. }
  7273. $w = $this->_freadint($f);
  7274. $h = $this->_freadint($f);
  7275. $bpc = ord(fread($f, 1));
  7276. if ($bpc > 8) {
  7277. //$this->Error('16-bit depth not supported: '.$file);
  7278. fclose($f);
  7279. return false;
  7280. }
  7281. $ct = ord(fread($f, 1));
  7282. if ($ct == 0) {
  7283. $colspace = 'DeviceGray';
  7284. } elseif ($ct == 2) {
  7285. $colspace = 'DeviceRGB';
  7286. } elseif ($ct == 3) {
  7287. $colspace = 'Indexed';
  7288. } else {
  7289. // alpha channel
  7290. fclose($f);
  7291. return 'pngalpha';
  7292. }
  7293. if (ord(fread($f, 1)) != 0) {
  7294. //$this->Error('Unknown compression method: '.$file);
  7295. fclose($f);
  7296. return false;
  7297. }
  7298. if (ord(fread($f, 1)) != 0) {
  7299. //$this->Error('Unknown filter method: '.$file);
  7300. fclose($f);
  7301. return false;
  7302. }
  7303. if (ord(fread($f, 1)) != 0) {
  7304. //$this->Error('Interlacing not supported: '.$file);
  7305. fclose($f);
  7306. return false;
  7307. }
  7308. fread($f, 4);
  7309. $parms = '/DecodeParms << /Predictor 15 /Colors '.($ct == 2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.' >>';
  7310. //Scan chunks looking for palette, transparency and image data
  7311. $pal = '';
  7312. $trns = '';
  7313. $data = '';
  7314. do {
  7315. $n = $this->_freadint($f);
  7316. $type = fread($f, 4);
  7317. if ($type == 'PLTE') {
  7318. //Read palette
  7319. $pal = $this->rfread($f, $n);
  7320. fread($f, 4);
  7321. } elseif ($type == 'tRNS') {
  7322. //Read transparency info
  7323. $t = $this->rfread($f, $n);
  7324. if ($ct == 0) {
  7325. $trns = array(ord(substr($t, 1, 1)));
  7326. } elseif ($ct == 2) {
  7327. $trns = array(ord(substr($t, 1, 1)), ord(substr($t, 3, 1)), ord(substr($t, 5, 1)));
  7328. } else {
  7329. $pos = strpos($t, chr(0));
  7330. if ($pos !== false) {
  7331. $trns = array($pos);
  7332. }
  7333. }
  7334. fread($f, 4);
  7335. } elseif ($type == 'IDAT') {
  7336. //Read image data block
  7337. $data .= $this->rfread($f, $n);
  7338. fread($f, 4);
  7339. } elseif ($type == 'IEND') {
  7340. break;
  7341. } else {
  7342. $this->rfread($f, $n + 4);
  7343. }
  7344. } while ($n);
  7345. if (($colspace == 'Indexed') AND (empty($pal))) {
  7346. //$this->Error('Missing palette in '.$file);
  7347. fclose($f);
  7348. return false;
  7349. }
  7350. fclose($f);
  7351. return array('w' => $w, 'h' => $h, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data);
  7352. }
  7353. /**
  7354. * Binary-safe and URL-safe file read.
  7355. * Reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met: length bytes have been read; EOF (end of file) is reached.
  7356. * @param $handle (resource)
  7357. * @param $length (int)
  7358. * @return Returns the read string or FALSE in case of error.
  7359. * @author Nicola Asuni
  7360. * @protected
  7361. * @since 4.5.027 (2009-03-16)
  7362. */
  7363. protected function rfread($handle, $length) {
  7364. $data = fread($handle, $length);
  7365. if ($data === false) {
  7366. return false;
  7367. }
  7368. $rest = $length - strlen($data);
  7369. if ($rest > 0) {
  7370. $data .= $this->rfread($handle, $rest);
  7371. }
  7372. return $data;
  7373. }
  7374. /**
  7375. * Extract info from a PNG image with alpha channel using the GD library.
  7376. * @param $file (string) Name of the file containing the image.
  7377. * @param $x (float) Abscissa of the upper-left corner.
  7378. * @param $y (float) Ordinate of the upper-left corner.
  7379. * @param $wpx (float) Original width of the image in pixels.
  7380. * @param $hpx (float) original height of the image in pixels.
  7381. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  7382. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  7383. * @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.
  7384. * @param $link (mixed) URL or identifier returned by AddLink().
  7385. * @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>
  7386. * @param $resize (boolean) If true resize (reduce) the image to fit $w and $h (requires GD library).
  7387. * @param $dpi (int) dot-per-inch resolution used on resize
  7388. * @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>
  7389. * @author Nicola Asuni
  7390. * @protected
  7391. * @since 4.3.007 (2008-12-04)
  7392. * @see Image()
  7393. */
  7394. protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign) {
  7395. // create temp image file (without alpha channel)
  7396. $tempfile_plain = tempnam(K_PATH_CACHE, 'mskp_');
  7397. // create temp alpha file
  7398. $tempfile_alpha = tempnam(K_PATH_CACHE, 'mska_');
  7399. if (extension_loaded('imagick')) { // ImageMagick
  7400. // ImageMagick library
  7401. $img = new Imagick();
  7402. $img->readImage($file);
  7403. // clone image object
  7404. $imga = $img->clone();
  7405. // extract alpha channel
  7406. $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE);
  7407. $img->negateImage(true);
  7408. $img->setImageFormat('png');
  7409. $img->writeImage($tempfile_alpha);
  7410. // remove alpha channel
  7411. $imga->separateImageChannel(39); // 39 = (imagick::CHANNEL_ALL & ~(imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE));
  7412. $imga->setImageFormat('png');
  7413. $imga->writeImage($tempfile_plain);
  7414. } else { // GD library
  7415. // generate images
  7416. $img = imagecreatefrompng($file);
  7417. $imgalpha = imagecreate($wpx, $hpx);
  7418. // generate gray scale palette (0 -> 255)
  7419. for ($c = 0; $c < 256; ++$c) {
  7420. ImageColorAllocate($imgalpha, $c, $c, $c);
  7421. }
  7422. // extract alpha channel
  7423. for ($xpx = 0; $xpx < $wpx; ++$xpx) {
  7424. for ($ypx = 0; $ypx < $hpx; ++$ypx) {
  7425. $color = imagecolorat($img, $xpx, $ypx);
  7426. $alpha = ($color >> 24); // shifts off the first 24 bits (where 8x3 are used for each color), and returns the remaining 7 allocated bits (commonly used for alpha)
  7427. $alpha = (((127 - $alpha) / 127) * 255); // GD alpha is only 7 bit (0 -> 127)
  7428. $alpha = $this->getGDgamma($alpha); // correct gamma
  7429. imagesetpixel($imgalpha, $xpx, $ypx, $alpha);
  7430. }
  7431. }
  7432. imagepng($imgalpha, $tempfile_alpha);
  7433. imagedestroy($imgalpha);
  7434. // extract image without alpha channel
  7435. $imgplain = imagecreatetruecolor($wpx, $hpx);
  7436. imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
  7437. imagepng($imgplain, $tempfile_plain);
  7438. imagedestroy($imgplain);
  7439. }
  7440. // embed mask image
  7441. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  7442. // embed image, masked with previously embedded mask
  7443. $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  7444. // remove temp files
  7445. unlink($tempfile_alpha);
  7446. unlink($tempfile_plain);
  7447. }
  7448. /**
  7449. * Correct the gamma value to be used with GD library
  7450. * @param $v (float) the gamma value to be corrected
  7451. * @protected
  7452. * @since 4.3.007 (2008-12-04)
  7453. */
  7454. protected function getGDgamma($v) {
  7455. return (pow(($v / 255), 2.2) * 255);
  7456. }
  7457. /**
  7458. * Performs a line break.
  7459. * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  7460. * @param $h (float) The height of the break. By default, the value equals the height of the last printed cell.
  7461. * @param $cell (boolean) if true add the current left (or right o for RTL) padding to the X coordinate
  7462. * @public
  7463. * @since 1.0
  7464. * @see Cell()
  7465. */
  7466. public function Ln($h='', $cell=false) {
  7467. 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'])) {
  7468. // revove vertical space from the top of the column
  7469. return;
  7470. }
  7471. if ($cell) {
  7472. if ($this->rtl) {
  7473. $cellpadding = $this->cell_padding['R'];
  7474. } else {
  7475. $cellpadding = $this->cell_padding['L'];
  7476. }
  7477. } else {
  7478. $cellpadding = 0;
  7479. }
  7480. if ($this->rtl) {
  7481. $this->x = $this->w - $this->rMargin - $cellpadding;
  7482. } else {
  7483. $this->x = $this->lMargin + $cellpadding;
  7484. }
  7485. if (is_string($h)) {
  7486. $this->y += $this->lasth;
  7487. } else {
  7488. $this->y += $h;
  7489. }
  7490. $this->newline = true;
  7491. }
  7492. /**
  7493. * Returns the relative X value of current position.
  7494. * The value is relative to the left border for LTR languages and to the right border for RTL languages.
  7495. * @return float
  7496. * @public
  7497. * @since 1.2
  7498. * @see SetX(), GetY(), SetY()
  7499. */
  7500. public function GetX() {
  7501. //Get x position
  7502. if ($this->rtl) {
  7503. return ($this->w - $this->x);
  7504. } else {
  7505. return $this->x;
  7506. }
  7507. }
  7508. /**
  7509. * Returns the absolute X value of current position.
  7510. * @return float
  7511. * @public
  7512. * @since 1.2
  7513. * @see SetX(), GetY(), SetY()
  7514. */
  7515. public function GetAbsX() {
  7516. return $this->x;
  7517. }
  7518. /**
  7519. * Returns the ordinate of the current position.
  7520. * @return float
  7521. * @public
  7522. * @since 1.0
  7523. * @see SetY(), GetX(), SetX()
  7524. */
  7525. public function GetY() {
  7526. return $this->y;
  7527. }
  7528. /**
  7529. * Defines the abscissa of the current position.
  7530. * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
  7531. * @param $x (float) The value of the abscissa.
  7532. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  7533. * @public
  7534. * @since 1.2
  7535. * @see GetX(), GetY(), SetY(), SetXY()
  7536. */
  7537. public function SetX($x, $rtloff=false) {
  7538. if (!$rtloff AND $this->rtl) {
  7539. if ($x >= 0) {
  7540. $this->x = $this->w - $x;
  7541. } else {
  7542. $this->x = abs($x);
  7543. }
  7544. } else {
  7545. if ($x >= 0) {
  7546. $this->x = $x;
  7547. } else {
  7548. $this->x = $this->w + $x;
  7549. }
  7550. }
  7551. if ($this->x < 0) {
  7552. $this->x = 0;
  7553. }
  7554. if ($this->x > $this->w) {
  7555. $this->x = $this->w;
  7556. }
  7557. }
  7558. /**
  7559. * Moves the current abscissa back to the left margin and sets the ordinate.
  7560. * If the passed value is negative, it is relative to the bottom of the page.
  7561. * @param $y (float) The value of the ordinate.
  7562. * @param $resetx (bool) if true (default) reset the X position.
  7563. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  7564. * @public
  7565. * @since 1.0
  7566. * @see GetX(), GetY(), SetY(), SetXY()
  7567. */
  7568. public function SetY($y, $resetx=true, $rtloff=false) {
  7569. if ($resetx) {
  7570. //reset x
  7571. if (!$rtloff AND $this->rtl) {
  7572. $this->x = $this->w - $this->rMargin;
  7573. } else {
  7574. $this->x = $this->lMargin;
  7575. }
  7576. }
  7577. if ($y >= 0) {
  7578. $this->y = $y;
  7579. } else {
  7580. $this->y = $this->h + $y;
  7581. }
  7582. if ($this->y < 0) {
  7583. $this->y = 0;
  7584. }
  7585. if ($this->y > $this->h) {
  7586. $this->y = $this->h;
  7587. }
  7588. }
  7589. /**
  7590. * Defines the abscissa and ordinate of the current position.
  7591. * If the passed values are negative, they are relative respectively to the right and bottom of the page.
  7592. * @param $x (float) The value of the abscissa.
  7593. * @param $y (float) The value of the ordinate.
  7594. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  7595. * @public
  7596. * @since 1.2
  7597. * @see SetX(), SetY()
  7598. */
  7599. public function SetXY($x, $y, $rtloff=false) {
  7600. $this->SetY($y, false, $rtloff);
  7601. $this->SetX($x, $rtloff);
  7602. }
  7603. /**
  7604. * Send the document to a given destination: string, local file or browser.
  7605. * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  7606. * The method first calls Close() if necessary to terminate the document.
  7607. * @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.
  7608. * @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>
  7609. * @public
  7610. * @since 1.0
  7611. * @see Close()
  7612. */
  7613. public function Output($name='doc.pdf', $dest='I') {
  7614. //Output PDF to some destination
  7615. //Finish document if necessary
  7616. if ($this->state < 3) {
  7617. $this->Close();
  7618. }
  7619. //Normalize parameters
  7620. if (is_bool($dest)) {
  7621. $dest = $dest ? 'D' : 'F';
  7622. }
  7623. $dest = strtoupper($dest);
  7624. if ($dest{0} != 'F') {
  7625. $name = preg_replace('/[\s]+/', '_', $name);
  7626. $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name);
  7627. }
  7628. if ($this->sign) {
  7629. // *** apply digital signature to the document ***
  7630. // get the document content
  7631. $pdfdoc = $this->getBuffer();
  7632. // remove last newline
  7633. $pdfdoc = substr($pdfdoc, 0, -1);
  7634. // Remove the original buffer
  7635. if (isset($this->diskcache) AND $this->diskcache) {
  7636. // remove buffer file from cache
  7637. unlink($this->buffer);
  7638. }
  7639. unset($this->buffer);
  7640. // remove filler space
  7641. $byterange_string_len = strlen($this->byterange_string);
  7642. // define the ByteRange
  7643. $byte_range = array();
  7644. $byte_range[0] = 0;
  7645. $byte_range[1] = strpos($pdfdoc, $this->byterange_string) + $byterange_string_len + 10;
  7646. $byte_range[2] = $byte_range[1] + $this->signature_max_length + 2;
  7647. $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
  7648. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).substr($pdfdoc, $byte_range[2]);
  7649. // replace the ByteRange
  7650. $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]);
  7651. $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
  7652. $pdfdoc = str_replace($this->byterange_string, $byterange, $pdfdoc);
  7653. // write the document to a temporary folder
  7654. $tempdoc = tempnam(K_PATH_CACHE, 'tmppdf_');
  7655. $f = fopen($tempdoc, 'wb');
  7656. if (!$f) {
  7657. $this->Error('Unable to create temporary file: '.$tempdoc);
  7658. }
  7659. $pdfdoc_length = strlen($pdfdoc);
  7660. fwrite($f, $pdfdoc, $pdfdoc_length);
  7661. fclose($f);
  7662. // get digital signature via openssl library
  7663. $tempsign = tempnam(K_PATH_CACHE, 'tmpsig_');
  7664. if (empty($this->signature_data['extracerts'])) {
  7665. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED);
  7666. } else {
  7667. 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']);
  7668. }
  7669. unlink($tempdoc);
  7670. // read signature
  7671. $signature = file_get_contents($tempsign);
  7672. unlink($tempsign);
  7673. // extract signature
  7674. $signature = substr($signature, $pdfdoc_length);
  7675. $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13));
  7676. $tmparr = explode("\n\n", $signature);
  7677. $signature = $tmparr[1];
  7678. unset($tmparr);
  7679. // decode signature
  7680. $signature = base64_decode(trim($signature));
  7681. // convert signature to hex
  7682. $signature = current(unpack('H*', $signature));
  7683. $signature = str_pad($signature, $this->signature_max_length, '0');
  7684. // Add signature to the document
  7685. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).'<'.$signature.'>'.substr($pdfdoc, $byte_range[1]);
  7686. $this->diskcache = false;
  7687. $this->buffer = &$pdfdoc;
  7688. $this->bufferlen = strlen($pdfdoc);
  7689. }
  7690. switch($dest) {
  7691. case 'I': {
  7692. // Send PDF to the standard output
  7693. if (ob_get_contents()) {
  7694. $this->Error('Some data has already been output, can\'t send PDF file');
  7695. }
  7696. if (php_sapi_name() != 'cli') {
  7697. //We send to a browser
  7698. header('Content-Type: application/pdf');
  7699. if (headers_sent()) {
  7700. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7701. }
  7702. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7703. header('Pragma: public');
  7704. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7705. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7706. header('Content-Length: '.$this->bufferlen);
  7707. header('Content-Disposition: inline; filename="'.basename($name).'";');
  7708. }
  7709. echo $this->getBuffer();
  7710. break;
  7711. }
  7712. case 'D': {
  7713. // Download PDF as file
  7714. if (ob_get_contents()) {
  7715. $this->Error('Some data has already been output, can\'t send PDF file');
  7716. }
  7717. header('Content-Description: File Transfer');
  7718. if (headers_sent()) {
  7719. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7720. }
  7721. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7722. header('Pragma: public');
  7723. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7724. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7725. // force download dialog
  7726. if (strpos(php_sapi_name(), 'cgi') === false) {
  7727. header('Content-Type: application/force-download');
  7728. header('Content-Type: application/octet-stream', false);
  7729. header('Content-Type: application/download', false);
  7730. header('Content-Type: application/pdf', false);
  7731. } else {
  7732. header('Content-Type: application/pdf');
  7733. }
  7734. // use the Content-Disposition header to supply a recommended filename
  7735. header('Content-Disposition: attachment; filename="'.basename($name).'";');
  7736. header('Content-Transfer-Encoding: binary');
  7737. header('Content-Length: '.$this->bufferlen);
  7738. echo $this->getBuffer();
  7739. break;
  7740. }
  7741. case 'F':
  7742. case 'FI':
  7743. case 'FD': {
  7744. // Save PDF to a local file
  7745. if ($this->diskcache) {
  7746. copy($this->buffer, $name);
  7747. } else {
  7748. $f = fopen($name, 'wb');
  7749. if (!$f) {
  7750. $this->Error('Unable to create output file: '.$name);
  7751. }
  7752. fwrite($f, $this->getBuffer(), $this->bufferlen);
  7753. fclose($f);
  7754. }
  7755. if ($dest == 'FI') {
  7756. // send headers to browser
  7757. header('Content-Type: application/pdf');
  7758. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7759. header('Pragma: public');
  7760. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7761. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7762. header('Content-Length: '.filesize($name));
  7763. header('Content-Disposition: inline; filename="'.basename($name).'";');
  7764. // send document to the browser
  7765. echo file_get_contents($name);
  7766. } elseif ($dest == 'FD') {
  7767. // send headers to browser
  7768. if (ob_get_contents()) {
  7769. $this->Error('Some data has already been output, can\'t send PDF file');
  7770. }
  7771. header('Content-Description: File Transfer');
  7772. if (headers_sent()) {
  7773. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7774. }
  7775. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7776. header('Pragma: public');
  7777. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7778. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7779. // force download dialog
  7780. if (strpos(php_sapi_name(), 'cgi') === false) {
  7781. header('Content-Type: application/force-download');
  7782. header('Content-Type: application/octet-stream', false);
  7783. header('Content-Type: application/download', false);
  7784. header('Content-Type: application/pdf', false);
  7785. } else {
  7786. header('Content-Type: application/pdf');
  7787. }
  7788. // use the Content-Disposition header to supply a recommended filename
  7789. header('Content-Disposition: attachment; filename="'.basename($name).'";');
  7790. header('Content-Transfer-Encoding: binary');
  7791. header('Content-Length: '.filesize($name));
  7792. // send document to the browser
  7793. echo file_get_contents($name);
  7794. }
  7795. break;
  7796. }
  7797. case 'E': {
  7798. // Return PDF as base64 mime multi-part email attachment (RFC 2045)
  7799. $retval = 'Content-Type: application/pdf;'."\r\n";
  7800. $retval .= ' name="'.$name.'"'."\r\n";
  7801. $retval .= 'Content-Transfer-Encoding: base64'."\r\n";
  7802. $retval .= 'Content-Disposition: attachment;'."\r\n";
  7803. $retval .= ' filename="'.$name.'"'."\r\n\r\n";
  7804. $retval .= chunk_split(base64_encode($this->getBuffer()), 76, "\r\n");
  7805. return $retval;
  7806. }
  7807. case 'S': {
  7808. // Returns PDF as a string
  7809. return $this->getBuffer();
  7810. }
  7811. default: {
  7812. $this->Error('Incorrect output destination: '.$dest);
  7813. }
  7814. }
  7815. return '';
  7816. }
  7817. /**
  7818. * Unset all class variables except the following critical variables: internal_encoding, state, bufferlen, buffer and diskcache.
  7819. * @param $destroyall (boolean) if true destroys all class variables, otherwise preserves critical variables.
  7820. * @param $preserve_objcopy (boolean) if true preserves the objcopy variable
  7821. * @public
  7822. * @since 4.5.016 (2009-02-24)
  7823. */
  7824. public function _destroy($destroyall=false, $preserve_objcopy=false) {
  7825. if ($destroyall AND isset($this->diskcache) AND $this->diskcache AND (!$preserve_objcopy) AND (!$this->empty_string($this->buffer))) {
  7826. // remove buffer file from cache
  7827. unlink($this->buffer);
  7828. }
  7829. foreach (array_keys(get_object_vars($this)) as $val) {
  7830. if ($destroyall OR (
  7831. ($val != 'internal_encoding')
  7832. AND ($val != 'state')
  7833. AND ($val != 'bufferlen')
  7834. AND ($val != 'buffer')
  7835. AND ($val != 'diskcache')
  7836. AND ($val != 'sign')
  7837. AND ($val != 'signature_data')
  7838. AND ($val != 'signature_max_length')
  7839. AND ($val != 'byterange_string')
  7840. )) {
  7841. if ((!$preserve_objcopy OR ($val != 'objcopy')) AND isset($this->$val)) {
  7842. unset($this->$val);
  7843. }
  7844. }
  7845. }
  7846. }
  7847. /**
  7848. * Check for locale-related bug
  7849. * @protected
  7850. */
  7851. protected function _dochecks() {
  7852. //Check for locale-related bug
  7853. if (1.1 == 1) {
  7854. $this->Error('Don\'t alter the locale before including class file');
  7855. }
  7856. //Check for decimal separator
  7857. if (sprintf('%.1F', 1.0) != '1.0') {
  7858. setlocale(LC_NUMERIC, 'C');
  7859. }
  7860. }
  7861. /**
  7862. * Return fonts path
  7863. * @return string
  7864. * @protected
  7865. */
  7866. protected function _getfontpath() {
  7867. if (!defined('K_PATH_FONTS') AND is_dir(dirname(__FILE__).'/fonts')) {
  7868. define('K_PATH_FONTS', dirname(__FILE__).'/fonts/');
  7869. }
  7870. return defined('K_PATH_FONTS') ? K_PATH_FONTS : '';
  7871. }
  7872. /**
  7873. * Output pages.
  7874. * @protected
  7875. */
  7876. protected function _putpages() {
  7877. $nb = $this->numpages;
  7878. if (!empty($this->AliasNbPages)) {
  7879. $nbs = $this->formatPageNumber($nb);
  7880. $nbu = $this->UTF8ToUTF16BE($nbs, false); // replacement for unicode font
  7881. $alias_a = $this->_escape($this->AliasNbPages);
  7882. $alias_au = $this->_escape('{'.$this->AliasNbPages.'}');
  7883. if ($this->isunicode) {
  7884. $alias_b = $this->_escape($this->UTF8ToLatin1($this->AliasNbPages));
  7885. $alias_bu = $this->_escape($this->UTF8ToLatin1('{'.$this->AliasNbPages.'}'));
  7886. $alias_c = $this->_escape($this->utf8StrRev($this->AliasNbPages, false, $this->tmprtl));
  7887. $alias_cu = $this->_escape($this->utf8StrRev('{'.$this->AliasNbPages.'}', false, $this->tmprtl));
  7888. }
  7889. }
  7890. if (!empty($this->AliasNumPage)) {
  7891. $alias_pa = $this->_escape($this->AliasNumPage);
  7892. $alias_pau = $this->_escape('{'.$this->AliasNumPage.'}');
  7893. if ($this->isunicode) {
  7894. $alias_pb = $this->_escape($this->UTF8ToLatin1($this->AliasNumPage));
  7895. $alias_pbu = $this->_escape($this->UTF8ToLatin1('{'.$this->AliasNumPage.'}'));
  7896. $alias_pc = $this->_escape($this->utf8StrRev($this->AliasNumPage, false, $this->tmprtl));
  7897. $alias_pcu = $this->_escape($this->utf8StrRev('{'.$this->AliasNumPage.'}', false, $this->tmprtl));
  7898. }
  7899. }
  7900. $pagegroupnum = 0;
  7901. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  7902. for ($n=1; $n <= $nb; ++$n) {
  7903. $temppage = $this->getPageBuffer($n);
  7904. if (!empty($this->pagegroups)) {
  7905. if(isset($this->newpagegroup[$n])) {
  7906. $pagegroupnum = 0;
  7907. }
  7908. ++$pagegroupnum;
  7909. foreach ($this->pagegroups as $k => $v) {
  7910. // replace total pages group numbers
  7911. $vs = $this->formatPageNumber($v);
  7912. $vu = $this->UTF8ToUTF16BE($vs, false);
  7913. $alias_ga = $this->_escape($k);
  7914. $alias_gau = $this->_escape('{'.$k.'}');
  7915. if ($this->isunicode) {
  7916. $alias_gb = $this->_escape($this->UTF8ToLatin1($k));
  7917. $alias_gbu = $this->_escape($this->UTF8ToLatin1('{'.$k.'}'));
  7918. $alias_gc = $this->_escape($this->utf8StrRev($k, false, $this->tmprtl));
  7919. $alias_gcu = $this->_escape($this->utf8StrRev('{'.$k.'}', false, $this->tmprtl));
  7920. }
  7921. $temppage = str_replace($alias_gau, $vu, $temppage);
  7922. if ($this->isunicode) {
  7923. $temppage = str_replace($alias_gbu, $vu, $temppage);
  7924. $temppage = str_replace($alias_gcu, $vu, $temppage);
  7925. $temppage = str_replace($alias_gb, $vs, $temppage);
  7926. $temppage = str_replace($alias_gc, $vs, $temppage);
  7927. }
  7928. $temppage = str_replace($alias_ga, $vs, $temppage);
  7929. // replace page group numbers
  7930. $pvs = $this->formatPageNumber($pagegroupnum);
  7931. $pvu = $this->UTF8ToUTF16BE($pvs, false);
  7932. $pk = str_replace('{nb', '{pnb', $k);
  7933. $alias_pga = $this->_escape($pk);
  7934. $alias_pgau = $this->_escape('{'.$pk.'}');
  7935. if ($this->isunicode) {
  7936. $alias_pgb = $this->_escape($this->UTF8ToLatin1($pk));
  7937. $alias_pgbu = $this->_escape($this->UTF8ToLatin1('{'.$pk.'}'));
  7938. $alias_pgc = $this->_escape($this->utf8StrRev($pk, false, $this->tmprtl));
  7939. $alias_pgcu = $this->_escape($this->utf8StrRev('{'.$pk.'}', false, $this->tmprtl));
  7940. }
  7941. $temppage = str_replace($alias_pgau, $pvu, $temppage);
  7942. if ($this->isunicode) {
  7943. $temppage = str_replace($alias_pgbu, $pvu, $temppage);
  7944. $temppage = str_replace($alias_pgcu, $pvu, $temppage);
  7945. $temppage = str_replace($alias_pgb, $pvs, $temppage);
  7946. $temppage = str_replace($alias_pgc, $pvs, $temppage);
  7947. }
  7948. $temppage = str_replace($alias_pga, $pvs, $temppage);
  7949. }
  7950. }
  7951. if (!empty($this->AliasNbPages)) {
  7952. // replace total pages number
  7953. $temppage = str_replace($alias_au, $nbu, $temppage);
  7954. if ($this->isunicode) {
  7955. $temppage = str_replace($alias_bu, $nbu, $temppage);
  7956. $temppage = str_replace($alias_cu, $nbu, $temppage);
  7957. $temppage = str_replace($alias_b, $nbs, $temppage);
  7958. $temppage = str_replace($alias_c, $nbs, $temppage);
  7959. }
  7960. $temppage = str_replace($alias_a, $nbs, $temppage);
  7961. }
  7962. if (!empty($this->AliasNumPage)) {
  7963. // replace page number
  7964. $pnbs = $this->formatPageNumber($n);
  7965. $pnbu = $this->UTF8ToUTF16BE($pnbs, false); // replacement for unicode font
  7966. $temppage = str_replace($alias_pau, $pnbu, $temppage);
  7967. if ($this->isunicode) {
  7968. $temppage = str_replace($alias_pbu, $pnbu, $temppage);
  7969. $temppage = str_replace($alias_pcu, $pnbu, $temppage);
  7970. $temppage = str_replace($alias_pb, $pnbs, $temppage);
  7971. $temppage = str_replace($alias_pc, $pnbs, $temppage);
  7972. }
  7973. $temppage = str_replace($alias_pa, $pnbs, $temppage);
  7974. }
  7975. $temppage = str_replace($this->epsmarker, '', $temppage);
  7976. //Page
  7977. $this->page_obj_id[$n] = $this->_newobj();
  7978. $out = '<<';
  7979. $out .= ' /Type /Page';
  7980. $out .= ' /Parent 1 0 R';
  7981. $out .= ' /LastModified '.$this->_datestring();
  7982. $out .= ' /Resources 2 0 R';
  7983. $boxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  7984. foreach ($boxes as $box) {
  7985. $out .= ' /'.$box;
  7986. $out .= sprintf(' [%.2F %.2F %.2F %.2F]', $this->pagedim[$n][$box]['llx'], $this->pagedim[$n][$box]['lly'], $this->pagedim[$n][$box]['urx'], $this->pagedim[$n][$box]['ury']);
  7987. }
  7988. if (isset($this->pagedim[$n]['BoxColorInfo']) AND !empty($this->pagedim[$n]['BoxColorInfo'])) {
  7989. $out .= ' /BoxColorInfo <<';
  7990. foreach ($boxes as $box) {
  7991. if (isset($this->pagedim[$n]['BoxColorInfo'][$box])) {
  7992. $out .= ' /'.$box.' <<';
  7993. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['C'])) {
  7994. $color = $this->pagedim[$n]['BoxColorInfo'][$box]['C'];
  7995. $out .= ' /C [';
  7996. $out .= sprintf(' %.3F %.3F %.3F', $color[0]/255, $color[1]/255, $color[2]/255);
  7997. $out .= ' ]';
  7998. }
  7999. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['W'])) {
  8000. $out .= ' /W '.($this->pagedim[$n]['BoxColorInfo'][$box]['W'] * $this->k);
  8001. }
  8002. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['S'])) {
  8003. $out .= ' /S /'.$this->pagedim[$n]['BoxColorInfo'][$box]['S'];
  8004. }
  8005. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['D'])) {
  8006. $dashes = $this->pagedim[$n]['BoxColorInfo'][$box]['D'];
  8007. $out .= ' /D [';
  8008. foreach ($dashes as $dash) {
  8009. $out .= sprintf(' %.3F', ($dash * $this->k));
  8010. }
  8011. $out .= ' ]';
  8012. }
  8013. $out .= ' >>';
  8014. }
  8015. }
  8016. $out .= ' >>';
  8017. }
  8018. $out .= ' /Contents '.($this->n + 1).' 0 R';
  8019. $out .= ' /Rotate '.$this->pagedim[$n]['Rotate'];
  8020. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceRGB >>';
  8021. if (isset($this->pagedim[$n]['trans']) AND !empty($this->pagedim[$n]['trans'])) {
  8022. // page transitions
  8023. if (isset($this->pagedim[$n]['trans']['Dur'])) {
  8024. $out .= ' /Dur '.$this->pagedim[$n]['trans']['Dur'];
  8025. }
  8026. $out .= ' /Trans <<';
  8027. $out .= ' /Type /Trans';
  8028. if (isset($this->pagedim[$n]['trans']['S'])) {
  8029. $out .= ' /S /'.$this->pagedim[$n]['trans']['S'];
  8030. }
  8031. if (isset($this->pagedim[$n]['trans']['D'])) {
  8032. $out .= ' /D '.$this->pagedim[$n]['trans']['D'];
  8033. }
  8034. if (isset($this->pagedim[$n]['trans']['Dm'])) {
  8035. $out .= ' /Dm /'.$this->pagedim[$n]['trans']['Dm'];
  8036. }
  8037. if (isset($this->pagedim[$n]['trans']['M'])) {
  8038. $out .= ' /M /'.$this->pagedim[$n]['trans']['M'];
  8039. }
  8040. if (isset($this->pagedim[$n]['trans']['Di'])) {
  8041. $out .= ' /Di '.$this->pagedim[$n]['trans']['Di'];
  8042. }
  8043. if (isset($this->pagedim[$n]['trans']['SS'])) {
  8044. $out .= ' /SS '.$this->pagedim[$n]['trans']['SS'];
  8045. }
  8046. if (isset($this->pagedim[$n]['trans']['B'])) {
  8047. $out .= ' /B '.$this->pagedim[$n]['trans']['B'];
  8048. }
  8049. $out .= ' >>';
  8050. }
  8051. $out .= $this->_getannotsrefs($n);
  8052. $out .= ' /PZ '.$this->pagedim[$n]['PZ'];
  8053. $out .= ' >>';
  8054. $out .= "\n".'endobj';
  8055. $this->_out($out);
  8056. //Page content
  8057. $p = ($this->compress) ? gzcompress($temppage) : $temppage;
  8058. $this->_newobj();
  8059. $p = $this->_getrawstream($p);
  8060. $this->_out('<<'.$filter.'/Length '.strlen($p).'>> stream'."\n".$p."\n".'endstream'."\n".'endobj');
  8061. if ($this->diskcache) {
  8062. // remove temporary files
  8063. unlink($this->pages[$n]);
  8064. }
  8065. }
  8066. //Pages root
  8067. $out = $this->_getobj(1)."\n";
  8068. $out .= '<< /Type /Pages /Kids [';
  8069. foreach($this->page_obj_id as $page_obj) {
  8070. $out .= ' '.$page_obj.' 0 R';
  8071. }
  8072. $out .= ' ] /Count '.$nb.' >>';
  8073. $out .= "\n".'endobj';
  8074. $this->_out($out);
  8075. }
  8076. /**
  8077. * Output references to page annotations
  8078. * @param $n (int) page number
  8079. * @protected
  8080. * @author Nicola Asuni
  8081. * @since 4.7.000 (2008-08-29)
  8082. * @deprecated
  8083. */
  8084. protected function _putannotsrefs($n) {
  8085. $this->_out($this->_getannotsrefs($n));
  8086. }
  8087. /**
  8088. * Get references to page annotations.
  8089. * @param $n (int) page number
  8090. * @return string
  8091. * @protected
  8092. * @author Nicola Asuni
  8093. * @since 5.0.010 (2010-05-17)
  8094. */
  8095. protected function _getannotsrefs($n) {
  8096. if (!(isset($this->PageAnnots[$n]) OR ($this->sign AND isset($this->signature_data['cert_type'])))) {
  8097. return '';
  8098. }
  8099. $out = ' /Annots [';
  8100. if (isset($this->PageAnnots[$n])) {
  8101. foreach ($this->PageAnnots[$n] as $key => $val) {
  8102. if (!in_array($val['n'], $this->radio_groups)) {
  8103. $out .= ' '.$val['n'].' 0 R';
  8104. }
  8105. }
  8106. // add radiobutton groups
  8107. if (isset($this->radiobutton_groups[$n])) {
  8108. foreach ($this->radiobutton_groups[$n] as $key => $data) {
  8109. if (isset($data['n'])) {
  8110. $out .= ' '.$data['n'].' 0 R';
  8111. }
  8112. }
  8113. }
  8114. }
  8115. if ($this->sign AND ($n == $this->signature_appearance['page']) AND isset($this->signature_data['cert_type'])) {
  8116. // set reference for signature object
  8117. $out .= ' '.$this->sig_obj_id.' 0 R';
  8118. }
  8119. $out .= ' ]';
  8120. return $out;
  8121. }
  8122. /**
  8123. * Output annotations objects for all pages.
  8124. * !!! THIS METHOD IS NOT YET COMPLETED !!!
  8125. * See section 12.5 of PDF 32000_2008 reference.
  8126. * @protected
  8127. * @author Nicola Asuni
  8128. * @since 4.0.018 (2008-08-06)
  8129. */
  8130. protected function _putannotsobjs() {
  8131. // reset object counter
  8132. for ($n=1; $n <= $this->numpages; ++$n) {
  8133. if (isset($this->PageAnnots[$n])) {
  8134. // set page annotations
  8135. foreach ($this->PageAnnots[$n] as $key => $pl) {
  8136. $annot_obj_id = $this->PageAnnots[$n][$key]['n'];
  8137. // create annotation object for grouping radiobuttons
  8138. if (isset($this->radiobutton_groups[$n][$pl['txt']]) AND is_array($this->radiobutton_groups[$n][$pl['txt']])) {
  8139. $radio_button_obj_id = $this->radiobutton_groups[$n][$pl['txt']]['n'];
  8140. $annots = '<<';
  8141. $annots .= ' /Type /Annot';
  8142. $annots .= ' /Subtype /Widget';
  8143. $annots .= ' /Rect [0 0 0 0]';
  8144. $annots .= ' /T '.$this->_datastring($pl['txt'], $radio_button_obj_id);
  8145. $annots .= ' /FT /Btn';
  8146. $annots .= ' /Ff 49152';
  8147. $annots .= ' /Kids [';
  8148. foreach ($this->radiobutton_groups[$n][$pl['txt']] as $key => $data) {
  8149. if ($key !== 'n') {
  8150. $annots .= ' '.$data['kid'].' 0 R';
  8151. if ($data['def'] !== 'Off') {
  8152. $defval = $data['def'];
  8153. }
  8154. }
  8155. }
  8156. $annots .= ' ]';
  8157. if (isset($defval)) {
  8158. $annots .= ' /V /'.$defval;
  8159. }
  8160. $annots .= ' >>';
  8161. $this->_out($this->_getobj($radio_button_obj_id)."\n".$annots."\n".'endobj');
  8162. $this->form_obj_id[] = $radio_button_obj_id;
  8163. // store object id to be used on Parent entry of Kids
  8164. $this->radiobutton_groups[$n][$pl['txt']] = $radio_button_obj_id;
  8165. }
  8166. $formfield = false;
  8167. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  8168. $a = $pl['x'] * $this->k;
  8169. $b = $this->pagedim[$n]['h'] - (($pl['y'] + $pl['h']) * $this->k);
  8170. $c = $pl['w'] * $this->k;
  8171. $d = $pl['h'] * $this->k;
  8172. $rect = sprintf('%.2F %.2F %.2F %.2F', $a, $b, $a+$c, $b+$d);
  8173. // create new annotation object
  8174. $annots = '<</Type /Annot';
  8175. $annots .= ' /Subtype /'.$pl['opt']['subtype'];
  8176. $annots .= ' /Rect ['.$rect.']';
  8177. $ft = array('Btn', 'Tx', 'Ch', 'Sig');
  8178. if (isset($pl['opt']['ft']) AND in_array($pl['opt']['ft'], $ft)) {
  8179. $annots .= ' /FT /'.$pl['opt']['ft'];
  8180. $formfield = true;
  8181. }
  8182. $annots .= ' /Contents '.$this->_textstring($pl['txt'], $annot_obj_id);
  8183. $annots .= ' /P '.$this->page_obj_id[$n].' 0 R';
  8184. $annots .= ' /NM '.$this->_datastring(sprintf('%04u-%04u', $n, $key), $annot_obj_id);
  8185. $annots .= ' /M '.$this->_datestring($annot_obj_id);
  8186. if (isset($pl['opt']['f'])) {
  8187. $val = 0;
  8188. if (is_array($pl['opt']['f'])) {
  8189. foreach ($pl['opt']['f'] as $f) {
  8190. switch (strtolower($f)) {
  8191. case 'invisible': {
  8192. $val += 1 << 0;
  8193. break;
  8194. }
  8195. case 'hidden': {
  8196. $val += 1 << 1;
  8197. break;
  8198. }
  8199. case 'print': {
  8200. $val += 1 << 2;
  8201. break;
  8202. }
  8203. case 'nozoom': {
  8204. $val += 1 << 3;
  8205. break;
  8206. }
  8207. case 'norotate': {
  8208. $val += 1 << 4;
  8209. break;
  8210. }
  8211. case 'noview': {
  8212. $val += 1 << 5;
  8213. break;
  8214. }
  8215. case 'readonly': {
  8216. $val += 1 << 6;
  8217. break;
  8218. }
  8219. case 'locked': {
  8220. $val += 1 << 8;
  8221. break;
  8222. }
  8223. case 'togglenoview': {
  8224. $val += 1 << 9;
  8225. break;
  8226. }
  8227. case 'lockedcontents': {
  8228. $val += 1 << 10;
  8229. break;
  8230. }
  8231. default: {
  8232. break;
  8233. }
  8234. }
  8235. }
  8236. } else {
  8237. $val = intval($pl['opt']['f']);
  8238. }
  8239. $annots .= ' /F '.intval($val);
  8240. }
  8241. if (isset($pl['opt']['as']) AND is_string($pl['opt']['as'])) {
  8242. $annots .= ' /AS /'.$pl['opt']['as'];
  8243. }
  8244. if (isset($pl['opt']['ap'])) {
  8245. // appearance stream
  8246. $annots .= ' /AP <<';
  8247. if (is_array($pl['opt']['ap'])) {
  8248. foreach ($pl['opt']['ap'] as $apmode => $apdef) {
  8249. // $apmode can be: n = normal; r = rollover; d = down;
  8250. $annots .= ' /'.strtoupper($apmode);
  8251. if (is_array($apdef)) {
  8252. $annots .= ' <<';
  8253. foreach ($apdef as $apstate => $stream) {
  8254. // reference to XObject that define the appearance for this mode-state
  8255. $apsobjid = $this->_putAPXObject($c, $d, $stream);
  8256. $annots .= ' /'.$apstate.' '.$apsobjid.' 0 R';
  8257. }
  8258. $annots .= ' >>';
  8259. } else {
  8260. // reference to XObject that define the appearance for this mode
  8261. $apsobjid = $this->_putAPXObject($c, $d, $apdef);
  8262. $annots .= ' '.$apsobjid.' 0 R';
  8263. }
  8264. }
  8265. } else {
  8266. $annots .= $pl['opt']['ap'];
  8267. }
  8268. $annots .= ' >>';
  8269. }
  8270. if (isset($pl['opt']['bs']) AND (is_array($pl['opt']['bs']))) {
  8271. $annots .= ' /BS <<';
  8272. $annots .= ' /Type /Border';
  8273. if (isset($pl['opt']['bs']['w'])) {
  8274. $annots .= ' /W '.intval($pl['opt']['bs']['w']);
  8275. }
  8276. $bstyles = array('S', 'D', 'B', 'I', 'U');
  8277. if (isset($pl['opt']['bs']['s']) AND in_array($pl['opt']['bs']['s'], $bstyles)) {
  8278. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  8279. }
  8280. if (isset($pl['opt']['bs']['d']) AND (is_array($pl['opt']['bs']['d']))) {
  8281. $annots .= ' /D [';
  8282. foreach ($pl['opt']['bs']['d'] as $cord) {
  8283. $annots .= ' '.intval($cord);
  8284. }
  8285. $annots .= ']';
  8286. }
  8287. $annots .= ' >>';
  8288. } else {
  8289. $annots .= ' /Border [';
  8290. if (isset($pl['opt']['border']) AND (count($pl['opt']['border']) >= 3)) {
  8291. $annots .= intval($pl['opt']['border'][0]).' ';
  8292. $annots .= intval($pl['opt']['border'][1]).' ';
  8293. $annots .= intval($pl['opt']['border'][2]);
  8294. if (isset($pl['opt']['border'][3]) AND is_array($pl['opt']['border'][3])) {
  8295. $annots .= ' [';
  8296. foreach ($pl['opt']['border'][3] as $dash) {
  8297. $annots .= intval($dash).' ';
  8298. }
  8299. $annots .= ']';
  8300. }
  8301. } else {
  8302. $annots .= '0 0 0';
  8303. }
  8304. $annots .= ']';
  8305. }
  8306. if (isset($pl['opt']['be']) AND (is_array($pl['opt']['be']))) {
  8307. $annots .= ' /BE <<';
  8308. $bstyles = array('S', 'C');
  8309. if (isset($pl['opt']['be']['s']) AND in_array($pl['opt']['be']['s'], $markups)) {
  8310. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  8311. } else {
  8312. $annots .= ' /S /S';
  8313. }
  8314. if (isset($pl['opt']['be']['i']) AND ($pl['opt']['be']['i'] >= 0) AND ($pl['opt']['be']['i'] <= 2)) {
  8315. $annots .= ' /I '.sprintf(' %.4F', $pl['opt']['be']['i']);
  8316. }
  8317. $annots .= '>>';
  8318. }
  8319. if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) {
  8320. $annots .= ' /C [';
  8321. foreach ($pl['opt']['c'] as $col) {
  8322. $col = intval($col);
  8323. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  8324. $annots .= sprintf(' %.4F', $color);
  8325. }
  8326. $annots .= ']';
  8327. }
  8328. //$annots .= ' /StructParent ';
  8329. //$annots .= ' /OC ';
  8330. $markups = array('text', 'freetext', 'line', 'square', 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp', 'caret', 'ink', 'fileattachment', 'sound');
  8331. if (in_array(strtolower($pl['opt']['subtype']), $markups)) {
  8332. // this is a markup type
  8333. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  8334. $annots .= ' /T '.$this->_textstring($pl['opt']['t'], $annot_obj_id);
  8335. }
  8336. //$annots .= ' /Popup ';
  8337. if (isset($pl['opt']['ca'])) {
  8338. $annots .= ' /CA '.sprintf('%.4F', floatval($pl['opt']['ca']));
  8339. }
  8340. if (isset($pl['opt']['rc'])) {
  8341. $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  8342. }
  8343. $annots .= ' /CreationDate '.$this->_datestring($annot_obj_id);
  8344. //$annots .= ' /IRT ';
  8345. if (isset($pl['opt']['subj'])) {
  8346. $annots .= ' /Subj '.$this->_textstring($pl['opt']['subj'], $annot_obj_id);
  8347. }
  8348. //$annots .= ' /RT ';
  8349. //$annots .= ' /IT ';
  8350. //$annots .= ' /ExData ';
  8351. }
  8352. $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt', 'ROpenArrow', 'RClosedArrow', 'Slash');
  8353. // Annotation types
  8354. switch (strtolower($pl['opt']['subtype'])) {
  8355. case 'text': {
  8356. if (isset($pl['opt']['open'])) {
  8357. $annots .= ' /Open '. (strtolower($pl['opt']['open']) == 'true' ? 'true' : 'false');
  8358. }
  8359. $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph');
  8360. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8361. $annots .= ' /Name /'.$pl['opt']['name'];
  8362. } else {
  8363. $annots .= ' /Name /Note';
  8364. }
  8365. $statemodels = array('Marked', 'Review');
  8366. if (isset($pl['opt']['statemodel']) AND in_array($pl['opt']['statemodel'], $statemodels)) {
  8367. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  8368. } else {
  8369. $pl['opt']['statemodel'] = 'Marked';
  8370. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  8371. }
  8372. if ($pl['opt']['statemodel'] == 'Marked') {
  8373. $states = array('Accepted', 'Unmarked');
  8374. } else {
  8375. $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None');
  8376. }
  8377. if (isset($pl['opt']['state']) AND in_array($pl['opt']['state'], $states)) {
  8378. $annots .= ' /State /'.$pl['opt']['state'];
  8379. } else {
  8380. if ($pl['opt']['statemodel'] == 'Marked') {
  8381. $annots .= ' /State /Unmarked';
  8382. } else {
  8383. $annots .= ' /State /None';
  8384. }
  8385. }
  8386. break;
  8387. }
  8388. case 'link': {
  8389. if(is_string($pl['txt'])) {
  8390. // external URI link
  8391. $annots .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>';
  8392. } else {
  8393. // internal link
  8394. $l = $this->links[$pl['txt']];
  8395. $annots .= sprintf(' /Dest [%u 0 R /XYZ 0 %.2F null]', $this->page_obj_id[($l[0])], ($this->pagedim[$l[0]]['h'] - ($l[1] * $this->k)));
  8396. }
  8397. $hmodes = array('N', 'I', 'O', 'P');
  8398. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmodes)) {
  8399. $annots .= ' /H /'.$pl['opt']['h'];
  8400. } else {
  8401. $annots .= ' /H /I';
  8402. }
  8403. //$annots .= ' /PA ';
  8404. //$annots .= ' /Quadpoints ';
  8405. break;
  8406. }
  8407. case 'freetext': {
  8408. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  8409. $annots .= ' /DA ('.$pl['opt']['da'].')';
  8410. }
  8411. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  8412. $annots .= ' /Q '.intval($pl['opt']['q']);
  8413. }
  8414. if (isset($pl['opt']['rc'])) {
  8415. $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  8416. }
  8417. if (isset($pl['opt']['ds'])) {
  8418. $annots .= ' /DS '.$this->_textstring($pl['opt']['ds'], $annot_obj_id);
  8419. }
  8420. if (isset($pl['opt']['cl']) AND is_array($pl['opt']['cl'])) {
  8421. $annots .= ' /CL [';
  8422. foreach ($pl['opt']['cl'] as $cl) {
  8423. $annots .= sprintf('%.4F ', $cl * $this->k);
  8424. }
  8425. $annots .= ']';
  8426. }
  8427. $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter');
  8428. if (isset($pl['opt']['it']) AND in_array($pl['opt']['it'], $tfit)) {
  8429. $annots .= ' /IT /'.$pl['opt']['it'];
  8430. }
  8431. if (isset($pl['opt']['rd']) AND is_array($pl['opt']['rd'])) {
  8432. $l = $pl['opt']['rd'][0] * $this->k;
  8433. $r = $pl['opt']['rd'][1] * $this->k;
  8434. $t = $pl['opt']['rd'][2] * $this->k;
  8435. $b = $pl['opt']['rd'][3] * $this->k;
  8436. $annots .= ' /RD ['.sprintf('%.2F %.2F %.2F %.2F', $l, $r, $t, $b).']';
  8437. }
  8438. if (isset($pl['opt']['le']) AND in_array($pl['opt']['le'], $lineendings)) {
  8439. $annots .= ' /LE /'.$pl['opt']['le'];
  8440. }
  8441. break;
  8442. }
  8443. case 'line': {
  8444. break;
  8445. }
  8446. case 'square': {
  8447. break;
  8448. }
  8449. case 'circle': {
  8450. break;
  8451. }
  8452. case 'polygon': {
  8453. break;
  8454. }
  8455. case 'polyline': {
  8456. break;
  8457. }
  8458. case 'highlight': {
  8459. break;
  8460. }
  8461. case 'underline': {
  8462. break;
  8463. }
  8464. case 'squiggly': {
  8465. break;
  8466. }
  8467. case 'strikeout': {
  8468. break;
  8469. }
  8470. case 'stamp': {
  8471. break;
  8472. }
  8473. case 'caret': {
  8474. break;
  8475. }
  8476. case 'ink': {
  8477. break;
  8478. }
  8479. case 'popup': {
  8480. break;
  8481. }
  8482. case 'fileattachment': {
  8483. if (!isset($pl['opt']['fs'])) {
  8484. break;
  8485. }
  8486. $filename = basename($pl['opt']['fs']);
  8487. if (isset($this->embeddedfiles[$filename]['n'])) {
  8488. $annots .= ' /FS <</Type /Filespec /F '.$this->_datastring($filename, $annot_obj_id).' /EF <</F '.$this->embeddedfiles[$filename]['n'].' 0 R>> >>';
  8489. $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag');
  8490. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8491. $annots .= ' /Name /'.$pl['opt']['name'];
  8492. } else {
  8493. $annots .= ' /Name /PushPin';
  8494. }
  8495. }
  8496. break;
  8497. }
  8498. case 'sound': {
  8499. if (!isset($pl['opt']['fs'])) {
  8500. break;
  8501. }
  8502. $filename = basename($pl['opt']['fs']);
  8503. if (isset($this->embeddedfiles[$filename]['n'])) {
  8504. // ... TO BE COMPLETED ...
  8505. // /R /C /B /E /CO /CP
  8506. $annots .= ' /Sound <</Type /Filespec /F '.$this->_datastring($filename, $annot_obj_id).' /EF <</F '.$this->embeddedfiles[$filename]['n'].' 0 R>> >>';
  8507. $iconsapp = array('Speaker', 'Mic');
  8508. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8509. $annots .= ' /Name /'.$pl['opt']['name'];
  8510. } else {
  8511. $annots .= ' /Name /Speaker';
  8512. }
  8513. }
  8514. break;
  8515. }
  8516. case 'movie': {
  8517. break;
  8518. }
  8519. case 'widget': {
  8520. $hmode = array('N', 'I', 'O', 'P', 'T');
  8521. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmode)) {
  8522. $annots .= ' /H /'.$pl['opt']['h'];
  8523. }
  8524. if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) {
  8525. $annots .= ' /MK <<';
  8526. if (isset($pl['opt']['mk']['r'])) {
  8527. $annots .= ' /R '.$pl['opt']['mk']['r'];
  8528. }
  8529. if (isset($pl['opt']['mk']['bc']) AND (is_array($pl['opt']['mk']['bc']))) {
  8530. $annots .= ' /BC [';
  8531. foreach($pl['opt']['mk']['bc'] AS $col) {
  8532. $col = intval($col);
  8533. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  8534. $annots .= sprintf(' %.2F', $color);
  8535. }
  8536. $annots .= ']';
  8537. }
  8538. if (isset($pl['opt']['mk']['bg']) AND (is_array($pl['opt']['mk']['bg']))) {
  8539. $annots .= ' /BG [';
  8540. foreach($pl['opt']['mk']['bg'] AS $col) {
  8541. $col = intval($col);
  8542. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  8543. $annots .= sprintf(' %.2F', $color);
  8544. }
  8545. $annots .= ']';
  8546. }
  8547. if (isset($pl['opt']['mk']['ca'])) {
  8548. $annots .= ' /CA '.$pl['opt']['mk']['ca'];
  8549. }
  8550. if (isset($pl['opt']['mk']['rc'])) {
  8551. $annots .= ' /RC '.$pl['opt']['mk']['rc'];
  8552. }
  8553. if (isset($pl['opt']['mk']['ac'])) {
  8554. $annots .= ' /AC '.$pl['opt']['mk']['ac'];
  8555. }
  8556. if (isset($pl['opt']['mk']['i'])) {
  8557. $info = $this->getImageBuffer($pl['opt']['mk']['i']);
  8558. if ($info !== false) {
  8559. $annots .= ' /I '.$info['n'].' 0 R';
  8560. }
  8561. }
  8562. if (isset($pl['opt']['mk']['ri'])) {
  8563. $info = $this->getImageBuffer($pl['opt']['mk']['ri']);
  8564. if ($info !== false) {
  8565. $annots .= ' /RI '.$info['n'].' 0 R';
  8566. }
  8567. }
  8568. if (isset($pl['opt']['mk']['ix'])) {
  8569. $info = $this->getImageBuffer($pl['opt']['mk']['ix']);
  8570. if ($info !== false) {
  8571. $annots .= ' /IX '.$info['n'].' 0 R';
  8572. }
  8573. }
  8574. if (isset($pl['opt']['mk']['if']) AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) {
  8575. $annots .= ' /IF <<';
  8576. $if_sw = array('A', 'B', 'S', 'N');
  8577. if (isset($pl['opt']['mk']['if']['sw']) AND in_array($pl['opt']['mk']['if']['sw'], $if_sw)) {
  8578. $annots .= ' /SW /'.$pl['opt']['mk']['if']['sw'];
  8579. }
  8580. $if_s = array('A', 'P');
  8581. if (isset($pl['opt']['mk']['if']['s']) AND in_array($pl['opt']['mk']['if']['s'], $if_s)) {
  8582. $annots .= ' /S /'.$pl['opt']['mk']['if']['s'];
  8583. }
  8584. if (isset($pl['opt']['mk']['if']['a']) AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) {
  8585. $annots .= sprintf(' /A [%.2F %.2F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]);
  8586. }
  8587. if (isset($pl['opt']['mk']['if']['fb']) AND ($pl['opt']['mk']['if']['fb'])) {
  8588. $annots .= ' /FB true';
  8589. }
  8590. $annots .= '>>';
  8591. }
  8592. if (isset($pl['opt']['mk']['tp']) AND ($pl['opt']['mk']['tp'] >= 0) AND ($pl['opt']['mk']['tp'] <= 6)) {
  8593. $annots .= ' /TP '.intval($pl['opt']['mk']['tp']);
  8594. } else {
  8595. $annots .= ' /TP 0';
  8596. }
  8597. $annots .= '>>';
  8598. } // end MK
  8599. // --- Entries for field dictionaries ---
  8600. if (isset($this->radiobutton_groups[$n][$pl['txt']])) {
  8601. // set parent
  8602. $annots .= ' /Parent '.$this->radiobutton_groups[$n][$pl['txt']].' 0 R';
  8603. }
  8604. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  8605. $annots .= ' /T '.$this->_datastring($pl['opt']['t'], $annot_obj_id);
  8606. }
  8607. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  8608. $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $annot_obj_id);
  8609. }
  8610. if (isset($pl['opt']['tm']) AND is_string($pl['opt']['tm'])) {
  8611. $annots .= ' /TM '.$this->_datastring($pl['opt']['tm'], $annot_obj_id);
  8612. }
  8613. if (isset($pl['opt']['ff'])) {
  8614. if (is_array($pl['opt']['ff'])) {
  8615. // array of bit settings
  8616. $flag = 0;
  8617. foreach($pl['opt']['ff'] as $val) {
  8618. $flag += 1 << ($val - 1);
  8619. }
  8620. } else {
  8621. $flag = intval($pl['opt']['ff']);
  8622. }
  8623. $annots .= ' /Ff '.$flag;
  8624. }
  8625. if (isset($pl['opt']['maxlen'])) {
  8626. $annots .= ' /MaxLen '.intval($pl['opt']['maxlen']);
  8627. }
  8628. if (isset($pl['opt']['v'])) {
  8629. $annots .= ' /V';
  8630. if (is_array($pl['opt']['v'])) {
  8631. foreach ($pl['opt']['v'] AS $optval) {
  8632. if (is_float($optval)) {
  8633. $optval = sprintf('%.2F', $optval);
  8634. }
  8635. $annots .= ' '.$optval;
  8636. }
  8637. } else {
  8638. $annots .= ' '.$this->_textstring($pl['opt']['v'], $annot_obj_id);
  8639. }
  8640. }
  8641. if (isset($pl['opt']['dv'])) {
  8642. $annots .= ' /DV';
  8643. if (is_array($pl['opt']['dv'])) {
  8644. foreach ($pl['opt']['dv'] AS $optval) {
  8645. if (is_float($optval)) {
  8646. $optval = sprintf('%.2F', $optval);
  8647. }
  8648. $annots .= ' '.$optval;
  8649. }
  8650. } else {
  8651. $annots .= ' '.$this->_textstring($pl['opt']['dv'], $annot_obj_id);
  8652. }
  8653. }
  8654. if (isset($pl['opt']['rv'])) {
  8655. $annots .= ' /RV';
  8656. if (is_array($pl['opt']['rv'])) {
  8657. foreach ($pl['opt']['rv'] AS $optval) {
  8658. if (is_float($optval)) {
  8659. $optval = sprintf('%.2F', $optval);
  8660. }
  8661. $annots .= ' '.$optval;
  8662. }
  8663. } else {
  8664. $annots .= ' '.$this->_textstring($pl['opt']['rv'], $annot_obj_id);
  8665. }
  8666. }
  8667. if (isset($pl['opt']['a']) AND !empty($pl['opt']['a'])) {
  8668. $annots .= ' /A << '.$pl['opt']['a'].' >>';
  8669. }
  8670. if (isset($pl['opt']['aa']) AND !empty($pl['opt']['aa'])) {
  8671. $annots .= ' /AA << '.$pl['opt']['aa'].' >>';
  8672. }
  8673. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  8674. $annots .= ' /DA ('.$pl['opt']['da'].')';
  8675. }
  8676. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  8677. $annots .= ' /Q '.intval($pl['opt']['q']);
  8678. }
  8679. if (isset($pl['opt']['opt']) AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) {
  8680. $annots .= ' /Opt [';
  8681. foreach($pl['opt']['opt'] AS $copt) {
  8682. if (is_array($copt)) {
  8683. $annots .= ' ['.$this->_textstring($copt[0], $annot_obj_id).' '.$this->_textstring($copt[1], $annot_obj_id).']';
  8684. } else {
  8685. $annots .= ' '.$this->_textstring($copt, $annot_obj_id);
  8686. }
  8687. }
  8688. $annots .= ']';
  8689. }
  8690. if (isset($pl['opt']['ti'])) {
  8691. $annots .= ' /TI '.intval($pl['opt']['ti']);
  8692. }
  8693. if (isset($pl['opt']['i']) AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) {
  8694. $annots .= ' /I [';
  8695. foreach($pl['opt']['i'] AS $copt) {
  8696. $annots .= intval($copt).' ';
  8697. }
  8698. $annots .= ']';
  8699. }
  8700. break;
  8701. }
  8702. case 'screen': {
  8703. break;
  8704. }
  8705. case 'printermark': {
  8706. break;
  8707. }
  8708. case 'trapnet': {
  8709. break;
  8710. }
  8711. case 'watermark': {
  8712. break;
  8713. }
  8714. case '3d': {
  8715. break;
  8716. }
  8717. default: {
  8718. break;
  8719. }
  8720. }
  8721. $annots .= '>>';
  8722. // create new annotation object
  8723. $this->_out($this->_getobj($annot_obj_id)."\n".$annots."\n".'endobj');
  8724. if ($formfield AND !isset($this->radiobutton_groups[$n][$pl['txt']])) {
  8725. // store reference of form object
  8726. $this->form_obj_id[] = $annot_obj_id;
  8727. }
  8728. }
  8729. }
  8730. } // end for each page
  8731. }
  8732. /**
  8733. * Put appearance streams XObject used to define annotation's appearance states
  8734. * @param $w (int) annotation width
  8735. * @param $h (int) annotation height
  8736. * @param $stream (string) appearance stream
  8737. * @return int object ID
  8738. * @protected
  8739. * @since 4.8.001 (2009-09-09)
  8740. */
  8741. protected function _putAPXObject($w=0, $h=0, $stream='') {
  8742. $stream = trim($stream);
  8743. $out = $this->_getobj()."\n";
  8744. $this->xobjects['AX'.$this->n] = array('n' => $this->n);
  8745. $out .= '<<';
  8746. $out .= ' /Type /XObject';
  8747. $out .= ' /Subtype /Form';
  8748. $out .= ' /FormType 1';
  8749. if ($this->compress) {
  8750. $stream = gzcompress($stream);
  8751. $out .= ' /Filter /FlateDecode';
  8752. }
  8753. $rect = sprintf('%.2F %.2F', $w, $h);
  8754. $out .= ' /BBox [0 0 '.$rect.']';
  8755. $out .= ' /Matrix [1 0 0 1 0 0]';
  8756. $out .= ' /Resources <<';
  8757. $out .= ' /ProcSet [/PDF /Text]';
  8758. $out .= ' /Font <<';
  8759. foreach ($this->annotation_fonts as $fontkey => $fontid) {
  8760. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  8761. }
  8762. $out .= ' >>';
  8763. $out .= ' >>';
  8764. $stream = $this->_getrawstream($stream);
  8765. $out .= ' /Length '.strlen($stream);
  8766. $out .= ' >>';
  8767. $out .= ' stream'."\n".$stream."\n".'endstream';
  8768. $out .= "\n".'endobj';
  8769. $this->_out($out);
  8770. return $this->n;
  8771. }
  8772. /**
  8773. * Get ULONG from string (Big Endian 32-bit unsigned integer).
  8774. * @param $str (string) string from where to extract value
  8775. * @param $offset (int) point from where to read the data
  8776. * @return int 32 bit value
  8777. * @author Nicola Asuni
  8778. * @protected
  8779. * @since 5.2.000 (2010-06-02)
  8780. */
  8781. protected function _getULONG(&$str, &$offset) {
  8782. $v = unpack('Ni', substr($str, $offset, 4));
  8783. $offset += 4;
  8784. return $v['i'];
  8785. }
  8786. /**
  8787. * Get USHORT from string (Big Endian 16-bit unsigned integer).
  8788. * @param $str (string) string from where to extract value
  8789. * @param $offset (int) point from where to read the data
  8790. * @return int 16 bit value
  8791. * @author Nicola Asuni
  8792. * @protected
  8793. * @since 5.2.000 (2010-06-02)
  8794. */
  8795. protected function _getUSHORT(&$str, &$offset) {
  8796. $v = unpack('ni', substr($str, $offset, 2));
  8797. $offset += 2;
  8798. return $v['i'];
  8799. }
  8800. /**
  8801. * Get SHORT from string (Big Endian 16-bit signed integer).
  8802. * @param $str (string) string from where to extract value
  8803. * @param $offset (int) point from where to read the data
  8804. * @return int 16 bit value
  8805. * @author Nicola Asuni
  8806. * @protected
  8807. * @since 5.2.000 (2010-06-02)
  8808. */
  8809. protected function _getSHORT(&$str, &$offset) {
  8810. $v = unpack('si', substr($str, $offset, 2));
  8811. $offset += 2;
  8812. return $v['i'];
  8813. }
  8814. /**
  8815. * Get BYTE from string (8-bit unsigned integer).
  8816. * @param $str (string) string from where to extract value
  8817. * @param $offset (int) point from where to read the data
  8818. * @return int 8 bit value
  8819. * @author Nicola Asuni
  8820. * @protected
  8821. * @since 5.2.000 (2010-06-02)
  8822. */
  8823. protected function _getBYTE(&$str, &$offset) {
  8824. $v = unpack('Ci', substr($str, $offset, 1));
  8825. ++$offset;
  8826. return $v['i'];
  8827. }
  8828. /**
  8829. * Returns a subset of the TrueType font data without the unused glyphs.
  8830. * @param $font (string) TrueType font data
  8831. * @param $subsetchars (array) array of used characters (the glyphs to keep)
  8832. * @return string a subset of TrueType font data without the unused glyphs
  8833. * @author Nicola Asuni
  8834. * @protected
  8835. * @since 5.2.000 (2010-06-02)
  8836. */
  8837. protected function _getTrueTypeFontSubset($font, $subsetchars) {
  8838. ksort($subsetchars);
  8839. $offset = 0; // offset position of the font data
  8840. if ($this->_getULONG($font, $offset) != 0x10000) {
  8841. // sfnt version must be 0x00010000 for TrueType version 1.0.
  8842. return $font;
  8843. }
  8844. // get number of tables
  8845. $numTables = $this->_getUSHORT($font, $offset);
  8846. // skip searchRange, entrySelector and rangeShift
  8847. $offset += 6;
  8848. // tables array
  8849. $table = array();
  8850. // for each table
  8851. for ($i = 0; $i < $numTables; ++$i) {
  8852. // get table info
  8853. $tag = substr($font, $offset, 4);
  8854. $offset += 4;
  8855. $table[$tag] = array();
  8856. $table[$tag]['checkSum'] = $this->_getULONG($font, $offset);
  8857. $table[$tag]['offset'] = $this->_getULONG($font, $offset);
  8858. $table[$tag]['length'] = $this->_getULONG($font, $offset);
  8859. }
  8860. // check magicNumber
  8861. $offset = $table['head']['offset'] + 12;
  8862. if ($this->_getULONG($font, $offset) != 0x5F0F3CF5) {
  8863. // magicNumber must be 0x5F0F3CF5
  8864. return $font;
  8865. }
  8866. // get offset mode (indexToLocFormat : 0 = short, 1 = long)
  8867. $offset = $table['head']['offset'] + 50;
  8868. $short_offset = ($this->_getSHORT($font, $offset) == 0);
  8869. // get the offsets to the locations of the glyphs in the font, relative to the beginning of the glyphData table
  8870. $indexToLoc = array();
  8871. $offset = $table['loca']['offset'];
  8872. if ($short_offset) {
  8873. // short version
  8874. $n = $table['loca']['length'] / 2; // numGlyphs + 1
  8875. for ($i = 0; $i < $n; ++$i) {
  8876. $indexToLoc[$i] = $this->_getUSHORT($font, $offset) * 2;
  8877. }
  8878. } else {
  8879. // long version
  8880. $n = $table['loca']['length'] / 4; // numGlyphs + 1
  8881. for ($i = 0; $i < $n; ++$i) {
  8882. $indexToLoc[$i] = $this->_getULONG($font, $offset);
  8883. }
  8884. }
  8885. // get glyphs indexes of chars from cmap table
  8886. $subsetglyphs = array(); // glyph IDs on key
  8887. $subsetglyphs[0] = true; // character codes that do not correspond to any glyph in the font should be mapped to glyph index 0
  8888. $offset = $table['cmap']['offset'] + 2;
  8889. $numEncodingTables = $this->_getUSHORT($font, $offset);
  8890. $encodingTables = array();
  8891. for ($i = 0; $i < $numEncodingTables; ++$i) {
  8892. $encodingTables[$i]['platformID'] = $this->_getUSHORT($font, $offset);
  8893. $encodingTables[$i]['encodingID'] = $this->_getUSHORT($font, $offset);
  8894. $encodingTables[$i]['offset'] = $this->_getULONG($font, $offset);
  8895. }
  8896. foreach ($encodingTables as $enctable) {
  8897. if (($enctable['platformID'] == 3) AND ($enctable['encodingID'] == 0)) {
  8898. $modesymbol = true;
  8899. } else {
  8900. $modesymbol = false;
  8901. }
  8902. $offset = $table['cmap']['offset'] + $enctable['offset'];
  8903. $format = $this->_getUSHORT($font, $offset);
  8904. switch ($format) {
  8905. case 0: { // Format 0: Byte encoding table
  8906. $offset += 4; // skip length and version/language
  8907. for ($k = 0; $k < 256; ++$k) {
  8908. if (isset($subsetchars[$k])) {
  8909. $g = $this->_getBYTE($font, $offset);
  8910. $subsetglyphs[$g] = $k;
  8911. } else {
  8912. ++$offset;
  8913. }
  8914. }
  8915. break;
  8916. }
  8917. case 2: { // Format 2: High-byte mapping through table
  8918. $offset += 4; // skip length and version
  8919. // to be implemented ...
  8920. break;
  8921. }
  8922. case 4: { // Format 4: Segment mapping to delta values
  8923. $length = $this->_getUSHORT($font, $offset);
  8924. $offset += 2; // skip version/language
  8925. $segCount = ($this->_getUSHORT($font, $offset) / 2);
  8926. $offset += 6; // skip searchRange, entrySelector, rangeShift
  8927. $endCount = array(); // array of end character codes for each segment
  8928. for ($k = 0; $k < $segCount; ++$k) {
  8929. $endCount[$k] = $this->_getUSHORT($font, $offset);
  8930. }
  8931. $offset += 2; // skip reservedPad
  8932. $startCount = array(); // array of start character codes for each segment
  8933. for ($k = 0; $k < $segCount; ++$k) {
  8934. $startCount[$k] = $this->_getUSHORT($font, $offset);
  8935. }
  8936. $idDelta = array(); // delta for all character codes in segment
  8937. for ($k = 0; $k < $segCount; ++$k) {
  8938. $idDelta[$k] = $this->_getUSHORT($font, $offset);
  8939. }
  8940. $idRangeOffset = array(); // Offsets into glyphIdArray or 0
  8941. for ($k = 0; $k < $segCount; ++$k) {
  8942. $idRangeOffset[$k] = $this->_getUSHORT($font, $offset);
  8943. }
  8944. $gidlen = ($length / 2) - 8 - (4 * $segCount);
  8945. $glyphIdArray = array(); // glyph index array
  8946. for ($k = 0; $k < $gidlen; ++$k) {
  8947. $glyphIdArray[$k] = $this->_getUSHORT($font, $offset);
  8948. }
  8949. for ($k = 0; $k < $segCount; ++$k) {
  8950. for ($c = $startCount[$k]; $c <= $endCount[$k]; ++$c) {
  8951. if (isset($subsetchars[$c])) {
  8952. if ($idRangeOffset[$k] == 0) {
  8953. $g = $c;
  8954. } else {
  8955. $gid = (($idRangeOffset[$k] / 2) + ($c - $startCount[$k]) - ($segCount - $k));
  8956. $g = $glyphIdArray[$gid];
  8957. }
  8958. $g += ($idDelta[$k] - 65536);
  8959. if ($g < 0) {
  8960. $g = 0;
  8961. }
  8962. $subsetglyphs[$g] = $c;
  8963. }
  8964. }
  8965. }
  8966. break;
  8967. }
  8968. case 6: { // Format 6: Trimmed table mapping
  8969. $offset += 4; // skip length and version/language
  8970. $firstCode = $this->_getUSHORT($font, $offset);
  8971. $entryCount = $this->_getUSHORT($font, $offset);
  8972. for ($k = 0; $k < $entryCount; ++$k) {
  8973. $c = ($k + $firstCode);
  8974. if (isset($subsetchars[$c])) {
  8975. $g = $this->_getUSHORT($font, $offset);
  8976. $subsetglyphs[$g] = $c;
  8977. } else {
  8978. $offset += 2;
  8979. }
  8980. }
  8981. break;
  8982. }
  8983. case 8: { // Format 8: Mixed 16-bit and 32-bit coverage
  8984. $offset += 10; // skip length and version
  8985. // to be implemented ...
  8986. break;
  8987. }
  8988. case 10: { // Format 10: Trimmed array
  8989. $offset += 10; // skip length and version/language
  8990. $startCharCode = $this->_getULONG($font, $offset);
  8991. $numChars = $this->_getULONG($font, $offset);
  8992. for ($k = 0; $k < $numChars; ++$k) {
  8993. $c = ($k + $startCharCode);
  8994. if (isset($subsetchars[$c])) {
  8995. $g = $this->_getUSHORT($font, $offset);
  8996. $subsetglyphs[$g] = $c;
  8997. } else {
  8998. $offset += 2;
  8999. }
  9000. }
  9001. break;
  9002. }
  9003. case 12: { // Format 12: Segmented coverage
  9004. $offset += 10; // skip length and version/language
  9005. $nGroups = $this->_getULONG($font, $offset);
  9006. for ($k = 0; $k < $nGroups; ++$k) {
  9007. $startCharCode = $this->_getULONG($font, $offset);
  9008. $endCharCode = $this->_getULONG($font, $offset);
  9009. $startGlyphCode = $this->_getULONG($font, $offset);
  9010. for ($c = $startCharCode; $c <= $endCharCode; ++$c) {
  9011. if (isset($subsetchars[$c])) {
  9012. $subsetglyphs[$startGlyphCode] = $c;
  9013. }
  9014. ++$startGlyphCode;
  9015. }
  9016. }
  9017. break;
  9018. }
  9019. }
  9020. }
  9021. // sort glyphs by key
  9022. ksort($subsetglyphs);
  9023. // add composite glyps to $subsetglyphs and remove missing glyphs
  9024. foreach ($subsetglyphs as $key => $val) {
  9025. if (isset($indexToLoc[$key])) {
  9026. $offset = $table['glyf']['offset'] + $indexToLoc[$key];
  9027. $numberOfContours = $this->_getSHORT($font, $offset);
  9028. if ($numberOfContours < 0) { // composite glyph
  9029. $offset += 8; // skip xMin, yMin, xMax, yMax
  9030. do {
  9031. $flags = $this->_getUSHORT($font, $offset);
  9032. $glyphIndex = $this->_getUSHORT($font, $offset);
  9033. if (!isset($subsetglyphs[$glyphIndex]) AND isset($indexToLoc[$glyphIndex])) {
  9034. // add missing glyphs
  9035. $subsetglyphs[$glyphIndex] = true;
  9036. }
  9037. // skip some bytes by case
  9038. if ($flags & 1) {
  9039. $offset += 4;
  9040. } else {
  9041. $offset += 2;
  9042. }
  9043. if ($flags & 8) {
  9044. $offset += 2;
  9045. } elseif ($flags & 64) {
  9046. $offset += 4;
  9047. } elseif ($flags & 128) {
  9048. $offset += 8;
  9049. }
  9050. } while ($flags & 32);
  9051. }
  9052. } else {
  9053. unset($subsetglyphs[$key]);
  9054. }
  9055. }
  9056. // build new glyf table with only used glyphs
  9057. $glyf = '';
  9058. $glyfSize = 0;
  9059. // create new empty indexToLoc table
  9060. $newIndexToLoc = array_fill(0, count($indexToLoc), 0);
  9061. $goffset = 0;
  9062. foreach ($subsetglyphs as $glyphID => $char) {
  9063. if (isset($indexToLoc[$glyphID]) AND isset($indexToLoc[($glyphID + 1)])) {
  9064. $start = $indexToLoc[$glyphID];
  9065. $length = ($indexToLoc[($glyphID + 1)] - $start);
  9066. $glyf .= substr($font, ($table['glyf']['offset'] + $start), $length);
  9067. $newIndexToLoc[$glyphID] = $goffset;
  9068. $goffset += $length;
  9069. }
  9070. }
  9071. // build new loca table
  9072. $loca = '';
  9073. if ($short_offset) {
  9074. foreach ($newIndexToLoc as $glyphID => $offset) {
  9075. $loca .= pack('n', ($offset / 2));
  9076. }
  9077. } else {
  9078. foreach ($newIndexToLoc as $glyphID => $offset) {
  9079. $loca .= pack('N', $offset);
  9080. }
  9081. }
  9082. // array of table names to preserve (loca and glyf tables will be added later)
  9083. //$table_names = array ('cmap', 'head', 'hhea', 'hmtx', 'maxp', 'name', 'OS/2', 'post', 'cvt ', 'fpgm', 'prep');
  9084. // the cmap table is not needed and shall not be present, since the mapping from character codes to glyph descriptions is provided separately
  9085. $table_names = array ('head', 'hhea', 'hmtx', 'maxp', 'cvt ', 'fpgm', 'prep'); // minimum required table names
  9086. // get the tables to preserve
  9087. $offset = 12;
  9088. foreach ($table as $tag => $val) {
  9089. if (in_array($tag, $table_names)) {
  9090. $table[$tag]['data'] = substr($font, $table[$tag]['offset'], $table[$tag]['length']);
  9091. if ($tag == 'head') {
  9092. // set the checkSumAdjustment to 0
  9093. $table[$tag]['data'] = substr($table[$tag]['data'], 0, 8)."\x0\x0\x0\x0".substr($table[$tag]['data'], 12);
  9094. }
  9095. $pad = 4 - ($table[$tag]['length'] % 4);
  9096. if ($pad != 4) {
  9097. // the length of a table must be a multiple of four bytes
  9098. $table[$tag]['length'] += $pad;
  9099. $table[$tag]['data'] .= str_repeat("\x0", $pad);
  9100. }
  9101. $table[$tag]['offset'] = $offset;
  9102. $offset += $table[$tag]['length'];
  9103. // check sum is not changed (so keep the following line commented)
  9104. //$table[$tag]['checkSum'] = $this->_getTTFtableChecksum($table[$tag]['data'], $table[$tag]['length']);
  9105. } else {
  9106. unset($table[$tag]);
  9107. }
  9108. }
  9109. // add loca
  9110. $table['loca']['data'] = $loca;
  9111. $table['loca']['length'] = strlen($loca);
  9112. $pad = 4 - ($table['loca']['length'] % 4);
  9113. if ($pad != 4) {
  9114. // the length of a table must be a multiple of four bytes
  9115. $table['loca']['length'] += $pad;
  9116. $table['loca']['data'] .= str_repeat("\x0", $pad);
  9117. }
  9118. $table['loca']['offset'] = $offset;
  9119. $table['loca']['checkSum'] = $this->_getTTFtableChecksum($table['loca']['data'], $table['loca']['length']);
  9120. $offset += $table['loca']['length'];
  9121. // add glyf
  9122. $table['glyf']['data'] = $glyf;
  9123. $table['glyf']['length'] = strlen($glyf);
  9124. $pad = 4 - ($table['glyf']['length'] % 4);
  9125. if ($pad != 4) {
  9126. // the length of a table must be a multiple of four bytes
  9127. $table['glyf']['length'] += $pad;
  9128. $table['glyf']['data'] .= str_repeat("\x0", $pad);
  9129. }
  9130. $table['glyf']['offset'] = $offset;
  9131. $table['glyf']['checkSum'] = $this->_getTTFtableChecksum($table['glyf']['data'], $table['glyf']['length']);
  9132. // rebuild font
  9133. $font = '';
  9134. $font .= pack('N', 0x10000); // sfnt version
  9135. $numTables = count($table);
  9136. $font .= pack('n', $numTables); // numTables
  9137. $entrySelector = floor(log($numTables, 2));
  9138. $searchRange = pow(2, $entrySelector) * 16;
  9139. $rangeShift = ($numTables * 16) - $searchRange;
  9140. $font .= pack('n', $searchRange); // searchRange
  9141. $font .= pack('n', $entrySelector); // entrySelector
  9142. $font .= pack('n', $rangeShift); // rangeShift
  9143. $offset = ($numTables * 16);
  9144. foreach ($table as $tag => $data) {
  9145. $font .= $tag; // tag
  9146. $font .= pack('N', $data['checkSum']); // checkSum
  9147. $font .= pack('N', ($data['offset'] + $offset)); // offset
  9148. $font .= pack('N', $data['length']); // length
  9149. }
  9150. foreach ($table as $data) {
  9151. $font .= $data['data'];
  9152. }
  9153. // set checkSumAdjustment on head table
  9154. $checkSumAdjustment = 0xB1B0AFBA - $this->_getTTFtableChecksum($font, strlen($font));
  9155. $font = substr($font, 0, $table['head']['offset'] + 8).pack('N', $checkSumAdjustment).substr($font, $table['head']['offset'] + 12);
  9156. return $font;
  9157. }
  9158. /**
  9159. * Returs the checksum of a TTF table.
  9160. * @param $table (string) table to check
  9161. * @param $length (int) lenght of table in bytes
  9162. * @return int checksum
  9163. * @author Nicola Asuni
  9164. * @protected
  9165. * @since 5.2.000 (2010-06-02)
  9166. */
  9167. protected function _getTTFtableChecksum($table, $length) {
  9168. $sum = 0;
  9169. $tlen = ($length / 4);
  9170. $offset = 0;
  9171. for ($i = 0; $i < $tlen; ++$i) {
  9172. $v = unpack('Ni', substr($table, $offset, 4));
  9173. $sum += $v['i'];
  9174. $offset += 4;
  9175. }
  9176. $sum = unpack('Ni', pack('N', $sum));
  9177. return $sum['i'];
  9178. }
  9179. /**
  9180. * Outputs font widths
  9181. * @param $font (array) font data
  9182. * @param $cidoffset (int) offset for CID values
  9183. * @return PDF command string for font widths
  9184. * @author Nicola Asuni
  9185. * @protected
  9186. * @since 4.4.000 (2008-12-07)
  9187. */
  9188. protected function _putfontwidths($font, $cidoffset=0) {
  9189. ksort($font['cw']);
  9190. $rangeid = 0;
  9191. $range = array();
  9192. $prevcid = -2;
  9193. $prevwidth = -1;
  9194. $interval = false;
  9195. // for each character
  9196. foreach ($font['cw'] as $cid => $width) {
  9197. $cid -= $cidoffset;
  9198. if ($font['subset'] AND ($cid > 255) AND (!isset($font['subsetchars'][$cid]))) {
  9199. // ignore the unused characters (font subsetting)
  9200. continue;
  9201. }
  9202. if ($width != $font['dw']) {
  9203. if ($cid == ($prevcid + 1)) {
  9204. // consecutive CID
  9205. if ($width == $prevwidth) {
  9206. if ($width == $range[$rangeid][0]) {
  9207. $range[$rangeid][] = $width;
  9208. } else {
  9209. array_pop($range[$rangeid]);
  9210. // new range
  9211. $rangeid = $prevcid;
  9212. $range[$rangeid] = array();
  9213. $range[$rangeid][] = $prevwidth;
  9214. $range[$rangeid][] = $width;
  9215. }
  9216. $interval = true;
  9217. $range[$rangeid]['interval'] = true;
  9218. } else {
  9219. if ($interval) {
  9220. // new range
  9221. $rangeid = $cid;
  9222. $range[$rangeid] = array();
  9223. $range[$rangeid][] = $width;
  9224. } else {
  9225. $range[$rangeid][] = $width;
  9226. }
  9227. $interval = false;
  9228. }
  9229. } else {
  9230. // new range
  9231. $rangeid = $cid;
  9232. $range[$rangeid] = array();
  9233. $range[$rangeid][] = $width;
  9234. $interval = false;
  9235. }
  9236. $prevcid = $cid;
  9237. $prevwidth = $width;
  9238. }
  9239. }
  9240. // optimize ranges
  9241. $prevk = -1;
  9242. $nextk = -1;
  9243. $prevint = false;
  9244. foreach ($range as $k => $ws) {
  9245. $cws = count($ws);
  9246. if (($k == $nextk) AND (!$prevint) AND ((!isset($ws['interval'])) OR ($cws < 4))) {
  9247. if (isset($range[$k]['interval'])) {
  9248. unset($range[$k]['interval']);
  9249. }
  9250. $range[$prevk] = array_merge($range[$prevk], $range[$k]);
  9251. unset($range[$k]);
  9252. } else {
  9253. $prevk = $k;
  9254. }
  9255. $nextk = $k + $cws;
  9256. if (isset($ws['interval'])) {
  9257. if ($cws > 3) {
  9258. $prevint = true;
  9259. } else {
  9260. $prevint = false;
  9261. }
  9262. unset($range[$k]['interval']);
  9263. --$nextk;
  9264. } else {
  9265. $prevint = false;
  9266. }
  9267. }
  9268. // output data
  9269. $w = '';
  9270. foreach ($range as $k => $ws) {
  9271. if (count(array_count_values($ws)) == 1) {
  9272. // interval mode is more compact
  9273. $w .= ' '.$k.' '.($k + count($ws) - 1).' '.$ws[0];
  9274. } else {
  9275. // range mode
  9276. $w .= ' '.$k.' [ '.implode(' ', $ws).' ]';
  9277. }
  9278. }
  9279. return '/W ['.$w.' ]';
  9280. }
  9281. /**
  9282. * Output fonts.
  9283. * @author Nicola Asuni
  9284. * @protected
  9285. */
  9286. protected function _putfonts() {
  9287. $nf = $this->n;
  9288. foreach ($this->diffs as $diff) {
  9289. //Encodings
  9290. $this->_newobj();
  9291. $this->_out('<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.'] >>'."\n".'endobj');
  9292. }
  9293. $mqr = $this->get_mqr();
  9294. $this->set_mqr(false);
  9295. foreach ($this->FontFiles as $file => $info) {
  9296. // search and get font file to embedd
  9297. $fontdir = $info['fontdir'];
  9298. $file = strtolower($file);
  9299. $fontfile = '';
  9300. // search files on various directories
  9301. if (($fontdir !== false) AND file_exists($fontdir.$file)) {
  9302. $fontfile = $fontdir.$file;
  9303. } elseif (file_exists($this->_getfontpath().$file)) {
  9304. $fontfile = $this->_getfontpath().$file;
  9305. } elseif (file_exists($file)) {
  9306. $fontfile = $file;
  9307. }
  9308. if (!$this->empty_string($fontfile)) {
  9309. $font = file_get_contents($fontfile);
  9310. $compressed = (substr($file, -2) == '.z');
  9311. if ((!$compressed) AND (isset($info['length2']))) {
  9312. $header = (ord($font{0}) == 128);
  9313. if ($header) {
  9314. //Strip first binary header
  9315. $font = substr($font, 6);
  9316. }
  9317. if ($header AND (ord($font{$info['length1']}) == 128)) {
  9318. //Strip second binary header
  9319. $font = substr($font, 0, $info['length1']).substr($font, ($info['length1'] + 6));
  9320. }
  9321. } elseif ($info['subset'] AND ((!$compressed) OR ($compressed AND function_exists('gzcompress')))) {
  9322. if ($compressed) {
  9323. // uncompress font
  9324. $font = gzuncompress($font);
  9325. }
  9326. // merge subset characters
  9327. $subsetchars = array(); // used chars
  9328. foreach ($info['fontkeys'] as $fontkey) {
  9329. $fontinfo = $this->getFontBuffer($fontkey);
  9330. $subsetchars += $fontinfo['subsetchars'];
  9331. }
  9332. $font = $this->_getTrueTypeFontSubset($font, $subsetchars);
  9333. if ($compressed) {
  9334. // recompress font
  9335. $font = gzcompress($font);
  9336. }
  9337. }
  9338. $this->_newobj();
  9339. $this->FontFiles[$file]['n'] = $this->n;
  9340. $stream = $this->_getrawstream($font);
  9341. $out = '<< /Length '.strlen($stream);
  9342. if ($compressed) {
  9343. $out .= ' /Filter /FlateDecode';
  9344. }
  9345. $out .= ' /Length1 '.$info['length1'];
  9346. if (isset($info['length2'])) {
  9347. $out .= ' /Length2 '.$info['length2'].' /Length3 0';
  9348. }
  9349. $out .= ' >>';
  9350. $out .= ' stream'."\n".$stream."\n".'endstream';
  9351. $out .= "\n".'endobj';
  9352. $this->_out($out);
  9353. }
  9354. }
  9355. $this->set_mqr($mqr);
  9356. foreach ($this->fontkeys as $k) {
  9357. //Font objects
  9358. $font = $this->getFontBuffer($k);
  9359. $type = $font['type'];
  9360. $name = $font['name'];
  9361. if ($type == 'core') {
  9362. // standard core font
  9363. $out = $this->_getobj($this->font_obj_ids[$k])."\n";
  9364. $out .= '<</Type /Font';
  9365. $out .= ' /Subtype /Type1';
  9366. $out .= ' /BaseFont /'.$name;
  9367. $out .= ' /Name /F'.$font['i'];
  9368. if ((strtolower($name) != 'symbol') AND (strtolower($name) != 'zapfdingbats')) {
  9369. $out .= ' /Encoding /WinAnsiEncoding';
  9370. }
  9371. if ($k == 'helvetica') {
  9372. // add default font for annotations
  9373. $this->annotation_fonts[$k] = $font['i'];
  9374. }
  9375. $out .= ' >>';
  9376. $out .= "\n".'endobj';
  9377. $this->_out($out);
  9378. } elseif (($type == 'Type1') OR ($type == 'TrueType')) {
  9379. // additional Type1 or TrueType font
  9380. $out = $this->_getobj($this->font_obj_ids[$k])."\n";
  9381. $out .= '<</Type /Font';
  9382. $out .= ' /Subtype /'.$type;
  9383. $out .= ' /BaseFont /'.$name;
  9384. $out .= ' /Name /F'.$font['i'];
  9385. $out .= ' /FirstChar 32 /LastChar 255';
  9386. $out .= ' /Widths '.($this->n + 1).' 0 R';
  9387. $out .= ' /FontDescriptor '.($this->n + 2).' 0 R';
  9388. if ($font['enc']) {
  9389. if (isset($font['diff'])) {
  9390. $out .= ' /Encoding '.($nf + $font['diff']).' 0 R';
  9391. } else {
  9392. $out .= ' /Encoding /WinAnsiEncoding';
  9393. }
  9394. }
  9395. $out .= ' >>';
  9396. $out .= "\n".'endobj';
  9397. $this->_out($out);
  9398. // Widths
  9399. $this->_newobj();
  9400. $cw = &$font['cw'];
  9401. $s = '[';
  9402. for ($i = 32; $i < 256; ++$i) {
  9403. $s .= $cw[$i].' ';
  9404. }
  9405. $s .= ']';
  9406. $s .= "\n".'endobj';
  9407. $this->_out($s);
  9408. //Descriptor
  9409. $this->_newobj();
  9410. $s = '<</Type /FontDescriptor /FontName /'.$name;
  9411. foreach ($font['desc'] as $fdk => $fdv) {
  9412. if(is_float($fdv)) {
  9413. $fdv = sprintf('%.3F', $fdv);
  9414. }
  9415. $s .= ' /'.$fdk.' '.$fdv.'';
  9416. }
  9417. if (!$this->empty_string($font['file'])) {
  9418. $s .= ' /FontFile'.($type == 'Type1' ? '' : '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R';
  9419. }
  9420. $s .= '>>';
  9421. $s .= "\n".'endobj';
  9422. $this->_out($s);
  9423. } else {
  9424. // additional types
  9425. $mtd = '_put'.strtolower($type);
  9426. if (!method_exists($this, $mtd)) {
  9427. $this->Error('Unsupported font type: '.$type);
  9428. }
  9429. $this->$mtd($font);
  9430. }
  9431. }
  9432. }
  9433. /**
  9434. * Adds unicode fonts.<br>
  9435. * Based on PDF Reference 1.3 (section 5)
  9436. * @param $font (array) font data
  9437. * @protected
  9438. * @author Nicola Asuni
  9439. * @since 1.52.0.TC005 (2005-01-05)
  9440. */
  9441. protected function _puttruetypeunicode($font) {
  9442. $fontname = '';
  9443. if ($font['subset']) {
  9444. // change name for font subsetting
  9445. $subtag = sprintf('%06u', $font['i']);
  9446. $subtag = strtr($subtag, '0123456789', 'ABCDEFGHIJ');
  9447. $fontname .= $subtag.'+';
  9448. }
  9449. $fontname .= $font['name'];
  9450. // Type0 Font
  9451. // A composite font composed of other fonts, organized hierarchically
  9452. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  9453. $out .= '<< /Type /Font';
  9454. $out .= ' /Subtype /Type0';
  9455. $out .= ' /BaseFont /'.$fontname;
  9456. $out .= ' /Name /F'.$font['i'];
  9457. $out .= ' /Encoding /'.$font['enc'];
  9458. $out .= ' /ToUnicode '.($this->n + 1).' 0 R';
  9459. $out .= ' /DescendantFonts ['.($this->n + 2).' 0 R]';
  9460. $out .= ' >>';
  9461. $out .= "\n".'endobj';
  9462. $this->_out($out);
  9463. // ToUnicode map for Identity-H
  9464. $stream = "/CIDInit /ProcSet findresource begin\n";
  9465. $stream .= "12 dict begin\n";
  9466. $stream .= "begincmap\n";
  9467. $stream .= "/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def\n";
  9468. $stream .= "/CMapName /Adobe-Identity-UCS def\n";
  9469. $stream .= "/CMapType 2 def\n";
  9470. $stream .= "/WMode 0 def\n";
  9471. $stream .= "1 begincodespacerange\n";
  9472. $stream .= "<0000> <FFFF>\n";
  9473. $stream .= "endcodespacerange\n";
  9474. $stream .= "100 beginbfrange\n";
  9475. $stream .= "<0000> <00ff> <0000>\n";
  9476. $stream .= "<0100> <01ff> <0100>\n";
  9477. $stream .= "<0200> <02ff> <0200>\n";
  9478. $stream .= "<0300> <03ff> <0300>\n";
  9479. $stream .= "<0400> <04ff> <0400>\n";
  9480. $stream .= "<0500> <05ff> <0500>\n";
  9481. $stream .= "<0600> <06ff> <0600>\n";
  9482. $stream .= "<0700> <07ff> <0700>\n";
  9483. $stream .= "<0800> <08ff> <0800>\n";
  9484. $stream .= "<0900> <09ff> <0900>\n";
  9485. $stream .= "<0a00> <0aff> <0a00>\n";
  9486. $stream .= "<0b00> <0bff> <0b00>\n";
  9487. $stream .= "<0c00> <0cff> <0c00>\n";
  9488. $stream .= "<0d00> <0dff> <0d00>\n";
  9489. $stream .= "<0e00> <0eff> <0e00>\n";
  9490. $stream .= "<0f00> <0fff> <0f00>\n";
  9491. $stream .= "<1000> <10ff> <1000>\n";
  9492. $stream .= "<1100> <11ff> <1100>\n";
  9493. $stream .= "<1200> <12ff> <1200>\n";
  9494. $stream .= "<1300> <13ff> <1300>\n";
  9495. $stream .= "<1400> <14ff> <1400>\n";
  9496. $stream .= "<1500> <15ff> <1500>\n";
  9497. $stream .= "<1600> <16ff> <1600>\n";
  9498. $stream .= "<1700> <17ff> <1700>\n";
  9499. $stream .= "<1800> <18ff> <1800>\n";
  9500. $stream .= "<1900> <19ff> <1900>\n";
  9501. $stream .= "<1a00> <1aff> <1a00>\n";
  9502. $stream .= "<1b00> <1bff> <1b00>\n";
  9503. $stream .= "<1c00> <1cff> <1c00>\n";
  9504. $stream .= "<1d00> <1dff> <1d00>\n";
  9505. $stream .= "<1e00> <1eff> <1e00>\n";
  9506. $stream .= "<1f00> <1fff> <1f00>\n";
  9507. $stream .= "<2000> <20ff> <2000>\n";
  9508. $stream .= "<2100> <21ff> <2100>\n";
  9509. $stream .= "<2200> <22ff> <2200>\n";
  9510. $stream .= "<2300> <23ff> <2300>\n";
  9511. $stream .= "<2400> <24ff> <2400>\n";
  9512. $stream .= "<2500> <25ff> <2500>\n";
  9513. $stream .= "<2600> <26ff> <2600>\n";
  9514. $stream .= "<2700> <27ff> <2700>\n";
  9515. $stream .= "<2800> <28ff> <2800>\n";
  9516. $stream .= "<2900> <29ff> <2900>\n";
  9517. $stream .= "<2a00> <2aff> <2a00>\n";
  9518. $stream .= "<2b00> <2bff> <2b00>\n";
  9519. $stream .= "<2c00> <2cff> <2c00>\n";
  9520. $stream .= "<2d00> <2dff> <2d00>\n";
  9521. $stream .= "<2e00> <2eff> <2e00>\n";
  9522. $stream .= "<2f00> <2fff> <2f00>\n";
  9523. $stream .= "<3000> <30ff> <3000>\n";
  9524. $stream .= "<3100> <31ff> <3100>\n";
  9525. $stream .= "<3200> <32ff> <3200>\n";
  9526. $stream .= "<3300> <33ff> <3300>\n";
  9527. $stream .= "<3400> <34ff> <3400>\n";
  9528. $stream .= "<3500> <35ff> <3500>\n";
  9529. $stream .= "<3600> <36ff> <3600>\n";
  9530. $stream .= "<3700> <37ff> <3700>\n";
  9531. $stream .= "<3800> <38ff> <3800>\n";
  9532. $stream .= "<3900> <39ff> <3900>\n";
  9533. $stream .= "<3a00> <3aff> <3a00>\n";
  9534. $stream .= "<3b00> <3bff> <3b00>\n";
  9535. $stream .= "<3c00> <3cff> <3c00>\n";
  9536. $stream .= "<3d00> <3dff> <3d00>\n";
  9537. $stream .= "<3e00> <3eff> <3e00>\n";
  9538. $stream .= "<3f00> <3fff> <3f00>\n";
  9539. $stream .= "<4000> <40ff> <4000>\n";
  9540. $stream .= "<4100> <41ff> <4100>\n";
  9541. $stream .= "<4200> <42ff> <4200>\n";
  9542. $stream .= "<4300> <43ff> <4300>\n";
  9543. $stream .= "<4400> <44ff> <4400>\n";
  9544. $stream .= "<4500> <45ff> <4500>\n";
  9545. $stream .= "<4600> <46ff> <4600>\n";
  9546. $stream .= "<4700> <47ff> <4700>\n";
  9547. $stream .= "<4800> <48ff> <4800>\n";
  9548. $stream .= "<4900> <49ff> <4900>\n";
  9549. $stream .= "<4a00> <4aff> <4a00>\n";
  9550. $stream .= "<4b00> <4bff> <4b00>\n";
  9551. $stream .= "<4c00> <4cff> <4c00>\n";
  9552. $stream .= "<4d00> <4dff> <4d00>\n";
  9553. $stream .= "<4e00> <4eff> <4e00>\n";
  9554. $stream .= "<4f00> <4fff> <4f00>\n";
  9555. $stream .= "<5000> <50ff> <5000>\n";
  9556. $stream .= "<5100> <51ff> <5100>\n";
  9557. $stream .= "<5200> <52ff> <5200>\n";
  9558. $stream .= "<5300> <53ff> <5300>\n";
  9559. $stream .= "<5400> <54ff> <5400>\n";
  9560. $stream .= "<5500> <55ff> <5500>\n";
  9561. $stream .= "<5600> <56ff> <5600>\n";
  9562. $stream .= "<5700> <57ff> <5700>\n";
  9563. $stream .= "<5800> <58ff> <5800>\n";
  9564. $stream .= "<5900> <59ff> <5900>\n";
  9565. $stream .= "<5a00> <5aff> <5a00>\n";
  9566. $stream .= "<5b00> <5bff> <5b00>\n";
  9567. $stream .= "<5c00> <5cff> <5c00>\n";
  9568. $stream .= "<5d00> <5dff> <5d00>\n";
  9569. $stream .= "<5e00> <5eff> <5e00>\n";
  9570. $stream .= "<5f00> <5fff> <5f00>\n";
  9571. $stream .= "<6000> <60ff> <6000>\n";
  9572. $stream .= "<6100> <61ff> <6100>\n";
  9573. $stream .= "<6200> <62ff> <6200>\n";
  9574. $stream .= "<6300> <63ff> <6300>\n";
  9575. $stream .= "endbfrange\n";
  9576. $stream .= "100 beginbfrange\n";
  9577. $stream .= "<6400> <64ff> <6400>\n";
  9578. $stream .= "<6500> <65ff> <6500>\n";
  9579. $stream .= "<6600> <66ff> <6600>\n";
  9580. $stream .= "<6700> <67ff> <6700>\n";
  9581. $stream .= "<6800> <68ff> <6800>\n";
  9582. $stream .= "<6900> <69ff> <6900>\n";
  9583. $stream .= "<6a00> <6aff> <6a00>\n";
  9584. $stream .= "<6b00> <6bff> <6b00>\n";
  9585. $stream .= "<6c00> <6cff> <6c00>\n";
  9586. $stream .= "<6d00> <6dff> <6d00>\n";
  9587. $stream .= "<6e00> <6eff> <6e00>\n";
  9588. $stream .= "<6f00> <6fff> <6f00>\n";
  9589. $stream .= "<7000> <70ff> <7000>\n";
  9590. $stream .= "<7100> <71ff> <7100>\n";
  9591. $stream .= "<7200> <72ff> <7200>\n";
  9592. $stream .= "<7300> <73ff> <7300>\n";
  9593. $stream .= "<7400> <74ff> <7400>\n";
  9594. $stream .= "<7500> <75ff> <7500>\n";
  9595. $stream .= "<7600> <76ff> <7600>\n";
  9596. $stream .= "<7700> <77ff> <7700>\n";
  9597. $stream .= "<7800> <78ff> <7800>\n";
  9598. $stream .= "<7900> <79ff> <7900>\n";
  9599. $stream .= "<7a00> <7aff> <7a00>\n";
  9600. $stream .= "<7b00> <7bff> <7b00>\n";
  9601. $stream .= "<7c00> <7cff> <7c00>\n";
  9602. $stream .= "<7d00> <7dff> <7d00>\n";
  9603. $stream .= "<7e00> <7eff> <7e00>\n";
  9604. $stream .= "<7f00> <7fff> <7f00>\n";
  9605. $stream .= "<8000> <80ff> <8000>\n";
  9606. $stream .= "<8100> <81ff> <8100>\n";
  9607. $stream .= "<8200> <82ff> <8200>\n";
  9608. $stream .= "<8300> <83ff> <8300>\n";
  9609. $stream .= "<8400> <84ff> <8400>\n";
  9610. $stream .= "<8500> <85ff> <8500>\n";
  9611. $stream .= "<8600> <86ff> <8600>\n";
  9612. $stream .= "<8700> <87ff> <8700>\n";
  9613. $stream .= "<8800> <88ff> <8800>\n";
  9614. $stream .= "<8900> <89ff> <8900>\n";
  9615. $stream .= "<8a00> <8aff> <8a00>\n";
  9616. $stream .= "<8b00> <8bff> <8b00>\n";
  9617. $stream .= "<8c00> <8cff> <8c00>\n";
  9618. $stream .= "<8d00> <8dff> <8d00>\n";
  9619. $stream .= "<8e00> <8eff> <8e00>\n";
  9620. $stream .= "<8f00> <8fff> <8f00>\n";
  9621. $stream .= "<9000> <90ff> <9000>\n";
  9622. $stream .= "<9100> <91ff> <9100>\n";
  9623. $stream .= "<9200> <92ff> <9200>\n";
  9624. $stream .= "<9300> <93ff> <9300>\n";
  9625. $stream .= "<9400> <94ff> <9400>\n";
  9626. $stream .= "<9500> <95ff> <9500>\n";
  9627. $stream .= "<9600> <96ff> <9600>\n";
  9628. $stream .= "<9700> <97ff> <9700>\n";
  9629. $stream .= "<9800> <98ff> <9800>\n";
  9630. $stream .= "<9900> <99ff> <9900>\n";
  9631. $stream .= "<9a00> <9aff> <9a00>\n";
  9632. $stream .= "<9b00> <9bff> <9b00>\n";
  9633. $stream .= "<9c00> <9cff> <9c00>\n";
  9634. $stream .= "<9d00> <9dff> <9d00>\n";
  9635. $stream .= "<9e00> <9eff> <9e00>\n";
  9636. $stream .= "<9f00> <9fff> <9f00>\n";
  9637. $stream .= "<a000> <a0ff> <a000>\n";
  9638. $stream .= "<a100> <a1ff> <a100>\n";
  9639. $stream .= "<a200> <a2ff> <a200>\n";
  9640. $stream .= "<a300> <a3ff> <a300>\n";
  9641. $stream .= "<a400> <a4ff> <a400>\n";
  9642. $stream .= "<a500> <a5ff> <a500>\n";
  9643. $stream .= "<a600> <a6ff> <a600>\n";
  9644. $stream .= "<a700> <a7ff> <a700>\n";
  9645. $stream .= "<a800> <a8ff> <a800>\n";
  9646. $stream .= "<a900> <a9ff> <a900>\n";
  9647. $stream .= "<aa00> <aaff> <aa00>\n";
  9648. $stream .= "<ab00> <abff> <ab00>\n";
  9649. $stream .= "<ac00> <acff> <ac00>\n";
  9650. $stream .= "<ad00> <adff> <ad00>\n";
  9651. $stream .= "<ae00> <aeff> <ae00>\n";
  9652. $stream .= "<af00> <afff> <af00>\n";
  9653. $stream .= "<b000> <b0ff> <b000>\n";
  9654. $stream .= "<b100> <b1ff> <b100>\n";
  9655. $stream .= "<b200> <b2ff> <b200>\n";
  9656. $stream .= "<b300> <b3ff> <b300>\n";
  9657. $stream .= "<b400> <b4ff> <b400>\n";
  9658. $stream .= "<b500> <b5ff> <b500>\n";
  9659. $stream .= "<b600> <b6ff> <b600>\n";
  9660. $stream .= "<b700> <b7ff> <b700>\n";
  9661. $stream .= "<b800> <b8ff> <b800>\n";
  9662. $stream .= "<b900> <b9ff> <b900>\n";
  9663. $stream .= "<ba00> <baff> <ba00>\n";
  9664. $stream .= "<bb00> <bbff> <bb00>\n";
  9665. $stream .= "<bc00> <bcff> <bc00>\n";
  9666. $stream .= "<bd00> <bdff> <bd00>\n";
  9667. $stream .= "<be00> <beff> <be00>\n";
  9668. $stream .= "<bf00> <bfff> <bf00>\n";
  9669. $stream .= "<c000> <c0ff> <c000>\n";
  9670. $stream .= "<c100> <c1ff> <c100>\n";
  9671. $stream .= "<c200> <c2ff> <c200>\n";
  9672. $stream .= "<c300> <c3ff> <c300>\n";
  9673. $stream .= "<c400> <c4ff> <c400>\n";
  9674. $stream .= "<c500> <c5ff> <c500>\n";
  9675. $stream .= "<c600> <c6ff> <c600>\n";
  9676. $stream .= "<c700> <c7ff> <c700>\n";
  9677. $stream .= "endbfrange\n";
  9678. $stream .= "56 beginbfrange\n";
  9679. $stream .= "<c800> <c8ff> <c800>\n";
  9680. $stream .= "<c900> <c9ff> <c900>\n";
  9681. $stream .= "<ca00> <caff> <ca00>\n";
  9682. $stream .= "<cb00> <cbff> <cb00>\n";
  9683. $stream .= "<cc00> <ccff> <cc00>\n";
  9684. $stream .= "<cd00> <cdff> <cd00>\n";
  9685. $stream .= "<ce00> <ceff> <ce00>\n";
  9686. $stream .= "<cf00> <cfff> <cf00>\n";
  9687. $stream .= "<d000> <d0ff> <d000>\n";
  9688. $stream .= "<d100> <d1ff> <d100>\n";
  9689. $stream .= "<d200> <d2ff> <d200>\n";
  9690. $stream .= "<d300> <d3ff> <d300>\n";
  9691. $stream .= "<d400> <d4ff> <d400>\n";
  9692. $stream .= "<d500> <d5ff> <d500>\n";
  9693. $stream .= "<d600> <d6ff> <d600>\n";
  9694. $stream .= "<d700> <d7ff> <d700>\n";
  9695. $stream .= "<d800> <d8ff> <d800>\n";
  9696. $stream .= "<d900> <d9ff> <d900>\n";
  9697. $stream .= "<da00> <daff> <da00>\n";
  9698. $stream .= "<db00> <dbff> <db00>\n";
  9699. $stream .= "<dc00> <dcff> <dc00>\n";
  9700. $stream .= "<dd00> <ddff> <dd00>\n";
  9701. $stream .= "<de00> <deff> <de00>\n";
  9702. $stream .= "<df00> <dfff> <df00>\n";
  9703. $stream .= "<e000> <e0ff> <e000>\n";
  9704. $stream .= "<e100> <e1ff> <e100>\n";
  9705. $stream .= "<e200> <e2ff> <e200>\n";
  9706. $stream .= "<e300> <e3ff> <e300>\n";
  9707. $stream .= "<e400> <e4ff> <e400>\n";
  9708. $stream .= "<e500> <e5ff> <e500>\n";
  9709. $stream .= "<e600> <e6ff> <e600>\n";
  9710. $stream .= "<e700> <e7ff> <e700>\n";
  9711. $stream .= "<e800> <e8ff> <e800>\n";
  9712. $stream .= "<e900> <e9ff> <e900>\n";
  9713. $stream .= "<ea00> <eaff> <ea00>\n";
  9714. $stream .= "<eb00> <ebff> <eb00>\n";
  9715. $stream .= "<ec00> <ecff> <ec00>\n";
  9716. $stream .= "<ed00> <edff> <ed00>\n";
  9717. $stream .= "<ee00> <eeff> <ee00>\n";
  9718. $stream .= "<ef00> <efff> <ef00>\n";
  9719. $stream .= "<f000> <f0ff> <f000>\n";
  9720. $stream .= "<f100> <f1ff> <f100>\n";
  9721. $stream .= "<f200> <f2ff> <f200>\n";
  9722. $stream .= "<f300> <f3ff> <f300>\n";
  9723. $stream .= "<f400> <f4ff> <f400>\n";
  9724. $stream .= "<f500> <f5ff> <f500>\n";
  9725. $stream .= "<f600> <f6ff> <f600>\n";
  9726. $stream .= "<f700> <f7ff> <f700>\n";
  9727. $stream .= "<f800> <f8ff> <f800>\n";
  9728. $stream .= "<f900> <f9ff> <f900>\n";
  9729. $stream .= "<fa00> <faff> <fa00>\n";
  9730. $stream .= "<fb00> <fbff> <fb00>\n";
  9731. $stream .= "<fc00> <fcff> <fc00>\n";
  9732. $stream .= "<fd00> <fdff> <fd00>\n";
  9733. $stream .= "<fe00> <feff> <fe00>\n";
  9734. $stream .= "<ff00> <ffff> <ff00>\n";
  9735. $stream .= "endbfrange\n";
  9736. $stream .= "endcmap\n";
  9737. $stream .= "CMapName currentdict /CMap defineresource pop\n";
  9738. $stream .= "end\n";
  9739. $stream .= "end";
  9740. // ToUnicode Object
  9741. $this->_newobj();
  9742. $stream = ($this->compress) ? gzcompress($stream) : $stream;
  9743. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  9744. $stream = $this->_getrawstream($stream);
  9745. $this->_out('<<'.$filter.'/Length '.strlen($stream).'>> stream'."\n".$stream."\n".'endstream'."\n".'endobj');
  9746. // CIDFontType2
  9747. // A CIDFont whose glyph descriptions are based on TrueType font technology
  9748. $oid = $this->_newobj();
  9749. $out = '<< /Type /Font';
  9750. $out .= ' /Subtype /CIDFontType2';
  9751. $out .= ' /BaseFont /'.$fontname;
  9752. // A dictionary containing entries that define the character collection of the CIDFont.
  9753. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  9754. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  9755. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  9756. $out .= ' /CIDSystemInfo << '.$cidinfo.' >>';
  9757. $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
  9758. $out .= ' /DW '.$font['dw']; // default width
  9759. $out .= "\n".$this->_putfontwidths($font, 0);
  9760. if (isset($font['ctg']) AND (!$this->empty_string($font['ctg']))) {
  9761. $out .= "\n".'/CIDToGIDMap '.($this->n + 2).' 0 R';
  9762. }
  9763. $out .= ' >>';
  9764. $out .= "\n".'endobj';
  9765. $this->_out($out);
  9766. // Font descriptor
  9767. // A font descriptor describing the CIDFont default metrics other than its glyph widths
  9768. $this->_newobj();
  9769. $out = '<< /Type /FontDescriptor';
  9770. $out .= ' /FontName /'.$fontname;
  9771. foreach ($font['desc'] as $key => $value) {
  9772. if(is_float($value)) {
  9773. $value = sprintf('%.3F', $value);
  9774. }
  9775. $out .= ' /'.$key.' '.$value;
  9776. }
  9777. $fontdir = false;
  9778. if (!$this->empty_string($font['file'])) {
  9779. // A stream containing a TrueType font
  9780. $out .= ' /FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R';
  9781. $fontdir = $this->FontFiles[$font['file']]['fontdir'];
  9782. }
  9783. $out .= ' >>';
  9784. $out .= "\n".'endobj';
  9785. $this->_out($out);
  9786. if (isset($font['ctg']) AND (!$this->empty_string($font['ctg']))) {
  9787. $this->_newobj();
  9788. // Embed CIDToGIDMap
  9789. // A specification of the mapping from CIDs to glyph indices
  9790. // search and get CTG font file to embedd
  9791. $ctgfile = strtolower($font['ctg']);
  9792. // search and get ctg font file to embedd
  9793. $fontfile = '';
  9794. // search files on various directories
  9795. if (($fontdir !== false) AND file_exists($fontdir.$ctgfile)) {
  9796. $fontfile = $fontdir.$ctgfile;
  9797. } elseif (file_exists($this->_getfontpath().$ctgfile)) {
  9798. $fontfile = $this->_getfontpath().$ctgfile;
  9799. } elseif (file_exists($ctgfile)) {
  9800. $fontfile = $ctgfile;
  9801. }
  9802. if ($this->empty_string($fontfile)) {
  9803. $this->Error('Font file not found: '.$ctgfile);
  9804. }
  9805. $stream = $this->_getrawstream(file_get_contents($fontfile));
  9806. $out = '<< /Length '.strlen($stream).'';
  9807. if (substr($fontfile, -2) == '.z') { // check file extension
  9808. // Decompresses data encoded using the public-domain
  9809. // zlib/deflate compression method, reproducing the
  9810. // original text or binary data
  9811. $out .= ' /Filter /FlateDecode';
  9812. }
  9813. $out .= ' >>';
  9814. $out .= ' stream'."\n".$stream."\n".'endstream';
  9815. $out .= "\n".'endobj';
  9816. $this->_out($out);
  9817. }
  9818. }
  9819. /**
  9820. * Output CID-0 fonts.
  9821. * A Type 0 CIDFont contains glyph descriptions based on the Adobe Type 1 font format
  9822. * @param $font (array) font data
  9823. * @protected
  9824. * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
  9825. * @since 3.2.000 (2008-06-23)
  9826. */
  9827. protected function _putcidfont0($font) {
  9828. $cidoffset = 0;
  9829. if (!isset($font['cw'][1])) {
  9830. $cidoffset = 31;
  9831. }
  9832. if (isset($font['cidinfo']['uni2cid'])) {
  9833. // convert unicode to cid.
  9834. $uni2cid = $font['cidinfo']['uni2cid'];
  9835. $cw = array();
  9836. foreach ($font['cw'] as $uni => $width) {
  9837. if (isset($uni2cid[$uni])) {
  9838. $cw[($uni2cid[$uni] + $cidoffset)] = $width;
  9839. } elseif ($uni < 256) {
  9840. $cw[$uni] = $width;
  9841. } // else unknown character
  9842. }
  9843. $font = array_merge($font, array('cw' => $cw));
  9844. }
  9845. $name = $font['name'];
  9846. $enc = $font['enc'];
  9847. if ($enc) {
  9848. $longname = $name.'-'.$enc;
  9849. } else {
  9850. $longname = $name;
  9851. }
  9852. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  9853. $out .= '<</Type /Font';
  9854. $out .= ' /Subtype /Type0';
  9855. $out .= ' /BaseFont /'.$longname;
  9856. $out .= ' /Name /F'.$font['i'];
  9857. if ($enc) {
  9858. $out .= ' /Encoding /'.$enc;
  9859. }
  9860. $out .= ' /DescendantFonts ['.($this->n + 1).' 0 R]';
  9861. $out .= ' >>';
  9862. $out .= "\n".'endobj';
  9863. $this->_out($out);
  9864. $oid = $this->_newobj();
  9865. $out = '<</Type /Font';
  9866. $out .= ' /Subtype /CIDFontType0';
  9867. $out .= ' /BaseFont /'.$name;
  9868. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  9869. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  9870. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  9871. $out .= ' /CIDSystemInfo <<'.$cidinfo.'>>';
  9872. $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
  9873. $out .= ' /DW '.$font['dw'];
  9874. $out .= "\n".$this->_putfontwidths($font, $cidoffset);
  9875. $out .= ' >>';
  9876. $out .= "\n".'endobj';
  9877. $this->_out($out);
  9878. $this->_newobj();
  9879. $s = '<</Type /FontDescriptor /FontName /'.$name;
  9880. foreach ($font['desc'] as $k => $v) {
  9881. if ($k != 'Style') {
  9882. if(is_float($v)) {
  9883. $v = sprintf('%.3F', $v);
  9884. }
  9885. $s .= ' /'.$k.' '.$v.'';
  9886. }
  9887. }
  9888. $s .= '>>';
  9889. $s .= "\n".'endobj';
  9890. $this->_out($s);
  9891. }
  9892. /**
  9893. * Output images.
  9894. * @protected
  9895. */
  9896. protected function _putimages() {
  9897. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  9898. foreach ($this->imagekeys as $file) {
  9899. $info = $this->getImageBuffer($file);
  9900. $oid = $this->_newobj();
  9901. $this->xobjects['I'.$info['i']] = array('n' => $oid);
  9902. $this->setImageSubBuffer($file, 'n', $this->n);
  9903. $out = '<</Type /XObject';
  9904. $out .= ' /Subtype /Image';
  9905. $out .= ' /Width '.$info['w'];
  9906. $out .= ' /Height '.$info['h'];
  9907. if (array_key_exists('masked', $info)) {
  9908. $out .= ' /SMask '.($this->n - 1).' 0 R';
  9909. }
  9910. if ($info['cs'] == 'Indexed') {
  9911. $out .= ' /ColorSpace [/Indexed /DeviceRGB '.((strlen($info['pal']) / 3) - 1).' '.($this->n + 1).' 0 R]';
  9912. } else {
  9913. $out .= ' /ColorSpace /'.$info['cs'];
  9914. if ($info['cs'] == 'DeviceCMYK') {
  9915. $out .= ' /Decode [1 0 1 0 1 0 1 0]';
  9916. }
  9917. }
  9918. $out .= ' /BitsPerComponent '.$info['bpc'];
  9919. if (isset($info['f'])) {
  9920. $out .= ' /Filter /'.$info['f'];
  9921. }
  9922. if (isset($info['parms'])) {
  9923. $out .= ' '.$info['parms'];
  9924. }
  9925. if (isset($info['trns']) AND is_array($info['trns'])) {
  9926. $trns='';
  9927. $count_info = count($info['trns']);
  9928. for ($i=0; $i < $count_info; ++$i) {
  9929. $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
  9930. }
  9931. $out .= ' /Mask ['.$trns.']';
  9932. }
  9933. $stream = $this->_getrawstream($info['data']);
  9934. $out .= ' /Length '.strlen($stream).' >>';
  9935. $out .= ' stream'."\n".$stream."\n".'endstream';
  9936. $out .= "\n".'endobj';
  9937. $this->_out($out);
  9938. //Palette
  9939. if ($info['cs'] == 'Indexed') {
  9940. $this->_newobj();
  9941. $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  9942. $pal = $this->_getrawstream($pal);
  9943. $this->_out('<<'.$filter.'/Length '.strlen($pal).'>> stream'."\n".$pal."\n".'endstream'."\n".'endobj');
  9944. }
  9945. }
  9946. }
  9947. /**
  9948. * Output Form XObjects Templates.
  9949. * @author Nicola Asuni
  9950. * @since 5.8.017 (2010-08-24)
  9951. * @protected
  9952. * @see startTemplate(), endTemplate(), printTemplate()
  9953. */
  9954. protected function _putxobjects() {
  9955. foreach ($this->xobjects as $key => $data) {
  9956. if (isset($data['outdata'])) {
  9957. $stream = trim($data['outdata']);
  9958. $out = $this->_getobj($data['n'])."\n";
  9959. $out .= '<<';
  9960. $out .= ' /Type /XObject';
  9961. $out .= ' /Subtype /Form';
  9962. $out .= ' /FormType 1';
  9963. if ($this->compress) {
  9964. $stream = gzcompress($stream);
  9965. $out .= ' /Filter /FlateDecode';
  9966. }
  9967. $out .= sprintf(' /BBox [%.2F %.2F %.2F %.2F]', ($data['x'] * $this->k), (-$data['y'] * $this->k), (($data['w'] + $data['x']) * $this->k), (($data['h'] - $data['y']) * $this->k));
  9968. $out .= ' /Matrix [1 0 0 1 0 0]';
  9969. $out .= ' /Resources <<';
  9970. $out .= ' /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  9971. // fonts
  9972. if (!empty($data['fonts'])) {
  9973. $out .= ' /Font <<';
  9974. foreach ($data['fonts'] as $fontkey => $fontid) {
  9975. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  9976. }
  9977. $out .= ' >>';
  9978. }
  9979. // images or nested xobjects
  9980. if (!empty($data['images']) OR !empty($data['xobjects'])) {
  9981. $out .= ' /XObject <<';
  9982. foreach ($data['images'] as $imgid) {
  9983. $out .= ' /I'.$imgid.' '.$this->xobjects['I'.$imgid]['n'].' 0 R';
  9984. }
  9985. foreach ($data['xobjects'] as $sub_id => $sub_objid) {
  9986. $out .= ' /'.$sub_id.' '.$sub_objid['n'].' 0 R';
  9987. }
  9988. $out .= ' >>';
  9989. }
  9990. $out .= ' >>';
  9991. $stream = $this->_getrawstream($stream);
  9992. $out .= ' /Length '.strlen($stream);
  9993. $out .= ' >>';
  9994. $out .= ' stream'."\n".$stream."\n".'endstream';
  9995. $out .= "\n".'endobj';
  9996. $this->_out($out);
  9997. }
  9998. }
  9999. }
  10000. /**
  10001. * Output Spot Colors Resources.
  10002. * @protected
  10003. * @since 4.0.024 (2008-09-12)
  10004. */
  10005. protected function _putspotcolors() {
  10006. foreach ($this->spot_colors as $name => $color) {
  10007. $this->_newobj();
  10008. $this->spot_colors[$name]['n'] = $this->n;
  10009. $out = '[/Separation /'.str_replace(' ', '#20', $name);
  10010. $out .= ' /DeviceCMYK <<';
  10011. $out .= ' /Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0]';
  10012. $out .= ' '.sprintf('/C1 [%.4F %.4F %.4F %.4F] ', ($color['c'] / 100), ($color['m'] / 100), ($color['y'] / 100), ($color['k'] / 100));
  10013. $out .= ' /FunctionType 2 /Domain [0 1] /N 1>>]';
  10014. $out .= "\n".'endobj';
  10015. $this->_out($out);
  10016. }
  10017. }
  10018. /**
  10019. * Return XObjects Dictionary.
  10020. * @return string XObjects dictionary
  10021. * @protected
  10022. * @since 5.8.014 (2010-08-23)
  10023. */
  10024. protected function _getxobjectdict() {
  10025. $out = '';
  10026. foreach ($this->xobjects as $id => $objid) {
  10027. $out .= ' /'.$id.' '.$objid['n'].' 0 R';
  10028. }
  10029. return $out;
  10030. }
  10031. /**
  10032. * Output Resources Dictionary.
  10033. * @protected
  10034. */
  10035. protected function _putresourcedict() {
  10036. $out = $this->_getobj(2)."\n";
  10037. $out .= '<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  10038. $out .= ' /Font <<';
  10039. foreach ($this->fontkeys as $fontkey) {
  10040. $font = $this->getFontBuffer($fontkey);
  10041. $out .= ' /F'.$font['i'].' '.$font['n'].' 0 R';
  10042. }
  10043. $out .= ' >>';
  10044. $out .= ' /XObject <<';
  10045. $out .= $this->_getxobjectdict();
  10046. $out .= ' >>';
  10047. // visibility
  10048. if ($this->pdflayers) {
  10049. $out .= ' /Properties <</OC1 '.$this->n_ocg_print.' 0 R /OC2 '.$this->n_ocg_view.' 0 R>>';
  10050. }
  10051. // transparency
  10052. $out .= ' /ExtGState <<';
  10053. foreach ($this->extgstates as $k => $extgstate) {
  10054. if (isset($extgstate['name'])) {
  10055. $out .= ' /'.$extgstate['name'];
  10056. } else {
  10057. $out .= ' /GS'.$k;
  10058. }
  10059. $out .= ' '.$extgstate['n'].' 0 R';
  10060. }
  10061. $out .= ' >>';
  10062. // gradient patterns
  10063. if (isset($this->gradients) AND (count($this->gradients) > 0)) {
  10064. $out .= ' /Pattern <<';
  10065. foreach ($this->gradients as $id => $grad) {
  10066. $out .= ' /p'.$id.' '.$grad['pattern'].' 0 R';
  10067. }
  10068. $out .= ' >>';
  10069. }
  10070. // gradient shadings
  10071. if (isset($this->gradients) AND (count($this->gradients) > 0)) {
  10072. $out .= ' /Shading <<';
  10073. foreach ($this->gradients as $id => $grad) {
  10074. $out .= ' /Sh'.$id.' '.$grad['id'].' 0 R';
  10075. }
  10076. $out .= ' >>';
  10077. }
  10078. // spot colors
  10079. if (isset($this->spot_colors) AND (count($this->spot_colors) > 0)) {
  10080. $out .= ' /ColorSpace <<';
  10081. foreach ($this->spot_colors as $color) {
  10082. $out .= ' /CS'.$color['i'].' '.$color['n'].' 0 R';
  10083. }
  10084. $out .= ' >>';
  10085. }
  10086. $out .= ' >>';
  10087. $out .= "\n".'endobj';
  10088. $this->_out($out);
  10089. }
  10090. /**
  10091. * Output Resources.
  10092. * @protected
  10093. */
  10094. protected function _putresources() {
  10095. $this->_putextgstates();
  10096. $this->_putocg();
  10097. $this->_putfonts();
  10098. $this->_putimages();
  10099. $this->_putxobjects();
  10100. $this->_putspotcolors();
  10101. $this->_putshaders();
  10102. $this->_putresourcedict();
  10103. $this->_putbookmarks();
  10104. $this->_putEmbeddedFiles();
  10105. $this->_putannotsobjs();
  10106. $this->_putjavascript();
  10107. $this->_putencryption();
  10108. }
  10109. /**
  10110. * Adds some Metadata information (Document Information Dictionary)
  10111. * (see Chapter 14.3.3 Document Information Dictionary of PDF32000_2008.pdf Reference)
  10112. * @return int object id
  10113. * @protected
  10114. */
  10115. protected function _putinfo() {
  10116. $oid = $this->_newobj();
  10117. $out = '<<';
  10118. // store current isunicode value
  10119. $prev_isunicode = $this->isunicode;
  10120. if ($this->docinfounicode) {
  10121. $this->isunicode = true;
  10122. }
  10123. if (!$this->empty_string($this->title)) {
  10124. // The document's title.
  10125. $out .= ' /Title '.$this->_textstring($this->title, $oid);
  10126. }
  10127. if (!$this->empty_string($this->author)) {
  10128. // The name of the person who created the document.
  10129. $out .= ' /Author '.$this->_textstring($this->author, $oid);
  10130. }
  10131. if (!$this->empty_string($this->subject)) {
  10132. // The subject of the document.
  10133. $out .= ' /Subject '.$this->_textstring($this->subject, $oid);
  10134. }
  10135. if (!$this->empty_string($this->keywords)) {
  10136. // Keywords associated with the document.
  10137. $out .= ' /Keywords '.$this->_textstring($this->keywords.' TCPDF', $oid);
  10138. }
  10139. if (!$this->empty_string($this->creator)) {
  10140. // 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.
  10141. $out .= ' /Creator '.$this->_textstring($this->creator, $oid);
  10142. }
  10143. // restore previous isunicode value
  10144. $this->isunicode = $prev_isunicode;
  10145. // default producer
  10146. $out .= ' /Producer '.$this->_textstring("\x54\x43\x50\x44\x46\x20".$this->tcpdf_version."\x20\x28\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29", $oid);
  10147. // The date and time the document was created, in human-readable form
  10148. $out .= ' /CreationDate '.$this->_datestring();
  10149. // The date and time the document was most recently modified, in human-readable form
  10150. $out .= ' /ModDate '.$this->_datestring();
  10151. // A name object indicating whether the document has been modified to include trapping information
  10152. $out .= ' /Trapped /False';
  10153. $out .= ' >>';
  10154. $out .= "\n".'endobj';
  10155. $this->_out($out);
  10156. return $oid;
  10157. }
  10158. /**
  10159. * Output Catalog.
  10160. * @return int object id
  10161. * @protected
  10162. */
  10163. protected function _putcatalog() {
  10164. $oid = $this->_newobj();
  10165. $out = '<< /Type /Catalog';
  10166. $out .= ' /Pages 1 0 R';
  10167. if ($this->ZoomMode == 'fullpage') {
  10168. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /Fit]';
  10169. } elseif ($this->ZoomMode == 'fullwidth') {
  10170. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /FitH null]';
  10171. } elseif ($this->ZoomMode == 'real') {
  10172. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null 1]';
  10173. } elseif (!is_string($this->ZoomMode)) {
  10174. $out .= sprintf(' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null %.2F]',($this->ZoomMode / 100));
  10175. }
  10176. if (isset($this->LayoutMode) AND (!$this->empty_string($this->LayoutMode))) {
  10177. $out .= ' /PageLayout /'.$this->LayoutMode;
  10178. }
  10179. if (isset($this->PageMode) AND (!$this->empty_string($this->PageMode))) {
  10180. $out .= ' /PageMode /'.$this->PageMode;
  10181. }
  10182. if (isset($this->l['a_meta_language'])) {
  10183. $out .= ' /Lang '.$this->_textstring($this->l['a_meta_language'], $oid);
  10184. }
  10185. $out .= ' /Names <<';
  10186. if ((!empty($this->javascript)) OR (!empty($this->js_objects))) {
  10187. $out .= ' /JavaScript '.($this->n_js).' 0 R';
  10188. }
  10189. $out .= ' >>';
  10190. if (count($this->outlines) > 0) {
  10191. $out .= ' /Outlines '.$this->OutlineRoot.' 0 R';
  10192. $out .= ' /PageMode /UseOutlines';
  10193. }
  10194. $out .= ' '.$this->_putviewerpreferences();
  10195. if ($this->pdflayers) {
  10196. $p = $this->n_ocg_print.' 0 R';
  10197. $v = $this->n_ocg_view.' 0 R';
  10198. $as = '<< /Event /Print /OCGs ['.$p.' '.$v.'] /Category [/Print] >> << /Event /View /OCGs ['.$p.' '.$v.'] /Category [/View] >>';
  10199. $out .= ' /OCProperties << /OCGs ['.$p.' '.$v.'] /D << /ON ['.$p.'] /OFF ['.$v.'] /AS ['.$as.'] >> >>';
  10200. }
  10201. // AcroForm
  10202. if (!empty($this->form_obj_id) OR ($this->sign AND isset($this->signature_data['cert_type']))) {
  10203. $out .= ' /AcroForm <<';
  10204. $objrefs = '';
  10205. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  10206. $objrefs .= $this->sig_obj_id.' 0 R';
  10207. }
  10208. if (!empty($this->form_obj_id)) {
  10209. foreach($this->form_obj_id as $objid) {
  10210. $objrefs .= ' '.$objid.' 0 R';
  10211. }
  10212. }
  10213. $out .= ' /Fields ['.$objrefs.']';
  10214. if (!empty($this->form_obj_id) AND !$this->sign) {
  10215. // It's better to turn off this value and set the appearance stream for each annotation (/AP) to avoid conflicts with signature fields.
  10216. $out .= ' /NeedAppearances true';
  10217. }
  10218. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  10219. if ($this->signature_data['cert_type'] > 0) {
  10220. $out .= ' /SigFlags 3';
  10221. } else {
  10222. $out .= ' /SigFlags 1';
  10223. }
  10224. }
  10225. //$out .= ' /CO ';
  10226. if (isset($this->annotation_fonts) AND !empty($this->annotation_fonts)) {
  10227. $out .= ' /DR <<';
  10228. $out .= ' /Font <<';
  10229. foreach ($this->annotation_fonts as $fontkey => $fontid) {
  10230. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  10231. }
  10232. $out .= ' >> >>';
  10233. }
  10234. $font = $this->getFontBuffer('helvetica');
  10235. $out .= ' /DA (/F'.$font['i'].' 0 Tf 0 g)';
  10236. $out .= ' /Q '.(($this->rtl)?'2':'0');
  10237. //$out .= ' /XFA ';
  10238. $out .= ' >>';
  10239. // signatures
  10240. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  10241. if ($this->signature_data['cert_type'] > 0) {
  10242. $out .= ' /Perms << /DocMDP '.($this->sig_obj_id + 1).' 0 R >>';
  10243. } else {
  10244. $out .= ' /Perms << /UR3 '.($this->sig_obj_id + 1).' 0 R >>';
  10245. }
  10246. }
  10247. }
  10248. $out .= ' >>';
  10249. $out .= "\n".'endobj';
  10250. $this->_out($out);
  10251. return $oid;
  10252. }
  10253. /**
  10254. * Output viewer preferences.
  10255. * @return string for viewer preferences
  10256. * @author Nicola asuni
  10257. * @since 3.1.000 (2008-06-09)
  10258. * @protected
  10259. */
  10260. protected function _putviewerpreferences() {
  10261. $out = '/ViewerPreferences <<';
  10262. if ($this->rtl) {
  10263. $out .= ' /Direction /R2L';
  10264. } else {
  10265. $out .= ' /Direction /L2R';
  10266. }
  10267. if (isset($this->viewer_preferences['HideToolbar']) AND ($this->viewer_preferences['HideToolbar'])) {
  10268. $out .= ' /HideToolbar true';
  10269. }
  10270. if (isset($this->viewer_preferences['HideMenubar']) AND ($this->viewer_preferences['HideMenubar'])) {
  10271. $out .= ' /HideMenubar true';
  10272. }
  10273. if (isset($this->viewer_preferences['HideWindowUI']) AND ($this->viewer_preferences['HideWindowUI'])) {
  10274. $out .= ' /HideWindowUI true';
  10275. }
  10276. if (isset($this->viewer_preferences['FitWindow']) AND ($this->viewer_preferences['FitWindow'])) {
  10277. $out .= ' /FitWindow true';
  10278. }
  10279. if (isset($this->viewer_preferences['CenterWindow']) AND ($this->viewer_preferences['CenterWindow'])) {
  10280. $out .= ' /CenterWindow true';
  10281. }
  10282. if (isset($this->viewer_preferences['DisplayDocTitle']) AND ($this->viewer_preferences['DisplayDocTitle'])) {
  10283. $out .= ' /DisplayDocTitle true';
  10284. }
  10285. if (isset($this->viewer_preferences['NonFullScreenPageMode'])) {
  10286. $out .= ' /NonFullScreenPageMode /'.$this->viewer_preferences['NonFullScreenPageMode'];
  10287. }
  10288. if (isset($this->viewer_preferences['ViewArea'])) {
  10289. $out .= ' /ViewArea /'.$this->viewer_preferences['ViewArea'];
  10290. }
  10291. if (isset($this->viewer_preferences['ViewClip'])) {
  10292. $out .= ' /ViewClip /'.$this->viewer_preferences['ViewClip'];
  10293. }
  10294. if (isset($this->viewer_preferences['PrintArea'])) {
  10295. $out .= ' /PrintArea /'.$this->viewer_preferences['PrintArea'];
  10296. }
  10297. if (isset($this->viewer_preferences['PrintClip'])) {
  10298. $out .= ' /PrintClip /'.$this->viewer_preferences['PrintClip'];
  10299. }
  10300. if (isset($this->viewer_preferences['PrintScaling'])) {
  10301. $out .= ' /PrintScaling /'.$this->viewer_preferences['PrintScaling'];
  10302. }
  10303. if (isset($this->viewer_preferences['Duplex']) AND (!$this->empty_string($this->viewer_preferences['Duplex']))) {
  10304. $out .= ' /Duplex /'.$this->viewer_preferences['Duplex'];
  10305. }
  10306. if (isset($this->viewer_preferences['PickTrayByPDFSize'])) {
  10307. if ($this->viewer_preferences['PickTrayByPDFSize']) {
  10308. $out .= ' /PickTrayByPDFSize true';
  10309. } else {
  10310. $out .= ' /PickTrayByPDFSize false';
  10311. }
  10312. }
  10313. if (isset($this->viewer_preferences['PrintPageRange'])) {
  10314. $PrintPageRangeNum = '';
  10315. foreach ($this->viewer_preferences['PrintPageRange'] as $k => $v) {
  10316. $PrintPageRangeNum .= ' '.($v - 1).'';
  10317. }
  10318. $out .= ' /PrintPageRange ['.substr($PrintPageRangeNum,1).']';
  10319. }
  10320. if (isset($this->viewer_preferences['NumCopies'])) {
  10321. $out .= ' /NumCopies '.intval($this->viewer_preferences['NumCopies']);
  10322. }
  10323. $out .= ' >>';
  10324. return $out;
  10325. }
  10326. /**
  10327. * Output PDF header.
  10328. * @protected
  10329. */
  10330. protected function _putheader() {
  10331. $this->_out('%PDF-'.$this->PDFVersion);
  10332. }
  10333. /**
  10334. * Output end of document (EOF).
  10335. * @protected
  10336. */
  10337. protected function _enddoc() {
  10338. $this->state = 1;
  10339. $this->_putheader();
  10340. $this->_putpages();
  10341. $this->_putresources();
  10342. // Signature
  10343. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  10344. // widget annotation for signature
  10345. $out = $this->_getobj($this->sig_obj_id)."\n";
  10346. $out .= '<< /Type /Annot';
  10347. $out .= ' /Subtype /Widget';
  10348. $out .= ' /Rect ['.$this->signature_appearance['rect'].']';
  10349. $out .= ' /P '.$this->page_obj_id[($this->signature_appearance['page'])].' 0 R'; // link to signature appearance page
  10350. $out .= ' /F 4';
  10351. $out .= ' /FT /Sig';
  10352. $out .= ' /T '.$this->_textstring('Signature', $this->sig_obj_id);
  10353. $out .= ' /Ff 0';
  10354. $out .= ' /V '.($this->sig_obj_id + 1).' 0 R';
  10355. $out .= ' >>';
  10356. $out .= "\n".'endobj';
  10357. $this->_out($out);
  10358. // signature
  10359. $this->_putsignature();
  10360. }
  10361. // Info
  10362. $objid_info = $this->_putinfo();
  10363. // Catalog
  10364. $objid_catalog = $this->_putcatalog();
  10365. // Cross-ref
  10366. $o = $this->bufferlen;
  10367. // XREF section
  10368. $this->_out('xref');
  10369. $this->_out('0 '.($this->n + 1));
  10370. $this->_out('0000000000 65535 f ');
  10371. for ($i=1; $i <= $this->n; ++$i) {
  10372. if (!isset($this->offsets[$i]) AND ($i > 1)) {
  10373. $this->offsets[$i] = $this->offsets[($i - 1)];
  10374. }
  10375. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
  10376. }
  10377. // TRAILER
  10378. $out = 'trailer <<';
  10379. $out .= ' /Size '.($this->n + 1);
  10380. $out .= ' /Root '.$objid_catalog.' 0 R';
  10381. $out .= ' /Info '.$objid_info.' 0 R';
  10382. if ($this->encrypted) {
  10383. $out .= ' /Encrypt '.$this->encryptdata['objid'].' 0 R';
  10384. }
  10385. $out .= ' /ID [ <'.$this->file_id.'> <'.$this->file_id.'> ]';
  10386. $out .= ' >>';
  10387. $this->_out($out);
  10388. $this->_out('startxref');
  10389. $this->_out($o);
  10390. $this->_out('%%EOF');
  10391. $this->state = 3; // end-of-doc
  10392. if ($this->diskcache) {
  10393. // remove temporary files used for images
  10394. foreach ($this->imagekeys as $key) {
  10395. // remove temporary files
  10396. unlink($this->images[$key]);
  10397. }
  10398. foreach ($this->fontkeys as $key) {
  10399. // remove temporary files
  10400. unlink($this->fonts[$key]);
  10401. }
  10402. }
  10403. }
  10404. /**
  10405. * Initialize a new page.
  10406. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  10407. * @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().
  10408. * @protected
  10409. * @see getPageSizeFromFormat(), setPageFormat()
  10410. */
  10411. protected function _beginpage($orientation='', $format='') {
  10412. ++$this->page;
  10413. $this->setPageBuffer($this->page, '');
  10414. // initialize array for graphics tranformation positions inside a page buffer
  10415. $this->transfmrk[$this->page] = array();
  10416. $this->state = 2;
  10417. if ($this->empty_string($orientation)) {
  10418. if (isset($this->CurOrientation)) {
  10419. $orientation = $this->CurOrientation;
  10420. } elseif ($this->fwPt > $this->fhPt) {
  10421. // landscape
  10422. $orientation = 'L';
  10423. } else {
  10424. // portrait
  10425. $orientation = 'P';
  10426. }
  10427. }
  10428. if ($this->empty_string($format)) {
  10429. $this->pagedim[$this->page] = $this->pagedim[($this->page - 1)];
  10430. $this->setPageOrientation($orientation);
  10431. } else {
  10432. $this->setPageFormat($format, $orientation);
  10433. }
  10434. if ($this->rtl) {
  10435. $this->x = $this->w - $this->rMargin;
  10436. } else {
  10437. $this->x = $this->lMargin;
  10438. }
  10439. $this->y = $this->tMargin;
  10440. if (isset($this->newpagegroup[$this->page])) {
  10441. // start a new group
  10442. $n = sizeof($this->pagegroups) + 1;
  10443. $alias = '{nb'.$n.'}';
  10444. $this->pagegroups[$alias] = 1;
  10445. $this->currpagegroup = $alias;
  10446. } elseif ($this->currpagegroup) {
  10447. ++$this->pagegroups[$this->currpagegroup];
  10448. }
  10449. }
  10450. /**
  10451. * Mark end of page.
  10452. * @protected
  10453. */
  10454. protected function _endpage() {
  10455. $this->setVisibility('all');
  10456. $this->state = 1;
  10457. }
  10458. /**
  10459. * Begin a new object and return the object number.
  10460. * @return int object number
  10461. * @protected
  10462. */
  10463. protected function _newobj() {
  10464. $this->_out($this->_getobj());
  10465. return $this->n;
  10466. }
  10467. /**
  10468. * Return the starting object string for the selected object ID.
  10469. * @param $objid (int) Object ID (leave empty to get a new ID).
  10470. * @return string the starting object string
  10471. * @protected
  10472. * @since 5.8.009 (2010-08-20)
  10473. */
  10474. protected function _getobj($objid='') {
  10475. if ($objid === '') {
  10476. ++$this->n;
  10477. $objid = $this->n;
  10478. }
  10479. $this->offsets[$objid] = $this->bufferlen;
  10480. return $objid.' 0 obj';
  10481. }
  10482. /**
  10483. * Underline text.
  10484. * @param $x (int) X coordinate
  10485. * @param $y (int) Y coordinate
  10486. * @param $txt (string) text to underline
  10487. * @protected
  10488. */
  10489. protected function _dounderline($x, $y, $txt) {
  10490. $w = $this->GetStringWidth($txt);
  10491. return $this->_dounderlinew($x, $y, $w);
  10492. }
  10493. /**
  10494. * Underline for rectangular text area.
  10495. * @param $x (int) X coordinate
  10496. * @param $y (int) Y coordinate
  10497. * @param $w (int) width to underline
  10498. * @protected
  10499. * @since 4.8.008 (2009-09-29)
  10500. */
  10501. protected function _dounderlinew($x, $y, $w) {
  10502. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  10503. return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew), $w * $this->k, $linew);
  10504. }
  10505. /**
  10506. * Line through text.
  10507. * @param $x (int) X coordinate
  10508. * @param $y (int) Y coordinate
  10509. * @param $txt (string) text to linethrough
  10510. * @protected
  10511. */
  10512. protected function _dolinethrough($x, $y, $txt) {
  10513. $w = $this->GetStringWidth($txt);
  10514. return $this->_dolinethroughw($x, $y, $w);
  10515. }
  10516. /**
  10517. * Line through for rectangular text area.
  10518. * @param $x (int) X coordinate
  10519. * @param $y (int) Y coordinate
  10520. * @param $w (int) line lenght (width)
  10521. * @protected
  10522. * @since 4.9.008 (2009-09-29)
  10523. */
  10524. protected function _dolinethroughw($x, $y, $w) {
  10525. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  10526. return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew + ($this->FontSizePt / 3)), $w * $this->k, $linew);
  10527. }
  10528. /**
  10529. * Overline text.
  10530. * @param $x (int) X coordinate
  10531. * @param $y (int) Y coordinate
  10532. * @param $txt (string) text to overline
  10533. * @protected
  10534. * @since 4.9.015 (2010-04-19)
  10535. */
  10536. protected function _dooverline($x, $y, $txt) {
  10537. $w = $this->GetStringWidth($txt);
  10538. return $this->_dooverlinew($x, $y, $w);
  10539. }
  10540. /**
  10541. * Overline for rectangular text area.
  10542. * @param $x (int) X coordinate
  10543. * @param $y (int) Y coordinate
  10544. * @param $w (int) width to overline
  10545. * @protected
  10546. * @since 4.9.015 (2010-04-19)
  10547. */
  10548. protected function _dooverlinew($x, $y, $w) {
  10549. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  10550. return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, (($this->h - $y + $this->FontAscent) * $this->k) - $linew, $w * $this->k, $linew);
  10551. }
  10552. /**
  10553. * Read a 4-byte (32 bit) integer from file.
  10554. * @param $f (string) file name.
  10555. * @return 4-byte integer
  10556. * @protected
  10557. */
  10558. protected function _freadint($f) {
  10559. $a = unpack('Ni', fread($f, 4));
  10560. return $a['i'];
  10561. }
  10562. /**
  10563. * Add "\" before "\", "(" and ")"
  10564. * @param $s (string) string to escape.
  10565. * @return string escaped string.
  10566. * @protected
  10567. */
  10568. protected function _escape($s) {
  10569. // the chr(13) substitution fixes the Bugs item #1421290.
  10570. return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
  10571. }
  10572. /**
  10573. * Format a data string for meta information
  10574. * @param $s (string) data string to escape.
  10575. * @param $n (int) object ID
  10576. * @return string escaped string.
  10577. * @protected
  10578. */
  10579. protected function _datastring($s, $n=0) {
  10580. if ($n == 0) {
  10581. $n = $this->n;
  10582. }
  10583. $s = $this->_encrypt_data($n, $s);
  10584. return '('. $this->_escape($s).')';
  10585. }
  10586. /**
  10587. * Returns a formatted date for meta information
  10588. * @param $n (int) object ID
  10589. * @return string escaped date string.
  10590. * @protected
  10591. * @since 4.6.028 (2009-08-25)
  10592. */
  10593. protected function _datestring($n=0) {
  10594. $current_time = substr_replace(date('YmdHisO'), '\'', (0 - 2), 0).'\'';
  10595. return $this->_datastring('D:'.$current_time, $n);
  10596. }
  10597. /**
  10598. * Format a text string for meta information
  10599. * @param $s (string) string to escape.
  10600. * @param $n (int) object ID
  10601. * @return string escaped string.
  10602. * @protected
  10603. */
  10604. protected function _textstring($s, $n=0) {
  10605. if ($this->isunicode) {
  10606. //Convert string to UTF-16BE
  10607. $s = $this->UTF8ToUTF16BE($s, true);
  10608. }
  10609. return $this->_datastring($s, $n);
  10610. }
  10611. /**
  10612. * THIS METHOD IS DEPRECATED
  10613. * Format a text string
  10614. * @param $s (string) string to escape.
  10615. * @return string escaped string.
  10616. * @protected
  10617. * @deprecated
  10618. */
  10619. protected function _escapetext($s) {
  10620. if ($this->isunicode) {
  10621. if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
  10622. $s = $this->UTF8ToLatin1($s);
  10623. } else {
  10624. //Convert string to UTF-16BE and reverse RTL language
  10625. $s = $this->utf8StrRev($s, false, $this->tmprtl);
  10626. }
  10627. }
  10628. return $this->_escape($s);
  10629. }
  10630. /**
  10631. * get raw output stream.
  10632. * @param $s (string) string to output.
  10633. * @param $n (int) object reference for encryption mode
  10634. * @protected
  10635. * @author Nicola Asuni
  10636. * @since 5.5.000 (2010-06-22)
  10637. */
  10638. protected function _getrawstream($s, $n=0) {
  10639. if ($n <= 0) {
  10640. // default to current object
  10641. $n = $this->n;
  10642. }
  10643. return $this->_encrypt_data($n, $s);
  10644. }
  10645. /**
  10646. * Format output stream (DEPRECATED).
  10647. * @param $s (string) string to output.
  10648. * @param $n (int) object reference for encryption mode
  10649. * @protected
  10650. * @deprecated
  10651. */
  10652. protected function _getstream($s, $n=0) {
  10653. return 'stream'."\n".$this->_getrawstream($s, $n)."\n".'endstream';
  10654. }
  10655. /**
  10656. * Output a stream (DEPRECATED).
  10657. * @param $s (string) string to output.
  10658. * @param $n (int) object reference for encryption mode
  10659. * @protected
  10660. * @deprecated
  10661. */
  10662. protected function _putstream($s, $n=0) {
  10663. $this->_out($this->_getstream($s, $n));
  10664. }
  10665. /**
  10666. * Output a string to the document.
  10667. * @param $s (string) string to output.
  10668. * @protected
  10669. */
  10670. protected function _out($s) {
  10671. if ($this->state == 2) {
  10672. if ($this->inxobj) {
  10673. // we are inside an XObject template
  10674. $this->xobjects[$this->xobjid]['outdata'] .= $s."\n";
  10675. } elseif ((!$this->InFooter) AND isset($this->footerlen[$this->page]) AND ($this->footerlen[$this->page] > 0)) {
  10676. // puts data before page footer
  10677. $pagebuff = $this->getPageBuffer($this->page);
  10678. $page = substr($pagebuff, 0, -$this->footerlen[$this->page]);
  10679. $footer = substr($pagebuff, -$this->footerlen[$this->page]);
  10680. $this->setPageBuffer($this->page, $page.$s."\n".$footer);
  10681. // update footer position
  10682. $this->footerpos[$this->page] += strlen($s."\n");
  10683. } else {
  10684. $this->setPageBuffer($this->page, $s."\n", true);
  10685. }
  10686. } else {
  10687. $this->setBuffer($s."\n");
  10688. }
  10689. }
  10690. /**
  10691. * Converts UTF-8 strings to codepoints array.<br>
  10692. * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br>
  10693. * Based on: http://www.faqs.org/rfcs/rfc3629.html
  10694. * <pre>
  10695. * Char. number range | UTF-8 octet sequence
  10696. * (hexadecimal) | (binary)
  10697. * --------------------+-----------------------------------------------
  10698. * 0000 0000-0000 007F | 0xxxxxxx
  10699. * 0000 0080-0000 07FF | 110xxxxx 10xxxxxx
  10700. * 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
  10701. * 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
  10702. * ---------------------------------------------------------------------
  10703. *
  10704. * ABFN notation:
  10705. * ---------------------------------------------------------------------
  10706. * UTF8-octets = *( UTF8-char )
  10707. * UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
  10708. * UTF8-1 = %x00-7F
  10709. * UTF8-2 = %xC2-DF UTF8-tail
  10710. *
  10711. * UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
  10712. * %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
  10713. * UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
  10714. * %xF4 %x80-8F 2( UTF8-tail )
  10715. * UTF8-tail = %x80-BF
  10716. * ---------------------------------------------------------------------
  10717. * </pre>
  10718. * @param $str (string) string to process.
  10719. * @return array containing codepoints (UTF-8 characters values)
  10720. * @protected
  10721. * @author Nicola Asuni
  10722. * @since 1.53.0.TC005 (2005-01-05)
  10723. */
  10724. protected function UTF8StringToArray($str) {
  10725. // build a unique string key
  10726. $strkey = md5($str);
  10727. if (isset($this->cache_UTF8StringToArray[$strkey])) {
  10728. // return cached value
  10729. $chrarray = $this->cache_UTF8StringToArray[$strkey]['s'];
  10730. if (!isset($this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']])) {
  10731. if ($this->isunicode) {
  10732. foreach ($chrarray as $chr) {
  10733. // store this char for font subsetting
  10734. $this->CurrentFont['subsetchars'][$chr] = true;
  10735. }
  10736. // update font subsetchars
  10737. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  10738. }
  10739. $this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']] = true;
  10740. }
  10741. return $chrarray;
  10742. }
  10743. // check cache size
  10744. if ($this->cache_size_UTF8StringToArray >= $this->cache_maxsize_UTF8StringToArray) {
  10745. // remove first element
  10746. array_shift($this->cache_UTF8StringToArray);
  10747. }
  10748. // new cache array for selected string
  10749. $this->cache_UTF8StringToArray[$strkey] = array('s' => array(), 'f' => array());
  10750. ++$this->cache_size_UTF8StringToArray;
  10751. if (!$this->isunicode) {
  10752. // split string into array of equivalent codes
  10753. $strarr = array();
  10754. $strlen = strlen($str);
  10755. for ($i=0; $i < $strlen; ++$i) {
  10756. $strarr[] = ord($str{$i});
  10757. }
  10758. // insert new value on cache
  10759. $this->cache_UTF8StringToArray[$strkey]['s'] = $strarr;
  10760. $this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']] = true;
  10761. return $strarr;
  10762. }
  10763. $unichar = -1; // last unicode char
  10764. $unicode = array(); // array containing unicode values
  10765. $bytes = array(); // array containing single character byte sequences
  10766. $numbytes = 1; // number of octetc needed to represent the UTF-8 character
  10767. $str .= ''; // force $str to be a string
  10768. $length = strlen($str);
  10769. for ($i = 0; $i < $length; ++$i) {
  10770. $char = ord($str{$i}); // get one string character at time
  10771. if (count($bytes) == 0) { // get starting octect
  10772. if ($char <= 0x7F) {
  10773. $unichar = $char; // use the character "as is" because is ASCII
  10774. $numbytes = 1;
  10775. } elseif (($char >> 0x05) == 0x06) { // 2 bytes character (0x06 = 110 BIN)
  10776. $bytes[] = ($char - 0xC0) << 0x06;
  10777. $numbytes = 2;
  10778. } elseif (($char >> 0x04) == 0x0E) { // 3 bytes character (0x0E = 1110 BIN)
  10779. $bytes[] = ($char - 0xE0) << 0x0C;
  10780. $numbytes = 3;
  10781. } elseif (($char >> 0x03) == 0x1E) { // 4 bytes character (0x1E = 11110 BIN)
  10782. $bytes[] = ($char - 0xF0) << 0x12;
  10783. $numbytes = 4;
  10784. } else {
  10785. // use replacement character for other invalid sequences
  10786. $unichar = 0xFFFD;
  10787. $bytes = array();
  10788. $numbytes = 1;
  10789. }
  10790. } elseif (($char >> 0x06) == 0x02) { // bytes 2, 3 and 4 must start with 0x02 = 10 BIN
  10791. $bytes[] = $char - 0x80;
  10792. if (count($bytes) == $numbytes) {
  10793. // compose UTF-8 bytes to a single unicode value
  10794. $char = $bytes[0];
  10795. for ($j = 1; $j < $numbytes; ++$j) {
  10796. $char += ($bytes[$j] << (($numbytes - $j - 1) * 0x06));
  10797. }
  10798. if ((($char >= 0xD800) AND ($char <= 0xDFFF)) OR ($char >= 0x10FFFF)) {
  10799. /* The definition of UTF-8 prohibits encoding character numbers between
  10800. U+D800 and U+DFFF, which are reserved for use with the UTF-16
  10801. encoding form (as surrogate pairs) and do not directly represent
  10802. characters. */
  10803. $unichar = 0xFFFD; // use replacement character
  10804. } else {
  10805. $unichar = $char; // add char to array
  10806. }
  10807. // reset data for next char
  10808. $bytes = array();
  10809. $numbytes = 1;
  10810. }
  10811. } else {
  10812. // use replacement character for other invalid sequences
  10813. $unichar = 0xFFFD;
  10814. $bytes = array();
  10815. $numbytes = 1;
  10816. }
  10817. if ($unichar >= 0) {
  10818. // insert unicode value into array
  10819. $unicode[] = $unichar;
  10820. // store this char for font subsetting
  10821. $this->CurrentFont['subsetchars'][$unichar] = true;
  10822. $unichar = -1;
  10823. }
  10824. }
  10825. // update font subsetchars
  10826. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  10827. // insert new value on cache
  10828. $this->cache_UTF8StringToArray[$strkey]['s'] = $unicode;
  10829. $this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']] = true;
  10830. return $unicode;
  10831. }
  10832. /**
  10833. * Converts UTF-8 strings to UTF16-BE.<br>
  10834. * @param $str (string) string to process.
  10835. * @param $setbom (boolean) if true set the Byte Order Mark (BOM = 0xFEFF)
  10836. * @return string
  10837. * @author Nicola Asuni
  10838. * @since 1.53.0.TC005 (2005-01-05)
  10839. * @see UTF8StringToArray(), arrUTF8ToUTF16BE()
  10840. * @protected
  10841. */
  10842. protected function UTF8ToUTF16BE($str, $setbom=true) {
  10843. if (!$this->isunicode) {
  10844. return $str; // string is not in unicode
  10845. }
  10846. $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values
  10847. return $this->arrUTF8ToUTF16BE($unicode, $setbom);
  10848. }
  10849. /**
  10850. * Converts UTF-8 strings to Latin1 when using the standard 14 core fonts.<br>
  10851. * @param $str (string) string to process.
  10852. * @return string
  10853. * @author Andrew Whitehead, Nicola Asuni
  10854. * @protected
  10855. * @since 3.2.000 (2008-06-23)
  10856. */
  10857. protected function UTF8ToLatin1($str) {
  10858. if (!$this->isunicode) {
  10859. return $str; // string is not in unicode
  10860. }
  10861. $outstr = ''; // string to be returned
  10862. $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values
  10863. foreach ($unicode as $char) {
  10864. if ($char < 256) {
  10865. $outstr .= chr($char);
  10866. } elseif (array_key_exists($char, $this->unicode->uni_utf8tolatin)) {
  10867. // map from UTF-8
  10868. $outstr .= chr($this->unicode->uni_utf8tolatin[$char]);
  10869. } elseif ($char == 0xFFFD) {
  10870. // skip
  10871. } else {
  10872. $outstr .= '?';
  10873. }
  10874. }
  10875. return $outstr;
  10876. }
  10877. /**
  10878. * Converts UTF-8 characters array to array of Latin1 characters<br>
  10879. * @param $unicode (array) array containing UTF-8 unicode values
  10880. * @return array
  10881. * @author Nicola Asuni
  10882. * @protected
  10883. * @since 4.8.023 (2010-01-15)
  10884. */
  10885. protected function UTF8ArrToLatin1($unicode) {
  10886. if ((!$this->isunicode) OR $this->isUnicodeFont()) {
  10887. return $unicode;
  10888. }
  10889. $outarr = array(); // array to be returned
  10890. foreach ($unicode as $char) {
  10891. if ($char < 256) {
  10892. $outarr[] = $char;
  10893. } elseif (array_key_exists($char, $this->unicode->uni_utf8tolatin)) {
  10894. // map from UTF-8
  10895. $outarr[] = $this->unicode->uni_utf8tolatin[$char];
  10896. } elseif ($char == 0xFFFD) {
  10897. // skip
  10898. } else {
  10899. $outarr[] = 63; // '?' character
  10900. }
  10901. }
  10902. return $outarr;
  10903. }
  10904. /**
  10905. * Converts array of UTF-8 characters to UTF16-BE string.<br>
  10906. * Based on: http://www.faqs.org/rfcs/rfc2781.html
  10907. * <pre>
  10908. * Encoding UTF-16:
  10909. *
  10910. * Encoding of a single character from an ISO 10646 character value to
  10911. * UTF-16 proceeds as follows. Let U be the character number, no greater
  10912. * than 0x10FFFF.
  10913. *
  10914. * 1) If U < 0x10000, encode U as a 16-bit unsigned integer and
  10915. * terminate.
  10916. *
  10917. * 2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
  10918. * U' must be less than or equal to 0xFFFFF. That is, U' can be
  10919. * represented in 20 bits.
  10920. *
  10921. * 3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
  10922. * 0xDC00, respectively. These integers each have 10 bits free to
  10923. * encode the character value, for a total of 20 bits.
  10924. *
  10925. * 4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
  10926. * bits of W1 and the 10 low-order bits of U' to the 10 low-order
  10927. * bits of W2. Terminate.
  10928. *
  10929. * Graphically, steps 2 through 4 look like:
  10930. * U' = yyyyyyyyyyxxxxxxxxxx
  10931. * W1 = 110110yyyyyyyyyy
  10932. * W2 = 110111xxxxxxxxxx
  10933. * </pre>
  10934. * @param $unicode (array) array containing UTF-8 unicode values
  10935. * @param $setbom (boolean) if true set the Byte Order Mark (BOM = 0xFEFF)
  10936. * @return string
  10937. * @protected
  10938. * @author Nicola Asuni
  10939. * @since 2.1.000 (2008-01-08)
  10940. * @see UTF8ToUTF16BE()
  10941. */
  10942. protected function arrUTF8ToUTF16BE($unicode, $setbom=true) {
  10943. $outstr = ''; // string to be returned
  10944. if ($setbom) {
  10945. $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
  10946. }
  10947. foreach ($unicode as $char) {
  10948. if ($char == 0x200b) {
  10949. // skip Unicode Character 'ZERO WIDTH SPACE' (DEC:8203, U+200B)
  10950. } elseif ($char == 0xFFFD) {
  10951. $outstr .= "\xFF\xFD"; // replacement character
  10952. } elseif ($char < 0x10000) {
  10953. $outstr .= chr($char >> 0x08);
  10954. $outstr .= chr($char & 0xFF);
  10955. } else {
  10956. $char -= 0x10000;
  10957. $w1 = 0xD800 | ($char >> 0x10);
  10958. $w2 = 0xDC00 | ($char & 0x3FF);
  10959. $outstr .= chr($w1 >> 0x08);
  10960. $outstr .= chr($w1 & 0xFF);
  10961. $outstr .= chr($w2 >> 0x08);
  10962. $outstr .= chr($w2 & 0xFF);
  10963. }
  10964. }
  10965. return $outstr;
  10966. }
  10967. // ====================================================
  10968. /**
  10969. * Set header font.
  10970. * @param $font (array) font
  10971. * @public
  10972. * @since 1.1
  10973. */
  10974. public function setHeaderFont($font) {
  10975. $this->header_font = $font;
  10976. }
  10977. /**
  10978. * Get header font.
  10979. * @return array()
  10980. * @public
  10981. * @since 4.0.012 (2008-07-24)
  10982. */
  10983. public function getHeaderFont() {
  10984. return $this->header_font;
  10985. }
  10986. /**
  10987. * Set footer font.
  10988. * @param $font (array) font
  10989. * @public
  10990. * @since 1.1
  10991. */
  10992. public function setFooterFont($font) {
  10993. $this->footer_font = $font;
  10994. }
  10995. /**
  10996. * Get Footer font.
  10997. * @return array()
  10998. * @public
  10999. * @since 4.0.012 (2008-07-24)
  11000. */
  11001. public function getFooterFont() {
  11002. return $this->footer_font;
  11003. }
  11004. /**
  11005. * Set language array.
  11006. * @param $language (array)
  11007. * @public
  11008. * @since 1.1
  11009. */
  11010. public function setLanguageArray($language) {
  11011. $this->l = $language;
  11012. if (isset($this->l['a_meta_dir'])) {
  11013. $this->rtl = $this->l['a_meta_dir']=='rtl' ? true : false;
  11014. } else {
  11015. $this->rtl = false;
  11016. }
  11017. }
  11018. /**
  11019. * Returns the PDF data.
  11020. * @public
  11021. */
  11022. public function getPDFData() {
  11023. if ($this->state < 3) {
  11024. $this->Close();
  11025. }
  11026. return $this->buffer;
  11027. }
  11028. /**
  11029. * Output anchor link.
  11030. * @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;)
  11031. * @param $name (string) link name
  11032. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  11033. * @param $firstline (boolean) if true prints only the first line and return the remaining string.
  11034. * @param $color (array) array of RGB text color
  11035. * @param $style (string) font style (U, D, B, I)
  11036. * @param $firstblock (boolean) if true the string is the starting of a line.
  11037. * @return the number of cells used or the remaining text if $firstline = true;
  11038. * @public
  11039. */
  11040. public function addHtmlLink($url, $name, $fill=false, $firstline=false, $color='', $style=-1, $firstblock=false) {
  11041. if (!$this->empty_string($url) AND ($url{0} == '#')) {
  11042. // convert url to internal link
  11043. $lnkdata = explode(',', $url);
  11044. if (isset($lnkdata[0])) {
  11045. $page = intval(substr($lnkdata[0], 1));
  11046. if (empty($page) OR ($page <= 0)) {
  11047. $page = $this->page;
  11048. }
  11049. if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
  11050. $lnky = floatval($lnkdata[1]);
  11051. } else {
  11052. $lnky = 0;
  11053. }
  11054. $url = $this->AddLink();
  11055. $this->SetLink($url, $lnky, $page);
  11056. }
  11057. }
  11058. // store current settings
  11059. $prevcolor = $this->fgcolor;
  11060. $prevstyle = $this->FontStyle;
  11061. if (empty($color)) {
  11062. $this->SetTextColorArray($this->htmlLinkColorArray);
  11063. } else {
  11064. $this->SetTextColorArray($color);
  11065. }
  11066. if ($style == -1) {
  11067. $this->SetFont('', $this->FontStyle.$this->htmlLinkFontStyle);
  11068. } else {
  11069. $this->SetFont('', $this->FontStyle.$style);
  11070. }
  11071. $ret = $this->Write($this->lasth, $name, $url, $fill, '', false, 0, $firstline, $firstblock, 0);
  11072. // restore settings
  11073. $this->SetFont('', $prevstyle);
  11074. $this->SetTextColorArray($prevcolor);
  11075. return $ret;
  11076. }
  11077. /**
  11078. * Returns an array (RGB or CMYK) from an html color name or a six-digit (i.e. #3FE5AA) or three-digit (i.e. #7FF) hexadecimal color representation.
  11079. * @param $hcolor (string) html color
  11080. * @return array RGB or CMYK color, or false in case of error.
  11081. * @public
  11082. */
  11083. public function convertHTMLColorToDec($hcolor='#FFFFFF') {
  11084. $returncolor = false;
  11085. $color = preg_replace('/[\s]*/', '', $hcolor); // remove extra spaces
  11086. $color = strtolower($color);
  11087. if (($dotpos = strpos($color, '.')) !== false) {
  11088. // remove class parent (i.e.: color.red)
  11089. $color = substr($color, ($dotpos + 1));
  11090. }
  11091. if (strlen($color) == 0) {
  11092. return false;
  11093. }
  11094. // RGB ARRAY
  11095. if (substr($color, 0, 3) == 'rgb') {
  11096. $codes = substr($color, 4);
  11097. $codes = str_replace(')', '', $codes);
  11098. $returncolor = explode(',', $codes);
  11099. foreach ($returncolor as $key => $val) {
  11100. if (strpos($val, '%') > 0) {
  11101. // percentage
  11102. $returncolor[$key] = (255 * intval($val) / 100);
  11103. } else {
  11104. $returncolor[$key] = intval($val);
  11105. }
  11106. // normalize value
  11107. $returncolor[$key] = max(0, min(255, $returncolor[$key]));
  11108. }
  11109. return $returncolor;
  11110. }
  11111. // CMYK ARRAY
  11112. if (substr($color, 0, 4) == 'cmyk') {
  11113. $codes = substr($color, 5);
  11114. $codes = str_replace(')', '', $codes);
  11115. $returncolor = explode(',', $codes);
  11116. foreach ($returncolor as $key => $val) {
  11117. if (strpos($val, '%') !== false) {
  11118. // percentage
  11119. $returncolor[$key] = (100 * intval($val) / 100);
  11120. } else {
  11121. $returncolor[$key] = intval($val);
  11122. }
  11123. // normalize value
  11124. $returncolor[$key] = max(0, min(100, $returncolor[$key]));
  11125. }
  11126. return $returncolor;
  11127. }
  11128. // COLOR NAME
  11129. if (substr($color, 0, 1) != '#') {
  11130. // decode color name
  11131. if (isset($this->webcolor[$color])) {
  11132. // web color
  11133. $color_code = $this->webcolor[$color];
  11134. } elseif (isset($this->spot_colors[$hcolor])) {
  11135. // custom defined spot color
  11136. return array($this->spot_colors[$hcolor]['c'], $this->spot_colors[$hcolor]['m'], $this->spot_colors[$hcolor]['y'], $this->spot_colors[$hcolor]['k'], $hcolor);
  11137. } elseif (isset($this->spotcolor[$color])) {
  11138. // spot color from configuration file
  11139. return $this->spotcolor[$color];
  11140. } else {
  11141. return false;
  11142. }
  11143. } else {
  11144. $color_code = substr($color, 1);
  11145. }
  11146. // RGB VALUE
  11147. switch (strlen($color_code)) {
  11148. case 3: {
  11149. // three-digit hexadecimal representation
  11150. $r = substr($color_code, 0, 1);
  11151. $g = substr($color_code, 1, 1);
  11152. $b = substr($color_code, 2, 1);
  11153. $returncolor = array();
  11154. $returncolor['R'] = max(0, min(255, hexdec($r.$r)));
  11155. $returncolor['G'] = max(0, min(255, hexdec($g.$g)));
  11156. $returncolor['B'] = max(0, min(255, hexdec($b.$b)));
  11157. break;
  11158. }
  11159. case 6: {
  11160. // six-digit hexadecimal representation
  11161. $returncolor = array();
  11162. $returncolor['R'] = max(0, min(255, hexdec(substr($color_code, 0, 2))));
  11163. $returncolor['G'] = max(0, min(255, hexdec(substr($color_code, 2, 2))));
  11164. $returncolor['B'] = max(0, min(255, hexdec(substr($color_code, 4, 2))));
  11165. break;
  11166. }
  11167. }
  11168. return $returncolor;
  11169. }
  11170. /**
  11171. * Converts pixels to User's Units.
  11172. * @param $px (int) pixels
  11173. * @return float value in user's unit
  11174. * @public
  11175. * @see setImageScale(), getImageScale()
  11176. */
  11177. public function pixelsToUnits($px) {
  11178. return ($px / ($this->imgscale * $this->k));
  11179. }
  11180. /**
  11181. * Reverse function for htmlentities.
  11182. * Convert entities in UTF-8.
  11183. * @param $text_to_convert (string) Text to convert.
  11184. * @return string converted text string
  11185. * @public
  11186. */
  11187. public function unhtmlentities($text_to_convert) {
  11188. return html_entity_decode($text_to_convert, ENT_QUOTES, $this->encoding);
  11189. }
  11190. // ENCRYPTION METHODS ----------------------------------
  11191. /**
  11192. * Returns a string containing random data to be used as a seed for encryption methods.
  11193. * @param $seed (string) starting seed value
  11194. * @return string containing random data
  11195. * @author Nicola Asuni
  11196. * @since 5.9.006 (2010-10-19)
  11197. * @protected
  11198. */
  11199. protected function getRandomSeed($seed='') {
  11200. $seed .= microtime();
  11201. if (function_exists('openssl_random_pseudo_bytes') AND (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) {
  11202. // this is not used on windows systems because it is very slow for a know bug
  11203. $seed .= openssl_random_pseudo_bytes(512);
  11204. } else {
  11205. for ($i = 0; $i < 23; ++$i) {
  11206. $seed .= uniqid('', true);
  11207. }
  11208. }
  11209. $seed .= uniqid('', true);
  11210. $seed .= rand();
  11211. $seed .= getmypid();
  11212. $seed .= __FILE__;
  11213. $seed .= $this->bufferlen;
  11214. if (isset($_SERVER['REMOTE_ADDR'])) {
  11215. $seed .= $_SERVER['REMOTE_ADDR'];
  11216. }
  11217. if (isset($_SERVER['HTTP_USER_AGENT'])) {
  11218. $seed .= $_SERVER['HTTP_USER_AGENT'];
  11219. }
  11220. if (isset($_SERVER['HTTP_ACCEPT'])) {
  11221. $seed .= $_SERVER['HTTP_ACCEPT'];
  11222. }
  11223. if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
  11224. $seed .= $_SERVER['HTTP_ACCEPT_ENCODING'];
  11225. }
  11226. if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  11227. $seed .= $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  11228. }
  11229. if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
  11230. $seed .= $_SERVER['HTTP_ACCEPT_CHARSET'];
  11231. }
  11232. $seed .= rand();
  11233. $seed .= uniqid('', true);
  11234. $seed .= microtime();
  11235. return $seed;
  11236. }
  11237. /**
  11238. * Compute encryption key depending on object number where the encrypted data is stored.
  11239. * This is used for all strings and streams without crypt filter specifier.
  11240. * @param $n (int) object number
  11241. * @return int object key
  11242. * @protected
  11243. * @author Nicola Asuni
  11244. * @since 2.0.000 (2008-01-02)
  11245. */
  11246. protected function _objectkey($n) {
  11247. $objkey = $this->encryptdata['key'].pack('VXxx', $n);
  11248. if ($this->encryptdata['mode'] == 2) { // AES-128
  11249. // AES padding
  11250. $objkey .= "\x73\x41\x6C\x54"; // sAlT
  11251. }
  11252. $objkey = substr($this->_md5_16($objkey), 0, (($this->encryptdata['Length'] / 8) + 5));
  11253. $objkey = substr($objkey, 0, 16);
  11254. return $objkey;
  11255. }
  11256. /**
  11257. * Encrypt the input string.
  11258. * @param $n (int) object number
  11259. * @param $s (string) data string to encrypt
  11260. * @return encrypted string
  11261. * @protected
  11262. * @author Nicola Asuni
  11263. * @since 5.0.005 (2010-05-11)
  11264. */
  11265. protected function _encrypt_data($n, $s) {
  11266. if (!$this->encrypted) {
  11267. return $s;
  11268. }
  11269. switch ($this->encryptdata['mode']) {
  11270. case 0: // RC4-40
  11271. case 1: { // RC4-128
  11272. $s = $this->_RC4($this->_objectkey($n), $s);
  11273. break;
  11274. }
  11275. case 2: { // AES-128
  11276. $s = $this->_AES($this->_objectkey($n), $s);
  11277. break;
  11278. }
  11279. case 3: { // AES-256
  11280. $s = $this->_AES($this->encryptdata['key'], $s);
  11281. break;
  11282. }
  11283. }
  11284. return $s;
  11285. }
  11286. /**
  11287. * Put encryption on PDF document.
  11288. * @protected
  11289. * @author Nicola Asuni
  11290. * @since 2.0.000 (2008-01-02)
  11291. */
  11292. protected function _putencryption() {
  11293. if (!$this->encrypted) {
  11294. return;
  11295. }
  11296. $this->encryptdata['objid'] = $this->_newobj();
  11297. $out = '<<';
  11298. if (!isset($this->encryptdata['Filter']) OR empty($this->encryptdata['Filter'])) {
  11299. $this->encryptdata['Filter'] = 'Standard';
  11300. }
  11301. $out .= ' /Filter /'.$this->encryptdata['Filter'];
  11302. if (isset($this->encryptdata['SubFilter']) AND !empty($this->encryptdata['SubFilter'])) {
  11303. $out .= ' /SubFilter /'.$this->encryptdata['SubFilter'];
  11304. }
  11305. if (!isset($this->encryptdata['V']) OR empty($this->encryptdata['V'])) {
  11306. $this->encryptdata['V'] = 1;
  11307. }
  11308. // V is a code specifying the algorithm to be used in encrypting and decrypting the document
  11309. $out .= ' /V '.$this->encryptdata['V'];
  11310. if (isset($this->encryptdata['Length']) AND !empty($this->encryptdata['Length'])) {
  11311. // The length of the encryption key, in bits. The value shall be a multiple of 8, in the range 40 to 256
  11312. $out .= ' /Length '.$this->encryptdata['Length'];
  11313. } else {
  11314. $out .= ' /Length 40';
  11315. }
  11316. if ($this->encryptdata['V'] >= 4) {
  11317. if (!isset($this->encryptdata['StmF']) OR empty($this->encryptdata['StmF'])) {
  11318. $this->encryptdata['StmF'] = 'Identity';
  11319. }
  11320. if (!isset($this->encryptdata['StrF']) OR empty($this->encryptdata['StrF'])) {
  11321. // The name of the crypt filter that shall be used when decrypting all strings in the document.
  11322. $this->encryptdata['StrF'] = 'Identity';
  11323. }
  11324. // A dictionary whose keys shall be crypt filter names and whose values shall be the corresponding crypt filter dictionaries.
  11325. if (isset($this->encryptdata['CF']) AND !empty($this->encryptdata['CF'])) {
  11326. $out .= ' /CF <<';
  11327. $out .= ' /'.$this->encryptdata['StmF'].' <<';
  11328. $out .= ' /Type /CryptFilter';
  11329. if (isset($this->encryptdata['CF']['CFM']) AND !empty($this->encryptdata['CF']['CFM'])) {
  11330. // The method used
  11331. $out .= ' /CFM /'.$this->encryptdata['CF']['CFM'];
  11332. if ($this->encryptdata['pubkey']) {
  11333. $out .= ' /Recipients [';
  11334. foreach ($this->encryptdata['Recipients'] as $rec) {
  11335. $out .= ' <'.$rec.'>';
  11336. }
  11337. $out .= ' ]';
  11338. if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) {
  11339. $out .= ' /EncryptMetadata false';
  11340. } else {
  11341. $out .= ' /EncryptMetadata true';
  11342. }
  11343. }
  11344. } else {
  11345. $out .= ' /CFM /None';
  11346. }
  11347. if (isset($this->encryptdata['CF']['AuthEvent']) AND !empty($this->encryptdata['CF']['AuthEvent'])) {
  11348. // The event to be used to trigger the authorization that is required to access encryption keys used by this filter.
  11349. $out .= ' /AuthEvent /'.$this->encryptdata['CF']['AuthEvent'];
  11350. } else {
  11351. $out .= ' /AuthEvent /DocOpen';
  11352. }
  11353. if (isset($this->encryptdata['CF']['Length']) AND !empty($this->encryptdata['CF']['Length'])) {
  11354. // The bit length of the encryption key.
  11355. $out .= ' /Length '.$this->encryptdata['CF']['Length'];
  11356. }
  11357. $out .= ' >> >>';
  11358. }
  11359. // The name of the crypt filter that shall be used by default when decrypting streams.
  11360. $out .= ' /StmF /'.$this->encryptdata['StmF'];
  11361. // The name of the crypt filter that shall be used when decrypting all strings in the document.
  11362. $out .= ' /StrF /'.$this->encryptdata['StrF'];
  11363. if (isset($this->encryptdata['EFF']) AND !empty($this->encryptdata['EFF'])) {
  11364. // The name of the crypt filter that shall be used when encrypting embedded file streams that do not have their own crypt filter specifier.
  11365. $out .= ' /EFF /'.$this->encryptdata[''];
  11366. }
  11367. }
  11368. // Additional encryption dictionary entries for the standard security handler
  11369. if ($this->encryptdata['pubkey']) {
  11370. if (($this->encryptdata['V'] < 4) AND isset($this->encryptdata['Recipients']) AND !empty($this->encryptdata['Recipients'])) {
  11371. $out .= ' /Recipients [';
  11372. foreach ($this->encryptdata['Recipients'] as $rec) {
  11373. $out .= ' <'.$rec.'>';
  11374. }
  11375. $out .= ' ]';
  11376. }
  11377. } else {
  11378. $out .= ' /R';
  11379. if ($this->encryptdata['V'] == 5) { // AES-256
  11380. $out .= ' 5';
  11381. $out .= ' /OE ('.$this->_escape($this->encryptdata['OE']).')';
  11382. $out .= ' /UE ('.$this->_escape($this->encryptdata['UE']).')';
  11383. $out .= ' /Perms ('.$this->_escape($this->encryptdata['perms']).')';
  11384. } elseif ($this->encryptdata['V'] == 4) { // AES-128
  11385. $out .= ' 4';
  11386. } elseif ($this->encryptdata['V'] < 2) { // RC-40
  11387. $out .= ' 2';
  11388. } else { // RC-128
  11389. $out .= ' 3';
  11390. }
  11391. $out .= ' /O ('.$this->_escape($this->encryptdata['O']).')';
  11392. $out .= ' /U ('.$this->_escape($this->encryptdata['U']).')';
  11393. $out .= ' /P '.$this->encryptdata['P'];
  11394. if (isset($this->encryptdata['EncryptMetadata']) AND (!$this->encryptdata['EncryptMetadata'])) {
  11395. $out .= ' /EncryptMetadata false';
  11396. } else {
  11397. $out .= ' /EncryptMetadata true';
  11398. }
  11399. }
  11400. $out .= ' >>';
  11401. $out .= "\n".'endobj';
  11402. $this->_out($out);
  11403. }
  11404. /**
  11405. * Returns the input text encrypted using RC4 algorithm and the specified key.
  11406. * RC4 is the standard encryption algorithm used in PDF format
  11407. * @param $key (string) encryption key
  11408. * @param $text (String) input text to be encrypted
  11409. * @return String encrypted text
  11410. * @protected
  11411. * @since 2.0.000 (2008-01-02)
  11412. * @author Klemen Vodopivec, Nicola Asuni
  11413. */
  11414. protected function _RC4($key, $text) {
  11415. if (function_exists('mcrypt_decrypt') AND ($out = @mcrypt_decrypt(MCRYPT_ARCFOUR, $key, $text, MCRYPT_MODE_STREAM, ''))) {
  11416. // try to use mcrypt function if exist
  11417. return $out;
  11418. }
  11419. if ($this->last_enc_key != $key) {
  11420. $k = str_repeat($key, ((256 / strlen($key)) + 1));
  11421. $rc4 = range(0, 255);
  11422. $j = 0;
  11423. for ($i = 0; $i < 256; ++$i) {
  11424. $t = $rc4[$i];
  11425. $j = ($j + $t + ord($k{$i})) % 256;
  11426. $rc4[$i] = $rc4[$j];
  11427. $rc4[$j] = $t;
  11428. }
  11429. $this->last_enc_key = $key;
  11430. $this->last_enc_key_c = $rc4;
  11431. } else {
  11432. $rc4 = $this->last_enc_key_c;
  11433. }
  11434. $len = strlen($text);
  11435. $a = 0;
  11436. $b = 0;
  11437. $out = '';
  11438. for ($i = 0; $i < $len; ++$i) {
  11439. $a = ($a + 1) % 256;
  11440. $t = $rc4[$a];
  11441. $b = ($b + $t) % 256;
  11442. $rc4[$a] = $rc4[$b];
  11443. $rc4[$b] = $t;
  11444. $k = $rc4[($rc4[$a] + $rc4[$b]) % 256];
  11445. $out .= chr(ord($text{$i}) ^ $k);
  11446. }
  11447. return $out;
  11448. }
  11449. /**
  11450. * Returns the input text exrypted using AES algorithm and the specified key.
  11451. * This method requires mcrypt.
  11452. * @param $key (string) encryption key
  11453. * @param $text (String) input text to be encrypted
  11454. * @return String encrypted text
  11455. * @protected
  11456. * @author Nicola Asuni
  11457. * @since 5.0.005 (2010-05-11)
  11458. */
  11459. protected function _AES($key, $text) {
  11460. // padding (RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0)
  11461. $padding = 16 - (strlen($text) % 16);
  11462. $text .= str_repeat(chr($padding), $padding);
  11463. $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND);
  11464. $text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv);
  11465. $text = $iv.$text;
  11466. return $text;
  11467. }
  11468. /**
  11469. * Encrypts a string using MD5 and returns it's value as a binary string.
  11470. * @param $str (string) input string
  11471. * @return String MD5 encrypted binary string
  11472. * @protected
  11473. * @since 2.0.000 (2008-01-02)
  11474. * @author Klemen Vodopivec
  11475. */
  11476. protected function _md5_16($str) {
  11477. return pack('H*', md5($str));
  11478. }
  11479. /**
  11480. * Compute U value (used for encryption)
  11481. * @return string U value
  11482. * @protected
  11483. * @since 2.0.000 (2008-01-02)
  11484. * @author Nicola Asuni
  11485. */
  11486. protected function _Uvalue() {
  11487. if ($this->encryptdata['mode'] == 0) { // RC4-40
  11488. return $this->_RC4($this->encryptdata['key'], $this->enc_padding);
  11489. } elseif ($this->encryptdata['mode'] < 3) { // RC4-128, AES-128
  11490. $tmp = $this->_md5_16($this->enc_padding.$this->encryptdata['fileid']);
  11491. $enc = $this->_RC4($this->encryptdata['key'], $tmp);
  11492. $len = strlen($tmp);
  11493. for ($i = 1; $i <= 19; ++$i) {
  11494. $ek = '';
  11495. for ($j = 0; $j < $len; ++$j) {
  11496. $ek .= chr(ord($this->encryptdata['key']{$j}) ^ $i);
  11497. }
  11498. $enc = $this->_RC4($ek, $enc);
  11499. }
  11500. $enc .= str_repeat("\x00", 16);
  11501. return substr($enc, 0, 32);
  11502. } elseif ($this->encryptdata['mode'] == 3) { // AES-256
  11503. $seed = $this->_md5_16($this->getRandomSeed());
  11504. // User Validation Salt
  11505. $this->encryptdata['UVS'] = substr($seed, 0, 8);
  11506. // User Key Salt
  11507. $this->encryptdata['UKS'] = substr($seed, 8, 16);
  11508. return hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UVS'], true).$this->encryptdata['UVS'].$this->encryptdata['UKS'];
  11509. }
  11510. }
  11511. /**
  11512. * Compute UE value (used for encryption)
  11513. * @return string UE value
  11514. * @protected
  11515. * @since 5.9.006 (2010-10-19)
  11516. * @author Nicola Asuni
  11517. */
  11518. protected function _UEvalue() {
  11519. $hashkey = hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UKS'], true);
  11520. $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
  11521. return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $hashkey, $this->encryptdata['key'], MCRYPT_MODE_CBC, $iv);
  11522. }
  11523. /**
  11524. * Compute O value (used for encryption)
  11525. * @return string O value
  11526. * @protected
  11527. * @since 2.0.000 (2008-01-02)
  11528. * @author Nicola Asuni
  11529. */
  11530. protected function _Ovalue() {
  11531. if ($this->encryptdata['mode'] < 3) { // RC4-40, RC4-128, AES-128
  11532. $tmp = $this->_md5_16($this->encryptdata['owner_password']);
  11533. if ($this->encryptdata['mode'] > 0) {
  11534. for ($i = 0; $i < 50; ++$i) {
  11535. $tmp = $this->_md5_16($tmp);
  11536. }
  11537. }
  11538. $owner_key = substr($tmp, 0, ($this->encryptdata['Length'] / 8));
  11539. $enc = $this->_RC4($owner_key, $this->encryptdata['user_password']);
  11540. if ($this->encryptdata['mode'] > 0) {
  11541. $len = strlen($owner_key);
  11542. for ($i = 1; $i <= 19; ++$i) {
  11543. $ek = '';
  11544. for ($j = 0; $j < $len; ++$j) {
  11545. $ek .= chr(ord($owner_key{$j}) ^ $i);
  11546. }
  11547. $enc = $this->_RC4($ek, $enc);
  11548. }
  11549. }
  11550. return $enc;
  11551. } elseif ($this->encryptdata['mode'] == 3) { // AES-256
  11552. $seed = $this->_md5_16($this->getRandomSeed());
  11553. // Owner Validation Salt
  11554. $this->encryptdata['OVS'] = substr($seed, 0, 8);
  11555. // Owner Key Salt
  11556. $this->encryptdata['OKS'] = substr($seed, 8, 16);
  11557. return hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OVS'].$this->encryptdata['U'], true).$this->encryptdata['OVS'].$this->encryptdata['OKS'];
  11558. }
  11559. }
  11560. /**
  11561. * Compute OE value (used for encryption)
  11562. * @return string OE value
  11563. * @protected
  11564. * @since 5.9.006 (2010-10-19)
  11565. * @author Nicola Asuni
  11566. */
  11567. protected function _OEvalue() {
  11568. $hashkey = hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OKS'].$this->encryptdata['U'], true);
  11569. $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
  11570. return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $hashkey, $this->encryptdata['key'], MCRYPT_MODE_CBC, $iv);
  11571. }
  11572. /**
  11573. * Convert password for AES-256 encryption mode
  11574. * @param $password (string) password
  11575. * @return string password
  11576. * @protected
  11577. * @since 5.9.006 (2010-10-19)
  11578. * @author Nicola Asuni
  11579. */
  11580. protected function _fixAES256Password($password) {
  11581. $psw = ''; // password to be returned
  11582. $psw_array = $this->utf8Bidi($this->UTF8StringToArray($password), $password, $this->rtl);
  11583. foreach ($psw_array as $c) {
  11584. $psw .= $this->unichr($c);
  11585. }
  11586. return substr($psw, 0, 127);
  11587. }
  11588. /**
  11589. * Compute encryption key
  11590. * @protected
  11591. * @since 2.0.000 (2008-01-02)
  11592. * @author Nicola Asuni
  11593. */
  11594. protected function _generateencryptionkey() {
  11595. $keybytelen = ($this->encryptdata['Length'] / 8);
  11596. if (!$this->encryptdata['pubkey']) { // standard mode
  11597. if ($this->encryptdata['mode'] == 3) { // AES-256
  11598. // generate 256 bit random key
  11599. $this->encryptdata['key'] = substr(hash('sha256', $this->getRandomSeed(), true), 0, $keybytelen);
  11600. // truncate passwords
  11601. $this->encryptdata['user_password'] = $this->_fixAES256Password($this->encryptdata['user_password']);
  11602. $this->encryptdata['owner_password'] = $this->_fixAES256Password($this->encryptdata['owner_password']);
  11603. // Compute U value
  11604. $this->encryptdata['U'] = $this->_Uvalue();
  11605. // Compute UE value
  11606. $this->encryptdata['UE'] = $this->_UEvalue();
  11607. // Compute O value
  11608. $this->encryptdata['O'] = $this->_Ovalue();
  11609. // Compute OE value
  11610. $this->encryptdata['OE'] = $this->_OEvalue();
  11611. // Compute P value
  11612. $this->encryptdata['P'] = $this->encryptdata['protection'];
  11613. // Computing the encryption dictionary's Perms (permissions) value
  11614. $perms = $this->getEncPermissionsString($this->encryptdata['protection']); // bytes 0-3
  11615. $perms .= chr(255).chr(255).chr(255).chr(255); // bytes 4-7
  11616. if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) { // byte 8
  11617. $perms .= 'F';
  11618. } else {
  11619. $perms .= 'T';
  11620. }
  11621. $perms .= 'adb'; // bytes 9-11
  11622. $perms .= 'nick'; // bytes 12-15
  11623. $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB));
  11624. $this->encryptdata['perms'] = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->encryptdata['key'], $perms, MCRYPT_MODE_ECB, $iv);
  11625. } else { // RC4-40, RC4-128, AES-128
  11626. // Pad passwords
  11627. $this->encryptdata['user_password'] = substr($this->encryptdata['user_password'].$this->enc_padding, 0, 32);
  11628. $this->encryptdata['owner_password'] = substr($this->encryptdata['owner_password'].$this->enc_padding, 0, 32);
  11629. // Compute O value
  11630. $this->encryptdata['O'] = $this->_Ovalue();
  11631. // get default permissions (reverse byte order)
  11632. $permissions = $this->getEncPermissionsString($this->encryptdata['protection']);
  11633. // Compute encryption key
  11634. $tmp = $this->_md5_16($this->encryptdata['user_password'].$this->encryptdata['O'].$permissions.$this->encryptdata['fileid']);
  11635. if ($this->encryptdata['mode'] > 0) {
  11636. for ($i = 0; $i < 50; ++$i) {
  11637. $tmp = $this->_md5_16(substr($tmp, 0, $keybytelen));
  11638. }
  11639. }
  11640. $this->encryptdata['key'] = substr($tmp, 0, $keybytelen);
  11641. // Compute U value
  11642. $this->encryptdata['U'] = $this->_Uvalue();
  11643. // Compute P value
  11644. $this->encryptdata['P'] = $this->encryptdata['protection'];
  11645. }
  11646. } else { // Public-Key mode
  11647. // random 20-byte seed
  11648. $seed = sha1($this->getRandomSeed(), true);
  11649. $recipient_bytes = '';
  11650. foreach ($this->encryptdata['pubkeys'] as $pubkey) {
  11651. // for each public certificate
  11652. if (isset($pubkey['p'])) {
  11653. $pkprotection = $this->getUserPermissionCode($pubkey['p'], $this->encryptdata['mode']);
  11654. } else {
  11655. $pkprotection = $this->encryptdata['protection'];
  11656. }
  11657. // get default permissions (reverse byte order)
  11658. $pkpermissions = $this->getEncPermissionsString($pkprotection);
  11659. // envelope data
  11660. $envelope = $seed.$pkpermissions;
  11661. // write the envelope data to a temporary file
  11662. $tempkeyfile = tempnam(K_PATH_CACHE, 'tmpkey_');
  11663. $f = fopen($tempkeyfile, 'wb');
  11664. if (!$f) {
  11665. $this->Error('Unable to create temporary key file: '.$tempkeyfile);
  11666. }
  11667. $envelope_lenght = strlen($envelope);
  11668. fwrite($f, $envelope, $envelope_lenght);
  11669. fclose($f);
  11670. $tempencfile = tempnam(K_PATH_CACHE, 'tmpenc_');
  11671. if (!openssl_pkcs7_encrypt($tempkeyfile, $tempencfile, $pubkey['c'], array(), PKCS7_DETACHED | PKCS7_BINARY)) {
  11672. $this->Error('Unable to encrypt the file: '.$tempkeyfile);
  11673. }
  11674. unlink($tempkeyfile);
  11675. // read encryption signature
  11676. $signature = file_get_contents($tempencfile, false, null, $envelope_lenght);
  11677. unlink($tempencfile);
  11678. // extract signature
  11679. $signature = substr($signature, strpos($signature, 'Content-Disposition'));
  11680. $tmparr = explode("\n\n", $signature);
  11681. $signature = trim($tmparr[1]);
  11682. unset($tmparr);
  11683. // decode signature
  11684. $signature = base64_decode($signature);
  11685. // convert signature to hex
  11686. $hexsignature = current(unpack('H*', $signature));
  11687. // store signature on recipients array
  11688. $this->encryptdata['Recipients'][] = $hexsignature;
  11689. // The bytes of each item in the Recipients array of PKCS#7 objects in the order in which they appear in the array
  11690. $recipient_bytes .= $signature;
  11691. }
  11692. // calculate encryption key
  11693. if ($this->encryptdata['mode'] == 3) { // AES-256
  11694. $this->encryptdata['key'] = substr(hash('sha256', $seed.$recipient_bytes, true), 0, $keybytelen);
  11695. } else { // RC4-40, RC4-128, AES-128
  11696. $this->encryptdata['key'] = substr(sha1($seed.$recipient_bytes, true), 0, $keybytelen);
  11697. }
  11698. }
  11699. }
  11700. /**
  11701. * Return the premission code used on encryption (P value).
  11702. * @param $permissions (Array) the set of permissions (specify the ones you want to block).
  11703. * @param $mode (int) encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
  11704. * @protected
  11705. * @since 5.0.005 (2010-05-12)
  11706. * @author Nicola Asuni
  11707. */
  11708. protected function getUserPermissionCode($permissions, $mode=0) {
  11709. $options = array(
  11710. 'owner' => 2, // bit 2 -- inverted logic: cleared by default
  11711. 'print' => 4, // bit 3
  11712. 'modify' => 8, // bit 4
  11713. 'copy' => 16, // bit 5
  11714. 'annot-forms' => 32, // bit 6
  11715. 'fill-forms' => 256, // bit 9
  11716. 'extract' => 512, // bit 10
  11717. 'assemble' => 1024,// bit 11
  11718. 'print-high' => 2048 // bit 12
  11719. );
  11720. $protection = 2147422012; // 32 bit: (01111111 11111111 00001111 00111100)
  11721. foreach ($permissions as $permission) {
  11722. if (!isset($options[$permission])) {
  11723. $this->Error('Incorrect permission: '.$permission);
  11724. }
  11725. if (($mode > 0) OR ($options[$permission] <= 32)) {
  11726. // set only valid permissions
  11727. if ($options[$permission] == 2) {
  11728. // the logic for bit 2 is inverted (cleared by default)
  11729. $protection += $options[$permission];
  11730. } else {
  11731. $protection -= $options[$permission];
  11732. }
  11733. }
  11734. }
  11735. return $protection;
  11736. }
  11737. /**
  11738. * Set document protection
  11739. * Remark: the protection against modification is for people who have the full Acrobat product.
  11740. * 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.
  11741. * 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.
  11742. * @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>
  11743. * @param $user_pass (String) user password. Empty by default.
  11744. * @param $owner_pass (String) owner password. If not specified, a random value is used.
  11745. * @param $mode (int) encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
  11746. * @param $pubkeys (String) array of recipients containing public-key certificates ('c') and permissions ('p'). For example: array(array('c' => 'file://../tcpdf.crt', 'p' => array('print')))
  11747. * @public
  11748. * @since 2.0.000 (2008-01-02)
  11749. * @author Nicola Asuni
  11750. */
  11751. 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) {
  11752. $this->encryptdata['protection'] = $this->getUserPermissionCode($permissions, $mode);
  11753. if (($pubkeys !== null) AND (is_array($pubkeys))) {
  11754. // public-key mode
  11755. $this->encryptdata['pubkeys'] = $pubkeys;
  11756. if ($mode == 0) {
  11757. // public-Key Security requires at least 128 bit
  11758. $mode = 1;
  11759. }
  11760. if (!function_exists('openssl_pkcs7_encrypt')) {
  11761. $this->Error('Public-Key Security requires openssl library.');
  11762. }
  11763. // Set Public-Key filter (availabe are: Entrust.PPKEF, Adobe.PPKLite, Adobe.PubSec)
  11764. $this->encryptdata['pubkey'] = true;
  11765. $this->encryptdata['Filter'] = 'Adobe.PubSec';
  11766. $this->encryptdata['StmF'] = 'DefaultCryptFilter';
  11767. $this->encryptdata['StrF'] = 'DefaultCryptFilter';
  11768. } else {
  11769. // standard mode (password mode)
  11770. $this->encryptdata['pubkey'] = false;
  11771. $this->encryptdata['Filter'] = 'Standard';
  11772. $this->encryptdata['StmF'] = 'StdCF';
  11773. $this->encryptdata['StrF'] = 'StdCF';
  11774. }
  11775. if ($mode > 1) { // AES
  11776. if (!extension_loaded('mcrypt')) {
  11777. $this->Error('AES encryption requires mcrypt library (http://www.php.net/manual/en/mcrypt.requirements.php).');
  11778. }
  11779. if (mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128) === false) {
  11780. $this->Error('AES encryption requires MCRYPT_RIJNDAEL_128 cypher.');
  11781. }
  11782. if (($mode == 3) AND !function_exists('hash')) {
  11783. // the Hash extension requires no external libraries and is enabled by default as of PHP 5.1.2.
  11784. $this->Error('AES 256 encryption requires HASH Message Digest Framework (http://www.php.net/manual/en/book.hash.php).');
  11785. }
  11786. }
  11787. if ($owner_pass === null) {
  11788. $owner_pass = md5($this->getRandomSeed());
  11789. }
  11790. $this->encryptdata['user_password'] = $user_pass;
  11791. $this->encryptdata['owner_password'] = $owner_pass;
  11792. $this->encryptdata['mode'] = $mode;
  11793. switch ($mode) {
  11794. case 0: { // RC4 40 bit
  11795. $this->encryptdata['V'] = 1;
  11796. $this->encryptdata['Length'] = 40;
  11797. $this->encryptdata['CF']['CFM'] = 'V2';
  11798. break;
  11799. }
  11800. case 1: { // RC4 128 bit
  11801. $this->encryptdata['V'] = 2;
  11802. $this->encryptdata['Length'] = 128;
  11803. $this->encryptdata['CF']['CFM'] = 'V2';
  11804. if ($this->encryptdata['pubkey']) {
  11805. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s4';
  11806. $this->encryptdata['Recipients'] = array();
  11807. }
  11808. break;
  11809. }
  11810. case 2: { // AES 128 bit
  11811. $this->encryptdata['V'] = 4;
  11812. $this->encryptdata['Length'] = 128;
  11813. $this->encryptdata['CF']['CFM'] = 'AESV2';
  11814. $this->encryptdata['CF']['Length'] = 128;
  11815. if ($this->encryptdata['pubkey']) {
  11816. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  11817. $this->encryptdata['Recipients'] = array();
  11818. }
  11819. break;
  11820. }
  11821. case 3: { // AES 256 bit
  11822. $this->encryptdata['V'] = 5;
  11823. $this->encryptdata['Length'] = 256;
  11824. $this->encryptdata['CF']['CFM'] = 'AESV3';
  11825. $this->encryptdata['CF']['Length'] = 256;
  11826. if ($this->encryptdata['pubkey']) {
  11827. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  11828. $this->encryptdata['Recipients'] = array();
  11829. }
  11830. break;
  11831. }
  11832. }
  11833. $this->encrypted = true;
  11834. $this->encryptdata['fileid'] = $this->convertHexStringToString($this->file_id);
  11835. $this->_generateencryptionkey();
  11836. }
  11837. /**
  11838. * Convert hexadecimal string to string
  11839. * @param $bs (string) byte-string to convert
  11840. * @return String
  11841. * @protected
  11842. * @since 5.0.005 (2010-05-12)
  11843. * @author Nicola Asuni
  11844. */
  11845. protected function convertHexStringToString($bs) {
  11846. $string = ''; // string to be returned
  11847. $bslenght = strlen($bs);
  11848. if (($bslenght % 2) != 0) {
  11849. // padding
  11850. $bs .= '0';
  11851. ++$bslenght;
  11852. }
  11853. for ($i = 0; $i < $bslenght; $i += 2) {
  11854. $string .= chr(hexdec($bs{$i}.$bs{($i + 1)}));
  11855. }
  11856. return $string;
  11857. }
  11858. /**
  11859. * Convert string to hexadecimal string (byte string)
  11860. * @param $s (string) string to convert
  11861. * @return byte string
  11862. * @protected
  11863. * @since 5.0.010 (2010-05-17)
  11864. * @author Nicola Asuni
  11865. */
  11866. protected function convertStringToHexString($s) {
  11867. $bs = '';
  11868. $chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY);
  11869. foreach ($chars as $c) {
  11870. $bs .= sprintf('%02s', dechex(ord($c)));
  11871. }
  11872. return $bs;
  11873. }
  11874. /**
  11875. * Convert encryption P value to a string of bytes, low-order byte first.
  11876. * @param $protection (string) 32bit encryption permission value (P value)
  11877. * @return String
  11878. * @protected
  11879. * @since 5.0.005 (2010-05-12)
  11880. * @author Nicola Asuni
  11881. */
  11882. protected function getEncPermissionsString($protection) {
  11883. $binprot = sprintf('%032b', $protection);
  11884. $str = chr(bindec(substr($binprot, 24, 8)));
  11885. $str .= chr(bindec(substr($binprot, 16, 8)));
  11886. $str .= chr(bindec(substr($binprot, 8, 8)));
  11887. $str .= chr(bindec(substr($binprot, 0, 8)));
  11888. return $str;
  11889. }
  11890. // END OF ENCRYPTION FUNCTIONS -------------------------
  11891. // START TRANSFORMATIONS SECTION -----------------------
  11892. /**
  11893. * Starts a 2D tranformation saving current graphic state.
  11894. * This function must be called before scaling, mirroring, translation, rotation and skewing.
  11895. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  11896. * @public
  11897. * @since 2.1.000 (2008-01-07)
  11898. * @see StartTransform(), StopTransform()
  11899. */
  11900. public function StartTransform() {
  11901. $this->_out('q');
  11902. if ($this->inxobj) {
  11903. // we are inside an XObject template
  11904. $this->xobjects[$this->xobjid]['transfmrk'][] = strlen($this->xobjects[$this->xobjid]['outdata']);
  11905. } else {
  11906. $this->transfmrk[$this->page][] = $this->pagelen[$this->page];
  11907. }
  11908. ++$this->transfmatrix_key;
  11909. $this->transfmatrix[$this->transfmatrix_key] = array();
  11910. }
  11911. /**
  11912. * Stops a 2D tranformation restoring previous graphic state.
  11913. * This function must be called after scaling, mirroring, translation, rotation and skewing.
  11914. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  11915. * @public
  11916. * @since 2.1.000 (2008-01-07)
  11917. * @see StartTransform(), StopTransform()
  11918. */
  11919. public function StopTransform() {
  11920. $this->_out('Q');
  11921. if (isset($this->transfmatrix[$this->transfmatrix_key])) {
  11922. array_pop($this->transfmatrix[$this->transfmatrix_key]);
  11923. --$this->transfmatrix_key;
  11924. }
  11925. if ($this->inxobj) {
  11926. // we are inside an XObject template
  11927. array_pop($this->xobjects[$this->xobjid]['transfmrk']);
  11928. } else {
  11929. array_pop($this->transfmrk[$this->page]);
  11930. }
  11931. }
  11932. /**
  11933. * Horizontal Scaling.
  11934. * @param $s_x (float) scaling factor for width as percent. 0 is not allowed.
  11935. * @param $x (int) abscissa of the scaling center. Default is current x position
  11936. * @param $y (int) ordinate of the scaling center. Default is current y position
  11937. * @public
  11938. * @since 2.1.000 (2008-01-07)
  11939. * @see StartTransform(), StopTransform()
  11940. */
  11941. public function ScaleX($s_x, $x='', $y='') {
  11942. $this->Scale($s_x, 100, $x, $y);
  11943. }
  11944. /**
  11945. * Vertical Scaling.
  11946. * @param $s_y (float) scaling factor for height as percent. 0 is not allowed.
  11947. * @param $x (int) abscissa of the scaling center. Default is current x position
  11948. * @param $y (int) ordinate of the scaling center. Default is current y position
  11949. * @public
  11950. * @since 2.1.000 (2008-01-07)
  11951. * @see StartTransform(), StopTransform()
  11952. */
  11953. public function ScaleY($s_y, $x='', $y='') {
  11954. $this->Scale(100, $s_y, $x, $y);
  11955. }
  11956. /**
  11957. * Vertical and horizontal proportional Scaling.
  11958. * @param $s (float) scaling factor for width and height as percent. 0 is not allowed.
  11959. * @param $x (int) abscissa of the scaling center. Default is current x position
  11960. * @param $y (int) ordinate of the scaling center. Default is current y position
  11961. * @public
  11962. * @since 2.1.000 (2008-01-07)
  11963. * @see StartTransform(), StopTransform()
  11964. */
  11965. public function ScaleXY($s, $x='', $y='') {
  11966. $this->Scale($s, $s, $x, $y);
  11967. }
  11968. /**
  11969. * Vertical and horizontal non-proportional Scaling.
  11970. * @param $s_x (float) scaling factor for width as percent. 0 is not allowed.
  11971. * @param $s_y (float) scaling factor for height as percent. 0 is not allowed.
  11972. * @param $x (int) abscissa of the scaling center. Default is current x position
  11973. * @param $y (int) ordinate of the scaling center. Default is current y position
  11974. * @public
  11975. * @since 2.1.000 (2008-01-07)
  11976. * @see StartTransform(), StopTransform()
  11977. */
  11978. public function Scale($s_x, $s_y, $x='', $y='') {
  11979. if ($x === '') {
  11980. $x = $this->x;
  11981. }
  11982. if ($y === '') {
  11983. $y = $this->y;
  11984. }
  11985. if (($s_x == 0) OR ($s_y == 0)) {
  11986. $this->Error('Please do not use values equal to zero for scaling');
  11987. }
  11988. $y = ($this->h - $y) * $this->k;
  11989. $x *= $this->k;
  11990. //calculate elements of transformation matrix
  11991. $s_x /= 100;
  11992. $s_y /= 100;
  11993. $tm = array();
  11994. $tm[0] = $s_x;
  11995. $tm[1] = 0;
  11996. $tm[2] = 0;
  11997. $tm[3] = $s_y;
  11998. $tm[4] = $x * (1 - $s_x);
  11999. $tm[5] = $y * (1 - $s_y);
  12000. //scale the coordinate system
  12001. $this->Transform($tm);
  12002. }
  12003. /**
  12004. * Horizontal Mirroring.
  12005. * @param $x (int) abscissa of the point. Default is current x position
  12006. * @public
  12007. * @since 2.1.000 (2008-01-07)
  12008. * @see StartTransform(), StopTransform()
  12009. */
  12010. public function MirrorH($x='') {
  12011. $this->Scale(-100, 100, $x);
  12012. }
  12013. /**
  12014. * Verical Mirroring.
  12015. * @param $y (int) ordinate of the point. Default is current y position
  12016. * @public
  12017. * @since 2.1.000 (2008-01-07)
  12018. * @see StartTransform(), StopTransform()
  12019. */
  12020. public function MirrorV($y='') {
  12021. $this->Scale(100, -100, '', $y);
  12022. }
  12023. /**
  12024. * Point reflection mirroring.
  12025. * @param $x (int) abscissa of the point. Default is current x position
  12026. * @param $y (int) ordinate of the point. Default is current y position
  12027. * @public
  12028. * @since 2.1.000 (2008-01-07)
  12029. * @see StartTransform(), StopTransform()
  12030. */
  12031. public function MirrorP($x='',$y='') {
  12032. $this->Scale(-100, -100, $x, $y);
  12033. }
  12034. /**
  12035. * Reflection against a straight line through point (x, y) with the gradient angle (angle).
  12036. * @param $angle (float) gradient angle of the straight line. Default is 0 (horizontal line).
  12037. * @param $x (int) abscissa of the point. Default is current x position
  12038. * @param $y (int) ordinate of the point. Default is current y position
  12039. * @public
  12040. * @since 2.1.000 (2008-01-07)
  12041. * @see StartTransform(), StopTransform()
  12042. */
  12043. public function MirrorL($angle=0, $x='',$y='') {
  12044. $this->Scale(-100, 100, $x, $y);
  12045. $this->Rotate(-2*($angle-90), $x, $y);
  12046. }
  12047. /**
  12048. * Translate graphic object horizontally.
  12049. * @param $t_x (int) movement to the right (or left for RTL)
  12050. * @public
  12051. * @since 2.1.000 (2008-01-07)
  12052. * @see StartTransform(), StopTransform()
  12053. */
  12054. public function TranslateX($t_x) {
  12055. $this->Translate($t_x, 0);
  12056. }
  12057. /**
  12058. * Translate graphic object vertically.
  12059. * @param $t_y (int) movement to the bottom
  12060. * @public
  12061. * @since 2.1.000 (2008-01-07)
  12062. * @see StartTransform(), StopTransform()
  12063. */
  12064. public function TranslateY($t_y) {
  12065. $this->Translate(0, $t_y);
  12066. }
  12067. /**
  12068. * Translate graphic object horizontally and vertically.
  12069. * @param $t_x (int) movement to the right
  12070. * @param $t_y (int) movement to the bottom
  12071. * @public
  12072. * @since 2.1.000 (2008-01-07)
  12073. * @see StartTransform(), StopTransform()
  12074. */
  12075. public function Translate($t_x, $t_y) {
  12076. //calculate elements of transformation matrix
  12077. $tm = array();
  12078. $tm[0] = 1;
  12079. $tm[1] = 0;
  12080. $tm[2] = 0;
  12081. $tm[3] = 1;
  12082. $tm[4] = $t_x * $this->k;
  12083. $tm[5] = -$t_y * $this->k;
  12084. //translate the coordinate system
  12085. $this->Transform($tm);
  12086. }
  12087. /**
  12088. * Rotate object.
  12089. * @param $angle (float) angle in degrees for counter-clockwise rotation
  12090. * @param $x (int) abscissa of the rotation center. Default is current x position
  12091. * @param $y (int) ordinate of the rotation center. Default is current y position
  12092. * @public
  12093. * @since 2.1.000 (2008-01-07)
  12094. * @see StartTransform(), StopTransform()
  12095. */
  12096. public function Rotate($angle, $x='', $y='') {
  12097. if ($x === '') {
  12098. $x = $this->x;
  12099. }
  12100. if ($y === '') {
  12101. $y = $this->y;
  12102. }
  12103. $y = ($this->h - $y) * $this->k;
  12104. $x *= $this->k;
  12105. //calculate elements of transformation matrix
  12106. $tm = array();
  12107. $tm[0] = cos(deg2rad($angle));
  12108. $tm[1] = sin(deg2rad($angle));
  12109. $tm[2] = -$tm[1];
  12110. $tm[3] = $tm[0];
  12111. $tm[4] = $x + ($tm[1] * $y) - ($tm[0] * $x);
  12112. $tm[5] = $y - ($tm[0] * $y) - ($tm[1] * $x);
  12113. //rotate the coordinate system around ($x,$y)
  12114. $this->Transform($tm);
  12115. }
  12116. /**
  12117. * Skew horizontally.
  12118. * @param $angle_x (float) angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  12119. * @param $x (int) abscissa of the skewing center. default is current x position
  12120. * @param $y (int) ordinate of the skewing center. default is current y position
  12121. * @public
  12122. * @since 2.1.000 (2008-01-07)
  12123. * @see StartTransform(), StopTransform()
  12124. */
  12125. public function SkewX($angle_x, $x='', $y='') {
  12126. $this->Skew($angle_x, 0, $x, $y);
  12127. }
  12128. /**
  12129. * Skew vertically.
  12130. * @param $angle_y (float) angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  12131. * @param $x (int) abscissa of the skewing center. default is current x position
  12132. * @param $y (int) ordinate of the skewing center. default is current y position
  12133. * @public
  12134. * @since 2.1.000 (2008-01-07)
  12135. * @see StartTransform(), StopTransform()
  12136. */
  12137. public function SkewY($angle_y, $x='', $y='') {
  12138. $this->Skew(0, $angle_y, $x, $y);
  12139. }
  12140. /**
  12141. * Skew.
  12142. * @param $angle_x (float) angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  12143. * @param $angle_y (float) angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  12144. * @param $x (int) abscissa of the skewing center. default is current x position
  12145. * @param $y (int) ordinate of the skewing center. default is current y position
  12146. * @public
  12147. * @since 2.1.000 (2008-01-07)
  12148. * @see StartTransform(), StopTransform()
  12149. */
  12150. public function Skew($angle_x, $angle_y, $x='', $y='') {
  12151. if ($x === '') {
  12152. $x = $this->x;
  12153. }
  12154. if ($y === '') {
  12155. $y = $this->y;
  12156. }
  12157. if (($angle_x <= -90) OR ($angle_x >= 90) OR ($angle_y <= -90) OR ($angle_y >= 90)) {
  12158. $this->Error('Please use values between -90 and +90 degrees for Skewing.');
  12159. }
  12160. $x *= $this->k;
  12161. $y = ($this->h - $y) * $this->k;
  12162. //calculate elements of transformation matrix
  12163. $tm = array();
  12164. $tm[0] = 1;
  12165. $tm[1] = tan(deg2rad($angle_y));
  12166. $tm[2] = tan(deg2rad($angle_x));
  12167. $tm[3] = 1;
  12168. $tm[4] = -$tm[2] * $y;
  12169. $tm[5] = -$tm[1] * $x;
  12170. //skew the coordinate system
  12171. $this->Transform($tm);
  12172. }
  12173. /**
  12174. * Apply graphic transformations.
  12175. * @param $tm (array) transformation matrix
  12176. * @protected
  12177. * @since 2.1.000 (2008-01-07)
  12178. * @see StartTransform(), StopTransform()
  12179. */
  12180. protected function Transform($tm) {
  12181. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
  12182. // add tranformation matrix
  12183. $this->transfmatrix[$this->transfmatrix_key][] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]);
  12184. // update transformation mark
  12185. if ($this->inxobj) {
  12186. // we are inside an XObject template
  12187. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  12188. $key = key($this->xobjects[$this->xobjid]['transfmrk']);
  12189. $this->xobjects[$this->xobjid]['transfmrk'][$key] = strlen($this->xobjects[$this->xobjid]['outdata']);
  12190. }
  12191. } elseif (end($this->transfmrk[$this->page]) !== false) {
  12192. $key = key($this->transfmrk[$this->page]);
  12193. $this->transfmrk[$this->page][$key] = $this->pagelen[$this->page];
  12194. }
  12195. }
  12196. // END TRANSFORMATIONS SECTION -------------------------
  12197. // START GRAPHIC FUNCTIONS SECTION ---------------------
  12198. // The following section is based on the code provided by David Hernandez Sanz
  12199. /**
  12200. * 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.
  12201. * @param $width (float) The width.
  12202. * @public
  12203. * @since 1.0
  12204. * @see Line(), Rect(), Cell(), MultiCell()
  12205. */
  12206. public function SetLineWidth($width) {
  12207. //Set line width
  12208. $this->LineWidth = $width;
  12209. $this->linestyleWidth = sprintf('%.2F w', ($width * $this->k));
  12210. if ($this->page > 0) {
  12211. $this->_out($this->linestyleWidth);
  12212. }
  12213. }
  12214. /**
  12215. * Returns the current the line width.
  12216. * @return int Line width
  12217. * @public
  12218. * @since 2.1.000 (2008-01-07)
  12219. * @see Line(), SetLineWidth()
  12220. */
  12221. public function GetLineWidth() {
  12222. return $this->LineWidth;
  12223. }
  12224. /**
  12225. * Set line style.
  12226. * @param $style (array) Line style. Array with keys among the following:
  12227. * <ul>
  12228. * <li>width (float): Width of the line in user units.</li>
  12229. * <li>cap (string): Type of cap to put on the line. Possible values are:
  12230. * butt, round, square. The difference between "square" and "butt" is that
  12231. * "square" projects a flat end past the end of the line.</li>
  12232. * <li>join (string): Type of join. Possible values are: miter, round,
  12233. * bevel.</li>
  12234. * <li>dash (mixed): Dash pattern. Is 0 (without dash) or string with
  12235. * series of length values, which are the lengths of the on and off dashes.
  12236. * For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
  12237. * 1 off, 2 on, 1 off, ...</li>
  12238. * <li>phase (integer): Modifier on the dash pattern which is used to shift
  12239. * the point at which the pattern starts.</li>
  12240. * <li>color (array): Draw color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K).</li>
  12241. * </ul>
  12242. * @param $ret (boolean) if true do not send the command.
  12243. * @return string the PDF command
  12244. * @public
  12245. * @since 2.1.000 (2008-01-08)
  12246. */
  12247. public function SetLineStyle($style, $ret=false) {
  12248. $s = ''; // string to be returned
  12249. if (!is_array($style)) {
  12250. return;
  12251. }
  12252. extract($style);
  12253. if (isset($width)) {
  12254. $this->LineWidth = $width;
  12255. $this->linestyleWidth = sprintf('%.2F w', ($width * $this->k));
  12256. $s .= $this->linestyleWidth.' ';
  12257. }
  12258. if (isset($cap)) {
  12259. $ca = array('butt' => 0, 'round'=> 1, 'square' => 2);
  12260. if (isset($ca[$cap])) {
  12261. $this->linestyleCap = $ca[$cap].' J';
  12262. $s .= $this->linestyleCap.' ';
  12263. }
  12264. }
  12265. if (isset($join)) {
  12266. $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2);
  12267. if (isset($ja[$join])) {
  12268. $this->linestyleJoin = $ja[$join].' j';
  12269. $s .= $this->linestyleJoin.' ';
  12270. }
  12271. }
  12272. if (isset($dash)) {
  12273. $dash_string = '';
  12274. if ($dash) {
  12275. if (preg_match('/^.+,/', $dash) > 0) {
  12276. $tab = explode(',', $dash);
  12277. } else {
  12278. $tab = array($dash);
  12279. }
  12280. $dash_string = '';
  12281. foreach ($tab as $i => $v) {
  12282. if ($i) {
  12283. $dash_string .= ' ';
  12284. }
  12285. $dash_string .= sprintf('%.2F', $v);
  12286. }
  12287. }
  12288. if (!isset($phase) OR !$dash) {
  12289. $phase = 0;
  12290. }
  12291. $this->linestyleDash = sprintf('[%s] %.2F d', $dash_string, $phase);
  12292. $s .= $this->linestyleDash.' ';
  12293. }
  12294. if (isset($color)) {
  12295. $s .= $this->SetDrawColorArray($color, true).' ';
  12296. }
  12297. if (!$ret) {
  12298. $this->_out($s);
  12299. }
  12300. return $s;
  12301. }
  12302. /**
  12303. * Begin a new subpath by moving the current point to coordinates (x, y), omitting any connecting line segment.
  12304. * @param $x (float) Abscissa of point.
  12305. * @param $y (float) Ordinate of point.
  12306. * @protected
  12307. * @since 2.1.000 (2008-01-08)
  12308. */
  12309. protected function _outPoint($x, $y) {
  12310. $this->_out(sprintf('%.2F %.2F m', $x * $this->k, ($this->h - $y) * $this->k));
  12311. }
  12312. /**
  12313. * Append a straight line segment from the current point to the point (x, y).
  12314. * The new current point shall be (x, y).
  12315. * @param $x (float) Abscissa of end point.
  12316. * @param $y (float) Ordinate of end point.
  12317. * @protected
  12318. * @since 2.1.000 (2008-01-08)
  12319. */
  12320. protected function _outLine($x, $y) {
  12321. $this->_out(sprintf('%.2F %.2F l', $x * $this->k, ($this->h - $y) * $this->k));
  12322. }
  12323. /**
  12324. * Append a rectangle to the current path as a complete subpath, with lower-left corner (x, y) and dimensions widthand height in user space.
  12325. * @param $x (float) Abscissa of upper-left corner.
  12326. * @param $y (float) Ordinate of upper-left corner.
  12327. * @param $w (float) Width.
  12328. * @param $h (float) Height.
  12329. * @param $op (string) options
  12330. * @protected
  12331. * @since 2.1.000 (2008-01-08)
  12332. */
  12333. protected function _outRect($x, $y, $w, $h, $op) {
  12334. $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s', $x * $this->k, ($this->h - $y) * $this->k, $w * $this->k, -$h * $this->k, $op));
  12335. }
  12336. /**
  12337. * Append a cubic Bézier 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ézier control points.
  12338. * The new current point shall be (x3, y3).
  12339. * @param $x1 (float) Abscissa of control point 1.
  12340. * @param $y1 (float) Ordinate of control point 1.
  12341. * @param $x2 (float) Abscissa of control point 2.
  12342. * @param $y2 (float) Ordinate of control point 2.
  12343. * @param $x3 (float) Abscissa of end point.
  12344. * @param $y3 (float) Ordinate of end point.
  12345. * @protected
  12346. * @since 2.1.000 (2008-01-08)
  12347. */
  12348. protected function _outCurve($x1, $y1, $x2, $y2, $x3, $y3) {
  12349. $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F 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));
  12350. }
  12351. /**
  12352. * Append a cubic Bézier 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ézier control points.
  12353. * The new current point shall be (x3, y3).
  12354. * @param $x2 (float) Abscissa of control point 2.
  12355. * @param $y2 (float) Ordinate of control point 2.
  12356. * @param $x3 (float) Abscissa of end point.
  12357. * @param $y3 (float) Ordinate of end point.
  12358. * @protected
  12359. * @since 4.9.019 (2010-04-26)
  12360. */
  12361. protected function _outCurveV($x2, $y2, $x3, $y3) {
  12362. $this->_out(sprintf('%.2F %.2F %.2F %.2F v', $x2 * $this->k, ($this->h - $y2) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k));
  12363. }
  12364. /**
  12365. * Append a cubic Bézier 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ézier control points.
  12366. * The new current point shall be (x3, y3).
  12367. * @param $x1 (float) Abscissa of control point 1.
  12368. * @param $y1 (float) Ordinate of control point 1.
  12369. * @param $x3 (float) Abscissa of end point.
  12370. * @param $y3 (float) Ordinate of end point.
  12371. * @protected
  12372. * @since 2.1.000 (2008-01-08)
  12373. */
  12374. protected function _outCurveY($x1, $y1, $x3, $y3) {
  12375. $this->_out(sprintf('%.2F %.2F %.2F %.2F y', $x1 * $this->k, ($this->h - $y1) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k));
  12376. }
  12377. /**
  12378. * Draws a line between two points.
  12379. * @param $x1 (float) Abscissa of first point.
  12380. * @param $y1 (float) Ordinate of first point.
  12381. * @param $x2 (float) Abscissa of second point.
  12382. * @param $y2 (float) Ordinate of second point.
  12383. * @param $style (array) Line style. Array like for SetLineStyle(). Default value: default line style (empty array).
  12384. * @public
  12385. * @since 1.0
  12386. * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
  12387. */
  12388. public function Line($x1, $y1, $x2, $y2, $style=array()) {
  12389. if (is_array($style)) {
  12390. $this->SetLineStyle($style);
  12391. }
  12392. $this->_outPoint($x1, $y1);
  12393. $this->_outLine($x2, $y2);
  12394. $this->_out('S');
  12395. }
  12396. /**
  12397. * Draws a rectangle.
  12398. * @param $x (float) Abscissa of upper-left corner.
  12399. * @param $y (float) Ordinate of upper-left corner.
  12400. * @param $w (float) Width.
  12401. * @param $h (float) Height.
  12402. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  12403. * @param $border_style (array) Border style of rectangle. Array with keys among the following:
  12404. * <ul>
  12405. * <li>all: Line style of all borders. Array like for SetLineStyle().</li>
  12406. * <li>L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for SetLineStyle().</li>
  12407. * </ul>
  12408. * If a key is not present or is null, not draws the border. Default value: default line style (empty array).
  12409. * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  12410. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  12411. * @public
  12412. * @since 1.0
  12413. * @see SetLineStyle()
  12414. */
  12415. public function Rect($x, $y, $w, $h, $style='', $border_style=array(), $fill_color=array()) {
  12416. if (!(false === strpos($style, 'F')) AND !empty($fill_color)) {
  12417. $this->SetFillColorArray($fill_color);
  12418. }
  12419. $op = $this->getPathPaintOperator($style);
  12420. if ((!$border_style) OR (isset($border_style['all']))) {
  12421. if (isset($border_style['all']) AND $border_style['all']) {
  12422. $this->SetLineStyle($border_style['all']);
  12423. $border_style = array();
  12424. }
  12425. }
  12426. $this->_outRect($x, $y, $w, $h, $op);
  12427. if ($border_style) {
  12428. $border_style2 = array();
  12429. foreach ($border_style as $line => $value) {
  12430. $length = strlen($line);
  12431. for ($i = 0; $i < $length; ++$i) {
  12432. $border_style2[$line[$i]] = $value;
  12433. }
  12434. }
  12435. $border_style = $border_style2;
  12436. if (isset($border_style['L']) AND $border_style['L']) {
  12437. $this->Line($x, $y, $x, $y + $h, $border_style['L']);
  12438. }
  12439. if (isset($border_style['T']) AND $border_style['T']) {
  12440. $this->Line($x, $y, $x + $w, $y, $border_style['T']);
  12441. }
  12442. if (isset($border_style['R']) AND $border_style['R']) {
  12443. $this->Line($x + $w, $y, $x + $w, $y + $h, $border_style['R']);
  12444. }
  12445. if (isset($border_style['B']) AND $border_style['B']) {
  12446. $this->Line($x, $y + $h, $x + $w, $y + $h, $border_style['B']);
  12447. }
  12448. }
  12449. }
  12450. /**
  12451. * Draws a Bezier curve.
  12452. * The Bezier curve is a tangent to the line between the control points at
  12453. * either end of the curve.
  12454. * @param $x0 (float) Abscissa of start point.
  12455. * @param $y0 (float) Ordinate of start point.
  12456. * @param $x1 (float) Abscissa of control point 1.
  12457. * @param $y1 (float) Ordinate of control point 1.
  12458. * @param $x2 (float) Abscissa of control point 2.
  12459. * @param $y2 (float) Ordinate of control point 2.
  12460. * @param $x3 (float) Abscissa of end point.
  12461. * @param $y3 (float) Ordinate of end point.
  12462. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  12463. * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
  12464. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  12465. * @public
  12466. * @see SetLineStyle()
  12467. * @since 2.1.000 (2008-01-08)
  12468. */
  12469. public function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style='', $line_style=array(), $fill_color=array()) {
  12470. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  12471. $this->SetFillColorArray($fill_color);
  12472. }
  12473. $op = $this->getPathPaintOperator($style);
  12474. if ($line_style) {
  12475. $this->SetLineStyle($line_style);
  12476. }
  12477. $this->_outPoint($x0, $y0);
  12478. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  12479. $this->_out($op);
  12480. }
  12481. /**
  12482. * Draws a poly-Bezier curve.
  12483. * Each Bezier curve segment is a tangent to the line between the control points at
  12484. * either end of the curve.
  12485. * @param $x0 (float) Abscissa of start point.
  12486. * @param $y0 (float) Ordinate of start point.
  12487. * @param $segments (float) An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
  12488. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  12489. * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
  12490. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  12491. * @public
  12492. * @see SetLineStyle()
  12493. * @since 3.0008 (2008-05-12)
  12494. */
  12495. public function Polycurve($x0, $y0, $segments, $style='', $line_style=array(), $fill_color=array()) {
  12496. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  12497. $this->SetFillColorArray($fill_color);
  12498. }
  12499. $op = $this->getPathPaintOperator($style);
  12500. if ($op == 'f') {
  12501. $line_style = array();
  12502. }
  12503. if ($line_style) {
  12504. $this->SetLineStyle($line_style);
  12505. }
  12506. $this->_outPoint($x0, $y0);
  12507. foreach ($segments as $segment) {
  12508. list($x1, $y1, $x2, $y2, $x3, $y3) = $segment;
  12509. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  12510. }
  12511. $this->_out($op);
  12512. }
  12513. /**
  12514. * Draws an ellipse.
  12515. * An ellipse is formed from n Bezier curves.
  12516. * @param $x0 (float) Abscissa of center point.
  12517. * @param $y0 (float) Ordinate of center point.
  12518. * @param $rx (float) Horizontal radius.
  12519. * @param $ry (float) Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
  12520. * @param $angle: (float) Angle oriented (anti-clockwise). Default value: 0.
  12521. * @param $astart: (float) Angle start of draw line. Default value: 0.
  12522. * @param $afinish: (float) Angle finish of draw line. Default value: 360.
  12523. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  12524. * @param $line_style (array) Line style of ellipse. Array like for SetLineStyle(). Default value: default line style (empty array).
  12525. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  12526. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse.
  12527. * @author Nicola Asuni
  12528. * @public
  12529. * @since 2.1.000 (2008-01-08)
  12530. */
  12531. public function Ellipse($x0, $y0, $rx, $ry='', $angle=0, $astart=0, $afinish=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
  12532. if ($this->empty_string($ry) OR ($ry == 0)) {
  12533. $ry = $rx;
  12534. }
  12535. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  12536. $this->SetFillColorArray($fill_color);
  12537. }
  12538. $op = $this->getPathPaintOperator($style);
  12539. if ($op == 'f') {
  12540. $line_style = array();
  12541. }
  12542. if ($line_style) {
  12543. $this->SetLineStyle($line_style);
  12544. }
  12545. $this->_outellipticalarc($x0, $y0, $rx, $ry, $angle, $astart, $afinish, false, $nc, true, true, false);
  12546. $this->_out($op);
  12547. }
  12548. /**
  12549. * Append an elliptical arc to the current path.
  12550. * An ellipse is formed from n Bezier curves.
  12551. * @param $xc (float) Abscissa of center point.
  12552. * @param $yc (float) Ordinate of center point.
  12553. * @param $rx (float) Horizontal radius.
  12554. * @param $ry (float) Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
  12555. * @param $xang: (float) Angle between the X-axis and the major axis of the ellipse. Default value: 0.
  12556. * @param $angs: (float) Angle start of draw line. Default value: 0.
  12557. * @param $angf: (float) Angle finish of draw line. Default value: 360.
  12558. * @param $pie (boolean) if true do not mark the border point (used to draw pie sectors).
  12559. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse.
  12560. * @param $startpoint (boolean) if true output a starting point.
  12561. * @param $ccw (boolean) if true draws in counter-clockwise.
  12562. * @param $svg (boolean) if true the angles are in svg mode (already calculated).
  12563. * @return array bounding box coordinates (x min, y min, x max, y max)
  12564. * @author Nicola Asuni
  12565. * @protected
  12566. * @since 4.9.019 (2010-04-26)
  12567. */
  12568. protected function _outellipticalarc($xc, $yc, $rx, $ry, $xang=0, $angs=0, $angf=360, $pie=false, $nc=2, $startpoint=true, $ccw=true, $svg=false) {
  12569. $k = $this->k;
  12570. if ($nc < 2) {
  12571. $nc = 2;
  12572. }
  12573. $xmin = 2147483647;
  12574. $ymin = 2147483647;
  12575. $xmax = 0;
  12576. $ymax = 0;
  12577. if ($pie) {
  12578. // center of the arc
  12579. $this->_outPoint($xc, $yc);
  12580. }
  12581. $xang = deg2rad((float) $xang);
  12582. $angs = deg2rad((float) $angs);
  12583. $angf = deg2rad((float) $angf);
  12584. if ($svg) {
  12585. $as = $angs;
  12586. $af = $angf;
  12587. } else {
  12588. $as = atan2((sin($angs) / $ry), (cos($angs) / $rx));
  12589. $af = atan2((sin($angf) / $ry), (cos($angf) / $rx));
  12590. }
  12591. if ($as < 0) {
  12592. $as += (2 * M_PI);
  12593. }
  12594. if ($af < 0) {
  12595. $af += (2 * M_PI);
  12596. }
  12597. if ($ccw AND ($as > $af)) {
  12598. // reverse rotation
  12599. $as -= (2 * M_PI);
  12600. } elseif (!$ccw AND ($as < $af)) {
  12601. // reverse rotation
  12602. $af -= (2 * M_PI);
  12603. }
  12604. $total_angle = ($af - $as);
  12605. if ($nc < 2) {
  12606. $nc = 2;
  12607. }
  12608. // total arcs to draw
  12609. $nc *= (2 * abs($total_angle) / M_PI);
  12610. $nc = round($nc) + 1;
  12611. // angle of each arc
  12612. $arcang = ($total_angle / $nc);
  12613. // center point in PDF coordinates
  12614. $x0 = $xc;
  12615. $y0 = ($this->h - $yc);
  12616. // starting angle
  12617. $ang = $as;
  12618. $alpha = sin($arcang) * ((sqrt(4 + (3 * pow(tan(($arcang) / 2), 2))) - 1) / 3);
  12619. $cos_xang = cos($xang);
  12620. $sin_xang = sin($xang);
  12621. $cos_ang = cos($ang);
  12622. $sin_ang = sin($ang);
  12623. // first arc point
  12624. $px1 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
  12625. $py1 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
  12626. // first Bezier control point
  12627. $qx1 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
  12628. $qy1 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
  12629. if ($pie) {
  12630. // line from center to arc starting point
  12631. $this->_outLine($px1, $this->h - $py1);
  12632. } elseif ($startpoint) {
  12633. // arc starting point
  12634. $this->_outPoint($px1, $this->h - $py1);
  12635. }
  12636. // draw arcs
  12637. for ($i = 1; $i <= $nc; ++$i) {
  12638. // starting angle
  12639. $ang = $as + ($i * $arcang);
  12640. if ($i == $nc) {
  12641. $ang = $af;
  12642. }
  12643. $cos_ang = cos($ang);
  12644. $sin_ang = sin($ang);
  12645. // second arc point
  12646. $px2 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
  12647. $py2 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
  12648. // second Bezier control point
  12649. $qx2 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
  12650. $qy2 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
  12651. // draw arc
  12652. $cx1 = ($px1 + $qx1);
  12653. $cy1 = ($this->h - ($py1 + $qy1));
  12654. $cx2 = ($px2 - $qx2);
  12655. $cy2 = ($this->h - ($py2 - $qy2));
  12656. $cx3 = $px2;
  12657. $cy3 = ($this->h - $py2);
  12658. $this->_outCurve($cx1, $cy1, $cx2, $cy2, $cx3, $cy3);
  12659. // get bounding box coordinates
  12660. $xmin = min($xmin, $cx1, $cx2, $cx3);
  12661. $ymin = min($ymin, $cy1, $cy2, $cy3);
  12662. $xmax = max($xmax, $cx1, $cx2, $cx3);
  12663. $ymax = max($ymax, $cy1, $cy2, $cy3);
  12664. // move to next point
  12665. $px1 = $px2;
  12666. $py1 = $py2;
  12667. $qx1 = $qx2;
  12668. $qy1 = $qy2;
  12669. }
  12670. if ($pie) {
  12671. $this->_outLine($xc, $yc);
  12672. // get bounding box coordinates
  12673. $xmin = min($xmin, $xc);
  12674. $ymin = min($ymin, $yc);
  12675. $xmax = max($xmax, $xc);
  12676. $ymax = max($ymax, $yc);
  12677. }
  12678. return array($xmin, $ymin, $xmax, $ymax);
  12679. }
  12680. /**
  12681. * Draws a circle.
  12682. * A circle is formed from n Bezier curves.
  12683. * @param $x0 (float) Abscissa of center point.
  12684. * @param $y0 (float) Ordinate of center point.
  12685. * @param $r (float) Radius.
  12686. * @param $angstr: (float) Angle start of draw line. Default value: 0.
  12687. * @param $angend: (float) Angle finish of draw line. Default value: 360.
  12688. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  12689. * @param $line_style (array) Line style of circle. Array like for SetLineStyle(). Default value: default line style (empty array).
  12690. * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  12691. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of circle.
  12692. * @public
  12693. * @since 2.1.000 (2008-01-08)
  12694. */
  12695. public function Circle($x0, $y0, $r, $angstr=0, $angend=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
  12696. $this->Ellipse($x0, $y0, $r, $r, 0, $angstr, $angend, $style, $line_style, $fill_color, $nc);
  12697. }
  12698. /**
  12699. * Draws a polygonal line
  12700. * @param $p (array) Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  12701. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  12702. * @param $line_style (array) Line style of polygon. Array with keys among the following:
  12703. * <ul>
  12704. * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
  12705. * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
  12706. * </ul>
  12707. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  12708. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  12709. * @since 4.8.003 (2009-09-15)
  12710. * @public
  12711. */
  12712. public function PolyLine($p, $style='', $line_style=array(), $fill_color=array()) {
  12713. $this->Polygon($p, $style, $line_style, $fill_color, false);
  12714. }
  12715. /**
  12716. * Draws a polygon.
  12717. * @param $p (array) Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  12718. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  12719. * @param $line_style (array) Line style of polygon. Array with keys among the following:
  12720. * <ul>
  12721. * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
  12722. * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
  12723. * </ul>
  12724. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  12725. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  12726. * @param $closed (boolean) if true the polygon is closes, otherwise will remain open
  12727. * @public
  12728. * @since 2.1.000 (2008-01-08)
  12729. */
  12730. public function Polygon($p, $style='', $line_style=array(), $fill_color=array(), $closed=true) {
  12731. $nc = count($p); // number of coordinates
  12732. $np = $nc / 2; // number of points
  12733. if ($closed) {
  12734. // close polygon by adding the first 2 points at the end (one line)
  12735. for ($i = 0; $i < 4; ++$i) {
  12736. $p[$nc + $i] = $p[$i];
  12737. }
  12738. // copy style for the last added line
  12739. if (isset($line_style[0])) {
  12740. $line_style[$np] = $line_style[0];
  12741. }
  12742. $nc += 4;
  12743. }
  12744. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  12745. $this->SetFillColorArray($fill_color);
  12746. }
  12747. $op = $this->getPathPaintOperator($style);
  12748. if ($op == 'f') {
  12749. $line_style = array();
  12750. }
  12751. $draw = true;
  12752. if ($line_style) {
  12753. if (isset($line_style['all'])) {
  12754. $this->SetLineStyle($line_style['all']);
  12755. } else {
  12756. $draw = false;
  12757. if ($op == 'B') {
  12758. // draw fill
  12759. $op = 'f';
  12760. $this->_outPoint($p[0], $p[1]);
  12761. for ($i = 2; $i < $nc; $i = $i + 2) {
  12762. $this->_outLine($p[$i], $p[$i + 1]);
  12763. }
  12764. $this->_out($op);
  12765. }
  12766. // draw outline
  12767. $this->_outPoint($p[0], $p[1]);
  12768. for ($i = 2; $i < $nc; $i = $i + 2) {
  12769. $line_num = ($i / 2) - 1;
  12770. if (isset($line_style[$line_num])) {
  12771. if ($line_style[$line_num] != 0) {
  12772. if (is_array($line_style[$line_num])) {
  12773. $this->_out('S');
  12774. $this->SetLineStyle($line_style[$line_num]);
  12775. $this->_outPoint($p[$i - 2], $p[$i - 1]);
  12776. $this->_outLine($p[$i], $p[$i + 1]);
  12777. $this->_out('S');
  12778. $this->_outPoint($p[$i], $p[$i + 1]);
  12779. } else {
  12780. $this->_outLine($p[$i], $p[$i + 1]);
  12781. }
  12782. }
  12783. } else {
  12784. $this->_outLine($p[$i], $p[$i + 1]);
  12785. }
  12786. }
  12787. $this->_out($op);
  12788. }
  12789. }
  12790. if ($draw) {
  12791. $this->_outPoint($p[0], $p[1]);
  12792. for ($i = 2; $i < $nc; $i = $i + 2) {
  12793. $this->_outLine($p[$i], $p[$i + 1]);
  12794. }
  12795. $this->_out($op);
  12796. }
  12797. }
  12798. /**
  12799. * Draws a regular polygon.
  12800. * @param $x0 (float) Abscissa of center point.
  12801. * @param $y0 (float) Ordinate of center point.
  12802. * @param $r: (float) Radius of inscribed circle.
  12803. * @param $ns (integer) Number of sides.
  12804. * @param $angle (float) Angle oriented (anti-clockwise). Default value: 0.
  12805. * @param $draw_circle (boolean) Draw inscribed circle or not. Default value: false.
  12806. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  12807. * @param $line_style (array) Line style of polygon sides. Array with keys among the following:
  12808. * <ul>
  12809. * <li>all: Line style of all sides. Array like for SetLineStyle().</li>
  12810. * <li>0 to ($ns - 1): Line style of each side. Array like for SetLineStyle().</li>
  12811. * </ul>
  12812. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  12813. * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  12814. * @param $circle_style (string) Style of rendering of inscribed circle (if draws). Possible values are:
  12815. * <ul>
  12816. * <li>D or empty string: Draw (default).</li>
  12817. * <li>F: Fill.</li>
  12818. * <li>DF or FD: Draw and fill.</li>
  12819. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  12820. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  12821. * </ul>
  12822. * @param $circle_outLine_style (array) Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
  12823. * @param $circle_fill_color (array) Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  12824. * @public
  12825. * @since 2.1.000 (2008-01-08)
  12826. */
  12827. 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()) {
  12828. if (3 > $ns) {
  12829. $ns = 3;
  12830. }
  12831. if ($draw_circle) {
  12832. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  12833. }
  12834. $p = array();
  12835. for ($i = 0; $i < $ns; ++$i) {
  12836. $a = $angle + ($i * 360 / $ns);
  12837. $a_rad = deg2rad((float) $a);
  12838. $p[] = $x0 + ($r * sin($a_rad));
  12839. $p[] = $y0 + ($r * cos($a_rad));
  12840. }
  12841. $this->Polygon($p, $style, $line_style, $fill_color);
  12842. }
  12843. /**
  12844. * Draws a star polygon
  12845. * @param $x0 (float) Abscissa of center point.
  12846. * @param $y0 (float) Ordinate of center point.
  12847. * @param $r (float) Radius of inscribed circle.
  12848. * @param $nv (integer) Number of vertices.
  12849. * @param $ng (integer) Number of gap (if ($ng % $nv = 1) then is a regular polygon).
  12850. * @param $angle: (float) Angle oriented (anti-clockwise). Default value: 0.
  12851. * @param $draw_circle: (boolean) Draw inscribed circle or not. Default value is false.
  12852. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  12853. * @param $line_style (array) Line style of polygon sides. Array with keys among the following:
  12854. * <ul>
  12855. * <li>all: Line style of all sides. Array like for
  12856. * SetLineStyle().</li>
  12857. * <li>0 to (n - 1): Line style of each side. Array like for SetLineStyle().</li>
  12858. * </ul>
  12859. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  12860. * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  12861. * @param $circle_style (string) Style of rendering of inscribed circle (if draws). Possible values are:
  12862. * <ul>
  12863. * <li>D or empty string: Draw (default).</li>
  12864. * <li>F: Fill.</li>
  12865. * <li>DF or FD: Draw and fill.</li>
  12866. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  12867. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  12868. * </ul>
  12869. * @param $circle_outLine_style (array) Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
  12870. * @param $circle_fill_color (array) Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  12871. * @public
  12872. * @since 2.1.000 (2008-01-08)
  12873. */
  12874. 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()) {
  12875. if ($nv < 2) {
  12876. $nv = 2;
  12877. }
  12878. if ($draw_circle) {
  12879. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  12880. }
  12881. $p2 = array();
  12882. $visited = array();
  12883. for ($i = 0; $i < $nv; ++$i) {
  12884. $a = $angle + ($i * 360 / $nv);
  12885. $a_rad = deg2rad((float) $a);
  12886. $p2[] = $x0 + ($r * sin($a_rad));
  12887. $p2[] = $y0 + ($r * cos($a_rad));
  12888. $visited[] = false;
  12889. }
  12890. $p = array();
  12891. $i = 0;
  12892. do {
  12893. $p[] = $p2[$i * 2];
  12894. $p[] = $p2[($i * 2) + 1];
  12895. $visited[$i] = true;
  12896. $i += $ng;
  12897. $i %= $nv;
  12898. } while (!$visited[$i]);
  12899. $this->Polygon($p, $style, $line_style, $fill_color);
  12900. }
  12901. /**
  12902. * Draws a rounded rectangle.
  12903. * @param $x (float) Abscissa of upper-left corner.
  12904. * @param $y (float) Ordinate of upper-left corner.
  12905. * @param $w (float) Width.
  12906. * @param $h (float) Height.
  12907. * @param $r (float) the radius of the circle used to round off the corners of the rectangle.
  12908. * @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 left, top right, bottom right and bottom left. Default value: all rounded corner ("1111").
  12909. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  12910. * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  12911. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  12912. * @public
  12913. * @since 2.1.000 (2008-01-08)
  12914. */
  12915. public function RoundedRect($x, $y, $w, $h, $r, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
  12916. $this->RoundedRectXY($x, $y, $w, $h, $r, $r, $round_corner, $style, $border_style, $fill_color);
  12917. }
  12918. /**
  12919. * Draws a rounded rectangle.
  12920. * @param $x (float) Abscissa of upper-left corner.
  12921. * @param $y (float) Ordinate of upper-left corner.
  12922. * @param $w (float) Width.
  12923. * @param $h (float) Height.
  12924. * @param $rx (float) the x-axis radius of the ellipse used to round off the corners of the rectangle.
  12925. * @param $ry (float) the y-axis radius of the ellipse used to round off the corners of the rectangle.
  12926. * @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 left, top right, bottom right and bottom left. Default value: all rounded corner ("1111").
  12927. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  12928. * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  12929. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  12930. * @public
  12931. * @since 4.9.019 (2010-04-22)
  12932. */
  12933. public function RoundedRectXY($x, $y, $w, $h, $rx, $ry, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
  12934. if (($round_corner == '0000') OR (($rx == $ry) AND ($rx == 0))) {
  12935. // Not rounded
  12936. $this->Rect($x, $y, $w, $h, $style, $border_style, $fill_color);
  12937. return;
  12938. }
  12939. // Rounded
  12940. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  12941. $this->SetFillColorArray($fill_color);
  12942. }
  12943. $op = $this->getPathPaintOperator($style);
  12944. if ($op == 'f') {
  12945. $border_style = array();
  12946. }
  12947. if ($border_style) {
  12948. $this->SetLineStyle($border_style);
  12949. }
  12950. $MyArc = 4 / 3 * (sqrt(2) - 1);
  12951. $this->_outPoint($x + $rx, $y);
  12952. $xc = $x + $w - $rx;
  12953. $yc = $y + $ry;
  12954. $this->_outLine($xc, $y);
  12955. if ($round_corner[0]) {
  12956. $this->_outCurve($xc + ($rx * $MyArc), $yc - $ry, $xc + $rx, $yc - ($ry * $MyArc), $xc + $rx, $yc);
  12957. } else {
  12958. $this->_outLine($x + $w, $y);
  12959. }
  12960. $xc = $x + $w - $rx;
  12961. $yc = $y + $h - $ry;
  12962. $this->_outLine($x + $w, $yc);
  12963. if ($round_corner[1]) {
  12964. $this->_outCurve($xc + $rx, $yc + ($ry * $MyArc), $xc + ($rx * $MyArc), $yc + $ry, $xc, $yc + $ry);
  12965. } else {
  12966. $this->_outLine($x + $w, $y + $h);
  12967. }
  12968. $xc = $x + $rx;
  12969. $yc = $y + $h - $ry;
  12970. $this->_outLine($xc, $y + $h);
  12971. if ($round_corner[2]) {
  12972. $this->_outCurve($xc - ($rx * $MyArc), $yc + $ry, $xc - $rx, $yc + ($ry * $MyArc), $xc - $rx, $yc);
  12973. } else {
  12974. $this->_outLine($x, $y + $h);
  12975. }
  12976. $xc = $x + $rx;
  12977. $yc = $y + $ry;
  12978. $this->_outLine($x, $yc);
  12979. if ($round_corner[3]) {
  12980. $this->_outCurve($xc - $rx, $yc - ($ry * $MyArc), $xc - ($rx * $MyArc), $yc - $ry, $xc, $yc - $ry);
  12981. } else {
  12982. $this->_outLine($x, $y);
  12983. $this->_outLine($x + $rx, $y);
  12984. }
  12985. $this->_out($op);
  12986. }
  12987. /**
  12988. * Draws a grahic arrow.
  12989. * @param $x0 (float) Abscissa of first point.
  12990. * @param $y0 (float) Ordinate of first point.
  12991. * @param $x1 (float) Abscissa of second point.
  12992. * @param $y1 (float) Ordinate of second point.
  12993. * @param $head_style (int) (0 = draw only arrowhead arms, 1 = draw closed arrowhead, but no fill, 2 = closed and filled arrowhead, 3 = filled arrowhead)
  12994. * @param $arm_size (float) length of arrowhead arms
  12995. * @param $arm_angle (int) angle between an arm and the shaft
  12996. * @author Piotr Galecki, Nicola Asuni, Andy Meier
  12997. * @since 4.6.018 (2009-07-10)
  12998. */
  12999. public function Arrow($x0, $y0, $x1, $y1, $head_style=0, $arm_size=5, $arm_angle=15) {
  13000. // getting arrow direction angle
  13001. // 0 deg angle is when both arms go along X axis. angle grows clockwise.
  13002. $dir_angle = atan2(($y0 - $y1), ($x0 - $x1));
  13003. if ($dir_angle < 0) {
  13004. $dir_angle += (2 * M_PI);
  13005. }
  13006. $arm_angle = deg2rad($arm_angle);
  13007. $sx1 = $x1;
  13008. $sy1 = $y1;
  13009. if ($head_style > 0) {
  13010. // calculate the stopping point for the arrow shaft
  13011. $sx1 = $x1 + (($arm_size - $this->LineWidth) * cos($dir_angle));
  13012. $sy1 = $y1 + (($arm_size - $this->LineWidth) * sin($dir_angle));
  13013. }
  13014. // main arrow line / shaft
  13015. $this->Line($x0, $y0, $sx1, $sy1);
  13016. // left arrowhead arm tip
  13017. $x2L = $x1 + ($arm_size * cos($dir_angle + $arm_angle));
  13018. $y2L = $y1 + ($arm_size * sin($dir_angle + $arm_angle));
  13019. // right arrowhead arm tip
  13020. $x2R = $x1 + ($arm_size * cos($dir_angle - $arm_angle));
  13021. $y2R = $y1 + ($arm_size * sin($dir_angle - $arm_angle));
  13022. $mode = 'D';
  13023. $style = array();
  13024. switch ($head_style) {
  13025. case 0: {
  13026. // draw only arrowhead arms
  13027. $mode = 'D';
  13028. $style = array(1, 1, 0);
  13029. break;
  13030. }
  13031. case 1: {
  13032. // draw closed arrowhead, but no fill
  13033. $mode = 'D';
  13034. break;
  13035. }
  13036. case 2: {
  13037. // closed and filled arrowhead
  13038. $mode = 'DF';
  13039. break;
  13040. }
  13041. case 3: {
  13042. // filled arrowhead
  13043. $mode = 'F';
  13044. break;
  13045. }
  13046. }
  13047. $this->Polygon(array($x2L, $y2L, $x1, $y1, $x2R, $y2R), $mode, $style, array());
  13048. }
  13049. // END GRAPHIC FUNCTIONS SECTION -----------------------
  13050. // BIDIRECTIONAL TEXT SECTION --------------------------
  13051. /**
  13052. * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  13053. * @param $str (string) string to manipulate.
  13054. * @param $setbom (bool) if true set the Byte Order Mark (BOM = 0xFEFF)
  13055. * @param $forcertl (bool) if true forces RTL text direction
  13056. * @return string
  13057. * @protected
  13058. * @author Nicola Asuni
  13059. * @since 2.1.000 (2008-01-08)
  13060. */
  13061. protected function utf8StrRev($str, $setbom=false, $forcertl=false) {
  13062. return $this->utf8StrArrRev($this->UTF8StringToArray($str), $str, $setbom, $forcertl);
  13063. }
  13064. /**
  13065. * Reverse the RLT substrings array using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  13066. * @param $arr (array) array of unicode values.
  13067. * @param $str (string) string to manipulate (or empty value).
  13068. * @param $setbom (bool) if true set the Byte Order Mark (BOM = 0xFEFF)
  13069. * @param $forcertl (bool) if true forces RTL text direction
  13070. * @return string
  13071. * @protected
  13072. * @author Nicola Asuni
  13073. * @since 4.9.000 (2010-03-27)
  13074. */
  13075. protected function utf8StrArrRev($arr, $str='', $setbom=false, $forcertl=false) {
  13076. return $this->arrUTF8ToUTF16BE($this->utf8Bidi($arr, $str, $forcertl), $setbom);
  13077. }
  13078. /**
  13079. * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  13080. * @param $ta (array) array of characters composing the string.
  13081. * @param $str (string) string to process
  13082. * @param $forcertl (bool) if 'R' forces RTL, if 'L' forces LTR
  13083. * @return array of unicode chars
  13084. * @author Nicola Asuni
  13085. * @protected
  13086. * @since 2.4.000 (2008-03-06)
  13087. */
  13088. protected function utf8Bidi($ta, $str='', $forcertl=false) {
  13089. // paragraph embedding level
  13090. $pel = 0;
  13091. // max level
  13092. $maxlevel = 0;
  13093. if ($this->empty_string($str)) {
  13094. // create string from array
  13095. $str = $this->UTF8ArrSubString($ta);
  13096. }
  13097. // check if string contains arabic text
  13098. if (preg_match($this->unicode->uni_RE_PATTERN_ARABIC, $str)) {
  13099. $arabic = true;
  13100. } else {
  13101. $arabic = false;
  13102. }
  13103. // check if string contains RTL text
  13104. if (!($forcertl OR $arabic OR preg_match($this->unicode->uni_RE_PATTERN_RTL, $str))) {
  13105. return $ta;
  13106. }
  13107. // get number of chars
  13108. $numchars = count($ta);
  13109. if ($forcertl == 'R') {
  13110. $pel = 1;
  13111. } elseif ($forcertl == 'L') {
  13112. $pel = 0;
  13113. } else {
  13114. // P2. In each paragraph, find the first character of type L, AL, or R.
  13115. // P3. If a character is found in P2 and it is of type AL or R, then set the paragraph embedding level to one; otherwise, set it to zero.
  13116. for ($i=0; $i < $numchars; ++$i) {
  13117. $type = $this->unicode->uni_type[$ta[$i]];
  13118. if ($type == 'L') {
  13119. $pel = 0;
  13120. break;
  13121. } elseif (($type == 'AL') OR ($type == 'R')) {
  13122. $pel = 1;
  13123. break;
  13124. }
  13125. }
  13126. }
  13127. // Current Embedding Level
  13128. $cel = $pel;
  13129. // directional override status
  13130. $dos = 'N';
  13131. $remember = array();
  13132. // start-of-level-run
  13133. $sor = $pel % 2 ? 'R' : 'L';
  13134. $eor = $sor;
  13135. // Array of characters data
  13136. $chardata = Array();
  13137. // X1. Begin by setting the current embedding level to the paragraph embedding level. Set the directional override status to neutral. Process each character iteratively, applying rules X2 through X9. Only embedding levels from 0 to 61 are valid in this phase.
  13138. // In the resolution of levels in rules I1 and I2, the maximum embedding level of 62 can be reached.
  13139. for ($i=0; $i < $numchars; ++$i) {
  13140. if ($ta[$i] == $this->unicode->uni_RLE) {
  13141. // X2. With each RLE, compute the least greater odd embedding level.
  13142. // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
  13143. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  13144. $next_level = $cel + ($cel % 2) + 1;
  13145. if ($next_level < 62) {
  13146. $remember[] = array('num' => $this->unicode->uni_RLE, 'cel' => $cel, 'dos' => $dos);
  13147. $cel = $next_level;
  13148. $dos = 'N';
  13149. $sor = $eor;
  13150. $eor = $cel % 2 ? 'R' : 'L';
  13151. }
  13152. } elseif ($ta[$i] == $this->unicode->uni_LRE) {
  13153. // X3. With each LRE, compute the least greater even embedding level.
  13154. // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
  13155. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  13156. $next_level = $cel + 2 - ($cel % 2);
  13157. if ( $next_level < 62 ) {
  13158. $remember[] = array('num' => $this->unicode->uni_LRE, 'cel' => $cel, 'dos' => $dos);
  13159. $cel = $next_level;
  13160. $dos = 'N';
  13161. $sor = $eor;
  13162. $eor = $cel % 2 ? 'R' : 'L';
  13163. }
  13164. } elseif ($ta[$i] == $this->unicode->uni_RLO) {
  13165. // X4. With each RLO, compute the least greater odd embedding level.
  13166. // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to right-to-left.
  13167. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  13168. $next_level = $cel + ($cel % 2) + 1;
  13169. if ($next_level < 62) {
  13170. $remember[] = array('num' => $this->unicode->uni_RLO, 'cel' => $cel, 'dos' => $dos);
  13171. $cel = $next_level;
  13172. $dos = 'R';
  13173. $sor = $eor;
  13174. $eor = $cel % 2 ? 'R' : 'L';
  13175. }
  13176. } elseif ($ta[$i] == $this->unicode->uni_LRO) {
  13177. // X5. With each LRO, compute the least greater even embedding level.
  13178. // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to left-to-right.
  13179. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  13180. $next_level = $cel + 2 - ($cel % 2);
  13181. if ( $next_level < 62 ) {
  13182. $remember[] = array('num' => $this->unicode->uni_LRO, 'cel' => $cel, 'dos' => $dos);
  13183. $cel = $next_level;
  13184. $dos = 'L';
  13185. $sor = $eor;
  13186. $eor = $cel % 2 ? 'R' : 'L';
  13187. }
  13188. } elseif ($ta[$i] == $this->unicode->uni_PDF) {
  13189. // X7. With each PDF, determine the matching embedding or override code. If there was a valid matching code, restore (pop) the last remembered (pushed) embedding level and directional override.
  13190. if (count($remember)) {
  13191. $last = count($remember ) - 1;
  13192. if (($remember[$last]['num'] == $this->unicode->uni_RLE) OR
  13193. ($remember[$last]['num'] == $this->unicode->uni_LRE) OR
  13194. ($remember[$last]['num'] == $this->unicode->uni_RLO) OR
  13195. ($remember[$last]['num'] == $this->unicode->uni_LRO)) {
  13196. $match = array_pop($remember);
  13197. $cel = $match['cel'];
  13198. $dos = $match['dos'];
  13199. $sor = $eor;
  13200. $eor = ($cel > $match['cel'] ? $cel : $match['cel']) % 2 ? 'R' : 'L';
  13201. }
  13202. }
  13203. } elseif (($ta[$i] != $this->unicode->uni_RLE) AND
  13204. ($ta[$i] != $this->unicode->uni_LRE) AND
  13205. ($ta[$i] != $this->unicode->uni_RLO) AND
  13206. ($ta[$i] != $this->unicode->uni_LRO) AND
  13207. ($ta[$i] != $this->unicode->uni_PDF)) {
  13208. // X6. For all types besides RLE, LRE, RLO, LRO, and PDF:
  13209. // a. Set the level of the current character to the current embedding level.
  13210. // b. Whenever the directional override status is not neutral, reset the current character type to the directional override status.
  13211. if ($dos != 'N') {
  13212. $chardir = $dos;
  13213. } else {
  13214. if (isset($this->unicode->uni_type[$ta[$i]])) {
  13215. $chardir = $this->unicode->uni_type[$ta[$i]];
  13216. } else {
  13217. $chardir = 'L';
  13218. }
  13219. }
  13220. // stores string characters and other information
  13221. $chardata[] = array('char' => $ta[$i], 'level' => $cel, 'type' => $chardir, 'sor' => $sor, 'eor' => $eor);
  13222. }
  13223. } // end for each char
  13224. // X8. All explicit directional embeddings and overrides are completely terminated at the end of each paragraph. Paragraph separators are not included in the embedding.
  13225. // X9. Remove all RLE, LRE, RLO, LRO, PDF, and BN codes.
  13226. // X10. The remaining rules are applied to each run of characters at the same level. For each run, determine the start-of-level-run (sor) and end-of-level-run (eor) type, either L or R. This depends on the higher of the two levels on either side of the boundary (at the start or end of the paragraph, the level of the 'other' run is the base embedding level). If the higher level is odd, the type is R; otherwise, it is L.
  13227. // 3.3.3 Resolving Weak Types
  13228. // Weak types are now resolved one level run at a time. At level run boundaries where the type of the character on the other side of the boundary is required, the type assigned to sor or eor is used.
  13229. // Nonspacing marks are now resolved based on the previous characters.
  13230. $numchars = count($chardata);
  13231. // W1. Examine each nonspacing mark (NSM) in the level run, and change the type of the NSM to the type of the previous character. If the NSM is at the start of the level run, it will get the type of sor.
  13232. $prevlevel = -1; // track level changes
  13233. $levcount = 0; // counts consecutive chars at the same level
  13234. for ($i=0; $i < $numchars; ++$i) {
  13235. if ($chardata[$i]['type'] == 'NSM') {
  13236. if ($levcount) {
  13237. $chardata[$i]['type'] = $chardata[$i]['sor'];
  13238. } elseif ($i > 0) {
  13239. $chardata[$i]['type'] = $chardata[($i-1)]['type'];
  13240. }
  13241. }
  13242. if ($chardata[$i]['level'] != $prevlevel) {
  13243. $levcount = 0;
  13244. } else {
  13245. ++$levcount;
  13246. }
  13247. $prevlevel = $chardata[$i]['level'];
  13248. }
  13249. // W2. Search backward from each instance of a European number until the first strong type (R, L, AL, or sor) is found. If an AL is found, change the type of the European number to Arabic number.
  13250. $prevlevel = -1;
  13251. $levcount = 0;
  13252. for ($i=0; $i < $numchars; ++$i) {
  13253. if ($chardata[$i]['char'] == 'EN') {
  13254. for ($j=$levcount; $j >= 0; $j--) {
  13255. if ($chardata[$j]['type'] == 'AL') {
  13256. $chardata[$i]['type'] = 'AN';
  13257. } elseif (($chardata[$j]['type'] == 'L') OR ($chardata[$j]['type'] == 'R')) {
  13258. break;
  13259. }
  13260. }
  13261. }
  13262. if ($chardata[$i]['level'] != $prevlevel) {
  13263. $levcount = 0;
  13264. } else {
  13265. ++$levcount;
  13266. }
  13267. $prevlevel = $chardata[$i]['level'];
  13268. }
  13269. // W3. Change all ALs to R.
  13270. for ($i=0; $i < $numchars; ++$i) {
  13271. if ($chardata[$i]['type'] == 'AL') {
  13272. $chardata[$i]['type'] = 'R';
  13273. }
  13274. }
  13275. // W4. A single European separator between two European numbers changes to a European number. A single common separator between two numbers of the same type changes to that type.
  13276. $prevlevel = -1;
  13277. $levcount = 0;
  13278. for ($i=0; $i < $numchars; ++$i) {
  13279. if (($levcount > 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
  13280. if (($chardata[$i]['type'] == 'ES') AND ($chardata[($i-1)]['type'] == 'EN') AND ($chardata[($i+1)]['type'] == 'EN')) {
  13281. $chardata[$i]['type'] = 'EN';
  13282. } elseif (($chardata[$i]['type'] == 'CS') AND ($chardata[($i-1)]['type'] == 'EN') AND ($chardata[($i+1)]['type'] == 'EN')) {
  13283. $chardata[$i]['type'] = 'EN';
  13284. } elseif (($chardata[$i]['type'] == 'CS') AND ($chardata[($i-1)]['type'] == 'AN') AND ($chardata[($i+1)]['type'] == 'AN')) {
  13285. $chardata[$i]['type'] = 'AN';
  13286. }
  13287. }
  13288. if ($chardata[$i]['level'] != $prevlevel) {
  13289. $levcount = 0;
  13290. } else {
  13291. ++$levcount;
  13292. }
  13293. $prevlevel = $chardata[$i]['level'];
  13294. }
  13295. // W5. A sequence of European terminators adjacent to European numbers changes to all European numbers.
  13296. $prevlevel = -1;
  13297. $levcount = 0;
  13298. for ($i=0; $i < $numchars; ++$i) {
  13299. if ($chardata[$i]['type'] == 'ET') {
  13300. if (($levcount > 0) AND ($chardata[($i-1)]['type'] == 'EN')) {
  13301. $chardata[$i]['type'] = 'EN';
  13302. } else {
  13303. $j = $i+1;
  13304. while (($j < $numchars) AND ($chardata[$j]['level'] == $prevlevel)) {
  13305. if ($chardata[$j]['type'] == 'EN') {
  13306. $chardata[$i]['type'] = 'EN';
  13307. break;
  13308. } elseif ($chardata[$j]['type'] != 'ET') {
  13309. break;
  13310. }
  13311. ++$j;
  13312. }
  13313. }
  13314. }
  13315. if ($chardata[$i]['level'] != $prevlevel) {
  13316. $levcount = 0;
  13317. } else {
  13318. ++$levcount;
  13319. }
  13320. $prevlevel = $chardata[$i]['level'];
  13321. }
  13322. // W6. Otherwise, separators and terminators change to Other Neutral.
  13323. $prevlevel = -1;
  13324. $levcount = 0;
  13325. for ($i=0; $i < $numchars; ++$i) {
  13326. if (($chardata[$i]['type'] == 'ET') OR ($chardata[$i]['type'] == 'ES') OR ($chardata[$i]['type'] == 'CS')) {
  13327. $chardata[$i]['type'] = 'ON';
  13328. }
  13329. if ($chardata[$i]['level'] != $prevlevel) {
  13330. $levcount = 0;
  13331. } else {
  13332. ++$levcount;
  13333. }
  13334. $prevlevel = $chardata[$i]['level'];
  13335. }
  13336. //W7. Search backward from each instance of a European number until the first strong type (R, L, or sor) is found. If an L is found, then change the type of the European number to L.
  13337. $prevlevel = -1;
  13338. $levcount = 0;
  13339. for ($i=0; $i < $numchars; ++$i) {
  13340. if ($chardata[$i]['char'] == 'EN') {
  13341. for ($j=$levcount; $j >= 0; $j--) {
  13342. if ($chardata[$j]['type'] == 'L') {
  13343. $chardata[$i]['type'] = 'L';
  13344. } elseif ($chardata[$j]['type'] == 'R') {
  13345. break;
  13346. }
  13347. }
  13348. }
  13349. if ($chardata[$i]['level'] != $prevlevel) {
  13350. $levcount = 0;
  13351. } else {
  13352. ++$levcount;
  13353. }
  13354. $prevlevel = $chardata[$i]['level'];
  13355. }
  13356. // N1. A sequence of neutrals takes the direction of the surrounding strong text if the text on both sides has the same direction. European and Arabic numbers act as if they were R in terms of their influence on neutrals. Start-of-level-run (sor) and end-of-level-run (eor) are used at level run boundaries.
  13357. $prevlevel = -1;
  13358. $levcount = 0;
  13359. for ($i=0; $i < $numchars; ++$i) {
  13360. if (($levcount > 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
  13361. if (($chardata[$i]['type'] == 'N') AND ($chardata[($i-1)]['type'] == 'L') AND ($chardata[($i+1)]['type'] == 'L')) {
  13362. $chardata[$i]['type'] = 'L';
  13363. } elseif (($chardata[$i]['type'] == 'N') AND
  13364. (($chardata[($i-1)]['type'] == 'R') OR ($chardata[($i-1)]['type'] == 'EN') OR ($chardata[($i-1)]['type'] == 'AN')) AND
  13365. (($chardata[($i+1)]['type'] == 'R') OR ($chardata[($i+1)]['type'] == 'EN') OR ($chardata[($i+1)]['type'] == 'AN'))) {
  13366. $chardata[$i]['type'] = 'R';
  13367. } elseif ($chardata[$i]['type'] == 'N') {
  13368. // N2. Any remaining neutrals take the embedding direction
  13369. $chardata[$i]['type'] = $chardata[$i]['sor'];
  13370. }
  13371. } elseif (($levcount == 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
  13372. // first char
  13373. if (($chardata[$i]['type'] == 'N') AND ($chardata[$i]['sor'] == 'L') AND ($chardata[($i+1)]['type'] == 'L')) {
  13374. $chardata[$i]['type'] = 'L';
  13375. } elseif (($chardata[$i]['type'] == 'N') AND
  13376. (($chardata[$i]['sor'] == 'R') OR ($chardata[$i]['sor'] == 'EN') OR ($chardata[$i]['sor'] == 'AN')) AND
  13377. (($chardata[($i+1)]['type'] == 'R') OR ($chardata[($i+1)]['type'] == 'EN') OR ($chardata[($i+1)]['type'] == 'AN'))) {
  13378. $chardata[$i]['type'] = 'R';
  13379. } elseif ($chardata[$i]['type'] == 'N') {
  13380. // N2. Any remaining neutrals take the embedding direction
  13381. $chardata[$i]['type'] = $chardata[$i]['sor'];
  13382. }
  13383. } elseif (($levcount > 0) AND ((($i+1) == $numchars) OR (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] != $prevlevel))) {
  13384. //last char
  13385. if (($chardata[$i]['type'] == 'N') AND ($chardata[($i-1)]['type'] == 'L') AND ($chardata[$i]['eor'] == 'L')) {
  13386. $chardata[$i]['type'] = 'L';
  13387. } elseif (($chardata[$i]['type'] == 'N') AND
  13388. (($chardata[($i-1)]['type'] == 'R') OR ($chardata[($i-1)]['type'] == 'EN') OR ($chardata[($i-1)]['type'] == 'AN')) AND
  13389. (($chardata[$i]['eor'] == 'R') OR ($chardata[$i]['eor'] == 'EN') OR ($chardata[$i]['eor'] == 'AN'))) {
  13390. $chardata[$i]['type'] = 'R';
  13391. } elseif ($chardata[$i]['type'] == 'N') {
  13392. // N2. Any remaining neutrals take the embedding direction
  13393. $chardata[$i]['type'] = $chardata[$i]['sor'];
  13394. }
  13395. } elseif ($chardata[$i]['type'] == 'N') {
  13396. // N2. Any remaining neutrals take the embedding direction
  13397. $chardata[$i]['type'] = $chardata[$i]['sor'];
  13398. }
  13399. if ($chardata[$i]['level'] != $prevlevel) {
  13400. $levcount = 0;
  13401. } else {
  13402. ++$levcount;
  13403. }
  13404. $prevlevel = $chardata[$i]['level'];
  13405. }
  13406. // I1. For all characters with an even (left-to-right) embedding direction, those of type R go up one level and those of type AN or EN go up two levels.
  13407. // I2. For all characters with an odd (right-to-left) embedding direction, those of type L, EN or AN go up one level.
  13408. for ($i=0; $i < $numchars; ++$i) {
  13409. $odd = $chardata[$i]['level'] % 2;
  13410. if ($odd) {
  13411. if (($chardata[$i]['type'] == 'L') OR ($chardata[$i]['type'] == 'AN') OR ($chardata[$i]['type'] == 'EN')) {
  13412. $chardata[$i]['level'] += 1;
  13413. }
  13414. } else {
  13415. if ($chardata[$i]['type'] == 'R') {
  13416. $chardata[$i]['level'] += 1;
  13417. } elseif (($chardata[$i]['type'] == 'AN') OR ($chardata[$i]['type'] == 'EN')) {
  13418. $chardata[$i]['level'] += 2;
  13419. }
  13420. }
  13421. $maxlevel = max($chardata[$i]['level'],$maxlevel);
  13422. }
  13423. // L1. On each line, reset the embedding level of the following characters to the paragraph embedding level:
  13424. // 1. Segment separators,
  13425. // 2. Paragraph separators,
  13426. // 3. Any sequence of whitespace characters preceding a segment separator or paragraph separator, and
  13427. // 4. Any sequence of white space characters at the end of the line.
  13428. for ($i=0; $i < $numchars; ++$i) {
  13429. if (($chardata[$i]['type'] == 'B') OR ($chardata[$i]['type'] == 'S')) {
  13430. $chardata[$i]['level'] = $pel;
  13431. } elseif ($chardata[$i]['type'] == 'WS') {
  13432. $j = $i+1;
  13433. while ($j < $numchars) {
  13434. if ((($chardata[$j]['type'] == 'B') OR ($chardata[$j]['type'] == 'S')) OR
  13435. (($j == ($numchars-1)) AND ($chardata[$j]['type'] == 'WS'))) {
  13436. $chardata[$i]['level'] = $pel;
  13437. break;
  13438. } elseif ($chardata[$j]['type'] != 'WS') {
  13439. break;
  13440. }
  13441. ++$j;
  13442. }
  13443. }
  13444. }
  13445. // Arabic Shaping
  13446. // Cursively connected scripts, such as Arabic or Syriac, require the selection of positional character shapes that depend on adjacent characters. Shaping is logically applied after the Bidirectional Algorithm is used and is limited to characters within the same directional run.
  13447. if ($arabic) {
  13448. $endedletter = array(1569,1570,1571,1572,1573,1575,1577,1583,1584,1585,1586,1608,1688);
  13449. $alfletter = array(1570,1571,1573,1575);
  13450. $chardata2 = $chardata;
  13451. $laaletter = false;
  13452. $charAL = array();
  13453. $x = 0;
  13454. for ($i=0; $i < $numchars; ++$i) {
  13455. if (($this->unicode->uni_type[$chardata[$i]['char']] == 'AL') OR ($chardata[$i]['char'] == 32) OR ($chardata[$i]['char'] == 8204)) {
  13456. $charAL[$x] = $chardata[$i];
  13457. $charAL[$x]['i'] = $i;
  13458. $chardata[$i]['x'] = $x;
  13459. ++$x;
  13460. }
  13461. }
  13462. $numAL = $x;
  13463. for ($i=0; $i < $numchars; ++$i) {
  13464. $thischar = $chardata[$i];
  13465. if ($i > 0) {
  13466. $prevchar = $chardata[($i-1)];
  13467. } else {
  13468. $prevchar = false;
  13469. }
  13470. if (($i+1) < $numchars) {
  13471. $nextchar = $chardata[($i+1)];
  13472. } else {
  13473. $nextchar = false;
  13474. }
  13475. if ($this->unicode->uni_type[$thischar['char']] == 'AL') {
  13476. $x = $thischar['x'];
  13477. if ($x > 0) {
  13478. $prevchar = $charAL[($x-1)];
  13479. } else {
  13480. $prevchar = false;
  13481. }
  13482. if (($x+1) < $numAL) {
  13483. $nextchar = $charAL[($x+1)];
  13484. } else {
  13485. $nextchar = false;
  13486. }
  13487. // if laa letter
  13488. if (($prevchar !== false) AND ($prevchar['char'] == 1604) AND (in_array($thischar['char'], $alfletter))) {
  13489. $arabicarr = $this->unicode->uni_laa_array;
  13490. $laaletter = true;
  13491. if ($x > 1) {
  13492. $prevchar = $charAL[($x-2)];
  13493. } else {
  13494. $prevchar = false;
  13495. }
  13496. } else {
  13497. $arabicarr = $this->unicode->uni_arabicsubst;
  13498. $laaletter = false;
  13499. }
  13500. if (($prevchar !== false) AND ($nextchar !== false) AND
  13501. (($this->unicode->uni_type[$prevchar['char']] == 'AL') OR ($this->unicode->uni_type[$prevchar['char']] == 'NSM')) AND
  13502. (($this->unicode->uni_type[$nextchar['char']] == 'AL') OR ($this->unicode->uni_type[$nextchar['char']] == 'NSM')) AND
  13503. ($prevchar['type'] == $thischar['type']) AND
  13504. ($nextchar['type'] == $thischar['type']) AND
  13505. ($nextchar['char'] != 1567)) {
  13506. if (in_array($prevchar['char'], $endedletter)) {
  13507. if (isset($arabicarr[$thischar['char']][2])) {
  13508. // initial
  13509. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][2];
  13510. }
  13511. } else {
  13512. if (isset($arabicarr[$thischar['char']][3])) {
  13513. // medial
  13514. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][3];
  13515. }
  13516. }
  13517. } elseif (($nextchar !== false) AND
  13518. (($this->unicode->uni_type[$nextchar['char']] == 'AL') OR ($this->unicode->uni_type[$nextchar['char']] == 'NSM')) AND
  13519. ($nextchar['type'] == $thischar['type']) AND
  13520. ($nextchar['char'] != 1567)) {
  13521. if (isset($arabicarr[$chardata[$i]['char']][2])) {
  13522. // initial
  13523. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][2];
  13524. }
  13525. } elseif ((($prevchar !== false) AND
  13526. (($this->unicode->uni_type[$prevchar['char']] == 'AL') OR ($this->unicode->uni_type[$prevchar['char']] == 'NSM')) AND
  13527. ($prevchar['type'] == $thischar['type'])) OR
  13528. (($nextchar !== false) AND ($nextchar['char'] == 1567))) {
  13529. // final
  13530. if (($i > 1) AND ($thischar['char'] == 1607) AND
  13531. ($chardata[$i-1]['char'] == 1604) AND
  13532. ($chardata[$i-2]['char'] == 1604)) {
  13533. //Allah Word
  13534. // mark characters to delete with false
  13535. $chardata2[$i-2]['char'] = false;
  13536. $chardata2[$i-1]['char'] = false;
  13537. $chardata2[$i]['char'] = 65010;
  13538. } else {
  13539. if (($prevchar !== false) AND in_array($prevchar['char'], $endedletter)) {
  13540. if (isset($arabicarr[$thischar['char']][0])) {
  13541. // isolated
  13542. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][0];
  13543. }
  13544. } else {
  13545. if (isset($arabicarr[$thischar['char']][1])) {
  13546. // final
  13547. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][1];
  13548. }
  13549. }
  13550. }
  13551. } elseif (isset($arabicarr[$thischar['char']][0])) {
  13552. // isolated
  13553. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][0];
  13554. }
  13555. // if laa letter
  13556. if ($laaletter) {
  13557. // mark characters to delete with false
  13558. $chardata2[($charAL[($x-1)]['i'])]['char'] = false;
  13559. }
  13560. } // end if AL (Arabic Letter)
  13561. } // end for each char
  13562. /*
  13563. * Combining characters that can occur with Arabic Shadda (0651 HEX, 1617 DEC) are replaced.
  13564. * Putting the combining mark and shadda in the same glyph allows us to avoid the two marks overlapping each other in an illegible manner.
  13565. */
  13566. $cw = &$this->CurrentFont['cw'];
  13567. for ($i = 0; $i < ($numchars-1); ++$i) {
  13568. if (($chardata2[$i]['char'] == 1617) AND (isset($this->unicode->uni_diacritics[($chardata2[$i+1]['char'])]))) {
  13569. // check if the subtitution font is defined on current font
  13570. if (isset($cw[($this->unicode->uni_diacritics[($chardata2[$i+1]['char'])])])) {
  13571. $chardata2[$i]['char'] = false;
  13572. $chardata2[$i+1]['char'] = $this->unicode->uni_diacritics[($chardata2[$i+1]['char'])];
  13573. }
  13574. }
  13575. }
  13576. // remove marked characters
  13577. foreach ($chardata2 as $key => $value) {
  13578. if ($value['char'] === false) {
  13579. unset($chardata2[$key]);
  13580. }
  13581. }
  13582. $chardata = array_values($chardata2);
  13583. $numchars = count($chardata);
  13584. unset($chardata2);
  13585. unset($arabicarr);
  13586. unset($laaletter);
  13587. unset($charAL);
  13588. }
  13589. // L2. From the highest level found in the text to the lowest odd level on each line, including intermediate levels not actually present in the text, reverse any contiguous sequence of characters that are at that level or higher.
  13590. for ($j=$maxlevel; $j > 0; $j--) {
  13591. $ordarray = Array();
  13592. $revarr = Array();
  13593. $onlevel = false;
  13594. for ($i=0; $i < $numchars; ++$i) {
  13595. if ($chardata[$i]['level'] >= $j) {
  13596. $onlevel = true;
  13597. if (isset($this->unicode->uni_mirror[$chardata[$i]['char']])) {
  13598. // L4. A character is depicted by a mirrored glyph if and only if (a) the resolved directionality of that character is R, and (b) the Bidi_Mirrored property value of that character is true.
  13599. $chardata[$i]['char'] = $this->unicode->uni_mirror[$chardata[$i]['char']];
  13600. }
  13601. $revarr[] = $chardata[$i];
  13602. } else {
  13603. if ($onlevel) {
  13604. $revarr = array_reverse($revarr);
  13605. $ordarray = array_merge($ordarray, $revarr);
  13606. $revarr = Array();
  13607. $onlevel = false;
  13608. }
  13609. $ordarray[] = $chardata[$i];
  13610. }
  13611. }
  13612. if ($onlevel) {
  13613. $revarr = array_reverse($revarr);
  13614. $ordarray = array_merge($ordarray, $revarr);
  13615. }
  13616. $chardata = $ordarray;
  13617. }
  13618. $ordarray = array();
  13619. for ($i=0; $i < $numchars; ++$i) {
  13620. $ordarray[] = $chardata[$i]['char'];
  13621. // store char values for subsetting
  13622. $this->CurrentFont['subsetchars'][$chardata[$i]['char']] = true;
  13623. }
  13624. // update font subsetchars
  13625. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  13626. return $ordarray;
  13627. }
  13628. // END OF BIDIRECTIONAL TEXT SECTION -------------------
  13629. /**
  13630. * Adds a bookmark.
  13631. * @param $txt (string) bookmark description.
  13632. * @param $level (int) bookmark level (minimum value is 0).
  13633. * @param $y (float) Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
  13634. * @param $page (int) target page number (leave empty for current page).
  13635. * @public
  13636. * @author Olivier Plathey, Nicola Asuni
  13637. * @since 2.1.002 (2008-02-12)
  13638. */
  13639. public function Bookmark($txt, $level=0, $y=-1, $page='') {
  13640. if ($level < 0) {
  13641. $level = 0;
  13642. }
  13643. if (isset($this->outlines[0])) {
  13644. $lastoutline = end($this->outlines);
  13645. $maxlevel = $lastoutline['l'] + 1;
  13646. } else {
  13647. $maxlevel = 0;
  13648. }
  13649. if ($level > $maxlevel) {
  13650. $level = $maxlevel;
  13651. }
  13652. if ($y == -1) {
  13653. $y = $this->GetY();
  13654. }
  13655. if (empty($page)) {
  13656. $page = $this->PageNo();
  13657. if (empty($page)) {
  13658. return;
  13659. }
  13660. }
  13661. $this->outlines[] = array('t' => $txt, 'l' => $level, 'y' => $y, 'p' => $page);
  13662. }
  13663. /**
  13664. * Create a bookmark PDF string.
  13665. * @protected
  13666. * @author Olivier Plathey, Nicola Asuni
  13667. * @since 2.1.002 (2008-02-12)
  13668. */
  13669. protected function _putbookmarks() {
  13670. $nb = count($this->outlines);
  13671. if ($nb == 0) {
  13672. return;
  13673. }
  13674. // get sorting columns
  13675. $outline_p = array();
  13676. $outline_y = array();
  13677. foreach ($this->outlines as $key => $row) {
  13678. $outline_p[$key] = $row['p'];
  13679. $outline_k[$key] = $key;
  13680. }
  13681. // sort outlines by page and original position
  13682. array_multisort($outline_p, SORT_NUMERIC, SORT_ASC, $outline_k, SORT_NUMERIC, SORT_ASC, $this->outlines);
  13683. $lru = array();
  13684. $level = 0;
  13685. foreach ($this->outlines as $i => $o) {
  13686. if ($o['l'] > 0) {
  13687. $parent = $lru[($o['l'] - 1)];
  13688. //Set parent and last pointers
  13689. $this->outlines[$i]['parent'] = $parent;
  13690. $this->outlines[$parent]['last'] = $i;
  13691. if ($o['l'] > $level) {
  13692. //Level increasing: set first pointer
  13693. $this->outlines[$parent]['first'] = $i;
  13694. }
  13695. } else {
  13696. $this->outlines[$i]['parent'] = $nb;
  13697. }
  13698. if (($o['l'] <= $level) AND ($i > 0)) {
  13699. //Set prev and next pointers
  13700. $prev = $lru[$o['l']];
  13701. $this->outlines[$prev]['next'] = $i;
  13702. $this->outlines[$i]['prev'] = $prev;
  13703. }
  13704. $lru[$o['l']] = $i;
  13705. $level = $o['l'];
  13706. }
  13707. //Outline items
  13708. $n = $this->n + 1;
  13709. $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';
  13710. foreach ($this->outlines as $i => $o) {
  13711. if (isset($this->page_obj_id[($o['p'])])) {
  13712. $oid = $this->_newobj();
  13713. // covert HTML title to string
  13714. $title = preg_replace($nltags, "\n", $o['t']);
  13715. $title = preg_replace("/[\r]+/si", '', $title);
  13716. $title = preg_replace("/[\n]+/si", "\n", $title);
  13717. $title = strip_tags($title);
  13718. $title = $this->stringTrim($title);
  13719. $out = '<</Title '.$this->_textstring($title, $oid);
  13720. $out .= ' /Parent '.($n + $o['parent']).' 0 R';
  13721. if (isset($o['prev'])) {
  13722. $out .= ' /Prev '.($n + $o['prev']).' 0 R';
  13723. }
  13724. if (isset($o['next'])) {
  13725. $out .= ' /Next '.($n + $o['next']).' 0 R';
  13726. }
  13727. if (isset($o['first'])) {
  13728. $out .= ' /First '.($n + $o['first']).' 0 R';
  13729. }
  13730. if (isset($o['last'])) {
  13731. $out .= ' /Last '.($n + $o['last']).' 0 R';
  13732. }
  13733. $out .= ' '.sprintf('/Dest [%u 0 R /XYZ 0 %.2F null]', $this->page_obj_id[($o['p'])], ($this->pagedim[$o['p']]['h'] - ($o['y'] * $this->k)));
  13734. $out .= ' /Count 0 >>';
  13735. $out .= "\n".'endobj';
  13736. $this->_out($out);
  13737. }
  13738. }
  13739. //Outline root
  13740. $this->OutlineRoot = $this->_newobj();
  13741. $this->_out('<< /Type /Outlines /First '.$n.' 0 R /Last '.($n + $lru[0]).' 0 R >>'."\n".'endobj');
  13742. }
  13743. // --- JAVASCRIPT ------------------------------------------------------
  13744. /**
  13745. * Adds a javascript
  13746. * @param $script (string) Javascript code
  13747. * @public
  13748. * @author Johannes Güntert, Nicola Asuni
  13749. * @since 2.1.002 (2008-02-12)
  13750. */
  13751. public function IncludeJS($script) {
  13752. $this->javascript .= $script;
  13753. }
  13754. /**
  13755. * Adds a javascript object and return object ID
  13756. * @param $script (string) Javascript code
  13757. * @param $onload (boolean) if true executes this object when opening the document
  13758. * @return int internal object ID
  13759. * @public
  13760. * @author Nicola Asuni
  13761. * @since 4.8.000 (2009-09-07)
  13762. */
  13763. public function addJavascriptObject($script, $onload=false) {
  13764. ++$this->n;
  13765. $this->js_objects[$this->n] = array('n' => $this->n, 'js' => $script, 'onload' => $onload);
  13766. return $this->n;
  13767. }
  13768. /**
  13769. * Create a javascript PDF string.
  13770. * @protected
  13771. * @author Johannes Güntert, Nicola Asuni
  13772. * @since 2.1.002 (2008-02-12)
  13773. */
  13774. protected function _putjavascript() {
  13775. if (empty($this->javascript) AND empty($this->js_objects)) {
  13776. return;
  13777. }
  13778. if (strpos($this->javascript, 'this.addField') > 0) {
  13779. if (!$this->ur['enabled']) {
  13780. //$this->setUserRights();
  13781. }
  13782. // the following two lines are used to avoid form fields duplication after saving
  13783. // The addField method only works when releasing user rights (UR3)
  13784. $jsa = sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%.2F,%.2F,%.2F,%.2F]);", 'tcpdfdocsaved', 'text', 0, 0, 1, 0, 1);
  13785. $jsb = "getField('tcpdfdocsaved').value='saved';";
  13786. $this->javascript = $jsa."\n".$this->javascript."\n".$jsb;
  13787. }
  13788. $this->n_js = $this->_newobj();
  13789. $out = ' << /Names [';
  13790. if (!empty($this->javascript)) {
  13791. $out .= ' (EmbeddedJS) '.($this->n + 1).' 0 R';
  13792. }
  13793. if (!empty($this->js_objects)) {
  13794. foreach ($this->js_objects as $key => $val) {
  13795. if ($val['onload']) {
  13796. $out .= ' (JS'.$key.') '.$key.' 0 R';
  13797. }
  13798. }
  13799. }
  13800. $out .= ' ] >>';
  13801. $out .= "\n".'endobj';
  13802. $this->_out($out);
  13803. // default Javascript object
  13804. if (!empty($this->javascript)) {
  13805. $obj_id = $this->_newobj();
  13806. $out = '<< /S /JavaScript';
  13807. $out .= ' /JS '.$this->_textstring($this->javascript, $obj_id);
  13808. $out .= ' >>';
  13809. $out .= "\n".'endobj';
  13810. $this->_out($out);
  13811. }
  13812. // additional Javascript objects
  13813. if (!empty($this->js_objects)) {
  13814. foreach ($this->js_objects as $key => $val) {
  13815. $out = $this->_getobj($key)."\n".' << /S /JavaScript /JS '.$this->_textstring($val['js'], $key).' >>'."\n".'endobj';
  13816. $this->_out($out);
  13817. }
  13818. }
  13819. }
  13820. /**
  13821. * Convert color to javascript color.
  13822. * @param $color (string) color name or "#RRGGBB"
  13823. * @protected
  13824. * @author Denis Van Nuffelen, Nicola Asuni
  13825. * @since 2.1.002 (2008-02-12)
  13826. */
  13827. protected function _JScolor($color) {
  13828. static $aColors = array('transparent', 'black', 'white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'dkGray', 'gray', 'ltGray');
  13829. if (substr($color,0,1) == '#') {
  13830. return sprintf("['RGB',%.3F,%.3F,%.3F]", hexdec(substr($color,1,2))/255, hexdec(substr($color,3,2))/255, hexdec(substr($color,5,2))/255);
  13831. }
  13832. if (!in_array($color,$aColors)) {
  13833. $this->Error('Invalid color: '.$color);
  13834. }
  13835. return 'color.'.$color;
  13836. }
  13837. /**
  13838. * Adds a javascript form field.
  13839. * @param $type (string) field type
  13840. * @param $name (string) field name
  13841. * @param $x (int) horizontal position
  13842. * @param $y (int) vertical position
  13843. * @param $w (int) width
  13844. * @param $h (int) height
  13845. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  13846. * @protected
  13847. * @author Denis Van Nuffelen, Nicola Asuni
  13848. * @since 2.1.002 (2008-02-12)
  13849. */
  13850. protected function _addfield($type, $name, $x, $y, $w, $h, $prop) {
  13851. if ($this->rtl) {
  13852. $x = $x - $w;
  13853. }
  13854. // the followind avoid fields duplication after saving the document
  13855. $this->javascript .= "if(getField('tcpdfdocsaved').value != 'saved') {";
  13856. $k = $this->k;
  13857. $this->javascript .= sprintf("f".$name."=this.addField('%s','%s',%u,[%.2F,%.2F,%.2F,%.2F]);", $name, $type, $this->PageNo()-1, $x*$k, ($this->h-$y)*$k+1, ($x+$w)*$k, ($this->h-$y-$h)*$k+1)."\n";
  13858. $this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n";
  13859. while (list($key, $val) = each($prop)) {
  13860. if (strcmp(substr($key, -5), 'Color') == 0) {
  13861. $val = $this->_JScolor($val);
  13862. } else {
  13863. $val = "'".$val."'";
  13864. }
  13865. $this->javascript .= 'f'.$name.'.'.$key.'='.$val.";\n";
  13866. }
  13867. if ($this->rtl) {
  13868. $this->x -= $w;
  13869. } else {
  13870. $this->x += $w;
  13871. }
  13872. $this->javascript .= '}';
  13873. }
  13874. // --- FORM FIELDS -----------------------------------------------------
  13875. /**
  13876. * Convert JavaScript form fields properties array to Annotation Properties array.
  13877. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  13878. * @return array of annotation properties
  13879. * @protected
  13880. * @author Nicola Asuni
  13881. * @since 4.8.000 (2009-09-06)
  13882. */
  13883. protected function getAnnotOptFromJSProp($prop) {
  13884. if (isset($prop['aopt']) AND is_array($prop['aopt'])) {
  13885. // the annotation options area lready defined
  13886. return $prop['aopt'];
  13887. }
  13888. $opt = array(); // value to be returned
  13889. // alignment: Controls how the text is laid out within the text field.
  13890. if (isset($prop['alignment'])) {
  13891. switch ($prop['alignment']) {
  13892. case 'left': {
  13893. $opt['q'] = 0;
  13894. break;
  13895. }
  13896. case 'center': {
  13897. $opt['q'] = 1;
  13898. break;
  13899. }
  13900. case 'right': {
  13901. $opt['q'] = 2;
  13902. break;
  13903. }
  13904. default: {
  13905. $opt['q'] = ($this->rtl)?2:0;
  13906. break;
  13907. }
  13908. }
  13909. }
  13910. // lineWidth: Specifies the thickness of the border when stroking the perimeter of a field's rectangle.
  13911. if (isset($prop['lineWidth'])) {
  13912. $linewidth = intval($prop['lineWidth']);
  13913. } else {
  13914. $linewidth = 1;
  13915. }
  13916. // borderStyle: The border style for a field.
  13917. if (isset($prop['borderStyle'])) {
  13918. switch ($prop['borderStyle']) {
  13919. case 'border.d':
  13920. case 'dashed': {
  13921. $opt['border'] = array(0, 0, $linewidth, array(3, 2));
  13922. $opt['bs'] = array('w'=>$linewidth, 's'=>'D', 'd'=>array(3, 2));
  13923. break;
  13924. }
  13925. case 'border.b':
  13926. case 'beveled': {
  13927. $opt['border'] = array(0, 0, $linewidth);
  13928. $opt['bs'] = array('w'=>$linewidth, 's'=>'B');
  13929. break;
  13930. }
  13931. case 'border.i':
  13932. case 'inset': {
  13933. $opt['border'] = array(0, 0, $linewidth);
  13934. $opt['bs'] = array('w'=>$linewidth, 's'=>'I');
  13935. break;
  13936. }
  13937. case 'border.u':
  13938. case 'underline': {
  13939. $opt['border'] = array(0, 0, $linewidth);
  13940. $opt['bs'] = array('w'=>$linewidth, 's'=>'U');
  13941. break;
  13942. }
  13943. default:
  13944. case 'border.s':
  13945. case 'solid': {
  13946. $opt['border'] = array(0, 0, $linewidth);
  13947. $opt['bs'] = array('w'=>$linewidth, 's'=>'S');
  13948. break;
  13949. }
  13950. }
  13951. }
  13952. if (isset($prop['border']) AND is_array($prop['border'])) {
  13953. $opt['border'] = $prop['border'];
  13954. }
  13955. if (!isset($opt['mk'])) {
  13956. $opt['mk'] = array();
  13957. }
  13958. if (!isset($opt['mk']['if'])) {
  13959. $opt['mk']['if'] = array();
  13960. }
  13961. $opt['mk']['if']['a'] = array(0.5, 0.5);
  13962. // buttonAlignX: Controls how space is distributed from the left of the button face with respect to the icon.
  13963. if (isset($prop['buttonAlignX'])) {
  13964. $opt['mk']['if']['a'][0] = $prop['buttonAlignX'];
  13965. }
  13966. // buttonAlignY: Controls how unused space is distributed from the bottom of the button face with respect to the icon.
  13967. if (isset($prop['buttonAlignY'])) {
  13968. $opt['mk']['if']['a'][1] = $prop['buttonAlignY'];
  13969. }
  13970. // buttonFitBounds: If true, the extent to which the icon may be scaled is set to the bounds of the button field.
  13971. if (isset($prop['buttonFitBounds']) AND ($prop['buttonFitBounds'] == 'true')) {
  13972. $opt['mk']['if']['fb'] = true;
  13973. }
  13974. // buttonScaleHow: Controls how the icon is scaled (if necessary) to fit inside the button face.
  13975. if (isset($prop['buttonScaleHow'])) {
  13976. switch ($prop['buttonScaleHow']) {
  13977. case 'scaleHow.proportional': {
  13978. $opt['mk']['if']['s'] = 'P';
  13979. break;
  13980. }
  13981. case 'scaleHow.anamorphic': {
  13982. $opt['mk']['if']['s'] = 'A';
  13983. break;
  13984. }
  13985. }
  13986. }
  13987. // buttonScaleWhen: Controls when an icon is scaled to fit inside the button face.
  13988. if (isset($prop['buttonScaleWhen'])) {
  13989. switch ($prop['buttonScaleWhen']) {
  13990. case 'scaleWhen.always': {
  13991. $opt['mk']['if']['sw'] = 'A';
  13992. break;
  13993. }
  13994. case 'scaleWhen.never': {
  13995. $opt['mk']['if']['sw'] = 'N';
  13996. break;
  13997. }
  13998. case 'scaleWhen.tooBig': {
  13999. $opt['mk']['if']['sw'] = 'B';
  14000. break;
  14001. }
  14002. case 'scaleWhen.tooSmall': {
  14003. $opt['mk']['if']['sw'] = 'S';
  14004. break;
  14005. }
  14006. }
  14007. }
  14008. // buttonPosition: Controls how the text and the icon of the button are positioned with respect to each other within the button face.
  14009. if (isset($prop['buttonPosition'])) {
  14010. switch ($prop['buttonPosition']) {
  14011. case 0:
  14012. case 'position.textOnly': {
  14013. $opt['mk']['tp'] = 0;
  14014. break;
  14015. }
  14016. case 1:
  14017. case 'position.iconOnly': {
  14018. $opt['mk']['tp'] = 1;
  14019. break;
  14020. }
  14021. case 2:
  14022. case 'position.iconTextV': {
  14023. $opt['mk']['tp'] = 2;
  14024. break;
  14025. }
  14026. case 3:
  14027. case 'position.textIconV': {
  14028. $opt['mk']['tp'] = 3;
  14029. break;
  14030. }
  14031. case 4:
  14032. case 'position.iconTextH': {
  14033. $opt['mk']['tp'] = 4;
  14034. break;
  14035. }
  14036. case 5:
  14037. case 'position.textIconH': {
  14038. $opt['mk']['tp'] = 5;
  14039. break;
  14040. }
  14041. case 6:
  14042. case 'position.overlay': {
  14043. $opt['mk']['tp'] = 6;
  14044. break;
  14045. }
  14046. }
  14047. }
  14048. // fillColor: Specifies the background color for a field.
  14049. if (isset($prop['fillColor'])) {
  14050. if (is_array($prop['fillColor'])) {
  14051. $opt['mk']['bg'] = $prop['fillColor'];
  14052. } else {
  14053. $opt['mk']['bg'] = $this->convertHTMLColorToDec($prop['fillColor']);
  14054. }
  14055. }
  14056. // strokeColor: Specifies the stroke color for a field that is used to stroke the rectangle of the field with a line as large as the line width.
  14057. if (isset($prop['strokeColor'])) {
  14058. if (is_array($prop['strokeColor'])) {
  14059. $opt['mk']['bc'] = $prop['strokeColor'];
  14060. } else {
  14061. $opt['mk']['bc'] = $this->convertHTMLColorToDec($prop['strokeColor']);
  14062. }
  14063. }
  14064. // rotation: The rotation of a widget in counterclockwise increments.
  14065. if (isset($prop['rotation'])) {
  14066. $opt['mk']['r'] = $prop['rotation'];
  14067. }
  14068. // charLimit: Limits the number of characters that a user can type into a text field.
  14069. if (isset($prop['charLimit'])) {
  14070. $opt['maxlen'] = intval($prop['charLimit']);
  14071. }
  14072. if (!isset($ff)) {
  14073. $ff = 0;
  14074. }
  14075. // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
  14076. if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
  14077. $ff += 1 << 0;
  14078. }
  14079. // required: Specifies whether a field requires a value.
  14080. if (isset($prop['required']) AND ($prop['required'] == 'true')) {
  14081. $ff += 1 << 1;
  14082. }
  14083. // multiline: Controls how text is wrapped within the field.
  14084. if (isset($prop['multiline']) AND ($prop['multiline'] == 'true')) {
  14085. $ff += 1 << 12;
  14086. }
  14087. // password: Specifies whether the field should display asterisks when data is entered in the field.
  14088. if (isset($prop['password']) AND ($prop['password'] == 'true')) {
  14089. $ff += 1 << 13;
  14090. }
  14091. // NoToggleToOff: If set, exactly one radio button shall be selected at all times; selecting the currently selected button has no effect.
  14092. if (isset($prop['NoToggleToOff']) AND ($prop['NoToggleToOff'] == 'true')) {
  14093. $ff += 1 << 14;
  14094. }
  14095. // Radio: If set, the field is a set of radio buttons.
  14096. if (isset($prop['Radio']) AND ($prop['Radio'] == 'true')) {
  14097. $ff += 1 << 15;
  14098. }
  14099. // Pushbutton: If set, the field is a pushbutton that does not retain a permanent value.
  14100. if (isset($prop['Pushbutton']) AND ($prop['Pushbutton'] == 'true')) {
  14101. $ff += 1 << 16;
  14102. }
  14103. // Combo: If set, the field is a combo box; if clear, the field is a list box.
  14104. if (isset($prop['Combo']) AND ($prop['Combo'] == 'true')) {
  14105. $ff += 1 << 17;
  14106. }
  14107. // editable: Controls whether a combo box is editable.
  14108. if (isset($prop['editable']) AND ($prop['editable'] == 'true')) {
  14109. $ff += 1 << 18;
  14110. }
  14111. // Sort: If set, the field's option items shall be sorted alphabetically.
  14112. if (isset($prop['Sort']) AND ($prop['Sort'] == 'true')) {
  14113. $ff += 1 << 19;
  14114. }
  14115. // fileSelect: If true, sets the file-select flag in the Options tab of the text field (Field is Used for File Selection).
  14116. if (isset($prop['fileSelect']) AND ($prop['fileSelect'] == 'true')) {
  14117. $ff += 1 << 20;
  14118. }
  14119. // multipleSelection: If true, indicates that a list box allows a multiple selection of items.
  14120. if (isset($prop['multipleSelection']) AND ($prop['multipleSelection'] == 'true')) {
  14121. $ff += 1 << 21;
  14122. }
  14123. // doNotSpellCheck: If true, spell checking is not performed on this editable text field.
  14124. if (isset($prop['doNotSpellCheck']) AND ($prop['doNotSpellCheck'] == 'true')) {
  14125. $ff += 1 << 22;
  14126. }
  14127. // doNotScroll: If true, the text field does not scroll and the user, therefore, is limited by the rectangular region designed for the field.
  14128. if (isset($prop['doNotScroll']) AND ($prop['doNotScroll'] == 'true')) {
  14129. $ff += 1 << 23;
  14130. }
  14131. // comb: If set to true, the field background is drawn as series of boxes (one for each character in the value of the field) and each character of the content is drawn within those boxes. The number of boxes drawn is determined from the charLimit property. It applies only to text fields. The setter will also raise if any of the following field properties are also set multiline, password, and fileSelect. A side-effect of setting this property is that the doNotScroll property is also set.
  14132. if (isset($prop['comb']) AND ($prop['comb'] == 'true')) {
  14133. $ff += 1 << 24;
  14134. }
  14135. // radiosInUnison: If false, even if a group of radio buttons have the same name and export value, they behave in a mutually exclusive fashion, like HTML radio buttons.
  14136. if (isset($prop['radiosInUnison']) AND ($prop['radiosInUnison'] == 'true')) {
  14137. $ff += 1 << 25;
  14138. }
  14139. // richText: If true, the field allows rich text formatting.
  14140. if (isset($prop['richText']) AND ($prop['richText'] == 'true')) {
  14141. $ff += 1 << 25;
  14142. }
  14143. // commitOnSelChange: Controls whether a field value is committed after a selection change.
  14144. if (isset($prop['commitOnSelChange']) AND ($prop['commitOnSelChange'] == 'true')) {
  14145. $ff += 1 << 26;
  14146. }
  14147. $opt['ff'] = $ff;
  14148. // defaultValue: The default value of a field - that is, the value that the field is set to when the form is reset.
  14149. if (isset($prop['defaultValue'])) {
  14150. $opt['dv'] = $prop['defaultValue'];
  14151. }
  14152. $f = 4; // default value for annotation flags
  14153. // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
  14154. if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
  14155. $f += 1 << 6;
  14156. }
  14157. // display: Controls whether the field is hidden or visible on screen and in print.
  14158. if (isset($prop['display'])) {
  14159. if ($prop['display'] == 'display.visible') {
  14160. //
  14161. } elseif ($prop['display'] == 'display.hidden') {
  14162. $f += 1 << 1;
  14163. } elseif ($prop['display'] == 'display.noPrint') {
  14164. $f -= 1 << 2;
  14165. } elseif ($prop['display'] == 'display.noView') {
  14166. $f += 1 << 5;
  14167. }
  14168. }
  14169. $opt['f'] = $f;
  14170. // currentValueIndices: Reads and writes single or multiple values of a list box or combo box.
  14171. if (isset($prop['currentValueIndices']) AND is_array($prop['currentValueIndices'])) {
  14172. $opt['i'] = $prop['currentValueIndices'];
  14173. }
  14174. // value: The value of the field data that the user has entered.
  14175. if (isset($prop['value'])) {
  14176. if (is_array($prop['value'])) {
  14177. $opt['opt'] = array();
  14178. foreach ($prop['value'] AS $key => $optval) {
  14179. // exportValues: An array of strings representing the export values for the field.
  14180. if (isset($prop['exportValues'][$key])) {
  14181. $opt['opt'][$key] = array($prop['exportValues'][$key], $prop['value'][$key]);
  14182. } else {
  14183. $opt['opt'][$key] = $prop['value'][$key];
  14184. }
  14185. }
  14186. } else {
  14187. $opt['v'] = $prop['value'];
  14188. }
  14189. }
  14190. // richValue: This property specifies the text contents and formatting of a rich text field.
  14191. if (isset($prop['richValue'])) {
  14192. $opt['rv'] = $prop['richValue'];
  14193. }
  14194. // submitName: If nonempty, used during form submission instead of name. Only applicable if submitting in HTML format (that is, URL-encoded).
  14195. if (isset($prop['submitName'])) {
  14196. $opt['tm'] = $prop['submitName'];
  14197. }
  14198. // name: Fully qualified field name.
  14199. if (isset($prop['name'])) {
  14200. $opt['t'] = $prop['name'];
  14201. }
  14202. // userName: The user name (short description string) of the field.
  14203. if (isset($prop['userName'])) {
  14204. $opt['tu'] = $prop['userName'];
  14205. }
  14206. // highlight: Defines how a button reacts when a user clicks it.
  14207. if (isset($prop['highlight'])) {
  14208. switch ($prop['highlight']) {
  14209. case 'none':
  14210. case 'highlight.n': {
  14211. $opt['h'] = 'N';
  14212. break;
  14213. }
  14214. case 'invert':
  14215. case 'highlight.i': {
  14216. $opt['h'] = 'i';
  14217. break;
  14218. }
  14219. case 'push':
  14220. case 'highlight.p': {
  14221. $opt['h'] = 'P';
  14222. break;
  14223. }
  14224. case 'outline':
  14225. case 'highlight.o': {
  14226. $opt['h'] = 'O';
  14227. break;
  14228. }
  14229. }
  14230. }
  14231. // Unsupported options:
  14232. // - calcOrderIndex: Changes the calculation order of fields in the document.
  14233. // - delay: Delays the redrawing of a field's appearance.
  14234. // - defaultStyle: This property defines the default style attributes for the form field.
  14235. // - style: Allows the user to set the glyph style of a check box or radio button.
  14236. // - textColor, textFont, textSize
  14237. return $opt;
  14238. }
  14239. /**
  14240. * Set default properties for form fields.
  14241. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  14242. * @public
  14243. * @author Nicola Asuni
  14244. * @since 4.8.000 (2009-09-06)
  14245. */
  14246. public function setFormDefaultProp($prop=array()) {
  14247. $this->default_form_prop = $prop;
  14248. }
  14249. /**
  14250. * Return the default properties for form fields.
  14251. * @return array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  14252. * @public
  14253. * @author Nicola Asuni
  14254. * @since 4.8.000 (2009-09-06)
  14255. */
  14256. public function getFormDefaultProp() {
  14257. return $this->default_form_prop;
  14258. }
  14259. /**
  14260. * Creates a text field
  14261. * @param $name (string) field name
  14262. * @param $w (float) Width of the rectangle
  14263. * @param $h (float) Height of the rectangle
  14264. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  14265. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  14266. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  14267. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  14268. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  14269. * @public
  14270. * @author Nicola Asuni
  14271. * @since 4.8.000 (2009-09-07)
  14272. */
  14273. public function TextField($name, $w, $h, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  14274. if ($x === '') {
  14275. $x = $this->x;
  14276. }
  14277. if ($y === '') {
  14278. $y = $this->y;
  14279. }
  14280. // check page for no-write regions and adapt page margins if necessary
  14281. $this->checkPageRegions($h, $x, $y);
  14282. if ($js) {
  14283. $this->_addfield('text', $name, $x, $y, $w, $h, $prop);
  14284. return;
  14285. }
  14286. // get default style
  14287. $prop = array_merge($this->getFormDefaultProp(), $prop);
  14288. // get annotation data
  14289. $popt = $this->getAnnotOptFromJSProp($prop);
  14290. // set default appearance stream
  14291. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  14292. $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  14293. $popt['da'] = $fontstyle;
  14294. $popt['ap'] = array();
  14295. $popt['ap']['n'] = 'q BT '.$fontstyle.' ET Q';
  14296. // merge options
  14297. $opt = array_merge($popt, $opt);
  14298. // remove some conflicting options
  14299. unset($opt['bs']);
  14300. // set remaining annotation data
  14301. $opt['Subtype'] = 'Widget';
  14302. $opt['ft'] = 'Tx';
  14303. $opt['t'] = $name;
  14304. /*
  14305. Additional annotation's parameters (check _putannotsobj() method):
  14306. //$opt['f']
  14307. //$opt['ap']
  14308. //$opt['as']
  14309. //$opt['bs']
  14310. //$opt['be']
  14311. //$opt['c']
  14312. //$opt['border']
  14313. //$opt['h']
  14314. //$opt['mk']
  14315. //$opt['mk']['r']
  14316. //$opt['mk']['bc']
  14317. //$opt['mk']['bg']
  14318. //$opt['mk']['ca']
  14319. //$opt['mk']['rc']
  14320. //$opt['mk']['ac']
  14321. //$opt['mk']['i']
  14322. //$opt['mk']['ri']
  14323. //$opt['mk']['ix']
  14324. //$opt['mk']['if']
  14325. //$opt['mk']['if']['sw']
  14326. //$opt['mk']['if']['s']
  14327. //$opt['mk']['if']['a']
  14328. //$opt['mk']['if']['fb']
  14329. //$opt['mk']['tp']
  14330. //$opt['tu']
  14331. //$opt['tm']
  14332. //$opt['ff']
  14333. //$opt['v']
  14334. //$opt['dv']
  14335. //$opt['a']
  14336. //$opt['aa']
  14337. //$opt['q']
  14338. */
  14339. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  14340. if ($this->rtl) {
  14341. $this->x -= $w;
  14342. } else {
  14343. $this->x += $w;
  14344. }
  14345. }
  14346. /**
  14347. * Creates a RadioButton field
  14348. * @param $name (string) field name
  14349. * @param $w (int) width
  14350. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  14351. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  14352. * @param $onvalue (string) value to be returned if selected.
  14353. * @param $checked (boolean) define the initial state.
  14354. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  14355. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  14356. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  14357. * @public
  14358. * @author Nicola Asuni
  14359. * @since 4.8.000 (2009-09-07)
  14360. */
  14361. public function RadioButton($name, $w, $prop=array(), $opt=array(), $onvalue='On', $checked=false, $x='', $y='', $js=false) {
  14362. if ($x === '') {
  14363. $x = $this->x;
  14364. }
  14365. if ($y === '') {
  14366. $y = $this->y;
  14367. }
  14368. // check page for no-write regions and adapt page margins if necessary
  14369. $this->checkPageRegions($w, $x, $y);
  14370. if ($js) {
  14371. $this->_addfield('radiobutton', $name, $x, $y, $w, $w, $prop);
  14372. return;
  14373. }
  14374. if ($this->empty_string($onvalue)) {
  14375. $onvalue = 'On';
  14376. }
  14377. if ($checked) {
  14378. $defval = $onvalue;
  14379. } else {
  14380. $defval = 'Off';
  14381. }
  14382. // set data for parent group
  14383. if (!isset($this->radiobutton_groups[$this->page])) {
  14384. $this->radiobutton_groups[$this->page] = array();
  14385. }
  14386. if (!isset($this->radiobutton_groups[$this->page][$name])) {
  14387. $this->radiobutton_groups[$this->page][$name] = array();
  14388. ++$this->n;
  14389. $this->radiobutton_groups[$this->page][$name]['n'] = $this->n;
  14390. $this->radio_groups[] = $this->n;
  14391. $kid = ($this->n + 2);
  14392. } else {
  14393. $kid = ($this->n + 1);
  14394. }
  14395. // save object ID to be added on Kids entry on parent object
  14396. $this->radiobutton_groups[$this->page][$name][] = array('kid' => $kid, 'def' => $defval);
  14397. // get default style
  14398. $prop = array_merge($this->getFormDefaultProp(), $prop);
  14399. $prop['NoToggleToOff'] = 'true';
  14400. $prop['Radio'] = 'true';
  14401. $prop['borderStyle'] = 'inset';
  14402. // get annotation data
  14403. $popt = $this->getAnnotOptFromJSProp($prop);
  14404. // set additional default values
  14405. $font = 'zapfdingbats';
  14406. $this->AddFont($font);
  14407. $tmpfont = $this->getFontBuffer($font);
  14408. $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  14409. $fontstyle = sprintf('/F%d %.2F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
  14410. $popt['da'] = $fontstyle;
  14411. $popt['ap'] = array();
  14412. $popt['ap']['n'] = array();
  14413. $popt['ap']['n'][$onvalue] = 'q BT '.$fontstyle.' 0 0 Td (8) Tj ET Q';
  14414. $popt['ap']['n']['Off'] = 'q BT '.$fontstyle.' 0 0 Td (8) Tj ET Q';
  14415. if (!isset($popt['mk'])) {
  14416. $popt['mk'] = array();
  14417. }
  14418. $popt['mk']['ca'] = '(l)';
  14419. // merge options
  14420. $opt = array_merge($popt, $opt);
  14421. // set remaining annotation data
  14422. $opt['Subtype'] = 'Widget';
  14423. $opt['ft'] = 'Btn';
  14424. if ($checked) {
  14425. $opt['v'] = array('/'.$onvalue);
  14426. $opt['as'] = $onvalue;
  14427. } else {
  14428. $opt['as'] = 'Off';
  14429. }
  14430. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  14431. if ($this->rtl) {
  14432. $this->x -= $w;
  14433. } else {
  14434. $this->x += $w;
  14435. }
  14436. }
  14437. /**
  14438. * Creates a List-box field
  14439. * @param $name (string) field name
  14440. * @param $w (int) width
  14441. * @param $h (int) height
  14442. * @param $values (array) array containing the list of values.
  14443. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  14444. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  14445. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  14446. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  14447. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  14448. * @public
  14449. * @author Nicola Asuni
  14450. * @since 4.8.000 (2009-09-07)
  14451. */
  14452. public function ListBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  14453. if ($x === '') {
  14454. $x = $this->x;
  14455. }
  14456. if ($y === '') {
  14457. $y = $this->y;
  14458. }
  14459. // check page for no-write regions and adapt page margins if necessary
  14460. $this->checkPageRegions($h, $x, $y);
  14461. if ($js) {
  14462. $this->_addfield('listbox', $name, $x, $y, $w, $h, $prop);
  14463. $s = '';
  14464. foreach ($values as $value) {
  14465. $s .= "'".addslashes($value)."',";
  14466. }
  14467. $this->javascript .= 'f'.$name.'.setItems(['.substr($s, 0, -1)."]);\n";
  14468. return;
  14469. }
  14470. // get default style
  14471. $prop = array_merge($this->getFormDefaultProp(), $prop);
  14472. // get annotation data
  14473. $popt = $this->getAnnotOptFromJSProp($prop);
  14474. // set additional default values
  14475. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  14476. $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  14477. $popt['da'] = $fontstyle;
  14478. $popt['ap'] = array();
  14479. $popt['ap']['n'] = 'q BT '.$fontstyle.' ET Q';
  14480. // merge options
  14481. $opt = array_merge($popt, $opt);
  14482. // set remaining annotation data
  14483. $opt['Subtype'] = 'Widget';
  14484. $opt['ft'] = 'Ch';
  14485. $opt['t'] = $name;
  14486. $opt['opt'] = $values;
  14487. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  14488. if ($this->rtl) {
  14489. $this->x -= $w;
  14490. } else {
  14491. $this->x += $w;
  14492. }
  14493. }
  14494. /**
  14495. * Creates a Combo-box field
  14496. * @param $name (string) field name
  14497. * @param $w (int) width
  14498. * @param $h (int) height
  14499. * @param $values (array) array containing the list of values.
  14500. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  14501. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  14502. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  14503. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  14504. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  14505. * @public
  14506. * @author Nicola Asuni
  14507. * @since 4.8.000 (2009-09-07)
  14508. */
  14509. public function ComboBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  14510. if ($x === '') {
  14511. $x = $this->x;
  14512. }
  14513. if ($y === '') {
  14514. $y = $this->y;
  14515. }
  14516. // check page for no-write regions and adapt page margins if necessary
  14517. $this->checkPageRegions($h, $x, $y);
  14518. if ($js) {
  14519. $this->_addfield('combobox', $name, $x, $y, $w, $h, $prop);
  14520. $s = '';
  14521. foreach ($values as $value) {
  14522. $s .= "'".addslashes($value)."',";
  14523. }
  14524. $this->javascript .= 'f'.$name.'.setItems(['.substr($s, 0, -1)."]);\n";
  14525. return;
  14526. }
  14527. // get default style
  14528. $prop = array_merge($this->getFormDefaultProp(), $prop);
  14529. $prop['Combo'] = true;
  14530. // get annotation data
  14531. $popt = $this->getAnnotOptFromJSProp($prop);
  14532. // set additional default options
  14533. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  14534. $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  14535. $popt['da'] = $fontstyle;
  14536. $popt['ap'] = array();
  14537. $popt['ap']['n'] = 'q BT '.$fontstyle.' ET Q';
  14538. // merge options
  14539. $opt = array_merge($popt, $opt);
  14540. // set remaining annotation data
  14541. $opt['Subtype'] = 'Widget';
  14542. $opt['ft'] = 'Ch';
  14543. $opt['t'] = $name;
  14544. $opt['opt'] = $values;
  14545. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  14546. if ($this->rtl) {
  14547. $this->x -= $w;
  14548. } else {
  14549. $this->x += $w;
  14550. }
  14551. }
  14552. /**
  14553. * Creates a CheckBox field
  14554. * @param $name (string) field name
  14555. * @param $w (int) width
  14556. * @param $checked (boolean) define the initial state.
  14557. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  14558. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  14559. * @param $onvalue (string) value to be returned if selected.
  14560. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  14561. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  14562. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  14563. * @public
  14564. * @author Nicola Asuni
  14565. * @since 4.8.000 (2009-09-07)
  14566. */
  14567. public function CheckBox($name, $w, $checked=false, $prop=array(), $opt=array(), $onvalue='Yes', $x='', $y='', $js=false) {
  14568. if ($x === '') {
  14569. $x = $this->x;
  14570. }
  14571. if ($y === '') {
  14572. $y = $this->y;
  14573. }
  14574. // check page for no-write regions and adapt page margins if necessary
  14575. $this->checkPageRegions($w, $x, $y);
  14576. if ($js) {
  14577. $this->_addfield('checkbox', $name, $x, $y, $w, $w, $prop);
  14578. return;
  14579. }
  14580. if (!isset($prop['value'])) {
  14581. $prop['value'] = array('Yes');
  14582. }
  14583. // get default style
  14584. $prop = array_merge($this->getFormDefaultProp(), $prop);
  14585. $prop['borderStyle'] = 'inset';
  14586. // get annotation data
  14587. $popt = $this->getAnnotOptFromJSProp($prop);
  14588. // set additional default options
  14589. $font = 'zapfdingbats';
  14590. $this->AddFont($font);
  14591. $tmpfont = $this->getFontBuffer($font);
  14592. $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  14593. $fontstyle = sprintf('/F%d %.2F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
  14594. $popt['da'] = $fontstyle;
  14595. $popt['ap'] = array();
  14596. $popt['ap']['n'] = array();
  14597. $popt['ap']['n']['Yes'] = 'q BT '.$fontstyle.' 0 0 Td (8) Tj ET Q';
  14598. $popt['ap']['n']['Off'] = 'q BT '.$fontstyle.' 0 0 Td (8) Tj ET Q';
  14599. // merge options
  14600. $opt = array_merge($popt, $opt);
  14601. // set remaining annotation data
  14602. $opt['Subtype'] = 'Widget';
  14603. $opt['ft'] = 'Btn';
  14604. $opt['t'] = $name;
  14605. $opt['opt'] = array($onvalue);
  14606. if ($checked) {
  14607. $opt['v'] = array('/0');
  14608. $opt['as'] = 'Yes';
  14609. } else {
  14610. $opt['v'] = array('/Off');
  14611. $opt['as'] = 'Off';
  14612. }
  14613. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  14614. if ($this->rtl) {
  14615. $this->x -= $w;
  14616. } else {
  14617. $this->x += $w;
  14618. }
  14619. }
  14620. /**
  14621. * Creates a button field
  14622. * @param $name (string) field name
  14623. * @param $w (int) width
  14624. * @param $h (int) height
  14625. * @param $caption (string) caption.
  14626. * @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.
  14627. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  14628. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  14629. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  14630. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  14631. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  14632. * @public
  14633. * @author Nicola Asuni
  14634. * @since 4.8.000 (2009-09-07)
  14635. */
  14636. public function Button($name, $w, $h, $caption, $action, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  14637. if ($x === '') {
  14638. $x = $this->x;
  14639. }
  14640. if ($y === '') {
  14641. $y = $this->y;
  14642. }
  14643. // check page for no-write regions and adapt page margins if necessary
  14644. $this->checkPageRegions($h, $x, $y);
  14645. if ($js) {
  14646. $this->_addfield('button', $name, $this->x, $this->y, $w, $h, $prop);
  14647. $this->javascript .= 'f'.$name.".buttonSetCaption('".addslashes($caption)."');\n";
  14648. $this->javascript .= 'f'.$name.".setAction('MouseUp','".addslashes($action)."');\n";
  14649. $this->javascript .= 'f'.$name.".highlight='push';\n";
  14650. $this->javascript .= 'f'.$name.".print=false;\n";
  14651. return;
  14652. }
  14653. // get default style
  14654. $prop = array_merge($this->getFormDefaultProp(), $prop);
  14655. $prop['Pushbutton'] = 'true';
  14656. $prop['highlight'] = 'push';
  14657. $prop['display'] = 'display.noPrint';
  14658. // get annotation data
  14659. $popt = $this->getAnnotOptFromJSProp($prop);
  14660. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  14661. $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  14662. $popt['da'] = $fontstyle;
  14663. $popt['ap'] = array();
  14664. $popt['ap']['n'] = 'q BT '.$fontstyle.' ET Q';
  14665. // set additional default options
  14666. if (!isset($popt['mk'])) {
  14667. $popt['mk'] = array();
  14668. }
  14669. $ann_obj_id = ($this->n + 1);
  14670. if (!empty($action) AND !is_array($action)) {
  14671. $ann_obj_id = ($this->n + 2);
  14672. }
  14673. $popt['mk']['ca'] = $this->_textstring($caption, $ann_obj_id);
  14674. $popt['mk']['rc'] = $this->_textstring($caption, $ann_obj_id);
  14675. $popt['mk']['ac'] = $this->_textstring($caption, $ann_obj_id);
  14676. // merge options
  14677. $opt = array_merge($popt, $opt);
  14678. // set remaining annotation data
  14679. $opt['Subtype'] = 'Widget';
  14680. $opt['ft'] = 'Btn';
  14681. $opt['t'] = $caption;
  14682. $opt['v'] = $name;
  14683. if (!empty($action)) {
  14684. if (is_array($action)) {
  14685. // form action options as on section 12.7.5 of PDF32000_2008.
  14686. $opt['aa'] = '/D <<';
  14687. $bmode = array('SubmitForm', 'ResetForm', 'ImportData');
  14688. foreach ($action AS $key => $val) {
  14689. if (($key == 'S') AND in_array($val, $bmode)) {
  14690. $opt['aa'] .= ' /S /'.$val;
  14691. } elseif (($key == 'F') AND (!empty($val))) {
  14692. $opt['aa'] .= ' /F '.$this->_datastring($val, $ann_obj_id);
  14693. } elseif (($key == 'Fields') AND is_array($val) AND !empty($val)) {
  14694. $opt['aa'] .= ' /Fields [';
  14695. foreach ($val AS $field) {
  14696. $opt['aa'] .= ' '.$this->_textstring($field, $ann_obj_id);
  14697. }
  14698. $opt['aa'] .= ']';
  14699. } elseif (($key == 'Flags')) {
  14700. $ff = 0;
  14701. if (is_array($val)) {
  14702. foreach ($val AS $flag) {
  14703. switch ($flag) {
  14704. case 'Include/Exclude': {
  14705. $ff += 1 << 0;
  14706. break;
  14707. }
  14708. case 'IncludeNoValueFields': {
  14709. $ff += 1 << 1;
  14710. break;
  14711. }
  14712. case 'ExportFormat': {
  14713. $ff += 1 << 2;
  14714. break;
  14715. }
  14716. case 'GetMethod': {
  14717. $ff += 1 << 3;
  14718. break;
  14719. }
  14720. case 'SubmitCoordinates': {
  14721. $ff += 1 << 4;
  14722. break;
  14723. }
  14724. case 'XFDF': {
  14725. $ff += 1 << 5;
  14726. break;
  14727. }
  14728. case 'IncludeAppendSaves': {
  14729. $ff += 1 << 6;
  14730. break;
  14731. }
  14732. case 'IncludeAnnotations': {
  14733. $ff += 1 << 7;
  14734. break;
  14735. }
  14736. case 'SubmitPDF': {
  14737. $ff += 1 << 8;
  14738. break;
  14739. }
  14740. case 'CanonicalFormat': {
  14741. $ff += 1 << 9;
  14742. break;
  14743. }
  14744. case 'ExclNonUserAnnots': {
  14745. $ff += 1 << 10;
  14746. break;
  14747. }
  14748. case 'ExclFKey': {
  14749. $ff += 1 << 11;
  14750. break;
  14751. }
  14752. case 'EmbedForm': {
  14753. $ff += 1 << 13;
  14754. break;
  14755. }
  14756. }
  14757. }
  14758. } else {
  14759. $ff = intval($val);
  14760. }
  14761. $opt['aa'] .= ' /Flags '.$ff;
  14762. }
  14763. }
  14764. $opt['aa'] .= ' >>';
  14765. } else {
  14766. // Javascript action or raw action command
  14767. $js_obj_id = $this->addJavascriptObject($action);
  14768. $opt['aa'] = '/D '.$js_obj_id.' 0 R';
  14769. }
  14770. }
  14771. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  14772. if ($this->rtl) {
  14773. $this->x -= $w;
  14774. } else {
  14775. $this->x += $w;
  14776. }
  14777. }
  14778. // --- END FORMS FIELDS ------------------------------------------------
  14779. /**
  14780. * Add certification signature (DocMDP or UR3)
  14781. * You can set only one signature type
  14782. * @protected
  14783. * @author Nicola Asuni
  14784. * @since 4.6.008 (2009-05-07)
  14785. */
  14786. protected function _putsignature() {
  14787. if ((!$this->sign) OR (!isset($this->signature_data['cert_type']))) {
  14788. return;
  14789. }
  14790. $out = $this->_getobj($this->sig_obj_id + 1)."\n";
  14791. $out .= '<< /Type /Sig';
  14792. $out .= ' /Filter /Adobe.PPKLite';
  14793. $out .= ' /SubFilter /adbe.pkcs7.detached';
  14794. $out .= ' '.$this->byterange_string;
  14795. $out .= ' /Contents<'.str_repeat('0', $this->signature_max_length).'>';
  14796. $out .= ' /Reference ['; // array of signature reference dictionaries
  14797. $out .= ' << /Type /SigRef';
  14798. if ($this->signature_data['cert_type'] > 0) {
  14799. $out .= ' /TransformMethod /DocMDP';
  14800. $out .= ' /TransformParams <<';
  14801. $out .= ' /Type /TransformParams';
  14802. $out .= ' /V /1.2';
  14803. $out .= ' /P '.$this->signature_data['cert_type'];
  14804. } else {
  14805. $out .= ' /TransformMethod /UR3';
  14806. $out .= ' /TransformParams <<';
  14807. $out .= ' /Type /TransformParams';
  14808. $out .= ' /V /2.2';
  14809. if (!$this->empty_string($this->ur['document'])) {
  14810. $out .= ' /Document['.$this->ur['document'].']';
  14811. }
  14812. if (!$this->empty_string($this->ur['form'])) {
  14813. $out .= ' /Form['.$this->ur['form'].']';
  14814. }
  14815. if (!$this->empty_string($this->ur['signature'])) {
  14816. $out .= ' /Signature['.$this->ur['signature'].']';
  14817. }
  14818. if (!$this->empty_string($this->ur['annots'])) {
  14819. $out .= ' /Annots['.$this->ur['annots'].']';
  14820. }
  14821. if (!$this->empty_string($this->ur['ef'])) {
  14822. $out .= ' /EF['.$this->ur['ef'].']';
  14823. }
  14824. if (!$this->empty_string($this->ur['formex'])) {
  14825. $out .= ' /FormEX['.$this->ur['formex'].']';
  14826. }
  14827. }
  14828. $out .= ' >>'; // close TransformParams
  14829. // optional digest data (values must be calculated and replaced later)
  14830. //$out .= ' /Data ********** 0 R';
  14831. //$out .= ' /DigestMethod/MD5';
  14832. //$out .= ' /DigestLocation[********** 34]';
  14833. //$out .= ' /DigestValue<********************************>';
  14834. $out .= ' >>';
  14835. $out .= ' ]'; // end of reference
  14836. if (isset($this->signature_data['info']['Name']) AND !$this->empty_string($this->signature_data['info']['Name'])) {
  14837. $out .= ' /Name '.$this->_textstring($this->signature_data['info']['Name']);
  14838. }
  14839. if (isset($this->signature_data['info']['Location']) AND !$this->empty_string($this->signature_data['info']['Location'])) {
  14840. $out .= ' /Location '.$this->_textstring($this->signature_data['info']['Location']);
  14841. }
  14842. if (isset($this->signature_data['info']['Reason']) AND !$this->empty_string($this->signature_data['info']['Reason'])) {
  14843. $out .= ' /Reason '.$this->_textstring($this->signature_data['info']['Reason']);
  14844. }
  14845. if (isset($this->signature_data['info']['ContactInfo']) AND !$this->empty_string($this->signature_data['info']['ContactInfo'])) {
  14846. $out .= ' /ContactInfo '.$this->_textstring($this->signature_data['info']['ContactInfo']);
  14847. }
  14848. $out .= ' /M '.$this->_datestring();
  14849. $out .= ' >>';
  14850. $out .= "\n".'endobj';
  14851. $this->_out($out);
  14852. }
  14853. /**
  14854. * Set User's Rights for PDF Reader
  14855. * WARNING: This is experimental and currently do not work.
  14856. * Check the PDF Reference 8.7.1 Transform Methods,
  14857. * Table 8.105 Entries in the UR transform parameters dictionary
  14858. * @param $enable (boolean) if true enable user's rights on PDF reader
  14859. * @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.
  14860. * @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.
  14861. * @param $form (string) Names specifying additional form-field-related usage rights for the document. Valid names are: /Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate
  14862. * @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.
  14863. * @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
  14864. Names specifying additional embedded-files-related usage rights for the document.
  14865. * @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.
  14866. * @public
  14867. * @author Nicola Asuni
  14868. * @since 2.9.000 (2008-03-26)
  14869. */
  14870. public function setUserRights(
  14871. $enable=true,
  14872. $document='/FullSave',
  14873. $annots='/Create/Delete/Modify/Copy/Import/Export',
  14874. $form='/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate',
  14875. $signature='/Modify',
  14876. $ef='/Create/Delete/Modify/Import',
  14877. $formex='') {
  14878. $this->ur['enabled'] = $enable;
  14879. $this->ur['document'] = $document;
  14880. $this->ur['annots'] = $annots;
  14881. $this->ur['form'] = $form;
  14882. $this->ur['signature'] = $signature;
  14883. $this->ur['ef'] = $ef;
  14884. $this->ur['formex'] = $formex;
  14885. if (!$this->sign) {
  14886. $this->setSignature('', '', '', '', 0, array());
  14887. }
  14888. }
  14889. /**
  14890. * Enable document signature (requires the OpenSSL Library).
  14891. * The digital signature improve document authenticity and integrity and allows o enable extra features on Acrobat Reader.
  14892. * To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  14893. * To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  14894. * To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
  14895. * @param $signing_cert (mixed) signing certificate (string or filename prefixed with 'file://')
  14896. * @param $private_key (mixed) private key (string or filename prefixed with 'file://')
  14897. * @param $private_key_password (string) password
  14898. * @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.
  14899. * @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.
  14900. * @param $info (array) array of option information: Name, Location, Reason, ContactInfo.
  14901. * @public
  14902. * @author Nicola Asuni
  14903. * @since 4.6.005 (2009-04-24)
  14904. */
  14905. public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array()) {
  14906. // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  14907. // to export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  14908. // to convert pfx certificate to pem: openssl
  14909. // OpenSSL> pkcs12 -in <cert.pfx> -out <cert.crt> -nodes
  14910. $this->sign = true;
  14911. ++$this->n;
  14912. $this->sig_obj_id = $this->n; // signature widget
  14913. ++$this->n; // signature object ($this->sig_obj_id + 1)
  14914. $this->signature_data = array();
  14915. if (strlen($signing_cert) == 0) {
  14916. $signing_cert = 'file://'.dirname(__FILE__).'/tcpdf.crt';
  14917. $private_key_password = 'tcpdfdemo';
  14918. }
  14919. if (strlen($private_key) == 0) {
  14920. $private_key = $signing_cert;
  14921. }
  14922. $this->signature_data['signcert'] = $signing_cert;
  14923. $this->signature_data['privkey'] = $private_key;
  14924. $this->signature_data['password'] = $private_key_password;
  14925. $this->signature_data['extracerts'] = $extracerts;
  14926. $this->signature_data['cert_type'] = $cert_type;
  14927. $this->signature_data['info'] = $info;
  14928. }
  14929. /**
  14930. * Set the digital signature appearance (a cliccable rectangle area to get signature properties)
  14931. * @param $x (float) Abscissa of the upper-left corner.
  14932. * @param $y (float) Ordinate of the upper-left corner.
  14933. * @param $w (float) Width of the signature area.
  14934. * @param $h (float) Height of the signature area.
  14935. * @param $page (int) option page number (if < 0 the current page is used).
  14936. * @public
  14937. * @author Nicola Asuni
  14938. * @since 5.3.011 (2010-06-17)
  14939. */
  14940. public function setSignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1) {
  14941. if (($page < 1) OR ($page > $this->numpages)) {
  14942. $this->signature_appearance['page'] = $this->page;
  14943. } else {
  14944. $this->signature_appearance['page'] = intval($page);
  14945. }
  14946. $a = $x * $this->k;
  14947. $b = $this->pagedim[($this->signature_appearance['page'])]['h'] - (($y + $h) * $this->k);
  14948. $c = $w * $this->k;
  14949. $d = $h * $this->k;
  14950. $this->signature_appearance['rect'] = sprintf('%.2F %.2F %.2F %.2F', $a, $b, $a+$c, $b+$d);
  14951. }
  14952. /**
  14953. * Create a new page group.
  14954. * NOTE: call this function before calling AddPage()
  14955. * @param $page (int) starting group page (leave empty for next page).
  14956. * @public
  14957. * @since 3.0.000 (2008-03-27)
  14958. */
  14959. public function startPageGroup($page='') {
  14960. if (empty($page)) {
  14961. $page = $this->page + 1;
  14962. }
  14963. $this->newpagegroup[$page] = true;
  14964. }
  14965. /**
  14966. * Defines a string alias for the total number of pages. It will be substituted as the document is closed.
  14967. * @param $numalias (string) The alias.
  14968. * @since 1.4
  14969. * @see getAliasNbPages(), PageNo(), Footer()
  14970. * @public
  14971. */
  14972. public function AliasNbPages($numalias="{nb}") {
  14973. $this->AliasNbPages = $numalias;
  14974. }
  14975. /**
  14976. * Returns the string alias used for the total number of pages.
  14977. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  14978. * @return string
  14979. * @since 4.0.018 (2008-08-08)
  14980. * @see AliasNbPages(), PageNo(), Footer()
  14981. * @public
  14982. */
  14983. public function getAliasNbPages() {
  14984. if ($this->isUnicodeFont()) {
  14985. return '{'.$this->AliasNbPages.'}';
  14986. }
  14987. return $this->AliasNbPages;
  14988. }
  14989. /**
  14990. * Defines a string alias for the page number. It will be substituted as the document is closed.
  14991. * @param $numalias (string) The alias.
  14992. * @since 4.5.000 (2009-01-02)
  14993. * @see getAliasNbPages(), PageNo(), Footer()
  14994. * @public
  14995. */
  14996. public function AliasNumPage($numalias="{pnb}") {
  14997. $this->AliasNumPage = $numalias;
  14998. }
  14999. /**
  15000. * Returns the string alias used for the page number.
  15001. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  15002. * @return string
  15003. * @since 4.5.000 (2009-01-02)
  15004. * @see AliasNbPages(), PageNo(), Footer()
  15005. * @public
  15006. */
  15007. public function getAliasNumPage() {
  15008. if ($this->isUnicodeFont()) {
  15009. return '{'.$this->AliasNumPage.'}';
  15010. }
  15011. return $this->AliasNumPage;
  15012. }
  15013. /**
  15014. * Return the current page in the group.
  15015. * @return current page in the group
  15016. * @public
  15017. * @since 3.0.000 (2008-03-27)
  15018. */
  15019. public function getGroupPageNo() {
  15020. return $this->pagegroups[$this->currpagegroup];
  15021. }
  15022. /**
  15023. * Returns the current group page number formatted as a string.
  15024. * @public
  15025. * @since 4.3.003 (2008-11-18)
  15026. * @see PaneNo(), formatPageNumber()
  15027. */
  15028. public function getGroupPageNoFormatted() {
  15029. return $this->formatPageNumber($this->getGroupPageNo());
  15030. }
  15031. /**
  15032. * Return the alias of the current page group
  15033. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  15034. * (will be replaced by the total number of pages in this group).
  15035. * @return alias of the current page group
  15036. * @public
  15037. * @since 3.0.000 (2008-03-27)
  15038. */
  15039. public function getPageGroupAlias() {
  15040. if ($this->isUnicodeFont()) {
  15041. return '{'.$this->currpagegroup.'}';
  15042. }
  15043. return $this->currpagegroup;
  15044. }
  15045. /**
  15046. * Return the alias for the page number on the current page group
  15047. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  15048. * (will be replaced by the total number of pages in this group).
  15049. * @return alias of the current page group
  15050. * @public
  15051. * @since 4.5.000 (2009-01-02)
  15052. */
  15053. public function getPageNumGroupAlias() {
  15054. if ($this->isUnicodeFont()) {
  15055. return '{'.str_replace('{nb', '{pnb', $this->currpagegroup).'}';
  15056. }
  15057. return str_replace('{nb', '{pnb', $this->currpagegroup);
  15058. }
  15059. /**
  15060. * Format the page numbers.
  15061. * This method can be overriden for custom formats.
  15062. * @param $num (int) page number
  15063. * @protected
  15064. * @since 4.2.005 (2008-11-06)
  15065. */
  15066. protected function formatPageNumber($num) {
  15067. return number_format((float)$num, 0, '', '.');
  15068. }
  15069. /**
  15070. * Format the page numbers on the Table Of Content.
  15071. * This method can be overriden for custom formats.
  15072. * @param $num (int) page number
  15073. * @protected
  15074. * @since 4.5.001 (2009-01-04)
  15075. * @see addTOC(), addHTMLTOC()
  15076. */
  15077. protected function formatTOCPageNumber($num) {
  15078. return number_format((float)$num, 0, '', '.');
  15079. }
  15080. /**
  15081. * Returns the current page number formatted as a string.
  15082. * @public
  15083. * @since 4.2.005 (2008-11-06)
  15084. * @see PaneNo(), formatPageNumber()
  15085. */
  15086. public function PageNoFormatted() {
  15087. return $this->formatPageNumber($this->PageNo());
  15088. }
  15089. /**
  15090. * Put visibility settings.
  15091. * @protected
  15092. * @since 3.0.000 (2008-03-27)
  15093. */
  15094. protected function _putocg() {
  15095. if ($this->pdflayers) {
  15096. $this->n_ocg_print = $this->_newobj();
  15097. $this->_out('<< /Type /OCG /Name '.$this->_textstring('print', $this->n_ocg_print).' /Usage << /Print <</PrintState /ON>> /View <</ViewState /OFF>> >> >>'."\n".'endobj');
  15098. $this->n_ocg_view = $this->_newobj();
  15099. $this->_out('<< /Type /OCG /Name '.$this->_textstring('view', $this->n_ocg_view).' /Usage << /Print <</PrintState /OFF>> /View <</ViewState /ON>> >> >>'."\n".'endobj');
  15100. }
  15101. }
  15102. /**
  15103. * Set the visibility of the successive elements.
  15104. * This can be useful, for instance, to put a background
  15105. * image or color that will show on screen but won't print.
  15106. * @param $v (string) visibility mode. Legal values are: all, print, screen.
  15107. * @public
  15108. * @since 3.0.000 (2008-03-27)
  15109. */
  15110. public function setVisibility($v) {
  15111. if ($this->openMarkedContent) {
  15112. // close existing open marked-content
  15113. $this->_out('EMC');
  15114. $this->openMarkedContent = false;
  15115. }
  15116. switch($v) {
  15117. case 'print': {
  15118. $this->_out('/OC /OC1 BDC');
  15119. $this->openMarkedContent = true;
  15120. $this->pdflayers = true;
  15121. break;
  15122. }
  15123. case 'screen': {
  15124. $this->_out('/OC /OC2 BDC');
  15125. $this->openMarkedContent = true;
  15126. $this->pdflayers = true;
  15127. break;
  15128. }
  15129. case 'all': {
  15130. break;
  15131. }
  15132. default: {
  15133. $this->Error('Incorrect visibility: '.$v);
  15134. break;
  15135. }
  15136. }
  15137. $this->visibility = $v;
  15138. }
  15139. /**
  15140. * Add transparency parameters to the current extgstate
  15141. * @param $parms (array) parameters
  15142. * @return the number of extgstates
  15143. * @protected
  15144. * @since 3.0.000 (2008-03-27)
  15145. */
  15146. protected function addExtGState($parms) {
  15147. $n = count($this->extgstates) + 1;
  15148. // check if this ExtGState already exist
  15149. for ($i = 1; $i < $n; ++$i) {
  15150. if ($this->extgstates[$i]['parms'] == $parms) {
  15151. // return reference to existing ExtGState
  15152. return $i;
  15153. }
  15154. }
  15155. $this->extgstates[$n]['parms'] = $parms;
  15156. return $n;
  15157. }
  15158. /**
  15159. * Add an extgstate
  15160. * @param $gs (array) extgstate
  15161. * @protected
  15162. * @since 3.0.000 (2008-03-27)
  15163. */
  15164. protected function setExtGState($gs) {
  15165. $this->_out(sprintf('/GS%d gs', $gs));
  15166. }
  15167. /**
  15168. * Put extgstates for object transparency
  15169. * @protected
  15170. * @since 3.0.000 (2008-03-27)
  15171. */
  15172. protected function _putextgstates() {
  15173. $ne = count($this->extgstates);
  15174. for ($i = 1; $i <= $ne; ++$i) {
  15175. $this->extgstates[$i]['n'] = $this->_newobj();
  15176. $out = '<< /Type /ExtGState';
  15177. foreach ($this->extgstates[$i]['parms'] as $k => $v) {
  15178. if (is_float($v)) {
  15179. $v = sprintf('%.2F', $v);
  15180. }
  15181. $out .= ' /'.$k.' '.$v;
  15182. }
  15183. $out .= ' >>';
  15184. $out .= "\n".'endobj';
  15185. $this->_out($out);
  15186. }
  15187. }
  15188. /**
  15189. * Set alpha for stroking (CA) and non-stroking (ca) operations.
  15190. * @param $alpha (float) real value from 0 (transparent) to 1 (opaque)
  15191. * @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
  15192. * @public
  15193. * @since 3.0.000 (2008-03-27)
  15194. */
  15195. public function setAlpha($alpha, $bm='Normal') {
  15196. $gs = $this->addExtGState(array('ca' => $alpha, 'CA' => $alpha, 'BM' => '/'.$bm, 'AIS' => 'false'));
  15197. $this->setExtGState($gs);
  15198. }
  15199. /**
  15200. * Set the default JPEG compression quality (1-100)
  15201. * @param $quality (int) JPEG quality, integer between 1 and 100
  15202. * @public
  15203. * @since 3.0.000 (2008-03-27)
  15204. */
  15205. public function setJPEGQuality($quality) {
  15206. if (($quality < 1) OR ($quality > 100)) {
  15207. $quality = 75;
  15208. }
  15209. $this->jpeg_quality = intval($quality);
  15210. }
  15211. /**
  15212. * Set the default number of columns in a row for HTML tables.
  15213. * @param $cols (int) number of columns
  15214. * @public
  15215. * @since 3.0.014 (2008-06-04)
  15216. */
  15217. public function setDefaultTableColumns($cols=4) {
  15218. $this->default_table_columns = intval($cols);
  15219. }
  15220. /**
  15221. * Set the height of the cell (line height) respect the font height.
  15222. * @param $h (int) cell proportion respect font height (typical value = 1.25).
  15223. * @public
  15224. * @since 3.0.014 (2008-06-04)
  15225. */
  15226. public function setCellHeightRatio($h) {
  15227. $this->cell_height_ratio = $h;
  15228. }
  15229. /**
  15230. * return the height of cell repect font height.
  15231. * @public
  15232. * @since 4.0.012 (2008-07-24)
  15233. */
  15234. public function getCellHeightRatio() {
  15235. return $this->cell_height_ratio;
  15236. }
  15237. /**
  15238. * Set the PDF version (check PDF reference for valid values).
  15239. * @param $version (string) PDF document version.
  15240. * @public
  15241. * @since 3.1.000 (2008-06-09)
  15242. */
  15243. public function setPDFVersion($version='1.7') {
  15244. $this->PDFVersion = $version;
  15245. }
  15246. /**
  15247. * Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
  15248. * (see Section 8.1 of PDF reference, "Viewer Preferences").
  15249. * <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>
  15250. * @param $preferences (array) array of options.
  15251. * @author Nicola Asuni
  15252. * @public
  15253. * @since 3.1.000 (2008-06-09)
  15254. */
  15255. public function setViewerPreferences($preferences) {
  15256. $this->viewer_preferences = $preferences;
  15257. }
  15258. /**
  15259. * Paints color transition registration bars
  15260. * @param $x (float) abscissa of the top left corner of the rectangle.
  15261. * @param $y (float) ordinate of the top left corner of the rectangle.
  15262. * @param $w (float) width of the rectangle.
  15263. * @param $h (float) height of the rectangle.
  15264. * @param $transition (boolean) if true prints tcolor transitions to white.
  15265. * @param $vertical (boolean) if true prints bar vertically.
  15266. * @param $colors (string) colors to print, one letter per color separated by comma (for example 'A,W,R,G,B,C,M,Y,K'): A=black, W=white, R=red, G=green, B=blue, C=cyan, M=magenta, Y=yellow, K=black.
  15267. * @author Nicola Asuni
  15268. * @since 4.9.000 (2010-03-26)
  15269. * @public
  15270. */
  15271. public function colorRegistrationBar($x, $y, $w, $h, $transition=true, $vertical=false, $colors='A,R,G,B,C,M,Y,K') {
  15272. $bars = explode(',', $colors);
  15273. $numbars = count($bars); // number of bars to print
  15274. // set bar measures
  15275. if ($vertical) {
  15276. $coords = array(0, 0, 0, 1);
  15277. $wb = $w / $numbars; // bar width
  15278. $hb = $h; // bar height
  15279. $xd = $wb; // delta x
  15280. $yd = 0; // delta y
  15281. } else {
  15282. $coords = array(1, 0, 0, 0);
  15283. $wb = $w; // bar width
  15284. $hb = $h / $numbars; // bar height
  15285. $xd = 0; // delta x
  15286. $yd = $hb; // delta y
  15287. }
  15288. $xb = $x;
  15289. $yb = $y;
  15290. foreach ($bars as $col) {
  15291. switch ($col) {
  15292. // set transition colors
  15293. case 'A': { // BLACK
  15294. $col_a = array(255);
  15295. $col_b = array(0);
  15296. break;
  15297. }
  15298. case 'W': { // WHITE
  15299. $col_a = array(0);
  15300. $col_b = array(255);
  15301. break;
  15302. }
  15303. case 'R': { // R
  15304. $col_a = array(255,255,255);
  15305. $col_b = array(255,0,0);
  15306. break;
  15307. }
  15308. case 'G': { // G
  15309. $col_a = array(255,255,255);
  15310. $col_b = array(0,255,0);
  15311. break;
  15312. }
  15313. case 'B': { // B
  15314. $col_a = array(255,255,255);
  15315. $col_b = array(0,0,255);
  15316. break;
  15317. }
  15318. case 'C': { // C
  15319. $col_a = array(0,0,0,0);
  15320. $col_b = array(100,0,0,0);
  15321. break;
  15322. }
  15323. case 'M': { // M
  15324. $col_a = array(0,0,0,0);
  15325. $col_b = array(0,100,0,0);
  15326. break;
  15327. }
  15328. case 'Y': { // Y
  15329. $col_a = array(0,0,0,0);
  15330. $col_b = array(0,0,100,0);
  15331. break;
  15332. }
  15333. case 'K': { // K
  15334. $col_a = array(0,0,0,0);
  15335. $col_b = array(0,0,0,100);
  15336. break;
  15337. }
  15338. default: { // GRAY
  15339. $col_a = array(255);
  15340. $col_b = array(0);
  15341. break;
  15342. }
  15343. }
  15344. if ($transition) {
  15345. // color gradient
  15346. $this->LinearGradient($xb, $yb, $wb, $hb, $col_a, $col_b, $coords);
  15347. } else {
  15348. // color rectangle
  15349. $this->SetFillColorArray($col_b);
  15350. $this->Rect($xb, $yb, $wb, $hb, 'F', array());
  15351. }
  15352. $xb += $xd;
  15353. $yb += $yd;
  15354. }
  15355. }
  15356. /**
  15357. * Paints crop mark
  15358. * @param $x (float) abscissa of the crop mark center.
  15359. * @param $y (float) ordinate of the crop mark center.
  15360. * @param $w (float) width of the crop mark.
  15361. * @param $h (float) height of the crop mark.
  15362. * @param $type (string) type of crop mark, one sybol per type separated by comma: A = top left, B = top right, C = bottom left, D = bottom right.
  15363. * @param $color (array) crop mark color (default black).
  15364. * @author Nicola Asuni
  15365. * @since 4.9.000 (2010-03-26)
  15366. * @public
  15367. */
  15368. public function cropMark($x, $y, $w, $h, $type='A,B,C,D', $color=array(0,0,0)) {
  15369. $this->SetLineStyle(array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $color));
  15370. $crops = explode(',', $type);
  15371. $numcrops = count($crops); // number of crop marks to print
  15372. $dw = $w / 4; // horizontal space to leave before the intersection point
  15373. $dh = $h / 4; // vertical space to leave before the intersection point
  15374. foreach ($crops as $crop) {
  15375. switch ($crop) {
  15376. case 'A': {
  15377. $x1 = $x;
  15378. $y1 = $y - $h;
  15379. $x2 = $x;
  15380. $y2 = $y - $dh;
  15381. $x3 = $x - $w;
  15382. $y3 = $y;
  15383. $x4 = $x - $dw;
  15384. $y4 = $y;
  15385. break;
  15386. }
  15387. case 'B': {
  15388. $x1 = $x;
  15389. $y1 = $y - $h;
  15390. $x2 = $x;
  15391. $y2 = $y - $dh;
  15392. $x3 = $x + $dw;
  15393. $y3 = $y;
  15394. $x4 = $x + $w;
  15395. $y4 = $y;
  15396. break;
  15397. }
  15398. case 'C': {
  15399. $x1 = $x - $w;
  15400. $y1 = $y;
  15401. $x2 = $x - $dw;
  15402. $y2 = $y;
  15403. $x3 = $x;
  15404. $y3 = $y + $dh;
  15405. $x4 = $x;
  15406. $y4 = $y + $h;
  15407. break;
  15408. }
  15409. case 'D': {
  15410. $x1 = $x + $dw;
  15411. $y1 = $y;
  15412. $x2 = $x + $w;
  15413. $y2 = $y;
  15414. $x3 = $x;
  15415. $y3 = $y + $dh;
  15416. $x4 = $x;
  15417. $y4 = $y + $h;
  15418. break;
  15419. }
  15420. }
  15421. $this->Line($x1, $y1, $x2, $y2);
  15422. $this->Line($x3, $y3, $x4, $y4);
  15423. }
  15424. }
  15425. /**
  15426. * Paints a registration mark
  15427. * @param $x (float) abscissa of the registration mark center.
  15428. * @param $y (float) ordinate of the registration mark center.
  15429. * @param $r (float) radius of the crop mark.
  15430. * @param $double (boolean) if true print two concentric crop marks.
  15431. * @param $cola (array) crop mark color (default black).
  15432. * @param $colb (array) second crop mark color.
  15433. * @author Nicola Asuni
  15434. * @since 4.9.000 (2010-03-26)
  15435. * @public
  15436. */
  15437. public function registrationMark($x, $y, $r, $double=false, $cola=array(0,0,0), $colb=array(255,255,255)) {
  15438. $line_style = array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $cola);
  15439. $this->SetFillColorArray($cola);
  15440. $this->PieSector($x, $y, $r, 90, 180, 'F');
  15441. $this->PieSector($x, $y, $r, 270, 360, 'F');
  15442. $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
  15443. if ($double) {
  15444. $r2 = $r * 0.5;
  15445. $this->SetFillColorArray($colb);
  15446. $this->PieSector($x, $y, $r2, 90, 180, 'F');
  15447. $this->PieSector($x, $y, $r2, 270, 360, 'F');
  15448. $this->SetFillColorArray($cola);
  15449. $this->PieSector($x, $y, $r2, 0, 90, 'F');
  15450. $this->PieSector($x, $y, $r2, 180, 270, 'F');
  15451. $this->Circle($x, $y, $r2, 0, 360, 'C', $line_style, array(), 8);
  15452. }
  15453. }
  15454. /**
  15455. * Paints a linear colour gradient.
  15456. * @param $x (float) abscissa of the top left corner of the rectangle.
  15457. * @param $y (float) ordinate of the top left corner of the rectangle.
  15458. * @param $w (float) width of the rectangle.
  15459. * @param $h (float) height of the rectangle.
  15460. * @param $col1 (array) first color (Grayscale, RGB or CMYK components).
  15461. * @param $col2 (array) second color (Grayscale, RGB or CMYK components).
  15462. * @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).
  15463. * @author Andreas Würmser, Nicola Asuni
  15464. * @since 3.1.000 (2008-06-09)
  15465. * @public
  15466. */
  15467. public function LinearGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0,0,1,0)) {
  15468. $this->Clip($x, $y, $w, $h);
  15469. $this->Gradient(2, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
  15470. }
  15471. /**
  15472. * Paints a radial colour gradient.
  15473. * @param $x (float) abscissa of the top left corner of the rectangle.
  15474. * @param $y (float) ordinate of the top left corner of the rectangle.
  15475. * @param $w (float) width of the rectangle.
  15476. * @param $h (float) height of the rectangle.
  15477. * @param $col1 (array) first color (Grayscale, RGB or CMYK components).
  15478. * @param $col2 (array) second color (Grayscale, RGB or CMYK components).
  15479. * @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.
  15480. * @author Andreas Würmser, Nicola Asuni
  15481. * @since 3.1.000 (2008-06-09)
  15482. * @public
  15483. */
  15484. public function RadialGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0.5,0.5,0.5,0.5,1)) {
  15485. $this->Clip($x, $y, $w, $h);
  15486. $this->Gradient(3, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
  15487. }
  15488. /**
  15489. * Paints a coons patch mesh.
  15490. * @param $x (float) abscissa of the top left corner of the rectangle.
  15491. * @param $y (float) ordinate of the top left corner of the rectangle.
  15492. * @param $w (float) width of the rectangle.
  15493. * @param $h (float) height of the rectangle.
  15494. * @param $col1 (array) first color (lower left corner) (RGB components).
  15495. * @param $col2 (array) second color (lower right corner) (RGB components).
  15496. * @param $col3 (array) third color (upper right corner) (RGB components).
  15497. * @param $col4 (array) fourth color (upper left corner) (RGB components).
  15498. * @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>
  15499. * @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
  15500. * @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
  15501. * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  15502. * @author Andreas Würmser, Nicola Asuni
  15503. * @since 3.1.000 (2008-06-09)
  15504. * @public
  15505. */
  15506. 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) {
  15507. $this->Clip($x, $y, $w, $h);
  15508. $n = count($this->gradients) + 1;
  15509. $this->gradients[$n] = array();
  15510. $this->gradients[$n]['type'] = 6; //coons patch mesh
  15511. $this->gradients[$n]['coords'] = array();
  15512. $this->gradients[$n]['antialias'] = $antialias;
  15513. $this->gradients[$n]['colors'] = array();
  15514. $this->gradients[$n]['transparency'] = false;
  15515. //check the coords array if it is the simple array or the multi patch array
  15516. if (!isset($coords[0]['f'])) {
  15517. //simple array -> convert to multi patch array
  15518. if (!isset($col1[1])) {
  15519. $col1[1] = $col1[2] = $col1[0];
  15520. }
  15521. if (!isset($col2[1])) {
  15522. $col2[1] = $col2[2] = $col2[0];
  15523. }
  15524. if (!isset($col3[1])) {
  15525. $col3[1] = $col3[2] = $col3[0];
  15526. }
  15527. if (!isset($col4[1])) {
  15528. $col4[1] = $col4[2] = $col4[0];
  15529. }
  15530. $patch_array[0]['f'] = 0;
  15531. $patch_array[0]['points'] = $coords;
  15532. $patch_array[0]['colors'][0]['r'] = $col1[0];
  15533. $patch_array[0]['colors'][0]['g'] = $col1[1];
  15534. $patch_array[0]['colors'][0]['b'] = $col1[2];
  15535. $patch_array[0]['colors'][1]['r'] = $col2[0];
  15536. $patch_array[0]['colors'][1]['g'] = $col2[1];
  15537. $patch_array[0]['colors'][1]['b'] = $col2[2];
  15538. $patch_array[0]['colors'][2]['r'] = $col3[0];
  15539. $patch_array[0]['colors'][2]['g'] = $col3[1];
  15540. $patch_array[0]['colors'][2]['b'] = $col3[2];
  15541. $patch_array[0]['colors'][3]['r'] = $col4[0];
  15542. $patch_array[0]['colors'][3]['g'] = $col4[1];
  15543. $patch_array[0]['colors'][3]['b'] = $col4[2];
  15544. } else {
  15545. //multi patch array
  15546. $patch_array = $coords;
  15547. }
  15548. $bpcd = 65535; //16 bits per coordinate
  15549. //build the data stream
  15550. $this->gradients[$n]['stream'] = '';
  15551. $count_patch = count($patch_array);
  15552. for ($i=0; $i < $count_patch; ++$i) {
  15553. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['f']); //start with the edge flag as 8 bit
  15554. $count_points = count($patch_array[$i]['points']);
  15555. for ($j=0; $j < $count_points; ++$j) {
  15556. //each point as 16 bit
  15557. $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $coords_min) / ($coords_max - $coords_min)) * $bpcd;
  15558. if ($patch_array[$i]['points'][$j] < 0) {
  15559. $patch_array[$i]['points'][$j] = 0;
  15560. }
  15561. if ($patch_array[$i]['points'][$j] > $bpcd) {
  15562. $patch_array[$i]['points'][$j] = $bpcd;
  15563. }
  15564. $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] / 256));
  15565. $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] % 256));
  15566. }
  15567. $count_cols = count($patch_array[$i]['colors']);
  15568. for ($j=0; $j < $count_cols; ++$j) {
  15569. //each color component as 8 bit
  15570. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['r']);
  15571. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['g']);
  15572. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['b']);
  15573. }
  15574. }
  15575. //paint the gradient
  15576. $this->_out('/Sh'.$n.' sh');
  15577. //restore previous Graphic State
  15578. $this->_out('Q');
  15579. }
  15580. /**
  15581. * Set a rectangular clipping area.
  15582. * @param $x (float) abscissa of the top left corner of the rectangle (or top right corner for RTL mode).
  15583. * @param $y (float) ordinate of the top left corner of the rectangle.
  15584. * @param $w (float) width of the rectangle.
  15585. * @param $h (float) height of the rectangle.
  15586. * @author Andreas Würmser, Nicola Asuni
  15587. * @since 3.1.000 (2008-06-09)
  15588. * @protected
  15589. */
  15590. protected function Clip($x, $y, $w, $h) {
  15591. if ($this->rtl) {
  15592. $x = $this->w - $x - $w;
  15593. }
  15594. //save current Graphic State
  15595. $s = 'q';
  15596. //set clipping area
  15597. $s .= sprintf(' %.2F %.2F %.2F %.2F re W n', $x*$this->k, ($this->h-$y)*$this->k, $w*$this->k, -$h*$this->k);
  15598. //set up transformation matrix for gradient
  15599. $s .= sprintf(' %.3F 0 0 %.3F %.3F %.3F cm', $w*$this->k, $h*$this->k, $x*$this->k, ($this->h-($y+$h))*$this->k);
  15600. $this->_out($s);
  15601. }
  15602. /**
  15603. * Output gradient.
  15604. * @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)
  15605. * @param $coords (array) array of coordinates.
  15606. * @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).
  15607. * @param $background (array) An array of colour components appropriate to the colour space, specifying a single background colour value.
  15608. * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  15609. * @author Nicola Asuni
  15610. * @since 3.1.000 (2008-06-09)
  15611. * @public
  15612. */
  15613. public function Gradient($type, $coords, $stops, $background=array(), $antialias=false) {
  15614. $n = count($this->gradients) + 1;
  15615. $this->gradients[$n] = array();
  15616. $this->gradients[$n]['type'] = $type;
  15617. $this->gradients[$n]['coords'] = $coords;
  15618. $this->gradients[$n]['antialias'] = $antialias;
  15619. $this->gradients[$n]['colors'] = array();
  15620. $this->gradients[$n]['transparency'] = false;
  15621. // color space
  15622. $numcolspace = count($stops[0]['color']);
  15623. $bcolor = array_values($background);
  15624. switch($numcolspace) {
  15625. case 4: { // CMYK
  15626. $this->gradients[$n]['colspace'] = 'DeviceCMYK';
  15627. if (!empty($background)) {
  15628. $this->gradients[$n]['background'] = sprintf('%.3F %.3F %.3F %.3F', $bcolor[0]/100, $bcolor[1]/100, $bcolor[2]/100, $bcolor[3]/100);
  15629. }
  15630. break;
  15631. }
  15632. case 3: { // RGB
  15633. $this->gradients[$n]['colspace'] = 'DeviceRGB';
  15634. if (!empty($background)) {
  15635. $this->gradients[$n]['background'] = sprintf('%.3F %.3F %.3F', $bcolor[0]/255, $bcolor[1]/255, $bcolor[2]/255);
  15636. }
  15637. break;
  15638. }
  15639. case 1: { // Gray scale
  15640. $this->gradients[$n]['colspace'] = 'DeviceGray';
  15641. if (!empty($background)) {
  15642. $this->gradients[$n]['background'] = sprintf('%.3F', $bcolor[0]/255);
  15643. }
  15644. break;
  15645. }
  15646. }
  15647. $num_stops = count($stops);
  15648. $last_stop_id = $num_stops - 1;
  15649. foreach ($stops as $key => $stop) {
  15650. $this->gradients[$n]['colors'][$key] = array();
  15651. // offset represents a location along the gradient vector
  15652. if (isset($stop['offset'])) {
  15653. $this->gradients[$n]['colors'][$key]['offset'] = $stop['offset'];
  15654. } else {
  15655. if ($key == 0) {
  15656. $this->gradients[$n]['colors'][$key]['offset'] = 0;
  15657. } elseif ($key == $last_stop_id) {
  15658. $this->gradients[$n]['colors'][$key]['offset'] = 1;
  15659. } else {
  15660. $offsetstep = (1 - $this->gradients[$n]['colors'][($key - 1)]['offset']) / ($num_stops - $key);
  15661. $this->gradients[$n]['colors'][$key]['offset'] = $this->gradients[$n]['colors'][($key - 1)]['offset'] + $offsetstep;
  15662. }
  15663. }
  15664. if (isset($stop['opacity'])) {
  15665. $this->gradients[$n]['colors'][$key]['opacity'] = $stop['opacity'];
  15666. if ($stop['opacity'] < 1) {
  15667. $this->gradients[$n]['transparency'] = true;
  15668. }
  15669. } else {
  15670. $this->gradients[$n]['colors'][$key]['opacity'] = 1;
  15671. }
  15672. // exponent for the exponential interpolation function
  15673. if (isset($stop['exponent'])) {
  15674. $this->gradients[$n]['colors'][$key]['exponent'] = $stop['exponent'];
  15675. } else {
  15676. $this->gradients[$n]['colors'][$key]['exponent'] = 1;
  15677. }
  15678. // set colors
  15679. $color = array_values($stop['color']);
  15680. switch($numcolspace) {
  15681. case 4: { // CMYK
  15682. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%.3F %.3F %.3F %.3F', $color[0]/100, $color[1]/100, $color[2]/100, $color[3]/100);
  15683. break;
  15684. }
  15685. case 3: { // RGB
  15686. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%.3F %.3F %.3F', $color[0]/255, $color[1]/255, $color[2]/255);
  15687. break;
  15688. }
  15689. case 1: { // Gray scale
  15690. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%.3F', $color[0]/255);
  15691. break;
  15692. }
  15693. }
  15694. }
  15695. if ($this->gradients[$n]['transparency']) {
  15696. // paint luminosity gradient
  15697. $this->_out('/TGS'.$n.' gs');
  15698. }
  15699. //paint the gradient
  15700. $this->_out('/Sh'.$n.' sh');
  15701. //restore previous Graphic State
  15702. $this->_out('Q');
  15703. }
  15704. /**
  15705. * Output gradient shaders.
  15706. * @author Nicola Asuni
  15707. * @since 3.1.000 (2008-06-09)
  15708. * @protected
  15709. */
  15710. function _putshaders() {
  15711. $idt = count($this->gradients); //index for transparency gradients
  15712. foreach ($this->gradients as $id => $grad) {
  15713. if (($grad['type'] == 2) OR ($grad['type'] == 3)) {
  15714. $fc = $this->_newobj();
  15715. $out = '<<';
  15716. $out .= ' /FunctionType 3';
  15717. $out .= ' /Domain [0 1]';
  15718. $functions = '';
  15719. $bounds = '';
  15720. $encode = '';
  15721. $i = 1;
  15722. $num_cols = count($grad['colors']);
  15723. $lastcols = $num_cols - 1;
  15724. for ($i = 1; $i < $num_cols; ++$i) {
  15725. $functions .= ($fc + $i).' 0 R ';
  15726. if ($i < $lastcols) {
  15727. $bounds .= sprintf('%.3F ', $grad['colors'][$i]['offset']);
  15728. }
  15729. $encode .= '0 1 ';
  15730. }
  15731. $out .= ' /Functions ['.trim($functions).']';
  15732. $out .= ' /Bounds ['.trim($bounds).']';
  15733. $out .= ' /Encode ['.trim($encode).']';
  15734. $out .= ' >>';
  15735. $out .= "\n".'endobj';
  15736. $this->_out($out);
  15737. for ($i = 1; $i < $num_cols; ++$i) {
  15738. $this->_newobj();
  15739. $out = '<<';
  15740. $out .= ' /FunctionType 2';
  15741. $out .= ' /Domain [0 1]';
  15742. $out .= ' /C0 ['.$grad['colors'][($i - 1)]['color'].']';
  15743. $out .= ' /C1 ['.$grad['colors'][$i]['color'].']';
  15744. $out .= ' /N '.$grad['colors'][$i]['exponent'];
  15745. $out .= ' >>';
  15746. $out .= "\n".'endobj';
  15747. $this->_out($out);
  15748. }
  15749. // set transparency fuctions
  15750. if ($grad['transparency']) {
  15751. $ft = $this->_newobj();
  15752. $out = '<<';
  15753. $out .= ' /FunctionType 3';
  15754. $out .= ' /Domain [0 1]';
  15755. $functions = '';
  15756. $i = 1;
  15757. $num_cols = count($grad['colors']);
  15758. for ($i = 1; $i < $num_cols; ++$i) {
  15759. $functions .= ($ft + $i).' 0 R ';
  15760. }
  15761. $out .= ' /Functions ['.trim($functions).']';
  15762. $out .= ' /Bounds ['.trim($bounds).']';
  15763. $out .= ' /Encode ['.trim($encode).']';
  15764. $out .= ' >>';
  15765. $out .= "\n".'endobj';
  15766. $this->_out($out);
  15767. for ($i = 1; $i < $num_cols; ++$i) {
  15768. $this->_newobj();
  15769. $out = '<<';
  15770. $out .= ' /FunctionType 2';
  15771. $out .= ' /Domain [0 1]';
  15772. $out .= ' /C0 ['.$grad['colors'][($i - 1)]['opacity'].']';
  15773. $out .= ' /C1 ['.$grad['colors'][$i]['opacity'].']';
  15774. $out .= ' /N '.$grad['colors'][$i]['exponent'];
  15775. $out .= ' >>';
  15776. $out .= "\n".'endobj';
  15777. $this->_out($out);
  15778. }
  15779. }
  15780. }
  15781. // set shading object
  15782. $this->_newobj();
  15783. $out = '<< /ShadingType '.$grad['type'];
  15784. if (isset($grad['colspace'])) {
  15785. $out .= ' /ColorSpace /'.$grad['colspace'];
  15786. } else {
  15787. $out .= ' /ColorSpace /DeviceRGB';
  15788. }
  15789. if (isset($grad['background']) AND !empty($grad['background'])) {
  15790. $out .= ' /Background ['.$grad['background'].']';
  15791. }
  15792. if (isset($grad['antialias']) AND ($grad['antialias'] === true)) {
  15793. $out .= ' /AntiAlias true';
  15794. }
  15795. if ($grad['type'] == 2) {
  15796. $out .= ' '.sprintf('/Coords [%.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]);
  15797. $out .= ' /Domain [0 1]';
  15798. $out .= ' /Function '.$fc.' 0 R';
  15799. $out .= ' /Extend [true true]';
  15800. $out .= ' >>';
  15801. } elseif ($grad['type'] == 3) {
  15802. //x0, y0, r0, x1, y1, r1
  15803. //at this this time radius of inner circle is 0
  15804. $out .= ' '.sprintf('/Coords [%.3F %.3F 0 %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]);
  15805. $out .= ' /Domain [0 1]';
  15806. $out .= ' /Function '.$fc.' 0 R';
  15807. $out .= ' /Extend [true true]';
  15808. $out .= ' >>';
  15809. } elseif ($grad['type'] == 6) {
  15810. $out .= ' /BitsPerCoordinate 16';
  15811. $out .= ' /BitsPerComponent 8';
  15812. $out .= ' /Decode[0 1 0 1 0 1 0 1 0 1]';
  15813. $out .= ' /BitsPerFlag 8';
  15814. $stream = $this->_getrawstream($grad['stream']);
  15815. $out .= ' /Length '.strlen($stream);
  15816. $out .= ' >>';
  15817. $out .= ' stream'."\n".$stream."\n".'endstream';
  15818. }
  15819. $out .= "\n".'endobj';
  15820. $this->_out($out);
  15821. if ($grad['transparency']) {
  15822. $shading_transparency = preg_replace('/\/ColorSpace \/[^\s]+/si', '/ColorSpace /DeviceGray', $out);
  15823. $shading_transparency = preg_replace('/\/Function [0-9]+ /si', '/Function '.$ft.' ', $shading_transparency);
  15824. }
  15825. $this->gradients[$id]['id'] = $this->n;
  15826. // set pattern object
  15827. $this->_newobj();
  15828. $out = '<< /Type /Pattern /PatternType 2';
  15829. $out .= ' /Shading '.$this->gradients[$id]['id'].' 0 R';
  15830. $out .= ' >>';
  15831. $out .= "\n".'endobj';
  15832. $this->_out($out);
  15833. $this->gradients[$id]['pattern'] = $this->n;
  15834. // set shading and pattern for transparency mask
  15835. if ($grad['transparency']) {
  15836. // luminosity pattern
  15837. $idgs = $id + $idt;
  15838. $this->_newobj();
  15839. $this->_out($shading_transparency);
  15840. $this->gradients[$idgs]['id'] = $this->n;
  15841. $this->_newobj();
  15842. $out = '<< /Type /Pattern /PatternType 2';
  15843. $out .= ' /Shading '.$this->gradients[$idgs]['id'].' 0 R';
  15844. $out .= ' >>';
  15845. $out .= "\n".'endobj';
  15846. $this->_out($out);
  15847. $this->gradients[$idgs]['pattern'] = $this->n;
  15848. // luminosity XObject
  15849. $oid = $this->_newobj();
  15850. $this->xobjects['LX'.$oid] = array('n' => $oid);
  15851. $filter = '';
  15852. $stream = 'q /a0 gs /Pattern cs /p'.$idgs.' scn 0 0 '.$this->wPt.' '.$this->hPt.' re f Q';
  15853. if ($this->compress) {
  15854. $filter = ' /Filter /FlateDecode';
  15855. $stream = gzcompress($stream);
  15856. }
  15857. $stream = $this->_getrawstream($stream);
  15858. $out = '<< /Type /XObject /Subtype /Form /FormType 1'.$filter;
  15859. $out .= ' /Length '.strlen($stream);
  15860. $rect = sprintf('%.2F %.2F', $this->wPt, $this->hPt);
  15861. $out .= ' /BBox [0 0 '.$rect.']';
  15862. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceGray >>';
  15863. $out .= ' /Resources <<';
  15864. $out .= ' /ExtGState << /a0 << /ca 1 /CA 1 >> >>';
  15865. $out .= ' /Pattern << /p'.$idgs.' '.$this->gradients[$idgs]['pattern'].' 0 R >>';
  15866. $out .= ' >>';
  15867. $out .= ' >> ';
  15868. $out .= ' stream'."\n".$stream."\n".'endstream';
  15869. $out .= "\n".'endobj';
  15870. $this->_out($out);
  15871. // SMask
  15872. $this->_newobj();
  15873. $out = '<< /Type /Mask /S /Luminosity /G '.($this->n - 1).' 0 R >>'."\n".'endobj';
  15874. $this->_out($out);
  15875. // ExtGState
  15876. $this->_newobj();
  15877. $out = '<< /Type /ExtGState /SMask '.($this->n - 1).' 0 R /AIS false >>'."\n".'endobj';
  15878. $this->_out($out);
  15879. $this->extgstates[] = array('n' => $this->n, 'name' => 'TGS'.$id);
  15880. }
  15881. }
  15882. }
  15883. /**
  15884. * Draw the sector of a circle.
  15885. * It can be used for instance to render pie charts.
  15886. * @param $xc (float) abscissa of the center.
  15887. * @param $yc (float) ordinate of the center.
  15888. * @param $r (float) radius.
  15889. * @param $a (float) start angle (in degrees).
  15890. * @param $b (float) end angle (in degrees).
  15891. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  15892. * @param $cw: (float) indicates whether to go clockwise (default: true).
  15893. * @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.
  15894. * @author Maxime Delorme, Nicola Asuni
  15895. * @since 3.1.000 (2008-06-09)
  15896. * @public
  15897. */
  15898. public function PieSector($xc, $yc, $r, $a, $b, $style='FD', $cw=true, $o=90) {
  15899. $this->PieSectorXY($xc, $yc, $r, $r, $a, $b, $style, $cw, $o);
  15900. }
  15901. /**
  15902. * Draw the sector of an ellipse.
  15903. * It can be used for instance to render pie charts.
  15904. * @param $xc (float) abscissa of the center.
  15905. * @param $yc (float) ordinate of the center.
  15906. * @param $rx (float) the x-axis radius.
  15907. * @param $ry (float) the y-axis radius.
  15908. * @param $a (float) start angle (in degrees).
  15909. * @param $b (float) end angle (in degrees).
  15910. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  15911. * @param $cw: (float) indicates whether to go clockwise.
  15912. * @param $o: (float) origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock).
  15913. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of arc.
  15914. * @author Maxime Delorme, Nicola Asuni
  15915. * @since 3.1.000 (2008-06-09)
  15916. * @public
  15917. */
  15918. public function PieSectorXY($xc, $yc, $rx, $ry, $a, $b, $style='FD', $cw=false, $o=0, $nc=2) {
  15919. if ($this->rtl) {
  15920. $xc = $this->w - $xc;
  15921. }
  15922. $op = $this->getPathPaintOperator($style);
  15923. if ($op == 'f') {
  15924. $line_style = array();
  15925. }
  15926. if ($cw) {
  15927. $d = $b;
  15928. $b = 360 - $a + $o;
  15929. $a = 360 - $d + $o;
  15930. } else {
  15931. $b += $o;
  15932. $a += $o;
  15933. }
  15934. $this->_outellipticalarc($xc, $yc, $rx, $ry, 0, $a, $b, true, $nc);
  15935. $this->_out($op);
  15936. }
  15937. /**
  15938. * Embed vector-based Adobe Illustrator (AI) or AI-compatible EPS files.
  15939. * NOTE: EPS is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  15940. * Only vector drawing is supported, not text or bitmap.
  15941. * 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).
  15942. * @param $file (string) Name of the file containing the image or a '@' character followed by the EPS/AI data string.
  15943. * @param $x (float) Abscissa of the upper-left corner.
  15944. * @param $y (float) Ordinate of the upper-left corner.
  15945. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  15946. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  15947. * @param $link (mixed) URL or identifier returned by AddLink().
  15948. * @param $useBoundingBox (boolean) specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true.
  15949. * @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>
  15950. * @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>
  15951. * @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)))
  15952. * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
  15953. * @param $fixoutvals (boolean) if true remove values outside the bounding box.
  15954. * @author Valentin Schmidt, Nicola Asuni
  15955. * @since 3.1.000 (2008-06-09)
  15956. * @public
  15957. */
  15958. public function ImageEps($file, $x='', $y='', $w=0, $h=0, $link='', $useBoundingBox=true, $align='', $palign='', $border=0, $fitonpage=false, $fixoutvals=false) {
  15959. if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
  15960. // convert EPS to raster image using GD or ImageMagick libraries
  15961. return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
  15962. }
  15963. if ($x === '') {
  15964. $x = $this->x;
  15965. }
  15966. if ($y === '') {
  15967. $y = $this->y;
  15968. }
  15969. // check page for no-write regions and adapt page margins if necessary
  15970. $this->checkPageRegions($h, $x, $y);
  15971. $k = $this->k;
  15972. if ($file{0} === '@') { // image from string
  15973. $data = substr($file, 1);
  15974. } else { // EPS/AI file
  15975. $data = file_get_contents($file);
  15976. }
  15977. if ($data === false) {
  15978. $this->Error('EPS file not found: '.$file);
  15979. }
  15980. $regs = array();
  15981. // EPS/AI compatibility check (only checks files created by Adobe Illustrator!)
  15982. preg_match("/%%Creator:([^\r\n]+)/", $data, $regs); # find Creator
  15983. if (count($regs) > 1) {
  15984. $version_str = trim($regs[1]); # e.g. "Adobe Illustrator(R) 8.0"
  15985. if (strpos($version_str, 'Adobe Illustrator') !== false) {
  15986. $versexp = explode(' ', $version_str);
  15987. $version = (float)array_pop($versexp);
  15988. if ($version >= 9) {
  15989. $this->Error('This version of Adobe Illustrator file is not supported: '.$file);
  15990. }
  15991. }
  15992. }
  15993. // strip binary bytes in front of PS-header
  15994. $start = strpos($data, '%!PS-Adobe');
  15995. if ($start > 0) {
  15996. $data = substr($data, $start);
  15997. }
  15998. // find BoundingBox params
  15999. preg_match("/%%BoundingBox:([^\r\n]+)/", $data, $regs);
  16000. if (count($regs) > 1) {
  16001. list($x1, $y1, $x2, $y2) = explode(' ', trim($regs[1]));
  16002. } else {
  16003. $this->Error('No BoundingBox found in EPS/AI file: '.$file);
  16004. }
  16005. $start = strpos($data, '%%EndSetup');
  16006. if ($start === false) {
  16007. $start = strpos($data, '%%EndProlog');
  16008. }
  16009. if ($start === false) {
  16010. $start = strpos($data, '%%BoundingBox');
  16011. }
  16012. $data = substr($data, $start);
  16013. $end = strpos($data, '%%PageTrailer');
  16014. if ($end===false) {
  16015. $end = strpos($data, 'showpage');
  16016. }
  16017. if ($end) {
  16018. $data = substr($data, 0, $end);
  16019. }
  16020. // calculate image width and height on document
  16021. if (($w <= 0) AND ($h <= 0)) {
  16022. $w = ($x2 - $x1) / $k;
  16023. $h = ($y2 - $y1) / $k;
  16024. } elseif ($w <= 0) {
  16025. $w = ($x2-$x1) / $k * ($h / (($y2 - $y1) / $k));
  16026. } elseif ($h <= 0) {
  16027. $h = ($y2 - $y1) / $k * ($w / (($x2 - $x1) / $k));
  16028. }
  16029. // fit the image on available space
  16030. $this->fitBlock($w, $h, $x, $y, $fitonpage);
  16031. if ($this->rasterize_vector_images) {
  16032. // convert EPS to raster image using GD or ImageMagick libraries
  16033. return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
  16034. }
  16035. // set scaling factors
  16036. $scale_x = $w / (($x2 - $x1) / $k);
  16037. $scale_y = $h / (($y2 - $y1) / $k);
  16038. // set alignment
  16039. $this->img_rb_y = $y + $h;
  16040. // set alignment
  16041. if ($this->rtl) {
  16042. if ($palign == 'L') {
  16043. $ximg = $this->lMargin;
  16044. } elseif ($palign == 'C') {
  16045. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  16046. } elseif ($palign == 'R') {
  16047. $ximg = $this->w - $this->rMargin - $w;
  16048. } else {
  16049. $ximg = $x - $w;
  16050. }
  16051. $this->img_rb_x = $ximg;
  16052. } else {
  16053. if ($palign == 'L') {
  16054. $ximg = $this->lMargin;
  16055. } elseif ($palign == 'C') {
  16056. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  16057. } elseif ($palign == 'R') {
  16058. $ximg = $this->w - $this->rMargin - $w;
  16059. } else {
  16060. $ximg = $x;
  16061. }
  16062. $this->img_rb_x = $ximg + $w;
  16063. }
  16064. if ($useBoundingBox) {
  16065. $dx = $ximg * $k - $x1;
  16066. $dy = $y * $k - $y1;
  16067. } else {
  16068. $dx = $ximg * $k;
  16069. $dy = $y * $k;
  16070. }
  16071. // save the current graphic state
  16072. $this->_out('q'.$this->epsmarker);
  16073. // translate
  16074. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', 1, 0, 0, 1, $dx, $dy + ($this->hPt - (2 * $y * $k) - ($y2 - $y1))));
  16075. // scale
  16076. if (isset($scale_x)) {
  16077. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y)));
  16078. }
  16079. // handle pc/unix/mac line endings
  16080. $lines = preg_split('/[\r\n]+/si', $data, -1, PREG_SPLIT_NO_EMPTY);
  16081. $u=0;
  16082. $cnt = count($lines);
  16083. for ($i=0; $i < $cnt; ++$i) {
  16084. $line = $lines[$i];
  16085. if (($line == '') OR ($line{0} == '%')) {
  16086. continue;
  16087. }
  16088. $len = strlen($line);
  16089. // check for spot color names
  16090. $color_name = '';
  16091. if (strcasecmp('x', substr(trim($line), -1)) == 0) {
  16092. if (preg_match('/\([^\)]*\)/', $line, $matches) > 0) {
  16093. // extract spot color name
  16094. $color_name = $matches[0];
  16095. // remove color name from string
  16096. $line = str_replace(' '.$color_name, '', $line);
  16097. // remove pharentesis from color name
  16098. $color_name = substr($color_name, 1, -1);
  16099. }
  16100. }
  16101. $chunks = explode(' ', $line);
  16102. $cmd = trim(array_pop($chunks));
  16103. // RGB
  16104. if (($cmd == 'Xa') OR ($cmd == 'XA')) {
  16105. $b = array_pop($chunks);
  16106. $g = array_pop($chunks);
  16107. $r = array_pop($chunks);
  16108. $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!
  16109. continue;
  16110. }
  16111. $skip = false;
  16112. if ($fixoutvals) {
  16113. // check for values outside the bounding box
  16114. switch ($cmd) {
  16115. case 'm':
  16116. case 'l':
  16117. case 'L': {
  16118. // skip values outside bounding box
  16119. foreach ($chunks as $key => $val) {
  16120. if ((($key % 2) == 0) AND (($val < $x1) OR ($val > $x2))) {
  16121. $skip = true;
  16122. } elseif ((($key % 2) != 0) AND (($val < $y1) OR ($val > $y2))) {
  16123. $skip = true;
  16124. }
  16125. }
  16126. }
  16127. }
  16128. }
  16129. switch ($cmd) {
  16130. case 'm':
  16131. case 'l':
  16132. case 'v':
  16133. case 'y':
  16134. case 'c':
  16135. case 'k':
  16136. case 'K':
  16137. case 'g':
  16138. case 'G':
  16139. case 's':
  16140. case 'S':
  16141. case 'J':
  16142. case 'j':
  16143. case 'w':
  16144. case 'M':
  16145. case 'd':
  16146. case 'n': {
  16147. if ($skip) {
  16148. break;
  16149. }
  16150. $this->_out($line);
  16151. break;
  16152. }
  16153. case 'x': {// custom fill color
  16154. if (empty($color_name)) {
  16155. // CMYK color
  16156. list($col_c, $col_m, $col_y, $col_k) = $chunks;
  16157. $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' k');
  16158. } else {
  16159. // Spot Color (CMYK + tint)
  16160. list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
  16161. $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
  16162. $color_cmd = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$color_name]['i'], (1 - $col_t));
  16163. $this->_out($color_cmd);
  16164. }
  16165. break;
  16166. }
  16167. case 'X': { // custom stroke color
  16168. if (empty($color_name)) {
  16169. // CMYK color
  16170. list($col_c, $col_m, $col_y, $col_k) = $chunks;
  16171. $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' K');
  16172. } else {
  16173. // Spot Color (CMYK + tint)
  16174. list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
  16175. $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
  16176. $color_cmd = sprintf('/CS%d CS %.3F SCN', $this->spot_colors[$color_name]['i'], (1 - $col_t));
  16177. $this->_out($color_cmd);
  16178. }
  16179. break;
  16180. }
  16181. case 'Y':
  16182. case 'N':
  16183. case 'V':
  16184. case 'L':
  16185. case 'C': {
  16186. if ($skip) {
  16187. break;
  16188. }
  16189. $line{$len-1} = strtolower($cmd);
  16190. $this->_out($line);
  16191. break;
  16192. }
  16193. case 'b':
  16194. case 'B': {
  16195. $this->_out($cmd . '*');
  16196. break;
  16197. }
  16198. case 'f':
  16199. case 'F': {
  16200. if ($u > 0) {
  16201. $isU = false;
  16202. $max = min(($i + 5), $cnt);
  16203. for ($j = ($i + 1); $j < $max; ++$j) {
  16204. $isU = ($isU OR (($lines[$j] == 'U') OR ($lines[$j] == '*U')));
  16205. }
  16206. if ($isU) {
  16207. $this->_out('f*');
  16208. }
  16209. } else {
  16210. $this->_out('f*');
  16211. }
  16212. break;
  16213. }
  16214. case '*u': {
  16215. ++$u;
  16216. break;
  16217. }
  16218. case '*U': {
  16219. --$u;
  16220. break;
  16221. }
  16222. }
  16223. }
  16224. // restore previous graphic state
  16225. $this->_out($this->epsmarker.'Q');
  16226. if (!empty($border)) {
  16227. $bx = $this->x;
  16228. $by = $this->y;
  16229. $this->x = $ximg;
  16230. if ($this->rtl) {
  16231. $this->x += $w;
  16232. }
  16233. $this->y = $y;
  16234. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  16235. $this->x = $bx;
  16236. $this->y = $by;
  16237. }
  16238. if ($link) {
  16239. $this->Link($ximg, $y, $w, $h, $link, 0);
  16240. }
  16241. // set pointer to align the next text/objects
  16242. switch($align) {
  16243. case 'T':{
  16244. $this->y = $y;
  16245. $this->x = $this->img_rb_x;
  16246. break;
  16247. }
  16248. case 'M':{
  16249. $this->y = $y + round($h/2);
  16250. $this->x = $this->img_rb_x;
  16251. break;
  16252. }
  16253. case 'B':{
  16254. $this->y = $this->img_rb_y;
  16255. $this->x = $this->img_rb_x;
  16256. break;
  16257. }
  16258. case 'N':{
  16259. $this->SetY($this->img_rb_y);
  16260. break;
  16261. }
  16262. default:{
  16263. break;
  16264. }
  16265. }
  16266. $this->endlinex = $this->img_rb_x;
  16267. }
  16268. /**
  16269. * Set document barcode.
  16270. * @param $bc (string) barcode
  16271. * @public
  16272. */
  16273. public function setBarcode($bc='') {
  16274. $this->barcode = $bc;
  16275. }
  16276. /**
  16277. * Get current barcode.
  16278. * @return string
  16279. * @public
  16280. * @since 4.0.012 (2008-07-24)
  16281. */
  16282. public function getBarcode() {
  16283. return $this->barcode;
  16284. }
  16285. /**
  16286. * Print a Linear Barcode.
  16287. * @param $code (string) code to print
  16288. * @param $type (string) type of barcode (see barcodes.php for supported formats).
  16289. * @param $x (int) x position in user units (empty string = current x position)
  16290. * @param $y (int) y position in user units (empty string = current y position)
  16291. * @param $w (int) width in user units (empty string = remaining page width)
  16292. * @param $h (int) height in user units (empty string = remaining page height)
  16293. * @param $xres (float) width of the smallest bar in user units (empty string = default value = 0.4mm)
  16294. * @param $style (array) array of options:<ul>
  16295. * <li>boolean $style['border'] if true prints a border</li>
  16296. * <li>int $style['padding'] padding to leave around the barcode in user units (set to 'auto' for automatic padding)</li>
  16297. * <li>int $style['hpadding'] horizontal padding in user units (set to 'auto' for automatic padding)</li>
  16298. * <li>int $style['vpadding'] vertical padding in user units (set to 'auto' for automatic padding)</li>
  16299. * <li>array $style['fgcolor'] color array for bars and text</li>
  16300. * <li>mixed $style['bgcolor'] color array for background (set to false for transparent)</li>
  16301. * <li>boolean $style['text'] if true prints text below the barcode</li>
  16302. * <li>string $style['label'] override default label</li>
  16303. * <li>string $style['font'] font name for text</li><li>int $style['fontsize'] font size for text</li>
  16304. * <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>
  16305. * <li>string $style['position'] horizontal position of the containing barcode cell on the page: L = left margin; C = center; R = right margin.</li>
  16306. * <li>string $style['align'] horizontal position of the barcode on the containing rectangle: L = left; C = center; R = right.</li>
  16307. * <li>string $style['stretch'] if true stretch the barcode to best fit the available width, otherwise uses $xres resolution for a single bar.</li>
  16308. * <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>
  16309. * <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>
  16310. * @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>
  16311. * @author Nicola Asuni
  16312. * @since 3.1.000 (2008-06-09)
  16313. * @public
  16314. */
  16315. public function write1DBarcode($code, $type, $x='', $y='', $w='', $h='', $xres='', $style='', $align='') {
  16316. if ($this->empty_string(trim($code))) {
  16317. return;
  16318. }
  16319. require_once(dirname(__FILE__).'/barcodes.php');
  16320. // save current graphic settings
  16321. $gvars = $this->getGraphicVars();
  16322. // create new barcode object
  16323. $barcodeobj = new TCPDFBarcode($code, $type);
  16324. $arrcode = $barcodeobj->getBarcodeArray();
  16325. if ($arrcode === false) {
  16326. $this->Error('Error in 1D barcode string');
  16327. }
  16328. // set default values
  16329. if (!isset($style['position'])) {
  16330. $style['position'] = '';
  16331. } elseif ($style['position'] == 'S') {
  16332. // keep this for backward compatibility
  16333. $style['position'] = '';
  16334. $style['stretch'] = true;
  16335. }
  16336. if (!isset($style['fitwidth'])) {
  16337. if (!isset($style['stretch'])) {
  16338. $style['fitwidth'] = true;
  16339. } else {
  16340. $style['fitwidth'] = false;
  16341. }
  16342. }
  16343. if ($style['fitwidth']) {
  16344. // disable stretch
  16345. $style['stretch'] = false;
  16346. }
  16347. if (!isset($style['stretch'])) {
  16348. if (($w === '') OR ($w <= 0)) {
  16349. $style['stretch'] = false;
  16350. } else {
  16351. $style['stretch'] = true;
  16352. }
  16353. }
  16354. if (!isset($style['fgcolor'])) {
  16355. $style['fgcolor'] = array(0,0,0); // default black
  16356. }
  16357. if (!isset($style['bgcolor'])) {
  16358. $style['bgcolor'] = false; // default transparent
  16359. }
  16360. if (!isset($style['border'])) {
  16361. $style['border'] = false;
  16362. }
  16363. $fontsize = 0;
  16364. if (!isset($style['text'])) {
  16365. $style['text'] = false;
  16366. }
  16367. if ($style['text'] AND isset($style['font'])) {
  16368. if (isset($style['fontsize'])) {
  16369. $fontsize = $style['fontsize'];
  16370. }
  16371. $this->SetFont($style['font'], '', $fontsize);
  16372. }
  16373. if (!isset($style['stretchtext'])) {
  16374. $style['stretchtext'] = 4;
  16375. }
  16376. if ($x === '') {
  16377. $x = $this->x;
  16378. }
  16379. if ($y === '') {
  16380. $y = $this->y;
  16381. }
  16382. // check page for no-write regions and adapt page margins if necessary
  16383. $this->checkPageRegions($h, $x, $y);
  16384. if (($w === '') OR ($w <= 0)) {
  16385. if ($this->rtl) {
  16386. $w = $x - $this->lMargin;
  16387. } else {
  16388. $w = $this->w - $this->rMargin - $x;
  16389. }
  16390. }
  16391. // padding
  16392. if (!isset($style['padding'])) {
  16393. $padding = 0;
  16394. } elseif ($style['padding'] === 'auto') {
  16395. $padding = 10 * ($w / ($arrcode['maxw'] + 20));
  16396. } else {
  16397. $padding = floatval($style['padding']);
  16398. }
  16399. // horizontal padding
  16400. if (!isset($style['hpadding'])) {
  16401. $hpadding = $padding;
  16402. } elseif ($style['hpadding'] === 'auto') {
  16403. $hpadding = 10 * ($w / ($arrcode['maxw'] + 20));
  16404. } else {
  16405. $hpadding = floatval($style['hpadding']);
  16406. }
  16407. // vertical padding
  16408. if (!isset($style['vpadding'])) {
  16409. $vpadding = $padding;
  16410. } elseif ($style['vpadding'] === 'auto') {
  16411. $vpadding = ($hpadding / 2);
  16412. } else {
  16413. $vpadding = floatval($style['vpadding']);
  16414. }
  16415. // calculate xres (single bar width)
  16416. $max_xres = ($w - (2 * $hpadding)) / $arrcode['maxw'];
  16417. if ($style['stretch']) {
  16418. $xres = $max_xres;
  16419. } else {
  16420. if ($this->empty_string($xres)) {
  16421. $xres = (0.141 * $this->k); // default bar width = 0.4 mm
  16422. }
  16423. if ($xres > $max_xres) {
  16424. // correct xres to fit on $w
  16425. $xres = $max_xres;
  16426. }
  16427. if ((isset($style['padding']) AND ($style['padding'] === 'auto'))
  16428. OR (isset($style['hpadding']) AND ($style['hpadding'] === 'auto'))) {
  16429. $hpadding = 10 * $xres;
  16430. if (isset($style['vpadding']) AND ($style['vpadding'] === 'auto')) {
  16431. $vpadding = ($hpadding / 2);
  16432. }
  16433. }
  16434. }
  16435. if ($style['fitwidth']) {
  16436. $wold = $w;
  16437. $w = (($arrcode['maxw'] * $xres) + (2 * $hpadding));
  16438. if (isset($style['cellfitalign'])) {
  16439. switch ($style['cellfitalign']) {
  16440. case 'L': {
  16441. if ($this->rtl) {
  16442. $x -= ($wold - $w);
  16443. }
  16444. break;
  16445. }
  16446. case 'R': {
  16447. if (!$this->rtl) {
  16448. $x += ($wold - $w);
  16449. }
  16450. break;
  16451. }
  16452. case 'C': {
  16453. if ($this->rtl) {
  16454. $x -= (($wold - $w) / 2);
  16455. } else {
  16456. $x += (($wold - $w) / 2);
  16457. }
  16458. break;
  16459. }
  16460. default : {
  16461. break;
  16462. }
  16463. }
  16464. }
  16465. }
  16466. $text_height = ($this->cell_height_ratio * $fontsize / $this->k);
  16467. // height
  16468. if (($h === '') OR ($h <= 0)) {
  16469. // set default height
  16470. $h = (($arrcode['maxw'] * $xres) / 3) + (2 * $vpadding) + $text_height;
  16471. }
  16472. $barh = $h - $text_height - (2 * $vpadding);
  16473. if ($barh <=0) {
  16474. // try to reduce font or padding to fit barcode on available height
  16475. if ($text_height > $h) {
  16476. $fontsize = (($h * $this->k) / (4 * $this->cell_height_ratio));
  16477. $text_height = ($this->cell_height_ratio * $fontsize / $this->k);
  16478. $this->SetFont($style['font'], '', $fontsize);
  16479. }
  16480. if ($vpadding > 0) {
  16481. $vpadding = (($h - $text_height) / 4);
  16482. }
  16483. $barh = $h - $text_height - (2 * $vpadding);
  16484. }
  16485. // fit the barcode on available space
  16486. $this->fitBlock($w, $h, $x, $y, false);
  16487. // set alignment
  16488. $this->img_rb_y = $y + $h;
  16489. // set alignment
  16490. if ($this->rtl) {
  16491. if ($style['position'] == 'L') {
  16492. $xpos = $this->lMargin;
  16493. } elseif ($style['position'] == 'C') {
  16494. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  16495. } elseif ($style['position'] == 'R') {
  16496. $xpos = $this->w - $this->rMargin - $w;
  16497. } else {
  16498. $xpos = $x - $w;
  16499. }
  16500. $this->img_rb_x = $xpos;
  16501. } else {
  16502. if ($style['position'] == 'L') {
  16503. $xpos = $this->lMargin;
  16504. } elseif ($style['position'] == 'C') {
  16505. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  16506. } elseif ($style['position'] == 'R') {
  16507. $xpos = $this->w - $this->rMargin - $w;
  16508. } else {
  16509. $xpos = $x;
  16510. }
  16511. $this->img_rb_x = $xpos + $w;
  16512. }
  16513. $xpos_rect = $xpos;
  16514. if (!isset($style['align'])) {
  16515. $style['align'] = 'C';
  16516. }
  16517. switch ($style['align']) {
  16518. case 'L': {
  16519. $xpos = $xpos_rect + $hpadding;
  16520. break;
  16521. }
  16522. case 'R': {
  16523. $xpos = $xpos_rect + ($w - ($arrcode['maxw'] * $xres)) - $hpadding;
  16524. break;
  16525. }
  16526. case 'C':
  16527. default : {
  16528. $xpos = $xpos_rect + (($w - ($arrcode['maxw'] * $xres)) / 2);
  16529. break;
  16530. }
  16531. }
  16532. $xpos_text = $xpos;
  16533. // barcode is always printed in LTR direction
  16534. $tempRTL = $this->rtl;
  16535. $this->rtl = false;
  16536. // print background color
  16537. if ($style['bgcolor']) {
  16538. $this->Rect($xpos_rect, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  16539. } elseif ($style['border']) {
  16540. $this->Rect($xpos_rect, $y, $w, $h, 'D');
  16541. }
  16542. // set foreground color
  16543. $this->SetDrawColorArray($style['fgcolor']);
  16544. $this->SetTextColorArray($style['fgcolor']);
  16545. // print bars
  16546. foreach ($arrcode['bcode'] as $k => $v) {
  16547. $bw = ($v['w'] * $xres);
  16548. if ($v['t']) {
  16549. // draw a vertical bar
  16550. $ypos = $y + $vpadding + ($v['p'] * $barh / $arrcode['maxh']);
  16551. $this->Rect($xpos, $ypos, $bw, ($v['h'] * $barh / $arrcode['maxh']), 'F', array(), $style['fgcolor']);
  16552. }
  16553. $xpos += $bw;
  16554. }
  16555. // print text
  16556. if ($style['text']) {
  16557. if (isset($style['label']) AND !$this->empty_string($style['label'])) {
  16558. $label = $style['label'];
  16559. } else {
  16560. $label = $code;
  16561. }
  16562. $txtwidth = ($arrcode['maxw'] * $xres);
  16563. if ($this->GetStringWidth($label) > $txtwidth) {
  16564. $style['stretchtext'] = 2;
  16565. }
  16566. // print text
  16567. $this->x = $xpos_text;
  16568. $this->y = $y + $vpadding + $barh;
  16569. $cellpadding = $this->cell_padding;
  16570. $this->SetCellPadding(0);
  16571. $this->Cell($txtwidth, '', $label, 0, 0, 'C', 0, '', $style['stretchtext'], false, 'T', 'T');
  16572. $this->cell_padding = $cellpadding;
  16573. }
  16574. // restore original direction
  16575. $this->rtl = $tempRTL;
  16576. // restore previous settings
  16577. $this->setGraphicVars($gvars);
  16578. // set pointer to align the next text/objects
  16579. switch($align) {
  16580. case 'T':{
  16581. $this->y = $y;
  16582. $this->x = $this->img_rb_x;
  16583. break;
  16584. }
  16585. case 'M':{
  16586. $this->y = $y + round($h / 2);
  16587. $this->x = $this->img_rb_x;
  16588. break;
  16589. }
  16590. case 'B':{
  16591. $this->y = $this->img_rb_y;
  16592. $this->x = $this->img_rb_x;
  16593. break;
  16594. }
  16595. case 'N':{
  16596. $this->SetY($this->img_rb_y);
  16597. break;
  16598. }
  16599. default:{
  16600. break;
  16601. }
  16602. }
  16603. $this->endlinex = $this->img_rb_x;
  16604. }
  16605. /**
  16606. * This function is DEPRECATED, please use the new write1DBarcode() function.
  16607. * @param $x (int) x position in user units
  16608. * @param $y (int) y position in user units
  16609. * @param $w (int) width in user units
  16610. * @param $h (int) height position in user units
  16611. * @param $type (string) type of barcode
  16612. * @param $style (string) barcode style
  16613. * @param $font (string) font for text
  16614. * @param $xres (int) x resolution
  16615. * @param $code (string) code to print
  16616. * @deprecated deprecated since version 3.1.000 (2008-06-10)
  16617. * @public
  16618. * @see write1DBarcode()
  16619. */
  16620. public function writeBarcode($x, $y, $w, $h, $type, $style, $font, $xres, $code) {
  16621. // convert old settings for the new write1DBarcode() function.
  16622. $xres = 1 / $xres;
  16623. $newstyle = array(
  16624. 'position' => '',
  16625. 'align' => '',
  16626. 'stretch' => false,
  16627. 'fitwidth' => false,
  16628. 'cellfitalign' => '',
  16629. 'border' => false,
  16630. 'padding' => 0,
  16631. 'fgcolor' => array(0,0,0),
  16632. 'bgcolor' => false,
  16633. 'text' => true,
  16634. 'font' => $font,
  16635. 'fontsize' => 8,
  16636. 'stretchtext' => 4
  16637. );
  16638. if ($style & 1) {
  16639. $newstyle['border'] = true;
  16640. }
  16641. if ($style & 2) {
  16642. $newstyle['bgcolor'] = false;
  16643. }
  16644. if ($style & 4) {
  16645. $newstyle['position'] = 'C';
  16646. } elseif ($style & 8) {
  16647. $newstyle['position'] = 'L';
  16648. } elseif ($style & 16) {
  16649. $newstyle['position'] = 'R';
  16650. }
  16651. if ($style & 128) {
  16652. $newstyle['text'] = true;
  16653. }
  16654. if ($style & 256) {
  16655. $newstyle['stretchtext'] = 4;
  16656. }
  16657. $this->write1DBarcode($code, $type, $x, $y, $w, $h, $xres, $newstyle, '');
  16658. }
  16659. /**
  16660. * Print 2D Barcode.
  16661. * @param $code (string) code to print
  16662. * @param $type (string) type of barcode (see 2dbarcodes.php for supported formats).
  16663. * @param $x (int) x position in user units
  16664. * @param $y (int) y position in user units
  16665. * @param $w (int) width in user units
  16666. * @param $h (int) height in user units
  16667. * @param $style (array) array of options:<ul>
  16668. * <li>boolean $style['border'] if true prints a border around the barcode</li>
  16669. * <li>int $style['padding'] padding to leave around the barcode in barcode units (set to 'auto' for automatic padding)</li>
  16670. * <li>int $style['hpadding'] horizontal padding in barcode units (set to 'auto' for automatic padding)</li>
  16671. * <li>int $style['vpadding'] vertical padding in barcode units (set to 'auto' for automatic padding)</li>
  16672. * <li>int $style['module_width'] width of a single module in points</li>
  16673. * <li>int $style['module_height'] height of a single module in points</li>
  16674. * <li>array $style['fgcolor'] color array for bars and text</li>
  16675. * <li>mixed $style['bgcolor'] color array for background or false for transparent</li>
  16676. * <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>
  16677. * <li>$style['module_height'] height of a single module in points</li></ul>
  16678. * @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>
  16679. * @param $distort (boolean) if true distort the barcode to fit width and height, otherwise preserve aspect ratio
  16680. * @author Nicola Asuni
  16681. * @since 4.5.037 (2009-04-07)
  16682. * @public
  16683. */
  16684. public function write2DBarcode($code, $type, $x='', $y='', $w='', $h='', $style='', $align='', $distort=false) {
  16685. if ($this->empty_string(trim($code))) {
  16686. return;
  16687. }
  16688. require_once(dirname(__FILE__).'/2dbarcodes.php');
  16689. // save current graphic settings
  16690. $gvars = $this->getGraphicVars();
  16691. // create new barcode object
  16692. $barcodeobj = new TCPDF2DBarcode($code, $type);
  16693. $arrcode = $barcodeobj->getBarcodeArray();
  16694. if (($arrcode === false) OR empty($arrcode)) {
  16695. $this->Error('Error in 2D barcode string');
  16696. }
  16697. // set default values
  16698. if (!isset($style['position'])) {
  16699. $style['position'] = '';
  16700. }
  16701. if (!isset($style['fgcolor'])) {
  16702. $style['fgcolor'] = array(0,0,0); // default black
  16703. }
  16704. if (!isset($style['bgcolor'])) {
  16705. $style['bgcolor'] = false; // default transparent
  16706. }
  16707. if (!isset($style['border'])) {
  16708. $style['border'] = false;
  16709. }
  16710. // padding
  16711. if (!isset($style['padding'])) {
  16712. $style['padding'] = 0;
  16713. } elseif ($style['padding'] === 'auto') {
  16714. $style['padding'] = 4;
  16715. }
  16716. if (!isset($style['hpadding'])) {
  16717. $style['hpadding'] = $style['padding'];
  16718. } elseif ($style['hpadding'] === 'auto') {
  16719. $style['hpadding'] = 4;
  16720. }
  16721. if (!isset($style['vpadding'])) {
  16722. $style['vpadding'] = $style['padding'];
  16723. } elseif ($style['vpadding'] === 'auto') {
  16724. $style['vpadding'] = 4;
  16725. }
  16726. // cell (module) dimension
  16727. if (!isset($style['module_width'])) {
  16728. $style['module_width'] = 1; // width of a single module in points
  16729. }
  16730. if (!isset($style['module_height'])) {
  16731. $style['module_height'] = 1; // height of a single module in points
  16732. }
  16733. if ($x === '') {
  16734. $x = $this->x;
  16735. }
  16736. if ($y === '') {
  16737. $y = $this->y;
  16738. }
  16739. // check page for no-write regions and adapt page margins if necessary
  16740. $this->checkPageRegions($h, $x, $y);
  16741. // number of barcode columns and rows
  16742. $rows = $arrcode['num_rows'];
  16743. $cols = $arrcode['num_cols'];
  16744. // module width and height
  16745. $mw = $style['module_width'];
  16746. $mh = $style['module_height'];
  16747. // get max dimensions
  16748. if ($this->rtl) {
  16749. $maxw = $x - $this->lMargin;
  16750. } else {
  16751. $maxw = $this->w - $this->rMargin - $x;
  16752. }
  16753. $maxh = ($this->h - $this->tMargin - $this->bMargin);
  16754. $ratioHW = ($rows * $mh) / ($cols * $mw);
  16755. $ratioWH = ($cols * $mw) / ($rows * $mh);
  16756. if (!$distort) {
  16757. if (($maxw * $ratioHW) > $maxh) {
  16758. $maxw = $maxh * $ratioWH;
  16759. }
  16760. if (($maxh * $ratioWH) > $maxw) {
  16761. $maxh = $maxw * $ratioHW;
  16762. }
  16763. }
  16764. // set maximum dimesions
  16765. if ($w > $maxw) {
  16766. $w = $maxw;
  16767. }
  16768. if ($h > $maxh) {
  16769. $h = $maxh;
  16770. }
  16771. $hpad = (2 * $style['hpadding']);
  16772. $vpad = (2 * $style['vpadding']);
  16773. // set dimensions
  16774. if ((($w === '') OR ($w <= 0)) AND (($h === '') OR ($h <= 0))) {
  16775. $w = ($cols + $hpad) * ($mw / $this->k);
  16776. $h = ($rows + $vpad) * ($mh / $this->k);
  16777. } elseif (($w === '') OR ($w <= 0)) {
  16778. $w = $h * $ratioWH;
  16779. } elseif (($h === '') OR ($h <= 0)) {
  16780. $h = $w * $ratioHW;
  16781. }
  16782. // barcode size (excluding padding)
  16783. $bw = ($w * $cols) / ($cols + $hpad);
  16784. $bh = ($h * $rows) / ($rows + $vpad);
  16785. // dimension of single barcode cell unit
  16786. $cw = $bw / $cols;
  16787. $ch = $bh / $rows;
  16788. if (!$distort) {
  16789. if (($cw / $ch) > ($mw / $mh)) {
  16790. // correct horizontal distortion
  16791. $cw = $ch * $mw / $mh;
  16792. $bw = $cw * $cols;
  16793. $style['hpadding'] = ($w - $bw) / (2 * $cw);
  16794. } else {
  16795. // correct vertical distortion
  16796. $ch = $cw * $mh / $mw;
  16797. $bh = $ch * $rows;
  16798. $style['vpadding'] = ($h - $bh) / (2 * $ch);
  16799. }
  16800. }
  16801. // fit the barcode on available space
  16802. $this->fitBlock($w, $h, $x, $y, false);
  16803. // set alignment
  16804. $this->img_rb_y = $y + $h;
  16805. // set alignment
  16806. if ($this->rtl) {
  16807. if ($style['position'] == 'L') {
  16808. $xpos = $this->lMargin;
  16809. } elseif ($style['position'] == 'C') {
  16810. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  16811. } elseif ($style['position'] == 'R') {
  16812. $xpos = $this->w - $this->rMargin - $w;
  16813. } else {
  16814. $xpos = $x - $w;
  16815. }
  16816. $this->img_rb_x = $xpos;
  16817. } else {
  16818. if ($style['position'] == 'L') {
  16819. $xpos = $this->lMargin;
  16820. } elseif ($style['position'] == 'C') {
  16821. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  16822. } elseif ($style['position'] == 'R') {
  16823. $xpos = $this->w - $this->rMargin - $w;
  16824. } else {
  16825. $xpos = $x;
  16826. }
  16827. $this->img_rb_x = $xpos + $w;
  16828. }
  16829. $xstart = $xpos + ($style['hpadding'] * $cw);
  16830. $ystart = $y + ($style['vpadding'] * $ch);
  16831. // barcode is always printed in LTR direction
  16832. $tempRTL = $this->rtl;
  16833. $this->rtl = false;
  16834. // print background color
  16835. if ($style['bgcolor']) {
  16836. $this->Rect($xpos, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  16837. } elseif ($style['border']) {
  16838. $this->Rect($xpos, $y, $w, $h, 'D');
  16839. }
  16840. // set foreground color
  16841. $this->SetDrawColorArray($style['fgcolor']);
  16842. // print barcode cells
  16843. // for each row
  16844. for ($r = 0; $r < $rows; ++$r) {
  16845. $xr = $xstart;
  16846. // for each column
  16847. for ($c = 0; $c < $cols; ++$c) {
  16848. if ($arrcode['bcode'][$r][$c] == 1) {
  16849. // draw a single barcode cell
  16850. $this->Rect($xr, $ystart, $cw, $ch, 'F', array(), $style['fgcolor']);
  16851. }
  16852. $xr += $cw;
  16853. }
  16854. $ystart += $ch;
  16855. }
  16856. // restore original direction
  16857. $this->rtl = $tempRTL;
  16858. // restore previous settings
  16859. $this->setGraphicVars($gvars);
  16860. // set pointer to align the next text/objects
  16861. switch($align) {
  16862. case 'T':{
  16863. $this->y = $y;
  16864. $this->x = $this->img_rb_x;
  16865. break;
  16866. }
  16867. case 'M':{
  16868. $this->y = $y + round($h/2);
  16869. $this->x = $this->img_rb_x;
  16870. break;
  16871. }
  16872. case 'B':{
  16873. $this->y = $this->img_rb_y;
  16874. $this->x = $this->img_rb_x;
  16875. break;
  16876. }
  16877. case 'N':{
  16878. $this->SetY($this->img_rb_y);
  16879. break;
  16880. }
  16881. default:{
  16882. break;
  16883. }
  16884. }
  16885. $this->endlinex = $this->img_rb_x;
  16886. }
  16887. /**
  16888. * Returns an array containing current margins:
  16889. * <ul>
  16890. <li>$ret['left'] = left margin</li>
  16891. <li>$ret['right'] = right margin</li>
  16892. <li>$ret['top'] = top margin</li>
  16893. <li>$ret['bottom'] = bottom margin</li>
  16894. <li>$ret['header'] = header margin</li>
  16895. <li>$ret['footer'] = footer margin</li>
  16896. <li>$ret['cell'] = cell padding array</li>
  16897. <li>$ret['padding_left'] = cell left padding</li>
  16898. <li>$ret['padding_top'] = cell top padding</li>
  16899. <li>$ret['padding_right'] = cell right padding</li>
  16900. <li>$ret['padding_bottom'] = cell bottom padding</li>
  16901. * </ul>
  16902. * @return array containing all margins measures
  16903. * @public
  16904. * @since 3.2.000 (2008-06-23)
  16905. */
  16906. public function getMargins() {
  16907. $ret = array(
  16908. 'left' => $this->lMargin,
  16909. 'right' => $this->rMargin,
  16910. 'top' => $this->tMargin,
  16911. 'bottom' => $this->bMargin,
  16912. 'header' => $this->header_margin,
  16913. 'footer' => $this->footer_margin,
  16914. 'cell' => $this->cell_padding,
  16915. 'padding_left' => $this->cell_padding['L'],
  16916. 'padding_top' => $this->cell_padding['T'],
  16917. 'padding_right' => $this->cell_padding['R'],
  16918. 'padding_bottom' => $this->cell_padding['B']
  16919. );
  16920. return $ret;
  16921. }
  16922. /**
  16923. * Returns an array containing original margins:
  16924. * <ul>
  16925. <li>$ret['left'] = left margin</li>
  16926. <li>$ret['right'] = right margin</li>
  16927. * </ul>
  16928. * @return array containing all margins measures
  16929. * @public
  16930. * @since 4.0.012 (2008-07-24)
  16931. */
  16932. public function getOriginalMargins() {
  16933. $ret = array(
  16934. 'left' => $this->original_lMargin,
  16935. 'right' => $this->original_rMargin
  16936. );
  16937. return $ret;
  16938. }
  16939. /**
  16940. * Returns the current font size.
  16941. * @return current font size
  16942. * @public
  16943. * @since 3.2.000 (2008-06-23)
  16944. */
  16945. public function getFontSize() {
  16946. return $this->FontSize;
  16947. }
  16948. /**
  16949. * Returns the current font size in points unit.
  16950. * @return current font size in points unit
  16951. * @public
  16952. * @since 3.2.000 (2008-06-23)
  16953. */
  16954. public function getFontSizePt() {
  16955. return $this->FontSizePt;
  16956. }
  16957. /**
  16958. * Returns the current font family name.
  16959. * @return string current font family name
  16960. * @public
  16961. * @since 4.3.008 (2008-12-05)
  16962. */
  16963. public function getFontFamily() {
  16964. return $this->FontFamily;
  16965. }
  16966. /**
  16967. * Returns the current font style.
  16968. * @return string current font style
  16969. * @public
  16970. * @since 4.3.008 (2008-12-05)
  16971. */
  16972. public function getFontStyle() {
  16973. return $this->FontStyle;
  16974. }
  16975. /**
  16976. * Cleanup HTML code (requires HTML Tidy library).
  16977. * @param $html (string) htmlcode to fix
  16978. * @param $default_css (string) CSS commands to add
  16979. * @param $tagvs (array) parameters for setHtmlVSpace method
  16980. * @param $tidy_options (array) options for tidy_parse_string function
  16981. * @return string XHTML code cleaned up
  16982. * @author Nicola Asuni
  16983. * @public
  16984. * @since 5.9.017 (2010-11-16)
  16985. * @see setHtmlVSpace()
  16986. */
  16987. public function fixHTMLCode($html, $default_css='', $tagvs='', $tidy_options='') {
  16988. // configure parameters for HTML Tidy
  16989. if ($tidy_options === '') {
  16990. $tidy_options = array (
  16991. 'clean' => 1,
  16992. 'drop-empty-paras' => 0,
  16993. 'drop-proprietary-attributes' => 1,
  16994. 'fix-backslash' => 1,
  16995. 'hide-comments' => 1,
  16996. 'join-styles' => 1,
  16997. 'lower-literals' => 1,
  16998. 'merge-divs' => 1,
  16999. 'merge-spans' => 1,
  17000. 'output-xhtml' => 1,
  17001. 'word-2000' => 1,
  17002. 'wrap' => 0,
  17003. 'output-bom' => 0,
  17004. //'char-encoding' => 'utf8',
  17005. //'input-encoding' => 'utf8',
  17006. //'output-encoding' => 'utf8'
  17007. );
  17008. }
  17009. // clean up the HTML code
  17010. $tidy = tidy_parse_string($html, $tidy_options);
  17011. // fix the HTML
  17012. $tidy->cleanRepair();
  17013. // get the CSS part
  17014. $tidy_head = tidy_get_head($tidy);
  17015. $css = $tidy_head->value;
  17016. $css = preg_replace('/<style([^>]+)>/ims', '<style>', $css);
  17017. $css = preg_replace('/<\/style>(.*)<style>/ims', "\n", $css);
  17018. $css = str_replace('/*<![CDATA[*/', '', $css);
  17019. $css = str_replace('/*]]>*/', '', $css);
  17020. preg_match('/<style>(.*)<\/style>/ims', $css, $matches);
  17021. $css = strtolower($matches[1]);
  17022. // include default css
  17023. $css = '<style>'.$default_css.$css.'</style>';
  17024. // get the body part
  17025. $tidy_body = tidy_get_body($tidy);
  17026. $html = $tidy_body->value;
  17027. // fix some self-closing tags
  17028. $html = str_replace('<br>', '<br />', $html);
  17029. // remove some empty tag blocks
  17030. $html = preg_replace('/<div([^\>]*)><\/div>/', '', $html);
  17031. $html = preg_replace('/<p([^\>]*)><\/p>/', '', $html);
  17032. if ($tagvs !== '') {
  17033. // set vertical space for some XHTML tags
  17034. $this->setHtmlVSpace($tagvs);
  17035. }
  17036. // return the cleaned XHTML code + CSS
  17037. return $css.$html;
  17038. }
  17039. /**
  17040. * Extracts the CSS properties from a CSS string.
  17041. * @param $cssdata (string) string containing CSS definitions.
  17042. * @return An array where the keys are the CSS selectors and the values are the CSS properties.
  17043. * @author Nicola Asuni
  17044. * @since 5.1.000 (2010-05-25)
  17045. * @protected
  17046. */
  17047. protected function extractCSSproperties($cssdata) {
  17048. if (empty($cssdata)) {
  17049. return array();
  17050. }
  17051. // remove comments
  17052. $cssdata = preg_replace('/\/\*[^\*]*\*\//', '', $cssdata);
  17053. // remove newlines and multiple spaces
  17054. $cssdata = preg_replace('/[\s]+/', ' ', $cssdata);
  17055. // remove some spaces
  17056. $cssdata = preg_replace('/[\s]*([;:\{\}]{1})[\s]*/', '\\1', $cssdata);
  17057. // remove empty blocks
  17058. $cssdata = preg_replace('/([^\}\{]+)\{\}/', '', $cssdata);
  17059. // replace media type parenthesis
  17060. $cssdata = preg_replace('/@media[\s]+([^\{]*)\{/i', '@media \\1§', $cssdata);
  17061. $cssdata = preg_replace('/\}\}/si', '}§', $cssdata);
  17062. // trim string
  17063. $cssdata = trim($cssdata);
  17064. // find media blocks (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  17065. $cssblocks = array();
  17066. $matches = array();
  17067. if (preg_match_all('/@media[\s]+([^\§]*)§([^§]*)§/i', $cssdata, $matches) > 0) {
  17068. foreach ($matches[1] as $key => $type) {
  17069. $cssblocks[$type] = $matches[2][$key];
  17070. }
  17071. // remove media blocks
  17072. $cssdata = preg_replace('/@media[\s]+([^\§]*)§([^§]*)§/i', '', $cssdata);
  17073. }
  17074. // keep 'all' and 'print' media, other media types are discarded
  17075. if (isset($cssblocks['all']) AND !empty($cssblocks['all'])) {
  17076. $cssdata .= $cssblocks['all'];
  17077. }
  17078. if (isset($cssblocks['print']) AND !empty($cssblocks['print'])) {
  17079. $cssdata .= $cssblocks['print'];
  17080. }
  17081. // reset css blocks array
  17082. $cssblocks = array();
  17083. $matches = array();
  17084. // explode css data string into array
  17085. if (substr($cssdata, -1) == '}') {
  17086. // remove last parethesis
  17087. $cssdata = substr($cssdata, 0, -1);
  17088. }
  17089. $matches = explode('}', $cssdata);
  17090. foreach ($matches as $key => $block) {
  17091. // index 0 contains the CSS selector, index 1 contains CSS properties
  17092. $cssblocks[$key] = explode('{', $block);
  17093. if (!isset($cssblocks[$key][1])) {
  17094. // remove empty definitions
  17095. unset($cssblocks[$key]);
  17096. }
  17097. }
  17098. // split groups of selectors (comma-separated list of selectors)
  17099. foreach ($cssblocks as $key => $block) {
  17100. if (strpos($block[0], ',') > 0) {
  17101. $selectors = explode(',', $block[0]);
  17102. foreach ($selectors as $sel) {
  17103. $cssblocks[] = array(0 => trim($sel), 1 => $block[1]);
  17104. }
  17105. unset($cssblocks[$key]);
  17106. }
  17107. }
  17108. // covert array to selector => properties
  17109. $cssdata = array();
  17110. foreach ($cssblocks as $block) {
  17111. $selector = $block[0];
  17112. // calculate selector's specificity
  17113. $matches = array();
  17114. $a = 0; // the declaration is not from is a 'style' attribute
  17115. $b = intval(preg_match_all('/[\#]/', $selector, $matches)); // number of ID attributes
  17116. $c = intval(preg_match_all('/[\[\.]/', $selector, $matches)); // number of other attributes
  17117. $c += intval(preg_match_all('/[\:]link|visited|hover|active|focus|target|lang|enabled|disabled|checked|indeterminate|root|nth|first|last|only|empty|contains|not/i', $selector, $matches)); // number of pseudo-classes
  17118. $d = intval(preg_match_all('/[\>\+\~\s]{1}[a-zA-Z0-9\*]+/', ' '.$selector, $matches)); // number of element names
  17119. $d += intval(preg_match_all('/[\:][\:]/', $selector, $matches)); // number of pseudo-elements
  17120. $specificity = $a.$b.$c.$d;
  17121. // add specificity to the beginning of the selector
  17122. $cssdata[$specificity.' '.$selector] = $block[1];
  17123. }
  17124. // sort selectors alphabetically to account for specificity
  17125. ksort($cssdata, SORT_STRING);
  17126. // return array
  17127. return $cssdata;
  17128. }
  17129. /**
  17130. * Returns true if the CSS selector is valid for the selected HTML tag
  17131. * @param $dom (array) array of HTML tags and properties
  17132. * @param $key (int) key of the current HTML tag
  17133. * @param $selector (string) CSS selector string
  17134. * @return true if the selector is valid, false otherwise
  17135. * @protected
  17136. * @since 5.1.000 (2010-05-25)
  17137. */
  17138. protected function isValidCSSSelectorForTag($dom, $key, $selector) {
  17139. $valid = false; // value to be returned
  17140. $tag = $dom[$key]['value'];
  17141. $class = array();
  17142. if (isset($dom[$key]['attribute']['class']) AND !empty($dom[$key]['attribute']['class'])) {
  17143. $class = explode(' ', strtolower($dom[$key]['attribute']['class']));
  17144. }
  17145. $id = '';
  17146. if (isset($dom[$key]['attribute']['id']) AND !empty($dom[$key]['attribute']['id'])) {
  17147. $id = strtolower($dom[$key]['attribute']['id']);
  17148. }
  17149. $selector = preg_replace('/([\>\+\~\s]{1})([\.]{1})([^\>\+\~\s]*)/si', '\\1*.\\3', $selector);
  17150. $matches = array();
  17151. if (preg_match_all('/([\>\+\~\s]{1})([a-zA-Z0-9\*]+)([^\>\+\~\s]*)/si', $selector, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) > 0) {
  17152. $parentop = array_pop($matches[1]);
  17153. $operator = $parentop[0];
  17154. $offset = $parentop[1];
  17155. $lasttag = array_pop($matches[2]);
  17156. $lasttag = strtolower(trim($lasttag[0]));
  17157. if (($lasttag == '*') OR ($lasttag == $tag)) {
  17158. // the last element on selector is our tag or 'any tag'
  17159. $attrib = array_pop($matches[3]);
  17160. $attrib = strtolower(trim($attrib[0]));
  17161. if (!empty($attrib)) {
  17162. // check if matches class, id, attribute, pseudo-class or pseudo-element
  17163. switch ($attrib{0}) {
  17164. case '.': { // class
  17165. if (in_array(substr($attrib, 1), $class)) {
  17166. $valid = true;
  17167. }
  17168. break;
  17169. }
  17170. case '#': { // ID
  17171. if (substr($attrib, 1) == $id) {
  17172. $valid = true;
  17173. }
  17174. break;
  17175. }
  17176. case '[': { // attribute
  17177. $attrmatch = array();
  17178. if (preg_match('/\[([a-zA-Z0-9]*)[\s]*([\~\^\$\*\|\=]*)[\s]*["]?([^"\]]*)["]?\]/i', $attrib, $attrmatch) > 0) {
  17179. $att = strtolower($attrmatch[1]);
  17180. $val = $attrmatch[3];
  17181. if (isset($dom[$key]['attribute'][$att])) {
  17182. switch ($attrmatch[2]) {
  17183. case '=': {
  17184. if ($dom[$key]['attribute'][$att] == $val) {
  17185. $valid = true;
  17186. }
  17187. break;
  17188. }
  17189. case '~=': {
  17190. if (in_array($val, explode(' ', $dom[$key]['attribute'][$att]))) {
  17191. $valid = true;
  17192. }
  17193. break;
  17194. }
  17195. case '^=': {
  17196. if ($val == substr($dom[$key]['attribute'][$att], 0, strlen($val))) {
  17197. $valid = true;
  17198. }
  17199. break;
  17200. }
  17201. case '$=': {
  17202. if ($val == substr($dom[$key]['attribute'][$att], -strlen($val))) {
  17203. $valid = true;
  17204. }
  17205. break;
  17206. }
  17207. case '*=': {
  17208. if (strpos($dom[$key]['attribute'][$att], $val) !== false) {
  17209. $valid = true;
  17210. }
  17211. break;
  17212. }
  17213. case '|=': {
  17214. if ($dom[$key]['attribute'][$att] == $val) {
  17215. $valid = true;
  17216. } elseif (preg_match('/'.$val.'[\-]{1}/i', $dom[$key]['attribute'][$att]) > 0) {
  17217. $valid = true;
  17218. }
  17219. break;
  17220. }
  17221. default: {
  17222. $valid = true;
  17223. }
  17224. }
  17225. }
  17226. }
  17227. break;
  17228. }
  17229. case ':': { // pseudo-class or pseudo-element
  17230. if ($attrib{1} == ':') { // pseudo-element
  17231. // pseudo-elements are not supported!
  17232. // (::first-line, ::first-letter, ::before, ::after)
  17233. } else { // pseudo-class
  17234. // pseudo-classes are not supported!
  17235. // (:root, :nth-child(n), :nth-last-child(n), :nth-of-type(n), :nth-last-of-type(n), :first-child, :last-child, :first-of-type, :last-of-type, :only-child, :only-of-type, :empty, :link, :visited, :active, :hover, :focus, :target, :lang(fr), :enabled, :disabled, :checked)
  17236. }
  17237. break;
  17238. }
  17239. } // end of switch
  17240. } else {
  17241. $valid = true;
  17242. }
  17243. if ($valid AND ($offset > 0)) {
  17244. $valid = false;
  17245. // check remaining selector part
  17246. $selector = substr($selector, 0, $offset);
  17247. switch ($operator) {
  17248. case ' ': { // descendant of an element
  17249. while ($dom[$key]['parent'] > 0) {
  17250. if ($this->isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector)) {
  17251. $valid = true;
  17252. break;
  17253. } else {
  17254. $key = $dom[$key]['parent'];
  17255. }
  17256. }
  17257. break;
  17258. }
  17259. case '>': { // child of an element
  17260. $valid = $this->isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector);
  17261. break;
  17262. }
  17263. case '+': { // immediately preceded by an element
  17264. for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) {
  17265. if ($dom[$i]['tag'] AND $dom[$i]['opening']) {
  17266. $valid = $this->isValidCSSSelectorForTag($dom, $i, $selector);
  17267. break;
  17268. }
  17269. }
  17270. break;
  17271. }
  17272. case '~': { // preceded by an element
  17273. for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) {
  17274. if ($dom[$i]['tag'] AND $dom[$i]['opening']) {
  17275. if ($this->isValidCSSSelectorForTag($dom, $i, $selector)) {
  17276. break;
  17277. }
  17278. }
  17279. }
  17280. break;
  17281. }
  17282. }
  17283. }
  17284. }
  17285. }
  17286. return $valid;
  17287. }
  17288. /**
  17289. * Returns the styles that apply for the selected HTML tag.
  17290. * @param $dom (array) array of HTML tags and properties
  17291. * @param $key (int) key of the current HTML tag
  17292. * @param $css (array) array of CSS properties
  17293. * @return string containing CSS properties
  17294. * @protected
  17295. * @since 5.1.000 (2010-05-25)
  17296. */
  17297. protected function getTagStyleFromCSS($dom, $key, $css) {
  17298. $tagstyle = ''; // style to be returned
  17299. // get all styles that apply
  17300. foreach($css as $selector => $style) {
  17301. // remove specificity
  17302. $selector = substr($selector, strpos($selector, ' '));
  17303. // check if this selector apply to current tag
  17304. if ($this->isValidCSSSelectorForTag($dom, $key, $selector)) {
  17305. // apply style
  17306. $tagstyle .= ';'.$style;
  17307. }
  17308. }
  17309. if (isset($dom[$key]['attribute']['style'])) {
  17310. // attach inline style (latest properties have high priority)
  17311. $tagstyle .= ';'.$dom[$key]['attribute']['style'];
  17312. }
  17313. // remove multiple semicolons
  17314. $tagstyle = preg_replace('/[;]+/', ';', $tagstyle);
  17315. return $tagstyle;
  17316. }
  17317. /**
  17318. * Returns the border width from CSS property
  17319. * @param $width (string) border width
  17320. * @return int with in user units
  17321. * @protected
  17322. * @since 5.7.000 (2010-08-02)
  17323. */
  17324. protected function getCSSBorderWidth($width) {
  17325. if ($width == 'thin') {
  17326. $width = (2 / $this->k);
  17327. } elseif ($width == 'medium') {
  17328. $width = (4 / $this->k);
  17329. } elseif ($width == 'thick') {
  17330. $width = (6 / $this->k);
  17331. } else {
  17332. $width = $this->getHTMLUnitToUnits($width, 1, 'px', false);
  17333. }
  17334. return $width;
  17335. }
  17336. /**
  17337. * Returns the border dash style from CSS property
  17338. * @param $style (string) border style to convert
  17339. * @return int sash style (return -1 in case of none or hidden border)
  17340. * @protected
  17341. * @since 5.7.000 (2010-08-02)
  17342. */
  17343. protected function getCSSBorderDashStyle($style) {
  17344. switch (strtolower($style)) {
  17345. case 'none':
  17346. case 'hidden': {
  17347. $dash = -1;
  17348. break;
  17349. }
  17350. case 'dotted': {
  17351. $dash = 1;
  17352. break;
  17353. }
  17354. case 'dashed': {
  17355. $dash = 3;
  17356. break;
  17357. }
  17358. case 'double':
  17359. case 'groove':
  17360. case 'ridge':
  17361. case 'inset':
  17362. case 'outset':
  17363. case 'solid':
  17364. default: {
  17365. $dash = 0;
  17366. break;
  17367. }
  17368. }
  17369. return $dash;
  17370. }
  17371. /**
  17372. * Returns the border style array from CSS border properties
  17373. * @param $cssborder (string) border properties
  17374. * @return array containing border properties
  17375. * @protected
  17376. * @since 5.7.000 (2010-08-02)
  17377. */
  17378. protected function getCSSBorderStyle($cssborder) {
  17379. $bprop = preg_split('/[\s]+/', trim($cssborder));
  17380. $border = array(); // value to be returned
  17381. switch (count($bprop)) {
  17382. case 3: {
  17383. $width = $bprop[0];
  17384. $style = $bprop[1];
  17385. $color = $bprop[2];
  17386. break;
  17387. }
  17388. case 2: {
  17389. $width = 'medium';
  17390. $style = $bprop[0];
  17391. $color = $bprop[1];
  17392. break;
  17393. }
  17394. case 1: {
  17395. $width = 'medium';
  17396. $style = $bprop[0];
  17397. $color = 'black';
  17398. break;
  17399. }
  17400. default: {
  17401. $width = 'medium';
  17402. $style = 'solid';
  17403. $color = 'black';
  17404. break;
  17405. }
  17406. }
  17407. if ($style == 'none') {
  17408. return array();
  17409. }
  17410. $border['cap'] = 'square';
  17411. $border['join'] = 'miter';
  17412. $border['dash'] = $this->getCSSBorderDashStyle($style);
  17413. if ($border['dash'] < 0) {
  17414. return array();
  17415. }
  17416. $border['width'] = $this->getCSSBorderWidth($width);
  17417. $border['color'] = $this->convertHTMLColorToDec($color);
  17418. return $border;
  17419. }
  17420. /**
  17421. * Get the internal Cell padding from CSS attribute.
  17422. * @param $csspadding (string) padding properties
  17423. * @param $width (float) width of the containing element
  17424. * @return array of cell paddings
  17425. * @public
  17426. * @since 5.9.000 (2010-10-04)
  17427. */
  17428. public function getCSSPadding($csspadding, $width=0) {
  17429. $padding = preg_split('/[\s]+/', trim($csspadding));
  17430. $cell_padding = array(); // value to be returned
  17431. switch (count($padding)) {
  17432. case 4: {
  17433. $cell_padding['T'] = $padding[0];
  17434. $cell_padding['R'] = $padding[1];
  17435. $cell_padding['B'] = $padding[2];
  17436. $cell_padding['L'] = $padding[3];
  17437. break;
  17438. }
  17439. case 3: {
  17440. $cell_padding['T'] = $padding[0];
  17441. $cell_padding['R'] = $padding[1];
  17442. $cell_padding['B'] = $padding[2];
  17443. $cell_padding['L'] = $padding[1];
  17444. break;
  17445. }
  17446. case 2: {
  17447. $cell_padding['T'] = $padding[0];
  17448. $cell_padding['R'] = $padding[1];
  17449. $cell_padding['B'] = $padding[0];
  17450. $cell_padding['L'] = $padding[1];
  17451. break;
  17452. }
  17453. case 1: {
  17454. $cell_padding['T'] = $padding[0];
  17455. $cell_padding['R'] = $padding[0];
  17456. $cell_padding['B'] = $padding[0];
  17457. $cell_padding['L'] = $padding[0];
  17458. break;
  17459. }
  17460. default: {
  17461. return $this->cell_padding;
  17462. }
  17463. }
  17464. if ($width == 0) {
  17465. $width = $this->w - $this->lMargin - $this->rMargin;
  17466. }
  17467. $cell_padding['T'] = $this->getHTMLUnitToUnits($cell_padding['T'], $width, 'px', false);
  17468. $cell_padding['R'] = $this->getHTMLUnitToUnits($cell_padding['R'], $width, 'px', false);
  17469. $cell_padding['B'] = $this->getHTMLUnitToUnits($cell_padding['B'], $width, 'px', false);
  17470. $cell_padding['L'] = $this->getHTMLUnitToUnits($cell_padding['L'], $width, 'px', false);
  17471. return $cell_padding;
  17472. }
  17473. /**
  17474. * Get the internal Cell margin from CSS attribute.
  17475. * @param $cssmargin (string) margin properties
  17476. * @param $width (float) width of the containing element
  17477. * @return array of cell margins
  17478. * @public
  17479. * @since 5.9.000 (2010-10-04)
  17480. */
  17481. public function getCSSMargin($cssmargin, $width=0) {
  17482. $margin = preg_split('/[\s]+/', trim($cssmargin));
  17483. $cell_margin = array(); // value to be returned
  17484. switch (count($margin)) {
  17485. case 4: {
  17486. $cell_margin['T'] = $margin[0];
  17487. $cell_margin['R'] = $margin[1];
  17488. $cell_margin['B'] = $margin[2];
  17489. $cell_margin['L'] = $margin[3];
  17490. break;
  17491. }
  17492. case 3: {
  17493. $cell_margin['T'] = $margin[0];
  17494. $cell_margin['R'] = $margin[1];
  17495. $cell_margin['B'] = $margin[2];
  17496. $cell_margin['L'] = $margin[1];
  17497. break;
  17498. }
  17499. case 2: {
  17500. $cell_margin['T'] = $margin[0];
  17501. $cell_margin['R'] = $margin[1];
  17502. $cell_margin['B'] = $margin[0];
  17503. $cell_margin['L'] = $margin[1];
  17504. break;
  17505. }
  17506. case 1: {
  17507. $cell_margin['T'] = $margin[0];
  17508. $cell_margin['R'] = $margin[0];
  17509. $cell_margin['B'] = $margin[0];
  17510. $cell_margin['L'] = $margin[0];
  17511. break;
  17512. }
  17513. default: {
  17514. return $this->cell_margin;
  17515. }
  17516. }
  17517. if ($width == 0) {
  17518. $width = $this->w - $this->lMargin - $this->rMargin;
  17519. }
  17520. $cell_margin['T'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['T']), $width, 'px', false);
  17521. $cell_margin['R'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['R']), $width, 'px', false);
  17522. $cell_margin['B'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['B']), $width, 'px', false);
  17523. $cell_margin['L'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['L']), $width, 'px', false);
  17524. return $cell_margin;
  17525. }
  17526. /**
  17527. * Get the border-spacing from CSS attribute.
  17528. * @param $cssbspace (string) border-spacing CSS properties
  17529. * @param $width (float) width of the containing element
  17530. * @return array of border spacings
  17531. * @public
  17532. * @since 5.9.010 (2010-10-27)
  17533. */
  17534. public function getCSSBorderMargin($cssbspace, $width=0) {
  17535. $space = preg_split('/[\s]+/', trim($cssbspace));
  17536. $border_spacing = array(); // value to be returned
  17537. switch (count($space)) {
  17538. case 2: {
  17539. $border_spacing['H'] = $space[0];
  17540. $border_spacing['V'] = $space[1];
  17541. break;
  17542. }
  17543. case 1: {
  17544. $border_spacing['H'] = $space[0];
  17545. $border_spacing['V'] = $space[0];
  17546. break;
  17547. }
  17548. default: {
  17549. return array('H' => 0, 'V' => 0);
  17550. }
  17551. }
  17552. if ($width == 0) {
  17553. $width = $this->w - $this->lMargin - $this->rMargin;
  17554. }
  17555. $border_spacing['H'] = $this->getHTMLUnitToUnits($border_spacing['H'], $width, 'px', false);
  17556. $border_spacing['V'] = $this->getHTMLUnitToUnits($border_spacing['V'], $width, 'px', false);
  17557. return $border_spacing;
  17558. }
  17559. /**
  17560. * Returns the letter-spacing value from CSS value
  17561. * @param $spacing (string) letter-spacing value
  17562. * @param $parent (float) font spacing (tracking/kerning) value of the parent element
  17563. * @return float quantity to increases or decreases the space between characters in a text.
  17564. * @protected
  17565. * @since 5.9.000 (2010-10-02)
  17566. */
  17567. protected function getCSSFontSpacing($spacing, $parent=0) {
  17568. $val = 0; // value to be returned
  17569. $spacing = trim($spacing);
  17570. switch ($spacing) {
  17571. case 'normal': {
  17572. $val = 0;
  17573. break;
  17574. }
  17575. case 'inherit': {
  17576. if ($parent == 'normal') {
  17577. $val = 0;
  17578. } else {
  17579. $val = $parent;
  17580. }
  17581. break;
  17582. }
  17583. default: {
  17584. $val = $this->getHTMLUnitToUnits($spacing, 0, 'px', false);
  17585. }
  17586. }
  17587. return $val;
  17588. }
  17589. /**
  17590. * Returns the percentage of font stretching from CSS value
  17591. * @param $stretch (string) stretch mode
  17592. * @param $parent (float) stretch value of the parent element
  17593. * @return float font stretching percentage
  17594. * @protected
  17595. * @since 5.9.000 (2010-10-02)
  17596. */
  17597. protected function getCSSFontStretching($stretch, $parent=100) {
  17598. $val = 100; // value to be returned
  17599. $stretch = trim($stretch);
  17600. switch ($stretch) {
  17601. case 'ultra-condensed': {
  17602. $val = 40;
  17603. break;
  17604. }
  17605. case 'extra-condensed': {
  17606. $val = 55;
  17607. break;
  17608. }
  17609. case 'condensed': {
  17610. $val = 70;
  17611. break;
  17612. }
  17613. case 'semi-condensed': {
  17614. $val = 85;
  17615. break;
  17616. }
  17617. case 'normal': {
  17618. $val = 100;
  17619. break;
  17620. }
  17621. case 'semi-expanded': {
  17622. $val = 115;
  17623. break;
  17624. }
  17625. case 'expanded': {
  17626. $val = 130;
  17627. break;
  17628. }
  17629. case 'extra-expanded': {
  17630. $val = 145;
  17631. break;
  17632. }
  17633. case 'ultra-expanded': {
  17634. $val = 160;
  17635. break;
  17636. }
  17637. case 'wider': {
  17638. $val = $parent + 10;
  17639. break;
  17640. }
  17641. case 'narrower': {
  17642. $val = $parent - 10;
  17643. break;
  17644. }
  17645. case 'inherit': {
  17646. if ($parent == 'normal') {
  17647. $val = 100;
  17648. } else {
  17649. $val = $parent;
  17650. }
  17651. break;
  17652. }
  17653. default: {
  17654. $val = $this->getHTMLUnitToUnits($stretch, 100, '%', false);
  17655. }
  17656. }
  17657. return $val;
  17658. }
  17659. /**
  17660. * Returns the HTML DOM array.
  17661. * @param $html (string) html code
  17662. * @return array
  17663. * @protected
  17664. * @since 3.2.000 (2008-06-20)
  17665. */
  17666. protected function getHtmlDomArray($html) {
  17667. // array of CSS styles ( selector => properties).
  17668. $css = array();
  17669. // get CSS array defined at previous call
  17670. $matches = array();
  17671. if (preg_match_all('/<cssarray>([^\<]*)<\/cssarray>/isU', $html, $matches) > 0) {
  17672. if (isset($matches[1][0])) {
  17673. $css = array_merge($css, unserialize($this->unhtmlentities($matches[1][0])));
  17674. }
  17675. $html = preg_replace('/<cssarray>(.*?)<\/cssarray>/isU', '', $html);
  17676. }
  17677. // extract external CSS files
  17678. $matches = array();
  17679. if (preg_match_all('/<link([^\>]*)>/isU', $html, $matches) > 0) {
  17680. foreach ($matches[1] as $key => $link) {
  17681. $type = array();
  17682. if (preg_match('/type[\s]*=[\s]*"text\/css"/', $link, $type)) {
  17683. $type = array();
  17684. preg_match('/media[\s]*=[\s]*"([^"]*)"/', $link, $type);
  17685. // get 'all' and 'print' media, other media types are discarded
  17686. // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  17687. if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
  17688. $type = array();
  17689. if (preg_match('/href[\s]*=[\s]*"([^"]*)"/', $link, $type) > 0) {
  17690. // read CSS data file
  17691. $cssdata = file_get_contents(trim($type[1]));
  17692. $css = array_merge($css, $this->extractCSSproperties($cssdata));
  17693. }
  17694. }
  17695. }
  17696. }
  17697. }
  17698. // extract style tags
  17699. $matches = array();
  17700. if (preg_match_all('/<style([^\>]*)>([^\<]*)<\/style>/isU', $html, $matches) > 0) {
  17701. foreach ($matches[1] as $key => $media) {
  17702. $type = array();
  17703. preg_match('/media[\s]*=[\s]*"([^"]*)"/', $media, $type);
  17704. // get 'all' and 'print' media, other media types are discarded
  17705. // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  17706. if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
  17707. $cssdata = $matches[2][$key];
  17708. $css = array_merge($css, $this->extractCSSproperties($cssdata));
  17709. }
  17710. }
  17711. }
  17712. // create a special tag to contain the CSS array (used for table content)
  17713. $csstagarray = '<cssarray>'.htmlentities(serialize($css)).'</cssarray>';
  17714. // remove head and style blocks
  17715. $html = preg_replace('/<head([^\>]*)>(.*?)<\/head>/siU', '', $html);
  17716. $html = preg_replace('/<style([^\>]*)>([^\<]*)<\/style>/isU', '', $html);
  17717. // define block tags
  17718. $blocktags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table','tr','td');
  17719. // define self-closing tags
  17720. $selfclosingtags = array('area','base','basefont','br','hr','input','img','link','meta');
  17721. // remove all unsupported tags (the line below lists all supported tags)
  17722. $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>');
  17723. //replace some blank characters
  17724. $html = preg_replace('/<pre/', '<xre', $html); // preserve pre tag
  17725. $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);
  17726. $html = preg_replace('@(\r\n|\r)@', "\n", $html);
  17727. $repTable = array("\t" => ' ', "\0" => ' ', "\x0B" => ' ', "\\" => "\\\\");
  17728. $html = strtr($html, $repTable);
  17729. $offset = 0;
  17730. while (($offset < strlen($html)) AND ($pos = strpos($html, '</pre>', $offset)) !== false) {
  17731. $html_a = substr($html, 0, $offset);
  17732. $html_b = substr($html, $offset, ($pos - $offset + 6));
  17733. while (preg_match("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", $html_b)) {
  17734. // preserve newlines on <pre> tag
  17735. $html_b = preg_replace("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", "<xre\\1>\\2<br />\\3</pre>", $html_b);
  17736. }
  17737. while (preg_match("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], $html_b)) {
  17738. // preserve spaces on <pre> tag
  17739. $html_b = preg_replace("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], "<xre\\1>\\2&nbsp;\\3</pre>", $html_b);
  17740. }
  17741. $html = $html_a.$html_b.substr($html, $pos + 6);
  17742. $offset = strlen($html_a.$html_b);
  17743. }
  17744. $offset = 0;
  17745. while (($offset < strlen($html)) AND ($pos = strpos($html, '</textarea>', $offset)) !== false) {
  17746. $html_a = substr($html, 0, $offset);
  17747. $html_b = substr($html, $offset, ($pos - $offset + 11));
  17748. while (preg_match("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", $html_b)) {
  17749. // preserve newlines on <textarea> tag
  17750. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", "<textarea\\1>\\2<TBR>\\3</textarea>", $html_b);
  17751. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)[\"](.*?)</textarea>'si", "<textarea\\1>\\2''\\3</textarea>", $html_b);
  17752. }
  17753. $html = $html_a.$html_b.substr($html, $pos + 11);
  17754. $offset = strlen($html_a.$html_b);
  17755. }
  17756. $html = preg_replace('/([\s]*)<option/si', '<option', $html);
  17757. $html = preg_replace('/<\/option>([\s]*)/si', '</option>', $html);
  17758. $offset = 0;
  17759. while (($offset < strlen($html)) AND ($pos = strpos($html, '</option>', $offset)) !== false) {
  17760. $html_a = substr($html, 0, $offset);
  17761. $html_b = substr($html, $offset, ($pos - $offset + 9));
  17762. while (preg_match("'<option([^\>]*)>(.*?)</option>'si", $html_b)) {
  17763. $html_b = preg_replace("'<option([\s]+)value=\"([^\"]*)\"([^\>]*)>(.*?)</option>'si", "\\2#!TaB!#\\4#!NwL!#", $html_b);
  17764. $html_b = preg_replace("'<option([^\>]*)>(.*?)</option>'si", "\\2#!NwL!#", $html_b);
  17765. }
  17766. $html = $html_a.$html_b.substr($html, $pos + 9);
  17767. $offset = strlen($html_a.$html_b);
  17768. }
  17769. if (preg_match("'</select'si", $html)) {
  17770. $html = preg_replace("'<select([^\>]*)>'si", "<select\\1 opt=\"", $html);
  17771. $html = preg_replace("'#!NwL!#</select>'si", "\" />", $html);
  17772. }
  17773. $html = str_replace("\n", ' ', $html);
  17774. // restore textarea newlines
  17775. $html = str_replace('<TBR>', "\n", $html);
  17776. // remove extra spaces from code
  17777. $html = preg_replace('/[\s]+<\/(table|tr|ul|ol|dl)>/', '</\\1>', $html);
  17778. $html = preg_replace('/'.$this->re_space['p'].'+<\/(td|th|li|dt|dd)>/'.$this->re_space['m'], '</\\1>', $html);
  17779. $html = preg_replace('/[\s]+<(tr|td|th|li|dt|dd)/', '<\\1', $html);
  17780. $html = preg_replace('/'.$this->re_space['p'].'+<(ul|ol|dl|br)/'.$this->re_space['m'], '<\\1', $html);
  17781. $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);
  17782. $html = preg_replace('/<\/(td|th)>/', '<marker style="font-size:0"/></\\1>', $html);
  17783. $html = preg_replace('/<\/table>([\s]*)<marker style="font-size:0"\/>/', '</table>', $html);
  17784. $html = preg_replace('/'.$this->re_space['p'].'+<img/'.$this->re_space['m'], chr(32).'<img', $html);
  17785. $html = preg_replace('/<img([^\>]*)>[\s]+([^\<])/xi', '<img\\1>&nbsp;\\2', $html);
  17786. $html = preg_replace('/<img([^\>]*)>/xi', '<img\\1><span><marker style="font-size:0"/></span>', $html);
  17787. $html = preg_replace('/<xre/', '<pre', $html); // restore pre tag
  17788. $html = preg_replace('/<textarea([^\>]*)>([^\<]*)<\/textarea>/xi', '<textarea\\1 value="\\2" />', $html);
  17789. $html = preg_replace('/<li([^\>]*)><\/li>/', '<li\\1>&nbsp;</li>', $html);
  17790. $html = preg_replace('/<li([^\>]*)>'.$this->re_space['p'].'*<img/'.$this->re_space['m'], '<li\\1><font size="1">&nbsp;</font><img', $html);
  17791. $html = preg_replace('/<([^\>\/]*)>[\s]/', '<\\1>&nbsp;', $html); // preserve some spaces
  17792. $html = preg_replace('/[\s]<\/([^\>]*)>/', '&nbsp;</\\1>', $html); // preserve some spaces
  17793. $html = preg_replace('/'.$this->re_space['p'].'+/'.$this->re_space['m'], chr(32), $html); // replace multiple spaces with a single space
  17794. // trim string
  17795. $html = $this->stringTrim($html);
  17796. // fix first image tag alignment
  17797. $html = preg_replace('/^<img/', '<span style="font-size:0"><br /></span> <img', $html, 1);
  17798. // pattern for generic tag
  17799. $tagpattern = '/(<[^>]+>)/';
  17800. // explodes the string
  17801. $a = preg_split($tagpattern, $html, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  17802. // count elements
  17803. $maxel = count($a);
  17804. $elkey = 0;
  17805. $key = 0;
  17806. // create an array of elements
  17807. $dom = array();
  17808. $dom[$key] = array();
  17809. // set inheritable properties fot the first void element
  17810. // 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
  17811. $dom[$key]['tag'] = false;
  17812. $dom[$key]['block'] = false;
  17813. $dom[$key]['value'] = '';
  17814. $dom[$key]['parent'] = 0;
  17815. $dom[$key]['fontname'] = $this->FontFamily;
  17816. $dom[$key]['fontstyle'] = $this->FontStyle;
  17817. $dom[$key]['fontsize'] = $this->FontSizePt;
  17818. $dom[$key]['font-stretch'] = $this->font_stretching;
  17819. $dom[$key]['letter-spacing'] = $this->font_spacing;
  17820. $dom[$key]['stroke'] = $this->textstrokewidth;
  17821. $dom[$key]['fill'] = (($this->textrendermode % 2) == 0);
  17822. $dom[$key]['clip'] = ($this->textrendermode > 3);
  17823. $dom[$key]['line-height'] = $this->cell_height_ratio;
  17824. $dom[$key]['bgcolor'] = false;
  17825. $dom[$key]['fgcolor'] = $this->fgcolor; // color
  17826. $dom[$key]['strokecolor'] = $this->strokecolor;
  17827. $dom[$key]['align'] = '';
  17828. $dom[$key]['listtype'] = '';
  17829. $dom[$key]['text-indent'] = 0;
  17830. $dom[$key]['border'] = array();
  17831. $dom[$key]['dir'] = $this->rtl?'rtl':'ltr';
  17832. $thead = false; // true when we are inside the THEAD tag
  17833. ++$key;
  17834. $level = array();
  17835. array_push($level, 0); // root
  17836. while ($elkey < $maxel) {
  17837. $dom[$key] = array();
  17838. $element = $a[$elkey];
  17839. $dom[$key]['elkey'] = $elkey;
  17840. if (preg_match($tagpattern, $element)) {
  17841. // html tag
  17842. $element = substr($element, 1, -1);
  17843. // get tag name
  17844. preg_match('/[\/]?([a-zA-Z0-9]*)/', $element, $tag);
  17845. $tagname = strtolower($tag[1]);
  17846. // check if we are inside a table header
  17847. if ($tagname == 'thead') {
  17848. if ($element{0} == '/') {
  17849. $thead = false;
  17850. } else {
  17851. $thead = true;
  17852. }
  17853. ++$elkey;
  17854. continue;
  17855. }
  17856. $dom[$key]['tag'] = true;
  17857. $dom[$key]['value'] = $tagname;
  17858. if (in_array($dom[$key]['value'], $blocktags)) {
  17859. $dom[$key]['block'] = true;
  17860. } else {
  17861. $dom[$key]['block'] = false;
  17862. }
  17863. if ($element{0} == '/') {
  17864. // *** closing html tag
  17865. $dom[$key]['opening'] = false;
  17866. $dom[$key]['parent'] = end($level);
  17867. array_pop($level);
  17868. $dom[$key]['fontname'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontname'];
  17869. $dom[$key]['fontstyle'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontstyle'];
  17870. $dom[$key]['fontsize'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize'];
  17871. $dom[$key]['font-stretch'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['font-stretch'];
  17872. $dom[$key]['letter-spacing'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['letter-spacing'];
  17873. $dom[$key]['stroke'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['stroke'];
  17874. $dom[$key]['fill'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fill'];
  17875. $dom[$key]['clip'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['clip'];
  17876. $dom[$key]['line-height'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['line-height'];
  17877. $dom[$key]['bgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor'];
  17878. $dom[$key]['fgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor'];
  17879. $dom[$key]['strokecolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['strokecolor'];
  17880. $dom[$key]['align'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['align'];
  17881. $dom[$key]['dir'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['dir'];
  17882. if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) {
  17883. $dom[$key]['listtype'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'];
  17884. }
  17885. // set the number of columns in table tag
  17886. if (($dom[$key]['value'] == 'tr') AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) {
  17887. $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'] = $dom[($dom[$key]['parent'])]['cols'];
  17888. }
  17889. if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  17890. $dom[($dom[$key]['parent'])]['content'] = $csstagarray;
  17891. for ($i = ($dom[$key]['parent'] + 1); $i < $key; ++$i) {
  17892. $dom[($dom[$key]['parent'])]['content'] .= $a[$dom[$i]['elkey']];
  17893. }
  17894. $key = $i;
  17895. // mark nested tables
  17896. $dom[($dom[$key]['parent'])]['content'] = str_replace('<table', '<table nested="true"', $dom[($dom[$key]['parent'])]['content']);
  17897. // remove thead sections from nested tables
  17898. $dom[($dom[$key]['parent'])]['content'] = str_replace('<thead>', '', $dom[($dom[$key]['parent'])]['content']);
  17899. $dom[($dom[$key]['parent'])]['content'] = str_replace('</thead>', '', $dom[($dom[$key]['parent'])]['content']);
  17900. }
  17901. // store header rows on a new table
  17902. if (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['thead'] === true)) {
  17903. if ($this->empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) {
  17904. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] = $a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']];
  17905. }
  17906. for ($i = $dom[$key]['parent']; $i <= $key; ++$i) {
  17907. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] .= $a[$dom[$i]['elkey']];
  17908. }
  17909. if (!isset($dom[($dom[$key]['parent'])]['attribute'])) {
  17910. $dom[($dom[$key]['parent'])]['attribute'] = array();
  17911. }
  17912. // header elements must be always contained in a single page
  17913. $dom[($dom[$key]['parent'])]['attribute']['nobr'] = 'true';
  17914. }
  17915. if (($dom[$key]['value'] == 'table') AND (!$this->empty_string($dom[($dom[$key]['parent'])]['thead']))) {
  17916. // remove the nobr attributes from the table header
  17917. $dom[($dom[$key]['parent'])]['thead'] = str_replace(' nobr="true"', '', $dom[($dom[$key]['parent'])]['thead']);
  17918. $dom[($dom[$key]['parent'])]['thead'] .= '</tablehead>';
  17919. }
  17920. } else {
  17921. // *** opening or self-closing html tag
  17922. $dom[$key]['opening'] = true;
  17923. $dom[$key]['parent'] = end($level);
  17924. if ((substr($element, -1, 1) == '/') OR (in_array($dom[$key]['value'], $selfclosingtags))) {
  17925. // self-closing tag
  17926. $dom[$key]['self'] = true;
  17927. } else {
  17928. // opening tag
  17929. array_push($level, $key);
  17930. $dom[$key]['self'] = false;
  17931. }
  17932. // copy some values from parent
  17933. $parentkey = 0;
  17934. if ($key > 0) {
  17935. $parentkey = $dom[$key]['parent'];
  17936. $dom[$key]['fontname'] = $dom[$parentkey]['fontname'];
  17937. $dom[$key]['fontstyle'] = $dom[$parentkey]['fontstyle'];
  17938. $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'];
  17939. $dom[$key]['font-stretch'] = $dom[$parentkey]['font-stretch'];
  17940. $dom[$key]['letter-spacing'] = $dom[$parentkey]['letter-spacing'];
  17941. $dom[$key]['stroke'] = $dom[$parentkey]['stroke'];
  17942. $dom[$key]['fill'] = $dom[$parentkey]['fill'];
  17943. $dom[$key]['clip'] = $dom[$parentkey]['clip'];
  17944. $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
  17945. $dom[$key]['bgcolor'] = $dom[$parentkey]['bgcolor'];
  17946. $dom[$key]['fgcolor'] = $dom[$parentkey]['fgcolor'];
  17947. $dom[$key]['strokecolor'] = $dom[$parentkey]['strokecolor'];
  17948. $dom[$key]['align'] = $dom[$parentkey]['align'];
  17949. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  17950. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  17951. $dom[$key]['border'] = array();
  17952. $dom[$key]['dir'] = $dom[$parentkey]['dir'];
  17953. }
  17954. // get attributes
  17955. preg_match_all('/([^=\s]*)[\s]*=[\s]*"([^"]*)"/', $element, $attr_array, PREG_PATTERN_ORDER);
  17956. $dom[$key]['attribute'] = array(); // reset attribute array
  17957. while (list($id, $name) = each($attr_array[1])) {
  17958. $dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id];
  17959. }
  17960. if (!empty($css)) {
  17961. // merge eternal CSS style to current style
  17962. $dom[$key]['attribute']['style'] = $this->getTagStyleFromCSS($dom, $key, $css);
  17963. }
  17964. // split style attributes
  17965. if (isset($dom[$key]['attribute']['style']) AND !empty($dom[$key]['attribute']['style'])) {
  17966. // get style attributes
  17967. preg_match_all('/([^;:\s]*):([^;]*)/', $dom[$key]['attribute']['style'], $style_array, PREG_PATTERN_ORDER);
  17968. $dom[$key]['style'] = array(); // reset style attribute array
  17969. while (list($id, $name) = each($style_array[1])) {
  17970. // in case of duplicate attribute the last replace the previous
  17971. $dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]);
  17972. }
  17973. // --- get some style attributes ---
  17974. // text direction
  17975. if (isset($dom[$key]['style']['direction'])) {
  17976. $dom[$key]['dir'] = $dom[$key]['style']['direction'];
  17977. }
  17978. // font family
  17979. if (isset($dom[$key]['style']['font-family'])) {
  17980. $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['style']['font-family']);
  17981. }
  17982. // list-style-type
  17983. if (isset($dom[$key]['style']['list-style-type'])) {
  17984. $dom[$key]['listtype'] = trim(strtolower($dom[$key]['style']['list-style-type']));
  17985. if ($dom[$key]['listtype'] == 'inherit') {
  17986. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  17987. }
  17988. }
  17989. // text-indent
  17990. if (isset($dom[$key]['style']['text-indent'])) {
  17991. $dom[$key]['text-indent'] = $this->getHTMLUnitToUnits($dom[$key]['style']['text-indent']);
  17992. if ($dom[$key]['text-indent'] == 'inherit') {
  17993. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  17994. }
  17995. }
  17996. // font size
  17997. if (isset($dom[$key]['style']['font-size'])) {
  17998. $fsize = trim($dom[$key]['style']['font-size']);
  17999. switch ($fsize) {
  18000. // absolute-size
  18001. case 'xx-small': {
  18002. $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 4;
  18003. break;
  18004. }
  18005. case 'x-small': {
  18006. $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 3;
  18007. break;
  18008. }
  18009. case 'small': {
  18010. $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 2;
  18011. break;
  18012. }
  18013. case 'medium': {
  18014. $dom[$key]['fontsize'] = $dom[0]['fontsize'];
  18015. break;
  18016. }
  18017. case 'large': {
  18018. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 2;
  18019. break;
  18020. }
  18021. case 'x-large': {
  18022. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 4;
  18023. break;
  18024. }
  18025. case 'xx-large': {
  18026. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 6;
  18027. break;
  18028. }
  18029. // relative-size
  18030. case 'smaller': {
  18031. $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'] - 3;
  18032. break;
  18033. }
  18034. case 'larger': {
  18035. $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'] + 3;
  18036. break;
  18037. }
  18038. default: {
  18039. $dom[$key]['fontsize'] = $this->getHTMLUnitToUnits($fsize, $dom[$parentkey]['fontsize'], 'pt', true);
  18040. }
  18041. }
  18042. }
  18043. // font-stretch
  18044. if (isset($dom[$key]['style']['font-stretch'])) {
  18045. $dom[$key]['font-stretch'] = $this->getCSSFontStretching($dom[$key]['style']['font-stretch'], $dom[$parentkey]['font-stretch']);
  18046. }
  18047. // letter-spacing
  18048. if (isset($dom[$key]['style']['letter-spacing'])) {
  18049. $dom[$key]['letter-spacing'] = $this->getCSSFontSpacing($dom[$key]['style']['letter-spacing'], $dom[$parentkey]['letter-spacing']);
  18050. }
  18051. // line-height
  18052. if (isset($dom[$key]['style']['line-height'])) {
  18053. $lineheight = trim($dom[$key]['style']['line-height']);
  18054. switch ($lineheight) {
  18055. // A normal line height. This is default
  18056. case 'normal': {
  18057. $dom[$key]['line-height'] = $dom[0]['line-height'];
  18058. break;
  18059. }
  18060. default: {
  18061. if (is_numeric($lineheight)) {
  18062. $lineheight = $lineheight * 100;
  18063. }
  18064. $dom[$key]['line-height'] = $this->getHTMLUnitToUnits($lineheight, 1, '%', true);
  18065. }
  18066. }
  18067. }
  18068. // font style
  18069. if (isset($dom[$key]['style']['font-weight'])) {
  18070. if (strtolower($dom[$key]['style']['font-weight']{0}) == 'n') {
  18071. $dom[$key]['fontstyle'] = '';
  18072. } elseif (strtolower($dom[$key]['style']['font-weight']{0}) == 'b') {
  18073. $dom[$key]['fontstyle'] .= 'B';
  18074. }
  18075. }
  18076. if (isset($dom[$key]['style']['font-style']) AND (strtolower($dom[$key]['style']['font-style']{0}) == 'i')) {
  18077. $dom[$key]['fontstyle'] .= 'I';
  18078. }
  18079. // font color
  18080. if (isset($dom[$key]['style']['color']) AND (!$this->empty_string($dom[$key]['style']['color']))) {
  18081. $dom[$key]['fgcolor'] = $this->convertHTMLColorToDec($dom[$key]['style']['color']);
  18082. } elseif ($dom[$key]['value'] == 'a') {
  18083. $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  18084. }
  18085. // background color
  18086. if (isset($dom[$key]['style']['background-color']) AND (!$this->empty_string($dom[$key]['style']['background-color']))) {
  18087. $dom[$key]['bgcolor'] = $this->convertHTMLColorToDec($dom[$key]['style']['background-color']);
  18088. }
  18089. // text-decoration
  18090. if (isset($dom[$key]['style']['text-decoration'])) {
  18091. $decors = explode(' ', strtolower($dom[$key]['style']['text-decoration']));
  18092. foreach ($decors as $dec) {
  18093. $dec = trim($dec);
  18094. if (!$this->empty_string($dec)) {
  18095. if ($dec{0} == 'u') {
  18096. // underline
  18097. $dom[$key]['fontstyle'] .= 'U';
  18098. } elseif ($dec{0} == 'l') {
  18099. // line-trough
  18100. $dom[$key]['fontstyle'] .= 'D';
  18101. } elseif ($dec{0} == 'o') {
  18102. // overline
  18103. $dom[$key]['fontstyle'] .= 'O';
  18104. }
  18105. }
  18106. }
  18107. } elseif ($dom[$key]['value'] == 'a') {
  18108. $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  18109. }
  18110. // check for width attribute
  18111. if (isset($dom[$key]['style']['width'])) {
  18112. $dom[$key]['width'] = $dom[$key]['style']['width'];
  18113. }
  18114. // check for height attribute
  18115. if (isset($dom[$key]['style']['height'])) {
  18116. $dom[$key]['height'] = $dom[$key]['style']['height'];
  18117. }
  18118. // check for text alignment
  18119. if (isset($dom[$key]['style']['text-align'])) {
  18120. $dom[$key]['align'] = strtoupper($dom[$key]['style']['text-align']{0});
  18121. }
  18122. // check for CSS border properties
  18123. if (isset($dom[$key]['style']['border'])) {
  18124. $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border']);
  18125. if (!empty($borderstyle)) {
  18126. $dom[$key]['border']['LTRB'] = $borderstyle;
  18127. }
  18128. }
  18129. if (isset($dom[$key]['style']['border-color'])) {
  18130. $brd_colors = preg_split('/[\s]+/', trim($dom[$key]['style']['border-color']));
  18131. if (isset($brd_colors[3])) {
  18132. $dom[$key]['border']['L']['color'] = $this->convertHTMLColorToDec($brd_colors[3]);
  18133. }
  18134. if (isset($brd_colors[1])) {
  18135. $dom[$key]['border']['R']['color'] = $this->convertHTMLColorToDec($brd_colors[1]);
  18136. }
  18137. if (isset($brd_colors[0])) {
  18138. $dom[$key]['border']['T']['color'] = $this->convertHTMLColorToDec($brd_colors[0]);
  18139. }
  18140. if (isset($brd_colors[2])) {
  18141. $dom[$key]['border']['B']['color'] = $this->convertHTMLColorToDec($brd_colors[2]);
  18142. }
  18143. }
  18144. if (isset($dom[$key]['style']['border-width'])) {
  18145. $brd_widths = preg_split('/[\s]+/', trim($dom[$key]['style']['border-width']));
  18146. if (isset($brd_widths[3])) {
  18147. $dom[$key]['border']['L']['width'] = $this->getCSSBorderWidth($brd_widths[3]);
  18148. }
  18149. if (isset($brd_widths[1])) {
  18150. $dom[$key]['border']['R']['width'] = $this->getCSSBorderWidth($brd_widths[1]);
  18151. }
  18152. if (isset($brd_widths[0])) {
  18153. $dom[$key]['border']['T']['width'] = $this->getCSSBorderWidth($brd_widths[0]);
  18154. }
  18155. if (isset($brd_widths[2])) {
  18156. $dom[$key]['border']['B']['width'] = $this->getCSSBorderWidth($brd_widths[2]);
  18157. }
  18158. }
  18159. if (isset($dom[$key]['style']['border-style'])) {
  18160. $brd_styles = preg_split('/[\s]+/', trim($dom[$key]['style']['border-style']));
  18161. if (isset($brd_styles[3])) {
  18162. $dom[$key]['border']['L']['cap'] = 'square';
  18163. $dom[$key]['border']['L']['join'] = 'miter';
  18164. $dom[$key]['border']['L']['dash'] = $this->getCSSBorderDashStyle($brd_styles[3]);
  18165. if ($dom[$key]['border']['L']['dash'] < 0) {
  18166. $dom[$key]['border']['L'] = array();
  18167. }
  18168. }
  18169. if (isset($brd_styles[1])) {
  18170. $dom[$key]['border']['R']['cap'] = 'square';
  18171. $dom[$key]['border']['R']['join'] = 'miter';
  18172. $dom[$key]['border']['R']['dash'] = $this->getCSSBorderDashStyle($brd_styles[1]);
  18173. if ($dom[$key]['border']['R']['dash'] < 0) {
  18174. $dom[$key]['border']['R'] = array();
  18175. }
  18176. }
  18177. if (isset($brd_styles[0])) {
  18178. $dom[$key]['border']['T']['cap'] = 'square';
  18179. $dom[$key]['border']['T']['join'] = 'miter';
  18180. $dom[$key]['border']['T']['dash'] = $this->getCSSBorderDashStyle($brd_styles[0]);
  18181. if ($dom[$key]['border']['T']['dash'] < 0) {
  18182. $dom[$key]['border']['T'] = array();
  18183. }
  18184. }
  18185. if (isset($brd_styles[2])) {
  18186. $dom[$key]['border']['B']['cap'] = 'square';
  18187. $dom[$key]['border']['B']['join'] = 'miter';
  18188. $dom[$key]['border']['B']['dash'] = $this->getCSSBorderDashStyle($brd_styles[2]);
  18189. if ($dom[$key]['border']['B']['dash'] < 0) {
  18190. $dom[$key]['border']['B'] = array();
  18191. }
  18192. }
  18193. }
  18194. $cellside = array('L' => 'left', 'R' => 'right', 'T' => 'top', 'B' => 'bottom');
  18195. foreach ($cellside as $bsk => $bsv) {
  18196. if (isset($dom[$key]['style']['border-'.$bsv])) {
  18197. $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border-'.$bsv]);
  18198. if (!empty($borderstyle)) {
  18199. $dom[$key]['border'][$bsk] = $borderstyle;
  18200. }
  18201. }
  18202. if (isset($dom[$key]['style']['border-'.$bsv.'-color'])) {
  18203. $dom[$key]['border'][$bsk]['color'] = $this->convertHTMLColorToDec($dom[$key]['style']['border-'.$bsv.'-color']);
  18204. }
  18205. if (isset($dom[$key]['style']['border-'.$bsv.'-width'])) {
  18206. $dom[$key]['border'][$bsk]['width'] = $this->getCSSBorderWidth($dom[$key]['style']['border-'.$bsv.'-width']);
  18207. }
  18208. if (isset($dom[$key]['style']['border-'.$bsv.'-style'])) {
  18209. $dom[$key]['border'][$bsk]['dash'] = $this->getCSSBorderDashStyle($dom[$key]['style']['border-'.$bsv.'-style']);
  18210. if ($dom[$key]['border'][$bsk]['dash'] < 0) {
  18211. $dom[$key]['border'][$bsk] = array();
  18212. }
  18213. }
  18214. }
  18215. // check for CSS padding properties
  18216. if (isset($dom[$key]['style']['padding'])) {
  18217. $dom[$key]['padding'] = $this->getCSSPadding($dom[$key]['style']['padding']);
  18218. } else {
  18219. $dom[$key]['padding'] = $this->cell_padding;
  18220. }
  18221. foreach ($cellside as $psk => $psv) {
  18222. if (isset($dom[$key]['style']['padding-'.$psv])) {
  18223. $dom[$key]['padding'][$psk] = $this->getHTMLUnitToUnits($dom[$key]['style']['padding-'.$psv], 0, 'px', false);
  18224. }
  18225. }
  18226. // check for CSS margin properties
  18227. if (isset($dom[$key]['style']['margin'])) {
  18228. $dom[$key]['margin'] = $this->getCSSMargin($dom[$key]['style']['margin']);
  18229. } else {
  18230. $dom[$key]['margin'] = $this->cell_margin;
  18231. }
  18232. foreach ($cellside as $psk => $psv) {
  18233. if (isset($dom[$key]['style']['margin-'.$psv])) {
  18234. $dom[$key]['margin'][$psk] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $dom[$key]['style']['margin-'.$psv]), 0, 'px', false);
  18235. }
  18236. }
  18237. // check for CSS border-spacing properties
  18238. if (isset($dom[$key]['style']['border-spacing'])) {
  18239. $dom[$key]['border-spacing'] = $this->getCSSBorderMargin($dom[$key]['style']['border-spacing']);
  18240. }
  18241. // page-break-inside
  18242. if (isset($dom[$key]['style']['page-break-inside']) AND ($dom[$key]['style']['page-break-inside'] == 'avoid')) {
  18243. $dom[$key]['attribute']['nobr'] = 'true';
  18244. }
  18245. // page-break-before
  18246. if (isset($dom[$key]['style']['page-break-before'])) {
  18247. if ($dom[$key]['style']['page-break-before'] == 'always') {
  18248. $dom[$key]['attribute']['pagebreak'] = 'true';
  18249. } elseif ($dom[$key]['style']['page-break-before'] == 'left') {
  18250. $dom[$key]['attribute']['pagebreak'] = 'left';
  18251. } elseif ($dom[$key]['style']['page-break-before'] == 'right') {
  18252. $dom[$key]['attribute']['pagebreak'] = 'right';
  18253. }
  18254. }
  18255. // page-break-after
  18256. if (isset($dom[$key]['style']['page-break-after'])) {
  18257. if ($dom[$key]['style']['page-break-after'] == 'always') {
  18258. $dom[$key]['attribute']['pagebreakafter'] = 'true';
  18259. } elseif ($dom[$key]['style']['page-break-after'] == 'left') {
  18260. $dom[$key]['attribute']['pagebreakafter'] = 'left';
  18261. } elseif ($dom[$key]['style']['page-break-after'] == 'right') {
  18262. $dom[$key]['attribute']['pagebreakafter'] = 'right';
  18263. }
  18264. }
  18265. }
  18266. if (isset($dom[$key]['attribute']['border']) AND ($dom[$key]['attribute']['border'] != 0)) {
  18267. $borderstyle = $this->getCSSBorderStyle($dom[$key]['attribute']['border'].' solid black');
  18268. if (!empty($borderstyle)) {
  18269. $dom[$key]['border']['LTRB'] = $borderstyle;
  18270. }
  18271. }
  18272. // check for font tag
  18273. if ($dom[$key]['value'] == 'font') {
  18274. // font family
  18275. if (isset($dom[$key]['attribute']['face'])) {
  18276. $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['attribute']['face']);
  18277. }
  18278. // font size
  18279. if (isset($dom[$key]['attribute']['size'])) {
  18280. if ($key > 0) {
  18281. if ($dom[$key]['attribute']['size']{0} == '+') {
  18282. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] + intval(substr($dom[$key]['attribute']['size'], 1));
  18283. } elseif ($dom[$key]['attribute']['size']{0} == '-') {
  18284. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] - intval(substr($dom[$key]['attribute']['size'], 1));
  18285. } else {
  18286. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  18287. }
  18288. } else {
  18289. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  18290. }
  18291. }
  18292. }
  18293. // force natural alignment for lists
  18294. if ((($dom[$key]['value'] == 'ul') OR ($dom[$key]['value'] == 'ol') OR ($dom[$key]['value'] == 'dl'))
  18295. AND (!isset($dom[$key]['align']) OR $this->empty_string($dom[$key]['align']) OR ($dom[$key]['align'] != 'J'))) {
  18296. if ($this->rtl) {
  18297. $dom[$key]['align'] = 'R';
  18298. } else {
  18299. $dom[$key]['align'] = 'L';
  18300. }
  18301. }
  18302. if (($dom[$key]['value'] == 'small') OR ($dom[$key]['value'] == 'sup') OR ($dom[$key]['value'] == 'sub')) {
  18303. if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
  18304. $dom[$key]['fontsize'] = $dom[$key]['fontsize'] * K_SMALL_RATIO;
  18305. }
  18306. }
  18307. if (($dom[$key]['value'] == 'strong') OR ($dom[$key]['value'] == 'b')) {
  18308. $dom[$key]['fontstyle'] .= 'B';
  18309. }
  18310. if (($dom[$key]['value'] == 'em') OR ($dom[$key]['value'] == 'i')) {
  18311. $dom[$key]['fontstyle'] .= 'I';
  18312. }
  18313. if ($dom[$key]['value'] == 'u') {
  18314. $dom[$key]['fontstyle'] .= 'U';
  18315. }
  18316. if (($dom[$key]['value'] == 'del') OR ($dom[$key]['value'] == 's') OR ($dom[$key]['value'] == 'strike')) {
  18317. $dom[$key]['fontstyle'] .= 'D';
  18318. }
  18319. if (!isset($dom[$key]['style']['text-decoration']) AND ($dom[$key]['value'] == 'a')) {
  18320. $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  18321. }
  18322. if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) {
  18323. $dom[$key]['fontname'] = $this->default_monospaced_font;
  18324. }
  18325. if (($dom[$key]['value']{0} == 'h') AND (intval($dom[$key]['value']{1}) > 0) AND (intval($dom[$key]['value']{1}) < 7)) {
  18326. // headings h1, h2, h3, h4, h5, h6
  18327. if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
  18328. $headsize = (4 - intval($dom[$key]['value']{1})) * 2;
  18329. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + $headsize;
  18330. }
  18331. if (!isset($dom[$key]['style']['font-weight'])) {
  18332. $dom[$key]['fontstyle'] .= 'B';
  18333. }
  18334. }
  18335. if (($dom[$key]['value'] == 'table')) {
  18336. $dom[$key]['rows'] = 0; // number of rows
  18337. $dom[$key]['trids'] = array(); // IDs of TR elements
  18338. $dom[$key]['thead'] = ''; // table header rows
  18339. }
  18340. if (($dom[$key]['value'] == 'tr')) {
  18341. $dom[$key]['cols'] = 0;
  18342. if ($thead) {
  18343. $dom[$key]['thead'] = true;
  18344. // rows on thead block are printed as a separate table
  18345. } else {
  18346. $dom[$key]['thead'] = false;
  18347. // store the number of rows on table element
  18348. ++$dom[($dom[$key]['parent'])]['rows'];
  18349. // store the TR elements IDs on table element
  18350. array_push($dom[($dom[$key]['parent'])]['trids'], $key);
  18351. }
  18352. }
  18353. if (($dom[$key]['value'] == 'th') OR ($dom[$key]['value'] == 'td')) {
  18354. if (isset($dom[$key]['attribute']['colspan'])) {
  18355. $colspan = intval($dom[$key]['attribute']['colspan']);
  18356. } else {
  18357. $colspan = 1;
  18358. }
  18359. $dom[$key]['attribute']['colspan'] = $colspan;
  18360. $dom[($dom[$key]['parent'])]['cols'] += $colspan;
  18361. }
  18362. // text direction
  18363. if (isset($dom[$key]['attribute']['dir'])) {
  18364. $dom[$key]['dir'] = $dom[$key]['attribute']['dir'];
  18365. }
  18366. // set foreground color attribute
  18367. if (isset($dom[$key]['attribute']['color']) AND (!$this->empty_string($dom[$key]['attribute']['color']))) {
  18368. $dom[$key]['fgcolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['color']);
  18369. } elseif (!isset($dom[$key]['style']['color']) AND ($dom[$key]['value'] == 'a')) {
  18370. $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  18371. }
  18372. // set background color attribute
  18373. if (isset($dom[$key]['attribute']['bgcolor']) AND (!$this->empty_string($dom[$key]['attribute']['bgcolor']))) {
  18374. $dom[$key]['bgcolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['bgcolor']);
  18375. }
  18376. // set stroke color attribute
  18377. if (isset($dom[$key]['attribute']['strokecolor']) AND (!$this->empty_string($dom[$key]['attribute']['strokecolor']))) {
  18378. $dom[$key]['strokecolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['strokecolor']);
  18379. }
  18380. // check for width attribute
  18381. if (isset($dom[$key]['attribute']['width'])) {
  18382. $dom[$key]['width'] = $dom[$key]['attribute']['width'];
  18383. }
  18384. // check for height attribute
  18385. if (isset($dom[$key]['attribute']['height'])) {
  18386. $dom[$key]['height'] = $dom[$key]['attribute']['height'];
  18387. }
  18388. // check for text alignment
  18389. if (isset($dom[$key]['attribute']['align']) AND (!$this->empty_string($dom[$key]['attribute']['align'])) AND ($dom[$key]['value'] !== 'img')) {
  18390. $dom[$key]['align'] = strtoupper($dom[$key]['attribute']['align']{0});
  18391. }
  18392. // check for text rendering mode (the following attributes do not exist in HTML)
  18393. if (isset($dom[$key]['attribute']['stroke'])) {
  18394. // font stroke width
  18395. $dom[$key]['stroke'] = $this->getHTMLUnitToUnits($dom[$key]['attribute']['stroke'], $dom[$key]['fontsize'], 'pt', true);
  18396. }
  18397. if (isset($dom[$key]['attribute']['fill'])) {
  18398. // font fill
  18399. if ($dom[$key]['attribute']['fill'] == 'true') {
  18400. $dom[$key]['fill'] = true;
  18401. } else {
  18402. $dom[$key]['fill'] = false;
  18403. }
  18404. }
  18405. if (isset($dom[$key]['attribute']['clip'])) {
  18406. // clipping mode
  18407. if ($dom[$key]['attribute']['clip'] == 'true') {
  18408. $dom[$key]['clip'] = true;
  18409. } else {
  18410. $dom[$key]['clip'] = false;
  18411. }
  18412. }
  18413. } // end opening tag
  18414. } else {
  18415. // text
  18416. $dom[$key]['tag'] = false;
  18417. $dom[$key]['block'] = false;
  18418. $element = str_replace('$nbsp;', $this->unichr(160), $element);
  18419. $dom[$key]['value'] = stripslashes($this->unhtmlentities($element));
  18420. $dom[$key]['parent'] = end($level);
  18421. $dom[$key]['dir'] = $dom[$dom[$key]['parent']]['dir'];
  18422. }
  18423. ++$elkey;
  18424. ++$key;
  18425. }
  18426. return $dom;
  18427. }
  18428. /**
  18429. * Returns the string used to find spaces
  18430. * @return string
  18431. * @protected
  18432. * @author Nicola Asuni
  18433. * @since 4.8.024 (2010-01-15)
  18434. */
  18435. protected function getSpaceString() {
  18436. $spacestr = chr(32);
  18437. if ($this->isUnicodeFont()) {
  18438. $spacestr = chr(0).chr(32);
  18439. }
  18440. return $spacestr;
  18441. }
  18442. /**
  18443. * Prints a cell (rectangular area) with optional borders, background color and html text string.
  18444. * 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 />
  18445. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  18446. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  18447. * @param $h (float) Cell minimum height. The cell extends automatically if needed.
  18448. * @param $x (float) upper-left corner X coordinate
  18449. * @param $y (float) upper-left corner Y coordinate
  18450. * @param $html (string) html text to print. Default value: empty string.
  18451. * @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)))
  18452. * @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>
  18453. Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  18454. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  18455. * @param $reseth (boolean) if true reset the last cell height (default true).
  18456. * @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>
  18457. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width.
  18458. * @see Multicell(), writeHTML()
  18459. * @public
  18460. */
  18461. public function writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true) {
  18462. return $this->MultiCell($w, $h, $html, $border, $align, $fill, $ln, $x, $y, $reseth, 0, true, $autopadding, 0);
  18463. }
  18464. /**
  18465. * Allows to preserve some HTML formatting (limited support).<br />
  18466. * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  18467. * 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
  18468. * @param $html (string) text to display
  18469. * @param $ln (boolean) if true add a new line after text (default = true)
  18470. * @param $fill (boolean) Indicates if the background must be painted (true) or transparent (false).
  18471. * @param $reseth (boolean) if true reset the last cell height (default false).
  18472. * @param $cell (boolean) if true add the current left (or right for RTL) padding to each Write (default false).
  18473. * @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>
  18474. * @public
  18475. */
  18476. public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='') {
  18477. $gvars = $this->getGraphicVars();
  18478. // store current values
  18479. $prev_cell_margin = $this->cell_margin;
  18480. $prev_cell_padding = $this->cell_padding;
  18481. $prevPage = $this->page;
  18482. $prevlMargin = $this->lMargin;
  18483. $prevrMargin = $this->rMargin;
  18484. $curfontname = $this->FontFamily;
  18485. $curfontstyle = $this->FontStyle;
  18486. $curfontsize = $this->FontSizePt;
  18487. $curfontascent = $this->getFontAscent($curfontname, $curfontstyle, $curfontsize);
  18488. $curfontdescent = $this->getFontDescent($curfontname, $curfontstyle, $curfontsize);
  18489. $curfontstretcing = $this->font_stretching;
  18490. $curfontkerning = $this->font_spacing;
  18491. $this->newline = true;
  18492. $newline = true;
  18493. $startlinepage = $this->page;
  18494. $minstartliney = $this->y;
  18495. $maxbottomliney = 0;
  18496. $startlinex = $this->x;
  18497. $startliney = $this->y;
  18498. $yshift = 0;
  18499. $loop = 0;
  18500. $curpos = 0;
  18501. $this_method_vars = array();
  18502. $undo = false;
  18503. $fontaligned = false;
  18504. $reverse_dir = false; // true when the text direction is reversed
  18505. $this->premode = false;
  18506. if ($this->inxobj) {
  18507. // we are inside an XObject template
  18508. $pask = count($this->xobjects[$this->xobjid]['annotations']);
  18509. } elseif (isset($this->PageAnnots[$this->page])) {
  18510. $pask = count($this->PageAnnots[$this->page]);
  18511. } else {
  18512. $pask = 0;
  18513. }
  18514. if ($this->inxobj) {
  18515. // we are inside an XObject template
  18516. $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
  18517. } elseif (!$this->InFooter) {
  18518. if (isset($this->footerlen[$this->page])) {
  18519. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  18520. } else {
  18521. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  18522. }
  18523. $startlinepos = $this->footerpos[$this->page];
  18524. } else {
  18525. // we are inside the footer
  18526. $startlinepos = $this->pagelen[$this->page];
  18527. }
  18528. $lalign = $align;
  18529. $plalign = $align;
  18530. if ($this->rtl) {
  18531. $w = $this->x - $this->lMargin;
  18532. } else {
  18533. $w = $this->w - $this->rMargin - $this->x;
  18534. }
  18535. $w -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  18536. if ($cell) {
  18537. if ($this->rtl) {
  18538. $this->x -= $this->cell_padding['R'];
  18539. $this->lMargin += $this->cell_padding['R'];
  18540. } else {
  18541. $this->x += $this->cell_padding['L'];
  18542. $this->rMargin += $this->cell_padding['L'];
  18543. }
  18544. }
  18545. if ($this->customlistindent >= 0) {
  18546. $this->listindent = $this->customlistindent;
  18547. } else {
  18548. $this->listindent = $this->GetStringWidth('000000');
  18549. }
  18550. $this->listindentlevel = 0;
  18551. // save previous states
  18552. $prev_cell_height_ratio = $this->cell_height_ratio;
  18553. $prev_listnum = $this->listnum;
  18554. $prev_listordered = $this->listordered;
  18555. $prev_listcount = $this->listcount;
  18556. $prev_lispacer = $this->lispacer;
  18557. $this->listnum = 0;
  18558. $this->listordered = array();
  18559. $this->listcount = array();
  18560. $this->lispacer = '';
  18561. if (($this->empty_string($this->lasth)) OR ($reseth)) {
  18562. // reset row height
  18563. $this->resetLastH();
  18564. }
  18565. $dom = $this->getHtmlDomArray($html);
  18566. $maxel = count($dom);
  18567. $key = 0;
  18568. while ($key < $maxel) {
  18569. if ($dom[$key]['tag'] AND isset($dom[$key]['attribute']['pagebreak'])) {
  18570. // check for pagebreak
  18571. if (($dom[$key]['attribute']['pagebreak'] == 'true') OR ($dom[$key]['attribute']['pagebreak'] == 'left') OR ($dom[$key]['attribute']['pagebreak'] == 'right')) {
  18572. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18573. $this->checkPageBreak($this->PageBreakTrigger + 1);
  18574. }
  18575. if ((($dom[$key]['attribute']['pagebreak'] == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  18576. OR (($dom[$key]['attribute']['pagebreak'] == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  18577. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18578. $this->checkPageBreak($this->PageBreakTrigger + 1);
  18579. }
  18580. }
  18581. if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND isset($dom[$key]['attribute']['nobr']) AND ($dom[$key]['attribute']['nobr'] == 'true')) {
  18582. if (isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) {
  18583. $dom[$key]['attribute']['nobr'] = false;
  18584. } else {
  18585. // store current object
  18586. $this->startTransaction();
  18587. // save this method vars
  18588. $this_method_vars['html'] = $html;
  18589. $this_method_vars['ln'] = $ln;
  18590. $this_method_vars['fill'] = $fill;
  18591. $this_method_vars['reseth'] = $reseth;
  18592. $this_method_vars['cell'] = $cell;
  18593. $this_method_vars['align'] = $align;
  18594. $this_method_vars['gvars'] = $gvars;
  18595. $this_method_vars['prevPage'] = $prevPage;
  18596. $this_method_vars['prev_cell_margin'] = $prev_cell_margin;
  18597. $this_method_vars['prev_cell_padding'] = $prev_cell_padding;
  18598. $this_method_vars['prevlMargin'] = $prevlMargin;
  18599. $this_method_vars['prevrMargin'] = $prevrMargin;
  18600. $this_method_vars['curfontname'] = $curfontname;
  18601. $this_method_vars['curfontstyle'] = $curfontstyle;
  18602. $this_method_vars['curfontsize'] = $curfontsize;
  18603. $this_method_vars['curfontascent'] = $curfontascent;
  18604. $this_method_vars['curfontdescent'] = $curfontdescent;
  18605. $this_method_vars['curfontstretcing'] = $curfontstretcing;
  18606. $this_method_vars['curfontkerning'] = $curfontkerning;
  18607. $this_method_vars['minstartliney'] = $minstartliney;
  18608. $this_method_vars['maxbottomliney'] = $maxbottomliney;
  18609. $this_method_vars['yshift'] = $yshift;
  18610. $this_method_vars['startlinepage'] = $startlinepage;
  18611. $this_method_vars['startlinepos'] = $startlinepos;
  18612. $this_method_vars['startlinex'] = $startlinex;
  18613. $this_method_vars['startliney'] = $startliney;
  18614. $this_method_vars['newline'] = $newline;
  18615. $this_method_vars['loop'] = $loop;
  18616. $this_method_vars['curpos'] = $curpos;
  18617. $this_method_vars['pask'] = $pask;
  18618. $this_method_vars['lalign'] = $lalign;
  18619. $this_method_vars['plalign'] = $plalign;
  18620. $this_method_vars['w'] = $w;
  18621. $this_method_vars['prev_cell_height_ratio'] = $prev_cell_height_ratio;
  18622. $this_method_vars['prev_listnum'] = $prev_listnum;
  18623. $this_method_vars['prev_listordered'] = $prev_listordered;
  18624. $this_method_vars['prev_listcount'] = $prev_listcount;
  18625. $this_method_vars['prev_lispacer'] = $prev_lispacer;
  18626. $this_method_vars['fontaligned'] = $fontaligned;
  18627. $this_method_vars['key'] = $key;
  18628. $this_method_vars['dom'] = $dom;
  18629. }
  18630. }
  18631. // print THEAD block
  18632. if (($dom[$key]['value'] == 'tr') AND isset($dom[$key]['thead']) AND $dom[$key]['thead']) {
  18633. if (isset($dom[$key]['parent']) AND isset($dom[$dom[$key]['parent']]['thead']) AND !$this->empty_string($dom[$dom[$key]['parent']]['thead'])) {
  18634. $this->inthead = true;
  18635. // print table header (thead)
  18636. $this->writeHTML($this->thead, false, false, false, false, '');
  18637. // check if we are on a new page or on a new column
  18638. if (($this->y < $this->start_transaction_y) OR ($this->checkPageBreak($this->lasth, '', false))) {
  18639. // we are on a new page or on a new column and the total object height is less than the available vertical space.
  18640. // restore previous object
  18641. $this->rollbackTransaction(true);
  18642. // restore previous values
  18643. foreach ($this_method_vars as $vkey => $vval) {
  18644. $$vkey = $vval;
  18645. }
  18646. // disable table header
  18647. $tmp_thead = $this->thead;
  18648. $this->thead = '';
  18649. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18650. $pre_y = $this->y;
  18651. if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
  18652. // fix for multicolumn mode
  18653. $startliney = $this->y;
  18654. }
  18655. $this->start_transaction_page = $this->page;
  18656. $this->start_transaction_y = $this->y;
  18657. // restore table header
  18658. $this->thead = $tmp_thead;
  18659. // fix table border properties
  18660. if (isset($dom[$dom[$key]['parent']]['attribute']['cellspacing'])) {
  18661. $tmp_cellspacing = $this->getHTMLUnitToUnits($dom[$dom[$key]['parent']]['attribute']['cellspacing'], 1, 'px');
  18662. } elseif (isset($dom[$dom[$key]['parent']]['border-spacing'])) {
  18663. $tmp_cellspacing = $dom[$dom[$key]['parent']]['border-spacing']['V'];
  18664. } else {
  18665. $tmp_cellspacing = 0;
  18666. }
  18667. $dom[$dom[$key]['parent']]['borderposition']['page'] = $this->page;
  18668. $dom[$dom[$key]['parent']]['borderposition']['column'] = $this->current_column;
  18669. $dom[$dom[$key]['parent']]['borderposition']['y'] = $this->y + $tmp_cellspacing;
  18670. $xoffset = ($this->x - $dom[$dom[$key]['parent']]['borderposition']['x']);
  18671. $dom[$dom[$key]['parent']]['borderposition']['x'] += $xoffset;
  18672. $dom[$dom[$key]['parent']]['borderposition']['xmax'] += $xoffset;
  18673. // print table header (thead)
  18674. $this->writeHTML($this->thead, false, false, false, false, '');
  18675. }
  18676. }
  18677. // move $key index forward to skip THEAD block
  18678. while ( ($key < $maxel) AND (!(
  18679. ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'tr') AND (!isset($dom[$key]['thead']) OR !$dom[$key]['thead']))
  18680. OR ($dom[$key]['tag'] AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == 'table'))) )) {
  18681. ++$key;
  18682. }
  18683. }
  18684. if ($dom[$key]['tag'] OR ($key == 0)) {
  18685. if ((($dom[$key]['value'] == 'table') OR ($dom[$key]['value'] == 'tr')) AND (isset($dom[$key]['align']))) {
  18686. $dom[$key]['align'] = ($this->rtl) ? 'R' : 'L';
  18687. }
  18688. // vertically align image in line
  18689. if ((!$this->newline) AND ($dom[$key]['value'] == 'img') AND (isset($dom[$key]['height'])) AND ($dom[$key]['height'] > 0)) {
  18690. // get image height
  18691. $imgh = $this->getHTMLUnitToUnits($dom[$key]['height'], $this->lasth, 'px');
  18692. $autolinebreak = false;
  18693. if (isset($dom[$key]['width']) AND ($dom[$key]['width'] > 0)) {
  18694. $imgw = $this->getHTMLUnitToUnits($dom[$key]['width'], 1, 'px', false);
  18695. if (($imgw <= ($this->w - $this->lMargin - $this->rMargin - $this->cell_padding['L'] - $this->cell_padding['R']))
  18696. AND ((($this->rtl) AND (($this->x - $imgw) < ($this->lMargin + $this->cell_padding['L'])))
  18697. OR ((!$this->rtl) AND (($this->x + $imgw) > ($this->w - $this->rMargin - $this->cell_padding['R']))))) {
  18698. // add automatic line break
  18699. $autolinebreak = true;
  18700. $this->Ln('', $cell);
  18701. if ((!$dom[($key-1)]['tag']) AND ($dom[($key-1)]['value'] == ' ')) {
  18702. // go back to evaluate this line break
  18703. --$key;
  18704. }
  18705. }
  18706. }
  18707. if (!$autolinebreak) {
  18708. if (!$this->InFooter) {
  18709. $pre_y = $this->y;
  18710. // check for page break
  18711. if ((!$this->checkPageBreak($imgh)) AND ($this->y < $pre_y)) {
  18712. // fix for multicolumn mode
  18713. $startliney = $this->y;
  18714. }
  18715. }
  18716. if ($this->page > $startlinepage) {
  18717. // fix line splitted over two pages
  18718. if (isset($this->footerlen[$startlinepage])) {
  18719. $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  18720. }
  18721. // line to be moved one page forward
  18722. $pagebuff = $this->getPageBuffer($startlinepage);
  18723. $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
  18724. $tstart = substr($pagebuff, 0, $startlinepos);
  18725. $tend = substr($this->getPageBuffer($startlinepage), $curpos);
  18726. // remove line from previous page
  18727. $this->setPageBuffer($startlinepage, $tstart.''.$tend);
  18728. $pagebuff = $this->getPageBuffer($this->page);
  18729. $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
  18730. $tend = substr($pagebuff, $this->cntmrk[$this->page]);
  18731. // add line start to current page
  18732. $yshift = $minstartliney - $this->y;
  18733. if ($fontaligned) {
  18734. $yshift += ($curfontsize / $this->k);
  18735. }
  18736. $try = sprintf('1 0 0 1 0 %.3F cm', ($yshift * $this->k));
  18737. $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  18738. // shift the annotations and links
  18739. if (isset($this->PageAnnots[$this->page])) {
  18740. $next_pask = count($this->PageAnnots[$this->page]);
  18741. } else {
  18742. $next_pask = 0;
  18743. }
  18744. if (isset($this->PageAnnots[$startlinepage])) {
  18745. foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
  18746. if ($pak >= $pask) {
  18747. $this->PageAnnots[$this->page][] = $pac;
  18748. unset($this->PageAnnots[$startlinepage][$pak]);
  18749. $npak = count($this->PageAnnots[$this->page]) - 1;
  18750. $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  18751. }
  18752. }
  18753. }
  18754. $pask = $next_pask;
  18755. $startlinepos = $this->cntmrk[$this->page];
  18756. $startlinepage = $this->page;
  18757. $startliney = $this->y;
  18758. $this->newline = false;
  18759. }
  18760. $this->y += ((($curfontsize * $this->cell_height_ratio / $this->k) + $curfontascent - $curfontdescent) / 2) - $imgh;
  18761. $minstartliney = min($this->y, $minstartliney);
  18762. $maxbottomliney = ($startliney + ($this->FontSize * $this->cell_height_ratio));
  18763. }
  18764. } elseif (isset($dom[$key]['fontname']) OR isset($dom[$key]['fontstyle']) OR isset($dom[$key]['fontsize']) OR isset($dom[$key]['line-height'])) {
  18765. // account for different font size
  18766. $pfontname = $curfontname;
  18767. $pfontstyle = $curfontstyle;
  18768. $pfontsize = $curfontsize;
  18769. $fontname = isset($dom[$key]['fontname']) ? $dom[$key]['fontname'] : $curfontname;
  18770. $fontstyle = isset($dom[$key]['fontstyle']) ? $dom[$key]['fontstyle'] : $curfontstyle;
  18771. $fontsize = isset($dom[$key]['fontsize']) ? $dom[$key]['fontsize'] : $curfontsize;
  18772. $fontascent = $this->getFontAscent($fontname, $fontstyle, $fontsize);
  18773. $fontdescent = $this->getFontDescent($fontname, $fontstyle, $fontsize);
  18774. if ( ($fontname != $curfontname) OR ($fontstyle != $curfontstyle) OR ($fontsize != $curfontsize)
  18775. OR ($this->cell_height_ratio != $dom[$key]['line-height'])
  18776. OR ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li')) ) {
  18777. if ((!$this->newline) AND ($key < ($maxel - 1))
  18778. AND ( (is_numeric($fontsize) AND ($fontsize >= 0) AND is_numeric($curfontsize) AND ($curfontsize >= 0) AND ($fontsize != $curfontsize))
  18779. OR ($this->cell_height_ratio != $dom[$key]['line-height']))
  18780. OR ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li')) ) {
  18781. if ($this->page > $startlinepage) {
  18782. // fix lines splitted over two pages
  18783. if (isset($this->footerlen[$startlinepage])) {
  18784. $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  18785. }
  18786. // line to be moved one page forward
  18787. $pagebuff = $this->getPageBuffer($startlinepage);
  18788. $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
  18789. $tstart = substr($pagebuff, 0, $startlinepos);
  18790. $tend = substr($this->getPageBuffer($startlinepage), $curpos);
  18791. // remove line start from previous page
  18792. $this->setPageBuffer($startlinepage, $tstart.''.$tend);
  18793. $pagebuff = $this->getPageBuffer($this->page);
  18794. $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
  18795. $tend = substr($pagebuff, $this->cntmrk[$this->page]);
  18796. // add line start to current page
  18797. $yshift = $minstartliney - $this->y;
  18798. $try = sprintf('1 0 0 1 0 %.3F cm', ($yshift * $this->k));
  18799. $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  18800. // shift the annotations and links
  18801. if (isset($this->PageAnnots[$this->page])) {
  18802. $next_pask = count($this->PageAnnots[$this->page]);
  18803. } else {
  18804. $next_pask = 0;
  18805. }
  18806. if (isset($this->PageAnnots[$startlinepage])) {
  18807. foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
  18808. if ($pak >= $pask) {
  18809. $this->PageAnnots[$this->page][] = $pac;
  18810. unset($this->PageAnnots[$startlinepage][$pak]);
  18811. $npak = count($this->PageAnnots[$this->page]) - 1;
  18812. $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  18813. }
  18814. }
  18815. }
  18816. $pask = $next_pask;
  18817. $startlinepos = $this->cntmrk[$this->page];
  18818. $startlinepage = $this->page;
  18819. $startliney = $this->y;
  18820. }
  18821. if (!isset($dom[$key]['line-height'])) {
  18822. $dom[$key]['line-height'] = $this->cell_height_ratio;
  18823. }
  18824. if (!$dom[$key]['block']) {
  18825. $this->y += (((($curfontsize * $this->cell_height_ratio ) - ($fontsize * $dom[$key]['line-height'])) / $this->k) + $curfontascent - $fontascent - $curfontdescent + $fontdescent) / 2;
  18826. if (($dom[$key]['value'] != 'sup') AND ($dom[$key]['value'] != 'sub')) {
  18827. $minstartliney = min($this->y, $minstartliney);
  18828. $maxbottomliney = max(($this->y + (($fontsize * $this->cell_height_ratio) / $this->k)), $maxbottomliney);
  18829. }
  18830. }
  18831. $this->cell_height_ratio = $dom[$key]['line-height'];
  18832. $fontaligned = true;
  18833. }
  18834. $this->SetFont($fontname, $fontstyle, $fontsize);
  18835. // reset row height
  18836. $this->resetLastH();
  18837. $curfontname = $fontname;
  18838. $curfontstyle = $fontstyle;
  18839. $curfontsize = $fontsize;
  18840. $curfontascent = $fontascent;
  18841. $curfontdescent = $fontdescent;
  18842. }
  18843. }
  18844. // set text rendering mode
  18845. $textstroke = isset($dom[$key]['stroke']) ? $dom[$key]['stroke'] : $this->textstrokewidth;
  18846. $textfill = isset($dom[$key]['fill']) ? $dom[$key]['fill'] : (($this->textrendermode % 2) == 0);
  18847. $textclip = isset($dom[$key]['clip']) ? $dom[$key]['clip'] : ($this->textrendermode > 3);
  18848. $this->setTextRenderingMode($textstroke, $textfill, $textclip);
  18849. if (isset($dom[$key]['font-stretch']) AND ($dom[$key]['font-stretch'] !== false)) {
  18850. $this->setFontStretching($dom[$key]['font-stretch']);
  18851. }
  18852. if (isset($dom[$key]['letter-spacing']) AND ($dom[$key]['letter-spacing'] !== false)) {
  18853. $this->setFontSpacing($dom[$key]['letter-spacing']);
  18854. }
  18855. if (($plalign == 'J') AND $dom[$key]['block']) {
  18856. $plalign = '';
  18857. }
  18858. // get current position on page buffer
  18859. $curpos = $this->pagelen[$startlinepage];
  18860. if (isset($dom[$key]['bgcolor']) AND ($dom[$key]['bgcolor'] !== false)) {
  18861. $this->SetFillColorArray($dom[$key]['bgcolor']);
  18862. $wfill = true;
  18863. } else {
  18864. $wfill = $fill | false;
  18865. }
  18866. if (isset($dom[$key]['fgcolor']) AND ($dom[$key]['fgcolor'] !== false)) {
  18867. $this->SetTextColorArray($dom[$key]['fgcolor']);
  18868. }
  18869. if (isset($dom[$key]['strokecolor']) AND ($dom[$key]['strokecolor'] !== false)) {
  18870. $this->SetDrawColorArray($dom[$key]['strokecolor']);
  18871. }
  18872. if (isset($dom[$key]['align'])) {
  18873. $lalign = $dom[$key]['align'];
  18874. }
  18875. if ($this->empty_string($lalign)) {
  18876. $lalign = $align;
  18877. }
  18878. }
  18879. // align lines
  18880. if ($this->newline AND (strlen($dom[$key]['value']) > 0) AND ($dom[$key]['value'] != 'td') AND ($dom[$key]['value'] != 'th')) {
  18881. $newline = true;
  18882. $fontaligned = false;
  18883. // we are at the beginning of a new line
  18884. if (isset($startlinex)) {
  18885. $yshift = $minstartliney - $startliney;
  18886. if (($yshift > 0) OR ($this->page > $startlinepage)) {
  18887. $yshift = 0;
  18888. }
  18889. $t_x = 0;
  18890. // the last line must be shifted to be aligned as requested
  18891. $linew = abs($this->endlinex - $startlinex);
  18892. if ($this->inxobj) {
  18893. // we are inside an XObject template
  18894. $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
  18895. if (isset($opentagpos)) {
  18896. $midpos = $opentagpos;
  18897. } else {
  18898. $midpos = 0;
  18899. }
  18900. if ($midpos > 0) {
  18901. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
  18902. $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  18903. } else {
  18904. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  18905. $pend = '';
  18906. }
  18907. } else {
  18908. $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
  18909. if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  18910. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  18911. $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
  18912. } elseif (isset($opentagpos)) {
  18913. $midpos = $opentagpos;
  18914. } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  18915. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  18916. $midpos = $this->footerpos[$startlinepage];
  18917. } else {
  18918. $midpos = 0;
  18919. }
  18920. if ($midpos > 0) {
  18921. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
  18922. $pend = substr($this->getPageBuffer($startlinepage), $midpos);
  18923. } else {
  18924. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
  18925. $pend = '';
  18926. }
  18927. }
  18928. if ((isset($plalign) AND ((($plalign == 'C') OR ($plalign == 'J') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
  18929. // calculate shifting amount
  18930. $tw = $w;
  18931. if (($plalign == 'J') AND $this->isRTLTextDir() AND ($this->num_columns > 1)) {
  18932. $tw += $this->cell_padding['R'];
  18933. }
  18934. if ($this->lMargin != $prevlMargin) {
  18935. $tw += ($prevlMargin - $this->lMargin);
  18936. }
  18937. if ($this->rMargin != $prevrMargin) {
  18938. $tw += ($prevrMargin - $this->rMargin);
  18939. }
  18940. $one_space_width = $this->GetStringWidth(chr(32));
  18941. $no = 0; // number of spaces on a line contained on a single block
  18942. if ($this->isRTLTextDir()) { // RTL
  18943. // remove left space if exist
  18944. $pos1 = $this->revstrpos($pmid, '[(');
  18945. if ($pos1 > 0) {
  18946. $pos1 = intval($pos1);
  18947. if ($this->isUnicodeFont()) {
  18948. $pos2 = intval($this->revstrpos($pmid, '[('.chr(0).chr(32)));
  18949. $spacelen = 2;
  18950. } else {
  18951. $pos2 = intval($this->revstrpos($pmid, '[('.chr(32)));
  18952. $spacelen = 1;
  18953. }
  18954. if ($pos1 == $pos2) {
  18955. $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
  18956. if (substr($pmid, $pos1, 4) == '[()]') {
  18957. $linew -= $one_space_width;
  18958. } elseif ($pos1 == strpos($pmid, '[(')) {
  18959. $no = 1;
  18960. }
  18961. }
  18962. }
  18963. } else { // LTR
  18964. // remove right space if exist
  18965. $pos1 = $this->revstrpos($pmid, ')]');
  18966. if ($pos1 > 0) {
  18967. $pos1 = intval($pos1);
  18968. if ($this->isUnicodeFont()) {
  18969. $pos2 = intval($this->revstrpos($pmid, chr(0).chr(32).')]')) + 2;
  18970. $spacelen = 2;
  18971. } else {
  18972. $pos2 = intval($this->revstrpos($pmid, chr(32).')]')) + 1;
  18973. $spacelen = 1;
  18974. }
  18975. if ($pos1 == $pos2) {
  18976. $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
  18977. $linew -= $one_space_width;
  18978. }
  18979. }
  18980. }
  18981. $mdiff = ($tw - $linew);
  18982. if ($plalign == 'C') {
  18983. if ($this->rtl) {
  18984. $t_x = -($mdiff / 2);
  18985. } else {
  18986. $t_x = ($mdiff / 2);
  18987. }
  18988. } elseif ($plalign == 'R') {
  18989. // right alignment on LTR document
  18990. $t_x = $mdiff;
  18991. } elseif ($plalign == 'L') {
  18992. // left alignment on RTL document
  18993. $t_x = -$mdiff;
  18994. } elseif (($plalign == 'J') AND ($plalign == $lalign)) {
  18995. // Justification
  18996. if ($this->isRTLTextDir()) {
  18997. // align text on the left
  18998. $t_x = -$mdiff;
  18999. }
  19000. $ns = 0; // number of spaces
  19001. $pmidtemp = $pmid;
  19002. // escape special characters
  19003. $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
  19004. $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
  19005. // search spaces
  19006. if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmidtemp, $lnstring, PREG_PATTERN_ORDER)) {
  19007. $spacestr = $this->getSpaceString();
  19008. $maxkk = count($lnstring[1]) - 1;
  19009. for ($kk=0; $kk <= $maxkk; ++$kk) {
  19010. // restore special characters
  19011. $lnstring[1][$kk] = str_replace('#!#OP#!#', '(', $lnstring[1][$kk]);
  19012. $lnstring[1][$kk] = str_replace('#!#CP#!#', ')', $lnstring[1][$kk]);
  19013. // store number of spaces on the strings
  19014. $lnstring[2][$kk] = substr_count($lnstring[1][$kk], $spacestr);
  19015. // count total spaces on line
  19016. $ns += $lnstring[2][$kk];
  19017. $lnstring[3][$kk] = $ns;
  19018. }
  19019. if ($ns == 0) {
  19020. $ns = 1;
  19021. }
  19022. // calculate additional space to add to each existing space
  19023. $spacewidth = ($mdiff / ($ns - $no)) * $this->k;
  19024. $spacewidthu = -1000 * ($mdiff + (($ns + $no) * $one_space_width)) / $ns / $this->FontSize;
  19025. if ($this->font_spacing != 0) {
  19026. // fixed spacing mode
  19027. $osw = -1000 * $this->font_spacing / $this->FontSize;
  19028. $spacewidthu += $osw;
  19029. }
  19030. $nsmax = $ns;
  19031. $ns = 0;
  19032. reset($lnstring);
  19033. $offset = 0;
  19034. $strcount = 0;
  19035. $prev_epsposbeg = 0;
  19036. $textpos = 0;
  19037. if ($this->isRTLTextDir()) {
  19038. $textpos = $this->wPt;
  19039. }
  19040. global $spacew;
  19041. while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x', $pmid, $strpiece, PREG_OFFSET_CAPTURE, $offset) == 1) {
  19042. // check if we are inside a string section '[( ... )]'
  19043. $stroffset = strpos($pmid, '[(', $offset);
  19044. if (($stroffset !== false) AND ($stroffset <= $strpiece[2][1])) {
  19045. // set offset to the end of string section
  19046. $offset = strpos($pmid, ')]', $stroffset);
  19047. while (($offset !== false) AND ($pmid{($offset - 1)} == '\\')) {
  19048. $offset = strpos($pmid, ')]', ($offset + 1));
  19049. }
  19050. if ($offset === false) {
  19051. $this->Error('HTML Justification: malformed PDF code.');
  19052. }
  19053. continue;
  19054. }
  19055. if ($this->isRTLTextDir()) {
  19056. $spacew = ($spacewidth * ($nsmax - $ns));
  19057. } else {
  19058. $spacew = ($spacewidth * $ns);
  19059. }
  19060. $offset = $strpiece[2][1] + strlen($strpiece[2][0]);
  19061. $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, $offset);
  19062. $epsposend = strpos($pmid, $this->epsmarker.'Q', $offset) + strlen($this->epsmarker.'Q');
  19063. if ((($epsposbeg > 0) AND ($epsposend > 0) AND ($offset > $epsposbeg) AND ($offset < $epsposend))
  19064. OR (($epsposbeg === false) AND ($epsposend > 0) AND ($offset < $epsposend))) {
  19065. // shift EPS images
  19066. $trx = sprintf('1 0 0 1 %.3F 0 cm', $spacew);
  19067. $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, ($prev_epsposbeg - 6));
  19068. $pmid_b = substr($pmid, 0, $epsposbeg);
  19069. $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg));
  19070. $pmid_e = substr($pmid, $epsposend);
  19071. $pmid = $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e;
  19072. $offset = $epsposend;
  19073. continue;
  19074. }
  19075. $prev_epsposbeg = $epsposbeg;
  19076. $currentxpos = 0;
  19077. // shift blocks of code
  19078. switch ($strpiece[2][0]) {
  19079. case 'Td':
  19080. case 'cm':
  19081. case 'm':
  19082. case 'l': {
  19083. // get current X position
  19084. preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches);
  19085. $currentxpos = $xmatches[1];
  19086. $textpos = $currentxpos;
  19087. if (($strcount <= $maxkk) AND ($strpiece[2][0] == 'Td')) {
  19088. $ns = $lnstring[3][$strcount];
  19089. if ($this->isRTLTextDir()) {
  19090. $spacew = ($spacewidth * ($nsmax - $ns));
  19091. }
  19092. ++$strcount;
  19093. }
  19094. // justify block
  19095. $pmid = preg_replace_callback('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x',
  19096. create_function('$matches', 'global $spacew;
  19097. $newx = sprintf("%.2F",(floatval($matches[1]) + $spacew));
  19098. return "".$newx." ".$matches[2]." x*#!#*x".$matches[3].$matches[4];'), $pmid, 1);
  19099. break;
  19100. }
  19101. case 're': {
  19102. // justify block
  19103. if (!$this->empty_string($this->lispacer)) {
  19104. $this->lispacer = '';
  19105. continue;
  19106. }
  19107. preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $xmatches);
  19108. $currentxpos = $xmatches[1];
  19109. global $x_diff, $w_diff;
  19110. $x_diff = 0;
  19111. $w_diff = 0;
  19112. if ($this->isRTLTextDir()) { // RTL
  19113. if ($currentxpos < $textpos) {
  19114. $x_diff = ($spacewidth * ($nsmax - $lnstring[3][$strcount]));
  19115. $w_diff = ($spacewidth * $lnstring[2][$strcount]);
  19116. } else {
  19117. if ($strcount > 0) {
  19118. $x_diff = ($spacewidth * ($nsmax - $lnstring[3][($strcount - 1)]));
  19119. $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
  19120. }
  19121. }
  19122. } else { // LTR
  19123. if ($currentxpos > $textpos) {
  19124. if ($strcount > 0) {
  19125. $x_diff = ($spacewidth * $lnstring[3][($strcount - 1)]);
  19126. }
  19127. $w_diff = ($spacewidth * $lnstring[2][$strcount]);
  19128. } else {
  19129. if ($strcount > 1) {
  19130. $x_diff = ($spacewidth * $lnstring[3][($strcount - 2)]);
  19131. }
  19132. if ($strcount > 0) {
  19133. $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
  19134. }
  19135. }
  19136. }
  19137. $pmid = preg_replace_callback('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x',
  19138. create_function('$matches', 'global $x_diff, $w_diff;
  19139. $newx = sprintf("%.2F",(floatval($matches[1]) + $x_diff));
  19140. $neww = sprintf("%.2F",(floatval($matches[3]) + $w_diff));
  19141. return "".$newx." ".$matches[2]." ".$neww." ".$matches[4]." x*#!#*x".$matches[5].$matches[6];'), $pmid, 1);
  19142. break;
  19143. }
  19144. case 'c': {
  19145. // get current X position
  19146. 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);
  19147. $currentxpos = $xmatches[1];
  19148. // justify block
  19149. $pmid = preg_replace_callback('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$xmatches[4].')[\s]('.$xmatches[5].')[\s]('.$strpiece[1][0].')[\s](c)([\s]*)/x',
  19150. create_function('$matches', 'global $spacew;
  19151. $newx1 = sprintf("%.3F",(floatval($matches[1]) + $spacew));
  19152. $newx2 = sprintf("%.3F",(floatval($matches[3]) + $spacew));
  19153. $newx3 = sprintf("%.3F",(floatval($matches[5]) + $spacew));
  19154. return "".$newx1." ".$matches[2]." ".$newx2." ".$matches[4]." ".$newx3." ".$matches[6]." x*#!#*x".$matches[7].$matches[8];'), $pmid, 1);
  19155. break;
  19156. }
  19157. }
  19158. // shift the annotations and links
  19159. $cxpos = ($currentxpos / $this->k);
  19160. $lmpos = ($this->lMargin + $this->cell_padding['L'] + $this->feps);
  19161. if ($this->inxobj) {
  19162. // we are inside an XObject template
  19163. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  19164. if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
  19165. if ($cxpos > $lmpos) {
  19166. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += ($spacew / $this->k);
  19167. $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  19168. } else {
  19169. $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  19170. }
  19171. break;
  19172. }
  19173. }
  19174. } elseif (isset($this->PageAnnots[$this->page])) {
  19175. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  19176. if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
  19177. if ($cxpos > $lmpos) {
  19178. $this->PageAnnots[$this->page][$pak]['x'] += ($spacew / $this->k);
  19179. $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  19180. } else {
  19181. $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  19182. }
  19183. break;
  19184. }
  19185. }
  19186. }
  19187. } // end of while
  19188. // remove markers
  19189. $pmid = str_replace('x*#!#*x', '', $pmid);
  19190. if ($this->isUnicodeFont()) {
  19191. // multibyte characters
  19192. $spacew = $spacewidthu;
  19193. if ($this->font_stretching != 100) {
  19194. // word spacing is affected by stretching
  19195. $spacew /= ($this->font_stretching / 100);
  19196. }
  19197. $pmidtemp = $pmid;
  19198. // escape special characters
  19199. $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
  19200. $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
  19201. $pmid = preg_replace_callback("/\[\(([^\)]*)\)\]/x",
  19202. create_function('$matches', 'global $spacew;
  19203. $matches[1] = str_replace("#!#OP#!#", "(", $matches[1]);
  19204. $matches[1] = str_replace("#!#CP#!#", ")", $matches[1]);
  19205. return "[(".str_replace(chr(0).chr(32), ") ".sprintf("%.3F", $spacew)." (", $matches[1]).")]";'), $pmidtemp);
  19206. if ($this->inxobj) {
  19207. // we are inside an XObject template
  19208. $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\n".$pend;
  19209. } else {
  19210. $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\n".$pend);
  19211. }
  19212. $endlinepos = strlen($pstart."\n".$pmid."\n");
  19213. } else {
  19214. // non-unicode (single-byte characters)
  19215. if ($this->font_stretching != 100) {
  19216. // word spacing (Tw) is affected by stretching
  19217. $spacewidth /= ($this->font_stretching / 100);
  19218. }
  19219. $rs = sprintf('%.3F Tw', $spacewidth);
  19220. $pmid = preg_replace("/\[\(/x", $rs.' [(', $pmid);
  19221. if ($this->inxobj) {
  19222. // we are inside an XObject template
  19223. $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend;
  19224. } else {
  19225. $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend);
  19226. }
  19227. $endlinepos = strlen($pstart."\n".$pmid."\nBT 0 Tw ET\n");
  19228. }
  19229. }
  19230. } // end of J
  19231. } // end if $startlinex
  19232. if (($t_x != 0) OR ($yshift < 0)) {
  19233. // shift the line
  19234. $trx = sprintf('1 0 0 1 %.3F %.3F cm', ($t_x * $this->k), ($yshift * $this->k));
  19235. $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
  19236. $endlinepos = strlen($pstart);
  19237. if ($this->inxobj) {
  19238. // we are inside an XObject template
  19239. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
  19240. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  19241. if ($pak >= $pask) {
  19242. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  19243. $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  19244. }
  19245. }
  19246. } else {
  19247. $this->setPageBuffer($startlinepage, $pstart.$pend);
  19248. // shift the annotations and links
  19249. if (isset($this->PageAnnots[$this->page])) {
  19250. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  19251. if ($pak >= $pask) {
  19252. $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  19253. $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  19254. }
  19255. }
  19256. }
  19257. }
  19258. $this->y -= $yshift;
  19259. }
  19260. }
  19261. $pbrk = $this->checkPageBreak($this->lasth);
  19262. $this->newline = false;
  19263. $startlinex = $this->x;
  19264. $startliney = $this->y;
  19265. if ($dom[$dom[$key]['parent']]['value'] == 'sup') {
  19266. $startliney -= ((0.3 * $this->FontSizePt) / $this->k);
  19267. } elseif ($dom[$dom[$key]['parent']]['value'] == 'sub') {
  19268. $startliney -= (($this->FontSizePt / 0.7) / $this->k);
  19269. } else {
  19270. $minstartliney = $startliney;
  19271. $maxbottomliney = ($this->y + (($fontsize * $this->cell_height_ratio) / $this->k));
  19272. }
  19273. $startlinepage = $this->page;
  19274. if (isset($endlinepos) AND (!$pbrk)) {
  19275. $startlinepos = $endlinepos;
  19276. } else {
  19277. if ($this->inxobj) {
  19278. // we are inside an XObject template
  19279. $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
  19280. } elseif (!$this->InFooter) {
  19281. if (isset($this->footerlen[$this->page])) {
  19282. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  19283. } else {
  19284. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  19285. }
  19286. $startlinepos = $this->footerpos[$this->page];
  19287. } else {
  19288. $startlinepos = $this->pagelen[$this->page];
  19289. }
  19290. }
  19291. unset($endlinepos);
  19292. $plalign = $lalign;
  19293. if (isset($this->PageAnnots[$this->page])) {
  19294. $pask = count($this->PageAnnots[$this->page]);
  19295. } else {
  19296. $pask = 0;
  19297. }
  19298. if (!($dom[$key]['tag'] AND !$dom[$key]['opening'] AND ($dom[$key]['value'] == 'table')
  19299. AND (isset($this->emptypagemrk[$this->page]))
  19300. AND ($this->emptypagemrk[$this->page] == $this->pagelen[$this->page]))) {
  19301. $this->SetFont($fontname, $fontstyle, $fontsize);
  19302. if ($wfill) {
  19303. $this->SetFillColorArray($this->bgcolor);
  19304. }
  19305. }
  19306. } // end newline
  19307. if (isset($opentagpos)) {
  19308. unset($opentagpos);
  19309. }
  19310. if ($dom[$key]['tag']) {
  19311. if ($dom[$key]['opening']) {
  19312. // get text indentation (if any)
  19313. if (isset($dom[$key]['text-indent']) AND $dom[$key]['block']) {
  19314. $this->textindent = $dom[$key]['text-indent'];
  19315. $this->newline = true;
  19316. }
  19317. // table
  19318. if ($dom[$key]['value'] == 'table') {
  19319. // available page width
  19320. if ($this->rtl) {
  19321. $wtmp = $this->x - $this->lMargin;
  19322. } else {
  19323. $wtmp = $this->w - $this->rMargin - $this->x;
  19324. }
  19325. // get cell spacing
  19326. if (isset($dom[$key]['attribute']['cellspacing'])) {
  19327. $clsp = $this->getHTMLUnitToUnits($dom[$key]['attribute']['cellspacing'], 1, 'px');
  19328. $cellspacing = array('H' => $clsp, 'V' => $clsp);
  19329. } elseif (isset($dom[$key]['border-spacing'])) {
  19330. $cellspacing = $dom[$key]['border-spacing'];
  19331. } else {
  19332. $cellspacing = array('H' => 0, 'V' => 0);
  19333. }
  19334. // table width
  19335. if (isset($dom[$key]['width'])) {
  19336. $table_width = $this->getHTMLUnitToUnits($dom[$key]['width'], $wtmp, 'px');
  19337. } else {
  19338. $table_width = $wtmp;
  19339. }
  19340. $table_width -= (2 * $cellspacing['H']);
  19341. if (!$this->inthead) {
  19342. $this->y += $cellspacing['V'];
  19343. }
  19344. if ($this->rtl) {
  19345. $cellspacingx = -$cellspacing['H'];
  19346. } else {
  19347. $cellspacingx = $cellspacing['H'];
  19348. }
  19349. // total table width without cellspaces
  19350. $table_columns_width = ($table_width - ($cellspacing['H'] * ($dom[$key]['cols'] - 1)));
  19351. // minimum column width
  19352. $table_min_column_width = ($table_columns_width / $dom[$key]['cols']);
  19353. // array of custom column widths
  19354. $table_colwidths = array_fill(0, $dom[$key]['cols'], $table_min_column_width);
  19355. }
  19356. // table row
  19357. if ($dom[$key]['value'] == 'tr') {
  19358. // reset column counter
  19359. $colid = 0;
  19360. }
  19361. // table cell
  19362. if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  19363. $trid = $dom[$key]['parent'];
  19364. $table_el = $dom[$trid]['parent'];
  19365. if (!isset($dom[$table_el]['cols'])) {
  19366. $dom[$table_el]['cols'] = $dom[$trid]['cols'];
  19367. }
  19368. // store border info
  19369. $tdborder = 0;
  19370. if (isset($dom[$key]['border']) AND !empty($dom[$key]['border'])) {
  19371. $tdborder = $dom[$key]['border'];
  19372. }
  19373. $colspan = $dom[$key]['attribute']['colspan'];
  19374. $old_cell_padding = $this->cell_padding;
  19375. if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) {
  19376. $crclpd = $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'], 1, 'px');
  19377. $current_cell_padding = array('L' => $crclpd, 'T' => $crclpd, 'R' => $crclpd, 'B' => $crclpd);
  19378. } elseif (isset($dom[($dom[$trid]['parent'])]['padding'])) {
  19379. $current_cell_padding = $dom[($dom[$trid]['parent'])]['padding'];
  19380. } else {
  19381. $current_cell_padding = array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0);
  19382. }
  19383. $this->cell_padding = $current_cell_padding;
  19384. if (isset($dom[$key]['height'])) {
  19385. // minimum cell height
  19386. $cellh = $this->getHTMLUnitToUnits($dom[$key]['height'], 0, 'px');
  19387. } else {
  19388. $cellh = 0;
  19389. }
  19390. if (isset($dom[$key]['content'])) {
  19391. $cell_content = $dom[$key]['content'];
  19392. } else {
  19393. $cell_content = '&nbsp;';
  19394. }
  19395. $tagtype = $dom[$key]['value'];
  19396. $parentid = $key;
  19397. while (($key < $maxel) AND (!(($dom[$key]['tag']) AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == $tagtype) AND ($dom[$key]['parent'] == $parentid)))) {
  19398. // move $key index forward
  19399. ++$key;
  19400. }
  19401. if (!isset($dom[$trid]['startpage'])) {
  19402. $dom[$trid]['startpage'] = $this->page;
  19403. } else {
  19404. $this->setPage($dom[$trid]['startpage']);
  19405. }
  19406. if (!isset($dom[$trid]['startcolumn'])) {
  19407. $dom[$trid]['startcolumn'] = $this->current_column;
  19408. } elseif ($this->current_column != $dom[$trid]['startcolumn']) {
  19409. $tmpx = $this->x;
  19410. $this->selectColumn($dom[$trid]['startcolumn']);
  19411. $this->x = $tmpx;
  19412. }
  19413. if (!isset($dom[$trid]['starty'])) {
  19414. $dom[$trid]['starty'] = $this->y;
  19415. } else {
  19416. $this->y = $dom[$trid]['starty'];
  19417. }
  19418. if (!isset($dom[$trid]['startx'])) {
  19419. $dom[$trid]['startx'] = $this->x;
  19420. $this->x += $cellspacingx;
  19421. } else {
  19422. $this->x += ($cellspacingx / 2);
  19423. }
  19424. if (isset($dom[$parentid]['attribute']['rowspan'])) {
  19425. $rowspan = intval($dom[$parentid]['attribute']['rowspan']);
  19426. } else {
  19427. $rowspan = 1;
  19428. }
  19429. // skip row-spanned cells started on the previous rows
  19430. if (isset($dom[$table_el]['rowspans'])) {
  19431. $rsk = 0;
  19432. $rskmax = count($dom[$table_el]['rowspans']);
  19433. while ($rsk < $rskmax) {
  19434. $trwsp = $dom[$table_el]['rowspans'][$rsk];
  19435. $rsstartx = $trwsp['startx'];
  19436. $rsendx = $trwsp['endx'];
  19437. // account for margin changes
  19438. if ($trwsp['startpage'] < $this->page) {
  19439. if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$trwsp['startpage']]['orm'])) {
  19440. $dl = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$trwsp['startpage']]['orm']);
  19441. $rsstartx -= $dl;
  19442. $rsendx -= $dl;
  19443. } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$trwsp['startpage']]['olm'])) {
  19444. $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$trwsp['startpage']]['olm']);
  19445. $rsstartx += $dl;
  19446. $rsendx += $dl;
  19447. }
  19448. }
  19449. if (($trwsp['rowspan'] > 0)
  19450. AND ($rsstartx > ($this->x - $cellspacing['H'] - $current_cell_padding['L'] - $this->feps))
  19451. AND ($rsstartx < ($this->x + $cellspacing['H'] + $current_cell_padding['R'] + $this->feps))
  19452. AND (($trwsp['starty'] < ($this->y - $this->feps)) OR ($trwsp['startpage'] < $this->page) OR ($trwsp['startcolumn'] < $this->current_column))) {
  19453. // set the starting X position of the current cell
  19454. $this->x = $rsendx + $cellspacingx;
  19455. // increment column indicator
  19456. $colid += $trwsp['colspan'];
  19457. if (($trwsp['rowspan'] == 1)
  19458. AND (isset($dom[$trid]['endy']))
  19459. AND (isset($dom[$trid]['endpage']))
  19460. AND (isset($dom[$trid]['endcolumn']))
  19461. AND ($trwsp['endpage'] == $dom[$trid]['endpage'])
  19462. AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
  19463. // set ending Y position for row
  19464. $dom[$table_el]['rowspans'][$rsk]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  19465. $dom[$trid]['endy'] = $dom[$table_el]['rowspans'][$rsk]['endy'];
  19466. }
  19467. $rsk = 0;
  19468. } else {
  19469. ++$rsk;
  19470. }
  19471. }
  19472. }
  19473. if (isset($dom[$parentid]['width'])) {
  19474. // user specified width
  19475. $cellw = $this->getHTMLUnitToUnits($dom[$parentid]['width'], $table_columns_width, 'px');
  19476. $tmpcw = ($cellw / $colspan);
  19477. for ($i = 0; $i < $colspan; ++$i) {
  19478. $table_colwidths[($colid + $i)] = $tmpcw;
  19479. }
  19480. } else {
  19481. // inherit column width
  19482. $cellw = 0;
  19483. for ($i = 0; $i < $colspan; ++$i) {
  19484. $cellw += $table_colwidths[($colid + $i)];
  19485. }
  19486. }
  19487. $cellw += (($colspan - 1) * $cellspacing['H']);
  19488. // increment column indicator
  19489. $colid += $colspan;
  19490. // add rowspan information to table element
  19491. if ($rowspan > 1) {
  19492. $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));
  19493. }
  19494. $cellid = array_push($dom[$trid]['cellpos'], array('startx' => $this->x));
  19495. if ($rowspan > 1) {
  19496. $dom[$trid]['cellpos'][($cellid - 1)]['rowspanid'] = ($trsid - 1);
  19497. }
  19498. // push background colors
  19499. if (isset($dom[$parentid]['bgcolor']) AND ($dom[$parentid]['bgcolor'] !== false)) {
  19500. $dom[$trid]['cellpos'][($cellid - 1)]['bgcolor'] = $dom[$parentid]['bgcolor'];
  19501. }
  19502. // store border info
  19503. if (isset($tdborder) AND !empty($tdborder)) {
  19504. $dom[$trid]['cellpos'][($cellid - 1)]['border'] = $tdborder;
  19505. }
  19506. $prevLastH = $this->lasth;
  19507. // store some info for multicolumn mode
  19508. if ($this->rtl) {
  19509. $this->colxshift['x'] = $this->w - $this->x - $this->rMargin;
  19510. } else {
  19511. $this->colxshift['x'] = $this->x - $this->lMargin;
  19512. }
  19513. $this->colxshift['s'] = $cellspacing;
  19514. $this->colxshift['p'] = $current_cell_padding;
  19515. // ****** write the cell content ******
  19516. $this->MultiCell($cellw, $cellh, $cell_content, false, $lalign, false, 2, '', '', true, 0, true);
  19517. // restore some values
  19518. $this->colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  19519. $this->lasth = $prevLastH;
  19520. $this->cell_padding = $old_cell_padding;
  19521. $dom[$trid]['cellpos'][($cellid - 1)]['endx'] = $this->x;
  19522. // update the end of row position
  19523. if ($rowspan <= 1) {
  19524. if (isset($dom[$trid]['endy'])) {
  19525. if (($this->page == $dom[$trid]['endpage']) AND ($this->current_column == $dom[$trid]['endcolumn'])) {
  19526. $dom[$trid]['endy'] = max($this->y, $dom[$trid]['endy']);
  19527. } elseif (($this->page > $dom[$trid]['endpage']) OR ($this->current_column > $dom[$trid]['endcolumn'])) {
  19528. $dom[$trid]['endy'] = $this->y;
  19529. }
  19530. } else {
  19531. $dom[$trid]['endy'] = $this->y;
  19532. }
  19533. if (isset($dom[$trid]['endpage'])) {
  19534. $dom[$trid]['endpage'] = max($this->page, $dom[$trid]['endpage']);
  19535. } else {
  19536. $dom[$trid]['endpage'] = $this->page;
  19537. }
  19538. if (isset($dom[$trid]['endcolumn'])) {
  19539. $dom[$trid]['endcolumn'] = max($this->current_column, $dom[$trid]['endcolumn']);
  19540. } else {
  19541. $dom[$trid]['endcolumn'] = $this->current_column;
  19542. }
  19543. } else {
  19544. // account for row-spanned cells
  19545. $dom[$table_el]['rowspans'][($trsid - 1)]['endx'] = $this->x;
  19546. $dom[$table_el]['rowspans'][($trsid - 1)]['endy'] = $this->y;
  19547. $dom[$table_el]['rowspans'][($trsid - 1)]['endpage'] = $this->page;
  19548. $dom[$table_el]['rowspans'][($trsid - 1)]['endcolumn'] = $this->current_column;
  19549. }
  19550. if (isset($dom[$table_el]['rowspans'])) {
  19551. // update endy and endpage on rowspanned cells
  19552. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  19553. if ($trwsp['rowspan'] > 0) {
  19554. if (isset($dom[$trid]['endpage'])) {
  19555. if (($trwsp['endpage'] == $dom[$trid]['endpage']) AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
  19556. $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  19557. } elseif (($trwsp['endpage'] < $dom[$trid]['endpage']) OR ($trwsp['endcolumn'] < $dom[$trid]['endcolumn'])) {
  19558. $dom[$table_el]['rowspans'][$k]['endy'] = $dom[$trid]['endy'];
  19559. $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[$trid]['endpage'];
  19560. $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[$trid]['endcolumn'];
  19561. } else {
  19562. $dom[$trid]['endy'] = $this->pagedim[$dom[$trid]['endpage']]['hk'] - $this->pagedim[$dom[$trid]['endpage']]['bm'];
  19563. }
  19564. }
  19565. }
  19566. }
  19567. }
  19568. $this->x += ($cellspacingx / 2);
  19569. } else {
  19570. // opening tag (or self-closing tag)
  19571. if (!isset($opentagpos)) {
  19572. if ($this->inxobj) {
  19573. // we are inside an XObject template
  19574. $opentagpos = strlen($this->xobjects[$this->xobjid]['outdata']);
  19575. } elseif (!$this->InFooter) {
  19576. if (isset($this->footerlen[$this->page])) {
  19577. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  19578. } else {
  19579. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  19580. }
  19581. $opentagpos = $this->footerpos[$this->page];
  19582. }
  19583. }
  19584. $this->openHTMLTagHandler($dom, $key, $cell);
  19585. }
  19586. } else { // closing tag
  19587. $prev_numpages = $this->numpages;
  19588. $old_bordermrk = $this->bordermrk[$this->page];
  19589. $this->closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney);
  19590. if ($this->bordermrk[$this->page] > $old_bordermrk) {
  19591. $startlinepos += ($this->bordermrk[$this->page] - $old_bordermrk);
  19592. }
  19593. if ($prev_numpages > $this->numpages) {
  19594. $startlinepage = $this->page;
  19595. }
  19596. }
  19597. } elseif (strlen($dom[$key]['value']) > 0) {
  19598. // print list-item
  19599. if (!$this->empty_string($this->lispacer) AND ($this->lispacer != '^')) {
  19600. $this->SetFont($pfontname, $pfontstyle, $pfontsize);
  19601. $this->resetLastH();
  19602. $minstartliney = $this->y;
  19603. $maxbottomliney = ($startliney + ($this->FontSize * $this->cell_height_ratio));
  19604. $this->putHtmlListBullet($this->listnum, $this->lispacer, $pfontsize);
  19605. $this->SetFont($curfontname, $curfontstyle, $curfontsize);
  19606. $this->resetLastH();
  19607. if (is_numeric($pfontsize) AND ($pfontsize > 0) AND is_numeric($curfontsize) AND ($curfontsize > 0) AND ($pfontsize != $curfontsize)) {
  19608. $pfontascent = $this->getFontAscent($pfontname, $pfontstyle, $pfontsize);
  19609. $pfontdescent = $this->getFontDescent($pfontname, $pfontstyle, $pfontsize);
  19610. $this->y += ((($pfontsize - $curfontsize) * $this->cell_height_ratio / $this->k) + $pfontascent - $curfontascent - $pfontdescent + $curfontdescent) / 2;
  19611. $minstartliney = min($this->y, $minstartliney);
  19612. $maxbottomliney = max(($this->y + (($pfontsize * $this->cell_height_ratio) / $this->k)), $maxbottomliney);
  19613. }
  19614. }
  19615. // text
  19616. $this->htmlvspace = 0;
  19617. if ((!$this->premode) AND $this->isRTLTextDir()) {
  19618. // reverse spaces order
  19619. $lsp = ''; // left spaces
  19620. $rsp = ''; // right spaces
  19621. if (preg_match('/^('.$this->re_space['p'].'+)/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
  19622. $lsp = $matches[1];
  19623. }
  19624. if (preg_match('/('.$this->re_space['p'].'+)$/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
  19625. $rsp = $matches[1];
  19626. }
  19627. $dom[$key]['value'] = $rsp.$this->stringTrim($dom[$key]['value']).$lsp;
  19628. }
  19629. if ($newline) {
  19630. if (!$this->premode) {
  19631. $prelen = strlen($dom[$key]['value']);
  19632. if ($this->isRTLTextDir()) {
  19633. // right trim except non-breaking space
  19634. $dom[$key]['value'] = $this->stringRightTrim($dom[$key]['value']);
  19635. } else {
  19636. // left trim except non-breaking space
  19637. $dom[$key]['value'] = $this->stringLeftTrim($dom[$key]['value']);
  19638. }
  19639. $postlen = strlen($dom[$key]['value']);
  19640. if (($postlen == 0) AND ($prelen > 0)) {
  19641. $dom[$key]['trimmed_space'] = true;
  19642. }
  19643. }
  19644. $newline = false;
  19645. $firstblock = true;
  19646. } else {
  19647. $firstblock = false;
  19648. // replace empty multiple spaces string with a single space
  19649. $dom[$key]['value'] = preg_replace('/^'.$this->re_space['p'].'+$/'.$this->re_space['m'], chr(32), $dom[$key]['value']);
  19650. }
  19651. $strrest = '';
  19652. if ($this->rtl) {
  19653. $this->x -= $this->textindent;
  19654. } else {
  19655. $this->x += $this->textindent;
  19656. }
  19657. if (!isset($dom[$key]['trimmed_space']) OR !$dom[$key]['trimmed_space']) {
  19658. $strlinelen = $this->GetStringWidth($dom[$key]['value']);
  19659. if (!empty($this->HREF) AND (isset($this->HREF['url']))) {
  19660. // HTML <a> Link
  19661. $hrefcolor = '';
  19662. if (isset($dom[($dom[$key]['parent'])]['fgcolor']) AND ($dom[($dom[$key]['parent'])]['fgcolor'] !== false)) {
  19663. $hrefcolor = $dom[($dom[$key]['parent'])]['fgcolor'];
  19664. }
  19665. $hrefstyle = -1;
  19666. if (isset($dom[($dom[$key]['parent'])]['fontstyle']) AND ($dom[($dom[$key]['parent'])]['fontstyle'] !== false)) {
  19667. $hrefstyle = $dom[($dom[$key]['parent'])]['fontstyle'];
  19668. }
  19669. $strrest = $this->addHtmlLink($this->HREF['url'], $dom[$key]['value'], $wfill, true, $hrefcolor, $hrefstyle, true);
  19670. } else {
  19671. $wadj = 0; // space to leave for block continuity
  19672. $adjblks = 0; // number of blocks
  19673. if ($this->rtl) {
  19674. $cwa = $this->x - $this->lMargin;
  19675. } else {
  19676. $cwa = $this->w - $this->rMargin - $this->x;
  19677. }
  19678. if ($strlinelen < $cwa) {
  19679. // check the next text blocks for continuity
  19680. $nkey = ($key + 1);
  19681. $write_block = true;
  19682. $same_textdir = true;
  19683. $tmp_fontname = $this->FontFamily;
  19684. $tmp_fontstyle = $this->FontStyle;
  19685. $tmp_fontsize = $this->FontSizePt;
  19686. while ($write_block AND isset($dom[$nkey])) {
  19687. if ($dom[$nkey]['tag']) {
  19688. if ($dom[$nkey]['block']) {
  19689. // end of block
  19690. $write_block = false;
  19691. }
  19692. $tmp_fontname = isset($dom[$nkey]['fontname']) ? $dom[$nkey]['fontname'] : $this->FontFamily;
  19693. $tmp_fontstyle = isset($dom[$nkey]['fontstyle']) ? $dom[$nkey]['fontstyle'] : $this->FontStyle;
  19694. $tmp_fontsize = isset($dom[$nkey]['fontsize']) ? $dom[$nkey]['fontsize'] : $this->FontSizePt;
  19695. $same_textdir = ($dom[$nkey]['dir'] == $dom[$key]['dir']);
  19696. } else {
  19697. $nextstr = preg_split('/'.$this->re_space['p'].'+/'.$this->re_space['m'], $dom[$nkey]['value']);
  19698. if (isset($nextstr[0])) {
  19699. if ($same_textdir) {
  19700. $wadj += $this->GetStringWidth($nextstr[0], $tmp_fontname, $tmp_fontstyle, $tmp_fontsize);
  19701. }
  19702. ++$adjblks;
  19703. }
  19704. if (isset($nextstr[1])) {
  19705. $write_block = false;
  19706. }
  19707. }
  19708. ++$nkey;
  19709. }
  19710. }
  19711. // check for reversed text direction
  19712. if (($wadj > 0) AND (($this->rtl AND ($this->tmprtl === 'L')) OR (!$this->rtl AND ($this->tmprtl === 'R')))) {
  19713. // LTR text on RTL direction or RTL text on LTR direction
  19714. $reverse_dir = true;
  19715. $this->rtl = !$this->rtl;
  19716. $revshift = ($strlinelen + $wadj + 0.000001); // add little quantity for rounding problems
  19717. if ($this->rtl) {
  19718. $this->x += $revshift;
  19719. } else {
  19720. $this->x -= $revshift;
  19721. }
  19722. $xws = $this->x;
  19723. }
  19724. // ****** write only until the end of the line and get the rest ******
  19725. $strrest = $this->Write($this->lasth, $dom[$key]['value'], '', $wfill, '', false, 0, true, $firstblock, 0, $wadj);
  19726. // restore default direction
  19727. if ($reverse_dir AND ($wadj == 0)) {
  19728. $this->x = $xws;
  19729. $this->rtl = !$this->rtl;
  19730. $reverse_dir = false;
  19731. }
  19732. }
  19733. }
  19734. $this->textindent = 0;
  19735. if (strlen($strrest) > 0) {
  19736. // store the remaining string on the previous $key position
  19737. $this->newline = true;
  19738. if ($strrest == $dom[$key]['value']) {
  19739. // used to avoid infinite loop
  19740. ++$loop;
  19741. } else {
  19742. $loop = 0;
  19743. }
  19744. $dom[$key]['value'] = $strrest;
  19745. if ($cell) {
  19746. if ($this->rtl) {
  19747. $this->x -= $this->cell_padding['R'];
  19748. } else {
  19749. $this->x += $this->cell_padding['L'];
  19750. }
  19751. }
  19752. if ($loop < 3) {
  19753. --$key;
  19754. }
  19755. } else {
  19756. $loop = 0;
  19757. }
  19758. }
  19759. ++$key;
  19760. 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')) {
  19761. // check if we are on a new page or on a new column
  19762. if ((!$undo) AND ($this->y < $this->start_transaction_y)) {
  19763. // we are on a new page or on a new column and the total object height is less than the available vertical space.
  19764. // restore previous object
  19765. $this->rollbackTransaction(true);
  19766. // restore previous values
  19767. foreach ($this_method_vars as $vkey => $vval) {
  19768. $$vkey = $vval;
  19769. }
  19770. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  19771. $pre_y = $this->y;
  19772. if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
  19773. $startliney = $this->y;
  19774. }
  19775. $undo = true; // avoid infinite loop
  19776. } else {
  19777. $undo = false;
  19778. }
  19779. }
  19780. } // end for each $key
  19781. // align the last line
  19782. if (isset($startlinex)) {
  19783. $yshift = $minstartliney - $startliney;
  19784. if (($yshift > 0) OR ($this->page > $startlinepage)) {
  19785. $yshift = 0;
  19786. }
  19787. $t_x = 0;
  19788. // the last line must be shifted to be aligned as requested
  19789. $linew = abs($this->endlinex - $startlinex);
  19790. if ($this->inxobj) {
  19791. // we are inside an XObject template
  19792. $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
  19793. if (isset($opentagpos)) {
  19794. $midpos = $opentagpos;
  19795. } else {
  19796. $midpos = 0;
  19797. }
  19798. if ($midpos > 0) {
  19799. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
  19800. $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  19801. } else {
  19802. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  19803. $pend = '';
  19804. }
  19805. } else {
  19806. $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
  19807. if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  19808. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  19809. $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
  19810. } elseif (isset($opentagpos)) {
  19811. $midpos = $opentagpos;
  19812. } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  19813. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  19814. $midpos = $this->footerpos[$startlinepage];
  19815. } else {
  19816. $midpos = 0;
  19817. }
  19818. if ($midpos > 0) {
  19819. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
  19820. $pend = substr($this->getPageBuffer($startlinepage), $midpos);
  19821. } else {
  19822. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
  19823. $pend = '';
  19824. }
  19825. }
  19826. if ((isset($plalign) AND ((($plalign == 'C') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
  19827. // calculate shifting amount
  19828. $tw = $w;
  19829. if ($this->lMargin != $prevlMargin) {
  19830. $tw += ($prevlMargin - $this->lMargin);
  19831. }
  19832. if ($this->rMargin != $prevrMargin) {
  19833. $tw += ($prevrMargin - $this->rMargin);
  19834. }
  19835. $one_space_width = $this->GetStringWidth(chr(32));
  19836. $no = 0; // number of spaces on a line contained on a single block
  19837. if ($this->isRTLTextDir()) { // RTL
  19838. // remove left space if exist
  19839. $pos1 = $this->revstrpos($pmid, '[(');
  19840. if ($pos1 > 0) {
  19841. $pos1 = intval($pos1);
  19842. if ($this->isUnicodeFont()) {
  19843. $pos2 = intval($this->revstrpos($pmid, '[('.chr(0).chr(32)));
  19844. $spacelen = 2;
  19845. } else {
  19846. $pos2 = intval($this->revstrpos($pmid, '[('.chr(32)));
  19847. $spacelen = 1;
  19848. }
  19849. if ($pos1 == $pos2) {
  19850. $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
  19851. if (substr($pmid, $pos1, 4) == '[()]') {
  19852. $linew -= $one_space_width;
  19853. } elseif ($pos1 == strpos($pmid, '[(')) {
  19854. $no = 1;
  19855. }
  19856. }
  19857. }
  19858. } else { // LTR
  19859. // remove right space if exist
  19860. $pos1 = $this->revstrpos($pmid, ')]');
  19861. if ($pos1 > 0) {
  19862. $pos1 = intval($pos1);
  19863. if ($this->isUnicodeFont()) {
  19864. $pos2 = intval($this->revstrpos($pmid, chr(0).chr(32).')]')) + 2;
  19865. $spacelen = 2;
  19866. } else {
  19867. $pos2 = intval($this->revstrpos($pmid, chr(32).')]')) + 1;
  19868. $spacelen = 1;
  19869. }
  19870. if ($pos1 == $pos2) {
  19871. $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
  19872. $linew -= $one_space_width;
  19873. }
  19874. }
  19875. }
  19876. $mdiff = ($tw - $linew);
  19877. if ($plalign == 'C') {
  19878. if ($this->rtl) {
  19879. $t_x = -($mdiff / 2);
  19880. } else {
  19881. $t_x = ($mdiff / 2);
  19882. }
  19883. } elseif ($plalign == 'R') {
  19884. // right alignment on LTR document
  19885. $t_x = $mdiff;
  19886. } elseif ($plalign == 'L') {
  19887. // left alignment on RTL document
  19888. $t_x = -$mdiff;
  19889. }
  19890. } // end if startlinex
  19891. if (($t_x != 0) OR ($yshift < 0)) {
  19892. // shift the line
  19893. $trx = sprintf('1 0 0 1 %.3F %.3F cm', ($t_x * $this->k), ($yshift * $this->k));
  19894. $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
  19895. $endlinepos = strlen($pstart);
  19896. if ($this->inxobj) {
  19897. // we are inside an XObject template
  19898. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
  19899. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  19900. if ($pak >= $pask) {
  19901. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  19902. $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  19903. }
  19904. }
  19905. } else {
  19906. $this->setPageBuffer($startlinepage, $pstart.$pend);
  19907. // shift the annotations and links
  19908. if (isset($this->PageAnnots[$this->page])) {
  19909. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  19910. if ($pak >= $pask) {
  19911. $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  19912. $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  19913. }
  19914. }
  19915. }
  19916. }
  19917. $this->y -= $yshift;
  19918. }
  19919. }
  19920. // restore previous values
  19921. $this->setGraphicVars($gvars);
  19922. if ($this->num_columns > 1) {
  19923. $this->selectColumn();
  19924. } elseif ($this->page > $prevPage) {
  19925. $this->lMargin = $this->pagedim[$this->page]['olm'];
  19926. $this->rMargin = $this->pagedim[$this->page]['orm'];
  19927. }
  19928. // restore previous list state
  19929. $this->cell_height_ratio = $prev_cell_height_ratio;
  19930. $this->listnum = $prev_listnum;
  19931. $this->listordered = $prev_listordered;
  19932. $this->listcount = $prev_listcount;
  19933. $this->lispacer = $prev_lispacer;
  19934. if ($ln AND (!($cell AND ($dom[$key-1]['value'] == 'table')))) {
  19935. $this->Ln($this->lasth);
  19936. if ($this->y < $maxbottomliney) {
  19937. $this->y = $maxbottomliney;
  19938. }
  19939. }
  19940. unset($dom);
  19941. }
  19942. /**
  19943. * Process opening tags.
  19944. * @param $dom (array) html dom array
  19945. * @param $key (int) current element id
  19946. * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
  19947. * @protected
  19948. */
  19949. protected function openHTMLTagHandler(&$dom, $key, $cell) {
  19950. $tag = $dom[$key];
  19951. $parent = $dom[($dom[$key]['parent'])];
  19952. $firsttag = ($key == 1);
  19953. // check for text direction attribute
  19954. if (isset($tag['dir'])) {
  19955. $this->setTempRTL($tag['dir']);
  19956. } else {
  19957. $this->tmprtl = false;
  19958. }
  19959. if ($tag['block']) {
  19960. $hbz = 0; // distance from y to line bottom
  19961. $hb = 0; // vertical space between block tags
  19962. // calculate vertical space for block tags
  19963. if (isset($this->tagvspaces[$tag['value']][0]['h']) AND ($this->tagvspaces[$tag['value']][0]['h'] >= 0)) {
  19964. $cur_h = $this->tagvspaces[$tag['value']][0]['h'];
  19965. } elseif (isset($tag['fontsize'])) {
  19966. $cur_h = ($tag['fontsize'] / $this->k) * $this->cell_height_ratio;
  19967. } else {
  19968. $cur_h = $this->FontSize * $this->cell_height_ratio;
  19969. }
  19970. if (isset($this->tagvspaces[$tag['value']][0]['n'])) {
  19971. $n = $this->tagvspaces[$tag['value']][0]['n'];
  19972. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  19973. $n = 0.6;
  19974. } else {
  19975. $n = 1;
  19976. }
  19977. $hb = ($n * $cur_h);
  19978. if (($this->htmlvspace <= 0) AND ($n > 0)) {
  19979. if (isset($parent['fontsize'])) {
  19980. $hbz = (($parent['fontsize'] / $this->k) * $this->cell_height_ratio);
  19981. } else {
  19982. $hbz = $this->FontSize * $this->cell_height_ratio;
  19983. }
  19984. }
  19985. }
  19986. // Opening tag
  19987. switch($tag['value']) {
  19988. case 'table': {
  19989. $cp = 0;
  19990. $cs = 0;
  19991. $dom[$key]['rowspans'] = array();
  19992. if (!isset($dom[$key]['attribute']['nested']) OR ($dom[$key]['attribute']['nested'] != 'true')) {
  19993. // set table header
  19994. if (!$this->empty_string($dom[$key]['thead'])) {
  19995. // set table header
  19996. $this->thead = $dom[$key]['thead'];
  19997. if (!isset($this->theadMargins) OR (empty($this->theadMargins))) {
  19998. $this->theadMargins = array();
  19999. $this->theadMargins['cell_padding'] = $this->cell_padding;
  20000. $this->theadMargins['lmargin'] = $this->lMargin;
  20001. $this->theadMargins['rmargin'] = $this->rMargin;
  20002. $this->theadMargins['page'] = $this->page;
  20003. }
  20004. }
  20005. }
  20006. // store current margins and page
  20007. $dom[$key]['old_cell_padding'] = $this->cell_padding;
  20008. if (isset($tag['attribute']['cellpadding'])) {
  20009. $pad = $this->getHTMLUnitToUnits($tag['attribute']['cellpadding'], 1, 'px');
  20010. $this->SetCellPadding($pad);
  20011. } elseif (isset($tag['padding'])) {
  20012. $this->cell_padding = $tag['padding'];
  20013. }
  20014. if (isset($tag['attribute']['cellspacing'])) {
  20015. $cs = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
  20016. } elseif (isset($tag['border-spacing'])) {
  20017. $cs = $tag['border-spacing']['V'];
  20018. }
  20019. $prev_y = $this->y;
  20020. if ($this->checkPageBreak(((2 * $cp) + (2 * $cs) + $this->lasth), '', false) OR ($this->y < $prev_y)) {
  20021. $this->inthead = true;
  20022. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  20023. $this->checkPageBreak($this->PageBreakTrigger + 1);
  20024. }
  20025. break;
  20026. }
  20027. case 'tr': {
  20028. // array of columns positions
  20029. $dom[$key]['cellpos'] = array();
  20030. break;
  20031. }
  20032. case 'hr': {
  20033. if ((isset($tag['height'])) AND ($tag['height'] != '')) {
  20034. $hrHeight = $this->getHTMLUnitToUnits($tag['height'], 1, 'px');
  20035. } else {
  20036. $hrHeight = $this->GetLineWidth();
  20037. }
  20038. $this->addHTMLVertSpace($hbz, ($hrHeight / 2), $cell, $firsttag);
  20039. $x = $this->GetX();
  20040. $y = $this->GetY();
  20041. $wtmp = $this->w - $this->lMargin - $this->rMargin;
  20042. if ($cell) {
  20043. $wtmp -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  20044. }
  20045. if ((isset($tag['width'])) AND ($tag['width'] != '')) {
  20046. $hrWidth = $this->getHTMLUnitToUnits($tag['width'], $wtmp, 'px');
  20047. } else {
  20048. $hrWidth = $wtmp;
  20049. }
  20050. $prevlinewidth = $this->GetLineWidth();
  20051. $this->SetLineWidth($hrHeight);
  20052. $this->Line($x, $y, $x + $hrWidth, $y);
  20053. $this->SetLineWidth($prevlinewidth);
  20054. $this->addHTMLVertSpace(($hrHeight / 2), 0, $cell, !isset($dom[($key + 1)]));
  20055. break;
  20056. }
  20057. case 'a': {
  20058. if (array_key_exists('href', $tag['attribute'])) {
  20059. $this->HREF['url'] = $tag['attribute']['href'];
  20060. }
  20061. break;
  20062. }
  20063. case 'img': {
  20064. if (isset($tag['attribute']['src'])) {
  20065. // replace relative path with real server path
  20066. if (($tag['attribute']['src'][0] == '/') AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
  20067. $findroot = strpos($tag['attribute']['src'], $_SERVER['DOCUMENT_ROOT']);
  20068. if (($findroot === false) OR ($findroot > 1)) {
  20069. $tag['attribute']['src'] = $_SERVER['DOCUMENT_ROOT'].$tag['attribute']['src'];
  20070. }
  20071. }
  20072. $tag['attribute']['src'] = urldecode($tag['attribute']['src']);
  20073. $type = $this->getImageFileType($tag['attribute']['src']);
  20074. $testscrtype = @parse_url($tag['attribute']['src']);
  20075. if (!isset($testscrtype['query']) OR empty($testscrtype['query'])) {
  20076. // convert URL to server path
  20077. $tag['attribute']['src'] = str_replace(K_PATH_URL, K_PATH_MAIN, $tag['attribute']['src']);
  20078. }
  20079. if (!isset($tag['width'])) {
  20080. $tag['width'] = 0;
  20081. }
  20082. if (!isset($tag['height'])) {
  20083. $tag['height'] = 0;
  20084. }
  20085. //if (!isset($tag['attribute']['align'])) {
  20086. // the only alignment supported is "bottom"
  20087. // further development is required for other modes.
  20088. $tag['attribute']['align'] = 'bottom';
  20089. //}
  20090. switch($tag['attribute']['align']) {
  20091. case 'top': {
  20092. $align = 'T';
  20093. break;
  20094. }
  20095. case 'middle': {
  20096. $align = 'M';
  20097. break;
  20098. }
  20099. case 'bottom': {
  20100. $align = 'B';
  20101. break;
  20102. }
  20103. default: {
  20104. $align = 'B';
  20105. break;
  20106. }
  20107. }
  20108. $prevy = $this->y;
  20109. $xpos = $this->x;
  20110. $imglink = '';
  20111. if (isset($this->HREF['url']) AND !$this->empty_string($this->HREF['url'])) {
  20112. $imglink = $this->HREF['url'];
  20113. if ($imglink{0} == '#') {
  20114. // convert url to internal link
  20115. $lnkdata = explode(',', $imglink);
  20116. if (isset($lnkdata[0])) {
  20117. $page = intval(substr($lnkdata[0], 1));
  20118. if (empty($page) OR ($page <= 0)) {
  20119. $page = $this->page;
  20120. }
  20121. if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
  20122. $lnky = floatval($lnkdata[1]);
  20123. } else {
  20124. $lnky = 0;
  20125. }
  20126. $imglink = $this->AddLink();
  20127. $this->SetLink($imglink, $lnky, $page);
  20128. }
  20129. }
  20130. }
  20131. $border = 0;
  20132. if (isset($tag['border']) AND !empty($tag['border'])) {
  20133. // currently only support 1 (frame) or a combination of 'LTRB'
  20134. $border = $tag['border'];
  20135. }
  20136. $iw = '';
  20137. if (isset($tag['width'])) {
  20138. $iw = $this->getHTMLUnitToUnits($tag['width'], 1, 'px', false);
  20139. }
  20140. $ih = '';
  20141. if (isset($tag['height'])) {
  20142. $ih = $this->getHTMLUnitToUnits($tag['height'], 1, 'px', false);
  20143. }
  20144. if (($type == 'eps') OR ($type == 'ai')) {
  20145. $this->ImageEps($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, $imglink, true, $align, '', $border, true);
  20146. } elseif ($type == 'svg') {
  20147. $this->ImageSVG($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, $imglink, $align, '', $border, true);
  20148. } else {
  20149. $this->Image($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, '', $imglink, $align, false, 300, '', false, false, $border, false, false, true);
  20150. }
  20151. switch($align) {
  20152. case 'T': {
  20153. $this->y = $prevy;
  20154. break;
  20155. }
  20156. case 'M': {
  20157. $this->y = (($this->img_rb_y + $prevy - ($tag['fontsize'] / $this->k)) / 2) ;
  20158. break;
  20159. }
  20160. case 'B': {
  20161. $this->y = $this->img_rb_y - ($tag['fontsize'] / $this->k);
  20162. break;
  20163. }
  20164. }
  20165. }
  20166. break;
  20167. }
  20168. case 'dl': {
  20169. ++$this->listnum;
  20170. if ($this->listnum == 1) {
  20171. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  20172. } else {
  20173. $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
  20174. }
  20175. break;
  20176. }
  20177. case 'dt': {
  20178. $this->addHTMLVertSpace($hbz, 0, $cell, $firsttag);
  20179. break;
  20180. }
  20181. case 'dd': {
  20182. if ($this->rtl) {
  20183. $this->rMargin += $this->listindent;
  20184. } else {
  20185. $this->lMargin += $this->listindent;
  20186. }
  20187. ++$this->listindentlevel;
  20188. $this->addHTMLVertSpace($hbz, 0, $cell, $firsttag);
  20189. break;
  20190. }
  20191. case 'ul':
  20192. case 'ol': {
  20193. ++$this->listnum;
  20194. if ($tag['value'] == 'ol') {
  20195. $this->listordered[$this->listnum] = true;
  20196. } else {
  20197. $this->listordered[$this->listnum] = false;
  20198. }
  20199. if (isset($tag['attribute']['start'])) {
  20200. $this->listcount[$this->listnum] = intval($tag['attribute']['start']) - 1;
  20201. } else {
  20202. $this->listcount[$this->listnum] = 0;
  20203. }
  20204. if ($this->rtl) {
  20205. $this->rMargin += $this->listindent;
  20206. $this->x -= $this->listindent;
  20207. } else {
  20208. $this->lMargin += $this->listindent;
  20209. $this->x += $this->listindent;
  20210. }
  20211. ++$this->listindentlevel;
  20212. if ($this->listnum == 1) {
  20213. if ($key > 1) {
  20214. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  20215. }
  20216. } else {
  20217. $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
  20218. }
  20219. break;
  20220. }
  20221. case 'li': {
  20222. if ($key > 2) {
  20223. $this->addHTMLVertSpace($hbz, 0, $cell, $firsttag);
  20224. }
  20225. if ($this->listordered[$this->listnum]) {
  20226. // ordered item
  20227. if (isset($parent['attribute']['type']) AND !$this->empty_string($parent['attribute']['type'])) {
  20228. $this->lispacer = $parent['attribute']['type'];
  20229. } elseif (isset($parent['listtype']) AND !$this->empty_string($parent['listtype'])) {
  20230. $this->lispacer = $parent['listtype'];
  20231. } elseif (isset($this->lisymbol) AND !$this->empty_string($this->lisymbol)) {
  20232. $this->lispacer = $this->lisymbol;
  20233. } else {
  20234. $this->lispacer = '#';
  20235. }
  20236. ++$this->listcount[$this->listnum];
  20237. if (isset($tag['attribute']['value'])) {
  20238. $this->listcount[$this->listnum] = intval($tag['attribute']['value']);
  20239. }
  20240. } else {
  20241. // unordered item
  20242. if (isset($parent['attribute']['type']) AND !$this->empty_string($parent['attribute']['type'])) {
  20243. $this->lispacer = $parent['attribute']['type'];
  20244. } elseif (isset($parent['listtype']) AND !$this->empty_string($parent['listtype'])) {
  20245. $this->lispacer = $parent['listtype'];
  20246. } elseif (isset($this->lisymbol) AND !$this->empty_string($this->lisymbol)) {
  20247. $this->lispacer = $this->lisymbol;
  20248. } else {
  20249. $this->lispacer = '!';
  20250. }
  20251. }
  20252. break;
  20253. }
  20254. case 'blockquote': {
  20255. if ($this->rtl) {
  20256. $this->rMargin += $this->listindent;
  20257. } else {
  20258. $this->lMargin += $this->listindent;
  20259. }
  20260. ++$this->listindentlevel;
  20261. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  20262. break;
  20263. }
  20264. case 'br': {
  20265. $this->addHTMLVertSpace($hbz, 0, $cell, $firsttag);
  20266. break;
  20267. }
  20268. case 'div': {
  20269. $this->addHTMLVertSpace($hbz, 0, $cell, $firsttag);
  20270. break;
  20271. }
  20272. case 'p': {
  20273. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  20274. break;
  20275. }
  20276. case 'pre': {
  20277. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  20278. $this->premode = true;
  20279. break;
  20280. }
  20281. case 'sup': {
  20282. $this->SetXY($this->GetX(), $this->GetY() - ((0.7 * $this->FontSizePt) / $this->k));
  20283. break;
  20284. }
  20285. case 'sub': {
  20286. $this->SetXY($this->GetX(), $this->GetY() + ((0.3 * $this->FontSizePt) / $this->k));
  20287. break;
  20288. }
  20289. case 'h1':
  20290. case 'h2':
  20291. case 'h3':
  20292. case 'h4':
  20293. case 'h5':
  20294. case 'h6': {
  20295. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  20296. break;
  20297. }
  20298. // Form fields (since 4.8.000 - 2009-09-07)
  20299. case 'form': {
  20300. if (isset($tag['attribute']['action'])) {
  20301. $this->form_action = $tag['attribute']['action'];
  20302. } else {
  20303. $this->form_action = K_PATH_URL.$_SERVER['SCRIPT_NAME'];
  20304. }
  20305. if (isset($tag['attribute']['enctype'])) {
  20306. $this->form_enctype = $tag['attribute']['enctype'];
  20307. } else {
  20308. $this->form_enctype = 'application/x-www-form-urlencoded';
  20309. }
  20310. if (isset($tag['attribute']['method'])) {
  20311. $this->form_mode = $tag['attribute']['method'];
  20312. } else {
  20313. $this->form_mode = 'post';
  20314. }
  20315. break;
  20316. }
  20317. case 'input': {
  20318. if (isset($tag['attribute']['name']) AND !$this->empty_string($tag['attribute']['name'])) {
  20319. $name = $tag['attribute']['name'];
  20320. } else {
  20321. break;
  20322. }
  20323. $prop = array();
  20324. $opt = array();
  20325. if (isset($tag['attribute']['readonly']) AND !$this->empty_string($tag['attribute']['readonly'])) {
  20326. $prop['readonly'] = true;
  20327. }
  20328. if (isset($tag['attribute']['value']) AND !$this->empty_string($tag['attribute']['value'])) {
  20329. $value = $tag['attribute']['value'];
  20330. }
  20331. if (isset($tag['attribute']['maxlength']) AND !$this->empty_string($tag['attribute']['maxlength'])) {
  20332. $opt['maxlen'] = intval($tag['attribute']['value']);
  20333. }
  20334. $h = $this->FontSize * $this->cell_height_ratio;
  20335. if (isset($tag['attribute']['size']) AND !$this->empty_string($tag['attribute']['size'])) {
  20336. $w = intval($tag['attribute']['size']) * $this->GetStringWidth(chr(32)) * 2;
  20337. } else {
  20338. $w = $h;
  20339. }
  20340. if (isset($tag['attribute']['checked']) AND (($tag['attribute']['checked'] == 'checked') OR ($tag['attribute']['checked'] == 'true'))) {
  20341. $checked = true;
  20342. } else {
  20343. $checked = false;
  20344. }
  20345. switch ($tag['attribute']['type']) {
  20346. case 'text': {
  20347. if (isset($value)) {
  20348. $opt['v'] = $value;
  20349. }
  20350. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  20351. break;
  20352. }
  20353. case 'password': {
  20354. if (isset($value)) {
  20355. $opt['v'] = $value;
  20356. }
  20357. $prop['password'] = 'true';
  20358. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  20359. break;
  20360. }
  20361. case 'checkbox': {
  20362. $this->CheckBox($name, $w, $checked, $prop, $opt, $value, '', '', false);
  20363. break;
  20364. }
  20365. case 'radio': {
  20366. $this->RadioButton($name, $w, $prop, $opt, $value, $checked, '', '', false);
  20367. break;
  20368. }
  20369. case 'submit': {
  20370. $w = $this->GetStringWidth($value) * 1.5;
  20371. $h *= 1.6;
  20372. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  20373. $action = array();
  20374. $action['S'] = 'SubmitForm';
  20375. $action['F'] = $this->form_action;
  20376. if ($this->form_enctype != 'FDF') {
  20377. $action['Flags'] = array('ExportFormat');
  20378. }
  20379. if ($this->form_mode == 'get') {
  20380. $action['Flags'] = array('GetMethod');
  20381. }
  20382. $this->Button($name, $w, $h, $value, $action, $prop, $opt, '', '', false);
  20383. break;
  20384. }
  20385. case 'reset': {
  20386. $w = $this->GetStringWidth($value) * 1.5;
  20387. $h *= 1.6;
  20388. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  20389. $this->Button($name, $w, $h, $value, array('S'=>'ResetForm'), $prop, $opt, '', '', false);
  20390. break;
  20391. }
  20392. case 'file': {
  20393. $prop['fileSelect'] = 'true';
  20394. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  20395. if (!isset($value)) {
  20396. $value = '*';
  20397. }
  20398. $w = $this->GetStringWidth($value) * 2;
  20399. $h *= 1.2;
  20400. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  20401. $jsaction = 'var f=this.getField(\''.$name.'\'); f.browseForFileToSubmit();';
  20402. $this->Button('FB_'.$name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  20403. break;
  20404. }
  20405. case 'hidden': {
  20406. if (isset($value)) {
  20407. $opt['v'] = $value;
  20408. }
  20409. $opt['f'] = array('invisible', 'hidden');
  20410. $this->TextField($name, 0, 0, $prop, $opt, '', '', false);
  20411. break;
  20412. }
  20413. case 'image': {
  20414. // THIS TYPE MUST BE FIXED
  20415. if (isset($tag['attribute']['src']) AND !$this->empty_string($tag['attribute']['src'])) {
  20416. $img = $tag['attribute']['src'];
  20417. } else {
  20418. break;
  20419. }
  20420. $value = 'img';
  20421. //$opt['mk'] = array('i'=>$img, 'tp'=>1, 'if'=>array('sw'=>'A', 's'=>'A', 'fb'=>false));
  20422. if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
  20423. $jsaction = $tag['attribute']['onclick'];
  20424. } else {
  20425. $jsaction = '';
  20426. }
  20427. $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  20428. break;
  20429. }
  20430. case 'button': {
  20431. $w = $this->GetStringWidth($value) * 1.5;
  20432. $h *= 1.6;
  20433. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  20434. if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
  20435. $jsaction = $tag['attribute']['onclick'];
  20436. } else {
  20437. $jsaction = '';
  20438. }
  20439. $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  20440. break;
  20441. }
  20442. }
  20443. break;
  20444. }
  20445. case 'textarea': {
  20446. $prop = array();
  20447. $opt = array();
  20448. if (isset($tag['attribute']['readonly']) AND !$this->empty_string($tag['attribute']['readonly'])) {
  20449. $prop['readonly'] = true;
  20450. }
  20451. if (isset($tag['attribute']['name']) AND !$this->empty_string($tag['attribute']['name'])) {
  20452. $name = $tag['attribute']['name'];
  20453. } else {
  20454. break;
  20455. }
  20456. if (isset($tag['attribute']['value']) AND !$this->empty_string($tag['attribute']['value'])) {
  20457. $opt['v'] = $tag['attribute']['value'];
  20458. }
  20459. if (isset($tag['attribute']['cols']) AND !$this->empty_string($tag['attribute']['cols'])) {
  20460. $w = intval($tag['attribute']['cols']) * $this->GetStringWidth(chr(32)) * 2;
  20461. } else {
  20462. $w = 40;
  20463. }
  20464. if (isset($tag['attribute']['rows']) AND !$this->empty_string($tag['attribute']['rows'])) {
  20465. $h = intval($tag['attribute']['rows']) * $this->FontSize * $this->cell_height_ratio;
  20466. } else {
  20467. $h = 10;
  20468. }
  20469. $prop['multiline'] = 'true';
  20470. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  20471. break;
  20472. }
  20473. case 'select': {
  20474. $h = $this->FontSize * $this->cell_height_ratio;
  20475. if (isset($tag['attribute']['size']) AND !$this->empty_string($tag['attribute']['size'])) {
  20476. $h *= ($tag['attribute']['size'] + 1);
  20477. }
  20478. $prop = array();
  20479. $opt = array();
  20480. if (isset($tag['attribute']['name']) AND !$this->empty_string($tag['attribute']['name'])) {
  20481. $name = $tag['attribute']['name'];
  20482. } else {
  20483. break;
  20484. }
  20485. $w = 0;
  20486. if (isset($tag['attribute']['opt']) AND !$this->empty_string($tag['attribute']['opt'])) {
  20487. $options = explode('#!NwL!#', $tag['attribute']['opt']);
  20488. $values = array();
  20489. foreach ($options as $val) {
  20490. if (strpos($val, '#!TaB!#') !== false) {
  20491. $opts = explode('#!TaB!#', $val);
  20492. $values[] = $opts;
  20493. $w = max($w, $this->GetStringWidth($opts[1]));
  20494. } else {
  20495. $values[] = $val;
  20496. $w = max($w, $this->GetStringWidth($val));
  20497. }
  20498. }
  20499. } else {
  20500. break;
  20501. }
  20502. $w *= 2;
  20503. if (isset($tag['attribute']['multiple']) AND ($tag['attribute']['multiple']='multiple')) {
  20504. $prop['multipleSelection'] = 'true';
  20505. $this->ListBox($name, $w, $h, $values, $prop, $opt, '', '', false);
  20506. } else {
  20507. $this->ComboBox($name, $w, $h, $values, $prop, $opt, '', '', false);
  20508. }
  20509. break;
  20510. }
  20511. case 'tcpdf': {
  20512. if (defined('K_TCPDF_CALLS_IN_HTML') AND (K_TCPDF_CALLS_IN_HTML === true)) {
  20513. // Special tag used to call TCPDF methods
  20514. if (isset($tag['attribute']['method'])) {
  20515. $tcpdf_method = $tag['attribute']['method'];
  20516. if (method_exists($this, $tcpdf_method)) {
  20517. if (isset($tag['attribute']['params']) AND (!empty($tag['attribute']['params']))) {
  20518. $params = unserialize(urldecode($tag['attribute']['params']));
  20519. call_user_func_array(array($this, $tcpdf_method), $params);
  20520. } else {
  20521. $this->$tcpdf_method();
  20522. }
  20523. $this->newline = true;
  20524. }
  20525. }
  20526. }
  20527. break;
  20528. }
  20529. default: {
  20530. break;
  20531. }
  20532. }
  20533. // define tags that support borders and background colors
  20534. $bordertags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table');
  20535. if (in_array($tag['value'], $bordertags)) {
  20536. // set border
  20537. $dom[$key]['borderposition'] = $this->getBorderStartPosition();
  20538. }
  20539. if ($dom[$key]['self'] AND isset($dom[$key]['attribute']['pagebreakafter'])) {
  20540. $pba = $dom[$key]['attribute']['pagebreakafter'];
  20541. // check for pagebreak
  20542. if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
  20543. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  20544. $this->checkPageBreak($this->PageBreakTrigger + 1);
  20545. }
  20546. if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  20547. OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  20548. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  20549. $this->checkPageBreak($this->PageBreakTrigger + 1);
  20550. }
  20551. }
  20552. }
  20553. /**
  20554. * Process closing tags.
  20555. * @param $dom (array) html dom array
  20556. * @param $key (int) current element id
  20557. * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
  20558. * @param $maxbottomliney (int) maximum y value of current line
  20559. * @protected
  20560. */
  20561. protected function closeHTMLTagHandler(&$dom, $key, $cell, $maxbottomliney=0) {
  20562. $tag = $dom[$key];
  20563. $parent = $dom[($dom[$key]['parent'])];
  20564. $lasttag = ((!isset($dom[($key + 1)])) OR ((!isset($dom[($key + 2)])) AND ($dom[($key + 1)]['value'] == 'marker')));
  20565. $in_table_head = false;
  20566. // maximum x position (used to draw borders)
  20567. if ($this->rtl) {
  20568. $xmax = $this->w;
  20569. } else {
  20570. $xmax = 0;
  20571. }
  20572. if ($tag['block']) {
  20573. $hbz = 0; // distance from y to line bottom
  20574. $hb = 0; // vertical space between block tags
  20575. // calculate vertical space for block tags
  20576. if (isset($this->tagvspaces[$tag['value']][1]['h']) AND ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) {
  20577. $pre_h = $this->tagvspaces[$tag['value']][1]['h'];
  20578. } elseif (isset($parent['fontsize'])) {
  20579. $pre_h = (($parent['fontsize'] / $this->k) * $this->cell_height_ratio);
  20580. } else {
  20581. $pre_h = $this->FontSize * $this->cell_height_ratio;
  20582. }
  20583. if (isset($this->tagvspaces[$tag['value']][1]['n'])) {
  20584. $n = $this->tagvspaces[$tag['value']][1]['n'];
  20585. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  20586. $n = 0.6;
  20587. } else {
  20588. $n = 1;
  20589. }
  20590. $hb = ($n * $pre_h);
  20591. if ($this->y < $maxbottomliney) {
  20592. $hbz = ($maxbottomliney - $this->y);
  20593. }
  20594. }
  20595. // Closing tag
  20596. switch($tag['value']) {
  20597. case 'tr': {
  20598. $table_el = $dom[($dom[$key]['parent'])]['parent'];
  20599. if (!isset($parent['endy'])) {
  20600. $dom[($dom[$key]['parent'])]['endy'] = $this->y;
  20601. $parent['endy'] = $this->y;
  20602. }
  20603. if (!isset($parent['endpage'])) {
  20604. $dom[($dom[$key]['parent'])]['endpage'] = $this->page;
  20605. $parent['endpage'] = $this->page;
  20606. }
  20607. if (!isset($parent['endcolumn'])) {
  20608. $dom[($dom[$key]['parent'])]['endcolumn'] = $this->current_column;
  20609. $parent['endcolumn'] = $this->current_column;
  20610. }
  20611. // update row-spanned cells
  20612. if (isset($dom[$table_el]['rowspans'])) {
  20613. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  20614. $dom[$table_el]['rowspans'][$k]['rowspan'] -= 1;
  20615. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  20616. if (($dom[$table_el]['rowspans'][$k]['endpage'] == $parent['endpage']) AND ($dom[$table_el]['rowspans'][$k]['endcolumn'] == $parent['endcolumn'])) {
  20617. $dom[($dom[$key]['parent'])]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $parent['endy']);
  20618. } elseif (($dom[$table_el]['rowspans'][$k]['endpage'] > $parent['endpage']) OR ($dom[$table_el]['rowspans'][$k]['endcolumn'] > $parent['endcolumn'])) {
  20619. $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  20620. $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  20621. $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  20622. }
  20623. }
  20624. }
  20625. // report new endy and endpage to the rowspanned cells
  20626. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  20627. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  20628. $dom[$table_el]['rowspans'][$k]['endpage'] = max($dom[$table_el]['rowspans'][$k]['endpage'], $dom[($dom[$key]['parent'])]['endpage']);
  20629. $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  20630. $dom[$table_el]['rowspans'][$k]['endcolumn'] = max($dom[$table_el]['rowspans'][$k]['endcolumn'], $dom[($dom[$key]['parent'])]['endcolumn']);
  20631. $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  20632. $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $dom[($dom[$key]['parent'])]['endy']);
  20633. $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  20634. }
  20635. }
  20636. // update remaining rowspanned cells
  20637. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  20638. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  20639. $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[($dom[$key]['parent'])]['endpage'];
  20640. $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[($dom[$key]['parent'])]['endcolumn'];
  20641. $dom[$table_el]['rowspans'][$k]['endy'] = $dom[($dom[$key]['parent'])]['endy'];
  20642. }
  20643. }
  20644. }
  20645. $this->setPage($dom[($dom[$key]['parent'])]['endpage']);
  20646. if ($this->num_columns > 1) {
  20647. $this->selectColumn($dom[($dom[$key]['parent'])]['endcolumn']);
  20648. }
  20649. $this->y = $dom[($dom[$key]['parent'])]['endy'];
  20650. if (isset($dom[$table_el]['attribute']['cellspacing'])) {
  20651. $this->y += $this->getHTMLUnitToUnits($dom[$table_el]['attribute']['cellspacing'], 1, 'px');
  20652. } elseif (isset($dom[$table_el]['border-spacing'])) {
  20653. $this->y += $dom[$table_el]['border-spacing']['V'];
  20654. }
  20655. $this->Ln(0, $cell);
  20656. if ($this->current_column == $parent['startcolumn']) {
  20657. $this->x = $parent['startx'];
  20658. }
  20659. // account for booklet mode
  20660. if ($this->page > $parent['startpage']) {
  20661. if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$parent['startpage']]['orm'])) {
  20662. $this->x -= ($this->pagedim[$this->page]['orm'] - $this->pagedim[$parent['startpage']]['orm']);
  20663. } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$parent['startpage']]['olm'])) {
  20664. $this->x += ($this->pagedim[$this->page]['olm'] - $this->pagedim[$parent['startpage']]['olm']);
  20665. }
  20666. }
  20667. break;
  20668. }
  20669. case 'tablehead':
  20670. // closing tag used for the thead part
  20671. $in_table_head = true;
  20672. $this->inthead = false;
  20673. case 'table': {
  20674. $table_el = $parent;
  20675. // set default border
  20676. if (isset($table_el['attribute']['border']) AND ($table_el['attribute']['border'] > 0)) {
  20677. // set default border
  20678. $border = array('LTRB' => array('width' => $this->getCSSBorderWidth($table_el['attribute']['border']), 'cap'=>'square', 'join'=>'miter', 'dash'=> 0, 'color'=>array(0,0,0)));
  20679. } else {
  20680. $border = 0;
  20681. }
  20682. $default_border = $border;
  20683. // fix bottom line alignment of last line before page break
  20684. foreach ($dom[($dom[$key]['parent'])]['trids'] as $j => $trkey) {
  20685. // update row-spanned cells
  20686. if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  20687. foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
  20688. if ($trwsp['trid'] == $trkey) {
  20689. $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] -= 1;
  20690. }
  20691. if (isset($prevtrkey) AND ($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] >= 0)) {
  20692. $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] = $trkey;
  20693. }
  20694. }
  20695. }
  20696. if (isset($prevtrkey) AND ($dom[$trkey]['startpage'] > $dom[$prevtrkey]['endpage'])) {
  20697. $pgendy = $this->pagedim[$dom[$prevtrkey]['endpage']]['hk'] - $this->pagedim[$dom[$prevtrkey]['endpage']]['bm'];
  20698. $dom[$prevtrkey]['endy'] = $pgendy;
  20699. // update row-spanned cells
  20700. if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  20701. foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
  20702. if (($trwsp['trid'] == $trkey) AND ($trwsp['mrowspan'] > 1) AND ($trwsp['endpage'] == $dom[$prevtrkey]['endpage'])) {
  20703. $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'] = $pgendy;
  20704. $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] = -1;
  20705. }
  20706. }
  20707. }
  20708. }
  20709. $prevtrkey = $trkey;
  20710. $table_el = $dom[($dom[$key]['parent'])];
  20711. }
  20712. // for each row
  20713. unset($xmax);
  20714. foreach ($table_el['trids'] as $j => $trkey) {
  20715. $parent = $dom[$trkey];
  20716. if (!isset($xmax)) {
  20717. $xmax = $parent['cellpos'][(count($parent['cellpos']) - 1)]['endx'];
  20718. }
  20719. // for each cell on the row
  20720. foreach ($parent['cellpos'] as $k => $cellpos) {
  20721. if (isset($cellpos['rowspanid']) AND ($cellpos['rowspanid'] >= 0)) {
  20722. $cellpos['startx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['startx'];
  20723. $cellpos['endx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['endx'];
  20724. $endy = $table_el['rowspans'][($cellpos['rowspanid'])]['endy'];
  20725. $startpage = $table_el['rowspans'][($cellpos['rowspanid'])]['startpage'];
  20726. $endpage = $table_el['rowspans'][($cellpos['rowspanid'])]['endpage'];
  20727. $startcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['startcolumn'];
  20728. $endcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['endcolumn'];
  20729. } else {
  20730. $endy = $parent['endy'];
  20731. $startpage = $parent['startpage'];
  20732. $endpage = $parent['endpage'];
  20733. $startcolumn = $parent['startcolumn'];
  20734. $endcolumn = $parent['endcolumn'];
  20735. }
  20736. if ($this->num_columns == 0) {
  20737. $this->num_columns = 1;
  20738. }
  20739. if (isset($cellpos['border'])) {
  20740. $border = $cellpos['border'];
  20741. }
  20742. if (isset($cellpos['bgcolor']) AND ($cellpos['bgcolor']) !== false) {
  20743. $this->SetFillColorArray($cellpos['bgcolor']);
  20744. $fill = true;
  20745. } else {
  20746. $fill = false;
  20747. }
  20748. $x = $cellpos['startx'];
  20749. $y = $parent['starty'];
  20750. $starty = $y;
  20751. $w = abs($cellpos['endx'] - $cellpos['startx']);
  20752. // get border modes
  20753. $border_start = $this->getBorderMode($border, $position='start');
  20754. $border_end = $this->getBorderMode($border, $position='end');
  20755. $border_middle = $this->getBorderMode($border, $position='middle');
  20756. // design borders around HTML cells.
  20757. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  20758. $ccode = '';
  20759. $this->setPage($page);
  20760. if ($this->num_columns < 2) {
  20761. // single-column mode
  20762. $this->x = $x;
  20763. $this->y = $this->tMargin;
  20764. }
  20765. // account for margin changes
  20766. if ($page > $startpage) {
  20767. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  20768. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  20769. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  20770. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  20771. }
  20772. }
  20773. if ($startpage == $endpage) { // single page
  20774. $deltacol = 0;
  20775. $deltath = 0;
  20776. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  20777. $this->selectColumn($column);
  20778. if ($startcolumn == $endcolumn) { // single column
  20779. $cborder = $border;
  20780. $h = $endy - $parent['starty'];
  20781. $this->y = $y;
  20782. $this->x = $x;
  20783. } elseif ($column == $startcolumn) { // first column
  20784. $cborder = $border_start;
  20785. $this->y = $starty;
  20786. $this->x = $x;
  20787. $h = $this->h - $this->y - $this->bMargin;
  20788. if ($this->rtl) {
  20789. $deltacol = $this->x + $this->rMargin - $this->w;
  20790. } else {
  20791. $deltacol = $this->x - $this->lMargin;
  20792. }
  20793. } elseif ($column == $endcolumn) { // end column
  20794. $cborder = $border_end;
  20795. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  20796. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  20797. }
  20798. $this->x += $deltacol;
  20799. $h = $endy - $this->y;
  20800. } else { // middle column
  20801. $cborder = $border_middle;
  20802. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  20803. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  20804. }
  20805. $this->x += $deltacol;
  20806. $h = $this->h - $this->y - $this->bMargin;
  20807. }
  20808. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  20809. } // end for each column
  20810. } elseif ($page == $startpage) { // first page
  20811. $deltacol = 0;
  20812. $deltath = 0;
  20813. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  20814. $this->selectColumn($column);
  20815. if ($column == $startcolumn) { // first column
  20816. $cborder = $border_start;
  20817. $this->y = $starty;
  20818. $this->x = $x;
  20819. $h = $this->h - $this->y - $this->bMargin;
  20820. if ($this->rtl) {
  20821. $deltacol = $this->x + $this->rMargin - $this->w;
  20822. } else {
  20823. $deltacol = $this->x - $this->lMargin;
  20824. }
  20825. } else { // middle column
  20826. $cborder = $border_middle;
  20827. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  20828. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  20829. }
  20830. $this->x += $deltacol;
  20831. $h = $this->h - $this->y - $this->bMargin;
  20832. }
  20833. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  20834. } // end for each column
  20835. } elseif ($page == $endpage) { // last page
  20836. $deltacol = 0;
  20837. $deltath = 0;
  20838. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  20839. $this->selectColumn($column);
  20840. if ($column == $endcolumn) { // end column
  20841. $cborder = $border_end;
  20842. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  20843. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  20844. }
  20845. $this->x += $deltacol;
  20846. $h = $endy - $this->y;
  20847. } else { // middle column
  20848. $cborder = $border_middle;
  20849. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  20850. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  20851. }
  20852. $this->x += $deltacol;
  20853. $h = $this->h - $this->y - $this->bMargin;
  20854. }
  20855. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  20856. } // end for each column
  20857. } else { // middle page
  20858. $deltacol = 0;
  20859. $deltath = 0;
  20860. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  20861. $this->selectColumn($column);
  20862. $cborder = $border_middle;
  20863. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  20864. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  20865. }
  20866. $this->x += $deltacol;
  20867. $h = $this->h - $this->y - $this->bMargin;
  20868. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  20869. } // end for each column
  20870. }
  20871. if ($cborder OR $fill) {
  20872. // draw border and fill
  20873. if ($this->inxobj) {
  20874. // we are inside an XObject template
  20875. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  20876. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  20877. $pagemark = &$this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  20878. } else {
  20879. $pagemark = &$this->xobjects[$this->xobjid]['intmrk'];
  20880. }
  20881. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  20882. $pstart = substr($pagebuff, 0, $pagemark);
  20883. $pend = substr($pagebuff, $pagemark);
  20884. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  20885. $pagemark += strlen($ccode);
  20886. } else {
  20887. // draw border and fill
  20888. if (end($this->transfmrk[$this->page]) !== false) {
  20889. $pagemarkkey = key($this->transfmrk[$this->page]);
  20890. $pagemark = &$this->transfmrk[$this->page][$pagemarkkey];
  20891. } elseif ($this->InFooter) {
  20892. $pagemark = &$this->footerpos[$this->page];
  20893. } else {
  20894. $pagemark = &$this->intmrk[$this->page];
  20895. }
  20896. $pagebuff = $this->getPageBuffer($this->page);
  20897. $pstart = substr($pagebuff, 0, $pagemark);
  20898. $pend = substr($pagebuff, $pagemark);
  20899. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  20900. $pagemark += strlen($ccode);
  20901. }
  20902. }
  20903. } // end for each page
  20904. // restore default border
  20905. $border = $default_border;
  20906. } // end for each cell on the row
  20907. if (isset($table_el['attribute']['cellspacing'])) {
  20908. $this->y += $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing'], 1, 'px');
  20909. } elseif (isset($table_el['border-spacing'])) {
  20910. $this->y += $table_el['border-spacing']['V'];
  20911. }
  20912. $this->Ln(0, $cell);
  20913. $this->x = $parent['startx'];
  20914. if ($endpage > $startpage) {
  20915. if (($this->rtl) AND ($this->pagedim[$endpage]['orm'] != $this->pagedim[$startpage]['orm'])) {
  20916. $this->x += ($this->pagedim[$endpage]['orm'] - $this->pagedim[$startpage]['orm']);
  20917. } elseif ((!$this->rtl) AND ($this->pagedim[$endpage]['olm'] != $this->pagedim[$startpage]['olm'])) {
  20918. $this->x += ($this->pagedim[$endpage]['olm'] - $this->pagedim[$startpage]['olm']);
  20919. }
  20920. }
  20921. }
  20922. if (!$in_table_head) { // we are not inside a thead section
  20923. $this->cell_padding = $table_el['old_cell_padding'];
  20924. // reset row height
  20925. $this->resetLastH();
  20926. if (($this->page == ($this->numpages - 1)) AND ($this->pageopen[$this->numpages])) {
  20927. $plendiff = ($this->pagelen[$this->numpages] - $this->emptypagemrk[$this->numpages]);
  20928. if (($plendiff > 0) AND ($plendiff < 60)) {
  20929. $pagediff = substr($this->getPageBuffer($this->numpages), $this->emptypagemrk[$this->numpages], $plendiff);
  20930. if (substr($pagediff, 0, 5) == 'BT /F') {
  20931. // the difference is only a font setting
  20932. $plendiff = 0;
  20933. }
  20934. }
  20935. if ($plendiff == 0) {
  20936. // remove last blank page
  20937. $this->deletePage($this->numpages);
  20938. }
  20939. }
  20940. if (isset($this->theadMargins['top'])) {
  20941. // restore top margin
  20942. $this->tMargin = $this->theadMargins['top'];
  20943. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  20944. }
  20945. if (!isset($table_el['attribute']['nested']) OR ($table_el['attribute']['nested'] != 'true')) {
  20946. // reset main table header
  20947. $this->thead = '';
  20948. $this->theadMargins = array();
  20949. }
  20950. }
  20951. $parent = $table_el;
  20952. break;
  20953. }
  20954. case 'a': {
  20955. $this->HREF = '';
  20956. break;
  20957. }
  20958. case 'sup': {
  20959. $this->SetXY($this->GetX(), $this->GetY() + ((0.7 * $parent['fontsize']) / $this->k));
  20960. break;
  20961. }
  20962. case 'sub': {
  20963. $this->SetXY($this->GetX(), $this->GetY() - ((0.3 * $parent['fontsize'])/$this->k));
  20964. break;
  20965. }
  20966. case 'div': {
  20967. $this->addHTMLVertSpace($hbz, 0, $cell, false, $lasttag);
  20968. break;
  20969. }
  20970. case 'blockquote': {
  20971. if ($this->rtl) {
  20972. $this->rMargin -= $this->listindent;
  20973. } else {
  20974. $this->lMargin -= $this->listindent;
  20975. }
  20976. --$this->listindentlevel;
  20977. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  20978. break;
  20979. }
  20980. case 'p': {
  20981. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  20982. break;
  20983. }
  20984. case 'pre': {
  20985. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  20986. $this->premode = false;
  20987. break;
  20988. }
  20989. case 'dl': {
  20990. --$this->listnum;
  20991. if ($this->listnum <= 0) {
  20992. $this->listnum = 0;
  20993. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  20994. } else {
  20995. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  20996. }
  20997. $this->resetLastH();
  20998. break;
  20999. }
  21000. case 'dt': {
  21001. $this->lispacer = '';
  21002. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  21003. break;
  21004. }
  21005. case 'dd': {
  21006. $this->lispacer = '';
  21007. if ($this->rtl) {
  21008. $this->rMargin -= $this->listindent;
  21009. } else {
  21010. $this->lMargin -= $this->listindent;
  21011. }
  21012. --$this->listindentlevel;
  21013. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  21014. break;
  21015. }
  21016. case 'ul':
  21017. case 'ol': {
  21018. --$this->listnum;
  21019. $this->lispacer = '';
  21020. if ($this->rtl) {
  21021. $this->rMargin -= $this->listindent;
  21022. } else {
  21023. $this->lMargin -= $this->listindent;
  21024. }
  21025. --$this->listindentlevel;
  21026. if ($this->listnum <= 0) {
  21027. $this->listnum = 0;
  21028. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  21029. } else {
  21030. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  21031. }
  21032. $this->resetLastH();
  21033. break;
  21034. }
  21035. case 'li': {
  21036. $this->lispacer = '';
  21037. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  21038. break;
  21039. }
  21040. case 'h1':
  21041. case 'h2':
  21042. case 'h3':
  21043. case 'h4':
  21044. case 'h5':
  21045. case 'h6': {
  21046. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  21047. break;
  21048. }
  21049. // Form fields (since 4.8.000 - 2009-09-07)
  21050. case 'form': {
  21051. $this->form_action = '';
  21052. $this->form_enctype = 'application/x-www-form-urlencoded';
  21053. break;
  21054. }
  21055. default : {
  21056. break;
  21057. }
  21058. }
  21059. // draw border and background (if any)
  21060. $this->drawHTMLTagBorder($parent, $xmax);
  21061. if (isset($dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'])) {
  21062. $pba = $dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'];
  21063. // check for pagebreak
  21064. if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
  21065. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  21066. $this->checkPageBreak($this->PageBreakTrigger + 1);
  21067. }
  21068. if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  21069. OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  21070. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  21071. $this->checkPageBreak($this->PageBreakTrigger + 1);
  21072. }
  21073. }
  21074. $this->tmprtl = false;
  21075. }
  21076. /**
  21077. * Add vertical spaces if needed.
  21078. * @param $hbz (string) Distance between current y and line bottom.
  21079. * @param $hb (string) The height of the break.
  21080. * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
  21081. * @param $firsttag (boolean) set to true when the tag is the first.
  21082. * @param $lasttag (boolean) set to true when the tag is the last.
  21083. * @protected
  21084. */
  21085. protected function addHTMLVertSpace($hbz=0, $hb=0, $cell=false, $firsttag=false, $lasttag=false) {
  21086. if ($firsttag) {
  21087. $this->Ln(0, $cell);
  21088. $this->htmlvspace = 0;
  21089. return;
  21090. }
  21091. if ($lasttag) {
  21092. $this->Ln($hbz, $cell);
  21093. $this->htmlvspace = 0;
  21094. return;
  21095. }
  21096. if ($hb < $this->htmlvspace) {
  21097. $hd = 0;
  21098. } else {
  21099. $hd = $hb - $this->htmlvspace;
  21100. $this->htmlvspace = $hb;
  21101. }
  21102. $this->Ln(($hbz + $hd), $cell);
  21103. }
  21104. /**
  21105. * Return the starting coordinates to draw an html border
  21106. * @return array containing top-left border coordinates
  21107. * @protected
  21108. * @since 5.7.000 (2010-08-03)
  21109. */
  21110. protected function getBorderStartPosition() {
  21111. if ($this->rtl) {
  21112. $xmax = $this->lMargin;
  21113. } else {
  21114. $xmax = $this->w - $this->rMargin;
  21115. }
  21116. return array('page' => $this->page, 'column' => $this->current_column, 'x' => $this->x, 'y' => $this->y, 'xmax' => $xmax);
  21117. }
  21118. /**
  21119. * Draw an HTML block border and fill
  21120. * @param $tag (array) array of tag properties.
  21121. * @param $xmax (int) end X coordinate for border.
  21122. * @protected
  21123. * @since 5.7.000 (2010-08-03)
  21124. */
  21125. protected function drawHTMLTagBorder($tag, $xmax) {
  21126. if (!isset($tag['borderposition'])) {
  21127. // nothing to draw
  21128. return;
  21129. }
  21130. $prev_x = $this->x;
  21131. $prev_y = $this->y;
  21132. $prev_lasth = $this->lasth;
  21133. $border = 0;
  21134. $fill = false;
  21135. $this->lasth = 0;
  21136. if (isset($tag['border']) AND !empty($tag['border'])) {
  21137. // get border style
  21138. $border = $tag['border'];
  21139. if (!$this->empty_string($this->thead) AND (!$this->inthead)) {
  21140. // border for table header
  21141. $border = $this->getBorderMode($border, $position='middle');
  21142. }
  21143. }
  21144. if (isset($tag['bgcolor']) AND ($tag['bgcolor'] !== false)) {
  21145. // get background color
  21146. $old_bgcolor = $this->bgcolor;
  21147. $this->SetFillColorArray($tag['bgcolor']);
  21148. $fill = true;
  21149. }
  21150. if (!$border AND !$fill) {
  21151. // nothing to draw
  21152. return;
  21153. }
  21154. if (isset($tag['attribute']['cellspacing'])) {
  21155. $clsp = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
  21156. $cellspacing = array('H' => $clsp, 'V' => $clsp);
  21157. } elseif (isset($tag['border-spacing'])) {
  21158. $cellspacing = $tag['border-spacing'];
  21159. } else {
  21160. $cellspacing = array('H' => 0, 'V' => 0);
  21161. }
  21162. if (($tag['value'] != 'table') AND (is_array($border)) AND (!empty($border))) {
  21163. // draw the border externally respect the sqare edge.
  21164. $border['mode'] = 'ext';
  21165. }
  21166. if ($this->rtl) {
  21167. if ($xmax >= $tag['borderposition']['x']) {
  21168. $xmax = $tag['borderposition']['xmax'];
  21169. }
  21170. $w = ($tag['borderposition']['x'] - $xmax);
  21171. } else {
  21172. if ($xmax <= $tag['borderposition']['x']) {
  21173. $xmax = $tag['borderposition']['xmax'];
  21174. }
  21175. $w = ($xmax - $tag['borderposition']['x']);
  21176. }
  21177. if ($w <= 0) {
  21178. return;
  21179. }
  21180. $w += $cellspacing['H'];
  21181. $startpage = $tag['borderposition']['page'];
  21182. $startcolumn = $tag['borderposition']['column'];
  21183. $x = $tag['borderposition']['x'];
  21184. $y = $tag['borderposition']['y'];
  21185. $endpage = $this->page;
  21186. $starty = $tag['borderposition']['y'] - $cellspacing['V'];
  21187. $currentY = $this->y;
  21188. $this->x = $x;
  21189. // get latest column
  21190. $endcolumn = $this->current_column;
  21191. if ($this->num_columns == 0) {
  21192. $this->num_columns = 1;
  21193. }
  21194. // get border modes
  21195. $border_start = $this->getBorderMode($border, $position='start');
  21196. $border_end = $this->getBorderMode($border, $position='end');
  21197. $border_middle = $this->getBorderMode($border, $position='middle');
  21198. // temporary disable page regions
  21199. $temp_page_regions = $this->page_regions;
  21200. $this->page_regions = array();
  21201. // design borders around HTML cells.
  21202. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  21203. $ccode = '';
  21204. $this->setPage($page);
  21205. if ($this->num_columns < 2) {
  21206. // single-column mode
  21207. $this->x = $x;
  21208. $this->y = $this->tMargin;
  21209. }
  21210. // account for margin changes
  21211. if ($page > $startpage) {
  21212. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  21213. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  21214. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  21215. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  21216. }
  21217. }
  21218. if ($startpage == $endpage) {
  21219. // single page
  21220. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  21221. $this->selectColumn($column);
  21222. if ($startcolumn == $endcolumn) { // single column
  21223. $cborder = $border;
  21224. $h = ($currentY - $y) + $cellspacing['V'];
  21225. $this->y = $starty;
  21226. } elseif ($column == $startcolumn) { // first column
  21227. $cborder = $border_start;
  21228. $this->y = $starty;
  21229. $h = $this->h - $this->y - $this->bMargin;
  21230. } elseif ($column == $endcolumn) { // end column
  21231. $cborder = $border_end;
  21232. $h = $currentY - $this->y;
  21233. } else { // middle column
  21234. $cborder = $border_middle;
  21235. $h = $this->h - $this->y - $this->bMargin;
  21236. }
  21237. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  21238. } // end for each column
  21239. } elseif ($page == $startpage) { // first page
  21240. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  21241. $this->selectColumn($column);
  21242. if ($column == $startcolumn) { // first column
  21243. $cborder = $border_start;
  21244. $this->y = $starty;
  21245. $h = $this->h - $this->y - $this->bMargin;
  21246. } else { // middle column
  21247. $cborder = $border_middle;
  21248. $h = $this->h - $this->y - $this->bMargin;
  21249. }
  21250. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  21251. } // end for each column
  21252. } elseif ($page == $endpage) { // last page
  21253. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  21254. $this->selectColumn($column);
  21255. if ($column == $endcolumn) {
  21256. // end column
  21257. $cborder = $border_end;
  21258. $h = $currentY - $this->y;
  21259. } else {
  21260. // middle column
  21261. $cborder = $border_middle;
  21262. $h = $this->h - $this->y - $this->bMargin;
  21263. }
  21264. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  21265. } // end for each column
  21266. } else { // middle page
  21267. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  21268. $this->selectColumn($column);
  21269. $cborder = $border_middle;
  21270. $h = $this->h - $this->y - $this->bMargin;
  21271. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  21272. } // end for each column
  21273. }
  21274. if ($cborder OR $fill) {
  21275. // draw border and fill
  21276. if ($this->inxobj) {
  21277. // we are inside an XObject template
  21278. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  21279. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  21280. $pagemark = &$this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  21281. } else {
  21282. $pagemark = &$this->xobjects[$this->xobjid]['intmrk'];
  21283. }
  21284. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  21285. $pstart = substr($pagebuff, 0, $pagemark);
  21286. $pend = substr($pagebuff, $pagemark);
  21287. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  21288. $pagemark += strlen($ccode);
  21289. } else {
  21290. if (end($this->transfmrk[$this->page]) !== false) {
  21291. $pagemarkkey = key($this->transfmrk[$this->page]);
  21292. $pagemark = &$this->transfmrk[$this->page][$pagemarkkey];
  21293. } elseif ($this->InFooter) {
  21294. $pagemark = &$this->footerpos[$this->page];
  21295. } else {
  21296. $pagemark = &$this->intmrk[$this->page];
  21297. }
  21298. $pagebuff = $this->getPageBuffer($this->page);
  21299. $pstart = substr($pagebuff, 0, $this->bordermrk[$this->page]);
  21300. $pend = substr($pagebuff, $this->bordermrk[$this->page]);
  21301. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  21302. $offsetlen = strlen($ccode);
  21303. $this->bordermrk[$this->page] += $offsetlen;
  21304. $this->cntmrk[$this->page] += $offsetlen;
  21305. $pagemark += $offsetlen;
  21306. }
  21307. }
  21308. } // end for each page
  21309. // restore page regions
  21310. $this->page_regions = $temp_page_regions;
  21311. if (isset($old_bgcolor)) {
  21312. // restore background color
  21313. $this->SetFillColorArray($old_bgcolor);
  21314. }
  21315. // restore pointer position
  21316. $this->x = $prev_x;
  21317. $this->y = $prev_y;
  21318. $this->lasth = $prev_lasth;
  21319. }
  21320. /**
  21321. * Set the default bullet to be used as LI bullet symbol
  21322. * @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')
  21323. * @public
  21324. * @since 4.0.028 (2008-09-26)
  21325. */
  21326. public function setLIsymbol($symbol='!') {
  21327. // check for custom image symbol
  21328. if (substr($symbol, 0, 4) == 'img|') {
  21329. $this->lisymbol = $symbol;
  21330. return;
  21331. }
  21332. $symbol = strtolower($symbol);
  21333. switch ($symbol) {
  21334. case '!' :
  21335. case '#' :
  21336. case 'disc' :
  21337. case 'circle' :
  21338. case 'square' :
  21339. case '1':
  21340. case 'decimal':
  21341. case 'decimal-leading-zero':
  21342. case 'i':
  21343. case 'lower-roman':
  21344. case 'I':
  21345. case 'upper-roman':
  21346. case 'a':
  21347. case 'lower-alpha':
  21348. case 'lower-latin':
  21349. case 'A':
  21350. case 'upper-alpha':
  21351. case 'upper-latin':
  21352. case 'lower-greek': {
  21353. $this->lisymbol = $symbol;
  21354. break;
  21355. }
  21356. default : {
  21357. $this->lisymbol = '';
  21358. }
  21359. }
  21360. }
  21361. /**
  21362. * Set the booklet mode for double-sided pages.
  21363. * @param $booklet (boolean) true set the booklet mode on, false otherwise.
  21364. * @param $inner (float) Inner page margin.
  21365. * @param $outer (float) Outer page margin.
  21366. * @public
  21367. * @since 4.2.000 (2008-10-29)
  21368. */
  21369. public function SetBooklet($booklet=true, $inner=-1, $outer=-1) {
  21370. $this->booklet = $booklet;
  21371. if ($inner >= 0) {
  21372. $this->lMargin = $inner;
  21373. }
  21374. if ($outer >= 0) {
  21375. $this->rMargin = $outer;
  21376. }
  21377. }
  21378. /**
  21379. * Swap the left and right margins.
  21380. * @param $reverse (boolean) if true swap left and right margins.
  21381. * @protected
  21382. * @since 4.2.000 (2008-10-29)
  21383. */
  21384. protected function swapMargins($reverse=true) {
  21385. if ($reverse) {
  21386. // swap left and right margins
  21387. $mtemp = $this->original_lMargin;
  21388. $this->original_lMargin = $this->original_rMargin;
  21389. $this->original_rMargin = $mtemp;
  21390. $deltam = $this->original_lMargin - $this->original_rMargin;
  21391. $this->lMargin += $deltam;
  21392. $this->rMargin -= $deltam;
  21393. }
  21394. }
  21395. /**
  21396. * Set the vertical spaces for HTML tags.
  21397. * The array must have the following structure (example):
  21398. * $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1)));
  21399. * The first array level contains the tag names,
  21400. * the second level contains 0 for opening tags or 1 for closing tags,
  21401. * the third level contains the vertical space unit (h) and the number spaces to add (n).
  21402. * If the h parameter is not specified, default values are used.
  21403. * @param $tagvs (array) array of tags and relative vertical spaces.
  21404. * @public
  21405. * @since 4.2.001 (2008-10-30)
  21406. */
  21407. public function setHtmlVSpace($tagvs) {
  21408. $this->tagvspaces = $tagvs;
  21409. }
  21410. /**
  21411. * Set custom width for list indentation.
  21412. * @param $width (float) width of the indentation. Use negative value to disable it.
  21413. * @public
  21414. * @since 4.2.007 (2008-11-12)
  21415. */
  21416. public function setListIndentWidth($width) {
  21417. return $this->customlistindent = floatval($width);
  21418. }
  21419. /**
  21420. * Set the top/bottom cell sides to be open or closed when the cell cross the page.
  21421. * @param $isopen (boolean) if true keeps the top/bottom border open for the cell sides that cross the page.
  21422. * @public
  21423. * @since 4.2.010 (2008-11-14)
  21424. */
  21425. public function setOpenCell($isopen) {
  21426. $this->opencell = $isopen;
  21427. }
  21428. /**
  21429. * Set the color and font style for HTML links.
  21430. * @param $color (array) RGB array of colors
  21431. * @param $fontstyle (string) additional font styles to add
  21432. * @public
  21433. * @since 4.4.003 (2008-12-09)
  21434. */
  21435. public function setHtmlLinksStyle($color=array(0,0,255), $fontstyle='U') {
  21436. $this->htmlLinkColorArray = $color;
  21437. $this->htmlLinkFontStyle = $fontstyle;
  21438. }
  21439. /**
  21440. * Convert HTML string containing value and unit of measure to user's units or points.
  21441. * @param $htmlval (string) string containing values and unit
  21442. * @param $refsize (string) reference value in points
  21443. * @param $defaultunit (string) default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  21444. * @param $points (boolean) if true returns points, otherwise returns value in user's units
  21445. * @return float value in user's unit or point if $points=true
  21446. * @public
  21447. * @since 4.4.004 (2008-12-10)
  21448. */
  21449. public function getHTMLUnitToUnits($htmlval, $refsize=1, $defaultunit='px', $points=false) {
  21450. $supportedunits = array('%', 'em', 'ex', 'px', 'in', 'cm', 'mm', 'pc', 'pt');
  21451. $retval = 0;
  21452. $value = 0;
  21453. $unit = 'px';
  21454. $k = $this->k;
  21455. if ($points) {
  21456. $k = 1;
  21457. }
  21458. if (in_array($defaultunit, $supportedunits)) {
  21459. $unit = $defaultunit;
  21460. }
  21461. if (is_numeric($htmlval)) {
  21462. $value = floatval($htmlval);
  21463. } elseif (preg_match('/([0-9\.\-\+]+)/', $htmlval, $mnum)) {
  21464. $value = floatval($mnum[1]);
  21465. if (preg_match('/([a-z%]+)/', $htmlval, $munit)) {
  21466. if (in_array($munit[1], $supportedunits)) {
  21467. $unit = $munit[1];
  21468. }
  21469. }
  21470. }
  21471. switch ($unit) {
  21472. // percentage
  21473. case '%': {
  21474. $retval = (($value * $refsize) / 100);
  21475. break;
  21476. }
  21477. // relative-size
  21478. case 'em': {
  21479. $retval = ($value * $refsize);
  21480. break;
  21481. }
  21482. // height of lower case 'x' (about half the font-size)
  21483. case 'ex': {
  21484. $retval = $value * ($refsize / 2);
  21485. break;
  21486. }
  21487. // absolute-size
  21488. case 'in': {
  21489. $retval = ($value * $this->dpi) / $k;
  21490. break;
  21491. }
  21492. // centimeters
  21493. case 'cm': {
  21494. $retval = ($value / 2.54 * $this->dpi) / $k;
  21495. break;
  21496. }
  21497. // millimeters
  21498. case 'mm': {
  21499. $retval = ($value / 25.4 * $this->dpi) / $k;
  21500. break;
  21501. }
  21502. // one pica is 12 points
  21503. case 'pc': {
  21504. $retval = ($value * 12) / $k;
  21505. break;
  21506. }
  21507. // points
  21508. case 'pt': {
  21509. $retval = $value / $k;
  21510. break;
  21511. }
  21512. // pixels
  21513. case 'px': {
  21514. $retval = $this->pixelsToUnits($value);
  21515. break;
  21516. }
  21517. }
  21518. return $retval;
  21519. }
  21520. /**
  21521. * Returns the Roman representation of an integer number
  21522. * @param $number (int) number to convert
  21523. * @return string roman representation of the specified number
  21524. * @since 4.4.004 (2008-12-10)
  21525. * @public
  21526. */
  21527. public function intToRoman($number) {
  21528. $roman = '';
  21529. while ($number >= 1000) {
  21530. $roman .= 'M';
  21531. $number -= 1000;
  21532. }
  21533. while ($number >= 900) {
  21534. $roman .= 'CM';
  21535. $number -= 900;
  21536. }
  21537. while ($number >= 500) {
  21538. $roman .= 'D';
  21539. $number -= 500;
  21540. }
  21541. while ($number >= 400) {
  21542. $roman .= 'CD';
  21543. $number -= 400;
  21544. }
  21545. while ($number >= 100) {
  21546. $roman .= 'C';
  21547. $number -= 100;
  21548. }
  21549. while ($number >= 90) {
  21550. $roman .= 'XC';
  21551. $number -= 90;
  21552. }
  21553. while ($number >= 50) {
  21554. $roman .= 'L';
  21555. $number -= 50;
  21556. }
  21557. while ($number >= 40) {
  21558. $roman .= 'XL';
  21559. $number -= 40;
  21560. }
  21561. while ($number >= 10) {
  21562. $roman .= 'X';
  21563. $number -= 10;
  21564. }
  21565. while ($number >= 9) {
  21566. $roman .= 'IX';
  21567. $number -= 9;
  21568. }
  21569. while ($number >= 5) {
  21570. $roman .= 'V';
  21571. $number -= 5;
  21572. }
  21573. while ($number >= 4) {
  21574. $roman .= 'IV';
  21575. $number -= 4;
  21576. }
  21577. while ($number >= 1) {
  21578. $roman .= 'I';
  21579. --$number;
  21580. }
  21581. return $roman;
  21582. }
  21583. /**
  21584. * Output an HTML list bullet or ordered item symbol
  21585. * @param $listdepth (int) list nesting level
  21586. * @param $listtype (string) type of list
  21587. * @param $size (float) current font size
  21588. * @protected
  21589. * @since 4.4.004 (2008-12-10)
  21590. */
  21591. protected function putHtmlListBullet($listdepth, $listtype='', $size=10) {
  21592. $size /= $this->k;
  21593. $fill = '';
  21594. $color = $this->fgcolor;
  21595. $width = 0;
  21596. $textitem = '';
  21597. $tmpx = $this->x;
  21598. $lspace = $this->GetStringWidth(' ');
  21599. if ($listtype == '^') {
  21600. // special symbol used for avoid justification of rect bullet
  21601. $this->lispacer = '';
  21602. return;
  21603. } elseif ($listtype == '!') {
  21604. // set default list type for unordered list
  21605. $deftypes = array('disc', 'circle', 'square');
  21606. $listtype = $deftypes[($listdepth - 1) % 3];
  21607. } elseif ($listtype == '#') {
  21608. // set default list type for ordered list
  21609. $listtype = 'decimal';
  21610. } elseif(substr($listtype, 0, 4) == 'img|') {
  21611. // custom image type ('img|type|width|height|image.ext')
  21612. $img = explode('|', $listtype);
  21613. $listtype = 'img';
  21614. }
  21615. switch ($listtype) {
  21616. // unordered types
  21617. case 'none': {
  21618. break;
  21619. }
  21620. case 'disc': {
  21621. $fill = 'F';
  21622. }
  21623. case 'circle': {
  21624. $fill .= 'D';
  21625. $r = $size / 6;
  21626. $lspace += (2 * $r);
  21627. if ($this->rtl) {
  21628. $this->x += $lspace;
  21629. } else {
  21630. $this->x -= $lspace;
  21631. }
  21632. $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), $r, 0, 360, $fill, array('color'=>$color), $color, 8);
  21633. break;
  21634. }
  21635. case 'square': {
  21636. $l = $size / 3;
  21637. $lspace += $l;
  21638. if ($this->rtl) {;
  21639. $this->x += $lspace;
  21640. } else {
  21641. $this->x -= $lspace;
  21642. }
  21643. $this->Rect($this->x, ($this->y + (($this->lasth - $l) / 2)), $l, $l, 'F', array(), $color);
  21644. break;
  21645. }
  21646. case 'img': {
  21647. // 1=>type, 2=>width, 3=>height, 4=>image.ext
  21648. $lspace += $img[2];
  21649. if ($this->rtl) {;
  21650. $this->x += $lspace;
  21651. } else {
  21652. $this->x -= $lspace;
  21653. }
  21654. $imgtype = strtolower($img[1]);
  21655. $prev_y = $this->y;
  21656. switch ($imgtype) {
  21657. case 'svg': {
  21658. $this->ImageSVG($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', 'T', '', 0, false);
  21659. break;
  21660. }
  21661. case 'ai':
  21662. case 'eps': {
  21663. $this->ImageEps($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', true, 'T', '', 0, false);
  21664. break;
  21665. }
  21666. default: {
  21667. $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);
  21668. break;
  21669. }
  21670. }
  21671. $this->y = $prev_y;
  21672. break;
  21673. }
  21674. // ordered types
  21675. // $this->listcount[$this->listnum];
  21676. // $textitem
  21677. case '1':
  21678. case 'decimal': {
  21679. $textitem = $this->listcount[$this->listnum];
  21680. break;
  21681. }
  21682. case 'decimal-leading-zero': {
  21683. $textitem = sprintf('%02d', $this->listcount[$this->listnum]);
  21684. break;
  21685. }
  21686. case 'i':
  21687. case 'lower-roman': {
  21688. $textitem = strtolower($this->intToRoman($this->listcount[$this->listnum]));
  21689. break;
  21690. }
  21691. case 'I':
  21692. case 'upper-roman': {
  21693. $textitem = $this->intToRoman($this->listcount[$this->listnum]);
  21694. break;
  21695. }
  21696. case 'a':
  21697. case 'lower-alpha':
  21698. case 'lower-latin': {
  21699. $textitem = chr(97 + $this->listcount[$this->listnum] - 1);
  21700. break;
  21701. }
  21702. case 'A':
  21703. case 'upper-alpha':
  21704. case 'upper-latin': {
  21705. $textitem = chr(65 + $this->listcount[$this->listnum] - 1);
  21706. break;
  21707. }
  21708. case 'lower-greek': {
  21709. $textitem = $this->unichr(945 + $this->listcount[$this->listnum] - 1);
  21710. break;
  21711. }
  21712. /*
  21713. // Types to be implemented (special handling)
  21714. case 'hebrew': {
  21715. break;
  21716. }
  21717. case 'armenian': {
  21718. break;
  21719. }
  21720. case 'georgian': {
  21721. break;
  21722. }
  21723. case 'cjk-ideographic': {
  21724. break;
  21725. }
  21726. case 'hiragana': {
  21727. break;
  21728. }
  21729. case 'katakana': {
  21730. break;
  21731. }
  21732. case 'hiragana-iroha': {
  21733. break;
  21734. }
  21735. case 'katakana-iroha': {
  21736. break;
  21737. }
  21738. */
  21739. default: {
  21740. $textitem = $this->listcount[$this->listnum];
  21741. }
  21742. }
  21743. if (!$this->empty_string($textitem)) {
  21744. // Check whether we need a new page or new column
  21745. $prev_y = $this->y;
  21746. $h = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  21747. if ($this->checkPageBreak($h) OR ($this->y < $prev_y)) {
  21748. $tmpx = $this->x;
  21749. }
  21750. // print ordered item
  21751. if ($this->rtl) {
  21752. $textitem = '.'.$textitem;
  21753. } else {
  21754. $textitem = $textitem.'.';
  21755. }
  21756. $lspace += $this->GetStringWidth($textitem);
  21757. if ($this->rtl) {
  21758. $this->x += $lspace;
  21759. } else {
  21760. $this->x -= $lspace;
  21761. }
  21762. $this->Write($this->lasth, $textitem, '', false, '', false, 0, false);
  21763. }
  21764. $this->x = $tmpx;
  21765. $this->lispacer = '^';
  21766. }
  21767. /**
  21768. * Returns current graphic variables as array.
  21769. * @return array of graphic variables
  21770. * @protected
  21771. * @since 4.2.010 (2008-11-14)
  21772. */
  21773. protected function getGraphicVars() {
  21774. $grapvars = array(
  21775. 'FontFamily' => $this->FontFamily,
  21776. 'FontStyle' => $this->FontStyle,
  21777. 'FontSizePt' => $this->FontSizePt,
  21778. 'rMargin' => $this->rMargin,
  21779. 'lMargin' => $this->lMargin,
  21780. 'cell_padding' => $this->cell_padding,
  21781. 'cell_margin' => $this->cell_margin,
  21782. 'LineWidth' => $this->LineWidth,
  21783. 'linestyleWidth' => $this->linestyleWidth,
  21784. 'linestyleCap' => $this->linestyleCap,
  21785. 'linestyleJoin' => $this->linestyleJoin,
  21786. 'linestyleDash' => $this->linestyleDash,
  21787. 'textrendermode' => $this->textrendermode,
  21788. 'textstrokewidth' => $this->textstrokewidth,
  21789. 'DrawColor' => $this->DrawColor,
  21790. 'FillColor' => $this->FillColor,
  21791. 'TextColor' => $this->TextColor,
  21792. 'ColorFlag' => $this->ColorFlag,
  21793. 'bgcolor' => $this->bgcolor,
  21794. 'fgcolor' => $this->fgcolor,
  21795. 'htmlvspace' => $this->htmlvspace,
  21796. 'listindent' => $this->listindent,
  21797. 'listindentlevel' => $this->listindentlevel,
  21798. 'listnum' => $this->listnum,
  21799. 'listordered' => $this->listordered,
  21800. 'listcount' => $this->listcount,
  21801. 'lispacer' => $this->lispacer,
  21802. 'cell_height_ratio' => $this->cell_height_ratio,
  21803. 'font_stretching' => $this->font_stretching,
  21804. 'font_spacing' => $this->font_spacing,
  21805. // extended
  21806. 'lasth' => $this->lasth,
  21807. 'tMargin' => $this->tMargin,
  21808. 'bMargin' => $this->bMargin,
  21809. 'AutoPageBreak' => $this->AutoPageBreak,
  21810. 'PageBreakTrigger' => $this->PageBreakTrigger,
  21811. 'x' => $this->x,
  21812. 'y' => $this->y,
  21813. 'w' => $this->w,
  21814. 'h' => $this->h,
  21815. 'wPt' => $this->wPt,
  21816. 'hPt' => $this->hPt,
  21817. 'fwPt' => $this->fwPt,
  21818. 'fhPt' => $this->fhPt,
  21819. 'page' => $this->page,
  21820. 'current_column' => $this->current_column,
  21821. 'num_columns' => $this->num_columns
  21822. );
  21823. return $grapvars;
  21824. }
  21825. /**
  21826. * Set graphic variables.
  21827. * @param $gvars (array) array of graphic variablesto restore
  21828. * @param $extended (boolean) if true restore extended graphic variables
  21829. * @protected
  21830. * @since 4.2.010 (2008-11-14)
  21831. */
  21832. protected function setGraphicVars($gvars, $extended=false) {
  21833. $this->FontFamily = $gvars['FontFamily'];
  21834. $this->FontStyle = $gvars['FontStyle'];
  21835. $this->FontSizePt = $gvars['FontSizePt'];
  21836. $this->rMargin = $gvars['rMargin'];
  21837. $this->lMargin = $gvars['lMargin'];
  21838. $this->cell_padding = $gvars['cell_padding'];
  21839. $this->cell_margin = $gvars['cell_margin'];
  21840. $this->LineWidth = $gvars['LineWidth'];
  21841. $this->linestyleWidth = $gvars['linestyleWidth'];
  21842. $this->linestyleCap = $gvars['linestyleCap'];
  21843. $this->linestyleJoin = $gvars['linestyleJoin'];
  21844. $this->linestyleDash = $gvars['linestyleDash'];
  21845. $this->textrendermode = $gvars['textrendermode'];
  21846. $this->textstrokewidth = $gvars['textstrokewidth'];
  21847. $this->DrawColor = $gvars['DrawColor'];
  21848. $this->FillColor = $gvars['FillColor'];
  21849. $this->TextColor = $gvars['TextColor'];
  21850. $this->ColorFlag = $gvars['ColorFlag'];
  21851. $this->bgcolor = $gvars['bgcolor'];
  21852. $this->fgcolor = $gvars['fgcolor'];
  21853. $this->htmlvspace = $gvars['htmlvspace'];
  21854. $this->listindent = $gvars['listindent'];
  21855. $this->listindentlevel = $gvars['listindentlevel'];
  21856. $this->listnum = $gvars['listnum'];
  21857. $this->listordered = $gvars['listordered'];
  21858. $this->listcount = $gvars['listcount'];
  21859. $this->lispacer = $gvars['lispacer'];
  21860. $this->cell_height_ratio = $gvars['cell_height_ratio'];
  21861. $this->font_stretching = $gvars['font_stretching'];
  21862. $this->font_spacing = $gvars['font_spacing'];
  21863. if ($extended) {
  21864. // restore extended values
  21865. $this->lasth = $gvars['lasth'];
  21866. $this->tMargin = $gvars['tMargin'];
  21867. $this->bMargin = $gvars['bMargin'];
  21868. $this->AutoPageBreak = $gvars['AutoPageBreak'];
  21869. $this->PageBreakTrigger = $gvars['PageBreakTrigger'];
  21870. $this->x = $gvars['x'];
  21871. $this->y = $gvars['y'];
  21872. $this->w = $gvars['w'];
  21873. $this->h = $gvars['h'];
  21874. $this->wPt = $gvars['wPt'];
  21875. $this->hPt = $gvars['hPt'];
  21876. $this->fwPt = $gvars['fwPt'];
  21877. $this->fhPt = $gvars['fhPt'];
  21878. $this->page = $gvars['page'];
  21879. $this->current_column = $gvars['current_column'];
  21880. $this->num_columns = $gvars['num_columns'];
  21881. }
  21882. $this->_out(''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor.'');
  21883. if (!$this->empty_string($this->FontFamily)) {
  21884. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  21885. }
  21886. }
  21887. /**
  21888. * Returns a temporary filename for caching object on filesystem.
  21889. * @param $name (string) prefix to add to filename
  21890. * @return string filename.
  21891. * @since 4.5.000 (2008-12-31)
  21892. * @protected
  21893. */
  21894. protected function getObjFilename($name) {
  21895. return tempnam(K_PATH_CACHE, $name.'_');
  21896. }
  21897. /**
  21898. * Writes data to a temporary file on filesystem.
  21899. * @param $filename (string) file name
  21900. * @param $data (mixed) data to write on file
  21901. * @param $append (boolean) if true append data, false replace.
  21902. * @since 4.5.000 (2008-12-31)
  21903. * @protected
  21904. */
  21905. protected function writeDiskCache($filename, $data, $append=false) {
  21906. if ($append) {
  21907. $fmode = 'ab+';
  21908. } else {
  21909. $fmode = 'wb+';
  21910. }
  21911. $f = @fopen($filename, $fmode);
  21912. if (!$f) {
  21913. $this->Error('Unable to write cache file: '.$filename);
  21914. } else {
  21915. fwrite($f, $data);
  21916. fclose($f);
  21917. }
  21918. // update file length (needed for transactions)
  21919. if (!isset($this->cache_file_length['_'.$filename])) {
  21920. $this->cache_file_length['_'.$filename] = strlen($data);
  21921. } else {
  21922. $this->cache_file_length['_'.$filename] += strlen($data);
  21923. }
  21924. }
  21925. /**
  21926. * Read data from a temporary file on filesystem.
  21927. * @param $filename (string) file name
  21928. * @return mixed retrieved data
  21929. * @since 4.5.000 (2008-12-31)
  21930. * @protected
  21931. */
  21932. protected function readDiskCache($filename) {
  21933. return file_get_contents($filename);
  21934. }
  21935. /**
  21936. * Set buffer content (always append data).
  21937. * @param $data (string) data
  21938. * @protected
  21939. * @since 4.5.000 (2009-01-02)
  21940. */
  21941. protected function setBuffer($data) {
  21942. $this->bufferlen += strlen($data);
  21943. if ($this->diskcache) {
  21944. if (!isset($this->buffer) OR $this->empty_string($this->buffer)) {
  21945. $this->buffer = $this->getObjFilename('buffer');
  21946. }
  21947. $this->writeDiskCache($this->buffer, $data, true);
  21948. } else {
  21949. $this->buffer .= $data;
  21950. }
  21951. }
  21952. /**
  21953. * Replace the buffer content
  21954. * @param $data (string) data
  21955. * @protected
  21956. * @since 5.5.000 (2010-06-22)
  21957. */
  21958. protected function replaceBuffer($data) {
  21959. $this->bufferlen = strlen($data);
  21960. if ($this->diskcache) {
  21961. if (!isset($this->buffer) OR $this->empty_string($this->buffer)) {
  21962. $this->buffer = $this->getObjFilename('buffer');
  21963. }
  21964. $this->writeDiskCache($this->buffer, $data, false);
  21965. } else {
  21966. $this->buffer = $data;
  21967. }
  21968. }
  21969. /**
  21970. * Get buffer content.
  21971. * @return string buffer content
  21972. * @protected
  21973. * @since 4.5.000 (2009-01-02)
  21974. */
  21975. protected function getBuffer() {
  21976. if ($this->diskcache) {
  21977. return $this->readDiskCache($this->buffer);
  21978. } else {
  21979. return $this->buffer;
  21980. }
  21981. }
  21982. /**
  21983. * Set page buffer content.
  21984. * @param $page (int) page number
  21985. * @param $data (string) page data
  21986. * @param $append (boolean) if true append data, false replace.
  21987. * @protected
  21988. * @since 4.5.000 (2008-12-31)
  21989. */
  21990. protected function setPageBuffer($page, $data, $append=false) {
  21991. if ($this->diskcache) {
  21992. if (!isset($this->pages[$page])) {
  21993. $this->pages[$page] = $this->getObjFilename('page'.$page);
  21994. }
  21995. $this->writeDiskCache($this->pages[$page], $data, $append);
  21996. } else {
  21997. if ($append) {
  21998. $this->pages[$page] .= $data;
  21999. } else {
  22000. $this->pages[$page] = $data;
  22001. }
  22002. }
  22003. if ($append AND isset($this->pagelen[$page])) {
  22004. $this->pagelen[$page] += strlen($data);
  22005. } else {
  22006. $this->pagelen[$page] = strlen($data);
  22007. }
  22008. }
  22009. /**
  22010. * Get page buffer content.
  22011. * @param $page (int) page number
  22012. * @return string page buffer content or false in case of error
  22013. * @protected
  22014. * @since 4.5.000 (2008-12-31)
  22015. */
  22016. protected function getPageBuffer($page) {
  22017. if ($this->diskcache) {
  22018. return $this->readDiskCache($this->pages[$page]);
  22019. } elseif (isset($this->pages[$page])) {
  22020. return $this->pages[$page];
  22021. }
  22022. return false;
  22023. }
  22024. /**
  22025. * Set image buffer content.
  22026. * @param $image (string) image key
  22027. * @param $data (array) image data
  22028. * @protected
  22029. * @since 4.5.000 (2008-12-31)
  22030. */
  22031. protected function setImageBuffer($image, $data) {
  22032. if ($this->diskcache) {
  22033. if (!isset($this->images[$image])) {
  22034. $this->images[$image] = $this->getObjFilename('image'.$image);
  22035. }
  22036. $this->writeDiskCache($this->images[$image], serialize($data));
  22037. } else {
  22038. $this->images[$image] = $data;
  22039. }
  22040. if (!in_array($image, $this->imagekeys)) {
  22041. $this->imagekeys[] = $image;
  22042. ++$this->numimages;
  22043. }
  22044. }
  22045. /**
  22046. * Set image buffer content for a specified sub-key.
  22047. * @param $image (string) image key
  22048. * @param $key (string) image sub-key
  22049. * @param $data (array) image data
  22050. * @protected
  22051. * @since 4.5.000 (2008-12-31)
  22052. */
  22053. protected function setImageSubBuffer($image, $key, $data) {
  22054. if (!isset($this->images[$image])) {
  22055. $this->setImageBuffer($image, array());
  22056. }
  22057. if ($this->diskcache) {
  22058. $tmpimg = $this->getImageBuffer($image);
  22059. $tmpimg[$key] = $data;
  22060. $this->writeDiskCache($this->images[$image], serialize($tmpimg));
  22061. } else {
  22062. $this->images[$image][$key] = $data;
  22063. }
  22064. }
  22065. /**
  22066. * Get image buffer content.
  22067. * @param $image (string) image key
  22068. * @return string image buffer content or false in case of error
  22069. * @protected
  22070. * @since 4.5.000 (2008-12-31)
  22071. */
  22072. protected function getImageBuffer($image) {
  22073. if ($this->diskcache AND isset($this->images[$image])) {
  22074. return unserialize($this->readDiskCache($this->images[$image]));
  22075. } elseif (isset($this->images[$image])) {
  22076. return $this->images[$image];
  22077. }
  22078. return false;
  22079. }
  22080. /**
  22081. * Set font buffer content.
  22082. * @param $font (string) font key
  22083. * @param $data (array) font data
  22084. * @protected
  22085. * @since 4.5.000 (2009-01-02)
  22086. */
  22087. protected function setFontBuffer($font, $data) {
  22088. if ($this->diskcache) {
  22089. if (!isset($this->fonts[$font])) {
  22090. $this->fonts[$font] = $this->getObjFilename('font');
  22091. }
  22092. $this->writeDiskCache($this->fonts[$font], serialize($data));
  22093. } else {
  22094. $this->fonts[$font] = $data;
  22095. }
  22096. if (!in_array($font, $this->fontkeys)) {
  22097. $this->fontkeys[] = $font;
  22098. // store object ID for current font
  22099. ++$this->n;
  22100. $this->font_obj_ids[$font] = $this->n;
  22101. $this->setFontSubBuffer($font, 'n', $this->n);
  22102. }
  22103. }
  22104. /**
  22105. * Set font buffer content.
  22106. * @param $font (string) font key
  22107. * @param $key (string) font sub-key
  22108. * @param $data (array) font data
  22109. * @protected
  22110. * @since 4.5.000 (2009-01-02)
  22111. */
  22112. protected function setFontSubBuffer($font, $key, $data) {
  22113. if (!isset($this->fonts[$font])) {
  22114. $this->setFontBuffer($font, array());
  22115. }
  22116. if ($this->diskcache) {
  22117. $tmpfont = $this->getFontBuffer($font);
  22118. $tmpfont[$key] = $data;
  22119. $this->writeDiskCache($this->fonts[$font], serialize($tmpfont));
  22120. } else {
  22121. $this->fonts[$font][$key] = $data;
  22122. }
  22123. }
  22124. /**
  22125. * Get font buffer content.
  22126. * @param $font (string) font key
  22127. * @return string font buffer content or false in case of error
  22128. * @protected
  22129. * @since 4.5.000 (2009-01-02)
  22130. */
  22131. protected function getFontBuffer($font) {
  22132. if ($this->diskcache AND isset($this->fonts[$font])) {
  22133. return unserialize($this->readDiskCache($this->fonts[$font]));
  22134. } elseif (isset($this->fonts[$font])) {
  22135. return $this->fonts[$font];
  22136. }
  22137. return false;
  22138. }
  22139. /**
  22140. * Move a page to a previous position.
  22141. * @param $frompage (int) number of the source page
  22142. * @param $topage (int) number of the destination page (must be less than $frompage)
  22143. * @return true in case of success, false in case of error.
  22144. * @public
  22145. * @since 4.5.000 (2009-01-02)
  22146. */
  22147. public function movePage($frompage, $topage) {
  22148. if (($frompage > $this->numpages) OR ($frompage <= $topage)) {
  22149. return false;
  22150. }
  22151. if ($frompage == $this->page) {
  22152. // close the page before moving it
  22153. $this->endPage();
  22154. }
  22155. // move all page-related states
  22156. $tmppage = $this->pages[$frompage];
  22157. $tmppagedim = $this->pagedim[$frompage];
  22158. $tmppagelen = $this->pagelen[$frompage];
  22159. $tmpintmrk = $this->intmrk[$frompage];
  22160. $tmpbordermrk = $this->bordermrk[$frompage];
  22161. $tmpcntmrk = $this->cntmrk[$frompage];
  22162. if (isset($this->footerpos[$frompage])) {
  22163. $tmpfooterpos = $this->footerpos[$frompage];
  22164. }
  22165. if (isset($this->footerlen[$frompage])) {
  22166. $tmpfooterlen = $this->footerlen[$frompage];
  22167. }
  22168. if (isset($this->transfmrk[$frompage])) {
  22169. $tmptransfmrk = $this->transfmrk[$frompage];
  22170. }
  22171. if (isset($this->PageAnnots[$frompage])) {
  22172. $tmpannots = $this->PageAnnots[$frompage];
  22173. }
  22174. if (isset($this->newpagegroup[$frompage])) {
  22175. $tmpnewpagegroup = $this->newpagegroup[$frompage];
  22176. }
  22177. for ($i = $frompage; $i > $topage; --$i) {
  22178. $j = $i - 1;
  22179. // shift pages down
  22180. $this->pages[$i] = $this->pages[$j];
  22181. $this->pagedim[$i] = $this->pagedim[$j];
  22182. $this->pagelen[$i] = $this->pagelen[$j];
  22183. $this->intmrk[$i] = $this->intmrk[$j];
  22184. $this->bordermrk[$i] = $this->bordermrk[$j];
  22185. $this->cntmrk[$i] = $this->cntmrk[$j];
  22186. if (isset($this->footerpos[$j])) {
  22187. $this->footerpos[$i] = $this->footerpos[$j];
  22188. } elseif (isset($this->footerpos[$i])) {
  22189. unset($this->footerpos[$i]);
  22190. }
  22191. if (isset($this->footerlen[$j])) {
  22192. $this->footerlen[$i] = $this->footerlen[$j];
  22193. } elseif (isset($this->footerlen[$i])) {
  22194. unset($this->footerlen[$i]);
  22195. }
  22196. if (isset($this->transfmrk[$j])) {
  22197. $this->transfmrk[$i] = $this->transfmrk[$j];
  22198. } elseif (isset($this->transfmrk[$i])) {
  22199. unset($this->transfmrk[$i]);
  22200. }
  22201. if (isset($this->PageAnnots[$j])) {
  22202. $this->PageAnnots[$i] = $this->PageAnnots[$j];
  22203. } elseif (isset($this->PageAnnots[$i])) {
  22204. unset($this->PageAnnots[$i]);
  22205. }
  22206. if (isset($this->newpagegroup[$j])) {
  22207. $this->newpagegroup[$i] = $this->newpagegroup[$j];
  22208. } elseif (isset($this->newpagegroup[$i])) {
  22209. unset($this->newpagegroup[$i]);
  22210. }
  22211. }
  22212. $this->pages[$topage] = $tmppage;
  22213. $this->pagedim[$topage] = $tmppagedim;
  22214. $this->pagelen[$topage] = $tmppagelen;
  22215. $this->intmrk[$topage] = $tmpintmrk;
  22216. $this->bordermrk[$topage] = $tmpbordermrk;
  22217. $this->cntmrk[$topage] = $tmpcntmrk;
  22218. if (isset($tmpfooterpos)) {
  22219. $this->footerpos[$topage] = $tmpfooterpos;
  22220. } elseif (isset($this->footerpos[$topage])) {
  22221. unset($this->footerpos[$topage]);
  22222. }
  22223. if (isset($tmpfooterlen)) {
  22224. $this->footerlen[$topage] = $tmpfooterlen;
  22225. } elseif (isset($this->footerlen[$topage])) {
  22226. unset($this->footerlen[$topage]);
  22227. }
  22228. if (isset($tmptransfmrk)) {
  22229. $this->transfmrk[$topage] = $tmptransfmrk;
  22230. } elseif (isset($this->transfmrk[$topage])) {
  22231. unset($this->transfmrk[$topage]);
  22232. }
  22233. if (isset($tmpannots)) {
  22234. $this->PageAnnots[$topage] = $tmpannots;
  22235. } elseif (isset($this->PageAnnots[$topage])) {
  22236. unset($this->PageAnnots[$topage]);
  22237. }
  22238. if (isset($tmpnewpagegroup)) {
  22239. $this->newpagegroup[$topage] = $tmpnewpagegroup;
  22240. } elseif (isset($this->newpagegroup[$topage])) {
  22241. unset($this->newpagegroup[$topage]);
  22242. }
  22243. // adjust outlines
  22244. $tmpoutlines = $this->outlines;
  22245. foreach ($tmpoutlines as $key => $outline) {
  22246. if (($outline['p'] >= $topage) AND ($outline['p'] < $frompage)) {
  22247. $this->outlines[$key]['p'] = $outline['p'] + 1;
  22248. } elseif ($outline['p'] == $frompage) {
  22249. $this->outlines[$key]['p'] = $topage;
  22250. }
  22251. }
  22252. // adjust links
  22253. $tmplinks = $this->links;
  22254. foreach ($tmplinks as $key => $link) {
  22255. if (($link[0] >= $topage) AND ($link[0] < $frompage)) {
  22256. $this->links[$key][0] = $link[0] + 1;
  22257. } elseif ($link[0] == $frompage) {
  22258. $this->links[$key][0] = $topage;
  22259. }
  22260. }
  22261. // adjust javascript
  22262. $tmpjavascript = $this->javascript;
  22263. global $jfrompage, $jtopage;
  22264. $jfrompage = $frompage;
  22265. $jtopage = $topage;
  22266. $this->javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/',
  22267. create_function('$matches', 'global $jfrompage, $jtopage;
  22268. $pagenum = intval($matches[3]) + 1;
  22269. if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) {
  22270. $newpage = ($pagenum + 1);
  22271. } elseif ($pagenum == $jfrompage) {
  22272. $newpage = $jtopage;
  22273. } else {
  22274. $newpage = $pagenum;
  22275. }
  22276. --$newpage;
  22277. return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript);
  22278. // return to last page
  22279. $this->lastPage(true);
  22280. return true;
  22281. }
  22282. /**
  22283. * Remove the specified page.
  22284. * @param $page (int) page to remove
  22285. * @return true in case of success, false in case of error.
  22286. * @public
  22287. * @since 4.6.004 (2009-04-23)
  22288. */
  22289. public function deletePage($page) {
  22290. if (($page < 1) OR ($page > $this->numpages)) {
  22291. return false;
  22292. }
  22293. // delete current page
  22294. unset($this->pages[$page]);
  22295. unset($this->pagedim[$page]);
  22296. unset($this->pagelen[$page]);
  22297. unset($this->intmrk[$page]);
  22298. unset($this->bordermrk[$page]);
  22299. unset($this->cntmrk[$page]);
  22300. if (isset($this->footerpos[$page])) {
  22301. unset($this->footerpos[$page]);
  22302. }
  22303. if (isset($this->footerlen[$page])) {
  22304. unset($this->footerlen[$page]);
  22305. }
  22306. if (isset($this->transfmrk[$page])) {
  22307. unset($this->transfmrk[$page]);
  22308. }
  22309. if (isset($this->PageAnnots[$page])) {
  22310. unset($this->PageAnnots[$page]);
  22311. }
  22312. if (isset($this->newpagegroup[$page])) {
  22313. unset($this->newpagegroup[$page]);
  22314. }
  22315. if (isset($this->pageopen[$page])) {
  22316. unset($this->pageopen[$page]);
  22317. }
  22318. if ($page < $this->numpages) {
  22319. // update remaining pages
  22320. for ($i = $page; $i < $this->numpages; ++$i) {
  22321. $j = $i + 1;
  22322. // shift pages
  22323. $this->pages[$i] = $this->pages[$j];
  22324. $this->pagedim[$i] = $this->pagedim[$j];
  22325. $this->pagelen[$i] = $this->pagelen[$j];
  22326. $this->intmrk[$i] = $this->intmrk[$j];
  22327. $this->bordermrk[$i] = $this->bordermrk[$j];
  22328. $this->cntmrk[$i] = $this->cntmrk[$j];
  22329. if (isset($this->footerpos[$j])) {
  22330. $this->footerpos[$i] = $this->footerpos[$j];
  22331. } elseif (isset($this->footerpos[$i])) {
  22332. unset($this->footerpos[$i]);
  22333. }
  22334. if (isset($this->footerlen[$j])) {
  22335. $this->footerlen[$i] = $this->footerlen[$j];
  22336. } elseif (isset($this->footerlen[$i])) {
  22337. unset($this->footerlen[$i]);
  22338. }
  22339. if (isset($this->transfmrk[$j])) {
  22340. $this->transfmrk[$i] = $this->transfmrk[$j];
  22341. } elseif (isset($this->transfmrk[$i])) {
  22342. unset($this->transfmrk[$i]);
  22343. }
  22344. if (isset($this->PageAnnots[$j])) {
  22345. $this->PageAnnots[$i] = $this->PageAnnots[$j];
  22346. } elseif (isset($this->PageAnnots[$i])) {
  22347. unset($this->PageAnnots[$i]);
  22348. }
  22349. if (isset($this->newpagegroup[$j])) {
  22350. $this->newpagegroup[$i] = $this->newpagegroup[$j];
  22351. } elseif (isset($this->newpagegroup[$i])) {
  22352. unset($this->newpagegroup[$i]);
  22353. }
  22354. if (isset($this->pageopen[$j])) {
  22355. $this->pageopen[$i] = $this->pageopen[$j];
  22356. } elseif (isset($this->pageopen[$i])) {
  22357. unset($this->pageopen[$i]);
  22358. }
  22359. }
  22360. // remove last page
  22361. unset($this->pages[$this->numpages]);
  22362. unset($this->pagedim[$this->numpages]);
  22363. unset($this->pagelen[$this->numpages]);
  22364. unset($this->intmrk[$this->numpages]);
  22365. unset($this->bordermrk[$this->numpages]);
  22366. unset($this->cntmrk[$this->numpages]);
  22367. if (isset($this->footerpos[$this->numpages])) {
  22368. unset($this->footerpos[$this->numpages]);
  22369. }
  22370. if (isset($this->footerlen[$this->numpages])) {
  22371. unset($this->footerlen[$this->numpages]);
  22372. }
  22373. if (isset($this->transfmrk[$this->numpages])) {
  22374. unset($this->transfmrk[$this->numpages]);
  22375. }
  22376. if (isset($this->PageAnnots[$this->numpages])) {
  22377. unset($this->PageAnnots[$this->numpages]);
  22378. }
  22379. if (isset($this->newpagegroup[$this->numpages])) {
  22380. unset($this->newpagegroup[$this->numpages]);
  22381. }
  22382. if (isset($this->pageopen[$this->numpages])) {
  22383. unset($this->pageopen[$this->numpages]);
  22384. }
  22385. }
  22386. --$this->numpages;
  22387. $this->page = $this->numpages;
  22388. // adjust outlines
  22389. $tmpoutlines = $this->outlines;
  22390. foreach ($tmpoutlines as $key => $outline) {
  22391. if ($outline['p'] > $page) {
  22392. $this->outlines[$key]['p'] = $outline['p'] - 1;
  22393. } elseif ($outline['p'] == $page) {
  22394. unset($this->outlines[$key]);
  22395. }
  22396. }
  22397. // adjust links
  22398. $tmplinks = $this->links;
  22399. foreach ($tmplinks as $key => $link) {
  22400. if ($link[0] > $page) {
  22401. $this->links[$key][0] = $link[0] - 1;
  22402. } elseif ($link[0] == $page) {
  22403. unset($this->links[$key]);
  22404. }
  22405. }
  22406. // adjust javascript
  22407. $tmpjavascript = $this->javascript;
  22408. global $jpage;
  22409. $jpage = $page;
  22410. $this->javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/',
  22411. create_function('$matches', 'global $jpage;
  22412. $pagenum = intval($matches[3]) + 1;
  22413. if ($pagenum >= $jpage) {
  22414. $newpage = ($pagenum - 1);
  22415. } elseif ($pagenum == $jpage) {
  22416. $newpage = 1;
  22417. } else {
  22418. $newpage = $pagenum;
  22419. }
  22420. --$newpage;
  22421. return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript);
  22422. // return to last page
  22423. $this->lastPage(true);
  22424. return true;
  22425. }
  22426. /**
  22427. * Clone the specified page to a new page.
  22428. * @param $page (int) number of page to copy (0 = current page)
  22429. * @return true in case of success, false in case of error.
  22430. * @public
  22431. * @since 4.9.015 (2010-04-20)
  22432. */
  22433. public function copyPage($page=0) {
  22434. if ($page == 0) {
  22435. // default value
  22436. $page = $this->page;
  22437. }
  22438. if (($page < 1) OR ($page > $this->numpages)) {
  22439. return false;
  22440. }
  22441. if ($page == $this->page) {
  22442. // close the page before cloning it
  22443. $this->endPage();
  22444. }
  22445. // copy all page-related states
  22446. ++$this->numpages;
  22447. $this->page = $this->numpages;
  22448. $this->pages[$this->page] = $this->pages[$page];
  22449. $this->pagedim[$this->page] = $this->pagedim[$page];
  22450. $this->pagelen[$this->page] = $this->pagelen[$page];
  22451. $this->intmrk[$this->page] = $this->intmrk[$page];
  22452. $this->bordermrk[$this->page] = $this->bordermrk[$page];
  22453. $this->cntmrk[$this->page] = $this->cntmrk[$page];
  22454. $this->pageopen[$this->page] = false;
  22455. if (isset($this->footerpos[$page])) {
  22456. $this->footerpos[$this->page] = $this->footerpos[$page];
  22457. }
  22458. if (isset($this->footerlen[$page])) {
  22459. $this->footerlen[$this->page] = $this->footerlen[$page];
  22460. }
  22461. if (isset($this->transfmrk[$page])) {
  22462. $this->transfmrk[$this->page] = $this->transfmrk[$page];
  22463. }
  22464. if (isset($this->PageAnnots[$page])) {
  22465. $this->PageAnnots[$this->page] = $this->PageAnnots[$page];
  22466. }
  22467. if (isset($this->newpagegroup[$page])) {
  22468. $this->newpagegroup[$this->page] = $this->newpagegroup[$page];
  22469. }
  22470. // copy outlines
  22471. $tmpoutlines = $this->outlines;
  22472. foreach ($tmpoutlines as $key => $outline) {
  22473. if ($outline['p'] == $page) {
  22474. $this->outlines[] = array('t' => $outline['t'], 'l' => $outline['l'], 'y' => $outline['y'], 'p' => $this->page);
  22475. }
  22476. }
  22477. // copy links
  22478. $tmplinks = $this->links;
  22479. foreach ($tmplinks as $key => $link) {
  22480. if ($link[0] == $page) {
  22481. $this->links[] = array($this->page, $link[1]);
  22482. }
  22483. }
  22484. // return to last page
  22485. $this->lastPage(true);
  22486. return true;
  22487. }
  22488. /**
  22489. * Output a Table of Content Index (TOC).
  22490. * Before calling this method you have to open the page using the addTOCPage() method.
  22491. * After calling this method you have to call endTOCPage() to close the TOC page.
  22492. * You can override this method to achieve different styles.
  22493. * @param $page (int) page number where this TOC should be inserted (leave empty for current page).
  22494. * @param $numbersfont (string) set the font for page numbers (please use monospaced font for better alignment).
  22495. * @param $filler (string) string used to fill the space between text and page number.
  22496. * @param $toc_name (string) name to use for TOC bookmark.
  22497. * @public
  22498. * @author Nicola Asuni
  22499. * @since 4.5.000 (2009-01-02)
  22500. * @see addTOCPage(), endTOCPage(), addHTMLTOC()
  22501. */
  22502. public function addTOC($page='', $numbersfont='', $filler='.', $toc_name='TOC') {
  22503. $fontsize = $this->FontSizePt;
  22504. $fontfamily = $this->FontFamily;
  22505. $fontstyle = $this->FontStyle;
  22506. $w = $this->w - $this->lMargin - $this->rMargin;
  22507. $spacer = $this->GetStringWidth(chr(32)) * 4;
  22508. $page_first = $this->getPage();
  22509. $lmargin = $this->lMargin;
  22510. $rmargin = $this->rMargin;
  22511. $x_start = $this->GetX();
  22512. $current_page = $this->page;
  22513. $current_column = $this->current_column;
  22514. if ($this->empty_string($numbersfont)) {
  22515. $numbersfont = $this->default_monospaced_font;
  22516. }
  22517. if ($this->empty_string($filler)) {
  22518. $filler = ' ';
  22519. }
  22520. if ($this->empty_string($page)) {
  22521. $gap = ' ';
  22522. } else {
  22523. $gap = '';
  22524. if ($page < 1) {
  22525. $page = 1;
  22526. }
  22527. }
  22528. foreach ($this->outlines as $key => $outline) {
  22529. if ($this->rtl) {
  22530. $aligntext = 'R';
  22531. $alignnum = 'L';
  22532. } else {
  22533. $aligntext = 'L';
  22534. $alignnum = 'R';
  22535. }
  22536. if ($outline['l'] == 0) {
  22537. $this->SetFont($fontfamily, $fontstyle.'B', $fontsize);
  22538. } else {
  22539. $this->SetFont($fontfamily, $fontstyle, $fontsize - $outline['l']);
  22540. }
  22541. // check for page break
  22542. $this->checkPageBreak(($this->FontSize * $this->cell_height_ratio));
  22543. // set margins and X position
  22544. if (($this->page == $current_page) AND ($this->current_column == $current_column)) {
  22545. $this->lMargin = $lmargin;
  22546. $this->rMargin = $rmargin;
  22547. } else {
  22548. if ($this->current_column != $current_column) {
  22549. if ($this->rtl) {
  22550. $x_start = $this->w - $this->columns[$this->current_column]['x'];
  22551. } else {
  22552. $x_start = $this->columns[$this->current_column]['x'];
  22553. }
  22554. }
  22555. $lmargin = $this->lMargin;
  22556. $rmargin = $this->rMargin;
  22557. $current_page = $this->page;
  22558. $current_column = $this->current_column;
  22559. }
  22560. $this->SetX($x_start);
  22561. $indent = ($spacer * $outline['l']);
  22562. if ($this->rtl) {
  22563. $this->rMargin += $indent;
  22564. $this->x -= $indent;
  22565. } else {
  22566. $this->lMargin += $indent;
  22567. $this->x += $indent;
  22568. }
  22569. $link = $this->AddLink();
  22570. $this->SetLink($link, $outline['y'], $outline['p']);
  22571. // write the text
  22572. $this->Write(0, $outline['t'], $link, 0, $aligntext, false, 0, false, false, 0);
  22573. $this->SetFont($numbersfont, $fontstyle, $fontsize);
  22574. if ($this->empty_string($page)) {
  22575. $pagenum = $outline['p'];
  22576. } else {
  22577. // placemark to be replaced with the correct number
  22578. $pagenum = '{#'.($outline['p']).'}';
  22579. if ($this->isUnicodeFont()) {
  22580. $pagenum = '{'.$pagenum.'}';
  22581. }
  22582. }
  22583. $numwidth = $this->GetStringWidth($pagenum);
  22584. if ($this->rtl) {
  22585. $tw = $this->x - $this->lMargin;
  22586. } else {
  22587. $tw = $this->w - $this->rMargin - $this->x;
  22588. }
  22589. $fw = $tw - $numwidth - $this->GetStringWidth(chr(32));
  22590. $numfills = floor($fw / $this->GetStringWidth($filler));
  22591. if ($numfills > 0) {
  22592. $rowfill = str_repeat($filler, $numfills);
  22593. } else {
  22594. $rowfill = '';
  22595. }
  22596. if ($this->rtl) {
  22597. $pagenum = $pagenum.$gap.$rowfill.' ';
  22598. } else {
  22599. $pagenum = ' '.$rowfill.$gap.$pagenum;
  22600. }
  22601. // write the number
  22602. $this->Cell($tw, 0, $pagenum, 0, 1, $alignnum, 0, $link, 0);
  22603. }
  22604. $page_last = $this->getPage();
  22605. $numpages = $page_last - $page_first + 1;
  22606. if (!$this->empty_string($page)) {
  22607. for ($p = $page_first; $p <= $page_last; ++$p) {
  22608. // get page data
  22609. $temppage = $this->getPageBuffer($p);
  22610. for ($n = 1; $n <= $this->numpages; ++$n) {
  22611. // update page numbers
  22612. $k = '{#'.$n.'}';
  22613. $ku = '{'.$k.'}';
  22614. $alias_a = $this->_escape($k);
  22615. $alias_au = $this->_escape($ku);
  22616. if ($this->isunicode) {
  22617. $alias_b = $this->_escape($this->UTF8ToLatin1($k));
  22618. $alias_bu = $this->_escape($this->UTF8ToLatin1($ku));
  22619. $alias_c = $this->_escape($this->utf8StrRev($k, false, $this->tmprtl));
  22620. $alias_cu = $this->_escape($this->utf8StrRev($ku, false, $this->tmprtl));
  22621. }
  22622. if ($n >= $page) {
  22623. $np = $n + $numpages;
  22624. } else {
  22625. $np = $n;
  22626. }
  22627. $ns = $this->formatTOCPageNumber($np);
  22628. $nu = $ns;
  22629. $sdiff = strlen($k) - strlen($ns) - 1;
  22630. $sdiffu = strlen($ku) - strlen($ns) - 1;
  22631. $sfill = str_repeat($filler, $sdiff);
  22632. $sfillu = str_repeat($filler, $sdiffu);
  22633. if ($this->rtl) {
  22634. $ns = $ns.' '.$sfill;
  22635. $nu = $nu.' '.$sfillu;
  22636. } else {
  22637. $ns = $sfill.' '.$ns;
  22638. $nu = $sfillu.' '.$nu;
  22639. }
  22640. $nu = $this->UTF8ToUTF16BE($nu, false);
  22641. $temppage = str_replace($alias_au, $nu, $temppage);
  22642. if ($this->isunicode) {
  22643. $temppage = str_replace($alias_bu, $nu, $temppage);
  22644. $temppage = str_replace($alias_cu, $nu, $temppage);
  22645. $temppage = str_replace($alias_b, $ns, $temppage);
  22646. $temppage = str_replace($alias_c, $ns, $temppage);
  22647. }
  22648. $temppage = str_replace($alias_a, $ns, $temppage);
  22649. }
  22650. // save changes
  22651. $this->setPageBuffer($p, $temppage);
  22652. }
  22653. // move pages
  22654. $this->Bookmark($toc_name, 0, 0, $page_first);
  22655. for ($i = 0; $i < $numpages; ++$i) {
  22656. $this->movePage($page_last, $page);
  22657. }
  22658. }
  22659. }
  22660. /**
  22661. * Output a Table Of Content Index (TOC) using HTML templates.
  22662. * Before calling this method you have to open the page using the addTOCPage() method.
  22663. * After calling this method you have to call endTOCPage() to close the TOC page.
  22664. * @param $page (int) page number where this TOC should be inserted (leave empty for current page).
  22665. * @param $toc_name (string) name to use for TOC bookmark.
  22666. * @param $templates (array) array of html templates. Use: "#TOC_DESCRIPTION#" for bookmark title, "#TOC_PAGE_NUMBER#" for page number.
  22667. * @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)
  22668. * @public
  22669. * @author Nicola Asuni
  22670. * @since 5.0.001 (2010-05-06)
  22671. * @see addTOCPage(), endTOCPage(), addTOC()
  22672. */
  22673. public function addHTMLTOC($page='', $toc_name='TOC', $templates=array(), $correct_align=true) {
  22674. $prev_htmlLinkColorArray = $this->htmlLinkColorArray;
  22675. $prev_htmlLinkFontStyle = $this->htmlLinkFontStyle;
  22676. // set new style for link
  22677. $this->htmlLinkColorArray = array();
  22678. $this->htmlLinkFontStyle = '';
  22679. $page_first = $this->getPage();
  22680. // get the font type used for numbers in each template
  22681. $current_font = $this->FontFamily;
  22682. foreach ($templates as $level => $html) {
  22683. $dom = $this->getHtmlDomArray($html);
  22684. foreach ($dom as $key => $value) {
  22685. if ($value['value'] == '#TOC_PAGE_NUMBER#') {
  22686. $this->SetFont($dom[($key - 1)]['fontname']);
  22687. $templates['F'.$level] = $this->isUnicodeFont();
  22688. }
  22689. }
  22690. }
  22691. $this->SetFont($current_font);
  22692. foreach ($this->outlines as $key => $outline) {
  22693. // get HTML template
  22694. $row = $templates[$outline['l']];
  22695. if ($this->empty_string($page)) {
  22696. $pagenum = $outline['p'];
  22697. } else {
  22698. // placemark to be replaced with the correct number
  22699. $pagenum = '{#'.($outline['p']).'}';
  22700. if ($templates['F'.$outline['l']]) {
  22701. $pagenum = '{'.$pagenum.'}';
  22702. }
  22703. }
  22704. // replace templates with current values
  22705. $row = str_replace('#TOC_DESCRIPTION#', $outline['t'], $row);
  22706. $row = str_replace('#TOC_PAGE_NUMBER#', $pagenum, $row);
  22707. // add link to page
  22708. $row = '<a href="#'.$outline['p'].','.$outline['y'].'">'.$row.'</a>';
  22709. // write bookmark entry
  22710. $this->writeHTML($row, false, false, true, false, '');
  22711. }
  22712. // restore link styles
  22713. $this->htmlLinkColorArray = $prev_htmlLinkColorArray;
  22714. $this->htmlLinkFontStyle = $prev_htmlLinkFontStyle;
  22715. // move TOC page and replace numbers
  22716. $page_last = $this->getPage();
  22717. $numpages = $page_last - $page_first + 1;
  22718. if (!$this->empty_string($page)) {
  22719. for ($p = $page_first; $p <= $page_last; ++$p) {
  22720. // get page data
  22721. $temppage = $this->getPageBuffer($p);
  22722. for ($n = 1; $n <= $this->numpages; ++$n) {
  22723. // update page numbers
  22724. $k = '{#'.$n.'}';
  22725. $ku = '{'.$k.'}';
  22726. $alias_a = $this->_escape($k);
  22727. $alias_au = $this->_escape('{'.$k.'}');
  22728. if ($this->isunicode) {
  22729. $alias_b = $this->_escape($this->UTF8ToLatin1($k));
  22730. $alias_bu = $this->_escape($this->UTF8ToLatin1($ku));
  22731. $alias_c = $this->_escape($this->utf8StrRev($k, false, $this->tmprtl));
  22732. $alias_cu = $this->_escape($this->utf8StrRev($ku, false, $this->tmprtl));
  22733. }
  22734. if ($n >= $page) {
  22735. $np = $n + $numpages;
  22736. } else {
  22737. $np = $n;
  22738. }
  22739. $ns = $this->formatTOCPageNumber($np);
  22740. $nu = $ns;
  22741. if ($correct_align) {
  22742. $sdiff = strlen($k) - strlen($ns);
  22743. $sdiffu = strlen($ku) - strlen($ns);
  22744. $sfill = str_repeat(' ', $sdiff);
  22745. $sfillu = str_repeat(' ', $sdiffu);
  22746. if ($this->rtl) {
  22747. $ns = $ns.$sfill;
  22748. $nu = $nu.$sfillu;
  22749. } else {
  22750. $ns = $sfill.$ns;
  22751. $nu = $sfillu.$nu;
  22752. }
  22753. }
  22754. $nu = $this->UTF8ToUTF16BE($nu, false);
  22755. $temppage = str_replace($alias_au, $nu, $temppage);
  22756. if ($this->isunicode) {
  22757. $temppage = str_replace($alias_bu, $nu, $temppage);
  22758. $temppage = str_replace($alias_cu, $nu, $temppage);
  22759. $temppage = str_replace($alias_b, $ns, $temppage);
  22760. $temppage = str_replace($alias_c, $ns, $temppage);
  22761. }
  22762. $temppage = str_replace($alias_a, $ns, $temppage);
  22763. }
  22764. // save changes
  22765. $this->setPageBuffer($p, $temppage);
  22766. }
  22767. // move pages
  22768. $this->Bookmark($toc_name, 0, 0, $page_first);
  22769. for ($i = 0; $i < $numpages; ++$i) {
  22770. $this->movePage($page_last, $page);
  22771. }
  22772. }
  22773. }
  22774. /**
  22775. * Stores a copy of the current TCPDF object used for undo operation.
  22776. * @public
  22777. * @since 4.5.029 (2009-03-19)
  22778. */
  22779. public function startTransaction() {
  22780. if (isset($this->objcopy)) {
  22781. // remove previous copy
  22782. $this->commitTransaction();
  22783. }
  22784. // record current page number and Y position
  22785. $this->start_transaction_page = $this->page;
  22786. $this->start_transaction_y = $this->y;
  22787. // clone current object
  22788. $this->objcopy = $this->objclone($this);
  22789. }
  22790. /**
  22791. * Delete the copy of the current TCPDF object used for undo operation.
  22792. * @public
  22793. * @since 4.5.029 (2009-03-19)
  22794. */
  22795. public function commitTransaction() {
  22796. if (isset($this->objcopy)) {
  22797. $this->objcopy->_destroy(true, true);
  22798. unset($this->objcopy);
  22799. }
  22800. }
  22801. /**
  22802. * This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction().
  22803. * @param $self (boolean) if true restores current class object to previous state without the need of reassignment via the returned value.
  22804. * @return TCPDF object.
  22805. * @public
  22806. * @since 4.5.029 (2009-03-19)
  22807. */
  22808. public function rollbackTransaction($self=false) {
  22809. if (isset($this->objcopy)) {
  22810. if (isset($this->objcopy->diskcache) AND $this->objcopy->diskcache) {
  22811. // truncate files to previous values
  22812. foreach ($this->objcopy->cache_file_length as $file => $length) {
  22813. $file = substr($file, 1);
  22814. $handle = fopen($file, 'r+');
  22815. ftruncate($handle, $length);
  22816. }
  22817. }
  22818. $this->_destroy(true, true);
  22819. if ($self) {
  22820. $objvars = get_object_vars($this->objcopy);
  22821. foreach ($objvars as $key => $value) {
  22822. $this->$key = $value;
  22823. }
  22824. }
  22825. return $this->objcopy;
  22826. }
  22827. return $this;
  22828. }
  22829. /**
  22830. * Creates a copy of a class object
  22831. * @param $object (object) class object to be cloned
  22832. * @return cloned object
  22833. * @public
  22834. * @since 4.5.029 (2009-03-19)
  22835. */
  22836. public function objclone($object) {
  22837. return @clone($object);
  22838. }
  22839. /**
  22840. * Determine whether a string is empty.
  22841. * @param $str (string) string to be checked
  22842. * @return boolean true if string is empty
  22843. * @public
  22844. * @since 4.5.044 (2009-04-16)
  22845. */
  22846. public function empty_string($str) {
  22847. return (is_null($str) OR (is_string($str) AND (strlen($str) == 0)));
  22848. }
  22849. /**
  22850. * Find position of last occurrence of a substring in a string
  22851. * @param $haystack (string) The string to search in.
  22852. * @param $needle (string) substring to search.
  22853. * @param $offset (int) May be specified to begin searching an arbitrary number of characters into the string.
  22854. * @return Returns the position where the needle exists. Returns FALSE if the needle was not found.
  22855. * @public
  22856. * @since 4.8.038 (2010-03-13)
  22857. */
  22858. public function revstrpos($haystack, $needle, $offset = 0) {
  22859. $length = strlen($haystack);
  22860. $offset = ($offset > 0)?($length - $offset):abs($offset);
  22861. $pos = strpos(strrev($haystack), strrev($needle), $offset);
  22862. return ($pos === false)?false:($length - $pos - strlen($needle));
  22863. }
  22864. // --- MULTI COLUMNS METHODS -----------------------
  22865. /**
  22866. * Set multiple columns of the same size
  22867. * @param $numcols (int) number of columns (set to zero to disable columns mode)
  22868. * @param $width (int) column width
  22869. * @param $y (int) column starting Y position (leave empty for current Y position)
  22870. * @public
  22871. * @since 4.9.001 (2010-03-28)
  22872. */
  22873. public function setEqualColumns($numcols=0, $width=0, $y='') {
  22874. $this->columns = array();
  22875. if ($numcols < 2) {
  22876. $numcols = 0;
  22877. $this->columns = array();
  22878. } else {
  22879. // maximum column width
  22880. $maxwidth = ($this->w - $this->original_lMargin - $this->original_rMargin) / $numcols;
  22881. if (($width == 0) OR ($width > $maxwidth)) {
  22882. $width = $maxwidth;
  22883. }
  22884. if ($this->empty_string($y)) {
  22885. $y = $this->y;
  22886. }
  22887. // space between columns
  22888. $space = (($this->w - $this->original_lMargin - $this->original_rMargin - ($numcols * $width)) / ($numcols - 1));
  22889. // fill the columns array (with, space, starting Y position)
  22890. for ($i = 0; $i < $numcols; ++$i) {
  22891. $this->columns[$i] = array('w' => $width, 's' => $space, 'y' => $y);
  22892. }
  22893. }
  22894. $this->num_columns = $numcols;
  22895. $this->current_column = 0;
  22896. $this->column_start_page = $this->page;
  22897. }
  22898. /**
  22899. * Set columns array.
  22900. * Each column is represented by an array of arrays with the following keys: (w = width, s = space between columns, y = column top position).
  22901. * @param $columns (array)
  22902. * @public
  22903. * @since 4.9.001 (2010-03-28)
  22904. */
  22905. public function setColumnsArray($columns) {
  22906. $this->columns = $columns;
  22907. $this->num_columns = count($columns);
  22908. $this->current_column = 0;
  22909. $this->column_start_page = $this->page;
  22910. }
  22911. /**
  22912. * Set position at a given column
  22913. * @param $col (int) column number (from 0 to getNumberOfColumns()-1); empty string = current column.
  22914. * @public
  22915. * @since 4.9.001 (2010-03-28)
  22916. */
  22917. public function selectColumn($col='') {
  22918. if (is_string($col)) {
  22919. $col = $this->current_column;
  22920. } elseif($col >= $this->num_columns) {
  22921. $col = 0;
  22922. }
  22923. $xshift = 0;
  22924. $enable_thead = false;
  22925. if ($this->num_columns > 1) {
  22926. if ($col != $this->current_column) {
  22927. // move Y pointer at the top of the column
  22928. if ($this->column_start_page == $this->page) {
  22929. $this->y = $this->columns[$col]['y'];
  22930. } else {
  22931. $this->y = $this->tMargin;
  22932. }
  22933. // Avoid to write table headers more than once
  22934. if (($this->page > $this->maxselcol['page']) OR (($this->page == $this->maxselcol['page']) AND ($col > $this->maxselcol['column']))) {
  22935. $enable_thead = true;
  22936. $this->maxselcol['page'] = $this->page;
  22937. $this->maxselcol['column'] = $col;
  22938. }
  22939. }
  22940. $xshift = $this->colxshift;
  22941. // set X position of the current column by case
  22942. $listindent = ($this->listindentlevel * $this->listindent);
  22943. $colpos = ($col * ($this->columns[$col]['w'] + $this->columns[$col]['s']));
  22944. if ($this->rtl) {
  22945. $x = $this->w - $this->original_rMargin - $colpos;
  22946. $this->rMargin = ($this->w - $x + $listindent);
  22947. $this->lMargin = ($x - $this->columns[$col]['w']);
  22948. $this->x = $x - $listindent;
  22949. } else {
  22950. $x = $this->original_lMargin + $colpos;
  22951. $this->lMargin = ($x + $listindent);
  22952. $this->rMargin = ($this->w - $x - $this->columns[$col]['w']);
  22953. $this->x = $x + $listindent;
  22954. }
  22955. $this->columns[$col]['x'] = $x;
  22956. }
  22957. $this->current_column = $col;
  22958. // fix for HTML mode
  22959. $this->newline = true;
  22960. // print HTML table header (if any)
  22961. if ((!$this->empty_string($this->thead)) AND (!$this->inthead)) {
  22962. if ($enable_thead) {
  22963. // print table header
  22964. $this->writeHTML($this->thead, false, false, false, false, '');
  22965. $this->y += $xshift['s']['V'];
  22966. // store end of header position
  22967. if (!isset($this->columns[$col]['th'])) {
  22968. $this->columns[$col]['th'] = array();
  22969. }
  22970. $this->columns[$col]['th']['\''.$this->page.'\''] = $this->y;
  22971. $this->lasth = 0;
  22972. } elseif (isset($this->columns[$col]['th']['\''.$this->page.'\''])) {
  22973. $this->y = $this->columns[$col]['th']['\''.$this->page.'\''];
  22974. }
  22975. }
  22976. // account for an html table cell over multiple columns
  22977. if ($this->rtl) {
  22978. $this->rMargin += $xshift['x'];
  22979. $this->x -= ($xshift['x'] + $xshift['p']['R']);
  22980. } else {
  22981. $this->lMargin += $xshift['x'];
  22982. $this->x += $xshift['x'] + $xshift['p']['L'];
  22983. }
  22984. }
  22985. /**
  22986. * Return the current column number
  22987. * @return int current column number
  22988. * @public
  22989. * @since 5.5.011 (2010-07-08)
  22990. */
  22991. public function getColumn() {
  22992. return $this->current_column;
  22993. }
  22994. /**
  22995. * Return the current number of columns.
  22996. * @return int number of columns
  22997. * @public
  22998. * @since 5.8.018 (2010-08-25)
  22999. */
  23000. public function getNumberOfColumns() {
  23001. return $this->num_columns;
  23002. }
  23003. /**
  23004. * Serialize an array of parameters to be used with TCPDF tag in HTML code.
  23005. * @param $pararray (array) parameters array
  23006. * @return sting containing serialized data
  23007. * @public
  23008. * @since 4.9.006 (2010-04-02)
  23009. */
  23010. public function serializeTCPDFtagParameters($pararray) {
  23011. return urlencode(serialize($pararray));
  23012. }
  23013. /**
  23014. * Set Text rendering mode.
  23015. * @param $stroke (int) outline size in user units (0 = disable).
  23016. * @param $fill (boolean) if true fills the text (default).
  23017. * @param $clip (boolean) if true activate clipping mode
  23018. * @public
  23019. * @since 4.9.008 (2009-04-02)
  23020. */
  23021. public function setTextRenderingMode($stroke=0, $fill=true, $clip=false) {
  23022. // Ref.: PDF 32000-1:2008 - 9.3.6 Text Rendering Mode
  23023. // convert text rendering parameters
  23024. if ($stroke < 0) {
  23025. $stroke = 0;
  23026. }
  23027. if ($fill === true) {
  23028. if ($stroke > 0) {
  23029. if ($clip === true) {
  23030. // Fill, then stroke text and add to path for clipping
  23031. $textrendermode = 6;
  23032. } else {
  23033. // Fill, then stroke text
  23034. $textrendermode = 2;
  23035. }
  23036. $textstrokewidth = $stroke;
  23037. } else {
  23038. if ($clip === true) {
  23039. // Fill text and add to path for clipping
  23040. $textrendermode = 4;
  23041. } else {
  23042. // Fill text
  23043. $textrendermode = 0;
  23044. }
  23045. }
  23046. } else {
  23047. if ($stroke > 0) {
  23048. if ($clip === true) {
  23049. // Stroke text and add to path for clipping
  23050. $textrendermode = 5;
  23051. } else {
  23052. // Stroke text
  23053. $textrendermode = 1;
  23054. }
  23055. $textstrokewidth = $stroke;
  23056. } else {
  23057. if ($clip === true) {
  23058. // Add text to path for clipping
  23059. $textrendermode = 7;
  23060. } else {
  23061. // Neither fill nor stroke text (invisible)
  23062. $textrendermode = 3;
  23063. }
  23064. }
  23065. }
  23066. $this->textrendermode = $textrendermode;
  23067. $this->textstrokewidth = $stroke * $this->k;
  23068. }
  23069. /**
  23070. * Returns an array of chars containing soft hyphens.
  23071. * @param $word (array) array of chars
  23072. * @param $patterns (array) Array of hypenation patterns.
  23073. * @param $dictionary (array) Array of words to be returned without applying the hyphenation algoritm.
  23074. * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens.
  23075. * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens.
  23076. * @param $charmin (int) Minimum word lenght to apply the hyphenation algoritm.
  23077. * @param $charmax (int) Maximum lenght of broken piece of word.
  23078. * @return array text with soft hyphens
  23079. * @author Nicola Asuni
  23080. * @since 4.9.012 (2010-04-12)
  23081. * @protected
  23082. */
  23083. protected function hyphenateWord($word, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
  23084. $hyphenword = array(); // hyphens positions
  23085. $numchars = count($word);
  23086. if ($numchars <= $charmin) {
  23087. return $word;
  23088. }
  23089. $word_string = $this->UTF8ArrSubString($word);
  23090. // some words will be returned as-is
  23091. $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})(\]?)$/';
  23092. if (preg_match($pattern, $word_string) > 0) {
  23093. // email
  23094. return $word;
  23095. }
  23096. $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})(\]?)$/';
  23097. if (preg_match($pattern, $word_string) > 0) {
  23098. // URL
  23099. return $word;
  23100. }
  23101. if (isset($dictionary[$word_string])) {
  23102. return $this->UTF8StringToArray($dictionary[$word_string]);
  23103. }
  23104. // suround word with '_' characters
  23105. $tmpword = array_merge(array(95), $word, array(95));
  23106. $tmpnumchars = $numchars + 2;
  23107. $maxpos = $tmpnumchars - $charmin;
  23108. for ($pos = 0; $pos < $maxpos; ++$pos) {
  23109. $imax = min(($tmpnumchars - $pos), $charmax);
  23110. for ($i = $charmin; $i <= $imax; ++$i) {
  23111. $subword = strtolower($this->UTF8ArrSubString($tmpword, $pos, $pos + $i));
  23112. if (isset($patterns[$subword])) {
  23113. $pattern = $this->UTF8StringToArray($patterns[$subword]);
  23114. $pattern_length = count($pattern);
  23115. $digits = 1;
  23116. for ($j = 0; $j < $pattern_length; ++$j) {
  23117. // check if $pattern[$j] is a number
  23118. if (($pattern[$j] >= 48) AND ($pattern[$j] <= 57)) {
  23119. if ($j == 0) {
  23120. $zero = $pos - 1;
  23121. } else {
  23122. $zero = $pos + $j - $digits;
  23123. }
  23124. if (!isset($hyphenword[$zero]) OR ($hyphenword[$zero] != $pattern[$j])) {
  23125. $hyphenword[$zero] = $this->unichr($pattern[$j]);
  23126. }
  23127. ++$digits;
  23128. }
  23129. }
  23130. }
  23131. }
  23132. }
  23133. $inserted = 0;
  23134. $maxpos = $numchars - $rightmin;
  23135. for($i = $leftmin; $i <= $maxpos; ++$i) {
  23136. if(isset($hyphenword[$i]) AND (($hyphenword[$i] % 2) != 0)) {
  23137. // 173 = soft hyphen character
  23138. array_splice($word, $i + $inserted, 0, 173);
  23139. ++$inserted;
  23140. }
  23141. }
  23142. return $word;
  23143. }
  23144. /**
  23145. * Returns an array of hyphenation patterns.
  23146. * @param $file (string) TEX file containing hypenation patterns. TEX pattrns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
  23147. * @return array of hyphenation patterns
  23148. * @author Nicola Asuni
  23149. * @since 4.9.012 (2010-04-12)
  23150. * @public
  23151. */
  23152. public function getHyphenPatternsFromTEX($file) {
  23153. // TEX patterns are available at:
  23154. // http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
  23155. $data = file_get_contents($file);
  23156. $patterns = array();
  23157. // remove comments
  23158. $data = preg_replace('/\%[^\n]*/', '', $data);
  23159. // extract the patterns part
  23160. preg_match('/\\\\patterns\{([^\}]*)\}/i', $data, $matches);
  23161. $data = trim(substr($matches[0], 10, -1));
  23162. // extract each pattern
  23163. $patterns_array = preg_split('/[\s]+/', $data);
  23164. // create new language array of patterns
  23165. $patterns = array();
  23166. foreach($patterns_array as $val) {
  23167. if (!$this->empty_string($val)) {
  23168. $val = trim($val);
  23169. $val = str_replace('\'', '\\\'', $val);
  23170. $key = preg_replace('/[0-9]+/', '', $val);
  23171. $patterns[$key] = $val;
  23172. }
  23173. }
  23174. return $patterns;
  23175. }
  23176. /**
  23177. * Returns text with soft hyphens.
  23178. * @param $text (string) text to process
  23179. * @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/
  23180. * @param $dictionary (array) Array of words to be returned without applying the hyphenation algoritm.
  23181. * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens.
  23182. * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens.
  23183. * @param $charmin (int) Minimum word lenght to apply the hyphenation algoritm.
  23184. * @param $charmax (int) Maximum lenght of broken piece of word.
  23185. * @return array text with soft hyphens
  23186. * @author Nicola Asuni
  23187. * @since 4.9.012 (2010-04-12)
  23188. * @public
  23189. */
  23190. public function hyphenateText($text, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
  23191. $text = $this->unhtmlentities($text);
  23192. $word = array(); // last word
  23193. $txtarr = array(); // text to be returned
  23194. $intag = false; // true if we are inside an HTML tag
  23195. if (!is_array($patterns)) {
  23196. $patterns = $this->getHyphenPatternsFromTEX($patterns);
  23197. }
  23198. // get array of characters
  23199. $unichars = $this->UTF8StringToArray($text);
  23200. // for each char
  23201. foreach ($unichars as $char) {
  23202. if ((!$intag) AND $this->unicode->uni_type[$char] == 'L') {
  23203. // letter character
  23204. $word[] = $char;
  23205. } else {
  23206. // other type of character
  23207. if (!$this->empty_string($word)) {
  23208. // hypenate the word
  23209. $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
  23210. $word = array();
  23211. }
  23212. $txtarr[] = $char;
  23213. if (chr($char) == '<') {
  23214. // we are inside an HTML tag
  23215. $intag = true;
  23216. } elseif ($intag AND (chr($char) == '>')) {
  23217. // end of HTML tag
  23218. $intag = false;
  23219. }
  23220. }
  23221. }
  23222. if (!$this->empty_string($word)) {
  23223. // hypenate the word
  23224. $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
  23225. }
  23226. // convert char array to string and return
  23227. return $this->UTF8ArrSubString($txtarr);
  23228. }
  23229. /**
  23230. * Enable/disable rasterization of vector images using ImageMagick library.
  23231. * @param $mode (boolean) if true enable rasterization, false otherwise.
  23232. * @public
  23233. * @since 5.0.000 (2010-04-27)
  23234. */
  23235. public function setRasterizeVectorImages($mode) {
  23236. $this->rasterize_vector_images = $mode;
  23237. }
  23238. /**
  23239. * Get the Path-Painting Operators.
  23240. * @param $style (string) Style of rendering. Possible values are:
  23241. * <ul>
  23242. * <li>S or D: Stroke the path.</li>
  23243. * <li>s or d: Close and stroke the path.</li>
  23244. * <li>f or F: Fill the path, using the nonzero winding number rule to determine the region to fill.</li>
  23245. * <li>f* or F*: Fill the path, using the even-odd rule to determine the region to fill.</li>
  23246. * <li>B or FD or DF: Fill and then stroke the path, using the nonzero winding number rule to determine the region to fill.</li>
  23247. * <li>B* or F*D or DF*: Fill and then stroke the path, using the even-odd rule to determine the region to fill.</li>
  23248. * <li>b or fd or df: Close, fill, and then stroke the path, using the nonzero winding number rule to determine the region to fill.</li>
  23249. * <li>b or f*d or df*: Close, fill, and then stroke the path, using the even-odd rule to determine the region to fill.</li>
  23250. * <li>CNZ: Clipping mode using the even-odd rule to determine which regions lie inside the clipping path.</li>
  23251. * <li>CEO: Clipping mode using the nonzero winding number rule to determine which regions lie inside the clipping path</li>
  23252. * <li>n: End the path object without filling or stroking it.</li>
  23253. * </ul>
  23254. * @param $default (string) default style
  23255. * @author Nicola Asuni
  23256. * @since 5.0.000 (2010-04-30)
  23257. * @protected
  23258. */
  23259. protected function getPathPaintOperator($style, $default='S') {
  23260. $op = '';
  23261. switch($style) {
  23262. case 'S':
  23263. case 'D': {
  23264. $op = 'S';
  23265. break;
  23266. }
  23267. case 's':
  23268. case 'd': {
  23269. $op = 's';
  23270. break;
  23271. }
  23272. case 'f':
  23273. case 'F': {
  23274. $op = 'f';
  23275. break;
  23276. }
  23277. case 'f*':
  23278. case 'F*': {
  23279. $op = 'f*';
  23280. break;
  23281. }
  23282. case 'B':
  23283. case 'FD':
  23284. case 'DF': {
  23285. $op = 'B';
  23286. break;
  23287. }
  23288. case 'B*':
  23289. case 'F*D':
  23290. case 'DF*': {
  23291. $op = 'B*';
  23292. break;
  23293. }
  23294. case 'b':
  23295. case 'fd':
  23296. case 'df': {
  23297. $op = 'b';
  23298. break;
  23299. }
  23300. case 'b*':
  23301. case 'f*d':
  23302. case 'df*': {
  23303. $op = 'b*';
  23304. break;
  23305. }
  23306. case 'CNZ': {
  23307. $op = 'W n';
  23308. break;
  23309. }
  23310. case 'CEO': {
  23311. $op = 'W* n';
  23312. break;
  23313. }
  23314. case 'n': {
  23315. $op = 'n';
  23316. break;
  23317. }
  23318. default: {
  23319. if (!empty($default)) {
  23320. $op = $this->getPathPaintOperator($default, '');
  23321. } else {
  23322. $op = '';
  23323. }
  23324. }
  23325. }
  23326. return $op;
  23327. }
  23328. /**
  23329. * Enable or disable default option for font subsetting.
  23330. * @param $enable (boolean) if true enable font subsetting by default.
  23331. * @author Nicola Asuni
  23332. * @public
  23333. * @since 5.3.002 (2010-06-07)
  23334. */
  23335. public function setFontSubsetting($enable=true) {
  23336. $this->font_subsetting = $enable ? true : false;
  23337. }
  23338. /**
  23339. * Return the default option for font subsetting.
  23340. * @return boolean default font subsetting state.
  23341. * @author Nicola Asuni
  23342. * @public
  23343. * @since 5.3.002 (2010-06-07)
  23344. */
  23345. public function getFontSubsetting() {
  23346. return $this->font_subsetting;
  23347. }
  23348. /**
  23349. * Left trim the input string
  23350. * @param $str (string) string to trim
  23351. * @param $replace (string) string that replace spaces.
  23352. * @return left trimmed string
  23353. * @author Nicola Asuni
  23354. * @public
  23355. * @since 5.8.000 (2010-08-11)
  23356. */
  23357. public function stringLeftTrim($str, $replace='') {
  23358. return preg_replace('/^'.$this->re_space['p'].'+/'.$this->re_space['m'], $replace, $str);
  23359. }
  23360. /**
  23361. * Right trim the input string
  23362. * @param $str (string) string to trim
  23363. * @param $replace (string) string that replace spaces.
  23364. * @return right trimmed string
  23365. * @author Nicola Asuni
  23366. * @public
  23367. * @since 5.8.000 (2010-08-11)
  23368. */
  23369. public function stringRightTrim($str, $replace='') {
  23370. return preg_replace('/'.$this->re_space['p'].'+$/'.$this->re_space['m'], $replace, $str);
  23371. }
  23372. /**
  23373. * Trim the input string
  23374. * @param $str (string) string to trim
  23375. * @param $replace (string) string that replace spaces.
  23376. * @return trimmed string
  23377. * @author Nicola Asuni
  23378. * @public
  23379. * @since 5.8.000 (2010-08-11)
  23380. */
  23381. public function stringTrim($str, $replace='') {
  23382. $str = $this->stringLeftTrim($str, $replace);
  23383. $str = $this->stringRightTrim($str, $replace);
  23384. return $str;
  23385. }
  23386. /**
  23387. * Return true if the current font is unicode type.
  23388. * @return true for unicode font, false otherwise.
  23389. * @author Nicola Asuni
  23390. * @public
  23391. * @since 5.8.002 (2010-08-14)
  23392. */
  23393. public function isUnicodeFont() {
  23394. return (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0'));
  23395. }
  23396. /**
  23397. * Return normalized font name
  23398. * @param $fontfamily (string) property string containing font family names
  23399. * @return string normalized font name
  23400. * @author Nicola Asuni
  23401. * @public
  23402. * @since 5.8.004 (2010-08-17)
  23403. */
  23404. public function getFontFamilyName($fontfamily) {
  23405. // remove spaces and symbols
  23406. $fontfamily = preg_replace('/[^a-z0-9\,]/', '', strtolower($fontfamily));
  23407. // extract all font names
  23408. $fontslist = preg_split('/[,]/', $fontfamily);
  23409. // find first valid font name
  23410. foreach ($fontslist as $font) {
  23411. // replace font variations
  23412. $font = preg_replace('/italic$/', 'I', $font);
  23413. $font = preg_replace('/oblique$/', 'I', $font);
  23414. $font = preg_replace('/bold([I]?)$/', 'B\\1', $font);
  23415. // replace common family names and core fonts
  23416. $pattern = array();
  23417. $replacement = array();
  23418. $pattern[] = '/^serif|^cursive|^fantasy|^timesnewroman/';
  23419. $replacement[] = 'times';
  23420. $pattern[] = '/^sansserif/';
  23421. $replacement[] = 'helvetica';
  23422. $pattern[] = '/^monospace/';
  23423. $replacement[] = 'courier';
  23424. $font = preg_replace($pattern, $replacement, $font);
  23425. if (in_array(strtolower($font), $this->fontlist) OR in_array($font, $this->fontkeys)) {
  23426. return $font;
  23427. }
  23428. }
  23429. // return current font as default
  23430. return $this->CurrentFont['fontkey'];
  23431. }
  23432. /**
  23433. * Start a new XObject Template.
  23434. * 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).
  23435. * 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.
  23436. * Note: X,Y coordinates will be reset to 0,0.
  23437. * @param $w (int) Template width in user units (empty string or zero = page width less margins)
  23438. * @param $h (int) Template height in user units (empty string or zero = page height less margins)
  23439. * @return int the XObject Template ID in case of success or false in case of error.
  23440. * @author Nicola Asuni
  23441. * @public
  23442. * @since 5.8.017 (2010-08-24)
  23443. * @see endTemplate(), printTemplate()
  23444. */
  23445. public function startTemplate($w=0, $h=0) {
  23446. if ($this->inxobj) {
  23447. // we are already inside an XObject template
  23448. return false;
  23449. }
  23450. $this->inxobj = true;
  23451. ++$this->n;
  23452. // XObject ID
  23453. $this->xobjid = 'XT'.$this->n;
  23454. // object ID
  23455. $this->xobjects[$this->xobjid] = array('n' => $this->n);
  23456. // store current graphic state
  23457. $this->xobjects[$this->xobjid]['gvars'] = $this->getGraphicVars();
  23458. // initialize data
  23459. $this->xobjects[$this->xobjid]['intmrk'] = 0;
  23460. $this->xobjects[$this->xobjid]['transfmrk'] = array();
  23461. $this->xobjects[$this->xobjid]['outdata'] = '';
  23462. $this->xobjects[$this->xobjid]['xobjects'] = array();
  23463. $this->xobjects[$this->xobjid]['images'] = array();
  23464. $this->xobjects[$this->xobjid]['fonts'] = array();
  23465. $this->xobjects[$this->xobjid]['annotations'] = array();
  23466. // set new environment
  23467. $this->num_columns = 1;
  23468. $this->current_column = 0;
  23469. $this->SetAutoPageBreak(false);
  23470. if (($w === '') OR ($w <= 0)) {
  23471. $w = $this->w - $this->lMargin - $this->rMargin;
  23472. }
  23473. if (($h === '') OR ($h <= 0)) {
  23474. $h = $this->h - $this->tMargin - $this->bMargin;
  23475. }
  23476. $this->xobjects[$this->xobjid]['x'] = 0;
  23477. $this->xobjects[$this->xobjid]['y'] = 0;
  23478. $this->xobjects[$this->xobjid]['w'] = $w;
  23479. $this->xobjects[$this->xobjid]['h'] = $h;
  23480. $this->w = $w;
  23481. $this->h = $h;
  23482. $this->wPt = $this->w * $this->k;
  23483. $this->hPt = $this->h * $this->k;
  23484. $this->fwPt = $this->wPt;
  23485. $this->fhPt = $this->hPt;
  23486. $this->x = 0;
  23487. $this->y = 0;
  23488. $this->lMargin = 0;
  23489. $this->rMargin = 0;
  23490. $this->tMargin = 0;
  23491. $this->bMargin = 0;
  23492. return $this->xobjid;
  23493. }
  23494. /**
  23495. * End the current XObject Template started with startTemplate() and restore the previous graphic state.
  23496. * 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).
  23497. * 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.
  23498. * @return int the XObject Template ID in case of success or false in case of error.
  23499. * @author Nicola Asuni
  23500. * @public
  23501. * @since 5.8.017 (2010-08-24)
  23502. * @see startTemplate(), printTemplate()
  23503. */
  23504. public function endTemplate() {
  23505. if (!$this->inxobj) {
  23506. // we are not inside a template
  23507. return false;
  23508. }
  23509. $this->inxobj = false;
  23510. // restore previous graphic state
  23511. $this->setGraphicVars($this->xobjects[$this->xobjid]['gvars'], true);
  23512. return $this->xobjid;
  23513. }
  23514. /**
  23515. * Print an XObject Template.
  23516. * You can print an XObject Template inside the currently opened Template.
  23517. * 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).
  23518. * 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.
  23519. * @param $id (string) The ID of XObject Template to print.
  23520. * @param $x (int) X position in user units (empty string = current x position)
  23521. * @param $y (int) Y position in user units (empty string = current y position)
  23522. * @param $w (int) Width in user units (zero = remaining page width)
  23523. * @param $h (int) Height in user units (zero = remaining page height)
  23524. * @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>
  23525. * @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>
  23526. * @param $fitonpage (boolean) if true the template is resized to not exceed page dimensions.
  23527. * @author Nicola Asuni
  23528. * @public
  23529. * @since 5.8.017 (2010-08-24)
  23530. * @see startTemplate(), endTemplate()
  23531. */
  23532. public function printTemplate($id, $x='', $y='', $w=0, $h=0, $align='', $palign='', $fitonpage=false) {
  23533. if (!isset($this->xobjects[$id])) {
  23534. $this->Error('The XObject Template \''.$id.'\' doesn\'t exist!');
  23535. }
  23536. if ($this->inxobj) {
  23537. if ($id == $this->xobjid) {
  23538. // close current template
  23539. $this->endTemplate();
  23540. } else {
  23541. // use the template as resource for the template currently opened
  23542. $this->xobjects[$this->xobjid]['xobjects'][$id] = $this->xobjects[$id];
  23543. }
  23544. }
  23545. // set default values
  23546. if ($x === '') {
  23547. $x = $this->x;
  23548. }
  23549. if ($y === '') {
  23550. $y = $this->y;
  23551. }
  23552. // check page for no-write regions and adapt page margins if necessary
  23553. $this->checkPageRegions($h, $x, $y);
  23554. $ow = $this->xobjects[$id]['w'];
  23555. $oh = $this->xobjects[$id]['h'];
  23556. // calculate template width and height on document
  23557. if (($w <= 0) AND ($h <= 0)) {
  23558. $w = $ow;
  23559. $h = $oh;
  23560. } elseif ($w <= 0) {
  23561. $w = $h * $ow / $oh;
  23562. } elseif ($h <= 0) {
  23563. $h = $w * $oh / $ow;
  23564. }
  23565. // fit the template on available space
  23566. $this->fitBlock($w, $h, $x, $y, $fitonpage);
  23567. // set page alignment
  23568. $rb_y = $y + $h;
  23569. // set alignment
  23570. if ($this->rtl) {
  23571. if ($palign == 'L') {
  23572. $xt = $this->lMargin;
  23573. } elseif ($palign == 'C') {
  23574. $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  23575. } elseif ($palign == 'R') {
  23576. $xt = $this->w - $this->rMargin - $w;
  23577. } else {
  23578. $xt = $x - $w;
  23579. }
  23580. $rb_x = $xt;
  23581. } else {
  23582. if ($palign == 'L') {
  23583. $xt = $this->lMargin;
  23584. } elseif ($palign == 'C') {
  23585. $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  23586. } elseif ($palign == 'R') {
  23587. $xt = $this->w - $this->rMargin - $w;
  23588. } else {
  23589. $xt = $x;
  23590. }
  23591. $rb_x = $xt + $w;
  23592. }
  23593. // print XObject Template + Transformation matrix
  23594. $this->StartTransform();
  23595. // translate and scale
  23596. $sx = ($w / $this->xobjects[$id]['w']);
  23597. $sy = ($h / $this->xobjects[$id]['h']);
  23598. $tm = array();
  23599. $tm[0] = $sx;
  23600. $tm[1] = 0;
  23601. $tm[2] = 0;
  23602. $tm[3] = $sy;
  23603. $tm[4] = $xt * $this->k;
  23604. $tm[5] = ($this->h - $h - $y) * $this->k;
  23605. $this->Transform($tm);
  23606. // set object
  23607. $this->_out('/'.$id.' Do');
  23608. $this->StopTransform();
  23609. // add annotations
  23610. if (!empty($this->xobjects[$id]['annotations'])) {
  23611. foreach ($this->xobjects[$id]['annotations'] as $annot) {
  23612. // transform original coordinates
  23613. $coordlt = $this->getTransformationMatrixProduct($tm, array(1, 0, 0, 1, ($annot['x'] * $this->k), (-$annot['y'] * $this->k)));
  23614. $ax = ($coordlt[4] / $this->k);
  23615. $ay = ($this->h - $h - ($coordlt[5] / $this->k));
  23616. $coordrb = $this->getTransformationMatrixProduct($tm, array(1, 0, 0, 1, (($annot['x'] + $annot['w']) * $this->k), ((-$annot['y'] - $annot['h']) * $this->k)));
  23617. $aw = ($coordrb[4] / $this->k) - $ax;
  23618. $ah = ($this->h - $h - ($coordrb[5] / $this->k)) - $ay;
  23619. $this->Annotation($ax, $ay, $aw, $ah, $annot['text'], $annot['opt'], $annot['spaces']);
  23620. }
  23621. }
  23622. // set pointer to align the next text/objects
  23623. switch($align) {
  23624. case 'T': {
  23625. $this->y = $y;
  23626. $this->x = $rb_x;
  23627. break;
  23628. }
  23629. case 'M': {
  23630. $this->y = $y + round($h/2);
  23631. $this->x = $rb_x;
  23632. break;
  23633. }
  23634. case 'B': {
  23635. $this->y = $rb_y;
  23636. $this->x = $rb_x;
  23637. break;
  23638. }
  23639. case 'N': {
  23640. $this->SetY($rb_y);
  23641. break;
  23642. }
  23643. default:{
  23644. break;
  23645. }
  23646. }
  23647. }
  23648. /**
  23649. * Set the percentage of character stretching.
  23650. * @param $perc (int) percentage of stretching (100 = no stretching)
  23651. * @author Nicola Asuni
  23652. * @public
  23653. * @since 5.9.000 (2010-09-29)
  23654. */
  23655. public function setFontStretching($perc=100) {
  23656. $this->font_stretching = $perc;
  23657. }
  23658. /**
  23659. * Get the percentage of character stretching.
  23660. * @return float stretching value
  23661. * @author Nicola Asuni
  23662. * @public
  23663. * @since 5.9.000 (2010-09-29)
  23664. */
  23665. public function getFontStretching() {
  23666. return $this->font_stretching;
  23667. }
  23668. /**
  23669. * Set the amount to increase or decrease the space between characters in a text.
  23670. * @param $spacing (float) amount to increase or decrease the space between characters in a text (0 = default spacing)
  23671. * @author Nicola Asuni
  23672. * @public
  23673. * @since 5.9.000 (2010-09-29)
  23674. */
  23675. public function setFontSpacing($spacing=0) {
  23676. $this->font_spacing = $spacing;
  23677. }
  23678. /**
  23679. * Get the amount to increase or decrease the space between characters in a text.
  23680. * @return int font spacing (tracking/kerning) value
  23681. * @author Nicola Asuni
  23682. * @public
  23683. * @since 5.9.000 (2010-09-29)
  23684. */
  23685. public function getFontSpacing() {
  23686. return $this->font_spacing;
  23687. }
  23688. /**
  23689. * Return an array of no-write page regions
  23690. * @return array of no-write page regions
  23691. * @author Nicola Asuni
  23692. * @public
  23693. * @since 5.9.003 (2010-10-13)
  23694. * @see setPageRegions(), addPageRegion()
  23695. */
  23696. public function getPageRegions() {
  23697. return $this->page_regions;
  23698. }
  23699. /**
  23700. * Set no-write regions on page.
  23701. * 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.
  23702. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  23703. * You can set multiple regions for the same page.
  23704. * @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.
  23705. * @author Nicola Asuni
  23706. * @public
  23707. * @since 5.9.003 (2010-10-13)
  23708. * @see addPageRegion(), getPageRegions()
  23709. */
  23710. public function setPageRegions($regions=array()) {
  23711. // empty current regions array
  23712. $this->page_regions = array();
  23713. // add regions
  23714. foreach ($regions as $data) {
  23715. $this->addPageRegion($data);
  23716. }
  23717. }
  23718. /**
  23719. * Add a single no-write region on selected page.
  23720. * 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.
  23721. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  23722. * You can set multiple regions for the same page.
  23723. * @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).
  23724. * @author Nicola Asuni
  23725. * @public
  23726. * @since 5.9.003 (2010-10-13)
  23727. * @see setPageRegions(), getPageRegions()
  23728. */
  23729. public function addPageRegion($region) {
  23730. if (!isset($region['page']) OR empty($region['page'])) {
  23731. $region['page'] = $this->page;
  23732. }
  23733. if (isset($region['xt']) AND isset($region['xb']) AND ($region['xt'] > 0) AND ($region['xb'] > 0)
  23734. AND isset($region['yt']) AND isset($region['yb']) AND ($region['yt'] >= 0) AND ($region['yt'] < $region['yb'])
  23735. AND isset($region['side']) AND (($region['side'] == 'L') OR ($region['side'] == 'R'))) {
  23736. $this->page_regions[] = $region;
  23737. }
  23738. }
  23739. /**
  23740. * Remove a single no-write region.
  23741. * @param $key (int) region key
  23742. * @author Nicola Asuni
  23743. * @public
  23744. * @since 5.9.003 (2010-10-13)
  23745. * @see setPageRegions(), getPageRegions()
  23746. */
  23747. public function removePageRegion($key) {
  23748. if (isset($this->page_regions[$key])) {
  23749. unset($this->page_regions[$key]);
  23750. }
  23751. }
  23752. /**
  23753. * Check page for no-write regions and adapt current coordinates and page margins if necessary.
  23754. * 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.
  23755. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  23756. * @param $h (float) height of the text/image/object to print in user units
  23757. * @param $x (float) current X coordinate in user units
  23758. * @param $y (float) current Y coordinate in user units
  23759. * @author Nicola Asuni
  23760. * @protected
  23761. * @since 5.9.003 (2010-10-13)
  23762. */
  23763. protected function checkPageRegions($h, &$x, &$y) {
  23764. // set default values
  23765. if ($x === '') {
  23766. $x = &$this->x;
  23767. }
  23768. if ($y === '') {
  23769. $y = &$this->y;
  23770. }
  23771. if (empty($this->page_regions)) {
  23772. // no page regions defined
  23773. return;
  23774. }
  23775. if (empty($h)) {
  23776. $h = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  23777. }
  23778. if ($this->AutoPageBreak AND (!$this->InFooter) AND (($y + $h) > $this->PageBreakTrigger)) {
  23779. // the content will be printed on a new page
  23780. return;
  23781. }
  23782. if ($this->num_columns > 1) {
  23783. if ($this->rtl) {
  23784. $this->lMargin = $this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w'];
  23785. } else {
  23786. $this->rMargin = $this->w - $this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w'];
  23787. }
  23788. } else {
  23789. if ($this->rtl) {
  23790. $this->lMargin = $this->original_lMargin;
  23791. } else {
  23792. $this->rMargin = $this->original_rMargin;
  23793. }
  23794. }
  23795. // adjust coordinates and page margins
  23796. foreach ($this->page_regions as $regid => $regdata) {
  23797. if ($regdata['page'] == $this->page) {
  23798. // check region boundaries
  23799. if (($y > ($regdata['yt'] - $h)) AND ($y <= $regdata['yb'])) {
  23800. // Y is inside the region
  23801. $minv = ($regdata['xb'] - $regdata['xt']) / ($regdata['yb'] - $regdata['yt']); // inverse of angular coefficient
  23802. $yt = max($y, $regdata['yt']);
  23803. $yb = min(($yt + $h), $regdata['yb']);
  23804. $xt = (($yt - $regdata['yt']) * $minv) + $regdata['xt'];
  23805. $xb = (($yb - $regdata['yt']) * $minv) + $regdata['xt'];
  23806. if ($regdata['side'] == 'L') { // left side
  23807. $new_margin = max($xt, $xb);
  23808. if ($this->lMargin < $new_margin) {
  23809. if ($this->rtl) {
  23810. // adjust left page margin
  23811. $this->lMargin = $new_margin;
  23812. }
  23813. if ($x < $new_margin) {
  23814. // adjust x position
  23815. $x = $new_margin;
  23816. if ($new_margin > ($this->w - $this->rMargin)) {
  23817. // adjust y position
  23818. $y = $regdata['yb'] - $h;
  23819. }
  23820. }
  23821. }
  23822. } elseif ($regdata['side'] == 'R') { // right side
  23823. $new_margin = min($xt, $xb);
  23824. if (($this->w - $this->rMargin) > $new_margin) {
  23825. if (!$this->rtl) {
  23826. // adjust right page margin
  23827. $this->rMargin = ($this->w - $new_margin);
  23828. }
  23829. if ($x > $new_margin) {
  23830. // adjust x position
  23831. $x = $new_margin;
  23832. if ($new_margin > $this->lMargin) {
  23833. // adjust y position
  23834. $y = $regdata['yb'] - $h;
  23835. }
  23836. }
  23837. }
  23838. }
  23839. }
  23840. }
  23841. }
  23842. }
  23843. // -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
  23844. // SVG METHODS
  23845. // -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
  23846. /**
  23847. * Embedd a Scalable Vector Graphics (SVG) image.
  23848. * NOTE: SVG standard is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  23849. * @param $file (string) Name of the SVG file or a '@' character followed by the SVG data string.
  23850. * @param $x (float) Abscissa of the upper-left corner.
  23851. * @param $y (float) Ordinate of the upper-left corner.
  23852. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  23853. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  23854. * @param $link (mixed) URL or identifier returned by AddLink().
  23855. * @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.
  23856. * @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>
  23857. * @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)))
  23858. * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
  23859. * @author Nicola Asuni
  23860. * @since 5.0.000 (2010-05-02)
  23861. * @public
  23862. */
  23863. public function ImageSVG($file, $x='', $y='', $w=0, $h=0, $link='', $align='', $palign='', $border=0, $fitonpage=false) {
  23864. if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
  23865. // convert SVG to raster image using GD or ImageMagick libraries
  23866. return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
  23867. }
  23868. if ($file{0} === '@') { // image from string
  23869. $this->svgdir = '';
  23870. $svgdata = substr($file, 1);
  23871. } else { // SVG file
  23872. $this->svgdir = dirname($file);
  23873. $svgdata = file_get_contents($file);
  23874. }
  23875. if ($svgdata === false) {
  23876. $this->Error('SVG file not found: '.$file);
  23877. }
  23878. if ($x === '') {
  23879. $x = $this->x;
  23880. }
  23881. if ($y === '') {
  23882. $y = $this->y;
  23883. }
  23884. // check page for no-write regions and adapt page margins if necessary
  23885. $this->checkPageRegions($h, $x, $y);
  23886. $k = $this->k;
  23887. $ox = 0;
  23888. $oy = 0;
  23889. $ow = $w;
  23890. $oh = $h;
  23891. $aspect_ratio_align = 'xMidYMid';
  23892. $aspect_ratio_ms = 'meet';
  23893. $regs = array();
  23894. // get original image width and height
  23895. preg_match('/<svg([^\>]*)>/si', $svgdata, $regs);
  23896. if (isset($regs[1]) AND !empty($regs[1])) {
  23897. $tmp = array();
  23898. if (preg_match('/[\s]+x[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  23899. $ox = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
  23900. }
  23901. $tmp = array();
  23902. if (preg_match('/[\s]+y[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  23903. $oy = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
  23904. }
  23905. $tmp = array();
  23906. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  23907. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  23908. }
  23909. $tmp = array();
  23910. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  23911. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  23912. }
  23913. $tmp = array();
  23914. $view_box = array();
  23915. if (preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.\-]+)[\s]+([0-9\.\-]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $regs[1], $tmp)) {
  23916. if (count($tmp) == 5) {
  23917. array_shift($tmp);
  23918. foreach ($tmp as $key => $val) {
  23919. $view_box[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
  23920. }
  23921. $ox = $view_box[0];
  23922. $oy = $view_box[1];
  23923. }
  23924. // get aspect ratio
  23925. $tmp = array();
  23926. if (preg_match('/[\s]+preserveAspectRatio[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  23927. $aspect_ratio = preg_split('/[\s]+/si', $tmp[1]);
  23928. switch (count($aspect_ratio)) {
  23929. case 3: {
  23930. $aspect_ratio_align = $aspect_ratio[1];
  23931. $aspect_ratio_ms = $aspect_ratio[2];
  23932. break;
  23933. }
  23934. case 2: {
  23935. $aspect_ratio_align = $aspect_ratio[0];
  23936. $aspect_ratio_ms = $aspect_ratio[1];
  23937. break;
  23938. }
  23939. case 1: {
  23940. $aspect_ratio_align = $aspect_ratio[0];
  23941. $aspect_ratio_ms = 'meet';
  23942. break;
  23943. }
  23944. }
  23945. }
  23946. }
  23947. }
  23948. // calculate image width and height on document
  23949. if (($w <= 0) AND ($h <= 0)) {
  23950. // convert image size to document unit
  23951. $w = $ow;
  23952. $h = $oh;
  23953. } elseif ($w <= 0) {
  23954. $w = $h * $ow / $oh;
  23955. } elseif ($h <= 0) {
  23956. $h = $w * $oh / $ow;
  23957. }
  23958. // fit the image on available space
  23959. $this->fitBlock($w, $h, $x, $y, $fitonpage);
  23960. if ($this->rasterize_vector_images) {
  23961. // convert SVG to raster image using GD or ImageMagick libraries
  23962. return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
  23963. }
  23964. // set alignment
  23965. $this->img_rb_y = $y + $h;
  23966. // set alignment
  23967. if ($this->rtl) {
  23968. if ($palign == 'L') {
  23969. $ximg = $this->lMargin;
  23970. } elseif ($palign == 'C') {
  23971. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  23972. } elseif ($palign == 'R') {
  23973. $ximg = $this->w - $this->rMargin - $w;
  23974. } else {
  23975. $ximg = $x - $w;
  23976. }
  23977. $this->img_rb_x = $ximg;
  23978. } else {
  23979. if ($palign == 'L') {
  23980. $ximg = $this->lMargin;
  23981. } elseif ($palign == 'C') {
  23982. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  23983. } elseif ($palign == 'R') {
  23984. $ximg = $this->w - $this->rMargin - $w;
  23985. } else {
  23986. $ximg = $x;
  23987. }
  23988. $this->img_rb_x = $ximg + $w;
  23989. }
  23990. // store current graphic vars
  23991. $gvars = $this->getGraphicVars();
  23992. // store SVG position and scale factors
  23993. $svgoffset_x = ($ximg - $ox) * $this->k;
  23994. $svgoffset_y = -($y - $oy) * $this->k;
  23995. if (isset($view_box[2]) AND ($view_box[2] > 0) AND ($view_box[3] > 0)) {
  23996. $ow = $view_box[2];
  23997. $oh = $view_box[3];
  23998. } else {
  23999. if ($ow <= 0) {
  24000. $ow = $w;
  24001. }
  24002. if ($oh <= 0) {
  24003. $oh = $h;
  24004. }
  24005. }
  24006. $svgscale_x = $w / $ow;
  24007. $svgscale_y = $h / $oh;
  24008. // scaling and alignment
  24009. if ($aspect_ratio_align != 'none') {
  24010. // store current scaling values
  24011. $svgscale_old_x = $svgscale_x;
  24012. $svgscale_old_y = $svgscale_y;
  24013. // force uniform scaling
  24014. if ($aspect_ratio_ms == 'slice') {
  24015. // the entire viewport is covered by the viewBox
  24016. if ($svgscale_x > $svgscale_y) {
  24017. $svgscale_y = $svgscale_x;
  24018. } elseif ($svgscale_x < $svgscale_y) {
  24019. $svgscale_x = $svgscale_y;
  24020. }
  24021. } else { // meet
  24022. // the entire viewBox is visible within the viewport
  24023. if ($svgscale_x < $svgscale_y) {
  24024. $svgscale_y = $svgscale_x;
  24025. } elseif ($svgscale_x > $svgscale_y) {
  24026. $svgscale_x = $svgscale_y;
  24027. }
  24028. }
  24029. // correct X alignment
  24030. switch (substr($aspect_ratio_align, 1, 3)) {
  24031. case 'Min': {
  24032. // do nothing
  24033. break;
  24034. }
  24035. case 'Max': {
  24036. $svgoffset_x += (($w * $this->k) - ($ow * $this->k * $svgscale_x));
  24037. break;
  24038. }
  24039. default:
  24040. case 'Mid': {
  24041. $svgoffset_x += ((($w * $this->k) - ($ow * $this->k * $svgscale_x)) / 2);
  24042. break;
  24043. }
  24044. }
  24045. // correct Y alignment
  24046. switch (substr($aspect_ratio_align, 5)) {
  24047. case 'Min': {
  24048. // do nothing
  24049. break;
  24050. }
  24051. case 'Max': {
  24052. $svgoffset_y -= (($h * $this->k) - ($oh * $this->k * $svgscale_y));
  24053. break;
  24054. }
  24055. default:
  24056. case 'Mid': {
  24057. $svgoffset_y -= ((($h * $this->k) - ($oh * $this->k * $svgscale_y)) / 2);
  24058. break;
  24059. }
  24060. }
  24061. }
  24062. // store current page break mode
  24063. $page_break_mode = $this->AutoPageBreak;
  24064. $page_break_margin = $this->getBreakMargin();
  24065. $cell_padding = $this->cell_padding;
  24066. $this->SetCellPadding(0);
  24067. $this->SetAutoPageBreak(false);
  24068. // save the current graphic state
  24069. $this->_out('q'.$this->epsmarker);
  24070. // set initial clipping mask
  24071. $this->Rect($x, $y, $w, $h, 'CNZ', array(), array());
  24072. // scale and translate
  24073. $e = $ox * $this->k * (1 - $svgscale_x);
  24074. $f = ($this->h - $oy) * $this->k * (1 - $svgscale_y);
  24075. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $svgscale_x, 0, 0, $svgscale_y, $e + $svgoffset_x, $f + $svgoffset_y));
  24076. // creates a new XML parser to be used by the other XML functions
  24077. $this->parser = xml_parser_create('UTF-8');
  24078. // the following function allows to use parser inside object
  24079. xml_set_object($this->parser, $this);
  24080. // disable case-folding for this XML parser
  24081. xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
  24082. // sets the element handler functions for the XML parser
  24083. xml_set_element_handler($this->parser, 'startSVGElementHandler', 'endSVGElementHandler');
  24084. // sets the character data handler function for the XML parser
  24085. xml_set_character_data_handler($this->parser, 'segSVGContentHandler');
  24086. // start parsing an XML document
  24087. if(!xml_parse($this->parser, $svgdata)) {
  24088. $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));
  24089. $this->Error($error_message);
  24090. }
  24091. // free this XML parser
  24092. xml_parser_free($this->parser);
  24093. // restore previous graphic state
  24094. $this->_out($this->epsmarker.'Q');
  24095. // restore graphic vars
  24096. $this->setGraphicVars($gvars);
  24097. $this->lasth = $gvars['lasth'];
  24098. if (!empty($border)) {
  24099. $bx = $this->x;
  24100. $by = $this->y;
  24101. $this->x = $ximg;
  24102. if ($this->rtl) {
  24103. $this->x += $w;
  24104. }
  24105. $this->y = $y;
  24106. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  24107. $this->x = $bx;
  24108. $this->y = $by;
  24109. }
  24110. if ($link) {
  24111. $this->Link($ximg, $y, $w, $h, $link, 0);
  24112. }
  24113. // set pointer to align the next text/objects
  24114. switch($align) {
  24115. case 'T':{
  24116. $this->y = $y;
  24117. $this->x = $this->img_rb_x;
  24118. break;
  24119. }
  24120. case 'M':{
  24121. $this->y = $y + round($h/2);
  24122. $this->x = $this->img_rb_x;
  24123. break;
  24124. }
  24125. case 'B':{
  24126. $this->y = $this->img_rb_y;
  24127. $this->x = $this->img_rb_x;
  24128. break;
  24129. }
  24130. case 'N':{
  24131. $this->SetY($this->img_rb_y);
  24132. break;
  24133. }
  24134. default:{
  24135. // restore pointer to starting position
  24136. $this->x = $gvars['x'];
  24137. $this->y = $gvars['y'];
  24138. $this->page = $gvars['page'];
  24139. $this->current_column = $gvars['current_column'];
  24140. $this->tMargin = $gvars['tMargin'];
  24141. $this->bMargin = $gvars['bMargin'];
  24142. $this->w = $gvars['w'];
  24143. $this->h = $gvars['h'];
  24144. $this->wPt = $gvars['wPt'];
  24145. $this->hPt = $gvars['hPt'];
  24146. $this->fwPt = $gvars['fwPt'];
  24147. $this->fhPt = $gvars['fhPt'];
  24148. break;
  24149. }
  24150. }
  24151. $this->endlinex = $this->img_rb_x;
  24152. // restore page break
  24153. $this->SetAutoPageBreak($page_break_mode, $page_break_margin);
  24154. $this->cell_padding = $cell_padding;
  24155. }
  24156. /**
  24157. * Get the tranformation matrix from SVG transform attribute
  24158. * @param $attribute (string) transformation
  24159. * @return array of transformations
  24160. * @author Nicola Asuni
  24161. * @since 5.0.000 (2010-05-02)
  24162. * @protected
  24163. */
  24164. protected function getSVGTransformMatrix($attribute) {
  24165. // identity matrix
  24166. $tm = array(1, 0, 0, 1, 0, 0);
  24167. $transform = array();
  24168. if (preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)[\s]*\(([^\)]+)\)/si', $attribute, $transform, PREG_SET_ORDER) > 0) {
  24169. foreach ($transform as $key => $data) {
  24170. if (!empty($data[2])) {
  24171. $a = 1;
  24172. $b = 0;
  24173. $c = 0;
  24174. $d = 1;
  24175. $e = 0;
  24176. $f = 0;
  24177. $regs = array();
  24178. switch ($data[1]) {
  24179. case 'matrix': {
  24180. if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  24181. $a = $regs[1];
  24182. $b = $regs[2];
  24183. $c = $regs[3];
  24184. $d = $regs[4];
  24185. $e = $regs[5];
  24186. $f = $regs[6];
  24187. }
  24188. break;
  24189. }
  24190. case 'translate': {
  24191. if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  24192. $e = $regs[1];
  24193. $f = $regs[2];
  24194. } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  24195. $e = $regs[1];
  24196. }
  24197. break;
  24198. }
  24199. case 'scale': {
  24200. if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  24201. $a = $regs[1];
  24202. $d = $regs[2];
  24203. } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  24204. $a = $regs[1];
  24205. $d = $a;
  24206. }
  24207. break;
  24208. }
  24209. case 'rotate': {
  24210. if (preg_match('/([0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  24211. $ang = deg2rad($regs[1]);
  24212. $x = $regs[2];
  24213. $y = $regs[3];
  24214. $a = cos($ang);
  24215. $b = sin($ang);
  24216. $c = -$b;
  24217. $d = $a;
  24218. $e = ($x * (1 - $a)) - ($y * $c);
  24219. $f = ($y * (1 - $d)) - ($x * $b);
  24220. } elseif (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
  24221. $ang = deg2rad($regs[1]);
  24222. $a = cos($ang);
  24223. $b = sin($ang);
  24224. $c = -$b;
  24225. $d = $a;
  24226. $e = 0;
  24227. $f = 0;
  24228. }
  24229. break;
  24230. }
  24231. case 'skewX': {
  24232. if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
  24233. $c = tan(deg2rad($regs[1]));
  24234. }
  24235. break;
  24236. }
  24237. case 'skewY': {
  24238. if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
  24239. $b = tan(deg2rad($regs[1]));
  24240. }
  24241. break;
  24242. }
  24243. }
  24244. $tm = $this->getTransformationMatrixProduct($tm, array($a, $b, $c, $d, $e, $f));
  24245. }
  24246. }
  24247. }
  24248. return $tm;
  24249. }
  24250. /**
  24251. * Get the product of two SVG tranformation matrices
  24252. * @param $ta (array) first SVG tranformation matrix
  24253. * @param $tb (array) second SVG tranformation matrix
  24254. * @return transformation array
  24255. * @author Nicola Asuni
  24256. * @since 5.0.000 (2010-05-02)
  24257. * @protected
  24258. */
  24259. protected function getTransformationMatrixProduct($ta, $tb) {
  24260. $tm = array();
  24261. $tm[0] = ($ta[0] * $tb[0]) + ($ta[2] * $tb[1]);
  24262. $tm[1] = ($ta[1] * $tb[0]) + ($ta[3] * $tb[1]);
  24263. $tm[2] = ($ta[0] * $tb[2]) + ($ta[2] * $tb[3]);
  24264. $tm[3] = ($ta[1] * $tb[2]) + ($ta[3] * $tb[3]);
  24265. $tm[4] = ($ta[0] * $tb[4]) + ($ta[2] * $tb[5]) + $ta[4];
  24266. $tm[5] = ($ta[1] * $tb[4]) + ($ta[3] * $tb[5]) + $ta[5];
  24267. return $tm;
  24268. }
  24269. /**
  24270. * Convert SVG transformation matrix to PDF.
  24271. * @param $tm (array) original SVG transformation matrix
  24272. * @return array transformation matrix
  24273. * @protected
  24274. * @since 5.0.000 (2010-05-02)
  24275. */
  24276. protected function convertSVGtMatrix($tm) {
  24277. $a = $tm[0];
  24278. $b = -$tm[1];
  24279. $c = -$tm[2];
  24280. $d = $tm[3];
  24281. $e = $this->getHTMLUnitToUnits($tm[4], 1, $this->svgunit, false) * $this->k;
  24282. $f = -$this->getHTMLUnitToUnits($tm[5], 1, $this->svgunit, false) * $this->k;
  24283. $x = 0;
  24284. $y = $this->h * $this->k;
  24285. $e = ($x * (1 - $a)) - ($y * $c) + $e;
  24286. $f = ($y * (1 - $d)) - ($x * $b) + $f;
  24287. return array($a, $b, $c, $d, $e, $f);
  24288. }
  24289. /**
  24290. * Apply SVG graphic transformation matrix.
  24291. * @param $tm (array) original SVG transformation matrix
  24292. * @protected
  24293. * @since 5.0.000 (2010-05-02)
  24294. */
  24295. protected function SVGTransform($tm) {
  24296. $this->Transform($this->convertSVGtMatrix($tm));
  24297. }
  24298. /**
  24299. * Apply the requested SVG styles (*** TO BE COMPLETED ***)
  24300. * @param $svgstyle (array) array of SVG styles to apply
  24301. * @param $prevsvgstyle (array) array of previous SVG style
  24302. * @param $x (int) X origin of the bounding box
  24303. * @param $y (int) Y origin of the bounding box
  24304. * @param $w (int) width of the bounding box
  24305. * @param $h (int) height of the bounding box
  24306. * @param $clip_function (string) clip function
  24307. * @param $clip_params (array) array of parameters for clipping function
  24308. * @return object style
  24309. * @author Nicola Asuni
  24310. * @since 5.0.000 (2010-05-02)
  24311. * @protected
  24312. */
  24313. protected function setSVGStyles($svgstyle, $prevsvgstyle, $x=0, $y=0, $w=1, $h=1, $clip_function='', $clip_params=array()) {
  24314. $objstyle = '';
  24315. if(!isset($svgstyle['opacity'])) {
  24316. return $objstyle;
  24317. }
  24318. // clip-path
  24319. $regs = array();
  24320. if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['clip-path'], $regs)) {
  24321. $clip_path = $this->svgclippaths[$regs[1]];
  24322. foreach ($clip_path as $cp) {
  24323. $this->startSVGElementHandler('clip-path', $cp['name'], $cp['attribs'], $cp['tm']);
  24324. }
  24325. }
  24326. // opacity
  24327. if ($svgstyle['opacity'] != 1) {
  24328. $this->SetAlpha($svgstyle['opacity']);
  24329. }
  24330. // color
  24331. $fill_color = $this->convertHTMLColorToDec($svgstyle['color']);
  24332. $this->SetFillColorArray($fill_color);
  24333. // text color
  24334. $text_color = $this->convertHTMLColorToDec($svgstyle['text-color']);
  24335. $this->SetTextColorArray($text_color);
  24336. // clip
  24337. if (preg_match('/rect\(([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)\)/si', $svgstyle['clip'], $regs)) {
  24338. $top = (isset($regs[1])?$this->getHTMLUnitToUnits($regs[1], 0, $this->svgunit, false):0);
  24339. $right = (isset($regs[2])?$this->getHTMLUnitToUnits($regs[2], 0, $this->svgunit, false):0);
  24340. $bottom = (isset($regs[3])?$this->getHTMLUnitToUnits($regs[3], 0, $this->svgunit, false):0);
  24341. $left = (isset($regs[4])?$this->getHTMLUnitToUnits($regs[4], 0, $this->svgunit, false):0);
  24342. $cx = $x + $left;
  24343. $cy = $y + $top;
  24344. $cw = $w - $left - $right;
  24345. $ch = $h - $top - $bottom;
  24346. if ($svgstyle['clip-rule'] == 'evenodd') {
  24347. $clip_rule = 'CNZ';
  24348. } else {
  24349. $clip_rule = 'CEO';
  24350. }
  24351. $this->Rect($cx, $cy, $cw, $ch, $clip_rule, array(), array());
  24352. }
  24353. // fill
  24354. $regs = array();
  24355. if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['fill'], $regs)) {
  24356. // gradient
  24357. $gradient = $this->svggradients[$regs[1]];
  24358. if (isset($gradient['xref'])) {
  24359. // reference to another gradient definition
  24360. $newgradient = $this->svggradients[$gradient['xref']];
  24361. $newgradient['coords'] = $gradient['coords'];
  24362. $newgradient['mode'] = $gradient['mode'];
  24363. $newgradient['gradientUnits'] = $gradient['gradientUnits'];
  24364. if (isset($gradient['gradientTransform'])) {
  24365. $newgradient['gradientTransform'] = $gradient['gradientTransform'];
  24366. }
  24367. $gradient = $newgradient;
  24368. }
  24369. //save current Graphic State
  24370. $this->_out('q');
  24371. //set clipping area
  24372. if (!empty($clip_function) AND method_exists($this, $clip_function)) {
  24373. $bbox = call_user_func_array(array($this, $clip_function), $clip_params);
  24374. if (is_array($bbox) AND (count($bbox) == 4)) {
  24375. list($x, $y, $w, $h) = $bbox;
  24376. }
  24377. }
  24378. if ($gradient['mode'] == 'measure') {
  24379. if (isset($gradient['gradientTransform']) AND !empty($gradient['gradientTransform'])) {
  24380. $gtm = $gradient['gradientTransform'];
  24381. // apply transformation matrix
  24382. $xa = ($gtm[0] * $gradient['coords'][0]) + ($gtm[2] * $gradient['coords'][1]) + $gtm[4];
  24383. $ya = ($gtm[1] * $gradient['coords'][0]) + ($gtm[3] * $gradient['coords'][1]) + $gtm[5];
  24384. $xb = ($gtm[0] * $gradient['coords'][2]) + ($gtm[2] * $gradient['coords'][3]) + $gtm[4];
  24385. $yb = ($gtm[1] * $gradient['coords'][2]) + ($gtm[3] * $gradient['coords'][3]) + $gtm[5];
  24386. if (isset($gradient['coords'][4])) {
  24387. $gradient['coords'][4] = sqrt(pow(($gtm[0] * $gradient['coords'][4]), 2) + pow(($gtm[1] * $gradient['coords'][4]), 2));
  24388. }
  24389. $gradient['coords'][0] = $xa;
  24390. $gradient['coords'][1] = $ya;
  24391. $gradient['coords'][2] = $xb;
  24392. $gradient['coords'][3] = $yb;
  24393. }
  24394. // convert SVG coordinates to user units
  24395. $gradient['coords'][0] = $this->getHTMLUnitToUnits($gradient['coords'][0], 0, $this->svgunit, false);
  24396. $gradient['coords'][1] = $this->getHTMLUnitToUnits($gradient['coords'][1], 0, $this->svgunit, false);
  24397. $gradient['coords'][2] = $this->getHTMLUnitToUnits($gradient['coords'][2], 0, $this->svgunit, false);
  24398. $gradient['coords'][3] = $this->getHTMLUnitToUnits($gradient['coords'][3], 0, $this->svgunit, false);
  24399. if (isset($gradient['coords'][4])) {
  24400. $gradient['coords'][4] = $this->getHTMLUnitToUnits($gradient['coords'][4], 0, $this->svgunit, false);
  24401. }
  24402. // shift units
  24403. if ($gradient['gradientUnits'] == 'objectBoundingBox') {
  24404. // convert to SVG coordinate system
  24405. $gradient['coords'][0] += $x;
  24406. $gradient['coords'][1] += $y;
  24407. $gradient['coords'][2] += $x;
  24408. $gradient['coords'][3] += $y;
  24409. }
  24410. if ($w <= 0) {
  24411. $w = 1;
  24412. }
  24413. if ($h <= 0) {
  24414. $h = 1;
  24415. }
  24416. // calculate percentages
  24417. $gradient['coords'][0] = ($gradient['coords'][0] - $x) / $w;
  24418. $gradient['coords'][1] = ($gradient['coords'][1] - $y) / $h;
  24419. $gradient['coords'][2] = ($gradient['coords'][2] - $x) / $w;
  24420. $gradient['coords'][3] = ($gradient['coords'][3] - $y) / $h;
  24421. if (isset($gradient['coords'][4])) {
  24422. $gradient['coords'][4] /= $w;
  24423. }
  24424. } elseif ($gradient['mode'] == 'percentage') {
  24425. foreach($gradient['coords'] as $key => $val) {
  24426. $gradient['coords'][$key] = (intval($val) / 100);
  24427. }
  24428. }
  24429. // fix values
  24430. foreach($gradient['coords'] as $key => $val) {
  24431. if ($val < 0) {
  24432. $gradient['coords'][$key] = 0;
  24433. } elseif ($val > 1) {
  24434. $gradient['coords'][$key] = 1;
  24435. }
  24436. }
  24437. if (($gradient['type'] == 2) AND ($gradient['coords'][0] == $gradient['coords'][2]) AND ($gradient['coords'][1] == $gradient['coords'][3])) {
  24438. // single color (no shading)
  24439. $gradient['coords'][0] = 1;
  24440. $gradient['coords'][1] = 0;
  24441. $gradient['coords'][2] = 0.999;
  24442. $gradient['coords'][3] = 0;
  24443. }
  24444. // swap Y coordinates
  24445. $tmp = $gradient['coords'][1];
  24446. $gradient['coords'][1] = $gradient['coords'][3];
  24447. $gradient['coords'][3] = $tmp;
  24448. // set transformation map for gradient
  24449. if ($gradient['type'] == 3) {
  24450. // gradient is always circular
  24451. $cy = $this->h - $y - ($gradient['coords'][1] * ($w + $h));
  24452. $this->_out(sprintf('%.3F 0 0 %.3F %.3F %.3F cm', $w*$this->k, $w*$this->k, $x*$this->k, $cy*$this->k));
  24453. } else {
  24454. $this->_out(sprintf('%.3F 0 0 %.3F %.3F %.3F cm', $w*$this->k, $h*$this->k, $x*$this->k, ($this->h-($y+$h))*$this->k));
  24455. }
  24456. if (count($gradient['stops']) > 1) {
  24457. $this->Gradient($gradient['type'], $gradient['coords'], $gradient['stops'], array(), false);
  24458. }
  24459. } elseif ($svgstyle['fill'] != 'none') {
  24460. $fill_color = $this->convertHTMLColorToDec($svgstyle['fill']);
  24461. if ($svgstyle['fill-opacity'] != 1) {
  24462. $this->SetAlpha($svgstyle['fill-opacity']);
  24463. }
  24464. $this->SetFillColorArray($fill_color);
  24465. if ($svgstyle['fill-rule'] == 'evenodd') {
  24466. $objstyle .= 'F*';
  24467. } else {
  24468. $objstyle .= 'F';
  24469. }
  24470. }
  24471. // stroke
  24472. if ($svgstyle['stroke'] != 'none') {
  24473. $stroke_style = array(
  24474. 'color' => $this->convertHTMLColorToDec($svgstyle['stroke']),
  24475. 'width' => $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false),
  24476. 'cap' => $svgstyle['stroke-linecap'],
  24477. 'join' => $svgstyle['stroke-linejoin']
  24478. );
  24479. if (isset($svgstyle['stroke-dasharray']) AND !empty($svgstyle['stroke-dasharray']) AND ($svgstyle['stroke-dasharray'] != 'none')) {
  24480. $stroke_style['dash'] = $svgstyle['stroke-dasharray'];
  24481. }
  24482. $this->SetLineStyle($stroke_style);
  24483. $objstyle .= 'D';
  24484. }
  24485. // font
  24486. $regs = array();
  24487. if (!empty($svgstyle['font'])) {
  24488. if (preg_match('/font-family[\s]*:[\s]*([^\;\"]*)/si', $svgstyle['font'], $regs)) {
  24489. $font_family = $this->getFontFamilyName($regs[1]);
  24490. } else {
  24491. $font_family = $svgstyle['font-family'];
  24492. }
  24493. if (preg_match('/font-size[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  24494. $font_size = trim($regs[1]);
  24495. } else {
  24496. $font_size = $svgstyle['font-size'];
  24497. }
  24498. if (preg_match('/font-style[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  24499. $font_style = trim($regs[1]);
  24500. } else {
  24501. $font_style = $svgstyle['font-style'];
  24502. }
  24503. if (preg_match('/font-weight[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  24504. $font_weight = trim($regs[1]);
  24505. } else {
  24506. $font_weight = $svgstyle['font-weight'];
  24507. }
  24508. if (preg_match('/font-stretch[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  24509. $font_stretch = trim($regs[1]);
  24510. } else {
  24511. $font_stretch = $svgstyle['font-stretch'];
  24512. }
  24513. if (preg_match('/letter-spacing[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  24514. $font_spacing = trim($regs[1]);
  24515. } else {
  24516. $font_spacing = $svgstyle['letter-spacing'];
  24517. }
  24518. } else {
  24519. $font_family = $this->getFontFamilyName($svgstyle['font-family']);
  24520. $font_size = $svgstyle['font-size'];
  24521. $font_style = $svgstyle['font-style'];
  24522. $font_weight = $svgstyle['font-weight'];
  24523. $font_stretch = $svgstyle['font-stretch'];
  24524. $font_spacing = $svgstyle['letter-spacing'];
  24525. }
  24526. $font_size = $this->getHTMLUnitToUnits($font_size, $prevsvgstyle['font-size'], $this->svgunit, false) * $this->k;
  24527. $font_stretch = $this->getCSSFontStretching($font_stretch, $svgstyle['font-stretch']);
  24528. $font_spacing = $this->getCSSFontSpacing($font_spacing, $svgstyle['letter-spacing']);
  24529. switch ($font_style) {
  24530. case 'italic': {
  24531. $font_style = 'I';
  24532. break;
  24533. }
  24534. case 'oblique': {
  24535. $font_style = 'I';
  24536. break;
  24537. }
  24538. default:
  24539. case 'normal': {
  24540. $font_style = '';
  24541. break;
  24542. }
  24543. }
  24544. switch ($font_weight) {
  24545. case 'bold':
  24546. case 'bolder': {
  24547. $font_style .= 'B';
  24548. break;
  24549. }
  24550. }
  24551. switch ($svgstyle['text-decoration']) {
  24552. case 'underline': {
  24553. $font_style .= 'U';
  24554. break;
  24555. }
  24556. case 'overline': {
  24557. $font_style .= 'O';
  24558. break;
  24559. }
  24560. case 'line-through': {
  24561. $font_style .= 'D';
  24562. break;
  24563. }
  24564. default:
  24565. case 'none': {
  24566. break;
  24567. }
  24568. }
  24569. $this->SetFont($font_family, $font_style, $font_size);
  24570. $this->setFontStretching($font_stretch);
  24571. $this->setFontSpacing($font_spacing);
  24572. return $objstyle;
  24573. }
  24574. /**
  24575. * Draws an SVG path
  24576. * @param $d (string) attribute d of the path SVG element
  24577. * @param $style (string) Style of rendering. Possible values are:
  24578. * <ul>
  24579. * <li>D or empty string: Draw (default).</li>
  24580. * <li>F: Fill.</li>
  24581. * <li>F*: Fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  24582. * <li>DF or FD: Draw and fill.</li>
  24583. * <li>DF* or FD*: Draw and fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  24584. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  24585. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  24586. * </ul>
  24587. * @return array of container box measures (x, y, w, h)
  24588. * @author Nicola Asuni
  24589. * @since 5.0.000 (2010-05-02)
  24590. * @protected
  24591. */
  24592. protected function SVGPath($d, $style='') {
  24593. // set fill/stroke style
  24594. $op = $this->getPathPaintOperator($style, '');
  24595. if (empty($op)) {
  24596. return;
  24597. }
  24598. $paths = array();
  24599. $d = preg_replace('/([0-9ACHLMQSTVZ])([\-\+])/si', '\\1 \\2', $d);
  24600. preg_match_all('/([ACHLMQSTVZ])[\s]*([^ACHLMQSTVZ\"]*)/si', $d, $paths, PREG_SET_ORDER);
  24601. $x = 0;
  24602. $y = 0;
  24603. $x1 = 0;
  24604. $y1 = 0;
  24605. $x2 = 0;
  24606. $y2 = 0;
  24607. $xmin = 2147483647;
  24608. $xmax = 0;
  24609. $ymin = 2147483647;
  24610. $ymax = 0;
  24611. $relcoord = false;
  24612. // draw curve pieces
  24613. foreach ($paths as $key => $val) {
  24614. // get curve type
  24615. $cmd = trim($val[1]);
  24616. if (strtolower($cmd) == $cmd) {
  24617. // use relative coordinated instead of absolute
  24618. $relcoord = true;
  24619. $xoffset = $x;
  24620. $yoffset = $y;
  24621. } else {
  24622. $relcoord = false;
  24623. $xoffset = 0;
  24624. $yoffset = 0;
  24625. }
  24626. $params = array();
  24627. if (isset($val[2])) {
  24628. // get curve parameters
  24629. $rawparams = preg_split('/([\,\s]+)/si', trim($val[2]));
  24630. $params = array();
  24631. foreach ($rawparams as $ck => $cp) {
  24632. $params[$ck] = $this->getHTMLUnitToUnits($cp, 0, $this->svgunit, false);
  24633. }
  24634. }
  24635. switch (strtoupper($cmd)) {
  24636. case 'M': { // moveto
  24637. foreach ($params as $ck => $cp) {
  24638. if (($ck % 2) == 0) {
  24639. $x = $cp + $xoffset;
  24640. } else {
  24641. $y = $cp + $yoffset;
  24642. if ($ck == 1) {
  24643. $this->_outPoint($x, $y);
  24644. } else {
  24645. $this->_outLine($x, $y);
  24646. }
  24647. $xmin = min($xmin, $x);
  24648. $ymin = min($ymin, $y);
  24649. $xmax = max($xmax, $x);
  24650. $ymax = max($ymax, $y);
  24651. if ($relcoord) {
  24652. $xoffset = $x;
  24653. $yoffset = $y;
  24654. }
  24655. }
  24656. }
  24657. break;
  24658. }
  24659. case 'L': { // lineto
  24660. foreach ($params as $ck => $cp) {
  24661. if (($ck % 2) == 0) {
  24662. $x = $cp + $xoffset;
  24663. } else {
  24664. $y = $cp + $yoffset;
  24665. $this->_outLine($x, $y);
  24666. $xmin = min($xmin, $x);
  24667. $ymin = min($ymin, $y);
  24668. $xmax = max($xmax, $x);
  24669. $ymax = max($ymax, $y);
  24670. if ($relcoord) {
  24671. $xoffset = $x;
  24672. $yoffset = $y;
  24673. }
  24674. }
  24675. }
  24676. break;
  24677. }
  24678. case 'H': { // horizontal lineto
  24679. foreach ($params as $ck => $cp) {
  24680. $x = $cp + $xoffset;
  24681. $this->_outLine($x, $y);
  24682. $xmin = min($xmin, $x);
  24683. $xmax = max($xmax, $x);
  24684. if ($relcoord) {
  24685. $xoffset = $x;
  24686. }
  24687. }
  24688. break;
  24689. }
  24690. case 'V': { // vertical lineto
  24691. foreach ($params as $ck => $cp) {
  24692. $y = $cp + $yoffset;
  24693. $this->_outLine($x, $y);
  24694. $ymin = min($ymin, $y);
  24695. $ymax = max($ymax, $y);
  24696. if ($relcoord) {
  24697. $yoffset = $y;
  24698. }
  24699. }
  24700. break;
  24701. }
  24702. case 'C': { // curveto
  24703. foreach ($params as $ck => $cp) {
  24704. $params[$ck] = $cp;
  24705. if ((($ck + 1) % 6) == 0) {
  24706. $x1 = $params[($ck - 5)] + $xoffset;
  24707. $y1 = $params[($ck - 4)] + $yoffset;
  24708. $x2 = $params[($ck - 3)] + $xoffset;
  24709. $y2 = $params[($ck - 2)] + $yoffset;
  24710. $x = $params[($ck - 1)] + $xoffset;
  24711. $y = $params[($ck)] + $yoffset;
  24712. $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
  24713. $xmin = min($xmin, $x, $x1, $x2);
  24714. $ymin = min($ymin, $y, $y1, $y2);
  24715. $xmax = max($xmax, $x, $x1, $x2);
  24716. $ymax = max($ymax, $y, $y1, $y2);
  24717. if ($relcoord) {
  24718. $xoffset = $x;
  24719. $yoffset = $y;
  24720. }
  24721. }
  24722. }
  24723. break;
  24724. }
  24725. case 'S': { // shorthand/smooth curveto
  24726. foreach ($params as $ck => $cp) {
  24727. $params[$ck] = $cp;
  24728. if ((($ck + 1) % 4) == 0) {
  24729. if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'C') OR (strtoupper($paths[($key - 1)][1]) == 'S'))) {
  24730. $x1 = (2 * $x) - $x2;
  24731. $y1 = (2 * $y) - $y2;
  24732. } else {
  24733. $x1 = $x;
  24734. $y1 = $y;
  24735. }
  24736. $x2 = $params[($ck - 3)] + $xoffset;
  24737. $y2 = $params[($ck - 2)] + $yoffset;
  24738. $x = $params[($ck - 1)] + $xoffset;
  24739. $y = $params[($ck)] + $yoffset;
  24740. $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
  24741. $xmin = min($xmin, $x, $x1, $x2);
  24742. $ymin = min($ymin, $y, $y1, $y2);
  24743. $xmax = max($xmax, $x, $x1, $x2);
  24744. $ymax = max($ymax, $y, $y1, $y2);
  24745. if ($relcoord) {
  24746. $xoffset = $x;
  24747. $yoffset = $y;
  24748. }
  24749. }
  24750. }
  24751. break;
  24752. }
  24753. case 'Q': { // quadratic Bézier curveto
  24754. foreach ($params as $ck => $cp) {
  24755. $params[$ck] = $cp;
  24756. if ((($ck + 1) % 4) == 0) {
  24757. // convert quadratic points to cubic points
  24758. $x1 = $params[($ck - 3)] + $xoffset;
  24759. $y1 = $params[($ck - 2)] + $yoffset;
  24760. $xa = ($x + (2 * $x1)) / 3;
  24761. $ya = ($y + (2 * $y1)) / 3;
  24762. $x = $params[($ck - 1)] + $xoffset;
  24763. $y = $params[($ck)] + $yoffset;
  24764. $xb = ($x + (2 * $x1)) / 3;
  24765. $yb = ($y + (2 * $y1)) / 3;
  24766. $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
  24767. $xmin = min($xmin, $x, $xa, $xb);
  24768. $ymin = min($ymin, $y, $ya, $yb);
  24769. $xmax = max($xmax, $x, $xa, $xb);
  24770. $ymax = max($ymax, $y, $ya, $yb);
  24771. if ($relcoord) {
  24772. $xoffset = $x;
  24773. $yoffset = $y;
  24774. }
  24775. }
  24776. }
  24777. break;
  24778. }
  24779. case 'T': { // shorthand/smooth quadratic Bézier curveto
  24780. foreach ($params as $ck => $cp) {
  24781. $params[$ck] = $cp;
  24782. if (($ck % 2) != 0) {
  24783. if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'Q') OR (strtoupper($paths[($key - 1)][1]) == 'T'))) {
  24784. $x1 = (2 * $x) - $x1;
  24785. $y1 = (2 * $y) - $y1;
  24786. } else {
  24787. $x1 = $x;
  24788. $y1 = $y;
  24789. }
  24790. // convert quadratic points to cubic points
  24791. $xa = ($x + (2 * $x1)) / 3;
  24792. $ya = ($y + (2 * $y1)) / 3;
  24793. $x = $params[($ck - 1)] + $xoffset;
  24794. $y = $params[($ck)] + $yoffset;
  24795. $xb = ($x + (2 * $x1)) / 3;
  24796. $yb = ($y + (2 * $y1)) / 3;
  24797. $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
  24798. $xmin = min($xmin, $x, $xa, $xb);
  24799. $ymin = min($ymin, $y, $ya, $yb);
  24800. $xmax = max($xmax, $x, $xa, $xb);
  24801. $ymax = max($ymax, $y, $ya, $yb);
  24802. if ($relcoord) {
  24803. $xoffset = $x;
  24804. $yoffset = $y;
  24805. }
  24806. }
  24807. }
  24808. break;
  24809. }
  24810. case 'A': { // elliptical arc
  24811. foreach ($params as $ck => $cp) {
  24812. $params[$ck] = $cp;
  24813. if ((($ck + 1) % 7) == 0) {
  24814. $x0 = $x;
  24815. $y0 = $y;
  24816. $rx = abs($params[($ck - 6)]);
  24817. $ry = abs($params[($ck - 5)]);
  24818. $ang = -$rawparams[($ck - 4)];
  24819. $angle = deg2rad($ang);
  24820. $fa = $rawparams[($ck - 3)]; // large-arc-flag
  24821. $fs = $rawparams[($ck - 2)]; // sweep-flag
  24822. $x = $params[($ck - 1)] + $xoffset;
  24823. $y = $params[$ck] + $yoffset;
  24824. $minlen = (0.01 / $this->k); // 3 point
  24825. if ((abs($x0 - $x) < $minlen) AND (abs($x0 - $x) < $minlen)) {
  24826. // endpoints are almost identical
  24827. break;
  24828. }
  24829. $cos_ang = cos($angle);
  24830. $sin_ang = sin($angle);
  24831. $a = (($x0 - $x) / 2);
  24832. $b = (($y0 - $y) / 2);
  24833. $xa = ($a * $cos_ang) - ($b * $sin_ang);
  24834. $ya = ($a * $sin_ang) + ($b * $cos_ang);
  24835. $rx2 = $rx * $rx;
  24836. $ry2 = $ry * $ry;
  24837. $xa2 = $xa * $xa;
  24838. $ya2 = $ya * $ya;
  24839. $delta = ($xa2 / $rx2) + ($ya2 / $ry2);
  24840. if ($delta > 1) {
  24841. $rx *= sqrt($delta);
  24842. $ry *= sqrt($delta);
  24843. $rx2 = $rx * $rx;
  24844. $ry2 = $ry * $ry;
  24845. }
  24846. $numerator = (($rx2 * $ry2) - ($rx2 * $ya2) - ($ry2 * $xa2));
  24847. if ($numerator < 0) {
  24848. $root = 0;
  24849. } else {
  24850. $root = sqrt($numerator / (($rx2 * $ya2) + ($ry2 * $xa2)));
  24851. }
  24852. if ($fa == $fs){
  24853. $root *= -1;
  24854. }
  24855. $cax = $root * (($rx * $ya) / $ry);
  24856. $cay = -$root * (($ry * $xa) / $rx);
  24857. // coordinates of ellipse center
  24858. $cx = ($cax * $cos_ang) - ($cay * $sin_ang) + (($x0 + $x) / 2);
  24859. $cy = ($cax * $sin_ang) + ($cay * $cos_ang) + (($y0 + $y) / 2);
  24860. // get angles
  24861. $angs = $this->getVectorsAngle(1, 0, (($xa - $cax) / $rx), (($cay - $ya) / $ry));
  24862. $dang = $this->getVectorsAngle((($xa - $cax) / $rx), (($ya - $cay) / $ry), ((-$xa - $cax) / $rx), ((-$ya - $cay) / $ry));
  24863. if (($fs == 0) AND ($dang > 0)) {
  24864. $dang -= (2 * M_PI);
  24865. } elseif (($fs == 1) AND ($dang < 0)) {
  24866. $dang += (2 * M_PI);
  24867. }
  24868. $angf = $angs - $dang;
  24869. if ((($fs == 0) AND ($angs > $angf)) OR (($fs == 1) AND ($angs < $angf))) {
  24870. // reverse angles
  24871. $tmp = $angs;
  24872. $angs = $angf;
  24873. $angf = $tmp;
  24874. }
  24875. $angs = round(rad2deg($angs), 6);
  24876. $angf = round(rad2deg($angf), 6);
  24877. // covent angles to positive values
  24878. if (($angs < 0) AND ($angf < 0)) {
  24879. $angs += 360;
  24880. $angf += 360;
  24881. }
  24882. $pie = false;
  24883. if (($key == 0) AND (isset($paths[($key + 1)][1])) AND (trim($paths[($key + 1)][1]) == 'z')) {
  24884. $pie = true;
  24885. }
  24886. list($axmin, $aymin, $axmax, $aymax) = $this->_outellipticalarc($cx, $cy, $rx, $ry, $ang, $angs, $angf, $pie, 2, false, ($fs == 0), true);
  24887. $xmin = min($xmin, $x, $axmin);
  24888. $ymin = min($ymin, $y, $aymin);
  24889. $xmax = max($xmax, $x, $axmax);
  24890. $ymax = max($ymax, $y, $aymax);
  24891. if ($relcoord) {
  24892. $xoffset = $x;
  24893. $yoffset = $y;
  24894. }
  24895. }
  24896. }
  24897. break;
  24898. }
  24899. case 'Z': {
  24900. $this->_out('h');
  24901. break;
  24902. }
  24903. }
  24904. } // end foreach
  24905. if (!empty($op)) {
  24906. $this->_out($op);
  24907. }
  24908. return array($xmin, $ymin, ($xmax - $xmin), ($ymax - $ymin));
  24909. }
  24910. /**
  24911. * Returns the angle in radiants between two vectors
  24912. * @param $x1 (int) X coordinate of first vector point
  24913. * @param $y1 (int) Y coordinate of first vector point
  24914. * @param $x2 (int) X coordinate of second vector point
  24915. * @param $y2 (int) Y coordinate of second vector point
  24916. * @author Nicola Asuni
  24917. * @since 5.0.000 (2010-05-04)
  24918. * @protected
  24919. */
  24920. protected function getVectorsAngle($x1, $y1, $x2, $y2) {
  24921. $dprod = ($x1 * $x2) + ($y1 * $y2);
  24922. $dist1 = sqrt(($x1 * $x1) + ($y1 * $y1));
  24923. $dist2 = sqrt(($x2 * $x2) + ($y2 * $y2));
  24924. $angle = acos($dprod / ($dist1 * $dist2));
  24925. if (is_nan($angle)) {
  24926. $angle = M_PI;
  24927. }
  24928. if ((($x1 * $y2) - ($x2 * $y1)) < 0) {
  24929. $angle *= -1;
  24930. }
  24931. return $angle;
  24932. }
  24933. /**
  24934. * Sets the opening SVG element handler function for the XML parser. (*** TO BE COMPLETED ***)
  24935. * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
  24936. * @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.
  24937. * @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.
  24938. * @param $ctm (array) tranformation matrix for clipping mode (starting transformation matrix).
  24939. * @author Nicola Asuni
  24940. * @since 5.0.000 (2010-05-02)
  24941. * @protected
  24942. */
  24943. protected function startSVGElementHandler($parser, $name, $attribs, $ctm=array()) {
  24944. // check if we are in clip mode
  24945. if ($this->svgclipmode) {
  24946. $this->svgclippaths[$this->svgclipid][] = array('name' => $name, 'attribs' => $attribs, 'tm' => $this->svgcliptm[$this->svgclipid]);
  24947. return;
  24948. }
  24949. if ($this->svgdefsmode AND !in_array($name, array('clipPath', 'linearGradient', 'radialGradient', 'stop'))) {
  24950. if (!isset($attribs['id'])) {
  24951. $attribs['id'] = 'DF_'.(count($this->svgdefs) + 1);
  24952. }
  24953. $this->svgdefs[$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
  24954. return;
  24955. }
  24956. $clipping = false;
  24957. if ($parser == 'clip-path') {
  24958. // set clipping mode
  24959. $clipping = true;
  24960. }
  24961. // get styling properties
  24962. $prev_svgstyle = $this->svgstyles[(count($this->svgstyles) - 1)]; // previous style
  24963. $svgstyle = $this->svgstyles[0]; // set default style
  24964. if (isset($attribs['style']) AND !$this->empty_string($attribs['style'])) {
  24965. // fix style for regular expression
  24966. $attribs['style'] = ';'.$attribs['style'];
  24967. }
  24968. foreach ($prev_svgstyle as $key => $val) {
  24969. if (in_array($key, $this->svginheritprop)) {
  24970. // inherit previous value
  24971. $svgstyle[$key] = $val;
  24972. }
  24973. if (isset($attribs[$key]) AND !$this->empty_string($attribs[$key])) {
  24974. // specific attribute settings
  24975. if ($attribs[$key] == 'inherit') {
  24976. $svgstyle[$key] = $val;
  24977. } else {
  24978. $svgstyle[$key] = $attribs[$key];
  24979. }
  24980. } elseif (isset($attribs['style']) AND !$this->empty_string($attribs['style'])) {
  24981. // CSS style syntax
  24982. $attrval = array();
  24983. if (preg_match('/[;\"\s]{1}'.$key.'[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval) AND isset($attrval[1])) {
  24984. if ($attrval[1] == 'inherit') {
  24985. $svgstyle[$key] = $val;
  24986. } else {
  24987. $svgstyle[$key] = $attrval[1];
  24988. }
  24989. }
  24990. }
  24991. }
  24992. // transformation matrix
  24993. if (!empty($ctm)) {
  24994. $tm = $ctm;
  24995. } else {
  24996. $tm = $this->svgstyles[(count($this->svgstyles) - 1)]['transfmatrix'];
  24997. }
  24998. if (isset($attribs['transform']) AND !empty($attribs['transform'])) {
  24999. $tm = $this->getTransformationMatrixProduct($tm, $this->getSVGTransformMatrix($attribs['transform']));
  25000. }
  25001. $svgstyle['transfmatrix'] = $tm;
  25002. $invisible = false;
  25003. if (($svgstyle['visibility'] == 'hidden') OR ($svgstyle['visibility'] == 'collapse') OR ($svgstyle['display'] == 'none')) {
  25004. // the current graphics element is invisible (nothing is painted)
  25005. $invisible = true;
  25006. }
  25007. // process tag
  25008. switch($name) {
  25009. case 'defs': {
  25010. $this->svgdefsmode = true;
  25011. break;
  25012. }
  25013. // clipPath
  25014. case 'clipPath': {
  25015. if ($invisible) {
  25016. break;
  25017. }
  25018. $this->svgclipmode = true;
  25019. if (!isset($attribs['id'])) {
  25020. $attribs['id'] = 'CP_'.(count($this->svgcliptm) + 1);
  25021. }
  25022. $this->svgclipid = $attribs['id'];
  25023. $this->svgclippaths[$this->svgclipid] = array();
  25024. $this->svgcliptm[$this->svgclipid] = $tm;
  25025. break;
  25026. }
  25027. case 'svg': {
  25028. // start of SVG object
  25029. break;
  25030. }
  25031. case 'g': {
  25032. // group together related graphics elements
  25033. array_push($this->svgstyles, $svgstyle);
  25034. $this->StartTransform();
  25035. $this->setSVGStyles($svgstyle, $prev_svgstyle);
  25036. break;
  25037. }
  25038. case 'linearGradient': {
  25039. if (!isset($attribs['id'])) {
  25040. $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
  25041. }
  25042. $this->svggradientid = $attribs['id'];
  25043. $this->svggradients[$this->svggradientid] = array();
  25044. $this->svggradients[$this->svggradientid]['type'] = 2;
  25045. $this->svggradients[$this->svggradientid]['stops'] = array();
  25046. if (isset($attribs['gradientUnits'])) {
  25047. $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  25048. } else {
  25049. $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  25050. }
  25051. //$attribs['spreadMethod']
  25052. $x1 = (isset($attribs['x1'])?$attribs['x1']:'0%');
  25053. $y1 = (isset($attribs['y1'])?$attribs['y1']:'0%');
  25054. $x2 = (isset($attribs['x2'])?$attribs['x2']:'100%');
  25055. $y2 = (isset($attribs['y2'])?$attribs['y2']:'0%');
  25056. if (substr($x1, -1) != '%') {
  25057. $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  25058. } else {
  25059. $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  25060. }
  25061. if (isset($attribs['gradientTransform'])) {
  25062. $this->svggradients[$this->svggradientid]['gradientTransform'] = $this->getSVGTransformMatrix($attribs['gradientTransform']);
  25063. }
  25064. $this->svggradients[$this->svggradientid]['coords'] = array($x1, $y1, $x2, $y2);
  25065. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  25066. // gradient is defined on another place
  25067. $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  25068. }
  25069. break;
  25070. }
  25071. case 'radialGradient': {
  25072. if (!isset($attribs['id'])) {
  25073. $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
  25074. }
  25075. $this->svggradientid = $attribs['id'];
  25076. $this->svggradients[$this->svggradientid] = array();
  25077. $this->svggradients[$this->svggradientid]['type'] = 3;
  25078. $this->svggradients[$this->svggradientid]['stops'] = array();
  25079. if (isset($attribs['gradientUnits'])) {
  25080. $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  25081. } else {
  25082. $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  25083. }
  25084. //$attribs['spreadMethod']
  25085. $cx = (isset($attribs['cx'])?$attribs['cx']:0.5);
  25086. $cy = (isset($attribs['cy'])?$attribs['cy']:0.5);
  25087. $fx = (isset($attribs['fx'])?$attribs['fx']:$cx);
  25088. $fy = (isset($attribs['fy'])?$attribs['fy']:$cy);
  25089. $r = (isset($attribs['r'])?$attribs['r']:0.5);
  25090. if (isset($attribs['cx']) AND (substr($attribs['cx'], -1) != '%')) {
  25091. $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  25092. } else {
  25093. $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  25094. }
  25095. if (isset($attribs['gradientTransform'])) {
  25096. $this->svggradients[$this->svggradientid]['gradientTransform'] = $this->getSVGTransformMatrix($attribs['gradientTransform']);
  25097. }
  25098. $this->svggradients[$this->svggradientid]['coords'] = array($cx, $cy, $fx, $fy, $r);
  25099. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  25100. // gradient is defined on another place
  25101. $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  25102. }
  25103. break;
  25104. }
  25105. case 'stop': {
  25106. // gradient stops
  25107. if (substr($attribs['offset'], -1) == '%') {
  25108. $offset = floatval(substr($attribs['offset'], -1)) / 100;
  25109. } else {
  25110. $offset = floatval($attribs['offset']);
  25111. if ($offset > 1) {
  25112. $offset /= 100;
  25113. }
  25114. }
  25115. $stop_color = isset($svgstyle['stop-color'])?$this->convertHTMLColorToDec($svgstyle['stop-color']):'black';
  25116. $opacity = isset($svgstyle['stop-opacity'])?$svgstyle['stop-opacity']:1;
  25117. $this->svggradients[$this->svggradientid]['stops'][] = array('offset' => $offset, 'color' => $stop_color, 'opacity' => $opacity);
  25118. break;
  25119. }
  25120. // paths
  25121. case 'path': {
  25122. if ($invisible) {
  25123. break;
  25124. }
  25125. if (isset($attribs['d'])) {
  25126. $d = trim($attribs['d']);
  25127. if (!empty($d)) {
  25128. if ($clipping) {
  25129. $this->SVGTransform($tm);
  25130. $this->SVGPath($d, 'CNZ');
  25131. } else {
  25132. $this->StartTransform();
  25133. $this->SVGTransform($tm);
  25134. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, 0, 0, 1, 1, 'SVGPath', array($d, 'CNZ'));
  25135. if (!empty($obstyle)) {
  25136. $this->SVGPath($d, $obstyle);
  25137. }
  25138. $this->StopTransform();
  25139. }
  25140. }
  25141. }
  25142. break;
  25143. }
  25144. // shapes
  25145. case 'rect': {
  25146. if ($invisible) {
  25147. break;
  25148. }
  25149. $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
  25150. $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
  25151. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
  25152. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
  25153. $rx = (isset($attribs['rx'])?$this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false):0);
  25154. $ry = (isset($attribs['ry'])?$this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false):$rx);
  25155. if ($clipping) {
  25156. $this->SVGTransform($tm);
  25157. $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ', array(), array());
  25158. } else {
  25159. $this->StartTransform();
  25160. $this->SVGTransform($tm);
  25161. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'RoundedRectXY', array($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ'));
  25162. if (!empty($obstyle)) {
  25163. $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', $obstyle, array(), array());
  25164. }
  25165. $this->StopTransform();
  25166. }
  25167. break;
  25168. }
  25169. case 'circle': {
  25170. if ($invisible) {
  25171. break;
  25172. }
  25173. $cx = (isset($attribs['cx'])?$this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false):0);
  25174. $cy = (isset($attribs['cy'])?$this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false):0);
  25175. $r = (isset($attribs['r'])?$this->getHTMLUnitToUnits($attribs['r'], 0, $this->svgunit, false):0);
  25176. $x = $cx - $r;
  25177. $y = $cy - $r;
  25178. $w = 2 * $r;
  25179. $h = $w;
  25180. if ($clipping) {
  25181. $this->SVGTransform($tm);
  25182. $this->Circle($cx, $cy, $r, 0, 360, 'CNZ', array(), array(), 8);
  25183. } else {
  25184. $this->StartTransform();
  25185. $this->SVGTransform($tm);
  25186. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Circle', array($cx, $cy, $r, 0, 360, 'CNZ'));
  25187. if (!empty($obstyle)) {
  25188. $this->Circle($cx, $cy, $r, 0, 360, $obstyle, array(), array(), 8);
  25189. }
  25190. $this->StopTransform();
  25191. }
  25192. break;
  25193. }
  25194. case 'ellipse': {
  25195. if ($invisible) {
  25196. break;
  25197. }
  25198. $cx = (isset($attribs['cx'])?$this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false):0);
  25199. $cy = (isset($attribs['cy'])?$this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false):0);
  25200. $rx = (isset($attribs['rx'])?$this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false):0);
  25201. $ry = (isset($attribs['ry'])?$this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false):0);
  25202. $x = $cx - $rx;
  25203. $y = $cy - $ry;
  25204. $w = 2 * $rx;
  25205. $h = 2 * $ry;
  25206. if ($clipping) {
  25207. $this->SVGTransform($tm);
  25208. $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ', array(), array(), 8);
  25209. } else {
  25210. $this->StartTransform();
  25211. $this->SVGTransform($tm);
  25212. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Ellipse', array($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ'));
  25213. if (!empty($obstyle)) {
  25214. $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, $obstyle, array(), array(), 8);
  25215. }
  25216. $this->StopTransform();
  25217. }
  25218. break;
  25219. }
  25220. case 'line': {
  25221. if ($invisible) {
  25222. break;
  25223. }
  25224. $x1 = (isset($attribs['x1'])?$this->getHTMLUnitToUnits($attribs['x1'], 0, $this->svgunit, false):0);
  25225. $y1 = (isset($attribs['y1'])?$this->getHTMLUnitToUnits($attribs['y1'], 0, $this->svgunit, false):0);
  25226. $x2 = (isset($attribs['x2'])?$this->getHTMLUnitToUnits($attribs['x2'], 0, $this->svgunit, false):0);
  25227. $y2 = (isset($attribs['y2'])?$this->getHTMLUnitToUnits($attribs['y2'], 0, $this->svgunit, false):0);
  25228. $x = $x1;
  25229. $y = $y1;
  25230. $w = abs($x2 - $x1);
  25231. $h = abs($y2 - $y1);
  25232. if (!$clipping) {
  25233. $this->StartTransform();
  25234. $this->SVGTransform($tm);
  25235. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Line', array($x1, $y1, $x2, $y2));
  25236. $this->Line($x1, $y1, $x2, $y2);
  25237. $this->StopTransform();
  25238. }
  25239. break;
  25240. }
  25241. case 'polyline':
  25242. case 'polygon': {
  25243. if ($invisible) {
  25244. break;
  25245. }
  25246. $points = (isset($attribs['points'])?$attribs['points']:'0 0');
  25247. $points = trim($points);
  25248. // note that point may use a complex syntax not covered here
  25249. $points = preg_split('/[\,\s]+/si', $points);
  25250. if (count($points) < 4) {
  25251. break;
  25252. }
  25253. $p = array();
  25254. $xmin = 2147483647;
  25255. $xmax = 0;
  25256. $ymin = 2147483647;
  25257. $ymax = 0;
  25258. foreach ($points as $key => $val) {
  25259. $p[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
  25260. if (($key % 2) == 0) {
  25261. // X coordinate
  25262. $xmin = min($xmin, $p[$key]);
  25263. $xmax = max($xmax, $p[$key]);
  25264. } else {
  25265. // Y coordinate
  25266. $ymin = min($ymin, $p[$key]);
  25267. $ymax = max($ymax, $p[$key]);
  25268. }
  25269. }
  25270. $x = $xmin;
  25271. $y = $ymin;
  25272. $w = ($xmax - $xmin);
  25273. $h = ($ymax - $ymin);
  25274. if ($name == 'polyline') {
  25275. $this->StartTransform();
  25276. $this->SVGTransform($tm);
  25277. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'PolyLine', array($p, 'CNZ'));
  25278. $this->PolyLine($p, 'D', array(), array());
  25279. $this->StopTransform();
  25280. } else { // polygon
  25281. if ($clipping) {
  25282. $this->SVGTransform($tm);
  25283. $this->Polygon($p, 'CNZ', array(), array(), true);
  25284. } else {
  25285. $this->StartTransform();
  25286. $this->SVGTransform($tm);
  25287. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Polygon', array($p, 'CNZ'));
  25288. if (!empty($obstyle)) {
  25289. $this->Polygon($p, $obstyle, array(), array(), true);
  25290. }
  25291. $this->StopTransform();
  25292. }
  25293. }
  25294. break;
  25295. }
  25296. // image
  25297. case 'image': {
  25298. if ($invisible) {
  25299. break;
  25300. }
  25301. if (!isset($attribs['xlink:href']) OR empty($attribs['xlink:href'])) {
  25302. break;
  25303. }
  25304. $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
  25305. $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
  25306. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
  25307. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
  25308. $img = $attribs['xlink:href'];
  25309. if (!$clipping) {
  25310. $this->StartTransform();
  25311. $this->SVGTransform($tm);
  25312. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h);
  25313. // fix image path
  25314. if (!$this->empty_string($this->svgdir) AND (($img{0} == '.') OR (basename($img) == $img))) {
  25315. // replace relative path with full server path
  25316. $img = $this->svgdir.'/'.$img;
  25317. }
  25318. if (($img{0} == '/') AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
  25319. $findroot = strpos($img, $_SERVER['DOCUMENT_ROOT']);
  25320. if (($findroot === false) OR ($findroot > 1)) {
  25321. // replace relative path with full server path
  25322. $img = $_SERVER['DOCUMENT_ROOT'].$img;
  25323. }
  25324. }
  25325. $img = urldecode($img);
  25326. $testscrtype = @parse_url($img);
  25327. if (!isset($testscrtype['query']) OR empty($testscrtype['query'])) {
  25328. // convert URL to server path
  25329. $img = str_replace(K_PATH_URL, K_PATH_MAIN, $img);
  25330. }
  25331. $this->Image($img, $x, $y, $w, $h);
  25332. $this->StopTransform();
  25333. }
  25334. break;
  25335. }
  25336. // text
  25337. case 'text':
  25338. case 'tspan': {
  25339. $this->svgtextmode['invisible'] = $invisible;
  25340. if ($invisible) {
  25341. break;
  25342. }
  25343. array_push($this->svgstyles, $svgstyle);
  25344. // only basic support - advanced features must be implemented
  25345. $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):$this->x);
  25346. $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):$this->y);
  25347. $svgstyle['text-color'] = $svgstyle['fill'];
  25348. $this->svgtext = '';
  25349. if (isset($svgstyle['text-anchor'])) {
  25350. $this->svgtextmode['text-anchor'] = $svgstyle['text-anchor'];
  25351. } else {
  25352. $this->svgtextmode['text-anchor'] = 'start';
  25353. }
  25354. if (isset($svgstyle['direction'])) {
  25355. if ($svgstyle['direction'] == 'rtl') {
  25356. $this->svgtextmode['rtl'] = true;
  25357. } else {
  25358. $this->svgtextmode['rtl'] = false;
  25359. }
  25360. } else {
  25361. $this->svgtextmode['rtl'] = false;
  25362. }
  25363. if (isset($svgstyle['stroke']) AND ($svgstyle['stroke'] != 'none') AND isset($svgstyle['stroke-width']) AND ($svgstyle['stroke-width'] > 0)) {
  25364. $this->svgtextmode['stroke'] = $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false);
  25365. } else {
  25366. $this->svgtextmode['stroke'] = false;
  25367. }
  25368. $this->StartTransform();
  25369. $this->SVGTransform($tm);
  25370. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, 1, 1);
  25371. $this->x = $x;
  25372. $this->y = $y;
  25373. break;
  25374. }
  25375. // use
  25376. case 'use': {
  25377. if (isset($attribs['xlink:href'])) {
  25378. $use = $this->svgdefs[substr($attribs['xlink:href'], 1)];
  25379. if (isset($attribs['xlink:href'])) {
  25380. unset($attribs['xlink:href']);
  25381. }
  25382. if (isset($attribs['id'])) {
  25383. unset($attribs['id']);
  25384. }
  25385. $attribs = array_merge($use['attribs'], $attribs);
  25386. $this->startSVGElementHandler($parser, $use['name'], $use['attribs']);
  25387. }
  25388. break;
  25389. }
  25390. default: {
  25391. break;
  25392. }
  25393. } // end of switch
  25394. }
  25395. /**
  25396. * Sets the closing SVG element handler function for the XML parser.
  25397. * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
  25398. * @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.
  25399. * @author Nicola Asuni
  25400. * @since 5.0.000 (2010-05-02)
  25401. * @protected
  25402. */
  25403. protected function endSVGElementHandler($parser, $name) {
  25404. switch($name) {
  25405. case 'defs': {
  25406. $this->svgdefsmode = false;
  25407. break;
  25408. }
  25409. // clipPath
  25410. case 'clipPath': {
  25411. $this->svgclipmode = false;
  25412. break;
  25413. }
  25414. case 'g': {
  25415. // ungroup: remove last style from array
  25416. array_pop($this->svgstyles);
  25417. $this->StopTransform();
  25418. break;
  25419. }
  25420. case 'text':
  25421. case 'tspan': {
  25422. if ($this->svgtextmode['invisible']) {
  25423. // This implementation must be fixed to following the rule:
  25424. // 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.
  25425. break;
  25426. }
  25427. // print text
  25428. $text = $this->stringTrim($this->svgtext);
  25429. if ($this->svgtextmode['text-anchor'] != 'start') {
  25430. $textlen = $this->GetStringWidth($text);
  25431. // check if string is RTL text
  25432. if ($this->svgtextmode['text-anchor'] == 'end') {
  25433. if ($this->svgtextmode['rtl']) {
  25434. $this->x += $textlen;
  25435. } else {
  25436. $this->x -= $textlen;
  25437. }
  25438. } elseif ($this->svgtextmode['text-anchor'] == 'middle') {
  25439. if ($this->svgtextmode['rtl']) {
  25440. $this->x += ($textlen / 2);
  25441. } else {
  25442. $this->x -= ($textlen / 2);
  25443. }
  25444. }
  25445. }
  25446. $textrendermode = $this->textrendermode;
  25447. $textstrokewidth = $this->textstrokewidth;
  25448. $this->setTextRenderingMode($this->svgtextmode['stroke'], true, false);
  25449. $this->Cell(0, 0, $text, 0, 0, '', false, '', 0, false, 'L', 'T');
  25450. // restore previous rendering mode
  25451. $this->textrendermode = $textrendermode;
  25452. $this->textstrokewidth = $textstrokewidth;
  25453. $this->svgtext = '';
  25454. $this->StopTransform();
  25455. array_pop($this->svgstyles);
  25456. break;
  25457. }
  25458. default: {
  25459. break;
  25460. }
  25461. }
  25462. }
  25463. /**
  25464. * Sets the character data handler function for the XML parser.
  25465. * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
  25466. * @param $data (string) The second parameter, data, contains the character data as a string.
  25467. * @author Nicola Asuni
  25468. * @since 5.0.000 (2010-05-02)
  25469. * @protected
  25470. */
  25471. protected function segSVGContentHandler($parser, $data) {
  25472. $this->svgtext .= $data;
  25473. }
  25474. // --- END SVG METHODS -----------------------------
  25475. } // END OF TCPDF CLASS
  25476. //============================================================+
  25477. // END OF FILE
  25478. //============================================================+