tcpdf.php 1.0 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925
  1. <?php
  2. //============================================================+
  3. // File name : tcpdf.php
  4. // Version : 5.9.207
  5. // Begin : 2002-08-03
  6. // Last Update : 2013-03-04
  7. // Author : Nicola Asuni - Tecnick.com LTD - Manor Coach House, Church Hill, Aldershot, Hants, GU12 4RQ, UK - www.tecnick.com - info@tecnick.com
  8. // License : http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT GNU-LGPLv3
  9. // -------------------------------------------------------------------
  10. // Copyright (C) 2002-2013 Nicola Asuni - Tecnick.com LTD
  11. //
  12. // This file is part of TCPDF software library.
  13. //
  14. // TCPDF is free software: you can redistribute it and/or modify it
  15. // under the terms of the GNU Lesser General Public License as
  16. // published by the Free Software Foundation, either version 3 of the
  17. // License, or (at your option) any later version.
  18. //
  19. // TCPDF is distributed in the hope that it will be useful, but
  20. // WITHOUT ANY WARRANTY; without even the implied warranty of
  21. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. // See the GNU Lesser General Public License for more details.
  23. //
  24. // You should have received a copy of the License
  25. // along with TCPDF. If not, see
  26. // <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
  27. //
  28. // See LICENSE.TXT file for more information.
  29. // -------------------------------------------------------------------
  30. //
  31. // Description :
  32. // This is a PHP class for generating PDF documents without requiring external extensions.
  33. //
  34. // NOTE:
  35. // This class was originally derived in 2002 from the Public
  36. // Domain FPDF class by Olivier Plathey (http://www.fpdf.org),
  37. // but now is almost entirely rewritten and contains thousands of
  38. // new lines of code and hundreds new features.
  39. //
  40. // Main features:
  41. // * no external libraries are required for the basic functions;
  42. // * all standard page formats, custom page formats, custom margins and units of measure;
  43. // * UTF-8 Unicode and Right-To-Left languages;
  44. // * TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;
  45. // * font subsetting;
  46. // * methods to publish some XHTML + CSS code, Javascript and Forms;
  47. // * images, graphic (geometric figures) and transformation methods;
  48. // * supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick (http://www.imagemagick.org/www/formats.html)
  49. // * 1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;
  50. // * JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  51. // * automatic page header and footer management;
  52. // * document encryption up to 256 bit and digital signature certifications;
  53. // * transactions to UNDO commands;
  54. // * PDF annotations, including links, text and file attachments;
  55. // * text rendering modes (fill, stroke and clipping);
  56. // * multiple columns mode;
  57. // * no-write page regions;
  58. // * bookmarks, named destinations and table of content;
  59. // * text hyphenation;
  60. // * text stretching and spacing (tracking);
  61. // * automatic page break, line break and text alignments including justification;
  62. // * automatic page numbering and page groups;
  63. // * move and delete pages;
  64. // * page compression (requires php-zlib extension);
  65. // * XOBject Templates;
  66. // * Layers and object visibility.
  67. // * PDF/A-1b support.
  68. //
  69. // -----------------------------------------------------------
  70. // 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. // Travis Harris for crop mark suggestion.
  100. // Aleksey Kuznetsov for some suggestions and text shadows.
  101. // Jim Hanlon for several suggestions and patches.
  102. // Anyone else that has reported a bug or sent a suggestion.
  103. //============================================================+
  104. /**
  105. * @file
  106. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  107. * 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>
  108. * <h3>TCPDF main features are:</h3>
  109. * <ul>
  110. * <li>no external libraries are required for the basic functions;</li>
  111. * <li>all standard page formats, custom page formats, custom margins and units of measure;</li>
  112. * <li>UTF-8 Unicode and Right-To-Left languages;</li>
  113. * <li>TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;</li>
  114. * <li>font subsetting;</li>
  115. * <li>methods to publish some XHTML + CSS code, Javascript and Forms;</li>
  116. * <li>images, graphic (geometric figures) and transformation methods;
  117. * <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>
  118. * <li>1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;</li>
  119. * <li>JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;</li>
  120. * <li>automatic page header and footer management;</li>
  121. * <li>document encryption up to 256 bit and digital signature certifications;</li>
  122. * <li>transactions to UNDO commands;</li>
  123. * <li>PDF annotations, including links, text and file attachments;</li>
  124. * <li>text rendering modes (fill, stroke and clipping);</li>
  125. * <li>multiple columns mode;</li>
  126. * <li>no-write page regions;</li>
  127. * <li>bookmarks, named destinations and table of content;</li>
  128. * <li>text hyphenation;</li>
  129. * <li>text stretching and spacing (tracking);</li>
  130. * <li>automatic page break, line break and text alignments including justification;</li>
  131. * <li>automatic page numbering and page groups;</li>
  132. * <li>move and delete pages;</li>
  133. * <li>page compression (requires php-zlib extension);</li>
  134. * <li>XOBject Templates;</li>
  135. * <li>Layers and object visibility;</li>
  136. * <li>PDF/A-1b support.</li>
  137. * </ul>
  138. * Tools to encode your unicode fonts are on fonts/utils directory.</p>
  139. * @package com.tecnick.tcpdf
  140. * @author Nicola Asuni
  141. * @version 5.9.207
  142. */
  143. // Main configuration file. Define the K_TCPDF_EXTERNAL_CONFIG constant to skip this file.
  144. require_once(dirname(__FILE__).'/config/tcpdf_config.php');
  145. /**
  146. * @class TCPDF
  147. * PHP class for generating PDF documents without requiring external extensions.
  148. * 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>
  149. * @package com.tecnick.tcpdf
  150. * @brief PHP class for generating PDF documents without requiring external extensions.
  151. * @version 5.9.207
  152. * @author Nicola Asuni - info@tecnick.com
  153. */
  154. class TCPDF {
  155. // private properties
  156. /**
  157. * Current TCPDF version.
  158. * @private
  159. */
  160. private $tcpdf_version = '5.9.207';
  161. // Protected properties
  162. /**
  163. * Current page number.
  164. * @protected
  165. */
  166. protected $page;
  167. /**
  168. * Current object number.
  169. * @protected
  170. */
  171. protected $n;
  172. /**
  173. * Array of object offsets.
  174. * @protected
  175. */
  176. protected $offsets = array();
  177. /**
  178. * Array of object IDs for each page.
  179. * @protected
  180. */
  181. protected $pageobjects = array();
  182. /**
  183. * Buffer holding in-memory PDF.
  184. * @protected
  185. */
  186. protected $buffer;
  187. /**
  188. * Array containing pages.
  189. * @protected
  190. */
  191. protected $pages = array();
  192. /**
  193. * Current document state.
  194. * @protected
  195. */
  196. protected $state;
  197. /**
  198. * Compression flag.
  199. * @protected
  200. */
  201. protected $compress;
  202. /**
  203. * Current page orientation (P = Portrait, L = Landscape).
  204. * @protected
  205. */
  206. protected $CurOrientation;
  207. /**
  208. * Page dimensions.
  209. * @protected
  210. */
  211. protected $pagedim = array();
  212. /**
  213. * Scale factor (number of points in user unit).
  214. * @protected
  215. */
  216. protected $k;
  217. /**
  218. * Width of page format in points.
  219. * @protected
  220. */
  221. protected $fwPt;
  222. /**
  223. * Height of page format in points.
  224. * @protected
  225. */
  226. protected $fhPt;
  227. /**
  228. * Current width of page in points.
  229. * @protected
  230. */
  231. protected $wPt;
  232. /**
  233. * Current height of page in points.
  234. * @protected
  235. */
  236. protected $hPt;
  237. /**
  238. * Current width of page in user unit.
  239. * @protected
  240. */
  241. protected $w;
  242. /**
  243. * Current height of page in user unit.
  244. * @protected
  245. */
  246. protected $h;
  247. /**
  248. * Left margin.
  249. * @protected
  250. */
  251. protected $lMargin;
  252. /**
  253. * Right margin.
  254. * @protected
  255. */
  256. protected $rMargin;
  257. /**
  258. * Cell left margin (used by regions).
  259. * @protected
  260. */
  261. protected $clMargin;
  262. /**
  263. * Cell right margin (used by regions).
  264. * @protected
  265. */
  266. protected $crMargin;
  267. /**
  268. * Top margin.
  269. * @protected
  270. */
  271. protected $tMargin;
  272. /**
  273. * Page break margin.
  274. * @protected
  275. */
  276. protected $bMargin;
  277. /**
  278. * Array of cell internal paddings ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
  279. * @since 5.9.000 (2010-10-03)
  280. * @protected
  281. */
  282. protected $cell_padding = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  283. /**
  284. * Array of cell margins ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
  285. * @since 5.9.000 (2010-10-04)
  286. * @protected
  287. */
  288. protected $cell_margin = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  289. /**
  290. * Current horizontal position in user unit for cell positioning.
  291. * @protected
  292. */
  293. protected $x;
  294. /**
  295. * Current vertical position in user unit for cell positioning.
  296. * @protected
  297. */
  298. protected $y;
  299. /**
  300. * Height of last cell printed.
  301. * @protected
  302. */
  303. protected $lasth;
  304. /**
  305. * Line width in user unit.
  306. * @protected
  307. */
  308. protected $LineWidth;
  309. /**
  310. * Array of standard font names.
  311. * @protected
  312. */
  313. protected $CoreFonts;
  314. /**
  315. * Array of used fonts.
  316. * @protected
  317. */
  318. protected $fonts = array();
  319. /**
  320. * Array of font files.
  321. * @protected
  322. */
  323. protected $FontFiles = array();
  324. /**
  325. * Array of encoding differences.
  326. * @protected
  327. */
  328. protected $diffs = array();
  329. /**
  330. * Array of used images.
  331. * @protected
  332. */
  333. protected $images = array();
  334. /**
  335. * Array of cached files.
  336. * @protected
  337. */
  338. protected $cached_files = array();
  339. /**
  340. * Array of Annotations in pages.
  341. * @protected
  342. */
  343. protected $PageAnnots = array();
  344. /**
  345. * Array of internal links.
  346. * @protected
  347. */
  348. protected $links = array();
  349. /**
  350. * Current font family.
  351. * @protected
  352. */
  353. protected $FontFamily;
  354. /**
  355. * Current font style.
  356. * @protected
  357. */
  358. protected $FontStyle;
  359. /**
  360. * Current font ascent (distance between font top and baseline).
  361. * @protected
  362. * @since 2.8.000 (2007-03-29)
  363. */
  364. protected $FontAscent;
  365. /**
  366. * Current font descent (distance between font bottom and baseline).
  367. * @protected
  368. * @since 2.8.000 (2007-03-29)
  369. */
  370. protected $FontDescent;
  371. /**
  372. * Underlining flag.
  373. * @protected
  374. */
  375. protected $underline;
  376. /**
  377. * Overlining flag.
  378. * @protected
  379. */
  380. protected $overline;
  381. /**
  382. * Current font info.
  383. * @protected
  384. */
  385. protected $CurrentFont;
  386. /**
  387. * Current font size in points.
  388. * @protected
  389. */
  390. protected $FontSizePt;
  391. /**
  392. * Current font size in user unit.
  393. * @protected
  394. */
  395. protected $FontSize;
  396. /**
  397. * Commands for drawing color.
  398. * @protected
  399. */
  400. protected $DrawColor;
  401. /**
  402. * Commands for filling color.
  403. * @protected
  404. */
  405. protected $FillColor;
  406. /**
  407. * Commands for text color.
  408. * @protected
  409. */
  410. protected $TextColor;
  411. /**
  412. * Indicates whether fill and text colors are different.
  413. * @protected
  414. */
  415. protected $ColorFlag;
  416. /**
  417. * Automatic page breaking.
  418. * @protected
  419. */
  420. protected $AutoPageBreak;
  421. /**
  422. * Threshold used to trigger page breaks.
  423. * @protected
  424. */
  425. protected $PageBreakTrigger;
  426. /**
  427. * Flag set when processing page header.
  428. * @protected
  429. */
  430. protected $InHeader = false;
  431. /**
  432. * Flag set when processing page footer.
  433. * @protected
  434. */
  435. protected $InFooter = false;
  436. /**
  437. * Zoom display mode.
  438. * @protected
  439. */
  440. protected $ZoomMode;
  441. /**
  442. * Layout display mode.
  443. * @protected
  444. */
  445. protected $LayoutMode;
  446. /**
  447. * If true set the document information dictionary in Unicode.
  448. * @protected
  449. */
  450. protected $docinfounicode = true;
  451. /**
  452. * Document title.
  453. * @protected
  454. */
  455. protected $title = '';
  456. /**
  457. * Document subject.
  458. * @protected
  459. */
  460. protected $subject = '';
  461. /**
  462. * Document author.
  463. * @protected
  464. */
  465. protected $author = '';
  466. /**
  467. * Document keywords.
  468. * @protected
  469. */
  470. protected $keywords = '';
  471. /**
  472. * Document creator.
  473. * @protected
  474. */
  475. protected $creator = '';
  476. /**
  477. * Starting page number.
  478. * @protected
  479. */
  480. protected $starting_page_number = 1;
  481. /**
  482. * String alias for total number of pages.
  483. * @protected
  484. */
  485. protected $alias_tot_pages = '{:ptp:}';
  486. /**
  487. * String alias for page number.
  488. * @protected
  489. */
  490. protected $alias_num_page = '{:pnp:}';
  491. /**
  492. * String alias for total number of pages in a single group.
  493. * @protected
  494. */
  495. protected $alias_group_tot_pages = '{:ptg:}';
  496. /**
  497. * String alias for group page number.
  498. * @protected
  499. */
  500. protected $alias_group_num_page = '{:png:}';
  501. /**
  502. * String alias for right shift compensation used to correctly align page numbers on the right.
  503. * @protected
  504. */
  505. protected $alias_right_shift = '{rsc:';
  506. /**
  507. * The right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image.
  508. * @since 2002-07-31
  509. * @author Nicola Asuni
  510. * @protected
  511. */
  512. protected $img_rb_x;
  513. /**
  514. * The right-bottom corner Y coordinate of last inserted image.
  515. * @since 2002-07-31
  516. * @author Nicola Asuni
  517. * @protected
  518. */
  519. protected $img_rb_y;
  520. /**
  521. * Adjusting factor to convert pixels to user units.
  522. * @since 2004-06-14
  523. * @author Nicola Asuni
  524. * @protected
  525. */
  526. protected $imgscale = 1;
  527. /**
  528. * Boolean flag set to true when the input text is unicode (require unicode fonts).
  529. * @since 2005-01-02
  530. * @author Nicola Asuni
  531. * @protected
  532. */
  533. protected $isunicode = false;
  534. /**
  535. * Object containing unicode data.
  536. * @since 5.9.004 (2010-10-18)
  537. * @author Nicola Asuni
  538. * @protected
  539. */
  540. protected $unicode;
  541. /**
  542. * Object containing font encoding maps.
  543. * @since 5.9.123 (2011-10-01)
  544. * @author Nicola Asuni
  545. * @protected
  546. */
  547. protected $encmaps;
  548. /**
  549. * PDF version.
  550. * @since 1.5.3
  551. * @protected
  552. */
  553. protected $PDFVersion = '1.7';
  554. /**
  555. * ID of the stored default header template (-1 = not set).
  556. * @protected
  557. */
  558. protected $header_xobjid = -1;
  559. /**
  560. * If true reset the Header Xobject template at each page
  561. * @protected
  562. */
  563. protected $header_xobj_autoreset = false;
  564. /**
  565. * Minimum distance between header and top page margin.
  566. * @protected
  567. */
  568. protected $header_margin;
  569. /**
  570. * Minimum distance between footer and bottom page margin.
  571. * @protected
  572. */
  573. protected $footer_margin;
  574. /**
  575. * Original left margin value.
  576. * @protected
  577. * @since 1.53.0.TC013
  578. */
  579. protected $original_lMargin;
  580. /**
  581. * Original right margin value.
  582. * @protected
  583. * @since 1.53.0.TC013
  584. */
  585. protected $original_rMargin;
  586. /**
  587. * Default font used on page header.
  588. * @protected
  589. */
  590. protected $header_font;
  591. /**
  592. * Default font used on page footer.
  593. * @protected
  594. */
  595. protected $footer_font;
  596. /**
  597. * Language templates.
  598. * @protected
  599. */
  600. protected $l;
  601. /**
  602. * Barcode to print on page footer (only if set).
  603. * @protected
  604. */
  605. protected $barcode = false;
  606. /**
  607. * Boolean flag to print/hide page header.
  608. * @protected
  609. */
  610. protected $print_header = true;
  611. /**
  612. * Boolean flag to print/hide page footer.
  613. * @protected
  614. */
  615. protected $print_footer = true;
  616. /**
  617. * Header image logo.
  618. * @protected
  619. */
  620. protected $header_logo = '';
  621. /**
  622. * Width of header image logo in user units.
  623. * @protected
  624. */
  625. protected $header_logo_width = 30;
  626. /**
  627. * Title to be printed on default page header.
  628. * @protected
  629. */
  630. protected $header_title = '';
  631. /**
  632. * String to pring on page header after title.
  633. * @protected
  634. */
  635. protected $header_string = '';
  636. /**
  637. * Color for header text (RGB array).
  638. * @since 5.9.174 (2012-07-25)
  639. * @protected
  640. */
  641. protected $header_text_color = array(0,0,0);
  642. /**
  643. * Color for header line (RGB array).
  644. * @since 5.9.174 (2012-07-25)
  645. * @protected
  646. */
  647. protected $header_line_color = array(0,0,0);
  648. /**
  649. * Color for footer text (RGB array).
  650. * @since 5.9.174 (2012-07-25)
  651. * @protected
  652. */
  653. protected $footer_text_color = array(0,0,0);
  654. /**
  655. * Color for footer line (RGB array).
  656. * @since 5.9.174 (2012-07-25)
  657. * @protected
  658. */
  659. protected $footer_line_color = array(0,0,0);
  660. /**
  661. * Text shadow data array.
  662. * @since 5.9.174 (2012-07-25)
  663. * @protected
  664. */
  665. protected $txtshadow = array('enabled'=>false, 'depth_w'=>0, 'depth_h'=>0, 'color'=>false, 'opacity'=>1, 'blend_mode'=>'Normal');
  666. /**
  667. * Default number of columns for html table.
  668. * @protected
  669. */
  670. protected $default_table_columns = 4;
  671. // variables for html parser
  672. /**
  673. * HTML PARSER: array to store current link and rendering styles.
  674. * @protected
  675. */
  676. protected $HREF = array();
  677. /**
  678. * List of available fonts on filesystem.
  679. * @protected
  680. */
  681. protected $fontlist = array();
  682. /**
  683. * Current foreground color.
  684. * @protected
  685. */
  686. protected $fgcolor;
  687. /**
  688. * HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  689. * @protected
  690. */
  691. protected $listordered = array();
  692. /**
  693. * HTML PARSER: array count list items on nested lists.
  694. * @protected
  695. */
  696. protected $listcount = array();
  697. /**
  698. * HTML PARSER: current list nesting level.
  699. * @protected
  700. */
  701. protected $listnum = 0;
  702. /**
  703. * HTML PARSER: indent amount for lists.
  704. * @protected
  705. */
  706. protected $listindent = 0;
  707. /**
  708. * HTML PARSER: current list indententation level.
  709. * @protected
  710. */
  711. protected $listindentlevel = 0;
  712. /**
  713. * Current background color.
  714. * @protected
  715. */
  716. protected $bgcolor;
  717. /**
  718. * Temporary font size in points.
  719. * @protected
  720. */
  721. protected $tempfontsize = 10;
  722. /**
  723. * Spacer string for LI tags.
  724. * @protected
  725. */
  726. protected $lispacer = '';
  727. /**
  728. * Default encoding.
  729. * @protected
  730. * @since 1.53.0.TC010
  731. */
  732. protected $encoding = 'UTF-8';
  733. /**
  734. * PHP internal encoding.
  735. * @protected
  736. * @since 1.53.0.TC016
  737. */
  738. protected $internal_encoding;
  739. /**
  740. * Boolean flag to indicate if the document language is Right-To-Left.
  741. * @protected
  742. * @since 2.0.000
  743. */
  744. protected $rtl = false;
  745. /**
  746. * Boolean flag used to force RTL or LTR string direction.
  747. * @protected
  748. * @since 2.0.000
  749. */
  750. protected $tmprtl = false;
  751. // --- Variables used for document encryption:
  752. /**
  753. * IBoolean flag indicating whether document is protected.
  754. * @protected
  755. * @since 2.0.000 (2008-01-02)
  756. */
  757. protected $encrypted;
  758. /**
  759. * Array containing encryption settings.
  760. * @protected
  761. * @since 5.0.005 (2010-05-11)
  762. */
  763. protected $encryptdata = array();
  764. /**
  765. * Last RC4 key encrypted (cached for optimisation).
  766. * @protected
  767. * @since 2.0.000 (2008-01-02)
  768. */
  769. protected $last_enc_key;
  770. /**
  771. * Last RC4 computed key.
  772. * @protected
  773. * @since 2.0.000 (2008-01-02)
  774. */
  775. protected $last_enc_key_c;
  776. /**
  777. * Encryption padding string.
  778. * @protected
  779. */
  780. 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";
  781. /**
  782. * File ID (used on document trailer).
  783. * @protected
  784. * @since 5.0.005 (2010-05-12)
  785. */
  786. protected $file_id;
  787. // --- bookmark ---
  788. /**
  789. * Outlines for bookmark.
  790. * @protected
  791. * @since 2.1.002 (2008-02-12)
  792. */
  793. protected $outlines = array();
  794. /**
  795. * Outline root for bookmark.
  796. * @protected
  797. * @since 2.1.002 (2008-02-12)
  798. */
  799. protected $OutlineRoot;
  800. // --- javascript and form ---
  801. /**
  802. * Javascript code.
  803. * @protected
  804. * @since 2.1.002 (2008-02-12)
  805. */
  806. protected $javascript = '';
  807. /**
  808. * Javascript counter.
  809. * @protected
  810. * @since 2.1.002 (2008-02-12)
  811. */
  812. protected $n_js;
  813. /**
  814. * line trough state
  815. * @protected
  816. * @since 2.8.000 (2008-03-19)
  817. */
  818. protected $linethrough;
  819. /**
  820. * Array with additional document-wide usage rights for the document.
  821. * @protected
  822. * @since 5.8.014 (2010-08-23)
  823. */
  824. protected $ur = array();
  825. /**
  826. * DPI (Dot Per Inch) Document Resolution (do not change).
  827. * @protected
  828. * @since 3.0.000 (2008-03-27)
  829. */
  830. protected $dpi = 72;
  831. /**
  832. * Array of page numbers were a new page group was started (the page numbers are the keys of the array).
  833. * @protected
  834. * @since 3.0.000 (2008-03-27)
  835. */
  836. protected $newpagegroup = array();
  837. /**
  838. * Array that contains the number of pages in each page group.
  839. * @protected
  840. * @since 3.0.000 (2008-03-27)
  841. */
  842. protected $pagegroups = array();
  843. /**
  844. * Current page group number.
  845. * @protected
  846. * @since 3.0.000 (2008-03-27)
  847. */
  848. protected $currpagegroup = 0;
  849. /**
  850. * Array of transparency objects and parameters.
  851. * @protected
  852. * @since 3.0.000 (2008-03-27)
  853. */
  854. protected $extgstates;
  855. /**
  856. * Set the default JPEG compression quality (1-100).
  857. * @protected
  858. * @since 3.0.000 (2008-03-27)
  859. */
  860. protected $jpeg_quality;
  861. /**
  862. * Default cell height ratio.
  863. * @protected
  864. * @since 3.0.014 (2008-05-23)
  865. */
  866. protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  867. /**
  868. * PDF viewer preferences.
  869. * @protected
  870. * @since 3.1.000 (2008-06-09)
  871. */
  872. protected $viewer_preferences;
  873. /**
  874. * A name object specifying how the document should be displayed when opened.
  875. * @protected
  876. * @since 3.1.000 (2008-06-09)
  877. */
  878. protected $PageMode;
  879. /**
  880. * Array for storing gradient information.
  881. * @protected
  882. * @since 3.1.000 (2008-06-09)
  883. */
  884. protected $gradients = array();
  885. /**
  886. * Array used to store positions inside the pages buffer (keys are the page numbers).
  887. * @protected
  888. * @since 3.2.000 (2008-06-26)
  889. */
  890. protected $intmrk = array();
  891. /**
  892. * Array used to store positions inside the pages buffer (keys are the page numbers).
  893. * @protected
  894. * @since 5.7.000 (2010-08-03)
  895. */
  896. protected $bordermrk = array();
  897. /**
  898. * Array used to store page positions to track empty pages (keys are the page numbers).
  899. * @protected
  900. * @since 5.8.007 (2010-08-18)
  901. */
  902. protected $emptypagemrk = array();
  903. /**
  904. * Array used to store content positions inside the pages buffer (keys are the page numbers).
  905. * @protected
  906. * @since 4.6.021 (2009-07-20)
  907. */
  908. protected $cntmrk = array();
  909. /**
  910. * Array used to store footer positions of each page.
  911. * @protected
  912. * @since 3.2.000 (2008-07-01)
  913. */
  914. protected $footerpos = array();
  915. /**
  916. * Array used to store footer length of each page.
  917. * @protected
  918. * @since 4.0.014 (2008-07-29)
  919. */
  920. protected $footerlen = array();
  921. /**
  922. * Boolean flag to indicate if a new line is created.
  923. * @protected
  924. * @since 3.2.000 (2008-07-01)
  925. */
  926. protected $newline = true;
  927. /**
  928. * End position of the latest inserted line.
  929. * @protected
  930. * @since 3.2.000 (2008-07-01)
  931. */
  932. protected $endlinex = 0;
  933. /**
  934. * PDF string for width value of the last line.
  935. * @protected
  936. * @since 4.0.006 (2008-07-16)
  937. */
  938. protected $linestyleWidth = '';
  939. /**
  940. * PDF string for CAP value of the last line.
  941. * @protected
  942. * @since 4.0.006 (2008-07-16)
  943. */
  944. protected $linestyleCap = '0 J';
  945. /**
  946. * PDF string for join value of the last line.
  947. * @protected
  948. * @since 4.0.006 (2008-07-16)
  949. */
  950. protected $linestyleJoin = '0 j';
  951. /**
  952. * PDF string for dash value of the last line.
  953. * @protected
  954. * @since 4.0.006 (2008-07-16)
  955. */
  956. protected $linestyleDash = '[] 0 d';
  957. /**
  958. * Boolean flag to indicate if marked-content sequence is open.
  959. * @protected
  960. * @since 4.0.013 (2008-07-28)
  961. */
  962. protected $openMarkedContent = false;
  963. /**
  964. * Count the latest inserted vertical spaces on HTML.
  965. * @protected
  966. * @since 4.0.021 (2008-08-24)
  967. */
  968. protected $htmlvspace = 0;
  969. /**
  970. * Array of Spot colors.
  971. * @protected
  972. * @since 4.0.024 (2008-09-12)
  973. */
  974. protected $spot_colors = array();
  975. /**
  976. * Symbol used for HTML unordered list items.
  977. * @protected
  978. * @since 4.0.028 (2008-09-26)
  979. */
  980. protected $lisymbol = '';
  981. /**
  982. * String used to mark the beginning and end of EPS image blocks.
  983. * @protected
  984. * @since 4.1.000 (2008-10-18)
  985. */
  986. protected $epsmarker = 'x#!#EPS#!#x';
  987. /**
  988. * Array of transformation matrix.
  989. * @protected
  990. * @since 4.2.000 (2008-10-29)
  991. */
  992. protected $transfmatrix = array();
  993. /**
  994. * Current key for transformation matrix.
  995. * @protected
  996. * @since 4.8.005 (2009-09-17)
  997. */
  998. protected $transfmatrix_key = 0;
  999. /**
  1000. * Booklet mode for double-sided pages.
  1001. * @protected
  1002. * @since 4.2.000 (2008-10-29)
  1003. */
  1004. protected $booklet = false;
  1005. /**
  1006. * Epsilon value used for float calculations.
  1007. * @protected
  1008. * @since 4.2.000 (2008-10-29)
  1009. */
  1010. protected $feps = 0.005;
  1011. /**
  1012. * Array used for custom vertical spaces for HTML tags.
  1013. * @protected
  1014. * @since 4.2.001 (2008-10-30)
  1015. */
  1016. protected $tagvspaces = array();
  1017. /**
  1018. * HTML PARSER: custom indent amount for lists. Negative value means disabled.
  1019. * @protected
  1020. * @since 4.2.007 (2008-11-12)
  1021. */
  1022. protected $customlistindent = -1;
  1023. /**
  1024. * Boolean flag to indicate if the border of the cell sides that cross the page should be removed.
  1025. * @protected
  1026. * @since 4.2.010 (2008-11-14)
  1027. */
  1028. protected $opencell = true;
  1029. /**
  1030. * Array of files to embedd.
  1031. * @protected
  1032. * @since 4.4.000 (2008-12-07)
  1033. */
  1034. protected $embeddedfiles = array();
  1035. /**
  1036. * Boolean flag to indicate if we are inside a PRE tag.
  1037. * @protected
  1038. * @since 4.4.001 (2008-12-08)
  1039. */
  1040. protected $premode = false;
  1041. /**
  1042. * Array used to store positions of graphics transformation blocks inside the page buffer.
  1043. * keys are the page numbers
  1044. * @protected
  1045. * @since 4.4.002 (2008-12-09)
  1046. */
  1047. protected $transfmrk = array();
  1048. /**
  1049. * Default color for html links.
  1050. * @protected
  1051. * @since 4.4.003 (2008-12-09)
  1052. */
  1053. protected $htmlLinkColorArray = array(0, 0, 255);
  1054. /**
  1055. * Default font style to add to html links.
  1056. * @protected
  1057. * @since 4.4.003 (2008-12-09)
  1058. */
  1059. protected $htmlLinkFontStyle = 'U';
  1060. /**
  1061. * Counts the number of pages.
  1062. * @protected
  1063. * @since 4.5.000 (2008-12-31)
  1064. */
  1065. protected $numpages = 0;
  1066. /**
  1067. * Array containing page lengths in bytes.
  1068. * @protected
  1069. * @since 4.5.000 (2008-12-31)
  1070. */
  1071. protected $pagelen = array();
  1072. /**
  1073. * Counts the number of pages.
  1074. * @protected
  1075. * @since 4.5.000 (2008-12-31)
  1076. */
  1077. protected $numimages = 0;
  1078. /**
  1079. * Store the image keys.
  1080. * @protected
  1081. * @since 4.5.000 (2008-12-31)
  1082. */
  1083. protected $imagekeys = array();
  1084. /**
  1085. * Length of the buffer in bytes.
  1086. * @protected
  1087. * @since 4.5.000 (2008-12-31)
  1088. */
  1089. protected $bufferlen = 0;
  1090. /**
  1091. * If true enables disk caching.
  1092. * @protected
  1093. * @since 4.5.000 (2008-12-31)
  1094. */
  1095. protected $diskcache = false;
  1096. /**
  1097. * Counts the number of fonts.
  1098. * @protected
  1099. * @since 4.5.000 (2009-01-02)
  1100. */
  1101. protected $numfonts = 0;
  1102. /**
  1103. * Store the font keys.
  1104. * @protected
  1105. * @since 4.5.000 (2009-01-02)
  1106. */
  1107. protected $fontkeys = array();
  1108. /**
  1109. * Store the font object IDs.
  1110. * @protected
  1111. * @since 4.8.001 (2009-09-09)
  1112. */
  1113. protected $font_obj_ids = array();
  1114. /**
  1115. * Store the fage status (true when opened, false when closed).
  1116. * @protected
  1117. * @since 4.5.000 (2009-01-02)
  1118. */
  1119. protected $pageopen = array();
  1120. /**
  1121. * Default monospace font.
  1122. * @protected
  1123. * @since 4.5.025 (2009-03-10)
  1124. */
  1125. protected $default_monospaced_font = 'courier';
  1126. /**
  1127. * Cloned copy of the current class object.
  1128. * @protected
  1129. * @since 4.5.029 (2009-03-19)
  1130. */
  1131. protected $objcopy;
  1132. /**
  1133. * Array used to store the lengths of cache files.
  1134. * @protected
  1135. * @since 4.5.029 (2009-03-19)
  1136. */
  1137. protected $cache_file_length = array();
  1138. /**
  1139. * Table header content to be repeated on each new page.
  1140. * @protected
  1141. * @since 4.5.030 (2009-03-20)
  1142. */
  1143. protected $thead = '';
  1144. /**
  1145. * Margins used for table header.
  1146. * @protected
  1147. * @since 4.5.030 (2009-03-20)
  1148. */
  1149. protected $theadMargins = array();
  1150. /**
  1151. * Cache array for UTF8StringToArray() method.
  1152. * @protected
  1153. * @since 4.5.037 (2009-04-07)
  1154. */
  1155. protected $cache_UTF8StringToArray = array();
  1156. /**
  1157. * Maximum size of cache array used for UTF8StringToArray() method.
  1158. * @protected
  1159. * @since 4.5.037 (2009-04-07)
  1160. */
  1161. protected $cache_maxsize_UTF8StringToArray = 8;
  1162. /**
  1163. * Current size of cache array used for UTF8StringToArray() method.
  1164. * @protected
  1165. * @since 4.5.037 (2009-04-07)
  1166. */
  1167. protected $cache_size_UTF8StringToArray = 0;
  1168. /**
  1169. * Boolean flag to enable document digital signature.
  1170. * @protected
  1171. * @since 4.6.005 (2009-04-24)
  1172. */
  1173. protected $sign = false;
  1174. /**
  1175. * Digital signature data.
  1176. * @protected
  1177. * @since 4.6.005 (2009-04-24)
  1178. */
  1179. protected $signature_data = array();
  1180. /**
  1181. * Digital signature max length.
  1182. * @protected
  1183. * @since 4.6.005 (2009-04-24)
  1184. */
  1185. protected $signature_max_length = 11742;
  1186. /**
  1187. * Data for digital signature appearance.
  1188. * @protected
  1189. * @since 5.3.011 (2010-06-16)
  1190. */
  1191. protected $signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
  1192. /**
  1193. * Array of empty digital signature appearances.
  1194. * @protected
  1195. * @since 5.9.101 (2011-07-06)
  1196. */
  1197. protected $empty_signature_appearance = array();
  1198. /**
  1199. * Regular expression used to find blank characters (required for word-wrapping).
  1200. * @protected
  1201. * @since 4.6.006 (2009-04-28)
  1202. */
  1203. protected $re_spaces = '/[^\S\xa0]/';
  1204. /**
  1205. * Array of $re_spaces parts.
  1206. * @protected
  1207. * @since 5.5.011 (2010-07-09)
  1208. */
  1209. protected $re_space = array('p' => '[^\S\xa0]', 'm' => '');
  1210. /**
  1211. * Digital signature object ID.
  1212. * @protected
  1213. * @since 4.6.022 (2009-06-23)
  1214. */
  1215. protected $sig_obj_id = 0;
  1216. /**
  1217. * ByteRange placemark used during digital signature process.
  1218. * @protected
  1219. * @since 4.6.028 (2009-08-25)
  1220. */
  1221. protected $byterange_string = '/ByteRange[0 ********** ********** **********]';
  1222. /**
  1223. * Placemark used during digital signature process.
  1224. * @protected
  1225. * @since 4.6.028 (2009-08-25)
  1226. */
  1227. protected $sig_annot_ref = '***SIGANNREF*** 0 R';
  1228. /**
  1229. * ID of page objects.
  1230. * @protected
  1231. * @since 4.7.000 (2009-08-29)
  1232. */
  1233. protected $page_obj_id = array();
  1234. /**
  1235. * List of form annotations IDs.
  1236. * @protected
  1237. * @since 4.8.000 (2009-09-07)
  1238. */
  1239. protected $form_obj_id = array();
  1240. /**
  1241. * 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.
  1242. * @protected
  1243. * @since 4.8.000 (2009-09-07)
  1244. */
  1245. protected $default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1246. /**
  1247. * Javascript objects array.
  1248. * @protected
  1249. * @since 4.8.000 (2009-09-07)
  1250. */
  1251. protected $js_objects = array();
  1252. /**
  1253. * Current form action (used during XHTML rendering).
  1254. * @protected
  1255. * @since 4.8.000 (2009-09-07)
  1256. */
  1257. protected $form_action = '';
  1258. /**
  1259. * Current form encryption type (used during XHTML rendering).
  1260. * @protected
  1261. * @since 4.8.000 (2009-09-07)
  1262. */
  1263. protected $form_enctype = 'application/x-www-form-urlencoded';
  1264. /**
  1265. * Current method to submit forms.
  1266. * @protected
  1267. * @since 4.8.000 (2009-09-07)
  1268. */
  1269. protected $form_mode = 'post';
  1270. /**
  1271. * List of fonts used on form fields (fontname => fontkey).
  1272. * @protected
  1273. * @since 4.8.001 (2009-09-09)
  1274. */
  1275. protected $annotation_fonts = array();
  1276. /**
  1277. * List of radio buttons parent objects.
  1278. * @protected
  1279. * @since 4.8.001 (2009-09-09)
  1280. */
  1281. protected $radiobutton_groups = array();
  1282. /**
  1283. * List of radio group objects IDs.
  1284. * @protected
  1285. * @since 4.8.001 (2009-09-09)
  1286. */
  1287. protected $radio_groups = array();
  1288. /**
  1289. * Text indentation value (used for text-indent CSS attribute).
  1290. * @protected
  1291. * @since 4.8.006 (2009-09-23)
  1292. */
  1293. protected $textindent = 0;
  1294. /**
  1295. * Store page number when startTransaction() is called.
  1296. * @protected
  1297. * @since 4.8.006 (2009-09-23)
  1298. */
  1299. protected $start_transaction_page = 0;
  1300. /**
  1301. * Store Y position when startTransaction() is called.
  1302. * @protected
  1303. * @since 4.9.001 (2010-03-28)
  1304. */
  1305. protected $start_transaction_y = 0;
  1306. /**
  1307. * True when we are printing the thead section on a new page.
  1308. * @protected
  1309. * @since 4.8.027 (2010-01-25)
  1310. */
  1311. protected $inthead = false;
  1312. /**
  1313. * Array of column measures (width, space, starting Y position).
  1314. * @protected
  1315. * @since 4.9.001 (2010-03-28)
  1316. */
  1317. protected $columns = array();
  1318. /**
  1319. * Number of colums.
  1320. * @protected
  1321. * @since 4.9.001 (2010-03-28)
  1322. */
  1323. protected $num_columns = 1;
  1324. /**
  1325. * Current column number.
  1326. * @protected
  1327. * @since 4.9.001 (2010-03-28)
  1328. */
  1329. protected $current_column = 0;
  1330. /**
  1331. * Starting page for columns.
  1332. * @protected
  1333. * @since 4.9.001 (2010-03-28)
  1334. */
  1335. protected $column_start_page = 0;
  1336. /**
  1337. * Maximum page and column selected.
  1338. * @protected
  1339. * @since 5.8.000 (2010-08-11)
  1340. */
  1341. protected $maxselcol = array('page' => 0, 'column' => 0);
  1342. /**
  1343. * Array of: X difference between table cell x start and starting page margin, cellspacing, cellpadding.
  1344. * @protected
  1345. * @since 5.8.000 (2010-08-11)
  1346. */
  1347. protected $colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  1348. /**
  1349. * 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.
  1350. * @protected
  1351. * @since 4.9.008 (2010-04-03)
  1352. */
  1353. protected $textrendermode = 0;
  1354. /**
  1355. * Text stroke width in doc units.
  1356. * @protected
  1357. * @since 4.9.008 (2010-04-03)
  1358. */
  1359. protected $textstrokewidth = 0;
  1360. /**
  1361. * Current stroke color.
  1362. * @protected
  1363. * @since 4.9.008 (2010-04-03)
  1364. */
  1365. protected $strokecolor;
  1366. /**
  1367. * Default unit of measure for document.
  1368. * @protected
  1369. * @since 5.0.000 (2010-04-22)
  1370. */
  1371. protected $pdfunit = 'mm';
  1372. /**
  1373. * Boolean flag true when we are on TOC (Table Of Content) page.
  1374. * @protected
  1375. */
  1376. protected $tocpage = false;
  1377. /**
  1378. * Boolean flag: if true convert vector images (SVG, EPS) to raster image using GD or ImageMagick library.
  1379. * @protected
  1380. * @since 5.0.000 (2010-04-26)
  1381. */
  1382. protected $rasterize_vector_images = false;
  1383. /**
  1384. * Boolean flag: if true enables font subsetting by default.
  1385. * @protected
  1386. * @since 5.3.002 (2010-06-07)
  1387. */
  1388. protected $font_subsetting = true;
  1389. /**
  1390. * Array of default graphic settings.
  1391. * @protected
  1392. * @since 5.5.008 (2010-07-02)
  1393. */
  1394. protected $default_graphic_vars = array();
  1395. /**
  1396. * Array of XObjects.
  1397. * @protected
  1398. * @since 5.8.014 (2010-08-23)
  1399. */
  1400. protected $xobjects = array();
  1401. /**
  1402. * Boolean value true when we are inside an XObject.
  1403. * @protected
  1404. * @since 5.8.017 (2010-08-24)
  1405. */
  1406. protected $inxobj = false;
  1407. /**
  1408. * Current XObject ID.
  1409. * @protected
  1410. * @since 5.8.017 (2010-08-24)
  1411. */
  1412. protected $xobjid = '';
  1413. /**
  1414. * Percentage of character stretching.
  1415. * @protected
  1416. * @since 5.9.000 (2010-09-29)
  1417. */
  1418. protected $font_stretching = 100;
  1419. /**
  1420. * Increases or decreases the space between characters in a text by the specified amount (tracking).
  1421. * @protected
  1422. * @since 5.9.000 (2010-09-29)
  1423. */
  1424. protected $font_spacing = 0;
  1425. /**
  1426. * Array of no-write regions.
  1427. * ('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)
  1428. * @protected
  1429. * @since 5.9.003 (2010-10-14)
  1430. */
  1431. protected $page_regions = array();
  1432. /**
  1433. * Boolean value true when page region check is active.
  1434. * @protected
  1435. */
  1436. protected $check_page_regions = true;
  1437. /**
  1438. * Array containing HTML color names and values.
  1439. * @protected
  1440. * @since 5.9.004 (2010-10-18)
  1441. */
  1442. protected $webcolor = array();
  1443. /**
  1444. * Array containing spot color names and values.
  1445. * @protected
  1446. * @since 5.9.012 (2010-11-11)
  1447. */
  1448. protected $spotcolor = array();
  1449. /**
  1450. * Array of PDF layers data.
  1451. * @protected
  1452. * @since 5.9.102 (2011-07-13)
  1453. */
  1454. protected $pdflayers = array();
  1455. /**
  1456. * A dictionary of names and corresponding destinations (Dests key on document Catalog).
  1457. * @protected
  1458. * @since 5.9.097 (2011-06-23)
  1459. */
  1460. protected $dests = array();
  1461. /**
  1462. * Object ID for Named Destinations
  1463. * @protected
  1464. * @since 5.9.097 (2011-06-23)
  1465. */
  1466. protected $n_dests;
  1467. /**
  1468. * Embedded Files Names
  1469. * @protected
  1470. * @since 5.9.204 (2013-01-23)
  1471. */
  1472. protected $efnames = array();
  1473. /**
  1474. * Directory used for the last SVG image.
  1475. * @protected
  1476. * @since 5.0.000 (2010-05-05)
  1477. */
  1478. protected $svgdir = '';
  1479. /**
  1480. * Deafult unit of measure for SVG.
  1481. * @protected
  1482. * @since 5.0.000 (2010-05-02)
  1483. */
  1484. protected $svgunit = 'px';
  1485. /**
  1486. * Array of SVG gradients.
  1487. * @protected
  1488. * @since 5.0.000 (2010-05-02)
  1489. */
  1490. protected $svggradients = array();
  1491. /**
  1492. * ID of last SVG gradient.
  1493. * @protected
  1494. * @since 5.0.000 (2010-05-02)
  1495. */
  1496. protected $svggradientid = 0;
  1497. /**
  1498. * Boolean value true when in SVG defs group.
  1499. * @protected
  1500. * @since 5.0.000 (2010-05-02)
  1501. */
  1502. protected $svgdefsmode = false;
  1503. /**
  1504. * Array of SVG defs.
  1505. * @protected
  1506. * @since 5.0.000 (2010-05-02)
  1507. */
  1508. protected $svgdefs = array();
  1509. /**
  1510. * Boolean value true when in SVG clipPath tag.
  1511. * @protected
  1512. * @since 5.0.000 (2010-04-26)
  1513. */
  1514. protected $svgclipmode = false;
  1515. /**
  1516. * Array of SVG clipPath commands.
  1517. * @protected
  1518. * @since 5.0.000 (2010-05-02)
  1519. */
  1520. protected $svgclippaths = array();
  1521. /**
  1522. * Array of SVG clipPath tranformation matrix.
  1523. * @protected
  1524. * @since 5.8.022 (2010-08-31)
  1525. */
  1526. protected $svgcliptm = array();
  1527. /**
  1528. * ID of last SVG clipPath.
  1529. * @protected
  1530. * @since 5.0.000 (2010-05-02)
  1531. */
  1532. protected $svgclipid = 0;
  1533. /**
  1534. * SVG text.
  1535. * @protected
  1536. * @since 5.0.000 (2010-05-02)
  1537. */
  1538. protected $svgtext = '';
  1539. /**
  1540. * SVG text properties.
  1541. * @protected
  1542. * @since 5.8.013 (2010-08-23)
  1543. */
  1544. protected $svgtextmode = array();
  1545. /**
  1546. * Array of hinheritable SVG properties.
  1547. * @protected
  1548. * @since 5.0.000 (2010-05-02)
  1549. */
  1550. 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');
  1551. /**
  1552. * Array of SVG properties.
  1553. * @protected
  1554. * @since 5.0.000 (2010-05-02)
  1555. */
  1556. protected $svgstyles = array(array(
  1557. 'alignment-baseline' => 'auto',
  1558. 'baseline-shift' => 'baseline',
  1559. 'clip' => 'auto',
  1560. 'clip-path' => 'none',
  1561. 'clip-rule' => 'nonzero',
  1562. 'color' => 'black',
  1563. 'color-interpolation' => 'sRGB',
  1564. 'color-interpolation-filters' => 'linearRGB',
  1565. 'color-profile' => 'auto',
  1566. 'color-rendering' => 'auto',
  1567. 'cursor' => 'auto',
  1568. 'direction' => 'ltr',
  1569. 'display' => 'inline',
  1570. 'dominant-baseline' => 'auto',
  1571. 'enable-background' => 'accumulate',
  1572. 'fill' => 'black',
  1573. 'fill-opacity' => 1,
  1574. 'fill-rule' => 'nonzero',
  1575. 'filter' => 'none',
  1576. 'flood-color' => 'black',
  1577. 'flood-opacity' => 1,
  1578. 'font' => '',
  1579. 'font-family' => 'helvetica',
  1580. 'font-size' => 'medium',
  1581. 'font-size-adjust' => 'none',
  1582. 'font-stretch' => 'normal',
  1583. 'font-style' => 'normal',
  1584. 'font-variant' => 'normal',
  1585. 'font-weight' => 'normal',
  1586. 'glyph-orientation-horizontal' => '0deg',
  1587. 'glyph-orientation-vertical' => 'auto',
  1588. 'image-rendering' => 'auto',
  1589. 'kerning' => 'auto',
  1590. 'letter-spacing' => 'normal',
  1591. 'lighting-color' => 'white',
  1592. 'marker' => '',
  1593. 'marker-end' => 'none',
  1594. 'marker-mid' => 'none',
  1595. 'marker-start' => 'none',
  1596. 'mask' => 'none',
  1597. 'opacity' => 1,
  1598. 'overflow' => 'auto',
  1599. 'pointer-events' => 'visiblePainted',
  1600. 'shape-rendering' => 'auto',
  1601. 'stop-color' => 'black',
  1602. 'stop-opacity' => 1,
  1603. 'stroke' => 'none',
  1604. 'stroke-dasharray' => 'none',
  1605. 'stroke-dashoffset' => 0,
  1606. 'stroke-linecap' => 'butt',
  1607. 'stroke-linejoin' => 'miter',
  1608. 'stroke-miterlimit' => 4,
  1609. 'stroke-opacity' => 1,
  1610. 'stroke-width' => 1,
  1611. 'text-anchor' => 'start',
  1612. 'text-decoration' => 'none',
  1613. 'text-rendering' => 'auto',
  1614. 'unicode-bidi' => 'normal',
  1615. 'visibility' => 'visible',
  1616. 'word-spacing' => 'normal',
  1617. 'writing-mode' => 'lr-tb',
  1618. 'text-color' => 'black',
  1619. 'transfmatrix' => array(1, 0, 0, 1, 0, 0)
  1620. ));
  1621. /**
  1622. * If true force sRGB color profile for all document.
  1623. * @protected
  1624. * @since 5.9.121 (2011-09-28)
  1625. */
  1626. protected $force_srgb = false;
  1627. /**
  1628. * If true set the document to PDF/A mode.
  1629. * @protected
  1630. * @since 5.9.121 (2011-09-27)
  1631. */
  1632. protected $pdfa_mode = false;
  1633. /**
  1634. * Document creation date-time
  1635. * @protected
  1636. * @since 5.9.152 (2012-03-22)
  1637. */
  1638. protected $doc_creation_timestamp;
  1639. /**
  1640. * Document modification date-time
  1641. * @protected
  1642. * @since 5.9.152 (2012-03-22)
  1643. */
  1644. protected $doc_modification_timestamp;
  1645. /**
  1646. * Custom XMP data.
  1647. * @protected
  1648. * @since 5.9.128 (2011-10-06)
  1649. */
  1650. protected $custom_xmp = '';
  1651. /**
  1652. * Overprint mode array.
  1653. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  1654. * @protected
  1655. * @since 5.9.152 (2012-03-23)
  1656. */
  1657. protected $overprint = array('OP' => false, 'op' => false, 'OPM' => 0);
  1658. /**
  1659. * Alpha mode array.
  1660. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  1661. * @protected
  1662. * @since 5.9.152 (2012-03-23)
  1663. */
  1664. protected $alpha = array('CA' => 1, 'ca' => 1, 'BM' => '/Normal', 'AIS' => false);
  1665. /**
  1666. * Define the page boundaries boxes to be set on document.
  1667. * @protected
  1668. * @since 5.9.152 (2012-03-23)
  1669. */
  1670. protected $page_boxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  1671. /**
  1672. * Set the document producer metadata.
  1673. * @protected
  1674. * @since 5.9.152 (2012-03-23)
  1675. */
  1676. protected $pdfproducer;
  1677. /**
  1678. * If true print TCPDF meta link.
  1679. * @protected
  1680. * @since 5.9.152 (2012-03-23)
  1681. */
  1682. protected $tcpdflink = true;
  1683. /**
  1684. * Cache array for computed GD gamma values.
  1685. * @protected
  1686. * @since 5.9.1632 (2012-06-05)
  1687. */
  1688. protected $gdgammacache = array();
  1689. //------------------------------------------------------------
  1690. // METHODS
  1691. //------------------------------------------------------------
  1692. /**
  1693. * This is the class constructor.
  1694. * It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).
  1695. * @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>
  1696. * @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.
  1697. * @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().
  1698. * @param $unicode (boolean) TRUE means that the input text is unicode (default = true)
  1699. * @param $encoding (string) Charset encoding; default is UTF-8.
  1700. * @param $diskcache (boolean) If TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
  1701. * @param $pdfa (boolean) If TRUE set the document to PDF/A mode.
  1702. * @public
  1703. * @see getPageSizeFromFormat(), setPageFormat()
  1704. */
  1705. public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false) {
  1706. /* Set internal character encoding to ASCII */
  1707. if (function_exists('mb_internal_encoding') AND mb_internal_encoding()) {
  1708. $this->internal_encoding = mb_internal_encoding();
  1709. mb_internal_encoding('ASCII');
  1710. }
  1711. // get array of HTML colors
  1712. require(dirname(__FILE__).'/htmlcolors.php');
  1713. $this->webcolor = $webcolor;
  1714. // get array of custom spot colors
  1715. if (file_exists(dirname(__FILE__).'/spotcolors.php')) {
  1716. require(dirname(__FILE__).'/spotcolors.php');
  1717. $this->spotcolor = $spotcolor;
  1718. } else {
  1719. $this->spotcolor = array();
  1720. }
  1721. require_once(dirname(__FILE__).'/unicode_data.php');
  1722. $this->unicode = new TCPDF_UNICODE_DATA();
  1723. require_once(dirname(__FILE__).'/encodings_maps.php');
  1724. $this->encmaps = new TCPDF_ENCODING_MAPS();
  1725. $this->font_obj_ids = array();
  1726. $this->page_obj_id = array();
  1727. $this->form_obj_id = array();
  1728. // set pdf/a mode
  1729. $this->pdfa_mode = $pdfa;
  1730. $this->force_srgb = false;
  1731. // set disk caching
  1732. $this->diskcache = $diskcache ? true : false;
  1733. // set language direction
  1734. $this->rtl = false;
  1735. $this->tmprtl = false;
  1736. // some checks
  1737. $this->_dochecks();
  1738. // initialization of properties
  1739. $this->isunicode = $unicode;
  1740. $this->page = 0;
  1741. $this->transfmrk[0] = array();
  1742. $this->pagedim = array();
  1743. $this->n = 2;
  1744. $this->buffer = '';
  1745. $this->pages = array();
  1746. $this->state = 0;
  1747. $this->fonts = array();
  1748. $this->FontFiles = array();
  1749. $this->diffs = array();
  1750. $this->images = array();
  1751. $this->links = array();
  1752. $this->gradients = array();
  1753. $this->InFooter = false;
  1754. $this->lasth = 0;
  1755. $this->FontFamily = defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica';
  1756. $this->FontStyle = '';
  1757. $this->FontSizePt = 12;
  1758. $this->underline = false;
  1759. $this->overline = false;
  1760. $this->linethrough = false;
  1761. $this->DrawColor = '0 G';
  1762. $this->FillColor = '0 g';
  1763. $this->TextColor = '0 g';
  1764. $this->ColorFlag = false;
  1765. $this->pdflayers = array();
  1766. // encryption values
  1767. $this->encrypted = false;
  1768. $this->last_enc_key = '';
  1769. // standard Unicode fonts
  1770. $this->CoreFonts = array(
  1771. 'courier'=>'Courier',
  1772. 'courierB'=>'Courier-Bold',
  1773. 'courierI'=>'Courier-Oblique',
  1774. 'courierBI'=>'Courier-BoldOblique',
  1775. 'helvetica'=>'Helvetica',
  1776. 'helveticaB'=>'Helvetica-Bold',
  1777. 'helveticaI'=>'Helvetica-Oblique',
  1778. 'helveticaBI'=>'Helvetica-BoldOblique',
  1779. 'times'=>'Times-Roman',
  1780. 'timesB'=>'Times-Bold',
  1781. 'timesI'=>'Times-Italic',
  1782. 'timesBI'=>'Times-BoldItalic',
  1783. 'symbol'=>'Symbol',
  1784. 'zapfdingbats'=>'ZapfDingbats'
  1785. );
  1786. // set scale factor
  1787. $this->setPageUnit($unit);
  1788. // set page format and orientation
  1789. $this->setPageFormat($format, $orientation);
  1790. // page margins (1 cm)
  1791. $margin = 28.35 / $this->k;
  1792. $this->SetMargins($margin, $margin);
  1793. $this->clMargin = $this->lMargin;
  1794. $this->crMargin = $this->rMargin;
  1795. // internal cell padding
  1796. $cpadding = $margin / 10;
  1797. $this->setCellPaddings($cpadding, 0, $cpadding, 0);
  1798. // cell margins
  1799. $this->setCellMargins(0, 0, 0, 0);
  1800. // line width (0.2 mm)
  1801. $this->LineWidth = 0.57 / $this->k;
  1802. $this->linestyleWidth = sprintf('%F w', ($this->LineWidth * $this->k));
  1803. $this->linestyleCap = '0 J';
  1804. $this->linestyleJoin = '0 j';
  1805. $this->linestyleDash = '[] 0 d';
  1806. // automatic page break
  1807. $this->SetAutoPageBreak(true, (2 * $margin));
  1808. // full width display mode
  1809. $this->SetDisplayMode('fullwidth');
  1810. // compression
  1811. $this->SetCompression();
  1812. // set default PDF version number
  1813. $this->setPDFVersion();
  1814. $this->pdfproducer = "\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";
  1815. $this->tcpdflink = true;
  1816. $this->encoding = $encoding;
  1817. $this->HREF = array();
  1818. $this->getFontsList();
  1819. $this->fgcolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1820. $this->strokecolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1821. $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255);
  1822. $this->extgstates = array();
  1823. $this->setTextShadow();
  1824. // user's rights
  1825. $this->sign = false;
  1826. $this->ur['enabled'] = false;
  1827. $this->ur['document'] = '/FullSave';
  1828. $this->ur['annots'] = '/Create/Delete/Modify/Copy/Import/Export';
  1829. $this->ur['form'] = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1830. $this->ur['signature'] = '/Modify';
  1831. $this->ur['ef'] = '/Create/Delete/Modify/Import';
  1832. $this->ur['formex'] = '';
  1833. $this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
  1834. $this->empty_signature_appearance = array();
  1835. // set default JPEG quality
  1836. $this->jpeg_quality = 75;
  1837. // initialize some settings
  1838. $this->utf8Bidi(array(''), '');
  1839. // set default font
  1840. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  1841. // check if PCRE Unicode support is enabled
  1842. if ($this->isunicode AND (@preg_match('/\pL/u', 'a') == 1)) {
  1843. // PCRE unicode support is turned ON
  1844. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  1845. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  1846. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  1847. //$this->setSpacesRE('/[^\S\P{Z}\P{Lo}\xa0]/u');
  1848. $this->setSpacesRE('/[^\S\P{Z}\xa0]/u');
  1849. } else {
  1850. // PCRE unicode support is turned OFF
  1851. $this->setSpacesRE('/[^\S\xa0]/');
  1852. }
  1853. $this->default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1854. // set file ID for trailer
  1855. $serformat = (is_array($format) ? serialize($format) : $format);
  1856. $this->file_id = md5($this->getRandomSeed('TCPDF'.$orientation.$unit.$serformat.$encoding));
  1857. // set document creation and modification timestamp
  1858. $this->doc_creation_timestamp = time();
  1859. $this->doc_modification_timestamp = $this->doc_creation_timestamp;
  1860. // get default graphic vars
  1861. $this->default_graphic_vars = $this->getGraphicVars();
  1862. $this->header_xobj_autoreset = false;
  1863. $this->custom_xmp = '';
  1864. }
  1865. /**
  1866. * Default destructor.
  1867. * @public
  1868. * @since 1.53.0.TC016
  1869. */
  1870. public function __destruct() {
  1871. // restore internal encoding
  1872. if (isset($this->internal_encoding) AND !empty($this->internal_encoding)) {
  1873. mb_internal_encoding($this->internal_encoding);
  1874. }
  1875. // unset all class variables
  1876. $this->_destroy(true);
  1877. }
  1878. /**
  1879. * Return the current TCPDF version.
  1880. * @return TCPDF version string
  1881. * @public
  1882. * @since 5.9.012 (2010-11-10)
  1883. */
  1884. public function getTCPDFVersion() {
  1885. return $this->tcpdf_version;
  1886. }
  1887. /**
  1888. * Set the units of measure for the document.
  1889. * @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.
  1890. * @public
  1891. * @since 3.0.015 (2008-06-06)
  1892. */
  1893. public function setPageUnit($unit) {
  1894. $unit = strtolower($unit);
  1895. //Set scale factor
  1896. switch ($unit) {
  1897. // points
  1898. case 'px':
  1899. case 'pt': {
  1900. $this->k = 1;
  1901. break;
  1902. }
  1903. // millimeters
  1904. case 'mm': {
  1905. $this->k = $this->dpi / 25.4;
  1906. break;
  1907. }
  1908. // centimeters
  1909. case 'cm': {
  1910. $this->k = $this->dpi / 2.54;
  1911. break;
  1912. }
  1913. // inches
  1914. case 'in': {
  1915. $this->k = $this->dpi;
  1916. break;
  1917. }
  1918. // unsupported unit
  1919. default : {
  1920. $this->Error('Incorrect unit: '.$unit);
  1921. break;
  1922. }
  1923. }
  1924. $this->pdfunit = $unit;
  1925. if (isset($this->CurOrientation)) {
  1926. $this->setPageOrientation($this->CurOrientation);
  1927. }
  1928. }
  1929. /**
  1930. * Get page dimensions from format name.
  1931. * @param $format (mixed) The format name. It can be: <ul>
  1932. * <li><b>ISO 216 A Series + 2 SIS 014711 extensions</b></li>
  1933. * <li>A0 (841x1189 mm ; 33.11x46.81 in)</li>
  1934. * <li>A1 (594x841 mm ; 23.39x33.11 in)</li>
  1935. * <li>A2 (420x594 mm ; 16.54x23.39 in)</li>
  1936. * <li>A3 (297x420 mm ; 11.69x16.54 in)</li>
  1937. * <li>A4 (210x297 mm ; 8.27x11.69 in)</li>
  1938. * <li>A5 (148x210 mm ; 5.83x8.27 in)</li>
  1939. * <li>A6 (105x148 mm ; 4.13x5.83 in)</li>
  1940. * <li>A7 (74x105 mm ; 2.91x4.13 in)</li>
  1941. * <li>A8 (52x74 mm ; 2.05x2.91 in)</li>
  1942. * <li>A9 (37x52 mm ; 1.46x2.05 in)</li>
  1943. * <li>A10 (26x37 mm ; 1.02x1.46 in)</li>
  1944. * <li>A11 (18x26 mm ; 0.71x1.02 in)</li>
  1945. * <li>A12 (13x18 mm ; 0.51x0.71 in)</li>
  1946. * <li><b>ISO 216 B Series + 2 SIS 014711 extensions</b></li>
  1947. * <li>B0 (1000x1414 mm ; 39.37x55.67 in)</li>
  1948. * <li>B1 (707x1000 mm ; 27.83x39.37 in)</li>
  1949. * <li>B2 (500x707 mm ; 19.69x27.83 in)</li>
  1950. * <li>B3 (353x500 mm ; 13.90x19.69 in)</li>
  1951. * <li>B4 (250x353 mm ; 9.84x13.90 in)</li>
  1952. * <li>B5 (176x250 mm ; 6.93x9.84 in)</li>
  1953. * <li>B6 (125x176 mm ; 4.92x6.93 in)</li>
  1954. * <li>B7 (88x125 mm ; 3.46x4.92 in)</li>
  1955. * <li>B8 (62x88 mm ; 2.44x3.46 in)</li>
  1956. * <li>B9 (44x62 mm ; 1.73x2.44 in)</li>
  1957. * <li>B10 (31x44 mm ; 1.22x1.73 in)</li>
  1958. * <li>B11 (22x31 mm ; 0.87x1.22 in)</li>
  1959. * <li>B12 (15x22 mm ; 0.59x0.87 in)</li>
  1960. * <li><b>ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION</b></li>
  1961. * <li>C0 (917x1297 mm ; 36.10x51.06 in)</li>
  1962. * <li>C1 (648x917 mm ; 25.51x36.10 in)</li>
  1963. * <li>C2 (458x648 mm ; 18.03x25.51 in)</li>
  1964. * <li>C3 (324x458 mm ; 12.76x18.03 in)</li>
  1965. * <li>C4 (229x324 mm ; 9.02x12.76 in)</li>
  1966. * <li>C5 (162x229 mm ; 6.38x9.02 in)</li>
  1967. * <li>C6 (114x162 mm ; 4.49x6.38 in)</li>
  1968. * <li>C7 (81x114 mm ; 3.19x4.49 in)</li>
  1969. * <li>C8 (57x81 mm ; 2.24x3.19 in)</li>
  1970. * <li>C9 (40x57 mm ; 1.57x2.24 in)</li>
  1971. * <li>C10 (28x40 mm ; 1.10x1.57 in)</li>
  1972. * <li>C11 (20x28 mm ; 0.79x1.10 in)</li>
  1973. * <li>C12 (14x20 mm ; 0.55x0.79 in)</li>
  1974. * <li>C76 (81x162 mm ; 3.19x6.38 in)</li>
  1975. * <li>DL (110x220 mm ; 4.33x8.66 in)</li>
  1976. * <li><b>SIS 014711 E Series</b></li>
  1977. * <li>E0 (879x1241 mm ; 34.61x48.86 in)</li>
  1978. * <li>E1 (620x879 mm ; 24.41x34.61 in)</li>
  1979. * <li>E2 (440x620 mm ; 17.32x24.41 in)</li>
  1980. * <li>E3 (310x440 mm ; 12.20x17.32 in)</li>
  1981. * <li>E4 (220x310 mm ; 8.66x12.20 in)</li>
  1982. * <li>E5 (155x220 mm ; 6.10x8.66 in)</li>
  1983. * <li>E6 (110x155 mm ; 4.33x6.10 in)</li>
  1984. * <li>E7 (78x110 mm ; 3.07x4.33 in)</li>
  1985. * <li>E8 (55x78 mm ; 2.17x3.07 in)</li>
  1986. * <li>E9 (39x55 mm ; 1.54x2.17 in)</li>
  1987. * <li>E10 (27x39 mm ; 1.06x1.54 in)</li>
  1988. * <li>E11 (19x27 mm ; 0.75x1.06 in)</li>
  1989. * <li>E12 (13x19 mm ; 0.51x0.75 in)</li>
  1990. * <li><b>SIS 014711 G Series</b></li>
  1991. * <li>G0 (958x1354 mm ; 37.72x53.31 in)</li>
  1992. * <li>G1 (677x958 mm ; 26.65x37.72 in)</li>
  1993. * <li>G2 (479x677 mm ; 18.86x26.65 in)</li>
  1994. * <li>G3 (338x479 mm ; 13.31x18.86 in)</li>
  1995. * <li>G4 (239x338 mm ; 9.41x13.31 in)</li>
  1996. * <li>G5 (169x239 mm ; 6.65x9.41 in)</li>
  1997. * <li>G6 (119x169 mm ; 4.69x6.65 in)</li>
  1998. * <li>G7 (84x119 mm ; 3.31x4.69 in)</li>
  1999. * <li>G8 (59x84 mm ; 2.32x3.31 in)</li>
  2000. * <li>G9 (42x59 mm ; 1.65x2.32 in)</li>
  2001. * <li>G10 (29x42 mm ; 1.14x1.65 in)</li>
  2002. * <li>G11 (21x29 mm ; 0.83x1.14 in)</li>
  2003. * <li>G12 (14x21 mm ; 0.55x0.83 in)</li>
  2004. * <li><b>ISO Press</b></li>
  2005. * <li>RA0 (860x1220 mm ; 33.86x48.03 in)</li>
  2006. * <li>RA1 (610x860 mm ; 24.02x33.86 in)</li>
  2007. * <li>RA2 (430x610 mm ; 16.93x24.02 in)</li>
  2008. * <li>RA3 (305x430 mm ; 12.01x16.93 in)</li>
  2009. * <li>RA4 (215x305 mm ; 8.46x12.01 in)</li>
  2010. * <li>SRA0 (900x1280 mm ; 35.43x50.39 in)</li>
  2011. * <li>SRA1 (640x900 mm ; 25.20x35.43 in)</li>
  2012. * <li>SRA2 (450x640 mm ; 17.72x25.20 in)</li>
  2013. * <li>SRA3 (320x450 mm ; 12.60x17.72 in)</li>
  2014. * <li>SRA4 (225x320 mm ; 8.86x12.60 in)</li>
  2015. * <li><b>German DIN 476</b></li>
  2016. * <li>4A0 (1682x2378 mm ; 66.22x93.62 in)</li>
  2017. * <li>2A0 (1189x1682 mm ; 46.81x66.22 in)</li>
  2018. * <li><b>Variations on the ISO Standard</b></li>
  2019. * <li>A2_EXTRA (445x619 mm ; 17.52x24.37 in)</li>
  2020. * <li>A3+ (329x483 mm ; 12.95x19.02 in)</li>
  2021. * <li>A3_EXTRA (322x445 mm ; 12.68x17.52 in)</li>
  2022. * <li>A3_SUPER (305x508 mm ; 12.01x20.00 in)</li>
  2023. * <li>SUPER_A3 (305x487 mm ; 12.01x19.17 in)</li>
  2024. * <li>A4_EXTRA (235x322 mm ; 9.25x12.68 in)</li>
  2025. * <li>A4_SUPER (229x322 mm ; 9.02x12.68 in)</li>
  2026. * <li>SUPER_A4 (227x356 mm ; 8.94x14.02 in)</li>
  2027. * <li>A4_LONG (210x348 mm ; 8.27x13.70 in)</li>
  2028. * <li>F4 (210x330 mm ; 8.27x12.99 in)</li>
  2029. * <li>SO_B5_EXTRA (202x276 mm ; 7.95x10.87 in)</li>
  2030. * <li>A5_EXTRA (173x235 mm ; 6.81x9.25 in)</li>
  2031. * <li><b>ANSI Series</b></li>
  2032. * <li>ANSI_E (864x1118 mm ; 34.00x44.00 in)</li>
  2033. * <li>ANSI_D (559x864 mm ; 22.00x34.00 in)</li>
  2034. * <li>ANSI_C (432x559 mm ; 17.00x22.00 in)</li>
  2035. * <li>ANSI_B (279x432 mm ; 11.00x17.00 in)</li>
  2036. * <li>ANSI_A (216x279 mm ; 8.50x11.00 in)</li>
  2037. * <li><b>Traditional 'Loose' North American Paper Sizes</b></li>
  2038. * <li>LEDGER, USLEDGER (432x279 mm ; 17.00x11.00 in)</li>
  2039. * <li>TABLOID, USTABLOID, BIBLE, ORGANIZERK (279x432 mm ; 11.00x17.00 in)</li>
  2040. * <li>LETTER, USLETTER, ORGANIZERM (216x279 mm ; 8.50x11.00 in)</li>
  2041. * <li>LEGAL, USLEGAL (216x356 mm ; 8.50x14.00 in)</li>
  2042. * <li>GLETTER, GOVERNMENTLETTER (203x267 mm ; 8.00x10.50 in)</li>
  2043. * <li>JLEGAL, JUNIORLEGAL (203x127 mm ; 8.00x5.00 in)</li>
  2044. * <li><b>Other North American Paper Sizes</b></li>
  2045. * <li>QUADDEMY (889x1143 mm ; 35.00x45.00 in)</li>
  2046. * <li>SUPER_B (330x483 mm ; 13.00x19.00 in)</li>
  2047. * <li>QUARTO (229x279 mm ; 9.00x11.00 in)</li>
  2048. * <li>FOLIO, GOVERNMENTLEGAL (216x330 mm ; 8.50x13.00 in)</li>
  2049. * <li>EXECUTIVE, MONARCH (184x267 mm ; 7.25x10.50 in)</li>
  2050. * <li>MEMO, STATEMENT, ORGANIZERL (140x216 mm ; 5.50x8.50 in)</li>
  2051. * <li>FOOLSCAP (210x330 mm ; 8.27x13.00 in)</li>
  2052. * <li>COMPACT (108x171 mm ; 4.25x6.75 in)</li>
  2053. * <li>ORGANIZERJ (70x127 mm ; 2.75x5.00 in)</li>
  2054. * <li><b>Canadian standard CAN 2-9.60M</b></li>
  2055. * <li>P1 (560x860 mm ; 22.05x33.86 in)</li>
  2056. * <li>P2 (430x560 mm ; 16.93x22.05 in)</li>
  2057. * <li>P3 (280x430 mm ; 11.02x16.93 in)</li>
  2058. * <li>P4 (215x280 mm ; 8.46x11.02 in)</li>
  2059. * <li>P5 (140x215 mm ; 5.51x8.46 in)</li>
  2060. * <li>P6 (107x140 mm ; 4.21x5.51 in)</li>
  2061. * <li><b>North American Architectural Sizes</b></li>
  2062. * <li>ARCH_E (914x1219 mm ; 36.00x48.00 in)</li>
  2063. * <li>ARCH_E1 (762x1067 mm ; 30.00x42.00 in)</li>
  2064. * <li>ARCH_D (610x914 mm ; 24.00x36.00 in)</li>
  2065. * <li>ARCH_C, BROADSHEET (457x610 mm ; 18.00x24.00 in)</li>
  2066. * <li>ARCH_B (305x457 mm ; 12.00x18.00 in)</li>
  2067. * <li>ARCH_A (229x305 mm ; 9.00x12.00 in)</li>
  2068. * <li><b>Announcement Envelopes</b></li>
  2069. * <li>ANNENV_A2 (111x146 mm ; 4.37x5.75 in)</li>
  2070. * <li>ANNENV_A6 (121x165 mm ; 4.75x6.50 in)</li>
  2071. * <li>ANNENV_A7 (133x184 mm ; 5.25x7.25 in)</li>
  2072. * <li>ANNENV_A8 (140x206 mm ; 5.50x8.12 in)</li>
  2073. * <li>ANNENV_A10 (159x244 mm ; 6.25x9.62 in)</li>
  2074. * <li>ANNENV_SLIM (98x225 mm ; 3.87x8.87 in)</li>
  2075. * <li><b>Commercial Envelopes</b></li>
  2076. * <li>COMMENV_N6_1/4 (89x152 mm ; 3.50x6.00 in)</li>
  2077. * <li>COMMENV_N6_3/4 (92x165 mm ; 3.62x6.50 in)</li>
  2078. * <li>COMMENV_N8 (98x191 mm ; 3.87x7.50 in)</li>
  2079. * <li>COMMENV_N9 (98x225 mm ; 3.87x8.87 in)</li>
  2080. * <li>COMMENV_N10 (105x241 mm ; 4.12x9.50 in)</li>
  2081. * <li>COMMENV_N11 (114x263 mm ; 4.50x10.37 in)</li>
  2082. * <li>COMMENV_N12 (121x279 mm ; 4.75x11.00 in)</li>
  2083. * <li>COMMENV_N14 (127x292 mm ; 5.00x11.50 in)</li>
  2084. * <li><b>Catalogue Envelopes</b></li>
  2085. * <li>CATENV_N1 (152x229 mm ; 6.00x9.00 in)</li>
  2086. * <li>CATENV_N1_3/4 (165x241 mm ; 6.50x9.50 in)</li>
  2087. * <li>CATENV_N2 (165x254 mm ; 6.50x10.00 in)</li>
  2088. * <li>CATENV_N3 (178x254 mm ; 7.00x10.00 in)</li>
  2089. * <li>CATENV_N6 (191x267 mm ; 7.50x10.50 in)</li>
  2090. * <li>CATENV_N7 (203x279 mm ; 8.00x11.00 in)</li>
  2091. * <li>CATENV_N8 (210x286 mm ; 8.25x11.25 in)</li>
  2092. * <li>CATENV_N9_1/2 (216x267 mm ; 8.50x10.50 in)</li>
  2093. * <li>CATENV_N9_3/4 (222x286 mm ; 8.75x11.25 in)</li>
  2094. * <li>CATENV_N10_1/2 (229x305 mm ; 9.00x12.00 in)</li>
  2095. * <li>CATENV_N12_1/2 (241x318 mm ; 9.50x12.50 in)</li>
  2096. * <li>CATENV_N13_1/2 (254x330 mm ; 10.00x13.00 in)</li>
  2097. * <li>CATENV_N14_1/4 (286x311 mm ; 11.25x12.25 in)</li>
  2098. * <li>CATENV_N14_1/2 (292x368 mm ; 11.50x14.50 in)</li>
  2099. * <li><b>Japanese (JIS P 0138-61) Standard B-Series</b></li>
  2100. * <li>JIS_B0 (1030x1456 mm ; 40.55x57.32 in)</li>
  2101. * <li>JIS_B1 (728x1030 mm ; 28.66x40.55 in)</li>
  2102. * <li>JIS_B2 (515x728 mm ; 20.28x28.66 in)</li>
  2103. * <li>JIS_B3 (364x515 mm ; 14.33x20.28 in)</li>
  2104. * <li>JIS_B4 (257x364 mm ; 10.12x14.33 in)</li>
  2105. * <li>JIS_B5 (182x257 mm ; 7.17x10.12 in)</li>
  2106. * <li>JIS_B6 (128x182 mm ; 5.04x7.17 in)</li>
  2107. * <li>JIS_B7 (91x128 mm ; 3.58x5.04 in)</li>
  2108. * <li>JIS_B8 (64x91 mm ; 2.52x3.58 in)</li>
  2109. * <li>JIS_B9 (45x64 mm ; 1.77x2.52 in)</li>
  2110. * <li>JIS_B10 (32x45 mm ; 1.26x1.77 in)</li>
  2111. * <li>JIS_B11 (22x32 mm ; 0.87x1.26 in)</li>
  2112. * <li>JIS_B12 (16x22 mm ; 0.63x0.87 in)</li>
  2113. * <li><b>PA Series</b></li>
  2114. * <li>PA0 (840x1120 mm ; 33.07x44.09 in)</li>
  2115. * <li>PA1 (560x840 mm ; 22.05x33.07 in)</li>
  2116. * <li>PA2 (420x560 mm ; 16.54x22.05 in)</li>
  2117. * <li>PA3 (280x420 mm ; 11.02x16.54 in)</li>
  2118. * <li>PA4 (210x280 mm ; 8.27x11.02 in)</li>
  2119. * <li>PA5 (140x210 mm ; 5.51x8.27 in)</li>
  2120. * <li>PA6 (105x140 mm ; 4.13x5.51 in)</li>
  2121. * <li>PA7 (70x105 mm ; 2.76x4.13 in)</li>
  2122. * <li>PA8 (52x70 mm ; 2.05x2.76 in)</li>
  2123. * <li>PA9 (35x52 mm ; 1.38x2.05 in)</li>
  2124. * <li>PA10 (26x35 mm ; 1.02x1.38 in)</li>
  2125. * <li><b>Standard Photographic Print Sizes</b></li>
  2126. * <li>PASSPORT_PHOTO (35x45 mm ; 1.38x1.77 in)</li>
  2127. * <li>E (82x120 mm ; 3.25x4.72 in)</li>
  2128. * <li>3R, L (89x127 mm ; 3.50x5.00 in)</li>
  2129. * <li>4R, KG (102x152 mm ; 4.02x5.98 in)</li>
  2130. * <li>4D (120x152 mm ; 4.72x5.98 in)</li>
  2131. * <li>5R, 2L (127x178 mm ; 5.00x7.01 in)</li>
  2132. * <li>6R, 8P (152x203 mm ; 5.98x7.99 in)</li>
  2133. * <li>8R, 6P (203x254 mm ; 7.99x10.00 in)</li>
  2134. * <li>S8R, 6PW (203x305 mm ; 7.99x12.01 in)</li>
  2135. * <li>10R, 4P (254x305 mm ; 10.00x12.01 in)</li>
  2136. * <li>S10R, 4PW (254x381 mm ; 10.00x15.00 in)</li>
  2137. * <li>11R (279x356 mm ; 10.98x14.02 in)</li>
  2138. * <li>S11R (279x432 mm ; 10.98x17.01 in)</li>
  2139. * <li>12R (305x381 mm ; 12.01x15.00 in)</li>
  2140. * <li>S12R (305x456 mm ; 12.01x17.95 in)</li>
  2141. * <li><b>Common Newspaper Sizes</b></li>
  2142. * <li>NEWSPAPER_BROADSHEET (750x600 mm ; 29.53x23.62 in)</li>
  2143. * <li>NEWSPAPER_BERLINER (470x315 mm ; 18.50x12.40 in)</li>
  2144. * <li>NEWSPAPER_COMPACT, NEWSPAPER_TABLOID (430x280 mm ; 16.93x11.02 in)</li>
  2145. * <li><b>Business Cards</b></li>
  2146. * <li>CREDIT_CARD, BUSINESS_CARD, BUSINESS_CARD_ISO7810 (54x86 mm ; 2.13x3.37 in)</li>
  2147. * <li>BUSINESS_CARD_ISO216 (52x74 mm ; 2.05x2.91 in)</li>
  2148. * <li>BUSINESS_CARD_IT, BUSINESS_CARD_UK, BUSINESS_CARD_FR, BUSINESS_CARD_DE, BUSINESS_CARD_ES (55x85 mm ; 2.17x3.35 in)</li>
  2149. * <li>BUSINESS_CARD_US, BUSINESS_CARD_CA (51x89 mm ; 2.01x3.50 in)</li>
  2150. * <li>BUSINESS_CARD_JP (55x91 mm ; 2.17x3.58 in)</li>
  2151. * <li>BUSINESS_CARD_HK (54x90 mm ; 2.13x3.54 in)</li>
  2152. * <li>BUSINESS_CARD_AU, BUSINESS_CARD_DK, BUSINESS_CARD_SE (55x90 mm ; 2.17x3.54 in)</li>
  2153. * <li>BUSINESS_CARD_RU, BUSINESS_CARD_CZ, BUSINESS_CARD_FI, BUSINESS_CARD_HU, BUSINESS_CARD_IL (50x90 mm ; 1.97x3.54 in)</li>
  2154. * <li><b>Billboards</b></li>
  2155. * <li>4SHEET (1016x1524 mm ; 40.00x60.00 in)</li>
  2156. * <li>6SHEET (1200x1800 mm ; 47.24x70.87 in)</li>
  2157. * <li>12SHEET (3048x1524 mm ; 120.00x60.00 in)</li>
  2158. * <li>16SHEET (2032x3048 mm ; 80.00x120.00 in)</li>
  2159. * <li>32SHEET (4064x3048 mm ; 160.00x120.00 in)</li>
  2160. * <li>48SHEET (6096x3048 mm ; 240.00x120.00 in)</li>
  2161. * <li>64SHEET (8128x3048 mm ; 320.00x120.00 in)</li>
  2162. * <li>96SHEET (12192x3048 mm ; 480.00x120.00 in)</li>
  2163. * <li><b>Old Imperial English (some are still used in USA)</b></li>
  2164. * <li>EN_EMPEROR (1219x1829 mm ; 48.00x72.00 in)</li>
  2165. * <li>EN_ANTIQUARIAN (787x1346 mm ; 31.00x53.00 in)</li>
  2166. * <li>EN_GRAND_EAGLE (730x1067 mm ; 28.75x42.00 in)</li>
  2167. * <li>EN_DOUBLE_ELEPHANT (679x1016 mm ; 26.75x40.00 in)</li>
  2168. * <li>EN_ATLAS (660x864 mm ; 26.00x34.00 in)</li>
  2169. * <li>EN_COLOMBIER (597x876 mm ; 23.50x34.50 in)</li>
  2170. * <li>EN_ELEPHANT (584x711 mm ; 23.00x28.00 in)</li>
  2171. * <li>EN_DOUBLE_DEMY (572x902 mm ; 22.50x35.50 in)</li>
  2172. * <li>EN_IMPERIAL (559x762 mm ; 22.00x30.00 in)</li>
  2173. * <li>EN_PRINCESS (546x711 mm ; 21.50x28.00 in)</li>
  2174. * <li>EN_CARTRIDGE (533x660 mm ; 21.00x26.00 in)</li>
  2175. * <li>EN_DOUBLE_LARGE_POST (533x838 mm ; 21.00x33.00 in)</li>
  2176. * <li>EN_ROYAL (508x635 mm ; 20.00x25.00 in)</li>
  2177. * <li>EN_SHEET, EN_HALF_POST (495x597 mm ; 19.50x23.50 in)</li>
  2178. * <li>EN_SUPER_ROYAL (483x686 mm ; 19.00x27.00 in)</li>
  2179. * <li>EN_DOUBLE_POST (483x775 mm ; 19.00x30.50 in)</li>
  2180. * <li>EN_MEDIUM (445x584 mm ; 17.50x23.00 in)</li>
  2181. * <li>EN_DEMY (445x572 mm ; 17.50x22.50 in)</li>
  2182. * <li>EN_LARGE_POST (419x533 mm ; 16.50x21.00 in)</li>
  2183. * <li>EN_COPY_DRAUGHT (406x508 mm ; 16.00x20.00 in)</li>
  2184. * <li>EN_POST (394x489 mm ; 15.50x19.25 in)</li>
  2185. * <li>EN_CROWN (381x508 mm ; 15.00x20.00 in)</li>
  2186. * <li>EN_PINCHED_POST (375x470 mm ; 14.75x18.50 in)</li>
  2187. * <li>EN_BRIEF (343x406 mm ; 13.50x16.00 in)</li>
  2188. * <li>EN_FOOLSCAP (343x432 mm ; 13.50x17.00 in)</li>
  2189. * <li>EN_SMALL_FOOLSCAP (337x419 mm ; 13.25x16.50 in)</li>
  2190. * <li>EN_POTT (318x381 mm ; 12.50x15.00 in)</li>
  2191. * <li><b>Old Imperial Belgian</b></li>
  2192. * <li>BE_GRAND_AIGLE (700x1040 mm ; 27.56x40.94 in)</li>
  2193. * <li>BE_COLOMBIER (620x850 mm ; 24.41x33.46 in)</li>
  2194. * <li>BE_DOUBLE_CARRE (620x920 mm ; 24.41x36.22 in)</li>
  2195. * <li>BE_ELEPHANT (616x770 mm ; 24.25x30.31 in)</li>
  2196. * <li>BE_PETIT_AIGLE (600x840 mm ; 23.62x33.07 in)</li>
  2197. * <li>BE_GRAND_JESUS (550x730 mm ; 21.65x28.74 in)</li>
  2198. * <li>BE_JESUS (540x730 mm ; 21.26x28.74 in)</li>
  2199. * <li>BE_RAISIN (500x650 mm ; 19.69x25.59 in)</li>
  2200. * <li>BE_GRAND_MEDIAN (460x605 mm ; 18.11x23.82 in)</li>
  2201. * <li>BE_DOUBLE_POSTE (435x565 mm ; 17.13x22.24 in)</li>
  2202. * <li>BE_COQUILLE (430x560 mm ; 16.93x22.05 in)</li>
  2203. * <li>BE_PETIT_MEDIAN (415x530 mm ; 16.34x20.87 in)</li>
  2204. * <li>BE_RUCHE (360x460 mm ; 14.17x18.11 in)</li>
  2205. * <li>BE_PROPATRIA (345x430 mm ; 13.58x16.93 in)</li>
  2206. * <li>BE_LYS (317x397 mm ; 12.48x15.63 in)</li>
  2207. * <li>BE_POT (307x384 mm ; 12.09x15.12 in)</li>
  2208. * <li>BE_ROSETTE (270x347 mm ; 10.63x13.66 in)</li>
  2209. * <li><b>Old Imperial French</b></li>
  2210. * <li>FR_UNIVERS (1000x1300 mm ; 39.37x51.18 in)</li>
  2211. * <li>FR_DOUBLE_COLOMBIER (900x1260 mm ; 35.43x49.61 in)</li>
  2212. * <li>FR_GRANDE_MONDE (900x1260 mm ; 35.43x49.61 in)</li>
  2213. * <li>FR_DOUBLE_SOLEIL (800x1200 mm ; 31.50x47.24 in)</li>
  2214. * <li>FR_DOUBLE_JESUS (760x1120 mm ; 29.92x44.09 in)</li>
  2215. * <li>FR_GRAND_AIGLE (750x1060 mm ; 29.53x41.73 in)</li>
  2216. * <li>FR_PETIT_AIGLE (700x940 mm ; 27.56x37.01 in)</li>
  2217. * <li>FR_DOUBLE_RAISIN (650x1000 mm ; 25.59x39.37 in)</li>
  2218. * <li>FR_JOURNAL (650x940 mm ; 25.59x37.01 in)</li>
  2219. * <li>FR_COLOMBIER_AFFICHE (630x900 mm ; 24.80x35.43 in)</li>
  2220. * <li>FR_DOUBLE_CAVALIER (620x920 mm ; 24.41x36.22 in)</li>
  2221. * <li>FR_CLOCHE (600x800 mm ; 23.62x31.50 in)</li>
  2222. * <li>FR_SOLEIL (600x800 mm ; 23.62x31.50 in)</li>
  2223. * <li>FR_DOUBLE_CARRE (560x900 mm ; 22.05x35.43 in)</li>
  2224. * <li>FR_DOUBLE_COQUILLE (560x880 mm ; 22.05x34.65 in)</li>
  2225. * <li>FR_JESUS (560x760 mm ; 22.05x29.92 in)</li>
  2226. * <li>FR_RAISIN (500x650 mm ; 19.69x25.59 in)</li>
  2227. * <li>FR_CAVALIER (460x620 mm ; 18.11x24.41 in)</li>
  2228. * <li>FR_DOUBLE_COURONNE (460x720 mm ; 18.11x28.35 in)</li>
  2229. * <li>FR_CARRE (450x560 mm ; 17.72x22.05 in)</li>
  2230. * <li>FR_COQUILLE (440x560 mm ; 17.32x22.05 in)</li>
  2231. * <li>FR_DOUBLE_TELLIERE (440x680 mm ; 17.32x26.77 in)</li>
  2232. * <li>FR_DOUBLE_CLOCHE (400x600 mm ; 15.75x23.62 in)</li>
  2233. * <li>FR_DOUBLE_POT (400x620 mm ; 15.75x24.41 in)</li>
  2234. * <li>FR_ECU (400x520 mm ; 15.75x20.47 in)</li>
  2235. * <li>FR_COURONNE (360x460 mm ; 14.17x18.11 in)</li>
  2236. * <li>FR_TELLIERE (340x440 mm ; 13.39x17.32 in)</li>
  2237. * <li>FR_POT (310x400 mm ; 12.20x15.75 in)</li>
  2238. * </ul>
  2239. * @return array containing page width and height in points
  2240. * @public
  2241. * @since 5.0.010 (2010-05-17)
  2242. */
  2243. public function getPageSizeFromFormat($format) {
  2244. // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 25.4 mm)
  2245. switch (strtoupper($format)) {
  2246. // ISO 216 A Series + 2 SIS 014711 extensions
  2247. case 'A0' : {$pf = array( 2383.937, 3370.394); break;}
  2248. case 'A1' : {$pf = array( 1683.780, 2383.937); break;}
  2249. case 'A2' : {$pf = array( 1190.551, 1683.780); break;}
  2250. case 'A3' : {$pf = array( 841.890, 1190.551); break;}
  2251. case 'A4' : {$pf = array( 595.276, 841.890); break;}
  2252. case 'A5' : {$pf = array( 419.528, 595.276); break;}
  2253. case 'A6' : {$pf = array( 297.638, 419.528); break;}
  2254. case 'A7' : {$pf = array( 209.764, 297.638); break;}
  2255. case 'A8' : {$pf = array( 147.402, 209.764); break;}
  2256. case 'A9' : {$pf = array( 104.882, 147.402); break;}
  2257. case 'A10': {$pf = array( 73.701, 104.882); break;}
  2258. case 'A11': {$pf = array( 51.024, 73.701); break;}
  2259. case 'A12': {$pf = array( 36.850, 51.024); break;}
  2260. // ISO 216 B Series + 2 SIS 014711 extensions
  2261. case 'B0' : {$pf = array( 2834.646, 4008.189); break;}
  2262. case 'B1' : {$pf = array( 2004.094, 2834.646); break;}
  2263. case 'B2' : {$pf = array( 1417.323, 2004.094); break;}
  2264. case 'B3' : {$pf = array( 1000.630, 1417.323); break;}
  2265. case 'B4' : {$pf = array( 708.661, 1000.630); break;}
  2266. case 'B5' : {$pf = array( 498.898, 708.661); break;}
  2267. case 'B6' : {$pf = array( 354.331, 498.898); break;}
  2268. case 'B7' : {$pf = array( 249.449, 354.331); break;}
  2269. case 'B8' : {$pf = array( 175.748, 249.449); break;}
  2270. case 'B9' : {$pf = array( 124.724, 175.748); break;}
  2271. case 'B10': {$pf = array( 87.874, 124.724); break;}
  2272. case 'B11': {$pf = array( 62.362, 87.874); break;}
  2273. case 'B12': {$pf = array( 42.520, 62.362); break;}
  2274. // ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION
  2275. case 'C0' : {$pf = array( 2599.370, 3676.535); break;}
  2276. case 'C1' : {$pf = array( 1836.850, 2599.370); break;}
  2277. case 'C2' : {$pf = array( 1298.268, 1836.850); break;}
  2278. case 'C3' : {$pf = array( 918.425, 1298.268); break;}
  2279. case 'C4' : {$pf = array( 649.134, 918.425); break;}
  2280. case 'C5' : {$pf = array( 459.213, 649.134); break;}
  2281. case 'C6' : {$pf = array( 323.150, 459.213); break;}
  2282. case 'C7' : {$pf = array( 229.606, 323.150); break;}
  2283. case 'C8' : {$pf = array( 161.575, 229.606); break;}
  2284. case 'C9' : {$pf = array( 113.386, 161.575); break;}
  2285. case 'C10': {$pf = array( 79.370, 113.386); break;}
  2286. case 'C11': {$pf = array( 56.693, 79.370); break;}
  2287. case 'C12': {$pf = array( 39.685, 56.693); break;}
  2288. case 'C76': {$pf = array( 229.606, 459.213); break;}
  2289. case 'DL' : {$pf = array( 311.811, 623.622); break;}
  2290. // SIS 014711 E Series
  2291. case 'E0' : {$pf = array( 2491.654, 3517.795); break;}
  2292. case 'E1' : {$pf = array( 1757.480, 2491.654); break;}
  2293. case 'E2' : {$pf = array( 1247.244, 1757.480); break;}
  2294. case 'E3' : {$pf = array( 878.740, 1247.244); break;}
  2295. case 'E4' : {$pf = array( 623.622, 878.740); break;}
  2296. case 'E5' : {$pf = array( 439.370, 623.622); break;}
  2297. case 'E6' : {$pf = array( 311.811, 439.370); break;}
  2298. case 'E7' : {$pf = array( 221.102, 311.811); break;}
  2299. case 'E8' : {$pf = array( 155.906, 221.102); break;}
  2300. case 'E9' : {$pf = array( 110.551, 155.906); break;}
  2301. case 'E10': {$pf = array( 76.535, 110.551); break;}
  2302. case 'E11': {$pf = array( 53.858, 76.535); break;}
  2303. case 'E12': {$pf = array( 36.850, 53.858); break;}
  2304. // SIS 014711 G Series
  2305. case 'G0' : {$pf = array( 2715.591, 3838.110); break;}
  2306. case 'G1' : {$pf = array( 1919.055, 2715.591); break;}
  2307. case 'G2' : {$pf = array( 1357.795, 1919.055); break;}
  2308. case 'G3' : {$pf = array( 958.110, 1357.795); break;}
  2309. case 'G4' : {$pf = array( 677.480, 958.110); break;}
  2310. case 'G5' : {$pf = array( 479.055, 677.480); break;}
  2311. case 'G6' : {$pf = array( 337.323, 479.055); break;}
  2312. case 'G7' : {$pf = array( 238.110, 337.323); break;}
  2313. case 'G8' : {$pf = array( 167.244, 238.110); break;}
  2314. case 'G9' : {$pf = array( 119.055, 167.244); break;}
  2315. case 'G10': {$pf = array( 82.205, 119.055); break;}
  2316. case 'G11': {$pf = array( 59.528, 82.205); break;}
  2317. case 'G12': {$pf = array( 39.685, 59.528); break;}
  2318. // ISO Press
  2319. case 'RA0': {$pf = array( 2437.795, 3458.268); break;}
  2320. case 'RA1': {$pf = array( 1729.134, 2437.795); break;}
  2321. case 'RA2': {$pf = array( 1218.898, 1729.134); break;}
  2322. case 'RA3': {$pf = array( 864.567, 1218.898); break;}
  2323. case 'RA4': {$pf = array( 609.449, 864.567); break;}
  2324. case 'SRA0': {$pf = array( 2551.181, 3628.346); break;}
  2325. case 'SRA1': {$pf = array( 1814.173, 2551.181); break;}
  2326. case 'SRA2': {$pf = array( 1275.591, 1814.173); break;}
  2327. case 'SRA3': {$pf = array( 907.087, 1275.591); break;}
  2328. case 'SRA4': {$pf = array( 637.795, 907.087); break;}
  2329. // German DIN 476
  2330. case '4A0': {$pf = array( 4767.874, 6740.787); break;}
  2331. case '2A0': {$pf = array( 3370.394, 4767.874); break;}
  2332. // Variations on the ISO Standard
  2333. case 'A2_EXTRA' : {$pf = array( 1261.417, 1754.646); break;}
  2334. case 'A3+' : {$pf = array( 932.598, 1369.134); break;}
  2335. case 'A3_EXTRA' : {$pf = array( 912.756, 1261.417); break;}
  2336. case 'A3_SUPER' : {$pf = array( 864.567, 1440.000); break;}
  2337. case 'SUPER_A3' : {$pf = array( 864.567, 1380.472); break;}
  2338. case 'A4_EXTRA' : {$pf = array( 666.142, 912.756); break;}
  2339. case 'A4_SUPER' : {$pf = array( 649.134, 912.756); break;}
  2340. case 'SUPER_A4' : {$pf = array( 643.465, 1009.134); break;}
  2341. case 'A4_LONG' : {$pf = array( 595.276, 986.457); break;}
  2342. case 'F4' : {$pf = array( 595.276, 935.433); break;}
  2343. case 'SO_B5_EXTRA': {$pf = array( 572.598, 782.362); break;}
  2344. case 'A5_EXTRA' : {$pf = array( 490.394, 666.142); break;}
  2345. // ANSI Series
  2346. case 'ANSI_E': {$pf = array( 2448.000, 3168.000); break;}
  2347. case 'ANSI_D': {$pf = array( 1584.000, 2448.000); break;}
  2348. case 'ANSI_C': {$pf = array( 1224.000, 1584.000); break;}
  2349. case 'ANSI_B': {$pf = array( 792.000, 1224.000); break;}
  2350. case 'ANSI_A': {$pf = array( 612.000, 792.000); break;}
  2351. // Traditional 'Loose' North American Paper Sizes
  2352. case 'USLEDGER':
  2353. case 'LEDGER' : {$pf = array( 1224.000, 792.000); break;}
  2354. case 'ORGANIZERK':
  2355. case 'BIBLE':
  2356. case 'USTABLOID':
  2357. case 'TABLOID': {$pf = array( 792.000, 1224.000); break;}
  2358. case 'ORGANIZERM':
  2359. case 'USLETTER':
  2360. case 'LETTER' : {$pf = array( 612.000, 792.000); break;}
  2361. case 'USLEGAL':
  2362. case 'LEGAL' : {$pf = array( 612.000, 1008.000); break;}
  2363. case 'GOVERNMENTLETTER':
  2364. case 'GLETTER': {$pf = array( 576.000, 756.000); break;}
  2365. case 'JUNIORLEGAL':
  2366. case 'JLEGAL' : {$pf = array( 576.000, 360.000); break;}
  2367. // Other North American Paper Sizes
  2368. case 'QUADDEMY': {$pf = array( 2520.000, 3240.000); break;}
  2369. case 'SUPER_B': {$pf = array( 936.000, 1368.000); break;}
  2370. case 'QUARTO': {$pf = array( 648.000, 792.000); break;}
  2371. case 'GOVERNMENTLEGAL':
  2372. case 'FOLIO': {$pf = array( 612.000, 936.000); break;}
  2373. case 'MONARCH':
  2374. case 'EXECUTIVE': {$pf = array( 522.000, 756.000); break;}
  2375. case 'ORGANIZERL':
  2376. case 'STATEMENT':
  2377. case 'MEMO': {$pf = array( 396.000, 612.000); break;}
  2378. case 'FOOLSCAP': {$pf = array( 595.440, 936.000); break;}
  2379. case 'COMPACT': {$pf = array( 306.000, 486.000); break;}
  2380. case 'ORGANIZERJ': {$pf = array( 198.000, 360.000); break;}
  2381. // Canadian standard CAN 2-9.60M
  2382. case 'P1': {$pf = array( 1587.402, 2437.795); break;}
  2383. case 'P2': {$pf = array( 1218.898, 1587.402); break;}
  2384. case 'P3': {$pf = array( 793.701, 1218.898); break;}
  2385. case 'P4': {$pf = array( 609.449, 793.701); break;}
  2386. case 'P5': {$pf = array( 396.850, 609.449); break;}
  2387. case 'P6': {$pf = array( 303.307, 396.850); break;}
  2388. // North American Architectural Sizes
  2389. case 'ARCH_E' : {$pf = array( 2592.000, 3456.000); break;}
  2390. case 'ARCH_E1': {$pf = array( 2160.000, 3024.000); break;}
  2391. case 'ARCH_D' : {$pf = array( 1728.000, 2592.000); break;}
  2392. case 'BROADSHEET':
  2393. case 'ARCH_C' : {$pf = array( 1296.000, 1728.000); break;}
  2394. case 'ARCH_B' : {$pf = array( 864.000, 1296.000); break;}
  2395. case 'ARCH_A' : {$pf = array( 648.000, 864.000); break;}
  2396. // --- North American Envelope Sizes ---
  2397. // - Announcement Envelopes
  2398. case 'ANNENV_A2' : {$pf = array( 314.640, 414.000); break;}
  2399. case 'ANNENV_A6' : {$pf = array( 342.000, 468.000); break;}
  2400. case 'ANNENV_A7' : {$pf = array( 378.000, 522.000); break;}
  2401. case 'ANNENV_A8' : {$pf = array( 396.000, 584.640); break;}
  2402. case 'ANNENV_A10' : {$pf = array( 450.000, 692.640); break;}
  2403. case 'ANNENV_SLIM': {$pf = array( 278.640, 638.640); break;}
  2404. // - Commercial Envelopes
  2405. case 'COMMENV_N6_1/4': {$pf = array( 252.000, 432.000); break;}
  2406. case 'COMMENV_N6_3/4': {$pf = array( 260.640, 468.000); break;}
  2407. case 'COMMENV_N8' : {$pf = array( 278.640, 540.000); break;}
  2408. case 'COMMENV_N9' : {$pf = array( 278.640, 638.640); break;}
  2409. case 'COMMENV_N10' : {$pf = array( 296.640, 684.000); break;}
  2410. case 'COMMENV_N11' : {$pf = array( 324.000, 746.640); break;}
  2411. case 'COMMENV_N12' : {$pf = array( 342.000, 792.000); break;}
  2412. case 'COMMENV_N14' : {$pf = array( 360.000, 828.000); break;}
  2413. // - Catalogue Envelopes
  2414. case 'CATENV_N1' : {$pf = array( 432.000, 648.000); break;}
  2415. case 'CATENV_N1_3/4' : {$pf = array( 468.000, 684.000); break;}
  2416. case 'CATENV_N2' : {$pf = array( 468.000, 720.000); break;}
  2417. case 'CATENV_N3' : {$pf = array( 504.000, 720.000); break;}
  2418. case 'CATENV_N6' : {$pf = array( 540.000, 756.000); break;}
  2419. case 'CATENV_N7' : {$pf = array( 576.000, 792.000); break;}
  2420. case 'CATENV_N8' : {$pf = array( 594.000, 810.000); break;}
  2421. case 'CATENV_N9_1/2' : {$pf = array( 612.000, 756.000); break;}
  2422. case 'CATENV_N9_3/4' : {$pf = array( 630.000, 810.000); break;}
  2423. case 'CATENV_N10_1/2': {$pf = array( 648.000, 864.000); break;}
  2424. case 'CATENV_N12_1/2': {$pf = array( 684.000, 900.000); break;}
  2425. case 'CATENV_N13_1/2': {$pf = array( 720.000, 936.000); break;}
  2426. case 'CATENV_N14_1/4': {$pf = array( 810.000, 882.000); break;}
  2427. case 'CATENV_N14_1/2': {$pf = array( 828.000, 1044.000); break;}
  2428. // Japanese (JIS P 0138-61) Standard B-Series
  2429. case 'JIS_B0' : {$pf = array( 2919.685, 4127.244); break;}
  2430. case 'JIS_B1' : {$pf = array( 2063.622, 2919.685); break;}
  2431. case 'JIS_B2' : {$pf = array( 1459.843, 2063.622); break;}
  2432. case 'JIS_B3' : {$pf = array( 1031.811, 1459.843); break;}
  2433. case 'JIS_B4' : {$pf = array( 728.504, 1031.811); break;}
  2434. case 'JIS_B5' : {$pf = array( 515.906, 728.504); break;}
  2435. case 'JIS_B6' : {$pf = array( 362.835, 515.906); break;}
  2436. case 'JIS_B7' : {$pf = array( 257.953, 362.835); break;}
  2437. case 'JIS_B8' : {$pf = array( 181.417, 257.953); break;}
  2438. case 'JIS_B9' : {$pf = array( 127.559, 181.417); break;}
  2439. case 'JIS_B10': {$pf = array( 90.709, 127.559); break;}
  2440. case 'JIS_B11': {$pf = array( 62.362, 90.709); break;}
  2441. case 'JIS_B12': {$pf = array( 45.354, 62.362); break;}
  2442. // PA Series
  2443. case 'PA0' : {$pf = array( 2381.102, 3174.803,); break;}
  2444. case 'PA1' : {$pf = array( 1587.402, 2381.102); break;}
  2445. case 'PA2' : {$pf = array( 1190.551, 1587.402); break;}
  2446. case 'PA3' : {$pf = array( 793.701, 1190.551); break;}
  2447. case 'PA4' : {$pf = array( 595.276, 793.701); break;}
  2448. case 'PA5' : {$pf = array( 396.850, 595.276); break;}
  2449. case 'PA6' : {$pf = array( 297.638, 396.850); break;}
  2450. case 'PA7' : {$pf = array( 198.425, 297.638); break;}
  2451. case 'PA8' : {$pf = array( 147.402, 198.425); break;}
  2452. case 'PA9' : {$pf = array( 99.213, 147.402); break;}
  2453. case 'PA10': {$pf = array( 73.701, 99.213); break;}
  2454. // Standard Photographic Print Sizes
  2455. case 'PASSPORT_PHOTO': {$pf = array( 99.213, 127.559); break;}
  2456. case 'E' : {$pf = array( 233.858, 340.157); break;}
  2457. case 'L':
  2458. case '3R' : {$pf = array( 252.283, 360.000); break;}
  2459. case 'KG':
  2460. case '4R' : {$pf = array( 289.134, 430.866); break;}
  2461. case '4D' : {$pf = array( 340.157, 430.866); break;}
  2462. case '2L':
  2463. case '5R' : {$pf = array( 360.000, 504.567); break;}
  2464. case '8P':
  2465. case '6R' : {$pf = array( 430.866, 575.433); break;}
  2466. case '6P':
  2467. case '8R' : {$pf = array( 575.433, 720.000); break;}
  2468. case '6PW':
  2469. case 'S8R' : {$pf = array( 575.433, 864.567); break;}
  2470. case '4P':
  2471. case '10R' : {$pf = array( 720.000, 864.567); break;}
  2472. case '4PW':
  2473. case 'S10R': {$pf = array( 720.000, 1080.000); break;}
  2474. case '11R' : {$pf = array( 790.866, 1009.134); break;}
  2475. case 'S11R': {$pf = array( 790.866, 1224.567); break;}
  2476. case '12R' : {$pf = array( 864.567, 1080.000); break;}
  2477. case 'S12R': {$pf = array( 864.567, 1292.598); break;}
  2478. // Common Newspaper Sizes
  2479. case 'NEWSPAPER_BROADSHEET': {$pf = array( 2125.984, 1700.787); break;}
  2480. case 'NEWSPAPER_BERLINER' : {$pf = array( 1332.283, 892.913); break;}
  2481. case 'NEWSPAPER_TABLOID':
  2482. case 'NEWSPAPER_COMPACT' : {$pf = array( 1218.898, 793.701); break;}
  2483. // Business Cards
  2484. case 'CREDIT_CARD':
  2485. case 'BUSINESS_CARD':
  2486. case 'BUSINESS_CARD_ISO7810': {$pf = array( 153.014, 242.646); break;}
  2487. case 'BUSINESS_CARD_ISO216' : {$pf = array( 147.402, 209.764); break;}
  2488. case 'BUSINESS_CARD_IT':
  2489. case 'BUSINESS_CARD_UK':
  2490. case 'BUSINESS_CARD_FR':
  2491. case 'BUSINESS_CARD_DE':
  2492. case 'BUSINESS_CARD_ES' : {$pf = array( 155.906, 240.945); break;}
  2493. case 'BUSINESS_CARD_CA':
  2494. case 'BUSINESS_CARD_US' : {$pf = array( 144.567, 252.283); break;}
  2495. case 'BUSINESS_CARD_JP' : {$pf = array( 155.906, 257.953); break;}
  2496. case 'BUSINESS_CARD_HK' : {$pf = array( 153.071, 255.118); break;}
  2497. case 'BUSINESS_CARD_AU':
  2498. case 'BUSINESS_CARD_DK':
  2499. case 'BUSINESS_CARD_SE' : {$pf = array( 155.906, 255.118); break;}
  2500. case 'BUSINESS_CARD_RU':
  2501. case 'BUSINESS_CARD_CZ':
  2502. case 'BUSINESS_CARD_FI':
  2503. case 'BUSINESS_CARD_HU':
  2504. case 'BUSINESS_CARD_IL' : {$pf = array( 141.732, 255.118); break;}
  2505. // Billboards
  2506. case '4SHEET' : {$pf = array( 2880.000, 4320.000); break;}
  2507. case '6SHEET' : {$pf = array( 3401.575, 5102.362); break;}
  2508. case '12SHEET': {$pf = array( 8640.000, 4320.000); break;}
  2509. case '16SHEET': {$pf = array( 5760.000, 8640.000); break;}
  2510. case '32SHEET': {$pf = array(11520.000, 8640.000); break;}
  2511. case '48SHEET': {$pf = array(17280.000, 8640.000); break;}
  2512. case '64SHEET': {$pf = array(23040.000, 8640.000); break;}
  2513. case '96SHEET': {$pf = array(34560.000, 8640.000); break;}
  2514. // Old European Sizes
  2515. // - Old Imperial English Sizes
  2516. case 'EN_EMPEROR' : {$pf = array( 3456.000, 5184.000); break;}
  2517. case 'EN_ANTIQUARIAN' : {$pf = array( 2232.000, 3816.000); break;}
  2518. case 'EN_GRAND_EAGLE' : {$pf = array( 2070.000, 3024.000); break;}
  2519. case 'EN_DOUBLE_ELEPHANT' : {$pf = array( 1926.000, 2880.000); break;}
  2520. case 'EN_ATLAS' : {$pf = array( 1872.000, 2448.000); break;}
  2521. case 'EN_COLOMBIER' : {$pf = array( 1692.000, 2484.000); break;}
  2522. case 'EN_ELEPHANT' : {$pf = array( 1656.000, 2016.000); break;}
  2523. case 'EN_DOUBLE_DEMY' : {$pf = array( 1620.000, 2556.000); break;}
  2524. case 'EN_IMPERIAL' : {$pf = array( 1584.000, 2160.000); break;}
  2525. case 'EN_PRINCESS' : {$pf = array( 1548.000, 2016.000); break;}
  2526. case 'EN_CARTRIDGE' : {$pf = array( 1512.000, 1872.000); break;}
  2527. case 'EN_DOUBLE_LARGE_POST': {$pf = array( 1512.000, 2376.000); break;}
  2528. case 'EN_ROYAL' : {$pf = array( 1440.000, 1800.000); break;}
  2529. case 'EN_SHEET':
  2530. case 'EN_HALF_POST' : {$pf = array( 1404.000, 1692.000); break;}
  2531. case 'EN_SUPER_ROYAL' : {$pf = array( 1368.000, 1944.000); break;}
  2532. case 'EN_DOUBLE_POST' : {$pf = array( 1368.000, 2196.000); break;}
  2533. case 'EN_MEDIUM' : {$pf = array( 1260.000, 1656.000); break;}
  2534. case 'EN_DEMY' : {$pf = array( 1260.000, 1620.000); break;}
  2535. case 'EN_LARGE_POST' : {$pf = array( 1188.000, 1512.000); break;}
  2536. case 'EN_COPY_DRAUGHT' : {$pf = array( 1152.000, 1440.000); break;}
  2537. case 'EN_POST' : {$pf = array( 1116.000, 1386.000); break;}
  2538. case 'EN_CROWN' : {$pf = array( 1080.000, 1440.000); break;}
  2539. case 'EN_PINCHED_POST' : {$pf = array( 1062.000, 1332.000); break;}
  2540. case 'EN_BRIEF' : {$pf = array( 972.000, 1152.000); break;}
  2541. case 'EN_FOOLSCAP' : {$pf = array( 972.000, 1224.000); break;}
  2542. case 'EN_SMALL_FOOLSCAP' : {$pf = array( 954.000, 1188.000); break;}
  2543. case 'EN_POTT' : {$pf = array( 900.000, 1080.000); break;}
  2544. // - Old Imperial Belgian Sizes
  2545. case 'BE_GRAND_AIGLE' : {$pf = array( 1984.252, 2948.031); break;}
  2546. case 'BE_COLOMBIER' : {$pf = array( 1757.480, 2409.449); break;}
  2547. case 'BE_DOUBLE_CARRE': {$pf = array( 1757.480, 2607.874); break;}
  2548. case 'BE_ELEPHANT' : {$pf = array( 1746.142, 2182.677); break;}
  2549. case 'BE_PETIT_AIGLE' : {$pf = array( 1700.787, 2381.102); break;}
  2550. case 'BE_GRAND_JESUS' : {$pf = array( 1559.055, 2069.291); break;}
  2551. case 'BE_JESUS' : {$pf = array( 1530.709, 2069.291); break;}
  2552. case 'BE_RAISIN' : {$pf = array( 1417.323, 1842.520); break;}
  2553. case 'BE_GRAND_MEDIAN': {$pf = array( 1303.937, 1714.961); break;}
  2554. case 'BE_DOUBLE_POSTE': {$pf = array( 1233.071, 1601.575); break;}
  2555. case 'BE_COQUILLE' : {$pf = array( 1218.898, 1587.402); break;}
  2556. case 'BE_PETIT_MEDIAN': {$pf = array( 1176.378, 1502.362); break;}
  2557. case 'BE_RUCHE' : {$pf = array( 1020.472, 1303.937); break;}
  2558. case 'BE_PROPATRIA' : {$pf = array( 977.953, 1218.898); break;}
  2559. case 'BE_LYS' : {$pf = array( 898.583, 1125.354); break;}
  2560. case 'BE_POT' : {$pf = array( 870.236, 1088.504); break;}
  2561. case 'BE_ROSETTE' : {$pf = array( 765.354, 983.622); break;}
  2562. // - Old Imperial French Sizes
  2563. case 'FR_UNIVERS' : {$pf = array( 2834.646, 3685.039); break;}
  2564. case 'FR_DOUBLE_COLOMBIER' : {$pf = array( 2551.181, 3571.654); break;}
  2565. case 'FR_GRANDE_MONDE' : {$pf = array( 2551.181, 3571.654); break;}
  2566. case 'FR_DOUBLE_SOLEIL' : {$pf = array( 2267.717, 3401.575); break;}
  2567. case 'FR_DOUBLE_JESUS' : {$pf = array( 2154.331, 3174.803); break;}
  2568. case 'FR_GRAND_AIGLE' : {$pf = array( 2125.984, 3004.724); break;}
  2569. case 'FR_PETIT_AIGLE' : {$pf = array( 1984.252, 2664.567); break;}
  2570. case 'FR_DOUBLE_RAISIN' : {$pf = array( 1842.520, 2834.646); break;}
  2571. case 'FR_JOURNAL' : {$pf = array( 1842.520, 2664.567); break;}
  2572. case 'FR_COLOMBIER_AFFICHE': {$pf = array( 1785.827, 2551.181); break;}
  2573. case 'FR_DOUBLE_CAVALIER' : {$pf = array( 1757.480, 2607.874); break;}
  2574. case 'FR_CLOCHE' : {$pf = array( 1700.787, 2267.717); break;}
  2575. case 'FR_SOLEIL' : {$pf = array( 1700.787, 2267.717); break;}
  2576. case 'FR_DOUBLE_CARRE' : {$pf = array( 1587.402, 2551.181); break;}
  2577. case 'FR_DOUBLE_COQUILLE' : {$pf = array( 1587.402, 2494.488); break;}
  2578. case 'FR_JESUS' : {$pf = array( 1587.402, 2154.331); break;}
  2579. case 'FR_RAISIN' : {$pf = array( 1417.323, 1842.520); break;}
  2580. case 'FR_CAVALIER' : {$pf = array( 1303.937, 1757.480); break;}
  2581. case 'FR_DOUBLE_COURONNE' : {$pf = array( 1303.937, 2040.945); break;}
  2582. case 'FR_CARRE' : {$pf = array( 1275.591, 1587.402); break;}
  2583. case 'FR_COQUILLE' : {$pf = array( 1247.244, 1587.402); break;}
  2584. case 'FR_DOUBLE_TELLIERE' : {$pf = array( 1247.244, 1927.559); break;}
  2585. case 'FR_DOUBLE_CLOCHE' : {$pf = array( 1133.858, 1700.787); break;}
  2586. case 'FR_DOUBLE_POT' : {$pf = array( 1133.858, 1757.480); break;}
  2587. case 'FR_ECU' : {$pf = array( 1133.858, 1474.016); break;}
  2588. case 'FR_COURONNE' : {$pf = array( 1020.472, 1303.937); break;}
  2589. case 'FR_TELLIERE' : {$pf = array( 963.780, 1247.244); break;}
  2590. case 'FR_POT' : {$pf = array( 878.740, 1133.858); break;}
  2591. // DEFAULT ISO A4
  2592. default: {$pf = array( 595.276, 841.890); break;}
  2593. }
  2594. return $pf;
  2595. }
  2596. /**
  2597. * Change the format of the current page
  2598. * @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>
  2599. * <li>['format'] = page format name (one of the above);</li>
  2600. * <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>
  2601. * <li>['PZ'] : The page's preferred zoom (magnification) factor.</li>
  2602. * <li>['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed:</li>
  2603. * <li>['MediaBox']['llx'] : lower-left x coordinate in points</li>
  2604. * <li>['MediaBox']['lly'] : lower-left y coordinate in points</li>
  2605. * <li>['MediaBox']['urx'] : upper-right x coordinate in points</li>
  2606. * <li>['MediaBox']['ury'] : upper-right y coordinate in points</li>
  2607. * <li>['CropBox'] : the visible region of default user space:</li>
  2608. * <li>['CropBox']['llx'] : lower-left x coordinate in points</li>
  2609. * <li>['CropBox']['lly'] : lower-left y coordinate in points</li>
  2610. * <li>['CropBox']['urx'] : upper-right x coordinate in points</li>
  2611. * <li>['CropBox']['ury'] : upper-right y coordinate in points</li>
  2612. * <li>['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment:</li>
  2613. * <li>['BleedBox']['llx'] : lower-left x coordinate in points</li>
  2614. * <li>['BleedBox']['lly'] : lower-left y coordinate in points</li>
  2615. * <li>['BleedBox']['urx'] : upper-right x coordinate in points</li>
  2616. * <li>['BleedBox']['ury'] : upper-right y coordinate in points</li>
  2617. * <li>['TrimBox'] : the intended dimensions of the finished page after trimming:</li>
  2618. * <li>['TrimBox']['llx'] : lower-left x coordinate in points</li>
  2619. * <li>['TrimBox']['lly'] : lower-left y coordinate in points</li>
  2620. * <li>['TrimBox']['urx'] : upper-right x coordinate in points</li>
  2621. * <li>['TrimBox']['ury'] : upper-right y coordinate in points</li>
  2622. * <li>['ArtBox'] : the extent of the page's meaningful content:</li>
  2623. * <li>['ArtBox']['llx'] : lower-left x coordinate in points</li>
  2624. * <li>['ArtBox']['lly'] : lower-left y coordinate in points</li>
  2625. * <li>['ArtBox']['urx'] : upper-right x coordinate in points</li>
  2626. * <li>['ArtBox']['ury'] : upper-right y coordinate in points</li>
  2627. * <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>
  2628. * <li>['BoxColorInfo'][BOXTYPE]['C'] : an array of three numbers in the range 0-255, representing the components in the DeviceRGB colour space.</li>
  2629. * <li>['BoxColorInfo'][BOXTYPE]['W'] : the guideline width in default user units</li>
  2630. * <li>['BoxColorInfo'][BOXTYPE]['S'] : the guideline style: S = Solid; D = Dashed</li>
  2631. * <li>['BoxColorInfo'][BOXTYPE]['D'] : dash array defining a pattern of dashes and gaps to be used in drawing dashed guidelines</li>
  2632. * <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>
  2633. * <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>
  2634. * <li>['trans']['S'] : transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li>
  2635. * <li>['trans']['D'] : The duration of the transition effect, in seconds.</li>
  2636. * <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>
  2637. * <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>
  2638. * <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>
  2639. * <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>
  2640. * <li>['trans']['B'] : (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li>
  2641. * </ul>
  2642. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul>
  2643. * <li>P or Portrait (default)</li>
  2644. * <li>L or Landscape</li>
  2645. * <li>'' (empty string) for automatic orientation</li>
  2646. * </ul>
  2647. * @protected
  2648. * @since 3.0.015 (2008-06-06)
  2649. * @see getPageSizeFromFormat()
  2650. */
  2651. protected function setPageFormat($format, $orientation='P') {
  2652. if (!empty($format) AND isset($this->pagedim[$this->page])) {
  2653. // remove inherited values
  2654. unset($this->pagedim[$this->page]);
  2655. }
  2656. if (is_string($format)) {
  2657. // get page measures from format name
  2658. $pf = $this->getPageSizeFromFormat($format);
  2659. $this->fwPt = $pf[0];
  2660. $this->fhPt = $pf[1];
  2661. } else {
  2662. // the boundaries of the physical medium on which the page shall be displayed or printed
  2663. if (isset($format['MediaBox'])) {
  2664. $this->setPageBoxes($this->page, 'MediaBox', $format['MediaBox']['llx'], $format['MediaBox']['lly'], $format['MediaBox']['urx'], $format['MediaBox']['ury'], false);
  2665. $this->fwPt = (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k);
  2666. $this->fhPt = (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k);
  2667. } else {
  2668. if (isset($format[0]) AND is_numeric($format[0]) AND isset($format[1]) AND is_numeric($format[1])) {
  2669. $pf = array(($format[0] * $this->k), ($format[1] * $this->k));
  2670. } else {
  2671. if (!isset($format['format'])) {
  2672. // default value
  2673. $format['format'] = 'A4';
  2674. }
  2675. $pf = $this->getPageSizeFromFormat($format['format']);
  2676. }
  2677. $this->fwPt = $pf[0];
  2678. $this->fhPt = $pf[1];
  2679. $this->setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true);
  2680. }
  2681. // the visible region of default user space
  2682. if (isset($format['CropBox'])) {
  2683. $this->setPageBoxes($this->page, 'CropBox', $format['CropBox']['llx'], $format['CropBox']['lly'], $format['CropBox']['urx'], $format['CropBox']['ury'], false);
  2684. }
  2685. // the region to which the contents of the page shall be clipped when output in a production environment
  2686. if (isset($format['BleedBox'])) {
  2687. $this->setPageBoxes($this->page, 'BleedBox', $format['BleedBox']['llx'], $format['BleedBox']['lly'], $format['BleedBox']['urx'], $format['BleedBox']['ury'], false);
  2688. }
  2689. // the intended dimensions of the finished page after trimming
  2690. if (isset($format['TrimBox'])) {
  2691. $this->setPageBoxes($this->page, 'TrimBox', $format['TrimBox']['llx'], $format['TrimBox']['lly'], $format['TrimBox']['urx'], $format['TrimBox']['ury'], false);
  2692. }
  2693. // the page's meaningful content (including potential white space)
  2694. if (isset($format['ArtBox'])) {
  2695. $this->setPageBoxes($this->page, 'ArtBox', $format['ArtBox']['llx'], $format['ArtBox']['lly'], $format['ArtBox']['urx'], $format['ArtBox']['ury'], false);
  2696. }
  2697. // specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for the various page boundaries
  2698. if (isset($format['BoxColorInfo'])) {
  2699. $this->pagedim[$this->page]['BoxColorInfo'] = $format['BoxColorInfo'];
  2700. }
  2701. if (isset($format['Rotate']) AND (($format['Rotate'] % 90) == 0)) {
  2702. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  2703. $this->pagedim[$this->page]['Rotate'] = intval($format['Rotate']);
  2704. }
  2705. if (isset($format['PZ'])) {
  2706. // The page's preferred zoom (magnification) factor
  2707. $this->pagedim[$this->page]['PZ'] = floatval($format['PZ']);
  2708. }
  2709. if (isset($format['trans'])) {
  2710. // The style and duration of the visual transition to use when moving from another page to the given page during a presentation
  2711. if (isset($format['trans']['Dur'])) {
  2712. // The page's display duration
  2713. $this->pagedim[$this->page]['trans']['Dur'] = floatval($format['trans']['Dur']);
  2714. }
  2715. $stansition_styles = array('Split', 'Blinds', 'Box', 'Wipe', 'Dissolve', 'Glitter', 'R', 'Fly', 'Push', 'Cover', 'Uncover', 'Fade');
  2716. if (isset($format['trans']['S']) AND in_array($format['trans']['S'], $stansition_styles)) {
  2717. // The transition style that shall be used when moving to this page from another during a presentation
  2718. $this->pagedim[$this->page]['trans']['S'] = $format['trans']['S'];
  2719. $valid_effect = array('Split', 'Blinds');
  2720. $valid_vals = array('H', 'V');
  2721. if (isset($format['trans']['Dm']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['Dm'], $valid_vals)) {
  2722. $this->pagedim[$this->page]['trans']['Dm'] = $format['trans']['Dm'];
  2723. }
  2724. $valid_effect = array('Split', 'Box', 'Fly');
  2725. $valid_vals = array('I', 'O');
  2726. if (isset($format['trans']['M']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['M'], $valid_vals)) {
  2727. $this->pagedim[$this->page]['trans']['M'] = $format['trans']['M'];
  2728. }
  2729. $valid_effect = array('Wipe', 'Glitter', 'Fly', 'Cover', 'Uncover', 'Push');
  2730. if (isset($format['trans']['Di']) AND in_array($format['trans']['S'], $valid_effect)) {
  2731. if (((($format['trans']['Di'] == 90) OR ($format['trans']['Di'] == 180)) AND ($format['trans']['S'] == 'Wipe'))
  2732. OR (($format['trans']['Di'] == 315) AND ($format['trans']['S'] == 'Glitter'))
  2733. OR (($format['trans']['Di'] == 0) OR ($format['trans']['Di'] == 270))) {
  2734. $this->pagedim[$this->page]['trans']['Di'] = intval($format['trans']['Di']);
  2735. }
  2736. }
  2737. if (isset($format['trans']['SS']) AND ($format['trans']['S'] == 'Fly')) {
  2738. $this->pagedim[$this->page]['trans']['SS'] = floatval($format['trans']['SS']);
  2739. }
  2740. if (isset($format['trans']['B']) AND ($format['trans']['B'] === true) AND ($format['trans']['S'] == 'Fly')) {
  2741. $this->pagedim[$this->page]['trans']['B'] = 'true';
  2742. }
  2743. } else {
  2744. $this->pagedim[$this->page]['trans']['S'] = 'R';
  2745. }
  2746. if (isset($format['trans']['D'])) {
  2747. // The duration of the transition effect, in seconds
  2748. $this->pagedim[$this->page]['trans']['D'] = floatval($format['trans']['D']);
  2749. } else {
  2750. $this->pagedim[$this->page]['trans']['D'] = 1;
  2751. }
  2752. }
  2753. }
  2754. $this->setPageOrientation($orientation);
  2755. }
  2756. /**
  2757. * Set page boundaries.
  2758. * @param $page (int) page number
  2759. * @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>
  2760. * @param $llx (float) lower-left x coordinate in user units
  2761. * @param $lly (float) lower-left y coordinate in user units
  2762. * @param $urx (float) upper-right x coordinate in user units
  2763. * @param $ury (float) upper-right y coordinate in user units
  2764. * @param $points (boolean) if true uses user units as unit of measure, otherwise uses PDF points
  2765. * @public
  2766. * @since 5.0.010 (2010-05-17)
  2767. */
  2768. public function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points=false) {
  2769. if (!isset($this->pagedim[$page])) {
  2770. // initialize array
  2771. $this->pagedim[$page] = array();
  2772. }
  2773. $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  2774. if (!in_array($type, $pageboxes)) {
  2775. return;
  2776. }
  2777. if ($points) {
  2778. $k = 1;
  2779. } else {
  2780. $k = $this->k;
  2781. }
  2782. $this->pagedim[$page][$type]['llx'] = ($llx * $k);
  2783. $this->pagedim[$page][$type]['lly'] = ($lly * $k);
  2784. $this->pagedim[$page][$type]['urx'] = ($urx * $k);
  2785. $this->pagedim[$page][$type]['ury'] = ($ury * $k);
  2786. }
  2787. /**
  2788. * Swap X and Y coordinates of page boxes (change page boxes orientation).
  2789. * @param $page (int) page number
  2790. * @protected
  2791. * @since 5.0.010 (2010-05-17)
  2792. */
  2793. protected function swapPageBoxCoordinates($page) {
  2794. $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  2795. foreach ($pageboxes as $type) {
  2796. // swap X and Y coordinates
  2797. if (isset($this->pagedim[$page][$type])) {
  2798. $tmp = $this->pagedim[$page][$type]['llx'];
  2799. $this->pagedim[$page][$type]['llx'] = $this->pagedim[$page][$type]['lly'];
  2800. $this->pagedim[$page][$type]['lly'] = $tmp;
  2801. $tmp = $this->pagedim[$page][$type]['urx'];
  2802. $this->pagedim[$page][$type]['urx'] = $this->pagedim[$page][$type]['ury'];
  2803. $this->pagedim[$page][$type]['ury'] = $tmp;
  2804. }
  2805. }
  2806. }
  2807. /**
  2808. * Set page orientation.
  2809. * @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>
  2810. * @param $autopagebreak (boolean) Boolean indicating if auto-page-break mode should be on or off.
  2811. * @param $bottommargin (float) bottom margin of the page.
  2812. * @public
  2813. * @since 3.0.015 (2008-06-06)
  2814. */
  2815. public function setPageOrientation($orientation, $autopagebreak='', $bottommargin='') {
  2816. if (!isset($this->pagedim[$this->page]['MediaBox'])) {
  2817. // the boundaries of the physical medium on which the page shall be displayed or printed
  2818. $this->setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true);
  2819. }
  2820. if (!isset($this->pagedim[$this->page]['CropBox'])) {
  2821. // the visible region of default user space
  2822. $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);
  2823. }
  2824. if (!isset($this->pagedim[$this->page]['BleedBox'])) {
  2825. // the region to which the contents of the page shall be clipped when output in a production environment
  2826. $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);
  2827. }
  2828. if (!isset($this->pagedim[$this->page]['TrimBox'])) {
  2829. // the intended dimensions of the finished page after trimming
  2830. $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);
  2831. }
  2832. if (!isset($this->pagedim[$this->page]['ArtBox'])) {
  2833. // the page's meaningful content (including potential white space)
  2834. $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);
  2835. }
  2836. if (!isset($this->pagedim[$this->page]['Rotate'])) {
  2837. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  2838. $this->pagedim[$this->page]['Rotate'] = 0;
  2839. }
  2840. if (!isset($this->pagedim[$this->page]['PZ'])) {
  2841. // The page's preferred zoom (magnification) factor
  2842. $this->pagedim[$this->page]['PZ'] = 1;
  2843. }
  2844. if ($this->fwPt > $this->fhPt) {
  2845. // landscape
  2846. $default_orientation = 'L';
  2847. } else {
  2848. // portrait
  2849. $default_orientation = 'P';
  2850. }
  2851. $valid_orientations = array('P', 'L');
  2852. if (empty($orientation)) {
  2853. $orientation = $default_orientation;
  2854. } else {
  2855. $orientation = strtoupper($orientation{0});
  2856. }
  2857. if (in_array($orientation, $valid_orientations) AND ($orientation != $default_orientation)) {
  2858. $this->CurOrientation = $orientation;
  2859. $this->wPt = $this->fhPt;
  2860. $this->hPt = $this->fwPt;
  2861. } else {
  2862. $this->CurOrientation = $default_orientation;
  2863. $this->wPt = $this->fwPt;
  2864. $this->hPt = $this->fhPt;
  2865. }
  2866. if ((abs($this->pagedim[$this->page]['MediaBox']['urx'] - $this->hPt) < $this->feps) AND (abs($this->pagedim[$this->page]['MediaBox']['ury'] - $this->wPt) < $this->feps)){
  2867. // swap X and Y coordinates (change page orientation)
  2868. $this->swapPageBoxCoordinates($this->page);
  2869. }
  2870. $this->w = ($this->wPt / $this->k);
  2871. $this->h = ($this->hPt / $this->k);
  2872. if ($this->empty_string($autopagebreak)) {
  2873. if (isset($this->AutoPageBreak)) {
  2874. $autopagebreak = $this->AutoPageBreak;
  2875. } else {
  2876. $autopagebreak = true;
  2877. }
  2878. }
  2879. if ($this->empty_string($bottommargin)) {
  2880. if (isset($this->bMargin)) {
  2881. $bottommargin = $this->bMargin;
  2882. } else {
  2883. // default value = 2 cm
  2884. $bottommargin = 2 * 28.35 / $this->k;
  2885. }
  2886. }
  2887. $this->SetAutoPageBreak($autopagebreak, $bottommargin);
  2888. // store page dimensions
  2889. $this->pagedim[$this->page]['w'] = $this->wPt;
  2890. $this->pagedim[$this->page]['h'] = $this->hPt;
  2891. $this->pagedim[$this->page]['wk'] = $this->w;
  2892. $this->pagedim[$this->page]['hk'] = $this->h;
  2893. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  2894. $this->pagedim[$this->page]['bm'] = $bottommargin;
  2895. $this->pagedim[$this->page]['lm'] = $this->lMargin;
  2896. $this->pagedim[$this->page]['rm'] = $this->rMargin;
  2897. $this->pagedim[$this->page]['pb'] = $autopagebreak;
  2898. $this->pagedim[$this->page]['or'] = $this->CurOrientation;
  2899. $this->pagedim[$this->page]['olm'] = $this->original_lMargin;
  2900. $this->pagedim[$this->page]['orm'] = $this->original_rMargin;
  2901. }
  2902. /**
  2903. * Set regular expression to detect withespaces or word separators.
  2904. * The pattern delimiter must be the forward-slash character "/".
  2905. * Some example patterns are:
  2906. * <pre>
  2907. * Non-Unicode or missing PCRE unicode support: "/[^\S\xa0]/"
  2908. * Unicode and PCRE unicode support: "/[^\S\P{Z}\xa0]/u"
  2909. * Unicode and PCRE unicode support in Chinese mode: "/[^\S\P{Z}\P{Lo}\xa0]/u"
  2910. * if PCRE unicode support is turned ON ("\P" is the negate class of "\p"):
  2911. * "\p{Z}" or "\p{Separator}": any kind of Unicode whitespace or invisible separator.
  2912. * "\p{Lo}" or "\p{Other_Letter}": a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  2913. * "\p{Lo}" is needed for Chinese characters because are packed next to each other without spaces in between.
  2914. * </pre>
  2915. * @param $re (string) regular expression (leave empty for default).
  2916. * @public
  2917. * @since 4.6.016 (2009-06-15)
  2918. */
  2919. public function setSpacesRE($re='/[^\S\xa0]/') {
  2920. $this->re_spaces = $re;
  2921. $re_parts = explode('/', $re);
  2922. // get pattern parts
  2923. $this->re_space = array();
  2924. if (isset($re_parts[1]) AND !empty($re_parts[1])) {
  2925. $this->re_space['p'] = $re_parts[1];
  2926. } else {
  2927. $this->re_space['p'] = '[\s]';
  2928. }
  2929. // set pattern modifiers
  2930. if (isset($re_parts[2]) AND !empty($re_parts[2])) {
  2931. $this->re_space['m'] = $re_parts[2];
  2932. } else {
  2933. $this->re_space['m'] = '';
  2934. }
  2935. }
  2936. /**
  2937. * Enable or disable Right-To-Left language mode
  2938. * @param $enable (Boolean) if true enable Right-To-Left language mode.
  2939. * @param $resetx (Boolean) if true reset the X position on direction change.
  2940. * @public
  2941. * @since 2.0.000 (2008-01-03)
  2942. */
  2943. public function setRTL($enable, $resetx=true) {
  2944. $enable = $enable ? true : false;
  2945. $resetx = ($resetx AND ($enable != $this->rtl));
  2946. $this->rtl = $enable;
  2947. $this->tmprtl = false;
  2948. if ($resetx) {
  2949. $this->Ln(0);
  2950. }
  2951. }
  2952. /**
  2953. * Return the RTL status
  2954. * @return boolean
  2955. * @public
  2956. * @since 4.0.012 (2008-07-24)
  2957. */
  2958. public function getRTL() {
  2959. return $this->rtl;
  2960. }
  2961. /**
  2962. * Force temporary RTL language direction
  2963. * @param $mode (mixed) can be false, 'L' for LTR or 'R' for RTL
  2964. * @public
  2965. * @since 2.1.000 (2008-01-09)
  2966. */
  2967. public function setTempRTL($mode) {
  2968. $newmode = false;
  2969. switch (strtoupper($mode)) {
  2970. case 'LTR':
  2971. case 'L': {
  2972. if ($this->rtl) {
  2973. $newmode = 'L';
  2974. }
  2975. break;
  2976. }
  2977. case 'RTL':
  2978. case 'R': {
  2979. if (!$this->rtl) {
  2980. $newmode = 'R';
  2981. }
  2982. break;
  2983. }
  2984. case false:
  2985. default: {
  2986. $newmode = false;
  2987. break;
  2988. }
  2989. }
  2990. $this->tmprtl = $newmode;
  2991. }
  2992. /**
  2993. * Return the current temporary RTL status
  2994. * @return boolean
  2995. * @public
  2996. * @since 4.8.014 (2009-11-04)
  2997. */
  2998. public function isRTLTextDir() {
  2999. return ($this->rtl OR ($this->tmprtl == 'R'));
  3000. }
  3001. /**
  3002. * Set the last cell height.
  3003. * @param $h (float) cell height.
  3004. * @author Nicola Asuni
  3005. * @public
  3006. * @since 1.53.0.TC034
  3007. */
  3008. public function setLastH($h) {
  3009. $this->lasth = $h;
  3010. }
  3011. /**
  3012. * Reset the last cell height.
  3013. * @public
  3014. * @since 5.9.000 (2010-10-03)
  3015. */
  3016. public function resetLastH() {
  3017. $this->lasth = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  3018. }
  3019. /**
  3020. * Get the last cell height.
  3021. * @return last cell height
  3022. * @public
  3023. * @since 4.0.017 (2008-08-05)
  3024. */
  3025. public function getLastH() {
  3026. return $this->lasth;
  3027. }
  3028. /**
  3029. * Set the adjusting factor to convert pixels to user units.
  3030. * @param $scale (float) adjusting factor to convert pixels to user units.
  3031. * @author Nicola Asuni
  3032. * @public
  3033. * @since 1.5.2
  3034. */
  3035. public function setImageScale($scale) {
  3036. $this->imgscale = $scale;
  3037. }
  3038. /**
  3039. * Returns the adjusting factor to convert pixels to user units.
  3040. * @return float adjusting factor to convert pixels to user units.
  3041. * @author Nicola Asuni
  3042. * @public
  3043. * @since 1.5.2
  3044. */
  3045. public function getImageScale() {
  3046. return $this->imgscale;
  3047. }
  3048. /**
  3049. * Returns an array of page dimensions:
  3050. * <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>
  3051. * @param $pagenum (int) page number (empty = current page)
  3052. * @return array of page dimensions.
  3053. * @author Nicola Asuni
  3054. * @public
  3055. * @since 4.5.027 (2009-03-16)
  3056. */
  3057. public function getPageDimensions($pagenum='') {
  3058. if (empty($pagenum)) {
  3059. $pagenum = $this->page;
  3060. }
  3061. return $this->pagedim[$pagenum];
  3062. }
  3063. /**
  3064. * Returns the page width in units.
  3065. * @param $pagenum (int) page number (empty = current page)
  3066. * @return int page width.
  3067. * @author Nicola Asuni
  3068. * @public
  3069. * @since 1.5.2
  3070. * @see getPageDimensions()
  3071. */
  3072. public function getPageWidth($pagenum='') {
  3073. if (empty($pagenum)) {
  3074. return $this->w;
  3075. }
  3076. return $this->pagedim[$pagenum]['w'];
  3077. }
  3078. /**
  3079. * Returns the page height in units.
  3080. * @param $pagenum (int) page number (empty = current page)
  3081. * @return int page height.
  3082. * @author Nicola Asuni
  3083. * @public
  3084. * @since 1.5.2
  3085. * @see getPageDimensions()
  3086. */
  3087. public function getPageHeight($pagenum='') {
  3088. if (empty($pagenum)) {
  3089. return $this->h;
  3090. }
  3091. return $this->pagedim[$pagenum]['h'];
  3092. }
  3093. /**
  3094. * Returns the page break margin.
  3095. * @param $pagenum (int) page number (empty = current page)
  3096. * @return int page break margin.
  3097. * @author Nicola Asuni
  3098. * @public
  3099. * @since 1.5.2
  3100. * @see getPageDimensions()
  3101. */
  3102. public function getBreakMargin($pagenum='') {
  3103. if (empty($pagenum)) {
  3104. return $this->bMargin;
  3105. }
  3106. return $this->pagedim[$pagenum]['bm'];
  3107. }
  3108. /**
  3109. * Returns the scale factor (number of points in user unit).
  3110. * @return int scale factor.
  3111. * @author Nicola Asuni
  3112. * @public
  3113. * @since 1.5.2
  3114. */
  3115. public function getScaleFactor() {
  3116. return $this->k;
  3117. }
  3118. /**
  3119. * Defines the left, top and right margins.
  3120. * @param $left (float) Left margin.
  3121. * @param $top (float) Top margin.
  3122. * @param $right (float) Right margin. Default value is the left one.
  3123. * @param $keepmargins (boolean) if true overwrites the default page margins
  3124. * @public
  3125. * @since 1.0
  3126. * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  3127. */
  3128. public function SetMargins($left, $top, $right=-1, $keepmargins=false) {
  3129. //Set left, top and right margins
  3130. $this->lMargin = $left;
  3131. $this->tMargin = $top;
  3132. if ($right == -1) {
  3133. $right = $left;
  3134. }
  3135. $this->rMargin = $right;
  3136. if ($keepmargins) {
  3137. // overwrite original values
  3138. $this->original_lMargin = $this->lMargin;
  3139. $this->original_rMargin = $this->rMargin;
  3140. }
  3141. }
  3142. /**
  3143. * 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.
  3144. * @param $margin (float) The margin.
  3145. * @public
  3146. * @since 1.4
  3147. * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  3148. */
  3149. public function SetLeftMargin($margin) {
  3150. //Set left margin
  3151. $this->lMargin = $margin;
  3152. if (($this->page > 0) AND ($this->x < $margin)) {
  3153. $this->x = $margin;
  3154. }
  3155. }
  3156. /**
  3157. * Defines the top margin. The method can be called before creating the first page.
  3158. * @param $margin (float) The margin.
  3159. * @public
  3160. * @since 1.5
  3161. * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  3162. */
  3163. public function SetTopMargin($margin) {
  3164. //Set top margin
  3165. $this->tMargin = $margin;
  3166. if (($this->page > 0) AND ($this->y < $margin)) {
  3167. $this->y = $margin;
  3168. }
  3169. }
  3170. /**
  3171. * Defines the right margin. The method can be called before creating the first page.
  3172. * @param $margin (float) The margin.
  3173. * @public
  3174. * @since 1.5
  3175. * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  3176. */
  3177. public function SetRightMargin($margin) {
  3178. $this->rMargin = $margin;
  3179. if (($this->page > 0) AND ($this->x > ($this->w - $margin))) {
  3180. $this->x = $this->w - $margin;
  3181. }
  3182. }
  3183. /**
  3184. * Set the same internal Cell padding for top, right, bottom, left-
  3185. * @param $pad (float) internal padding.
  3186. * @public
  3187. * @since 2.1.000 (2008-01-09)
  3188. * @see getCellPaddings(), setCellPaddings()
  3189. */
  3190. public function SetCellPadding($pad) {
  3191. if ($pad >= 0) {
  3192. $this->cell_padding['L'] = $pad;
  3193. $this->cell_padding['T'] = $pad;
  3194. $this->cell_padding['R'] = $pad;
  3195. $this->cell_padding['B'] = $pad;
  3196. }
  3197. }
  3198. /**
  3199. * Set the internal Cell paddings.
  3200. * @param $left (float) left padding
  3201. * @param $top (float) top padding
  3202. * @param $right (float) right padding
  3203. * @param $bottom (float) bottom padding
  3204. * @public
  3205. * @since 5.9.000 (2010-10-03)
  3206. * @see getCellPaddings(), SetCellPadding()
  3207. */
  3208. public function setCellPaddings($left='', $top='', $right='', $bottom='') {
  3209. if (($left !== '') AND ($left >= 0)) {
  3210. $this->cell_padding['L'] = $left;
  3211. }
  3212. if (($top !== '') AND ($top >= 0)) {
  3213. $this->cell_padding['T'] = $top;
  3214. }
  3215. if (($right !== '') AND ($right >= 0)) {
  3216. $this->cell_padding['R'] = $right;
  3217. }
  3218. if (($bottom !== '') AND ($bottom >= 0)) {
  3219. $this->cell_padding['B'] = $bottom;
  3220. }
  3221. }
  3222. /**
  3223. * Get the internal Cell padding array.
  3224. * @return array of padding values
  3225. * @public
  3226. * @since 5.9.000 (2010-10-03)
  3227. * @see setCellPaddings(), SetCellPadding()
  3228. */
  3229. public function getCellPaddings() {
  3230. return $this->cell_padding;
  3231. }
  3232. /**
  3233. * Set the internal Cell margins.
  3234. * @param $left (float) left margin
  3235. * @param $top (float) top margin
  3236. * @param $right (float) right margin
  3237. * @param $bottom (float) bottom margin
  3238. * @public
  3239. * @since 5.9.000 (2010-10-03)
  3240. * @see getCellMargins()
  3241. */
  3242. public function setCellMargins($left='', $top='', $right='', $bottom='') {
  3243. if (($left !== '') AND ($left >= 0)) {
  3244. $this->cell_margin['L'] = $left;
  3245. }
  3246. if (($top !== '') AND ($top >= 0)) {
  3247. $this->cell_margin['T'] = $top;
  3248. }
  3249. if (($right !== '') AND ($right >= 0)) {
  3250. $this->cell_margin['R'] = $right;
  3251. }
  3252. if (($bottom !== '') AND ($bottom >= 0)) {
  3253. $this->cell_margin['B'] = $bottom;
  3254. }
  3255. }
  3256. /**
  3257. * Get the internal Cell margin array.
  3258. * @return array of margin values
  3259. * @public
  3260. * @since 5.9.000 (2010-10-03)
  3261. * @see setCellMargins()
  3262. */
  3263. public function getCellMargins() {
  3264. return $this->cell_margin;
  3265. }
  3266. /**
  3267. * Adjust the internal Cell padding array to take account of the line width.
  3268. * @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)))
  3269. * @return array of adjustments
  3270. * @public
  3271. * @since 5.9.000 (2010-10-03)
  3272. */
  3273. protected function adjustCellPadding($brd=0) {
  3274. if (empty($brd)) {
  3275. return;
  3276. }
  3277. if (is_string($brd)) {
  3278. // convert string to array
  3279. $slen = strlen($brd);
  3280. $newbrd = array();
  3281. for ($i = 0; $i < $slen; ++$i) {
  3282. $newbrd[$brd[$i]] = true;
  3283. }
  3284. $brd = $newbrd;
  3285. } elseif (($brd === 1) OR ($brd === true) OR (is_numeric($brd) AND (intval($brd) > 0))) {
  3286. $brd = array('LRTB' => true);
  3287. }
  3288. if (!is_array($brd)) {
  3289. return;
  3290. }
  3291. // store current cell padding
  3292. $cp = $this->cell_padding;
  3293. // select border mode
  3294. if (isset($brd['mode'])) {
  3295. $mode = $brd['mode'];
  3296. unset($brd['mode']);
  3297. } else {
  3298. $mode = 'normal';
  3299. }
  3300. // process borders
  3301. foreach ($brd as $border => $style) {
  3302. $line_width = $this->LineWidth;
  3303. if (is_array($style) AND isset($style['width'])) {
  3304. // get border width
  3305. $line_width = $style['width'];
  3306. }
  3307. $adj = 0; // line width inside the cell
  3308. switch ($mode) {
  3309. case 'ext': {
  3310. $adj = 0;
  3311. break;
  3312. }
  3313. case 'int': {
  3314. $adj = $line_width;
  3315. break;
  3316. }
  3317. case 'normal':
  3318. default: {
  3319. $adj = ($line_width / 2);
  3320. break;
  3321. }
  3322. }
  3323. // correct internal cell padding if required to avoid overlap between text and lines
  3324. if ((strpos($border,'T') !== false) AND ($this->cell_padding['T'] < $adj)) {
  3325. $this->cell_padding['T'] = $adj;
  3326. }
  3327. if ((strpos($border,'R') !== false) AND ($this->cell_padding['R'] < $adj)) {
  3328. $this->cell_padding['R'] = $adj;
  3329. }
  3330. if ((strpos($border,'B') !== false) AND ($this->cell_padding['B'] < $adj)) {
  3331. $this->cell_padding['B'] = $adj;
  3332. }
  3333. if ((strpos($border,'L') !== false) AND ($this->cell_padding['L'] < $adj)) {
  3334. $this->cell_padding['L'] = $adj;
  3335. }
  3336. }
  3337. 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']));
  3338. }
  3339. /**
  3340. * 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.
  3341. * @param $auto (boolean) Boolean indicating if mode should be on or off.
  3342. * @param $margin (float) Distance from the bottom of the page.
  3343. * @public
  3344. * @since 1.0
  3345. * @see Cell(), MultiCell(), AcceptPageBreak()
  3346. */
  3347. public function SetAutoPageBreak($auto, $margin=0) {
  3348. $this->AutoPageBreak = $auto ? true : false;
  3349. $this->bMargin = $margin;
  3350. $this->PageBreakTrigger = $this->h - $margin;
  3351. }
  3352. /**
  3353. * Return the auto-page-break mode (true or false).
  3354. * @return boolean auto-page-break mode
  3355. * @public
  3356. * @since 5.9.088
  3357. */
  3358. public function getAutoPageBreak() {
  3359. return $this->AutoPageBreak;
  3360. }
  3361. /**
  3362. * Defines the way the document is to be displayed by the viewer.
  3363. * @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>
  3364. * @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>
  3365. * @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>
  3366. * @public
  3367. * @since 1.2
  3368. */
  3369. public function SetDisplayMode($zoom, $layout='SinglePage', $mode='UseNone') {
  3370. if (($zoom == 'fullpage') OR ($zoom == 'fullwidth') OR ($zoom == 'real') OR ($zoom == 'default') OR (!is_string($zoom))) {
  3371. $this->ZoomMode = $zoom;
  3372. } else {
  3373. $this->Error('Incorrect zoom display mode: '.$zoom);
  3374. }
  3375. switch ($layout) {
  3376. case 'default':
  3377. case 'single':
  3378. case 'SinglePage': {
  3379. $this->LayoutMode = 'SinglePage';
  3380. break;
  3381. }
  3382. case 'continuous':
  3383. case 'OneColumn': {
  3384. $this->LayoutMode = 'OneColumn';
  3385. break;
  3386. }
  3387. case 'two':
  3388. case 'TwoColumnLeft': {
  3389. $this->LayoutMode = 'TwoColumnLeft';
  3390. break;
  3391. }
  3392. case 'TwoColumnRight': {
  3393. $this->LayoutMode = 'TwoColumnRight';
  3394. break;
  3395. }
  3396. case 'TwoPageLeft': {
  3397. $this->LayoutMode = 'TwoPageLeft';
  3398. break;
  3399. }
  3400. case 'TwoPageRight': {
  3401. $this->LayoutMode = 'TwoPageRight';
  3402. break;
  3403. }
  3404. default: {
  3405. $this->LayoutMode = 'SinglePage';
  3406. }
  3407. }
  3408. switch ($mode) {
  3409. case 'UseNone': {
  3410. $this->PageMode = 'UseNone';
  3411. break;
  3412. }
  3413. case 'UseOutlines': {
  3414. $this->PageMode = 'UseOutlines';
  3415. break;
  3416. }
  3417. case 'UseThumbs': {
  3418. $this->PageMode = 'UseThumbs';
  3419. break;
  3420. }
  3421. case 'FullScreen': {
  3422. $this->PageMode = 'FullScreen';
  3423. break;
  3424. }
  3425. case 'UseOC': {
  3426. $this->PageMode = 'UseOC';
  3427. break;
  3428. }
  3429. case '': {
  3430. $this->PageMode = 'UseAttachments';
  3431. break;
  3432. }
  3433. default: {
  3434. $this->PageMode = 'UseNone';
  3435. }
  3436. }
  3437. }
  3438. /**
  3439. * 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.
  3440. * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  3441. * @param $compress (boolean) Boolean indicating if compression must be enabled.
  3442. * @public
  3443. * @since 1.4
  3444. */
  3445. public function SetCompression($compress=true) {
  3446. if (function_exists('gzcompress')) {
  3447. $this->compress = $compress ? true : false;
  3448. } else {
  3449. $this->compress = false;
  3450. }
  3451. }
  3452. /**
  3453. * Set flag to force sRGB_IEC61966-2.1 black scaled ICC color profile for the whole document.
  3454. * @param $mode (boolean) If true force sRGB output intent.
  3455. * @public
  3456. * @since 5.9.121 (2011-09-28)
  3457. */
  3458. public function setSRGBmode($mode=false) {
  3459. $this->force_srgb = $mode ? true : false;
  3460. }
  3461. /**
  3462. * Turn on/off Unicode mode for document information dictionary (meta tags).
  3463. * This has effect only when unicode mode is set to false.
  3464. * @param $unicode (boolean) if true set the meta information in Unicode
  3465. * @since 5.9.027 (2010-12-01)
  3466. * @public
  3467. */
  3468. public function SetDocInfoUnicode($unicode=true) {
  3469. $this->docinfounicode = $unicode ? true : false;
  3470. }
  3471. /**
  3472. * Defines the title of the document.
  3473. * @param $title (string) The title.
  3474. * @public
  3475. * @since 1.2
  3476. * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  3477. */
  3478. public function SetTitle($title) {
  3479. $this->title = $title;
  3480. }
  3481. /**
  3482. * Defines the subject of the document.
  3483. * @param $subject (string) The subject.
  3484. * @public
  3485. * @since 1.2
  3486. * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  3487. */
  3488. public function SetSubject($subject) {
  3489. $this->subject = $subject;
  3490. }
  3491. /**
  3492. * Defines the author of the document.
  3493. * @param $author (string) The name of the author.
  3494. * @public
  3495. * @since 1.2
  3496. * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  3497. */
  3498. public function SetAuthor($author) {
  3499. $this->author = $author;
  3500. }
  3501. /**
  3502. * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  3503. * @param $keywords (string) The list of keywords.
  3504. * @public
  3505. * @since 1.2
  3506. * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  3507. */
  3508. public function SetKeywords($keywords) {
  3509. $this->keywords = $keywords;
  3510. }
  3511. /**
  3512. * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  3513. * @param $creator (string) The name of the creator.
  3514. * @public
  3515. * @since 1.2
  3516. * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  3517. */
  3518. public function SetCreator($creator) {
  3519. $this->creator = $creator;
  3520. }
  3521. /**
  3522. * 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.
  3523. * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
  3524. * @param $msg (string) The error message
  3525. * @public
  3526. * @since 1.0
  3527. */
  3528. public function Error($msg) {
  3529. // unset all class variables
  3530. $this->_destroy(true);
  3531. $phpmainver = PHP_VERSION;
  3532. // exit program and print error
  3533. if ((intval($phpmainver[0]) < 5) OR !defined('K_TCPDF_THROW_EXCEPTION_ERROR') OR !K_TCPDF_THROW_EXCEPTION_ERROR) {
  3534. die('<strong>TCPDF ERROR: </strong>'.$msg);
  3535. } else {
  3536. throw new Exception('TCPDF ERROR: '.$msg);
  3537. }
  3538. }
  3539. /**
  3540. * This method begins the generation of the PDF document.
  3541. * It is not necessary to call it explicitly because AddPage() does it automatically.
  3542. * Note: no page is created by this method
  3543. * @public
  3544. * @since 1.0
  3545. * @see AddPage(), Close()
  3546. */
  3547. public function Open() {
  3548. $this->state = 1;
  3549. }
  3550. /**
  3551. * Terminates the PDF document.
  3552. * It is not necessary to call this method explicitly because Output() does it automatically.
  3553. * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  3554. * @public
  3555. * @since 1.0
  3556. * @see Open(), Output()
  3557. */
  3558. public function Close() {
  3559. if ($this->state == 3) {
  3560. return;
  3561. }
  3562. if ($this->page == 0) {
  3563. $this->AddPage();
  3564. }
  3565. $this->endLayer();
  3566. if ($this->tcpdflink) {
  3567. // save current graphic settings
  3568. $gvars = $this->getGraphicVars();
  3569. $this->setEqualColumns();
  3570. $this->lastpage(true);
  3571. $this->SetAutoPageBreak(false);
  3572. $this->x = 0;
  3573. $this->y = $this->h - (1 / $this->k);
  3574. $this->lMargin = 0;
  3575. $this->_out('q');
  3576. $font = defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica';
  3577. $this->SetFont($font, '', 1);
  3578. $this->setTextRenderingMode(0, false, false);
  3579. $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";
  3580. $lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67";
  3581. $this->Cell(0, 0, $msg, 0, 0, 'L', 0, $lnk, 0, false, 'D', 'B');
  3582. $this->_out('Q');
  3583. // restore graphic settings
  3584. $this->setGraphicVars($gvars);
  3585. }
  3586. // close page
  3587. $this->endPage();
  3588. // close document
  3589. $this->_enddoc();
  3590. // unset all class variables (except critical ones)
  3591. $this->_destroy(false);
  3592. }
  3593. /**
  3594. * Move pointer at the specified document page and update page dimensions.
  3595. * @param $pnum (int) page number (1 ... numpages)
  3596. * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
  3597. * @public
  3598. * @since 2.1.000 (2008-01-07)
  3599. * @see getPage(), lastpage(), getNumPages()
  3600. */
  3601. public function setPage($pnum, $resetmargins=false) {
  3602. if (($pnum == $this->page) AND ($this->state == 2)) {
  3603. return;
  3604. }
  3605. if (($pnum > 0) AND ($pnum <= $this->numpages)) {
  3606. $this->state = 2;
  3607. // save current graphic settings
  3608. //$gvars = $this->getGraphicVars();
  3609. $oldpage = $this->page;
  3610. $this->page = $pnum;
  3611. $this->wPt = $this->pagedim[$this->page]['w'];
  3612. $this->hPt = $this->pagedim[$this->page]['h'];
  3613. $this->w = $this->pagedim[$this->page]['wk'];
  3614. $this->h = $this->pagedim[$this->page]['hk'];
  3615. $this->tMargin = $this->pagedim[$this->page]['tm'];
  3616. $this->bMargin = $this->pagedim[$this->page]['bm'];
  3617. $this->original_lMargin = $this->pagedim[$this->page]['olm'];
  3618. $this->original_rMargin = $this->pagedim[$this->page]['orm'];
  3619. $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
  3620. $this->CurOrientation = $this->pagedim[$this->page]['or'];
  3621. $this->SetAutoPageBreak($this->AutoPageBreak, $this->bMargin);
  3622. // restore graphic settings
  3623. //$this->setGraphicVars($gvars);
  3624. if ($resetmargins) {
  3625. $this->lMargin = $this->pagedim[$this->page]['olm'];
  3626. $this->rMargin = $this->pagedim[$this->page]['orm'];
  3627. $this->SetY($this->tMargin);
  3628. } else {
  3629. // account for booklet mode
  3630. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  3631. $deltam = $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm'];
  3632. $this->lMargin += $deltam;
  3633. $this->rMargin -= $deltam;
  3634. }
  3635. }
  3636. } else {
  3637. $this->Error('Wrong page number on setPage() function: '.$pnum);
  3638. }
  3639. }
  3640. /**
  3641. * Reset pointer to the last document page.
  3642. * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
  3643. * @public
  3644. * @since 2.0.000 (2008-01-04)
  3645. * @see setPage(), getPage(), getNumPages()
  3646. */
  3647. public function lastPage($resetmargins=false) {
  3648. $this->setPage($this->getNumPages(), $resetmargins);
  3649. }
  3650. /**
  3651. * Get current document page number.
  3652. * @return int page number
  3653. * @public
  3654. * @since 2.1.000 (2008-01-07)
  3655. * @see setPage(), lastpage(), getNumPages()
  3656. */
  3657. public function getPage() {
  3658. return $this->page;
  3659. }
  3660. /**
  3661. * Get the total number of insered pages.
  3662. * @return int number of pages
  3663. * @public
  3664. * @since 2.1.000 (2008-01-07)
  3665. * @see setPage(), getPage(), lastpage()
  3666. */
  3667. public function getNumPages() {
  3668. return $this->numpages;
  3669. }
  3670. /**
  3671. * Adds a new TOC (Table Of Content) page to the document.
  3672. * @param $orientation (string) page orientation.
  3673. * @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().
  3674. * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
  3675. * @public
  3676. * @since 5.0.001 (2010-05-06)
  3677. * @see AddPage(), startPage(), endPage(), endTOCPage()
  3678. */
  3679. public function addTOCPage($orientation='', $format='', $keepmargins=false) {
  3680. $this->AddPage($orientation, $format, $keepmargins, true);
  3681. }
  3682. /**
  3683. * Terminate the current TOC (Table Of Content) page
  3684. * @public
  3685. * @since 5.0.001 (2010-05-06)
  3686. * @see AddPage(), startPage(), endPage(), addTOCPage()
  3687. */
  3688. public function endTOCPage() {
  3689. $this->endPage(true);
  3690. }
  3691. /**
  3692. * 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).
  3693. * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
  3694. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  3695. * @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().
  3696. * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
  3697. * @param $tocpage (boolean) if true set the tocpage state to true (the added page will be used to display Table Of Content).
  3698. * @public
  3699. * @since 1.0
  3700. * @see startPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  3701. */
  3702. public function AddPage($orientation='', $format='', $keepmargins=false, $tocpage=false) {
  3703. if ($this->inxobj) {
  3704. // we are inside an XObject template
  3705. return;
  3706. }
  3707. if (!isset($this->original_lMargin) OR $keepmargins) {
  3708. $this->original_lMargin = $this->lMargin;
  3709. }
  3710. if (!isset($this->original_rMargin) OR $keepmargins) {
  3711. $this->original_rMargin = $this->rMargin;
  3712. }
  3713. // terminate previous page
  3714. $this->endPage();
  3715. // start new page
  3716. $this->startPage($orientation, $format, $tocpage);
  3717. }
  3718. /**
  3719. * Terminate the current page
  3720. * @param $tocpage (boolean) if true set the tocpage state to false (end the page used to display Table Of Content).
  3721. * @public
  3722. * @since 4.2.010 (2008-11-14)
  3723. * @see AddPage(), startPage(), addTOCPage(), endTOCPage()
  3724. */
  3725. public function endPage($tocpage=false) {
  3726. // check if page is already closed
  3727. if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) {
  3728. return;
  3729. }
  3730. // print page footer
  3731. $this->setFooter();
  3732. // close page
  3733. $this->_endpage();
  3734. // mark page as closed
  3735. $this->pageopen[$this->page] = false;
  3736. if ($tocpage) {
  3737. $this->tocpage = false;
  3738. }
  3739. }
  3740. /**
  3741. * Starts a new page to the document. The page must be closed using the endPage() function.
  3742. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  3743. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  3744. * @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().
  3745. * @param $tocpage (boolean) if true the page is designated to contain the Table-Of-Content.
  3746. * @since 4.2.010 (2008-11-14)
  3747. * @see AddPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  3748. * @public
  3749. */
  3750. public function startPage($orientation='', $format='', $tocpage=false) {
  3751. if ($tocpage) {
  3752. $this->tocpage = true;
  3753. }
  3754. // move page numbers of documents to be attached
  3755. if ($this->tocpage) {
  3756. // move reference to unexistent pages (used for page attachments)
  3757. // adjust outlines
  3758. $tmpoutlines = $this->outlines;
  3759. foreach ($tmpoutlines as $key => $outline) {
  3760. if ($outline['p'] > $this->numpages) {
  3761. $this->outlines[$key]['p'] = ($outline['p'] + 1);
  3762. }
  3763. }
  3764. // adjust dests
  3765. $tmpdests = $this->dests;
  3766. foreach ($tmpdests as $key => $dest) {
  3767. if ($dest['p'] > $this->numpages) {
  3768. $this->dests[$key]['p'] = ($dest['p'] + 1);
  3769. }
  3770. }
  3771. // adjust links
  3772. $tmplinks = $this->links;
  3773. foreach ($tmplinks as $key => $link) {
  3774. if ($link[0] > $this->numpages) {
  3775. $this->links[$key][0] = ($link[0] + 1);
  3776. }
  3777. }
  3778. }
  3779. if ($this->numpages > $this->page) {
  3780. // this page has been already added
  3781. $this->setPage($this->page + 1);
  3782. $this->SetY($this->tMargin);
  3783. return;
  3784. }
  3785. // start a new page
  3786. if ($this->state == 0) {
  3787. $this->Open();
  3788. }
  3789. ++$this->numpages;
  3790. $this->swapMargins($this->booklet);
  3791. // save current graphic settings
  3792. $gvars = $this->getGraphicVars();
  3793. // start new page
  3794. $this->_beginpage($orientation, $format);
  3795. // mark page as open
  3796. $this->pageopen[$this->page] = true;
  3797. // restore graphic settings
  3798. $this->setGraphicVars($gvars);
  3799. // mark this point
  3800. $this->setPageMark();
  3801. // print page header
  3802. $this->setHeader();
  3803. // restore graphic settings
  3804. $this->setGraphicVars($gvars);
  3805. // mark this point
  3806. $this->setPageMark();
  3807. // print table header (if any)
  3808. $this->setTableHeader();
  3809. // set mark for empty page check
  3810. $this->emptypagemrk[$this->page]= $this->pagelen[$this->page];
  3811. }
  3812. /**
  3813. * Set start-writing mark on current page stream used to put borders and fills.
  3814. * Borders and fills are always created after content and inserted on the position marked by this method.
  3815. * This function must be called after calling Image() function for a background image.
  3816. * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
  3817. * @public
  3818. * @since 4.0.016 (2008-07-30)
  3819. */
  3820. public function setPageMark() {
  3821. $this->intmrk[$this->page] = $this->pagelen[$this->page];
  3822. $this->bordermrk[$this->page] = $this->intmrk[$this->page];
  3823. $this->setContentMark();
  3824. }
  3825. /**
  3826. * Set start-writing mark on selected page.
  3827. * Borders and fills are always created after content and inserted on the position marked by this method.
  3828. * @param $page (int) page number (default is the current page)
  3829. * @protected
  3830. * @since 4.6.021 (2009-07-20)
  3831. */
  3832. protected function setContentMark($page=0) {
  3833. if ($page <= 0) {
  3834. $page = $this->page;
  3835. }
  3836. if (isset($this->footerlen[$page])) {
  3837. $this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
  3838. } else {
  3839. $this->cntmrk[$page] = $this->pagelen[$page];
  3840. }
  3841. }
  3842. /**
  3843. * Set header data.
  3844. * @param $ln (string) header image logo
  3845. * @param $lw (string) header image logo width in mm
  3846. * @param $ht (string) string to print as title on document header
  3847. * @param $hs (string) string to print on document header
  3848. * @param $tc (array) RGB array color for text.
  3849. * @param $lc (array) RGB array color for line.
  3850. * @public
  3851. */
  3852. public function setHeaderData($ln='', $lw=0, $ht='', $hs='', $tc=array(0,0,0), $lc=array(0,0,0)) {
  3853. $this->header_logo = $ln;
  3854. $this->header_logo_width = $lw;
  3855. $this->header_title = $ht;
  3856. $this->header_string = $hs;
  3857. $this->header_text_color = $tc;
  3858. $this->header_line_color = $lc;
  3859. }
  3860. /**
  3861. * Set footer data.
  3862. * @param $tc (array) RGB array color for text.
  3863. * @param $lc (array) RGB array color for line.
  3864. * @public
  3865. */
  3866. public function setFooterData($tc=array(0,0,0), $lc=array(0,0,0)) {
  3867. $this->footer_text_color = $tc;
  3868. $this->footer_line_color = $lc;
  3869. }
  3870. /**
  3871. * Returns header data:
  3872. * <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>
  3873. * @return array()
  3874. * @public
  3875. * @since 4.0.012 (2008-07-24)
  3876. */
  3877. public function getHeaderData() {
  3878. $ret = array();
  3879. $ret['logo'] = $this->header_logo;
  3880. $ret['logo_width'] = $this->header_logo_width;
  3881. $ret['title'] = $this->header_title;
  3882. $ret['string'] = $this->header_string;
  3883. $ret['text_color'] = $this->header_text_color;
  3884. $ret['line_color'] = $this->header_line_color;
  3885. return $ret;
  3886. }
  3887. /**
  3888. * Set header margin.
  3889. * (minimum distance between header and top page margin)
  3890. * @param $hm (int) distance in user units
  3891. * @public
  3892. */
  3893. public function setHeaderMargin($hm=10) {
  3894. $this->header_margin = $hm;
  3895. }
  3896. /**
  3897. * Returns header margin in user units.
  3898. * @return float
  3899. * @since 4.0.012 (2008-07-24)
  3900. * @public
  3901. */
  3902. public function getHeaderMargin() {
  3903. return $this->header_margin;
  3904. }
  3905. /**
  3906. * Set footer margin.
  3907. * (minimum distance between footer and bottom page margin)
  3908. * @param $fm (int) distance in user units
  3909. * @public
  3910. */
  3911. public function setFooterMargin($fm=10) {
  3912. $this->footer_margin = $fm;
  3913. }
  3914. /**
  3915. * Returns footer margin in user units.
  3916. * @return float
  3917. * @since 4.0.012 (2008-07-24)
  3918. * @public
  3919. */
  3920. public function getFooterMargin() {
  3921. return $this->footer_margin;
  3922. }
  3923. /**
  3924. * Set a flag to print page header.
  3925. * @param $val (boolean) set to true to print the page header (default), false otherwise.
  3926. * @public
  3927. */
  3928. public function setPrintHeader($val=true) {
  3929. $this->print_header = $val ? true : false;
  3930. }
  3931. /**
  3932. * Set a flag to print page footer.
  3933. * @param $val (boolean) set to true to print the page footer (default), false otherwise.
  3934. * @public
  3935. */
  3936. public function setPrintFooter($val=true) {
  3937. $this->print_footer = $val ? true : false;
  3938. }
  3939. /**
  3940. * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
  3941. * @return float
  3942. * @public
  3943. */
  3944. public function getImageRBX() {
  3945. return $this->img_rb_x;
  3946. }
  3947. /**
  3948. * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
  3949. * @return float
  3950. * @public
  3951. */
  3952. public function getImageRBY() {
  3953. return $this->img_rb_y;
  3954. }
  3955. /**
  3956. * Reset the xobject template used by Header() method.
  3957. * @public
  3958. */
  3959. public function resetHeaderTemplate() {
  3960. $this->header_xobjid = -1;
  3961. }
  3962. /**
  3963. * Set a flag to automatically reset the xobject template used by Header() method at each page.
  3964. * @param $val (boolean) set to true to reset Header xobject template at each page, false otherwise.
  3965. * @public
  3966. */
  3967. public function setHeaderTemplateAutoreset($val=true) {
  3968. $this->header_xobj_autoreset = $val ? true : false;
  3969. }
  3970. /**
  3971. * This method is used to render the page header.
  3972. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3973. * @public
  3974. */
  3975. public function Header() {
  3976. if ($this->header_xobjid < 0) {
  3977. // start a new XObject Template
  3978. $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin);
  3979. $headerfont = $this->getHeaderFont();
  3980. $headerdata = $this->getHeaderData();
  3981. $this->y = $this->header_margin;
  3982. if ($this->rtl) {
  3983. $this->x = $this->w - $this->original_rMargin;
  3984. } else {
  3985. $this->x = $this->original_lMargin;
  3986. }
  3987. if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) {
  3988. $imgtype = $this->getImageFileType(K_PATH_IMAGES.$headerdata['logo']);
  3989. if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  3990. $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3991. } elseif ($imgtype == 'svg') {
  3992. $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3993. } else {
  3994. $this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3995. }
  3996. $imgy = $this->getImageRBY();
  3997. } else {
  3998. $imgy = $this->y;
  3999. }
  4000. $cell_height = round(($this->cell_height_ratio * $headerfont[2]) / $this->k, 2);
  4001. // set starting margin for text data cell
  4002. if ($this->getRTL()) {
  4003. $header_x = $this->original_rMargin + ($headerdata['logo_width'] * 1.1);
  4004. } else {
  4005. $header_x = $this->original_lMargin + ($headerdata['logo_width'] * 1.1);
  4006. }
  4007. $cw = $this->w - $this->original_lMargin - $this->original_rMargin - ($headerdata['logo_width'] * 1.1);
  4008. $this->SetTextColorArray($this->header_text_color);
  4009. // header title
  4010. $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1);
  4011. $this->SetX($header_x);
  4012. $this->Cell($cw, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
  4013. // header string
  4014. $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
  4015. $this->SetX($header_x);
  4016. $this->MultiCell($cw, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false, true, 0, 'T', false);
  4017. // print an ending header line
  4018. $this->SetLineStyle(array('width' => 0.85 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $headerdata['line_color']));
  4019. $this->SetY((2.835 / $this->k) + max($imgy, $this->y));
  4020. if ($this->rtl) {
  4021. $this->SetX($this->original_rMargin);
  4022. } else {
  4023. $this->SetX($this->original_lMargin);
  4024. }
  4025. $this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');
  4026. $this->endTemplate();
  4027. }
  4028. // print header template
  4029. $x = 0;
  4030. $dx = 0;
  4031. if (!$this->header_xobj_autoreset AND $this->booklet AND (($this->page % 2) == 0)) {
  4032. // adjust margins for booklet mode
  4033. $dx = ($this->original_lMargin - $this->original_rMargin);
  4034. }
  4035. if ($this->rtl) {
  4036. $x = $this->w + $dx;
  4037. } else {
  4038. $x = 0 + $dx;
  4039. }
  4040. $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false);
  4041. if ($this->header_xobj_autoreset) {
  4042. // reset header xobject template at each page
  4043. $this->header_xobjid = -1;
  4044. }
  4045. }
  4046. /**
  4047. * This method is used to render the page footer.
  4048. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  4049. * @public
  4050. */
  4051. public function Footer() {
  4052. $cur_y = $this->y;
  4053. $this->SetTextColorArray($this->footer_text_color);
  4054. //set style for cell border
  4055. $line_width = (0.85 / $this->k);
  4056. $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $this->footer_line_color));
  4057. //print document barcode
  4058. $barcode = $this->getBarcode();
  4059. if (!empty($barcode)) {
  4060. $this->Ln($line_width);
  4061. $barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin) / 3);
  4062. $style = array(
  4063. 'position' => $this->rtl?'R':'L',
  4064. 'align' => $this->rtl?'R':'L',
  4065. 'stretch' => false,
  4066. 'fitwidth' => true,
  4067. 'cellfitalign' => '',
  4068. 'border' => false,
  4069. 'padding' => 0,
  4070. 'fgcolor' => array(0,0,0),
  4071. 'bgcolor' => false,
  4072. 'text' => false
  4073. );
  4074. $this->write1DBarcode($barcode, 'C128', '', $cur_y + $line_width, '', (($this->footer_margin / 3) - $line_width), 0.3, $style, '');
  4075. }
  4076. $w_page = isset($this->l['w_page']) ? $this->l['w_page'].' ' : '';
  4077. if (empty($this->pagegroups)) {
  4078. $pagenumtxt = $w_page.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
  4079. } else {
  4080. $pagenumtxt = $w_page.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
  4081. }
  4082. $this->SetY($cur_y);
  4083. //Print page number
  4084. if ($this->getRTL()) {
  4085. $this->SetX($this->original_rMargin);
  4086. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
  4087. } else {
  4088. $this->SetX($this->original_lMargin);
  4089. $this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');
  4090. }
  4091. }
  4092. /**
  4093. * This method is used to render the page header.
  4094. * @protected
  4095. * @since 4.0.012 (2008-07-24)
  4096. */
  4097. protected function setHeader() {
  4098. if (!$this->print_header OR ($this->state != 2)) {
  4099. return;
  4100. }
  4101. $this->InHeader = true;
  4102. $this->setGraphicVars($this->default_graphic_vars);
  4103. $temp_thead = $this->thead;
  4104. $temp_theadMargins = $this->theadMargins;
  4105. $lasth = $this->lasth;
  4106. $this->_out('q');
  4107. $this->rMargin = $this->original_rMargin;
  4108. $this->lMargin = $this->original_lMargin;
  4109. $this->SetCellPadding(0);
  4110. //set current position
  4111. if ($this->rtl) {
  4112. $this->SetXY($this->original_rMargin, $this->header_margin);
  4113. } else {
  4114. $this->SetXY($this->original_lMargin, $this->header_margin);
  4115. }
  4116. $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
  4117. $this->Header();
  4118. //restore position
  4119. if ($this->rtl) {
  4120. $this->SetXY($this->original_rMargin, $this->tMargin);
  4121. } else {
  4122. $this->SetXY($this->original_lMargin, $this->tMargin);
  4123. }
  4124. $this->_out('Q');
  4125. $this->lasth = $lasth;
  4126. $this->thead = $temp_thead;
  4127. $this->theadMargins = $temp_theadMargins;
  4128. $this->newline = false;
  4129. $this->InHeader = false;
  4130. }
  4131. /**
  4132. * This method is used to render the page footer.
  4133. * @protected
  4134. * @since 4.0.012 (2008-07-24)
  4135. */
  4136. protected function setFooter() {
  4137. if ($this->state != 2) {
  4138. return;
  4139. }
  4140. $this->InFooter = true;
  4141. // save current graphic settings
  4142. $gvars = $this->getGraphicVars();
  4143. // mark this point
  4144. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  4145. $this->_out("\n");
  4146. if ($this->print_footer) {
  4147. $this->setGraphicVars($this->default_graphic_vars);
  4148. $this->current_column = 0;
  4149. $this->num_columns = 1;
  4150. $temp_thead = $this->thead;
  4151. $temp_theadMargins = $this->theadMargins;
  4152. $lasth = $this->lasth;
  4153. $this->_out('q');
  4154. $this->rMargin = $this->original_rMargin;
  4155. $this->lMargin = $this->original_lMargin;
  4156. $this->SetCellPadding(0);
  4157. //set current position
  4158. $footer_y = $this->h - $this->footer_margin;
  4159. if ($this->rtl) {
  4160. $this->SetXY($this->original_rMargin, $footer_y);
  4161. } else {
  4162. $this->SetXY($this->original_lMargin, $footer_y);
  4163. }
  4164. $this->SetFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
  4165. $this->Footer();
  4166. //restore position
  4167. if ($this->rtl) {
  4168. $this->SetXY($this->original_rMargin, $this->tMargin);
  4169. } else {
  4170. $this->SetXY($this->original_lMargin, $this->tMargin);
  4171. }
  4172. $this->_out('Q');
  4173. $this->lasth = $lasth;
  4174. $this->thead = $temp_thead;
  4175. $this->theadMargins = $temp_theadMargins;
  4176. }
  4177. // restore graphic settings
  4178. $this->setGraphicVars($gvars);
  4179. $this->current_column = $gvars['current_column'];
  4180. $this->num_columns = $gvars['num_columns'];
  4181. // calculate footer length
  4182. $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1;
  4183. $this->InFooter = false;
  4184. }
  4185. /**
  4186. * Check if we are on the page body (excluding page header and footer).
  4187. * @return true if we are not in page header nor in page footer, false otherwise.
  4188. * @protected
  4189. * @since 5.9.091 (2011-06-15)
  4190. */
  4191. protected function inPageBody() {
  4192. return (($this->InHeader === false) AND ($this->InFooter === false));
  4193. }
  4194. /**
  4195. * This method is used to render the table header on new page (if any).
  4196. * @protected
  4197. * @since 4.5.030 (2009-03-25)
  4198. */
  4199. protected function setTableHeader() {
  4200. if ($this->num_columns > 1) {
  4201. // multi column mode
  4202. return;
  4203. }
  4204. if (isset($this->theadMargins['top'])) {
  4205. // restore the original top-margin
  4206. $this->tMargin = $this->theadMargins['top'];
  4207. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  4208. $this->y = $this->tMargin;
  4209. }
  4210. if (!$this->empty_string($this->thead) AND (!$this->inthead)) {
  4211. // set margins
  4212. $prev_lMargin = $this->lMargin;
  4213. $prev_rMargin = $this->rMargin;
  4214. $prev_cell_padding = $this->cell_padding;
  4215. $this->lMargin = $this->theadMargins['lmargin'] + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$this->theadMargins['page']]['olm']);
  4216. $this->rMargin = $this->theadMargins['rmargin'] + ($this->pagedim[$this->page]['orm'] - $this->pagedim[$this->theadMargins['page']]['orm']);
  4217. $this->cell_padding = $this->theadMargins['cell_padding'];
  4218. if ($this->rtl) {
  4219. $this->x = $this->w - $this->rMargin;
  4220. } else {
  4221. $this->x = $this->lMargin;
  4222. }
  4223. // account for special "cell" mode
  4224. if ($this->theadMargins['cell']) {
  4225. if ($this->rtl) {
  4226. $this->x -= $this->cell_padding['R'];
  4227. } else {
  4228. $this->x += $this->cell_padding['L'];
  4229. }
  4230. }
  4231. // print table header
  4232. $this->writeHTML($this->thead, false, false, false, false, '');
  4233. // set new top margin to skip the table headers
  4234. if (!isset($this->theadMargins['top'])) {
  4235. $this->theadMargins['top'] = $this->tMargin;
  4236. }
  4237. // store end of header position
  4238. if (!isset($this->columns[0]['th'])) {
  4239. $this->columns[0]['th'] = array();
  4240. }
  4241. $this->columns[0]['th']['\''.$this->page.'\''] = $this->y;
  4242. $this->tMargin = $this->y;
  4243. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  4244. $this->lasth = 0;
  4245. $this->lMargin = $prev_lMargin;
  4246. $this->rMargin = $prev_rMargin;
  4247. $this->cell_padding = $prev_cell_padding;
  4248. }
  4249. }
  4250. /**
  4251. * Returns the current page number.
  4252. * @return int page number
  4253. * @public
  4254. * @since 1.0
  4255. * @see getAliasNbPages()
  4256. */
  4257. public function PageNo() {
  4258. return $this->page;
  4259. }
  4260. /**
  4261. * Defines a new spot color.
  4262. * It can be expressed in RGB components or gray scale.
  4263. * The method can be called before the first page is created and the value is retained from page to page.
  4264. * @param $name (string) Full name of the spot color.
  4265. * @param $c (float) Cyan color for CMYK. Value between 0 and 100.
  4266. * @param $m (float) Magenta color for CMYK. Value between 0 and 100.
  4267. * @param $y (float) Yellow color for CMYK. Value between 0 and 100.
  4268. * @param $k (float) Key (Black) color for CMYK. Value between 0 and 100.
  4269. * @public
  4270. * @since 4.0.024 (2008-09-12)
  4271. * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  4272. */
  4273. public function AddSpotColor($name, $c, $m, $y, $k) {
  4274. if (!isset($this->spot_colors[$name])) {
  4275. $i = (1 + count($this->spot_colors));
  4276. $this->spot_colors[$name] = array('C' => $c, 'M' => $m, 'Y' => $y, 'K' => $k, 'name' => $name, 'i' => $i);
  4277. }
  4278. }
  4279. /**
  4280. * Return the Spot color array.
  4281. * @param $name (string) Name of the spot color.
  4282. * @return (array) Spot color array or false if not defined.
  4283. * @public
  4284. * @since 5.9.125 (2011-10-03)
  4285. */
  4286. public function getSpotColor($name) {
  4287. if (isset($this->spot_colors[$name])) {
  4288. return $this->spot_colors[$name];
  4289. }
  4290. $color = preg_replace('/[\s]*/', '', $name); // remove extra spaces
  4291. $color = strtolower($color);
  4292. if (isset($this->spotcolor[$color])) {
  4293. $this->AddSpotColor($this->spotcolor[$color][4], $this->spotcolor[$color][0], $this->spotcolor[$color][1], $this->spotcolor[$color][2], $this->spotcolor[$color][3]);
  4294. return $this->spot_colors[$this->spotcolor[$color][4]];
  4295. }
  4296. return false;
  4297. }
  4298. /**
  4299. * Set the spot color for the specified type ('draw', 'fill', 'text').
  4300. * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  4301. * @param $name (string) Name of the spot color.
  4302. * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  4303. * @return (string) PDF color command.
  4304. * @public
  4305. * @since 5.9.125 (2011-10-03)
  4306. */
  4307. public function setSpotColor($type, $name, $tint=100) {
  4308. $spotcolor = $this->getSpotColor($name);
  4309. if ($spotcolor === false) {
  4310. $this->Error('Undefined spot color: '.$name.', you must add it on the spotcolors.php file.');
  4311. }
  4312. $tint = (max(0, min(100, $tint)) / 100);
  4313. $pdfcolor = sprintf('/CS%d ', $this->spot_colors[$name]['i']);
  4314. switch ($type) {
  4315. case 'draw': {
  4316. $pdfcolor .= sprintf('CS %F SCN', $tint);
  4317. $this->DrawColor = $pdfcolor;
  4318. $this->strokecolor = $spotcolor;
  4319. break;
  4320. }
  4321. case 'fill': {
  4322. $pdfcolor .= sprintf('cs %F scn', $tint);
  4323. $this->FillColor = $pdfcolor;
  4324. $this->bgcolor = $spotcolor;
  4325. break;
  4326. }
  4327. case 'text': {
  4328. $pdfcolor .= sprintf('cs %F scn', $tint);
  4329. $this->TextColor = $pdfcolor;
  4330. $this->fgcolor = $spotcolor;
  4331. break;
  4332. }
  4333. }
  4334. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  4335. if ($this->state == 2) {
  4336. $this->_out($pdfcolor);
  4337. }
  4338. if ($this->inxobj) {
  4339. // we are inside an XObject template
  4340. $this->xobjects[$this->xobjid]['spot_colors'][$name] = $this->spot_colors[$name];
  4341. }
  4342. return $pdfcolor;
  4343. }
  4344. /**
  4345. * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
  4346. * @param $name (string) Name of the spot color.
  4347. * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  4348. * @public
  4349. * @since 4.0.024 (2008-09-12)
  4350. * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  4351. */
  4352. public function SetDrawSpotColor($name, $tint=100) {
  4353. $this->setSpotColor('draw', $name, $tint);
  4354. }
  4355. /**
  4356. * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
  4357. * @param $name (string) Name of the spot color.
  4358. * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  4359. * @public
  4360. * @since 4.0.024 (2008-09-12)
  4361. * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
  4362. */
  4363. public function SetFillSpotColor($name, $tint=100) {
  4364. $this->setSpotColor('fill', $name, $tint);
  4365. }
  4366. /**
  4367. * Defines the spot color used for text.
  4368. * @param $name (string) Name of the spot color.
  4369. * @param $tint (int) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  4370. * @public
  4371. * @since 4.0.024 (2008-09-12)
  4372. * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
  4373. */
  4374. public function SetTextSpotColor($name, $tint=100) {
  4375. $this->setSpotColor('text', $name, $tint);
  4376. }
  4377. /**
  4378. * Set the color array for the specified type ('draw', 'fill', 'text').
  4379. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  4380. * The method can be called before the first page is created and the value is retained from page to page.
  4381. * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  4382. * @param $color (array) Array of colors (1=gray, 3=RGB, 4=CMYK or 5=spotcolor=CMYK+name values).
  4383. * @param $ret (boolean) If true do not send the PDF command.
  4384. * @return (string) The PDF command or empty string.
  4385. * @public
  4386. * @since 3.1.000 (2008-06-11)
  4387. */
  4388. public function setColorArray($type, $color, $ret=false) {
  4389. if (is_array($color)) {
  4390. $color = array_values($color);
  4391. // component: grey, RGB red or CMYK cyan
  4392. $c = isset($color[0]) ? $color[0] : -1;
  4393. // component: RGB green or CMYK magenta
  4394. $m = isset($color[1]) ? $color[1] : -1;
  4395. // component: RGB blue or CMYK yellow
  4396. $y = isset($color[2]) ? $color[2] : -1;
  4397. // component: CMYK black
  4398. $k = isset($color[3]) ? $color[3] : -1;
  4399. // color name
  4400. $name = isset($color[4]) ? $color[4] : '';
  4401. if ($c >= 0) {
  4402. return $this->setColor($type, $c, $m, $y, $k, $ret, $name);
  4403. }
  4404. }
  4405. return '';
  4406. }
  4407. /**
  4408. * Defines the color used for all drawing operations (lines, rectangles and cell borders).
  4409. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  4410. * The method can be called before the first page is created and the value is retained from page to page.
  4411. * @param $color (array) Array of colors (1, 3 or 4 values).
  4412. * @param $ret (boolean) If true do not send the PDF command.
  4413. * @return string the PDF command
  4414. * @public
  4415. * @since 3.1.000 (2008-06-11)
  4416. * @see SetDrawColor()
  4417. */
  4418. public function SetDrawColorArray($color, $ret=false) {
  4419. return $this->setColorArray('draw', $color, $ret);
  4420. }
  4421. /**
  4422. * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
  4423. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  4424. * The method can be called before the first page is created and the value is retained from page to page.
  4425. * @param $color (array) Array of colors (1, 3 or 4 values).
  4426. * @param $ret (boolean) If true do not send the PDF command.
  4427. * @public
  4428. * @since 3.1.000 (2008-6-11)
  4429. * @see SetFillColor()
  4430. */
  4431. public function SetFillColorArray($color, $ret=false) {
  4432. return $this->setColorArray('fill', $color, $ret);
  4433. }
  4434. /**
  4435. * Defines the color used for text. It can be expressed in RGB components or gray scale.
  4436. * The method can be called before the first page is created and the value is retained from page to page.
  4437. * @param $color (array) Array of colors (1, 3 or 4 values).
  4438. * @param $ret (boolean) If true do not send the PDF command.
  4439. * @public
  4440. * @since 3.1.000 (2008-6-11)
  4441. * @see SetFillColor()
  4442. */
  4443. public function SetTextColorArray($color, $ret=false) {
  4444. return $this->setColorArray('text', $color, $ret);
  4445. }
  4446. /**
  4447. * Defines the color used by the specified type ('draw', 'fill', 'text').
  4448. * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  4449. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  4450. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  4451. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  4452. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  4453. * @param $ret (boolean) If true do not send the command.
  4454. * @param $name (string) spot color name (if any)
  4455. * @return (string) The PDF command or empty string.
  4456. * @public
  4457. * @since 5.9.125 (2011-10-03)
  4458. */
  4459. public function setColor($type, $col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  4460. // set default values
  4461. if (!is_numeric($col1)) {
  4462. $col1 = 0;
  4463. }
  4464. if (!is_numeric($col2)) {
  4465. $col2 = -1;
  4466. }
  4467. if (!is_numeric($col3)) {
  4468. $col3 = -1;
  4469. }
  4470. if (!is_numeric($col4)) {
  4471. $col4 = -1;
  4472. }
  4473. // set color by case
  4474. $suffix = '';
  4475. if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
  4476. // Grey scale
  4477. $col1 = max(0, min(255, $col1));
  4478. $intcolor = array('G' => $col1);
  4479. $pdfcolor = sprintf('%F ', ($col1 / 255));
  4480. $suffix = 'g';
  4481. } elseif ($col4 == -1) {
  4482. // RGB
  4483. $col1 = max(0, min(255, $col1));
  4484. $col2 = max(0, min(255, $col2));
  4485. $col3 = max(0, min(255, $col3));
  4486. $intcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  4487. $pdfcolor = sprintf('%F %F %F ', ($col1 / 255), ($col2 / 255), ($col3 / 255));
  4488. $suffix = 'rg';
  4489. } else {
  4490. $col1 = max(0, min(100, $col1));
  4491. $col2 = max(0, min(100, $col2));
  4492. $col3 = max(0, min(100, $col3));
  4493. $col4 = max(0, min(100, $col4));
  4494. if (empty($name)) {
  4495. // CMYK
  4496. $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  4497. $pdfcolor = sprintf('%F %F %F %F ', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
  4498. $suffix = 'k';
  4499. } else {
  4500. // SPOT COLOR
  4501. $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
  4502. $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
  4503. $pdfcolor = $this->setSpotColor($type, $name, 100);
  4504. }
  4505. }
  4506. switch ($type) {
  4507. case 'draw': {
  4508. $pdfcolor .= strtoupper($suffix);
  4509. $this->DrawColor = $pdfcolor;
  4510. $this->strokecolor = $intcolor;
  4511. break;
  4512. }
  4513. case 'fill': {
  4514. $pdfcolor .= $suffix;
  4515. $this->FillColor = $pdfcolor;
  4516. $this->bgcolor = $intcolor;
  4517. break;
  4518. }
  4519. case 'text': {
  4520. $pdfcolor .= $suffix;
  4521. $this->TextColor = $pdfcolor;
  4522. $this->fgcolor = $intcolor;
  4523. break;
  4524. }
  4525. }
  4526. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  4527. if (($type != 'text') AND ($this->state == 2)) {
  4528. if (!$ret) {
  4529. $this->_out($pdfcolor);
  4530. }
  4531. return $pdfcolor;
  4532. }
  4533. return '';
  4534. }
  4535. /**
  4536. * Convert a color array into a string representation.
  4537. * @param $c (array) Array of colors.
  4538. * @return (string) The color array representation.
  4539. * @protected
  4540. * @since 5.9.137 (2011-12-01)
  4541. */
  4542. protected function getColorStringFromArray($c) {
  4543. $c = array_values($c);
  4544. $color = '[';
  4545. switch (count($c)) {
  4546. case 4: {
  4547. // CMYK
  4548. $color .= sprintf('%F %F %F %F', (max(0, min(100, floatval($c[0]))) / 100), (max(0, min(100, floatval($c[1]))) / 100), (max(0, min(100, floatval($c[2]))) / 100), (max(0, min(100, floatval($c[3]))) / 100));
  4549. break;
  4550. }
  4551. case 3: {
  4552. // RGB
  4553. $color .= sprintf('%F %F %F', (max(0, min(255, floatval($c[0]))) / 255), (max(0, min(255, floatval($c[1]))) / 255), (max(0, min(255, floatval($c[2]))) / 255));
  4554. break;
  4555. }
  4556. case 1: {
  4557. // grayscale
  4558. $color .= sprintf('%F', (max(0, min(255, floatval($c[0]))) / 255));
  4559. break;
  4560. }
  4561. }
  4562. $color .= ']';
  4563. return $color;
  4564. }
  4565. /**
  4566. * 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.
  4567. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  4568. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  4569. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  4570. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  4571. * @param $ret (boolean) If true do not send the command.
  4572. * @param $name (string) spot color name (if any)
  4573. * @return string the PDF command
  4574. * @public
  4575. * @since 1.3
  4576. * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  4577. */
  4578. public function SetDrawColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  4579. return $this->setColor('draw', $col1, $col2, $col3, $col4, $ret, $name);
  4580. }
  4581. /**
  4582. * 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.
  4583. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  4584. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  4585. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  4586. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  4587. * @param $ret (boolean) If true do not send the command.
  4588. * @param $name (string) Spot color name (if any).
  4589. * @return (string) The PDF command.
  4590. * @public
  4591. * @since 1.3
  4592. * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  4593. */
  4594. public function SetFillColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  4595. return $this->setColor('fill', $col1, $col2, $col3, $col4, $ret, $name);
  4596. }
  4597. /**
  4598. * 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.
  4599. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  4600. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  4601. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  4602. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  4603. * @param $ret (boolean) If true do not send the command.
  4604. * @param $name (string) Spot color name (if any).
  4605. * @return (string) Empty string.
  4606. * @public
  4607. * @since 1.3
  4608. * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  4609. */
  4610. public function SetTextColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  4611. return $this->setColor('text', $col1, $col2, $col3, $col4, $ret, $name);
  4612. }
  4613. /**
  4614. * Returns the length of a string in user unit. A font must be selected.<br>
  4615. * @param $s (string) The string whose length is to be computed
  4616. * @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.
  4617. * @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.
  4618. * @param $fontsize (float) Font size in points. The default value is the current size.
  4619. * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
  4620. * @return mixed int total string length or array of characted widths
  4621. * @author Nicola Asuni
  4622. * @public
  4623. * @since 1.2
  4624. */
  4625. public function GetStringWidth($s, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
  4626. return $this->GetArrStringWidth($this->utf8Bidi($this->UTF8StringToArray($s), $s, $this->tmprtl), $fontname, $fontstyle, $fontsize, $getarray);
  4627. }
  4628. /**
  4629. * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
  4630. * @param $sa (string) The array of chars whose total length is to be computed
  4631. * @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.
  4632. * @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.
  4633. * @param $fontsize (float) Font size in points. The default value is the current size.
  4634. * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
  4635. * @return mixed int total string length or array of characted widths
  4636. * @author Nicola Asuni
  4637. * @public
  4638. * @since 2.4.000 (2008-03-06)
  4639. */
  4640. public function GetArrStringWidth($sa, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
  4641. // store current values
  4642. if (!$this->empty_string($fontname)) {
  4643. $prev_FontFamily = $this->FontFamily;
  4644. $prev_FontStyle = $this->FontStyle;
  4645. $prev_FontSizePt = $this->FontSizePt;
  4646. $this->SetFont($fontname, $fontstyle, $fontsize, '', 'default', false);
  4647. }
  4648. // convert UTF-8 array to Latin1 if required
  4649. $sa = $this->UTF8ArrToLatin1($sa);
  4650. $w = 0; // total width
  4651. $wa = array(); // array of characters widths
  4652. foreach ($sa as $ck => $char) {
  4653. // character width
  4654. $cw = $this->GetCharWidth($char, isset($sa[($ck + 1)]));
  4655. $wa[] = $cw;
  4656. $w += $cw;
  4657. }
  4658. // restore previous values
  4659. if (!$this->empty_string($fontname)) {
  4660. $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt, '', 'default', false);
  4661. }
  4662. if ($getarray) {
  4663. return $wa;
  4664. }
  4665. return $w;
  4666. }
  4667. /**
  4668. * Returns the length of the char in user unit for the current font considering current stretching and spacing (tracking).
  4669. * @param $char (int) The char code whose length is to be returned
  4670. * @param $notlast (boolean) If false ignore the font-spacing.
  4671. * @return float char width
  4672. * @author Nicola Asuni
  4673. * @public
  4674. * @since 2.4.000 (2008-03-06)
  4675. */
  4676. public function GetCharWidth($char, $notlast=true) {
  4677. // get raw width
  4678. $chw = $this->getRawCharWidth($char);
  4679. if (($this->font_spacing < 0) OR (($this->font_spacing > 0) AND $notlast)) {
  4680. // increase/decrease font spacing
  4681. $chw += $this->font_spacing;
  4682. }
  4683. if ($this->font_stretching != 100) {
  4684. // fixed stretching mode
  4685. $chw *= ($this->font_stretching / 100);
  4686. }
  4687. return $chw;
  4688. }
  4689. /**
  4690. * Returns the length of the char in user unit for the current font.
  4691. * @param $char (int) The char code whose length is to be returned
  4692. * @return float char width
  4693. * @author Nicola Asuni
  4694. * @public
  4695. * @since 5.9.000 (2010-09-28)
  4696. */
  4697. public function getRawCharWidth($char) {
  4698. if ($char == 173) {
  4699. // SHY character will not be printed
  4700. return (0);
  4701. }
  4702. if (isset($this->CurrentFont['cw'][$char])) {
  4703. $w = $this->CurrentFont['cw'][$char];
  4704. } elseif (isset($this->CurrentFont['dw'])) {
  4705. // default width
  4706. $w = $this->CurrentFont['dw'];
  4707. } elseif (isset($this->CurrentFont['cw'][32])) {
  4708. // default width
  4709. $w = $this->CurrentFont['cw'][32];
  4710. } else {
  4711. $w = 600;
  4712. }
  4713. return $this->getAbsFontMeasure($w);
  4714. }
  4715. /**
  4716. * Returns the numbero of characters in a string.
  4717. * @param $s (string) The input string.
  4718. * @return int number of characters
  4719. * @public
  4720. * @since 2.0.0001 (2008-01-07)
  4721. */
  4722. public function GetNumChars($s) {
  4723. if ($this->isUnicodeFont()) {
  4724. return count($this->UTF8StringToArray($s));
  4725. }
  4726. return strlen($s);
  4727. }
  4728. /**
  4729. * Fill the list of available fonts ($this->fontlist).
  4730. * @protected
  4731. * @since 4.0.013 (2008-07-28)
  4732. */
  4733. protected function getFontsList() {
  4734. if (($fontsdir = opendir($this->_getfontpath())) !== false) {
  4735. while (($file = readdir($fontsdir)) !== false) {
  4736. if (substr($file, -4) == '.php') {
  4737. array_push($this->fontlist, strtolower(basename($file, '.php')));
  4738. }
  4739. }
  4740. closedir($fontsdir);
  4741. }
  4742. }
  4743. /**
  4744. * Imports a TrueType, Type1, core, or CID0 font and makes it available.
  4745. * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
  4746. * 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.
  4747. * @param $family (string) Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  4748. * @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>
  4749. * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  4750. * @return array containing the font data, or false in case of error.
  4751. * @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.
  4752. * @public
  4753. * @since 1.5
  4754. * @see SetFont(), setFontSubsetting()
  4755. */
  4756. public function AddFont($family, $style='', $fontfile='', $subset='default') {
  4757. if ($subset === 'default') {
  4758. $subset = $this->font_subsetting;
  4759. }
  4760. if ($this->pdfa_mode) {
  4761. $subset = false;
  4762. }
  4763. if ($this->empty_string($family)) {
  4764. if (!$this->empty_string($this->FontFamily)) {
  4765. $family = $this->FontFamily;
  4766. } else {
  4767. $this->Error('Empty font family');
  4768. }
  4769. }
  4770. // move embedded styles on $style
  4771. if (substr($family, -1) == 'I') {
  4772. $style .= 'I';
  4773. $family = substr($family, 0, -1);
  4774. }
  4775. if (substr($family, -1) == 'B') {
  4776. $style .= 'B';
  4777. $family = substr($family, 0, -1);
  4778. }
  4779. // normalize family name
  4780. $family = strtolower($family);
  4781. if ((!$this->isunicode) AND ($family == 'arial')) {
  4782. $family = 'helvetica';
  4783. }
  4784. if (($family == 'symbol') OR ($family == 'zapfdingbats')) {
  4785. $style = '';
  4786. }
  4787. if ($this->pdfa_mode AND (isset($this->CoreFonts[$family]))) {
  4788. // all fonts must be embedded
  4789. $family = 'pdfa'.$family;
  4790. }
  4791. $tempstyle = strtoupper($style);
  4792. $style = '';
  4793. // underline
  4794. if (strpos($tempstyle, 'U') !== false) {
  4795. $this->underline = true;
  4796. } else {
  4797. $this->underline = false;
  4798. }
  4799. // line-through (deleted)
  4800. if (strpos($tempstyle, 'D') !== false) {
  4801. $this->linethrough = true;
  4802. } else {
  4803. $this->linethrough = false;
  4804. }
  4805. // overline
  4806. if (strpos($tempstyle, 'O') !== false) {
  4807. $this->overline = true;
  4808. } else {
  4809. $this->overline = false;
  4810. }
  4811. // bold
  4812. if (strpos($tempstyle, 'B') !== false) {
  4813. $style .= 'B';
  4814. }
  4815. // oblique
  4816. if (strpos($tempstyle, 'I') !== false) {
  4817. $style .= 'I';
  4818. }
  4819. $bistyle = $style;
  4820. $fontkey = $family.$style;
  4821. $font_style = $style.($this->underline ? 'U' : '').($this->linethrough ? 'D' : '').($this->overline ? 'O' : '');
  4822. $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style);
  4823. // check if the font has been already added
  4824. $fb = $this->getFontBuffer($fontkey);
  4825. if ($fb !== false) {
  4826. if ($this->inxobj) {
  4827. // we are inside an XObject template
  4828. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $fb['i'];
  4829. }
  4830. return $fontdata;
  4831. }
  4832. if (isset($type)) {
  4833. unset($type);
  4834. }
  4835. if (isset($cw)) {
  4836. unset($cw);
  4837. }
  4838. // get specified font directory (if any)
  4839. $fontdir = false;
  4840. if (!$this->empty_string($fontfile)) {
  4841. $fontdir = dirname($fontfile);
  4842. if ($this->empty_string($fontdir) OR ($fontdir == '.')) {
  4843. $fontdir = '';
  4844. } else {
  4845. $fontdir .= '/';
  4846. }
  4847. }
  4848. $missing_style = false; // true when the font style variation is missing
  4849. // search and include font file
  4850. if ($this->empty_string($fontfile) OR (!file_exists($fontfile))) {
  4851. // build a standard filenames for specified font
  4852. $tmp_fontfile = str_replace(' ', '', $family).strtolower($style).'.php';
  4853. // search files on various directories
  4854. if (($fontdir !== false) AND file_exists($fontdir.$tmp_fontfile)) {
  4855. $fontfile = $fontdir.$tmp_fontfile;
  4856. } elseif (file_exists($this->_getfontpath().$tmp_fontfile)) {
  4857. $fontfile = $this->_getfontpath().$tmp_fontfile;
  4858. } elseif (file_exists($tmp_fontfile)) {
  4859. $fontfile = $tmp_fontfile;
  4860. } elseif (!$this->empty_string($style)) {
  4861. $missing_style = true;
  4862. // try to remove the style part
  4863. $tmp_fontfile = str_replace(' ', '', $family).'.php';
  4864. if (($fontdir !== false) AND file_exists($fontdir.$tmp_fontfile)) {
  4865. $fontfile = $fontdir.$tmp_fontfile;
  4866. } elseif (file_exists($this->_getfontpath().$tmp_fontfile)) {
  4867. $fontfile = $this->_getfontpath().$tmp_fontfile;
  4868. } else {
  4869. $fontfile = $tmp_fontfile;
  4870. }
  4871. }
  4872. }
  4873. // include font file
  4874. if (file_exists($fontfile)) {
  4875. include($fontfile);
  4876. } else {
  4877. $this->Error('Could not include font definition file: '.$family.'');
  4878. }
  4879. // check font parameters
  4880. if ((!isset($type)) OR (!isset($cw))) {
  4881. $this->Error('The font definition file has a bad format: '.$fontfile.'');
  4882. }
  4883. // SET default parameters
  4884. if (!isset($file) OR $this->empty_string($file)) {
  4885. $file = '';
  4886. }
  4887. if (!isset($enc) OR $this->empty_string($enc)) {
  4888. $enc = '';
  4889. }
  4890. if (!isset($cidinfo) OR $this->empty_string($cidinfo)) {
  4891. $cidinfo = array('Registry'=>'Adobe', 'Ordering'=>'Identity', 'Supplement'=>0);
  4892. $cidinfo['uni2cid'] = array();
  4893. }
  4894. if (!isset($ctg) OR $this->empty_string($ctg)) {
  4895. $ctg = '';
  4896. }
  4897. if (!isset($desc) OR $this->empty_string($desc)) {
  4898. $desc = array();
  4899. }
  4900. if (!isset($up) OR $this->empty_string($up)) {
  4901. $up = -100;
  4902. }
  4903. if (!isset($ut) OR $this->empty_string($ut)) {
  4904. $ut = 50;
  4905. }
  4906. if (!isset($cw) OR $this->empty_string($cw)) {
  4907. $cw = array();
  4908. }
  4909. if (!isset($dw) OR $this->empty_string($dw)) {
  4910. // set default width
  4911. if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) {
  4912. $dw = $desc['MissingWidth'];
  4913. } elseif (isset($cw[32])) {
  4914. $dw = $cw[32];
  4915. } else {
  4916. $dw = 600;
  4917. }
  4918. }
  4919. ++$this->numfonts;
  4920. if ($type == 'core') {
  4921. $name = $this->CoreFonts[$fontkey];
  4922. $subset = false;
  4923. } elseif (($type == 'TrueType') OR ($type == 'Type1')) {
  4924. $subset = false;
  4925. } elseif ($type == 'TrueTypeUnicode') {
  4926. $enc = 'Identity-H';
  4927. } elseif ($type == 'cidfont0') {
  4928. if ($this->pdfa_mode) {
  4929. $this->Error('All fonts must be embedded in PDF/A mode!');
  4930. }
  4931. } else {
  4932. $this->Error('Unknow font type: '.$type.'');
  4933. }
  4934. // set name if unset
  4935. if (!isset($name) OR empty($name)) {
  4936. $name = $fontkey;
  4937. }
  4938. // create artificial font style variations if missing (only works with non-embedded fonts)
  4939. if (($type != 'core') AND $missing_style) {
  4940. // style variations
  4941. $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic');
  4942. $name .= $styles[$bistyle];
  4943. // artificial bold
  4944. if (strpos($bistyle, 'B') !== false) {
  4945. if (isset($desc['StemV'])) {
  4946. // from normal to bold
  4947. $desc['StemV'] = round($desc['StemV'] * 1.75);
  4948. } else {
  4949. // bold
  4950. $desc['StemV'] = 123;
  4951. }
  4952. }
  4953. // artificial italic
  4954. if (strpos($bistyle, 'I') !== false) {
  4955. if (isset($desc['ItalicAngle'])) {
  4956. $desc['ItalicAngle'] -= 11;
  4957. } else {
  4958. $desc['ItalicAngle'] = -11;
  4959. }
  4960. if (isset($desc['Flags'])) {
  4961. $desc['Flags'] |= 64; //bit 7
  4962. } else {
  4963. $desc['Flags'] = 64;
  4964. }
  4965. }
  4966. }
  4967. // check if the array of characters bounding boxes is defined
  4968. if (!isset($cbbox)) {
  4969. $cbbox = array();
  4970. }
  4971. // initialize subsetchars
  4972. $subsetchars = array_fill(0, 255, true);
  4973. $this->setFontBuffer($fontkey, array('fontkey' => $fontkey, 'i' => $this->numfonts, 'type' => $type, 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'cbbox' => $cbbox, 'dw' => $dw, 'enc' => $enc, 'cidinfo' => $cidinfo, 'file' => $file, 'ctg' => $ctg, 'subset' => $subset, 'subsetchars' => $subsetchars));
  4974. if ($this->inxobj) {
  4975. // we are inside an XObject template
  4976. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts;
  4977. }
  4978. if (isset($diff) AND (!empty($diff))) {
  4979. //Search existing encodings
  4980. $d = 0;
  4981. $nb = count($this->diffs);
  4982. for ($i=1; $i <= $nb; ++$i) {
  4983. if ($this->diffs[$i] == $diff) {
  4984. $d = $i;
  4985. break;
  4986. }
  4987. }
  4988. if ($d == 0) {
  4989. $d = $nb + 1;
  4990. $this->diffs[$d] = $diff;
  4991. }
  4992. $this->setFontSubBuffer($fontkey, 'diff', $d);
  4993. }
  4994. if (!$this->empty_string($file)) {
  4995. if (!isset($this->FontFiles[$file])) {
  4996. if ((strcasecmp($type,'TrueType') == 0) OR (strcasecmp($type, 'TrueTypeUnicode') == 0)) {
  4997. $this->FontFiles[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  4998. } elseif ($type != 'core') {
  4999. $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  5000. }
  5001. } else {
  5002. // update fontkeys that are sharing this font file
  5003. $this->FontFiles[$file]['subset'] = ($this->FontFiles[$file]['subset'] AND $subset);
  5004. if (!in_array($fontkey, $this->FontFiles[$file]['fontkeys'])) {
  5005. $this->FontFiles[$file]['fontkeys'][] = $fontkey;
  5006. }
  5007. }
  5008. }
  5009. return $fontdata;
  5010. }
  5011. /**
  5012. * Sets the font used to print character strings.
  5013. * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  5014. * The method can be called before the first page is created and the font is retained from page to page.
  5015. * If you just wish to change the current font size, it is simpler to call SetFontSize().
  5016. * 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 />
  5017. * @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.
  5018. * @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.
  5019. * @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
  5020. * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  5021. * @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.
  5022. * @param $out (boolean) if true output the font size command, otherwise only set the font properties.
  5023. * @author Nicola Asuni
  5024. * @public
  5025. * @since 1.0
  5026. * @see AddFont(), SetFontSize()
  5027. */
  5028. public function SetFont($family, $style='', $size=null, $fontfile='', $subset='default', $out=true) {
  5029. //Select a font; size given in points
  5030. if ($size === null) {
  5031. $size = $this->FontSizePt;
  5032. }
  5033. if ($size < 0) {
  5034. $size = 0;
  5035. }
  5036. // try to add font (if not already added)
  5037. $fontdata = $this->AddFont($family, $style, $fontfile, $subset);
  5038. $this->FontFamily = $fontdata['family'];
  5039. $this->FontStyle = $fontdata['style'];
  5040. $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
  5041. $this->SetFontSize($size, $out);
  5042. }
  5043. /**
  5044. * Defines the size of the current font.
  5045. * @param $size (float) The font size in points.
  5046. * @param $out (boolean) if true output the font size command, otherwise only set the font properties.
  5047. * @public
  5048. * @since 1.0
  5049. * @see SetFont()
  5050. */
  5051. public function SetFontSize($size, $out=true) {
  5052. // font size in points
  5053. $this->FontSizePt = $size;
  5054. // font size in user units
  5055. $this->FontSize = $size / $this->k;
  5056. // calculate some font metrics
  5057. if (isset($this->CurrentFont['desc']['FontBBox'])) {
  5058. $bbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  5059. $font_height = ((intval($bbox[3]) - intval($bbox[1])) * $size / 1000);
  5060. } else {
  5061. $font_height = $size * 1.219;
  5062. }
  5063. if (isset($this->CurrentFont['desc']['Ascent']) AND ($this->CurrentFont['desc']['Ascent'] > 0)) {
  5064. $font_ascent = ($this->CurrentFont['desc']['Ascent'] * $size / 1000);
  5065. }
  5066. if (isset($this->CurrentFont['desc']['Descent']) AND ($this->CurrentFont['desc']['Descent'] <= 0)) {
  5067. $font_descent = (- $this->CurrentFont['desc']['Descent'] * $size / 1000);
  5068. }
  5069. if (!isset($font_ascent) AND !isset($font_descent)) {
  5070. // core font
  5071. $font_ascent = 0.76 * $font_height;
  5072. $font_descent = $font_height - $font_ascent;
  5073. } elseif (!isset($font_descent)) {
  5074. $font_descent = $font_height - $font_ascent;
  5075. } elseif (!isset($font_ascent)) {
  5076. $font_ascent = $font_height - $font_descent;
  5077. }
  5078. $this->FontAscent = ($font_ascent / $this->k);
  5079. $this->FontDescent = ($font_descent / $this->k);
  5080. if ($out AND ($this->page > 0) AND (isset($this->CurrentFont['i'])) AND ($this->state == 2)) {
  5081. $this->_out(sprintf('BT /F%d %F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  5082. }
  5083. }
  5084. /**
  5085. * Returns the bounding box of the current font in user units.
  5086. * @return array
  5087. * @public
  5088. * @since 5.9.152 (2012-03-23)
  5089. */
  5090. public function getFontBBox() {
  5091. $fbbox = array();
  5092. if (isset($this->CurrentFont['desc']['FontBBox'])) {
  5093. $tmpbbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  5094. $fbbox = array_map(array($this,'getAbsFontMeasure'), $tmpbbox);
  5095. } else {
  5096. // Find max width
  5097. if (isset($this->CurrentFont['desc']['MaxWidth'])) {
  5098. $maxw = $this->getAbsFontMeasure(intval($this->CurrentFont['desc']['MaxWidth']));
  5099. } else {
  5100. $maxw = 0;
  5101. if (isset($this->CurrentFont['desc']['MissingWidth'])) {
  5102. $maxw = max($maxw, $this->CurrentFont['desc']['MissingWidth']);
  5103. }
  5104. if (isset($this->CurrentFont['desc']['AvgWidth'])) {
  5105. $maxw = max($maxw, $this->CurrentFont['desc']['AvgWidth']);
  5106. }
  5107. if (isset($this->CurrentFont['dw'])) {
  5108. $maxw = max($maxw, $this->CurrentFont['dw']);
  5109. }
  5110. foreach ($this->CurrentFont['cw'] as $char => $w) {
  5111. $maxw = max($maxw, $w);
  5112. }
  5113. if ($maxw == 0) {
  5114. $maxw = 600;
  5115. }
  5116. $maxw = $this->getAbsFontMeasure($maxw);
  5117. }
  5118. $fbbox = array(0, -$this->FontDescent, $maxw, $this->FontAscent);
  5119. }
  5120. return $fbbox;
  5121. }
  5122. /**
  5123. * Convert a relative font measure into absolute value.
  5124. * @param $s (int) Font measure.
  5125. * @return float Absolute measure.
  5126. * @since 5.9.186 (2012-09-13)
  5127. */
  5128. public function getAbsFontMeasure($s) {
  5129. return ($s * $this->FontSize / 1000);
  5130. }
  5131. /**
  5132. * Returns the glyph bounding box of the specified character in the current font in user units.
  5133. * @param $char (int) Input character code.
  5134. * @return mixed array(xMin, yMin, xMax, yMax) or FALSE if not defined.
  5135. * @since 5.9.186 (2012-09-13)
  5136. */
  5137. public function getCharBBox($char) {
  5138. if (isset($this->CurrentFont['cbbox'][$char])) {
  5139. return array_map(array($this,'getAbsFontMeasure'), $this->CurrentFont['cbbox'][intval($char)]);
  5140. }
  5141. return false;
  5142. }
  5143. /**
  5144. * Return the font descent value
  5145. * @param $font (string) font name
  5146. * @param $style (string) font style
  5147. * @param $size (float) The size (in points)
  5148. * @return int font descent
  5149. * @public
  5150. * @author Nicola Asuni
  5151. * @since 4.9.003 (2010-03-30)
  5152. */
  5153. public function getFontDescent($font, $style='', $size=0) {
  5154. $fontdata = $this->AddFont($font, $style);
  5155. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  5156. if (isset($fontinfo['desc']['Descent']) AND ($fontinfo['desc']['Descent'] <= 0)) {
  5157. $descent = (- $fontinfo['desc']['Descent'] * $size / 1000);
  5158. } else {
  5159. $descent = (1.219 * 0.24 * $size);
  5160. }
  5161. return ($descent / $this->k);
  5162. }
  5163. /**
  5164. * Return the font ascent value.
  5165. * @param $font (string) font name
  5166. * @param $style (string) font style
  5167. * @param $size (float) The size (in points)
  5168. * @return int font ascent
  5169. * @public
  5170. * @author Nicola Asuni
  5171. * @since 4.9.003 (2010-03-30)
  5172. */
  5173. public function getFontAscent($font, $style='', $size=0) {
  5174. $fontdata = $this->AddFont($font, $style);
  5175. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  5176. if (isset($fontinfo['desc']['Ascent']) AND ($fontinfo['desc']['Ascent'] > 0)) {
  5177. $ascent = ($fontinfo['desc']['Ascent'] * $size / 1000);
  5178. } else {
  5179. $ascent = 1.219 * 0.76 * $size;
  5180. }
  5181. return ($ascent / $this->k);
  5182. }
  5183. /**
  5184. * Return true in the character is present in the specified font.
  5185. * @param $char (mixed) Character to check (integer value or string)
  5186. * @param $font (string) Font name (family name).
  5187. * @param $style (string) Font style.
  5188. * @return (boolean) true if the char is defined, false otherwise.
  5189. * @public
  5190. * @since 5.9.153 (2012-03-28)
  5191. */
  5192. public function isCharDefined($char, $font='', $style='') {
  5193. if (is_string($char)) {
  5194. // get character code
  5195. $char = $this->UTF8StringToArray($char);
  5196. $char = $char[0];
  5197. }
  5198. if ($this->empty_string($font)) {
  5199. if ($this->empty_string($style)) {
  5200. return (isset($this->CurrentFont['cw'][intval($char)]));
  5201. }
  5202. $font = $this->FontFamily;
  5203. }
  5204. $fontdata = $this->AddFont($font, $style);
  5205. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  5206. return (isset($fontinfo['cw'][intval($char)]));
  5207. }
  5208. /**
  5209. * Replace missing font characters on selected font with specified substitutions.
  5210. * @param $text (string) Text to process.
  5211. * @param $font (string) Font name (family name).
  5212. * @param $style (string) Font style.
  5213. * @param $subs (array) Array of possible character substitutions. The key is the character to check (integer value) and the value is a single intege value or an array of possible substitutes.
  5214. * @return (string) Processed text.
  5215. * @public
  5216. * @since 5.9.153 (2012-03-28)
  5217. */
  5218. public function replaceMissingChars($text, $font='', $style='', $subs=array()) {
  5219. if (empty($subs)) {
  5220. return $text;
  5221. }
  5222. if ($this->empty_string($font)) {
  5223. $font = $this->FontFamily;
  5224. }
  5225. $fontdata = $this->AddFont($font, $style);
  5226. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  5227. $uniarr = $this->UTF8StringToArray($text);
  5228. foreach ($uniarr as $k => $chr) {
  5229. if (!isset($fontinfo['cw'][$chr])) {
  5230. // this character is missing on the selected font
  5231. if (isset($subs[$chr])) {
  5232. // we have available substitutions
  5233. if (is_array($subs[$chr])) {
  5234. foreach($subs[$chr] as $s) {
  5235. if (isset($fontinfo['cw'][$s])) {
  5236. $uniarr[$k] = $s;
  5237. break;
  5238. }
  5239. }
  5240. } elseif (isset($fontinfo['cw'][$subs[$chr]])) {
  5241. $uniarr[$k] = $subs[$chr];
  5242. }
  5243. }
  5244. }
  5245. }
  5246. return $this->UniArrSubString($this->UTF8ArrayToUniArray($uniarr));
  5247. }
  5248. /**
  5249. * Defines the default monospaced font.
  5250. * @param $font (string) Font name.
  5251. * @public
  5252. * @since 4.5.025
  5253. */
  5254. public function SetDefaultMonospacedFont($font) {
  5255. $this->default_monospaced_font = $font;
  5256. }
  5257. /**
  5258. * 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 />
  5259. * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  5260. * @public
  5261. * @since 1.5
  5262. * @see Cell(), Write(), Image(), Link(), SetLink()
  5263. */
  5264. public function AddLink() {
  5265. //Create a new internal link
  5266. $n = count($this->links) + 1;
  5267. $this->links[$n] = array(0, 0);
  5268. return $n;
  5269. }
  5270. /**
  5271. * Defines the page and position a link points to.
  5272. * @param $link (int) The link identifier returned by AddLink()
  5273. * @param $y (float) Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  5274. * @param $page (int) Number of target page; -1 indicates the current page. This is the default value
  5275. * @public
  5276. * @since 1.5
  5277. * @see AddLink()
  5278. */
  5279. public function SetLink($link, $y=0, $page=-1) {
  5280. if ($y == -1) {
  5281. $y = $this->y;
  5282. }
  5283. if ($page == -1) {
  5284. $page = $this->page;
  5285. }
  5286. $this->links[$link] = array($page, $y);
  5287. }
  5288. /**
  5289. * Puts a link on a rectangular area of the page.
  5290. * 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.
  5291. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  5292. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  5293. * @param $w (float) Width of the rectangle
  5294. * @param $h (float) Height of the rectangle
  5295. * @param $link (mixed) URL or identifier returned by AddLink()
  5296. * @param $spaces (int) number of spaces on the text to link
  5297. * @public
  5298. * @since 1.5
  5299. * @see AddLink(), Annotation(), Cell(), Write(), Image()
  5300. */
  5301. public function Link($x, $y, $w, $h, $link, $spaces=0) {
  5302. $this->Annotation($x, $y, $w, $h, $link, array('Subtype'=>'Link'), $spaces);
  5303. }
  5304. /**
  5305. * Check if the URL exist.
  5306. * @param $ur (string) URL to check.
  5307. * @return Boolean true if the URl exist, false otherwise.
  5308. * @public
  5309. * @since 5.9.204 (2013-01-28)
  5310. */
  5311. public function isValidURL($url) {
  5312. $headers = @get_headers($url);
  5313. return (strpos($headers[0], '200') !== false);
  5314. }
  5315. /**
  5316. * Puts a markup annotation on a rectangular area of the page.
  5317. * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
  5318. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  5319. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  5320. * @param $w (float) Width of the rectangle
  5321. * @param $h (float) Height of the rectangle
  5322. * @param $text (string) annotation text or alternate content
  5323. * @param $opt (array) array of options (see section 8.4 of PDF reference 1.7).
  5324. * @param $spaces (int) number of spaces on the text to link
  5325. * @public
  5326. * @since 4.0.018 (2008-08-06)
  5327. */
  5328. public function Annotation($x, $y, $w, $h, $text, $opt=array('Subtype'=>'Text'), $spaces=0) {
  5329. if ($this->inxobj) {
  5330. // store parameters for later use on template
  5331. $this->xobjects[$this->xobjid]['annotations'][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'text' => $text, 'opt' => $opt, 'spaces' => $spaces);
  5332. return;
  5333. }
  5334. if ($x === '') {
  5335. $x = $this->x;
  5336. }
  5337. if ($y === '') {
  5338. $y = $this->y;
  5339. }
  5340. // check page for no-write regions and adapt page margins if necessary
  5341. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  5342. // recalculate coordinates to account for graphic transformations
  5343. if (isset($this->transfmatrix) AND !empty($this->transfmatrix)) {
  5344. for ($i=$this->transfmatrix_key; $i > 0; --$i) {
  5345. $maxid = count($this->transfmatrix[$i]) - 1;
  5346. for ($j=$maxid; $j >= 0; --$j) {
  5347. $ctm = $this->transfmatrix[$i][$j];
  5348. if (isset($ctm['a'])) {
  5349. $x = $x * $this->k;
  5350. $y = ($this->h - $y) * $this->k;
  5351. $w = $w * $this->k;
  5352. $h = $h * $this->k;
  5353. // top left
  5354. $xt = $x;
  5355. $yt = $y;
  5356. $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  5357. $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  5358. // top right
  5359. $xt = $x + $w;
  5360. $yt = $y;
  5361. $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  5362. $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  5363. // bottom left
  5364. $xt = $x;
  5365. $yt = $y - $h;
  5366. $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  5367. $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  5368. // bottom right
  5369. $xt = $x + $w;
  5370. $yt = $y - $h;
  5371. $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  5372. $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  5373. // new coordinates (rectangle area)
  5374. $x = min($x1, $x2, $x3, $x4);
  5375. $y = max($y1, $y2, $y3, $y4);
  5376. $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k;
  5377. $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k;
  5378. $x = $x / $this->k;
  5379. $y = $this->h - ($y / $this->k);
  5380. }
  5381. }
  5382. }
  5383. }
  5384. if ($this->page <= 0) {
  5385. $page = 1;
  5386. } else {
  5387. $page = $this->page;
  5388. }
  5389. if (!isset($this->PageAnnots[$page])) {
  5390. $this->PageAnnots[$page] = array();
  5391. }
  5392. $this->PageAnnots[$page][] = array('n' => ++$this->n, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces);
  5393. if (!$this->pdfa_mode) {
  5394. if ((($opt['Subtype'] == 'FileAttachment') OR ($opt['Subtype'] == 'Sound')) AND (!$this->empty_string($opt['FS']))
  5395. AND (file_exists($opt['FS']) OR $this->isValidURL($opt['FS']))
  5396. AND (!isset($this->embeddedfiles[basename($opt['FS'])]))) {
  5397. $this->embeddedfiles[basename($opt['FS'])] = array('f' => ++$this->n, 'n' => ++$this->n, 'file' => $opt['FS']);
  5398. }
  5399. }
  5400. // Add widgets annotation's icons
  5401. if (isset($opt['mk']['i']) AND file_exists($opt['mk']['i'])) {
  5402. $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
  5403. }
  5404. if (isset($opt['mk']['ri']) AND file_exists($opt['mk']['ri'])) {
  5405. $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  5406. }
  5407. if (isset($opt['mk']['ix']) AND file_exists($opt['mk']['ix'])) {
  5408. $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  5409. }
  5410. }
  5411. /**
  5412. * Embedd the attached files.
  5413. * @since 4.4.000 (2008-12-07)
  5414. * @protected
  5415. * @see Annotation()
  5416. */
  5417. protected function _putEmbeddedFiles() {
  5418. if ($this->pdfa_mode) {
  5419. // embedded files are not allowed in PDF/A mode
  5420. return;
  5421. }
  5422. reset($this->embeddedfiles);
  5423. foreach ($this->embeddedfiles as $filename => $filedata) {
  5424. // update name tree
  5425. $this->efnames[$filename] = $filedata['f'].' 0 R';
  5426. // embedded file specification object
  5427. $out = $this->_getobj($filedata['f'])."\n";
  5428. $out .= '<</Type /Filespec /F '.$this->_datastring($filename, $filedata['f']).' /EF <</F '.$filedata['n'].' 0 R>> >>';
  5429. $out .= "\n".'endobj';
  5430. $this->_out($out);
  5431. // embedded file object
  5432. $data = file_get_contents($filedata['file']);
  5433. $filter = '';
  5434. $rawsize = strlen($data);
  5435. if ($this->compress) {
  5436. $data = gzcompress($data);
  5437. $filter = ' /Filter /FlateDecode';
  5438. }
  5439. $stream = $this->_getrawstream($data, $filedata['n']);
  5440. $out = $this->_getobj($filedata['n'])."\n";
  5441. $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' /Params <</Size '.$rawsize.'>> >>';
  5442. $out .= ' stream'."\n".$stream."\n".'endstream';
  5443. $out .= "\n".'endobj';
  5444. $this->_out($out);
  5445. }
  5446. }
  5447. /**
  5448. * Prints a text cell at the specified position.
  5449. * This method allows to place a string precisely on the page.
  5450. * @param $x (float) Abscissa of the cell origin
  5451. * @param $y (float) Ordinate of the cell origin
  5452. * @param $txt (string) String to print
  5453. * @param $fstroke (int) outline size in user units (false = disable)
  5454. * @param $fclip (boolean) if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
  5455. * @param $ffill (boolean) if true fills the text
  5456. * @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)))
  5457. * @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.
  5458. * @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>
  5459. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  5460. * @param $link (mixed) URL or identifier returned by AddLink().
  5461. * @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.
  5462. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  5463. * @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>
  5464. * @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>
  5465. * @param $rtloff (boolean) if true uses the page top-left corner as origin of axis for $x and $y initial position.
  5466. * @public
  5467. * @since 1.0
  5468. * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
  5469. */
  5470. 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) {
  5471. $textrendermode = $this->textrendermode;
  5472. $textstrokewidth = $this->textstrokewidth;
  5473. $this->setTextRenderingMode($fstroke, $ffill, $fclip);
  5474. $this->SetXY($x, $y, $rtloff);
  5475. $this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
  5476. // restore previous rendering mode
  5477. $this->textrendermode = $textrendermode;
  5478. $this->textstrokewidth = $textstrokewidth;
  5479. }
  5480. /**
  5481. * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
  5482. * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  5483. * This method is called automatically and should not be called directly by the application.
  5484. * @return boolean
  5485. * @public
  5486. * @since 1.4
  5487. * @see SetAutoPageBreak()
  5488. */
  5489. public function AcceptPageBreak() {
  5490. if ($this->num_columns > 1) {
  5491. // multi column mode
  5492. if ($this->current_column < ($this->num_columns - 1)) {
  5493. // go to next column
  5494. $this->selectColumn($this->current_column + 1);
  5495. } elseif ($this->AutoPageBreak) {
  5496. // add a new page
  5497. $this->AddPage();
  5498. // set first column
  5499. $this->selectColumn(0);
  5500. }
  5501. // avoid page breaking from checkPageBreak()
  5502. return false;
  5503. }
  5504. return $this->AutoPageBreak;
  5505. }
  5506. /**
  5507. * Add page if needed.
  5508. * @param $h (float) Cell height. Default value: 0.
  5509. * @param $y (mixed) starting y position, leave empty for current position.
  5510. * @param $addpage (boolean) if true add a page, otherwise only return the true/false state
  5511. * @return boolean true in case of page break, false otherwise.
  5512. * @since 3.2.000 (2008-07-01)
  5513. * @protected
  5514. */
  5515. protected function checkPageBreak($h=0, $y='', $addpage=true) {
  5516. if ($this->empty_string($y)) {
  5517. $y = $this->y;
  5518. }
  5519. $current_page = $this->page;
  5520. if ((($y + $h) > $this->PageBreakTrigger) AND ($this->inPageBody()) AND ($this->AcceptPageBreak())) {
  5521. if ($addpage) {
  5522. //Automatic page break
  5523. $x = $this->x;
  5524. $this->AddPage($this->CurOrientation);
  5525. $this->y = $this->tMargin;
  5526. $oldpage = $this->page - 1;
  5527. if ($this->rtl) {
  5528. if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm']) {
  5529. $this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']);
  5530. } else {
  5531. $this->x = $x;
  5532. }
  5533. } else {
  5534. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  5535. $this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']);
  5536. } else {
  5537. $this->x = $x;
  5538. }
  5539. }
  5540. }
  5541. return true;
  5542. }
  5543. if ($current_page != $this->page) {
  5544. // account for columns mode
  5545. return true;
  5546. }
  5547. return false;
  5548. }
  5549. /**
  5550. * Removes SHY characters from text.
  5551. * Unicode Data:<ul>
  5552. * <li>Name : SOFT HYPHEN, commonly abbreviated as SHY</li>
  5553. * <li>HTML Entity (decimal): "&amp;#173;"</li>
  5554. * <li>HTML Entity (hex): "&amp;#xad;"</li>
  5555. * <li>HTML Entity (named): "&amp;shy;"</li>
  5556. * <li>How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]</li>
  5557. * <li>UTF-8 (hex): 0xC2 0xAD (c2ad)</li>
  5558. * <li>UTF-8 character: chr(194).chr(173)</li>
  5559. * </ul>
  5560. * @param $txt (string) input string
  5561. * @return string without SHY characters.
  5562. * @public
  5563. * @since (4.5.019) 2009-02-28
  5564. */
  5565. public function removeSHY($txt='') {
  5566. $txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt);
  5567. if (!$this->isunicode) {
  5568. $txt = preg_replace('/([\\xad]{1})/', '', $txt);
  5569. }
  5570. return $txt;
  5571. }
  5572. /**
  5573. * 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 />
  5574. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  5575. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  5576. * @param $h (float) Cell height. Default value: 0.
  5577. * @param $txt (string) String to print. Default value: empty string.
  5578. * @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)))
  5579. * @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.
  5580. * @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>
  5581. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  5582. * @param $link (mixed) URL or identifier returned by AddLink().
  5583. * @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.
  5584. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  5585. * @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>
  5586. * @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>
  5587. * @public
  5588. * @since 1.0
  5589. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  5590. */
  5591. 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') {
  5592. $prev_cell_margin = $this->cell_margin;
  5593. $prev_cell_padding = $this->cell_padding;
  5594. $this->adjustCellPadding($border);
  5595. if (!$ignore_min_height) {
  5596. $min_cell_height = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  5597. if ($h < $min_cell_height) {
  5598. $h = $min_cell_height;
  5599. }
  5600. }
  5601. $this->checkPageBreak($h + $this->cell_margin['T'] + $this->cell_margin['B']);
  5602. // apply text shadow if enabled
  5603. if ($this->txtshadow['enabled']) {
  5604. // save data
  5605. $x = $this->x;
  5606. $y = $this->y;
  5607. $bc = $this->bgcolor;
  5608. $fc = $this->fgcolor;
  5609. $sc = $this->strokecolor;
  5610. $alpha = $this->alpha;
  5611. // print shadow
  5612. $this->x += $this->txtshadow['depth_w'];
  5613. $this->y += $this->txtshadow['depth_h'];
  5614. $this->SetFillColorArray($this->txtshadow['color']);
  5615. $this->SetTextColorArray($this->txtshadow['color']);
  5616. $this->SetDrawColorArray($this->txtshadow['color']);
  5617. if ($this->txtshadow['opacity'] != $alpha['CA']) {
  5618. $this->setAlpha($this->txtshadow['opacity'], $this->txtshadow['blend_mode']);
  5619. }
  5620. if ($this->state == 2) {
  5621. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  5622. }
  5623. //restore data
  5624. $this->x = $x;
  5625. $this->y = $y;
  5626. $this->SetFillColorArray($bc);
  5627. $this->SetTextColorArray($fc);
  5628. $this->SetDrawColorArray($sc);
  5629. if ($this->txtshadow['opacity'] != $alpha['CA']) {
  5630. $this->setAlpha($alpha['CA'], $alpha['BM'], $alpha['ca'], $alpha['AIS']);
  5631. }
  5632. }
  5633. if ($this->state == 2) {
  5634. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  5635. }
  5636. $this->cell_padding = $prev_cell_padding;
  5637. $this->cell_margin = $prev_cell_margin;
  5638. }
  5639. /**
  5640. * 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 />
  5641. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  5642. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  5643. * @param $h (float) Cell height. Default value: 0.
  5644. * @param $txt (string) String to print. Default value: empty string.
  5645. * @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)))
  5646. * @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.
  5647. * @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>
  5648. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  5649. * @param $link (mixed) URL or identifier returned by AddLink().
  5650. * @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.
  5651. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  5652. * @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>
  5653. * @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>
  5654. * @return string containing cell code
  5655. * @protected
  5656. * @since 1.0
  5657. * @see Cell()
  5658. */
  5659. 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') {
  5660. // replace 'NO-BREAK SPACE' (U+00A0) character with a simple space
  5661. $txt = str_replace($this->unichr(160), ' ', $txt);
  5662. $prev_cell_margin = $this->cell_margin;
  5663. $prev_cell_padding = $this->cell_padding;
  5664. $txt = $this->removeSHY($txt);
  5665. $rs = ''; //string to be returned
  5666. $this->adjustCellPadding($border);
  5667. if (!$ignore_min_height) {
  5668. $min_cell_height = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  5669. if ($h < $min_cell_height) {
  5670. $h = $min_cell_height;
  5671. }
  5672. }
  5673. $k = $this->k;
  5674. // check page for no-write regions and adapt page margins if necessary
  5675. list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
  5676. if ($this->rtl) {
  5677. $x = $this->x - $this->cell_margin['R'];
  5678. } else {
  5679. $x = $this->x + $this->cell_margin['L'];
  5680. }
  5681. $y = $this->y + $this->cell_margin['T'];
  5682. $prev_font_stretching = $this->font_stretching;
  5683. $prev_font_spacing = $this->font_spacing;
  5684. // cell vertical alignment
  5685. switch ($calign) {
  5686. case 'A': {
  5687. // font top
  5688. switch ($valign) {
  5689. case 'T': {
  5690. // top
  5691. $y -= $this->cell_padding['T'];
  5692. break;
  5693. }
  5694. case 'B': {
  5695. // bottom
  5696. $y -= ($h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent);
  5697. break;
  5698. }
  5699. default:
  5700. case 'C':
  5701. case 'M': {
  5702. // center
  5703. $y -= (($h - $this->FontAscent - $this->FontDescent) / 2);
  5704. break;
  5705. }
  5706. }
  5707. break;
  5708. }
  5709. case 'L': {
  5710. // font baseline
  5711. switch ($valign) {
  5712. case 'T': {
  5713. // top
  5714. $y -= ($this->cell_padding['T'] + $this->FontAscent);
  5715. break;
  5716. }
  5717. case 'B': {
  5718. // bottom
  5719. $y -= ($h - $this->cell_padding['B'] - $this->FontDescent);
  5720. break;
  5721. }
  5722. default:
  5723. case 'C':
  5724. case 'M': {
  5725. // center
  5726. $y -= (($h + $this->FontAscent - $this->FontDescent) / 2);
  5727. break;
  5728. }
  5729. }
  5730. break;
  5731. }
  5732. case 'D': {
  5733. // font bottom
  5734. switch ($valign) {
  5735. case 'T': {
  5736. // top
  5737. $y -= ($this->cell_padding['T'] + $this->FontAscent + $this->FontDescent);
  5738. break;
  5739. }
  5740. case 'B': {
  5741. // bottom
  5742. $y -= ($h - $this->cell_padding['B']);
  5743. break;
  5744. }
  5745. default:
  5746. case 'C':
  5747. case 'M': {
  5748. // center
  5749. $y -= (($h + $this->FontAscent + $this->FontDescent) / 2);
  5750. break;
  5751. }
  5752. }
  5753. break;
  5754. }
  5755. case 'B': {
  5756. // cell bottom
  5757. $y -= $h;
  5758. break;
  5759. }
  5760. case 'C':
  5761. case 'M': {
  5762. // cell center
  5763. $y -= ($h / 2);
  5764. break;
  5765. }
  5766. default:
  5767. case 'T': {
  5768. // cell top
  5769. break;
  5770. }
  5771. }
  5772. // text vertical alignment
  5773. switch ($valign) {
  5774. case 'T': {
  5775. // top
  5776. $yt = $y + $this->cell_padding['T'];
  5777. break;
  5778. }
  5779. case 'B': {
  5780. // bottom
  5781. $yt = $y + $h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent;
  5782. break;
  5783. }
  5784. default:
  5785. case 'C':
  5786. case 'M': {
  5787. // center
  5788. $yt = $y + (($h - $this->FontAscent - $this->FontDescent) / 2);
  5789. break;
  5790. }
  5791. }
  5792. $basefonty = $yt + $this->FontAscent;
  5793. if ($this->empty_string($w) OR ($w <= 0)) {
  5794. if ($this->rtl) {
  5795. $w = $x - $this->lMargin;
  5796. } else {
  5797. $w = $this->w - $this->rMargin - $x;
  5798. }
  5799. }
  5800. $s = '';
  5801. // fill and borders
  5802. if (is_string($border) AND (strlen($border) == 4)) {
  5803. // full border
  5804. $border = 1;
  5805. }
  5806. if ($fill OR ($border == 1)) {
  5807. if ($fill) {
  5808. $op = ($border == 1) ? 'B' : 'f';
  5809. } else {
  5810. $op = 'S';
  5811. }
  5812. if ($this->rtl) {
  5813. $xk = (($x - $w) * $k);
  5814. } else {
  5815. $xk = ($x * $k);
  5816. }
  5817. $s .= sprintf('%F %F %F %F re %s ', $xk, (($this->h - $y) * $k), ($w * $k), (-$h * $k), $op);
  5818. }
  5819. // draw borders
  5820. $s .= $this->getCellBorder($x, $y, $w, $h, $border);
  5821. if ($txt != '') {
  5822. $txt2 = $txt;
  5823. if ($this->isunicode) {
  5824. if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
  5825. $txt2 = $this->UTF8ToLatin1($txt2);
  5826. } else {
  5827. $unicode = $this->UTF8StringToArray($txt); // array of UTF-8 unicode values
  5828. $unicode = $this->utf8Bidi($unicode, '', $this->tmprtl);
  5829. // replace thai chars (if any)
  5830. if (defined('K_THAI_TOPCHARS') AND (K_THAI_TOPCHARS == true)) {
  5831. // number of chars
  5832. $numchars = count($unicode);
  5833. // po pla, for far, for fan
  5834. $longtail = array(0x0e1b, 0x0e1d, 0x0e1f);
  5835. // do chada, to patak
  5836. $lowtail = array(0x0e0e, 0x0e0f);
  5837. // mai hun arkad, sara i, sara ii, sara ue, sara uee
  5838. $upvowel = array(0x0e31, 0x0e34, 0x0e35, 0x0e36, 0x0e37);
  5839. // mai ek, mai tho, mai tri, mai chattawa, karan
  5840. $tonemark = array(0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c);
  5841. // sara u, sara uu, pinthu
  5842. $lowvowel = array(0x0e38, 0x0e39, 0x0e3a);
  5843. $output = array();
  5844. for ($i = 0; $i < $numchars; $i++) {
  5845. if (($unicode[$i] >= 0x0e00) && ($unicode[$i] <= 0x0e5b)) {
  5846. $ch0 = $unicode[$i];
  5847. $ch1 = ($i > 0) ? $unicode[($i - 1)] : 0;
  5848. $ch2 = ($i > 1) ? $unicode[($i - 2)] : 0;
  5849. $chn = ($i < ($numchars - 1)) ? $unicode[($i + 1)] : 0;
  5850. if (in_array($ch0, $tonemark)) {
  5851. if ($chn == 0x0e33) {
  5852. // sara um
  5853. if (in_array($ch1, $longtail)) {
  5854. // tonemark at upper left
  5855. $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
  5856. } else {
  5857. // tonemark at upper right (normal position)
  5858. $output[] = $ch0;
  5859. }
  5860. } elseif (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $lowvowel))) {
  5861. // tonemark at lower left
  5862. $output[] = $this->replaceChar($ch0, (0xf705 + $ch0 - 0x0e48));
  5863. } elseif (in_array($ch1, $upvowel)) {
  5864. if (in_array($ch2, $longtail)) {
  5865. // tonemark at upper left
  5866. $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
  5867. } else {
  5868. // tonemark at upper right (normal position)
  5869. $output[] = $ch0;
  5870. }
  5871. } else {
  5872. // tonemark at lower right
  5873. $output[] = $this->replaceChar($ch0, (0xf70a + $ch0 - 0x0e48));
  5874. }
  5875. } elseif (($ch0 == 0x0e33) AND (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $tonemark)))) {
  5876. // add lower left nikhahit and sara aa
  5877. if ($this->isCharDefined(0xf711) AND $this->isCharDefined(0x0e32)) {
  5878. $output[] = 0xf711;
  5879. $this->CurrentFont['subsetchars'][0xf711] = true;
  5880. $output[] = 0x0e32;
  5881. $this->CurrentFont['subsetchars'][0x0e32] = true;
  5882. } else {
  5883. $output[] = $ch0;
  5884. }
  5885. } elseif (in_array($ch1, $longtail)) {
  5886. if ($ch0 == 0x0e31) {
  5887. // lower left mai hun arkad
  5888. $output[] = $this->replaceChar($ch0, 0xf710);
  5889. } elseif (in_array($ch0, $upvowel)) {
  5890. // lower left
  5891. $output[] = $this->replaceChar($ch0, (0xf701 + $ch0 - 0x0e34));
  5892. } elseif ($ch0 == 0x0e47) {
  5893. // lower left mai tai koo
  5894. $output[] = $this->replaceChar($ch0, 0xf712);
  5895. } else {
  5896. // normal character
  5897. $output[] = $ch0;
  5898. }
  5899. } elseif (in_array($ch1, $lowtail) AND in_array($ch0, $lowvowel)) {
  5900. // lower vowel
  5901. $output[] = $this->replaceChar($ch0, (0xf718 + $ch0 - 0x0e38));
  5902. } elseif (($ch0 == 0x0e0d) AND in_array($chn, $lowvowel)) {
  5903. // yo ying without lower part
  5904. $output[] = $this->replaceChar($ch0, 0xf70f);
  5905. } elseif (($ch0 == 0x0e10) AND in_array($chn, $lowvowel)) {
  5906. // tho santan without lower part
  5907. $output[] = $this->replaceChar($ch0, 0xf700);
  5908. } else {
  5909. $output[] = $ch0;
  5910. }
  5911. } else {
  5912. // non-thai character
  5913. $output[] = $unicode[$i];
  5914. }
  5915. }
  5916. $unicode = $output;
  5917. // update font subsetchars
  5918. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  5919. } // end of K_THAI_TOPCHARS
  5920. $txt2 = $this->arrUTF8ToUTF16BE($unicode, false);
  5921. }
  5922. }
  5923. $txt2 = $this->_escape($txt2);
  5924. // get current text width (considering general font stretching and spacing)
  5925. $txwidth = $this->GetStringWidth($txt);
  5926. $width = $txwidth;
  5927. // check for stretch mode
  5928. if ($stretch > 0) {
  5929. // calculate ratio between cell width and text width
  5930. if ($width <= 0) {
  5931. $ratio = 1;
  5932. } else {
  5933. $ratio = (($w - $this->cell_padding['L'] - $this->cell_padding['R']) / $width);
  5934. }
  5935. // check if stretching is required
  5936. if (($ratio < 1) OR (($ratio > 1) AND (($stretch % 2) == 0))) {
  5937. // the text will be stretched to fit cell width
  5938. if ($stretch > 2) {
  5939. // set new character spacing
  5940. $this->font_spacing += ($w - $this->cell_padding['L'] - $this->cell_padding['R'] - $width) / (max(($this->GetNumChars($txt) - 1), 1) * ($this->font_stretching / 100));
  5941. } else {
  5942. // set new horizontal stretching
  5943. $this->font_stretching *= $ratio;
  5944. }
  5945. // recalculate text width (the text fills the entire cell)
  5946. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5947. // reset alignment
  5948. $align = '';
  5949. }
  5950. }
  5951. if ($this->font_stretching != 100) {
  5952. // apply font stretching
  5953. $rs .= sprintf('BT %F Tz ET ', $this->font_stretching);
  5954. }
  5955. if ($this->font_spacing != 0) {
  5956. // increase/decrease font spacing
  5957. $rs .= sprintf('BT %F Tc ET ', ($this->font_spacing * $this->k));
  5958. }
  5959. if ($this->ColorFlag AND ($this->textrendermode < 4)) {
  5960. $s .= 'q '.$this->TextColor.' ';
  5961. }
  5962. // rendering mode
  5963. $s .= sprintf('BT %d Tr %F w ET ', $this->textrendermode, ($this->textstrokewidth * $this->k));
  5964. // count number of spaces
  5965. $ns = substr_count($txt, chr(32));
  5966. // Justification
  5967. $spacewidth = 0;
  5968. if (($align == 'J') AND ($ns > 0)) {
  5969. if ($this->isUnicodeFont()) {
  5970. // get string width without spaces
  5971. $width = $this->GetStringWidth(str_replace(' ', '', $txt));
  5972. // calculate average space width
  5973. $spacewidth = -1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1) / $this->FontSize;
  5974. if ($this->font_stretching != 100) {
  5975. // word spacing is affected by stretching
  5976. $spacewidth /= ($this->font_stretching / 100);
  5977. }
  5978. // set word position to be used with TJ operator
  5979. $txt2 = str_replace(chr(0).chr(32), ') '.sprintf('%F', $spacewidth).' (', $txt2);
  5980. $unicode_justification = true;
  5981. } else {
  5982. // get string width
  5983. $width = $txwidth;
  5984. // new space width
  5985. $spacewidth = (($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1)) * $this->k;
  5986. if ($this->font_stretching != 100) {
  5987. // word spacing (Tw) is affected by stretching
  5988. $spacewidth /= ($this->font_stretching / 100);
  5989. }
  5990. // set word spacing
  5991. $rs .= sprintf('BT %F Tw ET ', $spacewidth);
  5992. }
  5993. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5994. }
  5995. // replace carriage return characters
  5996. $txt2 = str_replace("\r", ' ', $txt2);
  5997. switch ($align) {
  5998. case 'C': {
  5999. $dx = ($w - $width) / 2;
  6000. break;
  6001. }
  6002. case 'R': {
  6003. if ($this->rtl) {
  6004. $dx = $this->cell_padding['R'];
  6005. } else {
  6006. $dx = $w - $width - $this->cell_padding['R'];
  6007. }
  6008. break;
  6009. }
  6010. case 'L': {
  6011. if ($this->rtl) {
  6012. $dx = $w - $width - $this->cell_padding['L'];
  6013. } else {
  6014. $dx = $this->cell_padding['L'];
  6015. }
  6016. break;
  6017. }
  6018. case 'J':
  6019. default: {
  6020. if ($this->rtl) {
  6021. $dx = $this->cell_padding['R'];
  6022. } else {
  6023. $dx = $this->cell_padding['L'];
  6024. }
  6025. break;
  6026. }
  6027. }
  6028. if ($this->rtl) {
  6029. $xdx = $x - $dx - $width;
  6030. } else {
  6031. $xdx = $x + $dx;
  6032. }
  6033. $xdk = $xdx * $k;
  6034. // print text
  6035. $s .= sprintf('BT %F %F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
  6036. if (isset($uniblock)) {
  6037. // print overlapping characters as separate string
  6038. $xshift = 0; // horizontal shift
  6039. $ty = (($this->h - $basefonty + (0.2 * $this->FontSize)) * $k);
  6040. $spw = (($w - $txwidth - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1));
  6041. foreach ($uniblock as $uk => $uniarr) {
  6042. if (($uk % 2) == 0) {
  6043. // x space to skip
  6044. if ($spacewidth != 0) {
  6045. // justification shift
  6046. $xshift += (count(array_keys($uniarr, 32)) * $spw);
  6047. }
  6048. $xshift += $this->GetArrStringWidth($uniarr); // + shift justification
  6049. } else {
  6050. // character to print
  6051. $topchr = $this->arrUTF8ToUTF16BE($uniarr, false);
  6052. $topchr = $this->_escape($topchr);
  6053. $s .= sprintf(' BT %F %F Td [(%s)] TJ ET', ($xdk + ($xshift * $k)), $ty, $topchr);
  6054. }
  6055. }
  6056. }
  6057. if ($this->underline) {
  6058. $s .= ' '.$this->_dounderlinew($xdx, $basefonty, $width);
  6059. }
  6060. if ($this->linethrough) {
  6061. $s .= ' '.$this->_dolinethroughw($xdx, $basefonty, $width);
  6062. }
  6063. if ($this->overline) {
  6064. $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width);
  6065. }
  6066. if ($this->ColorFlag AND ($this->textrendermode < 4)) {
  6067. $s .= ' Q';
  6068. }
  6069. if ($link) {
  6070. $this->Link($xdx, $yt, $width, ($this->FontAscent + $this->FontDescent), $link, $ns);
  6071. }
  6072. }
  6073. // output cell
  6074. if ($s) {
  6075. // output cell
  6076. $rs .= $s;
  6077. if ($this->font_spacing != 0) {
  6078. // reset font spacing mode
  6079. $rs .= ' BT 0 Tc ET';
  6080. }
  6081. if ($this->font_stretching != 100) {
  6082. // reset font stretching mode
  6083. $rs .= ' BT 100 Tz ET';
  6084. }
  6085. }
  6086. // reset word spacing
  6087. if (!$this->isUnicodeFont() AND ($align == 'J')) {
  6088. $rs .= ' BT 0 Tw ET';
  6089. }
  6090. // reset stretching and spacing
  6091. $this->font_stretching = $prev_font_stretching;
  6092. $this->font_spacing = $prev_font_spacing;
  6093. $this->lasth = $h;
  6094. if ($ln > 0) {
  6095. //Go to the beginning of the next line
  6096. $this->y = $y + $h + $this->cell_margin['B'];
  6097. if ($ln == 1) {
  6098. if ($this->rtl) {
  6099. $this->x = $this->w - $this->rMargin;
  6100. } else {
  6101. $this->x = $this->lMargin;
  6102. }
  6103. }
  6104. } else {
  6105. // go left or right by case
  6106. if ($this->rtl) {
  6107. $this->x = $x - $w - $this->cell_margin['L'];
  6108. } else {
  6109. $this->x = $x + $w + $this->cell_margin['R'];
  6110. }
  6111. }
  6112. $gstyles = ''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor."\n";
  6113. $rs = $gstyles.$rs;
  6114. $this->cell_padding = $prev_cell_padding;
  6115. $this->cell_margin = $prev_cell_margin;
  6116. return $rs;
  6117. }
  6118. /**
  6119. * Replace a char if is defined on the current font.
  6120. * @param $oldchar (int) Integer code (unicode) of the character to replace.
  6121. * @param $newchar (int) Integer code (unicode) of the new character.
  6122. * @return int the replaced char or the old char in case the new char i not defined
  6123. * @protected
  6124. * @since 5.9.167 (2012-06-22)
  6125. */
  6126. protected function replaceChar($oldchar, $newchar) {
  6127. if ($this->isCharDefined($newchar)) {
  6128. // add the new char on the subset list
  6129. $this->CurrentFont['subsetchars'][$newchar] = true;
  6130. // return the new character
  6131. return $newchar;
  6132. }
  6133. // return the old char
  6134. return $oldchar;
  6135. }
  6136. /**
  6137. * Returns the code to draw the cell border
  6138. * @param $x (float) X coordinate.
  6139. * @param $y (float) Y coordinate.
  6140. * @param $w (float) Cell width.
  6141. * @param $h (float) Cell height.
  6142. * @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)))
  6143. * @return string containing cell border code
  6144. * @protected
  6145. * @see SetLineStyle()
  6146. * @since 5.7.000 (2010-08-02)
  6147. */
  6148. protected function getCellBorder($x, $y, $w, $h, $brd) {
  6149. $s = ''; // string to be returned
  6150. if (empty($brd)) {
  6151. return $s;
  6152. }
  6153. if ($brd == 1) {
  6154. $brd = array('LRTB' => true);
  6155. }
  6156. // calculate coordinates for border
  6157. $k = $this->k;
  6158. if ($this->rtl) {
  6159. $xeL = ($x - $w) * $k;
  6160. $xeR = $x * $k;
  6161. } else {
  6162. $xeL = $x * $k;
  6163. $xeR = ($x + $w) * $k;
  6164. }
  6165. $yeL = (($this->h - ($y + $h)) * $k);
  6166. $yeT = (($this->h - $y) * $k);
  6167. $xeT = $xeL;
  6168. $xeB = $xeR;
  6169. $yeR = $yeT;
  6170. $yeB = $yeL;
  6171. if (is_string($brd)) {
  6172. // convert string to array
  6173. $slen = strlen($brd);
  6174. $newbrd = array();
  6175. for ($i = 0; $i < $slen; ++$i) {
  6176. $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
  6177. }
  6178. $brd = $newbrd;
  6179. }
  6180. if (isset($brd['mode'])) {
  6181. $mode = $brd['mode'];
  6182. unset($brd['mode']);
  6183. } else {
  6184. $mode = 'normal';
  6185. }
  6186. foreach ($brd as $border => $style) {
  6187. if (is_array($style) AND !empty($style)) {
  6188. // apply border style
  6189. $prev_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' ';
  6190. $s .= $this->SetLineStyle($style, true)."\n";
  6191. }
  6192. switch ($mode) {
  6193. case 'ext': {
  6194. $off = (($this->LineWidth / 2) * $k);
  6195. $xL = $xeL - $off;
  6196. $xR = $xeR + $off;
  6197. $yT = $yeT + $off;
  6198. $yL = $yeL - $off;
  6199. $xT = $xL;
  6200. $xB = $xR;
  6201. $yR = $yT;
  6202. $yB = $yL;
  6203. $w += $this->LineWidth;
  6204. $h += $this->LineWidth;
  6205. break;
  6206. }
  6207. case 'int': {
  6208. $off = ($this->LineWidth / 2) * $k;
  6209. $xL = $xeL + $off;
  6210. $xR = $xeR - $off;
  6211. $yT = $yeT - $off;
  6212. $yL = $yeL + $off;
  6213. $xT = $xL;
  6214. $xB = $xR;
  6215. $yR = $yT;
  6216. $yB = $yL;
  6217. $w -= $this->LineWidth;
  6218. $h -= $this->LineWidth;
  6219. break;
  6220. }
  6221. case 'normal':
  6222. default: {
  6223. $xL = $xeL;
  6224. $xT = $xeT;
  6225. $xB = $xeB;
  6226. $xR = $xeR;
  6227. $yL = $yeL;
  6228. $yT = $yeT;
  6229. $yB = $yeB;
  6230. $yR = $yeR;
  6231. break;
  6232. }
  6233. }
  6234. // draw borders by case
  6235. if (strlen($border) == 4) {
  6236. $s .= sprintf('%F %F %F %F re S ', $xT, $yT, ($w * $k), (-$h * $k));
  6237. } elseif (strlen($border) == 3) {
  6238. if (strpos($border,'B') === false) { // LTR
  6239. $s .= sprintf('%F %F m ', $xL, $yL);
  6240. $s .= sprintf('%F %F l ', $xT, $yT);
  6241. $s .= sprintf('%F %F l ', $xR, $yR);
  6242. $s .= sprintf('%F %F l ', $xB, $yB);
  6243. $s .= 'S ';
  6244. } elseif (strpos($border,'L') === false) { // TRB
  6245. $s .= sprintf('%F %F m ', $xT, $yT);
  6246. $s .= sprintf('%F %F l ', $xR, $yR);
  6247. $s .= sprintf('%F %F l ', $xB, $yB);
  6248. $s .= sprintf('%F %F l ', $xL, $yL);
  6249. $s .= 'S ';
  6250. } elseif (strpos($border,'T') === false) { // RBL
  6251. $s .= sprintf('%F %F m ', $xR, $yR);
  6252. $s .= sprintf('%F %F l ', $xB, $yB);
  6253. $s .= sprintf('%F %F l ', $xL, $yL);
  6254. $s .= sprintf('%F %F l ', $xT, $yT);
  6255. $s .= 'S ';
  6256. } elseif (strpos($border,'R') === false) { // BLT
  6257. $s .= sprintf('%F %F m ', $xB, $yB);
  6258. $s .= sprintf('%F %F l ', $xL, $yL);
  6259. $s .= sprintf('%F %F l ', $xT, $yT);
  6260. $s .= sprintf('%F %F l ', $xR, $yR);
  6261. $s .= 'S ';
  6262. }
  6263. } elseif (strlen($border) == 2) {
  6264. if ((strpos($border,'L') !== false) AND (strpos($border,'T') !== false)) { // LT
  6265. $s .= sprintf('%F %F m ', $xL, $yL);
  6266. $s .= sprintf('%F %F l ', $xT, $yT);
  6267. $s .= sprintf('%F %F l ', $xR, $yR);
  6268. $s .= 'S ';
  6269. } elseif ((strpos($border,'T') !== false) AND (strpos($border,'R') !== false)) { // TR
  6270. $s .= sprintf('%F %F m ', $xT, $yT);
  6271. $s .= sprintf('%F %F l ', $xR, $yR);
  6272. $s .= sprintf('%F %F l ', $xB, $yB);
  6273. $s .= 'S ';
  6274. } elseif ((strpos($border,'R') !== false) AND (strpos($border,'B') !== false)) { // RB
  6275. $s .= sprintf('%F %F m ', $xR, $yR);
  6276. $s .= sprintf('%F %F l ', $xB, $yB);
  6277. $s .= sprintf('%F %F l ', $xL, $yL);
  6278. $s .= 'S ';
  6279. } elseif ((strpos($border,'B') !== false) AND (strpos($border,'L') !== false)) { // BL
  6280. $s .= sprintf('%F %F m ', $xB, $yB);
  6281. $s .= sprintf('%F %F l ', $xL, $yL);
  6282. $s .= sprintf('%F %F l ', $xT, $yT);
  6283. $s .= 'S ';
  6284. } elseif ((strpos($border,'L') !== false) AND (strpos($border,'R') !== false)) { // LR
  6285. $s .= sprintf('%F %F m ', $xL, $yL);
  6286. $s .= sprintf('%F %F l ', $xT, $yT);
  6287. $s .= 'S ';
  6288. $s .= sprintf('%F %F m ', $xR, $yR);
  6289. $s .= sprintf('%F %F l ', $xB, $yB);
  6290. $s .= 'S ';
  6291. } elseif ((strpos($border,'T') !== false) AND (strpos($border,'B') !== false)) { // TB
  6292. $s .= sprintf('%F %F m ', $xT, $yT);
  6293. $s .= sprintf('%F %F l ', $xR, $yR);
  6294. $s .= 'S ';
  6295. $s .= sprintf('%F %F m ', $xB, $yB);
  6296. $s .= sprintf('%F %F l ', $xL, $yL);
  6297. $s .= 'S ';
  6298. }
  6299. } else { // strlen($border) == 1
  6300. if (strpos($border,'L') !== false) { // L
  6301. $s .= sprintf('%F %F m ', $xL, $yL);
  6302. $s .= sprintf('%F %F l ', $xT, $yT);
  6303. $s .= 'S ';
  6304. } elseif (strpos($border,'T') !== false) { // T
  6305. $s .= sprintf('%F %F m ', $xT, $yT);
  6306. $s .= sprintf('%F %F l ', $xR, $yR);
  6307. $s .= 'S ';
  6308. } elseif (strpos($border,'R') !== false) { // R
  6309. $s .= sprintf('%F %F m ', $xR, $yR);
  6310. $s .= sprintf('%F %F l ', $xB, $yB);
  6311. $s .= 'S ';
  6312. } elseif (strpos($border,'B') !== false) { // B
  6313. $s .= sprintf('%F %F m ', $xB, $yB);
  6314. $s .= sprintf('%F %F l ', $xL, $yL);
  6315. $s .= 'S ';
  6316. }
  6317. }
  6318. if (is_array($style) AND !empty($style)) {
  6319. // reset border style to previous value
  6320. $s .= "\n".$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor."\n";
  6321. }
  6322. }
  6323. return $s;
  6324. }
  6325. /**
  6326. * This method allows printing text with line breaks.
  6327. * 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 />
  6328. * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  6329. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  6330. * @param $h (float) Cell minimum height. The cell extends automatically if needed.
  6331. * @param $txt (string) String to print
  6332. * @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)))
  6333. * @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>
  6334. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  6335. * @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>
  6336. * @param $x (float) x position in user units
  6337. * @param $y (float) y position in user units
  6338. * @param $reseth (boolean) if true reset the last cell height (default true).
  6339. * @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.
  6340. * @param $ishtml (boolean) INTERNAL USE ONLY -- set to true if $txt is HTML content (default = false). Never set this parameter to true, use instead writeHTMLCell() or writeHTML() methods.
  6341. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width.
  6342. * @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.
  6343. * @param $valign (string) Vertical alignment of text (requires $maxh = $h > 0). Possible values are:<ul><li>T: TOP</li><li>M: middle</li><li>B: bottom</li></ul>. This feature works only when $ishtml=false and the cell must fit in a single page.
  6344. * @param $fitcell (boolean) if true attempt to fit all the text within the cell by reducing the font size (do not work in HTML mode).
  6345. * @return int Return the number of cells or 1 for html mode.
  6346. * @public
  6347. * @since 1.3
  6348. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  6349. */
  6350. 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) {
  6351. $prev_cell_margin = $this->cell_margin;
  6352. $prev_cell_padding = $this->cell_padding;
  6353. // adjust internal padding
  6354. $this->adjustCellPadding($border);
  6355. $mc_padding = $this->cell_padding;
  6356. $mc_margin = $this->cell_margin;
  6357. $this->cell_padding['T'] = 0;
  6358. $this->cell_padding['B'] = 0;
  6359. $this->setCellMargins(0, 0, 0, 0);
  6360. if ($this->empty_string($this->lasth) OR $reseth) {
  6361. // reset row height
  6362. $this->resetLastH();
  6363. }
  6364. if (!$this->empty_string($y)) {
  6365. $this->SetY($y);
  6366. } else {
  6367. $y = $this->GetY();
  6368. }
  6369. $resth = 0;
  6370. if (($h > 0) AND $this->inPageBody() AND (($y + $h + $mc_margin['T'] + $mc_margin['B']) > $this->PageBreakTrigger)) {
  6371. // spit cell in more pages/columns
  6372. $newh = ($this->PageBreakTrigger - $y);
  6373. $resth = ($h - $newh); // cell to be printed on the next page/column
  6374. $h = $newh;
  6375. }
  6376. // get current page number
  6377. $startpage = $this->page;
  6378. // get current column
  6379. $startcolumn = $this->current_column;
  6380. if (!$this->empty_string($x)) {
  6381. $this->SetX($x);
  6382. } else {
  6383. $x = $this->GetX();
  6384. }
  6385. // check page for no-write regions and adapt page margins if necessary
  6386. list($x, $y) = $this->checkPageRegions(0, $x, $y);
  6387. // apply margins
  6388. $oy = $y + $mc_margin['T'];
  6389. if ($this->rtl) {
  6390. $ox = ($this->w - $x - $mc_margin['R']);
  6391. } else {
  6392. $ox = ($x + $mc_margin['L']);
  6393. }
  6394. $this->x = $ox;
  6395. $this->y = $oy;
  6396. // set width
  6397. if ($this->empty_string($w) OR ($w <= 0)) {
  6398. if ($this->rtl) {
  6399. $w = ($this->x - $this->lMargin - $mc_margin['L']);
  6400. } else {
  6401. $w = ($this->w - $this->x - $this->rMargin - $mc_margin['R']);
  6402. }
  6403. }
  6404. // store original margin values
  6405. $lMargin = $this->lMargin;
  6406. $rMargin = $this->rMargin;
  6407. if ($this->rtl) {
  6408. $this->rMargin = ($this->w - $this->x);
  6409. $this->lMargin = ($this->x - $w);
  6410. } else {
  6411. $this->lMargin = ($this->x);
  6412. $this->rMargin = ($this->w - $this->x - $w);
  6413. }
  6414. $this->clMargin = $this->lMargin;
  6415. $this->crMargin = $this->rMargin;
  6416. if ($autopadding) {
  6417. // add top padding
  6418. $this->y += $mc_padding['T'];
  6419. }
  6420. if ($ishtml) { // ******* Write HTML text
  6421. $this->writeHTML($txt, true, false, $reseth, true, $align);
  6422. $nl = 1;
  6423. } else { // ******* Write simple text
  6424. $prev_FontSizePt = $this->FontSizePt;
  6425. // vertical alignment
  6426. if ($maxh > 0) {
  6427. // get text height
  6428. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  6429. if ($fitcell) {
  6430. // try to reduce font size to fit text on cell (use a quick search algorithm)
  6431. $fmin = 1;
  6432. $fmax = $this->FontSizePt;
  6433. $prev_text_height = $text_height;
  6434. $maxit = 100; // max number of iterations
  6435. while ($maxit > 0) {
  6436. $fmid = (($fmax + $fmin) / 2);
  6437. $this->SetFontSize($fmid, false);
  6438. $this->resetLastH();
  6439. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  6440. if (($text_height == $maxh) OR (($text_height < $maxh) AND ($fmin >= ($fmax - 0.01)))) {
  6441. break;
  6442. } elseif ($text_height < $maxh) {
  6443. $fmin = $fmid;
  6444. } else {
  6445. $fmax = $fmid;
  6446. }
  6447. --$maxit;
  6448. }
  6449. $this->SetFontSize($this->FontSizePt);
  6450. }
  6451. if ($text_height < $maxh) {
  6452. if ($valign == 'M') {
  6453. // text vertically centered
  6454. $this->y += (($maxh - $text_height) / 2);
  6455. } elseif ($valign == 'B') {
  6456. // text vertically aligned on bottom
  6457. $this->y += ($maxh - $text_height);
  6458. }
  6459. }
  6460. }
  6461. $nl = $this->Write($this->lasth, $txt, '', 0, $align, true, $stretch, false, true, $maxh, 0, $mc_margin);
  6462. if ($fitcell) {
  6463. // restore font size
  6464. $this->SetFontSize($prev_FontSizePt);
  6465. }
  6466. }
  6467. if ($autopadding) {
  6468. // add bottom padding
  6469. $this->y += $mc_padding['B'];
  6470. }
  6471. // Get end-of-text Y position
  6472. $currentY = $this->y;
  6473. // get latest page number
  6474. $endpage = $this->page;
  6475. if ($resth > 0) {
  6476. $skip = ($endpage - $startpage);
  6477. $tmpresth = $resth;
  6478. while ($tmpresth > 0) {
  6479. if ($skip <= 0) {
  6480. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  6481. $this->checkPageBreak($this->PageBreakTrigger + 1);
  6482. }
  6483. if ($this->num_columns > 1) {
  6484. $tmpresth -= ($this->h - $this->y - $this->bMargin);
  6485. } else {
  6486. $tmpresth -= ($this->h - $this->tMargin - $this->bMargin);
  6487. }
  6488. --$skip;
  6489. }
  6490. $currentY = $this->y;
  6491. $endpage = $this->page;
  6492. }
  6493. // get latest column
  6494. $endcolumn = $this->current_column;
  6495. if ($this->num_columns == 0) {
  6496. $this->num_columns = 1;
  6497. }
  6498. // disable page regions check
  6499. $check_page_regions = $this->check_page_regions;
  6500. $this->check_page_regions = false;
  6501. // get border modes
  6502. $border_start = $this->getBorderMode($border, $position='start');
  6503. $border_end = $this->getBorderMode($border, $position='end');
  6504. $border_middle = $this->getBorderMode($border, $position='middle');
  6505. // design borders around HTML cells.
  6506. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  6507. $ccode = '';
  6508. $this->setPage($page);
  6509. if ($this->num_columns < 2) {
  6510. // single-column mode
  6511. $this->SetX($x);
  6512. $this->y = $this->tMargin;
  6513. }
  6514. // account for margin changes
  6515. if ($page > $startpage) {
  6516. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  6517. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  6518. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  6519. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  6520. }
  6521. }
  6522. if ($startpage == $endpage) {
  6523. // single page
  6524. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  6525. $this->selectColumn($column);
  6526. if ($this->rtl) {
  6527. $this->x -= $mc_margin['R'];
  6528. } else {
  6529. $this->x += $mc_margin['L'];
  6530. }
  6531. if ($startcolumn == $endcolumn) { // single column
  6532. $cborder = $border;
  6533. $h = max($h, ($currentY - $oy));
  6534. $this->y = $oy;
  6535. } elseif ($column == $startcolumn) { // first column
  6536. $cborder = $border_start;
  6537. $this->y = $oy;
  6538. $h = $this->h - $this->y - $this->bMargin;
  6539. } elseif ($column == $endcolumn) { // end column
  6540. $cborder = $border_end;
  6541. $h = $currentY - $this->y;
  6542. if ($resth > $h) {
  6543. $h = $resth;
  6544. }
  6545. } else { // middle column
  6546. $cborder = $border_middle;
  6547. $h = $this->h - $this->y - $this->bMargin;
  6548. $resth -= $h;
  6549. }
  6550. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  6551. } // end for each column
  6552. } elseif ($page == $startpage) { // first page
  6553. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  6554. $this->selectColumn($column);
  6555. if ($this->rtl) {
  6556. $this->x -= $mc_margin['R'];
  6557. } else {
  6558. $this->x += $mc_margin['L'];
  6559. }
  6560. if ($column == $startcolumn) { // first column
  6561. $cborder = $border_start;
  6562. $this->y = $oy;
  6563. $h = $this->h - $this->y - $this->bMargin;
  6564. } else { // middle column
  6565. $cborder = $border_middle;
  6566. $h = $this->h - $this->y - $this->bMargin;
  6567. $resth -= $h;
  6568. }
  6569. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  6570. } // end for each column
  6571. } elseif ($page == $endpage) { // last page
  6572. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  6573. $this->selectColumn($column);
  6574. if ($this->rtl) {
  6575. $this->x -= $mc_margin['R'];
  6576. } else {
  6577. $this->x += $mc_margin['L'];
  6578. }
  6579. if ($column == $endcolumn) {
  6580. // end column
  6581. $cborder = $border_end;
  6582. $h = $currentY - $this->y;
  6583. if ($resth > $h) {
  6584. $h = $resth;
  6585. }
  6586. } else {
  6587. // middle column
  6588. $cborder = $border_middle;
  6589. $h = $this->h - $this->y - $this->bMargin;
  6590. $resth -= $h;
  6591. }
  6592. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  6593. } // end for each column
  6594. } else { // middle page
  6595. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  6596. $this->selectColumn($column);
  6597. if ($this->rtl) {
  6598. $this->x -= $mc_margin['R'];
  6599. } else {
  6600. $this->x += $mc_margin['L'];
  6601. }
  6602. $cborder = $border_middle;
  6603. $h = $this->h - $this->y - $this->bMargin;
  6604. $resth -= $h;
  6605. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  6606. } // end for each column
  6607. }
  6608. if ($cborder OR $fill) {
  6609. $offsetlen = strlen($ccode);
  6610. // draw border and fill
  6611. if ($this->inxobj) {
  6612. // we are inside an XObject template
  6613. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  6614. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  6615. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  6616. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  6617. } else {
  6618. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  6619. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  6620. }
  6621. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  6622. $pstart = substr($pagebuff, 0, $pagemark);
  6623. $pend = substr($pagebuff, $pagemark);
  6624. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  6625. } else {
  6626. if (end($this->transfmrk[$this->page]) !== false) {
  6627. $pagemarkkey = key($this->transfmrk[$this->page]);
  6628. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  6629. $this->transfmrk[$this->page][$pagemarkkey] += $offsetlen;
  6630. } elseif ($this->InFooter) {
  6631. $pagemark = $this->footerpos[$this->page];
  6632. $this->footerpos[$this->page] += $offsetlen;
  6633. } else {
  6634. $pagemark = $this->intmrk[$this->page];
  6635. $this->intmrk[$this->page] += $offsetlen;
  6636. }
  6637. $pagebuff = $this->getPageBuffer($this->page);
  6638. $pstart = substr($pagebuff, 0, $pagemark);
  6639. $pend = substr($pagebuff, $pagemark);
  6640. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  6641. }
  6642. }
  6643. } // end for each page
  6644. // restore page regions check
  6645. $this->check_page_regions = $check_page_regions;
  6646. // Get end-of-cell Y position
  6647. $currentY = $this->GetY();
  6648. // restore previous values
  6649. if ($this->num_columns > 1) {
  6650. $this->selectColumn();
  6651. } else {
  6652. // restore original margins
  6653. $this->lMargin = $lMargin;
  6654. $this->rMargin = $rMargin;
  6655. if ($this->page > $startpage) {
  6656. // check for margin variations between pages (i.e. booklet mode)
  6657. $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$startpage]['olm']);
  6658. $dr = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$startpage]['orm']);
  6659. if (($dl != 0) OR ($dr != 0)) {
  6660. $this->lMargin += $dl;
  6661. $this->rMargin += $dr;
  6662. }
  6663. }
  6664. }
  6665. if ($ln > 0) {
  6666. //Go to the beginning of the next line
  6667. $this->SetY($currentY + $mc_margin['B']);
  6668. if ($ln == 2) {
  6669. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  6670. }
  6671. } else {
  6672. // go left or right by case
  6673. $this->setPage($startpage);
  6674. $this->y = $y;
  6675. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  6676. }
  6677. $this->setContentMark();
  6678. $this->cell_padding = $prev_cell_padding;
  6679. $this->cell_margin = $prev_cell_margin;
  6680. $this->clMargin = $this->lMargin;
  6681. $this->crMargin = $this->rMargin;
  6682. return $nl;
  6683. }
  6684. /**
  6685. * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages)
  6686. * @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)))
  6687. * @param $position (string) multicell position: 'start', 'middle', 'end'
  6688. * @return border mode array
  6689. * @protected
  6690. * @since 4.4.002 (2008-12-09)
  6691. */
  6692. protected function getBorderMode($brd, $position='start') {
  6693. if ((!$this->opencell) OR empty($brd)) {
  6694. return $brd;
  6695. }
  6696. if ($brd == 1) {
  6697. $brd = 'LTRB';
  6698. }
  6699. if (is_string($brd)) {
  6700. // convert string to array
  6701. $slen = strlen($brd);
  6702. $newbrd = array();
  6703. for ($i = 0; $i < $slen; ++$i) {
  6704. $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
  6705. }
  6706. $brd = $newbrd;
  6707. }
  6708. foreach ($brd as $border => $style) {
  6709. switch ($position) {
  6710. case 'start': {
  6711. if (strpos($border, 'B') !== false) {
  6712. // remove bottom line
  6713. $newkey = str_replace('B', '', $border);
  6714. if (strlen($newkey) > 0) {
  6715. $brd[$newkey] = $style;
  6716. }
  6717. unset($brd[$border]);
  6718. }
  6719. break;
  6720. }
  6721. case 'middle': {
  6722. if (strpos($border, 'B') !== false) {
  6723. // remove bottom line
  6724. $newkey = str_replace('B', '', $border);
  6725. if (strlen($newkey) > 0) {
  6726. $brd[$newkey] = $style;
  6727. }
  6728. unset($brd[$border]);
  6729. $border = $newkey;
  6730. }
  6731. if (strpos($border, 'T') !== false) {
  6732. // remove bottom line
  6733. $newkey = str_replace('T', '', $border);
  6734. if (strlen($newkey) > 0) {
  6735. $brd[$newkey] = $style;
  6736. }
  6737. unset($brd[$border]);
  6738. }
  6739. break;
  6740. }
  6741. case 'end': {
  6742. if (strpos($border, 'T') !== false) {
  6743. // remove bottom line
  6744. $newkey = str_replace('T', '', $border);
  6745. if (strlen($newkey) > 0) {
  6746. $brd[$newkey] = $style;
  6747. }
  6748. unset($brd[$border]);
  6749. }
  6750. break;
  6751. }
  6752. }
  6753. }
  6754. return $brd;
  6755. }
  6756. /**
  6757. * This method return the estimated number of lines for print a simple text string using Multicell() method.
  6758. * @param $txt (string) String for calculating his height
  6759. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  6760. * @param $reseth (boolean) if true reset the last cell height (default false).
  6761. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
  6762. * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
  6763. * @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)))
  6764. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  6765. * @author Alexander Escalona Fernández, Nicola Asuni
  6766. * @public
  6767. * @since 4.5.011
  6768. */
  6769. public function getNumLines($txt, $w=0, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
  6770. if ($txt === '') {
  6771. // empty string
  6772. return 1;
  6773. }
  6774. // adjust internal padding
  6775. $prev_cell_padding = $this->cell_padding;
  6776. $prev_lasth = $this->lasth;
  6777. if (is_array($cellpadding)) {
  6778. $this->cell_padding = $cellpadding;
  6779. }
  6780. $this->adjustCellPadding($border);
  6781. if ($this->empty_string($w) OR ($w <= 0)) {
  6782. if ($this->rtl) {
  6783. $w = $this->x - $this->lMargin;
  6784. } else {
  6785. $w = $this->w - $this->rMargin - $this->x;
  6786. }
  6787. }
  6788. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6789. if ($reseth) {
  6790. // reset row height
  6791. $this->resetLastH();
  6792. }
  6793. $lines = 1;
  6794. $sum = 0;
  6795. $chars = $this->utf8Bidi($this->UTF8StringToArray($txt), $txt, $this->tmprtl);
  6796. $charsWidth = $this->GetArrStringWidth($chars, '', '', 0, true);
  6797. $length = count($chars);
  6798. $lastSeparator = -1;
  6799. for ($i = 0; $i < $length; ++$i) {
  6800. $charWidth = $charsWidth[$i];
  6801. if (preg_match($this->re_spaces, $this->unichr($chars[$i]))) {
  6802. $lastSeparator = $i;
  6803. }
  6804. if ((($sum + $charWidth) > $wmax) OR ($chars[$i] == 10)) {
  6805. ++$lines;
  6806. if ($chars[$i] == 10) {
  6807. $lastSeparator = -1;
  6808. $sum = 0;
  6809. } elseif ($lastSeparator != -1) {
  6810. $i = $lastSeparator;
  6811. $lastSeparator = -1;
  6812. $sum = 0;
  6813. } else {
  6814. $sum = $charWidth;
  6815. }
  6816. } else {
  6817. $sum += $charWidth;
  6818. }
  6819. }
  6820. if ($chars[($length - 1)] == 10) {
  6821. --$lines;
  6822. }
  6823. $this->cell_padding = $prev_cell_padding;
  6824. $this->lasth = $prev_lasth;
  6825. return $lines;
  6826. }
  6827. /**
  6828. * This method return the estimated height needed for printing a simple text string using the Multicell() method.
  6829. * Generally, if you want to know the exact height for a block of content you can use the following alternative technique:
  6830. * @pre
  6831. * // store current object
  6832. * $pdf->startTransaction();
  6833. * // store starting values
  6834. * $start_y = $pdf->GetY();
  6835. * $start_page = $pdf->getPage();
  6836. * // call your printing functions with your parameters
  6837. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6838. * $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);
  6839. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6840. * // get the new Y
  6841. * $end_y = $pdf->GetY();
  6842. * $end_page = $pdf->getPage();
  6843. * // calculate height
  6844. * $height = 0;
  6845. * if ($end_page == $start_page) {
  6846. * $height = $end_y - $start_y;
  6847. * } else {
  6848. * for ($page=$start_page; $page <= $end_page; ++$page) {
  6849. * $this->setPage($page);
  6850. * if ($page == $start_page) {
  6851. * // first page
  6852. * $height = $this->h - $start_y - $this->bMargin;
  6853. * } elseif ($page == $end_page) {
  6854. * // last page
  6855. * $height = $end_y - $this->tMargin;
  6856. * } else {
  6857. * $height = $this->h - $this->tMargin - $this->bMargin;
  6858. * }
  6859. * }
  6860. * }
  6861. * // restore previous object
  6862. * $pdf = $pdf->rollbackTransaction();
  6863. *
  6864. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  6865. * @param $txt (string) String for calculating his height
  6866. * @param $reseth (boolean) if true reset the last cell height (default false).
  6867. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
  6868. * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
  6869. * @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)))
  6870. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  6871. * @author Nicola Asuni, Alexander Escalona Fernández
  6872. * @public
  6873. */
  6874. public function getStringHeight($w, $txt, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
  6875. // adjust internal padding
  6876. $prev_cell_padding = $this->cell_padding;
  6877. $prev_lasth = $this->lasth;
  6878. if (is_array($cellpadding)) {
  6879. $this->cell_padding = $cellpadding;
  6880. }
  6881. $this->adjustCellPadding($border);
  6882. $lines = $this->getNumLines($txt, $w, $reseth, $autopadding, $cellpadding, $border);
  6883. $height = $lines * ($this->FontSize * $this->cell_height_ratio);
  6884. if ($autopadding) {
  6885. // add top and bottom padding
  6886. $height += ($this->cell_padding['T'] + $this->cell_padding['B']);
  6887. }
  6888. $this->cell_padding = $prev_cell_padding;
  6889. $this->lasth = $prev_lasth;
  6890. return $height;
  6891. }
  6892. /**
  6893. * This method prints text from the current position.<br />
  6894. * @param $h (float) Line height
  6895. * @param $txt (string) String to print
  6896. * @param $link (mixed) URL or identifier returned by AddLink()
  6897. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  6898. * @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>
  6899. * @param $ln (boolean) if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
  6900. * @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.
  6901. * @param $firstline (boolean) if true prints only the first line and return the remaining string.
  6902. * @param $firstblock (boolean) if true the string is the starting of a line.
  6903. * @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.
  6904. * @param $wadj (float) first line width will be reduced by this amount (used in HTML mode).
  6905. * @param $margin (array) margin array of the parent container
  6906. * @return mixed Return the number of cells or the remaining string if $firstline = true.
  6907. * @public
  6908. * @since 1.5
  6909. */
  6910. public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $stretch=0, $firstline=false, $firstblock=false, $maxh=0, $wadj=0, $margin='') {
  6911. // check page for no-write regions and adapt page margins if necessary
  6912. list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
  6913. if (strlen($txt) == 0) {
  6914. // fix empty text
  6915. $txt = ' ';
  6916. }
  6917. if ($margin === '') {
  6918. // set default margins
  6919. $margin = $this->cell_margin;
  6920. }
  6921. // remove carriage returns
  6922. $s = str_replace("\r", '', $txt);
  6923. // check if string contains arabic text
  6924. if (preg_match($this->unicode->uni_RE_PATTERN_ARABIC, $s)) {
  6925. $arabic = true;
  6926. } else {
  6927. $arabic = false;
  6928. }
  6929. // check if string contains RTL text
  6930. if ($arabic OR ($this->tmprtl == 'R') OR preg_match($this->unicode->uni_RE_PATTERN_RTL, $s)) {
  6931. $rtlmode = true;
  6932. } else {
  6933. $rtlmode = false;
  6934. }
  6935. // get a char width
  6936. $chrwidth = $this->GetCharWidth(46); // dot character
  6937. // get array of unicode values
  6938. $chars = $this->UTF8StringToArray($s);
  6939. // calculate maximum width for a single character on string
  6940. $chrw = $this->GetArrStringWidth($chars, '', '', 0, true);
  6941. array_walk($chrw, array($this, 'getRawCharWidth'));
  6942. $maxchwidth = max($chrw);
  6943. // get array of chars
  6944. $uchars = $this->UTF8ArrayToUniArray($chars);
  6945. // get the number of characters
  6946. $nb = count($chars);
  6947. // replacement for SHY character (minus symbol)
  6948. $shy_replacement = 45;
  6949. $shy_replacement_char = $this->unichr($shy_replacement);
  6950. // widht for SHY replacement
  6951. $shy_replacement_width = $this->GetCharWidth($shy_replacement);
  6952. // max Y
  6953. $maxy = $this->y + $maxh - $h - $this->cell_padding['T'] - $this->cell_padding['B'];
  6954. // page width
  6955. $pw = $w = $this->w - $this->lMargin - $this->rMargin;
  6956. // calculate remaining line width ($w)
  6957. if ($this->rtl) {
  6958. $w = $this->x - $this->lMargin;
  6959. } else {
  6960. $w = $this->w - $this->rMargin - $this->x;
  6961. }
  6962. // max column width
  6963. $wmax = ($w - $wadj);
  6964. if (!$firstline) {
  6965. $wmax -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  6966. }
  6967. if ((!$firstline) AND (($chrwidth > $wmax) OR ($maxchwidth > $wmax))) {
  6968. // the maximum width character do not fit on column
  6969. return '';
  6970. }
  6971. // minimum row height
  6972. $row_height = max($h, $this->FontSize * $this->cell_height_ratio);
  6973. $start_page = $this->page;
  6974. $i = 0; // character position
  6975. $j = 0; // current starting position
  6976. $sep = -1; // position of the last blank space
  6977. $shy = false; // true if the last blank is a soft hypen (SHY)
  6978. $l = 0; // current string length
  6979. $nl = 0; //number of lines
  6980. $linebreak = false;
  6981. $pc = 0; // previous character
  6982. // for each character
  6983. while ($i < $nb) {
  6984. if (($maxh > 0) AND ($this->y >= $maxy) ) {
  6985. break;
  6986. }
  6987. //Get the current character
  6988. $c = $chars[$i];
  6989. if ($c == 10) { // 10 = "\n" = new line
  6990. //Explicit line break
  6991. if ($align == 'J') {
  6992. if ($this->rtl) {
  6993. $talign = 'R';
  6994. } else {
  6995. $talign = 'L';
  6996. }
  6997. } else {
  6998. $talign = $align;
  6999. }
  7000. $tmpstr = $this->UniArrSubString($uchars, $j, $i);
  7001. if ($firstline) {
  7002. $startx = $this->x;
  7003. $tmparr = array_slice($chars, $j, ($i - $j));
  7004. if ($rtlmode) {
  7005. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  7006. }
  7007. $linew = $this->GetArrStringWidth($tmparr);
  7008. unset($tmparr);
  7009. if ($this->rtl) {
  7010. $this->endlinex = $startx - $linew;
  7011. } else {
  7012. $this->endlinex = $startx + $linew;
  7013. }
  7014. $w = $linew;
  7015. $tmpcellpadding = $this->cell_padding;
  7016. if ($maxh == 0) {
  7017. $this->SetCellPadding(0);
  7018. }
  7019. }
  7020. if ($firstblock AND $this->isRTLTextDir()) {
  7021. $tmpstr = $this->stringRightTrim($tmpstr);
  7022. }
  7023. // Skip newlines at the begining of a page or column
  7024. if (!empty($tmpstr) OR ($this->y < ($this->PageBreakTrigger - $row_height))) {
  7025. $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
  7026. }
  7027. unset($tmpstr);
  7028. if ($firstline) {
  7029. $this->cell_padding = $tmpcellpadding;
  7030. return ($this->UniArrSubString($uchars, $i));
  7031. }
  7032. ++$nl;
  7033. $j = $i + 1;
  7034. $l = 0;
  7035. $sep = -1;
  7036. $shy = false;
  7037. // account for margin changes
  7038. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
  7039. $this->AcceptPageBreak();
  7040. if ($this->rtl) {
  7041. $this->x -= $margin['R'];
  7042. } else {
  7043. $this->x += $margin['L'];
  7044. }
  7045. $this->lMargin += $margin['L'];
  7046. $this->rMargin += $margin['R'];
  7047. }
  7048. $w = $this->getRemainingWidth();
  7049. $wmax = ($w - $this->cell_padding['L'] - $this->cell_padding['R']);
  7050. } else {
  7051. // 160 is the non-breaking space.
  7052. // 173 is SHY (Soft Hypen).
  7053. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  7054. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  7055. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  7056. if (($c != 160)
  7057. AND (($c == 173)
  7058. OR preg_match($this->re_spaces, $this->unichr($c))
  7059. OR (($c == 45)
  7060. AND ($i < ($nb - 1))
  7061. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], $this->unichr($pc))
  7062. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], $this->unichr($chars[($i + 1)]))
  7063. )
  7064. )
  7065. ) {
  7066. // update last blank space position
  7067. $sep = $i;
  7068. // check if is a SHY
  7069. if (($c == 173) OR ($c == 45)) {
  7070. $shy = true;
  7071. if ($pc == 45) {
  7072. $tmp_shy_replacement_width = 0;
  7073. $tmp_shy_replacement_char = '';
  7074. } else {
  7075. $tmp_shy_replacement_width = $shy_replacement_width;
  7076. $tmp_shy_replacement_char = $shy_replacement_char;
  7077. }
  7078. } else {
  7079. $shy = false;
  7080. }
  7081. }
  7082. // update string length
  7083. if ($this->isUnicodeFont() AND ($arabic)) {
  7084. // with bidirectional algorithm some chars may be changed affecting the line length
  7085. // *** very slow ***
  7086. $l = $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl));
  7087. } else {
  7088. $l += $this->GetCharWidth($c);
  7089. }
  7090. if (($l > $wmax) OR (($c == 173) AND (($l + $tmp_shy_replacement_width) > $wmax)) ) {
  7091. // we have reached the end of column
  7092. if ($sep == -1) {
  7093. // check if the line was already started
  7094. if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $this->cell_padding['R'] - $margin['R'] - $chrwidth)))
  7095. OR ((!$this->rtl) AND ($this->x >= ($this->lMargin + $this->cell_padding['L'] + $margin['L'] + $chrwidth)))) {
  7096. // print a void cell and go to next line
  7097. $this->Cell($w, $h, '', 0, 1);
  7098. $linebreak = true;
  7099. if ($firstline) {
  7100. return ($this->UniArrSubString($uchars, $j));
  7101. }
  7102. } else {
  7103. // truncate the word because do not fit on column
  7104. $tmpstr = $this->UniArrSubString($uchars, $j, $i);
  7105. if ($firstline) {
  7106. $startx = $this->x;
  7107. $tmparr = array_slice($chars, $j, ($i - $j));
  7108. if ($rtlmode) {
  7109. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  7110. }
  7111. $linew = $this->GetArrStringWidth($tmparr);
  7112. unset($tmparr);
  7113. if ($this->rtl) {
  7114. $this->endlinex = $startx - $linew;
  7115. } else {
  7116. $this->endlinex = $startx + $linew;
  7117. }
  7118. $w = $linew;
  7119. $tmpcellpadding = $this->cell_padding;
  7120. if ($maxh == 0) {
  7121. $this->SetCellPadding(0);
  7122. }
  7123. }
  7124. if ($firstblock AND $this->isRTLTextDir()) {
  7125. $tmpstr = $this->stringRightTrim($tmpstr);
  7126. }
  7127. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  7128. unset($tmpstr);
  7129. if ($firstline) {
  7130. $this->cell_padding = $tmpcellpadding;
  7131. return ($this->UniArrSubString($uchars, $i));
  7132. }
  7133. $j = $i;
  7134. --$i;
  7135. }
  7136. } else {
  7137. // word wrapping
  7138. if ($this->rtl AND (!$firstblock) AND ($sep < $i)) {
  7139. $endspace = 1;
  7140. } else {
  7141. $endspace = 0;
  7142. }
  7143. // check the length of the next string
  7144. $strrest = $this->UniArrSubString($uchars, ($sep + $endspace));
  7145. $nextstr = preg_split('/'.$this->re_space['p'].'/'.$this->re_space['m'], $this->stringTrim($strrest));
  7146. if (isset($nextstr[0]) AND ($this->GetStringWidth($nextstr[0]) > $pw)) {
  7147. // truncate the word because do not fit on a full page width
  7148. $tmpstr = $this->UniArrSubString($uchars, $j, $i);
  7149. if ($firstline) {
  7150. $startx = $this->x;
  7151. $tmparr = array_slice($chars, $j, ($i - $j));
  7152. if ($rtlmode) {
  7153. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  7154. }
  7155. $linew = $this->GetArrStringWidth($tmparr);
  7156. unset($tmparr);
  7157. if ($this->rtl) {
  7158. $this->endlinex = ($startx - $linew);
  7159. } else {
  7160. $this->endlinex = ($startx + $linew);
  7161. }
  7162. $w = $linew;
  7163. $tmpcellpadding = $this->cell_padding;
  7164. if ($maxh == 0) {
  7165. $this->SetCellPadding(0);
  7166. }
  7167. }
  7168. if ($firstblock AND $this->isRTLTextDir()) {
  7169. $tmpstr = $this->stringRightTrim($tmpstr);
  7170. }
  7171. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  7172. unset($tmpstr);
  7173. if ($firstline) {
  7174. $this->cell_padding = $tmpcellpadding;
  7175. return ($this->UniArrSubString($uchars, $i));
  7176. }
  7177. $j = $i;
  7178. --$i;
  7179. } else {
  7180. // word wrapping
  7181. if ($shy) {
  7182. // add hypen (minus symbol) at the end of the line
  7183. $shy_width = $tmp_shy_replacement_width;
  7184. if ($this->rtl) {
  7185. $shy_char_left = $tmp_shy_replacement_char;
  7186. $shy_char_right = '';
  7187. } else {
  7188. $shy_char_left = '';
  7189. $shy_char_right = $tmp_shy_replacement_char;
  7190. }
  7191. } else {
  7192. $shy_width = 0;
  7193. $shy_char_left = '';
  7194. $shy_char_right = '';
  7195. }
  7196. $tmpstr = $this->UniArrSubString($uchars, $j, ($sep + $endspace));
  7197. if ($firstline) {
  7198. $startx = $this->x;
  7199. $tmparr = array_slice($chars, $j, (($sep + $endspace) - $j));
  7200. if ($rtlmode) {
  7201. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  7202. }
  7203. $linew = $this->GetArrStringWidth($tmparr);
  7204. unset($tmparr);
  7205. if ($this->rtl) {
  7206. $this->endlinex = $startx - $linew - $shy_width;
  7207. } else {
  7208. $this->endlinex = $startx + $linew + $shy_width;
  7209. }
  7210. $w = $linew;
  7211. $tmpcellpadding = $this->cell_padding;
  7212. if ($maxh == 0) {
  7213. $this->SetCellPadding(0);
  7214. }
  7215. }
  7216. // print the line
  7217. if ($firstblock AND $this->isRTLTextDir()) {
  7218. $tmpstr = $this->stringRightTrim($tmpstr);
  7219. }
  7220. $this->Cell($w, $h, $shy_char_left.$tmpstr.$shy_char_right, 0, 1, $align, $fill, $link, $stretch);
  7221. unset($tmpstr);
  7222. if ($firstline) {
  7223. if ($chars[$sep] == 45) {
  7224. $endspace += 1;
  7225. }
  7226. // return the remaining text
  7227. $this->cell_padding = $tmpcellpadding;
  7228. return ($this->UniArrSubString($uchars, ($sep + $endspace)));
  7229. }
  7230. $i = $sep;
  7231. $sep = -1;
  7232. $shy = false;
  7233. $j = ($i + 1);
  7234. }
  7235. }
  7236. // account for margin changes
  7237. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
  7238. $this->AcceptPageBreak();
  7239. if ($this->rtl) {
  7240. $this->x -= $margin['R'];
  7241. } else {
  7242. $this->x += $margin['L'];
  7243. }
  7244. $this->lMargin += $margin['L'];
  7245. $this->rMargin += $margin['R'];
  7246. }
  7247. $w = $this->getRemainingWidth();
  7248. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  7249. if ($linebreak) {
  7250. $linebreak = false;
  7251. } else {
  7252. ++$nl;
  7253. $l = 0;
  7254. }
  7255. }
  7256. }
  7257. // save last character
  7258. $pc = $c;
  7259. ++$i;
  7260. } // end while i < nb
  7261. // print last substring (if any)
  7262. if ($l > 0) {
  7263. switch ($align) {
  7264. case 'J':
  7265. case 'C': {
  7266. $w = $w;
  7267. break;
  7268. }
  7269. case 'L': {
  7270. if ($this->rtl) {
  7271. $w = $w;
  7272. } else {
  7273. $w = $l;
  7274. }
  7275. break;
  7276. }
  7277. case 'R': {
  7278. if ($this->rtl) {
  7279. $w = $l;
  7280. } else {
  7281. $w = $w;
  7282. }
  7283. break;
  7284. }
  7285. default: {
  7286. $w = $l;
  7287. break;
  7288. }
  7289. }
  7290. $tmpstr = $this->UniArrSubString($uchars, $j, $nb);
  7291. if ($firstline) {
  7292. $startx = $this->x;
  7293. $tmparr = array_slice($chars, $j, ($nb - $j));
  7294. if ($rtlmode) {
  7295. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  7296. }
  7297. $linew = $this->GetArrStringWidth($tmparr);
  7298. unset($tmparr);
  7299. if ($this->rtl) {
  7300. $this->endlinex = $startx - $linew;
  7301. } else {
  7302. $this->endlinex = $startx + $linew;
  7303. }
  7304. $w = $linew;
  7305. $tmpcellpadding = $this->cell_padding;
  7306. if ($maxh == 0) {
  7307. $this->SetCellPadding(0);
  7308. }
  7309. }
  7310. if ($firstblock AND $this->isRTLTextDir()) {
  7311. $tmpstr = $this->stringRightTrim($tmpstr);
  7312. }
  7313. $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
  7314. unset($tmpstr);
  7315. if ($firstline) {
  7316. $this->cell_padding = $tmpcellpadding;
  7317. return ($this->UniArrSubString($uchars, $nb));
  7318. }
  7319. ++$nl;
  7320. }
  7321. if ($firstline) {
  7322. return '';
  7323. }
  7324. return $nl;
  7325. }
  7326. /**
  7327. * Returns the remaining width between the current position and margins.
  7328. * @return int Return the remaining width
  7329. * @protected
  7330. */
  7331. protected function getRemainingWidth() {
  7332. list($this->x, $this->y) = $this->checkPageRegions(0, $this->x, $this->y);
  7333. if ($this->rtl) {
  7334. return ($this->x - $this->lMargin);
  7335. } else {
  7336. return ($this->w - $this->rMargin - $this->x);
  7337. }
  7338. }
  7339. /**
  7340. * Extract a slice of the $strarr array and return it as string.
  7341. * @param $strarr (string) The input array of characters.
  7342. * @param $start (int) the starting element of $strarr.
  7343. * @param $end (int) first element that will not be returned.
  7344. * @return Return part of a string
  7345. * @public
  7346. */
  7347. public function UTF8ArrSubString($strarr, $start='', $end='') {
  7348. if (strlen($start) == 0) {
  7349. $start = 0;
  7350. }
  7351. if (strlen($end) == 0) {
  7352. $end = count($strarr);
  7353. }
  7354. $string = '';
  7355. for ($i=$start; $i < $end; ++$i) {
  7356. $string .= $this->unichr($strarr[$i]);
  7357. }
  7358. return $string;
  7359. }
  7360. /**
  7361. * Extract a slice of the $uniarr array and return it as string.
  7362. * @param $uniarr (string) The input array of characters.
  7363. * @param $start (int) the starting element of $strarr.
  7364. * @param $end (int) first element that will not be returned.
  7365. * @return Return part of a string
  7366. * @public
  7367. * @since 4.5.037 (2009-04-07)
  7368. */
  7369. public function UniArrSubString($uniarr, $start='', $end='') {
  7370. if (strlen($start) == 0) {
  7371. $start = 0;
  7372. }
  7373. if (strlen($end) == 0) {
  7374. $end = count($uniarr);
  7375. }
  7376. $string = '';
  7377. for ($i=$start; $i < $end; ++$i) {
  7378. $string .= $uniarr[$i];
  7379. }
  7380. return $string;
  7381. }
  7382. /**
  7383. * Convert an array of UTF8 values to array of unicode characters
  7384. * @param $ta (string) The input array of UTF8 values.
  7385. * @return Return array of unicode characters
  7386. * @public
  7387. * @since 4.5.037 (2009-04-07)
  7388. */
  7389. public function UTF8ArrayToUniArray($ta) {
  7390. return array_map(array($this, 'unichr'), $ta);
  7391. }
  7392. /**
  7393. * Returns the unicode caracter specified by UTF-8 value
  7394. * @param $c (int) UTF-8 value
  7395. * @return Returns the specified character.
  7396. * @author Miguel Perez, Nicola Asuni
  7397. * @public
  7398. * @since 2.3.000 (2008-03-05)
  7399. */
  7400. public function unichr($c) {
  7401. if (!$this->isunicode) {
  7402. return chr($c);
  7403. } elseif ($c <= 0x7F) {
  7404. // one byte
  7405. return chr($c);
  7406. } elseif ($c <= 0x7FF) {
  7407. // two bytes
  7408. return chr(0xC0 | $c >> 6).chr(0x80 | $c & 0x3F);
  7409. } elseif ($c <= 0xFFFF) {
  7410. // three bytes
  7411. return chr(0xE0 | $c >> 12).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F);
  7412. } elseif ($c <= 0x10FFFF) {
  7413. // four bytes
  7414. return chr(0xF0 | $c >> 18).chr(0x80 | $c >> 12 & 0x3F).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F);
  7415. } else {
  7416. return '';
  7417. }
  7418. }
  7419. /**
  7420. * Return the image type given the file name or array returned by getimagesize() function.
  7421. * @param $imgfile (string) image file name
  7422. * @param $iminfo (array) array of image information returned by getimagesize() function.
  7423. * @return string image type
  7424. * @since 4.8.017 (2009-11-27)
  7425. */
  7426. public function getImageFileType($imgfile, $iminfo=array()) {
  7427. $type = '';
  7428. if (isset($iminfo['mime']) AND !empty($iminfo['mime'])) {
  7429. $mime = explode('/', $iminfo['mime']);
  7430. if ((count($mime) > 1) AND ($mime[0] == 'image') AND (!empty($mime[1]))) {
  7431. $type = strtolower(trim($mime[1]));
  7432. }
  7433. }
  7434. if (empty($type)) {
  7435. $fileinfo = pathinfo($imgfile);
  7436. if (isset($fileinfo['extension']) AND (!$this->empty_string($fileinfo['extension']))) {
  7437. $type = strtolower(trim($fileinfo['extension']));
  7438. }
  7439. }
  7440. if ($type == 'jpg') {
  7441. $type = 'jpeg';
  7442. }
  7443. return $type;
  7444. }
  7445. /**
  7446. * Set the block dimensions accounting for page breaks and page/column fitting
  7447. * @param $w (float) width
  7448. * @param $h (float) height
  7449. * @param $x (float) X coordinate
  7450. * @param $y (float) Y coodiante
  7451. * @param $fitonpage (boolean) if true the block is resized to not exceed page dimensions.
  7452. * @return array($w, $h, $x, $y)
  7453. * @protected
  7454. * @since 5.5.009 (2010-07-05)
  7455. */
  7456. protected function fitBlock($w, $h, $x, $y, $fitonpage=false) {
  7457. if ($w <= 0) {
  7458. // set maximum width
  7459. $w = ($this->w - $this->lMargin - $this->rMargin);
  7460. }
  7461. if ($h <= 0) {
  7462. // set maximum height
  7463. $h = ($this->PageBreakTrigger - $this->tMargin);
  7464. }
  7465. // resize the block to be vertically contained on a single page or single column
  7466. if ($fitonpage OR $this->AutoPageBreak) {
  7467. $ratio_wh = ($w / $h);
  7468. if ($h > ($this->PageBreakTrigger - $this->tMargin)) {
  7469. $h = $this->PageBreakTrigger - $this->tMargin;
  7470. $w = ($h * $ratio_wh);
  7471. }
  7472. // resize the block to be horizontally contained on a single page or single column
  7473. if ($fitonpage) {
  7474. $maxw = ($this->w - $this->lMargin - $this->rMargin);
  7475. if ($w > $maxw) {
  7476. $w = $maxw;
  7477. $h = ($w / $ratio_wh);
  7478. }
  7479. }
  7480. }
  7481. // Check whether we need a new page or new column first as this does not fit
  7482. $prev_x = $this->x;
  7483. $prev_y = $this->y;
  7484. if ($this->checkPageBreak($h, $y) OR ($this->y < $prev_y)) {
  7485. $y = $this->y;
  7486. if ($this->rtl) {
  7487. $x += ($prev_x - $this->x);
  7488. } else {
  7489. $x += ($this->x - $prev_x);
  7490. }
  7491. $this->newline = true;
  7492. }
  7493. // resize the block to be contained on the remaining available page or column space
  7494. if ($fitonpage) {
  7495. $ratio_wh = ($w / $h);
  7496. if (($y + $h) > $this->PageBreakTrigger) {
  7497. $h = $this->PageBreakTrigger - $y;
  7498. $w = ($h * $ratio_wh);
  7499. }
  7500. if ((!$this->rtl) AND (($x + $w) > ($this->w - $this->rMargin))) {
  7501. $w = $this->w - $this->rMargin - $x;
  7502. $h = ($w / $ratio_wh);
  7503. } elseif (($this->rtl) AND (($x - $w) < ($this->lMargin))) {
  7504. $w = $x - $this->lMargin;
  7505. $h = ($w / $ratio_wh);
  7506. }
  7507. }
  7508. return array($w, $h, $x, $y);
  7509. }
  7510. /**
  7511. * Puts an image in the page.
  7512. * The upper-left corner must be given.
  7513. * The dimensions can be specified in different ways:<ul>
  7514. * <li>explicit width and height (expressed in user unit)</li>
  7515. * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
  7516. * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  7517. * 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;
  7518. * The format can be specified explicitly or inferred from the file extension.<br />
  7519. * It is possible to put a link on the image.<br />
  7520. * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  7521. * @param $file (string) Name of the file containing the image or a '@' character followed by the image data string. To link an image without embedding it on the document, set an asterisk character before the URL (i.e.: '*http://www.example.com/image.jpg').
  7522. * @param $x (float) Abscissa of the upper-left corner (LTR) or upper-right corner (RTL).
  7523. * @param $y (float) Ordinate of the upper-left corner (LTR) or upper-right corner (RTL).
  7524. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  7525. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  7526. * @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.
  7527. * @param $link (mixed) URL or identifier returned by AddLink().
  7528. * @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>
  7529. * @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).
  7530. * @param $dpi (int) dot-per-inch resolution used on resize
  7531. * @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>
  7532. * @param $ismask (boolean) true if this image is a mask, false otherwise
  7533. * @param $imgmask (mixed) image object returned by this function or false
  7534. * @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)))
  7535. * @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).
  7536. * @param $hidden (boolean) If true do not display the image.
  7537. * @param $fitonpage (boolean) If true the image is resized to not exceed page dimensions.
  7538. * @param $alt (boolean) If true the image will be added as alternative and not directly printed (the ID of the image will be returned).
  7539. * @param $altimgs (array) Array of alternate images IDs. Each alternative image must be an array with two values: an integer representing the image ID (the value returned by the Image method) and a boolean value to indicate if the image is the default for printing.
  7540. * @return image information
  7541. * @public
  7542. * @since 1.1
  7543. */
  7544. public function Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false, $alt=false, $altimgs=array()) {
  7545. if ($this->state != 2) {
  7546. return;
  7547. }
  7548. if ($x === '') {
  7549. $x = $this->x;
  7550. }
  7551. if ($y === '') {
  7552. $y = $this->y;
  7553. }
  7554. // check page for no-write regions and adapt page margins if necessary
  7555. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  7556. $exurl = ''; // external streams
  7557. // check if we are passing an image as file or string
  7558. if ($file[0] === '@') {
  7559. // image from string
  7560. $imgdata = substr($file, 1);
  7561. $file = $this->getObjFilename('img');
  7562. $fp = fopen($file, 'w');
  7563. fwrite($fp, $imgdata);
  7564. fclose($fp);
  7565. unset($imgdata);
  7566. $imsize = @getimagesize($file);
  7567. if ($imsize === FALSE) {
  7568. unlink($file);
  7569. } else {
  7570. $this->cached_files[] = $file;
  7571. }
  7572. } else { // image file
  7573. if ($file{0} === '*') {
  7574. // image as external stream
  7575. $file = substr($file, 1);
  7576. $exurl = $file;
  7577. }
  7578. // check if is local file
  7579. if (!@file_exists($file)) {
  7580. // encode spaces on filename (file is probably an URL)
  7581. $file = str_replace(' ', '%20', $file);
  7582. }
  7583. if (@file_exists($file)) {
  7584. // get image dimensions
  7585. $imsize = @getimagesize($file);
  7586. } else {
  7587. $imsize = false;
  7588. }
  7589. if ($imsize === FALSE) {
  7590. if (function_exists('curl_init')) {
  7591. // try to get remote file data using cURL
  7592. $cs = curl_init(); // curl session
  7593. curl_setopt($cs, CURLOPT_URL, $file);
  7594. curl_setopt($cs, CURLOPT_BINARYTRANSFER, true);
  7595. curl_setopt($cs, CURLOPT_FAILONERROR, true);
  7596. curl_setopt($cs, CURLOPT_RETURNTRANSFER, true);
  7597. if ((ini_get('open_basedir') == '') AND (!ini_get('safe_mode'))) {
  7598. curl_setopt($cs, CURLOPT_FOLLOWLOCATION, true);
  7599. }
  7600. curl_setopt($cs, CURLOPT_CONNECTTIMEOUT, 5);
  7601. curl_setopt($cs, CURLOPT_TIMEOUT, 30);
  7602. curl_setopt($cs, CURLOPT_USERAGENT, 'TCPDF');
  7603. $imgdata = curl_exec($cs);
  7604. curl_close($cs);
  7605. if ($imgdata !== FALSE) {
  7606. // copy image to cache
  7607. $file = $this->getObjFilename('img');
  7608. $fp = fopen($file, 'w');
  7609. fwrite($fp, $imgdata);
  7610. fclose($fp);
  7611. unset($imgdata);
  7612. $imsize = @getimagesize($file);
  7613. if ($imsize === FALSE) {
  7614. unlink($file);
  7615. } else {
  7616. $this->cached_files[] = $file;
  7617. }
  7618. }
  7619. } elseif (($w > 0) AND ($h > 0)) {
  7620. // get measures from specified data
  7621. $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  7622. $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  7623. $imsize = array($pw, $ph);
  7624. }
  7625. }
  7626. }
  7627. if ($imsize === FALSE) {
  7628. if (substr($file, 0, -34) == K_PATH_CACHE.'msk') { // mask file
  7629. // get measures from specified data
  7630. $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  7631. $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  7632. $imsize = array($pw, $ph);
  7633. } else {
  7634. $this->Error('[Image] Unable to get image: '.$file);
  7635. }
  7636. }
  7637. // file hash
  7638. $filehash = md5($this->file_id.$file);
  7639. // get original image width and height in pixels
  7640. list($pixw, $pixh) = $imsize;
  7641. // calculate image width and height on document
  7642. if (($w <= 0) AND ($h <= 0)) {
  7643. // convert image size to document unit
  7644. $w = $this->pixelsToUnits($pixw);
  7645. $h = $this->pixelsToUnits($pixh);
  7646. } elseif ($w <= 0) {
  7647. $w = $h * $pixw / $pixh;
  7648. } elseif ($h <= 0) {
  7649. $h = $w * $pixh / $pixw;
  7650. } elseif (($fitbox !== false) AND ($w > 0) AND ($h > 0)) {
  7651. if (strlen($fitbox) !== 2) {
  7652. // set default alignment
  7653. $fitbox = '--';
  7654. }
  7655. // scale image dimensions proportionally to fit within the ($w, $h) box
  7656. if ((($w * $pixh) / ($h * $pixw)) < 1) {
  7657. // store current height
  7658. $oldh = $h;
  7659. // calculate new height
  7660. $h = $w * $pixh / $pixw;
  7661. // height difference
  7662. $hdiff = ($oldh - $h);
  7663. // vertical alignment
  7664. switch (strtoupper($fitbox{1})) {
  7665. case 'T': {
  7666. break;
  7667. }
  7668. case 'M': {
  7669. $y += ($hdiff / 2);
  7670. break;
  7671. }
  7672. case 'B': {
  7673. $y += $hdiff;
  7674. break;
  7675. }
  7676. }
  7677. } else {
  7678. // store current width
  7679. $oldw = $w;
  7680. // calculate new width
  7681. $w = $h * $pixw / $pixh;
  7682. // width difference
  7683. $wdiff = ($oldw - $w);
  7684. // horizontal alignment
  7685. switch (strtoupper($fitbox{0})) {
  7686. case 'L': {
  7687. if ($this->rtl) {
  7688. $x -= $wdiff;
  7689. }
  7690. break;
  7691. }
  7692. case 'C': {
  7693. if ($this->rtl) {
  7694. $x -= ($wdiff / 2);
  7695. } else {
  7696. $x += ($wdiff / 2);
  7697. }
  7698. break;
  7699. }
  7700. case 'R': {
  7701. if (!$this->rtl) {
  7702. $x += $wdiff;
  7703. }
  7704. break;
  7705. }
  7706. }
  7707. }
  7708. }
  7709. // fit the image on available space
  7710. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  7711. // calculate new minimum dimensions in pixels
  7712. $neww = round($w * $this->k * $dpi / $this->dpi);
  7713. $newh = round($h * $this->k * $dpi / $this->dpi);
  7714. // check if resize is necessary (resize is used only to reduce the image)
  7715. $newsize = ($neww * $newh);
  7716. $pixsize = ($pixw * $pixh);
  7717. if (intval($resize) == 2) {
  7718. $resize = true;
  7719. } elseif ($newsize >= $pixsize) {
  7720. $resize = false;
  7721. }
  7722. // check if image has been already added on document
  7723. $newimage = true;
  7724. if (in_array($file, $this->imagekeys)) {
  7725. $newimage = false;
  7726. // get existing image data
  7727. $info = $this->getImageBuffer($file);
  7728. if (substr($file, 0, -34) != K_PATH_CACHE.'msk') {
  7729. // check if the newer image is larger
  7730. $oldsize = ($info['w'] * $info['h']);
  7731. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  7732. $newimage = true;
  7733. }
  7734. }
  7735. } elseif (substr($file, 0, -34) != K_PATH_CACHE.'msk') {
  7736. // check for cached images with alpha channel
  7737. $tempfile_plain = K_PATH_CACHE.'mskp_'.$filehash;
  7738. $tempfile_alpha = K_PATH_CACHE.'mska_'.$filehash;
  7739. if (in_array($tempfile_plain, $this->imagekeys)) {
  7740. // get existing image data
  7741. $info = $this->getImageBuffer($tempfile_plain);
  7742. // check if the newer image is larger
  7743. $oldsize = ($info['w'] * $info['h']);
  7744. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  7745. $newimage = true;
  7746. } else {
  7747. $newimage = false;
  7748. // embed mask image
  7749. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  7750. // embed image, masked with previously embedded mask
  7751. return $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  7752. }
  7753. }
  7754. }
  7755. if ($newimage) {
  7756. //First use of image, get info
  7757. $type = strtolower($type);
  7758. if ($type == '') {
  7759. $type = $this->getImageFileType($file, $imsize);
  7760. } elseif ($type == 'jpg') {
  7761. $type = 'jpeg';
  7762. }
  7763. $mqr = $this->get_mqr();
  7764. $this->set_mqr(false);
  7765. // Specific image handlers
  7766. $mtd = '_parse'.$type;
  7767. // GD image handler function
  7768. $gdfunction = 'imagecreatefrom'.$type;
  7769. $info = false;
  7770. if ((method_exists($this, $mtd)) AND (!($resize AND (function_exists($gdfunction) OR extension_loaded('imagick'))))) {
  7771. // TCPDF image functions
  7772. $info = $this->$mtd($file);
  7773. if ($info == 'pngalpha') {
  7774. return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign, $filehash);
  7775. }
  7776. }
  7777. if (!$info) {
  7778. if (function_exists($gdfunction)) {
  7779. // GD library
  7780. $img = $gdfunction($file);
  7781. if ($resize) {
  7782. $imgr = imagecreatetruecolor($neww, $newh);
  7783. if (($type == 'gif') OR ($type == 'png')) {
  7784. $imgr = $this->_setGDImageTransparency($imgr, $img);
  7785. }
  7786. imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
  7787. if (($type == 'gif') OR ($type == 'png')) {
  7788. $info = $this->_toPNG($imgr);
  7789. } else {
  7790. $info = $this->_toJPEG($imgr);
  7791. }
  7792. } else {
  7793. if (($type == 'gif') OR ($type == 'png')) {
  7794. $info = $this->_toPNG($img);
  7795. } else {
  7796. $info = $this->_toJPEG($img);
  7797. }
  7798. }
  7799. } elseif (extension_loaded('imagick')) {
  7800. // ImageMagick library
  7801. $img = new Imagick();
  7802. if ($type == 'SVG') {
  7803. // get SVG file content
  7804. $svgimg = file_get_contents($file);
  7805. // get width and height
  7806. $regs = array();
  7807. if (preg_match('/<svg([^\>]*)>/si', $svgimg, $regs)) {
  7808. $svgtag = $regs[1];
  7809. $tmp = array();
  7810. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  7811. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  7812. $owu = sprintf('%F', ($ow * $dpi / 72)).$this->pdfunit;
  7813. $svgtag = preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si', ' width="'.$owu.'"', $svgtag, 1);
  7814. } else {
  7815. $ow = $w;
  7816. }
  7817. $tmp = array();
  7818. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  7819. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  7820. $ohu = sprintf('%F', ($oh * $dpi / 72)).$this->pdfunit;
  7821. $svgtag = preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si', ' height="'.$ohu.'"', $svgtag, 1);
  7822. } else {
  7823. $oh = $h;
  7824. }
  7825. $tmp = array();
  7826. if (!preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $svgtag, $tmp)) {
  7827. $vbw = ($ow * $this->imgscale * $this->k);
  7828. $vbh = ($oh * $this->imgscale * $this->k);
  7829. $vbox = sprintf(' viewBox="0 0 %F %F" ', $vbw, $vbh);
  7830. $svgtag = $vbox.$svgtag;
  7831. }
  7832. $svgimg = preg_replace('/<svg([^\>]*)>/si', '<svg'.$svgtag.'>', $svgimg, 1);
  7833. }
  7834. $img->readImageBlob($svgimg);
  7835. } else {
  7836. $img->readImage($file);
  7837. }
  7838. if ($resize) {
  7839. $img->resizeImage($neww, $newh, 10, 1, false);
  7840. }
  7841. $img->setCompressionQuality($this->jpeg_quality);
  7842. $img->setImageFormat('jpeg');
  7843. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  7844. $img->writeImage($tempname);
  7845. $info = $this->_parsejpeg($tempname);
  7846. unlink($tempname);
  7847. $img->destroy();
  7848. } else {
  7849. return;
  7850. }
  7851. }
  7852. if ($info === false) {
  7853. //If false, we cannot process image
  7854. return;
  7855. }
  7856. $this->set_mqr($mqr);
  7857. if ($ismask) {
  7858. // force grayscale
  7859. $info['cs'] = 'DeviceGray';
  7860. }
  7861. if ($imgmask !== false) {
  7862. $info['masked'] = $imgmask;
  7863. }
  7864. if (!empty($exurl)) {
  7865. $info['exurl'] = $exurl;
  7866. }
  7867. // array of alternative images
  7868. $info['altimgs'] = $altimgs;
  7869. // add image to document
  7870. $info['i'] = $this->setImageBuffer($file, $info);
  7871. }
  7872. // set alignment
  7873. $this->img_rb_y = $y + $h;
  7874. // set alignment
  7875. if ($this->rtl) {
  7876. if ($palign == 'L') {
  7877. $ximg = $this->lMargin;
  7878. } elseif ($palign == 'C') {
  7879. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  7880. } elseif ($palign == 'R') {
  7881. $ximg = $this->w - $this->rMargin - $w;
  7882. } else {
  7883. $ximg = $x - $w;
  7884. }
  7885. $this->img_rb_x = $ximg;
  7886. } else {
  7887. if ($palign == 'L') {
  7888. $ximg = $this->lMargin;
  7889. } elseif ($palign == 'C') {
  7890. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  7891. } elseif ($palign == 'R') {
  7892. $ximg = $this->w - $this->rMargin - $w;
  7893. } else {
  7894. $ximg = $x;
  7895. }
  7896. $this->img_rb_x = $ximg + $w;
  7897. }
  7898. if ($ismask OR $hidden) {
  7899. // image is not displayed
  7900. return $info['i'];
  7901. }
  7902. $xkimg = $ximg * $this->k;
  7903. if (!$alt) {
  7904. // only non-alternative immages will be set
  7905. $this->_out(sprintf('q %F 0 0 %F %F %F cm /I%u Do Q', ($w * $this->k), ($h * $this->k), $xkimg, (($this->h - ($y + $h)) * $this->k), $info['i']));
  7906. }
  7907. if (!empty($border)) {
  7908. $bx = $this->x;
  7909. $by = $this->y;
  7910. $this->x = $ximg;
  7911. if ($this->rtl) {
  7912. $this->x += $w;
  7913. }
  7914. $this->y = $y;
  7915. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  7916. $this->x = $bx;
  7917. $this->y = $by;
  7918. }
  7919. if ($link) {
  7920. $this->Link($ximg, $y, $w, $h, $link, 0);
  7921. }
  7922. // set pointer to align the next text/objects
  7923. switch($align) {
  7924. case 'T': {
  7925. $this->y = $y;
  7926. $this->x = $this->img_rb_x;
  7927. break;
  7928. }
  7929. case 'M': {
  7930. $this->y = $y + round($h/2);
  7931. $this->x = $this->img_rb_x;
  7932. break;
  7933. }
  7934. case 'B': {
  7935. $this->y = $this->img_rb_y;
  7936. $this->x = $this->img_rb_x;
  7937. break;
  7938. }
  7939. case 'N': {
  7940. $this->SetY($this->img_rb_y);
  7941. break;
  7942. }
  7943. default:{
  7944. break;
  7945. }
  7946. }
  7947. $this->endlinex = $this->img_rb_x;
  7948. if ($this->inxobj) {
  7949. // we are inside an XObject template
  7950. $this->xobjects[$this->xobjid]['images'][] = $info['i'];
  7951. }
  7952. return $info['i'];
  7953. }
  7954. /**
  7955. * Sets the current active configuration setting of magic_quotes_runtime (if the set_magic_quotes_runtime function exist)
  7956. * @param $mqr (boolean) FALSE for off, TRUE for on.
  7957. * @since 4.6.025 (2009-08-17)
  7958. */
  7959. public function set_mqr($mqr) {
  7960. if (!defined('PHP_VERSION_ID')) {
  7961. $version = PHP_VERSION;
  7962. define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
  7963. }
  7964. if (PHP_VERSION_ID < 50300) {
  7965. @set_magic_quotes_runtime($mqr);
  7966. }
  7967. }
  7968. /**
  7969. * Gets the current active configuration setting of magic_quotes_runtime (if the get_magic_quotes_runtime function exist)
  7970. * @return Returns 0 if magic quotes runtime is off or get_magic_quotes_runtime doesn't exist, 1 otherwise.
  7971. * @since 4.6.025 (2009-08-17)
  7972. */
  7973. public function get_mqr() {
  7974. if (!defined('PHP_VERSION_ID')) {
  7975. $version = PHP_VERSION;
  7976. define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
  7977. }
  7978. if (PHP_VERSION_ID < 50300) {
  7979. return @get_magic_quotes_runtime();
  7980. }
  7981. return 0;
  7982. }
  7983. /**
  7984. * Convert the loaded image to a JPEG and then return a structure for the PDF creator.
  7985. * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
  7986. * @param $image (image) Image object.
  7987. * return image JPEG image object.
  7988. * @protected
  7989. */
  7990. protected function _toJPEG($image) {
  7991. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  7992. imagejpeg($image, $tempname, $this->jpeg_quality);
  7993. imagedestroy($image);
  7994. $retvars = $this->_parsejpeg($tempname);
  7995. // tidy up by removing temporary image
  7996. unlink($tempname);
  7997. return $retvars;
  7998. }
  7999. /**
  8000. * Convert the loaded image to a PNG and then return a structure for the PDF creator.
  8001. * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
  8002. * @param $image (image) Image object.
  8003. * return image PNG image object.
  8004. * @protected
  8005. * @since 4.9.016 (2010-04-20)
  8006. */
  8007. protected function _toPNG($image) {
  8008. // set temporary image file name
  8009. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  8010. // turn off interlaced mode
  8011. imageinterlace($image, 0);
  8012. // create temporary PNG image
  8013. imagepng($image, $tempname);
  8014. // remove image from memory
  8015. imagedestroy($image);
  8016. // get PNG image data
  8017. $retvars = $this->_parsepng($tempname);
  8018. // tidy up by removing temporary image
  8019. unlink($tempname);
  8020. return $retvars;
  8021. }
  8022. /**
  8023. * Set the transparency for the given GD image.
  8024. * @param $new_image (image) GD image object
  8025. * @param $image (image) GD image object.
  8026. * return GD image object.
  8027. * @protected
  8028. * @since 4.9.016 (2010-04-20)
  8029. */
  8030. protected function _setGDImageTransparency($new_image, $image) {
  8031. // transparency index
  8032. $tid = imagecolortransparent($image);
  8033. // default transparency color
  8034. $tcol = array('red' => 255, 'green' => 255, 'blue' => 255);
  8035. if ($tid >= 0) {
  8036. // get the colors for the transparency index
  8037. $tcol = imagecolorsforindex($image, $tid);
  8038. }
  8039. $tid = imagecolorallocate($new_image, $tcol['red'], $tcol['green'], $tcol['blue']);
  8040. imagefill($new_image, 0, 0, $tid);
  8041. imagecolortransparent($new_image, $tid);
  8042. return $new_image;
  8043. }
  8044. /**
  8045. * Extract info from a JPEG file without using the GD library.
  8046. * @param $file (string) image file to parse
  8047. * @return array structure containing the image data
  8048. * @protected
  8049. */
  8050. protected function _parsejpeg($file) {
  8051. $a = getimagesize($file);
  8052. if (empty($a)) {
  8053. $this->Error('Missing or incorrect image file: '.$file);
  8054. }
  8055. if ($a[2] != 2) {
  8056. $this->Error('Not a JPEG file: '.$file);
  8057. }
  8058. // bits per pixel
  8059. $bpc = isset($a['bits']) ? intval($a['bits']) : 8;
  8060. // number of image channels
  8061. if (!isset($a['channels'])) {
  8062. $channels = 3;
  8063. } else {
  8064. $channels = intval($a['channels']);
  8065. }
  8066. // default colour space
  8067. switch ($channels) {
  8068. case 1: {
  8069. $colspace = 'DeviceGray';
  8070. break;
  8071. }
  8072. case 3: {
  8073. $colspace = 'DeviceRGB';
  8074. break;
  8075. }
  8076. case 4: {
  8077. $colspace = 'DeviceCMYK';
  8078. break;
  8079. }
  8080. default: {
  8081. $channels = 3;
  8082. $colspace = 'DeviceRGB';
  8083. break;
  8084. }
  8085. }
  8086. // get file content
  8087. $data = file_get_contents($file);
  8088. // check for embedded ICC profile
  8089. $icc = array();
  8090. $offset = 0;
  8091. while (($pos = strpos($data, "ICC_PROFILE\0", $offset)) !== false) {
  8092. // get ICC sequence length
  8093. $length = ($this->_getUSHORT($data, ($pos - 2)) - 16);
  8094. // marker sequence number
  8095. $msn = max(1, ord($data[($pos + 12)]));
  8096. // number of markers (total of APP2 used)
  8097. $nom = max(1, ord($data[($pos + 13)]));
  8098. // get sequence segment
  8099. $icc[($msn - 1)] = substr($data, ($pos + 14), $length);
  8100. // move forward to next sequence
  8101. $offset = ($pos + 14 + $length);
  8102. }
  8103. // order and compact ICC segments
  8104. if (count($icc) > 0) {
  8105. ksort($icc);
  8106. $icc = implode('', $icc);
  8107. if ((ord($icc{36}) != 0x61) OR (ord($icc{37}) != 0x63) OR (ord($icc{38}) != 0x73) OR (ord($icc{39}) != 0x70)) {
  8108. // invalid ICC profile
  8109. $icc = false;
  8110. }
  8111. } else {
  8112. $icc = false;
  8113. }
  8114. return array('w' => $a[0], 'h' => $a[1], 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data);
  8115. }
  8116. /**
  8117. * Extract info from a PNG file without using the GD library.
  8118. * @param $file (string) image file to parse
  8119. * @return array structure containing the image data
  8120. * @protected
  8121. */
  8122. protected function _parsepng($file) {
  8123. $f = fopen($file, 'rb');
  8124. if ($f === false) {
  8125. $this->Error('Can\'t open image file: '.$file);
  8126. }
  8127. //Check signature
  8128. if (fread($f, 8) != chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
  8129. $this->Error('Not a PNG file: '.$file);
  8130. }
  8131. //Read header chunk
  8132. fread($f, 4);
  8133. if (fread($f, 4) != 'IHDR') {
  8134. $this->Error('Incorrect PNG file: '.$file);
  8135. }
  8136. $w = $this->_freadint($f);
  8137. $h = $this->_freadint($f);
  8138. $bpc = ord(fread($f, 1));
  8139. if ($bpc > 8) {
  8140. //$this->Error('16-bit depth not supported: '.$file);
  8141. fclose($f);
  8142. return false;
  8143. }
  8144. $ct = ord(fread($f, 1));
  8145. if ($ct == 0) {
  8146. $colspace = 'DeviceGray';
  8147. } elseif ($ct == 2) {
  8148. $colspace = 'DeviceRGB';
  8149. } elseif ($ct == 3) {
  8150. $colspace = 'Indexed';
  8151. } else {
  8152. // alpha channel
  8153. fclose($f);
  8154. return 'pngalpha';
  8155. }
  8156. if (ord(fread($f, 1)) != 0) {
  8157. //$this->Error('Unknown compression method: '.$file);
  8158. fclose($f);
  8159. return false;
  8160. }
  8161. if (ord(fread($f, 1)) != 0) {
  8162. //$this->Error('Unknown filter method: '.$file);
  8163. fclose($f);
  8164. return false;
  8165. }
  8166. if (ord(fread($f, 1)) != 0) {
  8167. //$this->Error('Interlacing not supported: '.$file);
  8168. fclose($f);
  8169. return false;
  8170. }
  8171. fread($f, 4);
  8172. $channels = ($ct == 2 ? 3 : 1);
  8173. $parms = '/DecodeParms << /Predictor 15 /Colors '.$channels.' /BitsPerComponent '.$bpc.' /Columns '.$w.' >>';
  8174. //Scan chunks looking for palette, transparency and image data
  8175. $pal = '';
  8176. $trns = '';
  8177. $data = '';
  8178. $icc = false;
  8179. do {
  8180. $n = $this->_freadint($f);
  8181. $type = fread($f, 4);
  8182. if ($type == 'PLTE') {
  8183. // read palette
  8184. $pal = $this->rfread($f, $n);
  8185. fread($f, 4);
  8186. } elseif ($type == 'tRNS') {
  8187. // read transparency info
  8188. $t = $this->rfread($f, $n);
  8189. if ($ct == 0) {
  8190. $trns = array(ord($t{1}));
  8191. } elseif ($ct == 2) {
  8192. $trns = array(ord($t{1}), ord($t{3}), ord($t{5}));
  8193. } else {
  8194. $pos = strpos($t, chr(0));
  8195. if ($pos !== false) {
  8196. $trns = array($pos);
  8197. }
  8198. }
  8199. fread($f, 4);
  8200. } elseif ($type == 'IDAT') {
  8201. // read image data block
  8202. $data .= $this->rfread($f, $n);
  8203. fread($f, 4);
  8204. } elseif ($type == 'iCCP') {
  8205. // skip profile name
  8206. $len = 0;
  8207. while ((ord(fread($f, 1)) > 0) AND ($len < 80)) {
  8208. ++$len;
  8209. }
  8210. // skip null separator
  8211. fread($f, 1);
  8212. // get compression method
  8213. if (ord(fread($f, 1)) != 0) {
  8214. //$this->Error('Unknown filter method: '.$file);
  8215. fclose($f);
  8216. return false;
  8217. }
  8218. // read ICC Color Profile
  8219. $icc = $this->rfread($f, ($n - $len - 2));
  8220. // decompress profile
  8221. $icc = gzuncompress($icc);
  8222. fread($f, 4);
  8223. } elseif ($type == 'IEND') {
  8224. break;
  8225. } else {
  8226. $this->rfread($f, $n + 4);
  8227. }
  8228. } while ($n);
  8229. if (($colspace == 'Indexed') AND (empty($pal))) {
  8230. //$this->Error('Missing palette in '.$file);
  8231. fclose($f);
  8232. return false;
  8233. }
  8234. fclose($f);
  8235. return array('w' => $w, 'h' => $h, 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data);
  8236. }
  8237. /**
  8238. * Binary-safe and URL-safe file read.
  8239. * 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.
  8240. * @param $handle (resource)
  8241. * @param $length (int)
  8242. * @return Returns the read string or FALSE in case of error.
  8243. * @author Nicola Asuni
  8244. * @protected
  8245. * @since 4.5.027 (2009-03-16)
  8246. */
  8247. protected function rfread($handle, $length) {
  8248. $data = fread($handle, $length);
  8249. if ($data === false) {
  8250. return false;
  8251. }
  8252. $rest = $length - strlen($data);
  8253. if ($rest > 0) {
  8254. $data .= $this->rfread($handle, $rest);
  8255. }
  8256. return $data;
  8257. }
  8258. /**
  8259. * Extract info from a PNG image with alpha channel using the GD library.
  8260. * @param $file (string) Name of the file containing the image.
  8261. * @param $x (float) Abscissa of the upper-left corner.
  8262. * @param $y (float) Ordinate of the upper-left corner.
  8263. * @param $wpx (float) Original width of the image in pixels.
  8264. * @param $hpx (float) original height of the image in pixels.
  8265. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  8266. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  8267. * @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.
  8268. * @param $link (mixed) URL or identifier returned by AddLink().
  8269. * @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>
  8270. * @param $resize (boolean) If true resize (reduce) the image to fit $w and $h (requires GD library).
  8271. * @param $dpi (int) dot-per-inch resolution used on resize
  8272. * @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>
  8273. * @param $filehash (string) File hash used to build unique file names.
  8274. * @author Nicola Asuni
  8275. * @protected
  8276. * @since 4.3.007 (2008-12-04)
  8277. * @see Image()
  8278. */
  8279. protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $filehash='') {
  8280. if (empty($filehash)) {
  8281. $filehash = md5($this->file_id.$file);
  8282. }
  8283. // create temp image file (without alpha channel)
  8284. $tempfile_plain = K_PATH_CACHE.'mskp_'.$filehash;
  8285. // create temp alpha file
  8286. $tempfile_alpha = K_PATH_CACHE.'mska_'.$filehash;
  8287. if (extension_loaded('imagick')) { // ImageMagick extension
  8288. // ImageMagick library
  8289. $img = new Imagick();
  8290. $img->readImage($file);
  8291. // clone image object
  8292. $imga = $this->objclone($img);
  8293. // extract alpha channel
  8294. if (method_exists($img, 'setImageAlphaChannel') AND defined('Imagick::ALPHACHANNEL_EXTRACT')) {
  8295. $img->setImageAlphaChannel(Imagick::ALPHACHANNEL_EXTRACT);
  8296. } else {
  8297. $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE);
  8298. $img->negateImage(true);
  8299. }
  8300. $img->setImageFormat('png');
  8301. $img->writeImage($tempfile_alpha);
  8302. // remove alpha channel
  8303. if (method_exists($imga, 'setImageMatte')) {
  8304. $imga->setImageMatte(false);
  8305. } else {
  8306. $imga->separateImageChannel(39); // 39 = (imagick::CHANNEL_ALL & ~(imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE));
  8307. }
  8308. $imga->setImageFormat('png');
  8309. $imga->writeImage($tempfile_plain);
  8310. } elseif (function_exists('imagecreatefrompng')) { // GD extension
  8311. // generate images
  8312. $img = imagecreatefrompng($file);
  8313. $imgalpha = imagecreate($wpx, $hpx);
  8314. // generate gray scale palette (0 -> 255)
  8315. for ($c = 0; $c < 256; ++$c) {
  8316. ImageColorAllocate($imgalpha, $c, $c, $c);
  8317. }
  8318. // extract alpha channel
  8319. for ($xpx = 0; $xpx < $wpx; ++$xpx) {
  8320. for ($ypx = 0; $ypx < $hpx; ++$ypx) {
  8321. $color = imagecolorat($img, $xpx, $ypx);
  8322. $alpha = $this->getGDgamma($color); // correct gamma
  8323. imagesetpixel($imgalpha, $xpx, $ypx, $alpha);
  8324. }
  8325. }
  8326. imagepng($imgalpha, $tempfile_alpha);
  8327. imagedestroy($imgalpha);
  8328. // extract image without alpha channel
  8329. $imgplain = imagecreatetruecolor($wpx, $hpx);
  8330. imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
  8331. imagepng($imgplain, $tempfile_plain);
  8332. imagedestroy($imgplain);
  8333. } else {
  8334. $this->Error('TCPDF requires the Imagick or GD extension to handle PNG images with alpha channel.');
  8335. }
  8336. // embed mask image
  8337. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  8338. // embed image, masked with previously embedded mask
  8339. $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  8340. // remove temp files
  8341. unlink($tempfile_alpha);
  8342. unlink($tempfile_plain);
  8343. }
  8344. /**
  8345. * Get the GD-corrected PNG gamma value from alpha color
  8346. * @param $c (int) alpha color
  8347. * @protected
  8348. * @since 4.3.007 (2008-12-04)
  8349. */
  8350. protected function getGDgamma($c) {
  8351. if (!isset($this->gdgammacache["'".$c."'"])) {
  8352. // shifts off the first 24 bits (where 8x3 are used for each color),
  8353. // and returns the remaining 7 allocated bits (commonly used for alpha)
  8354. $alpha = ($c >> 24);
  8355. // GD alpha is only 7 bit (0 -> 127)
  8356. $alpha = (((127 - $alpha) / 127) * 255);
  8357. // correct gamma
  8358. $this->gdgammacache["'".$c."'"] = (pow(($alpha / 255), 2.2) * 255);
  8359. // store the latest values on cache to improve performances
  8360. if (count($this->gdgammacache) > 8) {
  8361. // remove one element from the cache array
  8362. array_shift($this->gdgammacache);
  8363. }
  8364. }
  8365. return $this->gdgammacache["'".$c."'"];
  8366. }
  8367. /**
  8368. * Performs a line break.
  8369. * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  8370. * @param $h (float) The height of the break. By default, the value equals the height of the last printed cell.
  8371. * @param $cell (boolean) if true add the current left (or right o for RTL) padding to the X coordinate
  8372. * @public
  8373. * @since 1.0
  8374. * @see Cell()
  8375. */
  8376. public function Ln($h='', $cell=false) {
  8377. 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'])) {
  8378. // revove vertical space from the top of the column
  8379. return;
  8380. }
  8381. if ($cell) {
  8382. if ($this->rtl) {
  8383. $cellpadding = $this->cell_padding['R'];
  8384. } else {
  8385. $cellpadding = $this->cell_padding['L'];
  8386. }
  8387. } else {
  8388. $cellpadding = 0;
  8389. }
  8390. if ($this->rtl) {
  8391. $this->x = $this->w - $this->rMargin - $cellpadding;
  8392. } else {
  8393. $this->x = $this->lMargin + $cellpadding;
  8394. }
  8395. if (is_string($h)) {
  8396. $this->y += $this->lasth;
  8397. } else {
  8398. $this->y += $h;
  8399. }
  8400. $this->newline = true;
  8401. }
  8402. /**
  8403. * Returns the relative X value of current position.
  8404. * The value is relative to the left border for LTR languages and to the right border for RTL languages.
  8405. * @return float
  8406. * @public
  8407. * @since 1.2
  8408. * @see SetX(), GetY(), SetY()
  8409. */
  8410. public function GetX() {
  8411. //Get x position
  8412. if ($this->rtl) {
  8413. return ($this->w - $this->x);
  8414. } else {
  8415. return $this->x;
  8416. }
  8417. }
  8418. /**
  8419. * Returns the absolute X value of current position.
  8420. * @return float
  8421. * @public
  8422. * @since 1.2
  8423. * @see SetX(), GetY(), SetY()
  8424. */
  8425. public function GetAbsX() {
  8426. return $this->x;
  8427. }
  8428. /**
  8429. * Returns the ordinate of the current position.
  8430. * @return float
  8431. * @public
  8432. * @since 1.0
  8433. * @see SetY(), GetX(), SetX()
  8434. */
  8435. public function GetY() {
  8436. return $this->y;
  8437. }
  8438. /**
  8439. * Defines the abscissa of the current position.
  8440. * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
  8441. * @param $x (float) The value of the abscissa in user units.
  8442. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  8443. * @public
  8444. * @since 1.2
  8445. * @see GetX(), GetY(), SetY(), SetXY()
  8446. */
  8447. public function SetX($x, $rtloff=false) {
  8448. $x = floatval($x);
  8449. if (!$rtloff AND $this->rtl) {
  8450. if ($x >= 0) {
  8451. $this->x = $this->w - $x;
  8452. } else {
  8453. $this->x = abs($x);
  8454. }
  8455. } else {
  8456. if ($x >= 0) {
  8457. $this->x = $x;
  8458. } else {
  8459. $this->x = $this->w + $x;
  8460. }
  8461. }
  8462. if ($this->x < 0) {
  8463. $this->x = 0;
  8464. }
  8465. if ($this->x > $this->w) {
  8466. $this->x = $this->w;
  8467. }
  8468. }
  8469. /**
  8470. * Moves the current abscissa back to the left margin and sets the ordinate.
  8471. * If the passed value is negative, it is relative to the bottom of the page.
  8472. * @param $y (float) The value of the ordinate in user units.
  8473. * @param $resetx (bool) if true (default) reset the X position.
  8474. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  8475. * @public
  8476. * @since 1.0
  8477. * @see GetX(), GetY(), SetY(), SetXY()
  8478. */
  8479. public function SetY($y, $resetx=true, $rtloff=false) {
  8480. $y = floatval($y);
  8481. if ($resetx) {
  8482. //reset x
  8483. if (!$rtloff AND $this->rtl) {
  8484. $this->x = $this->w - $this->rMargin;
  8485. } else {
  8486. $this->x = $this->lMargin;
  8487. }
  8488. }
  8489. if ($y >= 0) {
  8490. $this->y = $y;
  8491. } else {
  8492. $this->y = $this->h + $y;
  8493. }
  8494. if ($this->y < 0) {
  8495. $this->y = 0;
  8496. }
  8497. if ($this->y > $this->h) {
  8498. $this->y = $this->h;
  8499. }
  8500. }
  8501. /**
  8502. * Defines the abscissa and ordinate of the current position.
  8503. * If the passed values are negative, they are relative respectively to the right and bottom of the page.
  8504. * @param $x (float) The value of the abscissa.
  8505. * @param $y (float) The value of the ordinate.
  8506. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  8507. * @public
  8508. * @since 1.2
  8509. * @see SetX(), SetY()
  8510. */
  8511. public function SetXY($x, $y, $rtloff=false) {
  8512. $this->SetY($y, false, $rtloff);
  8513. $this->SetX($x, $rtloff);
  8514. }
  8515. /**
  8516. * Set the absolute X coordinate of the current pointer.
  8517. * @param $x (float) The value of the abscissa in user units.
  8518. * @public
  8519. * @since 5.9.186 (2012-09-13)
  8520. * @see setAbsX(), setAbsY(), SetAbsXY()
  8521. */
  8522. public function SetAbsX($x) {
  8523. $this->x = floatval($x);
  8524. }
  8525. /**
  8526. * Set the absolute Y coordinate of the current pointer.
  8527. * @param $y (float) (float) The value of the ordinate in user units.
  8528. * @public
  8529. * @since 5.9.186 (2012-09-13)
  8530. * @see setAbsX(), setAbsY(), SetAbsXY()
  8531. */
  8532. public function SetAbsY($y) {
  8533. $this->y = floatval($y);
  8534. }
  8535. /**
  8536. * Set the absolute X and Y coordinates of the current pointer.
  8537. * @param $x (float) The value of the abscissa in user units.
  8538. * @param $y (float) (float) The value of the ordinate in user units.
  8539. * @public
  8540. * @since 5.9.186 (2012-09-13)
  8541. * @see setAbsX(), setAbsY(), SetAbsXY()
  8542. */
  8543. public function SetAbsXY($x, $y) {
  8544. $this->SetAbsX($x);
  8545. $this->SetAbsY($y);
  8546. }
  8547. /**
  8548. * Ouput input data and compress it if possible.
  8549. * @param $data (string) Data to output.
  8550. * @param $length (int) Data length in bytes.
  8551. * @protected
  8552. * @since 5.9.086
  8553. */
  8554. protected function sendOutputData($data, $length) {
  8555. if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
  8556. // the content length may vary if the server is using compression
  8557. header('Content-Length: '.$length);
  8558. }
  8559. echo $data;
  8560. }
  8561. /**
  8562. * Send the document to a given destination: string, local file or browser.
  8563. * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  8564. * The method first calls Close() if necessary to terminate the document.
  8565. * @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.
  8566. * @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>
  8567. * @public
  8568. * @since 1.0
  8569. * @see Close()
  8570. */
  8571. public function Output($name='doc.pdf', $dest='I') {
  8572. //Output PDF to some destination
  8573. //Finish document if necessary
  8574. if ($this->state < 3) {
  8575. $this->Close();
  8576. }
  8577. //Normalize parameters
  8578. if (is_bool($dest)) {
  8579. $dest = $dest ? 'D' : 'F';
  8580. }
  8581. $dest = strtoupper($dest);
  8582. if ($dest{0} != 'F') {
  8583. $name = preg_replace('/[\s]+/', '_', $name);
  8584. $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name);
  8585. }
  8586. if ($this->sign) {
  8587. // *** apply digital signature to the document ***
  8588. // get the document content
  8589. $pdfdoc = $this->getBuffer();
  8590. // remove last newline
  8591. $pdfdoc = substr($pdfdoc, 0, -1);
  8592. // Remove the original buffer
  8593. if (isset($this->diskcache) AND $this->diskcache) {
  8594. // remove buffer file from cache
  8595. unlink($this->buffer);
  8596. }
  8597. unset($this->buffer);
  8598. // remove filler space
  8599. $byterange_string_len = strlen($this->byterange_string);
  8600. // define the ByteRange
  8601. $byte_range = array();
  8602. $byte_range[0] = 0;
  8603. $byte_range[1] = strpos($pdfdoc, $this->byterange_string) + $byterange_string_len + 10;
  8604. $byte_range[2] = $byte_range[1] + $this->signature_max_length + 2;
  8605. $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
  8606. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).substr($pdfdoc, $byte_range[2]);
  8607. // replace the ByteRange
  8608. $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]);
  8609. $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
  8610. $pdfdoc = str_replace($this->byterange_string, $byterange, $pdfdoc);
  8611. // write the document to a temporary folder
  8612. $tempdoc = tempnam(K_PATH_CACHE, 'tmppdf_');
  8613. $f = fopen($tempdoc, 'wb');
  8614. if (!$f) {
  8615. $this->Error('Unable to create temporary file: '.$tempdoc);
  8616. }
  8617. $pdfdoc_length = strlen($pdfdoc);
  8618. fwrite($f, $pdfdoc, $pdfdoc_length);
  8619. fclose($f);
  8620. // get digital signature via openssl library
  8621. $tempsign = tempnam(K_PATH_CACHE, 'tmpsig_');
  8622. if (empty($this->signature_data['extracerts'])) {
  8623. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED);
  8624. } else {
  8625. 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']);
  8626. }
  8627. unlink($tempdoc);
  8628. // read signature
  8629. $signature = file_get_contents($tempsign);
  8630. unlink($tempsign);
  8631. // extract signature
  8632. $signature = substr($signature, $pdfdoc_length);
  8633. $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13));
  8634. $tmparr = explode("\n\n", $signature);
  8635. $signature = $tmparr[1];
  8636. unset($tmparr);
  8637. // decode signature
  8638. $signature = base64_decode(trim($signature));
  8639. // convert signature to hex
  8640. $signature = current(unpack('H*', $signature));
  8641. $signature = str_pad($signature, $this->signature_max_length, '0');
  8642. // disable disk caching
  8643. $this->diskcache = false;
  8644. // Add signature to the document
  8645. $this->buffer = substr($pdfdoc, 0, $byte_range[1]).'<'.$signature.'>'.substr($pdfdoc, $byte_range[1]);
  8646. $this->bufferlen = strlen($this->buffer);
  8647. }
  8648. switch($dest) {
  8649. case 'I': {
  8650. // Send PDF to the standard output
  8651. if (ob_get_contents()) {
  8652. $this->Error('Some data has already been output, can\'t send PDF file');
  8653. }
  8654. if (php_sapi_name() != 'cli') {
  8655. // send output to a browser
  8656. header('Content-Type: application/pdf');
  8657. if (headers_sent()) {
  8658. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  8659. }
  8660. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  8661. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  8662. header('Pragma: public');
  8663. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  8664. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  8665. header('Content-Disposition: inline; filename="'.basename($name).'"');
  8666. $this->sendOutputData($this->getBuffer(), $this->bufferlen);
  8667. } else {
  8668. echo $this->getBuffer();
  8669. }
  8670. break;
  8671. }
  8672. case 'D': {
  8673. // download PDF as file
  8674. if (ob_get_contents()) {
  8675. $this->Error('Some data has already been output, can\'t send PDF file');
  8676. }
  8677. header('Content-Description: File Transfer');
  8678. if (headers_sent()) {
  8679. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  8680. }
  8681. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  8682. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  8683. header('Pragma: public');
  8684. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  8685. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  8686. // force download dialog
  8687. if (strpos(php_sapi_name(), 'cgi') === false) {
  8688. header('Content-Type: application/force-download');
  8689. header('Content-Type: application/octet-stream', false);
  8690. header('Content-Type: application/download', false);
  8691. header('Content-Type: application/pdf', false);
  8692. } else {
  8693. header('Content-Type: application/pdf');
  8694. }
  8695. // use the Content-Disposition header to supply a recommended filename
  8696. header('Content-Disposition: attachment; filename="'.basename($name).'"');
  8697. header('Content-Transfer-Encoding: binary');
  8698. $this->sendOutputData($this->getBuffer(), $this->bufferlen);
  8699. break;
  8700. }
  8701. case 'F':
  8702. case 'FI':
  8703. case 'FD': {
  8704. // save PDF to a local file
  8705. if ($this->diskcache) {
  8706. copy($this->buffer, $name);
  8707. } else {
  8708. $f = fopen($name, 'wb');
  8709. if (!$f) {
  8710. $this->Error('Unable to create output file: '.$name);
  8711. }
  8712. fwrite($f, $this->getBuffer(), $this->bufferlen);
  8713. fclose($f);
  8714. }
  8715. if ($dest == 'FI') {
  8716. // send headers to browser
  8717. header('Content-Type: application/pdf');
  8718. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  8719. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  8720. header('Pragma: public');
  8721. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  8722. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  8723. header('Content-Disposition: inline; filename="'.basename($name).'"');
  8724. $this->sendOutputData(file_get_contents($name), filesize($name));
  8725. } elseif ($dest == 'FD') {
  8726. // send headers to browser
  8727. if (ob_get_contents()) {
  8728. $this->Error('Some data has already been output, can\'t send PDF file');
  8729. }
  8730. header('Content-Description: File Transfer');
  8731. if (headers_sent()) {
  8732. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  8733. }
  8734. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  8735. header('Pragma: public');
  8736. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  8737. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  8738. // force download dialog
  8739. if (strpos(php_sapi_name(), 'cgi') === false) {
  8740. header('Content-Type: application/force-download');
  8741. header('Content-Type: application/octet-stream', false);
  8742. header('Content-Type: application/download', false);
  8743. header('Content-Type: application/pdf', false);
  8744. } else {
  8745. header('Content-Type: application/pdf');
  8746. }
  8747. // use the Content-Disposition header to supply a recommended filename
  8748. header('Content-Disposition: attachment; filename="'.basename($name).'"');
  8749. header('Content-Transfer-Encoding: binary');
  8750. $this->sendOutputData(file_get_contents($name), filesize($name));
  8751. }
  8752. break;
  8753. }
  8754. case 'E': {
  8755. // return PDF as base64 mime multi-part email attachment (RFC 2045)
  8756. $retval = 'Content-Type: application/pdf;'."\r\n";
  8757. $retval .= ' name="'.$name.'"'."\r\n";
  8758. $retval .= 'Content-Transfer-Encoding: base64'."\r\n";
  8759. $retval .= 'Content-Disposition: attachment;'."\r\n";
  8760. $retval .= ' filename="'.$name.'"'."\r\n\r\n";
  8761. $retval .= chunk_split(base64_encode($this->getBuffer()), 76, "\r\n");
  8762. return $retval;
  8763. }
  8764. case 'S': {
  8765. // returns PDF as a string
  8766. return $this->getBuffer();
  8767. }
  8768. default: {
  8769. $this->Error('Incorrect output destination: '.$dest);
  8770. }
  8771. }
  8772. return '';
  8773. }
  8774. /**
  8775. * Unset all class variables except the following critical variables.
  8776. * @param $destroyall (boolean) if true destroys all class variables, otherwise preserves critical variables.
  8777. * @param $preserve_objcopy (boolean) if true preserves the objcopy variable
  8778. * @public
  8779. * @since 4.5.016 (2009-02-24)
  8780. */
  8781. public function _destroy($destroyall=false, $preserve_objcopy=false) {
  8782. if ($destroyall AND isset($this->diskcache) AND $this->diskcache AND (!$preserve_objcopy) AND (!$this->empty_string($this->buffer))) {
  8783. // remove buffer file from cache
  8784. unlink($this->buffer);
  8785. }
  8786. if ($destroyall AND isset($this->cached_files) AND !empty($this->cached_files)) {
  8787. // remove cached files
  8788. foreach ($this->cached_files as $cachefile) {
  8789. if (is_file($cachefile)) {
  8790. unlink($cachefile);
  8791. }
  8792. }
  8793. unset($this->cached_files);
  8794. }
  8795. foreach (array_keys(get_object_vars($this)) as $val) {
  8796. if ($destroyall OR (
  8797. ($val != 'internal_encoding')
  8798. AND ($val != 'state')
  8799. AND ($val != 'bufferlen')
  8800. AND ($val != 'buffer')
  8801. AND ($val != 'diskcache')
  8802. AND ($val != 'cached_files')
  8803. AND ($val != 'sign')
  8804. AND ($val != 'signature_data')
  8805. AND ($val != 'signature_max_length')
  8806. AND ($val != 'byterange_string')
  8807. )) {
  8808. if ((!$preserve_objcopy OR ($val != 'objcopy')) AND isset($this->$val)) {
  8809. unset($this->$val);
  8810. }
  8811. }
  8812. }
  8813. }
  8814. /**
  8815. * Check for locale-related bug
  8816. * @protected
  8817. */
  8818. protected function _dochecks() {
  8819. //Check for locale-related bug
  8820. if (1.1 == 1) {
  8821. $this->Error('Don\'t alter the locale before including class file');
  8822. }
  8823. //Check for decimal separator
  8824. if (sprintf('%.1F', 1.0) != '1.0') {
  8825. setlocale(LC_NUMERIC, 'C');
  8826. }
  8827. }
  8828. /**
  8829. * Return fonts path
  8830. * @return string
  8831. * @protected
  8832. */
  8833. protected function _getfontpath() {
  8834. if (!defined('K_PATH_FONTS') AND is_dir(dirname(__FILE__).'/fonts')) {
  8835. define('K_PATH_FONTS', dirname(__FILE__).'/fonts/');
  8836. }
  8837. return defined('K_PATH_FONTS') ? K_PATH_FONTS : '';
  8838. }
  8839. /**
  8840. * Return an array containing variations for the basic page number alias.
  8841. * @param $a (string) Base alias.
  8842. * @return array of page number aliases
  8843. * @protected
  8844. */
  8845. protected function getInternalPageNumberAliases($a= '') {
  8846. $alias = array();
  8847. // build array of Unicode + ASCII variants (the order is important)
  8848. $alias = array('u' => array(), 'a' => array());
  8849. $u = '{'.$a.'}';
  8850. $alias['u'][] = $this->_escape($u);
  8851. if ($this->isunicode) {
  8852. $alias['u'][] = $this->_escape($this->UTF8ToLatin1($u));
  8853. $alias['u'][] = $this->_escape($this->utf8StrRev($u, false, $this->tmprtl));
  8854. $alias['a'][] = $this->_escape($this->UTF8ToLatin1($a));
  8855. $alias['a'][] = $this->_escape($this->utf8StrRev($a, false, $this->tmprtl));
  8856. }
  8857. $alias['a'][] = $this->_escape($a);
  8858. return $alias;
  8859. }
  8860. /**
  8861. * Return an array containing all internal page aliases.
  8862. * @return array of page number aliases
  8863. * @protected
  8864. */
  8865. protected function getAllInternalPageNumberAliases() {
  8866. $basic_alias = array($this->alias_tot_pages, $this->alias_num_page, $this->alias_group_tot_pages, $this->alias_group_num_page, $this->alias_right_shift);
  8867. $pnalias = array();
  8868. foreach($basic_alias as $k => $a) {
  8869. $pnalias[$k] = $this->getInternalPageNumberAliases($a);
  8870. }
  8871. return $pnalias;
  8872. }
  8873. /**
  8874. * Replace page number aliases with number.
  8875. * @param $page (string) Page content.
  8876. * @param $replace (array) Array of replacements (array keys are replacement strings, values are alias arrays).
  8877. * @param $diff (int) If passed, this will be set to the total char number difference between alias and replacements.
  8878. * @return replaced page content and updated $diff parameter as array.
  8879. * @protected
  8880. */
  8881. protected function replacePageNumAliases($page, $replace, $diff=0) {
  8882. foreach ($replace as $rep) {
  8883. foreach ($rep[3] as $a) {
  8884. if (strpos($page, $a) !== false) {
  8885. $page = str_replace($a, $rep[0], $page);
  8886. $diff += ($rep[2] - $rep[1]);
  8887. }
  8888. }
  8889. }
  8890. return array($page, $diff);
  8891. }
  8892. /**
  8893. * Replace right shift page number aliases with spaces to correct right alignment.
  8894. * This works perfectly only when using monospaced fonts.
  8895. * @param $page (string) Page content.
  8896. * @param $aliases (array) Array of page aliases.
  8897. * @param $diff (int) initial difference to add.
  8898. * @return replaced page content.
  8899. * @protected
  8900. */
  8901. protected function replaceRightShiftPageNumAliases($page, $aliases, $diff) {
  8902. foreach ($aliases as $type => $alias) {
  8903. foreach ($alias as $a) {
  8904. // find position of compensation factor
  8905. $startnum = (strpos($a, ':') + 1);
  8906. $a = substr($a, 0, $startnum);
  8907. if (($pos = strpos($page, $a)) !== false) {
  8908. // end of alias
  8909. $endnum = strpos($page, '}', $pos);
  8910. // string to be replaced
  8911. $aa = substr($page, $pos, ($endnum - $pos + 1));
  8912. // get compensation factor
  8913. $ratio = substr($page, ($pos + $startnum), ($endnum - $pos - $startnum));
  8914. $ratio = preg_replace('/[^0-9\.]/', '', $ratio);
  8915. $ratio = floatval($ratio);
  8916. if ($type == 'u') {
  8917. $chrdiff = floor(($diff + 12) * $ratio);
  8918. $shift = str_repeat(' ', $chrdiff);
  8919. $shift = $this->UTF8ToUTF16BE($shift, false);
  8920. } else {
  8921. $chrdiff = floor(($diff + 11) * $ratio);
  8922. $shift = str_repeat(' ', $chrdiff);
  8923. }
  8924. $page = str_replace($aa, $shift, $page);
  8925. }
  8926. }
  8927. }
  8928. return $page;
  8929. }
  8930. /**
  8931. * Set page boxes to be included on page descriptions.
  8932. * @param $boxes (array) Array of page boxes to set on document: ('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox').
  8933. * @protected
  8934. */
  8935. protected function setPageBoxTypes($boxes) {
  8936. $validboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  8937. $this->page_boxes = array();
  8938. foreach ($boxes as $box) {
  8939. if (in_array($box, $validboxes)) {
  8940. $this->page_boxes[] = $box;
  8941. }
  8942. }
  8943. }
  8944. /**
  8945. * Output pages (and replace page number aliases).
  8946. * @protected
  8947. */
  8948. protected function _putpages() {
  8949. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  8950. // get internal aliases for page numbers
  8951. $pnalias = $this->getAllInternalPageNumberAliases();
  8952. $num_pages = $this->numpages;
  8953. $ptpa = $this->formatPageNumber(($this->starting_page_number + $num_pages - 1));
  8954. $ptpu = $this->UTF8ToUTF16BE($ptpa, false);
  8955. $ptp_num_chars = $this->GetNumChars($ptpa);
  8956. $pagegroupnum = 0;
  8957. $groupnum = 0;
  8958. $ptgu = 1;
  8959. $ptga = 1;
  8960. for ($n = 1; $n <= $num_pages; ++$n) {
  8961. // get current page
  8962. $temppage = $this->getPageBuffer($n);
  8963. $pagelen = strlen($temppage);
  8964. // set replacements for total pages number
  8965. $pnpa = $this->formatPageNumber(($this->starting_page_number + $n - 1));
  8966. $pnpu = $this->UTF8ToUTF16BE($pnpa, false);
  8967. $pnp_num_chars = $this->GetNumChars($pnpa);
  8968. $pdiff = 0; // difference used for right shift alignment of page numbers
  8969. $gdiff = 0; // difference used for right shift alignment of page group numbers
  8970. if (!empty($this->pagegroups)) {
  8971. if (isset($this->newpagegroup[$n])) {
  8972. $pagegroupnum = 0;
  8973. ++$groupnum;
  8974. $ptga = $this->formatPageNumber($this->pagegroups[$groupnum]);
  8975. $ptgu = $this->UTF8ToUTF16BE($ptga, false);
  8976. $ptg_num_chars = $this->GetNumChars($ptga);
  8977. }
  8978. ++$pagegroupnum;
  8979. $pnga = $this->formatPageNumber($pagegroupnum);
  8980. $pngu = $this->UTF8ToUTF16BE($pnga, false);
  8981. $png_num_chars = $this->GetNumChars($pnga);
  8982. // replace page numbers
  8983. $replace = array();
  8984. $replace[] = array($ptgu, $ptg_num_chars, 9, $pnalias[2]['u']);
  8985. $replace[] = array($ptga, $ptg_num_chars, 7, $pnalias[2]['a']);
  8986. $replace[] = array($pngu, $png_num_chars, 9, $pnalias[3]['u']);
  8987. $replace[] = array($pnga, $png_num_chars, 7, $pnalias[3]['a']);
  8988. list($temppage, $gdiff) = $this->replacePageNumAliases($temppage, $replace, $gdiff);
  8989. }
  8990. // replace page numbers
  8991. $replace = array();
  8992. $replace[] = array($ptpu, $ptp_num_chars, 9, $pnalias[0]['u']);
  8993. $replace[] = array($ptpa, $ptp_num_chars, 7, $pnalias[0]['a']);
  8994. $replace[] = array($pnpu, $pnp_num_chars, 9, $pnalias[1]['u']);
  8995. $replace[] = array($pnpa, $pnp_num_chars, 7, $pnalias[1]['a']);
  8996. list($temppage, $pdiff) = $this->replacePageNumAliases($temppage, $replace, $pdiff);
  8997. // replace right shift alias
  8998. $temppage = $this->replaceRightShiftPageNumAliases($temppage, $pnalias[4], max($pdiff, $gdiff));
  8999. // replace EPS marker
  9000. $temppage = str_replace($this->epsmarker, '', $temppage);
  9001. //Page
  9002. $this->page_obj_id[$n] = $this->_newobj();
  9003. $out = '<<';
  9004. $out .= ' /Type /Page';
  9005. $out .= ' /Parent 1 0 R';
  9006. $out .= ' /LastModified '.$this->_datestring(0, $this->doc_modification_timestamp);
  9007. $out .= ' /Resources 2 0 R';
  9008. foreach ($this->page_boxes as $box) {
  9009. $out .= ' /'.$box;
  9010. $out .= sprintf(' [%F %F %F %F]', $this->pagedim[$n][$box]['llx'], $this->pagedim[$n][$box]['lly'], $this->pagedim[$n][$box]['urx'], $this->pagedim[$n][$box]['ury']);
  9011. }
  9012. if (isset($this->pagedim[$n]['BoxColorInfo']) AND !empty($this->pagedim[$n]['BoxColorInfo'])) {
  9013. $out .= ' /BoxColorInfo <<';
  9014. foreach ($this->page_boxes as $box) {
  9015. if (isset($this->pagedim[$n]['BoxColorInfo'][$box])) {
  9016. $out .= ' /'.$box.' <<';
  9017. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['C'])) {
  9018. $color = $this->pagedim[$n]['BoxColorInfo'][$box]['C'];
  9019. $out .= ' /C [';
  9020. $out .= sprintf(' %F %F %F', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
  9021. $out .= ' ]';
  9022. }
  9023. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['W'])) {
  9024. $out .= ' /W '.($this->pagedim[$n]['BoxColorInfo'][$box]['W'] * $this->k);
  9025. }
  9026. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['S'])) {
  9027. $out .= ' /S /'.$this->pagedim[$n]['BoxColorInfo'][$box]['S'];
  9028. }
  9029. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['D'])) {
  9030. $dashes = $this->pagedim[$n]['BoxColorInfo'][$box]['D'];
  9031. $out .= ' /D [';
  9032. foreach ($dashes as $dash) {
  9033. $out .= sprintf(' %F', ($dash * $this->k));
  9034. }
  9035. $out .= ' ]';
  9036. }
  9037. $out .= ' >>';
  9038. }
  9039. }
  9040. $out .= ' >>';
  9041. }
  9042. $out .= ' /Contents '.($this->n + 1).' 0 R';
  9043. $out .= ' /Rotate '.$this->pagedim[$n]['Rotate'];
  9044. if (!$this->pdfa_mode) {
  9045. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceRGB >>';
  9046. }
  9047. if (isset($this->pagedim[$n]['trans']) AND !empty($this->pagedim[$n]['trans'])) {
  9048. // page transitions
  9049. if (isset($this->pagedim[$n]['trans']['Dur'])) {
  9050. $out .= ' /Dur '.$this->pagedim[$n]['trans']['Dur'];
  9051. }
  9052. $out .= ' /Trans <<';
  9053. $out .= ' /Type /Trans';
  9054. if (isset($this->pagedim[$n]['trans']['S'])) {
  9055. $out .= ' /S /'.$this->pagedim[$n]['trans']['S'];
  9056. }
  9057. if (isset($this->pagedim[$n]['trans']['D'])) {
  9058. $out .= ' /D '.$this->pagedim[$n]['trans']['D'];
  9059. }
  9060. if (isset($this->pagedim[$n]['trans']['Dm'])) {
  9061. $out .= ' /Dm /'.$this->pagedim[$n]['trans']['Dm'];
  9062. }
  9063. if (isset($this->pagedim[$n]['trans']['M'])) {
  9064. $out .= ' /M /'.$this->pagedim[$n]['trans']['M'];
  9065. }
  9066. if (isset($this->pagedim[$n]['trans']['Di'])) {
  9067. $out .= ' /Di '.$this->pagedim[$n]['trans']['Di'];
  9068. }
  9069. if (isset($this->pagedim[$n]['trans']['SS'])) {
  9070. $out .= ' /SS '.$this->pagedim[$n]['trans']['SS'];
  9071. }
  9072. if (isset($this->pagedim[$n]['trans']['B'])) {
  9073. $out .= ' /B '.$this->pagedim[$n]['trans']['B'];
  9074. }
  9075. $out .= ' >>';
  9076. }
  9077. $out .= $this->_getannotsrefs($n);
  9078. $out .= ' /PZ '.$this->pagedim[$n]['PZ'];
  9079. $out .= ' >>';
  9080. $out .= "\n".'endobj';
  9081. $this->_out($out);
  9082. //Page content
  9083. $p = ($this->compress) ? gzcompress($temppage) : $temppage;
  9084. $this->_newobj();
  9085. $p = $this->_getrawstream($p);
  9086. $this->_out('<<'.$filter.'/Length '.strlen($p).'>> stream'."\n".$p."\n".'endstream'."\n".'endobj');
  9087. if ($this->diskcache) {
  9088. // remove temporary files
  9089. unlink($this->pages[$n]);
  9090. }
  9091. }
  9092. //Pages root
  9093. $out = $this->_getobj(1)."\n";
  9094. $out .= '<< /Type /Pages /Kids [';
  9095. foreach($this->page_obj_id as $page_obj) {
  9096. $out .= ' '.$page_obj.' 0 R';
  9097. }
  9098. $out .= ' ] /Count '.$num_pages.' >>';
  9099. $out .= "\n".'endobj';
  9100. $this->_out($out);
  9101. }
  9102. /**
  9103. * Output references to page annotations
  9104. * @param $n (int) page number
  9105. * @protected
  9106. * @author Nicola Asuni
  9107. * @since 4.7.000 (2008-08-29)
  9108. * @deprecated
  9109. */
  9110. protected function _putannotsrefs($n) {
  9111. $this->_out($this->_getannotsrefs($n));
  9112. }
  9113. /**
  9114. * Get references to page annotations.
  9115. * @param $n (int) page number
  9116. * @return string
  9117. * @protected
  9118. * @author Nicola Asuni
  9119. * @since 5.0.010 (2010-05-17)
  9120. */
  9121. protected function _getannotsrefs($n) {
  9122. if (!(isset($this->PageAnnots[$n]) OR ($this->sign AND isset($this->signature_data['cert_type'])))) {
  9123. return '';
  9124. }
  9125. $out = ' /Annots [';
  9126. if (isset($this->PageAnnots[$n])) {
  9127. foreach ($this->PageAnnots[$n] as $key => $val) {
  9128. if (!in_array($val['n'], $this->radio_groups)) {
  9129. $out .= ' '.$val['n'].' 0 R';
  9130. }
  9131. }
  9132. // add radiobutton groups
  9133. if (isset($this->radiobutton_groups[$n])) {
  9134. foreach ($this->radiobutton_groups[$n] as $key => $data) {
  9135. if (isset($data['n'])) {
  9136. $out .= ' '.$data['n'].' 0 R';
  9137. }
  9138. }
  9139. }
  9140. }
  9141. if ($this->sign AND ($n == $this->signature_appearance['page']) AND isset($this->signature_data['cert_type'])) {
  9142. // set reference for signature object
  9143. $out .= ' '.$this->sig_obj_id.' 0 R';
  9144. }
  9145. if (!empty($this->empty_signature_appearance)) {
  9146. foreach ($this->empty_signature_appearance as $esa) {
  9147. if ($esa['page'] == $n) {
  9148. // set reference for empty signature objects
  9149. $out .= ' '.$esa['objid'].' 0 R';
  9150. }
  9151. }
  9152. }
  9153. $out .= ' ]';
  9154. return $out;
  9155. }
  9156. /**
  9157. * Output annotations objects for all pages.
  9158. * !!! THIS METHOD IS NOT YET COMPLETED !!!
  9159. * See section 12.5 of PDF 32000_2008 reference.
  9160. * @protected
  9161. * @author Nicola Asuni
  9162. * @since 4.0.018 (2008-08-06)
  9163. */
  9164. protected function _putannotsobjs() {
  9165. // reset object counter
  9166. for ($n=1; $n <= $this->numpages; ++$n) {
  9167. if (isset($this->PageAnnots[$n])) {
  9168. // set page annotations
  9169. foreach ($this->PageAnnots[$n] as $key => $pl) {
  9170. $annot_obj_id = $this->PageAnnots[$n][$key]['n'];
  9171. // create annotation object for grouping radiobuttons
  9172. if (isset($this->radiobutton_groups[$n][$pl['txt']]) AND is_array($this->radiobutton_groups[$n][$pl['txt']])) {
  9173. $radio_button_obj_id = $this->radiobutton_groups[$n][$pl['txt']]['n'];
  9174. $annots = '<<';
  9175. $annots .= ' /Type /Annot';
  9176. $annots .= ' /Subtype /Widget';
  9177. $annots .= ' /Rect [0 0 0 0]';
  9178. if ($this->radiobutton_groups[$n][$pl['txt']]['#readonly#']) {
  9179. // read only
  9180. $annots .= ' /F 68';
  9181. $annots .= ' /Ff 49153';
  9182. } else {
  9183. $annots .= ' /F 4'; // default print for PDF/A
  9184. $annots .= ' /Ff 49152';
  9185. }
  9186. $annots .= ' /T '.$this->_datastring($pl['txt'], $radio_button_obj_id);
  9187. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  9188. $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $radio_button_obj_id);
  9189. }
  9190. $annots .= ' /FT /Btn';
  9191. $annots .= ' /Kids [';
  9192. $defval = '';
  9193. foreach ($this->radiobutton_groups[$n][$pl['txt']] as $key => $data) {
  9194. if (isset($data['kid'])) {
  9195. $annots .= ' '.$data['kid'].' 0 R';
  9196. if ($data['def'] !== 'Off') {
  9197. $defval = $data['def'];
  9198. }
  9199. }
  9200. }
  9201. $annots .= ' ]';
  9202. if (!empty($defval)) {
  9203. $annots .= ' /V /'.$defval;
  9204. }
  9205. $annots .= ' >>';
  9206. $this->_out($this->_getobj($radio_button_obj_id)."\n".$annots."\n".'endobj');
  9207. $this->form_obj_id[] = $radio_button_obj_id;
  9208. // store object id to be used on Parent entry of Kids
  9209. $this->radiobutton_groups[$n][$pl['txt']] = $radio_button_obj_id;
  9210. }
  9211. $formfield = false;
  9212. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  9213. $a = $pl['x'] * $this->k;
  9214. $b = $this->pagedim[$n]['h'] - (($pl['y'] + $pl['h']) * $this->k);
  9215. $c = $pl['w'] * $this->k;
  9216. $d = $pl['h'] * $this->k;
  9217. $rect = sprintf('%F %F %F %F', $a, $b, $a+$c, $b+$d);
  9218. // create new annotation object
  9219. $annots = '<</Type /Annot';
  9220. $annots .= ' /Subtype /'.$pl['opt']['subtype'];
  9221. $annots .= ' /Rect ['.$rect.']';
  9222. $ft = array('Btn', 'Tx', 'Ch', 'Sig');
  9223. if (isset($pl['opt']['ft']) AND in_array($pl['opt']['ft'], $ft)) {
  9224. $annots .= ' /FT /'.$pl['opt']['ft'];
  9225. $formfield = true;
  9226. }
  9227. $annots .= ' /Contents '.$this->_textstring($pl['txt'], $annot_obj_id);
  9228. $annots .= ' /P '.$this->page_obj_id[$n].' 0 R';
  9229. $annots .= ' /NM '.$this->_datastring(sprintf('%04u-%04u', $n, $key), $annot_obj_id);
  9230. $annots .= ' /M '.$this->_datestring($annot_obj_id, $this->doc_modification_timestamp);
  9231. if (isset($pl['opt']['f'])) {
  9232. $fval = 0;
  9233. if (is_array($pl['opt']['f'])) {
  9234. foreach ($pl['opt']['f'] as $f) {
  9235. switch (strtolower($f)) {
  9236. case 'invisible': {
  9237. $fval += 1 << 0;
  9238. break;
  9239. }
  9240. case 'hidden': {
  9241. $fval += 1 << 1;
  9242. break;
  9243. }
  9244. case 'print': {
  9245. $fval += 1 << 2;
  9246. break;
  9247. }
  9248. case 'nozoom': {
  9249. $fval += 1 << 3;
  9250. break;
  9251. }
  9252. case 'norotate': {
  9253. $fval += 1 << 4;
  9254. break;
  9255. }
  9256. case 'noview': {
  9257. $fval += 1 << 5;
  9258. break;
  9259. }
  9260. case 'readonly': {
  9261. $fval += 1 << 6;
  9262. break;
  9263. }
  9264. case 'locked': {
  9265. $fval += 1 << 8;
  9266. break;
  9267. }
  9268. case 'togglenoview': {
  9269. $fval += 1 << 9;
  9270. break;
  9271. }
  9272. case 'lockedcontents': {
  9273. $fval += 1 << 10;
  9274. break;
  9275. }
  9276. default: {
  9277. break;
  9278. }
  9279. }
  9280. }
  9281. } else {
  9282. $fval = intval($pl['opt']['f']);
  9283. }
  9284. } else {
  9285. $fval = 4;
  9286. }
  9287. if ($this->pdfa_mode) {
  9288. // force print flag for PDF/A mode
  9289. $fval |= 4;
  9290. }
  9291. $annots .= ' /F '.intval($fval);
  9292. if (isset($pl['opt']['as']) AND is_string($pl['opt']['as'])) {
  9293. $annots .= ' /AS /'.$pl['opt']['as'];
  9294. }
  9295. if (isset($pl['opt']['ap'])) {
  9296. // appearance stream
  9297. $annots .= ' /AP <<';
  9298. if (is_array($pl['opt']['ap'])) {
  9299. foreach ($pl['opt']['ap'] as $apmode => $apdef) {
  9300. // $apmode can be: n = normal; r = rollover; d = down;
  9301. $annots .= ' /'.strtoupper($apmode);
  9302. if (is_array($apdef)) {
  9303. $annots .= ' <<';
  9304. foreach ($apdef as $apstate => $stream) {
  9305. // reference to XObject that define the appearance for this mode-state
  9306. $apsobjid = $this->_putAPXObject($c, $d, $stream);
  9307. $annots .= ' /'.$apstate.' '.$apsobjid.' 0 R';
  9308. }
  9309. $annots .= ' >>';
  9310. } else {
  9311. // reference to XObject that define the appearance for this mode
  9312. $apsobjid = $this->_putAPXObject($c, $d, $apdef);
  9313. $annots .= ' '.$apsobjid.' 0 R';
  9314. }
  9315. }
  9316. } else {
  9317. $annots .= $pl['opt']['ap'];
  9318. }
  9319. $annots .= ' >>';
  9320. }
  9321. if (isset($pl['opt']['bs']) AND (is_array($pl['opt']['bs']))) {
  9322. $annots .= ' /BS <<';
  9323. $annots .= ' /Type /Border';
  9324. if (isset($pl['opt']['bs']['w'])) {
  9325. $annots .= ' /W '.intval($pl['opt']['bs']['w']);
  9326. }
  9327. $bstyles = array('S', 'D', 'B', 'I', 'U');
  9328. if (isset($pl['opt']['bs']['s']) AND in_array($pl['opt']['bs']['s'], $bstyles)) {
  9329. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  9330. }
  9331. if (isset($pl['opt']['bs']['d']) AND (is_array($pl['opt']['bs']['d']))) {
  9332. $annots .= ' /D [';
  9333. foreach ($pl['opt']['bs']['d'] as $cord) {
  9334. $annots .= ' '.intval($cord);
  9335. }
  9336. $annots .= ']';
  9337. }
  9338. $annots .= ' >>';
  9339. } else {
  9340. $annots .= ' /Border [';
  9341. if (isset($pl['opt']['border']) AND (count($pl['opt']['border']) >= 3)) {
  9342. $annots .= intval($pl['opt']['border'][0]).' ';
  9343. $annots .= intval($pl['opt']['border'][1]).' ';
  9344. $annots .= intval($pl['opt']['border'][2]);
  9345. if (isset($pl['opt']['border'][3]) AND is_array($pl['opt']['border'][3])) {
  9346. $annots .= ' [';
  9347. foreach ($pl['opt']['border'][3] as $dash) {
  9348. $annots .= intval($dash).' ';
  9349. }
  9350. $annots .= ']';
  9351. }
  9352. } else {
  9353. $annots .= '0 0 0';
  9354. }
  9355. $annots .= ']';
  9356. }
  9357. if (isset($pl['opt']['be']) AND (is_array($pl['opt']['be']))) {
  9358. $annots .= ' /BE <<';
  9359. $bstyles = array('S', 'C');
  9360. if (isset($pl['opt']['be']['s']) AND in_array($pl['opt']['be']['s'], $bstyles)) {
  9361. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  9362. } else {
  9363. $annots .= ' /S /S';
  9364. }
  9365. if (isset($pl['opt']['be']['i']) AND ($pl['opt']['be']['i'] >= 0) AND ($pl['opt']['be']['i'] <= 2)) {
  9366. $annots .= ' /I '.sprintf(' %F', $pl['opt']['be']['i']);
  9367. }
  9368. $annots .= '>>';
  9369. }
  9370. if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) {
  9371. $annots .= ' /C '.$this->getColorStringFromArray($pl['opt']['c']);
  9372. }
  9373. //$annots .= ' /StructParent ';
  9374. //$annots .= ' /OC ';
  9375. $markups = array('text', 'freetext', 'line', 'square', 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp', 'caret', 'ink', 'fileattachment', 'sound');
  9376. if (in_array(strtolower($pl['opt']['subtype']), $markups)) {
  9377. // this is a markup type
  9378. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  9379. $annots .= ' /T '.$this->_textstring($pl['opt']['t'], $annot_obj_id);
  9380. }
  9381. //$annots .= ' /Popup ';
  9382. if (isset($pl['opt']['ca'])) {
  9383. $annots .= ' /CA '.sprintf('%F', floatval($pl['opt']['ca']));
  9384. }
  9385. if (isset($pl['opt']['rc'])) {
  9386. $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  9387. }
  9388. $annots .= ' /CreationDate '.$this->_datestring($annot_obj_id, $this->doc_creation_timestamp);
  9389. //$annots .= ' /IRT ';
  9390. if (isset($pl['opt']['subj'])) {
  9391. $annots .= ' /Subj '.$this->_textstring($pl['opt']['subj'], $annot_obj_id);
  9392. }
  9393. //$annots .= ' /RT ';
  9394. //$annots .= ' /IT ';
  9395. //$annots .= ' /ExData ';
  9396. }
  9397. $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt', 'ROpenArrow', 'RClosedArrow', 'Slash');
  9398. // Annotation types
  9399. switch (strtolower($pl['opt']['subtype'])) {
  9400. case 'text': {
  9401. if (isset($pl['opt']['open'])) {
  9402. $annots .= ' /Open '. (strtolower($pl['opt']['open']) == 'true' ? 'true' : 'false');
  9403. }
  9404. $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph');
  9405. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  9406. $annots .= ' /Name /'.$pl['opt']['name'];
  9407. } else {
  9408. $annots .= ' /Name /Note';
  9409. }
  9410. $statemodels = array('Marked', 'Review');
  9411. if (isset($pl['opt']['statemodel']) AND in_array($pl['opt']['statemodel'], $statemodels)) {
  9412. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  9413. } else {
  9414. $pl['opt']['statemodel'] = 'Marked';
  9415. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  9416. }
  9417. if ($pl['opt']['statemodel'] == 'Marked') {
  9418. $states = array('Accepted', 'Unmarked');
  9419. } else {
  9420. $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None');
  9421. }
  9422. if (isset($pl['opt']['state']) AND in_array($pl['opt']['state'], $states)) {
  9423. $annots .= ' /State /'.$pl['opt']['state'];
  9424. } else {
  9425. if ($pl['opt']['statemodel'] == 'Marked') {
  9426. $annots .= ' /State /Unmarked';
  9427. } else {
  9428. $annots .= ' /State /None';
  9429. }
  9430. }
  9431. break;
  9432. }
  9433. case 'link': {
  9434. if (is_string($pl['txt'])) {
  9435. if ($pl['txt'][0] == '#') {
  9436. // internal destination
  9437. $annots .= ' /Dest /'.$this->encodeNameObject(substr($pl['txt'], 1));
  9438. } elseif ($pl['txt'][0] == '%') {
  9439. // embedded PDF file
  9440. $filename = basename(substr($pl['txt'], 1));
  9441. $annots .= ' /A << /S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($n - 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>';
  9442. } elseif ($pl['txt'][0] == '*') {
  9443. // embedded generic file
  9444. $filename = basename(substr($pl['txt'], 1));
  9445. $jsa = 'var D=event.target.doc;var MyData=D.dataObjects;for (var i in MyData) if (MyData[i].path=="'.$filename.'") D.exportDataObject( { cName : MyData[i].name, nLaunch : 2});';
  9446. $annots .= ' /A << /S /JavaScript /JS '.$this->_textstring($jsa, $annot_obj_id).'>>';
  9447. } else {
  9448. // external URI link
  9449. $annots .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>';
  9450. }
  9451. } elseif (isset($this->links[$pl['txt']])) {
  9452. // internal link ID
  9453. $l = $this->links[$pl['txt']];
  9454. if (isset($this->page_obj_id[($l[0])])) {
  9455. $annots .= sprintf(' /Dest [%u 0 R /XYZ 0 %F null]', $this->page_obj_id[($l[0])], ($this->pagedim[$l[0]]['h'] - ($l[1] * $this->k)));
  9456. }
  9457. }
  9458. $hmodes = array('N', 'I', 'O', 'P');
  9459. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmodes)) {
  9460. $annots .= ' /H /'.$pl['opt']['h'];
  9461. } else {
  9462. $annots .= ' /H /I';
  9463. }
  9464. //$annots .= ' /PA ';
  9465. //$annots .= ' /Quadpoints ';
  9466. break;
  9467. }
  9468. case 'freetext': {
  9469. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  9470. $annots .= ' /DA ('.$pl['opt']['da'].')';
  9471. }
  9472. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  9473. $annots .= ' /Q '.intval($pl['opt']['q']);
  9474. }
  9475. if (isset($pl['opt']['rc'])) {
  9476. $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  9477. }
  9478. if (isset($pl['opt']['ds'])) {
  9479. $annots .= ' /DS '.$this->_textstring($pl['opt']['ds'], $annot_obj_id);
  9480. }
  9481. if (isset($pl['opt']['cl']) AND is_array($pl['opt']['cl'])) {
  9482. $annots .= ' /CL [';
  9483. foreach ($pl['opt']['cl'] as $cl) {
  9484. $annots .= sprintf('%F ', $cl * $this->k);
  9485. }
  9486. $annots .= ']';
  9487. }
  9488. $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter');
  9489. if (isset($pl['opt']['it']) AND in_array($pl['opt']['it'], $tfit)) {
  9490. $annots .= ' /IT /'.$pl['opt']['it'];
  9491. }
  9492. if (isset($pl['opt']['rd']) AND is_array($pl['opt']['rd'])) {
  9493. $l = $pl['opt']['rd'][0] * $this->k;
  9494. $r = $pl['opt']['rd'][1] * $this->k;
  9495. $t = $pl['opt']['rd'][2] * $this->k;
  9496. $b = $pl['opt']['rd'][3] * $this->k;
  9497. $annots .= ' /RD ['.sprintf('%F %F %F %F', $l, $r, $t, $b).']';
  9498. }
  9499. if (isset($pl['opt']['le']) AND in_array($pl['opt']['le'], $lineendings)) {
  9500. $annots .= ' /LE /'.$pl['opt']['le'];
  9501. }
  9502. break;
  9503. }
  9504. case 'line': {
  9505. break;
  9506. }
  9507. case 'square': {
  9508. break;
  9509. }
  9510. case 'circle': {
  9511. break;
  9512. }
  9513. case 'polygon': {
  9514. break;
  9515. }
  9516. case 'polyline': {
  9517. break;
  9518. }
  9519. case 'highlight': {
  9520. break;
  9521. }
  9522. case 'underline': {
  9523. break;
  9524. }
  9525. case 'squiggly': {
  9526. break;
  9527. }
  9528. case 'strikeout': {
  9529. break;
  9530. }
  9531. case 'stamp': {
  9532. break;
  9533. }
  9534. case 'caret': {
  9535. break;
  9536. }
  9537. case 'ink': {
  9538. break;
  9539. }
  9540. case 'popup': {
  9541. break;
  9542. }
  9543. case 'fileattachment': {
  9544. if ($this->pdfa_mode) {
  9545. // embedded files are not allowed in PDF/A mode
  9546. break;
  9547. }
  9548. if (!isset($pl['opt']['fs'])) {
  9549. break;
  9550. }
  9551. $filename = basename($pl['opt']['fs']);
  9552. if (isset($this->embeddedfiles[$filename]['f'])) {
  9553. $annots .= ' /FS '.$this->embeddedfiles[$filename]['f'].' 0 R';
  9554. $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag');
  9555. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  9556. $annots .= ' /Name /'.$pl['opt']['name'];
  9557. } else {
  9558. $annots .= ' /Name /PushPin';
  9559. }
  9560. // index (zero-based) of the annotation in the Annots array of this page
  9561. $this->embeddedfiles[$filename]['a'] = $key;
  9562. }
  9563. break;
  9564. }
  9565. case 'sound': {
  9566. if (!isset($pl['opt']['fs'])) {
  9567. break;
  9568. }
  9569. $filename = basename($pl['opt']['fs']);
  9570. if (isset($this->embeddedfiles[$filename]['f'])) {
  9571. // ... TO BE COMPLETED ...
  9572. // /R /C /B /E /CO /CP
  9573. $annots .= ' /Sound '.$this->embeddedfiles[$filename]['f'].' 0 R';
  9574. $iconsapp = array('Speaker', 'Mic');
  9575. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  9576. $annots .= ' /Name /'.$pl['opt']['name'];
  9577. } else {
  9578. $annots .= ' /Name /Speaker';
  9579. }
  9580. }
  9581. break;
  9582. }
  9583. case 'movie': {
  9584. break;
  9585. }
  9586. case 'widget': {
  9587. $hmode = array('N', 'I', 'O', 'P', 'T');
  9588. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmode)) {
  9589. $annots .= ' /H /'.$pl['opt']['h'];
  9590. }
  9591. if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) {
  9592. $annots .= ' /MK <<';
  9593. if (isset($pl['opt']['mk']['r'])) {
  9594. $annots .= ' /R '.$pl['opt']['mk']['r'];
  9595. }
  9596. if (isset($pl['opt']['mk']['bc']) AND (is_array($pl['opt']['mk']['bc']))) {
  9597. $annots .= ' /BC '.$this->getColorStringFromArray($pl['opt']['mk']['bc']);
  9598. }
  9599. if (isset($pl['opt']['mk']['bg']) AND (is_array($pl['opt']['mk']['bg']))) {
  9600. $annots .= ' /BG '.$this->getColorStringFromArray($pl['opt']['mk']['bg']);
  9601. }
  9602. if (isset($pl['opt']['mk']['ca'])) {
  9603. $annots .= ' /CA '.$pl['opt']['mk']['ca'];
  9604. }
  9605. if (isset($pl['opt']['mk']['rc'])) {
  9606. $annots .= ' /RC '.$pl['opt']['mk']['rc'];
  9607. }
  9608. if (isset($pl['opt']['mk']['ac'])) {
  9609. $annots .= ' /AC '.$pl['opt']['mk']['ac'];
  9610. }
  9611. if (isset($pl['opt']['mk']['i'])) {
  9612. $info = $this->getImageBuffer($pl['opt']['mk']['i']);
  9613. if ($info !== false) {
  9614. $annots .= ' /I '.$info['n'].' 0 R';
  9615. }
  9616. }
  9617. if (isset($pl['opt']['mk']['ri'])) {
  9618. $info = $this->getImageBuffer($pl['opt']['mk']['ri']);
  9619. if ($info !== false) {
  9620. $annots .= ' /RI '.$info['n'].' 0 R';
  9621. }
  9622. }
  9623. if (isset($pl['opt']['mk']['ix'])) {
  9624. $info = $this->getImageBuffer($pl['opt']['mk']['ix']);
  9625. if ($info !== false) {
  9626. $annots .= ' /IX '.$info['n'].' 0 R';
  9627. }
  9628. }
  9629. if (isset($pl['opt']['mk']['if']) AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) {
  9630. $annots .= ' /IF <<';
  9631. $if_sw = array('A', 'B', 'S', 'N');
  9632. if (isset($pl['opt']['mk']['if']['sw']) AND in_array($pl['opt']['mk']['if']['sw'], $if_sw)) {
  9633. $annots .= ' /SW /'.$pl['opt']['mk']['if']['sw'];
  9634. }
  9635. $if_s = array('A', 'P');
  9636. if (isset($pl['opt']['mk']['if']['s']) AND in_array($pl['opt']['mk']['if']['s'], $if_s)) {
  9637. $annots .= ' /S /'.$pl['opt']['mk']['if']['s'];
  9638. }
  9639. if (isset($pl['opt']['mk']['if']['a']) AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) {
  9640. $annots .= sprintf(' /A [%F %F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]);
  9641. }
  9642. if (isset($pl['opt']['mk']['if']['fb']) AND ($pl['opt']['mk']['if']['fb'])) {
  9643. $annots .= ' /FB true';
  9644. }
  9645. $annots .= '>>';
  9646. }
  9647. if (isset($pl['opt']['mk']['tp']) AND ($pl['opt']['mk']['tp'] >= 0) AND ($pl['opt']['mk']['tp'] <= 6)) {
  9648. $annots .= ' /TP '.intval($pl['opt']['mk']['tp']);
  9649. }
  9650. $annots .= '>>';
  9651. } // end MK
  9652. // --- Entries for field dictionaries ---
  9653. if (isset($this->radiobutton_groups[$n][$pl['txt']])) {
  9654. // set parent
  9655. $annots .= ' /Parent '.$this->radiobutton_groups[$n][$pl['txt']].' 0 R';
  9656. }
  9657. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  9658. $annots .= ' /T '.$this->_datastring($pl['opt']['t'], $annot_obj_id);
  9659. }
  9660. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  9661. $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $annot_obj_id);
  9662. }
  9663. if (isset($pl['opt']['tm']) AND is_string($pl['opt']['tm'])) {
  9664. $annots .= ' /TM '.$this->_datastring($pl['opt']['tm'], $annot_obj_id);
  9665. }
  9666. if (isset($pl['opt']['ff'])) {
  9667. if (is_array($pl['opt']['ff'])) {
  9668. // array of bit settings
  9669. $flag = 0;
  9670. foreach($pl['opt']['ff'] as $val) {
  9671. $flag += 1 << ($val - 1);
  9672. }
  9673. } else {
  9674. $flag = intval($pl['opt']['ff']);
  9675. }
  9676. $annots .= ' /Ff '.$flag;
  9677. }
  9678. if (isset($pl['opt']['maxlen'])) {
  9679. $annots .= ' /MaxLen '.intval($pl['opt']['maxlen']);
  9680. }
  9681. if (isset($pl['opt']['v'])) {
  9682. $annots .= ' /V';
  9683. if (is_array($pl['opt']['v'])) {
  9684. foreach ($pl['opt']['v'] AS $optval) {
  9685. if (is_float($optval)) {
  9686. $optval = sprintf('%F', $optval);
  9687. }
  9688. $annots .= ' '.$optval;
  9689. }
  9690. } else {
  9691. $annots .= ' '.$this->_textstring($pl['opt']['v'], $annot_obj_id);
  9692. }
  9693. }
  9694. if (isset($pl['opt']['dv'])) {
  9695. $annots .= ' /DV';
  9696. if (is_array($pl['opt']['dv'])) {
  9697. foreach ($pl['opt']['dv'] AS $optval) {
  9698. if (is_float($optval)) {
  9699. $optval = sprintf('%F', $optval);
  9700. }
  9701. $annots .= ' '.$optval;
  9702. }
  9703. } else {
  9704. $annots .= ' '.$this->_textstring($pl['opt']['dv'], $annot_obj_id);
  9705. }
  9706. }
  9707. if (isset($pl['opt']['rv'])) {
  9708. $annots .= ' /RV';
  9709. if (is_array($pl['opt']['rv'])) {
  9710. foreach ($pl['opt']['rv'] AS $optval) {
  9711. if (is_float($optval)) {
  9712. $optval = sprintf('%F', $optval);
  9713. }
  9714. $annots .= ' '.$optval;
  9715. }
  9716. } else {
  9717. $annots .= ' '.$this->_textstring($pl['opt']['rv'], $annot_obj_id);
  9718. }
  9719. }
  9720. if (isset($pl['opt']['a']) AND !empty($pl['opt']['a'])) {
  9721. $annots .= ' /A << '.$pl['opt']['a'].' >>';
  9722. }
  9723. if (isset($pl['opt']['aa']) AND !empty($pl['opt']['aa'])) {
  9724. $annots .= ' /AA << '.$pl['opt']['aa'].' >>';
  9725. }
  9726. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  9727. $annots .= ' /DA ('.$pl['opt']['da'].')';
  9728. }
  9729. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  9730. $annots .= ' /Q '.intval($pl['opt']['q']);
  9731. }
  9732. if (isset($pl['opt']['opt']) AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) {
  9733. $annots .= ' /Opt [';
  9734. foreach($pl['opt']['opt'] AS $copt) {
  9735. if (is_array($copt)) {
  9736. $annots .= ' ['.$this->_textstring($copt[0], $annot_obj_id).' '.$this->_textstring($copt[1], $annot_obj_id).']';
  9737. } else {
  9738. $annots .= ' '.$this->_textstring($copt, $annot_obj_id);
  9739. }
  9740. }
  9741. $annots .= ']';
  9742. }
  9743. if (isset($pl['opt']['ti'])) {
  9744. $annots .= ' /TI '.intval($pl['opt']['ti']);
  9745. }
  9746. if (isset($pl['opt']['i']) AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) {
  9747. $annots .= ' /I [';
  9748. foreach($pl['opt']['i'] AS $copt) {
  9749. $annots .= intval($copt).' ';
  9750. }
  9751. $annots .= ']';
  9752. }
  9753. break;
  9754. }
  9755. case 'screen': {
  9756. break;
  9757. }
  9758. case 'printermark': {
  9759. break;
  9760. }
  9761. case 'trapnet': {
  9762. break;
  9763. }
  9764. case 'watermark': {
  9765. break;
  9766. }
  9767. case '3d': {
  9768. break;
  9769. }
  9770. default: {
  9771. break;
  9772. }
  9773. }
  9774. $annots .= '>>';
  9775. // create new annotation object
  9776. $this->_out($this->_getobj($annot_obj_id)."\n".$annots."\n".'endobj');
  9777. if ($formfield AND !isset($this->radiobutton_groups[$n][$pl['txt']])) {
  9778. // store reference of form object
  9779. $this->form_obj_id[] = $annot_obj_id;
  9780. }
  9781. }
  9782. }
  9783. } // end for each page
  9784. }
  9785. /**
  9786. * Put appearance streams XObject used to define annotation's appearance states.
  9787. * @param $w (int) annotation width
  9788. * @param $h (int) annotation height
  9789. * @param $stream (string) appearance stream
  9790. * @return int object ID
  9791. * @protected
  9792. * @since 4.8.001 (2009-09-09)
  9793. */
  9794. protected function _putAPXObject($w=0, $h=0, $stream='') {
  9795. $stream = trim($stream);
  9796. $out = $this->_getobj()."\n";
  9797. $this->xobjects['AX'.$this->n] = array('n' => $this->n);
  9798. $out .= '<<';
  9799. $out .= ' /Type /XObject';
  9800. $out .= ' /Subtype /Form';
  9801. $out .= ' /FormType 1';
  9802. if ($this->compress) {
  9803. $stream = gzcompress($stream);
  9804. $out .= ' /Filter /FlateDecode';
  9805. }
  9806. $rect = sprintf('%F %F', $w, $h);
  9807. $out .= ' /BBox [0 0 '.$rect.']';
  9808. $out .= ' /Matrix [1 0 0 1 0 0]';
  9809. $out .= ' /Resources 2 0 R';
  9810. $stream = $this->_getrawstream($stream);
  9811. $out .= ' /Length '.strlen($stream);
  9812. $out .= ' >>';
  9813. $out .= ' stream'."\n".$stream."\n".'endstream';
  9814. $out .= "\n".'endobj';
  9815. $this->_out($out);
  9816. return $this->n;
  9817. }
  9818. /**
  9819. * Get ULONG from string (Big Endian 32-bit unsigned integer).
  9820. * @param $str (string) string from where to extract value
  9821. * @param $offset (int) point from where to read the data
  9822. * @return int 32 bit value
  9823. * @author Nicola Asuni
  9824. * @protected
  9825. * @since 5.2.000 (2010-06-02)
  9826. */
  9827. protected function _getULONG($str, $offset) {
  9828. $v = unpack('Ni', substr($str, $offset, 4));
  9829. return $v['i'];
  9830. }
  9831. /**
  9832. * Get USHORT from string (Big Endian 16-bit unsigned integer).
  9833. * @param $str (string) string from where to extract value
  9834. * @param $offset (int) point from where to read the data
  9835. * @return int 16 bit value
  9836. * @author Nicola Asuni
  9837. * @protected
  9838. * @since 5.2.000 (2010-06-02)
  9839. */
  9840. protected function _getUSHORT($str, $offset) {
  9841. $v = unpack('ni', substr($str, $offset, 2));
  9842. return $v['i'];
  9843. }
  9844. /**
  9845. * Get SHORT from string (Big Endian 16-bit signed integer).
  9846. * @param $str (string) String from where to extract value.
  9847. * @param $offset (int) Point from where to read the data.
  9848. * @return int 16 bit value
  9849. * @author Nicola Asuni
  9850. * @protected
  9851. * @since 5.2.000 (2010-06-02)
  9852. */
  9853. protected function _getSHORT($str, $offset) {
  9854. $v = unpack('si', substr($str, $offset, 2));
  9855. return $v['i'];
  9856. }
  9857. /**
  9858. * Get FWORD from string (Big Endian 16-bit signed integer).
  9859. * @param $str (string) String from where to extract value.
  9860. * @param $offset (int) Point from where to read the data.
  9861. * @return int 16 bit value
  9862. * @author Nicola Asuni
  9863. * @protected
  9864. * @since 5.9.123 (2011-09-30)
  9865. */
  9866. protected function _getFWORD($str, $offset) {
  9867. $v = $this->_getUSHORT($str, $offset);
  9868. if ($v > 0x7fff) {
  9869. $v -= 0x10000;
  9870. }
  9871. return $v;
  9872. }
  9873. /**
  9874. * Get UFWORD from string (Big Endian 16-bit unsigned integer).
  9875. * @param $str (string) string from where to extract value
  9876. * @param $offset (int) point from where to read the data
  9877. * @return int 16 bit value
  9878. * @author Nicola Asuni
  9879. * @protected
  9880. * @since 5.9.123 (2011-09-30)
  9881. */
  9882. protected function _getUFWORD($str, $offset) {
  9883. $v = $this->_getUSHORT($str, $offset);
  9884. return $v;
  9885. }
  9886. /**
  9887. * Get FIXED from string (32-bit signed fixed-point number (16.16).
  9888. * @param $str (string) string from where to extract value
  9889. * @param $offset (int) point from where to read the data
  9890. * @return int 16 bit value
  9891. * @author Nicola Asuni
  9892. * @protected
  9893. * @since 5.9.123 (2011-09-30)
  9894. */
  9895. protected function _getFIXED($str, $offset) {
  9896. // mantissa
  9897. $m = $this->_getFWORD($str, $offset);
  9898. // fraction
  9899. $f = $this->_getUSHORT($str, ($offset + 2));
  9900. $v = floatval(''.$m.'.'.$f.'');
  9901. return $v;
  9902. }
  9903. /**
  9904. * Get BYTE from string (8-bit unsigned integer).
  9905. * @param $str (string) String from where to extract value.
  9906. * @param $offset (int) Point from where to read the data.
  9907. * @return int 8 bit value
  9908. * @author Nicola Asuni
  9909. * @protected
  9910. * @since 5.2.000 (2010-06-02)
  9911. */
  9912. protected function _getBYTE($str, $offset) {
  9913. $v = unpack('Ci', substr($str, $offset, 1));
  9914. return $v['i'];
  9915. }
  9916. /**
  9917. * Update the CIDToGIDMap string with a new value.
  9918. * @param $map (string) CIDToGIDMap.
  9919. * @param $cid (int) CID value.
  9920. * @param $gid (int) GID value.
  9921. * @return (string) CIDToGIDMap.
  9922. * @author Nicola Asuni
  9923. * @protected
  9924. * @since 5.9.123 (2011-09-29)
  9925. */
  9926. protected function updateCIDtoGIDmap($map, $cid, $gid) {
  9927. if (($cid >= 0) AND ($cid <= 0xFFFF) AND ($gid >= 0)) {
  9928. if ($gid > 0xFFFF) {
  9929. $gid -= 0x10000;
  9930. }
  9931. $map[($cid * 2)] = chr($gid >> 8);
  9932. $map[(($cid * 2) + 1)] = chr($gid & 0xFF);
  9933. }
  9934. return $map;
  9935. }
  9936. /**
  9937. * Convert and add the selected TrueType or Type1 font to the fonts folder (that must be writeable).
  9938. * @param $fontfile (string) Font file (full path).
  9939. * @param $fonttype (string) Font type. Leave empty for autodetect mode. Valid values are: TrueTypeUnicode, TrueType, Type1, CID0JP = CID-0 Japanese, CID0KR = CID-0 Korean, CID0CS = CID-0 Chinese Simplified, CID0CT = CID-0 Chinese Traditional.
  9940. * @param $enc (string) Name of the encoding table to use. Leave empty for default mode. Omit this parameter for TrueType Unicode and symbolic fonts like Symbol or ZapfDingBats.
  9941. * @param $flags (int) Unsigned 32-bit integer containing flags specifying various characteristics of the font (PDF32000:2008 - 9.8.2 Font Descriptor Flags): +1 for fixed font; +4 for symbol or +32 for non-symbol; +64 for italic. Fixed and Italic mode are generally autodetected so you have to set it to 32 = non-symbolic font (default) or 4 = symbolic font.
  9942. * @param $outpath (string) Output path for generated font files (must be writeable by the web server). Leave empty for default font folder.
  9943. * @param $platid (int) Platform ID for CMAP table to extract (when building a Unicode font for Windows this value should be 3, for Macintosh should be 1).
  9944. * @param $encid (int) Encoding ID for CMAP table to extract (when building a Unicode font for Windows this value should be 1, for Macintosh should be 0). When Platform ID is 3, legal values for Encoding ID are: 0=Symbol, 1=Unicode, 2=ShiftJIS, 3=PRC, 4=Big5, 5=Wansung, 6=Johab, 7=Reserved, 8=Reserved, 9=Reserved, 10=UCS-4.
  9945. * @param $addcbbox (boolean) If true includes the character bounding box information on the php font file.
  9946. * @return (string) TCPDF font name.
  9947. * @author Nicola Asuni
  9948. * @public
  9949. * @since 5.9.123 (2010-09-30)
  9950. */
  9951. public function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $outpath='', $platid=3, $encid=1, $addcbbox=false) {
  9952. if (!file_exists($fontfile)) {
  9953. $this->Error('Could not find file: '.$fontfile.'');
  9954. }
  9955. // font metrics
  9956. $fmetric = array();
  9957. // build new font name for TCPDF compatibility
  9958. $font_path_parts = pathinfo($fontfile);
  9959. if (!isset($font_path_parts['filename'])) {
  9960. $font_path_parts['filename'] = substr($font_path_parts['basename'], 0, -(strlen($font_path_parts['extension']) + 1));
  9961. }
  9962. $font_name = strtolower($font_path_parts['filename']);
  9963. $font_name = preg_replace('/[^a-z0-9_]/', '', $font_name);
  9964. $search = array('bold', 'oblique', 'italic', 'regular');
  9965. $replace = array('b', 'i', 'i', '');
  9966. $font_name = str_replace($search, $replace, $font_name);
  9967. if (empty($font_name)) {
  9968. // set generic name
  9969. $font_name = 'tcpdffont';
  9970. }
  9971. // set output path
  9972. if (empty($outpath)) {
  9973. $outpath = $this->_getfontpath();
  9974. }
  9975. // check if this font already exist
  9976. if (file_exists($outpath.$font_name.'.php')) {
  9977. // this font already exist (delete it from fonts folder to rebuild it)
  9978. return $font_name;
  9979. }
  9980. $fmetric['file'] = $font_name.'.z';
  9981. $fmetric['ctg'] = $font_name.'.ctg.z';
  9982. // get font data
  9983. $font = file_get_contents($fontfile);
  9984. $fmetric['originalsize'] = strlen($font);
  9985. // autodetect font type
  9986. if (empty($fonttype)) {
  9987. if ($this->_getULONG($font, 0) == 0x10000) {
  9988. // True Type (Unicode or not)
  9989. $fonttype = 'TrueTypeUnicode';
  9990. } elseif (substr($font, 0, 4) == 'OTTO') {
  9991. // Open Type (Unicode or not)
  9992. $this->Error('Unsupported font format: OpenType with CFF data.');
  9993. } else {
  9994. // Type 1
  9995. $fonttype = 'Type1';
  9996. }
  9997. }
  9998. // set font type
  9999. switch ($fonttype) {
  10000. case 'CID0CT':
  10001. case 'CID0CS':
  10002. case 'CID0KR':
  10003. case 'CID0JP': {
  10004. $fmetric['type'] = 'cidfont0';
  10005. break;
  10006. }
  10007. case 'Type1': {
  10008. $fmetric['type'] = 'Type1';
  10009. if (empty($enc) AND (($flags & 4) == 0)) {
  10010. $enc = 'cp1252';
  10011. }
  10012. break;
  10013. }
  10014. case 'TrueType': {
  10015. $fmetric['type'] = 'TrueType';
  10016. break;
  10017. }
  10018. case 'TrueTypeUnicode':
  10019. default: {
  10020. $fmetric['type'] = 'TrueTypeUnicode';
  10021. break;
  10022. }
  10023. }
  10024. // set encoding maps (if any)
  10025. $fmetric['enc'] = preg_replace('/[^A-Za-z0-9_\-]/', '', $enc);
  10026. $fmetric['diff'] = '';
  10027. if (($fmetric['type'] == 'TrueType') OR ($fmetric['type'] == 'Type1')) {
  10028. if (!empty($enc) AND ($enc != 'cp1252') AND isset($this->encmaps->encmap[$enc])) {
  10029. // build differences from reference encoding
  10030. $enc_ref = $this->encmaps->encmap['cp1252'];
  10031. $enc_target = $this->encmaps->encmap[$enc];
  10032. $last = 0;
  10033. for ($i = 32; $i <= 255; ++$i) {
  10034. if ($enc_target != $enc_ref[$i]) {
  10035. if ($i != ($last + 1)) {
  10036. $fmetric['diff'] .= $i.' ';
  10037. }
  10038. $last = $i;
  10039. $fmetric['diff'] .= '/'.$enc_target[$i].' ';
  10040. }
  10041. }
  10042. }
  10043. }
  10044. // parse the font by type
  10045. if ($fmetric['type'] == 'Type1') {
  10046. // ---------- TYPE 1 ----------
  10047. // read first segment
  10048. $a = unpack('Cmarker/Ctype/Vsize', substr($font, 0, 6));
  10049. if ($a['marker'] != 128) {
  10050. $this->Error('Font file is not a valid binary Type1');
  10051. }
  10052. $fmetric['size1'] = $a['size'];
  10053. $data = substr($font, 6, $fmetric['size1']);
  10054. // read second segment
  10055. $a = unpack('Cmarker/Ctype/Vsize', substr($font, (6 + $fmetric['size1']), 6));
  10056. if ($a['marker'] != 128) {
  10057. $this->Error('Font file is not a valid binary Type1');
  10058. }
  10059. $fmetric['size2'] = $a['size'];
  10060. $encrypted = substr($font, (12 + $fmetric['size1']), $fmetric['size2']);
  10061. $data .= $encrypted;
  10062. // store compressed font
  10063. $fp = fopen($outpath.$fmetric['file'], 'wb');
  10064. fwrite($fp, gzcompress($data));
  10065. fclose($fp);
  10066. // get font info
  10067. $fmetric['Flags'] = $flags;
  10068. preg_match ('#/FullName[\s]*\(([^\)]*)#', $font, $matches);
  10069. $fmetric['name'] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $matches[1]);
  10070. preg_match('#/FontBBox[\s]*{([^}]*)#', $font, $matches);
  10071. $fmetric['bbox'] = trim($matches[1]);
  10072. $bv = explode(' ', $fmetric['bbox']);
  10073. $fmetric['Ascent'] = intval($bv[3]);
  10074. $fmetric['Descent'] = intval($bv[1]);
  10075. preg_match('#/ItalicAngle[\s]*([0-9\+\-]*)#', $font, $matches);
  10076. $fmetric['italicAngle'] = intval($matches[1]);
  10077. if ($fmetric['italicAngle'] != 0) {
  10078. $fmetric['Flags'] |= 64;
  10079. }
  10080. preg_match('#/UnderlinePosition[\s]*([0-9\+\-]*)#', $font, $matches);
  10081. $fmetric['underlinePosition'] = intval($matches[1]);
  10082. preg_match('#/UnderlineThickness[\s]*([0-9\+\-]*)#', $font, $matches);
  10083. $fmetric['underlineThickness'] = intval($matches[1]);
  10084. preg_match('#/isFixedPitch[\s]*([^\s]*)#', $font, $matches);
  10085. if ($matches[1] == 'true') {
  10086. $fmetric['Flags'] |= 1;
  10087. }
  10088. // get internal map
  10089. $imap = array();
  10090. if (preg_match_all('#dup[\s]([0-9]+)[\s]*/([^\s]*)[\s]put#sU', $font, $fmap, PREG_SET_ORDER) > 0) {
  10091. foreach ($fmap as $v) {
  10092. $imap[$v[2]] = $v[1];
  10093. }
  10094. }
  10095. // decrypt eexec encrypted part
  10096. $r = 55665; // eexec encryption constant
  10097. $c1 = 52845;
  10098. $c2 = 22719;
  10099. $elen = strlen($encrypted);
  10100. $eplain = '';
  10101. for ($i = 0; $i < $elen; ++$i) {
  10102. $chr = ord($encrypted[$i]);
  10103. $eplain .= chr($chr ^ ($r >> 8));
  10104. $r = ((($chr + $r) * $c1 + $c2) % 65536);
  10105. }
  10106. if (preg_match('#/ForceBold[\s]*([^\s]*)#', $eplain, $matches) > 0) {
  10107. if ($matches[1] == 'true') {
  10108. $fmetric['Flags'] |= 0x40000;
  10109. }
  10110. }
  10111. if (preg_match('#/StdVW[\s]*\[([^\]]*)#', $eplain, $matches) > 0) {
  10112. $fmetric['StemV'] = intval($matches[1]);
  10113. } else {
  10114. $fmetric['StemV'] = 70;
  10115. }
  10116. if (preg_match('#/StdHW[\s]*\[([^\]]*)#', $eplain, $matches) > 0) {
  10117. $fmetric['StemH'] = intval($matches[1]);
  10118. } else {
  10119. $fmetric['StemH'] = 30;
  10120. }
  10121. if (preg_match('#/BlueValues[\s]*\[([^\]]*)#', $eplain, $matches) > 0) {
  10122. $bv = explode(' ', $matches[1]);
  10123. if (count($bv) >= 6) {
  10124. $v1 = intval($bv[2]);
  10125. $v2 = intval($bv[4]);
  10126. if ($v1 <= $v2) {
  10127. $fmetric['XHeight'] = $v1;
  10128. $fmetric['CapHeight'] = $v2;
  10129. } else {
  10130. $fmetric['XHeight'] = $v2;
  10131. $fmetric['CapHeight'] = $v1;
  10132. }
  10133. } else {
  10134. $fmetric['XHeight'] = 450;
  10135. $fmetric['CapHeight'] = 700;
  10136. }
  10137. } else {
  10138. $fmetric['XHeight'] = 450;
  10139. $fmetric['CapHeight'] = 700;
  10140. }
  10141. // get the number of random bytes at the beginning of charstrings
  10142. if (preg_match('#/lenIV[\s]*([0-9]*)#', $eplain, $matches) > 0) {
  10143. $lenIV = intval($matches[1]);
  10144. } else {
  10145. $lenIV = 4;
  10146. }
  10147. $fmetric['Leading'] = 0;
  10148. // get charstring data
  10149. $eplain = substr($eplain, (strpos($eplain, '/CharStrings') + 1));
  10150. preg_match_all('#/([A-Za-z0-9\.]*)[\s][0-9]+[\s]RD[\s](.*)[\s]ND#sU', $eplain, $matches, PREG_SET_ORDER);
  10151. if (!empty($enc) AND isset($this->encmaps->encmap[$enc])) {
  10152. $enc_map = $this->encmaps->encmap[$enc];
  10153. } else {
  10154. $enc_map = false;
  10155. }
  10156. $fmetric['cw'] = '';
  10157. $fmetric['MaxWidth'] = 0;
  10158. $cwidths = array();
  10159. foreach ($matches as $k => $v) {
  10160. $cid = 0;
  10161. if (isset($imap[$v[1]])) {
  10162. $cid = $imap[$v[1]];
  10163. } elseif ($enc_map !== false) {
  10164. $cid = array_search($v[1], $enc_map);
  10165. if ($cid === false) {
  10166. $cid = 0;
  10167. } elseif ($cid > 1000) {
  10168. $cid -= 1000;
  10169. }
  10170. }
  10171. // decrypt charstring encrypted part
  10172. $r = 4330; // charstring encryption constant
  10173. $c1 = 52845;
  10174. $c2 = 22719;
  10175. $cd = $v[2];
  10176. $clen = strlen($cd);
  10177. $ccom = array();
  10178. for ($i = 0; $i < $clen; ++$i) {
  10179. $chr = ord($cd[$i]);
  10180. $ccom[] = ($chr ^ ($r >> 8));
  10181. $r = ((($chr + $r) * $c1 + $c2) % 65536);
  10182. }
  10183. // decode numbers
  10184. $cdec = array();
  10185. $ck = 0;
  10186. $i = $lenIV;
  10187. while ($i < $clen) {
  10188. if ($ccom[$i] < 32) {
  10189. $cdec[$ck] = $ccom[$i];
  10190. if (($ck > 0) AND ($cdec[$ck] == 13)) {
  10191. // hsbw command: update width
  10192. $cwidths[$cid] = $cdec[($ck - 1)];
  10193. }
  10194. ++$i;
  10195. } elseif (($ccom[$i] >= 32) AND ($ccom[$i] <= 246)) {
  10196. $cdec[$ck] = ($ccom[$i] - 139);
  10197. ++$i;
  10198. } elseif (($ccom[$i] >= 247) AND ($ccom[$i] <= 250)) {
  10199. $cdec[$ck] = ((($ccom[$i] - 247) * 256) + $ccom[($i + 1)] + 108);
  10200. $i += 2;
  10201. } elseif (($ccom[$i] >= 251) AND ($ccom[$i] <= 254)) {
  10202. $cdec[$ck] = ((-($ccom[$i] - 251) * 256) - $ccom[($i + 1)] - 108);
  10203. $i += 2;
  10204. } elseif ($ccom[$i] == 255) {
  10205. $sval = chr($ccom[($i + 1)]).chr($ccom[($i + 2)]).chr($ccom[($i + 3)]).chr($ccom[($i + 4)]);
  10206. $vsval = unpack('li', $sval);
  10207. $cdec[$ck] = $vsval['i'];
  10208. $i += 5;
  10209. }
  10210. ++$ck;
  10211. }
  10212. } // end for each matches
  10213. $fmetric['MissingWidth'] = $cwidths[0];
  10214. $fmetric['MaxWidth'] = $fmetric['MissingWidth'];
  10215. $fmetric['AvgWidth'] = 0;
  10216. // set chars widths
  10217. for ($cid = 0; $cid <= 255; ++$cid) {
  10218. if (isset($cwidths[$cid])) {
  10219. if ($cwidths[$cid] > $fmetric['MaxWidth']) {
  10220. $fmetric['MaxWidth'] = $cwidths[$cid];
  10221. }
  10222. $fmetric['AvgWidth'] += $cwidths[$cid];
  10223. $fmetric['cw'] .= ','.$cid.'=>'.$cwidths[$cid];
  10224. } else {
  10225. $fmetric['cw'] .= ','.$cid.'=>'.$fmetric['MissingWidth'];
  10226. }
  10227. }
  10228. $fmetric['AvgWidth'] = round($fmetric['AvgWidth'] / count($cwidths));
  10229. } else {
  10230. // ---------- TRUE TYPE ----------
  10231. if ($fmetric['type'] != 'cidfont0') {
  10232. // store compressed font
  10233. $fp = fopen($outpath.$fmetric['file'], 'wb');
  10234. fwrite($fp, gzcompress($font));
  10235. fclose($fp);
  10236. }
  10237. $offset = 0; // offset position of the font data
  10238. if ($this->_getULONG($font, $offset) != 0x10000) {
  10239. // sfnt version must be 0x00010000 for TrueType version 1.0.
  10240. return $font;
  10241. }
  10242. $offset += 4;
  10243. // get number of tables
  10244. $numTables = $this->_getUSHORT($font, $offset);
  10245. $offset += 2;
  10246. // skip searchRange, entrySelector and rangeShift
  10247. $offset += 6;
  10248. // tables array
  10249. $table = array();
  10250. // ---------- get tables ----------
  10251. for ($i = 0; $i < $numTables; ++$i) {
  10252. // get table info
  10253. $tag = substr($font, $offset, 4);
  10254. $offset += 4;
  10255. $table[$tag] = array();
  10256. $table[$tag]['checkSum'] = $this->_getULONG($font, $offset);
  10257. $offset += 4;
  10258. $table[$tag]['offset'] = $this->_getULONG($font, $offset);
  10259. $offset += 4;
  10260. $table[$tag]['length'] = $this->_getULONG($font, $offset);
  10261. $offset += 4;
  10262. }
  10263. // check magicNumber
  10264. $offset = $table['head']['offset'] + 12;
  10265. if ($this->_getULONG($font, $offset) != 0x5F0F3CF5) {
  10266. // magicNumber must be 0x5F0F3CF5
  10267. return $font;
  10268. }
  10269. $offset += 4;
  10270. $offset += 2; // skip flags
  10271. // get FUnits
  10272. $fmetric['unitsPerEm'] = $this->_getUSHORT($font, $offset);
  10273. $offset += 2;
  10274. // units ratio constant
  10275. $urk = (1000 / $fmetric['unitsPerEm']);
  10276. $offset += 16; // skip created, modified
  10277. $xMin = round($this->_getFWORD($font, $offset) * $urk);
  10278. $offset += 2;
  10279. $yMin = round($this->_getFWORD($font, $offset) * $urk);
  10280. $offset += 2;
  10281. $xMax = round($this->_getFWORD($font, $offset) * $urk);
  10282. $offset += 2;
  10283. $yMax = round($this->_getFWORD($font, $offset) * $urk);
  10284. $offset += 2;
  10285. $fmetric['bbox'] = ''.$xMin.' '.$yMin.' '.$xMax.' '.$yMax.'';
  10286. $macStyle = $this->_getUSHORT($font, $offset);
  10287. $offset += 2;
  10288. // PDF font flags
  10289. $fmetric['Flags'] = $flags;
  10290. if (($macStyle & 2) == 2) {
  10291. // italic flag
  10292. $fmetric['Flags'] |= 64;
  10293. }
  10294. // get offset mode (indexToLocFormat : 0 = short, 1 = long)
  10295. $offset = $table['head']['offset'] + 50;
  10296. $short_offset = ($this->_getSHORT($font, $offset) == 0);
  10297. $offset += 2;
  10298. // get the offsets to the locations of the glyphs in the font, relative to the beginning of the glyphData table
  10299. $indexToLoc = array();
  10300. $offset = $table['loca']['offset'];
  10301. if ($short_offset) {
  10302. // short version
  10303. $tot_num_glyphs = ($table['loca']['length'] / 2); // numGlyphs + 1
  10304. for ($i = 0; $i < $tot_num_glyphs; ++$i) {
  10305. $indexToLoc[$i] = $this->_getUSHORT($font, $offset) * 2;
  10306. $offset += 2;
  10307. }
  10308. } else {
  10309. // long version
  10310. $tot_num_glyphs = ($table['loca']['length'] / 4); // numGlyphs + 1
  10311. for ($i = 0; $i < $tot_num_glyphs; ++$i) {
  10312. $indexToLoc[$i] = $this->_getULONG($font, $offset);
  10313. $offset += 4;
  10314. }
  10315. }
  10316. // get glyphs indexes of chars from cmap table
  10317. $offset = $table['cmap']['offset'] + 2;
  10318. $numEncodingTables = $this->_getUSHORT($font, $offset);
  10319. $offset += 2;
  10320. $encodingTables = array();
  10321. for ($i = 0; $i < $numEncodingTables; ++$i) {
  10322. $encodingTables[$i]['platformID'] = $this->_getUSHORT($font, $offset);
  10323. $offset += 2;
  10324. $encodingTables[$i]['encodingID'] = $this->_getUSHORT($font, $offset);
  10325. $offset += 2;
  10326. $encodingTables[$i]['offset'] = $this->_getULONG($font, $offset);
  10327. $offset += 4;
  10328. }
  10329. // ---------- get os/2 metrics ----------
  10330. $offset = $table['OS/2']['offset'];
  10331. $offset += 2; // skip version
  10332. // xAvgCharWidth
  10333. $fmetric['AvgWidth'] = round($this->_getFWORD($font, $offset) * $urk);
  10334. $offset += 2;
  10335. // usWeightClass
  10336. $usWeightClass = round($this->_getUFWORD($font, $offset) * $urk);
  10337. // estimate StemV and StemH (400 = usWeightClass for Normal - Regular font)
  10338. $fmetric['StemV'] = round((70 * $usWeightClass) / 400);
  10339. $fmetric['StemH'] = round((30 * $usWeightClass) / 400);
  10340. $offset += 2;
  10341. $offset += 2; // usWidthClass
  10342. $fsType = $this->_getSHORT($font, $offset);
  10343. $offset += 2;
  10344. if ($fsType == 2) {
  10345. $this->Error('This Font cannot be modified, embedded or exchanged in any manner without first obtaining permission of the legal owner.');
  10346. }
  10347. // ---------- get font name ----------
  10348. $fmetric['name'] = '';
  10349. $offset = $table['name']['offset'];
  10350. $offset += 2; // skip Format selector (=0).
  10351. // Number of NameRecords that follow n.
  10352. $numNameRecords = $this->_getUSHORT($font, $offset);
  10353. $offset += 2;
  10354. // Offset to start of string storage (from start of table).
  10355. $stringStorageOffset = $this->_getUSHORT($font, $offset);
  10356. $offset += 2;
  10357. for ($i = 0; $i < $numNameRecords; ++$i) {
  10358. $offset += 6; // skip Platform ID, Platform-specific encoding ID, Language ID.
  10359. // Name ID.
  10360. $nameID = $this->_getUSHORT($font, $offset);
  10361. $offset += 2;
  10362. if ($nameID == 6) {
  10363. // String length (in bytes).
  10364. $stringLength = $this->_getUSHORT($font, $offset);
  10365. $offset += 2;
  10366. // String offset from start of storage area (in bytes).
  10367. $stringOffset = $this->_getUSHORT($font, $offset);
  10368. $offset += 2;
  10369. $offset = ($table['name']['offset'] + $stringStorageOffset + $stringOffset);
  10370. $fmetric['name'] = substr($font, $offset, $stringLength);
  10371. $fmetric['name'] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $fmetric['name']);
  10372. break;
  10373. } else {
  10374. $offset += 4; // skip String length, String offset
  10375. }
  10376. }
  10377. if (empty($fmetric['name'])) {
  10378. $fmetric['name'] = $font_name;
  10379. }
  10380. // ---------- get post data ----------
  10381. $offset = $table['post']['offset'];
  10382. $offset += 4; // skip Format Type
  10383. $fmetric['italicAngle'] = $this->_getFIXED($font, $offset);
  10384. $offset += 4;
  10385. $fmetric['underlinePosition'] = round($this->_getFWORD($font, $offset) * $urk);
  10386. $offset += 2;
  10387. $fmetric['underlineThickness'] = round($this->_getFWORD($font, $offset) * $urk);
  10388. $offset += 2;
  10389. $isFixedPitch = ($this->_getULONG($font, $offset) == 0) ? false : true;
  10390. $offset += 2;
  10391. if ($isFixedPitch) {
  10392. $fmetric['Flags'] |= 1;
  10393. }
  10394. // ---------- get hhea data ----------
  10395. $offset = $table['hhea']['offset'];
  10396. $offset += 4; // skip Table version number
  10397. // Ascender
  10398. $fmetric['Ascent'] = round($this->_getFWORD($font, $offset) * $urk);
  10399. $offset += 2;
  10400. // Descender
  10401. $fmetric['Descent'] = round($this->_getFWORD($font, $offset) * $urk);
  10402. $offset += 2;
  10403. // LineGap
  10404. $fmetric['Leading'] = round($this->_getFWORD($font, $offset) * $urk);
  10405. $offset += 2;
  10406. // advanceWidthMax
  10407. $fmetric['MaxWidth'] = round($this->_getUFWORD($font, $offset) * $urk);
  10408. $offset += 2;
  10409. $offset += 22; // skip some values
  10410. // get the number of hMetric entries in hmtx table
  10411. $numberOfHMetrics = $this->_getUSHORT($font, $offset);
  10412. // ---------- get maxp data ----------
  10413. $offset = $table['maxp']['offset'];
  10414. $offset += 4; // skip Table version number
  10415. // get the the number of glyphs in the font.
  10416. $numGlyphs = $this->_getUSHORT($font, $offset);
  10417. // ---------- get CIDToGIDMap ----------
  10418. $ctg = array();
  10419. foreach ($encodingTables as $enctable) {
  10420. // get only specified Platform ID and Encoding ID
  10421. if (($enctable['platformID'] == $platid) AND ($enctable['encodingID'] == $encid)) {
  10422. $offset = $table['cmap']['offset'] + $enctable['offset'];
  10423. $format = $this->_getUSHORT($font, $offset);
  10424. $offset += 2;
  10425. switch ($format) {
  10426. case 0: { // Format 0: Byte encoding table
  10427. $offset += 4; // skip length and version/language
  10428. for ($c = 0; $c < 256; ++$c) {
  10429. $g = $this->_getBYTE($font, $offset);
  10430. $ctg[$c] = $g;
  10431. ++$offset;
  10432. }
  10433. break;
  10434. }
  10435. case 2: { // Format 2: High-byte mapping through table
  10436. $offset += 4; // skip length and version/language
  10437. $numSubHeaders = 0;
  10438. for ($i = 0; $i < 256; ++$i) {
  10439. // Array that maps high bytes to subHeaders: value is subHeader index * 8.
  10440. $subHeaderKeys[$i] = ($this->_getUSHORT($font, $offset) / 8);
  10441. $offset += 2;
  10442. if ($numSubHeaders < $subHeaderKeys[$i]) {
  10443. $numSubHeaders = $subHeaderKeys[$i];
  10444. }
  10445. }
  10446. // the number of subHeaders is equal to the max of subHeaderKeys + 1
  10447. ++$numSubHeaders;
  10448. // read subHeader structures
  10449. $subHeaders = array();
  10450. $numGlyphIndexArray = 0;
  10451. for ($k = 0; $k < $numSubHeaders; ++$k) {
  10452. $subHeaders[$k]['firstCode'] = $this->_getUSHORT($font, $offset);
  10453. $offset += 2;
  10454. $subHeaders[$k]['entryCount'] = $this->_getUSHORT($font, $offset);
  10455. $offset += 2;
  10456. $subHeaders[$k]['idDelta'] = $this->_getUSHORT($font, $offset);
  10457. $offset += 2;
  10458. $subHeaders[$k]['idRangeOffset'] = $this->_getUSHORT($font, $offset);
  10459. $offset += 2;
  10460. $subHeaders[$k]['idRangeOffset'] -= (2 + (($numSubHeaders - $k - 1) * 8));
  10461. $subHeaders[$k]['idRangeOffset'] /= 2;
  10462. $numGlyphIndexArray += $subHeaders[$k]['entryCount'];
  10463. }
  10464. for ($k = 0; $k < $numGlyphIndexArray; ++$k) {
  10465. $glyphIndexArray[$k] = $this->_getUSHORT($font, $offset);
  10466. $offset += 2;
  10467. }
  10468. for ($i = 0; $i < 256; ++$i) {
  10469. $k = $subHeaderKeys[$i];
  10470. if ($k == 0) {
  10471. // one byte code
  10472. $c = $i;
  10473. $g = $glyphIndexArray[0];
  10474. $ctg[$c] = $g;
  10475. } else {
  10476. // two bytes code
  10477. $start_byte = $subHeaders[$k]['firstCode'];
  10478. $end_byte = $start_byte + $subHeaders[$k]['entryCount'];
  10479. for ($j = $start_byte; $j < $end_byte; ++$j) {
  10480. // combine high and low bytes
  10481. $c = (($i << 8) + $j);
  10482. $idRangeOffset = ($subHeaders[$k]['idRangeOffset'] + $j - $subHeaders[$k]['firstCode']);
  10483. $g = ($glyphIndexArray[$idRangeOffset] + $idDelta[$k]) % 65536;
  10484. if ($g < 0) {
  10485. $g = 0;
  10486. }
  10487. $ctg[$c] = $g;
  10488. }
  10489. }
  10490. }
  10491. break;
  10492. }
  10493. case 4: { // Format 4: Segment mapping to delta values
  10494. $length = $this->_getUSHORT($font, $offset);
  10495. $offset += 2;
  10496. $offset += 2; // skip version/language
  10497. $segCount = ($this->_getUSHORT($font, $offset) / 2);
  10498. $offset += 2;
  10499. $offset += 6; // skip searchRange, entrySelector, rangeShift
  10500. $endCount = array(); // array of end character codes for each segment
  10501. for ($k = 0; $k < $segCount; ++$k) {
  10502. $endCount[$k] = $this->_getUSHORT($font, $offset);
  10503. $offset += 2;
  10504. }
  10505. $offset += 2; // skip reservedPad
  10506. $startCount = array(); // array of start character codes for each segment
  10507. for ($k = 0; $k < $segCount; ++$k) {
  10508. $startCount[$k] = $this->_getUSHORT($font, $offset);
  10509. $offset += 2;
  10510. }
  10511. $idDelta = array(); // delta for all character codes in segment
  10512. for ($k = 0; $k < $segCount; ++$k) {
  10513. $idDelta[$k] = $this->_getUSHORT($font, $offset);
  10514. $offset += 2;
  10515. }
  10516. $idRangeOffset = array(); // Offsets into glyphIdArray or 0
  10517. for ($k = 0; $k < $segCount; ++$k) {
  10518. $idRangeOffset[$k] = $this->_getUSHORT($font, $offset);
  10519. $offset += 2;
  10520. }
  10521. $gidlen = ($length / 2) - 8 - (4 * $segCount);
  10522. $glyphIdArray = array(); // glyph index array
  10523. for ($k = 0; $k < $gidlen; ++$k) {
  10524. $glyphIdArray[$k] = $this->_getUSHORT($font, $offset);
  10525. $offset += 2;
  10526. }
  10527. for ($k = 0; $k < $segCount; ++$k) {
  10528. for ($c = $startCount[$k]; $c <= $endCount[$k]; ++$c) {
  10529. if ($idRangeOffset[$k] == 0) {
  10530. $g = ($idDelta[$k] + $c) % 65536;
  10531. } else {
  10532. $gid = (($idRangeOffset[$k] / 2) + ($c - $startCount[$k]) - ($segCount - $k));
  10533. $g = ($glyphIdArray[$gid] + $idDelta[$k]) % 65536;
  10534. }
  10535. if ($g < 0) {
  10536. $g = 0;
  10537. }
  10538. $ctg[$c] = $g;
  10539. }
  10540. }
  10541. break;
  10542. }
  10543. case 6: { // Format 6: Trimmed table mapping
  10544. $offset += 4; // skip length and version/language
  10545. $firstCode = $this->_getUSHORT($font, $offset);
  10546. $offset += 2;
  10547. $entryCount = $this->_getUSHORT($font, $offset);
  10548. $offset += 2;
  10549. for ($k = 0; $k < $entryCount; ++$k) {
  10550. $c = ($k + $firstCode);
  10551. $g = $this->_getUSHORT($font, $offset);
  10552. $offset += 2;
  10553. $ctg[$c] = $g;
  10554. }
  10555. break;
  10556. }
  10557. case 8: { // Format 8: Mixed 16-bit and 32-bit coverage
  10558. $offset += 10; // skip reserved, length and version/language
  10559. for ($k = 0; $k < 8192; ++$k) {
  10560. $is32[$k] = $this->_getBYTE($font, $offset);
  10561. ++$offset;
  10562. }
  10563. $nGroups = $this->_getULONG($font, $offset);
  10564. $offset += 4;
  10565. for ($i = 0; $i < $nGroups; ++$i) {
  10566. $startCharCode = $this->_getULONG($font, $offset);
  10567. $offset += 4;
  10568. $endCharCode = $this->_getULONG($font, $offset);
  10569. $offset += 4;
  10570. $startGlyphID = $this->_getULONG($font, $offset);
  10571. $offset += 4;
  10572. for ($k = $startCharCode; $k <= $endCharCode; ++$k) {
  10573. $is32idx = floor($c / 8);
  10574. if ((isset($is32[$is32idx])) AND (($is32[$is32idx] & (1 << (7 - ($c % 8)))) == 0)) {
  10575. $c = $k;
  10576. } else {
  10577. // 32 bit format
  10578. // convert to decimal (http://www.unicode.org/faq//utf_bom.html#utf16-4)
  10579. //LEAD_OFFSET = (0xD800 - (0x10000 >> 10)) = 55232
  10580. //SURROGATE_OFFSET = (0x10000 - (0xD800 << 10) - 0xDC00) = -56613888
  10581. $c = ((55232 + ($k >> 10)) << 10) + (0xDC00 + ($k & 0x3FF)) -56613888;
  10582. }
  10583. $ctg[$c] = 0;
  10584. ++$startGlyphID;
  10585. }
  10586. }
  10587. break;
  10588. }
  10589. case 10: { // Format 10: Trimmed array
  10590. $offset += 10; // skip reserved, length and version/language
  10591. $startCharCode = $this->_getULONG($font, $offset);
  10592. $offset += 4;
  10593. $numChars = $this->_getULONG($font, $offset);
  10594. $offset += 4;
  10595. for ($k = 0; $k < $numChars; ++$k) {
  10596. $c = ($k + $startCharCode);
  10597. $g = $this->_getUSHORT($font, $offset);
  10598. $ctg[$c] = $g;
  10599. $offset += 2;
  10600. }
  10601. break;
  10602. }
  10603. case 12: { // Format 12: Segmented coverage
  10604. $offset += 10; // skip length and version/language
  10605. $nGroups = $this->_getULONG($font, $offset);
  10606. $offset += 4;
  10607. for ($k = 0; $k < $nGroups; ++$k) {
  10608. $startCharCode = $this->_getULONG($font, $offset);
  10609. $offset += 4;
  10610. $endCharCode = $this->_getULONG($font, $offset);
  10611. $offset += 4;
  10612. $startGlyphCode = $this->_getULONG($font, $offset);
  10613. $offset += 4;
  10614. for ($c = $startCharCode; $c <= $endCharCode; ++$c) {
  10615. $ctg[$c] = $startGlyphCode;
  10616. ++$startGlyphCode;
  10617. }
  10618. }
  10619. break;
  10620. }
  10621. case 13: { // Format 13: Many-to-one range mappings
  10622. // to be implemented ...
  10623. break;
  10624. }
  10625. case 14: { // Format 14: Unicode Variation Sequences
  10626. // to be implemented ...
  10627. break;
  10628. }
  10629. }
  10630. }
  10631. }
  10632. if (!isset($ctg[0])) {
  10633. $ctg[0] = 0;
  10634. }
  10635. // get xHeight (height of x)
  10636. $offset = ($table['glyf']['offset'] + $indexToLoc[$ctg[120]] + 4);
  10637. $yMin = $this->_getFWORD($font, $offset);
  10638. $offset += 4;
  10639. $yMax = $this->_getFWORD($font, $offset);
  10640. $offset += 2;
  10641. $fmetric['XHeight'] = round(($yMax - $yMin) * $urk);
  10642. // get CapHeight (height of H)
  10643. $offset = ($table['glyf']['offset'] + $indexToLoc[$ctg[72]] + 4);
  10644. $yMin = $this->_getFWORD($font, $offset);
  10645. $offset += 4;
  10646. $yMax = $this->_getFWORD($font, $offset);
  10647. $offset += 2;
  10648. $fmetric['CapHeight'] = round(($yMax - $yMin) * $urk);
  10649. // ceate widths array
  10650. $cw = array();
  10651. $offset = $table['hmtx']['offset'];
  10652. for ($i = 0 ; $i < $numberOfHMetrics; ++$i) {
  10653. $cw[$i] = round($this->_getUFWORD($font, $offset) * $urk);
  10654. $offset += 4; // skip lsb
  10655. }
  10656. if ($numberOfHMetrics < $numGlyphs) {
  10657. // fill missing widths with the last value
  10658. $cw = array_pad($cw, $numGlyphs, $cw[($numberOfHMetrics - 1)]);
  10659. }
  10660. $fmetric['MissingWidth'] = $cw[0];
  10661. $fmetric['cw'] = '';
  10662. for ($cid = 0; $cid <= 65535; ++$cid) {
  10663. if (isset($ctg[$cid])) {
  10664. if (isset($cw[$ctg[$cid]])) {
  10665. $fmetric['cw'] .= ','.$cid.'=>'.$cw[$ctg[$cid]];
  10666. }
  10667. if ($addcbbox AND isset($indexToLoc[$ctg[$cid]])) {
  10668. $offset = ($table['glyf']['offset'] + $indexToLoc[$ctg[$cid]]);
  10669. $xMin = round($this->_getFWORD($font, $offset + 2)) * $urk;
  10670. $yMin = round($this->_getFWORD($font, $offset + 4)) * $urk;
  10671. $xMax = round($this->_getFWORD($font, $offset + 6)) * $urk;
  10672. $yMax = round($this->_getFWORD($font, $offset + 8)) * $urk;
  10673. $fmetric['cbbox'] .= ','.$cid.'=>array('.$xMin.','.$yMin.','.$xMax.','.$yMax.')';
  10674. }
  10675. }
  10676. }
  10677. } // end of true type
  10678. if (($fmetric['type'] == 'TrueTypeUnicode') AND (count($ctg) == 256)) {
  10679. $fmetric['type'] == 'TrueType';
  10680. }
  10681. // ---------- create php font file ----------
  10682. $pfile = '<'.'?'.'php'."\n";
  10683. $pfile .= '// TCPDF FONT FILE DESCRIPTION'."\n";
  10684. $pfile .= '$type=\''.$fmetric['type'].'\';'."\n";
  10685. $pfile .= '$name=\''.$fmetric['name'].'\';'."\n";
  10686. $pfile .= '$up='.$fmetric['underlinePosition'].';'."\n";
  10687. $pfile .= '$ut='.$fmetric['underlineThickness'].';'."\n";
  10688. if ($fmetric['MissingWidth'] > 0) {
  10689. $pfile .= '$dw='.$fmetric['MissingWidth'].';'."\n";
  10690. } else {
  10691. $pfile .= '$dw='.$fmetric['AvgWidth'].';'."\n";
  10692. }
  10693. $pfile .= '$diff=\''.$fmetric['diff'].'\';'."\n";
  10694. if ($fmetric['type'] == 'Type1') {
  10695. // Type 1
  10696. $pfile .= '$enc=\''.$fmetric['enc'].'\';'."\n";
  10697. $pfile .= '$file=\''.$fmetric['file'].'\';'."\n";
  10698. $pfile .= '$size1='.$fmetric['size1'].';'."\n";
  10699. $pfile .= '$size2='.$fmetric['size2'].';'."\n";
  10700. } else {
  10701. $pfile .= '$originalsize='.$fmetric['originalsize'].';'."\n";
  10702. if ($fmetric['type'] == 'cidfont0') {
  10703. // CID-0
  10704. switch ($fonttype) {
  10705. case 'CID0JP': {
  10706. $pfile .= '// Japanese'."\n";
  10707. $pfile .= '$enc=\'UniJIS-UTF16-H\';'."\n";
  10708. $pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'Japan1\',\'Supplement\'=>5);'."\n";
  10709. $pfile .= 'include(dirname(__FILE__).\'/uni2cid_aj16.php\');'."\n";
  10710. break;
  10711. }
  10712. case 'CID0KR': {
  10713. $pfile .= '// Korean'."\n";
  10714. $pfile .= '$enc=\'UniKS-UTF16-H\';'."\n";
  10715. $pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'Korea1\',\'Supplement\'=>0);'."\n";
  10716. $pfile .= 'include(dirname(__FILE__).\'/uni2cid_ak12.php\');'."\n";
  10717. break;
  10718. }
  10719. case 'CID0CS': {
  10720. $pfile .= '// Chinese Simplified'."\n";
  10721. $pfile .= '$enc=\'UniGB-UTF16-H\';'."\n";
  10722. $pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'GB1\',\'Supplement\'=>2);'."\n";
  10723. $pfile .= 'include(dirname(__FILE__).\'/uni2cid_ag15.php\');'."\n";
  10724. break;
  10725. }
  10726. case 'CID0CT':
  10727. default: {
  10728. $pfile .= '// Chinese Traditional'."\n";
  10729. $pfile .= '$enc=\'UniCNS-UTF16-H\';'."\n";
  10730. $pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'CNS1\',\'Supplement\'=>0);'."\n";
  10731. $pfile .= 'include(dirname(__FILE__).\'/uni2cid_aj16.php\');'."\n";
  10732. break;
  10733. }
  10734. }
  10735. } else {
  10736. // TrueType
  10737. $pfile .= '$enc=\''.$fmetric['enc'].'\';'."\n";
  10738. $pfile .= '$file=\''.$fmetric['file'].'\';'."\n";
  10739. $pfile .= '$ctg=\''.$fmetric['ctg'].'\';'."\n";
  10740. // create CIDToGIDMap
  10741. $cidtogidmap = str_pad('', 131072, "\x00"); // (256 * 256 * 2) = 131072
  10742. foreach ($ctg as $cid => $gid) {
  10743. $cidtogidmap = $this->updateCIDtoGIDmap($cidtogidmap, $cid, $ctg[$cid]);
  10744. }
  10745. // store compressed CIDToGIDMap
  10746. $fp = fopen($outpath.$fmetric['ctg'], 'wb');
  10747. fwrite($fp, gzcompress($cidtogidmap));
  10748. fclose($fp);
  10749. }
  10750. }
  10751. $pfile .= '$desc=array(';
  10752. $pfile .= '\'Flags\'=>'.$fmetric['Flags'].',';
  10753. $pfile .= '\'FontBBox\'=>\'['.$fmetric['bbox'].']\',';
  10754. $pfile .= '\'ItalicAngle\'=>'.$fmetric['italicAngle'].',';
  10755. $pfile .= '\'Ascent\'=>'.$fmetric['Ascent'].',';
  10756. $pfile .= '\'Descent\'=>'.$fmetric['Descent'].',';
  10757. $pfile .= '\'Leading\'=>'.$fmetric['Leading'].',';
  10758. $pfile .= '\'CapHeight\'=>'.$fmetric['CapHeight'].',';
  10759. $pfile .= '\'XHeight\'=>'.$fmetric['XHeight'].',';
  10760. $pfile .= '\'StemV\'=>'.$fmetric['StemV'].',';
  10761. $pfile .= '\'StemH\'=>'.$fmetric['StemH'].',';
  10762. $pfile .= '\'AvgWidth\'=>'.$fmetric['AvgWidth'].',';
  10763. $pfile .= '\'MaxWidth\'=>'.$fmetric['MaxWidth'].',';
  10764. $pfile .= '\'MissingWidth\'=>'.$fmetric['MissingWidth'].'';
  10765. $pfile .= ');'."\n";
  10766. if (isset($fmetric['cbbox'])) {
  10767. $pfile .= '$cbbox=array('.substr($fmetric['cbbox'], 1).');'."\n";
  10768. }
  10769. $pfile .= '$cw=array('.substr($fmetric['cw'], 1).');'."\n";
  10770. $pfile .= '// --- EOF ---'."\n";
  10771. // store file
  10772. $fp = fopen($outpath.$font_name.'.php', 'w');
  10773. fwrite($fp, $pfile);
  10774. fclose($fp);
  10775. // return TCPDF font name
  10776. return $font_name;
  10777. }
  10778. /**
  10779. * Returns a subset of the TrueType font data without the unused glyphs.
  10780. * @param $font (string) TrueType font data.
  10781. * @param $subsetchars (array) Array of used characters (the glyphs to keep).
  10782. * @return (string) A subset of TrueType font data without the unused glyphs.
  10783. * @author Nicola Asuni
  10784. * @protected
  10785. * @since 5.2.000 (2010-06-02)
  10786. */
  10787. protected function _getTrueTypeFontSubset($font, $subsetchars) {
  10788. ksort($subsetchars);
  10789. $offset = 0; // offset position of the font data
  10790. if ($this->_getULONG($font, $offset) != 0x10000) {
  10791. // sfnt version must be 0x00010000 for TrueType version 1.0.
  10792. return $font;
  10793. }
  10794. $offset += 4;
  10795. // get number of tables
  10796. $numTables = $this->_getUSHORT($font, $offset);
  10797. $offset += 2;
  10798. // skip searchRange, entrySelector and rangeShift
  10799. $offset += 6;
  10800. // tables array
  10801. $table = array();
  10802. // for each table
  10803. for ($i = 0; $i < $numTables; ++$i) {
  10804. // get table info
  10805. $tag = substr($font, $offset, 4);
  10806. $offset += 4;
  10807. $table[$tag] = array();
  10808. $table[$tag]['checkSum'] = $this->_getULONG($font, $offset);
  10809. $offset += 4;
  10810. $table[$tag]['offset'] = $this->_getULONG($font, $offset);
  10811. $offset += 4;
  10812. $table[$tag]['length'] = $this->_getULONG($font, $offset);
  10813. $offset += 4;
  10814. }
  10815. // check magicNumber
  10816. $offset = $table['head']['offset'] + 12;
  10817. if ($this->_getULONG($font, $offset) != 0x5F0F3CF5) {
  10818. // magicNumber must be 0x5F0F3CF5
  10819. return $font;
  10820. }
  10821. $offset += 4;
  10822. // get offset mode (indexToLocFormat : 0 = short, 1 = long)
  10823. $offset = $table['head']['offset'] + 50;
  10824. $short_offset = ($this->_getSHORT($font, $offset) == 0);
  10825. $offset += 2;
  10826. // get the offsets to the locations of the glyphs in the font, relative to the beginning of the glyphData table
  10827. $indexToLoc = array();
  10828. $offset = $table['loca']['offset'];
  10829. if ($short_offset) {
  10830. // short version
  10831. $tot_num_glyphs = ($table['loca']['length'] / 2); // numGlyphs + 1
  10832. for ($i = 0; $i < $tot_num_glyphs; ++$i) {
  10833. $indexToLoc[$i] = $this->_getUSHORT($font, $offset) * 2;
  10834. $offset += 2;
  10835. }
  10836. } else {
  10837. // long version
  10838. $tot_num_glyphs = ($table['loca']['length'] / 4); // numGlyphs + 1
  10839. for ($i = 0; $i < $tot_num_glyphs; ++$i) {
  10840. $indexToLoc[$i] = $this->_getULONG($font, $offset);
  10841. $offset += 4;
  10842. }
  10843. }
  10844. // get glyphs indexes of chars from cmap table
  10845. $subsetglyphs = array(); // glyph IDs on key
  10846. $subsetglyphs[0] = true; // character codes that do not correspond to any glyph in the font should be mapped to glyph index 0
  10847. $offset = $table['cmap']['offset'] + 2;
  10848. $numEncodingTables = $this->_getUSHORT($font, $offset);
  10849. $offset += 2;
  10850. $encodingTables = array();
  10851. for ($i = 0; $i < $numEncodingTables; ++$i) {
  10852. $encodingTables[$i]['platformID'] = $this->_getUSHORT($font, $offset);
  10853. $offset += 2;
  10854. $encodingTables[$i]['encodingID'] = $this->_getUSHORT($font, $offset);
  10855. $offset += 2;
  10856. $encodingTables[$i]['offset'] = $this->_getULONG($font, $offset);
  10857. $offset += 4;
  10858. }
  10859. foreach ($encodingTables as $enctable) {
  10860. // get all platforms and encodings
  10861. $offset = $table['cmap']['offset'] + $enctable['offset'];
  10862. $format = $this->_getUSHORT($font, $offset);
  10863. $offset += 2;
  10864. switch ($format) {
  10865. case 0: { // Format 0: Byte encoding table
  10866. $offset += 4; // skip length and version/language
  10867. for ($c = 0; $c < 256; ++$c) {
  10868. if (isset($subsetchars[$c])) {
  10869. $g = $this->_getBYTE($font, $offset);
  10870. $subsetglyphs[$g] = true;
  10871. }
  10872. ++$offset;
  10873. }
  10874. break;
  10875. }
  10876. case 2: { // Format 2: High-byte mapping through table
  10877. $offset += 4; // skip length and version/language
  10878. $numSubHeaders = 0;
  10879. for ($i = 0; $i < 256; ++$i) {
  10880. // Array that maps high bytes to subHeaders: value is subHeader index * 8.
  10881. $subHeaderKeys[$i] = ($this->_getUSHORT($font, $offset) / 8);
  10882. $offset += 2;
  10883. if ($numSubHeaders < $subHeaderKeys[$i]) {
  10884. $numSubHeaders = $subHeaderKeys[$i];
  10885. }
  10886. }
  10887. // the number of subHeaders is equal to the max of subHeaderKeys + 1
  10888. ++$numSubHeaders;
  10889. // read subHeader structures
  10890. $subHeaders = array();
  10891. $numGlyphIndexArray = 0;
  10892. for ($k = 0; $k < $numSubHeaders; ++$k) {
  10893. $subHeaders[$k]['firstCode'] = $this->_getUSHORT($font, $offset);
  10894. $offset += 2;
  10895. $subHeaders[$k]['entryCount'] = $this->_getUSHORT($font, $offset);
  10896. $offset += 2;
  10897. $subHeaders[$k]['idDelta'] = $this->_getUSHORT($font, $offset);
  10898. $offset += 2;
  10899. $subHeaders[$k]['idRangeOffset'] = $this->_getUSHORT($font, $offset);
  10900. $offset += 2;
  10901. $subHeaders[$k]['idRangeOffset'] -= (2 + (($numSubHeaders - $k - 1) * 8));
  10902. $subHeaders[$k]['idRangeOffset'] /= 2;
  10903. $numGlyphIndexArray += $subHeaders[$k]['entryCount'];
  10904. }
  10905. for ($k = 0; $k < $numGlyphIndexArray; ++$k) {
  10906. $glyphIndexArray[$k] = $this->_getUSHORT($font, $offset);
  10907. $offset += 2;
  10908. }
  10909. for ($i = 0; $i < 256; ++$i) {
  10910. $k = $subHeaderKeys[$i];
  10911. if ($k == 0) {
  10912. // one byte code
  10913. $c = $i;
  10914. if (isset($subsetchars[$c])) {
  10915. $g = $glyphIndexArray[0];
  10916. $subsetglyphs[$g] = true;
  10917. }
  10918. } else {
  10919. // two bytes code
  10920. $start_byte = $subHeaders[$k]['firstCode'];
  10921. $end_byte = $start_byte + $subHeaders[$k]['entryCount'];
  10922. for ($j = $start_byte; $j < $end_byte; ++$j) {
  10923. // combine high and low bytes
  10924. $c = (($i << 8) + $j);
  10925. if (isset($subsetchars[$c])) {
  10926. $idRangeOffset = ($subHeaders[$k]['idRangeOffset'] + $j - $subHeaders[$k]['firstCode']);
  10927. $g = ($glyphIndexArray[$idRangeOffset] + $idDelta[$k]) % 65536;
  10928. if ($g < 0) {
  10929. $g = 0;
  10930. }
  10931. $subsetglyphs[$g] = true;
  10932. }
  10933. }
  10934. }
  10935. }
  10936. break;
  10937. }
  10938. case 4: { // Format 4: Segment mapping to delta values
  10939. $length = $this->_getUSHORT($font, $offset);
  10940. $offset += 2;
  10941. $offset += 2; // skip version/language
  10942. $segCount = ($this->_getUSHORT($font, $offset) / 2);
  10943. $offset += 2;
  10944. $offset += 6; // skip searchRange, entrySelector, rangeShift
  10945. $endCount = array(); // array of end character codes for each segment
  10946. for ($k = 0; $k < $segCount; ++$k) {
  10947. $endCount[$k] = $this->_getUSHORT($font, $offset);
  10948. $offset += 2;
  10949. }
  10950. $offset += 2; // skip reservedPad
  10951. $startCount = array(); // array of start character codes for each segment
  10952. for ($k = 0; $k < $segCount; ++$k) {
  10953. $startCount[$k] = $this->_getUSHORT($font, $offset);
  10954. $offset += 2;
  10955. }
  10956. $idDelta = array(); // delta for all character codes in segment
  10957. for ($k = 0; $k < $segCount; ++$k) {
  10958. $idDelta[$k] = $this->_getUSHORT($font, $offset);
  10959. $offset += 2;
  10960. }
  10961. $idRangeOffset = array(); // Offsets into glyphIdArray or 0
  10962. for ($k = 0; $k < $segCount; ++$k) {
  10963. $idRangeOffset[$k] = $this->_getUSHORT($font, $offset);
  10964. $offset += 2;
  10965. }
  10966. $gidlen = ($length / 2) - 8 - (4 * $segCount);
  10967. $glyphIdArray = array(); // glyph index array
  10968. for ($k = 0; $k < $gidlen; ++$k) {
  10969. $glyphIdArray[$k] = $this->_getUSHORT($font, $offset);
  10970. $offset += 2;
  10971. }
  10972. for ($k = 0; $k < $segCount; ++$k) {
  10973. for ($c = $startCount[$k]; $c <= $endCount[$k]; ++$c) {
  10974. if (isset($subsetchars[$c])) {
  10975. if ($idRangeOffset[$k] == 0) {
  10976. $g = ($idDelta[$k] + $c) % 65536;
  10977. } else {
  10978. $gid = (($idRangeOffset[$k] / 2) + ($c - $startCount[$k]) - ($segCount - $k));
  10979. $g = ($glyphIdArray[$gid] + $idDelta[$k]) % 65536;
  10980. }
  10981. if ($g < 0) {
  10982. $g = 0;
  10983. }
  10984. $subsetglyphs[$g] = true;
  10985. }
  10986. }
  10987. }
  10988. break;
  10989. }
  10990. case 6: { // Format 6: Trimmed table mapping
  10991. $offset += 4; // skip length and version/language
  10992. $firstCode = $this->_getUSHORT($font, $offset);
  10993. $offset += 2;
  10994. $entryCount = $this->_getUSHORT($font, $offset);
  10995. $offset += 2;
  10996. for ($k = 0; $k < $entryCount; ++$k) {
  10997. $c = ($k + $firstCode);
  10998. if (isset($subsetchars[$c])) {
  10999. $g = $this->_getUSHORT($font, $offset);
  11000. $subsetglyphs[$g] = true;
  11001. }
  11002. $offset += 2;
  11003. }
  11004. break;
  11005. }
  11006. case 8: { // Format 8: Mixed 16-bit and 32-bit coverage
  11007. $offset += 10; // skip reserved, length and version/language
  11008. for ($k = 0; $k < 8192; ++$k) {
  11009. $is32[$k] = $this->_getBYTE($font, $offset);
  11010. ++$offset;
  11011. }
  11012. $nGroups = $this->_getULONG($font, $offset);
  11013. $offset += 4;
  11014. for ($i = 0; $i < $nGroups; ++$i) {
  11015. $startCharCode = $this->_getULONG($font, $offset);
  11016. $offset += 4;
  11017. $endCharCode = $this->_getULONG($font, $offset);
  11018. $offset += 4;
  11019. $startGlyphID = $this->_getULONG($font, $offset);
  11020. $offset += 4;
  11021. for ($k = $startCharCode; $k <= $endCharCode; ++$k) {
  11022. $is32idx = floor($c / 8);
  11023. if ((isset($is32[$is32idx])) AND (($is32[$is32idx] & (1 << (7 - ($c % 8)))) == 0)) {
  11024. $c = $k;
  11025. } else {
  11026. // 32 bit format
  11027. // convert to decimal (http://www.unicode.org/faq//utf_bom.html#utf16-4)
  11028. //LEAD_OFFSET = (0xD800 - (0x10000 >> 10)) = 55232
  11029. //SURROGATE_OFFSET = (0x10000 - (0xD800 << 10) - 0xDC00) = -56613888
  11030. $c = ((55232 + ($k >> 10)) << 10) + (0xDC00 + ($k & 0x3FF)) -56613888;
  11031. }
  11032. if (isset($subsetchars[$c])) {
  11033. $subsetglyphs[$startGlyphID] = true;
  11034. }
  11035. ++$startGlyphID;
  11036. }
  11037. }
  11038. break;
  11039. }
  11040. case 10: { // Format 10: Trimmed array
  11041. $offset += 10; // skip reserved, length and version/language
  11042. $startCharCode = $this->_getULONG($font, $offset);
  11043. $offset += 4;
  11044. $numChars = $this->_getULONG($font, $offset);
  11045. $offset += 4;
  11046. for ($k = 0; $k < $numChars; ++$k) {
  11047. $c = ($k + $startCharCode);
  11048. if (isset($subsetchars[$c])) {
  11049. $g = $this->_getUSHORT($font, $offset);
  11050. $subsetglyphs[$g] = true;
  11051. }
  11052. $offset += 2;
  11053. }
  11054. break;
  11055. }
  11056. case 12: { // Format 12: Segmented coverage
  11057. $offset += 10; // skip length and version/language
  11058. $nGroups = $this->_getULONG($font, $offset);
  11059. $offset += 4;
  11060. for ($k = 0; $k < $nGroups; ++$k) {
  11061. $startCharCode = $this->_getULONG($font, $offset);
  11062. $offset += 4;
  11063. $endCharCode = $this->_getULONG($font, $offset);
  11064. $offset += 4;
  11065. $startGlyphCode = $this->_getULONG($font, $offset);
  11066. $offset += 4;
  11067. for ($c = $startCharCode; $c <= $endCharCode; ++$c) {
  11068. if (isset($subsetchars[$c])) {
  11069. $subsetglyphs[$startGlyphCode] = true;
  11070. }
  11071. ++$startGlyphCode;
  11072. }
  11073. }
  11074. break;
  11075. }
  11076. case 13: { // Format 13: Many-to-one range mappings
  11077. // to be implemented ...
  11078. break;
  11079. }
  11080. case 14: { // Format 14: Unicode Variation Sequences
  11081. // to be implemented ...
  11082. break;
  11083. }
  11084. }
  11085. }
  11086. // include all parts of composite glyphs
  11087. $new_sga = $subsetglyphs;
  11088. while (!empty($new_sga)) {
  11089. $sga = $new_sga;
  11090. $new_sga = array();
  11091. foreach ($sga as $key => $val) {
  11092. if (isset($indexToLoc[$key])) {
  11093. $offset = ($table['glyf']['offset'] + $indexToLoc[$key]);
  11094. $numberOfContours = $this->_getSHORT($font, $offset);
  11095. $offset += 2;
  11096. if ($numberOfContours < 0) { // composite glyph
  11097. $offset += 8; // skip xMin, yMin, xMax, yMax
  11098. do {
  11099. $flags = $this->_getUSHORT($font, $offset);
  11100. $offset += 2;
  11101. $glyphIndex = $this->_getUSHORT($font, $offset);
  11102. $offset += 2;
  11103. if (!isset($subsetglyphs[$glyphIndex])) {
  11104. // add missing glyphs
  11105. $new_sga[$glyphIndex] = true;
  11106. }
  11107. // skip some bytes by case
  11108. if ($flags & 1) {
  11109. $offset += 4;
  11110. } else {
  11111. $offset += 2;
  11112. }
  11113. if ($flags & 8) {
  11114. $offset += 2;
  11115. } elseif ($flags & 64) {
  11116. $offset += 4;
  11117. } elseif ($flags & 128) {
  11118. $offset += 8;
  11119. }
  11120. } while ($flags & 32);
  11121. }
  11122. }
  11123. }
  11124. $subsetglyphs += $new_sga;
  11125. }
  11126. // sort glyphs by key (and remove duplicates)
  11127. ksort($subsetglyphs);
  11128. // build new glyf and loca tables
  11129. $glyf = '';
  11130. $loca = '';
  11131. $offset = 0;
  11132. $glyf_offset = $table['glyf']['offset'];
  11133. for ($i = 0; $i < $tot_num_glyphs; ++$i) {
  11134. if (isset($subsetglyphs[$i])) {
  11135. $length = ($indexToLoc[($i + 1)] - $indexToLoc[$i]);
  11136. $glyf .= substr($font, ($glyf_offset + $indexToLoc[$i]), $length);
  11137. } else {
  11138. $length = 0;
  11139. }
  11140. if ($short_offset) {
  11141. $loca .= pack('n', ($offset / 2));
  11142. } else {
  11143. $loca .= pack('N', $offset);
  11144. }
  11145. $offset += $length;
  11146. }
  11147. // array of table names to preserve (loca and glyf tables will be added later)
  11148. // the cmap table is not needed and shall not be present, since the mapping from character codes to glyph descriptions is provided separately
  11149. $table_names = array ('head', 'hhea', 'hmtx', 'maxp', 'cvt ', 'fpgm', 'prep'); // minimum required table names
  11150. // get the tables to preserve
  11151. $offset = 12;
  11152. foreach ($table as $tag => $val) {
  11153. if (in_array($tag, $table_names)) {
  11154. $table[$tag]['data'] = substr($font, $table[$tag]['offset'], $table[$tag]['length']);
  11155. if ($tag == 'head') {
  11156. // set the checkSumAdjustment to 0
  11157. $table[$tag]['data'] = substr($table[$tag]['data'], 0, 8)."\x0\x0\x0\x0".substr($table[$tag]['data'], 12);
  11158. }
  11159. $pad = 4 - ($table[$tag]['length'] % 4);
  11160. if ($pad != 4) {
  11161. // the length of a table must be a multiple of four bytes
  11162. $table[$tag]['length'] += $pad;
  11163. $table[$tag]['data'] .= str_repeat("\x0", $pad);
  11164. }
  11165. $table[$tag]['offset'] = $offset;
  11166. $offset += $table[$tag]['length'];
  11167. // check sum is not changed (so keep the following line commented)
  11168. //$table[$tag]['checkSum'] = $this->_getTTFtableChecksum($table[$tag]['data'], $table[$tag]['length']);
  11169. } else {
  11170. unset($table[$tag]);
  11171. }
  11172. }
  11173. // add loca
  11174. $table['loca']['data'] = $loca;
  11175. $table['loca']['length'] = strlen($loca);
  11176. $pad = 4 - ($table['loca']['length'] % 4);
  11177. if ($pad != 4) {
  11178. // the length of a table must be a multiple of four bytes
  11179. $table['loca']['length'] += $pad;
  11180. $table['loca']['data'] .= str_repeat("\x0", $pad);
  11181. }
  11182. $table['loca']['offset'] = $offset;
  11183. $table['loca']['checkSum'] = $this->_getTTFtableChecksum($table['loca']['data'], $table['loca']['length']);
  11184. $offset += $table['loca']['length'];
  11185. // add glyf
  11186. $table['glyf']['data'] = $glyf;
  11187. $table['glyf']['length'] = strlen($glyf);
  11188. $pad = 4 - ($table['glyf']['length'] % 4);
  11189. if ($pad != 4) {
  11190. // the length of a table must be a multiple of four bytes
  11191. $table['glyf']['length'] += $pad;
  11192. $table['glyf']['data'] .= str_repeat("\x0", $pad);
  11193. }
  11194. $table['glyf']['offset'] = $offset;
  11195. $table['glyf']['checkSum'] = $this->_getTTFtableChecksum($table['glyf']['data'], $table['glyf']['length']);
  11196. // rebuild font
  11197. $font = '';
  11198. $font .= pack('N', 0x10000); // sfnt version
  11199. $numTables = count($table);
  11200. $font .= pack('n', $numTables); // numTables
  11201. $entrySelector = floor(log($numTables, 2));
  11202. $searchRange = pow(2, $entrySelector) * 16;
  11203. $rangeShift = ($numTables * 16) - $searchRange;
  11204. $font .= pack('n', $searchRange); // searchRange
  11205. $font .= pack('n', $entrySelector); // entrySelector
  11206. $font .= pack('n', $rangeShift); // rangeShift
  11207. $offset = ($numTables * 16);
  11208. foreach ($table as $tag => $data) {
  11209. $font .= $tag; // tag
  11210. $font .= pack('N', $data['checkSum']); // checkSum
  11211. $font .= pack('N', ($data['offset'] + $offset)); // offset
  11212. $font .= pack('N', $data['length']); // length
  11213. }
  11214. foreach ($table as $data) {
  11215. $font .= $data['data'];
  11216. }
  11217. // set checkSumAdjustment on head table
  11218. $checkSumAdjustment = 0xB1B0AFBA - $this->_getTTFtableChecksum($font, strlen($font));
  11219. $font = substr($font, 0, $table['head']['offset'] + 8).pack('N', $checkSumAdjustment).substr($font, $table['head']['offset'] + 12);
  11220. return $font;
  11221. }
  11222. /**
  11223. * Returs the checksum of a TTF table.
  11224. * @param $table (string) table to check
  11225. * @param $length (int) length of table in bytes
  11226. * @return int checksum
  11227. * @author Nicola Asuni
  11228. * @protected
  11229. * @since 5.2.000 (2010-06-02)
  11230. */
  11231. protected function _getTTFtableChecksum($table, $length) {
  11232. $sum = 0;
  11233. $tlen = ($length / 4);
  11234. $offset = 0;
  11235. for ($i = 0; $i < $tlen; ++$i) {
  11236. $v = unpack('Ni', substr($table, $offset, 4));
  11237. $sum += $v['i'];
  11238. $offset += 4;
  11239. }
  11240. $sum = unpack('Ni', pack('N', $sum));
  11241. return $sum['i'];
  11242. }
  11243. /**
  11244. * Outputs font widths
  11245. * @param $font (array) font data
  11246. * @param $cidoffset (int) offset for CID values
  11247. * @return PDF command string for font widths
  11248. * @author Nicola Asuni
  11249. * @protected
  11250. * @since 4.4.000 (2008-12-07)
  11251. */
  11252. protected function _putfontwidths($font, $cidoffset=0) {
  11253. ksort($font['cw']);
  11254. $rangeid = 0;
  11255. $range = array();
  11256. $prevcid = -2;
  11257. $prevwidth = -1;
  11258. $interval = false;
  11259. // for each character
  11260. foreach ($font['cw'] as $cid => $width) {
  11261. $cid -= $cidoffset;
  11262. if ($font['subset'] AND (!isset($font['subsetchars'][$cid]))) {
  11263. // ignore the unused characters (font subsetting)
  11264. continue;
  11265. }
  11266. if ($width != $font['dw']) {
  11267. if ($cid == ($prevcid + 1)) {
  11268. // consecutive CID
  11269. if ($width == $prevwidth) {
  11270. if ($width == $range[$rangeid][0]) {
  11271. $range[$rangeid][] = $width;
  11272. } else {
  11273. array_pop($range[$rangeid]);
  11274. // new range
  11275. $rangeid = $prevcid;
  11276. $range[$rangeid] = array();
  11277. $range[$rangeid][] = $prevwidth;
  11278. $range[$rangeid][] = $width;
  11279. }
  11280. $interval = true;
  11281. $range[$rangeid]['interval'] = true;
  11282. } else {
  11283. if ($interval) {
  11284. // new range
  11285. $rangeid = $cid;
  11286. $range[$rangeid] = array();
  11287. $range[$rangeid][] = $width;
  11288. } else {
  11289. $range[$rangeid][] = $width;
  11290. }
  11291. $interval = false;
  11292. }
  11293. } else {
  11294. // new range
  11295. $rangeid = $cid;
  11296. $range[$rangeid] = array();
  11297. $range[$rangeid][] = $width;
  11298. $interval = false;
  11299. }
  11300. $prevcid = $cid;
  11301. $prevwidth = $width;
  11302. }
  11303. }
  11304. // optimize ranges
  11305. $prevk = -1;
  11306. $nextk = -1;
  11307. $prevint = false;
  11308. foreach ($range as $k => $ws) {
  11309. $cws = count($ws);
  11310. if (($k == $nextk) AND (!$prevint) AND ((!isset($ws['interval'])) OR ($cws < 4))) {
  11311. if (isset($range[$k]['interval'])) {
  11312. unset($range[$k]['interval']);
  11313. }
  11314. $range[$prevk] = array_merge($range[$prevk], $range[$k]);
  11315. unset($range[$k]);
  11316. } else {
  11317. $prevk = $k;
  11318. }
  11319. $nextk = $k + $cws;
  11320. if (isset($ws['interval'])) {
  11321. if ($cws > 3) {
  11322. $prevint = true;
  11323. } else {
  11324. $prevint = false;
  11325. }
  11326. if (isset($range[$k]['interval'])) {
  11327. unset($range[$k]['interval']);
  11328. }
  11329. --$nextk;
  11330. } else {
  11331. $prevint = false;
  11332. }
  11333. }
  11334. // output data
  11335. $w = '';
  11336. foreach ($range as $k => $ws) {
  11337. if (count(array_count_values($ws)) == 1) {
  11338. // interval mode is more compact
  11339. $w .= ' '.$k.' '.($k + count($ws) - 1).' '.$ws[0];
  11340. } else {
  11341. // range mode
  11342. $w .= ' '.$k.' [ '.implode(' ', $ws).' ]';
  11343. }
  11344. }
  11345. return '/W ['.$w.' ]';
  11346. }
  11347. /**
  11348. * Output fonts.
  11349. * @author Nicola Asuni
  11350. * @protected
  11351. */
  11352. protected function _putfonts() {
  11353. $nf = $this->n;
  11354. foreach ($this->diffs as $diff) {
  11355. //Encodings
  11356. $this->_newobj();
  11357. $this->_out('<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.'] >>'."\n".'endobj');
  11358. }
  11359. $mqr = $this->get_mqr();
  11360. $this->set_mqr(false);
  11361. foreach ($this->FontFiles as $file => $info) {
  11362. // search and get font file to embedd
  11363. $fontdir = $info['fontdir'];
  11364. $file = strtolower($file);
  11365. $fontfile = '';
  11366. // search files on various directories
  11367. if (($fontdir !== false) AND file_exists($fontdir.$file)) {
  11368. $fontfile = $fontdir.$file;
  11369. } elseif (file_exists($this->_getfontpath().$file)) {
  11370. $fontfile = $this->_getfontpath().$file;
  11371. } elseif (file_exists($file)) {
  11372. $fontfile = $file;
  11373. }
  11374. if (!$this->empty_string($fontfile)) {
  11375. $font = file_get_contents($fontfile);
  11376. $compressed = (substr($file, -2) == '.z');
  11377. if ((!$compressed) AND (isset($info['length2']))) {
  11378. $header = (ord($font{0}) == 128);
  11379. if ($header) {
  11380. // strip first binary header
  11381. $font = substr($font, 6);
  11382. }
  11383. if ($header AND (ord($font[$info['length1']]) == 128)) {
  11384. // strip second binary header
  11385. $font = substr($font, 0, $info['length1']).substr($font, ($info['length1'] + 6));
  11386. }
  11387. } elseif ($info['subset'] AND ((!$compressed) OR ($compressed AND function_exists('gzcompress')))) {
  11388. if ($compressed) {
  11389. // uncompress font
  11390. $font = gzuncompress($font);
  11391. }
  11392. // merge subset characters
  11393. $subsetchars = array(); // used chars
  11394. foreach ($info['fontkeys'] as $fontkey) {
  11395. $fontinfo = $this->getFontBuffer($fontkey);
  11396. $subsetchars += $fontinfo['subsetchars'];
  11397. }
  11398. // rebuild a font subset
  11399. $font = $this->_getTrueTypeFontSubset($font, $subsetchars);
  11400. // calculate new font length
  11401. $info['length1'] = strlen($font);
  11402. if ($compressed) {
  11403. // recompress font
  11404. $font = gzcompress($font);
  11405. }
  11406. }
  11407. $this->_newobj();
  11408. $this->FontFiles[$file]['n'] = $this->n;
  11409. $stream = $this->_getrawstream($font);
  11410. $out = '<< /Length '.strlen($stream);
  11411. if ($compressed) {
  11412. $out .= ' /Filter /FlateDecode';
  11413. }
  11414. $out .= ' /Length1 '.$info['length1'];
  11415. if (isset($info['length2'])) {
  11416. $out .= ' /Length2 '.$info['length2'].' /Length3 0';
  11417. }
  11418. $out .= ' >>';
  11419. $out .= ' stream'."\n".$stream."\n".'endstream';
  11420. $out .= "\n".'endobj';
  11421. $this->_out($out);
  11422. }
  11423. }
  11424. $this->set_mqr($mqr);
  11425. foreach ($this->fontkeys as $k) {
  11426. //Font objects
  11427. $font = $this->getFontBuffer($k);
  11428. $type = $font['type'];
  11429. $name = $font['name'];
  11430. if ($type == 'core') {
  11431. // standard core font
  11432. $out = $this->_getobj($this->font_obj_ids[$k])."\n";
  11433. $out .= '<</Type /Font';
  11434. $out .= ' /Subtype /Type1';
  11435. $out .= ' /BaseFont /'.$name;
  11436. $out .= ' /Name /F'.$font['i'];
  11437. if ((strtolower($name) != 'symbol') AND (strtolower($name) != 'zapfdingbats')) {
  11438. $out .= ' /Encoding /WinAnsiEncoding';
  11439. }
  11440. if ($k == 'helvetica') {
  11441. // add default font for annotations
  11442. $this->annotation_fonts[$k] = $font['i'];
  11443. }
  11444. $out .= ' >>';
  11445. $out .= "\n".'endobj';
  11446. $this->_out($out);
  11447. } elseif (($type == 'Type1') OR ($type == 'TrueType')) {
  11448. // additional Type1 or TrueType font
  11449. $out = $this->_getobj($this->font_obj_ids[$k])."\n";
  11450. $out .= '<</Type /Font';
  11451. $out .= ' /Subtype /'.$type;
  11452. $out .= ' /BaseFont /'.$name;
  11453. $out .= ' /Name /F'.$font['i'];
  11454. $out .= ' /FirstChar 32 /LastChar 255';
  11455. $out .= ' /Widths '.($this->n + 1).' 0 R';
  11456. $out .= ' /FontDescriptor '.($this->n + 2).' 0 R';
  11457. if ($font['enc']) {
  11458. if (isset($font['diff'])) {
  11459. $out .= ' /Encoding '.($nf + $font['diff']).' 0 R';
  11460. } else {
  11461. $out .= ' /Encoding /WinAnsiEncoding';
  11462. }
  11463. }
  11464. $out .= ' >>';
  11465. $out .= "\n".'endobj';
  11466. $this->_out($out);
  11467. // Widths
  11468. $this->_newobj();
  11469. $s = '[';
  11470. for ($i = 32; $i < 256; ++$i) {
  11471. if (isset($font['cw'][$i])) {
  11472. $s .= $font['cw'][$i].' ';
  11473. } else {
  11474. $s .= $font['dw'].' ';
  11475. }
  11476. }
  11477. $s .= ']';
  11478. $s .= "\n".'endobj';
  11479. $this->_out($s);
  11480. //Descriptor
  11481. $this->_newobj();
  11482. $s = '<</Type /FontDescriptor /FontName /'.$name;
  11483. foreach ($font['desc'] as $fdk => $fdv) {
  11484. if (is_float($fdv)) {
  11485. $fdv = sprintf('%F', $fdv);
  11486. }
  11487. $s .= ' /'.$fdk.' '.$fdv.'';
  11488. }
  11489. if (!$this->empty_string($font['file'])) {
  11490. $s .= ' /FontFile'.($type == 'Type1' ? '' : '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R';
  11491. }
  11492. $s .= '>>';
  11493. $s .= "\n".'endobj';
  11494. $this->_out($s);
  11495. } else {
  11496. // additional types
  11497. $mtd = '_put'.strtolower($type);
  11498. if (!method_exists($this, $mtd)) {
  11499. $this->Error('Unsupported font type: '.$type);
  11500. }
  11501. $this->$mtd($font);
  11502. }
  11503. }
  11504. }
  11505. /**
  11506. * Adds unicode fonts.<br>
  11507. * Based on PDF Reference 1.3 (section 5)
  11508. * @param $font (array) font data
  11509. * @protected
  11510. * @author Nicola Asuni
  11511. * @since 1.52.0.TC005 (2005-01-05)
  11512. */
  11513. protected function _puttruetypeunicode($font) {
  11514. $fontname = '';
  11515. if ($font['subset']) {
  11516. // change name for font subsetting
  11517. $subtag = sprintf('%06u', $font['i']);
  11518. $subtag = strtr($subtag, '0123456789', 'ABCDEFGHIJ');
  11519. $fontname .= $subtag.'+';
  11520. }
  11521. $fontname .= $font['name'];
  11522. // Type0 Font
  11523. // A composite font composed of other fonts, organized hierarchically
  11524. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  11525. $out .= '<< /Type /Font';
  11526. $out .= ' /Subtype /Type0';
  11527. $out .= ' /BaseFont /'.$fontname;
  11528. $out .= ' /Name /F'.$font['i'];
  11529. $out .= ' /Encoding /'.$font['enc'];
  11530. $out .= ' /ToUnicode '.($this->n + 1).' 0 R';
  11531. $out .= ' /DescendantFonts ['.($this->n + 2).' 0 R]';
  11532. $out .= ' >>';
  11533. $out .= "\n".'endobj';
  11534. $this->_out($out);
  11535. // ToUnicode map for Identity-H
  11536. $stream = "/CIDInit /ProcSet findresource begin\n";
  11537. $stream .= "12 dict begin\n";
  11538. $stream .= "begincmap\n";
  11539. $stream .= "/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def\n";
  11540. $stream .= "/CMapName /Adobe-Identity-UCS def\n";
  11541. $stream .= "/CMapType 2 def\n";
  11542. $stream .= "/WMode 0 def\n";
  11543. $stream .= "1 begincodespacerange\n";
  11544. $stream .= "<0000> <FFFF>\n";
  11545. $stream .= "endcodespacerange\n";
  11546. $stream .= "100 beginbfrange\n";
  11547. $stream .= "<0000> <00ff> <0000>\n";
  11548. $stream .= "<0100> <01ff> <0100>\n";
  11549. $stream .= "<0200> <02ff> <0200>\n";
  11550. $stream .= "<0300> <03ff> <0300>\n";
  11551. $stream .= "<0400> <04ff> <0400>\n";
  11552. $stream .= "<0500> <05ff> <0500>\n";
  11553. $stream .= "<0600> <06ff> <0600>\n";
  11554. $stream .= "<0700> <07ff> <0700>\n";
  11555. $stream .= "<0800> <08ff> <0800>\n";
  11556. $stream .= "<0900> <09ff> <0900>\n";
  11557. $stream .= "<0a00> <0aff> <0a00>\n";
  11558. $stream .= "<0b00> <0bff> <0b00>\n";
  11559. $stream .= "<0c00> <0cff> <0c00>\n";
  11560. $stream .= "<0d00> <0dff> <0d00>\n";
  11561. $stream .= "<0e00> <0eff> <0e00>\n";
  11562. $stream .= "<0f00> <0fff> <0f00>\n";
  11563. $stream .= "<1000> <10ff> <1000>\n";
  11564. $stream .= "<1100> <11ff> <1100>\n";
  11565. $stream .= "<1200> <12ff> <1200>\n";
  11566. $stream .= "<1300> <13ff> <1300>\n";
  11567. $stream .= "<1400> <14ff> <1400>\n";
  11568. $stream .= "<1500> <15ff> <1500>\n";
  11569. $stream .= "<1600> <16ff> <1600>\n";
  11570. $stream .= "<1700> <17ff> <1700>\n";
  11571. $stream .= "<1800> <18ff> <1800>\n";
  11572. $stream .= "<1900> <19ff> <1900>\n";
  11573. $stream .= "<1a00> <1aff> <1a00>\n";
  11574. $stream .= "<1b00> <1bff> <1b00>\n";
  11575. $stream .= "<1c00> <1cff> <1c00>\n";
  11576. $stream .= "<1d00> <1dff> <1d00>\n";
  11577. $stream .= "<1e00> <1eff> <1e00>\n";
  11578. $stream .= "<1f00> <1fff> <1f00>\n";
  11579. $stream .= "<2000> <20ff> <2000>\n";
  11580. $stream .= "<2100> <21ff> <2100>\n";
  11581. $stream .= "<2200> <22ff> <2200>\n";
  11582. $stream .= "<2300> <23ff> <2300>\n";
  11583. $stream .= "<2400> <24ff> <2400>\n";
  11584. $stream .= "<2500> <25ff> <2500>\n";
  11585. $stream .= "<2600> <26ff> <2600>\n";
  11586. $stream .= "<2700> <27ff> <2700>\n";
  11587. $stream .= "<2800> <28ff> <2800>\n";
  11588. $stream .= "<2900> <29ff> <2900>\n";
  11589. $stream .= "<2a00> <2aff> <2a00>\n";
  11590. $stream .= "<2b00> <2bff> <2b00>\n";
  11591. $stream .= "<2c00> <2cff> <2c00>\n";
  11592. $stream .= "<2d00> <2dff> <2d00>\n";
  11593. $stream .= "<2e00> <2eff> <2e00>\n";
  11594. $stream .= "<2f00> <2fff> <2f00>\n";
  11595. $stream .= "<3000> <30ff> <3000>\n";
  11596. $stream .= "<3100> <31ff> <3100>\n";
  11597. $stream .= "<3200> <32ff> <3200>\n";
  11598. $stream .= "<3300> <33ff> <3300>\n";
  11599. $stream .= "<3400> <34ff> <3400>\n";
  11600. $stream .= "<3500> <35ff> <3500>\n";
  11601. $stream .= "<3600> <36ff> <3600>\n";
  11602. $stream .= "<3700> <37ff> <3700>\n";
  11603. $stream .= "<3800> <38ff> <3800>\n";
  11604. $stream .= "<3900> <39ff> <3900>\n";
  11605. $stream .= "<3a00> <3aff> <3a00>\n";
  11606. $stream .= "<3b00> <3bff> <3b00>\n";
  11607. $stream .= "<3c00> <3cff> <3c00>\n";
  11608. $stream .= "<3d00> <3dff> <3d00>\n";
  11609. $stream .= "<3e00> <3eff> <3e00>\n";
  11610. $stream .= "<3f00> <3fff> <3f00>\n";
  11611. $stream .= "<4000> <40ff> <4000>\n";
  11612. $stream .= "<4100> <41ff> <4100>\n";
  11613. $stream .= "<4200> <42ff> <4200>\n";
  11614. $stream .= "<4300> <43ff> <4300>\n";
  11615. $stream .= "<4400> <44ff> <4400>\n";
  11616. $stream .= "<4500> <45ff> <4500>\n";
  11617. $stream .= "<4600> <46ff> <4600>\n";
  11618. $stream .= "<4700> <47ff> <4700>\n";
  11619. $stream .= "<4800> <48ff> <4800>\n";
  11620. $stream .= "<4900> <49ff> <4900>\n";
  11621. $stream .= "<4a00> <4aff> <4a00>\n";
  11622. $stream .= "<4b00> <4bff> <4b00>\n";
  11623. $stream .= "<4c00> <4cff> <4c00>\n";
  11624. $stream .= "<4d00> <4dff> <4d00>\n";
  11625. $stream .= "<4e00> <4eff> <4e00>\n";
  11626. $stream .= "<4f00> <4fff> <4f00>\n";
  11627. $stream .= "<5000> <50ff> <5000>\n";
  11628. $stream .= "<5100> <51ff> <5100>\n";
  11629. $stream .= "<5200> <52ff> <5200>\n";
  11630. $stream .= "<5300> <53ff> <5300>\n";
  11631. $stream .= "<5400> <54ff> <5400>\n";
  11632. $stream .= "<5500> <55ff> <5500>\n";
  11633. $stream .= "<5600> <56ff> <5600>\n";
  11634. $stream .= "<5700> <57ff> <5700>\n";
  11635. $stream .= "<5800> <58ff> <5800>\n";
  11636. $stream .= "<5900> <59ff> <5900>\n";
  11637. $stream .= "<5a00> <5aff> <5a00>\n";
  11638. $stream .= "<5b00> <5bff> <5b00>\n";
  11639. $stream .= "<5c00> <5cff> <5c00>\n";
  11640. $stream .= "<5d00> <5dff> <5d00>\n";
  11641. $stream .= "<5e00> <5eff> <5e00>\n";
  11642. $stream .= "<5f00> <5fff> <5f00>\n";
  11643. $stream .= "<6000> <60ff> <6000>\n";
  11644. $stream .= "<6100> <61ff> <6100>\n";
  11645. $stream .= "<6200> <62ff> <6200>\n";
  11646. $stream .= "<6300> <63ff> <6300>\n";
  11647. $stream .= "endbfrange\n";
  11648. $stream .= "100 beginbfrange\n";
  11649. $stream .= "<6400> <64ff> <6400>\n";
  11650. $stream .= "<6500> <65ff> <6500>\n";
  11651. $stream .= "<6600> <66ff> <6600>\n";
  11652. $stream .= "<6700> <67ff> <6700>\n";
  11653. $stream .= "<6800> <68ff> <6800>\n";
  11654. $stream .= "<6900> <69ff> <6900>\n";
  11655. $stream .= "<6a00> <6aff> <6a00>\n";
  11656. $stream .= "<6b00> <6bff> <6b00>\n";
  11657. $stream .= "<6c00> <6cff> <6c00>\n";
  11658. $stream .= "<6d00> <6dff> <6d00>\n";
  11659. $stream .= "<6e00> <6eff> <6e00>\n";
  11660. $stream .= "<6f00> <6fff> <6f00>\n";
  11661. $stream .= "<7000> <70ff> <7000>\n";
  11662. $stream .= "<7100> <71ff> <7100>\n";
  11663. $stream .= "<7200> <72ff> <7200>\n";
  11664. $stream .= "<7300> <73ff> <7300>\n";
  11665. $stream .= "<7400> <74ff> <7400>\n";
  11666. $stream .= "<7500> <75ff> <7500>\n";
  11667. $stream .= "<7600> <76ff> <7600>\n";
  11668. $stream .= "<7700> <77ff> <7700>\n";
  11669. $stream .= "<7800> <78ff> <7800>\n";
  11670. $stream .= "<7900> <79ff> <7900>\n";
  11671. $stream .= "<7a00> <7aff> <7a00>\n";
  11672. $stream .= "<7b00> <7bff> <7b00>\n";
  11673. $stream .= "<7c00> <7cff> <7c00>\n";
  11674. $stream .= "<7d00> <7dff> <7d00>\n";
  11675. $stream .= "<7e00> <7eff> <7e00>\n";
  11676. $stream .= "<7f00> <7fff> <7f00>\n";
  11677. $stream .= "<8000> <80ff> <8000>\n";
  11678. $stream .= "<8100> <81ff> <8100>\n";
  11679. $stream .= "<8200> <82ff> <8200>\n";
  11680. $stream .= "<8300> <83ff> <8300>\n";
  11681. $stream .= "<8400> <84ff> <8400>\n";
  11682. $stream .= "<8500> <85ff> <8500>\n";
  11683. $stream .= "<8600> <86ff> <8600>\n";
  11684. $stream .= "<8700> <87ff> <8700>\n";
  11685. $stream .= "<8800> <88ff> <8800>\n";
  11686. $stream .= "<8900> <89ff> <8900>\n";
  11687. $stream .= "<8a00> <8aff> <8a00>\n";
  11688. $stream .= "<8b00> <8bff> <8b00>\n";
  11689. $stream .= "<8c00> <8cff> <8c00>\n";
  11690. $stream .= "<8d00> <8dff> <8d00>\n";
  11691. $stream .= "<8e00> <8eff> <8e00>\n";
  11692. $stream .= "<8f00> <8fff> <8f00>\n";
  11693. $stream .= "<9000> <90ff> <9000>\n";
  11694. $stream .= "<9100> <91ff> <9100>\n";
  11695. $stream .= "<9200> <92ff> <9200>\n";
  11696. $stream .= "<9300> <93ff> <9300>\n";
  11697. $stream .= "<9400> <94ff> <9400>\n";
  11698. $stream .= "<9500> <95ff> <9500>\n";
  11699. $stream .= "<9600> <96ff> <9600>\n";
  11700. $stream .= "<9700> <97ff> <9700>\n";
  11701. $stream .= "<9800> <98ff> <9800>\n";
  11702. $stream .= "<9900> <99ff> <9900>\n";
  11703. $stream .= "<9a00> <9aff> <9a00>\n";
  11704. $stream .= "<9b00> <9bff> <9b00>\n";
  11705. $stream .= "<9c00> <9cff> <9c00>\n";
  11706. $stream .= "<9d00> <9dff> <9d00>\n";
  11707. $stream .= "<9e00> <9eff> <9e00>\n";
  11708. $stream .= "<9f00> <9fff> <9f00>\n";
  11709. $stream .= "<a000> <a0ff> <a000>\n";
  11710. $stream .= "<a100> <a1ff> <a100>\n";
  11711. $stream .= "<a200> <a2ff> <a200>\n";
  11712. $stream .= "<a300> <a3ff> <a300>\n";
  11713. $stream .= "<a400> <a4ff> <a400>\n";
  11714. $stream .= "<a500> <a5ff> <a500>\n";
  11715. $stream .= "<a600> <a6ff> <a600>\n";
  11716. $stream .= "<a700> <a7ff> <a700>\n";
  11717. $stream .= "<a800> <a8ff> <a800>\n";
  11718. $stream .= "<a900> <a9ff> <a900>\n";
  11719. $stream .= "<aa00> <aaff> <aa00>\n";
  11720. $stream .= "<ab00> <abff> <ab00>\n";
  11721. $stream .= "<ac00> <acff> <ac00>\n";
  11722. $stream .= "<ad00> <adff> <ad00>\n";
  11723. $stream .= "<ae00> <aeff> <ae00>\n";
  11724. $stream .= "<af00> <afff> <af00>\n";
  11725. $stream .= "<b000> <b0ff> <b000>\n";
  11726. $stream .= "<b100> <b1ff> <b100>\n";
  11727. $stream .= "<b200> <b2ff> <b200>\n";
  11728. $stream .= "<b300> <b3ff> <b300>\n";
  11729. $stream .= "<b400> <b4ff> <b400>\n";
  11730. $stream .= "<b500> <b5ff> <b500>\n";
  11731. $stream .= "<b600> <b6ff> <b600>\n";
  11732. $stream .= "<b700> <b7ff> <b700>\n";
  11733. $stream .= "<b800> <b8ff> <b800>\n";
  11734. $stream .= "<b900> <b9ff> <b900>\n";
  11735. $stream .= "<ba00> <baff> <ba00>\n";
  11736. $stream .= "<bb00> <bbff> <bb00>\n";
  11737. $stream .= "<bc00> <bcff> <bc00>\n";
  11738. $stream .= "<bd00> <bdff> <bd00>\n";
  11739. $stream .= "<be00> <beff> <be00>\n";
  11740. $stream .= "<bf00> <bfff> <bf00>\n";
  11741. $stream .= "<c000> <c0ff> <c000>\n";
  11742. $stream .= "<c100> <c1ff> <c100>\n";
  11743. $stream .= "<c200> <c2ff> <c200>\n";
  11744. $stream .= "<c300> <c3ff> <c300>\n";
  11745. $stream .= "<c400> <c4ff> <c400>\n";
  11746. $stream .= "<c500> <c5ff> <c500>\n";
  11747. $stream .= "<c600> <c6ff> <c600>\n";
  11748. $stream .= "<c700> <c7ff> <c700>\n";
  11749. $stream .= "endbfrange\n";
  11750. $stream .= "56 beginbfrange\n";
  11751. $stream .= "<c800> <c8ff> <c800>\n";
  11752. $stream .= "<c900> <c9ff> <c900>\n";
  11753. $stream .= "<ca00> <caff> <ca00>\n";
  11754. $stream .= "<cb00> <cbff> <cb00>\n";
  11755. $stream .= "<cc00> <ccff> <cc00>\n";
  11756. $stream .= "<cd00> <cdff> <cd00>\n";
  11757. $stream .= "<ce00> <ceff> <ce00>\n";
  11758. $stream .= "<cf00> <cfff> <cf00>\n";
  11759. $stream .= "<d000> <d0ff> <d000>\n";
  11760. $stream .= "<d100> <d1ff> <d100>\n";
  11761. $stream .= "<d200> <d2ff> <d200>\n";
  11762. $stream .= "<d300> <d3ff> <d300>\n";
  11763. $stream .= "<d400> <d4ff> <d400>\n";
  11764. $stream .= "<d500> <d5ff> <d500>\n";
  11765. $stream .= "<d600> <d6ff> <d600>\n";
  11766. $stream .= "<d700> <d7ff> <d700>\n";
  11767. $stream .= "<d800> <d8ff> <d800>\n";
  11768. $stream .= "<d900> <d9ff> <d900>\n";
  11769. $stream .= "<da00> <daff> <da00>\n";
  11770. $stream .= "<db00> <dbff> <db00>\n";
  11771. $stream .= "<dc00> <dcff> <dc00>\n";
  11772. $stream .= "<dd00> <ddff> <dd00>\n";
  11773. $stream .= "<de00> <deff> <de00>\n";
  11774. $stream .= "<df00> <dfff> <df00>\n";
  11775. $stream .= "<e000> <e0ff> <e000>\n";
  11776. $stream .= "<e100> <e1ff> <e100>\n";
  11777. $stream .= "<e200> <e2ff> <e200>\n";
  11778. $stream .= "<e300> <e3ff> <e300>\n";
  11779. $stream .= "<e400> <e4ff> <e400>\n";
  11780. $stream .= "<e500> <e5ff> <e500>\n";
  11781. $stream .= "<e600> <e6ff> <e600>\n";
  11782. $stream .= "<e700> <e7ff> <e700>\n";
  11783. $stream .= "<e800> <e8ff> <e800>\n";
  11784. $stream .= "<e900> <e9ff> <e900>\n";
  11785. $stream .= "<ea00> <eaff> <ea00>\n";
  11786. $stream .= "<eb00> <ebff> <eb00>\n";
  11787. $stream .= "<ec00> <ecff> <ec00>\n";
  11788. $stream .= "<ed00> <edff> <ed00>\n";
  11789. $stream .= "<ee00> <eeff> <ee00>\n";
  11790. $stream .= "<ef00> <efff> <ef00>\n";
  11791. $stream .= "<f000> <f0ff> <f000>\n";
  11792. $stream .= "<f100> <f1ff> <f100>\n";
  11793. $stream .= "<f200> <f2ff> <f200>\n";
  11794. $stream .= "<f300> <f3ff> <f300>\n";
  11795. $stream .= "<f400> <f4ff> <f400>\n";
  11796. $stream .= "<f500> <f5ff> <f500>\n";
  11797. $stream .= "<f600> <f6ff> <f600>\n";
  11798. $stream .= "<f700> <f7ff> <f700>\n";
  11799. $stream .= "<f800> <f8ff> <f800>\n";
  11800. $stream .= "<f900> <f9ff> <f900>\n";
  11801. $stream .= "<fa00> <faff> <fa00>\n";
  11802. $stream .= "<fb00> <fbff> <fb00>\n";
  11803. $stream .= "<fc00> <fcff> <fc00>\n";
  11804. $stream .= "<fd00> <fdff> <fd00>\n";
  11805. $stream .= "<fe00> <feff> <fe00>\n";
  11806. $stream .= "<ff00> <ffff> <ff00>\n";
  11807. $stream .= "endbfrange\n";
  11808. $stream .= "endcmap\n";
  11809. $stream .= "CMapName currentdict /CMap defineresource pop\n";
  11810. $stream .= "end\n";
  11811. $stream .= "end";
  11812. // ToUnicode Object
  11813. $this->_newobj();
  11814. $stream = ($this->compress) ? gzcompress($stream) : $stream;
  11815. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  11816. $stream = $this->_getrawstream($stream);
  11817. $this->_out('<<'.$filter.'/Length '.strlen($stream).'>> stream'."\n".$stream."\n".'endstream'."\n".'endobj');
  11818. // CIDFontType2
  11819. // A CIDFont whose glyph descriptions are based on TrueType font technology
  11820. $oid = $this->_newobj();
  11821. $out = '<< /Type /Font';
  11822. $out .= ' /Subtype /CIDFontType2';
  11823. $out .= ' /BaseFont /'.$fontname;
  11824. // A dictionary containing entries that define the character collection of the CIDFont.
  11825. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  11826. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  11827. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  11828. $out .= ' /CIDSystemInfo << '.$cidinfo.' >>';
  11829. $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
  11830. $out .= ' /DW '.$font['dw']; // default width
  11831. $out .= "\n".$this->_putfontwidths($font, 0);
  11832. if (isset($font['ctg']) AND (!$this->empty_string($font['ctg']))) {
  11833. $out .= "\n".'/CIDToGIDMap '.($this->n + 2).' 0 R';
  11834. }
  11835. $out .= ' >>';
  11836. $out .= "\n".'endobj';
  11837. $this->_out($out);
  11838. // Font descriptor
  11839. // A font descriptor describing the CIDFont default metrics other than its glyph widths
  11840. $this->_newobj();
  11841. $out = '<< /Type /FontDescriptor';
  11842. $out .= ' /FontName /'.$fontname;
  11843. foreach ($font['desc'] as $key => $value) {
  11844. if (is_float($value)) {
  11845. $value = sprintf('%F', $value);
  11846. }
  11847. $out .= ' /'.$key.' '.$value;
  11848. }
  11849. $fontdir = false;
  11850. if (!$this->empty_string($font['file'])) {
  11851. // A stream containing a TrueType font
  11852. $out .= ' /FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R';
  11853. $fontdir = $this->FontFiles[$font['file']]['fontdir'];
  11854. }
  11855. $out .= ' >>';
  11856. $out .= "\n".'endobj';
  11857. $this->_out($out);
  11858. if (isset($font['ctg']) AND (!$this->empty_string($font['ctg']))) {
  11859. $this->_newobj();
  11860. // Embed CIDToGIDMap
  11861. // A specification of the mapping from CIDs to glyph indices
  11862. // search and get CTG font file to embedd
  11863. $ctgfile = strtolower($font['ctg']);
  11864. // search and get ctg font file to embedd
  11865. $fontfile = '';
  11866. // search files on various directories
  11867. if (($fontdir !== false) AND file_exists($fontdir.$ctgfile)) {
  11868. $fontfile = $fontdir.$ctgfile;
  11869. } elseif (file_exists($this->_getfontpath().$ctgfile)) {
  11870. $fontfile = $this->_getfontpath().$ctgfile;
  11871. } elseif (file_exists($ctgfile)) {
  11872. $fontfile = $ctgfile;
  11873. }
  11874. if ($this->empty_string($fontfile)) {
  11875. $this->Error('Font file not found: '.$ctgfile);
  11876. }
  11877. $stream = $this->_getrawstream(file_get_contents($fontfile));
  11878. $out = '<< /Length '.strlen($stream).'';
  11879. if (substr($fontfile, -2) == '.z') { // check file extension
  11880. // Decompresses data encoded using the public-domain
  11881. // zlib/deflate compression method, reproducing the
  11882. // original text or binary data
  11883. $out .= ' /Filter /FlateDecode';
  11884. }
  11885. $out .= ' >>';
  11886. $out .= ' stream'."\n".$stream."\n".'endstream';
  11887. $out .= "\n".'endobj';
  11888. $this->_out($out);
  11889. }
  11890. }
  11891. /**
  11892. * Output CID-0 fonts.
  11893. * A Type 0 CIDFont contains glyph descriptions based on the Adobe Type 1 font format
  11894. * @param $font (array) font data
  11895. * @protected
  11896. * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
  11897. * @since 3.2.000 (2008-06-23)
  11898. */
  11899. protected function _putcidfont0($font) {
  11900. $cidoffset = 0;
  11901. if (!isset($font['cw'][1])) {
  11902. $cidoffset = 31;
  11903. }
  11904. if (isset($font['cidinfo']['uni2cid'])) {
  11905. // convert unicode to cid.
  11906. $uni2cid = $font['cidinfo']['uni2cid'];
  11907. $cw = array();
  11908. foreach ($font['cw'] as $uni => $width) {
  11909. if (isset($uni2cid[$uni])) {
  11910. $cw[($uni2cid[$uni] + $cidoffset)] = $width;
  11911. } elseif ($uni < 256) {
  11912. $cw[$uni] = $width;
  11913. } // else unknown character
  11914. }
  11915. $font = array_merge($font, array('cw' => $cw));
  11916. }
  11917. $name = $font['name'];
  11918. $enc = $font['enc'];
  11919. if ($enc) {
  11920. $longname = $name.'-'.$enc;
  11921. } else {
  11922. $longname = $name;
  11923. }
  11924. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  11925. $out .= '<</Type /Font';
  11926. $out .= ' /Subtype /Type0';
  11927. $out .= ' /BaseFont /'.$longname;
  11928. $out .= ' /Name /F'.$font['i'];
  11929. if ($enc) {
  11930. $out .= ' /Encoding /'.$enc;
  11931. }
  11932. $out .= ' /DescendantFonts ['.($this->n + 1).' 0 R]';
  11933. $out .= ' >>';
  11934. $out .= "\n".'endobj';
  11935. $this->_out($out);
  11936. $oid = $this->_newobj();
  11937. $out = '<</Type /Font';
  11938. $out .= ' /Subtype /CIDFontType0';
  11939. $out .= ' /BaseFont /'.$name;
  11940. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  11941. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  11942. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  11943. $out .= ' /CIDSystemInfo <<'.$cidinfo.'>>';
  11944. $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
  11945. $out .= ' /DW '.$font['dw'];
  11946. $out .= "\n".$this->_putfontwidths($font, $cidoffset);
  11947. $out .= ' >>';
  11948. $out .= "\n".'endobj';
  11949. $this->_out($out);
  11950. $this->_newobj();
  11951. $s = '<</Type /FontDescriptor /FontName /'.$name;
  11952. foreach ($font['desc'] as $k => $v) {
  11953. if ($k != 'Style') {
  11954. if (is_float($v)) {
  11955. $v = sprintf('%F', $v);
  11956. }
  11957. $s .= ' /'.$k.' '.$v.'';
  11958. }
  11959. }
  11960. $s .= '>>';
  11961. $s .= "\n".'endobj';
  11962. $this->_out($s);
  11963. }
  11964. /**
  11965. * Output images.
  11966. * @protected
  11967. */
  11968. protected function _putimages() {
  11969. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  11970. foreach ($this->imagekeys as $file) {
  11971. $info = $this->getImageBuffer($file);
  11972. // set object for alternate images array
  11973. if ((!$this->pdfa_mode) AND isset($info['altimgs']) AND !empty($info['altimgs'])) {
  11974. $altoid = $this->_newobj();
  11975. $out = '[';
  11976. foreach ($info['altimgs'] as $altimage) {
  11977. if (isset($this->xobjects['I'.$altimage[0]]['n'])) {
  11978. $out .= ' << /Image '.$this->xobjects['I'.$altimage[0]]['n'].' 0 R';
  11979. $out .= ' /DefaultForPrinting';
  11980. if ($altimage[1] === true) {
  11981. $out .= ' true';
  11982. } else {
  11983. $out .= ' false';
  11984. }
  11985. $out .= ' >>';
  11986. }
  11987. }
  11988. $out .= ' ]';
  11989. $out .= "\n".'endobj';
  11990. $this->_out($out);
  11991. }
  11992. // set image object
  11993. $oid = $this->_newobj();
  11994. $this->xobjects['I'.$info['i']] = array('n' => $oid);
  11995. $this->setImageSubBuffer($file, 'n', $this->n);
  11996. $out = '<</Type /XObject';
  11997. $out .= ' /Subtype /Image';
  11998. $out .= ' /Width '.$info['w'];
  11999. $out .= ' /Height '.$info['h'];
  12000. if (array_key_exists('masked', $info)) {
  12001. $out .= ' /SMask '.($this->n - 1).' 0 R';
  12002. }
  12003. // set color space
  12004. $icc = false;
  12005. if (isset($info['icc']) AND ($info['icc'] !== false)) {
  12006. // ICC Colour Space
  12007. $icc = true;
  12008. $out .= ' /ColorSpace [/ICCBased '.($this->n + 1).' 0 R]';
  12009. } elseif ($info['cs'] == 'Indexed') {
  12010. // Indexed Colour Space
  12011. $out .= ' /ColorSpace [/Indexed /DeviceRGB '.((strlen($info['pal']) / 3) - 1).' '.($this->n + 1).' 0 R]';
  12012. } else {
  12013. // Device Colour Space
  12014. $out .= ' /ColorSpace /'.$info['cs'];
  12015. }
  12016. if ($info['cs'] == 'DeviceCMYK') {
  12017. $out .= ' /Decode [1 0 1 0 1 0 1 0]';
  12018. }
  12019. $out .= ' /BitsPerComponent '.$info['bpc'];
  12020. if (isset($altoid) AND ($altoid > 0)) {
  12021. // reference to alternate images dictionary
  12022. $out .= ' /Alternates '.$altoid.' 0 R';
  12023. }
  12024. if (isset($info['exurl']) AND !empty($info['exurl'])) {
  12025. // external stream
  12026. $out .= ' /Length 0';
  12027. $out .= ' /F << /FS /URL /F '.$this->_datastring($info['exurl'], $oid).' >>';
  12028. if (isset($info['f'])) {
  12029. $out .= ' /FFilter /'.$info['f'];
  12030. }
  12031. $out .= ' >>';
  12032. $out .= ' stream'."\n".'endstream';
  12033. } else {
  12034. if (isset($info['f'])) {
  12035. $out .= ' /Filter /'.$info['f'];
  12036. }
  12037. if (isset($info['parms'])) {
  12038. $out .= ' '.$info['parms'];
  12039. }
  12040. if (isset($info['trns']) AND is_array($info['trns'])) {
  12041. $trns = '';
  12042. $count_info = count($info['trns']);
  12043. for ($i=0; $i < $count_info; ++$i) {
  12044. $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
  12045. }
  12046. $out .= ' /Mask ['.$trns.']';
  12047. }
  12048. $stream = $this->_getrawstream($info['data']);
  12049. $out .= ' /Length '.strlen($stream).' >>';
  12050. $out .= ' stream'."\n".$stream."\n".'endstream';
  12051. }
  12052. $out .= "\n".'endobj';
  12053. $this->_out($out);
  12054. if ($icc) {
  12055. // ICC colour profile
  12056. $this->_newobj();
  12057. $icc = ($this->compress) ? gzcompress($info['icc']) : $info['icc'];
  12058. $icc = $this->_getrawstream($icc);
  12059. $this->_out('<</N '.$info['ch'].' /Alternate /'.$info['cs'].' '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
  12060. } elseif ($info['cs'] == 'Indexed') {
  12061. // colour palette
  12062. $this->_newobj();
  12063. $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  12064. $pal = $this->_getrawstream($pal);
  12065. $this->_out('<<'.$filter.'/Length '.strlen($pal).'>> stream'."\n".$pal."\n".'endstream'."\n".'endobj');
  12066. }
  12067. }
  12068. }
  12069. /**
  12070. * Output Form XObjects Templates.
  12071. * @author Nicola Asuni
  12072. * @since 5.8.017 (2010-08-24)
  12073. * @protected
  12074. * @see startTemplate(), endTemplate(), printTemplate()
  12075. */
  12076. protected function _putxobjects() {
  12077. foreach ($this->xobjects as $key => $data) {
  12078. if (isset($data['outdata'])) {
  12079. $stream = trim($data['outdata']);
  12080. $out = $this->_getobj($data['n'])."\n";
  12081. $out .= '<<';
  12082. $out .= ' /Type /XObject';
  12083. $out .= ' /Subtype /Form';
  12084. $out .= ' /FormType 1';
  12085. if ($this->compress) {
  12086. $stream = gzcompress($stream);
  12087. $out .= ' /Filter /FlateDecode';
  12088. }
  12089. $out .= sprintf(' /BBox [%F %F %F %F]', ($data['x'] * $this->k), (-$data['y'] * $this->k), (($data['w'] + $data['x']) * $this->k), (($data['h'] - $data['y']) * $this->k));
  12090. $out .= ' /Matrix [1 0 0 1 0 0]';
  12091. $out .= ' /Resources <<';
  12092. $out .= ' /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  12093. if (!$this->pdfa_mode) {
  12094. // transparency
  12095. if (isset($data['extgstates']) AND !empty($data['extgstates'])) {
  12096. $out .= ' /ExtGState <<';
  12097. foreach ($data['extgstates'] as $k => $extgstate) {
  12098. if (isset($this->extgstates[$k]['name'])) {
  12099. $out .= ' /'.$this->extgstates[$k]['name'];
  12100. } else {
  12101. $out .= ' /GS'.$k;
  12102. }
  12103. $out .= ' '.$this->extgstates[$k]['n'].' 0 R';
  12104. }
  12105. $out .= ' >>';
  12106. }
  12107. if (isset($data['gradients']) AND !empty($data['gradients'])) {
  12108. $gp = '';
  12109. $gs = '';
  12110. foreach ($data['gradients'] as $id => $grad) {
  12111. // gradient patterns
  12112. $gp .= ' /p'.$id.' '.$this->gradients[$id]['pattern'].' 0 R';
  12113. // gradient shadings
  12114. $gs .= ' /Sh'.$id.' '.$this->gradients[$id]['id'].' 0 R';
  12115. }
  12116. $out .= ' /Pattern <<'.$gp.' >>';
  12117. $out .= ' /Shading <<'.$gs.' >>';
  12118. }
  12119. }
  12120. // spot colors
  12121. if (isset($data['spot_colors']) AND !empty($data['spot_colors'])) {
  12122. $out .= ' /ColorSpace <<';
  12123. foreach ($data['spot_colors'] as $name => $color) {
  12124. $out .= ' /CS'.$color['i'].' '.$this->spot_colors[$name]['n'].' 0 R';
  12125. }
  12126. $out .= ' >>';
  12127. }
  12128. // fonts
  12129. if (!empty($data['fonts'])) {
  12130. $out .= ' /Font <<';
  12131. foreach ($data['fonts'] as $fontkey => $fontid) {
  12132. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  12133. }
  12134. $out .= ' >>';
  12135. }
  12136. // images or nested xobjects
  12137. if (!empty($data['images']) OR !empty($data['xobjects'])) {
  12138. $out .= ' /XObject <<';
  12139. foreach ($data['images'] as $imgid) {
  12140. $out .= ' /I'.$imgid.' '.$this->xobjects['I'.$imgid]['n'].' 0 R';
  12141. }
  12142. foreach ($data['xobjects'] as $sub_id => $sub_objid) {
  12143. $out .= ' /'.$sub_id.' '.$sub_objid['n'].' 0 R';
  12144. }
  12145. $out .= ' >>';
  12146. }
  12147. $out .= ' >>'; //end resources
  12148. if (isset($data['group']) AND ($data['group'] !== false)) {
  12149. // set transparency group
  12150. $out .= ' /Group << /Type /Group /S /Transparency';
  12151. if (is_array($data['group'])) {
  12152. if (isset($data['group']['CS']) AND !empty($data['group']['CS'])) {
  12153. $out .= ' /CS /'.$data['group']['CS'];
  12154. }
  12155. if (isset($data['group']['I'])) {
  12156. $out .= ' /I /'.($data['group']['I']===true?'true':'false');
  12157. }
  12158. if (isset($data['group']['K'])) {
  12159. $out .= ' /K /'.($data['group']['K']===true?'true':'false');
  12160. }
  12161. }
  12162. $out .= ' >>';
  12163. }
  12164. $stream = $this->_getrawstream($stream, $data['n']);
  12165. $out .= ' /Length '.strlen($stream);
  12166. $out .= ' >>';
  12167. $out .= ' stream'."\n".$stream."\n".'endstream';
  12168. $out .= "\n".'endobj';
  12169. $this->_out($out);
  12170. }
  12171. }
  12172. }
  12173. /**
  12174. * Output Spot Colors Resources.
  12175. * @protected
  12176. * @since 4.0.024 (2008-09-12)
  12177. */
  12178. protected function _putspotcolors() {
  12179. foreach ($this->spot_colors as $name => $color) {
  12180. $this->_newobj();
  12181. $this->spot_colors[$name]['n'] = $this->n;
  12182. $out = '[/Separation /'.str_replace(' ', '#20', $name);
  12183. $out .= ' /DeviceCMYK <<';
  12184. $out .= ' /Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0]';
  12185. $out .= ' '.sprintf('/C1 [%F %F %F %F] ', ($color['C'] / 100), ($color['M'] / 100), ($color['Y'] / 100), ($color['K'] / 100));
  12186. $out .= ' /FunctionType 2 /Domain [0 1] /N 1>>]';
  12187. $out .= "\n".'endobj';
  12188. $this->_out($out);
  12189. }
  12190. }
  12191. /**
  12192. * Return XObjects Dictionary.
  12193. * @return string XObjects dictionary
  12194. * @protected
  12195. * @since 5.8.014 (2010-08-23)
  12196. */
  12197. protected function _getxobjectdict() {
  12198. $out = '';
  12199. foreach ($this->xobjects as $id => $objid) {
  12200. $out .= ' /'.$id.' '.$objid['n'].' 0 R';
  12201. }
  12202. return $out;
  12203. }
  12204. /**
  12205. * Output Resources Dictionary.
  12206. * @protected
  12207. */
  12208. protected function _putresourcedict() {
  12209. $out = $this->_getobj(2)."\n";
  12210. $out .= '<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  12211. $out .= ' /Font <<';
  12212. foreach ($this->fontkeys as $fontkey) {
  12213. $font = $this->getFontBuffer($fontkey);
  12214. $out .= ' /F'.$font['i'].' '.$font['n'].' 0 R';
  12215. }
  12216. $out .= ' >>';
  12217. $out .= ' /XObject <<';
  12218. $out .= $this->_getxobjectdict();
  12219. $out .= ' >>';
  12220. // layers
  12221. if (!empty($this->pdflayers)) {
  12222. $out .= ' /Properties <<';
  12223. foreach ($this->pdflayers as $layer) {
  12224. $out .= ' /'.$layer['layer'].' '.$layer['objid'].' 0 R';
  12225. }
  12226. $out .= ' >>';
  12227. }
  12228. if (!$this->pdfa_mode) {
  12229. // transparency
  12230. if (isset($this->extgstates) AND !empty($this->extgstates)) {
  12231. $out .= ' /ExtGState <<';
  12232. foreach ($this->extgstates as $k => $extgstate) {
  12233. if (isset($extgstate['name'])) {
  12234. $out .= ' /'.$extgstate['name'];
  12235. } else {
  12236. $out .= ' /GS'.$k;
  12237. }
  12238. $out .= ' '.$extgstate['n'].' 0 R';
  12239. }
  12240. $out .= ' >>';
  12241. }
  12242. if (isset($this->gradients) AND !empty($this->gradients)) {
  12243. $gp = '';
  12244. $gs = '';
  12245. foreach ($this->gradients as $id => $grad) {
  12246. // gradient patterns
  12247. $gp .= ' /p'.$id.' '.$grad['pattern'].' 0 R';
  12248. // gradient shadings
  12249. $gs .= ' /Sh'.$id.' '.$grad['id'].' 0 R';
  12250. }
  12251. $out .= ' /Pattern <<'.$gp.' >>';
  12252. $out .= ' /Shading <<'.$gs.' >>';
  12253. }
  12254. }
  12255. // spot colors
  12256. if (isset($this->spot_colors) AND !empty($this->spot_colors)) {
  12257. $out .= ' /ColorSpace <<';
  12258. foreach ($this->spot_colors as $color) {
  12259. $out .= ' /CS'.$color['i'].' '.$color['n'].' 0 R';
  12260. }
  12261. $out .= ' >>';
  12262. }
  12263. $out .= ' >>';
  12264. $out .= "\n".'endobj';
  12265. $this->_out($out);
  12266. }
  12267. /**
  12268. * Output Resources.
  12269. * @protected
  12270. */
  12271. protected function _putresources() {
  12272. $this->_putextgstates();
  12273. $this->_putocg();
  12274. $this->_putfonts();
  12275. $this->_putimages();
  12276. $this->_putspotcolors();
  12277. $this->_putshaders();
  12278. $this->_putxobjects();
  12279. $this->_putresourcedict();
  12280. $this->_putdests();
  12281. $this->_putEmbeddedFiles();
  12282. $this->_putannotsobjs();
  12283. $this->_putjavascript();
  12284. $this->_putbookmarks();
  12285. $this->_putencryption();
  12286. }
  12287. /**
  12288. * Adds some Metadata information (Document Information Dictionary)
  12289. * (see Chapter 14.3.3 Document Information Dictionary of PDF32000_2008.pdf Reference)
  12290. * @return int object id
  12291. * @protected
  12292. */
  12293. protected function _putinfo() {
  12294. $oid = $this->_newobj();
  12295. $out = '<<';
  12296. // store current isunicode value
  12297. $prev_isunicode = $this->isunicode;
  12298. if ($this->docinfounicode) {
  12299. $this->isunicode = true;
  12300. }
  12301. if (!$this->empty_string($this->title)) {
  12302. // The document's title.
  12303. $out .= ' /Title '.$this->_textstring($this->title, $oid);
  12304. }
  12305. if (!$this->empty_string($this->author)) {
  12306. // The name of the person who created the document.
  12307. $out .= ' /Author '.$this->_textstring($this->author, $oid);
  12308. }
  12309. if (!$this->empty_string($this->subject)) {
  12310. // The subject of the document.
  12311. $out .= ' /Subject '.$this->_textstring($this->subject, $oid);
  12312. }
  12313. if (!$this->empty_string($this->keywords)) {
  12314. // Keywords associated with the document.
  12315. $out .= ' /Keywords '.$this->_textstring($this->keywords.' TCPDF', $oid);
  12316. }
  12317. if (!$this->empty_string($this->creator)) {
  12318. // 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.
  12319. $out .= ' /Creator '.$this->_textstring($this->creator, $oid);
  12320. }
  12321. // restore previous isunicode value
  12322. $this->isunicode = $prev_isunicode;
  12323. // default producer
  12324. $out .= ' /Producer '.$this->_textstring($this->pdfproducer, $oid);
  12325. // The date and time the document was created, in human-readable form
  12326. $out .= ' /CreationDate '.$this->_datestring(0, $this->doc_creation_timestamp);
  12327. // The date and time the document was most recently modified, in human-readable form
  12328. $out .= ' /ModDate '.$this->_datestring(0, $this->doc_modification_timestamp);
  12329. // A name object indicating whether the document has been modified to include trapping information
  12330. $out .= ' /Trapped /False';
  12331. $out .= ' >>';
  12332. $out .= "\n".'endobj';
  12333. $this->_out($out);
  12334. return $oid;
  12335. }
  12336. /**
  12337. * Set additional XMP data to be added on the default XMP data just before the end of "x:xmpmeta" tag.
  12338. * IMPORTANT: This data is added as-is without controls, so you have to validate your data before using this method!
  12339. * @param $xmp (string) Custom XMP data.
  12340. * @since 5.9.128 (2011-10-06)
  12341. * @public
  12342. */
  12343. public function setExtraXMP($xmp) {
  12344. $this->custom_xmp = $xmp;
  12345. }
  12346. /**
  12347. * Put XMP data object and return ID.
  12348. * @return (int) The object ID.
  12349. * @since 5.9.121 (2011-09-28)
  12350. * @protected
  12351. */
  12352. protected function _putXMP() {
  12353. $oid = $this->_newobj();
  12354. // store current isunicode value
  12355. $prev_isunicode = $this->isunicode;
  12356. $this->isunicode = true;
  12357. $prev_encrypted = $this->encrypted;
  12358. $this->encrypted = false;
  12359. // set XMP data
  12360. $xmp = '<?xpacket begin="'.$this->unichr(0xfeff).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n";
  12361. $xmp .= '<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.2.1-c043 52.372728, 2009/01/18-15:08:04">'."\n";
  12362. $xmp .= "\t".'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n";
  12363. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
  12364. $xmp .= "\t\t\t".'<dc:format>application/pdf</dc:format>'."\n";
  12365. $xmp .= "\t\t\t".'<dc:title>'."\n";
  12366. $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
  12367. $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.$this->_escapeXML($this->title).'</rdf:li>'."\n";
  12368. $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
  12369. $xmp .= "\t\t\t".'</dc:title>'."\n";
  12370. $xmp .= "\t\t\t".'<dc:creator>'."\n";
  12371. $xmp .= "\t\t\t\t".'<rdf:Seq>'."\n";
  12372. $xmp .= "\t\t\t\t\t".'<rdf:li>'.$this->_escapeXML($this->author).'</rdf:li>'."\n";
  12373. $xmp .= "\t\t\t\t".'</rdf:Seq>'."\n";
  12374. $xmp .= "\t\t\t".'</dc:creator>'."\n";
  12375. $xmp .= "\t\t\t".'<dc:description>'."\n";
  12376. $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
  12377. $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.$this->_escapeXML($this->subject).'</rdf:li>'."\n";
  12378. $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
  12379. $xmp .= "\t\t\t".'</dc:description>'."\n";
  12380. $xmp .= "\t\t\t".'<dc:subject>'."\n";
  12381. $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
  12382. $xmp .= "\t\t\t\t\t".'<rdf:li>'.$this->_escapeXML($this->keywords).' TCPDF</rdf:li>'."\n";
  12383. $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
  12384. $xmp .= "\t\t\t".'</dc:subject>'."\n";
  12385. $xmp .= "\t\t".'</rdf:Description>'."\n";
  12386. // convert doc creation date format
  12387. $dcdate = $this->getFormattedDate($this->doc_creation_timestamp);
  12388. $doccreationdate = substr($dcdate, 0, 4).'-'.substr($dcdate, 4, 2).'-'.substr($dcdate, 6, 2);
  12389. $doccreationdate .= 'T'.substr($dcdate, 8, 2).':'.substr($dcdate, 10, 2).':'.substr($dcdate, 12, 2);
  12390. $doccreationdate .= '+'.substr($dcdate, 15, 2).':'.substr($dcdate, 18, 2);
  12391. $doccreationdate = $this->_escapeXML($doccreationdate);
  12392. // convert doc modification date format
  12393. $dmdate = $this->getFormattedDate($this->doc_modification_timestamp);
  12394. $docmoddate = substr($dmdate, 0, 4).'-'.substr($dmdate, 4, 2).'-'.substr($dmdate, 6, 2);
  12395. $docmoddate .= 'T'.substr($dmdate, 8, 2).':'.substr($dmdate, 10, 2).':'.substr($dmdate, 12, 2);
  12396. $docmoddate .= '+'.substr($dmdate, 15, 2).':'.substr($dmdate, 18, 2);
  12397. $docmoddate = $this->_escapeXML($docmoddate);
  12398. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n";
  12399. $xmp .= "\t\t\t".'<xmp:CreateDate>'.$doccreationdate.'</xmp:CreateDate>'."\n";
  12400. $xmp .= "\t\t\t".'<xmp:CreatorTool>'.$this->creator.'</xmp:CreatorTool>'."\n";
  12401. $xmp .= "\t\t\t".'<xmp:ModifyDate>'.$docmoddate.'</xmp:ModifyDate>'."\n";
  12402. $xmp .= "\t\t\t".'<xmp:MetadataDate>'.$doccreationdate.'</xmp:MetadataDate>'."\n";
  12403. $xmp .= "\t\t".'</rdf:Description>'."\n";
  12404. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n";
  12405. $xmp .= "\t\t\t".'<pdf:Keywords>'.$this->_escapeXML($this->keywords).' TCPDF</pdf:Keywords>'."\n";
  12406. $xmp .= "\t\t\t".'<pdf:Producer>'.$this->_escapeXML($this->pdfproducer).'</pdf:Producer>'."\n";
  12407. $xmp .= "\t\t".'</rdf:Description>'."\n";
  12408. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n";
  12409. $uuid = 'uuid:'.substr($this->file_id, 0, 8).'-'.substr($this->file_id, 8, 4).'-'.substr($this->file_id, 12, 4).'-'.substr($this->file_id, 16, 4).'-'.substr($this->file_id, 20, 12);
  12410. $xmp .= "\t\t\t".'<xmpMM:DocumentID>'.$uuid.'</xmpMM:DocumentID>'."\n";
  12411. $xmp .= "\t\t\t".'<xmpMM:InstanceID>'.$uuid.'</xmpMM:InstanceID>'."\n";
  12412. $xmp .= "\t\t".'</rdf:Description>'."\n";
  12413. if ($this->pdfa_mode) {
  12414. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">'."\n";
  12415. $xmp .= "\t\t\t".'<pdfaid:part>1</pdfaid:part>'."\n";
  12416. $xmp .= "\t\t\t".'<pdfaid:conformance>B</pdfaid:conformance>'."\n";
  12417. $xmp .= "\t\t".'</rdf:Description>'."\n";
  12418. }
  12419. // XMP extension schemas
  12420. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdfaExtension="http://www.aiim.org/pdfa/ns/extension/" xmlns:pdfaSchema="http://www.aiim.org/pdfa/ns/schema#" xmlns:pdfaProperty="http://www.aiim.org/pdfa/ns/property#">'."\n";
  12421. $xmp .= "\t\t\t".'<pdfaExtension:schemas>'."\n";
  12422. $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
  12423. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  12424. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/pdf/1.3/</pdfaSchema:namespaceURI>'."\n";
  12425. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdf</pdfaSchema:prefix>'."\n";
  12426. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>Adobe PDF Schema</pdfaSchema:schema>'."\n";
  12427. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  12428. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  12429. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/xap/1.0/mm/</pdfaSchema:namespaceURI>'."\n";
  12430. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>xmpMM</pdfaSchema:prefix>'."\n";
  12431. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>XMP Media Management Schema</pdfaSchema:schema>'."\n";
  12432. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  12433. $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  12434. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  12435. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  12436. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>UUID based identifier for specific incarnation of a document</pdfaProperty:description>'."\n";
  12437. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>InstanceID</pdfaProperty:name>'."\n";
  12438. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>URI</pdfaProperty:valueType>'."\n";
  12439. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  12440. $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  12441. $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  12442. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  12443. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  12444. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://www.aiim.org/pdfa/ns/id/</pdfaSchema:namespaceURI>'."\n";
  12445. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdfaid</pdfaSchema:prefix>'."\n";
  12446. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>PDF/A ID Schema</pdfaSchema:schema>'."\n";
  12447. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  12448. $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  12449. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  12450. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  12451. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Part of PDF/A standard</pdfaProperty:description>'."\n";
  12452. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>part</pdfaProperty:name>'."\n";
  12453. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Integer</pdfaProperty:valueType>'."\n";
  12454. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  12455. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  12456. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  12457. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Amendment of PDF/A standard</pdfaProperty:description>'."\n";
  12458. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>amd</pdfaProperty:name>'."\n";
  12459. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
  12460. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  12461. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  12462. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  12463. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Conformance level of PDF/A standard</pdfaProperty:description>'."\n";
  12464. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>conformance</pdfaProperty:name>'."\n";
  12465. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
  12466. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  12467. $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  12468. $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  12469. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  12470. $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
  12471. $xmp .= "\t\t\t".'</pdfaExtension:schemas>'."\n";
  12472. $xmp .= "\t\t".'</rdf:Description>'."\n";
  12473. $xmp .= "\t".'</rdf:RDF>'."\n";
  12474. $xmp .= $this->custom_xmp;
  12475. $xmp .= '</x:xmpmeta>'."\n";
  12476. $xmp .= '<?xpacket end="w"?>';
  12477. $out = '<< /Type /Metadata /Subtype /XML /Length '.strlen($xmp).' >> stream'."\n".$xmp."\n".'endstream'."\n".'endobj';
  12478. // restore previous isunicode value
  12479. $this->isunicode = $prev_isunicode;
  12480. $this->encrypted = $prev_encrypted;
  12481. $this->_out($out);
  12482. return $oid;
  12483. }
  12484. /**
  12485. * Output Catalog.
  12486. * @return int object id
  12487. * @protected
  12488. */
  12489. protected function _putcatalog() {
  12490. // put XMP
  12491. $xmpobj = $this->_putXMP();
  12492. // if required, add standard sRGB_IEC61966-2.1 blackscaled ICC colour profile
  12493. if ($this->pdfa_mode OR $this->force_srgb) {
  12494. $iccobj = $this->_newobj();
  12495. $icc = file_get_contents(dirname(__FILE__).'/sRGB.icc');
  12496. $filter = '';
  12497. if ($this->compress) {
  12498. $filter = ' /Filter /FlateDecode';
  12499. $icc = gzcompress($icc);
  12500. }
  12501. $icc = $this->_getrawstream($icc);
  12502. $this->_out('<</N 3 '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
  12503. }
  12504. // start catalog
  12505. $oid = $this->_newobj();
  12506. $out = '<< /Type /Catalog';
  12507. $out .= ' /Version /'.$this->PDFVersion;
  12508. //$out .= ' /Extensions <<>>';
  12509. $out .= ' /Pages 1 0 R';
  12510. //$out .= ' /PageLabels ' //...;
  12511. $out .= ' /Names <<';
  12512. if ((!$this->pdfa_mode) AND !empty($this->n_js)) {
  12513. $out .= ' /JavaScript '.$this->n_js;
  12514. }
  12515. if (!empty($this->efnames)) {
  12516. $out .= ' /EmbeddedFiles <</Names [';
  12517. foreach ($this->efnames AS $fn => $fref) {
  12518. $out .= ' '.$this->_datastring($fn).' '.$fref;
  12519. }
  12520. $out .= ' ]>>';
  12521. }
  12522. $out .= ' >>';
  12523. if (!empty($this->dests)) {
  12524. $out .= ' /Dests '.($this->n_dests).' 0 R';
  12525. }
  12526. $out .= $this->_putviewerpreferences();
  12527. if (isset($this->LayoutMode) AND (!$this->empty_string($this->LayoutMode))) {
  12528. $out .= ' /PageLayout /'.$this->LayoutMode;
  12529. }
  12530. if (isset($this->PageMode) AND (!$this->empty_string($this->PageMode))) {
  12531. $out .= ' /PageMode /'.$this->PageMode;
  12532. }
  12533. if (count($this->outlines) > 0) {
  12534. $out .= ' /Outlines '.$this->OutlineRoot.' 0 R';
  12535. $out .= ' /PageMode /UseOutlines';
  12536. }
  12537. //$out .= ' /Threads []';
  12538. if ($this->ZoomMode == 'fullpage') {
  12539. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /Fit]';
  12540. } elseif ($this->ZoomMode == 'fullwidth') {
  12541. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /FitH null]';
  12542. } elseif ($this->ZoomMode == 'real') {
  12543. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null 1]';
  12544. } elseif (!is_string($this->ZoomMode)) {
  12545. $out .= sprintf(' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null %F]', ($this->ZoomMode / 100));
  12546. }
  12547. //$out .= ' /AA <<>>';
  12548. //$out .= ' /URI <<>>';
  12549. $out .= ' /Metadata '.$xmpobj.' 0 R';
  12550. //$out .= ' /StructTreeRoot <<>>';
  12551. //$out .= ' /MarkInfo <<>>';
  12552. if (isset($this->l['a_meta_language'])) {
  12553. $out .= ' /Lang '.$this->_textstring($this->l['a_meta_language'], $oid);
  12554. }
  12555. //$out .= ' /SpiderInfo <<>>';
  12556. // set OutputIntent to sRGB IEC61966-2.1 if required
  12557. if ($this->pdfa_mode OR $this->force_srgb) {
  12558. $out .= ' /OutputIntents [<<';
  12559. $out .= ' /Type /OutputIntent';
  12560. $out .= ' /S /GTS_PDFA1';
  12561. $out .= ' /OutputCondition '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  12562. $out .= ' /OutputConditionIdentifier '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  12563. $out .= ' /RegistryName '.$this->_textstring('http://www.color.org', $oid);
  12564. $out .= ' /Info '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  12565. $out .= ' /DestOutputProfile '.$iccobj.' 0 R';
  12566. $out .= ' >>]';
  12567. }
  12568. //$out .= ' /PieceInfo <<>>';
  12569. if (!empty($this->pdflayers)) {
  12570. $lyrobjs = '';
  12571. $lyrobjs_print = '';
  12572. $lyrobjs_view = '';
  12573. foreach ($this->pdflayers as $layer) {
  12574. $lyrobjs .= ' '.$layer['objid'].' 0 R';
  12575. if ($layer['print']) {
  12576. $lyrobjs_print .= ' '.$layer['objid'].' 0 R';
  12577. }
  12578. if ($layer['view']) {
  12579. $lyrobjs_view .= ' '.$layer['objid'].' 0 R';
  12580. }
  12581. }
  12582. $out .= ' /OCProperties << /OCGs ['.$lyrobjs.']';
  12583. $out .= ' /D <<';
  12584. $out .= ' /Name '.$this->_textstring('Layers', $oid);
  12585. $out .= ' /Creator '.$this->_textstring('TCPDF', $oid);
  12586. $out .= ' /BaseState /ON';
  12587. $out .= ' /ON ['.$lyrobjs_print.']';
  12588. $out .= ' /OFF ['.$lyrobjs_view.']';
  12589. $out .= ' /Intent /View';
  12590. $out .= ' /AS [';
  12591. $out .= ' << /Event /Print /OCGs ['.$lyrobjs.'] /Category [/Print] >>';
  12592. $out .= ' << /Event /View /OCGs ['.$lyrobjs.'] /Category [/View] >>';
  12593. $out .= ' ]';
  12594. $out .= ' /Order ['.$lyrobjs.']';
  12595. $out .= ' /ListMode /AllPages';
  12596. //$out .= ' /RBGroups ['..']';
  12597. //$out .= ' /Locked ['..']';
  12598. $out .= ' >>';
  12599. $out .= ' >>';
  12600. }
  12601. // AcroForm
  12602. if (!empty($this->form_obj_id) OR ($this->sign AND isset($this->signature_data['cert_type']))) {
  12603. $out .= ' /AcroForm <<';
  12604. $objrefs = '';
  12605. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  12606. // set reference for signature object
  12607. $objrefs .= $this->sig_obj_id.' 0 R';
  12608. }
  12609. if (!empty($this->empty_signature_appearance)) {
  12610. foreach ($this->empty_signature_appearance as $esa) {
  12611. // set reference for empty signature objects
  12612. $objrefs .= ' '.$esa['objid'].' 0 R';
  12613. }
  12614. }
  12615. if (!empty($this->form_obj_id)) {
  12616. foreach($this->form_obj_id as $objid) {
  12617. $objrefs .= ' '.$objid.' 0 R';
  12618. }
  12619. }
  12620. $out .= ' /Fields ['.$objrefs.']';
  12621. // It's better to turn off this value and set the appearance stream for each annotation (/AP) to avoid conflicts with signature fields.
  12622. $out .= ' /NeedAppearances false';
  12623. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  12624. if ($this->signature_data['cert_type'] > 0) {
  12625. $out .= ' /SigFlags 3';
  12626. } else {
  12627. $out .= ' /SigFlags 1';
  12628. }
  12629. }
  12630. //$out .= ' /CO ';
  12631. if (isset($this->annotation_fonts) AND !empty($this->annotation_fonts)) {
  12632. $out .= ' /DR <<';
  12633. $out .= ' /Font <<';
  12634. foreach ($this->annotation_fonts as $fontkey => $fontid) {
  12635. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  12636. }
  12637. $out .= ' >> >>';
  12638. }
  12639. $font = $this->getFontBuffer('helvetica');
  12640. $out .= ' /DA (/F'.$font['i'].' 0 Tf 0 g)';
  12641. $out .= ' /Q '.(($this->rtl)?'2':'0');
  12642. //$out .= ' /XFA ';
  12643. $out .= ' >>';
  12644. // signatures
  12645. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  12646. if ($this->signature_data['cert_type'] > 0) {
  12647. $out .= ' /Perms << /DocMDP '.($this->sig_obj_id + 1).' 0 R >>';
  12648. } else {
  12649. $out .= ' /Perms << /UR3 '.($this->sig_obj_id + 1).' 0 R >>';
  12650. }
  12651. }
  12652. }
  12653. //$out .= ' /Legal <<>>';
  12654. //$out .= ' /Requirements []';
  12655. //$out .= ' /Collection <<>>';
  12656. //$out .= ' /NeedsRendering true';
  12657. $out .= ' >>';
  12658. $out .= "\n".'endobj';
  12659. $this->_out($out);
  12660. return $oid;
  12661. }
  12662. /**
  12663. * Output viewer preferences.
  12664. * @return string for viewer preferences
  12665. * @author Nicola asuni
  12666. * @since 3.1.000 (2008-06-09)
  12667. * @protected
  12668. */
  12669. protected function _putviewerpreferences() {
  12670. $out = ' /ViewerPreferences <<';
  12671. if ($this->rtl) {
  12672. $out .= ' /Direction /R2L';
  12673. } else {
  12674. $out .= ' /Direction /L2R';
  12675. }
  12676. if (isset($this->viewer_preferences['HideToolbar']) AND ($this->viewer_preferences['HideToolbar'])) {
  12677. $out .= ' /HideToolbar true';
  12678. }
  12679. if (isset($this->viewer_preferences['HideMenubar']) AND ($this->viewer_preferences['HideMenubar'])) {
  12680. $out .= ' /HideMenubar true';
  12681. }
  12682. if (isset($this->viewer_preferences['HideWindowUI']) AND ($this->viewer_preferences['HideWindowUI'])) {
  12683. $out .= ' /HideWindowUI true';
  12684. }
  12685. if (isset($this->viewer_preferences['FitWindow']) AND ($this->viewer_preferences['FitWindow'])) {
  12686. $out .= ' /FitWindow true';
  12687. }
  12688. if (isset($this->viewer_preferences['CenterWindow']) AND ($this->viewer_preferences['CenterWindow'])) {
  12689. $out .= ' /CenterWindow true';
  12690. }
  12691. if (isset($this->viewer_preferences['DisplayDocTitle']) AND ($this->viewer_preferences['DisplayDocTitle'])) {
  12692. $out .= ' /DisplayDocTitle true';
  12693. }
  12694. if (isset($this->viewer_preferences['NonFullScreenPageMode'])) {
  12695. $out .= ' /NonFullScreenPageMode /'.$this->viewer_preferences['NonFullScreenPageMode'];
  12696. }
  12697. if (isset($this->viewer_preferences['ViewArea'])) {
  12698. $out .= ' /ViewArea /'.$this->viewer_preferences['ViewArea'];
  12699. }
  12700. if (isset($this->viewer_preferences['ViewClip'])) {
  12701. $out .= ' /ViewClip /'.$this->viewer_preferences['ViewClip'];
  12702. }
  12703. if (isset($this->viewer_preferences['PrintArea'])) {
  12704. $out .= ' /PrintArea /'.$this->viewer_preferences['PrintArea'];
  12705. }
  12706. if (isset($this->viewer_preferences['PrintClip'])) {
  12707. $out .= ' /PrintClip /'.$this->viewer_preferences['PrintClip'];
  12708. }
  12709. if (isset($this->viewer_preferences['PrintScaling'])) {
  12710. $out .= ' /PrintScaling /'.$this->viewer_preferences['PrintScaling'];
  12711. }
  12712. if (isset($this->viewer_preferences['Duplex']) AND (!$this->empty_string($this->viewer_preferences['Duplex']))) {
  12713. $out .= ' /Duplex /'.$this->viewer_preferences['Duplex'];
  12714. }
  12715. if (isset($this->viewer_preferences['PickTrayByPDFSize'])) {
  12716. if ($this->viewer_preferences['PickTrayByPDFSize']) {
  12717. $out .= ' /PickTrayByPDFSize true';
  12718. } else {
  12719. $out .= ' /PickTrayByPDFSize false';
  12720. }
  12721. }
  12722. if (isset($this->viewer_preferences['PrintPageRange'])) {
  12723. $PrintPageRangeNum = '';
  12724. foreach ($this->viewer_preferences['PrintPageRange'] as $k => $v) {
  12725. $PrintPageRangeNum .= ' '.($v - 1).'';
  12726. }
  12727. $out .= ' /PrintPageRange ['.substr($PrintPageRangeNum,1).']';
  12728. }
  12729. if (isset($this->viewer_preferences['NumCopies'])) {
  12730. $out .= ' /NumCopies '.intval($this->viewer_preferences['NumCopies']);
  12731. }
  12732. $out .= ' >>';
  12733. return $out;
  12734. }
  12735. /**
  12736. * Output PDF File Header (7.5.2).
  12737. * @protected
  12738. */
  12739. protected function _putheader() {
  12740. $this->_out('%PDF-'.$this->PDFVersion);
  12741. $this->_out('%'.chr(0xe2).chr(0xe3).chr(0xcf).chr(0xd3));
  12742. }
  12743. /**
  12744. * Output end of document (EOF).
  12745. * @protected
  12746. */
  12747. protected function _enddoc() {
  12748. $this->state = 1;
  12749. $this->_putheader();
  12750. $this->_putpages();
  12751. $this->_putresources();
  12752. // empty signature fields
  12753. if (!empty($this->empty_signature_appearance)) {
  12754. foreach ($this->empty_signature_appearance as $key => $esa) {
  12755. // widget annotation for empty signature
  12756. $out = $this->_getobj($esa['objid'])."\n";
  12757. $out .= '<< /Type /Annot';
  12758. $out .= ' /Subtype /Widget';
  12759. $out .= ' /Rect ['.$esa['rect'].']';
  12760. $out .= ' /P '.$this->page_obj_id[($esa['page'])].' 0 R'; // link to signature appearance page
  12761. $out .= ' /F 4';
  12762. $out .= ' /FT /Sig';
  12763. $signame = sprintf('Signature_%03d', ($key + 1));
  12764. $out .= ' /T '.$this->_textstring($signame, $esa['objid']);
  12765. $out .= ' /Ff 0';
  12766. $out .= ' >>';
  12767. $out .= "\n".'endobj';
  12768. $this->_out($out);
  12769. }
  12770. }
  12771. // Signature
  12772. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  12773. // widget annotation for signature
  12774. $out = $this->_getobj($this->sig_obj_id)."\n";
  12775. $out .= '<< /Type /Annot';
  12776. $out .= ' /Subtype /Widget';
  12777. $out .= ' /Rect ['.$this->signature_appearance['rect'].']';
  12778. $out .= ' /P '.$this->page_obj_id[($this->signature_appearance['page'])].' 0 R'; // link to signature appearance page
  12779. $out .= ' /F 4';
  12780. $out .= ' /FT /Sig';
  12781. $out .= ' /T '.$this->_textstring('Signature_000', $this->sig_obj_id);
  12782. $out .= ' /Ff 0';
  12783. $out .= ' /V '.($this->sig_obj_id + 1).' 0 R';
  12784. $out .= ' >>';
  12785. $out .= "\n".'endobj';
  12786. $this->_out($out);
  12787. // signature
  12788. $this->_putsignature();
  12789. }
  12790. // Info
  12791. $objid_info = $this->_putinfo();
  12792. // Catalog
  12793. $objid_catalog = $this->_putcatalog();
  12794. // Cross-ref
  12795. $o = $this->bufferlen;
  12796. // XREF section
  12797. $this->_out('xref');
  12798. $this->_out('0 '.($this->n + 1));
  12799. $this->_out('0000000000 65535 f ');
  12800. $freegen = ($this->n + 2);
  12801. for ($i=1; $i <= $this->n; ++$i) {
  12802. if (!isset($this->offsets[$i]) AND ($i > 1)) {
  12803. $this->_out(sprintf('0000000000 %05d f ', $freegen));
  12804. ++$freegen;
  12805. } else {
  12806. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
  12807. }
  12808. }
  12809. // TRAILER
  12810. $out = 'trailer'."\n";
  12811. $out .= '<<';
  12812. $out .= ' /Size '.($this->n + 1);
  12813. $out .= ' /Root '.$objid_catalog.' 0 R';
  12814. $out .= ' /Info '.$objid_info.' 0 R';
  12815. if ($this->encrypted) {
  12816. $out .= ' /Encrypt '.$this->encryptdata['objid'].' 0 R';
  12817. }
  12818. $out .= ' /ID [ <'.$this->file_id.'> <'.$this->file_id.'> ]';
  12819. $out .= ' >>';
  12820. $this->_out($out);
  12821. $this->_out('startxref');
  12822. $this->_out($o);
  12823. $this->_out('%%EOF');
  12824. $this->state = 3; // end-of-doc
  12825. if ($this->diskcache) {
  12826. // remove temporary files used for images
  12827. foreach ($this->imagekeys as $key) {
  12828. // remove temporary files
  12829. unlink($this->images[$key]);
  12830. }
  12831. foreach ($this->fontkeys as $key) {
  12832. // remove temporary files
  12833. unlink($this->fonts[$key]);
  12834. }
  12835. }
  12836. }
  12837. /**
  12838. * Initialize a new page.
  12839. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  12840. * @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().
  12841. * @protected
  12842. * @see getPageSizeFromFormat(), setPageFormat()
  12843. */
  12844. protected function _beginpage($orientation='', $format='') {
  12845. ++$this->page;
  12846. $this->pageobjects[$this->page] = array();
  12847. $this->setPageBuffer($this->page, '');
  12848. // initialize array for graphics tranformation positions inside a page buffer
  12849. $this->transfmrk[$this->page] = array();
  12850. $this->state = 2;
  12851. if ($this->empty_string($orientation)) {
  12852. if (isset($this->CurOrientation)) {
  12853. $orientation = $this->CurOrientation;
  12854. } elseif ($this->fwPt > $this->fhPt) {
  12855. // landscape
  12856. $orientation = 'L';
  12857. } else {
  12858. // portrait
  12859. $orientation = 'P';
  12860. }
  12861. }
  12862. if ($this->empty_string($format)) {
  12863. $this->pagedim[$this->page] = $this->pagedim[($this->page - 1)];
  12864. $this->setPageOrientation($orientation);
  12865. } else {
  12866. $this->setPageFormat($format, $orientation);
  12867. }
  12868. if ($this->rtl) {
  12869. $this->x = $this->w - $this->rMargin;
  12870. } else {
  12871. $this->x = $this->lMargin;
  12872. }
  12873. $this->y = $this->tMargin;
  12874. if (isset($this->newpagegroup[$this->page])) {
  12875. // start a new group
  12876. $this->currpagegroup = $this->newpagegroup[$this->page];
  12877. $this->pagegroups[$this->currpagegroup] = 1;
  12878. } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) {
  12879. ++$this->pagegroups[$this->currpagegroup];
  12880. }
  12881. }
  12882. /**
  12883. * Mark end of page.
  12884. * @protected
  12885. */
  12886. protected function _endpage() {
  12887. $this->setVisibility('all');
  12888. $this->state = 1;
  12889. }
  12890. /**
  12891. * Begin a new object and return the object number.
  12892. * @return int object number
  12893. * @protected
  12894. */
  12895. protected function _newobj() {
  12896. $this->_out($this->_getobj());
  12897. return $this->n;
  12898. }
  12899. /**
  12900. * Return the starting object string for the selected object ID.
  12901. * @param $objid (int) Object ID (leave empty to get a new ID).
  12902. * @return string the starting object string
  12903. * @protected
  12904. * @since 5.8.009 (2010-08-20)
  12905. */
  12906. protected function _getobj($objid='') {
  12907. if ($objid === '') {
  12908. ++$this->n;
  12909. $objid = $this->n;
  12910. }
  12911. $this->offsets[$objid] = $this->bufferlen;
  12912. $this->pageobjects[$this->page][] = $objid;
  12913. return $objid.' 0 obj';
  12914. }
  12915. /**
  12916. * Underline text.
  12917. * @param $x (int) X coordinate
  12918. * @param $y (int) Y coordinate
  12919. * @param $txt (string) text to underline
  12920. * @protected
  12921. */
  12922. protected function _dounderline($x, $y, $txt) {
  12923. $w = $this->GetStringWidth($txt);
  12924. return $this->_dounderlinew($x, $y, $w);
  12925. }
  12926. /**
  12927. * Underline for rectangular text area.
  12928. * @param $x (int) X coordinate
  12929. * @param $y (int) Y coordinate
  12930. * @param $w (int) width to underline
  12931. * @protected
  12932. * @since 4.8.008 (2009-09-29)
  12933. */
  12934. protected function _dounderlinew($x, $y, $w) {
  12935. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  12936. return sprintf('%F %F %F %F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew), $w * $this->k, $linew);
  12937. }
  12938. /**
  12939. * Line through text.
  12940. * @param $x (int) X coordinate
  12941. * @param $y (int) Y coordinate
  12942. * @param $txt (string) text to linethrough
  12943. * @protected
  12944. */
  12945. protected function _dolinethrough($x, $y, $txt) {
  12946. $w = $this->GetStringWidth($txt);
  12947. return $this->_dolinethroughw($x, $y, $w);
  12948. }
  12949. /**
  12950. * Line through for rectangular text area.
  12951. * @param $x (int) X coordinate
  12952. * @param $y (int) Y coordinate
  12953. * @param $w (int) line length (width)
  12954. * @protected
  12955. * @since 4.9.008 (2009-09-29)
  12956. */
  12957. protected function _dolinethroughw($x, $y, $w) {
  12958. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  12959. return sprintf('%F %F %F %F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew + ($this->FontSizePt / 3)), $w * $this->k, $linew);
  12960. }
  12961. /**
  12962. * Overline text.
  12963. * @param $x (int) X coordinate
  12964. * @param $y (int) Y coordinate
  12965. * @param $txt (string) text to overline
  12966. * @protected
  12967. * @since 4.9.015 (2010-04-19)
  12968. */
  12969. protected function _dooverline($x, $y, $txt) {
  12970. $w = $this->GetStringWidth($txt);
  12971. return $this->_dooverlinew($x, $y, $w);
  12972. }
  12973. /**
  12974. * Overline for rectangular text area.
  12975. * @param $x (int) X coordinate
  12976. * @param $y (int) Y coordinate
  12977. * @param $w (int) width to overline
  12978. * @protected
  12979. * @since 4.9.015 (2010-04-19)
  12980. */
  12981. protected function _dooverlinew($x, $y, $w) {
  12982. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  12983. return sprintf('%F %F %F %F re f', $x * $this->k, (($this->h - $y + $this->FontAscent) * $this->k) - $linew, $w * $this->k, $linew);
  12984. }
  12985. /**
  12986. * Read a 4-byte (32 bit) integer from file.
  12987. * @param $f (string) file name.
  12988. * @return 4-byte integer
  12989. * @protected
  12990. */
  12991. protected function _freadint($f) {
  12992. $a = unpack('Ni', fread($f, 4));
  12993. return $a['i'];
  12994. }
  12995. /**
  12996. * Add "\" before "\", "(" and ")"
  12997. * @param $s (string) string to escape.
  12998. * @return string escaped string.
  12999. * @protected
  13000. */
  13001. protected function _escape($s) {
  13002. // the chr(13) substitution fixes the Bugs item #1421290.
  13003. return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
  13004. }
  13005. /**
  13006. * Format a data string for meta information
  13007. * @param $s (string) data string to escape.
  13008. * @param $n (int) object ID
  13009. * @return string escaped string.
  13010. * @protected
  13011. */
  13012. protected function _datastring($s, $n=0) {
  13013. if ($n == 0) {
  13014. $n = $this->n;
  13015. }
  13016. $s = $this->_encrypt_data($n, $s);
  13017. return '('. $this->_escape($s).')';
  13018. }
  13019. /**
  13020. * Set the document creation timestamp
  13021. * @param $time (mixed) Document creation timestamp in seconds or date-time string.
  13022. * @public
  13023. * @since 5.9.152 (2012-03-23)
  13024. */
  13025. public function setDocCreationTimestamp($time) {
  13026. if (is_string($time)) {
  13027. $time = getTimestamp($time);
  13028. }
  13029. $this->doc_creation_timestamp = intval($time);
  13030. }
  13031. /**
  13032. * Set the document modification timestamp
  13033. * @param $time (mixed) Document modification timestamp in seconds or date-time string.
  13034. * @public
  13035. * @since 5.9.152 (2012-03-23)
  13036. */
  13037. public function setDocModificationTimestamp($time) {
  13038. if (is_string($time)) {
  13039. $time = getTimestamp($time);
  13040. }
  13041. $this->doc_modification_timestamp = intval($time);
  13042. }
  13043. /**
  13044. * Returns document creation timestamp in seconds.
  13045. * @return (int) Creation timestamp in seconds.
  13046. * @public
  13047. * @since 5.9.152 (2012-03-23)
  13048. */
  13049. public function getDocCreationTimestamp() {
  13050. return $this->doc_creation_timestamp;
  13051. }
  13052. /**
  13053. * Returns document modification timestamp in seconds.
  13054. * @return (int) Modfication timestamp in seconds.
  13055. * @public
  13056. * @since 5.9.152 (2012-03-23)
  13057. */
  13058. public function getDocModificationTimestamp() {
  13059. return $this->doc_modification_timestamp;
  13060. }
  13061. /**
  13062. * Returns timestamp in seconds from formatted date-time.
  13063. * @param $date (string) Formatted date-time.
  13064. * @return int seconds.
  13065. * @public
  13066. * @since 5.9.152 (2012-03-23)
  13067. */
  13068. public function getTimestamp($date) {
  13069. if (($date[0] == 'D') AND ($date[1] == ':')) {
  13070. // remove date prefix if present
  13071. $date = substr($date, 2);
  13072. }
  13073. return strtotime($date);
  13074. }
  13075. /**
  13076. * Returns a formatted date-time.
  13077. * @param $time (int) Time in seconds.
  13078. * @return string escaped date string.
  13079. * @public
  13080. * @since 5.9.152 (2012-03-23)
  13081. */
  13082. public function getFormattedDate($time) {
  13083. return substr_replace(date('YmdHisO', intval($time)), '\'', (0 - 2), 0).'\'';
  13084. }
  13085. /**
  13086. * Returns a formatted date for meta information
  13087. * @param $n (int) Object ID.
  13088. * @param $timestamp (int) Timestamp to convert.
  13089. * @return string escaped date string.
  13090. * @protected
  13091. * @since 4.6.028 (2009-08-25)
  13092. */
  13093. protected function _datestring($n=0, $timestamp=0) {
  13094. if ((empty($timestamp)) OR ($timestamp < 0)) {
  13095. $timestamp = $this->doc_creation_timestamp;
  13096. }
  13097. return $this->_datastring('D:'.$this->getFormattedDate($timestamp), $n);
  13098. }
  13099. /**
  13100. * Format a text string for meta information
  13101. * @param $s (string) string to escape.
  13102. * @param $n (int) object ID
  13103. * @return string escaped string.
  13104. * @protected
  13105. */
  13106. protected function _textstring($s, $n=0) {
  13107. if ($this->isunicode) {
  13108. //Convert string to UTF-16BE
  13109. $s = $this->UTF8ToUTF16BE($s, true);
  13110. }
  13111. return $this->_datastring($s, $n);
  13112. }
  13113. /**
  13114. * THIS METHOD IS DEPRECATED
  13115. * Format a text string
  13116. * @param $s (string) string to escape.
  13117. * @return string escaped string.
  13118. * @protected
  13119. * @deprecated
  13120. */
  13121. protected function _escapetext($s) {
  13122. if ($this->isunicode) {
  13123. if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
  13124. $s = $this->UTF8ToLatin1($s);
  13125. } else {
  13126. //Convert string to UTF-16BE and reverse RTL language
  13127. $s = $this->utf8StrRev($s, false, $this->tmprtl);
  13128. }
  13129. }
  13130. return $this->_escape($s);
  13131. }
  13132. /**
  13133. * Escape some special characters (&lt; &gt; &amp;) for XML output.
  13134. * @param $str (string) Input string to convert.
  13135. * @return converted string
  13136. * @since 5.9.121 (2011-09-28)
  13137. * @protected
  13138. */
  13139. protected function _escapeXML($str) {
  13140. $replaceTable = array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;');
  13141. $str = strtr($str, $replaceTable);
  13142. return $str;
  13143. }
  13144. /**
  13145. * get raw output stream.
  13146. * @param $s (string) string to output.
  13147. * @param $n (int) object reference for encryption mode
  13148. * @protected
  13149. * @author Nicola Asuni
  13150. * @since 5.5.000 (2010-06-22)
  13151. */
  13152. protected function _getrawstream($s, $n=0) {
  13153. if ($n <= 0) {
  13154. // default to current object
  13155. $n = $this->n;
  13156. }
  13157. return $this->_encrypt_data($n, $s);
  13158. }
  13159. /**
  13160. * Format output stream (DEPRECATED).
  13161. * @param $s (string) string to output.
  13162. * @param $n (int) object reference for encryption mode
  13163. * @protected
  13164. * @deprecated
  13165. */
  13166. protected function _getstream($s, $n=0) {
  13167. return 'stream'."\n".$this->_getrawstream($s, $n)."\n".'endstream';
  13168. }
  13169. /**
  13170. * Output a stream (DEPRECATED).
  13171. * @param $s (string) string to output.
  13172. * @param $n (int) object reference for encryption mode
  13173. * @protected
  13174. * @deprecated
  13175. */
  13176. protected function _putstream($s, $n=0) {
  13177. $this->_out($this->_getstream($s, $n));
  13178. }
  13179. /**
  13180. * Output a string to the document.
  13181. * @param $s (string) string to output.
  13182. * @protected
  13183. */
  13184. protected function _out($s) {
  13185. if ($this->state == 2) {
  13186. if ($this->inxobj) {
  13187. // we are inside an XObject template
  13188. $this->xobjects[$this->xobjid]['outdata'] .= $s."\n";
  13189. } elseif ((!$this->InFooter) AND isset($this->footerlen[$this->page]) AND ($this->footerlen[$this->page] > 0)) {
  13190. // puts data before page footer
  13191. $pagebuff = $this->getPageBuffer($this->page);
  13192. $page = substr($pagebuff, 0, -$this->footerlen[$this->page]);
  13193. $footer = substr($pagebuff, -$this->footerlen[$this->page]);
  13194. $this->setPageBuffer($this->page, $page.$s."\n".$footer);
  13195. // update footer position
  13196. $this->footerpos[$this->page] += strlen($s."\n");
  13197. } else {
  13198. // set page data
  13199. $this->setPageBuffer($this->page, $s."\n", true);
  13200. }
  13201. } elseif ($this->state > 0) {
  13202. // set general data
  13203. $this->setBuffer($s."\n");
  13204. }
  13205. }
  13206. /**
  13207. * Converts UTF-8 strings to codepoints array.<br>
  13208. * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br>
  13209. * Based on: http://www.faqs.org/rfcs/rfc3629.html
  13210. * <pre>
  13211. * Char. number range | UTF-8 octet sequence
  13212. * (hexadecimal) | (binary)
  13213. * --------------------+-----------------------------------------------
  13214. * 0000 0000-0000 007F | 0xxxxxxx
  13215. * 0000 0080-0000 07FF | 110xxxxx 10xxxxxx
  13216. * 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
  13217. * 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
  13218. * ---------------------------------------------------------------------
  13219. *
  13220. * ABFN notation:
  13221. * ---------------------------------------------------------------------
  13222. * UTF8-octets = *( UTF8-char )
  13223. * UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
  13224. * UTF8-1 = %x00-7F
  13225. * UTF8-2 = %xC2-DF UTF8-tail
  13226. *
  13227. * UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
  13228. * %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
  13229. * UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
  13230. * %xF4 %x80-8F 2( UTF8-tail )
  13231. * UTF8-tail = %x80-BF
  13232. * ---------------------------------------------------------------------
  13233. * </pre>
  13234. * @param $str (string) string to process.
  13235. * @return array containing codepoints (UTF-8 characters values)
  13236. * @protected
  13237. * @author Nicola Asuni
  13238. * @since 1.53.0.TC005 (2005-01-05)
  13239. */
  13240. protected function UTF8StringToArray($str) {
  13241. // build a unique string key
  13242. $strkey = md5($str);
  13243. if (isset($this->cache_UTF8StringToArray[$strkey])) {
  13244. // return cached value
  13245. $chrarray = $this->cache_UTF8StringToArray[$strkey]['s'];
  13246. if (!isset($this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']])) {
  13247. if ($this->isunicode) {
  13248. foreach ($chrarray as $chr) {
  13249. // store this char for font subsetting
  13250. $this->CurrentFont['subsetchars'][$chr] = true;
  13251. }
  13252. // update font subsetchars
  13253. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  13254. }
  13255. $this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']] = true;
  13256. }
  13257. return $chrarray;
  13258. }
  13259. // check cache size
  13260. if ($this->cache_size_UTF8StringToArray >= $this->cache_maxsize_UTF8StringToArray) {
  13261. // remove first element
  13262. array_shift($this->cache_UTF8StringToArray);
  13263. }
  13264. // new cache array for selected string
  13265. $this->cache_UTF8StringToArray[$strkey] = array('s' => array(), 'f' => array());
  13266. ++$this->cache_size_UTF8StringToArray;
  13267. if (!$this->isunicode) {
  13268. // split string into array of equivalent codes
  13269. $strarr = array();
  13270. $strlen = strlen($str);
  13271. for ($i=0; $i < $strlen; ++$i) {
  13272. $strarr[] = ord($str[$i]);
  13273. }
  13274. // insert new value on cache
  13275. $this->cache_UTF8StringToArray[$strkey]['s'] = $strarr;
  13276. $this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']] = true;
  13277. return $strarr;
  13278. }
  13279. $unichar = -1; // last unicode char
  13280. $unicode = array(); // array containing unicode values
  13281. $bytes = array(); // array containing single character byte sequences
  13282. $numbytes = 1; // number of octetc needed to represent the UTF-8 character
  13283. $str .= ''; // force $str to be a string
  13284. $length = strlen($str);
  13285. for ($i = 0; $i < $length; ++$i) {
  13286. $char = ord($str[$i]); // get one string character at time
  13287. if (count($bytes) == 0) { // get starting octect
  13288. if ($char <= 0x7F) {
  13289. $unichar = $char; // use the character "as is" because is ASCII
  13290. $numbytes = 1;
  13291. } elseif (($char >> 0x05) == 0x06) { // 2 bytes character (0x06 = 110 BIN)
  13292. $bytes[] = ($char - 0xC0) << 0x06;
  13293. $numbytes = 2;
  13294. } elseif (($char >> 0x04) == 0x0E) { // 3 bytes character (0x0E = 1110 BIN)
  13295. $bytes[] = ($char - 0xE0) << 0x0C;
  13296. $numbytes = 3;
  13297. } elseif (($char >> 0x03) == 0x1E) { // 4 bytes character (0x1E = 11110 BIN)
  13298. $bytes[] = ($char - 0xF0) << 0x12;
  13299. $numbytes = 4;
  13300. } else {
  13301. // use replacement character for other invalid sequences
  13302. $unichar = 0xFFFD;
  13303. $bytes = array();
  13304. $numbytes = 1;
  13305. }
  13306. } elseif (($char >> 0x06) == 0x02) { // bytes 2, 3 and 4 must start with 0x02 = 10 BIN
  13307. $bytes[] = $char - 0x80;
  13308. if (count($bytes) == $numbytes) {
  13309. // compose UTF-8 bytes to a single unicode value
  13310. $char = $bytes[0];
  13311. for ($j = 1; $j < $numbytes; ++$j) {
  13312. $char += ($bytes[$j] << (($numbytes - $j - 1) * 0x06));
  13313. }
  13314. if ((($char >= 0xD800) AND ($char <= 0xDFFF)) OR ($char >= 0x10FFFF)) {
  13315. /* The definition of UTF-8 prohibits encoding character numbers between
  13316. U+D800 and U+DFFF, which are reserved for use with the UTF-16
  13317. encoding form (as surrogate pairs) and do not directly represent
  13318. characters. */
  13319. $unichar = 0xFFFD; // use replacement character
  13320. } else {
  13321. $unichar = $char; // add char to array
  13322. }
  13323. // reset data for next char
  13324. $bytes = array();
  13325. $numbytes = 1;
  13326. }
  13327. } else {
  13328. // use replacement character for other invalid sequences
  13329. $unichar = 0xFFFD;
  13330. $bytes = array();
  13331. $numbytes = 1;
  13332. }
  13333. if ($unichar >= 0) {
  13334. // insert unicode value into array
  13335. $unicode[] = $unichar;
  13336. // store this char for font subsetting
  13337. $this->CurrentFont['subsetchars'][$unichar] = true;
  13338. $unichar = -1;
  13339. }
  13340. }
  13341. // update font subsetchars
  13342. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  13343. // insert new value on cache
  13344. $this->cache_UTF8StringToArray[$strkey]['s'] = $unicode;
  13345. $this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']] = true;
  13346. return $unicode;
  13347. }
  13348. /**
  13349. * Converts UTF-8 strings to UTF16-BE.<br>
  13350. * @param $str (string) string to process.
  13351. * @param $setbom (boolean) if true set the Byte Order Mark (BOM = 0xFEFF)
  13352. * @return string
  13353. * @author Nicola Asuni
  13354. * @since 1.53.0.TC005 (2005-01-05)
  13355. * @see UTF8StringToArray(), arrUTF8ToUTF16BE()
  13356. * @protected
  13357. */
  13358. protected function UTF8ToUTF16BE($str, $setbom=false) {
  13359. if (!$this->isunicode) {
  13360. return $str; // string is not in unicode
  13361. }
  13362. $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values
  13363. return $this->arrUTF8ToUTF16BE($unicode, $setbom);
  13364. }
  13365. /**
  13366. * Converts UTF-8 strings to Latin1 when using the standard 14 core fonts.<br>
  13367. * @param $str (string) string to process.
  13368. * @return string
  13369. * @author Andrew Whitehead, Nicola Asuni
  13370. * @protected
  13371. * @since 3.2.000 (2008-06-23)
  13372. */
  13373. protected function UTF8ToLatin1($str) {
  13374. if (!$this->isunicode) {
  13375. return $str; // string is not in unicode
  13376. }
  13377. $outstr = ''; // string to be returned
  13378. $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values
  13379. foreach ($unicode as $char) {
  13380. if ($char < 256) {
  13381. $outstr .= chr($char);
  13382. } elseif (array_key_exists($char, $this->unicode->uni_utf8tolatin)) {
  13383. // map from UTF-8
  13384. $outstr .= chr($this->unicode->uni_utf8tolatin[$char]);
  13385. } elseif ($char == 0xFFFD) {
  13386. // skip
  13387. } else {
  13388. $outstr .= '?';
  13389. }
  13390. }
  13391. return $outstr;
  13392. }
  13393. /**
  13394. * Converts UTF-8 characters array to array of Latin1 characters<br>
  13395. * @param $unicode (array) array containing UTF-8 unicode values
  13396. * @return array
  13397. * @author Nicola Asuni
  13398. * @protected
  13399. * @since 4.8.023 (2010-01-15)
  13400. */
  13401. protected function UTF8ArrToLatin1($unicode) {
  13402. if ((!$this->isunicode) OR $this->isUnicodeFont()) {
  13403. return $unicode;
  13404. }
  13405. $outarr = array(); // array to be returned
  13406. foreach ($unicode as $char) {
  13407. if ($char < 256) {
  13408. $outarr[] = $char;
  13409. } elseif (array_key_exists($char, $this->unicode->uni_utf8tolatin)) {
  13410. // map from UTF-8
  13411. $outarr[] = $this->unicode->uni_utf8tolatin[$char];
  13412. } elseif ($char == 0xFFFD) {
  13413. // skip
  13414. } else {
  13415. $outarr[] = 63; // '?' character
  13416. }
  13417. }
  13418. return $outarr;
  13419. }
  13420. /**
  13421. * Converts array of UTF-8 characters to UTF16-BE string.<br>
  13422. * Based on: http://www.faqs.org/rfcs/rfc2781.html
  13423. * <pre>
  13424. * Encoding UTF-16:
  13425. *
  13426. * Encoding of a single character from an ISO 10646 character value to
  13427. * UTF-16 proceeds as follows. Let U be the character number, no greater
  13428. * than 0x10FFFF.
  13429. *
  13430. * 1) If U < 0x10000, encode U as a 16-bit unsigned integer and
  13431. * terminate.
  13432. *
  13433. * 2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
  13434. * U' must be less than or equal to 0xFFFFF. That is, U' can be
  13435. * represented in 20 bits.
  13436. *
  13437. * 3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
  13438. * 0xDC00, respectively. These integers each have 10 bits free to
  13439. * encode the character value, for a total of 20 bits.
  13440. *
  13441. * 4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
  13442. * bits of W1 and the 10 low-order bits of U' to the 10 low-order
  13443. * bits of W2. Terminate.
  13444. *
  13445. * Graphically, steps 2 through 4 look like:
  13446. * U' = yyyyyyyyyyxxxxxxxxxx
  13447. * W1 = 110110yyyyyyyyyy
  13448. * W2 = 110111xxxxxxxxxx
  13449. * </pre>
  13450. * @param $unicode (array) array containing UTF-8 unicode values
  13451. * @param $setbom (boolean) if true set the Byte Order Mark (BOM = 0xFEFF)
  13452. * @return string
  13453. * @protected
  13454. * @author Nicola Asuni
  13455. * @since 2.1.000 (2008-01-08)
  13456. * @see UTF8ToUTF16BE()
  13457. */
  13458. protected function arrUTF8ToUTF16BE($unicode, $setbom=false) {
  13459. $outstr = ''; // string to be returned
  13460. if ($setbom) {
  13461. $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
  13462. }
  13463. foreach ($unicode as $char) {
  13464. if ($char == 0x200b) {
  13465. // skip Unicode Character 'ZERO WIDTH SPACE' (DEC:8203, U+200B)
  13466. } elseif ($char == 0xFFFD) {
  13467. $outstr .= "\xFF\xFD"; // replacement character
  13468. } elseif ($char < 0x10000) {
  13469. $outstr .= chr($char >> 0x08);
  13470. $outstr .= chr($char & 0xFF);
  13471. } else {
  13472. $char -= 0x10000;
  13473. $w1 = 0xD800 | ($char >> 0x0a);
  13474. $w2 = 0xDC00 | ($char & 0x3FF);
  13475. $outstr .= chr($w1 >> 0x08);
  13476. $outstr .= chr($w1 & 0xFF);
  13477. $outstr .= chr($w2 >> 0x08);
  13478. $outstr .= chr($w2 & 0xFF);
  13479. }
  13480. }
  13481. return $outstr;
  13482. }
  13483. // ====================================================
  13484. /**
  13485. * Set header font.
  13486. * @param $font (array) font
  13487. * @public
  13488. * @since 1.1
  13489. */
  13490. public function setHeaderFont($font) {
  13491. $this->header_font = $font;
  13492. }
  13493. /**
  13494. * Get header font.
  13495. * @return array()
  13496. * @public
  13497. * @since 4.0.012 (2008-07-24)
  13498. */
  13499. public function getHeaderFont() {
  13500. return $this->header_font;
  13501. }
  13502. /**
  13503. * Set footer font.
  13504. * @param $font (array) font
  13505. * @public
  13506. * @since 1.1
  13507. */
  13508. public function setFooterFont($font) {
  13509. $this->footer_font = $font;
  13510. }
  13511. /**
  13512. * Get Footer font.
  13513. * @return array()
  13514. * @public
  13515. * @since 4.0.012 (2008-07-24)
  13516. */
  13517. public function getFooterFont() {
  13518. return $this->footer_font;
  13519. }
  13520. /**
  13521. * Set language array.
  13522. * @param $language (array)
  13523. * @public
  13524. * @since 1.1
  13525. */
  13526. public function setLanguageArray($language) {
  13527. $this->l = $language;
  13528. if (isset($this->l['a_meta_dir'])) {
  13529. $this->rtl = $this->l['a_meta_dir']=='rtl' ? true : false;
  13530. } else {
  13531. $this->rtl = false;
  13532. }
  13533. }
  13534. /**
  13535. * Returns the PDF data.
  13536. * @public
  13537. */
  13538. public function getPDFData() {
  13539. if ($this->state < 3) {
  13540. $this->Close();
  13541. }
  13542. return $this->buffer;
  13543. }
  13544. /**
  13545. * Output anchor link.
  13546. * @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;)
  13547. * @param $name (string) link name
  13548. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  13549. * @param $firstline (boolean) if true prints only the first line and return the remaining string.
  13550. * @param $color (array) array of RGB text color
  13551. * @param $style (string) font style (U, D, B, I)
  13552. * @param $firstblock (boolean) if true the string is the starting of a line.
  13553. * @return the number of cells used or the remaining text if $firstline = true;
  13554. * @public
  13555. */
  13556. public function addHtmlLink($url, $name, $fill=false, $firstline=false, $color='', $style=-1, $firstblock=false) {
  13557. if (!$this->empty_string($url) AND ($url[0] == '#') AND is_numeric($url[1])) {
  13558. // convert url to internal link
  13559. $lnkdata = explode(',', $url);
  13560. if (isset($lnkdata[0])) {
  13561. $page = intval(substr($lnkdata[0], 1));
  13562. if (empty($page) OR ($page <= 0)) {
  13563. $page = $this->page;
  13564. }
  13565. if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
  13566. $lnky = floatval($lnkdata[1]);
  13567. } else {
  13568. $lnky = 0;
  13569. }
  13570. $url = $this->AddLink();
  13571. $this->SetLink($url, $lnky, $page);
  13572. }
  13573. }
  13574. // store current settings
  13575. $prevcolor = $this->fgcolor;
  13576. $prevstyle = $this->FontStyle;
  13577. if (empty($color)) {
  13578. $this->SetTextColorArray($this->htmlLinkColorArray);
  13579. } else {
  13580. $this->SetTextColorArray($color);
  13581. }
  13582. if ($style == -1) {
  13583. $this->SetFont('', $this->FontStyle.$this->htmlLinkFontStyle);
  13584. } else {
  13585. $this->SetFont('', $this->FontStyle.$style);
  13586. }
  13587. $ret = $this->Write($this->lasth, $name, $url, $fill, '', false, 0, $firstline, $firstblock, 0);
  13588. // restore settings
  13589. $this->SetFont('', $prevstyle);
  13590. $this->SetTextColorArray($prevcolor);
  13591. return $ret;
  13592. }
  13593. /**
  13594. * 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, or a javascript color array, or javascript color name.
  13595. * @param $hcolor (string) HTML color.
  13596. * @param $defcol (array) Color to return in case of error.
  13597. * @return array RGB or CMYK color, or false in case of error.
  13598. * @public
  13599. */
  13600. public function convertHTMLColorToDec($hcolor='#FFFFFF', $defcol=array('R'=>128,'G'=>128,'B'=>128)) {
  13601. $color = preg_replace('/[\s]*/', '', $hcolor); // remove extra spaces
  13602. $color = strtolower($color);
  13603. // check for javascript color array syntax
  13604. if (strpos($color, '[') !== false) {
  13605. if (preg_match('/[\[][\"\'](t|g|rgb|cmyk)[\"\'][\,]?([0-9\.]*)[\,]?([0-9\.]*)[\,]?([0-9\.]*)[\,]?([0-9\.]*)[\]]/', $color, $m) > 0) {
  13606. $returncolor = array();
  13607. switch ($m[1]) {
  13608. case 'cmyk': {
  13609. // RGB
  13610. $returncolor['C'] = max(0, min(100, (floatval($m[2]) * 100)));
  13611. $returncolor['M'] = max(0, min(100, (floatval($m[3]) * 100)));
  13612. $returncolor['Y'] = max(0, min(100, (floatval($m[4]) * 100)));
  13613. $returncolor['K'] = max(0, min(100, (floatval($m[5]) * 100)));
  13614. break;
  13615. }
  13616. case 'rgb': {
  13617. // RGB
  13618. $returncolor['R'] = max(0, min(255, (floatval($m[2]) * 255)));
  13619. $returncolor['G'] = max(0, min(255, (floatval($m[3]) * 255)));
  13620. $returncolor['B'] = max(0, min(255, (floatval($m[4]) * 255)));
  13621. break;
  13622. }
  13623. case 'g': {
  13624. // grayscale
  13625. $returncolor['G'] = max(0, min(255, (floatval($m[2]) * 255)));
  13626. break;
  13627. }
  13628. case 't':
  13629. default: {
  13630. // transparent (empty array)
  13631. break;
  13632. }
  13633. }
  13634. return $returncolor;
  13635. }
  13636. } elseif (($dotpos = strpos($color, '.')) !== false) {
  13637. // remove class parent (i.e.: color.red)
  13638. $color = substr($color, ($dotpos + 1));
  13639. if ($color == 'transparent') {
  13640. // transparent (empty array)
  13641. return array();
  13642. }
  13643. }
  13644. if (strlen($color) == 0) {
  13645. return $defcol;
  13646. }
  13647. // RGB ARRAY
  13648. if (substr($color, 0, 3) == 'rgb') {
  13649. $codes = substr($color, 4);
  13650. $codes = str_replace(')', '', $codes);
  13651. $returncolor = explode(',', $codes);
  13652. foreach ($returncolor as $key => $val) {
  13653. if (strpos($val, '%') > 0) {
  13654. // percentage
  13655. $returncolor[$key] = (255 * intval($val) / 100);
  13656. } else {
  13657. $returncolor[$key] = intval($val);
  13658. }
  13659. // normalize value
  13660. $returncolor[$key] = max(0, min(255, $returncolor[$key]));
  13661. }
  13662. return $returncolor;
  13663. }
  13664. // CMYK ARRAY
  13665. if (substr($color, 0, 4) == 'cmyk') {
  13666. $codes = substr($color, 5);
  13667. $codes = str_replace(')', '', $codes);
  13668. $returncolor = explode(',', $codes);
  13669. foreach ($returncolor as $key => $val) {
  13670. if (strpos($val, '%') !== false) {
  13671. // percentage
  13672. $returncolor[$key] = (100 * intval($val) / 100);
  13673. } else {
  13674. $returncolor[$key] = intval($val);
  13675. }
  13676. // normalize value
  13677. $returncolor[$key] = max(0, min(100, $returncolor[$key]));
  13678. }
  13679. return $returncolor;
  13680. }
  13681. if ($color{0} != '#') {
  13682. // COLOR NAME
  13683. if (isset($this->webcolor[$color])) {
  13684. // web color
  13685. $color_code = $this->webcolor[$color];
  13686. } else {
  13687. // spot color
  13688. $returncolor = $this->getSpotColor($color);
  13689. if ($returncolor === false) {
  13690. $returncolor = $defcol;
  13691. }
  13692. return $returncolor;
  13693. }
  13694. } else {
  13695. $color_code = substr($color, 1);
  13696. }
  13697. // HEXADECIMAL REPRESENTATION
  13698. switch (strlen($color_code)) {
  13699. case 3: {
  13700. // 3-digit RGB hexadecimal representation
  13701. $r = substr($color_code, 0, 1);
  13702. $g = substr($color_code, 1, 1);
  13703. $b = substr($color_code, 2, 1);
  13704. $returncolor = array();
  13705. $returncolor['R'] = max(0, min(255, hexdec($r.$r)));
  13706. $returncolor['G'] = max(0, min(255, hexdec($g.$g)));
  13707. $returncolor['B'] = max(0, min(255, hexdec($b.$b)));
  13708. break;
  13709. }
  13710. case 6: {
  13711. // 6-digit RGB hexadecimal representation
  13712. $returncolor = array();
  13713. $returncolor['R'] = max(0, min(255, hexdec(substr($color_code, 0, 2))));
  13714. $returncolor['G'] = max(0, min(255, hexdec(substr($color_code, 2, 2))));
  13715. $returncolor['B'] = max(0, min(255, hexdec(substr($color_code, 4, 2))));
  13716. break;
  13717. }
  13718. case 8: {
  13719. // 8-digit CMYK hexadecimal representation
  13720. $returncolor = array();
  13721. $returncolor['C'] = max(0, min(100, round(hexdec(substr($color_code, 0, 2)) / 2.55)));
  13722. $returncolor['M'] = max(0, min(100, round(hexdec(substr($color_code, 2, 2)) / 2.55)));
  13723. $returncolor['Y'] = max(0, min(100, round(hexdec(substr($color_code, 4, 2)) / 2.55)));
  13724. $returncolor['K'] = max(0, min(100, round(hexdec(substr($color_code, 6, 2)) / 2.55)));
  13725. break;
  13726. }
  13727. default: {
  13728. $returncolor = $defcol;
  13729. break;
  13730. }
  13731. }
  13732. return $returncolor;
  13733. }
  13734. /**
  13735. * Converts pixels to User's Units.
  13736. * @param $px (int) pixels
  13737. * @return float value in user's unit
  13738. * @public
  13739. * @see setImageScale(), getImageScale()
  13740. */
  13741. public function pixelsToUnits($px) {
  13742. return ($px / ($this->imgscale * $this->k));
  13743. }
  13744. /**
  13745. * Reverse function for htmlentities.
  13746. * Convert entities in UTF-8.
  13747. * @param $text_to_convert (string) Text to convert.
  13748. * @return string converted text string
  13749. * @public
  13750. */
  13751. public function unhtmlentities($text_to_convert) {
  13752. return @html_entity_decode($text_to_convert, ENT_QUOTES, $this->encoding);
  13753. }
  13754. // ENCRYPTION METHODS ----------------------------------
  13755. /**
  13756. * Returns a string containing random data to be used as a seed for encryption methods.
  13757. * @param $seed (string) starting seed value
  13758. * @return string containing random data
  13759. * @author Nicola Asuni
  13760. * @since 5.9.006 (2010-10-19)
  13761. * @protected
  13762. */
  13763. protected function getRandomSeed($seed='') {
  13764. $seed .= microtime();
  13765. if (function_exists('openssl_random_pseudo_bytes') AND (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) {
  13766. // this is not used on windows systems because it is very slow for a know bug
  13767. $seed .= openssl_random_pseudo_bytes(512);
  13768. } else {
  13769. for ($i = 0; $i < 23; ++$i) {
  13770. $seed .= uniqid('', true);
  13771. }
  13772. }
  13773. $seed .= uniqid('', true);
  13774. $seed .= rand();
  13775. $seed .= getmypid();
  13776. $seed .= __FILE__;
  13777. $seed .= $this->bufferlen;
  13778. if (isset($_SERVER['REMOTE_ADDR'])) {
  13779. $seed .= $_SERVER['REMOTE_ADDR'];
  13780. }
  13781. if (isset($_SERVER['HTTP_USER_AGENT'])) {
  13782. $seed .= $_SERVER['HTTP_USER_AGENT'];
  13783. }
  13784. if (isset($_SERVER['HTTP_ACCEPT'])) {
  13785. $seed .= $_SERVER['HTTP_ACCEPT'];
  13786. }
  13787. if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
  13788. $seed .= $_SERVER['HTTP_ACCEPT_ENCODING'];
  13789. }
  13790. if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  13791. $seed .= $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  13792. }
  13793. if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
  13794. $seed .= $_SERVER['HTTP_ACCEPT_CHARSET'];
  13795. }
  13796. $seed .= rand();
  13797. $seed .= uniqid('', true);
  13798. $seed .= microtime();
  13799. return $seed;
  13800. }
  13801. /**
  13802. * Compute encryption key depending on object number where the encrypted data is stored.
  13803. * This is used for all strings and streams without crypt filter specifier.
  13804. * @param $n (int) object number
  13805. * @return int object key
  13806. * @protected
  13807. * @author Nicola Asuni
  13808. * @since 2.0.000 (2008-01-02)
  13809. */
  13810. protected function _objectkey($n) {
  13811. $objkey = $this->encryptdata['key'].pack('VXxx', $n);
  13812. if ($this->encryptdata['mode'] == 2) { // AES-128
  13813. // AES padding
  13814. $objkey .= "\x73\x41\x6C\x54"; // sAlT
  13815. }
  13816. $objkey = substr($this->_md5_16($objkey), 0, (($this->encryptdata['Length'] / 8) + 5));
  13817. $objkey = substr($objkey, 0, 16);
  13818. return $objkey;
  13819. }
  13820. /**
  13821. * Encrypt the input string.
  13822. * @param $n (int) object number
  13823. * @param $s (string) data string to encrypt
  13824. * @return encrypted string
  13825. * @protected
  13826. * @author Nicola Asuni
  13827. * @since 5.0.005 (2010-05-11)
  13828. */
  13829. protected function _encrypt_data($n, $s) {
  13830. if (!$this->encrypted) {
  13831. return $s;
  13832. }
  13833. switch ($this->encryptdata['mode']) {
  13834. case 0: // RC4-40
  13835. case 1: { // RC4-128
  13836. $s = $this->_RC4($this->_objectkey($n), $s);
  13837. break;
  13838. }
  13839. case 2: { // AES-128
  13840. $s = $this->_AES($this->_objectkey($n), $s);
  13841. break;
  13842. }
  13843. case 3: { // AES-256
  13844. $s = $this->_AES($this->encryptdata['key'], $s);
  13845. break;
  13846. }
  13847. }
  13848. return $s;
  13849. }
  13850. /**
  13851. * Put encryption on PDF document.
  13852. * @protected
  13853. * @author Nicola Asuni
  13854. * @since 2.0.000 (2008-01-02)
  13855. */
  13856. protected function _putencryption() {
  13857. if (!$this->encrypted) {
  13858. return;
  13859. }
  13860. $this->encryptdata['objid'] = $this->_newobj();
  13861. $out = '<<';
  13862. if (!isset($this->encryptdata['Filter']) OR empty($this->encryptdata['Filter'])) {
  13863. $this->encryptdata['Filter'] = 'Standard';
  13864. }
  13865. $out .= ' /Filter /'.$this->encryptdata['Filter'];
  13866. if (isset($this->encryptdata['SubFilter']) AND !empty($this->encryptdata['SubFilter'])) {
  13867. $out .= ' /SubFilter /'.$this->encryptdata['SubFilter'];
  13868. }
  13869. if (!isset($this->encryptdata['V']) OR empty($this->encryptdata['V'])) {
  13870. $this->encryptdata['V'] = 1;
  13871. }
  13872. // V is a code specifying the algorithm to be used in encrypting and decrypting the document
  13873. $out .= ' /V '.$this->encryptdata['V'];
  13874. if (isset($this->encryptdata['Length']) AND !empty($this->encryptdata['Length'])) {
  13875. // The length of the encryption key, in bits. The value shall be a multiple of 8, in the range 40 to 256
  13876. $out .= ' /Length '.$this->encryptdata['Length'];
  13877. } else {
  13878. $out .= ' /Length 40';
  13879. }
  13880. if ($this->encryptdata['V'] >= 4) {
  13881. if (!isset($this->encryptdata['StmF']) OR empty($this->encryptdata['StmF'])) {
  13882. $this->encryptdata['StmF'] = 'Identity';
  13883. }
  13884. if (!isset($this->encryptdata['StrF']) OR empty($this->encryptdata['StrF'])) {
  13885. // The name of the crypt filter that shall be used when decrypting all strings in the document.
  13886. $this->encryptdata['StrF'] = 'Identity';
  13887. }
  13888. // A dictionary whose keys shall be crypt filter names and whose values shall be the corresponding crypt filter dictionaries.
  13889. if (isset($this->encryptdata['CF']) AND !empty($this->encryptdata['CF'])) {
  13890. $out .= ' /CF <<';
  13891. $out .= ' /'.$this->encryptdata['StmF'].' <<';
  13892. $out .= ' /Type /CryptFilter';
  13893. if (isset($this->encryptdata['CF']['CFM']) AND !empty($this->encryptdata['CF']['CFM'])) {
  13894. // The method used
  13895. $out .= ' /CFM /'.$this->encryptdata['CF']['CFM'];
  13896. if ($this->encryptdata['pubkey']) {
  13897. $out .= ' /Recipients [';
  13898. foreach ($this->encryptdata['Recipients'] as $rec) {
  13899. $out .= ' <'.$rec.'>';
  13900. }
  13901. $out .= ' ]';
  13902. if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) {
  13903. $out .= ' /EncryptMetadata false';
  13904. } else {
  13905. $out .= ' /EncryptMetadata true';
  13906. }
  13907. }
  13908. } else {
  13909. $out .= ' /CFM /None';
  13910. }
  13911. if (isset($this->encryptdata['CF']['AuthEvent']) AND !empty($this->encryptdata['CF']['AuthEvent'])) {
  13912. // The event to be used to trigger the authorization that is required to access encryption keys used by this filter.
  13913. $out .= ' /AuthEvent /'.$this->encryptdata['CF']['AuthEvent'];
  13914. } else {
  13915. $out .= ' /AuthEvent /DocOpen';
  13916. }
  13917. if (isset($this->encryptdata['CF']['Length']) AND !empty($this->encryptdata['CF']['Length'])) {
  13918. // The bit length of the encryption key.
  13919. $out .= ' /Length '.$this->encryptdata['CF']['Length'];
  13920. }
  13921. $out .= ' >> >>';
  13922. }
  13923. // The name of the crypt filter that shall be used by default when decrypting streams.
  13924. $out .= ' /StmF /'.$this->encryptdata['StmF'];
  13925. // The name of the crypt filter that shall be used when decrypting all strings in the document.
  13926. $out .= ' /StrF /'.$this->encryptdata['StrF'];
  13927. if (isset($this->encryptdata['EFF']) AND !empty($this->encryptdata['EFF'])) {
  13928. // The name of the crypt filter that shall be used when encrypting embedded file streams that do not have their own crypt filter specifier.
  13929. $out .= ' /EFF /'.$this->encryptdata[''];
  13930. }
  13931. }
  13932. // Additional encryption dictionary entries for the standard security handler
  13933. if ($this->encryptdata['pubkey']) {
  13934. if (($this->encryptdata['V'] < 4) AND isset($this->encryptdata['Recipients']) AND !empty($this->encryptdata['Recipients'])) {
  13935. $out .= ' /Recipients [';
  13936. foreach ($this->encryptdata['Recipients'] as $rec) {
  13937. $out .= ' <'.$rec.'>';
  13938. }
  13939. $out .= ' ]';
  13940. }
  13941. } else {
  13942. $out .= ' /R';
  13943. if ($this->encryptdata['V'] == 5) { // AES-256
  13944. $out .= ' 5';
  13945. $out .= ' /OE ('.$this->_escape($this->encryptdata['OE']).')';
  13946. $out .= ' /UE ('.$this->_escape($this->encryptdata['UE']).')';
  13947. $out .= ' /Perms ('.$this->_escape($this->encryptdata['perms']).')';
  13948. } elseif ($this->encryptdata['V'] == 4) { // AES-128
  13949. $out .= ' 4';
  13950. } elseif ($this->encryptdata['V'] < 2) { // RC-40
  13951. $out .= ' 2';
  13952. } else { // RC-128
  13953. $out .= ' 3';
  13954. }
  13955. $out .= ' /O ('.$this->_escape($this->encryptdata['O']).')';
  13956. $out .= ' /U ('.$this->_escape($this->encryptdata['U']).')';
  13957. $out .= ' /P '.$this->encryptdata['P'];
  13958. if (isset($this->encryptdata['EncryptMetadata']) AND (!$this->encryptdata['EncryptMetadata'])) {
  13959. $out .= ' /EncryptMetadata false';
  13960. } else {
  13961. $out .= ' /EncryptMetadata true';
  13962. }
  13963. }
  13964. $out .= ' >>';
  13965. $out .= "\n".'endobj';
  13966. $this->_out($out);
  13967. }
  13968. /**
  13969. * Returns the input text encrypted using RC4 algorithm and the specified key.
  13970. * RC4 is the standard encryption algorithm used in PDF format
  13971. * @param $key (string) encryption key
  13972. * @param $text (String) input text to be encrypted
  13973. * @return String encrypted text
  13974. * @protected
  13975. * @since 2.0.000 (2008-01-02)
  13976. * @author Klemen Vodopivec, Nicola Asuni
  13977. */
  13978. protected function _RC4($key, $text) {
  13979. if (function_exists('mcrypt_decrypt') AND ($out = @mcrypt_decrypt(MCRYPT_ARCFOUR, $key, $text, MCRYPT_MODE_STREAM, ''))) {
  13980. // try to use mcrypt function if exist
  13981. return $out;
  13982. }
  13983. if ($this->last_enc_key != $key) {
  13984. $k = str_repeat($key, ((256 / strlen($key)) + 1));
  13985. $rc4 = range(0, 255);
  13986. $j = 0;
  13987. for ($i = 0; $i < 256; ++$i) {
  13988. $t = $rc4[$i];
  13989. $j = ($j + $t + ord($k[$i])) % 256;
  13990. $rc4[$i] = $rc4[$j];
  13991. $rc4[$j] = $t;
  13992. }
  13993. $this->last_enc_key = $key;
  13994. $this->last_enc_key_c = $rc4;
  13995. } else {
  13996. $rc4 = $this->last_enc_key_c;
  13997. }
  13998. $len = strlen($text);
  13999. $a = 0;
  14000. $b = 0;
  14001. $out = '';
  14002. for ($i = 0; $i < $len; ++$i) {
  14003. $a = ($a + 1) % 256;
  14004. $t = $rc4[$a];
  14005. $b = ($b + $t) % 256;
  14006. $rc4[$a] = $rc4[$b];
  14007. $rc4[$b] = $t;
  14008. $k = $rc4[($rc4[$a] + $rc4[$b]) % 256];
  14009. $out .= chr(ord($text[$i]) ^ $k);
  14010. }
  14011. return $out;
  14012. }
  14013. /**
  14014. * Returns the input text exrypted using AES algorithm and the specified key.
  14015. * This method requires mcrypt.
  14016. * @param $key (string) encryption key
  14017. * @param $text (String) input text to be encrypted
  14018. * @return String encrypted text
  14019. * @protected
  14020. * @author Nicola Asuni
  14021. * @since 5.0.005 (2010-05-11)
  14022. */
  14023. protected function _AES($key, $text) {
  14024. // padding (RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0)
  14025. $padding = 16 - (strlen($text) % 16);
  14026. $text .= str_repeat(chr($padding), $padding);
  14027. $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND);
  14028. $text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv);
  14029. $text = $iv.$text;
  14030. return $text;
  14031. }
  14032. /**
  14033. * Encrypts a string using MD5 and returns it's value as a binary string.
  14034. * @param $str (string) input string
  14035. * @return String MD5 encrypted binary string
  14036. * @protected
  14037. * @since 2.0.000 (2008-01-02)
  14038. * @author Klemen Vodopivec
  14039. */
  14040. protected function _md5_16($str) {
  14041. return pack('H*', md5($str));
  14042. }
  14043. /**
  14044. * Compute U value (used for encryption)
  14045. * @return string U value
  14046. * @protected
  14047. * @since 2.0.000 (2008-01-02)
  14048. * @author Nicola Asuni
  14049. */
  14050. protected function _Uvalue() {
  14051. if ($this->encryptdata['mode'] == 0) { // RC4-40
  14052. return $this->_RC4($this->encryptdata['key'], $this->enc_padding);
  14053. } elseif ($this->encryptdata['mode'] < 3) { // RC4-128, AES-128
  14054. $tmp = $this->_md5_16($this->enc_padding.$this->encryptdata['fileid']);
  14055. $enc = $this->_RC4($this->encryptdata['key'], $tmp);
  14056. $len = strlen($tmp);
  14057. for ($i = 1; $i <= 19; ++$i) {
  14058. $ek = '';
  14059. for ($j = 0; $j < $len; ++$j) {
  14060. $ek .= chr(ord($this->encryptdata['key'][$j]) ^ $i);
  14061. }
  14062. $enc = $this->_RC4($ek, $enc);
  14063. }
  14064. $enc .= str_repeat("\x00", 16);
  14065. return substr($enc, 0, 32);
  14066. } elseif ($this->encryptdata['mode'] == 3) { // AES-256
  14067. $seed = $this->_md5_16($this->getRandomSeed());
  14068. // User Validation Salt
  14069. $this->encryptdata['UVS'] = substr($seed, 0, 8);
  14070. // User Key Salt
  14071. $this->encryptdata['UKS'] = substr($seed, 8, 16);
  14072. return hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UVS'], true).$this->encryptdata['UVS'].$this->encryptdata['UKS'];
  14073. }
  14074. }
  14075. /**
  14076. * Compute UE value (used for encryption)
  14077. * @return string UE value
  14078. * @protected
  14079. * @since 5.9.006 (2010-10-19)
  14080. * @author Nicola Asuni
  14081. */
  14082. protected function _UEvalue() {
  14083. $hashkey = hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UKS'], true);
  14084. $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
  14085. return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $hashkey, $this->encryptdata['key'], MCRYPT_MODE_CBC, $iv);
  14086. }
  14087. /**
  14088. * Compute O value (used for encryption)
  14089. * @return string O value
  14090. * @protected
  14091. * @since 2.0.000 (2008-01-02)
  14092. * @author Nicola Asuni
  14093. */
  14094. protected function _Ovalue() {
  14095. if ($this->encryptdata['mode'] < 3) { // RC4-40, RC4-128, AES-128
  14096. $tmp = $this->_md5_16($this->encryptdata['owner_password']);
  14097. if ($this->encryptdata['mode'] > 0) {
  14098. for ($i = 0; $i < 50; ++$i) {
  14099. $tmp = $this->_md5_16($tmp);
  14100. }
  14101. }
  14102. $owner_key = substr($tmp, 0, ($this->encryptdata['Length'] / 8));
  14103. $enc = $this->_RC4($owner_key, $this->encryptdata['user_password']);
  14104. if ($this->encryptdata['mode'] > 0) {
  14105. $len = strlen($owner_key);
  14106. for ($i = 1; $i <= 19; ++$i) {
  14107. $ek = '';
  14108. for ($j = 0; $j < $len; ++$j) {
  14109. $ek .= chr(ord($owner_key[$j]) ^ $i);
  14110. }
  14111. $enc = $this->_RC4($ek, $enc);
  14112. }
  14113. }
  14114. return $enc;
  14115. } elseif ($this->encryptdata['mode'] == 3) { // AES-256
  14116. $seed = $this->_md5_16($this->getRandomSeed());
  14117. // Owner Validation Salt
  14118. $this->encryptdata['OVS'] = substr($seed, 0, 8);
  14119. // Owner Key Salt
  14120. $this->encryptdata['OKS'] = substr($seed, 8, 16);
  14121. return hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OVS'].$this->encryptdata['U'], true).$this->encryptdata['OVS'].$this->encryptdata['OKS'];
  14122. }
  14123. }
  14124. /**
  14125. * Compute OE value (used for encryption)
  14126. * @return string OE value
  14127. * @protected
  14128. * @since 5.9.006 (2010-10-19)
  14129. * @author Nicola Asuni
  14130. */
  14131. protected function _OEvalue() {
  14132. $hashkey = hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OKS'].$this->encryptdata['U'], true);
  14133. $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
  14134. return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $hashkey, $this->encryptdata['key'], MCRYPT_MODE_CBC, $iv);
  14135. }
  14136. /**
  14137. * Convert password for AES-256 encryption mode
  14138. * @param $password (string) password
  14139. * @return string password
  14140. * @protected
  14141. * @since 5.9.006 (2010-10-19)
  14142. * @author Nicola Asuni
  14143. */
  14144. protected function _fixAES256Password($password) {
  14145. $psw = ''; // password to be returned
  14146. $psw_array = $this->utf8Bidi($this->UTF8StringToArray($password), $password, $this->rtl);
  14147. foreach ($psw_array as $c) {
  14148. $psw .= $this->unichr($c);
  14149. }
  14150. return substr($psw, 0, 127);
  14151. }
  14152. /**
  14153. * Compute encryption key
  14154. * @protected
  14155. * @since 2.0.000 (2008-01-02)
  14156. * @author Nicola Asuni
  14157. */
  14158. protected function _generateencryptionkey() {
  14159. $keybytelen = ($this->encryptdata['Length'] / 8);
  14160. if (!$this->encryptdata['pubkey']) { // standard mode
  14161. if ($this->encryptdata['mode'] == 3) { // AES-256
  14162. // generate 256 bit random key
  14163. $this->encryptdata['key'] = substr(hash('sha256', $this->getRandomSeed(), true), 0, $keybytelen);
  14164. // truncate passwords
  14165. $this->encryptdata['user_password'] = $this->_fixAES256Password($this->encryptdata['user_password']);
  14166. $this->encryptdata['owner_password'] = $this->_fixAES256Password($this->encryptdata['owner_password']);
  14167. // Compute U value
  14168. $this->encryptdata['U'] = $this->_Uvalue();
  14169. // Compute UE value
  14170. $this->encryptdata['UE'] = $this->_UEvalue();
  14171. // Compute O value
  14172. $this->encryptdata['O'] = $this->_Ovalue();
  14173. // Compute OE value
  14174. $this->encryptdata['OE'] = $this->_OEvalue();
  14175. // Compute P value
  14176. $this->encryptdata['P'] = $this->encryptdata['protection'];
  14177. // Computing the encryption dictionary's Perms (permissions) value
  14178. $perms = $this->getEncPermissionsString($this->encryptdata['protection']); // bytes 0-3
  14179. $perms .= chr(255).chr(255).chr(255).chr(255); // bytes 4-7
  14180. if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) { // byte 8
  14181. $perms .= 'F';
  14182. } else {
  14183. $perms .= 'T';
  14184. }
  14185. $perms .= 'adb'; // bytes 9-11
  14186. $perms .= 'nick'; // bytes 12-15
  14187. $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB));
  14188. $this->encryptdata['perms'] = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->encryptdata['key'], $perms, MCRYPT_MODE_ECB, $iv);
  14189. } else { // RC4-40, RC4-128, AES-128
  14190. // Pad passwords
  14191. $this->encryptdata['user_password'] = substr($this->encryptdata['user_password'].$this->enc_padding, 0, 32);
  14192. $this->encryptdata['owner_password'] = substr($this->encryptdata['owner_password'].$this->enc_padding, 0, 32);
  14193. // Compute O value
  14194. $this->encryptdata['O'] = $this->_Ovalue();
  14195. // get default permissions (reverse byte order)
  14196. $permissions = $this->getEncPermissionsString($this->encryptdata['protection']);
  14197. // Compute encryption key
  14198. $tmp = $this->_md5_16($this->encryptdata['user_password'].$this->encryptdata['O'].$permissions.$this->encryptdata['fileid']);
  14199. if ($this->encryptdata['mode'] > 0) {
  14200. for ($i = 0; $i < 50; ++$i) {
  14201. $tmp = $this->_md5_16(substr($tmp, 0, $keybytelen));
  14202. }
  14203. }
  14204. $this->encryptdata['key'] = substr($tmp, 0, $keybytelen);
  14205. // Compute U value
  14206. $this->encryptdata['U'] = $this->_Uvalue();
  14207. // Compute P value
  14208. $this->encryptdata['P'] = $this->encryptdata['protection'];
  14209. }
  14210. } else { // Public-Key mode
  14211. // random 20-byte seed
  14212. $seed = sha1($this->getRandomSeed(), true);
  14213. $recipient_bytes = '';
  14214. foreach ($this->encryptdata['pubkeys'] as $pubkey) {
  14215. // for each public certificate
  14216. if (isset($pubkey['p'])) {
  14217. $pkprotection = $this->getUserPermissionCode($pubkey['p'], $this->encryptdata['mode']);
  14218. } else {
  14219. $pkprotection = $this->encryptdata['protection'];
  14220. }
  14221. // get default permissions (reverse byte order)
  14222. $pkpermissions = $this->getEncPermissionsString($pkprotection);
  14223. // envelope data
  14224. $envelope = $seed.$pkpermissions;
  14225. // write the envelope data to a temporary file
  14226. $tempkeyfile = tempnam(K_PATH_CACHE, 'tmpkey_');
  14227. $f = fopen($tempkeyfile, 'wb');
  14228. if (!$f) {
  14229. $this->Error('Unable to create temporary key file: '.$tempkeyfile);
  14230. }
  14231. $envelope_length = strlen($envelope);
  14232. fwrite($f, $envelope, $envelope_length);
  14233. fclose($f);
  14234. $tempencfile = tempnam(K_PATH_CACHE, 'tmpenc_');
  14235. if (!openssl_pkcs7_encrypt($tempkeyfile, $tempencfile, $pubkey['c'], array(), PKCS7_BINARY | PKCS7_DETACHED)) {
  14236. $this->Error('Unable to encrypt the file: '.$tempkeyfile);
  14237. }
  14238. unlink($tempkeyfile);
  14239. // read encryption signature
  14240. $signature = file_get_contents($tempencfile, false, null, $envelope_length);
  14241. unlink($tempencfile);
  14242. // extract signature
  14243. $signature = substr($signature, strpos($signature, 'Content-Disposition'));
  14244. $tmparr = explode("\n\n", $signature);
  14245. $signature = trim($tmparr[1]);
  14246. unset($tmparr);
  14247. // decode signature
  14248. $signature = base64_decode($signature);
  14249. // convert signature to hex
  14250. $hexsignature = current(unpack('H*', $signature));
  14251. // store signature on recipients array
  14252. $this->encryptdata['Recipients'][] = $hexsignature;
  14253. // The bytes of each item in the Recipients array of PKCS#7 objects in the order in which they appear in the array
  14254. $recipient_bytes .= $signature;
  14255. }
  14256. // calculate encryption key
  14257. if ($this->encryptdata['mode'] == 3) { // AES-256
  14258. $this->encryptdata['key'] = substr(hash('sha256', $seed.$recipient_bytes, true), 0, $keybytelen);
  14259. } else { // RC4-40, RC4-128, AES-128
  14260. $this->encryptdata['key'] = substr(sha1($seed.$recipient_bytes, true), 0, $keybytelen);
  14261. }
  14262. }
  14263. }
  14264. /**
  14265. * Return the premission code used on encryption (P value).
  14266. * @param $permissions (Array) the set of permissions (specify the ones you want to block).
  14267. * @param $mode (int) encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
  14268. * @protected
  14269. * @since 5.0.005 (2010-05-12)
  14270. * @author Nicola Asuni
  14271. */
  14272. protected function getUserPermissionCode($permissions, $mode=0) {
  14273. $options = array(
  14274. 'owner' => 2, // bit 2 -- inverted logic: cleared by default
  14275. 'print' => 4, // bit 3
  14276. 'modify' => 8, // bit 4
  14277. 'copy' => 16, // bit 5
  14278. 'annot-forms' => 32, // bit 6
  14279. 'fill-forms' => 256, // bit 9
  14280. 'extract' => 512, // bit 10
  14281. 'assemble' => 1024,// bit 11
  14282. 'print-high' => 2048 // bit 12
  14283. );
  14284. $protection = 2147422012; // 32 bit: (01111111 11111111 00001111 00111100)
  14285. foreach ($permissions as $permission) {
  14286. if (!isset($options[$permission])) {
  14287. $this->Error('Incorrect permission: '.$permission);
  14288. }
  14289. if (($mode > 0) OR ($options[$permission] <= 32)) {
  14290. // set only valid permissions
  14291. if ($options[$permission] == 2) {
  14292. // the logic for bit 2 is inverted (cleared by default)
  14293. $protection += $options[$permission];
  14294. } else {
  14295. $protection -= $options[$permission];
  14296. }
  14297. }
  14298. }
  14299. return $protection;
  14300. }
  14301. /**
  14302. * Set document protection
  14303. * Remark: the protection against modification is for people who have the full Acrobat product.
  14304. * 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.
  14305. * 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.
  14306. * @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>
  14307. * @param $user_pass (String) user password. Empty by default.
  14308. * @param $owner_pass (String) owner password. If not specified, a random value is used.
  14309. * @param $mode (int) encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
  14310. * @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')))
  14311. * @public
  14312. * @since 2.0.000 (2008-01-02)
  14313. * @author Nicola Asuni
  14314. */
  14315. 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) {
  14316. if ($this->pdfa_mode) {
  14317. // encryption is not allowed in PDF/A mode
  14318. return;
  14319. }
  14320. $this->encryptdata['protection'] = $this->getUserPermissionCode($permissions, $mode);
  14321. if (($pubkeys !== null) AND (is_array($pubkeys))) {
  14322. // public-key mode
  14323. $this->encryptdata['pubkeys'] = $pubkeys;
  14324. if ($mode == 0) {
  14325. // public-Key Security requires at least 128 bit
  14326. $mode = 1;
  14327. }
  14328. if (!function_exists('openssl_pkcs7_encrypt')) {
  14329. $this->Error('Public-Key Security requires openssl library.');
  14330. }
  14331. // Set Public-Key filter (availabe are: Entrust.PPKEF, Adobe.PPKLite, Adobe.PubSec)
  14332. $this->encryptdata['pubkey'] = true;
  14333. $this->encryptdata['Filter'] = 'Adobe.PubSec';
  14334. $this->encryptdata['StmF'] = 'DefaultCryptFilter';
  14335. $this->encryptdata['StrF'] = 'DefaultCryptFilter';
  14336. } else {
  14337. // standard mode (password mode)
  14338. $this->encryptdata['pubkey'] = false;
  14339. $this->encryptdata['Filter'] = 'Standard';
  14340. $this->encryptdata['StmF'] = 'StdCF';
  14341. $this->encryptdata['StrF'] = 'StdCF';
  14342. }
  14343. if ($mode > 1) { // AES
  14344. if (!extension_loaded('mcrypt')) {
  14345. $this->Error('AES encryption requires mcrypt library (http://www.php.net/manual/en/mcrypt.requirements.php).');
  14346. }
  14347. if (mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128) === false) {
  14348. $this->Error('AES encryption requires MCRYPT_RIJNDAEL_128 cypher.');
  14349. }
  14350. if (($mode == 3) AND !function_exists('hash')) {
  14351. // the Hash extension requires no external libraries and is enabled by default as of PHP 5.1.2.
  14352. $this->Error('AES 256 encryption requires HASH Message Digest Framework (http://www.php.net/manual/en/book.hash.php).');
  14353. }
  14354. }
  14355. if ($owner_pass === null) {
  14356. $owner_pass = md5($this->getRandomSeed());
  14357. }
  14358. $this->encryptdata['user_password'] = $user_pass;
  14359. $this->encryptdata['owner_password'] = $owner_pass;
  14360. $this->encryptdata['mode'] = $mode;
  14361. switch ($mode) {
  14362. case 0: { // RC4 40 bit
  14363. $this->encryptdata['V'] = 1;
  14364. $this->encryptdata['Length'] = 40;
  14365. $this->encryptdata['CF']['CFM'] = 'V2';
  14366. break;
  14367. }
  14368. case 1: { // RC4 128 bit
  14369. $this->encryptdata['V'] = 2;
  14370. $this->encryptdata['Length'] = 128;
  14371. $this->encryptdata['CF']['CFM'] = 'V2';
  14372. if ($this->encryptdata['pubkey']) {
  14373. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s4';
  14374. $this->encryptdata['Recipients'] = array();
  14375. }
  14376. break;
  14377. }
  14378. case 2: { // AES 128 bit
  14379. $this->encryptdata['V'] = 4;
  14380. $this->encryptdata['Length'] = 128;
  14381. $this->encryptdata['CF']['CFM'] = 'AESV2';
  14382. $this->encryptdata['CF']['Length'] = 128;
  14383. if ($this->encryptdata['pubkey']) {
  14384. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  14385. $this->encryptdata['Recipients'] = array();
  14386. }
  14387. break;
  14388. }
  14389. case 3: { // AES 256 bit
  14390. $this->encryptdata['V'] = 5;
  14391. $this->encryptdata['Length'] = 256;
  14392. $this->encryptdata['CF']['CFM'] = 'AESV3';
  14393. $this->encryptdata['CF']['Length'] = 256;
  14394. if ($this->encryptdata['pubkey']) {
  14395. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  14396. $this->encryptdata['Recipients'] = array();
  14397. }
  14398. break;
  14399. }
  14400. }
  14401. $this->encrypted = true;
  14402. $this->encryptdata['fileid'] = $this->convertHexStringToString($this->file_id);
  14403. $this->_generateencryptionkey();
  14404. }
  14405. /**
  14406. * Convert hexadecimal string to string
  14407. * @param $bs (string) byte-string to convert
  14408. * @return String
  14409. * @protected
  14410. * @since 5.0.005 (2010-05-12)
  14411. * @author Nicola Asuni
  14412. */
  14413. protected function convertHexStringToString($bs) {
  14414. $string = ''; // string to be returned
  14415. $bslength = strlen($bs);
  14416. if (($bslength % 2) != 0) {
  14417. // padding
  14418. $bs .= '0';
  14419. ++$bslength;
  14420. }
  14421. for ($i = 0; $i < $bslength; $i += 2) {
  14422. $string .= chr(hexdec($bs[$i].$bs[($i + 1)]));
  14423. }
  14424. return $string;
  14425. }
  14426. /**
  14427. * Convert string to hexadecimal string (byte string)
  14428. * @param $s (string) string to convert
  14429. * @return byte string
  14430. * @protected
  14431. * @since 5.0.010 (2010-05-17)
  14432. * @author Nicola Asuni
  14433. */
  14434. protected function convertStringToHexString($s) {
  14435. $bs = '';
  14436. $chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY);
  14437. foreach ($chars as $c) {
  14438. $bs .= sprintf('%02s', dechex(ord($c)));
  14439. }
  14440. return $bs;
  14441. }
  14442. /**
  14443. * Convert encryption P value to a string of bytes, low-order byte first.
  14444. * @param $protection (string) 32bit encryption permission value (P value)
  14445. * @return String
  14446. * @protected
  14447. * @since 5.0.005 (2010-05-12)
  14448. * @author Nicola Asuni
  14449. */
  14450. protected function getEncPermissionsString($protection) {
  14451. $binprot = sprintf('%032b', $protection);
  14452. $str = chr(bindec(substr($binprot, 24, 8)));
  14453. $str .= chr(bindec(substr($binprot, 16, 8)));
  14454. $str .= chr(bindec(substr($binprot, 8, 8)));
  14455. $str .= chr(bindec(substr($binprot, 0, 8)));
  14456. return $str;
  14457. }
  14458. // END OF ENCRYPTION FUNCTIONS -------------------------
  14459. // START TRANSFORMATIONS SECTION -----------------------
  14460. /**
  14461. * Starts a 2D tranformation saving current graphic state.
  14462. * This function must be called before scaling, mirroring, translation, rotation and skewing.
  14463. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  14464. * @public
  14465. * @since 2.1.000 (2008-01-07)
  14466. * @see StartTransform(), StopTransform()
  14467. */
  14468. public function StartTransform() {
  14469. if ($this->state != 2) {
  14470. return;
  14471. }
  14472. $this->_out('q');
  14473. if ($this->inxobj) {
  14474. // we are inside an XObject template
  14475. $this->xobjects[$this->xobjid]['transfmrk'][] = strlen($this->xobjects[$this->xobjid]['outdata']);
  14476. } else {
  14477. $this->transfmrk[$this->page][] = $this->pagelen[$this->page];
  14478. }
  14479. ++$this->transfmatrix_key;
  14480. $this->transfmatrix[$this->transfmatrix_key] = array();
  14481. }
  14482. /**
  14483. * Stops a 2D tranformation restoring previous graphic state.
  14484. * This function must be called after scaling, mirroring, translation, rotation and skewing.
  14485. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  14486. * @public
  14487. * @since 2.1.000 (2008-01-07)
  14488. * @see StartTransform(), StopTransform()
  14489. */
  14490. public function StopTransform() {
  14491. if ($this->state != 2) {
  14492. return;
  14493. }
  14494. $this->_out('Q');
  14495. if (isset($this->transfmatrix[$this->transfmatrix_key])) {
  14496. array_pop($this->transfmatrix[$this->transfmatrix_key]);
  14497. --$this->transfmatrix_key;
  14498. }
  14499. if ($this->inxobj) {
  14500. // we are inside an XObject template
  14501. array_pop($this->xobjects[$this->xobjid]['transfmrk']);
  14502. } else {
  14503. array_pop($this->transfmrk[$this->page]);
  14504. }
  14505. }
  14506. /**
  14507. * Horizontal Scaling.
  14508. * @param $s_x (float) scaling factor for width as percent. 0 is not allowed.
  14509. * @param $x (int) abscissa of the scaling center. Default is current x position
  14510. * @param $y (int) ordinate of the scaling center. Default is current y position
  14511. * @public
  14512. * @since 2.1.000 (2008-01-07)
  14513. * @see StartTransform(), StopTransform()
  14514. */
  14515. public function ScaleX($s_x, $x='', $y='') {
  14516. $this->Scale($s_x, 100, $x, $y);
  14517. }
  14518. /**
  14519. * Vertical Scaling.
  14520. * @param $s_y (float) scaling factor for height as percent. 0 is not allowed.
  14521. * @param $x (int) abscissa of the scaling center. Default is current x position
  14522. * @param $y (int) ordinate of the scaling center. Default is current y position
  14523. * @public
  14524. * @since 2.1.000 (2008-01-07)
  14525. * @see StartTransform(), StopTransform()
  14526. */
  14527. public function ScaleY($s_y, $x='', $y='') {
  14528. $this->Scale(100, $s_y, $x, $y);
  14529. }
  14530. /**
  14531. * Vertical and horizontal proportional Scaling.
  14532. * @param $s (float) scaling factor for width and height as percent. 0 is not allowed.
  14533. * @param $x (int) abscissa of the scaling center. Default is current x position
  14534. * @param $y (int) ordinate of the scaling center. Default is current y position
  14535. * @public
  14536. * @since 2.1.000 (2008-01-07)
  14537. * @see StartTransform(), StopTransform()
  14538. */
  14539. public function ScaleXY($s, $x='', $y='') {
  14540. $this->Scale($s, $s, $x, $y);
  14541. }
  14542. /**
  14543. * Vertical and horizontal non-proportional Scaling.
  14544. * @param $s_x (float) scaling factor for width as percent. 0 is not allowed.
  14545. * @param $s_y (float) scaling factor for height as percent. 0 is not allowed.
  14546. * @param $x (int) abscissa of the scaling center. Default is current x position
  14547. * @param $y (int) ordinate of the scaling center. Default is current y position
  14548. * @public
  14549. * @since 2.1.000 (2008-01-07)
  14550. * @see StartTransform(), StopTransform()
  14551. */
  14552. public function Scale($s_x, $s_y, $x='', $y='') {
  14553. if ($x === '') {
  14554. $x = $this->x;
  14555. }
  14556. if ($y === '') {
  14557. $y = $this->y;
  14558. }
  14559. if (($s_x == 0) OR ($s_y == 0)) {
  14560. $this->Error('Please do not use values equal to zero for scaling');
  14561. }
  14562. $y = ($this->h - $y) * $this->k;
  14563. $x *= $this->k;
  14564. //calculate elements of transformation matrix
  14565. $s_x /= 100;
  14566. $s_y /= 100;
  14567. $tm = array();
  14568. $tm[0] = $s_x;
  14569. $tm[1] = 0;
  14570. $tm[2] = 0;
  14571. $tm[3] = $s_y;
  14572. $tm[4] = $x * (1 - $s_x);
  14573. $tm[5] = $y * (1 - $s_y);
  14574. //scale the coordinate system
  14575. $this->Transform($tm);
  14576. }
  14577. /**
  14578. * Horizontal Mirroring.
  14579. * @param $x (int) abscissa of the point. Default is current x position
  14580. * @public
  14581. * @since 2.1.000 (2008-01-07)
  14582. * @see StartTransform(), StopTransform()
  14583. */
  14584. public function MirrorH($x='') {
  14585. $this->Scale(-100, 100, $x);
  14586. }
  14587. /**
  14588. * Verical Mirroring.
  14589. * @param $y (int) ordinate of the point. Default is current y position
  14590. * @public
  14591. * @since 2.1.000 (2008-01-07)
  14592. * @see StartTransform(), StopTransform()
  14593. */
  14594. public function MirrorV($y='') {
  14595. $this->Scale(100, -100, '', $y);
  14596. }
  14597. /**
  14598. * Point reflection mirroring.
  14599. * @param $x (int) abscissa of the point. Default is current x position
  14600. * @param $y (int) ordinate of the point. Default is current y position
  14601. * @public
  14602. * @since 2.1.000 (2008-01-07)
  14603. * @see StartTransform(), StopTransform()
  14604. */
  14605. public function MirrorP($x='',$y='') {
  14606. $this->Scale(-100, -100, $x, $y);
  14607. }
  14608. /**
  14609. * Reflection against a straight line through point (x, y) with the gradient angle (angle).
  14610. * @param $angle (float) gradient angle of the straight line. Default is 0 (horizontal line).
  14611. * @param $x (int) abscissa of the point. Default is current x position
  14612. * @param $y (int) ordinate of the point. Default is current y position
  14613. * @public
  14614. * @since 2.1.000 (2008-01-07)
  14615. * @see StartTransform(), StopTransform()
  14616. */
  14617. public function MirrorL($angle=0, $x='',$y='') {
  14618. $this->Scale(-100, 100, $x, $y);
  14619. $this->Rotate(-2*($angle-90), $x, $y);
  14620. }
  14621. /**
  14622. * Translate graphic object horizontally.
  14623. * @param $t_x (int) movement to the right (or left for RTL)
  14624. * @public
  14625. * @since 2.1.000 (2008-01-07)
  14626. * @see StartTransform(), StopTransform()
  14627. */
  14628. public function TranslateX($t_x) {
  14629. $this->Translate($t_x, 0);
  14630. }
  14631. /**
  14632. * Translate graphic object vertically.
  14633. * @param $t_y (int) movement to the bottom
  14634. * @public
  14635. * @since 2.1.000 (2008-01-07)
  14636. * @see StartTransform(), StopTransform()
  14637. */
  14638. public function TranslateY($t_y) {
  14639. $this->Translate(0, $t_y);
  14640. }
  14641. /**
  14642. * Translate graphic object horizontally and vertically.
  14643. * @param $t_x (int) movement to the right
  14644. * @param $t_y (int) movement to the bottom
  14645. * @public
  14646. * @since 2.1.000 (2008-01-07)
  14647. * @see StartTransform(), StopTransform()
  14648. */
  14649. public function Translate($t_x, $t_y) {
  14650. //calculate elements of transformation matrix
  14651. $tm = array();
  14652. $tm[0] = 1;
  14653. $tm[1] = 0;
  14654. $tm[2] = 0;
  14655. $tm[3] = 1;
  14656. $tm[4] = $t_x * $this->k;
  14657. $tm[5] = -$t_y * $this->k;
  14658. //translate the coordinate system
  14659. $this->Transform($tm);
  14660. }
  14661. /**
  14662. * Rotate object.
  14663. * @param $angle (float) angle in degrees for counter-clockwise rotation
  14664. * @param $x (int) abscissa of the rotation center. Default is current x position
  14665. * @param $y (int) ordinate of the rotation center. Default is current y position
  14666. * @public
  14667. * @since 2.1.000 (2008-01-07)
  14668. * @see StartTransform(), StopTransform()
  14669. */
  14670. public function Rotate($angle, $x='', $y='') {
  14671. if ($x === '') {
  14672. $x = $this->x;
  14673. }
  14674. if ($y === '') {
  14675. $y = $this->y;
  14676. }
  14677. $y = ($this->h - $y) * $this->k;
  14678. $x *= $this->k;
  14679. //calculate elements of transformation matrix
  14680. $tm = array();
  14681. $tm[0] = cos(deg2rad($angle));
  14682. $tm[1] = sin(deg2rad($angle));
  14683. $tm[2] = -$tm[1];
  14684. $tm[3] = $tm[0];
  14685. $tm[4] = $x + ($tm[1] * $y) - ($tm[0] * $x);
  14686. $tm[5] = $y - ($tm[0] * $y) - ($tm[1] * $x);
  14687. //rotate the coordinate system around ($x,$y)
  14688. $this->Transform($tm);
  14689. }
  14690. /**
  14691. * Skew horizontally.
  14692. * @param $angle_x (float) angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  14693. * @param $x (int) abscissa of the skewing center. default is current x position
  14694. * @param $y (int) ordinate of the skewing center. default is current y position
  14695. * @public
  14696. * @since 2.1.000 (2008-01-07)
  14697. * @see StartTransform(), StopTransform()
  14698. */
  14699. public function SkewX($angle_x, $x='', $y='') {
  14700. $this->Skew($angle_x, 0, $x, $y);
  14701. }
  14702. /**
  14703. * Skew vertically.
  14704. * @param $angle_y (float) angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  14705. * @param $x (int) abscissa of the skewing center. default is current x position
  14706. * @param $y (int) ordinate of the skewing center. default is current y position
  14707. * @public
  14708. * @since 2.1.000 (2008-01-07)
  14709. * @see StartTransform(), StopTransform()
  14710. */
  14711. public function SkewY($angle_y, $x='', $y='') {
  14712. $this->Skew(0, $angle_y, $x, $y);
  14713. }
  14714. /**
  14715. * Skew.
  14716. * @param $angle_x (float) angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  14717. * @param $angle_y (float) angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  14718. * @param $x (int) abscissa of the skewing center. default is current x position
  14719. * @param $y (int) ordinate of the skewing center. default is current y position
  14720. * @public
  14721. * @since 2.1.000 (2008-01-07)
  14722. * @see StartTransform(), StopTransform()
  14723. */
  14724. public function Skew($angle_x, $angle_y, $x='', $y='') {
  14725. if ($x === '') {
  14726. $x = $this->x;
  14727. }
  14728. if ($y === '') {
  14729. $y = $this->y;
  14730. }
  14731. if (($angle_x <= -90) OR ($angle_x >= 90) OR ($angle_y <= -90) OR ($angle_y >= 90)) {
  14732. $this->Error('Please use values between -90 and +90 degrees for Skewing.');
  14733. }
  14734. $x *= $this->k;
  14735. $y = ($this->h - $y) * $this->k;
  14736. //calculate elements of transformation matrix
  14737. $tm = array();
  14738. $tm[0] = 1;
  14739. $tm[1] = tan(deg2rad($angle_y));
  14740. $tm[2] = tan(deg2rad($angle_x));
  14741. $tm[3] = 1;
  14742. $tm[4] = -$tm[2] * $y;
  14743. $tm[5] = -$tm[1] * $x;
  14744. //skew the coordinate system
  14745. $this->Transform($tm);
  14746. }
  14747. /**
  14748. * Apply graphic transformations.
  14749. * @param $tm (array) transformation matrix
  14750. * @protected
  14751. * @since 2.1.000 (2008-01-07)
  14752. * @see StartTransform(), StopTransform()
  14753. */
  14754. protected function Transform($tm) {
  14755. if ($this->state != 2) {
  14756. return;
  14757. }
  14758. $this->_out(sprintf('%F %F %F %F %F %F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
  14759. // add tranformation matrix
  14760. $this->transfmatrix[$this->transfmatrix_key][] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]);
  14761. // update transformation mark
  14762. if ($this->inxobj) {
  14763. // we are inside an XObject template
  14764. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  14765. $key = key($this->xobjects[$this->xobjid]['transfmrk']);
  14766. $this->xobjects[$this->xobjid]['transfmrk'][$key] = strlen($this->xobjects[$this->xobjid]['outdata']);
  14767. }
  14768. } elseif (end($this->transfmrk[$this->page]) !== false) {
  14769. $key = key($this->transfmrk[$this->page]);
  14770. $this->transfmrk[$this->page][$key] = $this->pagelen[$this->page];
  14771. }
  14772. }
  14773. // END TRANSFORMATIONS SECTION -------------------------
  14774. // START GRAPHIC FUNCTIONS SECTION ---------------------
  14775. // The following section is based on the code provided by David Hernandez Sanz
  14776. /**
  14777. * 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.
  14778. * @param $width (float) The width.
  14779. * @public
  14780. * @since 1.0
  14781. * @see Line(), Rect(), Cell(), MultiCell()
  14782. */
  14783. public function SetLineWidth($width) {
  14784. //Set line width
  14785. $this->LineWidth = $width;
  14786. $this->linestyleWidth = sprintf('%F w', ($width * $this->k));
  14787. if ($this->state == 2) {
  14788. $this->_out($this->linestyleWidth);
  14789. }
  14790. }
  14791. /**
  14792. * Returns the current the line width.
  14793. * @return int Line width
  14794. * @public
  14795. * @since 2.1.000 (2008-01-07)
  14796. * @see Line(), SetLineWidth()
  14797. */
  14798. public function GetLineWidth() {
  14799. return $this->LineWidth;
  14800. }
  14801. /**
  14802. * Set line style.
  14803. * @param $style (array) Line style. Array with keys among the following:
  14804. * <ul>
  14805. * <li>width (float): Width of the line in user units.</li>
  14806. * <li>cap (string): Type of cap to put on the line. Possible values are:
  14807. * butt, round, square. The difference between "square" and "butt" is that
  14808. * "square" projects a flat end past the end of the line.</li>
  14809. * <li>join (string): Type of join. Possible values are: miter, round,
  14810. * bevel.</li>
  14811. * <li>dash (mixed): Dash pattern. Is 0 (without dash) or string with
  14812. * series of length values, which are the lengths of the on and off dashes.
  14813. * For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
  14814. * 1 off, 2 on, 1 off, ...</li>
  14815. * <li>phase (integer): Modifier on the dash pattern which is used to shift
  14816. * the point at which the pattern starts.</li>
  14817. * <li>color (array): Draw color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName).</li>
  14818. * </ul>
  14819. * @param $ret (boolean) if true do not send the command.
  14820. * @return string the PDF command
  14821. * @public
  14822. * @since 2.1.000 (2008-01-08)
  14823. */
  14824. public function SetLineStyle($style, $ret=false) {
  14825. $s = ''; // string to be returned
  14826. if (!is_array($style)) {
  14827. return;
  14828. }
  14829. if (isset($style['width'])) {
  14830. $this->LineWidth = $style['width'];
  14831. $this->linestyleWidth = sprintf('%F w', ($style['width'] * $this->k));
  14832. $s .= $this->linestyleWidth.' ';
  14833. }
  14834. if (isset($style['cap'])) {
  14835. $ca = array('butt' => 0, 'round'=> 1, 'square' => 2);
  14836. if (isset($ca[$style['cap']])) {
  14837. $this->linestyleCap = $ca[$style['cap']].' J';
  14838. $s .= $this->linestyleCap.' ';
  14839. }
  14840. }
  14841. if (isset($style['join'])) {
  14842. $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2);
  14843. if (isset($ja[$style['join']])) {
  14844. $this->linestyleJoin = $ja[$style['join']].' j';
  14845. $s .= $this->linestyleJoin.' ';
  14846. }
  14847. }
  14848. if (isset($style['dash'])) {
  14849. $dash_string = '';
  14850. if ($style['dash']) {
  14851. if (preg_match('/^.+,/', $style['dash']) > 0) {
  14852. $tab = explode(',', $style['dash']);
  14853. } else {
  14854. $tab = array($style['dash']);
  14855. }
  14856. $dash_string = '';
  14857. foreach ($tab as $i => $v) {
  14858. if ($i) {
  14859. $dash_string .= ' ';
  14860. }
  14861. $dash_string .= sprintf('%F', $v);
  14862. }
  14863. }
  14864. if (!isset($style['phase']) OR !$style['dash']) {
  14865. $style['phase'] = 0;
  14866. }
  14867. $this->linestyleDash = sprintf('[%s] %F d', $dash_string, $style['phase']);
  14868. $s .= $this->linestyleDash.' ';
  14869. }
  14870. if (isset($style['color'])) {
  14871. $s .= $this->SetDrawColorArray($style['color'], true).' ';
  14872. }
  14873. if (!$ret AND ($this->state == 2)) {
  14874. $this->_out($s);
  14875. }
  14876. return $s;
  14877. }
  14878. /**
  14879. * Begin a new subpath by moving the current point to coordinates (x, y), omitting any connecting line segment.
  14880. * @param $x (float) Abscissa of point.
  14881. * @param $y (float) Ordinate of point.
  14882. * @protected
  14883. * @since 2.1.000 (2008-01-08)
  14884. */
  14885. protected function _outPoint($x, $y) {
  14886. if ($this->state == 2) {
  14887. $this->_out(sprintf('%F %F m', ($x * $this->k), (($this->h - $y) * $this->k)));
  14888. }
  14889. }
  14890. /**
  14891. * Append a straight line segment from the current point to the point (x, y).
  14892. * The new current point shall be (x, y).
  14893. * @param $x (float) Abscissa of end point.
  14894. * @param $y (float) Ordinate of end point.
  14895. * @protected
  14896. * @since 2.1.000 (2008-01-08)
  14897. */
  14898. protected function _outLine($x, $y) {
  14899. if ($this->state == 2) {
  14900. $this->_out(sprintf('%F %F l', ($x * $this->k), (($this->h - $y) * $this->k)));
  14901. }
  14902. }
  14903. /**
  14904. * Append a rectangle to the current path as a complete subpath, with lower-left corner (x, y) and dimensions widthand height in user space.
  14905. * @param $x (float) Abscissa of upper-left corner.
  14906. * @param $y (float) Ordinate of upper-left corner.
  14907. * @param $w (float) Width.
  14908. * @param $h (float) Height.
  14909. * @param $op (string) options
  14910. * @protected
  14911. * @since 2.1.000 (2008-01-08)
  14912. */
  14913. protected function _outRect($x, $y, $w, $h, $op) {
  14914. if ($this->state == 2) {
  14915. $this->_out(sprintf('%F %F %F %F re %s', $x * $this->k, ($this->h - $y) * $this->k, $w * $this->k, -$h * $this->k, $op));
  14916. }
  14917. }
  14918. /**
  14919. * 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.
  14920. * The new current point shall be (x3, y3).
  14921. * @param $x1 (float) Abscissa of control point 1.
  14922. * @param $y1 (float) Ordinate of control point 1.
  14923. * @param $x2 (float) Abscissa of control point 2.
  14924. * @param $y2 (float) Ordinate of control point 2.
  14925. * @param $x3 (float) Abscissa of end point.
  14926. * @param $y3 (float) Ordinate of end point.
  14927. * @protected
  14928. * @since 2.1.000 (2008-01-08)
  14929. */
  14930. protected function _outCurve($x1, $y1, $x2, $y2, $x3, $y3) {
  14931. if ($this->state == 2) {
  14932. $this->_out(sprintf('%F %F %F %F %F %F c', $x1 * $this->k, ($this->h - $y1) * $this->k, $x2 * $this->k, ($this->h - $y2) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k));
  14933. }
  14934. }
  14935. /**
  14936. * 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.
  14937. * The new current point shall be (x3, y3).
  14938. * @param $x2 (float) Abscissa of control point 2.
  14939. * @param $y2 (float) Ordinate of control point 2.
  14940. * @param $x3 (float) Abscissa of end point.
  14941. * @param $y3 (float) Ordinate of end point.
  14942. * @protected
  14943. * @since 4.9.019 (2010-04-26)
  14944. */
  14945. protected function _outCurveV($x2, $y2, $x3, $y3) {
  14946. if ($this->state == 2) {
  14947. $this->_out(sprintf('%F %F %F %F v', $x2 * $this->k, ($this->h - $y2) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k));
  14948. }
  14949. }
  14950. /**
  14951. * 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.
  14952. * The new current point shall be (x3, y3).
  14953. * @param $x1 (float) Abscissa of control point 1.
  14954. * @param $y1 (float) Ordinate of control point 1.
  14955. * @param $x3 (float) Abscissa of end point.
  14956. * @param $y3 (float) Ordinate of end point.
  14957. * @protected
  14958. * @since 2.1.000 (2008-01-08)
  14959. */
  14960. protected function _outCurveY($x1, $y1, $x3, $y3) {
  14961. if ($this->state == 2) {
  14962. $this->_out(sprintf('%F %F %F %F y', $x1 * $this->k, ($this->h - $y1) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k));
  14963. }
  14964. }
  14965. /**
  14966. * Draws a line between two points.
  14967. * @param $x1 (float) Abscissa of first point.
  14968. * @param $y1 (float) Ordinate of first point.
  14969. * @param $x2 (float) Abscissa of second point.
  14970. * @param $y2 (float) Ordinate of second point.
  14971. * @param $style (array) Line style. Array like for SetLineStyle(). Default value: default line style (empty array).
  14972. * @public
  14973. * @since 1.0
  14974. * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
  14975. */
  14976. public function Line($x1, $y1, $x2, $y2, $style=array()) {
  14977. if ($this->state != 2) {
  14978. return;
  14979. }
  14980. if (is_array($style)) {
  14981. $this->SetLineStyle($style);
  14982. }
  14983. $this->_outPoint($x1, $y1);
  14984. $this->_outLine($x2, $y2);
  14985. $this->_out('S');
  14986. }
  14987. /**
  14988. * Draws a rectangle.
  14989. * @param $x (float) Abscissa of upper-left corner.
  14990. * @param $y (float) Ordinate of upper-left corner.
  14991. * @param $w (float) Width.
  14992. * @param $h (float) Height.
  14993. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  14994. * @param $border_style (array) Border style of rectangle. Array with keys among the following:
  14995. * <ul>
  14996. * <li>all: Line style of all borders. Array like for SetLineStyle().</li>
  14997. * <li>L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for SetLineStyle().</li>
  14998. * </ul>
  14999. * If a key is not present or is null, not draws the border. Default value: default line style (empty array).
  15000. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  15001. * @public
  15002. * @since 1.0
  15003. * @see SetLineStyle()
  15004. */
  15005. public function Rect($x, $y, $w, $h, $style='', $border_style=array(), $fill_color=array()) {
  15006. if ($this->state != 2) {
  15007. return;
  15008. }
  15009. if (!(false === strpos($style, 'F')) AND !empty($fill_color)) {
  15010. $this->SetFillColorArray($fill_color);
  15011. }
  15012. $op = $this->getPathPaintOperator($style);
  15013. if ((!$border_style) OR (isset($border_style['all']))) {
  15014. if (isset($border_style['all']) AND $border_style['all']) {
  15015. $this->SetLineStyle($border_style['all']);
  15016. $border_style = array();
  15017. }
  15018. }
  15019. $this->_outRect($x, $y, $w, $h, $op);
  15020. if ($border_style) {
  15021. $border_style2 = array();
  15022. foreach ($border_style as $line => $value) {
  15023. $length = strlen($line);
  15024. for ($i = 0; $i < $length; ++$i) {
  15025. $border_style2[$line[$i]] = $value;
  15026. }
  15027. }
  15028. $border_style = $border_style2;
  15029. if (isset($border_style['L']) AND $border_style['L']) {
  15030. $this->Line($x, $y, $x, $y + $h, $border_style['L']);
  15031. }
  15032. if (isset($border_style['T']) AND $border_style['T']) {
  15033. $this->Line($x, $y, $x + $w, $y, $border_style['T']);
  15034. }
  15035. if (isset($border_style['R']) AND $border_style['R']) {
  15036. $this->Line($x + $w, $y, $x + $w, $y + $h, $border_style['R']);
  15037. }
  15038. if (isset($border_style['B']) AND $border_style['B']) {
  15039. $this->Line($x, $y + $h, $x + $w, $y + $h, $border_style['B']);
  15040. }
  15041. }
  15042. }
  15043. /**
  15044. * Draws a Bezier curve.
  15045. * The Bezier curve is a tangent to the line between the control points at
  15046. * either end of the curve.
  15047. * @param $x0 (float) Abscissa of start point.
  15048. * @param $y0 (float) Ordinate of start point.
  15049. * @param $x1 (float) Abscissa of control point 1.
  15050. * @param $y1 (float) Ordinate of control point 1.
  15051. * @param $x2 (float) Abscissa of control point 2.
  15052. * @param $y2 (float) Ordinate of control point 2.
  15053. * @param $x3 (float) Abscissa of end point.
  15054. * @param $y3 (float) Ordinate of end point.
  15055. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  15056. * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
  15057. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  15058. * @public
  15059. * @see SetLineStyle()
  15060. * @since 2.1.000 (2008-01-08)
  15061. */
  15062. public function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style='', $line_style=array(), $fill_color=array()) {
  15063. if ($this->state != 2) {
  15064. return;
  15065. }
  15066. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  15067. $this->SetFillColorArray($fill_color);
  15068. }
  15069. $op = $this->getPathPaintOperator($style);
  15070. if ($line_style) {
  15071. $this->SetLineStyle($line_style);
  15072. }
  15073. $this->_outPoint($x0, $y0);
  15074. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  15075. $this->_out($op);
  15076. }
  15077. /**
  15078. * Draws a poly-Bezier curve.
  15079. * Each Bezier curve segment is a tangent to the line between the control points at
  15080. * either end of the curve.
  15081. * @param $x0 (float) Abscissa of start point.
  15082. * @param $y0 (float) Ordinate of start point.
  15083. * @param $segments (float) An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
  15084. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  15085. * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
  15086. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  15087. * @public
  15088. * @see SetLineStyle()
  15089. * @since 3.0008 (2008-05-12)
  15090. */
  15091. public function Polycurve($x0, $y0, $segments, $style='', $line_style=array(), $fill_color=array()) {
  15092. if ($this->state != 2) {
  15093. return;
  15094. }
  15095. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  15096. $this->SetFillColorArray($fill_color);
  15097. }
  15098. $op = $this->getPathPaintOperator($style);
  15099. if ($op == 'f') {
  15100. $line_style = array();
  15101. }
  15102. if ($line_style) {
  15103. $this->SetLineStyle($line_style);
  15104. }
  15105. $this->_outPoint($x0, $y0);
  15106. foreach ($segments as $segment) {
  15107. list($x1, $y1, $x2, $y2, $x3, $y3) = $segment;
  15108. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  15109. }
  15110. $this->_out($op);
  15111. }
  15112. /**
  15113. * Draws an ellipse.
  15114. * An ellipse is formed from n Bezier curves.
  15115. * @param $x0 (float) Abscissa of center point.
  15116. * @param $y0 (float) Ordinate of center point.
  15117. * @param $rx (float) Horizontal radius.
  15118. * @param $ry (float) Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
  15119. * @param $angle: (float) Angle oriented (anti-clockwise). Default value: 0.
  15120. * @param $astart: (float) Angle start of draw line. Default value: 0.
  15121. * @param $afinish: (float) Angle finish of draw line. Default value: 360.
  15122. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  15123. * @param $line_style (array) Line style of ellipse. Array like for SetLineStyle(). Default value: default line style (empty array).
  15124. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  15125. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse.
  15126. * @author Nicola Asuni
  15127. * @public
  15128. * @since 2.1.000 (2008-01-08)
  15129. */
  15130. public function Ellipse($x0, $y0, $rx, $ry='', $angle=0, $astart=0, $afinish=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
  15131. if ($this->state != 2) {
  15132. return;
  15133. }
  15134. if ($this->empty_string($ry) OR ($ry == 0)) {
  15135. $ry = $rx;
  15136. }
  15137. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  15138. $this->SetFillColorArray($fill_color);
  15139. }
  15140. $op = $this->getPathPaintOperator($style);
  15141. if ($op == 'f') {
  15142. $line_style = array();
  15143. }
  15144. if ($line_style) {
  15145. $this->SetLineStyle($line_style);
  15146. }
  15147. $this->_outellipticalarc($x0, $y0, $rx, $ry, $angle, $astart, $afinish, false, $nc, true, true, false);
  15148. $this->_out($op);
  15149. }
  15150. /**
  15151. * Append an elliptical arc to the current path.
  15152. * An ellipse is formed from n Bezier curves.
  15153. * @param $xc (float) Abscissa of center point.
  15154. * @param $yc (float) Ordinate of center point.
  15155. * @param $rx (float) Horizontal radius.
  15156. * @param $ry (float) Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
  15157. * @param $xang: (float) Angle between the X-axis and the major axis of the ellipse. Default value: 0.
  15158. * @param $angs: (float) Angle start of draw line. Default value: 0.
  15159. * @param $angf: (float) Angle finish of draw line. Default value: 360.
  15160. * @param $pie (boolean) if true do not mark the border point (used to draw pie sectors).
  15161. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse.
  15162. * @param $startpoint (boolean) if true output a starting point.
  15163. * @param $ccw (boolean) if true draws in counter-clockwise.
  15164. * @param $svg (boolean) if true the angles are in svg mode (already calculated).
  15165. * @return array bounding box coordinates (x min, y min, x max, y max)
  15166. * @author Nicola Asuni
  15167. * @protected
  15168. * @since 4.9.019 (2010-04-26)
  15169. */
  15170. protected function _outellipticalarc($xc, $yc, $rx, $ry, $xang=0, $angs=0, $angf=360, $pie=false, $nc=2, $startpoint=true, $ccw=true, $svg=false) {
  15171. $k = $this->k;
  15172. if ($nc < 2) {
  15173. $nc = 2;
  15174. }
  15175. $xmin = 2147483647;
  15176. $ymin = 2147483647;
  15177. $xmax = 0;
  15178. $ymax = 0;
  15179. if ($pie) {
  15180. // center of the arc
  15181. $this->_outPoint($xc, $yc);
  15182. }
  15183. $xang = deg2rad((float) $xang);
  15184. $angs = deg2rad((float) $angs);
  15185. $angf = deg2rad((float) $angf);
  15186. if ($svg) {
  15187. $as = $angs;
  15188. $af = $angf;
  15189. } else {
  15190. $as = atan2((sin($angs) / $ry), (cos($angs) / $rx));
  15191. $af = atan2((sin($angf) / $ry), (cos($angf) / $rx));
  15192. }
  15193. if ($as < 0) {
  15194. $as += (2 * M_PI);
  15195. }
  15196. if ($af < 0) {
  15197. $af += (2 * M_PI);
  15198. }
  15199. if ($ccw AND ($as > $af)) {
  15200. // reverse rotation
  15201. $as -= (2 * M_PI);
  15202. } elseif (!$ccw AND ($as < $af)) {
  15203. // reverse rotation
  15204. $af -= (2 * M_PI);
  15205. }
  15206. $total_angle = ($af - $as);
  15207. if ($nc < 2) {
  15208. $nc = 2;
  15209. }
  15210. // total arcs to draw
  15211. $nc *= (2 * abs($total_angle) / M_PI);
  15212. $nc = round($nc) + 1;
  15213. // angle of each arc
  15214. $arcang = ($total_angle / $nc);
  15215. // center point in PDF coordinates
  15216. $x0 = $xc;
  15217. $y0 = ($this->h - $yc);
  15218. // starting angle
  15219. $ang = $as;
  15220. $alpha = sin($arcang) * ((sqrt(4 + (3 * pow(tan(($arcang) / 2), 2))) - 1) / 3);
  15221. $cos_xang = cos($xang);
  15222. $sin_xang = sin($xang);
  15223. $cos_ang = cos($ang);
  15224. $sin_ang = sin($ang);
  15225. // first arc point
  15226. $px1 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
  15227. $py1 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
  15228. // first Bezier control point
  15229. $qx1 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
  15230. $qy1 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
  15231. if ($pie) {
  15232. // line from center to arc starting point
  15233. $this->_outLine($px1, $this->h - $py1);
  15234. } elseif ($startpoint) {
  15235. // arc starting point
  15236. $this->_outPoint($px1, $this->h - $py1);
  15237. }
  15238. // draw arcs
  15239. for ($i = 1; $i <= $nc; ++$i) {
  15240. // starting angle
  15241. $ang = $as + ($i * $arcang);
  15242. if ($i == $nc) {
  15243. $ang = $af;
  15244. }
  15245. $cos_ang = cos($ang);
  15246. $sin_ang = sin($ang);
  15247. // second arc point
  15248. $px2 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
  15249. $py2 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
  15250. // second Bezier control point
  15251. $qx2 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
  15252. $qy2 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
  15253. // draw arc
  15254. $cx1 = ($px1 + $qx1);
  15255. $cy1 = ($this->h - ($py1 + $qy1));
  15256. $cx2 = ($px2 - $qx2);
  15257. $cy2 = ($this->h - ($py2 - $qy2));
  15258. $cx3 = $px2;
  15259. $cy3 = ($this->h - $py2);
  15260. $this->_outCurve($cx1, $cy1, $cx2, $cy2, $cx3, $cy3);
  15261. // get bounding box coordinates
  15262. $xmin = min($xmin, $cx1, $cx2, $cx3);
  15263. $ymin = min($ymin, $cy1, $cy2, $cy3);
  15264. $xmax = max($xmax, $cx1, $cx2, $cx3);
  15265. $ymax = max($ymax, $cy1, $cy2, $cy3);
  15266. // move to next point
  15267. $px1 = $px2;
  15268. $py1 = $py2;
  15269. $qx1 = $qx2;
  15270. $qy1 = $qy2;
  15271. }
  15272. if ($pie) {
  15273. $this->_outLine($xc, $yc);
  15274. // get bounding box coordinates
  15275. $xmin = min($xmin, $xc);
  15276. $ymin = min($ymin, $yc);
  15277. $xmax = max($xmax, $xc);
  15278. $ymax = max($ymax, $yc);
  15279. }
  15280. return array($xmin, $ymin, $xmax, $ymax);
  15281. }
  15282. /**
  15283. * Draws a circle.
  15284. * A circle is formed from n Bezier curves.
  15285. * @param $x0 (float) Abscissa of center point.
  15286. * @param $y0 (float) Ordinate of center point.
  15287. * @param $r (float) Radius.
  15288. * @param $angstr: (float) Angle start of draw line. Default value: 0.
  15289. * @param $angend: (float) Angle finish of draw line. Default value: 360.
  15290. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  15291. * @param $line_style (array) Line style of circle. Array like for SetLineStyle(). Default value: default line style (empty array).
  15292. * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  15293. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of circle.
  15294. * @public
  15295. * @since 2.1.000 (2008-01-08)
  15296. */
  15297. public function Circle($x0, $y0, $r, $angstr=0, $angend=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
  15298. $this->Ellipse($x0, $y0, $r, $r, 0, $angstr, $angend, $style, $line_style, $fill_color, $nc);
  15299. }
  15300. /**
  15301. * Draws a polygonal line
  15302. * @param $p (array) Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  15303. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  15304. * @param $line_style (array) Line style of polygon. Array with keys among the following:
  15305. * <ul>
  15306. * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
  15307. * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
  15308. * </ul>
  15309. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  15310. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  15311. * @since 4.8.003 (2009-09-15)
  15312. * @public
  15313. */
  15314. public function PolyLine($p, $style='', $line_style=array(), $fill_color=array()) {
  15315. $this->Polygon($p, $style, $line_style, $fill_color, false);
  15316. }
  15317. /**
  15318. * Draws a polygon.
  15319. * @param $p (array) Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  15320. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  15321. * @param $line_style (array) Line style of polygon. Array with keys among the following:
  15322. * <ul>
  15323. * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
  15324. * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
  15325. * </ul>
  15326. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  15327. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  15328. * @param $closed (boolean) if true the polygon is closes, otherwise will remain open
  15329. * @public
  15330. * @since 2.1.000 (2008-01-08)
  15331. */
  15332. public function Polygon($p, $style='', $line_style=array(), $fill_color=array(), $closed=true) {
  15333. if ($this->state != 2) {
  15334. return;
  15335. }
  15336. $nc = count($p); // number of coordinates
  15337. $np = $nc / 2; // number of points
  15338. if ($closed) {
  15339. // close polygon by adding the first 2 points at the end (one line)
  15340. for ($i = 0; $i < 4; ++$i) {
  15341. $p[$nc + $i] = $p[$i];
  15342. }
  15343. // copy style for the last added line
  15344. if (isset($line_style[0])) {
  15345. $line_style[$np] = $line_style[0];
  15346. }
  15347. $nc += 4;
  15348. }
  15349. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  15350. $this->SetFillColorArray($fill_color);
  15351. }
  15352. $op = $this->getPathPaintOperator($style);
  15353. if ($op == 'f') {
  15354. $line_style = array();
  15355. }
  15356. $draw = true;
  15357. if ($line_style) {
  15358. if (isset($line_style['all'])) {
  15359. $this->SetLineStyle($line_style['all']);
  15360. } else {
  15361. $draw = false;
  15362. if ($op == 'B') {
  15363. // draw fill
  15364. $op = 'f';
  15365. $this->_outPoint($p[0], $p[1]);
  15366. for ($i = 2; $i < $nc; $i = $i + 2) {
  15367. $this->_outLine($p[$i], $p[$i + 1]);
  15368. }
  15369. $this->_out($op);
  15370. }
  15371. // draw outline
  15372. $this->_outPoint($p[0], $p[1]);
  15373. for ($i = 2; $i < $nc; $i = $i + 2) {
  15374. $line_num = ($i / 2) - 1;
  15375. if (isset($line_style[$line_num])) {
  15376. if ($line_style[$line_num] != 0) {
  15377. if (is_array($line_style[$line_num])) {
  15378. $this->_out('S');
  15379. $this->SetLineStyle($line_style[$line_num]);
  15380. $this->_outPoint($p[$i - 2], $p[$i - 1]);
  15381. $this->_outLine($p[$i], $p[$i + 1]);
  15382. $this->_out('S');
  15383. $this->_outPoint($p[$i], $p[$i + 1]);
  15384. } else {
  15385. $this->_outLine($p[$i], $p[$i + 1]);
  15386. }
  15387. }
  15388. } else {
  15389. $this->_outLine($p[$i], $p[$i + 1]);
  15390. }
  15391. }
  15392. $this->_out($op);
  15393. }
  15394. }
  15395. if ($draw) {
  15396. $this->_outPoint($p[0], $p[1]);
  15397. for ($i = 2; $i < $nc; $i = $i + 2) {
  15398. $this->_outLine($p[$i], $p[$i + 1]);
  15399. }
  15400. $this->_out($op);
  15401. }
  15402. }
  15403. /**
  15404. * Draws a regular polygon.
  15405. * @param $x0 (float) Abscissa of center point.
  15406. * @param $y0 (float) Ordinate of center point.
  15407. * @param $r: (float) Radius of inscribed circle.
  15408. * @param $ns (integer) Number of sides.
  15409. * @param $angle (float) Angle oriented (anti-clockwise). Default value: 0.
  15410. * @param $draw_circle (boolean) Draw inscribed circle or not. Default value: false.
  15411. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  15412. * @param $line_style (array) Line style of polygon sides. Array with keys among the following:
  15413. * <ul>
  15414. * <li>all: Line style of all sides. Array like for SetLineStyle().</li>
  15415. * <li>0 to ($ns - 1): Line style of each side. Array like for SetLineStyle().</li>
  15416. * </ul>
  15417. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  15418. * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  15419. * @param $circle_style (string) Style of rendering of inscribed circle (if draws). Possible values are:
  15420. * <ul>
  15421. * <li>D or empty string: Draw (default).</li>
  15422. * <li>F: Fill.</li>
  15423. * <li>DF or FD: Draw and fill.</li>
  15424. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  15425. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  15426. * </ul>
  15427. * @param $circle_outLine_style (array) Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
  15428. * @param $circle_fill_color (array) Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  15429. * @public
  15430. * @since 2.1.000 (2008-01-08)
  15431. */
  15432. 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()) {
  15433. if (3 > $ns) {
  15434. $ns = 3;
  15435. }
  15436. if ($draw_circle) {
  15437. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  15438. }
  15439. $p = array();
  15440. for ($i = 0; $i < $ns; ++$i) {
  15441. $a = $angle + ($i * 360 / $ns);
  15442. $a_rad = deg2rad((float) $a);
  15443. $p[] = $x0 + ($r * sin($a_rad));
  15444. $p[] = $y0 + ($r * cos($a_rad));
  15445. }
  15446. $this->Polygon($p, $style, $line_style, $fill_color);
  15447. }
  15448. /**
  15449. * Draws a star polygon
  15450. * @param $x0 (float) Abscissa of center point.
  15451. * @param $y0 (float) Ordinate of center point.
  15452. * @param $r (float) Radius of inscribed circle.
  15453. * @param $nv (integer) Number of vertices.
  15454. * @param $ng (integer) Number of gap (if ($ng % $nv = 1) then is a regular polygon).
  15455. * @param $angle: (float) Angle oriented (anti-clockwise). Default value: 0.
  15456. * @param $draw_circle: (boolean) Draw inscribed circle or not. Default value is false.
  15457. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  15458. * @param $line_style (array) Line style of polygon sides. Array with keys among the following:
  15459. * <ul>
  15460. * <li>all: Line style of all sides. Array like for
  15461. * SetLineStyle().</li>
  15462. * <li>0 to (n - 1): Line style of each side. Array like for SetLineStyle().</li>
  15463. * </ul>
  15464. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  15465. * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  15466. * @param $circle_style (string) Style of rendering of inscribed circle (if draws). Possible values are:
  15467. * <ul>
  15468. * <li>D or empty string: Draw (default).</li>
  15469. * <li>F: Fill.</li>
  15470. * <li>DF or FD: Draw and fill.</li>
  15471. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  15472. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  15473. * </ul>
  15474. * @param $circle_outLine_style (array) Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
  15475. * @param $circle_fill_color (array) Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  15476. * @public
  15477. * @since 2.1.000 (2008-01-08)
  15478. */
  15479. 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()) {
  15480. if ($nv < 2) {
  15481. $nv = 2;
  15482. }
  15483. if ($draw_circle) {
  15484. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  15485. }
  15486. $p2 = array();
  15487. $visited = array();
  15488. for ($i = 0; $i < $nv; ++$i) {
  15489. $a = $angle + ($i * 360 / $nv);
  15490. $a_rad = deg2rad((float) $a);
  15491. $p2[] = $x0 + ($r * sin($a_rad));
  15492. $p2[] = $y0 + ($r * cos($a_rad));
  15493. $visited[] = false;
  15494. }
  15495. $p = array();
  15496. $i = 0;
  15497. do {
  15498. $p[] = $p2[$i * 2];
  15499. $p[] = $p2[($i * 2) + 1];
  15500. $visited[$i] = true;
  15501. $i += $ng;
  15502. $i %= $nv;
  15503. } while (!$visited[$i]);
  15504. $this->Polygon($p, $style, $line_style, $fill_color);
  15505. }
  15506. /**
  15507. * Draws a rounded rectangle.
  15508. * @param $x (float) Abscissa of upper-left corner.
  15509. * @param $y (float) Ordinate of upper-left corner.
  15510. * @param $w (float) Width.
  15511. * @param $h (float) Height.
  15512. * @param $r (float) the radius of the circle used to round off the corners of the rectangle.
  15513. * @param $round_corner (string) Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top right, bottom right, bottom left and top left. Default value: all rounded corner ("1111").
  15514. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  15515. * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  15516. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  15517. * @public
  15518. * @since 2.1.000 (2008-01-08)
  15519. */
  15520. public function RoundedRect($x, $y, $w, $h, $r, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
  15521. $this->RoundedRectXY($x, $y, $w, $h, $r, $r, $round_corner, $style, $border_style, $fill_color);
  15522. }
  15523. /**
  15524. * Draws a rounded rectangle.
  15525. * @param $x (float) Abscissa of upper-left corner.
  15526. * @param $y (float) Ordinate of upper-left corner.
  15527. * @param $w (float) Width.
  15528. * @param $h (float) Height.
  15529. * @param $rx (float) the x-axis radius of the ellipse used to round off the corners of the rectangle.
  15530. * @param $ry (float) the y-axis radius of the ellipse used to round off the corners of the rectangle.
  15531. * @param $round_corner (string) Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top right, bottom right, bottom left and top left. Default value: all rounded corner ("1111").
  15532. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  15533. * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  15534. * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  15535. * @public
  15536. * @since 4.9.019 (2010-04-22)
  15537. */
  15538. public function RoundedRectXY($x, $y, $w, $h, $rx, $ry, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
  15539. if ($this->state != 2) {
  15540. return;
  15541. }
  15542. if (($round_corner == '0000') OR (($rx == $ry) AND ($rx == 0))) {
  15543. // Not rounded
  15544. $this->Rect($x, $y, $w, $h, $style, $border_style, $fill_color);
  15545. return;
  15546. }
  15547. // Rounded
  15548. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  15549. $this->SetFillColorArray($fill_color);
  15550. }
  15551. $op = $this->getPathPaintOperator($style);
  15552. if ($op == 'f') {
  15553. $border_style = array();
  15554. }
  15555. if ($border_style) {
  15556. $this->SetLineStyle($border_style);
  15557. }
  15558. $MyArc = 4 / 3 * (sqrt(2) - 1);
  15559. $this->_outPoint($x + $rx, $y);
  15560. $xc = $x + $w - $rx;
  15561. $yc = $y + $ry;
  15562. $this->_outLine($xc, $y);
  15563. if ($round_corner[0]) {
  15564. $this->_outCurve($xc + ($rx * $MyArc), $yc - $ry, $xc + $rx, $yc - ($ry * $MyArc), $xc + $rx, $yc);
  15565. } else {
  15566. $this->_outLine($x + $w, $y);
  15567. }
  15568. $xc = $x + $w - $rx;
  15569. $yc = $y + $h - $ry;
  15570. $this->_outLine($x + $w, $yc);
  15571. if ($round_corner[1]) {
  15572. $this->_outCurve($xc + $rx, $yc + ($ry * $MyArc), $xc + ($rx * $MyArc), $yc + $ry, $xc, $yc + $ry);
  15573. } else {
  15574. $this->_outLine($x + $w, $y + $h);
  15575. }
  15576. $xc = $x + $rx;
  15577. $yc = $y + $h - $ry;
  15578. $this->_outLine($xc, $y + $h);
  15579. if ($round_corner[2]) {
  15580. $this->_outCurve($xc - ($rx * $MyArc), $yc + $ry, $xc - $rx, $yc + ($ry * $MyArc), $xc - $rx, $yc);
  15581. } else {
  15582. $this->_outLine($x, $y + $h);
  15583. }
  15584. $xc = $x + $rx;
  15585. $yc = $y + $ry;
  15586. $this->_outLine($x, $yc);
  15587. if ($round_corner[3]) {
  15588. $this->_outCurve($xc - $rx, $yc - ($ry * $MyArc), $xc - ($rx * $MyArc), $yc - $ry, $xc, $yc - $ry);
  15589. } else {
  15590. $this->_outLine($x, $y);
  15591. $this->_outLine($x + $rx, $y);
  15592. }
  15593. $this->_out($op);
  15594. }
  15595. /**
  15596. * Draws a grahic arrow.
  15597. * @param $x0 (float) Abscissa of first point.
  15598. * @param $y0 (float) Ordinate of first point.
  15599. * @param $x1 (float) Abscissa of second point.
  15600. * @param $y1 (float) Ordinate of second point.
  15601. * @param $head_style (int) (0 = draw only arrowhead arms, 1 = draw closed arrowhead, but no fill, 2 = closed and filled arrowhead, 3 = filled arrowhead)
  15602. * @param $arm_size (float) length of arrowhead arms
  15603. * @param $arm_angle (int) angle between an arm and the shaft
  15604. * @author Piotr Galecki, Nicola Asuni, Andy Meier
  15605. * @since 4.6.018 (2009-07-10)
  15606. */
  15607. public function Arrow($x0, $y0, $x1, $y1, $head_style=0, $arm_size=5, $arm_angle=15) {
  15608. // getting arrow direction angle
  15609. // 0 deg angle is when both arms go along X axis. angle grows clockwise.
  15610. $dir_angle = atan2(($y0 - $y1), ($x0 - $x1));
  15611. if ($dir_angle < 0) {
  15612. $dir_angle += (2 * M_PI);
  15613. }
  15614. $arm_angle = deg2rad($arm_angle);
  15615. $sx1 = $x1;
  15616. $sy1 = $y1;
  15617. if ($head_style > 0) {
  15618. // calculate the stopping point for the arrow shaft
  15619. $sx1 = $x1 + (($arm_size - $this->LineWidth) * cos($dir_angle));
  15620. $sy1 = $y1 + (($arm_size - $this->LineWidth) * sin($dir_angle));
  15621. }
  15622. // main arrow line / shaft
  15623. $this->Line($x0, $y0, $sx1, $sy1);
  15624. // left arrowhead arm tip
  15625. $x2L = $x1 + ($arm_size * cos($dir_angle + $arm_angle));
  15626. $y2L = $y1 + ($arm_size * sin($dir_angle + $arm_angle));
  15627. // right arrowhead arm tip
  15628. $x2R = $x1 + ($arm_size * cos($dir_angle - $arm_angle));
  15629. $y2R = $y1 + ($arm_size * sin($dir_angle - $arm_angle));
  15630. $mode = 'D';
  15631. $style = array();
  15632. switch ($head_style) {
  15633. case 0: {
  15634. // draw only arrowhead arms
  15635. $mode = 'D';
  15636. $style = array(1, 1, 0);
  15637. break;
  15638. }
  15639. case 1: {
  15640. // draw closed arrowhead, but no fill
  15641. $mode = 'D';
  15642. break;
  15643. }
  15644. case 2: {
  15645. // closed and filled arrowhead
  15646. $mode = 'DF';
  15647. break;
  15648. }
  15649. case 3: {
  15650. // filled arrowhead
  15651. $mode = 'F';
  15652. break;
  15653. }
  15654. }
  15655. $this->Polygon(array($x2L, $y2L, $x1, $y1, $x2R, $y2R), $mode, $style, array());
  15656. }
  15657. // END GRAPHIC FUNCTIONS SECTION -----------------------
  15658. // BIDIRECTIONAL TEXT SECTION --------------------------
  15659. /**
  15660. * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  15661. * @param $str (string) string to manipulate.
  15662. * @param $setbom (bool) if true set the Byte Order Mark (BOM = 0xFEFF)
  15663. * @param $forcertl (bool) if true forces RTL text direction
  15664. * @return string
  15665. * @protected
  15666. * @author Nicola Asuni
  15667. * @since 2.1.000 (2008-01-08)
  15668. */
  15669. protected function utf8StrRev($str, $setbom=false, $forcertl=false) {
  15670. return $this->utf8StrArrRev($this->UTF8StringToArray($str), $str, $setbom, $forcertl);
  15671. }
  15672. /**
  15673. * Reverse the RLT substrings array using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  15674. * @param $arr (array) array of unicode values.
  15675. * @param $str (string) string to manipulate (or empty value).
  15676. * @param $setbom (bool) if true set the Byte Order Mark (BOM = 0xFEFF)
  15677. * @param $forcertl (bool) if true forces RTL text direction
  15678. * @return string
  15679. * @protected
  15680. * @author Nicola Asuni
  15681. * @since 4.9.000 (2010-03-27)
  15682. */
  15683. protected function utf8StrArrRev($arr, $str='', $setbom=false, $forcertl=false) {
  15684. return $this->arrUTF8ToUTF16BE($this->utf8Bidi($arr, $str, $forcertl), $setbom);
  15685. }
  15686. /**
  15687. * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  15688. * @param $ta (array) array of characters composing the string.
  15689. * @param $str (string) string to process
  15690. * @param $forcertl (bool) if 'R' forces RTL, if 'L' forces LTR
  15691. * @return array of unicode chars
  15692. * @author Nicola Asuni
  15693. * @protected
  15694. * @since 2.4.000 (2008-03-06)
  15695. */
  15696. protected function utf8Bidi($ta, $str='', $forcertl=false) {
  15697. // paragraph embedding level
  15698. $pel = 0;
  15699. // max level
  15700. $maxlevel = 0;
  15701. if ($this->empty_string($str)) {
  15702. // create string from array
  15703. $str = $this->UTF8ArrSubString($ta);
  15704. }
  15705. // check if string contains arabic text
  15706. if (preg_match($this->unicode->uni_RE_PATTERN_ARABIC, $str)) {
  15707. $arabic = true;
  15708. } else {
  15709. $arabic = false;
  15710. }
  15711. // check if string contains RTL text
  15712. if (!($forcertl OR $arabic OR preg_match($this->unicode->uni_RE_PATTERN_RTL, $str))) {
  15713. return $ta;
  15714. }
  15715. // get number of chars
  15716. $numchars = count($ta);
  15717. if ($forcertl == 'R') {
  15718. $pel = 1;
  15719. } elseif ($forcertl == 'L') {
  15720. $pel = 0;
  15721. } else {
  15722. // P2. In each paragraph, find the first character of type L, AL, or R.
  15723. // 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.
  15724. for ($i=0; $i < $numchars; ++$i) {
  15725. $type = $this->unicode->uni_type[$ta[$i]];
  15726. if ($type == 'L') {
  15727. $pel = 0;
  15728. break;
  15729. } elseif (($type == 'AL') OR ($type == 'R')) {
  15730. $pel = 1;
  15731. break;
  15732. }
  15733. }
  15734. }
  15735. // Current Embedding Level
  15736. $cel = $pel;
  15737. // directional override status
  15738. $dos = 'N';
  15739. $remember = array();
  15740. // start-of-level-run
  15741. $sor = $pel % 2 ? 'R' : 'L';
  15742. $eor = $sor;
  15743. // Array of characters data
  15744. $chardata = Array();
  15745. // 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.
  15746. // In the resolution of levels in rules I1 and I2, the maximum embedding level of 62 can be reached.
  15747. for ($i=0; $i < $numchars; ++$i) {
  15748. if ($ta[$i] == $this->unicode->uni_RLE) {
  15749. // X2. With each RLE, compute the least greater odd embedding level.
  15750. // 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.
  15751. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  15752. $next_level = $cel + ($cel % 2) + 1;
  15753. if ($next_level < 62) {
  15754. $remember[] = array('num' => $this->unicode->uni_RLE, 'cel' => $cel, 'dos' => $dos);
  15755. $cel = $next_level;
  15756. $dos = 'N';
  15757. $sor = $eor;
  15758. $eor = $cel % 2 ? 'R' : 'L';
  15759. }
  15760. } elseif ($ta[$i] == $this->unicode->uni_LRE) {
  15761. // X3. With each LRE, compute the least greater even embedding level.
  15762. // 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.
  15763. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  15764. $next_level = $cel + 2 - ($cel % 2);
  15765. if ( $next_level < 62 ) {
  15766. $remember[] = array('num' => $this->unicode->uni_LRE, 'cel' => $cel, 'dos' => $dos);
  15767. $cel = $next_level;
  15768. $dos = 'N';
  15769. $sor = $eor;
  15770. $eor = $cel % 2 ? 'R' : 'L';
  15771. }
  15772. } elseif ($ta[$i] == $this->unicode->uni_RLO) {
  15773. // X4. With each RLO, compute the least greater odd embedding level.
  15774. // 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.
  15775. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  15776. $next_level = $cel + ($cel % 2) + 1;
  15777. if ($next_level < 62) {
  15778. $remember[] = array('num' => $this->unicode->uni_RLO, 'cel' => $cel, 'dos' => $dos);
  15779. $cel = $next_level;
  15780. $dos = 'R';
  15781. $sor = $eor;
  15782. $eor = $cel % 2 ? 'R' : 'L';
  15783. }
  15784. } elseif ($ta[$i] == $this->unicode->uni_LRO) {
  15785. // X5. With each LRO, compute the least greater even embedding level.
  15786. // 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.
  15787. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  15788. $next_level = $cel + 2 - ($cel % 2);
  15789. if ( $next_level < 62 ) {
  15790. $remember[] = array('num' => $this->unicode->uni_LRO, 'cel' => $cel, 'dos' => $dos);
  15791. $cel = $next_level;
  15792. $dos = 'L';
  15793. $sor = $eor;
  15794. $eor = $cel % 2 ? 'R' : 'L';
  15795. }
  15796. } elseif ($ta[$i] == $this->unicode->uni_PDF) {
  15797. // 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.
  15798. if (count($remember)) {
  15799. $last = count($remember ) - 1;
  15800. if (($remember[$last]['num'] == $this->unicode->uni_RLE) OR
  15801. ($remember[$last]['num'] == $this->unicode->uni_LRE) OR
  15802. ($remember[$last]['num'] == $this->unicode->uni_RLO) OR
  15803. ($remember[$last]['num'] == $this->unicode->uni_LRO)) {
  15804. $match = array_pop($remember);
  15805. $cel = $match['cel'];
  15806. $dos = $match['dos'];
  15807. $sor = $eor;
  15808. $eor = ($cel > $match['cel'] ? $cel : $match['cel']) % 2 ? 'R' : 'L';
  15809. }
  15810. }
  15811. } elseif (($ta[$i] != $this->unicode->uni_RLE) AND
  15812. ($ta[$i] != $this->unicode->uni_LRE) AND
  15813. ($ta[$i] != $this->unicode->uni_RLO) AND
  15814. ($ta[$i] != $this->unicode->uni_LRO) AND
  15815. ($ta[$i] != $this->unicode->uni_PDF)) {
  15816. // X6. For all types besides RLE, LRE, RLO, LRO, and PDF:
  15817. // a. Set the level of the current character to the current embedding level.
  15818. // b. Whenever the directional override status is not neutral, reset the current character type to the directional override status.
  15819. if ($dos != 'N') {
  15820. $chardir = $dos;
  15821. } else {
  15822. if (isset($this->unicode->uni_type[$ta[$i]])) {
  15823. $chardir = $this->unicode->uni_type[$ta[$i]];
  15824. } else {
  15825. $chardir = 'L';
  15826. }
  15827. }
  15828. // stores string characters and other information
  15829. $chardata[] = array('char' => $ta[$i], 'level' => $cel, 'type' => $chardir, 'sor' => $sor, 'eor' => $eor);
  15830. }
  15831. } // end for each char
  15832. // X8. All explicit directional embeddings and overrides are completely terminated at the end of each paragraph. Paragraph separators are not included in the embedding.
  15833. // X9. Remove all RLE, LRE, RLO, LRO, PDF, and BN codes.
  15834. // 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.
  15835. // 3.3.3 Resolving Weak Types
  15836. // 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.
  15837. // Nonspacing marks are now resolved based on the previous characters.
  15838. $numchars = count($chardata);
  15839. // 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.
  15840. $prevlevel = -1; // track level changes
  15841. $levcount = 0; // counts consecutive chars at the same level
  15842. for ($i=0; $i < $numchars; ++$i) {
  15843. if ($chardata[$i]['type'] == 'NSM') {
  15844. if ($levcount) {
  15845. $chardata[$i]['type'] = $chardata[$i]['sor'];
  15846. } elseif ($i > 0) {
  15847. $chardata[$i]['type'] = $chardata[($i-1)]['type'];
  15848. }
  15849. }
  15850. if ($chardata[$i]['level'] != $prevlevel) {
  15851. $levcount = 0;
  15852. } else {
  15853. ++$levcount;
  15854. }
  15855. $prevlevel = $chardata[$i]['level'];
  15856. }
  15857. // 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.
  15858. $prevlevel = -1;
  15859. $levcount = 0;
  15860. for ($i=0; $i < $numchars; ++$i) {
  15861. if ($chardata[$i]['char'] == 'EN') {
  15862. for ($j=$levcount; $j >= 0; $j--) {
  15863. if ($chardata[$j]['type'] == 'AL') {
  15864. $chardata[$i]['type'] = 'AN';
  15865. } elseif (($chardata[$j]['type'] == 'L') OR ($chardata[$j]['type'] == 'R')) {
  15866. break;
  15867. }
  15868. }
  15869. }
  15870. if ($chardata[$i]['level'] != $prevlevel) {
  15871. $levcount = 0;
  15872. } else {
  15873. ++$levcount;
  15874. }
  15875. $prevlevel = $chardata[$i]['level'];
  15876. }
  15877. // W3. Change all ALs to R.
  15878. for ($i=0; $i < $numchars; ++$i) {
  15879. if ($chardata[$i]['type'] == 'AL') {
  15880. $chardata[$i]['type'] = 'R';
  15881. }
  15882. }
  15883. // 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.
  15884. $prevlevel = -1;
  15885. $levcount = 0;
  15886. for ($i=0; $i < $numchars; ++$i) {
  15887. if (($levcount > 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
  15888. if (($chardata[$i]['type'] == 'ES') AND ($chardata[($i-1)]['type'] == 'EN') AND ($chardata[($i+1)]['type'] == 'EN')) {
  15889. $chardata[$i]['type'] = 'EN';
  15890. } elseif (($chardata[$i]['type'] == 'CS') AND ($chardata[($i-1)]['type'] == 'EN') AND ($chardata[($i+1)]['type'] == 'EN')) {
  15891. $chardata[$i]['type'] = 'EN';
  15892. } elseif (($chardata[$i]['type'] == 'CS') AND ($chardata[($i-1)]['type'] == 'AN') AND ($chardata[($i+1)]['type'] == 'AN')) {
  15893. $chardata[$i]['type'] = 'AN';
  15894. }
  15895. }
  15896. if ($chardata[$i]['level'] != $prevlevel) {
  15897. $levcount = 0;
  15898. } else {
  15899. ++$levcount;
  15900. }
  15901. $prevlevel = $chardata[$i]['level'];
  15902. }
  15903. // W5. A sequence of European terminators adjacent to European numbers changes to all European numbers.
  15904. $prevlevel = -1;
  15905. $levcount = 0;
  15906. for ($i=0; $i < $numchars; ++$i) {
  15907. if ($chardata[$i]['type'] == 'ET') {
  15908. if (($levcount > 0) AND ($chardata[($i-1)]['type'] == 'EN')) {
  15909. $chardata[$i]['type'] = 'EN';
  15910. } else {
  15911. $j = $i+1;
  15912. while (($j < $numchars) AND ($chardata[$j]['level'] == $prevlevel)) {
  15913. if ($chardata[$j]['type'] == 'EN') {
  15914. $chardata[$i]['type'] = 'EN';
  15915. break;
  15916. } elseif ($chardata[$j]['type'] != 'ET') {
  15917. break;
  15918. }
  15919. ++$j;
  15920. }
  15921. }
  15922. }
  15923. if ($chardata[$i]['level'] != $prevlevel) {
  15924. $levcount = 0;
  15925. } else {
  15926. ++$levcount;
  15927. }
  15928. $prevlevel = $chardata[$i]['level'];
  15929. }
  15930. // W6. Otherwise, separators and terminators change to Other Neutral.
  15931. $prevlevel = -1;
  15932. $levcount = 0;
  15933. for ($i=0; $i < $numchars; ++$i) {
  15934. if (($chardata[$i]['type'] == 'ET') OR ($chardata[$i]['type'] == 'ES') OR ($chardata[$i]['type'] == 'CS')) {
  15935. $chardata[$i]['type'] = 'ON';
  15936. }
  15937. if ($chardata[$i]['level'] != $prevlevel) {
  15938. $levcount = 0;
  15939. } else {
  15940. ++$levcount;
  15941. }
  15942. $prevlevel = $chardata[$i]['level'];
  15943. }
  15944. //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.
  15945. $prevlevel = -1;
  15946. $levcount = 0;
  15947. for ($i=0; $i < $numchars; ++$i) {
  15948. if ($chardata[$i]['char'] == 'EN') {
  15949. for ($j=$levcount; $j >= 0; $j--) {
  15950. if ($chardata[$j]['type'] == 'L') {
  15951. $chardata[$i]['type'] = 'L';
  15952. } elseif ($chardata[$j]['type'] == 'R') {
  15953. break;
  15954. }
  15955. }
  15956. }
  15957. if ($chardata[$i]['level'] != $prevlevel) {
  15958. $levcount = 0;
  15959. } else {
  15960. ++$levcount;
  15961. }
  15962. $prevlevel = $chardata[$i]['level'];
  15963. }
  15964. // 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.
  15965. $prevlevel = -1;
  15966. $levcount = 0;
  15967. for ($i=0; $i < $numchars; ++$i) {
  15968. if (($levcount > 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
  15969. if (($chardata[$i]['type'] == 'N') AND ($chardata[($i-1)]['type'] == 'L') AND ($chardata[($i+1)]['type'] == 'L')) {
  15970. $chardata[$i]['type'] = 'L';
  15971. } elseif (($chardata[$i]['type'] == 'N') AND
  15972. (($chardata[($i-1)]['type'] == 'R') OR ($chardata[($i-1)]['type'] == 'EN') OR ($chardata[($i-1)]['type'] == 'AN')) AND
  15973. (($chardata[($i+1)]['type'] == 'R') OR ($chardata[($i+1)]['type'] == 'EN') OR ($chardata[($i+1)]['type'] == 'AN'))) {
  15974. $chardata[$i]['type'] = 'R';
  15975. } elseif ($chardata[$i]['type'] == 'N') {
  15976. // N2. Any remaining neutrals take the embedding direction
  15977. $chardata[$i]['type'] = $chardata[$i]['sor'];
  15978. }
  15979. } elseif (($levcount == 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
  15980. // first char
  15981. if (($chardata[$i]['type'] == 'N') AND ($chardata[$i]['sor'] == 'L') AND ($chardata[($i+1)]['type'] == 'L')) {
  15982. $chardata[$i]['type'] = 'L';
  15983. } elseif (($chardata[$i]['type'] == 'N') AND
  15984. (($chardata[$i]['sor'] == 'R') OR ($chardata[$i]['sor'] == 'EN') OR ($chardata[$i]['sor'] == 'AN')) AND
  15985. (($chardata[($i+1)]['type'] == 'R') OR ($chardata[($i+1)]['type'] == 'EN') OR ($chardata[($i+1)]['type'] == 'AN'))) {
  15986. $chardata[$i]['type'] = 'R';
  15987. } elseif ($chardata[$i]['type'] == 'N') {
  15988. // N2. Any remaining neutrals take the embedding direction
  15989. $chardata[$i]['type'] = $chardata[$i]['sor'];
  15990. }
  15991. } elseif (($levcount > 0) AND ((($i+1) == $numchars) OR (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] != $prevlevel))) {
  15992. //last char
  15993. if (($chardata[$i]['type'] == 'N') AND ($chardata[($i-1)]['type'] == 'L') AND ($chardata[$i]['eor'] == 'L')) {
  15994. $chardata[$i]['type'] = 'L';
  15995. } elseif (($chardata[$i]['type'] == 'N') AND
  15996. (($chardata[($i-1)]['type'] == 'R') OR ($chardata[($i-1)]['type'] == 'EN') OR ($chardata[($i-1)]['type'] == 'AN')) AND
  15997. (($chardata[$i]['eor'] == 'R') OR ($chardata[$i]['eor'] == 'EN') OR ($chardata[$i]['eor'] == 'AN'))) {
  15998. $chardata[$i]['type'] = 'R';
  15999. } elseif ($chardata[$i]['type'] == 'N') {
  16000. // N2. Any remaining neutrals take the embedding direction
  16001. $chardata[$i]['type'] = $chardata[$i]['sor'];
  16002. }
  16003. } elseif ($chardata[$i]['type'] == 'N') {
  16004. // N2. Any remaining neutrals take the embedding direction
  16005. $chardata[$i]['type'] = $chardata[$i]['sor'];
  16006. }
  16007. if ($chardata[$i]['level'] != $prevlevel) {
  16008. $levcount = 0;
  16009. } else {
  16010. ++$levcount;
  16011. }
  16012. $prevlevel = $chardata[$i]['level'];
  16013. }
  16014. // 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.
  16015. // I2. For all characters with an odd (right-to-left) embedding direction, those of type L, EN or AN go up one level.
  16016. for ($i=0; $i < $numchars; ++$i) {
  16017. $odd = $chardata[$i]['level'] % 2;
  16018. if ($odd) {
  16019. if (($chardata[$i]['type'] == 'L') OR ($chardata[$i]['type'] == 'AN') OR ($chardata[$i]['type'] == 'EN')) {
  16020. $chardata[$i]['level'] += 1;
  16021. }
  16022. } else {
  16023. if ($chardata[$i]['type'] == 'R') {
  16024. $chardata[$i]['level'] += 1;
  16025. } elseif (($chardata[$i]['type'] == 'AN') OR ($chardata[$i]['type'] == 'EN')) {
  16026. $chardata[$i]['level'] += 2;
  16027. }
  16028. }
  16029. $maxlevel = max($chardata[$i]['level'],$maxlevel);
  16030. }
  16031. // L1. On each line, reset the embedding level of the following characters to the paragraph embedding level:
  16032. // 1. Segment separators,
  16033. // 2. Paragraph separators,
  16034. // 3. Any sequence of whitespace characters preceding a segment separator or paragraph separator, and
  16035. // 4. Any sequence of white space characters at the end of the line.
  16036. for ($i=0; $i < $numchars; ++$i) {
  16037. if (($chardata[$i]['type'] == 'B') OR ($chardata[$i]['type'] == 'S')) {
  16038. $chardata[$i]['level'] = $pel;
  16039. } elseif ($chardata[$i]['type'] == 'WS') {
  16040. $j = $i+1;
  16041. while ($j < $numchars) {
  16042. if ((($chardata[$j]['type'] == 'B') OR ($chardata[$j]['type'] == 'S')) OR
  16043. (($j == ($numchars-1)) AND ($chardata[$j]['type'] == 'WS'))) {
  16044. $chardata[$i]['level'] = $pel;
  16045. break;
  16046. } elseif ($chardata[$j]['type'] != 'WS') {
  16047. break;
  16048. }
  16049. ++$j;
  16050. }
  16051. }
  16052. }
  16053. // Arabic Shaping
  16054. // 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.
  16055. if ($arabic) {
  16056. $endedletter = array(1569,1570,1571,1572,1573,1575,1577,1583,1584,1585,1586,1608,1688);
  16057. $alfletter = array(1570,1571,1573,1575);
  16058. $chardata2 = $chardata;
  16059. $laaletter = false;
  16060. $charAL = array();
  16061. $x = 0;
  16062. for ($i=0; $i < $numchars; ++$i) {
  16063. if (($this->unicode->uni_type[$chardata[$i]['char']] == 'AL') OR ($chardata[$i]['char'] == 32) OR ($chardata[$i]['char'] == 8204)) {
  16064. $charAL[$x] = $chardata[$i];
  16065. $charAL[$x]['i'] = $i;
  16066. $chardata[$i]['x'] = $x;
  16067. ++$x;
  16068. }
  16069. }
  16070. $numAL = $x;
  16071. for ($i=0; $i < $numchars; ++$i) {
  16072. $thischar = $chardata[$i];
  16073. if ($i > 0) {
  16074. $prevchar = $chardata[($i-1)];
  16075. } else {
  16076. $prevchar = false;
  16077. }
  16078. if (($i+1) < $numchars) {
  16079. $nextchar = $chardata[($i+1)];
  16080. } else {
  16081. $nextchar = false;
  16082. }
  16083. if ($this->unicode->uni_type[$thischar['char']] == 'AL') {
  16084. $x = $thischar['x'];
  16085. if ($x > 0) {
  16086. $prevchar = $charAL[($x-1)];
  16087. } else {
  16088. $prevchar = false;
  16089. }
  16090. if (($x+1) < $numAL) {
  16091. $nextchar = $charAL[($x+1)];
  16092. } else {
  16093. $nextchar = false;
  16094. }
  16095. // if laa letter
  16096. if (($prevchar !== false) AND ($prevchar['char'] == 1604) AND (in_array($thischar['char'], $alfletter))) {
  16097. $arabicarr = $this->unicode->uni_laa_array;
  16098. $laaletter = true;
  16099. if ($x > 1) {
  16100. $prevchar = $charAL[($x-2)];
  16101. } else {
  16102. $prevchar = false;
  16103. }
  16104. } else {
  16105. $arabicarr = $this->unicode->uni_arabicsubst;
  16106. $laaletter = false;
  16107. }
  16108. if (($prevchar !== false) AND ($nextchar !== false) AND
  16109. (($this->unicode->uni_type[$prevchar['char']] == 'AL') OR ($this->unicode->uni_type[$prevchar['char']] == 'NSM')) AND
  16110. (($this->unicode->uni_type[$nextchar['char']] == 'AL') OR ($this->unicode->uni_type[$nextchar['char']] == 'NSM')) AND
  16111. ($prevchar['type'] == $thischar['type']) AND
  16112. ($nextchar['type'] == $thischar['type']) AND
  16113. ($nextchar['char'] != 1567)) {
  16114. if (in_array($prevchar['char'], $endedletter)) {
  16115. if (isset($arabicarr[$thischar['char']][2])) {
  16116. // initial
  16117. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][2];
  16118. }
  16119. } else {
  16120. if (isset($arabicarr[$thischar['char']][3])) {
  16121. // medial
  16122. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][3];
  16123. }
  16124. }
  16125. } elseif (($nextchar !== false) AND
  16126. (($this->unicode->uni_type[$nextchar['char']] == 'AL') OR ($this->unicode->uni_type[$nextchar['char']] == 'NSM')) AND
  16127. ($nextchar['type'] == $thischar['type']) AND
  16128. ($nextchar['char'] != 1567)) {
  16129. if (isset($arabicarr[$chardata[$i]['char']][2])) {
  16130. // initial
  16131. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][2];
  16132. }
  16133. } elseif ((($prevchar !== false) AND
  16134. (($this->unicode->uni_type[$prevchar['char']] == 'AL') OR ($this->unicode->uni_type[$prevchar['char']] == 'NSM')) AND
  16135. ($prevchar['type'] == $thischar['type'])) OR
  16136. (($nextchar !== false) AND ($nextchar['char'] == 1567))) {
  16137. // final
  16138. if (($i > 1) AND ($thischar['char'] == 1607) AND
  16139. ($chardata[$i-1]['char'] == 1604) AND
  16140. ($chardata[$i-2]['char'] == 1604)) {
  16141. //Allah Word
  16142. // mark characters to delete with false
  16143. $chardata2[$i-2]['char'] = false;
  16144. $chardata2[$i-1]['char'] = false;
  16145. $chardata2[$i]['char'] = 65010;
  16146. } else {
  16147. if (($prevchar !== false) AND in_array($prevchar['char'], $endedletter)) {
  16148. if (isset($arabicarr[$thischar['char']][0])) {
  16149. // isolated
  16150. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][0];
  16151. }
  16152. } else {
  16153. if (isset($arabicarr[$thischar['char']][1])) {
  16154. // final
  16155. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][1];
  16156. }
  16157. }
  16158. }
  16159. } elseif (isset($arabicarr[$thischar['char']][0])) {
  16160. // isolated
  16161. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][0];
  16162. }
  16163. // if laa letter
  16164. if ($laaletter) {
  16165. // mark characters to delete with false
  16166. $chardata2[($charAL[($x-1)]['i'])]['char'] = false;
  16167. }
  16168. } // end if AL (Arabic Letter)
  16169. } // end for each char
  16170. /*
  16171. * Combining characters that can occur with Arabic Shadda (0651 HEX, 1617 DEC) are replaced.
  16172. * Putting the combining mark and shadda in the same glyph allows us to avoid the two marks overlapping each other in an illegible manner.
  16173. */
  16174. for ($i = 0; $i < ($numchars-1); ++$i) {
  16175. if (($chardata2[$i]['char'] == 1617) AND (isset($this->unicode->uni_diacritics[($chardata2[$i+1]['char'])]))) {
  16176. // check if the subtitution font is defined on current font
  16177. if (isset($this->CurrentFont['cw'][($this->unicode->uni_diacritics[($chardata2[$i+1]['char'])])])) {
  16178. $chardata2[$i]['char'] = false;
  16179. $chardata2[$i+1]['char'] = $this->unicode->uni_diacritics[($chardata2[$i+1]['char'])];
  16180. }
  16181. }
  16182. }
  16183. // remove marked characters
  16184. foreach ($chardata2 as $key => $value) {
  16185. if ($value['char'] === false) {
  16186. unset($chardata2[$key]);
  16187. }
  16188. }
  16189. $chardata = array_values($chardata2);
  16190. $numchars = count($chardata);
  16191. unset($chardata2);
  16192. unset($arabicarr);
  16193. unset($laaletter);
  16194. unset($charAL);
  16195. }
  16196. // 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.
  16197. for ($j=$maxlevel; $j > 0; $j--) {
  16198. $ordarray = Array();
  16199. $revarr = Array();
  16200. $onlevel = false;
  16201. for ($i=0; $i < $numchars; ++$i) {
  16202. if ($chardata[$i]['level'] >= $j) {
  16203. $onlevel = true;
  16204. if (isset($this->unicode->uni_mirror[$chardata[$i]['char']])) {
  16205. // 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.
  16206. $chardata[$i]['char'] = $this->unicode->uni_mirror[$chardata[$i]['char']];
  16207. }
  16208. $revarr[] = $chardata[$i];
  16209. } else {
  16210. if ($onlevel) {
  16211. $revarr = array_reverse($revarr);
  16212. $ordarray = array_merge($ordarray, $revarr);
  16213. $revarr = Array();
  16214. $onlevel = false;
  16215. }
  16216. $ordarray[] = $chardata[$i];
  16217. }
  16218. }
  16219. if ($onlevel) {
  16220. $revarr = array_reverse($revarr);
  16221. $ordarray = array_merge($ordarray, $revarr);
  16222. }
  16223. $chardata = $ordarray;
  16224. }
  16225. $ordarray = array();
  16226. for ($i=0; $i < $numchars; ++$i) {
  16227. $ordarray[] = $chardata[$i]['char'];
  16228. // store char values for subsetting
  16229. $this->CurrentFont['subsetchars'][$chardata[$i]['char']] = true;
  16230. }
  16231. // update font subsetchars
  16232. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  16233. return $ordarray;
  16234. }
  16235. // END OF BIDIRECTIONAL TEXT SECTION -------------------
  16236. /**
  16237. * Encode a name object.
  16238. * @param $name (string) Name object to encode.
  16239. * @return (string) Encoded name object.
  16240. * @protected
  16241. * @author Nicola Asuni
  16242. * @since 5.9.097 (2011-06-23)
  16243. */
  16244. protected function encodeNameObject($name) {
  16245. $escname = '';
  16246. $length = strlen($name);
  16247. for ($i = 0; $i < $length; ++$i) {
  16248. $chr = $name[$i];
  16249. if (preg_match('/[0-9a-zA-Z]/', $chr) == 1) {
  16250. $escname .= $chr;
  16251. } else {
  16252. $escname .= sprintf('#%02X', ord($chr));
  16253. }
  16254. }
  16255. return $escname;
  16256. }
  16257. /**
  16258. * Add a Named Destination.
  16259. * NOTE: destination names are unique, so only last entry will be saved.
  16260. * @param $name (string) Destination name.
  16261. * @param $y (float) Y position in user units of the destiantion on the selected page (default = -1 = current position; 0 = page start;).
  16262. * @param $page (int) Target page number (leave empty for current page).
  16263. * @param $x (float) X position in user units of the destiantion on the selected page (default = -1 = current position;).
  16264. * @return (string) Stripped named destination identifier or false in case of error.
  16265. * @public
  16266. * @author Christian Deligant, Nicola Asuni
  16267. * @since 5.9.097 (2011-06-23)
  16268. */
  16269. public function setDestination($name, $y=-1, $page='', $x=-1) {
  16270. // remove unsupported characters
  16271. $name = $this->encodeNameObject($name);
  16272. if ($this->empty_string($name)) {
  16273. return false;
  16274. }
  16275. if ($y == -1) {
  16276. $y = $this->GetY();
  16277. } elseif ($y < 0) {
  16278. $y = 0;
  16279. } elseif ($y > $this->h) {
  16280. $y = $this->h;
  16281. }
  16282. if ($x == -1) {
  16283. $x = $this->GetX();
  16284. } elseif ($x < 0) {
  16285. $x = 0;
  16286. } elseif ($x > $this->w) {
  16287. $x = $this->w;
  16288. }
  16289. if (empty($page)) {
  16290. $page = $this->PageNo();
  16291. if (empty($page)) {
  16292. return;
  16293. }
  16294. }
  16295. $this->dests[$name] = array('x' => $x, 'y' => $y, 'p' => $page);
  16296. return $name;
  16297. }
  16298. /**
  16299. * Return the Named Destination array.
  16300. * @return (array) Named Destination array.
  16301. * @public
  16302. * @author Nicola Asuni
  16303. * @since 5.9.097 (2011-06-23)
  16304. */
  16305. public function getDestination() {
  16306. return $this->dests;
  16307. }
  16308. /**
  16309. * Insert Named Destinations.
  16310. * @protected
  16311. * @author Johannes Güntert, Nicola Asuni
  16312. * @since 5.9.098 (2011-06-23)
  16313. */
  16314. protected function _putdests() {
  16315. if (empty($this->dests)) {
  16316. return;
  16317. }
  16318. $this->n_dests = $this->_newobj();
  16319. $out = ' <<';
  16320. foreach($this->dests as $name => $o) {
  16321. $out .= ' /'.$name.' '.sprintf('[%u 0 R /XYZ %F %F null]', $this->page_obj_id[($o['p'])], ($o['x'] * $this->k), ($this->pagedim[$o['p']]['h'] - ($o['y'] * $this->k)));
  16322. }
  16323. $out .= ' >>';
  16324. $out .= "\n".'endobj';
  16325. $this->_out($out);
  16326. }
  16327. /**
  16328. * Adds a bookmark - alias for Bookmark().
  16329. * @param $txt (string) Bookmark description.
  16330. * @param $level (int) Bookmark level (minimum value is 0).
  16331. * @param $y (float) Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
  16332. * @param $page (int) Target page number (leave empty for current page).
  16333. * @param $style (string) Font style: B = Bold, I = Italic, BI = Bold + Italic.
  16334. * @param $color (array) RGB color array (values from 0 to 255).
  16335. * @param $x (float) X position in user units of the bookmark on the selected page (default = -1 = current position;).
  16336. * @param $link (mixed) URL, or numerical link ID, or named destination (# character followed by the destination name), or embedded file (* character followed by the file name).
  16337. * @public
  16338. */
  16339. public function setBookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='') {
  16340. $this->Bookmark($txt, $level, $y, $page, $style, $color, $x, $link);
  16341. }
  16342. /**
  16343. * Adds a bookmark.
  16344. * @param $txt (string) Bookmark description.
  16345. * @param $level (int) Bookmark level (minimum value is 0).
  16346. * @param $y (float) Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
  16347. * @param $page (int) Target page number (leave empty for current page).
  16348. * @param $style (string) Font style: B = Bold, I = Italic, BI = Bold + Italic.
  16349. * @param $color (array) RGB color array (values from 0 to 255).
  16350. * @param $x (float) X position in user units of the bookmark on the selected page (default = -1 = current position;).
  16351. * @param $link (mixed) URL, or numerical link ID, or named destination (# character followed by the destination name), or embedded file (* character followed by the file name).
  16352. * @public
  16353. * @since 2.1.002 (2008-02-12)
  16354. */
  16355. public function Bookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='') {
  16356. if ($level < 0) {
  16357. $level = 0;
  16358. }
  16359. if (isset($this->outlines[0])) {
  16360. $lastoutline = end($this->outlines);
  16361. $maxlevel = $lastoutline['l'] + 1;
  16362. } else {
  16363. $maxlevel = 0;
  16364. }
  16365. if ($level > $maxlevel) {
  16366. $level = $maxlevel;
  16367. }
  16368. if ($y == -1) {
  16369. $y = $this->GetY();
  16370. } elseif ($y < 0) {
  16371. $y = 0;
  16372. } elseif ($y > $this->h) {
  16373. $y = $this->h;
  16374. }
  16375. if ($x == -1) {
  16376. $x = $this->GetX();
  16377. } elseif ($x < 0) {
  16378. $x = 0;
  16379. } elseif ($x > $this->w) {
  16380. $x = $this->w;
  16381. }
  16382. if (empty($page)) {
  16383. $page = $this->PageNo();
  16384. if (empty($page)) {
  16385. return;
  16386. }
  16387. }
  16388. $this->outlines[] = array('t' => $txt, 'l' => $level, 'x' => $x, 'y' => $y, 'p' => $page, 's' => strtoupper($style), 'c' => $color, 'u' => $link);
  16389. }
  16390. /**
  16391. * Sort bookmarks for page and key.
  16392. * @protected
  16393. * @since 5.9.119 (2011-09-19)
  16394. */
  16395. protected function sortBookmarks() {
  16396. // get sorting columns
  16397. $outline_p = array();
  16398. $outline_y = array();
  16399. foreach ($this->outlines as $key => $row) {
  16400. $outline_p[$key] = $row['p'];
  16401. $outline_k[$key] = $key;
  16402. }
  16403. // sort outlines by page and original position
  16404. array_multisort($outline_p, SORT_NUMERIC, SORT_ASC, $outline_k, SORT_NUMERIC, SORT_ASC, $this->outlines);
  16405. }
  16406. /**
  16407. * Create a bookmark PDF string.
  16408. * @protected
  16409. * @author Olivier Plathey, Nicola Asuni
  16410. * @since 2.1.002 (2008-02-12)
  16411. */
  16412. protected function _putbookmarks() {
  16413. $nb = count($this->outlines);
  16414. if ($nb == 0) {
  16415. return;
  16416. }
  16417. // sort bookmarks
  16418. $this->sortBookmarks();
  16419. $lru = array();
  16420. $level = 0;
  16421. foreach ($this->outlines as $i => $o) {
  16422. if ($o['l'] > 0) {
  16423. $parent = $lru[($o['l'] - 1)];
  16424. //Set parent and last pointers
  16425. $this->outlines[$i]['parent'] = $parent;
  16426. $this->outlines[$parent]['last'] = $i;
  16427. if ($o['l'] > $level) {
  16428. //Level increasing: set first pointer
  16429. $this->outlines[$parent]['first'] = $i;
  16430. }
  16431. } else {
  16432. $this->outlines[$i]['parent'] = $nb;
  16433. }
  16434. if (($o['l'] <= $level) AND ($i > 0)) {
  16435. //Set prev and next pointers
  16436. $prev = $lru[$o['l']];
  16437. $this->outlines[$prev]['next'] = $i;
  16438. $this->outlines[$i]['prev'] = $prev;
  16439. }
  16440. $lru[$o['l']] = $i;
  16441. $level = $o['l'];
  16442. }
  16443. //Outline items
  16444. $n = $this->n + 1;
  16445. $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';
  16446. foreach ($this->outlines as $i => $o) {
  16447. $oid = $this->_newobj();
  16448. // covert HTML title to string
  16449. $title = preg_replace($nltags, "\n", $o['t']);
  16450. $title = preg_replace("/[\r]+/si", '', $title);
  16451. $title = preg_replace("/[\n]+/si", "\n", $title);
  16452. $title = strip_tags($title);
  16453. $title = $this->stringTrim($title);
  16454. $out = '<</Title '.$this->_textstring($title, $oid);
  16455. $out .= ' /Parent '.($n + $o['parent']).' 0 R';
  16456. if (isset($o['prev'])) {
  16457. $out .= ' /Prev '.($n + $o['prev']).' 0 R';
  16458. }
  16459. if (isset($o['next'])) {
  16460. $out .= ' /Next '.($n + $o['next']).' 0 R';
  16461. }
  16462. if (isset($o['first'])) {
  16463. $out .= ' /First '.($n + $o['first']).' 0 R';
  16464. }
  16465. if (isset($o['last'])) {
  16466. $out .= ' /Last '.($n + $o['last']).' 0 R';
  16467. }
  16468. if (isset($o['u']) AND !empty($o['u'])) {
  16469. // link
  16470. if (is_string($o['u'])) {
  16471. if ($o['u'][0] == '#') {
  16472. // internal destination
  16473. $out .= ' /Dest /'.$this->encodeNameObject(substr($o['u'], 1));
  16474. } elseif ($o['u'][0] == '%') {
  16475. // embedded PDF file
  16476. $filename = basename(substr($o['u'], 1));
  16477. $out .= ' /A <</S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($o['p'] - 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>';
  16478. } elseif ($o['u'][0] == '*') {
  16479. // embedded generic file
  16480. $filename = basename(substr($o['u'], 1));
  16481. $jsa = 'var D=event.target.doc;var MyData=D.dataObjects;for (var i in MyData) if (MyData[i].path=="'.$filename.'") D.exportDataObject( { cName : MyData[i].name, nLaunch : 2});';
  16482. $out .= ' /A <</S /JavaScript /JS '.$this->_textstring($jsa, $oid).'>>';
  16483. } else {
  16484. // external URI link
  16485. $out .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($o['u']), $oid).'>>';
  16486. }
  16487. } elseif (isset($this->links[$o['u']])) {
  16488. // internal link ID
  16489. $l = $this->links[$o['u']];
  16490. if (isset($this->page_obj_id[($l[0])])) {
  16491. $out .= sprintf(' /Dest [%u 0 R /XYZ 0 %F null]', $this->page_obj_id[($l[0])], ($this->pagedim[$l[0]]['h'] - ($l[1] * $this->k)));
  16492. }
  16493. }
  16494. } elseif (isset($this->page_obj_id[($o['p'])])) {
  16495. // link to a page
  16496. $out .= ' '.sprintf('/Dest [%u 0 R /XYZ %F %F null]', $this->page_obj_id[($o['p'])], ($o['x'] * $this->k), ($this->pagedim[$o['p']]['h'] - ($o['y'] * $this->k)));
  16497. }
  16498. // set font style
  16499. $style = 0;
  16500. if (!empty($o['s'])) {
  16501. // bold
  16502. if (strpos($o['s'], 'B') !== false) {
  16503. $style |= 2;
  16504. }
  16505. // oblique
  16506. if (strpos($o['s'], 'I') !== false) {
  16507. $style |= 1;
  16508. }
  16509. }
  16510. $out .= sprintf(' /F %d', $style);
  16511. // set bookmark color
  16512. if (isset($o['c']) AND is_array($o['c']) AND (count($o['c']) == 3)) {
  16513. $color = array_values($o['c']);
  16514. $out .= sprintf(' /C [%F %F %F]', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
  16515. } else {
  16516. // black
  16517. $out .= ' /C [0.0 0.0 0.0]';
  16518. }
  16519. $out .= ' /Count 0'; // normally closed item
  16520. $out .= ' >>';
  16521. $out .= "\n".'endobj';
  16522. $this->_out($out);
  16523. }
  16524. //Outline root
  16525. $this->OutlineRoot = $this->_newobj();
  16526. $this->_out('<< /Type /Outlines /First '.$n.' 0 R /Last '.($n + $lru[0]).' 0 R >>'."\n".'endobj');
  16527. }
  16528. // --- JAVASCRIPT ------------------------------------------------------
  16529. /**
  16530. * Adds a javascript
  16531. * @param $script (string) Javascript code
  16532. * @public
  16533. * @author Johannes Güntert, Nicola Asuni
  16534. * @since 2.1.002 (2008-02-12)
  16535. */
  16536. public function IncludeJS($script) {
  16537. $this->javascript .= $script;
  16538. }
  16539. /**
  16540. * Adds a javascript object and return object ID
  16541. * @param $script (string) Javascript code
  16542. * @param $onload (boolean) if true executes this object when opening the document
  16543. * @return int internal object ID
  16544. * @public
  16545. * @author Nicola Asuni
  16546. * @since 4.8.000 (2009-09-07)
  16547. */
  16548. public function addJavascriptObject($script, $onload=false) {
  16549. if ($this->pdfa_mode) {
  16550. // javascript is not allowed in PDF/A mode
  16551. return false;
  16552. }
  16553. ++$this->n;
  16554. $this->js_objects[$this->n] = array('n' => $this->n, 'js' => $script, 'onload' => $onload);
  16555. return $this->n;
  16556. }
  16557. /**
  16558. * Create a javascript PDF string.
  16559. * @protected
  16560. * @author Johannes Güntert, Nicola Asuni
  16561. * @since 2.1.002 (2008-02-12)
  16562. */
  16563. protected function _putjavascript() {
  16564. if ($this->pdfa_mode OR (empty($this->javascript) AND empty($this->js_objects))) {
  16565. return;
  16566. }
  16567. if (strpos($this->javascript, 'this.addField') > 0) {
  16568. if (!$this->ur['enabled']) {
  16569. //$this->setUserRights();
  16570. }
  16571. // the following two lines are used to avoid form fields duplication after saving
  16572. // The addField method only works when releasing user rights (UR3)
  16573. $jsa = sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%F,%F,%F,%F]);", 'tcpdfdocsaved', 'text', 0, 0, 1, 0, 1);
  16574. $jsb = "getField('tcpdfdocsaved').value='saved';";
  16575. $this->javascript = $jsa."\n".$this->javascript."\n".$jsb;
  16576. }
  16577. // name tree for javascript
  16578. $this->n_js = '<< /Names [';
  16579. if (!empty($this->javascript)) {
  16580. $this->n_js .= ' (EmbeddedJS) '.($this->n + 1).' 0 R';
  16581. }
  16582. if (!empty($this->js_objects)) {
  16583. foreach ($this->js_objects as $key => $val) {
  16584. if ($val['onload']) {
  16585. $this->n_js .= ' (JS'.$key.') '.$key.' 0 R';
  16586. }
  16587. }
  16588. }
  16589. $this->n_js .= ' ] >>';
  16590. // default Javascript object
  16591. if (!empty($this->javascript)) {
  16592. $obj_id = $this->_newobj();
  16593. $out = '<< /S /JavaScript';
  16594. $out .= ' /JS '.$this->_textstring($this->javascript, $obj_id);
  16595. $out .= ' >>';
  16596. $out .= "\n".'endobj';
  16597. $this->_out($out);
  16598. }
  16599. // additional Javascript objects
  16600. if (!empty($this->js_objects)) {
  16601. foreach ($this->js_objects as $key => $val) {
  16602. $out = $this->_getobj($key)."\n".' << /S /JavaScript /JS '.$this->_textstring($val['js'], $key).' >>'."\n".'endobj';
  16603. $this->_out($out);
  16604. }
  16605. }
  16606. }
  16607. /**
  16608. * Convert color to javascript color.
  16609. * @param $color (string) color name or "#RRGGBB"
  16610. * @protected
  16611. * @author Denis Van Nuffelen, Nicola Asuni
  16612. * @since 2.1.002 (2008-02-12)
  16613. */
  16614. protected function _JScolor($color) {
  16615. static $aColors = array('transparent', 'black', 'white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'dkGray', 'gray', 'ltGray');
  16616. if (substr($color,0,1) == '#') {
  16617. return sprintf("['RGB',%F,%F,%F]", hexdec(substr($color,1,2))/255, hexdec(substr($color,3,2))/255, hexdec(substr($color,5,2))/255);
  16618. }
  16619. if (!in_array($color,$aColors)) {
  16620. $this->Error('Invalid color: '.$color);
  16621. }
  16622. return 'color.'.$color;
  16623. }
  16624. /**
  16625. * Adds a javascript form field.
  16626. * @param $type (string) field type
  16627. * @param $name (string) field name
  16628. * @param $x (int) horizontal position
  16629. * @param $y (int) vertical position
  16630. * @param $w (int) width
  16631. * @param $h (int) height
  16632. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  16633. * @protected
  16634. * @author Denis Van Nuffelen, Nicola Asuni
  16635. * @since 2.1.002 (2008-02-12)
  16636. */
  16637. protected function _addfield($type, $name, $x, $y, $w, $h, $prop) {
  16638. if ($this->rtl) {
  16639. $x = $x - $w;
  16640. }
  16641. // the followind avoid fields duplication after saving the document
  16642. $this->javascript .= "if (getField('tcpdfdocsaved').value != 'saved') {";
  16643. $k = $this->k;
  16644. $this->javascript .= sprintf("f".$name."=this.addField('%s','%s',%u,[%F,%F,%F,%F]);", $name, $type, $this->PageNo()-1, $x*$k, ($this->h-$y)*$k+1, ($x+$w)*$k, ($this->h-$y-$h)*$k+1)."\n";
  16645. $this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n";
  16646. while (list($key, $val) = each($prop)) {
  16647. if (strcmp(substr($key, -5), 'Color') == 0) {
  16648. $val = $this->_JScolor($val);
  16649. } else {
  16650. $val = "'".$val."'";
  16651. }
  16652. $this->javascript .= 'f'.$name.'.'.$key.'='.$val.";\n";
  16653. }
  16654. if ($this->rtl) {
  16655. $this->x -= $w;
  16656. } else {
  16657. $this->x += $w;
  16658. }
  16659. $this->javascript .= '}';
  16660. }
  16661. // --- FORM FIELDS -----------------------------------------------------
  16662. /**
  16663. * Convert JavaScript form fields properties array to Annotation Properties array.
  16664. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  16665. * @return array of annotation properties
  16666. * @protected
  16667. * @author Nicola Asuni
  16668. * @since 4.8.000 (2009-09-06)
  16669. */
  16670. protected function getAnnotOptFromJSProp($prop) {
  16671. if (isset($prop['aopt']) AND is_array($prop['aopt'])) {
  16672. // the annotation options area lready defined
  16673. return $prop['aopt'];
  16674. }
  16675. $opt = array(); // value to be returned
  16676. // alignment: Controls how the text is laid out within the text field.
  16677. if (isset($prop['alignment'])) {
  16678. switch ($prop['alignment']) {
  16679. case 'left': {
  16680. $opt['q'] = 0;
  16681. break;
  16682. }
  16683. case 'center': {
  16684. $opt['q'] = 1;
  16685. break;
  16686. }
  16687. case 'right': {
  16688. $opt['q'] = 2;
  16689. break;
  16690. }
  16691. default: {
  16692. $opt['q'] = ($this->rtl)?2:0;
  16693. break;
  16694. }
  16695. }
  16696. }
  16697. // lineWidth: Specifies the thickness of the border when stroking the perimeter of a field's rectangle.
  16698. if (isset($prop['lineWidth'])) {
  16699. $linewidth = intval($prop['lineWidth']);
  16700. } else {
  16701. $linewidth = 1;
  16702. }
  16703. // borderStyle: The border style for a field.
  16704. if (isset($prop['borderStyle'])) {
  16705. switch ($prop['borderStyle']) {
  16706. case 'border.d':
  16707. case 'dashed': {
  16708. $opt['border'] = array(0, 0, $linewidth, array(3, 2));
  16709. $opt['bs'] = array('w'=>$linewidth, 's'=>'D', 'd'=>array(3, 2));
  16710. break;
  16711. }
  16712. case 'border.b':
  16713. case 'beveled': {
  16714. $opt['border'] = array(0, 0, $linewidth);
  16715. $opt['bs'] = array('w'=>$linewidth, 's'=>'B');
  16716. break;
  16717. }
  16718. case 'border.i':
  16719. case 'inset': {
  16720. $opt['border'] = array(0, 0, $linewidth);
  16721. $opt['bs'] = array('w'=>$linewidth, 's'=>'I');
  16722. break;
  16723. }
  16724. case 'border.u':
  16725. case 'underline': {
  16726. $opt['border'] = array(0, 0, $linewidth);
  16727. $opt['bs'] = array('w'=>$linewidth, 's'=>'U');
  16728. break;
  16729. }
  16730. case 'border.s':
  16731. case 'solid': {
  16732. $opt['border'] = array(0, 0, $linewidth);
  16733. $opt['bs'] = array('w'=>$linewidth, 's'=>'S');
  16734. break;
  16735. }
  16736. default: {
  16737. break;
  16738. }
  16739. }
  16740. }
  16741. if (isset($prop['border']) AND is_array($prop['border'])) {
  16742. $opt['border'] = $prop['border'];
  16743. }
  16744. if (!isset($opt['mk'])) {
  16745. $opt['mk'] = array();
  16746. }
  16747. if (!isset($opt['mk']['if'])) {
  16748. $opt['mk']['if'] = array();
  16749. }
  16750. $opt['mk']['if']['a'] = array(0.5, 0.5);
  16751. // buttonAlignX: Controls how space is distributed from the left of the button face with respect to the icon.
  16752. if (isset($prop['buttonAlignX'])) {
  16753. $opt['mk']['if']['a'][0] = $prop['buttonAlignX'];
  16754. }
  16755. // buttonAlignY: Controls how unused space is distributed from the bottom of the button face with respect to the icon.
  16756. if (isset($prop['buttonAlignY'])) {
  16757. $opt['mk']['if']['a'][1] = $prop['buttonAlignY'];
  16758. }
  16759. // buttonFitBounds: If true, the extent to which the icon may be scaled is set to the bounds of the button field.
  16760. if (isset($prop['buttonFitBounds']) AND ($prop['buttonFitBounds'] == 'true')) {
  16761. $opt['mk']['if']['fb'] = true;
  16762. }
  16763. // buttonScaleHow: Controls how the icon is scaled (if necessary) to fit inside the button face.
  16764. if (isset($prop['buttonScaleHow'])) {
  16765. switch ($prop['buttonScaleHow']) {
  16766. case 'scaleHow.proportional': {
  16767. $opt['mk']['if']['s'] = 'P';
  16768. break;
  16769. }
  16770. case 'scaleHow.anamorphic': {
  16771. $opt['mk']['if']['s'] = 'A';
  16772. break;
  16773. }
  16774. }
  16775. }
  16776. // buttonScaleWhen: Controls when an icon is scaled to fit inside the button face.
  16777. if (isset($prop['buttonScaleWhen'])) {
  16778. switch ($prop['buttonScaleWhen']) {
  16779. case 'scaleWhen.always': {
  16780. $opt['mk']['if']['sw'] = 'A';
  16781. break;
  16782. }
  16783. case 'scaleWhen.never': {
  16784. $opt['mk']['if']['sw'] = 'N';
  16785. break;
  16786. }
  16787. case 'scaleWhen.tooBig': {
  16788. $opt['mk']['if']['sw'] = 'B';
  16789. break;
  16790. }
  16791. case 'scaleWhen.tooSmall': {
  16792. $opt['mk']['if']['sw'] = 'S';
  16793. break;
  16794. }
  16795. }
  16796. }
  16797. // buttonPosition: Controls how the text and the icon of the button are positioned with respect to each other within the button face.
  16798. if (isset($prop['buttonPosition'])) {
  16799. switch ($prop['buttonPosition']) {
  16800. case 0:
  16801. case 'position.textOnly': {
  16802. $opt['mk']['tp'] = 0;
  16803. break;
  16804. }
  16805. case 1:
  16806. case 'position.iconOnly': {
  16807. $opt['mk']['tp'] = 1;
  16808. break;
  16809. }
  16810. case 2:
  16811. case 'position.iconTextV': {
  16812. $opt['mk']['tp'] = 2;
  16813. break;
  16814. }
  16815. case 3:
  16816. case 'position.textIconV': {
  16817. $opt['mk']['tp'] = 3;
  16818. break;
  16819. }
  16820. case 4:
  16821. case 'position.iconTextH': {
  16822. $opt['mk']['tp'] = 4;
  16823. break;
  16824. }
  16825. case 5:
  16826. case 'position.textIconH': {
  16827. $opt['mk']['tp'] = 5;
  16828. break;
  16829. }
  16830. case 6:
  16831. case 'position.overlay': {
  16832. $opt['mk']['tp'] = 6;
  16833. break;
  16834. }
  16835. }
  16836. }
  16837. // fillColor: Specifies the background color for a field.
  16838. if (isset($prop['fillColor'])) {
  16839. if (is_array($prop['fillColor'])) {
  16840. $opt['mk']['bg'] = $prop['fillColor'];
  16841. } else {
  16842. $opt['mk']['bg'] = $this->convertHTMLColorToDec($prop['fillColor']);
  16843. }
  16844. }
  16845. // 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.
  16846. if (isset($prop['strokeColor'])) {
  16847. if (is_array($prop['strokeColor'])) {
  16848. $opt['mk']['bc'] = $prop['strokeColor'];
  16849. } else {
  16850. $opt['mk']['bc'] = $this->convertHTMLColorToDec($prop['strokeColor']);
  16851. }
  16852. }
  16853. // rotation: The rotation of a widget in counterclockwise increments.
  16854. if (isset($prop['rotation'])) {
  16855. $opt['mk']['r'] = $prop['rotation'];
  16856. }
  16857. // charLimit: Limits the number of characters that a user can type into a text field.
  16858. if (isset($prop['charLimit'])) {
  16859. $opt['maxlen'] = intval($prop['charLimit']);
  16860. }
  16861. if (!isset($ff)) {
  16862. $ff = 0; // default value
  16863. }
  16864. // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
  16865. if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
  16866. $ff += 1 << 0;
  16867. }
  16868. // required: Specifies whether a field requires a value.
  16869. if (isset($prop['required']) AND ($prop['required'] == 'true')) {
  16870. $ff += 1 << 1;
  16871. }
  16872. // multiline: Controls how text is wrapped within the field.
  16873. if (isset($prop['multiline']) AND ($prop['multiline'] == 'true')) {
  16874. $ff += 1 << 12;
  16875. }
  16876. // password: Specifies whether the field should display asterisks when data is entered in the field.
  16877. if (isset($prop['password']) AND ($prop['password'] == 'true')) {
  16878. $ff += 1 << 13;
  16879. }
  16880. // NoToggleToOff: If set, exactly one radio button shall be selected at all times; selecting the currently selected button has no effect.
  16881. if (isset($prop['NoToggleToOff']) AND ($prop['NoToggleToOff'] == 'true')) {
  16882. $ff += 1 << 14;
  16883. }
  16884. // Radio: If set, the field is a set of radio buttons.
  16885. if (isset($prop['Radio']) AND ($prop['Radio'] == 'true')) {
  16886. $ff += 1 << 15;
  16887. }
  16888. // Pushbutton: If set, the field is a pushbutton that does not retain a permanent value.
  16889. if (isset($prop['Pushbutton']) AND ($prop['Pushbutton'] == 'true')) {
  16890. $ff += 1 << 16;
  16891. }
  16892. // Combo: If set, the field is a combo box; if clear, the field is a list box.
  16893. if (isset($prop['Combo']) AND ($prop['Combo'] == 'true')) {
  16894. $ff += 1 << 17;
  16895. }
  16896. // editable: Controls whether a combo box is editable.
  16897. if (isset($prop['editable']) AND ($prop['editable'] == 'true')) {
  16898. $ff += 1 << 18;
  16899. }
  16900. // Sort: If set, the field's option items shall be sorted alphabetically.
  16901. if (isset($prop['Sort']) AND ($prop['Sort'] == 'true')) {
  16902. $ff += 1 << 19;
  16903. }
  16904. // fileSelect: If true, sets the file-select flag in the Options tab of the text field (Field is Used for File Selection).
  16905. if (isset($prop['fileSelect']) AND ($prop['fileSelect'] == 'true')) {
  16906. $ff += 1 << 20;
  16907. }
  16908. // multipleSelection: If true, indicates that a list box allows a multiple selection of items.
  16909. if (isset($prop['multipleSelection']) AND ($prop['multipleSelection'] == 'true')) {
  16910. $ff += 1 << 21;
  16911. }
  16912. // doNotSpellCheck: If true, spell checking is not performed on this editable text field.
  16913. if (isset($prop['doNotSpellCheck']) AND ($prop['doNotSpellCheck'] == 'true')) {
  16914. $ff += 1 << 22;
  16915. }
  16916. // doNotScroll: If true, the text field does not scroll and the user, therefore, is limited by the rectangular region designed for the field.
  16917. if (isset($prop['doNotScroll']) AND ($prop['doNotScroll'] == 'true')) {
  16918. $ff += 1 << 23;
  16919. }
  16920. // 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.
  16921. if (isset($prop['comb']) AND ($prop['comb'] == 'true')) {
  16922. $ff += 1 << 24;
  16923. }
  16924. // 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.
  16925. if (isset($prop['radiosInUnison']) AND ($prop['radiosInUnison'] == 'true')) {
  16926. $ff += 1 << 25;
  16927. }
  16928. // richText: If true, the field allows rich text formatting.
  16929. if (isset($prop['richText']) AND ($prop['richText'] == 'true')) {
  16930. $ff += 1 << 25;
  16931. }
  16932. // commitOnSelChange: Controls whether a field value is committed after a selection change.
  16933. if (isset($prop['commitOnSelChange']) AND ($prop['commitOnSelChange'] == 'true')) {
  16934. $ff += 1 << 26;
  16935. }
  16936. $opt['ff'] = $ff;
  16937. // defaultValue: The default value of a field - that is, the value that the field is set to when the form is reset.
  16938. if (isset($prop['defaultValue'])) {
  16939. $opt['dv'] = $prop['defaultValue'];
  16940. }
  16941. $f = 4; // default value for annotation flags
  16942. // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
  16943. if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
  16944. $f += 1 << 6;
  16945. }
  16946. // display: Controls whether the field is hidden or visible on screen and in print.
  16947. if (isset($prop['display'])) {
  16948. if ($prop['display'] == 'display.visible') {
  16949. //
  16950. } elseif ($prop['display'] == 'display.hidden') {
  16951. $f += 1 << 1;
  16952. } elseif ($prop['display'] == 'display.noPrint') {
  16953. $f -= 1 << 2;
  16954. } elseif ($prop['display'] == 'display.noView') {
  16955. $f += 1 << 5;
  16956. }
  16957. }
  16958. $opt['f'] = $f;
  16959. // currentValueIndices: Reads and writes single or multiple values of a list box or combo box.
  16960. if (isset($prop['currentValueIndices']) AND is_array($prop['currentValueIndices'])) {
  16961. $opt['i'] = $prop['currentValueIndices'];
  16962. }
  16963. // value: The value of the field data that the user has entered.
  16964. if (isset($prop['value'])) {
  16965. if (is_array($prop['value'])) {
  16966. $opt['opt'] = array();
  16967. foreach ($prop['value'] AS $key => $optval) {
  16968. // exportValues: An array of strings representing the export values for the field.
  16969. if (isset($prop['exportValues'][$key])) {
  16970. $opt['opt'][$key] = array($prop['exportValues'][$key], $prop['value'][$key]);
  16971. } else {
  16972. $opt['opt'][$key] = $prop['value'][$key];
  16973. }
  16974. }
  16975. } else {
  16976. $opt['v'] = $prop['value'];
  16977. }
  16978. }
  16979. // richValue: This property specifies the text contents and formatting of a rich text field.
  16980. if (isset($prop['richValue'])) {
  16981. $opt['rv'] = $prop['richValue'];
  16982. }
  16983. // submitName: If nonempty, used during form submission instead of name. Only applicable if submitting in HTML format (that is, URL-encoded).
  16984. if (isset($prop['submitName'])) {
  16985. $opt['tm'] = $prop['submitName'];
  16986. }
  16987. // name: Fully qualified field name.
  16988. if (isset($prop['name'])) {
  16989. $opt['t'] = $prop['name'];
  16990. }
  16991. // userName: The user name (short description string) of the field.
  16992. if (isset($prop['userName'])) {
  16993. $opt['tu'] = $prop['userName'];
  16994. }
  16995. // highlight: Defines how a button reacts when a user clicks it.
  16996. if (isset($prop['highlight'])) {
  16997. switch ($prop['highlight']) {
  16998. case 'none':
  16999. case 'highlight.n': {
  17000. $opt['h'] = 'N';
  17001. break;
  17002. }
  17003. case 'invert':
  17004. case 'highlight.i': {
  17005. $opt['h'] = 'i';
  17006. break;
  17007. }
  17008. case 'push':
  17009. case 'highlight.p': {
  17010. $opt['h'] = 'P';
  17011. break;
  17012. }
  17013. case 'outline':
  17014. case 'highlight.o': {
  17015. $opt['h'] = 'O';
  17016. break;
  17017. }
  17018. }
  17019. }
  17020. // Unsupported options:
  17021. // - calcOrderIndex: Changes the calculation order of fields in the document.
  17022. // - delay: Delays the redrawing of a field's appearance.
  17023. // - defaultStyle: This property defines the default style attributes for the form field.
  17024. // - style: Allows the user to set the glyph style of a check box or radio button.
  17025. // - textColor, textFont, textSize
  17026. return $opt;
  17027. }
  17028. /**
  17029. * Set default properties for form fields.
  17030. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  17031. * @public
  17032. * @author Nicola Asuni
  17033. * @since 4.8.000 (2009-09-06)
  17034. */
  17035. public function setFormDefaultProp($prop=array()) {
  17036. $this->default_form_prop = $prop;
  17037. }
  17038. /**
  17039. * Return the default properties for form fields.
  17040. * @return array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  17041. * @public
  17042. * @author Nicola Asuni
  17043. * @since 4.8.000 (2009-09-06)
  17044. */
  17045. public function getFormDefaultProp() {
  17046. return $this->default_form_prop;
  17047. }
  17048. /**
  17049. * Creates a text field
  17050. * @param $name (string) field name
  17051. * @param $w (float) Width of the rectangle
  17052. * @param $h (float) Height of the rectangle
  17053. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  17054. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  17055. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  17056. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  17057. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  17058. * @public
  17059. * @author Nicola Asuni
  17060. * @since 4.8.000 (2009-09-07)
  17061. */
  17062. public function TextField($name, $w, $h, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  17063. if ($x === '') {
  17064. $x = $this->x;
  17065. }
  17066. if ($y === '') {
  17067. $y = $this->y;
  17068. }
  17069. // check page for no-write regions and adapt page margins if necessary
  17070. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  17071. if ($js) {
  17072. $this->_addfield('text', $name, $x, $y, $w, $h, $prop);
  17073. return;
  17074. }
  17075. // get default style
  17076. $prop = array_merge($this->getFormDefaultProp(), $prop);
  17077. // get annotation data
  17078. $popt = $this->getAnnotOptFromJSProp($prop);
  17079. // set default appearance stream
  17080. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  17081. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  17082. $popt['da'] = $fontstyle;
  17083. // build appearance stream
  17084. $popt['ap'] = array();
  17085. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  17086. $text = '';
  17087. if (isset($prop['value']) AND !empty($prop['value'])) {
  17088. $text = $prop['value'];
  17089. } elseif (isset($opt['v']) AND !empty($opt['v'])) {
  17090. $text = $opt['v'];
  17091. }
  17092. $tmpid = $this->startTemplate($w, $h, false);
  17093. $align = '';
  17094. if (isset($popt['q'])) {
  17095. switch ($popt['q']) {
  17096. case 0: {
  17097. $align = 'L';
  17098. break;
  17099. }
  17100. case 1: {
  17101. $align = 'C';
  17102. break;
  17103. }
  17104. case 2: {
  17105. $align = 'R';
  17106. break;
  17107. }
  17108. default: {
  17109. $align = '';
  17110. break;
  17111. }
  17112. }
  17113. }
  17114. $this->MultiCell($w, $h, $text, 0, $align, false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  17115. $this->endTemplate();
  17116. --$this->n;
  17117. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  17118. unset($this->xobjects[$tmpid]);
  17119. $popt['ap']['n'] .= 'Q EMC';
  17120. // merge options
  17121. $opt = array_merge($popt, $opt);
  17122. // remove some conflicting options
  17123. unset($opt['bs']);
  17124. // set remaining annotation data
  17125. $opt['Subtype'] = 'Widget';
  17126. $opt['ft'] = 'Tx';
  17127. $opt['t'] = $name;
  17128. // Additional annotation's parameters (check _putannotsobj() method):
  17129. //$opt['f']
  17130. //$opt['as']
  17131. //$opt['bs']
  17132. //$opt['be']
  17133. //$opt['c']
  17134. //$opt['border']
  17135. //$opt['h']
  17136. //$opt['mk'];
  17137. //$opt['mk']['r']
  17138. //$opt['mk']['bc'];
  17139. //$opt['mk']['bg'];
  17140. unset($opt['mk']['ca']);
  17141. unset($opt['mk']['rc']);
  17142. unset($opt['mk']['ac']);
  17143. unset($opt['mk']['i']);
  17144. unset($opt['mk']['ri']);
  17145. unset($opt['mk']['ix']);
  17146. unset($opt['mk']['if']);
  17147. //$opt['mk']['if']['sw'];
  17148. //$opt['mk']['if']['s'];
  17149. //$opt['mk']['if']['a'];
  17150. //$opt['mk']['if']['fb'];
  17151. unset($opt['mk']['tp']);
  17152. //$opt['tu']
  17153. //$opt['tm']
  17154. //$opt['ff']
  17155. //$opt['v']
  17156. //$opt['dv']
  17157. //$opt['a']
  17158. //$opt['aa']
  17159. //$opt['q']
  17160. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  17161. if ($this->rtl) {
  17162. $this->x -= $w;
  17163. } else {
  17164. $this->x += $w;
  17165. }
  17166. }
  17167. /**
  17168. * Creates a RadioButton field.
  17169. * @param $name (string) Field name.
  17170. * @param $w (int) Width of the radio button.
  17171. * @param $prop (array) Javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  17172. * @param $opt (array) Annotation parameters. Possible values are described on official PDF32000_2008 reference.
  17173. * @param $onvalue (string) Value to be returned if selected.
  17174. * @param $checked (boolean) Define the initial state.
  17175. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  17176. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  17177. * @param $js (boolean) If true put the field using JavaScript (requires Acrobat Writer to be rendered).
  17178. * @public
  17179. * @author Nicola Asuni
  17180. * @since 4.8.000 (2009-09-07)
  17181. */
  17182. public function RadioButton($name, $w, $prop=array(), $opt=array(), $onvalue='On', $checked=false, $x='', $y='', $js=false) {
  17183. if ($x === '') {
  17184. $x = $this->x;
  17185. }
  17186. if ($y === '') {
  17187. $y = $this->y;
  17188. }
  17189. // check page for no-write regions and adapt page margins if necessary
  17190. list($x, $y) = $this->checkPageRegions($w, $x, $y);
  17191. if ($js) {
  17192. $this->_addfield('radiobutton', $name, $x, $y, $w, $w, $prop);
  17193. return;
  17194. }
  17195. if ($this->empty_string($onvalue)) {
  17196. $onvalue = 'On';
  17197. }
  17198. if ($checked) {
  17199. $defval = $onvalue;
  17200. } else {
  17201. $defval = 'Off';
  17202. }
  17203. // set font
  17204. $font = 'zapfdingbats';
  17205. if ($this->pdfa_mode) {
  17206. // all fonts must be embedded
  17207. $font = 'pdfa'.$font;
  17208. }
  17209. $this->AddFont($font);
  17210. $tmpfont = $this->getFontBuffer($font);
  17211. // set data for parent group
  17212. if (!isset($this->radiobutton_groups[$this->page])) {
  17213. $this->radiobutton_groups[$this->page] = array();
  17214. }
  17215. if (!isset($this->radiobutton_groups[$this->page][$name])) {
  17216. $this->radiobutton_groups[$this->page][$name] = array();
  17217. ++$this->n;
  17218. $this->radiobutton_groups[$this->page][$name]['n'] = $this->n;
  17219. $this->radio_groups[] = $this->n;
  17220. }
  17221. $kid = ($this->n + 1);
  17222. // save object ID to be added on Kids entry on parent object
  17223. $this->radiobutton_groups[$this->page][$name][] = array('kid' => $kid, 'def' => $defval);
  17224. // get default style
  17225. $prop = array_merge($this->getFormDefaultProp(), $prop);
  17226. $prop['NoToggleToOff'] = 'true';
  17227. $prop['Radio'] = 'true';
  17228. $prop['borderStyle'] = 'inset';
  17229. // get annotation data
  17230. $popt = $this->getAnnotOptFromJSProp($prop);
  17231. // set additional default options
  17232. $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  17233. $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
  17234. $popt['da'] = $fontstyle;
  17235. // build appearance stream
  17236. $popt['ap'] = array();
  17237. $popt['ap']['n'] = array();
  17238. $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][108])) / 2) * $this->k);
  17239. $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k);
  17240. $popt['ap']['n'][$onvalue] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(108).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, $fx, $fy);
  17241. $popt['ap']['n']['Off'] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(109).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, $fx, $fy);
  17242. if (!isset($popt['mk'])) {
  17243. $popt['mk'] = array();
  17244. }
  17245. $popt['mk']['ca'] = '(l)';
  17246. // merge options
  17247. $opt = array_merge($popt, $opt);
  17248. // set remaining annotation data
  17249. $opt['Subtype'] = 'Widget';
  17250. $opt['ft'] = 'Btn';
  17251. if ($checked) {
  17252. $opt['v'] = array('/'.$onvalue);
  17253. $opt['as'] = $onvalue;
  17254. } else {
  17255. $opt['as'] = 'Off';
  17256. }
  17257. // store readonly flag
  17258. if (!isset($this->radiobutton_groups[$this->page][$name]['#readonly#'])) {
  17259. $this->radiobutton_groups[$this->page][$name]['#readonly#'] = false;
  17260. }
  17261. $this->radiobutton_groups[$this->page][$name]['#readonly#'] |= ($opt['f'] & 64);
  17262. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  17263. if ($this->rtl) {
  17264. $this->x -= $w;
  17265. } else {
  17266. $this->x += $w;
  17267. }
  17268. }
  17269. /**
  17270. * Creates a List-box field
  17271. * @param $name (string) field name
  17272. * @param $w (int) width
  17273. * @param $h (int) height
  17274. * @param $values (array) array containing the list of values.
  17275. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  17276. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  17277. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  17278. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  17279. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  17280. * @public
  17281. * @author Nicola Asuni
  17282. * @since 4.8.000 (2009-09-07)
  17283. */
  17284. public function ListBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  17285. if ($x === '') {
  17286. $x = $this->x;
  17287. }
  17288. if ($y === '') {
  17289. $y = $this->y;
  17290. }
  17291. // check page for no-write regions and adapt page margins if necessary
  17292. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  17293. if ($js) {
  17294. $this->_addfield('listbox', $name, $x, $y, $w, $h, $prop);
  17295. $s = '';
  17296. foreach ($values as $value) {
  17297. if (is_array($value)) {
  17298. $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
  17299. } else {
  17300. $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
  17301. }
  17302. }
  17303. $this->javascript .= 'f'.$name.'.setItems('.substr($s, 1).');'."\n";
  17304. return;
  17305. }
  17306. // get default style
  17307. $prop = array_merge($this->getFormDefaultProp(), $prop);
  17308. // get annotation data
  17309. $popt = $this->getAnnotOptFromJSProp($prop);
  17310. // set additional default values
  17311. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  17312. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  17313. $popt['da'] = $fontstyle;
  17314. // build appearance stream
  17315. $popt['ap'] = array();
  17316. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  17317. $text = '';
  17318. foreach($values as $item) {
  17319. if (is_array($item)) {
  17320. $text .= $item[1]."\n";
  17321. } else {
  17322. $text .= $item."\n";
  17323. }
  17324. }
  17325. $tmpid = $this->startTemplate($w, $h, false);
  17326. $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  17327. $this->endTemplate();
  17328. --$this->n;
  17329. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  17330. unset($this->xobjects[$tmpid]);
  17331. $popt['ap']['n'] .= 'Q EMC';
  17332. // merge options
  17333. $opt = array_merge($popt, $opt);
  17334. // set remaining annotation data
  17335. $opt['Subtype'] = 'Widget';
  17336. $opt['ft'] = 'Ch';
  17337. $opt['t'] = $name;
  17338. $opt['opt'] = $values;
  17339. unset($opt['mk']['ca']);
  17340. unset($opt['mk']['rc']);
  17341. unset($opt['mk']['ac']);
  17342. unset($opt['mk']['i']);
  17343. unset($opt['mk']['ri']);
  17344. unset($opt['mk']['ix']);
  17345. unset($opt['mk']['if']);
  17346. unset($opt['mk']['tp']);
  17347. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  17348. if ($this->rtl) {
  17349. $this->x -= $w;
  17350. } else {
  17351. $this->x += $w;
  17352. }
  17353. }
  17354. /**
  17355. * Creates a Combo-box field
  17356. * @param $name (string) field name
  17357. * @param $w (int) width
  17358. * @param $h (int) height
  17359. * @param $values (array) array containing the list of values.
  17360. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  17361. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  17362. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  17363. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  17364. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  17365. * @public
  17366. * @author Nicola Asuni
  17367. * @since 4.8.000 (2009-09-07)
  17368. */
  17369. public function ComboBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  17370. if ($x === '') {
  17371. $x = $this->x;
  17372. }
  17373. if ($y === '') {
  17374. $y = $this->y;
  17375. }
  17376. // check page for no-write regions and adapt page margins if necessary
  17377. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  17378. if ($js) {
  17379. $this->_addfield('combobox', $name, $x, $y, $w, $h, $prop);
  17380. $s = '';
  17381. foreach ($values as $value) {
  17382. if (is_array($value)) {
  17383. $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
  17384. } else {
  17385. $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
  17386. }
  17387. }
  17388. $this->javascript .= 'f'.$name.'.setItems('.substr($s, 1).');'."\n";
  17389. return;
  17390. }
  17391. // get default style
  17392. $prop = array_merge($this->getFormDefaultProp(), $prop);
  17393. $prop['Combo'] = true;
  17394. // get annotation data
  17395. $popt = $this->getAnnotOptFromJSProp($prop);
  17396. // set additional default options
  17397. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  17398. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  17399. $popt['da'] = $fontstyle;
  17400. // build appearance stream
  17401. $popt['ap'] = array();
  17402. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  17403. $text = '';
  17404. foreach($values as $item) {
  17405. if (is_array($item)) {
  17406. $text .= $item[1]."\n";
  17407. } else {
  17408. $text .= $item."\n";
  17409. }
  17410. }
  17411. $tmpid = $this->startTemplate($w, $h, false);
  17412. $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  17413. $this->endTemplate();
  17414. --$this->n;
  17415. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  17416. unset($this->xobjects[$tmpid]);
  17417. $popt['ap']['n'] .= 'Q EMC';
  17418. // merge options
  17419. $opt = array_merge($popt, $opt);
  17420. // set remaining annotation data
  17421. $opt['Subtype'] = 'Widget';
  17422. $opt['ft'] = 'Ch';
  17423. $opt['t'] = $name;
  17424. $opt['opt'] = $values;
  17425. unset($opt['mk']['ca']);
  17426. unset($opt['mk']['rc']);
  17427. unset($opt['mk']['ac']);
  17428. unset($opt['mk']['i']);
  17429. unset($opt['mk']['ri']);
  17430. unset($opt['mk']['ix']);
  17431. unset($opt['mk']['if']);
  17432. unset($opt['mk']['tp']);
  17433. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  17434. if ($this->rtl) {
  17435. $this->x -= $w;
  17436. } else {
  17437. $this->x += $w;
  17438. }
  17439. }
  17440. /**
  17441. * Creates a CheckBox field
  17442. * @param $name (string) field name
  17443. * @param $w (int) width
  17444. * @param $checked (boolean) define the initial state.
  17445. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  17446. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  17447. * @param $onvalue (string) value to be returned if selected.
  17448. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  17449. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  17450. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  17451. * @public
  17452. * @author Nicola Asuni
  17453. * @since 4.8.000 (2009-09-07)
  17454. */
  17455. public function CheckBox($name, $w, $checked=false, $prop=array(), $opt=array(), $onvalue='Yes', $x='', $y='', $js=false) {
  17456. if ($x === '') {
  17457. $x = $this->x;
  17458. }
  17459. if ($y === '') {
  17460. $y = $this->y;
  17461. }
  17462. // check page for no-write regions and adapt page margins if necessary
  17463. list($x, $y) = $this->checkPageRegions($w, $x, $y);
  17464. if ($js) {
  17465. $this->_addfield('checkbox', $name, $x, $y, $w, $w, $prop);
  17466. return;
  17467. }
  17468. if (!isset($prop['value'])) {
  17469. $prop['value'] = array('Yes');
  17470. }
  17471. // get default style
  17472. $prop = array_merge($this->getFormDefaultProp(), $prop);
  17473. $prop['borderStyle'] = 'inset';
  17474. // get annotation data
  17475. $popt = $this->getAnnotOptFromJSProp($prop);
  17476. // set additional default options
  17477. $font = 'zapfdingbats';
  17478. if ($this->pdfa_mode) {
  17479. // all fonts must be embedded
  17480. $font = 'pdfa'.$font;
  17481. }
  17482. $this->AddFont($font);
  17483. $tmpfont = $this->getFontBuffer($font);
  17484. $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  17485. $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
  17486. $popt['da'] = $fontstyle;
  17487. // build appearance stream
  17488. $popt['ap'] = array();
  17489. $popt['ap']['n'] = array();
  17490. $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][110])) / 2) * $this->k);
  17491. $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k);
  17492. $popt['ap']['n']['Yes'] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(110).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, $fx, $fy);
  17493. $popt['ap']['n']['Off'] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(111).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, $fx, $fy);
  17494. // merge options
  17495. $opt = array_merge($popt, $opt);
  17496. // set remaining annotation data
  17497. $opt['Subtype'] = 'Widget';
  17498. $opt['ft'] = 'Btn';
  17499. $opt['t'] = $name;
  17500. if ($this->empty_string($onvalue)) {
  17501. $onvalue = 'Yes';
  17502. }
  17503. $opt['opt'] = array($onvalue);
  17504. if ($checked) {
  17505. $opt['v'] = array('/Yes');
  17506. $opt['as'] = 'Yes';
  17507. } else {
  17508. $opt['v'] = array('/Off');
  17509. $opt['as'] = 'Off';
  17510. }
  17511. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  17512. if ($this->rtl) {
  17513. $this->x -= $w;
  17514. } else {
  17515. $this->x += $w;
  17516. }
  17517. }
  17518. /**
  17519. * Creates a button field
  17520. * @param $name (string) field name
  17521. * @param $w (int) width
  17522. * @param $h (int) height
  17523. * @param $caption (string) caption.
  17524. * @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.
  17525. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  17526. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  17527. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  17528. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  17529. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  17530. * @public
  17531. * @author Nicola Asuni
  17532. * @since 4.8.000 (2009-09-07)
  17533. */
  17534. public function Button($name, $w, $h, $caption, $action, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  17535. if ($x === '') {
  17536. $x = $this->x;
  17537. }
  17538. if ($y === '') {
  17539. $y = $this->y;
  17540. }
  17541. // check page for no-write regions and adapt page margins if necessary
  17542. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  17543. if ($js) {
  17544. $this->_addfield('button', $name, $this->x, $this->y, $w, $h, $prop);
  17545. $this->javascript .= 'f'.$name.".buttonSetCaption('".addslashes($caption)."');\n";
  17546. $this->javascript .= 'f'.$name.".setAction('MouseUp','".addslashes($action)."');\n";
  17547. $this->javascript .= 'f'.$name.".highlight='push';\n";
  17548. $this->javascript .= 'f'.$name.".print=false;\n";
  17549. return;
  17550. }
  17551. // get default style
  17552. $prop = array_merge($this->getFormDefaultProp(), $prop);
  17553. $prop['Pushbutton'] = 'true';
  17554. $prop['highlight'] = 'push';
  17555. $prop['display'] = 'display.noPrint';
  17556. // get annotation data
  17557. $popt = $this->getAnnotOptFromJSProp($prop);
  17558. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  17559. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  17560. $popt['da'] = $fontstyle;
  17561. // build appearance stream
  17562. $popt['ap'] = array();
  17563. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  17564. $tmpid = $this->startTemplate($w, $h, false);
  17565. $bw = (2 / $this->k); // border width
  17566. $border = array(
  17567. 'L' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
  17568. 'R' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)),
  17569. 'T' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
  17570. 'B' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)));
  17571. $this->SetFillColor(204);
  17572. $this->Cell($w, $h, $caption, $border, 0, 'C', true, '', 1, false, 'T', 'M');
  17573. $this->endTemplate();
  17574. --$this->n;
  17575. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  17576. unset($this->xobjects[$tmpid]);
  17577. $popt['ap']['n'] .= 'Q EMC';
  17578. // set additional default options
  17579. if (!isset($popt['mk'])) {
  17580. $popt['mk'] = array();
  17581. }
  17582. $ann_obj_id = ($this->n + 1);
  17583. if (!empty($action) AND !is_array($action)) {
  17584. $ann_obj_id = ($this->n + 2);
  17585. }
  17586. $popt['mk']['ca'] = $this->_textstring($caption, $ann_obj_id);
  17587. $popt['mk']['rc'] = $this->_textstring($caption, $ann_obj_id);
  17588. $popt['mk']['ac'] = $this->_textstring($caption, $ann_obj_id);
  17589. // merge options
  17590. $opt = array_merge($popt, $opt);
  17591. // set remaining annotation data
  17592. $opt['Subtype'] = 'Widget';
  17593. $opt['ft'] = 'Btn';
  17594. $opt['t'] = $caption;
  17595. $opt['v'] = $name;
  17596. if (!empty($action)) {
  17597. if (is_array($action)) {
  17598. // form action options as on section 12.7.5 of PDF32000_2008.
  17599. $opt['aa'] = '/D <<';
  17600. $bmode = array('SubmitForm', 'ResetForm', 'ImportData');
  17601. foreach ($action AS $key => $val) {
  17602. if (($key == 'S') AND in_array($val, $bmode)) {
  17603. $opt['aa'] .= ' /S /'.$val;
  17604. } elseif (($key == 'F') AND (!empty($val))) {
  17605. $opt['aa'] .= ' /F '.$this->_datastring($val, $ann_obj_id);
  17606. } elseif (($key == 'Fields') AND is_array($val) AND !empty($val)) {
  17607. $opt['aa'] .= ' /Fields [';
  17608. foreach ($val AS $field) {
  17609. $opt['aa'] .= ' '.$this->_textstring($field, $ann_obj_id);
  17610. }
  17611. $opt['aa'] .= ']';
  17612. } elseif (($key == 'Flags')) {
  17613. $ff = 0;
  17614. if (is_array($val)) {
  17615. foreach ($val AS $flag) {
  17616. switch ($flag) {
  17617. case 'Include/Exclude': {
  17618. $ff += 1 << 0;
  17619. break;
  17620. }
  17621. case 'IncludeNoValueFields': {
  17622. $ff += 1 << 1;
  17623. break;
  17624. }
  17625. case 'ExportFormat': {
  17626. $ff += 1 << 2;
  17627. break;
  17628. }
  17629. case 'GetMethod': {
  17630. $ff += 1 << 3;
  17631. break;
  17632. }
  17633. case 'SubmitCoordinates': {
  17634. $ff += 1 << 4;
  17635. break;
  17636. }
  17637. case 'XFDF': {
  17638. $ff += 1 << 5;
  17639. break;
  17640. }
  17641. case 'IncludeAppendSaves': {
  17642. $ff += 1 << 6;
  17643. break;
  17644. }
  17645. case 'IncludeAnnotations': {
  17646. $ff += 1 << 7;
  17647. break;
  17648. }
  17649. case 'SubmitPDF': {
  17650. $ff += 1 << 8;
  17651. break;
  17652. }
  17653. case 'CanonicalFormat': {
  17654. $ff += 1 << 9;
  17655. break;
  17656. }
  17657. case 'ExclNonUserAnnots': {
  17658. $ff += 1 << 10;
  17659. break;
  17660. }
  17661. case 'ExclFKey': {
  17662. $ff += 1 << 11;
  17663. break;
  17664. }
  17665. case 'EmbedForm': {
  17666. $ff += 1 << 13;
  17667. break;
  17668. }
  17669. }
  17670. }
  17671. } else {
  17672. $ff = intval($val);
  17673. }
  17674. $opt['aa'] .= ' /Flags '.$ff;
  17675. }
  17676. }
  17677. $opt['aa'] .= ' >>';
  17678. } else {
  17679. // Javascript action or raw action command
  17680. $js_obj_id = $this->addJavascriptObject($action);
  17681. $opt['aa'] = '/D '.$js_obj_id.' 0 R';
  17682. }
  17683. }
  17684. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  17685. if ($this->rtl) {
  17686. $this->x -= $w;
  17687. } else {
  17688. $this->x += $w;
  17689. }
  17690. }
  17691. // --- END FORMS FIELDS ------------------------------------------------
  17692. /**
  17693. * Add certification signature (DocMDP or UR3)
  17694. * You can set only one signature type
  17695. * @protected
  17696. * @author Nicola Asuni
  17697. * @since 4.6.008 (2009-05-07)
  17698. */
  17699. protected function _putsignature() {
  17700. if ((!$this->sign) OR (!isset($this->signature_data['cert_type']))) {
  17701. return;
  17702. }
  17703. $sigobjid = ($this->sig_obj_id + 1);
  17704. $out = $this->_getobj($sigobjid)."\n";
  17705. $out .= '<< /Type /Sig';
  17706. $out .= ' /Filter /Adobe.PPKLite';
  17707. $out .= ' /SubFilter /adbe.pkcs7.detached';
  17708. $out .= ' '.$this->byterange_string;
  17709. $out .= ' /Contents<'.str_repeat('0', $this->signature_max_length).'>';
  17710. $out .= ' /Reference ['; // array of signature reference dictionaries
  17711. $out .= ' << /Type /SigRef';
  17712. if ($this->signature_data['cert_type'] > 0) {
  17713. $out .= ' /TransformMethod /DocMDP';
  17714. $out .= ' /TransformParams <<';
  17715. $out .= ' /Type /TransformParams';
  17716. $out .= ' /P '.$this->signature_data['cert_type'];
  17717. $out .= ' /V /1.2';
  17718. } else {
  17719. $out .= ' /TransformMethod /UR3';
  17720. $out .= ' /TransformParams <<';
  17721. $out .= ' /Type /TransformParams';
  17722. $out .= ' /V /2.2';
  17723. if (!$this->empty_string($this->ur['document'])) {
  17724. $out .= ' /Document['.$this->ur['document'].']';
  17725. }
  17726. if (!$this->empty_string($this->ur['form'])) {
  17727. $out .= ' /Form['.$this->ur['form'].']';
  17728. }
  17729. if (!$this->empty_string($this->ur['signature'])) {
  17730. $out .= ' /Signature['.$this->ur['signature'].']';
  17731. }
  17732. if (!$this->empty_string($this->ur['annots'])) {
  17733. $out .= ' /Annots['.$this->ur['annots'].']';
  17734. }
  17735. if (!$this->empty_string($this->ur['ef'])) {
  17736. $out .= ' /EF['.$this->ur['ef'].']';
  17737. }
  17738. if (!$this->empty_string($this->ur['formex'])) {
  17739. $out .= ' /FormEX['.$this->ur['formex'].']';
  17740. }
  17741. }
  17742. $out .= ' >>'; // close TransformParams
  17743. // optional digest data (values must be calculated and replaced later)
  17744. //$out .= ' /Data ********** 0 R';
  17745. //$out .= ' /DigestMethod/MD5';
  17746. //$out .= ' /DigestLocation[********** 34]';
  17747. //$out .= ' /DigestValue<********************************>';
  17748. $out .= ' >>';
  17749. $out .= ' ]'; // end of reference
  17750. if (isset($this->signature_data['info']['Name']) AND !$this->empty_string($this->signature_data['info']['Name'])) {
  17751. $out .= ' /Name '.$this->_textstring($this->signature_data['info']['Name'], $sigobjid);
  17752. }
  17753. if (isset($this->signature_data['info']['Location']) AND !$this->empty_string($this->signature_data['info']['Location'])) {
  17754. $out .= ' /Location '.$this->_textstring($this->signature_data['info']['Location'], $sigobjid);
  17755. }
  17756. if (isset($this->signature_data['info']['Reason']) AND !$this->empty_string($this->signature_data['info']['Reason'])) {
  17757. $out .= ' /Reason '.$this->_textstring($this->signature_data['info']['Reason'], $sigobjid);
  17758. }
  17759. if (isset($this->signature_data['info']['ContactInfo']) AND !$this->empty_string($this->signature_data['info']['ContactInfo'])) {
  17760. $out .= ' /ContactInfo '.$this->_textstring($this->signature_data['info']['ContactInfo'], $sigobjid);
  17761. }
  17762. $out .= ' /M '.$this->_datestring($sigobjid, $this->doc_modification_timestamp);
  17763. $out .= ' >>';
  17764. $out .= "\n".'endobj';
  17765. $this->_out($out);
  17766. }
  17767. /**
  17768. * Set User's Rights for PDF Reader
  17769. * WARNING: This is experimental and currently do not work.
  17770. * Check the PDF Reference 8.7.1 Transform Methods,
  17771. * Table 8.105 Entries in the UR transform parameters dictionary
  17772. * @param $enable (boolean) if true enable user's rights on PDF reader
  17773. * @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.
  17774. * @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.
  17775. * @param $form (string) Names specifying additional form-field-related usage rights for the document. Valid names are: /Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate
  17776. * @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.
  17777. * @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
  17778. Names specifying additional embedded-files-related usage rights for the document.
  17779. * @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.
  17780. * @public
  17781. * @author Nicola Asuni
  17782. * @since 2.9.000 (2008-03-26)
  17783. */
  17784. public function setUserRights(
  17785. $enable=true,
  17786. $document='/FullSave',
  17787. $annots='/Create/Delete/Modify/Copy/Import/Export',
  17788. $form='/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate',
  17789. $signature='/Modify',
  17790. $ef='/Create/Delete/Modify/Import',
  17791. $formex='') {
  17792. $this->ur['enabled'] = $enable;
  17793. $this->ur['document'] = $document;
  17794. $this->ur['annots'] = $annots;
  17795. $this->ur['form'] = $form;
  17796. $this->ur['signature'] = $signature;
  17797. $this->ur['ef'] = $ef;
  17798. $this->ur['formex'] = $formex;
  17799. if (!$this->sign) {
  17800. $this->setSignature('', '', '', '', 0, array());
  17801. }
  17802. }
  17803. /**
  17804. * Enable document signature (requires the OpenSSL Library).
  17805. * The digital signature improve document authenticity and integrity and allows o enable extra features on Acrobat Reader.
  17806. * To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  17807. * To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  17808. * To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
  17809. * @param $signing_cert (mixed) signing certificate (string or filename prefixed with 'file://')
  17810. * @param $private_key (mixed) private key (string or filename prefixed with 'file://')
  17811. * @param $private_key_password (string) password
  17812. * @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.
  17813. * @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.
  17814. * @param $info (array) array of option information: Name, Location, Reason, ContactInfo.
  17815. * @public
  17816. * @author Nicola Asuni
  17817. * @since 4.6.005 (2009-04-24)
  17818. */
  17819. public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array()) {
  17820. // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  17821. // to export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  17822. // to convert pfx certificate to pem: openssl
  17823. // OpenSSL> pkcs12 -in <cert.pfx> -out <cert.crt> -nodes
  17824. $this->sign = true;
  17825. ++$this->n;
  17826. $this->sig_obj_id = $this->n; // signature widget
  17827. ++$this->n; // signature object ($this->sig_obj_id + 1)
  17828. $this->signature_data = array();
  17829. if (strlen($signing_cert) == 0) {
  17830. $signing_cert = 'file://'.dirname(__FILE__).'/tcpdf.crt';
  17831. $private_key_password = 'tcpdfdemo';
  17832. }
  17833. if (strlen($private_key) == 0) {
  17834. $private_key = $signing_cert;
  17835. }
  17836. $this->signature_data['signcert'] = $signing_cert;
  17837. $this->signature_data['privkey'] = $private_key;
  17838. $this->signature_data['password'] = $private_key_password;
  17839. $this->signature_data['extracerts'] = $extracerts;
  17840. $this->signature_data['cert_type'] = $cert_type;
  17841. $this->signature_data['info'] = $info;
  17842. }
  17843. /**
  17844. * Set the digital signature appearance (a cliccable rectangle area to get signature properties)
  17845. * @param $x (float) Abscissa of the upper-left corner.
  17846. * @param $y (float) Ordinate of the upper-left corner.
  17847. * @param $w (float) Width of the signature area.
  17848. * @param $h (float) Height of the signature area.
  17849. * @param $page (int) option page number (if < 0 the current page is used).
  17850. * @public
  17851. * @author Nicola Asuni
  17852. * @since 5.3.011 (2010-06-17)
  17853. */
  17854. public function setSignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1) {
  17855. $this->signature_appearance = $this->getSignatureAppearanceArray($x, $y, $w, $h, $page);
  17856. }
  17857. /**
  17858. * Add an empty digital signature appearance (a cliccable rectangle area to get signature properties)
  17859. * @param $x (float) Abscissa of the upper-left corner.
  17860. * @param $y (float) Ordinate of the upper-left corner.
  17861. * @param $w (float) Width of the signature area.
  17862. * @param $h (float) Height of the signature area.
  17863. * @param $page (int) option page number (if < 0 the current page is used).
  17864. * @public
  17865. * @author Nicola Asuni
  17866. * @since 5.9.101 (2011-07-06)
  17867. */
  17868. public function addEmptySignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1) {
  17869. ++$this->n;
  17870. $this->empty_signature_appearance[] = array('objid' => $this->n) + $this->getSignatureAppearanceArray($x, $y, $w, $h, $page);
  17871. }
  17872. /**
  17873. * Get the array that defines the signature appearance (page and rectangle coordinates).
  17874. * @param $x (float) Abscissa of the upper-left corner.
  17875. * @param $y (float) Ordinate of the upper-left corner.
  17876. * @param $w (float) Width of the signature area.
  17877. * @param $h (float) Height of the signature area.
  17878. * @param $page (int) option page number (if < 0 the current page is used).
  17879. * @return (array) Array defining page and rectangle coordinates of signature appearance.
  17880. * @protected
  17881. * @author Nicola Asuni
  17882. * @since 5.9.101 (2011-07-06)
  17883. */
  17884. protected function getSignatureAppearanceArray($x=0, $y=0, $w=0, $h=0, $page=-1) {
  17885. $sigapp = array();
  17886. if (($page < 1) OR ($page > $this->numpages)) {
  17887. $sigapp['page'] = $this->page;
  17888. } else {
  17889. $sigapp['page'] = intval($page);
  17890. }
  17891. $a = $x * $this->k;
  17892. $b = $this->pagedim[($sigapp['page'])]['h'] - (($y + $h) * $this->k);
  17893. $c = $w * $this->k;
  17894. $d = $h * $this->k;
  17895. $sigapp['rect'] = sprintf('%F %F %F %F', $a, $b, ($a + $c), ($b + $d));
  17896. return $sigapp;
  17897. }
  17898. /**
  17899. * Create a new page group.
  17900. * NOTE: call this function before calling AddPage()
  17901. * @param $page (int) starting group page (leave empty for next page).
  17902. * @public
  17903. * @since 3.0.000 (2008-03-27)
  17904. */
  17905. public function startPageGroup($page='') {
  17906. if (empty($page)) {
  17907. $page = $this->page + 1;
  17908. }
  17909. $this->newpagegroup[$page] = sizeof($this->newpagegroup) + 1;
  17910. }
  17911. /**
  17912. * This method is DEPRECATED and doesn't have any effect.
  17913. * Please remove any reference to this method.
  17914. * @param $s (string) Empty parameter.
  17915. * @deprecated deprecated since version 5.9.089 (2011-06-13)
  17916. * @public
  17917. */
  17918. public function AliasNbPages($s='') {}
  17919. /**
  17920. * This method is DEPRECATED and doesn't have any effect.
  17921. * Please remove any reference to this method.
  17922. * @param $s (string) Empty parameter.
  17923. * @deprecated deprecated since version 5.9.089 (2011-06-13)
  17924. * @public
  17925. */
  17926. public function AliasNumPage($s='') {}
  17927. /**
  17928. * Set the starting page number.
  17929. * @param $num (int) Starting page number.
  17930. * @since 5.9.093 (2011-06-16)
  17931. * @public
  17932. */
  17933. public function setStartingPageNumber($num=1) {
  17934. $this->starting_page_number = max(0, intval($num));
  17935. }
  17936. /**
  17937. * Returns the string alias used right align page numbers.
  17938. * If the current font is unicode type, the returned string wil contain an additional open curly brace.
  17939. * @return string
  17940. * @since 5.9.099 (2011-06-27)
  17941. * @public
  17942. */
  17943. public function getAliasRightShift() {
  17944. // calculate aproximatively the ratio between widths of aliases and replacements.
  17945. $ref = '{'.$this->alias_right_shift.'}{'.$this->alias_tot_pages.'}{'.$this->alias_num_page.'}';
  17946. $rep = str_repeat(' ', $this->GetNumChars($ref));
  17947. $wdiff = max(1, ($this->GetStringWidth($ref) / $this->GetStringWidth($rep)));
  17948. $sdiff = sprintf('%F', $wdiff);
  17949. $alias = $this->alias_right_shift.$sdiff.'}';
  17950. if ($this->isUnicodeFont()) {
  17951. $alias = '{'.$alias;
  17952. }
  17953. return $alias;
  17954. }
  17955. /**
  17956. * Returns the string alias used for the total number of pages.
  17957. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  17958. * This alias will be replaced by the total number of pages in the document.
  17959. * @return string
  17960. * @since 4.0.018 (2008-08-08)
  17961. * @public
  17962. */
  17963. public function getAliasNbPages() {
  17964. if ($this->isUnicodeFont()) {
  17965. return '{'.$this->alias_tot_pages.'}';
  17966. }
  17967. return $this->alias_tot_pages;
  17968. }
  17969. /**
  17970. * Returns the string alias used for the page number.
  17971. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  17972. * This alias will be replaced by the page number.
  17973. * @return string
  17974. * @since 4.5.000 (2009-01-02)
  17975. * @public
  17976. */
  17977. public function getAliasNumPage() {
  17978. if ($this->isUnicodeFont()) {
  17979. return '{'.$this->alias_num_page.'}';
  17980. }
  17981. return $this->alias_num_page;
  17982. }
  17983. /**
  17984. * Return the alias for the total number of pages in the current page group.
  17985. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  17986. * This alias will be replaced by the total number of pages in this group.
  17987. * @return alias of the current page group
  17988. * @public
  17989. * @since 3.0.000 (2008-03-27)
  17990. */
  17991. public function getPageGroupAlias() {
  17992. if ($this->isUnicodeFont()) {
  17993. return '{'.$this->alias_group_tot_pages.'}';
  17994. }
  17995. return $this->alias_group_tot_pages;
  17996. }
  17997. /**
  17998. * Return the alias for the page number on the current page group.
  17999. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  18000. * This alias will be replaced by the page number (relative to the belonging group).
  18001. * @return alias of the current page group
  18002. * @public
  18003. * @since 4.5.000 (2009-01-02)
  18004. */
  18005. public function getPageNumGroupAlias() {
  18006. if ($this->isUnicodeFont()) {
  18007. return '{'.$this->alias_group_num_page.'}';
  18008. }
  18009. return $this->alias_group_num_page;
  18010. }
  18011. /**
  18012. * Return the current page in the group.
  18013. * @return current page in the group
  18014. * @public
  18015. * @since 3.0.000 (2008-03-27)
  18016. */
  18017. public function getGroupPageNo() {
  18018. return $this->pagegroups[$this->currpagegroup];
  18019. }
  18020. /**
  18021. * Returns the current group page number formatted as a string.
  18022. * @public
  18023. * @since 4.3.003 (2008-11-18)
  18024. * @see PaneNo(), formatPageNumber()
  18025. */
  18026. public function getGroupPageNoFormatted() {
  18027. return $this->formatPageNumber($this->getGroupPageNo());
  18028. }
  18029. /**
  18030. * Format the page numbers.
  18031. * This method can be overriden for custom formats.
  18032. * @param $num (int) page number
  18033. * @protected
  18034. * @since 4.2.005 (2008-11-06)
  18035. */
  18036. protected function formatPageNumber($num) {
  18037. return number_format((float)$num, 0, '', '.');
  18038. }
  18039. /**
  18040. * Format the page numbers on the Table Of Content.
  18041. * This method can be overriden for custom formats.
  18042. * @param $num (int) page number
  18043. * @protected
  18044. * @since 4.5.001 (2009-01-04)
  18045. * @see addTOC(), addHTMLTOC()
  18046. */
  18047. protected function formatTOCPageNumber($num) {
  18048. return number_format((float)$num, 0, '', '.');
  18049. }
  18050. /**
  18051. * Returns the current page number formatted as a string.
  18052. * @public
  18053. * @since 4.2.005 (2008-11-06)
  18054. * @see PaneNo(), formatPageNumber()
  18055. */
  18056. public function PageNoFormatted() {
  18057. return $this->formatPageNumber($this->PageNo());
  18058. }
  18059. /**
  18060. * Put pdf layers.
  18061. * @protected
  18062. * @since 3.0.000 (2008-03-27)
  18063. */
  18064. protected function _putocg() {
  18065. if (empty($this->pdflayers)) {
  18066. return;
  18067. }
  18068. foreach ($this->pdflayers as $key => $layer) {
  18069. $this->pdflayers[$key]['objid'] = $this->_newobj();
  18070. $out = '<< /Type /OCG';
  18071. $out .= ' /Name '.$this->_textstring($layer['name'], $this->pdflayers[$key]['objid']);
  18072. $out .= ' /Usage <<';
  18073. $out .= ' /Print <</PrintState /'.($layer['print']?'ON':'OFF').'>>';
  18074. $out .= ' /View <</ViewState /'.($layer['view']?'ON':'OFF').'>>';
  18075. $out .= ' >> >>';
  18076. $out .= "\n".'endobj';
  18077. $this->_out($out);
  18078. }
  18079. }
  18080. /**
  18081. * Start a new pdf layer.
  18082. * @param $name (string) Layer name (only a-z letters and numbers). Leave empty for automatic name.
  18083. * @param $print (boolean) Set to true to print this layer.
  18084. * @param $view (boolean) Set to true to view this layer.
  18085. * @public
  18086. * @since 5.9.102 (2011-07-13)
  18087. */
  18088. public function startLayer($name='', $print=true, $view=true) {
  18089. if ($this->state != 2) {
  18090. return;
  18091. }
  18092. $layer = sprintf('LYR%03d', (count($this->pdflayers) + 1));
  18093. if (empty($name)) {
  18094. $name = $layer;
  18095. } else {
  18096. $name = preg_replace('/[^a-zA-Z0-9_\-]/', '', $name);
  18097. }
  18098. $this->pdflayers[] = array('layer' => $layer, 'name' => $name, 'print' => $print, 'view' => $view);
  18099. $this->openMarkedContent = true;
  18100. $this->_out('/OC /'.$layer.' BDC');
  18101. }
  18102. /**
  18103. * End the current PDF layer.
  18104. * @public
  18105. * @since 5.9.102 (2011-07-13)
  18106. */
  18107. public function endLayer() {
  18108. if ($this->state != 2) {
  18109. return;
  18110. }
  18111. if ($this->openMarkedContent) {
  18112. // close existing open marked-content layer
  18113. $this->_out('EMC');
  18114. $this->openMarkedContent = false;
  18115. }
  18116. }
  18117. /**
  18118. * Set the visibility of the successive elements.
  18119. * This can be useful, for instance, to put a background
  18120. * image or color that will show on screen but won't print.
  18121. * @param $v (string) visibility mode. Legal values are: all, print, screen or view.
  18122. * @public
  18123. * @since 3.0.000 (2008-03-27)
  18124. */
  18125. public function setVisibility($v) {
  18126. if ($this->state != 2) {
  18127. return;
  18128. }
  18129. $this->endLayer();
  18130. switch($v) {
  18131. case 'print': {
  18132. $this->startLayer('Print', true, false);
  18133. break;
  18134. }
  18135. case 'view':
  18136. case 'screen': {
  18137. $this->startLayer('View', false, true);
  18138. break;
  18139. }
  18140. case 'all': {
  18141. $this->_out('');
  18142. break;
  18143. }
  18144. default: {
  18145. $this->Error('Incorrect visibility: '.$v);
  18146. break;
  18147. }
  18148. }
  18149. }
  18150. /**
  18151. * Add transparency parameters to the current extgstate
  18152. * @param $parms (array) parameters
  18153. * @return the number of extgstates
  18154. * @protected
  18155. * @since 3.0.000 (2008-03-27)
  18156. */
  18157. protected function addExtGState($parms) {
  18158. if ($this->pdfa_mode) {
  18159. // transparencies are not allowed in PDF/A mode
  18160. return;
  18161. }
  18162. // check if this ExtGState already exist
  18163. foreach ($this->extgstates as $i => $ext) {
  18164. if ($ext['parms'] == $parms) {
  18165. if ($this->inxobj) {
  18166. // we are inside an XObject template
  18167. $this->xobjects[$this->xobjid]['extgstates'][$i] = $ext;
  18168. }
  18169. // return reference to existing ExtGState
  18170. return $i;
  18171. }
  18172. }
  18173. $n = (count($this->extgstates) + 1);
  18174. $this->extgstates[$n] = array('parms' => $parms);
  18175. if ($this->inxobj) {
  18176. // we are inside an XObject template
  18177. $this->xobjects[$this->xobjid]['extgstates'][$n] = $this->extgstates[$n];
  18178. }
  18179. return $n;
  18180. }
  18181. /**
  18182. * Add an extgstate
  18183. * @param $gs (array) extgstate
  18184. * @protected
  18185. * @since 3.0.000 (2008-03-27)
  18186. */
  18187. protected function setExtGState($gs) {
  18188. if ($this->pdfa_mode OR ($this->state != 2)) {
  18189. // transparency is not allowed in PDF/A mode
  18190. return;
  18191. }
  18192. $this->_out(sprintf('/GS%d gs', $gs));
  18193. }
  18194. /**
  18195. * Put extgstates for object transparency
  18196. * @protected
  18197. * @since 3.0.000 (2008-03-27)
  18198. */
  18199. protected function _putextgstates() {
  18200. foreach ($this->extgstates as $i => $ext) {
  18201. $this->extgstates[$i]['n'] = $this->_newobj();
  18202. $out = '<< /Type /ExtGState';
  18203. foreach ($ext['parms'] as $k => $v) {
  18204. if (is_float($v)) {
  18205. $v = sprintf('%F', $v);
  18206. } elseif ($v === true) {
  18207. $v = 'true';
  18208. } elseif ($v === false) {
  18209. $v = 'false';
  18210. }
  18211. $out .= ' /'.$k.' '.$v;
  18212. }
  18213. $out .= ' >>';
  18214. $out .= "\n".'endobj';
  18215. $this->_out($out);
  18216. }
  18217. }
  18218. /**
  18219. * Set overprint mode for stroking (OP) and non-stroking (op) painting operations.
  18220. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  18221. * @param $stroking (boolean) If true apply overprint for stroking operations.
  18222. * @param $nonstroking (boolean) If true apply overprint for painting operations other than stroking.
  18223. * @param $mode (integer) Overprint mode: (0 = each source colour component value replaces the value previously painted for the corresponding device colorant; 1 = a tint value of 0.0 for a source colour component shall leave the corresponding component of the previously painted colour unchanged).
  18224. * @public
  18225. * @since 5.9.152 (2012-03-23)
  18226. */
  18227. public function setOverprint($stroking=true, $nonstroking='', $mode=0) {
  18228. if ($this->state != 2) {
  18229. return;
  18230. }
  18231. $stroking = $stroking ? true : false;
  18232. if ($this->empty_string($nonstroking)) {
  18233. // default value if not set
  18234. $nonstroking = $stroking;
  18235. } else {
  18236. $nonstroking = $nonstroking ? true : false;
  18237. }
  18238. if (($mode != 0) AND ($mode != 1)) {
  18239. $mode = 0;
  18240. }
  18241. $this->overprint = array('OP' => $stroking, 'op' => $nonstroking, 'OPM' => $mode);
  18242. $gs = $this->addExtGState($this->overprint);
  18243. $this->setExtGState($gs);
  18244. }
  18245. /**
  18246. * Get the overprint mode array (OP, op, OPM).
  18247. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  18248. * @return array.
  18249. * @public
  18250. * @since 5.9.152 (2012-03-23)
  18251. */
  18252. public function getOverprint() {
  18253. return $this->overprint;
  18254. }
  18255. /**
  18256. * Set alpha for stroking (CA) and non-stroking (ca) operations.
  18257. * @param $stroking (float) Alpha value for stroking operations: real value from 0 (transparent) to 1 (opaque).
  18258. * @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
  18259. * @param $nonstroking (float) Alpha value for non-stroking operations: real value from 0 (transparent) to 1 (opaque).
  18260. * @param $ais (boolean)
  18261. * @public
  18262. * @since 3.0.000 (2008-03-27)
  18263. */
  18264. public function setAlpha($stroking=1, $bm='Normal', $nonstroking='', $ais=false) {
  18265. if ($this->pdfa_mode) {
  18266. // transparency is not allowed in PDF/A mode
  18267. return;
  18268. }
  18269. $stroking = floatval($stroking);
  18270. if ($this->empty_string($nonstroking)) {
  18271. // default value if not set
  18272. $nonstroking = $stroking;
  18273. } else {
  18274. $nonstroking = floatval($nonstroking);
  18275. }
  18276. if ($bm[0] == '/') {
  18277. // remove trailing slash
  18278. $bm = substr($bm, 1);
  18279. }
  18280. if (!in_array($bm, array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge', 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion', 'Hue', 'Saturation', 'Color', 'Luminosity'))) {
  18281. $bm = 'Normal';
  18282. }
  18283. $ais = $ais ? true : false;
  18284. $this->alpha = array('CA' => $stroking, 'ca' => $nonstroking, 'BM' => '/'.$bm, 'AIS' => $ais);
  18285. $gs = $this->addExtGState($this->alpha);
  18286. $this->setExtGState($gs);
  18287. }
  18288. /**
  18289. * Get the alpha mode array (CA, ca, BM, AIS).
  18290. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  18291. * @return array.
  18292. * @public
  18293. * @since 5.9.152 (2012-03-23)
  18294. */
  18295. public function getAlpha() {
  18296. return $this->alpha;
  18297. }
  18298. /**
  18299. * Set the default JPEG compression quality (1-100)
  18300. * @param $quality (int) JPEG quality, integer between 1 and 100
  18301. * @public
  18302. * @since 3.0.000 (2008-03-27)
  18303. */
  18304. public function setJPEGQuality($quality) {
  18305. if (($quality < 1) OR ($quality > 100)) {
  18306. $quality = 75;
  18307. }
  18308. $this->jpeg_quality = intval($quality);
  18309. }
  18310. /**
  18311. * Set the default number of columns in a row for HTML tables.
  18312. * @param $cols (int) number of columns
  18313. * @public
  18314. * @since 3.0.014 (2008-06-04)
  18315. */
  18316. public function setDefaultTableColumns($cols=4) {
  18317. $this->default_table_columns = intval($cols);
  18318. }
  18319. /**
  18320. * Set the height of the cell (line height) respect the font height.
  18321. * @param $h (int) cell proportion respect font height (typical value = 1.25).
  18322. * @public
  18323. * @since 3.0.014 (2008-06-04)
  18324. */
  18325. public function setCellHeightRatio($h) {
  18326. $this->cell_height_ratio = $h;
  18327. }
  18328. /**
  18329. * return the height of cell repect font height.
  18330. * @public
  18331. * @since 4.0.012 (2008-07-24)
  18332. */
  18333. public function getCellHeightRatio() {
  18334. return $this->cell_height_ratio;
  18335. }
  18336. /**
  18337. * Set the PDF version (check PDF reference for valid values).
  18338. * @param $version (string) PDF document version.
  18339. * @public
  18340. * @since 3.1.000 (2008-06-09)
  18341. */
  18342. public function setPDFVersion($version='1.7') {
  18343. if ($this->pdfa_mode) {
  18344. // PDF/A mode
  18345. $this->PDFVersion = '1.4';
  18346. } else {
  18347. $this->PDFVersion = $version;
  18348. }
  18349. }
  18350. /**
  18351. * Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
  18352. * (see Section 8.1 of PDF reference, "Viewer Preferences").
  18353. * <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>
  18354. * @param $preferences (array) array of options.
  18355. * @author Nicola Asuni
  18356. * @public
  18357. * @since 3.1.000 (2008-06-09)
  18358. */
  18359. public function setViewerPreferences($preferences) {
  18360. $this->viewer_preferences = $preferences;
  18361. }
  18362. /**
  18363. * Paints color transition registration bars
  18364. * @param $x (float) abscissa of the top left corner of the rectangle.
  18365. * @param $y (float) ordinate of the top left corner of the rectangle.
  18366. * @param $w (float) width of the rectangle.
  18367. * @param $h (float) height of the rectangle.
  18368. * @param $transition (boolean) if true prints tcolor transitions to white.
  18369. * @param $vertical (boolean) if true prints bar vertically.
  18370. * @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.
  18371. * @author Nicola Asuni
  18372. * @since 4.9.000 (2010-03-26)
  18373. * @public
  18374. */
  18375. public function colorRegistrationBar($x, $y, $w, $h, $transition=true, $vertical=false, $colors='A,R,G,B,C,M,Y,K') {
  18376. $bars = explode(',', $colors);
  18377. $numbars = count($bars); // number of bars to print
  18378. // set bar measures
  18379. if ($vertical) {
  18380. $coords = array(0, 0, 0, 1);
  18381. $wb = $w / $numbars; // bar width
  18382. $hb = $h; // bar height
  18383. $xd = $wb; // delta x
  18384. $yd = 0; // delta y
  18385. } else {
  18386. $coords = array(1, 0, 0, 0);
  18387. $wb = $w; // bar width
  18388. $hb = $h / $numbars; // bar height
  18389. $xd = 0; // delta x
  18390. $yd = $hb; // delta y
  18391. }
  18392. $xb = $x;
  18393. $yb = $y;
  18394. foreach ($bars as $col) {
  18395. switch ($col) {
  18396. // set transition colors
  18397. case 'A': { // BLACK
  18398. $col_a = array(255);
  18399. $col_b = array(0);
  18400. break;
  18401. }
  18402. case 'W': { // WHITE
  18403. $col_a = array(0);
  18404. $col_b = array(255);
  18405. break;
  18406. }
  18407. case 'R': { // R
  18408. $col_a = array(255,255,255);
  18409. $col_b = array(255,0,0);
  18410. break;
  18411. }
  18412. case 'G': { // G
  18413. $col_a = array(255,255,255);
  18414. $col_b = array(0,255,0);
  18415. break;
  18416. }
  18417. case 'B': { // B
  18418. $col_a = array(255,255,255);
  18419. $col_b = array(0,0,255);
  18420. break;
  18421. }
  18422. case 'C': { // C
  18423. $col_a = array(0,0,0,0);
  18424. $col_b = array(100,0,0,0);
  18425. break;
  18426. }
  18427. case 'M': { // M
  18428. $col_a = array(0,0,0,0);
  18429. $col_b = array(0,100,0,0);
  18430. break;
  18431. }
  18432. case 'Y': { // Y
  18433. $col_a = array(0,0,0,0);
  18434. $col_b = array(0,0,100,0);
  18435. break;
  18436. }
  18437. case 'K': { // K
  18438. $col_a = array(0,0,0,0);
  18439. $col_b = array(0,0,0,100);
  18440. break;
  18441. }
  18442. default: { // GRAY
  18443. $col_a = array(255);
  18444. $col_b = array(0);
  18445. break;
  18446. }
  18447. }
  18448. if ($transition) {
  18449. // color gradient
  18450. $this->LinearGradient($xb, $yb, $wb, $hb, $col_a, $col_b, $coords);
  18451. } else {
  18452. // color rectangle
  18453. $this->SetFillColorArray($col_b);
  18454. $this->Rect($xb, $yb, $wb, $hb, 'F', array());
  18455. }
  18456. $xb += $xd;
  18457. $yb += $yd;
  18458. }
  18459. }
  18460. /**
  18461. * Paints crop marks.
  18462. * @param $x (float) abscissa of the crop mark center.
  18463. * @param $y (float) ordinate of the crop mark center.
  18464. * @param $w (float) width of the crop mark.
  18465. * @param $h (float) height of the crop mark.
  18466. * @param $type (string) type of crop mark, one symbol per type separated by comma: T = TOP, F = BOTTOM, L = LEFT, R = RIGHT, TL = A = TOP-LEFT, TR = B = TOP-RIGHT, BL = C = BOTTOM-LEFT, BR = D = BOTTOM-RIGHT.
  18467. * @param $color (array) crop mark color (default black).
  18468. * @author Nicola Asuni
  18469. * @since 4.9.000 (2010-03-26)
  18470. * @public
  18471. */
  18472. public function cropMark($x, $y, $w, $h, $type='T,R,B,L', $color=array(0,0,0)) {
  18473. $this->SetLineStyle(array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $color));
  18474. $type = strtoupper($type);
  18475. $type = preg_replace('/[^A-Z\-\,]*/', '', $type);
  18476. // split type in single components
  18477. $type = str_replace('-', ',', $type);
  18478. $type = str_replace('TL', 'T,L', $type);
  18479. $type = str_replace('TR', 'T,R', $type);
  18480. $type = str_replace('BL', 'F,L', $type);
  18481. $type = str_replace('BR', 'F,R', $type);
  18482. $type = str_replace('A', 'T,L', $type);
  18483. $type = str_replace('B', 'T,R', $type);
  18484. $type = str_replace('T,RO', 'BO', $type);
  18485. $type = str_replace('C', 'F,L', $type);
  18486. $type = str_replace('D', 'F,R', $type);
  18487. $crops = explode(',', strtoupper($type));
  18488. // remove duplicates
  18489. $crops = array_unique($crops);
  18490. $dw = ($w / 4); // horizontal space to leave before the intersection point
  18491. $dh = ($h / 4); // vertical space to leave before the intersection point
  18492. foreach ($crops as $crop) {
  18493. switch ($crop) {
  18494. case 'T':
  18495. case 'TOP': {
  18496. $x1 = $x;
  18497. $y1 = ($y - $h);
  18498. $x2 = $x;
  18499. $y2 = ($y - $dh);
  18500. break;
  18501. }
  18502. case 'F':
  18503. case 'BOTTOM': {
  18504. $x1 = $x;
  18505. $y1 = ($y + $dh);
  18506. $x2 = $x;
  18507. $y2 = ($y + $h);
  18508. break;
  18509. }
  18510. case 'L':
  18511. case 'LEFT': {
  18512. $x1 = ($x - $w);
  18513. $y1 = $y;
  18514. $x2 = ($x - $dw);
  18515. $y2 = $y;
  18516. break;
  18517. }
  18518. case 'R':
  18519. case 'RIGHT': {
  18520. $x1 = ($x + $dw);
  18521. $y1 = $y;
  18522. $x2 = ($x + $w);
  18523. $y2 = $y;
  18524. break;
  18525. }
  18526. }
  18527. $this->Line($x1, $y1, $x2, $y2);
  18528. }
  18529. }
  18530. /**
  18531. * Paints a registration mark
  18532. * @param $x (float) abscissa of the registration mark center.
  18533. * @param $y (float) ordinate of the registration mark center.
  18534. * @param $r (float) radius of the crop mark.
  18535. * @param $double (boolean) if true print two concentric crop marks.
  18536. * @param $cola (array) crop mark color (default black).
  18537. * @param $colb (array) second crop mark color.
  18538. * @author Nicola Asuni
  18539. * @since 4.9.000 (2010-03-26)
  18540. * @public
  18541. */
  18542. public function registrationMark($x, $y, $r, $double=false, $cola=array(0,0,0), $colb=array(255,255,255)) {
  18543. $line_style = array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $cola);
  18544. $this->SetFillColorArray($cola);
  18545. $this->PieSector($x, $y, $r, 90, 180, 'F');
  18546. $this->PieSector($x, $y, $r, 270, 360, 'F');
  18547. $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
  18548. if ($double) {
  18549. $r2 = $r * 0.5;
  18550. $this->SetFillColorArray($colb);
  18551. $this->PieSector($x, $y, $r2, 90, 180, 'F');
  18552. $this->PieSector($x, $y, $r2, 270, 360, 'F');
  18553. $this->SetFillColorArray($cola);
  18554. $this->PieSector($x, $y, $r2, 0, 90, 'F');
  18555. $this->PieSector($x, $y, $r2, 180, 270, 'F');
  18556. $this->Circle($x, $y, $r2, 0, 360, 'C', $line_style, array(), 8);
  18557. }
  18558. }
  18559. /**
  18560. * Paints a linear colour gradient.
  18561. * @param $x (float) abscissa of the top left corner of the rectangle.
  18562. * @param $y (float) ordinate of the top left corner of the rectangle.
  18563. * @param $w (float) width of the rectangle.
  18564. * @param $h (float) height of the rectangle.
  18565. * @param $col1 (array) first color (Grayscale, RGB or CMYK components).
  18566. * @param $col2 (array) second color (Grayscale, RGB or CMYK components).
  18567. * @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).
  18568. * @author Andreas Würmser, Nicola Asuni
  18569. * @since 3.1.000 (2008-06-09)
  18570. * @public
  18571. */
  18572. public function LinearGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0,0,1,0)) {
  18573. $this->Clip($x, $y, $w, $h);
  18574. $this->Gradient(2, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
  18575. }
  18576. /**
  18577. * Paints a radial colour gradient.
  18578. * @param $x (float) abscissa of the top left corner of the rectangle.
  18579. * @param $y (float) ordinate of the top left corner of the rectangle.
  18580. * @param $w (float) width of the rectangle.
  18581. * @param $h (float) height of the rectangle.
  18582. * @param $col1 (array) first color (Grayscale, RGB or CMYK components).
  18583. * @param $col2 (array) second color (Grayscale, RGB or CMYK components).
  18584. * @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.
  18585. * @author Andreas Würmser, Nicola Asuni
  18586. * @since 3.1.000 (2008-06-09)
  18587. * @public
  18588. */
  18589. public function RadialGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0.5,0.5,0.5,0.5,1)) {
  18590. $this->Clip($x, $y, $w, $h);
  18591. $this->Gradient(3, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
  18592. }
  18593. /**
  18594. * Paints a coons patch mesh.
  18595. * @param $x (float) abscissa of the top left corner of the rectangle.
  18596. * @param $y (float) ordinate of the top left corner of the rectangle.
  18597. * @param $w (float) width of the rectangle.
  18598. * @param $h (float) height of the rectangle.
  18599. * @param $col1 (array) first color (lower left corner) (RGB components).
  18600. * @param $col2 (array) second color (lower right corner) (RGB components).
  18601. * @param $col3 (array) third color (upper right corner) (RGB components).
  18602. * @param $col4 (array) fourth color (upper left corner) (RGB components).
  18603. * @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>
  18604. * @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
  18605. * @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
  18606. * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  18607. * @author Andreas Würmser, Nicola Asuni
  18608. * @since 3.1.000 (2008-06-09)
  18609. * @public
  18610. */
  18611. 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) {
  18612. if ($this->pdfa_mode OR ($this->state != 2)) {
  18613. return;
  18614. }
  18615. $this->Clip($x, $y, $w, $h);
  18616. $n = count($this->gradients) + 1;
  18617. $this->gradients[$n] = array();
  18618. $this->gradients[$n]['type'] = 6; //coons patch mesh
  18619. $this->gradients[$n]['coords'] = array();
  18620. $this->gradients[$n]['antialias'] = $antialias;
  18621. $this->gradients[$n]['colors'] = array();
  18622. $this->gradients[$n]['transparency'] = false;
  18623. //check the coords array if it is the simple array or the multi patch array
  18624. if (!isset($coords[0]['f'])) {
  18625. //simple array -> convert to multi patch array
  18626. if (!isset($col1[1])) {
  18627. $col1[1] = $col1[2] = $col1[0];
  18628. }
  18629. if (!isset($col2[1])) {
  18630. $col2[1] = $col2[2] = $col2[0];
  18631. }
  18632. if (!isset($col3[1])) {
  18633. $col3[1] = $col3[2] = $col3[0];
  18634. }
  18635. if (!isset($col4[1])) {
  18636. $col4[1] = $col4[2] = $col4[0];
  18637. }
  18638. $patch_array[0]['f'] = 0;
  18639. $patch_array[0]['points'] = $coords;
  18640. $patch_array[0]['colors'][0]['r'] = $col1[0];
  18641. $patch_array[0]['colors'][0]['g'] = $col1[1];
  18642. $patch_array[0]['colors'][0]['b'] = $col1[2];
  18643. $patch_array[0]['colors'][1]['r'] = $col2[0];
  18644. $patch_array[0]['colors'][1]['g'] = $col2[1];
  18645. $patch_array[0]['colors'][1]['b'] = $col2[2];
  18646. $patch_array[0]['colors'][2]['r'] = $col3[0];
  18647. $patch_array[0]['colors'][2]['g'] = $col3[1];
  18648. $patch_array[0]['colors'][2]['b'] = $col3[2];
  18649. $patch_array[0]['colors'][3]['r'] = $col4[0];
  18650. $patch_array[0]['colors'][3]['g'] = $col4[1];
  18651. $patch_array[0]['colors'][3]['b'] = $col4[2];
  18652. } else {
  18653. //multi patch array
  18654. $patch_array = $coords;
  18655. }
  18656. $bpcd = 65535; //16 bits per coordinate
  18657. //build the data stream
  18658. $this->gradients[$n]['stream'] = '';
  18659. $count_patch = count($patch_array);
  18660. for ($i=0; $i < $count_patch; ++$i) {
  18661. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['f']); //start with the edge flag as 8 bit
  18662. $count_points = count($patch_array[$i]['points']);
  18663. for ($j=0; $j < $count_points; ++$j) {
  18664. //each point as 16 bit
  18665. $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $coords_min) / ($coords_max - $coords_min)) * $bpcd;
  18666. if ($patch_array[$i]['points'][$j] < 0) {
  18667. $patch_array[$i]['points'][$j] = 0;
  18668. }
  18669. if ($patch_array[$i]['points'][$j] > $bpcd) {
  18670. $patch_array[$i]['points'][$j] = $bpcd;
  18671. }
  18672. $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] / 256));
  18673. $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] % 256));
  18674. }
  18675. $count_cols = count($patch_array[$i]['colors']);
  18676. for ($j=0; $j < $count_cols; ++$j) {
  18677. //each color component as 8 bit
  18678. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['r']);
  18679. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['g']);
  18680. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['b']);
  18681. }
  18682. }
  18683. //paint the gradient
  18684. $this->_out('/Sh'.$n.' sh');
  18685. //restore previous Graphic State
  18686. $this->_out('Q');
  18687. if ($this->inxobj) {
  18688. // we are inside an XObject template
  18689. $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
  18690. }
  18691. }
  18692. /**
  18693. * Set a rectangular clipping area.
  18694. * @param $x (float) abscissa of the top left corner of the rectangle (or top right corner for RTL mode).
  18695. * @param $y (float) ordinate of the top left corner of the rectangle.
  18696. * @param $w (float) width of the rectangle.
  18697. * @param $h (float) height of the rectangle.
  18698. * @author Andreas Würmser, Nicola Asuni
  18699. * @since 3.1.000 (2008-06-09)
  18700. * @protected
  18701. */
  18702. protected function Clip($x, $y, $w, $h) {
  18703. if ($this->state != 2) {
  18704. return;
  18705. }
  18706. if ($this->rtl) {
  18707. $x = $this->w - $x - $w;
  18708. }
  18709. //save current Graphic State
  18710. $s = 'q';
  18711. //set clipping area
  18712. $s .= sprintf(' %F %F %F %F re W n', $x*$this->k, ($this->h-$y)*$this->k, $w*$this->k, -$h*$this->k);
  18713. //set up transformation matrix for gradient
  18714. $s .= sprintf(' %F 0 0 %F %F %F cm', $w*$this->k, $h*$this->k, $x*$this->k, ($this->h-($y+$h))*$this->k);
  18715. $this->_out($s);
  18716. }
  18717. /**
  18718. * Output gradient.
  18719. * @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)
  18720. * @param $coords (array) array of coordinates.
  18721. * @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).
  18722. * @param $background (array) An array of colour components appropriate to the colour space, specifying a single background colour value.
  18723. * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  18724. * @author Nicola Asuni
  18725. * @since 3.1.000 (2008-06-09)
  18726. * @public
  18727. */
  18728. public function Gradient($type, $coords, $stops, $background=array(), $antialias=false) {
  18729. if ($this->pdfa_mode OR ($this->state != 2)) {
  18730. return;
  18731. }
  18732. $n = count($this->gradients) + 1;
  18733. $this->gradients[$n] = array();
  18734. $this->gradients[$n]['type'] = $type;
  18735. $this->gradients[$n]['coords'] = $coords;
  18736. $this->gradients[$n]['antialias'] = $antialias;
  18737. $this->gradients[$n]['colors'] = array();
  18738. $this->gradients[$n]['transparency'] = false;
  18739. // color space
  18740. $numcolspace = count($stops[0]['color']);
  18741. $bcolor = array_values($background);
  18742. switch($numcolspace) {
  18743. case 4: { // CMYK
  18744. $this->gradients[$n]['colspace'] = 'DeviceCMYK';
  18745. if (!empty($background)) {
  18746. $this->gradients[$n]['background'] = sprintf('%F %F %F %F', $bcolor[0]/100, $bcolor[1]/100, $bcolor[2]/100, $bcolor[3]/100);
  18747. }
  18748. break;
  18749. }
  18750. case 3: { // RGB
  18751. $this->gradients[$n]['colspace'] = 'DeviceRGB';
  18752. if (!empty($background)) {
  18753. $this->gradients[$n]['background'] = sprintf('%F %F %F', $bcolor[0]/255, $bcolor[1]/255, $bcolor[2]/255);
  18754. }
  18755. break;
  18756. }
  18757. case 1: { // Gray scale
  18758. $this->gradients[$n]['colspace'] = 'DeviceGray';
  18759. if (!empty($background)) {
  18760. $this->gradients[$n]['background'] = sprintf('%F', $bcolor[0]/255);
  18761. }
  18762. break;
  18763. }
  18764. }
  18765. $num_stops = count($stops);
  18766. $last_stop_id = $num_stops - 1;
  18767. foreach ($stops as $key => $stop) {
  18768. $this->gradients[$n]['colors'][$key] = array();
  18769. // offset represents a location along the gradient vector
  18770. if (isset($stop['offset'])) {
  18771. $this->gradients[$n]['colors'][$key]['offset'] = $stop['offset'];
  18772. } else {
  18773. if ($key == 0) {
  18774. $this->gradients[$n]['colors'][$key]['offset'] = 0;
  18775. } elseif ($key == $last_stop_id) {
  18776. $this->gradients[$n]['colors'][$key]['offset'] = 1;
  18777. } else {
  18778. $offsetstep = (1 - $this->gradients[$n]['colors'][($key - 1)]['offset']) / ($num_stops - $key);
  18779. $this->gradients[$n]['colors'][$key]['offset'] = $this->gradients[$n]['colors'][($key - 1)]['offset'] + $offsetstep;
  18780. }
  18781. }
  18782. if (isset($stop['opacity'])) {
  18783. $this->gradients[$n]['colors'][$key]['opacity'] = $stop['opacity'];
  18784. if ((!$this->pdfa_mode) AND ($stop['opacity'] < 1)) {
  18785. $this->gradients[$n]['transparency'] = true;
  18786. }
  18787. } else {
  18788. $this->gradients[$n]['colors'][$key]['opacity'] = 1;
  18789. }
  18790. // exponent for the exponential interpolation function
  18791. if (isset($stop['exponent'])) {
  18792. $this->gradients[$n]['colors'][$key]['exponent'] = $stop['exponent'];
  18793. } else {
  18794. $this->gradients[$n]['colors'][$key]['exponent'] = 1;
  18795. }
  18796. // set colors
  18797. $color = array_values($stop['color']);
  18798. switch($numcolspace) {
  18799. case 4: { // CMYK
  18800. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F %F', $color[0]/100, $color[1]/100, $color[2]/100, $color[3]/100);
  18801. break;
  18802. }
  18803. case 3: { // RGB
  18804. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F', $color[0]/255, $color[1]/255, $color[2]/255);
  18805. break;
  18806. }
  18807. case 1: { // Gray scale
  18808. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F', $color[0]/255);
  18809. break;
  18810. }
  18811. }
  18812. }
  18813. if ($this->gradients[$n]['transparency']) {
  18814. // paint luminosity gradient
  18815. $this->_out('/TGS'.$n.' gs');
  18816. }
  18817. //paint the gradient
  18818. $this->_out('/Sh'.$n.' sh');
  18819. //restore previous Graphic State
  18820. $this->_out('Q');
  18821. if ($this->inxobj) {
  18822. // we are inside an XObject template
  18823. $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
  18824. }
  18825. }
  18826. /**
  18827. * Output gradient shaders.
  18828. * @author Nicola Asuni
  18829. * @since 3.1.000 (2008-06-09)
  18830. * @protected
  18831. */
  18832. function _putshaders() {
  18833. if ($this->pdfa_mode) {
  18834. return;
  18835. }
  18836. $idt = count($this->gradients); //index for transparency gradients
  18837. foreach ($this->gradients as $id => $grad) {
  18838. if (($grad['type'] == 2) OR ($grad['type'] == 3)) {
  18839. $fc = $this->_newobj();
  18840. $out = '<<';
  18841. $out .= ' /FunctionType 3';
  18842. $out .= ' /Domain [0 1]';
  18843. $functions = '';
  18844. $bounds = '';
  18845. $encode = '';
  18846. $i = 1;
  18847. $num_cols = count($grad['colors']);
  18848. $lastcols = $num_cols - 1;
  18849. for ($i = 1; $i < $num_cols; ++$i) {
  18850. $functions .= ($fc + $i).' 0 R ';
  18851. if ($i < $lastcols) {
  18852. $bounds .= sprintf('%F ', $grad['colors'][$i]['offset']);
  18853. }
  18854. $encode .= '0 1 ';
  18855. }
  18856. $out .= ' /Functions ['.trim($functions).']';
  18857. $out .= ' /Bounds ['.trim($bounds).']';
  18858. $out .= ' /Encode ['.trim($encode).']';
  18859. $out .= ' >>';
  18860. $out .= "\n".'endobj';
  18861. $this->_out($out);
  18862. for ($i = 1; $i < $num_cols; ++$i) {
  18863. $this->_newobj();
  18864. $out = '<<';
  18865. $out .= ' /FunctionType 2';
  18866. $out .= ' /Domain [0 1]';
  18867. $out .= ' /C0 ['.$grad['colors'][($i - 1)]['color'].']';
  18868. $out .= ' /C1 ['.$grad['colors'][$i]['color'].']';
  18869. $out .= ' /N '.$grad['colors'][$i]['exponent'];
  18870. $out .= ' >>';
  18871. $out .= "\n".'endobj';
  18872. $this->_out($out);
  18873. }
  18874. // set transparency fuctions
  18875. if ($grad['transparency']) {
  18876. $ft = $this->_newobj();
  18877. $out = '<<';
  18878. $out .= ' /FunctionType 3';
  18879. $out .= ' /Domain [0 1]';
  18880. $functions = '';
  18881. $i = 1;
  18882. $num_cols = count($grad['colors']);
  18883. for ($i = 1; $i < $num_cols; ++$i) {
  18884. $functions .= ($ft + $i).' 0 R ';
  18885. }
  18886. $out .= ' /Functions ['.trim($functions).']';
  18887. $out .= ' /Bounds ['.trim($bounds).']';
  18888. $out .= ' /Encode ['.trim($encode).']';
  18889. $out .= ' >>';
  18890. $out .= "\n".'endobj';
  18891. $this->_out($out);
  18892. for ($i = 1; $i < $num_cols; ++$i) {
  18893. $this->_newobj();
  18894. $out = '<<';
  18895. $out .= ' /FunctionType 2';
  18896. $out .= ' /Domain [0 1]';
  18897. $out .= ' /C0 ['.$grad['colors'][($i - 1)]['opacity'].']';
  18898. $out .= ' /C1 ['.$grad['colors'][$i]['opacity'].']';
  18899. $out .= ' /N '.$grad['colors'][$i]['exponent'];
  18900. $out .= ' >>';
  18901. $out .= "\n".'endobj';
  18902. $this->_out($out);
  18903. }
  18904. }
  18905. }
  18906. // set shading object
  18907. $this->_newobj();
  18908. $out = '<< /ShadingType '.$grad['type'];
  18909. if (isset($grad['colspace'])) {
  18910. $out .= ' /ColorSpace /'.$grad['colspace'];
  18911. } else {
  18912. $out .= ' /ColorSpace /DeviceRGB';
  18913. }
  18914. if (isset($grad['background']) AND !empty($grad['background'])) {
  18915. $out .= ' /Background ['.$grad['background'].']';
  18916. }
  18917. if (isset($grad['antialias']) AND ($grad['antialias'] === true)) {
  18918. $out .= ' /AntiAlias true';
  18919. }
  18920. if ($grad['type'] == 2) {
  18921. $out .= ' '.sprintf('/Coords [%F %F %F %F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]);
  18922. $out .= ' /Domain [0 1]';
  18923. $out .= ' /Function '.$fc.' 0 R';
  18924. $out .= ' /Extend [true true]';
  18925. $out .= ' >>';
  18926. } elseif ($grad['type'] == 3) {
  18927. //x0, y0, r0, x1, y1, r1
  18928. //at this this time radius of inner circle is 0
  18929. $out .= ' '.sprintf('/Coords [%F %F 0 %F %F %F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]);
  18930. $out .= ' /Domain [0 1]';
  18931. $out .= ' /Function '.$fc.' 0 R';
  18932. $out .= ' /Extend [true true]';
  18933. $out .= ' >>';
  18934. } elseif ($grad['type'] == 6) {
  18935. $out .= ' /BitsPerCoordinate 16';
  18936. $out .= ' /BitsPerComponent 8';
  18937. $out .= ' /Decode[0 1 0 1 0 1 0 1 0 1]';
  18938. $out .= ' /BitsPerFlag 8';
  18939. $stream = $this->_getrawstream($grad['stream']);
  18940. $out .= ' /Length '.strlen($stream);
  18941. $out .= ' >>';
  18942. $out .= ' stream'."\n".$stream."\n".'endstream';
  18943. }
  18944. $out .= "\n".'endobj';
  18945. $this->_out($out);
  18946. if ($grad['transparency']) {
  18947. $shading_transparency = preg_replace('/\/ColorSpace \/[^\s]+/si', '/ColorSpace /DeviceGray', $out);
  18948. $shading_transparency = preg_replace('/\/Function [0-9]+ /si', '/Function '.$ft.' ', $shading_transparency);
  18949. }
  18950. $this->gradients[$id]['id'] = $this->n;
  18951. // set pattern object
  18952. $this->_newobj();
  18953. $out = '<< /Type /Pattern /PatternType 2';
  18954. $out .= ' /Shading '.$this->gradients[$id]['id'].' 0 R';
  18955. $out .= ' >>';
  18956. $out .= "\n".'endobj';
  18957. $this->_out($out);
  18958. $this->gradients[$id]['pattern'] = $this->n;
  18959. // set shading and pattern for transparency mask
  18960. if ($grad['transparency']) {
  18961. // luminosity pattern
  18962. $idgs = $id + $idt;
  18963. $this->_newobj();
  18964. $this->_out($shading_transparency);
  18965. $this->gradients[$idgs]['id'] = $this->n;
  18966. $this->_newobj();
  18967. $out = '<< /Type /Pattern /PatternType 2';
  18968. $out .= ' /Shading '.$this->gradients[$idgs]['id'].' 0 R';
  18969. $out .= ' >>';
  18970. $out .= "\n".'endobj';
  18971. $this->_out($out);
  18972. $this->gradients[$idgs]['pattern'] = $this->n;
  18973. // luminosity XObject
  18974. $oid = $this->_newobj();
  18975. $this->xobjects['LX'.$oid] = array('n' => $oid);
  18976. $filter = '';
  18977. $stream = 'q /a0 gs /Pattern cs /p'.$idgs.' scn 0 0 '.$this->wPt.' '.$this->hPt.' re f Q';
  18978. if ($this->compress) {
  18979. $filter = ' /Filter /FlateDecode';
  18980. $stream = gzcompress($stream);
  18981. }
  18982. $stream = $this->_getrawstream($stream);
  18983. $out = '<< /Type /XObject /Subtype /Form /FormType 1'.$filter;
  18984. $out .= ' /Length '.strlen($stream);
  18985. $rect = sprintf('%F %F', $this->wPt, $this->hPt);
  18986. $out .= ' /BBox [0 0 '.$rect.']';
  18987. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceGray >>';
  18988. $out .= ' /Resources <<';
  18989. $out .= ' /ExtGState << /a0 << /ca 1 /CA 1 >> >>';
  18990. $out .= ' /Pattern << /p'.$idgs.' '.$this->gradients[$idgs]['pattern'].' 0 R >>';
  18991. $out .= ' >>';
  18992. $out .= ' >> ';
  18993. $out .= ' stream'."\n".$stream."\n".'endstream';
  18994. $out .= "\n".'endobj';
  18995. $this->_out($out);
  18996. // SMask
  18997. $this->_newobj();
  18998. $out = '<< /Type /Mask /S /Luminosity /G '.($this->n - 1).' 0 R >>'."\n".'endobj';
  18999. $this->_out($out);
  19000. // ExtGState
  19001. $this->_newobj();
  19002. $out = '<< /Type /ExtGState /SMask '.($this->n - 1).' 0 R /AIS false >>'."\n".'endobj';
  19003. $this->_out($out);
  19004. $this->extgstates[] = array('n' => $this->n, 'name' => 'TGS'.$id);
  19005. }
  19006. }
  19007. }
  19008. /**
  19009. * Draw the sector of a circle.
  19010. * It can be used for instance to render pie charts.
  19011. * @param $xc (float) abscissa of the center.
  19012. * @param $yc (float) ordinate of the center.
  19013. * @param $r (float) radius.
  19014. * @param $a (float) start angle (in degrees).
  19015. * @param $b (float) end angle (in degrees).
  19016. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  19017. * @param $cw: (float) indicates whether to go clockwise (default: true).
  19018. * @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.
  19019. * @author Maxime Delorme, Nicola Asuni
  19020. * @since 3.1.000 (2008-06-09)
  19021. * @public
  19022. */
  19023. public function PieSector($xc, $yc, $r, $a, $b, $style='FD', $cw=true, $o=90) {
  19024. $this->PieSectorXY($xc, $yc, $r, $r, $a, $b, $style, $cw, $o);
  19025. }
  19026. /**
  19027. * Draw the sector of an ellipse.
  19028. * It can be used for instance to render pie charts.
  19029. * @param $xc (float) abscissa of the center.
  19030. * @param $yc (float) ordinate of the center.
  19031. * @param $rx (float) the x-axis radius.
  19032. * @param $ry (float) the y-axis radius.
  19033. * @param $a (float) start angle (in degrees).
  19034. * @param $b (float) end angle (in degrees).
  19035. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  19036. * @param $cw: (float) indicates whether to go clockwise.
  19037. * @param $o: (float) origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock).
  19038. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of arc.
  19039. * @author Maxime Delorme, Nicola Asuni
  19040. * @since 3.1.000 (2008-06-09)
  19041. * @public
  19042. */
  19043. public function PieSectorXY($xc, $yc, $rx, $ry, $a, $b, $style='FD', $cw=false, $o=0, $nc=2) {
  19044. if ($this->state != 2) {
  19045. return;
  19046. }
  19047. if ($this->rtl) {
  19048. $xc = ($this->w - $xc);
  19049. }
  19050. $op = $this->getPathPaintOperator($style);
  19051. if ($op == 'f') {
  19052. $line_style = array();
  19053. }
  19054. if ($cw) {
  19055. $d = $b;
  19056. $b = (360 - $a + $o);
  19057. $a = (360 - $d + $o);
  19058. } else {
  19059. $b += $o;
  19060. $a += $o;
  19061. }
  19062. $this->_outellipticalarc($xc, $yc, $rx, $ry, 0, $a, $b, true, $nc);
  19063. $this->_out($op);
  19064. }
  19065. /**
  19066. * Embed vector-based Adobe Illustrator (AI) or AI-compatible EPS files.
  19067. * NOTE: EPS is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  19068. * Only vector drawing is supported, not text or bitmap.
  19069. * 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).
  19070. * @param $file (string) Name of the file containing the image or a '@' character followed by the EPS/AI data string.
  19071. * @param $x (float) Abscissa of the upper-left corner.
  19072. * @param $y (float) Ordinate of the upper-left corner.
  19073. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  19074. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  19075. * @param $link (mixed) URL or identifier returned by AddLink().
  19076. * @param $useBoundingBox (boolean) specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true.
  19077. * @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>
  19078. * @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>
  19079. * @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)))
  19080. * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
  19081. * @param $fixoutvals (boolean) if true remove values outside the bounding box.
  19082. * @author Valentin Schmidt, Nicola Asuni
  19083. * @since 3.1.000 (2008-06-09)
  19084. * @public
  19085. */
  19086. public function ImageEps($file, $x='', $y='', $w=0, $h=0, $link='', $useBoundingBox=true, $align='', $palign='', $border=0, $fitonpage=false, $fixoutvals=false) {
  19087. if ($this->state != 2) {
  19088. return;
  19089. }
  19090. if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
  19091. // convert EPS to raster image using GD or ImageMagick libraries
  19092. return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
  19093. }
  19094. if ($x === '') {
  19095. $x = $this->x;
  19096. }
  19097. if ($y === '') {
  19098. $y = $this->y;
  19099. }
  19100. // check page for no-write regions and adapt page margins if necessary
  19101. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  19102. $k = $this->k;
  19103. if ($file{0} === '@') { // image from string
  19104. $data = substr($file, 1);
  19105. } else { // EPS/AI file
  19106. $data = file_get_contents($file);
  19107. }
  19108. if ($data === false) {
  19109. $this->Error('EPS file not found: '.$file);
  19110. }
  19111. $regs = array();
  19112. // EPS/AI compatibility check (only checks files created by Adobe Illustrator!)
  19113. preg_match("/%%Creator:([^\r\n]+)/", $data, $regs); # find Creator
  19114. if (count($regs) > 1) {
  19115. $version_str = trim($regs[1]); # e.g. "Adobe Illustrator(R) 8.0"
  19116. if (strpos($version_str, 'Adobe Illustrator') !== false) {
  19117. $versexp = explode(' ', $version_str);
  19118. $version = (float)array_pop($versexp);
  19119. if ($version >= 9) {
  19120. $this->Error('This version of Adobe Illustrator file is not supported: '.$file);
  19121. }
  19122. }
  19123. }
  19124. // strip binary bytes in front of PS-header
  19125. $start = strpos($data, '%!PS-Adobe');
  19126. if ($start > 0) {
  19127. $data = substr($data, $start);
  19128. }
  19129. // find BoundingBox params
  19130. preg_match("/%%BoundingBox:([^\r\n]+)/", $data, $regs);
  19131. if (count($regs) > 1) {
  19132. list($x1, $y1, $x2, $y2) = explode(' ', trim($regs[1]));
  19133. } else {
  19134. $this->Error('No BoundingBox found in EPS/AI file: '.$file);
  19135. }
  19136. $start = strpos($data, '%%EndSetup');
  19137. if ($start === false) {
  19138. $start = strpos($data, '%%EndProlog');
  19139. }
  19140. if ($start === false) {
  19141. $start = strpos($data, '%%BoundingBox');
  19142. }
  19143. $data = substr($data, $start);
  19144. $end = strpos($data, '%%PageTrailer');
  19145. if ($end===false) {
  19146. $end = strpos($data, 'showpage');
  19147. }
  19148. if ($end) {
  19149. $data = substr($data, 0, $end);
  19150. }
  19151. // calculate image width and height on document
  19152. if (($w <= 0) AND ($h <= 0)) {
  19153. $w = ($x2 - $x1) / $k;
  19154. $h = ($y2 - $y1) / $k;
  19155. } elseif ($w <= 0) {
  19156. $w = ($x2-$x1) / $k * ($h / (($y2 - $y1) / $k));
  19157. } elseif ($h <= 0) {
  19158. $h = ($y2 - $y1) / $k * ($w / (($x2 - $x1) / $k));
  19159. }
  19160. // fit the image on available space
  19161. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  19162. if ($this->rasterize_vector_images) {
  19163. // convert EPS to raster image using GD or ImageMagick libraries
  19164. return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
  19165. }
  19166. // set scaling factors
  19167. $scale_x = $w / (($x2 - $x1) / $k);
  19168. $scale_y = $h / (($y2 - $y1) / $k);
  19169. // set alignment
  19170. $this->img_rb_y = $y + $h;
  19171. // set alignment
  19172. if ($this->rtl) {
  19173. if ($palign == 'L') {
  19174. $ximg = $this->lMargin;
  19175. } elseif ($palign == 'C') {
  19176. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  19177. } elseif ($palign == 'R') {
  19178. $ximg = $this->w - $this->rMargin - $w;
  19179. } else {
  19180. $ximg = $x - $w;
  19181. }
  19182. $this->img_rb_x = $ximg;
  19183. } else {
  19184. if ($palign == 'L') {
  19185. $ximg = $this->lMargin;
  19186. } elseif ($palign == 'C') {
  19187. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  19188. } elseif ($palign == 'R') {
  19189. $ximg = $this->w - $this->rMargin - $w;
  19190. } else {
  19191. $ximg = $x;
  19192. }
  19193. $this->img_rb_x = $ximg + $w;
  19194. }
  19195. if ($useBoundingBox) {
  19196. $dx = $ximg * $k - $x1;
  19197. $dy = $y * $k - $y1;
  19198. } else {
  19199. $dx = $ximg * $k;
  19200. $dy = $y * $k;
  19201. }
  19202. // save the current graphic state
  19203. $this->_out('q'.$this->epsmarker);
  19204. // translate
  19205. $this->_out(sprintf('%F %F %F %F %F %F cm', 1, 0, 0, 1, $dx, $dy + ($this->hPt - (2 * $y * $k) - ($y2 - $y1))));
  19206. // scale
  19207. if (isset($scale_x)) {
  19208. $this->_out(sprintf('%F %F %F %F %F %F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y)));
  19209. }
  19210. // handle pc/unix/mac line endings
  19211. $lines = preg_split('/[\r\n]+/si', $data, -1, PREG_SPLIT_NO_EMPTY);
  19212. $u=0;
  19213. $cnt = count($lines);
  19214. for ($i=0; $i < $cnt; ++$i) {
  19215. $line = $lines[$i];
  19216. if (($line == '') OR ($line{0} == '%')) {
  19217. continue;
  19218. }
  19219. $len = strlen($line);
  19220. // check for spot color names
  19221. $color_name = '';
  19222. if (strcasecmp('x', substr(trim($line), -1)) == 0) {
  19223. if (preg_match('/\([^\)]*\)/', $line, $matches) > 0) {
  19224. // extract spot color name
  19225. $color_name = $matches[0];
  19226. // remove color name from string
  19227. $line = str_replace(' '.$color_name, '', $line);
  19228. // remove pharentesis from color name
  19229. $color_name = substr($color_name, 1, -1);
  19230. }
  19231. }
  19232. $chunks = explode(' ', $line);
  19233. $cmd = trim(array_pop($chunks));
  19234. // RGB
  19235. if (($cmd == 'Xa') OR ($cmd == 'XA')) {
  19236. $b = array_pop($chunks);
  19237. $g = array_pop($chunks);
  19238. $r = array_pop($chunks);
  19239. $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!
  19240. continue;
  19241. }
  19242. $skip = false;
  19243. if ($fixoutvals) {
  19244. // check for values outside the bounding box
  19245. switch ($cmd) {
  19246. case 'm':
  19247. case 'l':
  19248. case 'L': {
  19249. // skip values outside bounding box
  19250. foreach ($chunks as $key => $val) {
  19251. if ((($key % 2) == 0) AND (($val < $x1) OR ($val > $x2))) {
  19252. $skip = true;
  19253. } elseif ((($key % 2) != 0) AND (($val < $y1) OR ($val > $y2))) {
  19254. $skip = true;
  19255. }
  19256. }
  19257. }
  19258. }
  19259. }
  19260. switch ($cmd) {
  19261. case 'm':
  19262. case 'l':
  19263. case 'v':
  19264. case 'y':
  19265. case 'c':
  19266. case 'k':
  19267. case 'K':
  19268. case 'g':
  19269. case 'G':
  19270. case 's':
  19271. case 'S':
  19272. case 'J':
  19273. case 'j':
  19274. case 'w':
  19275. case 'M':
  19276. case 'd':
  19277. case 'n': {
  19278. if ($skip) {
  19279. break;
  19280. }
  19281. $this->_out($line);
  19282. break;
  19283. }
  19284. case 'x': {// custom fill color
  19285. if (empty($color_name)) {
  19286. // CMYK color
  19287. list($col_c, $col_m, $col_y, $col_k) = $chunks;
  19288. $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' k');
  19289. } else {
  19290. // Spot Color (CMYK + tint)
  19291. list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
  19292. $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
  19293. $color_cmd = sprintf('/CS%d cs %F scn', $this->spot_colors[$color_name]['i'], (1 - $col_t));
  19294. $this->_out($color_cmd);
  19295. }
  19296. break;
  19297. }
  19298. case 'X': { // custom stroke color
  19299. if (empty($color_name)) {
  19300. // CMYK color
  19301. list($col_c, $col_m, $col_y, $col_k) = $chunks;
  19302. $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' K');
  19303. } else {
  19304. // Spot Color (CMYK + tint)
  19305. list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
  19306. $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
  19307. $color_cmd = sprintf('/CS%d CS %F SCN', $this->spot_colors[$color_name]['i'], (1 - $col_t));
  19308. $this->_out($color_cmd);
  19309. }
  19310. break;
  19311. }
  19312. case 'Y':
  19313. case 'N':
  19314. case 'V':
  19315. case 'L':
  19316. case 'C': {
  19317. if ($skip) {
  19318. break;
  19319. }
  19320. $line[($len - 1)] = strtolower($cmd);
  19321. $this->_out($line);
  19322. break;
  19323. }
  19324. case 'b':
  19325. case 'B': {
  19326. $this->_out($cmd . '*');
  19327. break;
  19328. }
  19329. case 'f':
  19330. case 'F': {
  19331. if ($u > 0) {
  19332. $isU = false;
  19333. $max = min(($i + 5), $cnt);
  19334. for ($j = ($i + 1); $j < $max; ++$j) {
  19335. $isU = ($isU OR (($lines[$j] == 'U') OR ($lines[$j] == '*U')));
  19336. }
  19337. if ($isU) {
  19338. $this->_out('f*');
  19339. }
  19340. } else {
  19341. $this->_out('f*');
  19342. }
  19343. break;
  19344. }
  19345. case '*u': {
  19346. ++$u;
  19347. break;
  19348. }
  19349. case '*U': {
  19350. --$u;
  19351. break;
  19352. }
  19353. }
  19354. }
  19355. // restore previous graphic state
  19356. $this->_out($this->epsmarker.'Q');
  19357. if (!empty($border)) {
  19358. $bx = $this->x;
  19359. $by = $this->y;
  19360. $this->x = $ximg;
  19361. if ($this->rtl) {
  19362. $this->x += $w;
  19363. }
  19364. $this->y = $y;
  19365. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  19366. $this->x = $bx;
  19367. $this->y = $by;
  19368. }
  19369. if ($link) {
  19370. $this->Link($ximg, $y, $w, $h, $link, 0);
  19371. }
  19372. // set pointer to align the next text/objects
  19373. switch($align) {
  19374. case 'T':{
  19375. $this->y = $y;
  19376. $this->x = $this->img_rb_x;
  19377. break;
  19378. }
  19379. case 'M':{
  19380. $this->y = $y + round($h/2);
  19381. $this->x = $this->img_rb_x;
  19382. break;
  19383. }
  19384. case 'B':{
  19385. $this->y = $this->img_rb_y;
  19386. $this->x = $this->img_rb_x;
  19387. break;
  19388. }
  19389. case 'N':{
  19390. $this->SetY($this->img_rb_y);
  19391. break;
  19392. }
  19393. default:{
  19394. break;
  19395. }
  19396. }
  19397. $this->endlinex = $this->img_rb_x;
  19398. }
  19399. /**
  19400. * Set document barcode.
  19401. * @param $bc (string) barcode
  19402. * @public
  19403. */
  19404. public function setBarcode($bc='') {
  19405. $this->barcode = $bc;
  19406. }
  19407. /**
  19408. * Get current barcode.
  19409. * @return string
  19410. * @public
  19411. * @since 4.0.012 (2008-07-24)
  19412. */
  19413. public function getBarcode() {
  19414. return $this->barcode;
  19415. }
  19416. /**
  19417. * Print a Linear Barcode.
  19418. * @param $code (string) code to print
  19419. * @param $type (string) type of barcode (see barcodes.php for supported formats).
  19420. * @param $x (int) x position in user units (empty string = current x position)
  19421. * @param $y (int) y position in user units (empty string = current y position)
  19422. * @param $w (int) width in user units (empty string = remaining page width)
  19423. * @param $h (int) height in user units (empty string = remaining page height)
  19424. * @param $xres (float) width of the smallest bar in user units (empty string = default value = 0.4mm)
  19425. * @param $style (array) array of options:<ul>
  19426. * <li>boolean $style['border'] if true prints a border</li>
  19427. * <li>int $style['padding'] padding to leave around the barcode in user units (set to 'auto' for automatic padding)</li>
  19428. * <li>int $style['hpadding'] horizontal padding in user units (set to 'auto' for automatic padding)</li>
  19429. * <li>int $style['vpadding'] vertical padding in user units (set to 'auto' for automatic padding)</li>
  19430. * <li>array $style['fgcolor'] color array for bars and text</li>
  19431. * <li>mixed $style['bgcolor'] color array for background (set to false for transparent)</li>
  19432. * <li>boolean $style['text'] if true prints text below the barcode</li>
  19433. * <li>string $style['label'] override default label</li>
  19434. * <li>string $style['font'] font name for text</li><li>int $style['fontsize'] font size for text</li>
  19435. * <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>
  19436. * <li>string $style['position'] horizontal position of the containing barcode cell on the page: L = left margin; C = center; R = right margin.</li>
  19437. * <li>string $style['align'] horizontal position of the barcode on the containing rectangle: L = left; C = center; R = right.</li>
  19438. * <li>string $style['stretch'] if true stretch the barcode to best fit the available width, otherwise uses $xres resolution for a single bar.</li>
  19439. * <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>
  19440. * <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>
  19441. * @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>
  19442. * @author Nicola Asuni
  19443. * @since 3.1.000 (2008-06-09)
  19444. * @public
  19445. */
  19446. public function write1DBarcode($code, $type, $x='', $y='', $w='', $h='', $xres='', $style='', $align='') {
  19447. if ($this->empty_string(trim($code))) {
  19448. return;
  19449. }
  19450. require_once(dirname(__FILE__).'/barcodes.php');
  19451. // save current graphic settings
  19452. $gvars = $this->getGraphicVars();
  19453. // create new barcode object
  19454. $barcodeobj = new TCPDFBarcode($code, $type);
  19455. $arrcode = $barcodeobj->getBarcodeArray();
  19456. if (($arrcode === false) OR empty($arrcode) OR ($arrcode['maxw'] == 0)) {
  19457. $this->Error('Error in 1D barcode string');
  19458. }
  19459. // set default values
  19460. if (!isset($style['position'])) {
  19461. $style['position'] = '';
  19462. } elseif ($style['position'] == 'S') {
  19463. // keep this for backward compatibility
  19464. $style['position'] = '';
  19465. $style['stretch'] = true;
  19466. }
  19467. if (!isset($style['fitwidth'])) {
  19468. if (!isset($style['stretch'])) {
  19469. $style['fitwidth'] = true;
  19470. } else {
  19471. $style['fitwidth'] = false;
  19472. }
  19473. }
  19474. if ($style['fitwidth']) {
  19475. // disable stretch
  19476. $style['stretch'] = false;
  19477. }
  19478. if (!isset($style['stretch'])) {
  19479. if (($w === '') OR ($w <= 0)) {
  19480. $style['stretch'] = false;
  19481. } else {
  19482. $style['stretch'] = true;
  19483. }
  19484. }
  19485. if (!isset($style['fgcolor'])) {
  19486. $style['fgcolor'] = array(0,0,0); // default black
  19487. }
  19488. if (!isset($style['bgcolor'])) {
  19489. $style['bgcolor'] = false; // default transparent
  19490. }
  19491. if (!isset($style['border'])) {
  19492. $style['border'] = false;
  19493. }
  19494. $fontsize = 0;
  19495. if (!isset($style['text'])) {
  19496. $style['text'] = false;
  19497. }
  19498. if ($style['text'] AND isset($style['font'])) {
  19499. if (isset($style['fontsize'])) {
  19500. $fontsize = $style['fontsize'];
  19501. }
  19502. $this->SetFont($style['font'], '', $fontsize);
  19503. }
  19504. if (!isset($style['stretchtext'])) {
  19505. $style['stretchtext'] = 4;
  19506. }
  19507. if ($x === '') {
  19508. $x = $this->x;
  19509. }
  19510. if ($y === '') {
  19511. $y = $this->y;
  19512. }
  19513. // check page for no-write regions and adapt page margins if necessary
  19514. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  19515. if (($w === '') OR ($w <= 0)) {
  19516. if ($this->rtl) {
  19517. $w = $x - $this->lMargin;
  19518. } else {
  19519. $w = $this->w - $this->rMargin - $x;
  19520. }
  19521. }
  19522. // padding
  19523. if (!isset($style['padding'])) {
  19524. $padding = 0;
  19525. } elseif ($style['padding'] === 'auto') {
  19526. $padding = 10 * ($w / ($arrcode['maxw'] + 20));
  19527. } else {
  19528. $padding = floatval($style['padding']);
  19529. }
  19530. // horizontal padding
  19531. if (!isset($style['hpadding'])) {
  19532. $hpadding = $padding;
  19533. } elseif ($style['hpadding'] === 'auto') {
  19534. $hpadding = 10 * ($w / ($arrcode['maxw'] + 20));
  19535. } else {
  19536. $hpadding = floatval($style['hpadding']);
  19537. }
  19538. // vertical padding
  19539. if (!isset($style['vpadding'])) {
  19540. $vpadding = $padding;
  19541. } elseif ($style['vpadding'] === 'auto') {
  19542. $vpadding = ($hpadding / 2);
  19543. } else {
  19544. $vpadding = floatval($style['vpadding']);
  19545. }
  19546. // calculate xres (single bar width)
  19547. $max_xres = ($w - (2 * $hpadding)) / $arrcode['maxw'];
  19548. if ($style['stretch']) {
  19549. $xres = $max_xres;
  19550. } else {
  19551. if ($this->empty_string($xres)) {
  19552. $xres = (0.141 * $this->k); // default bar width = 0.4 mm
  19553. }
  19554. if ($xres > $max_xres) {
  19555. // correct xres to fit on $w
  19556. $xres = $max_xres;
  19557. }
  19558. if ((isset($style['padding']) AND ($style['padding'] === 'auto'))
  19559. OR (isset($style['hpadding']) AND ($style['hpadding'] === 'auto'))) {
  19560. $hpadding = 10 * $xres;
  19561. if (isset($style['vpadding']) AND ($style['vpadding'] === 'auto')) {
  19562. $vpadding = ($hpadding / 2);
  19563. }
  19564. }
  19565. }
  19566. if ($style['fitwidth']) {
  19567. $wold = $w;
  19568. $w = (($arrcode['maxw'] * $xres) + (2 * $hpadding));
  19569. if (isset($style['cellfitalign'])) {
  19570. switch ($style['cellfitalign']) {
  19571. case 'L': {
  19572. if ($this->rtl) {
  19573. $x -= ($wold - $w);
  19574. }
  19575. break;
  19576. }
  19577. case 'R': {
  19578. if (!$this->rtl) {
  19579. $x += ($wold - $w);
  19580. }
  19581. break;
  19582. }
  19583. case 'C': {
  19584. if ($this->rtl) {
  19585. $x -= (($wold - $w) / 2);
  19586. } else {
  19587. $x += (($wold - $w) / 2);
  19588. }
  19589. break;
  19590. }
  19591. default : {
  19592. break;
  19593. }
  19594. }
  19595. }
  19596. }
  19597. $text_height = ($this->cell_height_ratio * $fontsize / $this->k);
  19598. // height
  19599. if (($h === '') OR ($h <= 0)) {
  19600. // set default height
  19601. $h = (($arrcode['maxw'] * $xres) / 3) + (2 * $vpadding) + $text_height;
  19602. }
  19603. $barh = $h - $text_height - (2 * $vpadding);
  19604. if ($barh <=0) {
  19605. // try to reduce font or padding to fit barcode on available height
  19606. if ($text_height > $h) {
  19607. $fontsize = (($h * $this->k) / (4 * $this->cell_height_ratio));
  19608. $text_height = ($this->cell_height_ratio * $fontsize / $this->k);
  19609. $this->SetFont($style['font'], '', $fontsize);
  19610. }
  19611. if ($vpadding > 0) {
  19612. $vpadding = (($h - $text_height) / 4);
  19613. }
  19614. $barh = $h - $text_height - (2 * $vpadding);
  19615. }
  19616. // fit the barcode on available space
  19617. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
  19618. // set alignment
  19619. $this->img_rb_y = $y + $h;
  19620. // set alignment
  19621. if ($this->rtl) {
  19622. if ($style['position'] == 'L') {
  19623. $xpos = $this->lMargin;
  19624. } elseif ($style['position'] == 'C') {
  19625. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  19626. } elseif ($style['position'] == 'R') {
  19627. $xpos = $this->w - $this->rMargin - $w;
  19628. } else {
  19629. $xpos = $x - $w;
  19630. }
  19631. $this->img_rb_x = $xpos;
  19632. } else {
  19633. if ($style['position'] == 'L') {
  19634. $xpos = $this->lMargin;
  19635. } elseif ($style['position'] == 'C') {
  19636. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  19637. } elseif ($style['position'] == 'R') {
  19638. $xpos = $this->w - $this->rMargin - $w;
  19639. } else {
  19640. $xpos = $x;
  19641. }
  19642. $this->img_rb_x = $xpos + $w;
  19643. }
  19644. $xpos_rect = $xpos;
  19645. if (!isset($style['align'])) {
  19646. $style['align'] = 'C';
  19647. }
  19648. switch ($style['align']) {
  19649. case 'L': {
  19650. $xpos = $xpos_rect + $hpadding;
  19651. break;
  19652. }
  19653. case 'R': {
  19654. $xpos = $xpos_rect + ($w - ($arrcode['maxw'] * $xres)) - $hpadding;
  19655. break;
  19656. }
  19657. case 'C':
  19658. default : {
  19659. $xpos = $xpos_rect + (($w - ($arrcode['maxw'] * $xres)) / 2);
  19660. break;
  19661. }
  19662. }
  19663. $xpos_text = $xpos;
  19664. // barcode is always printed in LTR direction
  19665. $tempRTL = $this->rtl;
  19666. $this->rtl = false;
  19667. // print background color
  19668. if ($style['bgcolor']) {
  19669. $this->Rect($xpos_rect, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  19670. } elseif ($style['border']) {
  19671. $this->Rect($xpos_rect, $y, $w, $h, 'D');
  19672. }
  19673. // set foreground color
  19674. $this->SetDrawColorArray($style['fgcolor']);
  19675. $this->SetTextColorArray($style['fgcolor']);
  19676. // print bars
  19677. foreach ($arrcode['bcode'] as $k => $v) {
  19678. $bw = ($v['w'] * $xres);
  19679. if ($v['t']) {
  19680. // draw a vertical bar
  19681. $ypos = $y + $vpadding + ($v['p'] * $barh / $arrcode['maxh']);
  19682. $this->Rect($xpos, $ypos, $bw, ($v['h'] * $barh / $arrcode['maxh']), 'F', array(), $style['fgcolor']);
  19683. }
  19684. $xpos += $bw;
  19685. }
  19686. // print text
  19687. if ($style['text']) {
  19688. if (isset($style['label']) AND !$this->empty_string($style['label'])) {
  19689. $label = $style['label'];
  19690. } else {
  19691. $label = $code;
  19692. }
  19693. $txtwidth = ($arrcode['maxw'] * $xres);
  19694. if ($this->GetStringWidth($label) > $txtwidth) {
  19695. $style['stretchtext'] = 2;
  19696. }
  19697. // print text
  19698. $this->x = $xpos_text;
  19699. $this->y = $y + $vpadding + $barh;
  19700. $cellpadding = $this->cell_padding;
  19701. $this->SetCellPadding(0);
  19702. $this->Cell($txtwidth, '', $label, 0, 0, 'C', false, '', $style['stretchtext'], false, 'T', 'T');
  19703. $this->cell_padding = $cellpadding;
  19704. }
  19705. // restore original direction
  19706. $this->rtl = $tempRTL;
  19707. // restore previous settings
  19708. $this->setGraphicVars($gvars);
  19709. // set pointer to align the next text/objects
  19710. switch($align) {
  19711. case 'T':{
  19712. $this->y = $y;
  19713. $this->x = $this->img_rb_x;
  19714. break;
  19715. }
  19716. case 'M':{
  19717. $this->y = $y + round($h / 2);
  19718. $this->x = $this->img_rb_x;
  19719. break;
  19720. }
  19721. case 'B':{
  19722. $this->y = $this->img_rb_y;
  19723. $this->x = $this->img_rb_x;
  19724. break;
  19725. }
  19726. case 'N':{
  19727. $this->SetY($this->img_rb_y);
  19728. break;
  19729. }
  19730. default:{
  19731. break;
  19732. }
  19733. }
  19734. $this->endlinex = $this->img_rb_x;
  19735. }
  19736. /**
  19737. * This function is DEPRECATED, please use the new write1DBarcode() function.
  19738. * @param $x (int) x position in user units
  19739. * @param $y (int) y position in user units
  19740. * @param $w (int) width in user units
  19741. * @param $h (int) height position in user units
  19742. * @param $type (string) type of barcode
  19743. * @param $style (string) barcode style
  19744. * @param $font (string) font for text
  19745. * @param $xres (int) x resolution
  19746. * @param $code (string) code to print
  19747. * @deprecated deprecated since version 3.1.000 (2008-06-10)
  19748. * @public
  19749. * @see write1DBarcode()
  19750. */
  19751. public function writeBarcode($x, $y, $w, $h, $type, $style, $font, $xres, $code) {
  19752. // convert old settings for the new write1DBarcode() function.
  19753. $xres = 1 / $xres;
  19754. $newstyle = array(
  19755. 'position' => '',
  19756. 'align' => '',
  19757. 'stretch' => false,
  19758. 'fitwidth' => false,
  19759. 'cellfitalign' => '',
  19760. 'border' => false,
  19761. 'padding' => 0,
  19762. 'fgcolor' => array(0,0,0),
  19763. 'bgcolor' => false,
  19764. 'text' => true,
  19765. 'font' => $font,
  19766. 'fontsize' => 8,
  19767. 'stretchtext' => 4
  19768. );
  19769. if ($style & 1) {
  19770. $newstyle['border'] = true;
  19771. }
  19772. if ($style & 2) {
  19773. $newstyle['bgcolor'] = false;
  19774. }
  19775. if ($style & 4) {
  19776. $newstyle['position'] = 'C';
  19777. } elseif ($style & 8) {
  19778. $newstyle['position'] = 'L';
  19779. } elseif ($style & 16) {
  19780. $newstyle['position'] = 'R';
  19781. }
  19782. if ($style & 128) {
  19783. $newstyle['text'] = true;
  19784. }
  19785. if ($style & 256) {
  19786. $newstyle['stretchtext'] = 4;
  19787. }
  19788. $this->write1DBarcode($code, $type, $x, $y, $w, $h, $xres, $newstyle, '');
  19789. }
  19790. /**
  19791. * Print 2D Barcode.
  19792. * @param $code (string) code to print
  19793. * @param $type (string) type of barcode (see 2dbarcodes.php for supported formats).
  19794. * @param $x (int) x position in user units
  19795. * @param $y (int) y position in user units
  19796. * @param $w (int) width in user units
  19797. * @param $h (int) height in user units
  19798. * @param $style (array) array of options:<ul>
  19799. * <li>boolean $style['border'] if true prints a border around the barcode</li>
  19800. * <li>int $style['padding'] padding to leave around the barcode in barcode units (set to 'auto' for automatic padding)</li>
  19801. * <li>int $style['hpadding'] horizontal padding in barcode units (set to 'auto' for automatic padding)</li>
  19802. * <li>int $style['vpadding'] vertical padding in barcode units (set to 'auto' for automatic padding)</li>
  19803. * <li>int $style['module_width'] width of a single module in points</li>
  19804. * <li>int $style['module_height'] height of a single module in points</li>
  19805. * <li>array $style['fgcolor'] color array for bars and text</li>
  19806. * <li>mixed $style['bgcolor'] color array for background or false for transparent</li>
  19807. * <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>
  19808. * <li>$style['module_height'] height of a single module in points</li></ul>
  19809. * @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>
  19810. * @param $distort (boolean) if true distort the barcode to fit width and height, otherwise preserve aspect ratio
  19811. * @author Nicola Asuni
  19812. * @since 4.5.037 (2009-04-07)
  19813. * @public
  19814. */
  19815. public function write2DBarcode($code, $type, $x='', $y='', $w='', $h='', $style='', $align='', $distort=false) {
  19816. if ($this->empty_string(trim($code))) {
  19817. return;
  19818. }
  19819. require_once(dirname(__FILE__).'/2dbarcodes.php');
  19820. // save current graphic settings
  19821. $gvars = $this->getGraphicVars();
  19822. // create new barcode object
  19823. $barcodeobj = new TCPDF2DBarcode($code, $type);
  19824. $arrcode = $barcodeobj->getBarcodeArray();
  19825. if (($arrcode === false) OR empty($arrcode) OR !isset($arrcode['num_rows']) OR ($arrcode['num_rows'] == 0) OR !isset($arrcode['num_cols']) OR ($arrcode['num_cols'] == 0)) {
  19826. $this->Error('Error in 2D barcode string');
  19827. }
  19828. // set default values
  19829. if (!isset($style['position'])) {
  19830. $style['position'] = '';
  19831. }
  19832. if (!isset($style['fgcolor'])) {
  19833. $style['fgcolor'] = array(0,0,0); // default black
  19834. }
  19835. if (!isset($style['bgcolor'])) {
  19836. $style['bgcolor'] = false; // default transparent
  19837. }
  19838. if (!isset($style['border'])) {
  19839. $style['border'] = false;
  19840. }
  19841. // padding
  19842. if (!isset($style['padding'])) {
  19843. $style['padding'] = 0;
  19844. } elseif ($style['padding'] === 'auto') {
  19845. $style['padding'] = 4;
  19846. }
  19847. if (!isset($style['hpadding'])) {
  19848. $style['hpadding'] = $style['padding'];
  19849. } elseif ($style['hpadding'] === 'auto') {
  19850. $style['hpadding'] = 4;
  19851. }
  19852. if (!isset($style['vpadding'])) {
  19853. $style['vpadding'] = $style['padding'];
  19854. } elseif ($style['vpadding'] === 'auto') {
  19855. $style['vpadding'] = 4;
  19856. }
  19857. $hpad = (2 * $style['hpadding']);
  19858. $vpad = (2 * $style['vpadding']);
  19859. // cell (module) dimension
  19860. if (!isset($style['module_width'])) {
  19861. $style['module_width'] = 1; // width of a single module in points
  19862. }
  19863. if (!isset($style['module_height'])) {
  19864. $style['module_height'] = 1; // height of a single module in points
  19865. }
  19866. if ($x === '') {
  19867. $x = $this->x;
  19868. }
  19869. if ($y === '') {
  19870. $y = $this->y;
  19871. }
  19872. // check page for no-write regions and adapt page margins if necessary
  19873. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  19874. // number of barcode columns and rows
  19875. $rows = $arrcode['num_rows'];
  19876. $cols = $arrcode['num_cols'];
  19877. // module width and height
  19878. $mw = $style['module_width'];
  19879. $mh = $style['module_height'];
  19880. if (($mw == 0) OR ($mh == 0)) {
  19881. $this->Error('Error in 2D barcode string');
  19882. }
  19883. // get max dimensions
  19884. if ($this->rtl) {
  19885. $maxw = $x - $this->lMargin;
  19886. } else {
  19887. $maxw = $this->w - $this->rMargin - $x;
  19888. }
  19889. $maxh = ($this->h - $this->tMargin - $this->bMargin);
  19890. $ratioHW = ((($rows * $mh) + $hpad) / (($cols * $mw) + $vpad));
  19891. $ratioWH = ((($cols * $mw) + $vpad) / (($rows * $mh) + $hpad));
  19892. if (!$distort) {
  19893. if (($maxw * $ratioHW) > $maxh) {
  19894. $maxw = $maxh * $ratioWH;
  19895. }
  19896. if (($maxh * $ratioWH) > $maxw) {
  19897. $maxh = $maxw * $ratioHW;
  19898. }
  19899. }
  19900. // set maximum dimesions
  19901. if ($w > $maxw) {
  19902. $w = $maxw;
  19903. }
  19904. if ($h > $maxh) {
  19905. $h = $maxh;
  19906. }
  19907. // set dimensions
  19908. if ((($w === '') OR ($w <= 0)) AND (($h === '') OR ($h <= 0))) {
  19909. $w = ($cols + $hpad) * ($mw / $this->k);
  19910. $h = ($rows + $vpad) * ($mh / $this->k);
  19911. } elseif (($w === '') OR ($w <= 0)) {
  19912. $w = $h * $ratioWH;
  19913. } elseif (($h === '') OR ($h <= 0)) {
  19914. $h = $w * $ratioHW;
  19915. }
  19916. // barcode size (excluding padding)
  19917. $bw = ($w * $cols) / ($cols + $hpad);
  19918. $bh = ($h * $rows) / ($rows + $vpad);
  19919. // dimension of single barcode cell unit
  19920. $cw = $bw / $cols;
  19921. $ch = $bh / $rows;
  19922. if (!$distort) {
  19923. if (($cw / $ch) > ($mw / $mh)) {
  19924. // correct horizontal distortion
  19925. $cw = $ch * $mw / $mh;
  19926. $bw = $cw * $cols;
  19927. $style['hpadding'] = ($w - $bw) / (2 * $cw);
  19928. } else {
  19929. // correct vertical distortion
  19930. $ch = $cw * $mh / $mw;
  19931. $bh = $ch * $rows;
  19932. $style['vpadding'] = ($h - $bh) / (2 * $ch);
  19933. }
  19934. }
  19935. // fit the barcode on available space
  19936. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
  19937. // set alignment
  19938. $this->img_rb_y = $y + $h;
  19939. // set alignment
  19940. if ($this->rtl) {
  19941. if ($style['position'] == 'L') {
  19942. $xpos = $this->lMargin;
  19943. } elseif ($style['position'] == 'C') {
  19944. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  19945. } elseif ($style['position'] == 'R') {
  19946. $xpos = $this->w - $this->rMargin - $w;
  19947. } else {
  19948. $xpos = $x - $w;
  19949. }
  19950. $this->img_rb_x = $xpos;
  19951. } else {
  19952. if ($style['position'] == 'L') {
  19953. $xpos = $this->lMargin;
  19954. } elseif ($style['position'] == 'C') {
  19955. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  19956. } elseif ($style['position'] == 'R') {
  19957. $xpos = $this->w - $this->rMargin - $w;
  19958. } else {
  19959. $xpos = $x;
  19960. }
  19961. $this->img_rb_x = $xpos + $w;
  19962. }
  19963. $xstart = $xpos + ($style['hpadding'] * $cw);
  19964. $ystart = $y + ($style['vpadding'] * $ch);
  19965. // barcode is always printed in LTR direction
  19966. $tempRTL = $this->rtl;
  19967. $this->rtl = false;
  19968. // print background color
  19969. if ($style['bgcolor']) {
  19970. $this->Rect($xpos, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  19971. } elseif ($style['border']) {
  19972. $this->Rect($xpos, $y, $w, $h, 'D');
  19973. }
  19974. // set foreground color
  19975. $this->SetDrawColorArray($style['fgcolor']);
  19976. // print barcode cells
  19977. // for each row
  19978. for ($r = 0; $r < $rows; ++$r) {
  19979. $xr = $xstart;
  19980. // for each column
  19981. for ($c = 0; $c < $cols; ++$c) {
  19982. if ($arrcode['bcode'][$r][$c] == 1) {
  19983. // draw a single barcode cell
  19984. $this->Rect($xr, $ystart, $cw, $ch, 'F', array(), $style['fgcolor']);
  19985. }
  19986. $xr += $cw;
  19987. }
  19988. $ystart += $ch;
  19989. }
  19990. // restore original direction
  19991. $this->rtl = $tempRTL;
  19992. // restore previous settings
  19993. $this->setGraphicVars($gvars);
  19994. // set pointer to align the next text/objects
  19995. switch($align) {
  19996. case 'T':{
  19997. $this->y = $y;
  19998. $this->x = $this->img_rb_x;
  19999. break;
  20000. }
  20001. case 'M':{
  20002. $this->y = $y + round($h/2);
  20003. $this->x = $this->img_rb_x;
  20004. break;
  20005. }
  20006. case 'B':{
  20007. $this->y = $this->img_rb_y;
  20008. $this->x = $this->img_rb_x;
  20009. break;
  20010. }
  20011. case 'N':{
  20012. $this->SetY($this->img_rb_y);
  20013. break;
  20014. }
  20015. default:{
  20016. break;
  20017. }
  20018. }
  20019. $this->endlinex = $this->img_rb_x;
  20020. }
  20021. /**
  20022. * Returns an array containing current margins:
  20023. * <ul>
  20024. <li>$ret['left'] = left margin</li>
  20025. <li>$ret['right'] = right margin</li>
  20026. <li>$ret['top'] = top margin</li>
  20027. <li>$ret['bottom'] = bottom margin</li>
  20028. <li>$ret['header'] = header margin</li>
  20029. <li>$ret['footer'] = footer margin</li>
  20030. <li>$ret['cell'] = cell padding array</li>
  20031. <li>$ret['padding_left'] = cell left padding</li>
  20032. <li>$ret['padding_top'] = cell top padding</li>
  20033. <li>$ret['padding_right'] = cell right padding</li>
  20034. <li>$ret['padding_bottom'] = cell bottom padding</li>
  20035. * </ul>
  20036. * @return array containing all margins measures
  20037. * @public
  20038. * @since 3.2.000 (2008-06-23)
  20039. */
  20040. public function getMargins() {
  20041. $ret = array(
  20042. 'left' => $this->lMargin,
  20043. 'right' => $this->rMargin,
  20044. 'top' => $this->tMargin,
  20045. 'bottom' => $this->bMargin,
  20046. 'header' => $this->header_margin,
  20047. 'footer' => $this->footer_margin,
  20048. 'cell' => $this->cell_padding,
  20049. 'padding_left' => $this->cell_padding['L'],
  20050. 'padding_top' => $this->cell_padding['T'],
  20051. 'padding_right' => $this->cell_padding['R'],
  20052. 'padding_bottom' => $this->cell_padding['B']
  20053. );
  20054. return $ret;
  20055. }
  20056. /**
  20057. * Returns an array containing original margins:
  20058. * <ul>
  20059. <li>$ret['left'] = left margin</li>
  20060. <li>$ret['right'] = right margin</li>
  20061. * </ul>
  20062. * @return array containing all margins measures
  20063. * @public
  20064. * @since 4.0.012 (2008-07-24)
  20065. */
  20066. public function getOriginalMargins() {
  20067. $ret = array(
  20068. 'left' => $this->original_lMargin,
  20069. 'right' => $this->original_rMargin
  20070. );
  20071. return $ret;
  20072. }
  20073. /**
  20074. * Returns the current font size.
  20075. * @return current font size
  20076. * @public
  20077. * @since 3.2.000 (2008-06-23)
  20078. */
  20079. public function getFontSize() {
  20080. return $this->FontSize;
  20081. }
  20082. /**
  20083. * Returns the current font size in points unit.
  20084. * @return current font size in points unit
  20085. * @public
  20086. * @since 3.2.000 (2008-06-23)
  20087. */
  20088. public function getFontSizePt() {
  20089. return $this->FontSizePt;
  20090. }
  20091. /**
  20092. * Returns the current font family name.
  20093. * @return string current font family name
  20094. * @public
  20095. * @since 4.3.008 (2008-12-05)
  20096. */
  20097. public function getFontFamily() {
  20098. return $this->FontFamily;
  20099. }
  20100. /**
  20101. * Returns the current font style.
  20102. * @return string current font style
  20103. * @public
  20104. * @since 4.3.008 (2008-12-05)
  20105. */
  20106. public function getFontStyle() {
  20107. return $this->FontStyle;
  20108. }
  20109. /**
  20110. * Cleanup HTML code (requires HTML Tidy library).
  20111. * @param $html (string) htmlcode to fix
  20112. * @param $default_css (string) CSS commands to add
  20113. * @param $tagvs (array) parameters for setHtmlVSpace method
  20114. * @param $tidy_options (array) options for tidy_parse_string function
  20115. * @return string XHTML code cleaned up
  20116. * @author Nicola Asuni
  20117. * @public
  20118. * @since 5.9.017 (2010-11-16)
  20119. * @see setHtmlVSpace()
  20120. */
  20121. public function fixHTMLCode($html, $default_css='', $tagvs='', $tidy_options='') {
  20122. // configure parameters for HTML Tidy
  20123. if ($tidy_options === '') {
  20124. $tidy_options = array (
  20125. 'clean' => 1,
  20126. 'drop-empty-paras' => 0,
  20127. 'drop-proprietary-attributes' => 1,
  20128. 'fix-backslash' => 1,
  20129. 'hide-comments' => 1,
  20130. 'join-styles' => 1,
  20131. 'lower-literals' => 1,
  20132. 'merge-divs' => 1,
  20133. 'merge-spans' => 1,
  20134. 'output-xhtml' => 1,
  20135. 'word-2000' => 1,
  20136. 'wrap' => 0,
  20137. 'output-bom' => 0,
  20138. //'char-encoding' => 'utf8',
  20139. //'input-encoding' => 'utf8',
  20140. //'output-encoding' => 'utf8'
  20141. );
  20142. }
  20143. // clean up the HTML code
  20144. $tidy = tidy_parse_string($html, $tidy_options);
  20145. // fix the HTML
  20146. $tidy->cleanRepair();
  20147. // get the CSS part
  20148. $tidy_head = tidy_get_head($tidy);
  20149. $css = $tidy_head->value;
  20150. $css = preg_replace('/<style([^>]+)>/ims', '<style>', $css);
  20151. $css = preg_replace('/<\/style>(.*)<style>/ims', "\n", $css);
  20152. $css = str_replace('/*<![CDATA[*/', '', $css);
  20153. $css = str_replace('/*]]>*/', '', $css);
  20154. preg_match('/<style>(.*)<\/style>/ims', $css, $matches);
  20155. if (isset($matches[1])) {
  20156. $css = strtolower($matches[1]);
  20157. } else {
  20158. $css = '';
  20159. }
  20160. // include default css
  20161. $css = '<style>'.$default_css.$css.'</style>';
  20162. // get the body part
  20163. $tidy_body = tidy_get_body($tidy);
  20164. $html = $tidy_body->value;
  20165. // fix some self-closing tags
  20166. $html = str_replace('<br>', '<br />', $html);
  20167. // remove some empty tag blocks
  20168. $html = preg_replace('/<div([^\>]*)><\/div>/', '', $html);
  20169. $html = preg_replace('/<p([^\>]*)><\/p>/', '', $html);
  20170. if ($tagvs !== '') {
  20171. // set vertical space for some XHTML tags
  20172. $this->setHtmlVSpace($tagvs);
  20173. }
  20174. // return the cleaned XHTML code + CSS
  20175. return $css.$html;
  20176. }
  20177. /**
  20178. * Extracts the CSS properties from a CSS string.
  20179. * @param $cssdata (string) string containing CSS definitions.
  20180. * @return An array where the keys are the CSS selectors and the values are the CSS properties.
  20181. * @author Nicola Asuni
  20182. * @since 5.1.000 (2010-05-25)
  20183. * @protected
  20184. */
  20185. protected function extractCSSproperties($cssdata) {
  20186. if (empty($cssdata)) {
  20187. return array();
  20188. }
  20189. // remove comments
  20190. $cssdata = preg_replace('/\/\*[^\*]*\*\//', '', $cssdata);
  20191. // remove newlines and multiple spaces
  20192. $cssdata = preg_replace('/[\s]+/', ' ', $cssdata);
  20193. // remove some spaces
  20194. $cssdata = preg_replace('/[\s]*([;:\{\}]{1})[\s]*/', '\\1', $cssdata);
  20195. // remove empty blocks
  20196. $cssdata = preg_replace('/([^\}\{]+)\{\}/', '', $cssdata);
  20197. // replace media type parenthesis
  20198. $cssdata = preg_replace('/@media[\s]+([^\{]*)\{/i', '@media \\1§', $cssdata);
  20199. $cssdata = preg_replace('/\}\}/si', '}§', $cssdata);
  20200. // trim string
  20201. $cssdata = trim($cssdata);
  20202. // find media blocks (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  20203. $cssblocks = array();
  20204. $matches = array();
  20205. if (preg_match_all('/@media[\s]+([^\§]*)§([^§]*)§/i', $cssdata, $matches) > 0) {
  20206. foreach ($matches[1] as $key => $type) {
  20207. $cssblocks[$type] = $matches[2][$key];
  20208. }
  20209. // remove media blocks
  20210. $cssdata = preg_replace('/@media[\s]+([^\§]*)§([^§]*)§/i', '', $cssdata);
  20211. }
  20212. // keep 'all' and 'print' media, other media types are discarded
  20213. if (isset($cssblocks['all']) AND !empty($cssblocks['all'])) {
  20214. $cssdata .= $cssblocks['all'];
  20215. }
  20216. if (isset($cssblocks['print']) AND !empty($cssblocks['print'])) {
  20217. $cssdata .= $cssblocks['print'];
  20218. }
  20219. // reset css blocks array
  20220. $cssblocks = array();
  20221. $matches = array();
  20222. // explode css data string into array
  20223. if (substr($cssdata, -1) == '}') {
  20224. // remove last parethesis
  20225. $cssdata = substr($cssdata, 0, -1);
  20226. }
  20227. $matches = explode('}', $cssdata);
  20228. foreach ($matches as $key => $block) {
  20229. // index 0 contains the CSS selector, index 1 contains CSS properties
  20230. $cssblocks[$key] = explode('{', $block);
  20231. if (!isset($cssblocks[$key][1])) {
  20232. // remove empty definitions
  20233. unset($cssblocks[$key]);
  20234. }
  20235. }
  20236. // split groups of selectors (comma-separated list of selectors)
  20237. foreach ($cssblocks as $key => $block) {
  20238. if (strpos($block[0], ',') > 0) {
  20239. $selectors = explode(',', $block[0]);
  20240. foreach ($selectors as $sel) {
  20241. $cssblocks[] = array(0 => trim($sel), 1 => $block[1]);
  20242. }
  20243. unset($cssblocks[$key]);
  20244. }
  20245. }
  20246. // covert array to selector => properties
  20247. $cssdata = array();
  20248. foreach ($cssblocks as $block) {
  20249. $selector = $block[0];
  20250. // calculate selector's specificity
  20251. $matches = array();
  20252. $a = 0; // the declaration is not from is a 'style' attribute
  20253. $b = intval(preg_match_all('/[\#]/', $selector, $matches)); // number of ID attributes
  20254. $c = intval(preg_match_all('/[\[\.]/', $selector, $matches)); // number of other attributes
  20255. $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
  20256. $d = intval(preg_match_all('/[\>\+\~\s]{1}[a-zA-Z0-9]+/', ' '.$selector, $matches)); // number of element names
  20257. $d += intval(preg_match_all('/[\:][\:]/', $selector, $matches)); // number of pseudo-elements
  20258. $specificity = $a.$b.$c.$d;
  20259. // add specificity to the beginning of the selector
  20260. $cssdata[$specificity.' '.$selector] = $block[1];
  20261. }
  20262. // sort selectors alphabetically to account for specificity
  20263. ksort($cssdata, SORT_STRING);
  20264. // return array
  20265. return $cssdata;
  20266. }
  20267. /**
  20268. * Returns true if the CSS selector is valid for the selected HTML tag
  20269. * @param $dom (array) array of HTML tags and properties
  20270. * @param $key (int) key of the current HTML tag
  20271. * @param $selector (string) CSS selector string
  20272. * @return true if the selector is valid, false otherwise
  20273. * @protected
  20274. * @since 5.1.000 (2010-05-25)
  20275. */
  20276. protected function isValidCSSSelectorForTag($dom, $key, $selector) {
  20277. $valid = false; // value to be returned
  20278. $tag = $dom[$key]['value'];
  20279. $class = array();
  20280. if (isset($dom[$key]['attribute']['class']) AND !empty($dom[$key]['attribute']['class'])) {
  20281. $class = explode(' ', strtolower($dom[$key]['attribute']['class']));
  20282. }
  20283. $id = '';
  20284. if (isset($dom[$key]['attribute']['id']) AND !empty($dom[$key]['attribute']['id'])) {
  20285. $id = strtolower($dom[$key]['attribute']['id']);
  20286. }
  20287. $selector = preg_replace('/([\>\+\~\s]{1})([\.]{1})([^\>\+\~\s]*)/si', '\\1*.\\3', $selector);
  20288. $matches = array();
  20289. if (preg_match_all('/([\>\+\~\s]{1})([a-zA-Z0-9\*]+)([^\>\+\~\s]*)/si', $selector, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) > 0) {
  20290. $parentop = array_pop($matches[1]);
  20291. $operator = $parentop[0];
  20292. $offset = $parentop[1];
  20293. $lasttag = array_pop($matches[2]);
  20294. $lasttag = strtolower(trim($lasttag[0]));
  20295. if (($lasttag == '*') OR ($lasttag == $tag)) {
  20296. // the last element on selector is our tag or 'any tag'
  20297. $attrib = array_pop($matches[3]);
  20298. $attrib = strtolower(trim($attrib[0]));
  20299. if (!empty($attrib)) {
  20300. // check if matches class, id, attribute, pseudo-class or pseudo-element
  20301. switch ($attrib{0}) {
  20302. case '.': { // class
  20303. if (in_array(substr($attrib, 1), $class)) {
  20304. $valid = true;
  20305. }
  20306. break;
  20307. }
  20308. case '#': { // ID
  20309. if (substr($attrib, 1) == $id) {
  20310. $valid = true;
  20311. }
  20312. break;
  20313. }
  20314. case '[': { // attribute
  20315. $attrmatch = array();
  20316. if (preg_match('/\[([a-zA-Z0-9]*)[\s]*([\~\^\$\*\|\=]*)[\s]*["]?([^"\]]*)["]?\]/i', $attrib, $attrmatch) > 0) {
  20317. $att = strtolower($attrmatch[1]);
  20318. $val = $attrmatch[3];
  20319. if (isset($dom[$key]['attribute'][$att])) {
  20320. switch ($attrmatch[2]) {
  20321. case '=': {
  20322. if ($dom[$key]['attribute'][$att] == $val) {
  20323. $valid = true;
  20324. }
  20325. break;
  20326. }
  20327. case '~=': {
  20328. if (in_array($val, explode(' ', $dom[$key]['attribute'][$att]))) {
  20329. $valid = true;
  20330. }
  20331. break;
  20332. }
  20333. case '^=': {
  20334. if ($val == substr($dom[$key]['attribute'][$att], 0, strlen($val))) {
  20335. $valid = true;
  20336. }
  20337. break;
  20338. }
  20339. case '$=': {
  20340. if ($val == substr($dom[$key]['attribute'][$att], -strlen($val))) {
  20341. $valid = true;
  20342. }
  20343. break;
  20344. }
  20345. case '*=': {
  20346. if (strpos($dom[$key]['attribute'][$att], $val) !== false) {
  20347. $valid = true;
  20348. }
  20349. break;
  20350. }
  20351. case '|=': {
  20352. if ($dom[$key]['attribute'][$att] == $val) {
  20353. $valid = true;
  20354. } elseif (preg_match('/'.$val.'[\-]{1}/i', $dom[$key]['attribute'][$att]) > 0) {
  20355. $valid = true;
  20356. }
  20357. break;
  20358. }
  20359. default: {
  20360. $valid = true;
  20361. }
  20362. }
  20363. }
  20364. }
  20365. break;
  20366. }
  20367. case ':': { // pseudo-class or pseudo-element
  20368. if ($attrib{1} == ':') { // pseudo-element
  20369. // pseudo-elements are not supported!
  20370. // (::first-line, ::first-letter, ::before, ::after)
  20371. } else { // pseudo-class
  20372. // pseudo-classes are not supported!
  20373. // (: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)
  20374. }
  20375. break;
  20376. }
  20377. } // end of switch
  20378. } else {
  20379. $valid = true;
  20380. }
  20381. if ($valid AND ($offset > 0)) {
  20382. $valid = false;
  20383. // check remaining selector part
  20384. $selector = substr($selector, 0, $offset);
  20385. switch ($operator) {
  20386. case ' ': { // descendant of an element
  20387. while ($dom[$key]['parent'] > 0) {
  20388. if ($this->isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector)) {
  20389. $valid = true;
  20390. break;
  20391. } else {
  20392. $key = $dom[$key]['parent'];
  20393. }
  20394. }
  20395. break;
  20396. }
  20397. case '>': { // child of an element
  20398. $valid = $this->isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector);
  20399. break;
  20400. }
  20401. case '+': { // immediately preceded by an element
  20402. for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) {
  20403. if ($dom[$i]['tag'] AND $dom[$i]['opening']) {
  20404. $valid = $this->isValidCSSSelectorForTag($dom, $i, $selector);
  20405. break;
  20406. }
  20407. }
  20408. break;
  20409. }
  20410. case '~': { // preceded by an element
  20411. for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) {
  20412. if ($dom[$i]['tag'] AND $dom[$i]['opening']) {
  20413. if ($this->isValidCSSSelectorForTag($dom, $i, $selector)) {
  20414. break;
  20415. }
  20416. }
  20417. }
  20418. break;
  20419. }
  20420. }
  20421. }
  20422. }
  20423. }
  20424. return $valid;
  20425. }
  20426. /**
  20427. * Returns the styles array that apply for the selected HTML tag.
  20428. * @param $dom (array) array of HTML tags and properties
  20429. * @param $key (int) key of the current HTML tag
  20430. * @param $css (array) array of CSS properties
  20431. * @return array containing CSS properties
  20432. * @protected
  20433. * @since 5.1.000 (2010-05-25)
  20434. */
  20435. protected function getCSSdataArray($dom, $key, $css) {
  20436. $cssarray = array(); // style to be returned
  20437. // get parent CSS selectors
  20438. $selectors = array();
  20439. if (isset($dom[($dom[$key]['parent'])]['csssel'])) {
  20440. $selectors = $dom[($dom[$key]['parent'])]['csssel'];
  20441. }
  20442. // get all styles that apply
  20443. foreach($css as $selector => $style) {
  20444. $pos = strpos($selector, ' ');
  20445. // get specificity
  20446. $specificity = substr($selector, 0, $pos);
  20447. // remove specificity
  20448. $selector = substr($selector, $pos);
  20449. // check if this selector apply to current tag
  20450. if ($this->isValidCSSSelectorForTag($dom, $key, $selector)) {
  20451. if (!in_array($selector, $selectors)) {
  20452. // add style if not already added on parent selector
  20453. $cssarray[] = array('k' => $selector, 's' => $specificity, 'c' => $style);
  20454. $selectors[] = $selector;
  20455. }
  20456. }
  20457. }
  20458. if (isset($dom[$key]['attribute']['style'])) {
  20459. // attach inline style (latest properties have high priority)
  20460. $cssarray[] = array('k' => '', 's' => '1000', 'c' => $dom[$key]['attribute']['style']);
  20461. }
  20462. // order the css array to account for specificity
  20463. $cssordered = array();
  20464. foreach ($cssarray as $key => $val) {
  20465. $skey = sprintf('%04d', $key);
  20466. $cssordered[$val['s'].'_'.$skey] = $val;
  20467. }
  20468. // sort selectors alphabetically to account for specificity
  20469. ksort($cssordered, SORT_STRING);
  20470. return array($selectors, $cssordered);
  20471. }
  20472. /**
  20473. * Compact CSS data array into single string.
  20474. * @param $css (array) array of CSS properties
  20475. * @return string containing merged CSS properties
  20476. * @protected
  20477. * @since 5.9.070 (2011-04-19)
  20478. */
  20479. protected function getTagStyleFromCSSarray($css) {
  20480. $tagstyle = ''; // value to be returned
  20481. foreach ($css as $style) {
  20482. // split single css commands
  20483. $csscmds = explode(';', $style['c']);
  20484. foreach ($csscmds as $cmd) {
  20485. if (!empty($cmd)) {
  20486. $pos = strpos($cmd, ':');
  20487. if ($pos !== false) {
  20488. $cmd = substr($cmd, 0, ($pos + 1));
  20489. if (strpos($tagstyle, $cmd) !== false) {
  20490. // remove duplicate commands (last commands have high priority)
  20491. $tagstyle = preg_replace('/'.$cmd.'[^;]+/i', '', $tagstyle);
  20492. }
  20493. }
  20494. }
  20495. }
  20496. $tagstyle .= ';'.$style['c'];
  20497. }
  20498. // remove multiple semicolons
  20499. $tagstyle = preg_replace('/[;]+/', ';', $tagstyle);
  20500. return $tagstyle;
  20501. }
  20502. /**
  20503. * Returns the border width from CSS property
  20504. * @param $width (string) border width
  20505. * @return int with in user units
  20506. * @protected
  20507. * @since 5.7.000 (2010-08-02)
  20508. */
  20509. protected function getCSSBorderWidth($width) {
  20510. if ($width == 'thin') {
  20511. $width = (2 / $this->k);
  20512. } elseif ($width == 'medium') {
  20513. $width = (4 / $this->k);
  20514. } elseif ($width == 'thick') {
  20515. $width = (6 / $this->k);
  20516. } else {
  20517. $width = $this->getHTMLUnitToUnits($width, 1, 'px', false);
  20518. }
  20519. return $width;
  20520. }
  20521. /**
  20522. * Returns the border dash style from CSS property
  20523. * @param $style (string) border style to convert
  20524. * @return int sash style (return -1 in case of none or hidden border)
  20525. * @protected
  20526. * @since 5.7.000 (2010-08-02)
  20527. */
  20528. protected function getCSSBorderDashStyle($style) {
  20529. switch (strtolower($style)) {
  20530. case 'none':
  20531. case 'hidden': {
  20532. $dash = -1;
  20533. break;
  20534. }
  20535. case 'dotted': {
  20536. $dash = 1;
  20537. break;
  20538. }
  20539. case 'dashed': {
  20540. $dash = 3;
  20541. break;
  20542. }
  20543. case 'double':
  20544. case 'groove':
  20545. case 'ridge':
  20546. case 'inset':
  20547. case 'outset':
  20548. case 'solid':
  20549. default: {
  20550. $dash = 0;
  20551. break;
  20552. }
  20553. }
  20554. return $dash;
  20555. }
  20556. /**
  20557. * Returns the border style array from CSS border properties
  20558. * @param $cssborder (string) border properties
  20559. * @return array containing border properties
  20560. * @protected
  20561. * @since 5.7.000 (2010-08-02)
  20562. */
  20563. protected function getCSSBorderStyle($cssborder) {
  20564. $bprop = preg_split('/[\s]+/', trim($cssborder));
  20565. $border = array(); // value to be returned
  20566. switch (count($bprop)) {
  20567. case 3: {
  20568. $width = $bprop[0];
  20569. $style = $bprop[1];
  20570. $color = $bprop[2];
  20571. break;
  20572. }
  20573. case 2: {
  20574. $width = 'medium';
  20575. $style = $bprop[0];
  20576. $color = $bprop[1];
  20577. break;
  20578. }
  20579. case 1: {
  20580. $width = 'medium';
  20581. $style = $bprop[0];
  20582. $color = 'black';
  20583. break;
  20584. }
  20585. default: {
  20586. $width = 'medium';
  20587. $style = 'solid';
  20588. $color = 'black';
  20589. break;
  20590. }
  20591. }
  20592. if ($style == 'none') {
  20593. return array();
  20594. }
  20595. $border['cap'] = 'square';
  20596. $border['join'] = 'miter';
  20597. $border['dash'] = $this->getCSSBorderDashStyle($style);
  20598. if ($border['dash'] < 0) {
  20599. return array();
  20600. }
  20601. $border['width'] = $this->getCSSBorderWidth($width);
  20602. $border['color'] = $this->convertHTMLColorToDec($color);
  20603. return $border;
  20604. }
  20605. /**
  20606. * Get the internal Cell padding from CSS attribute.
  20607. * @param $csspadding (string) padding properties
  20608. * @param $width (float) width of the containing element
  20609. * @return array of cell paddings
  20610. * @public
  20611. * @since 5.9.000 (2010-10-04)
  20612. */
  20613. public function getCSSPadding($csspadding, $width=0) {
  20614. $padding = preg_split('/[\s]+/', trim($csspadding));
  20615. $cell_padding = array(); // value to be returned
  20616. switch (count($padding)) {
  20617. case 4: {
  20618. $cell_padding['T'] = $padding[0];
  20619. $cell_padding['R'] = $padding[1];
  20620. $cell_padding['B'] = $padding[2];
  20621. $cell_padding['L'] = $padding[3];
  20622. break;
  20623. }
  20624. case 3: {
  20625. $cell_padding['T'] = $padding[0];
  20626. $cell_padding['R'] = $padding[1];
  20627. $cell_padding['B'] = $padding[2];
  20628. $cell_padding['L'] = $padding[1];
  20629. break;
  20630. }
  20631. case 2: {
  20632. $cell_padding['T'] = $padding[0];
  20633. $cell_padding['R'] = $padding[1];
  20634. $cell_padding['B'] = $padding[0];
  20635. $cell_padding['L'] = $padding[1];
  20636. break;
  20637. }
  20638. case 1: {
  20639. $cell_padding['T'] = $padding[0];
  20640. $cell_padding['R'] = $padding[0];
  20641. $cell_padding['B'] = $padding[0];
  20642. $cell_padding['L'] = $padding[0];
  20643. break;
  20644. }
  20645. default: {
  20646. return $this->cell_padding;
  20647. }
  20648. }
  20649. if ($width == 0) {
  20650. $width = $this->w - $this->lMargin - $this->rMargin;
  20651. }
  20652. $cell_padding['T'] = $this->getHTMLUnitToUnits($cell_padding['T'], $width, 'px', false);
  20653. $cell_padding['R'] = $this->getHTMLUnitToUnits($cell_padding['R'], $width, 'px', false);
  20654. $cell_padding['B'] = $this->getHTMLUnitToUnits($cell_padding['B'], $width, 'px', false);
  20655. $cell_padding['L'] = $this->getHTMLUnitToUnits($cell_padding['L'], $width, 'px', false);
  20656. return $cell_padding;
  20657. }
  20658. /**
  20659. * Get the internal Cell margin from CSS attribute.
  20660. * @param $cssmargin (string) margin properties
  20661. * @param $width (float) width of the containing element
  20662. * @return array of cell margins
  20663. * @public
  20664. * @since 5.9.000 (2010-10-04)
  20665. */
  20666. public function getCSSMargin($cssmargin, $width=0) {
  20667. $margin = preg_split('/[\s]+/', trim($cssmargin));
  20668. $cell_margin = array(); // value to be returned
  20669. switch (count($margin)) {
  20670. case 4: {
  20671. $cell_margin['T'] = $margin[0];
  20672. $cell_margin['R'] = $margin[1];
  20673. $cell_margin['B'] = $margin[2];
  20674. $cell_margin['L'] = $margin[3];
  20675. break;
  20676. }
  20677. case 3: {
  20678. $cell_margin['T'] = $margin[0];
  20679. $cell_margin['R'] = $margin[1];
  20680. $cell_margin['B'] = $margin[2];
  20681. $cell_margin['L'] = $margin[1];
  20682. break;
  20683. }
  20684. case 2: {
  20685. $cell_margin['T'] = $margin[0];
  20686. $cell_margin['R'] = $margin[1];
  20687. $cell_margin['B'] = $margin[0];
  20688. $cell_margin['L'] = $margin[1];
  20689. break;
  20690. }
  20691. case 1: {
  20692. $cell_margin['T'] = $margin[0];
  20693. $cell_margin['R'] = $margin[0];
  20694. $cell_margin['B'] = $margin[0];
  20695. $cell_margin['L'] = $margin[0];
  20696. break;
  20697. }
  20698. default: {
  20699. return $this->cell_margin;
  20700. }
  20701. }
  20702. if ($width == 0) {
  20703. $width = $this->w - $this->lMargin - $this->rMargin;
  20704. }
  20705. $cell_margin['T'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['T']), $width, 'px', false);
  20706. $cell_margin['R'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['R']), $width, 'px', false);
  20707. $cell_margin['B'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['B']), $width, 'px', false);
  20708. $cell_margin['L'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['L']), $width, 'px', false);
  20709. return $cell_margin;
  20710. }
  20711. /**
  20712. * Get the border-spacing from CSS attribute.
  20713. * @param $cssbspace (string) border-spacing CSS properties
  20714. * @param $width (float) width of the containing element
  20715. * @return array of border spacings
  20716. * @public
  20717. * @since 5.9.010 (2010-10-27)
  20718. */
  20719. public function getCSSBorderMargin($cssbspace, $width=0) {
  20720. $space = preg_split('/[\s]+/', trim($cssbspace));
  20721. $border_spacing = array(); // value to be returned
  20722. switch (count($space)) {
  20723. case 2: {
  20724. $border_spacing['H'] = $space[0];
  20725. $border_spacing['V'] = $space[1];
  20726. break;
  20727. }
  20728. case 1: {
  20729. $border_spacing['H'] = $space[0];
  20730. $border_spacing['V'] = $space[0];
  20731. break;
  20732. }
  20733. default: {
  20734. return array('H' => 0, 'V' => 0);
  20735. }
  20736. }
  20737. if ($width == 0) {
  20738. $width = $this->w - $this->lMargin - $this->rMargin;
  20739. }
  20740. $border_spacing['H'] = $this->getHTMLUnitToUnits($border_spacing['H'], $width, 'px', false);
  20741. $border_spacing['V'] = $this->getHTMLUnitToUnits($border_spacing['V'], $width, 'px', false);
  20742. return $border_spacing;
  20743. }
  20744. /**
  20745. * Returns the letter-spacing value from CSS value
  20746. * @param $spacing (string) letter-spacing value
  20747. * @param $parent (float) font spacing (tracking) value of the parent element
  20748. * @return float quantity to increases or decreases the space between characters in a text.
  20749. * @protected
  20750. * @since 5.9.000 (2010-10-02)
  20751. */
  20752. protected function getCSSFontSpacing($spacing, $parent=0) {
  20753. $val = 0; // value to be returned
  20754. $spacing = trim($spacing);
  20755. switch ($spacing) {
  20756. case 'normal': {
  20757. $val = 0;
  20758. break;
  20759. }
  20760. case 'inherit': {
  20761. if ($parent == 'normal') {
  20762. $val = 0;
  20763. } else {
  20764. $val = $parent;
  20765. }
  20766. break;
  20767. }
  20768. default: {
  20769. $val = $this->getHTMLUnitToUnits($spacing, 0, 'px', false);
  20770. }
  20771. }
  20772. return $val;
  20773. }
  20774. /**
  20775. * Returns the percentage of font stretching from CSS value
  20776. * @param $stretch (string) stretch mode
  20777. * @param $parent (float) stretch value of the parent element
  20778. * @return float font stretching percentage
  20779. * @protected
  20780. * @since 5.9.000 (2010-10-02)
  20781. */
  20782. protected function getCSSFontStretching($stretch, $parent=100) {
  20783. $val = 100; // value to be returned
  20784. $stretch = trim($stretch);
  20785. switch ($stretch) {
  20786. case 'ultra-condensed': {
  20787. $val = 40;
  20788. break;
  20789. }
  20790. case 'extra-condensed': {
  20791. $val = 55;
  20792. break;
  20793. }
  20794. case 'condensed': {
  20795. $val = 70;
  20796. break;
  20797. }
  20798. case 'semi-condensed': {
  20799. $val = 85;
  20800. break;
  20801. }
  20802. case 'normal': {
  20803. $val = 100;
  20804. break;
  20805. }
  20806. case 'semi-expanded': {
  20807. $val = 115;
  20808. break;
  20809. }
  20810. case 'expanded': {
  20811. $val = 130;
  20812. break;
  20813. }
  20814. case 'extra-expanded': {
  20815. $val = 145;
  20816. break;
  20817. }
  20818. case 'ultra-expanded': {
  20819. $val = 160;
  20820. break;
  20821. }
  20822. case 'wider': {
  20823. $val = $parent + 10;
  20824. break;
  20825. }
  20826. case 'narrower': {
  20827. $val = $parent - 10;
  20828. break;
  20829. }
  20830. case 'inherit': {
  20831. if ($parent == 'normal') {
  20832. $val = 100;
  20833. } else {
  20834. $val = $parent;
  20835. }
  20836. break;
  20837. }
  20838. default: {
  20839. $val = $this->getHTMLUnitToUnits($stretch, 100, '%', false);
  20840. }
  20841. }
  20842. return $val;
  20843. }
  20844. /**
  20845. * Returns the HTML DOM array.
  20846. * @param $html (string) html code
  20847. * @return array
  20848. * @protected
  20849. * @since 3.2.000 (2008-06-20)
  20850. */
  20851. protected function getHtmlDomArray($html) {
  20852. // array of CSS styles ( selector => properties).
  20853. $css = array();
  20854. // get CSS array defined at previous call
  20855. $matches = array();
  20856. if (preg_match_all('/<cssarray>([^\<]*)<\/cssarray>/isU', $html, $matches) > 0) {
  20857. if (isset($matches[1][0])) {
  20858. $css = array_merge($css, unserialize($this->unhtmlentities($matches[1][0])));
  20859. }
  20860. $html = preg_replace('/<cssarray>(.*?)<\/cssarray>/isU', '', $html);
  20861. }
  20862. // extract external CSS files
  20863. $matches = array();
  20864. if (preg_match_all('/<link([^\>]*)>/isU', $html, $matches) > 0) {
  20865. foreach ($matches[1] as $key => $link) {
  20866. $type = array();
  20867. if (preg_match('/type[\s]*=[\s]*"text\/css"/', $link, $type)) {
  20868. $type = array();
  20869. preg_match('/media[\s]*=[\s]*"([^"]*)"/', $link, $type);
  20870. // get 'all' and 'print' media, other media types are discarded
  20871. // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  20872. if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
  20873. $type = array();
  20874. if (preg_match('/href[\s]*=[\s]*"([^"]*)"/', $link, $type) > 0) {
  20875. // read CSS data file
  20876. $cssdata = file_get_contents(trim($type[1]));
  20877. $css = array_merge($css, $this->extractCSSproperties($cssdata));
  20878. }
  20879. }
  20880. }
  20881. }
  20882. }
  20883. // extract style tags
  20884. $matches = array();
  20885. if (preg_match_all('/<style([^\>]*)>([^\<]*)<\/style>/isU', $html, $matches) > 0) {
  20886. foreach ($matches[1] as $key => $media) {
  20887. $type = array();
  20888. preg_match('/media[\s]*=[\s]*"([^"]*)"/', $media, $type);
  20889. // get 'all' and 'print' media, other media types are discarded
  20890. // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  20891. if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
  20892. $cssdata = $matches[2][$key];
  20893. $css = array_merge($css, $this->extractCSSproperties($cssdata));
  20894. }
  20895. }
  20896. }
  20897. // create a special tag to contain the CSS array (used for table content)
  20898. $csstagarray = '<cssarray>'.htmlentities(serialize($css)).'</cssarray>';
  20899. // remove head and style blocks
  20900. $html = preg_replace('/<head([^\>]*)>(.*?)<\/head>/siU', '', $html);
  20901. $html = preg_replace('/<style([^\>]*)>([^\<]*)<\/style>/isU', '', $html);
  20902. // define block tags
  20903. $blocktags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table','tr','td');
  20904. // define self-closing tags
  20905. $selfclosingtags = array('area','base','basefont','br','hr','input','img','link','meta');
  20906. // remove all unsupported tags (the line below lists all supported tags)
  20907. $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>');
  20908. //replace some blank characters
  20909. $html = preg_replace('/<pre/', '<xre', $html); // preserve pre tag
  20910. $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);
  20911. $html = preg_replace('@(\r\n|\r)@', "\n", $html);
  20912. $repTable = array("\t" => ' ', "\0" => ' ', "\x0B" => ' ', "\\" => "\\\\");
  20913. $html = strtr($html, $repTable);
  20914. $offset = 0;
  20915. while (($offset < strlen($html)) AND ($pos = strpos($html, '</pre>', $offset)) !== false) {
  20916. $html_a = substr($html, 0, $offset);
  20917. $html_b = substr($html, $offset, ($pos - $offset + 6));
  20918. while (preg_match("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", $html_b)) {
  20919. // preserve newlines on <pre> tag
  20920. $html_b = preg_replace("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", "<xre\\1>\\2<br />\\3</pre>", $html_b);
  20921. }
  20922. while (preg_match("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], $html_b)) {
  20923. // preserve spaces on <pre> tag
  20924. $html_b = preg_replace("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], "<xre\\1>\\2&nbsp;\\3</pre>", $html_b);
  20925. }
  20926. $html = $html_a.$html_b.substr($html, $pos + 6);
  20927. $offset = strlen($html_a.$html_b);
  20928. }
  20929. $offset = 0;
  20930. while (($offset < strlen($html)) AND ($pos = strpos($html, '</textarea>', $offset)) !== false) {
  20931. $html_a = substr($html, 0, $offset);
  20932. $html_b = substr($html, $offset, ($pos - $offset + 11));
  20933. while (preg_match("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", $html_b)) {
  20934. // preserve newlines on <textarea> tag
  20935. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", "<textarea\\1>\\2<TBR>\\3</textarea>", $html_b);
  20936. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)[\"](.*?)</textarea>'si", "<textarea\\1>\\2''\\3</textarea>", $html_b);
  20937. }
  20938. $html = $html_a.$html_b.substr($html, $pos + 11);
  20939. $offset = strlen($html_a.$html_b);
  20940. }
  20941. $html = preg_replace('/([\s]*)<option/si', '<option', $html);
  20942. $html = preg_replace('/<\/option>([\s]*)/si', '</option>', $html);
  20943. $offset = 0;
  20944. while (($offset < strlen($html)) AND ($pos = strpos($html, '</option>', $offset)) !== false) {
  20945. $html_a = substr($html, 0, $offset);
  20946. $html_b = substr($html, $offset, ($pos - $offset + 9));
  20947. while (preg_match("'<option([^\>]*)>(.*?)</option>'si", $html_b)) {
  20948. $html_b = preg_replace("'<option([\s]+)value=\"([^\"]*)\"([^\>]*)>(.*?)</option>'si", "\\2#!TaB!#\\4#!NwL!#", $html_b);
  20949. $html_b = preg_replace("'<option([^\>]*)>(.*?)</option>'si", "\\2#!NwL!#", $html_b);
  20950. }
  20951. $html = $html_a.$html_b.substr($html, $pos + 9);
  20952. $offset = strlen($html_a.$html_b);
  20953. }
  20954. if (preg_match("'</select'si", $html)) {
  20955. $html = preg_replace("'<select([^\>]*)>'si", "<select\\1 opt=\"", $html);
  20956. $html = preg_replace("'#!NwL!#</select>'si", "\" />", $html);
  20957. }
  20958. $html = str_replace("\n", ' ', $html);
  20959. // restore textarea newlines
  20960. $html = str_replace('<TBR>', "\n", $html);
  20961. // remove extra spaces from code
  20962. $html = preg_replace('/[\s]+<\/(table|tr|ul|ol|dl)>/', '</\\1>', $html);
  20963. $html = preg_replace('/'.$this->re_space['p'].'+<\/(td|th|li|dt|dd)>/'.$this->re_space['m'], '</\\1>', $html);
  20964. $html = preg_replace('/[\s]+<(tr|td|th|li|dt|dd)/', '<\\1', $html);
  20965. $html = preg_replace('/'.$this->re_space['p'].'+<(ul|ol|dl|br)/'.$this->re_space['m'], '<\\1', $html);
  20966. $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);
  20967. $html = preg_replace('/<\/(td|th)>/', '<marker style="font-size:0"/></\\1>', $html);
  20968. $html = preg_replace('/<\/table>([\s]*)<marker style="font-size:0"\/>/', '</table>', $html);
  20969. $html = preg_replace('/'.$this->re_space['p'].'+<img/'.$this->re_space['m'], chr(32).'<img', $html);
  20970. $html = preg_replace('/<img([^\>]*)>[\s]+([^\<])/xi', '<img\\1>&nbsp;\\2', $html);
  20971. $html = preg_replace('/<img([^\>]*)>/xi', '<img\\1><span><marker style="font-size:0"/></span>', $html);
  20972. $html = preg_replace('/<xre/', '<pre', $html); // restore pre tag
  20973. $html = preg_replace('/<textarea([^\>]*)>([^\<]*)<\/textarea>/xi', '<textarea\\1 value="\\2" />', $html);
  20974. $html = preg_replace('/<li([^\>]*)><\/li>/', '<li\\1>&nbsp;</li>', $html);
  20975. $html = preg_replace('/<li([^\>]*)>'.$this->re_space['p'].'*<img/'.$this->re_space['m'], '<li\\1><font size="1">&nbsp;</font><img', $html);
  20976. $html = preg_replace('/<([^\>\/]*)>[\s]/', '<\\1>&nbsp;', $html); // preserve some spaces
  20977. $html = preg_replace('/[\s]<\/([^\>]*)>/', '&nbsp;</\\1>', $html); // preserve some spaces
  20978. $html = preg_replace('/<su([bp])/', '<zws/><su\\1', $html); // fix sub/sup alignment
  20979. $html = preg_replace('/<\/su([bp])>/', '</su\\1><zws/>', $html); // fix sub/sup alignment
  20980. $html = preg_replace('/'.$this->re_space['p'].'+/'.$this->re_space['m'], chr(32), $html); // replace multiple spaces with a single space
  20981. // trim string
  20982. $html = $this->stringTrim($html);
  20983. // fix first image tag alignment
  20984. $html = preg_replace('/^<img/', '<span style="font-size:0"><br /></span> <img', $html, 1);
  20985. // pattern for generic tag
  20986. $tagpattern = '/(<[^>]+>)/';
  20987. // explodes the string
  20988. $a = preg_split($tagpattern, $html, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  20989. // count elements
  20990. $maxel = count($a);
  20991. $elkey = 0;
  20992. $key = 0;
  20993. // create an array of elements
  20994. $dom = array();
  20995. $dom[$key] = array();
  20996. // set inheritable properties fot the first void element
  20997. // 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
  20998. $dom[$key]['tag'] = false;
  20999. $dom[$key]['block'] = false;
  21000. $dom[$key]['value'] = '';
  21001. $dom[$key]['parent'] = 0;
  21002. $dom[$key]['hide'] = false;
  21003. $dom[$key]['fontname'] = $this->FontFamily;
  21004. $dom[$key]['fontstyle'] = $this->FontStyle;
  21005. $dom[$key]['fontsize'] = $this->FontSizePt;
  21006. $dom[$key]['font-stretch'] = $this->font_stretching;
  21007. $dom[$key]['letter-spacing'] = $this->font_spacing;
  21008. $dom[$key]['stroke'] = $this->textstrokewidth;
  21009. $dom[$key]['fill'] = (($this->textrendermode % 2) == 0);
  21010. $dom[$key]['clip'] = ($this->textrendermode > 3);
  21011. $dom[$key]['line-height'] = $this->cell_height_ratio;
  21012. $dom[$key]['bgcolor'] = false;
  21013. $dom[$key]['fgcolor'] = $this->fgcolor; // color
  21014. $dom[$key]['strokecolor'] = $this->strokecolor;
  21015. $dom[$key]['align'] = '';
  21016. $dom[$key]['listtype'] = '';
  21017. $dom[$key]['text-indent'] = 0;
  21018. $dom[$key]['border'] = array();
  21019. $dom[$key]['dir'] = $this->rtl?'rtl':'ltr';
  21020. $thead = false; // true when we are inside the THEAD tag
  21021. ++$key;
  21022. $level = array();
  21023. array_push($level, 0); // root
  21024. while ($elkey < $maxel) {
  21025. $dom[$key] = array();
  21026. $element = $a[$elkey];
  21027. $dom[$key]['elkey'] = $elkey;
  21028. if (preg_match($tagpattern, $element)) {
  21029. // html tag
  21030. $element = substr($element, 1, -1);
  21031. // get tag name
  21032. preg_match('/[\/]?([a-zA-Z0-9]*)/', $element, $tag);
  21033. $tagname = strtolower($tag[1]);
  21034. // check if we are inside a table header
  21035. if ($tagname == 'thead') {
  21036. if ($element{0} == '/') {
  21037. $thead = false;
  21038. } else {
  21039. $thead = true;
  21040. }
  21041. ++$elkey;
  21042. continue;
  21043. }
  21044. $dom[$key]['tag'] = true;
  21045. $dom[$key]['value'] = $tagname;
  21046. if (in_array($dom[$key]['value'], $blocktags)) {
  21047. $dom[$key]['block'] = true;
  21048. } else {
  21049. $dom[$key]['block'] = false;
  21050. }
  21051. if ($element{0} == '/') {
  21052. // *** closing html tag
  21053. $dom[$key]['opening'] = false;
  21054. $dom[$key]['parent'] = end($level);
  21055. array_pop($level);
  21056. $dom[$key]['hide'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['hide'];
  21057. $dom[$key]['fontname'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontname'];
  21058. $dom[$key]['fontstyle'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontstyle'];
  21059. $dom[$key]['fontsize'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize'];
  21060. $dom[$key]['font-stretch'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['font-stretch'];
  21061. $dom[$key]['letter-spacing'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['letter-spacing'];
  21062. $dom[$key]['stroke'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['stroke'];
  21063. $dom[$key]['fill'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fill'];
  21064. $dom[$key]['clip'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['clip'];
  21065. $dom[$key]['line-height'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['line-height'];
  21066. $dom[$key]['bgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor'];
  21067. $dom[$key]['fgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor'];
  21068. $dom[$key]['strokecolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['strokecolor'];
  21069. $dom[$key]['align'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['align'];
  21070. $dom[$key]['dir'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['dir'];
  21071. if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) {
  21072. $dom[$key]['listtype'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'];
  21073. }
  21074. // set the number of columns in table tag
  21075. if (($dom[$key]['value'] == 'tr') AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) {
  21076. $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'] = $dom[($dom[$key]['parent'])]['cols'];
  21077. }
  21078. if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  21079. $dom[($dom[$key]['parent'])]['content'] = $csstagarray;
  21080. for ($i = ($dom[$key]['parent'] + 1); $i < $key; ++$i) {
  21081. $dom[($dom[$key]['parent'])]['content'] .= $a[$dom[$i]['elkey']];
  21082. }
  21083. $key = $i;
  21084. // mark nested tables
  21085. $dom[($dom[$key]['parent'])]['content'] = str_replace('<table', '<table nested="true"', $dom[($dom[$key]['parent'])]['content']);
  21086. // remove thead sections from nested tables
  21087. $dom[($dom[$key]['parent'])]['content'] = str_replace('<thead>', '', $dom[($dom[$key]['parent'])]['content']);
  21088. $dom[($dom[$key]['parent'])]['content'] = str_replace('</thead>', '', $dom[($dom[$key]['parent'])]['content']);
  21089. }
  21090. // store header rows on a new table
  21091. if (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['thead'] === true)) {
  21092. if ($this->empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) {
  21093. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] = $csstagarray.$a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']];
  21094. }
  21095. for ($i = $dom[$key]['parent']; $i <= $key; ++$i) {
  21096. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] .= $a[$dom[$i]['elkey']];
  21097. }
  21098. if (!isset($dom[($dom[$key]['parent'])]['attribute'])) {
  21099. $dom[($dom[$key]['parent'])]['attribute'] = array();
  21100. }
  21101. // header elements must be always contained in a single page
  21102. $dom[($dom[$key]['parent'])]['attribute']['nobr'] = 'true';
  21103. }
  21104. if (($dom[$key]['value'] == 'table') AND (!$this->empty_string($dom[($dom[$key]['parent'])]['thead']))) {
  21105. // remove the nobr attributes from the table header
  21106. $dom[($dom[$key]['parent'])]['thead'] = str_replace(' nobr="true"', '', $dom[($dom[$key]['parent'])]['thead']);
  21107. $dom[($dom[$key]['parent'])]['thead'] .= '</tablehead>';
  21108. }
  21109. } else {
  21110. // *** opening or self-closing html tag
  21111. $dom[$key]['opening'] = true;
  21112. $dom[$key]['parent'] = end($level);
  21113. if ((substr($element, -1, 1) == '/') OR (in_array($dom[$key]['value'], $selfclosingtags))) {
  21114. // self-closing tag
  21115. $dom[$key]['self'] = true;
  21116. } else {
  21117. // opening tag
  21118. array_push($level, $key);
  21119. $dom[$key]['self'] = false;
  21120. }
  21121. // copy some values from parent
  21122. $parentkey = 0;
  21123. if ($key > 0) {
  21124. $parentkey = $dom[$key]['parent'];
  21125. $dom[$key]['hide'] = $dom[$parentkey]['hide'];
  21126. $dom[$key]['fontname'] = $dom[$parentkey]['fontname'];
  21127. $dom[$key]['fontstyle'] = $dom[$parentkey]['fontstyle'];
  21128. $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'];
  21129. $dom[$key]['font-stretch'] = $dom[$parentkey]['font-stretch'];
  21130. $dom[$key]['letter-spacing'] = $dom[$parentkey]['letter-spacing'];
  21131. $dom[$key]['stroke'] = $dom[$parentkey]['stroke'];
  21132. $dom[$key]['fill'] = $dom[$parentkey]['fill'];
  21133. $dom[$key]['clip'] = $dom[$parentkey]['clip'];
  21134. $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
  21135. $dom[$key]['bgcolor'] = $dom[$parentkey]['bgcolor'];
  21136. $dom[$key]['fgcolor'] = $dom[$parentkey]['fgcolor'];
  21137. $dom[$key]['strokecolor'] = $dom[$parentkey]['strokecolor'];
  21138. $dom[$key]['align'] = $dom[$parentkey]['align'];
  21139. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  21140. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  21141. $dom[$key]['border'] = array();
  21142. $dom[$key]['dir'] = $dom[$parentkey]['dir'];
  21143. }
  21144. // get attributes
  21145. preg_match_all('/([^=\s]*)[\s]*=[\s]*"([^"]*)"/', $element, $attr_array, PREG_PATTERN_ORDER);
  21146. $dom[$key]['attribute'] = array(); // reset attribute array
  21147. while (list($id, $name) = each($attr_array[1])) {
  21148. $dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id];
  21149. }
  21150. if (!empty($css)) {
  21151. // merge CSS style to current style
  21152. list($dom[$key]['csssel'], $dom[$key]['cssdata']) = $this->getCSSdataArray($dom, $key, $css);
  21153. $dom[$key]['attribute']['style'] = $this->getTagStyleFromCSSarray($dom[$key]['cssdata']);
  21154. }
  21155. // split style attributes
  21156. if (isset($dom[$key]['attribute']['style']) AND !empty($dom[$key]['attribute']['style'])) {
  21157. // get style attributes
  21158. preg_match_all('/([^;:\s]*):([^;]*)/', $dom[$key]['attribute']['style'], $style_array, PREG_PATTERN_ORDER);
  21159. $dom[$key]['style'] = array(); // reset style attribute array
  21160. while (list($id, $name) = each($style_array[1])) {
  21161. // in case of duplicate attribute the last replace the previous
  21162. $dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]);
  21163. }
  21164. // --- get some style attributes ---
  21165. // text direction
  21166. if (isset($dom[$key]['style']['direction'])) {
  21167. $dom[$key]['dir'] = $dom[$key]['style']['direction'];
  21168. }
  21169. // display
  21170. if (isset($dom[$key]['style']['display'])) {
  21171. $dom[$key]['hide'] = (trim(strtolower($dom[$key]['style']['display'])) == 'none');
  21172. }
  21173. // font family
  21174. if (isset($dom[$key]['style']['font-family'])) {
  21175. $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['style']['font-family']);
  21176. }
  21177. // list-style-type
  21178. if (isset($dom[$key]['style']['list-style-type'])) {
  21179. $dom[$key]['listtype'] = trim(strtolower($dom[$key]['style']['list-style-type']));
  21180. if ($dom[$key]['listtype'] == 'inherit') {
  21181. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  21182. }
  21183. }
  21184. // text-indent
  21185. if (isset($dom[$key]['style']['text-indent'])) {
  21186. $dom[$key]['text-indent'] = $this->getHTMLUnitToUnits($dom[$key]['style']['text-indent']);
  21187. if ($dom[$key]['text-indent'] == 'inherit') {
  21188. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  21189. }
  21190. }
  21191. // font size
  21192. if (isset($dom[$key]['style']['font-size'])) {
  21193. $fsize = trim($dom[$key]['style']['font-size']);
  21194. switch ($fsize) {
  21195. // absolute-size
  21196. case 'xx-small': {
  21197. $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 4;
  21198. break;
  21199. }
  21200. case 'x-small': {
  21201. $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 3;
  21202. break;
  21203. }
  21204. case 'small': {
  21205. $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 2;
  21206. break;
  21207. }
  21208. case 'medium': {
  21209. $dom[$key]['fontsize'] = $dom[0]['fontsize'];
  21210. break;
  21211. }
  21212. case 'large': {
  21213. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 2;
  21214. break;
  21215. }
  21216. case 'x-large': {
  21217. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 4;
  21218. break;
  21219. }
  21220. case 'xx-large': {
  21221. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 6;
  21222. break;
  21223. }
  21224. // relative-size
  21225. case 'smaller': {
  21226. $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'] - 3;
  21227. break;
  21228. }
  21229. case 'larger': {
  21230. $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'] + 3;
  21231. break;
  21232. }
  21233. default: {
  21234. $dom[$key]['fontsize'] = $this->getHTMLUnitToUnits($fsize, $dom[$parentkey]['fontsize'], 'pt', true);
  21235. }
  21236. }
  21237. }
  21238. // font-stretch
  21239. if (isset($dom[$key]['style']['font-stretch'])) {
  21240. $dom[$key]['font-stretch'] = $this->getCSSFontStretching($dom[$key]['style']['font-stretch'], $dom[$parentkey]['font-stretch']);
  21241. }
  21242. // letter-spacing
  21243. if (isset($dom[$key]['style']['letter-spacing'])) {
  21244. $dom[$key]['letter-spacing'] = $this->getCSSFontSpacing($dom[$key]['style']['letter-spacing'], $dom[$parentkey]['letter-spacing']);
  21245. }
  21246. // line-height
  21247. if (isset($dom[$key]['style']['line-height'])) {
  21248. $lineheight = trim($dom[$key]['style']['line-height']);
  21249. switch ($lineheight) {
  21250. // A normal line height. This is default
  21251. case 'normal': {
  21252. $dom[$key]['line-height'] = $dom[0]['line-height'];
  21253. break;
  21254. }
  21255. default: {
  21256. if (is_numeric($lineheight)) {
  21257. $lineheight = $lineheight * 100;
  21258. }
  21259. $dom[$key]['line-height'] = $this->getHTMLUnitToUnits($lineheight, 1, '%', true);
  21260. }
  21261. }
  21262. }
  21263. // font style
  21264. if (isset($dom[$key]['style']['font-weight'])) {
  21265. if (strtolower($dom[$key]['style']['font-weight']{0}) == 'n') {
  21266. if (strpos($dom[$key]['fontstyle'], 'B') !== false) {
  21267. $dom[$key]['fontstyle'] = str_replace('B', '', $dom[$key]['fontstyle']);
  21268. }
  21269. } elseif (strtolower($dom[$key]['style']['font-weight']{0}) == 'b') {
  21270. $dom[$key]['fontstyle'] .= 'B';
  21271. }
  21272. }
  21273. if (isset($dom[$key]['style']['font-style']) AND (strtolower($dom[$key]['style']['font-style']{0}) == 'i')) {
  21274. $dom[$key]['fontstyle'] .= 'I';
  21275. }
  21276. // font color
  21277. if (isset($dom[$key]['style']['color']) AND (!$this->empty_string($dom[$key]['style']['color']))) {
  21278. $dom[$key]['fgcolor'] = $this->convertHTMLColorToDec($dom[$key]['style']['color']);
  21279. } elseif ($dom[$key]['value'] == 'a') {
  21280. $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  21281. }
  21282. // background color
  21283. if (isset($dom[$key]['style']['background-color']) AND (!$this->empty_string($dom[$key]['style']['background-color']))) {
  21284. $dom[$key]['bgcolor'] = $this->convertHTMLColorToDec($dom[$key]['style']['background-color']);
  21285. }
  21286. // text-decoration
  21287. if (isset($dom[$key]['style']['text-decoration'])) {
  21288. $decors = explode(' ', strtolower($dom[$key]['style']['text-decoration']));
  21289. foreach ($decors as $dec) {
  21290. $dec = trim($dec);
  21291. if (!$this->empty_string($dec)) {
  21292. if ($dec{0} == 'u') {
  21293. // underline
  21294. $dom[$key]['fontstyle'] .= 'U';
  21295. } elseif ($dec{0} == 'l') {
  21296. // line-trough
  21297. $dom[$key]['fontstyle'] .= 'D';
  21298. } elseif ($dec{0} == 'o') {
  21299. // overline
  21300. $dom[$key]['fontstyle'] .= 'O';
  21301. }
  21302. }
  21303. }
  21304. } elseif ($dom[$key]['value'] == 'a') {
  21305. $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  21306. }
  21307. // check for width attribute
  21308. if (isset($dom[$key]['style']['width'])) {
  21309. $dom[$key]['width'] = $dom[$key]['style']['width'];
  21310. }
  21311. // check for height attribute
  21312. if (isset($dom[$key]['style']['height'])) {
  21313. $dom[$key]['height'] = $dom[$key]['style']['height'];
  21314. }
  21315. // check for text alignment
  21316. if (isset($dom[$key]['style']['text-align'])) {
  21317. $dom[$key]['align'] = strtoupper($dom[$key]['style']['text-align']{0});
  21318. }
  21319. // check for CSS border properties
  21320. if (isset($dom[$key]['style']['border'])) {
  21321. $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border']);
  21322. if (!empty($borderstyle)) {
  21323. $dom[$key]['border']['LTRB'] = $borderstyle;
  21324. }
  21325. }
  21326. if (isset($dom[$key]['style']['border-color'])) {
  21327. $brd_colors = preg_split('/[\s]+/', trim($dom[$key]['style']['border-color']));
  21328. if (isset($brd_colors[3])) {
  21329. $dom[$key]['border']['L']['color'] = $this->convertHTMLColorToDec($brd_colors[3]);
  21330. }
  21331. if (isset($brd_colors[1])) {
  21332. $dom[$key]['border']['R']['color'] = $this->convertHTMLColorToDec($brd_colors[1]);
  21333. }
  21334. if (isset($brd_colors[0])) {
  21335. $dom[$key]['border']['T']['color'] = $this->convertHTMLColorToDec($brd_colors[0]);
  21336. }
  21337. if (isset($brd_colors[2])) {
  21338. $dom[$key]['border']['B']['color'] = $this->convertHTMLColorToDec($brd_colors[2]);
  21339. }
  21340. }
  21341. if (isset($dom[$key]['style']['border-width'])) {
  21342. $brd_widths = preg_split('/[\s]+/', trim($dom[$key]['style']['border-width']));
  21343. if (isset($brd_widths[3])) {
  21344. $dom[$key]['border']['L']['width'] = $this->getCSSBorderWidth($brd_widths[3]);
  21345. }
  21346. if (isset($brd_widths[1])) {
  21347. $dom[$key]['border']['R']['width'] = $this->getCSSBorderWidth($brd_widths[1]);
  21348. }
  21349. if (isset($brd_widths[0])) {
  21350. $dom[$key]['border']['T']['width'] = $this->getCSSBorderWidth($brd_widths[0]);
  21351. }
  21352. if (isset($brd_widths[2])) {
  21353. $dom[$key]['border']['B']['width'] = $this->getCSSBorderWidth($brd_widths[2]);
  21354. }
  21355. }
  21356. if (isset($dom[$key]['style']['border-style'])) {
  21357. $brd_styles = preg_split('/[\s]+/', trim($dom[$key]['style']['border-style']));
  21358. if (isset($brd_styles[3]) AND ($brd_styles[3]!='none')) {
  21359. $dom[$key]['border']['L']['cap'] = 'square';
  21360. $dom[$key]['border']['L']['join'] = 'miter';
  21361. $dom[$key]['border']['L']['dash'] = $this->getCSSBorderDashStyle($brd_styles[3]);
  21362. if ($dom[$key]['border']['L']['dash'] < 0) {
  21363. $dom[$key]['border']['L'] = array();
  21364. }
  21365. }
  21366. if (isset($brd_styles[1])) {
  21367. $dom[$key]['border']['R']['cap'] = 'square';
  21368. $dom[$key]['border']['R']['join'] = 'miter';
  21369. $dom[$key]['border']['R']['dash'] = $this->getCSSBorderDashStyle($brd_styles[1]);
  21370. if ($dom[$key]['border']['R']['dash'] < 0) {
  21371. $dom[$key]['border']['R'] = array();
  21372. }
  21373. }
  21374. if (isset($brd_styles[0])) {
  21375. $dom[$key]['border']['T']['cap'] = 'square';
  21376. $dom[$key]['border']['T']['join'] = 'miter';
  21377. $dom[$key]['border']['T']['dash'] = $this->getCSSBorderDashStyle($brd_styles[0]);
  21378. if ($dom[$key]['border']['T']['dash'] < 0) {
  21379. $dom[$key]['border']['T'] = array();
  21380. }
  21381. }
  21382. if (isset($brd_styles[2])) {
  21383. $dom[$key]['border']['B']['cap'] = 'square';
  21384. $dom[$key]['border']['B']['join'] = 'miter';
  21385. $dom[$key]['border']['B']['dash'] = $this->getCSSBorderDashStyle($brd_styles[2]);
  21386. if ($dom[$key]['border']['B']['dash'] < 0) {
  21387. $dom[$key]['border']['B'] = array();
  21388. }
  21389. }
  21390. }
  21391. $cellside = array('L' => 'left', 'R' => 'right', 'T' => 'top', 'B' => 'bottom');
  21392. foreach ($cellside as $bsk => $bsv) {
  21393. if (isset($dom[$key]['style']['border-'.$bsv])) {
  21394. $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border-'.$bsv]);
  21395. if (!empty($borderstyle)) {
  21396. $dom[$key]['border'][$bsk] = $borderstyle;
  21397. }
  21398. }
  21399. if (isset($dom[$key]['style']['border-'.$bsv.'-color'])) {
  21400. $dom[$key]['border'][$bsk]['color'] = $this->convertHTMLColorToDec($dom[$key]['style']['border-'.$bsv.'-color']);
  21401. }
  21402. if (isset($dom[$key]['style']['border-'.$bsv.'-width'])) {
  21403. $dom[$key]['border'][$bsk]['width'] = $this->getCSSBorderWidth($dom[$key]['style']['border-'.$bsv.'-width']);
  21404. }
  21405. if (isset($dom[$key]['style']['border-'.$bsv.'-style'])) {
  21406. $dom[$key]['border'][$bsk]['dash'] = $this->getCSSBorderDashStyle($dom[$key]['style']['border-'.$bsv.'-style']);
  21407. if ($dom[$key]['border'][$bsk]['dash'] < 0) {
  21408. $dom[$key]['border'][$bsk] = array();
  21409. }
  21410. }
  21411. }
  21412. // check for CSS padding properties
  21413. if (isset($dom[$key]['style']['padding'])) {
  21414. $dom[$key]['padding'] = $this->getCSSPadding($dom[$key]['style']['padding']);
  21415. } else {
  21416. $dom[$key]['padding'] = $this->cell_padding;
  21417. }
  21418. foreach ($cellside as $psk => $psv) {
  21419. if (isset($dom[$key]['style']['padding-'.$psv])) {
  21420. $dom[$key]['padding'][$psk] = $this->getHTMLUnitToUnits($dom[$key]['style']['padding-'.$psv], 0, 'px', false);
  21421. }
  21422. }
  21423. // check for CSS margin properties
  21424. if (isset($dom[$key]['style']['margin'])) {
  21425. $dom[$key]['margin'] = $this->getCSSMargin($dom[$key]['style']['margin']);
  21426. } else {
  21427. $dom[$key]['margin'] = $this->cell_margin;
  21428. }
  21429. foreach ($cellside as $psk => $psv) {
  21430. if (isset($dom[$key]['style']['margin-'.$psv])) {
  21431. $dom[$key]['margin'][$psk] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $dom[$key]['style']['margin-'.$psv]), 0, 'px', false);
  21432. }
  21433. }
  21434. // check for CSS border-spacing properties
  21435. if (isset($dom[$key]['style']['border-spacing'])) {
  21436. $dom[$key]['border-spacing'] = $this->getCSSBorderMargin($dom[$key]['style']['border-spacing']);
  21437. }
  21438. // page-break-inside
  21439. if (isset($dom[$key]['style']['page-break-inside']) AND ($dom[$key]['style']['page-break-inside'] == 'avoid')) {
  21440. $dom[$key]['attribute']['nobr'] = 'true';
  21441. }
  21442. // page-break-before
  21443. if (isset($dom[$key]['style']['page-break-before'])) {
  21444. if ($dom[$key]['style']['page-break-before'] == 'always') {
  21445. $dom[$key]['attribute']['pagebreak'] = 'true';
  21446. } elseif ($dom[$key]['style']['page-break-before'] == 'left') {
  21447. $dom[$key]['attribute']['pagebreak'] = 'left';
  21448. } elseif ($dom[$key]['style']['page-break-before'] == 'right') {
  21449. $dom[$key]['attribute']['pagebreak'] = 'right';
  21450. }
  21451. }
  21452. // page-break-after
  21453. if (isset($dom[$key]['style']['page-break-after'])) {
  21454. if ($dom[$key]['style']['page-break-after'] == 'always') {
  21455. $dom[$key]['attribute']['pagebreakafter'] = 'true';
  21456. } elseif ($dom[$key]['style']['page-break-after'] == 'left') {
  21457. $dom[$key]['attribute']['pagebreakafter'] = 'left';
  21458. } elseif ($dom[$key]['style']['page-break-after'] == 'right') {
  21459. $dom[$key]['attribute']['pagebreakafter'] = 'right';
  21460. }
  21461. }
  21462. }
  21463. if (isset($dom[$key]['attribute']['display'])) {
  21464. $dom[$key]['hide'] = (trim(strtolower($dom[$key]['attribute']['display'])) == 'none');
  21465. }
  21466. if (isset($dom[$key]['attribute']['border']) AND ($dom[$key]['attribute']['border'] != 0)) {
  21467. $borderstyle = $this->getCSSBorderStyle($dom[$key]['attribute']['border'].' solid black');
  21468. if (!empty($borderstyle)) {
  21469. $dom[$key]['border']['LTRB'] = $borderstyle;
  21470. }
  21471. }
  21472. // check for font tag
  21473. if ($dom[$key]['value'] == 'font') {
  21474. // font family
  21475. if (isset($dom[$key]['attribute']['face'])) {
  21476. $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['attribute']['face']);
  21477. }
  21478. // font size
  21479. if (isset($dom[$key]['attribute']['size'])) {
  21480. if ($key > 0) {
  21481. if ($dom[$key]['attribute']['size']{0} == '+') {
  21482. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] + intval(substr($dom[$key]['attribute']['size'], 1));
  21483. } elseif ($dom[$key]['attribute']['size']{0} == '-') {
  21484. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] - intval(substr($dom[$key]['attribute']['size'], 1));
  21485. } else {
  21486. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  21487. }
  21488. } else {
  21489. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  21490. }
  21491. }
  21492. }
  21493. // force natural alignment for lists
  21494. if ((($dom[$key]['value'] == 'ul') OR ($dom[$key]['value'] == 'ol') OR ($dom[$key]['value'] == 'dl'))
  21495. AND (!isset($dom[$key]['align']) OR $this->empty_string($dom[$key]['align']) OR ($dom[$key]['align'] != 'J'))) {
  21496. if ($this->rtl) {
  21497. $dom[$key]['align'] = 'R';
  21498. } else {
  21499. $dom[$key]['align'] = 'L';
  21500. }
  21501. }
  21502. if (($dom[$key]['value'] == 'small') OR ($dom[$key]['value'] == 'sup') OR ($dom[$key]['value'] == 'sub')) {
  21503. if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
  21504. $dom[$key]['fontsize'] = $dom[$key]['fontsize'] * K_SMALL_RATIO;
  21505. }
  21506. }
  21507. if (($dom[$key]['value'] == 'strong') OR ($dom[$key]['value'] == 'b')) {
  21508. $dom[$key]['fontstyle'] .= 'B';
  21509. }
  21510. if (($dom[$key]['value'] == 'em') OR ($dom[$key]['value'] == 'i')) {
  21511. $dom[$key]['fontstyle'] .= 'I';
  21512. }
  21513. if ($dom[$key]['value'] == 'u') {
  21514. $dom[$key]['fontstyle'] .= 'U';
  21515. }
  21516. if (($dom[$key]['value'] == 'del') OR ($dom[$key]['value'] == 's') OR ($dom[$key]['value'] == 'strike')) {
  21517. $dom[$key]['fontstyle'] .= 'D';
  21518. }
  21519. if (!isset($dom[$key]['style']['text-decoration']) AND ($dom[$key]['value'] == 'a')) {
  21520. $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  21521. }
  21522. if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) {
  21523. $dom[$key]['fontname'] = $this->default_monospaced_font;
  21524. }
  21525. if (($dom[$key]['value']{0} == 'h') AND (intval($dom[$key]['value']{1}) > 0) AND (intval($dom[$key]['value']{1}) < 7)) {
  21526. // headings h1, h2, h3, h4, h5, h6
  21527. if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
  21528. $headsize = (4 - intval($dom[$key]['value']{1})) * 2;
  21529. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + $headsize;
  21530. }
  21531. if (!isset($dom[$key]['style']['font-weight'])) {
  21532. $dom[$key]['fontstyle'] .= 'B';
  21533. }
  21534. }
  21535. if (($dom[$key]['value'] == 'table')) {
  21536. $dom[$key]['rows'] = 0; // number of rows
  21537. $dom[$key]['trids'] = array(); // IDs of TR elements
  21538. $dom[$key]['thead'] = ''; // table header rows
  21539. }
  21540. if (($dom[$key]['value'] == 'tr')) {
  21541. $dom[$key]['cols'] = 0;
  21542. if ($thead) {
  21543. $dom[$key]['thead'] = true;
  21544. // rows on thead block are printed as a separate table
  21545. } else {
  21546. $dom[$key]['thead'] = false;
  21547. // store the number of rows on table element
  21548. ++$dom[($dom[$key]['parent'])]['rows'];
  21549. // store the TR elements IDs on table element
  21550. array_push($dom[($dom[$key]['parent'])]['trids'], $key);
  21551. }
  21552. }
  21553. if (($dom[$key]['value'] == 'th') OR ($dom[$key]['value'] == 'td')) {
  21554. if (isset($dom[$key]['attribute']['colspan'])) {
  21555. $colspan = intval($dom[$key]['attribute']['colspan']);
  21556. } else {
  21557. $colspan = 1;
  21558. }
  21559. $dom[$key]['attribute']['colspan'] = $colspan;
  21560. $dom[($dom[$key]['parent'])]['cols'] += $colspan;
  21561. }
  21562. // text direction
  21563. if (isset($dom[$key]['attribute']['dir'])) {
  21564. $dom[$key]['dir'] = $dom[$key]['attribute']['dir'];
  21565. }
  21566. // set foreground color attribute
  21567. if (isset($dom[$key]['attribute']['color']) AND (!$this->empty_string($dom[$key]['attribute']['color']))) {
  21568. $dom[$key]['fgcolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['color']);
  21569. } elseif (!isset($dom[$key]['style']['color']) AND ($dom[$key]['value'] == 'a')) {
  21570. $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  21571. }
  21572. // set background color attribute
  21573. if (isset($dom[$key]['attribute']['bgcolor']) AND (!$this->empty_string($dom[$key]['attribute']['bgcolor']))) {
  21574. $dom[$key]['bgcolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['bgcolor']);
  21575. }
  21576. // set stroke color attribute
  21577. if (isset($dom[$key]['attribute']['strokecolor']) AND (!$this->empty_string($dom[$key]['attribute']['strokecolor']))) {
  21578. $dom[$key]['strokecolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['strokecolor']);
  21579. }
  21580. // check for width attribute
  21581. if (isset($dom[$key]['attribute']['width'])) {
  21582. $dom[$key]['width'] = $dom[$key]['attribute']['width'];
  21583. }
  21584. // check for height attribute
  21585. if (isset($dom[$key]['attribute']['height'])) {
  21586. $dom[$key]['height'] = $dom[$key]['attribute']['height'];
  21587. }
  21588. // check for text alignment
  21589. if (isset($dom[$key]['attribute']['align']) AND (!$this->empty_string($dom[$key]['attribute']['align'])) AND ($dom[$key]['value'] !== 'img')) {
  21590. $dom[$key]['align'] = strtoupper($dom[$key]['attribute']['align']{0});
  21591. }
  21592. // check for text rendering mode (the following attributes do not exist in HTML)
  21593. if (isset($dom[$key]['attribute']['stroke'])) {
  21594. // font stroke width
  21595. $dom[$key]['stroke'] = $this->getHTMLUnitToUnits($dom[$key]['attribute']['stroke'], $dom[$key]['fontsize'], 'pt', true);
  21596. }
  21597. if (isset($dom[$key]['attribute']['fill'])) {
  21598. // font fill
  21599. if ($dom[$key]['attribute']['fill'] == 'true') {
  21600. $dom[$key]['fill'] = true;
  21601. } else {
  21602. $dom[$key]['fill'] = false;
  21603. }
  21604. }
  21605. if (isset($dom[$key]['attribute']['clip'])) {
  21606. // clipping mode
  21607. if ($dom[$key]['attribute']['clip'] == 'true') {
  21608. $dom[$key]['clip'] = true;
  21609. } else {
  21610. $dom[$key]['clip'] = false;
  21611. }
  21612. }
  21613. } // end opening tag
  21614. } else {
  21615. // text
  21616. $dom[$key]['tag'] = false;
  21617. $dom[$key]['block'] = false;
  21618. //$element = str_replace('&nbsp;', $this->unichr(160), $element);
  21619. $dom[$key]['value'] = stripslashes($this->unhtmlentities($element));
  21620. $dom[$key]['parent'] = end($level);
  21621. $dom[$key]['dir'] = $dom[$dom[$key]['parent']]['dir'];
  21622. }
  21623. ++$elkey;
  21624. ++$key;
  21625. }
  21626. return $dom;
  21627. }
  21628. /**
  21629. * Returns the string used to find spaces
  21630. * @return string
  21631. * @protected
  21632. * @author Nicola Asuni
  21633. * @since 4.8.024 (2010-01-15)
  21634. */
  21635. protected function getSpaceString() {
  21636. $spacestr = chr(32);
  21637. if ($this->isUnicodeFont()) {
  21638. $spacestr = chr(0).chr(32);
  21639. }
  21640. return $spacestr;
  21641. }
  21642. /**
  21643. * Prints a cell (rectangular area) with optional borders, background color and html text string.
  21644. * 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 />
  21645. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  21646. * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  21647. * 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
  21648. * NOTE: all the HTML attributes must be enclosed in double-quote.
  21649. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  21650. * @param $h (float) Cell minimum height. The cell extends automatically if needed.
  21651. * @param $x (float) upper-left corner X coordinate
  21652. * @param $y (float) upper-left corner Y coordinate
  21653. * @param $html (string) html text to print. Default value: empty string.
  21654. * @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)))
  21655. * @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>
  21656. Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  21657. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  21658. * @param $reseth (boolean) if true reset the last cell height (default true).
  21659. * @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>
  21660. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width.
  21661. * @see Multicell(), writeHTML()
  21662. * @public
  21663. */
  21664. public function writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true) {
  21665. return $this->MultiCell($w, $h, $html, $border, $align, $fill, $ln, $x, $y, $reseth, 0, true, $autopadding, 0, 'T', false);
  21666. }
  21667. /**
  21668. * Allows to preserve some HTML formatting (limited support).<br />
  21669. * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  21670. * 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
  21671. * NOTE: all the HTML attributes must be enclosed in double-quote.
  21672. * @param $html (string) text to display
  21673. * @param $ln (boolean) if true add a new line after text (default = true)
  21674. * @param $fill (boolean) Indicates if the background must be painted (true) or transparent (false).
  21675. * @param $reseth (boolean) if true reset the last cell height (default false).
  21676. * @param $cell (boolean) if true add the current left (or right for RTL) padding to each Write (default false).
  21677. * @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>
  21678. * @public
  21679. */
  21680. public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='') {
  21681. $gvars = $this->getGraphicVars();
  21682. // store current values
  21683. $prev_cell_margin = $this->cell_margin;
  21684. $prev_cell_padding = $this->cell_padding;
  21685. $prevPage = $this->page;
  21686. $prevlMargin = $this->lMargin;
  21687. $prevrMargin = $this->rMargin;
  21688. $curfontname = $this->FontFamily;
  21689. $curfontstyle = $this->FontStyle;
  21690. $curfontsize = $this->FontSizePt;
  21691. $curfontascent = $this->getFontAscent($curfontname, $curfontstyle, $curfontsize);
  21692. $curfontdescent = $this->getFontDescent($curfontname, $curfontstyle, $curfontsize);
  21693. $curfontstretcing = $this->font_stretching;
  21694. $curfonttracking = $this->font_spacing;
  21695. $this->newline = true;
  21696. $newline = true;
  21697. $startlinepage = $this->page;
  21698. $minstartliney = $this->y;
  21699. $maxbottomliney = 0;
  21700. $startlinex = $this->x;
  21701. $startliney = $this->y;
  21702. $yshift = 0;
  21703. $loop = 0;
  21704. $curpos = 0;
  21705. $this_method_vars = array();
  21706. $undo = false;
  21707. $fontaligned = false;
  21708. $reverse_dir = false; // true when the text direction is reversed
  21709. $this->premode = false;
  21710. if ($this->inxobj) {
  21711. // we are inside an XObject template
  21712. $pask = count($this->xobjects[$this->xobjid]['annotations']);
  21713. } elseif (isset($this->PageAnnots[$this->page])) {
  21714. $pask = count($this->PageAnnots[$this->page]);
  21715. } else {
  21716. $pask = 0;
  21717. }
  21718. if ($this->inxobj) {
  21719. // we are inside an XObject template
  21720. $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
  21721. } elseif (!$this->InFooter) {
  21722. if (isset($this->footerlen[$this->page])) {
  21723. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  21724. } else {
  21725. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  21726. }
  21727. $startlinepos = $this->footerpos[$this->page];
  21728. } else {
  21729. // we are inside the footer
  21730. $startlinepos = $this->pagelen[$this->page];
  21731. }
  21732. $lalign = $align;
  21733. $plalign = $align;
  21734. if ($this->rtl) {
  21735. $w = $this->x - $this->lMargin;
  21736. } else {
  21737. $w = $this->w - $this->rMargin - $this->x;
  21738. }
  21739. $w -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  21740. if ($cell) {
  21741. if ($this->rtl) {
  21742. $this->x -= $this->cell_padding['R'];
  21743. $this->lMargin += $this->cell_padding['R'];
  21744. } else {
  21745. $this->x += $this->cell_padding['L'];
  21746. $this->rMargin += $this->cell_padding['L'];
  21747. }
  21748. }
  21749. if ($this->customlistindent >= 0) {
  21750. $this->listindent = $this->customlistindent;
  21751. } else {
  21752. $this->listindent = $this->GetStringWidth('000000');
  21753. }
  21754. $this->listindentlevel = 0;
  21755. // save previous states
  21756. $prev_cell_height_ratio = $this->cell_height_ratio;
  21757. $prev_listnum = $this->listnum;
  21758. $prev_listordered = $this->listordered;
  21759. $prev_listcount = $this->listcount;
  21760. $prev_lispacer = $this->lispacer;
  21761. $this->listnum = 0;
  21762. $this->listordered = array();
  21763. $this->listcount = array();
  21764. $this->lispacer = '';
  21765. if (($this->empty_string($this->lasth)) OR ($reseth)) {
  21766. // reset row height
  21767. $this->resetLastH();
  21768. }
  21769. $dom = $this->getHtmlDomArray($html);
  21770. $maxel = count($dom);
  21771. $key = 0;
  21772. $hidden_node_key = -1;
  21773. while ($key < $maxel) {
  21774. if ($dom[$key]['tag']) {
  21775. if ($dom[$key]['opening']) {
  21776. if (($hidden_node_key <= 0) AND $dom[$key]['hide']) {
  21777. // store the node key
  21778. $hidden_node_key = $key;
  21779. }
  21780. } elseif (($hidden_node_key > 0) AND ($dom[$key]['parent'] == $hidden_node_key)) {
  21781. // we have reached the closing tag of the hidden node
  21782. $hidden_node_key = 0;
  21783. }
  21784. }
  21785. if ($hidden_node_key >= 0) {
  21786. // skip this node
  21787. ++$key;
  21788. if ($hidden_node_key == 0) {
  21789. // reset hidden mode
  21790. $hidden_node_key = -1;
  21791. }
  21792. continue;
  21793. }
  21794. if ($dom[$key]['tag'] AND isset($dom[$key]['attribute']['pagebreak'])) {
  21795. // check for pagebreak
  21796. if (($dom[$key]['attribute']['pagebreak'] == 'true') OR ($dom[$key]['attribute']['pagebreak'] == 'left') OR ($dom[$key]['attribute']['pagebreak'] == 'right')) {
  21797. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  21798. $this->checkPageBreak($this->PageBreakTrigger + 1);
  21799. $this->htmlvspace = ($this->PageBreakTrigger + 1);
  21800. }
  21801. if ((($dom[$key]['attribute']['pagebreak'] == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  21802. OR (($dom[$key]['attribute']['pagebreak'] == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  21803. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  21804. $this->checkPageBreak($this->PageBreakTrigger + 1);
  21805. $this->htmlvspace = ($this->PageBreakTrigger + 1);
  21806. }
  21807. }
  21808. if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND isset($dom[$key]['attribute']['nobr']) AND ($dom[$key]['attribute']['nobr'] == 'true')) {
  21809. if (isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) {
  21810. $dom[$key]['attribute']['nobr'] = false;
  21811. } else {
  21812. // store current object
  21813. $this->startTransaction();
  21814. // save this method vars
  21815. $this_method_vars['html'] = $html;
  21816. $this_method_vars['ln'] = $ln;
  21817. $this_method_vars['fill'] = $fill;
  21818. $this_method_vars['reseth'] = $reseth;
  21819. $this_method_vars['cell'] = $cell;
  21820. $this_method_vars['align'] = $align;
  21821. $this_method_vars['gvars'] = $gvars;
  21822. $this_method_vars['prevPage'] = $prevPage;
  21823. $this_method_vars['prev_cell_margin'] = $prev_cell_margin;
  21824. $this_method_vars['prev_cell_padding'] = $prev_cell_padding;
  21825. $this_method_vars['prevlMargin'] = $prevlMargin;
  21826. $this_method_vars['prevrMargin'] = $prevrMargin;
  21827. $this_method_vars['curfontname'] = $curfontname;
  21828. $this_method_vars['curfontstyle'] = $curfontstyle;
  21829. $this_method_vars['curfontsize'] = $curfontsize;
  21830. $this_method_vars['curfontascent'] = $curfontascent;
  21831. $this_method_vars['curfontdescent'] = $curfontdescent;
  21832. $this_method_vars['curfontstretcing'] = $curfontstretcing;
  21833. $this_method_vars['curfonttracking'] = $curfonttracking;
  21834. $this_method_vars['minstartliney'] = $minstartliney;
  21835. $this_method_vars['maxbottomliney'] = $maxbottomliney;
  21836. $this_method_vars['yshift'] = $yshift;
  21837. $this_method_vars['startlinepage'] = $startlinepage;
  21838. $this_method_vars['startlinepos'] = $startlinepos;
  21839. $this_method_vars['startlinex'] = $startlinex;
  21840. $this_method_vars['startliney'] = $startliney;
  21841. $this_method_vars['newline'] = $newline;
  21842. $this_method_vars['loop'] = $loop;
  21843. $this_method_vars['curpos'] = $curpos;
  21844. $this_method_vars['pask'] = $pask;
  21845. $this_method_vars['lalign'] = $lalign;
  21846. $this_method_vars['plalign'] = $plalign;
  21847. $this_method_vars['w'] = $w;
  21848. $this_method_vars['prev_cell_height_ratio'] = $prev_cell_height_ratio;
  21849. $this_method_vars['prev_listnum'] = $prev_listnum;
  21850. $this_method_vars['prev_listordered'] = $prev_listordered;
  21851. $this_method_vars['prev_listcount'] = $prev_listcount;
  21852. $this_method_vars['prev_lispacer'] = $prev_lispacer;
  21853. $this_method_vars['fontaligned'] = $fontaligned;
  21854. $this_method_vars['key'] = $key;
  21855. $this_method_vars['dom'] = $dom;
  21856. }
  21857. }
  21858. // print THEAD block
  21859. if (($dom[$key]['value'] == 'tr') AND isset($dom[$key]['thead']) AND $dom[$key]['thead']) {
  21860. if (isset($dom[$key]['parent']) AND isset($dom[$dom[$key]['parent']]['thead']) AND !$this->empty_string($dom[$dom[$key]['parent']]['thead'])) {
  21861. $this->inthead = true;
  21862. // print table header (thead)
  21863. $this->writeHTML($this->thead, false, false, false, false, '');
  21864. // check if we are on a new page or on a new column
  21865. if (($this->y < $this->start_transaction_y) OR ($this->checkPageBreak($this->lasth, '', false))) {
  21866. // we are on a new page or on a new column and the total object height is less than the available vertical space.
  21867. // restore previous object
  21868. $this->rollbackTransaction(true);
  21869. // restore previous values
  21870. foreach ($this_method_vars as $vkey => $vval) {
  21871. $$vkey = $vval;
  21872. }
  21873. // disable table header
  21874. $tmp_thead = $this->thead;
  21875. $this->thead = '';
  21876. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  21877. $pre_y = $this->y;
  21878. if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
  21879. // fix for multicolumn mode
  21880. $startliney = $this->y;
  21881. }
  21882. $this->start_transaction_page = $this->page;
  21883. $this->start_transaction_y = $this->y;
  21884. // restore table header
  21885. $this->thead = $tmp_thead;
  21886. // fix table border properties
  21887. if (isset($dom[$dom[$key]['parent']]['attribute']['cellspacing'])) {
  21888. $tmp_cellspacing = $this->getHTMLUnitToUnits($dom[$dom[$key]['parent']]['attribute']['cellspacing'], 1, 'px');
  21889. } elseif (isset($dom[$dom[$key]['parent']]['border-spacing'])) {
  21890. $tmp_cellspacing = $dom[$dom[$key]['parent']]['border-spacing']['V'];
  21891. } else {
  21892. $tmp_cellspacing = 0;
  21893. }
  21894. $dom[$dom[$key]['parent']]['borderposition']['page'] = $this->page;
  21895. $dom[$dom[$key]['parent']]['borderposition']['column'] = $this->current_column;
  21896. $dom[$dom[$key]['parent']]['borderposition']['y'] = $this->y + $tmp_cellspacing;
  21897. $xoffset = ($this->x - $dom[$dom[$key]['parent']]['borderposition']['x']);
  21898. $dom[$dom[$key]['parent']]['borderposition']['x'] += $xoffset;
  21899. $dom[$dom[$key]['parent']]['borderposition']['xmax'] += $xoffset;
  21900. // print table header (thead)
  21901. $this->writeHTML($this->thead, false, false, false, false, '');
  21902. }
  21903. }
  21904. // move $key index forward to skip THEAD block
  21905. while ( ($key < $maxel) AND (!(
  21906. ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'tr') AND (!isset($dom[$key]['thead']) OR !$dom[$key]['thead']))
  21907. OR ($dom[$key]['tag'] AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == 'table'))) )) {
  21908. ++$key;
  21909. }
  21910. }
  21911. if ($dom[$key]['tag'] OR ($key == 0)) {
  21912. if ((($dom[$key]['value'] == 'table') OR ($dom[$key]['value'] == 'tr')) AND (isset($dom[$key]['align']))) {
  21913. $dom[$key]['align'] = ($this->rtl) ? 'R' : 'L';
  21914. }
  21915. // vertically align image in line
  21916. if ((!$this->newline) AND ($dom[$key]['value'] == 'img') AND (isset($dom[$key]['height'])) AND ($dom[$key]['height'] > 0)) {
  21917. // get image height
  21918. $imgh = $this->getHTMLUnitToUnits($dom[$key]['height'], $this->lasth, 'px');
  21919. $autolinebreak = false;
  21920. if (isset($dom[$key]['width']) AND ($dom[$key]['width'] > 0)) {
  21921. $imgw = $this->getHTMLUnitToUnits($dom[$key]['width'], 1, 'px', false);
  21922. if (($imgw <= ($this->w - $this->lMargin - $this->rMargin - $this->cell_padding['L'] - $this->cell_padding['R']))
  21923. AND ((($this->rtl) AND (($this->x - $imgw) < ($this->lMargin + $this->cell_padding['L'])))
  21924. OR ((!$this->rtl) AND (($this->x + $imgw) > ($this->w - $this->rMargin - $this->cell_padding['R']))))) {
  21925. // add automatic line break
  21926. $autolinebreak = true;
  21927. $this->Ln('', $cell);
  21928. if ((!$dom[($key-1)]['tag']) AND ($dom[($key-1)]['value'] == ' ')) {
  21929. // go back to evaluate this line break
  21930. --$key;
  21931. }
  21932. }
  21933. }
  21934. if (!$autolinebreak) {
  21935. if ($this->inPageBody()) {
  21936. $pre_y = $this->y;
  21937. // check for page break
  21938. if ((!$this->checkPageBreak($imgh)) AND ($this->y < $pre_y)) {
  21939. // fix for multicolumn mode
  21940. $startliney = $this->y;
  21941. }
  21942. }
  21943. if ($this->page > $startlinepage) {
  21944. // fix line splitted over two pages
  21945. if (isset($this->footerlen[$startlinepage])) {
  21946. $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  21947. }
  21948. // line to be moved one page forward
  21949. $pagebuff = $this->getPageBuffer($startlinepage);
  21950. $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
  21951. $tstart = substr($pagebuff, 0, $startlinepos);
  21952. $tend = substr($this->getPageBuffer($startlinepage), $curpos);
  21953. // remove line from previous page
  21954. $this->setPageBuffer($startlinepage, $tstart.''.$tend);
  21955. $pagebuff = $this->getPageBuffer($this->page);
  21956. $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
  21957. $tend = substr($pagebuff, $this->cntmrk[$this->page]);
  21958. // add line start to current page
  21959. $yshift = ($minstartliney - $this->y);
  21960. if ($fontaligned) {
  21961. $yshift += ($curfontsize / $this->k);
  21962. }
  21963. $try = sprintf('1 0 0 1 0 %F cm', ($yshift * $this->k));
  21964. $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  21965. // shift the annotations and links
  21966. if (isset($this->PageAnnots[$this->page])) {
  21967. $next_pask = count($this->PageAnnots[$this->page]);
  21968. } else {
  21969. $next_pask = 0;
  21970. }
  21971. if (isset($this->PageAnnots[$startlinepage])) {
  21972. foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
  21973. if ($pak >= $pask) {
  21974. $this->PageAnnots[$this->page][] = $pac;
  21975. unset($this->PageAnnots[$startlinepage][$pak]);
  21976. $npak = count($this->PageAnnots[$this->page]) - 1;
  21977. $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  21978. }
  21979. }
  21980. }
  21981. $pask = $next_pask;
  21982. $startlinepos = $this->cntmrk[$this->page];
  21983. $startlinepage = $this->page;
  21984. $startliney = $this->y;
  21985. $this->newline = false;
  21986. }
  21987. $this->y += ((($curfontsize * $this->cell_height_ratio / $this->k) + $curfontascent - $curfontdescent) / 2) - $imgh;
  21988. $minstartliney = min($this->y, $minstartliney);
  21989. $maxbottomliney = ($startliney + ($this->FontSize * $this->cell_height_ratio));
  21990. }
  21991. } elseif (isset($dom[$key]['fontname']) OR isset($dom[$key]['fontstyle']) OR isset($dom[$key]['fontsize']) OR isset($dom[$key]['line-height'])) {
  21992. // account for different font size
  21993. $pfontname = $curfontname;
  21994. $pfontstyle = $curfontstyle;
  21995. $pfontsize = $curfontsize;
  21996. $fontname = isset($dom[$key]['fontname']) ? $dom[$key]['fontname'] : $curfontname;
  21997. $fontstyle = isset($dom[$key]['fontstyle']) ? $dom[$key]['fontstyle'] : $curfontstyle;
  21998. $fontsize = isset($dom[$key]['fontsize']) ? $dom[$key]['fontsize'] : $curfontsize;
  21999. $fontascent = $this->getFontAscent($fontname, $fontstyle, $fontsize);
  22000. $fontdescent = $this->getFontDescent($fontname, $fontstyle, $fontsize);
  22001. if (($fontname != $curfontname) OR ($fontstyle != $curfontstyle) OR ($fontsize != $curfontsize)
  22002. OR ($this->cell_height_ratio != $dom[$key]['line-height'])
  22003. OR ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li')) ) {
  22004. if (($key < ($maxel - 1)) AND (
  22005. ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li'))
  22006. OR ($this->cell_height_ratio != $dom[$key]['line-height'])
  22007. OR (!$this->newline AND is_numeric($fontsize) AND is_numeric($curfontsize) AND ($fontsize >= 0) AND ($curfontsize >= 0) AND ($fontsize != $curfontsize))
  22008. )) {
  22009. if ($this->page > $startlinepage) {
  22010. // fix lines splitted over two pages
  22011. if (isset($this->footerlen[$startlinepage])) {
  22012. $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  22013. }
  22014. // line to be moved one page forward
  22015. $pagebuff = $this->getPageBuffer($startlinepage);
  22016. $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
  22017. $tstart = substr($pagebuff, 0, $startlinepos);
  22018. $tend = substr($this->getPageBuffer($startlinepage), $curpos);
  22019. // remove line start from previous page
  22020. $this->setPageBuffer($startlinepage, $tstart.''.$tend);
  22021. $pagebuff = $this->getPageBuffer($this->page);
  22022. $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
  22023. $tend = substr($pagebuff, $this->cntmrk[$this->page]);
  22024. // add line start to current page
  22025. $yshift = ($minstartliney - $this->y);
  22026. $try = sprintf('1 0 0 1 0 %F cm', ($yshift * $this->k));
  22027. $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  22028. // shift the annotations and links
  22029. if (isset($this->PageAnnots[$this->page])) {
  22030. $next_pask = count($this->PageAnnots[$this->page]);
  22031. } else {
  22032. $next_pask = 0;
  22033. }
  22034. if (isset($this->PageAnnots[$startlinepage])) {
  22035. foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
  22036. if ($pak >= $pask) {
  22037. $this->PageAnnots[$this->page][] = $pac;
  22038. unset($this->PageAnnots[$startlinepage][$pak]);
  22039. $npak = count($this->PageAnnots[$this->page]) - 1;
  22040. $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  22041. }
  22042. }
  22043. }
  22044. $pask = $next_pask;
  22045. $startlinepos = $this->cntmrk[$this->page];
  22046. $startlinepage = $this->page;
  22047. $startliney = $this->y;
  22048. }
  22049. if (!isset($dom[$key]['line-height'])) {
  22050. $dom[$key]['line-height'] = $this->cell_height_ratio;
  22051. }
  22052. if (!$dom[$key]['block']) {
  22053. if (!(isset($dom[($key + 1)]) AND $dom[($key + 1)]['tag'] AND (!$dom[($key + 1)]['opening']) AND ($dom[($key + 1)]['value'] != 'li') AND $dom[$key]['tag'] AND (!$dom[$key]['opening']))) {
  22054. $this->y += (((($curfontsize * $this->cell_height_ratio) - ($fontsize * $dom[$key]['line-height'])) / $this->k) + $curfontascent - $fontascent - $curfontdescent + $fontdescent) / 2;
  22055. }
  22056. if (($dom[$key]['value'] != 'sup') AND ($dom[$key]['value'] != 'sub')) {
  22057. $current_line_align_data = array($key, $minstartliney, $maxbottomliney);
  22058. if (isset($line_align_data) AND (($line_align_data[0] == ($key - 1)) OR (($line_align_data[0] == ($key - 2)) AND (isset($dom[($key - 1)])) AND (preg_match('/^([\s]+)$/', $dom[($key - 1)]['value']) > 0)))) {
  22059. $minstartliney = min($this->y, $line_align_data[1]);
  22060. $maxbottomliney = max(($this->y + (($fontsize * $this->cell_height_ratio) / $this->k)), $line_align_data[2]);
  22061. } else {
  22062. $minstartliney = min($this->y, $minstartliney);
  22063. $maxbottomliney = max(($this->y + (($fontsize * $this->cell_height_ratio) / $this->k)), $maxbottomliney);
  22064. }
  22065. $line_align_data = $current_line_align_data;
  22066. }
  22067. }
  22068. $this->cell_height_ratio = $dom[$key]['line-height'];
  22069. $fontaligned = true;
  22070. }
  22071. $this->SetFont($fontname, $fontstyle, $fontsize);
  22072. // reset row height
  22073. $this->resetLastH();
  22074. $curfontname = $fontname;
  22075. $curfontstyle = $fontstyle;
  22076. $curfontsize = $fontsize;
  22077. $curfontascent = $fontascent;
  22078. $curfontdescent = $fontdescent;
  22079. }
  22080. }
  22081. // set text rendering mode
  22082. $textstroke = isset($dom[$key]['stroke']) ? $dom[$key]['stroke'] : $this->textstrokewidth;
  22083. $textfill = isset($dom[$key]['fill']) ? $dom[$key]['fill'] : (($this->textrendermode % 2) == 0);
  22084. $textclip = isset($dom[$key]['clip']) ? $dom[$key]['clip'] : ($this->textrendermode > 3);
  22085. $this->setTextRenderingMode($textstroke, $textfill, $textclip);
  22086. if (isset($dom[$key]['font-stretch']) AND ($dom[$key]['font-stretch'] !== false)) {
  22087. $this->setFontStretching($dom[$key]['font-stretch']);
  22088. }
  22089. if (isset($dom[$key]['letter-spacing']) AND ($dom[$key]['letter-spacing'] !== false)) {
  22090. $this->setFontSpacing($dom[$key]['letter-spacing']);
  22091. }
  22092. if (($plalign == 'J') AND $dom[$key]['block']) {
  22093. $plalign = '';
  22094. }
  22095. // get current position on page buffer
  22096. $curpos = $this->pagelen[$startlinepage];
  22097. if (isset($dom[$key]['bgcolor']) AND ($dom[$key]['bgcolor'] !== false)) {
  22098. $this->SetFillColorArray($dom[$key]['bgcolor']);
  22099. $wfill = true;
  22100. } else {
  22101. $wfill = $fill | false;
  22102. }
  22103. if (isset($dom[$key]['fgcolor']) AND ($dom[$key]['fgcolor'] !== false)) {
  22104. $this->SetTextColorArray($dom[$key]['fgcolor']);
  22105. }
  22106. if (isset($dom[$key]['strokecolor']) AND ($dom[$key]['strokecolor'] !== false)) {
  22107. $this->SetDrawColorArray($dom[$key]['strokecolor']);
  22108. }
  22109. if (isset($dom[$key]['align'])) {
  22110. $lalign = $dom[$key]['align'];
  22111. }
  22112. if ($this->empty_string($lalign)) {
  22113. $lalign = $align;
  22114. }
  22115. }
  22116. // align lines
  22117. if ($this->newline AND (strlen($dom[$key]['value']) > 0) AND ($dom[$key]['value'] != 'td') AND ($dom[$key]['value'] != 'th')) {
  22118. $newline = true;
  22119. $fontaligned = false;
  22120. // we are at the beginning of a new line
  22121. if (isset($startlinex)) {
  22122. $yshift = ($minstartliney - $startliney);
  22123. if (($yshift > 0) OR ($this->page > $startlinepage)) {
  22124. $yshift = 0;
  22125. }
  22126. $t_x = 0;
  22127. // the last line must be shifted to be aligned as requested
  22128. $linew = abs($this->endlinex - $startlinex);
  22129. if ($this->inxobj) {
  22130. // we are inside an XObject template
  22131. $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
  22132. if (isset($opentagpos)) {
  22133. $midpos = $opentagpos;
  22134. } else {
  22135. $midpos = 0;
  22136. }
  22137. if ($midpos > 0) {
  22138. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
  22139. $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  22140. } else {
  22141. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  22142. $pend = '';
  22143. }
  22144. } else {
  22145. $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
  22146. if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  22147. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  22148. $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
  22149. } elseif (isset($opentagpos)) {
  22150. $midpos = $opentagpos;
  22151. } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  22152. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  22153. $midpos = $this->footerpos[$startlinepage];
  22154. } else {
  22155. $midpos = 0;
  22156. }
  22157. if ($midpos > 0) {
  22158. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
  22159. $pend = substr($this->getPageBuffer($startlinepage), $midpos);
  22160. } else {
  22161. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
  22162. $pend = '';
  22163. }
  22164. }
  22165. if ((isset($plalign) AND ((($plalign == 'C') OR ($plalign == 'J') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
  22166. // calculate shifting amount
  22167. $tw = $w;
  22168. if (($plalign == 'J') AND $this->isRTLTextDir() AND ($this->num_columns > 1)) {
  22169. $tw += $this->cell_padding['R'];
  22170. }
  22171. if ($this->lMargin != $prevlMargin) {
  22172. $tw += ($prevlMargin - $this->lMargin);
  22173. }
  22174. if ($this->rMargin != $prevrMargin) {
  22175. $tw += ($prevrMargin - $this->rMargin);
  22176. }
  22177. $one_space_width = $this->GetStringWidth(chr(32));
  22178. $no = 0; // number of spaces on a line contained on a single block
  22179. if ($this->isRTLTextDir()) { // RTL
  22180. // remove left space if exist
  22181. $pos1 = $this->revstrpos($pmid, '[(');
  22182. if ($pos1 > 0) {
  22183. $pos1 = intval($pos1);
  22184. if ($this->isUnicodeFont()) {
  22185. $pos2 = intval($this->revstrpos($pmid, '[('.chr(0).chr(32)));
  22186. $spacelen = 2;
  22187. } else {
  22188. $pos2 = intval($this->revstrpos($pmid, '[('.chr(32)));
  22189. $spacelen = 1;
  22190. }
  22191. if ($pos1 == $pos2) {
  22192. $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
  22193. if (substr($pmid, $pos1, 4) == '[()]') {
  22194. $linew -= $one_space_width;
  22195. } elseif ($pos1 == strpos($pmid, '[(')) {
  22196. $no = 1;
  22197. }
  22198. }
  22199. }
  22200. } else { // LTR
  22201. // remove right space if exist
  22202. $pos1 = $this->revstrpos($pmid, ')]');
  22203. if ($pos1 > 0) {
  22204. $pos1 = intval($pos1);
  22205. if ($this->isUnicodeFont()) {
  22206. $pos2 = intval($this->revstrpos($pmid, chr(0).chr(32).')]')) + 2;
  22207. $spacelen = 2;
  22208. } else {
  22209. $pos2 = intval($this->revstrpos($pmid, chr(32).')]')) + 1;
  22210. $spacelen = 1;
  22211. }
  22212. if ($pos1 == $pos2) {
  22213. $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
  22214. $linew -= $one_space_width;
  22215. }
  22216. }
  22217. }
  22218. $mdiff = ($tw - $linew);
  22219. if ($plalign == 'C') {
  22220. if ($this->rtl) {
  22221. $t_x = -($mdiff / 2);
  22222. } else {
  22223. $t_x = ($mdiff / 2);
  22224. }
  22225. } elseif ($plalign == 'R') {
  22226. // right alignment on LTR document
  22227. $t_x = $mdiff;
  22228. } elseif ($plalign == 'L') {
  22229. // left alignment on RTL document
  22230. $t_x = -$mdiff;
  22231. } elseif (($plalign == 'J') AND ($plalign == $lalign)) {
  22232. // Justification
  22233. if ($this->isRTLTextDir()) {
  22234. // align text on the left
  22235. $t_x = -$mdiff;
  22236. }
  22237. $ns = 0; // number of spaces
  22238. $pmidtemp = $pmid;
  22239. // escape special characters
  22240. $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
  22241. $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
  22242. // search spaces
  22243. if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmidtemp, $lnstring, PREG_PATTERN_ORDER)) {
  22244. $spacestr = $this->getSpaceString();
  22245. $maxkk = count($lnstring[1]) - 1;
  22246. for ($kk=0; $kk <= $maxkk; ++$kk) {
  22247. // restore special characters
  22248. $lnstring[1][$kk] = str_replace('#!#OP#!#', '(', $lnstring[1][$kk]);
  22249. $lnstring[1][$kk] = str_replace('#!#CP#!#', ')', $lnstring[1][$kk]);
  22250. // store number of spaces on the strings
  22251. $lnstring[2][$kk] = substr_count($lnstring[1][$kk], $spacestr);
  22252. // count total spaces on line
  22253. $ns += $lnstring[2][$kk];
  22254. $lnstring[3][$kk] = $ns;
  22255. }
  22256. if ($ns == 0) {
  22257. $ns = 1;
  22258. }
  22259. // calculate additional space to add to each existing space
  22260. $spacewidth = ($mdiff / ($ns - $no)) * $this->k;
  22261. $spacewidthu = -1000 * ($mdiff + (($ns + $no) * $one_space_width)) / $ns / $this->FontSize;
  22262. if ($this->font_spacing != 0) {
  22263. // fixed spacing mode
  22264. $osw = -1000 * $this->font_spacing / $this->FontSize;
  22265. $spacewidthu += $osw;
  22266. }
  22267. $nsmax = $ns;
  22268. $ns = 0;
  22269. reset($lnstring);
  22270. $offset = 0;
  22271. $strcount = 0;
  22272. $prev_epsposbeg = 0;
  22273. $textpos = 0;
  22274. if ($this->isRTLTextDir()) {
  22275. $textpos = $this->wPt;
  22276. }
  22277. global $spacew;
  22278. while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x', $pmid, $strpiece, PREG_OFFSET_CAPTURE, $offset) == 1) {
  22279. // check if we are inside a string section '[( ... )]'
  22280. $stroffset = strpos($pmid, '[(', $offset);
  22281. if (($stroffset !== false) AND ($stroffset <= $strpiece[2][1])) {
  22282. // set offset to the end of string section
  22283. $offset = strpos($pmid, ')]', $stroffset);
  22284. while (($offset !== false) AND ($pmid[($offset - 1)] == '\\')) {
  22285. $offset = strpos($pmid, ')]', ($offset + 1));
  22286. }
  22287. if ($offset === false) {
  22288. $this->Error('HTML Justification: malformed PDF code.');
  22289. }
  22290. continue;
  22291. }
  22292. if ($this->isRTLTextDir()) {
  22293. $spacew = ($spacewidth * ($nsmax - $ns));
  22294. } else {
  22295. $spacew = ($spacewidth * $ns);
  22296. }
  22297. $offset = $strpiece[2][1] + strlen($strpiece[2][0]);
  22298. $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, $offset);
  22299. $epsposend = strpos($pmid, $this->epsmarker.'Q', $offset) + strlen($this->epsmarker.'Q');
  22300. if ((($epsposbeg > 0) AND ($epsposend > 0) AND ($offset > $epsposbeg) AND ($offset < $epsposend))
  22301. OR (($epsposbeg === false) AND ($epsposend > 0) AND ($offset < $epsposend))) {
  22302. // shift EPS images
  22303. $trx = sprintf('1 0 0 1 %F 0 cm', $spacew);
  22304. $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, ($prev_epsposbeg - 6));
  22305. $pmid_b = substr($pmid, 0, $epsposbeg);
  22306. $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg));
  22307. $pmid_e = substr($pmid, $epsposend);
  22308. $pmid = $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e;
  22309. $offset = $epsposend;
  22310. continue;
  22311. }
  22312. $prev_epsposbeg = $epsposbeg;
  22313. $currentxpos = 0;
  22314. // shift blocks of code
  22315. switch ($strpiece[2][0]) {
  22316. case 'Td':
  22317. case 'cm':
  22318. case 'm':
  22319. case 'l': {
  22320. // get current X position
  22321. preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches);
  22322. $currentxpos = $xmatches[1];
  22323. $textpos = $currentxpos;
  22324. if (($strcount <= $maxkk) AND ($strpiece[2][0] == 'Td')) {
  22325. $ns = $lnstring[3][$strcount];
  22326. if ($this->isRTLTextDir()) {
  22327. $spacew = ($spacewidth * ($nsmax - $ns));
  22328. }
  22329. ++$strcount;
  22330. }
  22331. // justify block
  22332. $pmid = preg_replace_callback('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x',
  22333. create_function('$matches', 'global $spacew;
  22334. $newx = sprintf("%F",(floatval($matches[1]) + $spacew));
  22335. return "".$newx." ".$matches[2]." x*#!#*x".$matches[3].$matches[4];'), $pmid, 1);
  22336. break;
  22337. }
  22338. case 're': {
  22339. // justify block
  22340. if (!$this->empty_string($this->lispacer)) {
  22341. $this->lispacer = '';
  22342. continue;
  22343. }
  22344. preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $xmatches);
  22345. $currentxpos = $xmatches[1];
  22346. global $x_diff, $w_diff;
  22347. $x_diff = 0;
  22348. $w_diff = 0;
  22349. if ($this->isRTLTextDir()) { // RTL
  22350. if ($currentxpos < $textpos) {
  22351. $x_diff = ($spacewidth * ($nsmax - $lnstring[3][$strcount]));
  22352. $w_diff = ($spacewidth * $lnstring[2][$strcount]);
  22353. } else {
  22354. if ($strcount > 0) {
  22355. $x_diff = ($spacewidth * ($nsmax - $lnstring[3][($strcount - 1)]));
  22356. $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
  22357. }
  22358. }
  22359. } else { // LTR
  22360. if ($currentxpos > $textpos) {
  22361. if ($strcount > 0) {
  22362. $x_diff = ($spacewidth * $lnstring[3][($strcount - 1)]);
  22363. }
  22364. $w_diff = ($spacewidth * $lnstring[2][$strcount]);
  22365. } else {
  22366. if ($strcount > 1) {
  22367. $x_diff = ($spacewidth * $lnstring[3][($strcount - 2)]);
  22368. }
  22369. if ($strcount > 0) {
  22370. $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
  22371. }
  22372. }
  22373. }
  22374. $pmid = preg_replace_callback('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x',
  22375. create_function('$matches', 'global $x_diff, $w_diff;
  22376. $newx = sprintf("%F",(floatval($matches[1]) + $x_diff));
  22377. $neww = sprintf("%F",(floatval($matches[3]) + $w_diff));
  22378. return "".$newx." ".$matches[2]." ".$neww." ".$matches[4]." x*#!#*x".$matches[5].$matches[6];'), $pmid, 1);
  22379. break;
  22380. }
  22381. case 'c': {
  22382. // get current X position
  22383. 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);
  22384. $currentxpos = $xmatches[1];
  22385. // justify block
  22386. $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',
  22387. create_function('$matches', 'global $spacew;
  22388. $newx1 = sprintf("%F",(floatval($matches[1]) + $spacew));
  22389. $newx2 = sprintf("%F",(floatval($matches[3]) + $spacew));
  22390. $newx3 = sprintf("%F",(floatval($matches[5]) + $spacew));
  22391. return "".$newx1." ".$matches[2]." ".$newx2." ".$matches[4]." ".$newx3." ".$matches[6]." x*#!#*x".$matches[7].$matches[8];'), $pmid, 1);
  22392. break;
  22393. }
  22394. }
  22395. // shift the annotations and links
  22396. $cxpos = ($currentxpos / $this->k);
  22397. $lmpos = ($this->lMargin + $this->cell_padding['L'] + $this->feps);
  22398. if ($this->inxobj) {
  22399. // we are inside an XObject template
  22400. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  22401. if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
  22402. if ($cxpos > $lmpos) {
  22403. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += ($spacew / $this->k);
  22404. $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  22405. } else {
  22406. $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  22407. }
  22408. break;
  22409. }
  22410. }
  22411. } elseif (isset($this->PageAnnots[$this->page])) {
  22412. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  22413. if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
  22414. if ($cxpos > $lmpos) {
  22415. $this->PageAnnots[$this->page][$pak]['x'] += ($spacew / $this->k);
  22416. $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  22417. } else {
  22418. $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  22419. }
  22420. break;
  22421. }
  22422. }
  22423. }
  22424. } // end of while
  22425. // remove markers
  22426. $pmid = str_replace('x*#!#*x', '', $pmid);
  22427. if ($this->isUnicodeFont()) {
  22428. // multibyte characters
  22429. $spacew = $spacewidthu;
  22430. if ($this->font_stretching != 100) {
  22431. // word spacing is affected by stretching
  22432. $spacew /= ($this->font_stretching / 100);
  22433. }
  22434. $pmidtemp = $pmid;
  22435. // escape special characters
  22436. $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
  22437. $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
  22438. $pmid = preg_replace_callback("/\[\(([^\)]*)\)\]/x",
  22439. create_function('$matches', 'global $spacew;
  22440. $matches[1] = str_replace("#!#OP#!#", "(", $matches[1]);
  22441. $matches[1] = str_replace("#!#CP#!#", ")", $matches[1]);
  22442. return "[(".str_replace(chr(0).chr(32), ") ".sprintf("%F", $spacew)." (", $matches[1]).")]";'), $pmidtemp);
  22443. if ($this->inxobj) {
  22444. // we are inside an XObject template
  22445. $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\n".$pend;
  22446. } else {
  22447. $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\n".$pend);
  22448. }
  22449. $endlinepos = strlen($pstart."\n".$pmid."\n");
  22450. } else {
  22451. // non-unicode (single-byte characters)
  22452. if ($this->font_stretching != 100) {
  22453. // word spacing (Tw) is affected by stretching
  22454. $spacewidth /= ($this->font_stretching / 100);
  22455. }
  22456. $rs = sprintf('%F Tw', $spacewidth);
  22457. $pmid = preg_replace("/\[\(/x", $rs.' [(', $pmid);
  22458. if ($this->inxobj) {
  22459. // we are inside an XObject template
  22460. $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend;
  22461. } else {
  22462. $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend);
  22463. }
  22464. $endlinepos = strlen($pstart."\n".$pmid."\nBT 0 Tw ET\n");
  22465. }
  22466. }
  22467. } // end of J
  22468. } // end if $startlinex
  22469. if (($t_x != 0) OR ($yshift < 0)) {
  22470. // shift the line
  22471. $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k), ($yshift * $this->k));
  22472. $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
  22473. $endlinepos = strlen($pstart);
  22474. if ($this->inxobj) {
  22475. // we are inside an XObject template
  22476. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
  22477. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  22478. if ($pak >= $pask) {
  22479. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  22480. $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  22481. }
  22482. }
  22483. } else {
  22484. $this->setPageBuffer($startlinepage, $pstart.$pend);
  22485. // shift the annotations and links
  22486. if (isset($this->PageAnnots[$this->page])) {
  22487. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  22488. if ($pak >= $pask) {
  22489. $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  22490. $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  22491. }
  22492. }
  22493. }
  22494. }
  22495. $this->y -= $yshift;
  22496. }
  22497. }
  22498. $pbrk = $this->checkPageBreak($this->lasth);
  22499. $this->newline = false;
  22500. $startlinex = $this->x;
  22501. $startliney = $this->y;
  22502. if ($dom[$dom[$key]['parent']]['value'] == 'sup') {
  22503. $startliney -= ((0.3 * $this->FontSizePt) / $this->k);
  22504. } elseif ($dom[$dom[$key]['parent']]['value'] == 'sub') {
  22505. $startliney -= (($this->FontSizePt / 0.7) / $this->k);
  22506. } else {
  22507. $minstartliney = $startliney;
  22508. $maxbottomliney = ($this->y + (($fontsize * $this->cell_height_ratio) / $this->k));
  22509. }
  22510. $startlinepage = $this->page;
  22511. if (isset($endlinepos) AND (!$pbrk)) {
  22512. $startlinepos = $endlinepos;
  22513. } else {
  22514. if ($this->inxobj) {
  22515. // we are inside an XObject template
  22516. $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
  22517. } elseif (!$this->InFooter) {
  22518. if (isset($this->footerlen[$this->page])) {
  22519. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  22520. } else {
  22521. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  22522. }
  22523. $startlinepos = $this->footerpos[$this->page];
  22524. } else {
  22525. $startlinepos = $this->pagelen[$this->page];
  22526. }
  22527. }
  22528. unset($endlinepos);
  22529. $plalign = $lalign;
  22530. if (isset($this->PageAnnots[$this->page])) {
  22531. $pask = count($this->PageAnnots[$this->page]);
  22532. } else {
  22533. $pask = 0;
  22534. }
  22535. if (!($dom[$key]['tag'] AND !$dom[$key]['opening'] AND ($dom[$key]['value'] == 'table')
  22536. AND (isset($this->emptypagemrk[$this->page]))
  22537. AND ($this->emptypagemrk[$this->page] == $this->pagelen[$this->page]))) {
  22538. $this->SetFont($fontname, $fontstyle, $fontsize);
  22539. if ($wfill) {
  22540. $this->SetFillColorArray($this->bgcolor);
  22541. }
  22542. }
  22543. } // end newline
  22544. if (isset($opentagpos)) {
  22545. unset($opentagpos);
  22546. }
  22547. if ($dom[$key]['tag']) {
  22548. if ($dom[$key]['opening']) {
  22549. // get text indentation (if any)
  22550. if (isset($dom[$key]['text-indent']) AND $dom[$key]['block']) {
  22551. $this->textindent = $dom[$key]['text-indent'];
  22552. $this->newline = true;
  22553. }
  22554. // table
  22555. if ($dom[$key]['value'] == 'table') {
  22556. // available page width
  22557. if ($this->rtl) {
  22558. $wtmp = $this->x - $this->lMargin;
  22559. } else {
  22560. $wtmp = $this->w - $this->rMargin - $this->x;
  22561. }
  22562. // get cell spacing
  22563. if (isset($dom[$key]['attribute']['cellspacing'])) {
  22564. $clsp = $this->getHTMLUnitToUnits($dom[$key]['attribute']['cellspacing'], 1, 'px');
  22565. $cellspacing = array('H' => $clsp, 'V' => $clsp);
  22566. } elseif (isset($dom[$key]['border-spacing'])) {
  22567. $cellspacing = $dom[$key]['border-spacing'];
  22568. } else {
  22569. $cellspacing = array('H' => 0, 'V' => 0);
  22570. }
  22571. // table width
  22572. if (isset($dom[$key]['width'])) {
  22573. $table_width = $this->getHTMLUnitToUnits($dom[$key]['width'], $wtmp, 'px');
  22574. } else {
  22575. $table_width = $wtmp;
  22576. }
  22577. $table_width -= (2 * $cellspacing['H']);
  22578. if (!$this->inthead) {
  22579. $this->y += $cellspacing['V'];
  22580. }
  22581. if ($this->rtl) {
  22582. $cellspacingx = -$cellspacing['H'];
  22583. } else {
  22584. $cellspacingx = $cellspacing['H'];
  22585. }
  22586. // total table width without cellspaces
  22587. $table_columns_width = ($table_width - ($cellspacing['H'] * ($dom[$key]['cols'] - 1)));
  22588. // minimum column width
  22589. $table_min_column_width = ($table_columns_width / $dom[$key]['cols']);
  22590. // array of custom column widths
  22591. $table_colwidths = array_fill(0, $dom[$key]['cols'], $table_min_column_width);
  22592. }
  22593. // table row
  22594. if ($dom[$key]['value'] == 'tr') {
  22595. // reset column counter
  22596. $colid = 0;
  22597. }
  22598. // table cell
  22599. if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  22600. $trid = $dom[$key]['parent'];
  22601. $table_el = $dom[$trid]['parent'];
  22602. if (!isset($dom[$table_el]['cols'])) {
  22603. $dom[$table_el]['cols'] = $dom[$trid]['cols'];
  22604. }
  22605. // store border info
  22606. $tdborder = 0;
  22607. if (isset($dom[$key]['border']) AND !empty($dom[$key]['border'])) {
  22608. $tdborder = $dom[$key]['border'];
  22609. }
  22610. $colspan = $dom[$key]['attribute']['colspan'];
  22611. $old_cell_padding = $this->cell_padding;
  22612. if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) {
  22613. $crclpd = $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'], 1, 'px');
  22614. $current_cell_padding = array('L' => $crclpd, 'T' => $crclpd, 'R' => $crclpd, 'B' => $crclpd);
  22615. } elseif (isset($dom[($dom[$trid]['parent'])]['padding'])) {
  22616. $current_cell_padding = $dom[($dom[$trid]['parent'])]['padding'];
  22617. } else {
  22618. $current_cell_padding = array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0);
  22619. }
  22620. $this->cell_padding = $current_cell_padding;
  22621. if (isset($dom[$key]['height'])) {
  22622. // minimum cell height
  22623. $cellh = $this->getHTMLUnitToUnits($dom[$key]['height'], 0, 'px');
  22624. } else {
  22625. $cellh = 0;
  22626. }
  22627. if (isset($dom[$key]['content'])) {
  22628. $cell_content = stripslashes($dom[$key]['content']);
  22629. } else {
  22630. $cell_content = '&nbsp;';
  22631. }
  22632. $tagtype = $dom[$key]['value'];
  22633. $parentid = $key;
  22634. while (($key < $maxel) AND (!(($dom[$key]['tag']) AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == $tagtype) AND ($dom[$key]['parent'] == $parentid)))) {
  22635. // move $key index forward
  22636. ++$key;
  22637. }
  22638. if (!isset($dom[$trid]['startpage'])) {
  22639. $dom[$trid]['startpage'] = $this->page;
  22640. } else {
  22641. $this->setPage($dom[$trid]['startpage']);
  22642. }
  22643. if (!isset($dom[$trid]['startcolumn'])) {
  22644. $dom[$trid]['startcolumn'] = $this->current_column;
  22645. } elseif ($this->current_column != $dom[$trid]['startcolumn']) {
  22646. $tmpx = $this->x;
  22647. $this->selectColumn($dom[$trid]['startcolumn']);
  22648. $this->x = $tmpx;
  22649. }
  22650. if (!isset($dom[$trid]['starty'])) {
  22651. $dom[$trid]['starty'] = $this->y;
  22652. } else {
  22653. $this->y = $dom[$trid]['starty'];
  22654. }
  22655. if (!isset($dom[$trid]['startx'])) {
  22656. $dom[$trid]['startx'] = $this->x;
  22657. $this->x += $cellspacingx;
  22658. } else {
  22659. $this->x += ($cellspacingx / 2);
  22660. }
  22661. if (isset($dom[$parentid]['attribute']['rowspan'])) {
  22662. $rowspan = intval($dom[$parentid]['attribute']['rowspan']);
  22663. } else {
  22664. $rowspan = 1;
  22665. }
  22666. // skip row-spanned cells started on the previous rows
  22667. if (isset($dom[$table_el]['rowspans'])) {
  22668. $rsk = 0;
  22669. $rskmax = count($dom[$table_el]['rowspans']);
  22670. while ($rsk < $rskmax) {
  22671. $trwsp = $dom[$table_el]['rowspans'][$rsk];
  22672. $rsstartx = $trwsp['startx'];
  22673. $rsendx = $trwsp['endx'];
  22674. // account for margin changes
  22675. if ($trwsp['startpage'] < $this->page) {
  22676. if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$trwsp['startpage']]['orm'])) {
  22677. $dl = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$trwsp['startpage']]['orm']);
  22678. $rsstartx -= $dl;
  22679. $rsendx -= $dl;
  22680. } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$trwsp['startpage']]['olm'])) {
  22681. $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$trwsp['startpage']]['olm']);
  22682. $rsstartx += $dl;
  22683. $rsendx += $dl;
  22684. }
  22685. }
  22686. if (($trwsp['rowspan'] > 0)
  22687. AND ($rsstartx > ($this->x - $cellspacing['H'] - $current_cell_padding['L'] - $this->feps))
  22688. AND ($rsstartx < ($this->x + $cellspacing['H'] + $current_cell_padding['R'] + $this->feps))
  22689. AND (($trwsp['starty'] < ($this->y - $this->feps)) OR ($trwsp['startpage'] < $this->page) OR ($trwsp['startcolumn'] < $this->current_column))) {
  22690. // set the starting X position of the current cell
  22691. $this->x = $rsendx + $cellspacingx;
  22692. // increment column indicator
  22693. $colid += $trwsp['colspan'];
  22694. if (($trwsp['rowspan'] == 1)
  22695. AND (isset($dom[$trid]['endy']))
  22696. AND (isset($dom[$trid]['endpage']))
  22697. AND (isset($dom[$trid]['endcolumn']))
  22698. AND ($trwsp['endpage'] == $dom[$trid]['endpage'])
  22699. AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
  22700. // set ending Y position for row
  22701. $dom[$table_el]['rowspans'][$rsk]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  22702. $dom[$trid]['endy'] = $dom[$table_el]['rowspans'][$rsk]['endy'];
  22703. }
  22704. $rsk = 0;
  22705. } else {
  22706. ++$rsk;
  22707. }
  22708. }
  22709. }
  22710. if (isset($dom[$parentid]['width'])) {
  22711. // user specified width
  22712. $cellw = $this->getHTMLUnitToUnits($dom[$parentid]['width'], $table_columns_width, 'px');
  22713. $tmpcw = ($cellw / $colspan);
  22714. for ($i = 0; $i < $colspan; ++$i) {
  22715. $table_colwidths[($colid + $i)] = $tmpcw;
  22716. }
  22717. } else {
  22718. // inherit column width
  22719. $cellw = 0;
  22720. for ($i = 0; $i < $colspan; ++$i) {
  22721. $cellw += $table_colwidths[($colid + $i)];
  22722. }
  22723. }
  22724. $cellw += (($colspan - 1) * $cellspacing['H']);
  22725. // increment column indicator
  22726. $colid += $colspan;
  22727. // add rowspan information to table element
  22728. if ($rowspan > 1) {
  22729. $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));
  22730. }
  22731. $cellid = array_push($dom[$trid]['cellpos'], array('startx' => $this->x));
  22732. if ($rowspan > 1) {
  22733. $dom[$trid]['cellpos'][($cellid - 1)]['rowspanid'] = ($trsid - 1);
  22734. }
  22735. // push background colors
  22736. if (isset($dom[$parentid]['bgcolor']) AND ($dom[$parentid]['bgcolor'] !== false)) {
  22737. $dom[$trid]['cellpos'][($cellid - 1)]['bgcolor'] = $dom[$parentid]['bgcolor'];
  22738. }
  22739. // store border info
  22740. if (isset($tdborder) AND !empty($tdborder)) {
  22741. $dom[$trid]['cellpos'][($cellid - 1)]['border'] = $tdborder;
  22742. }
  22743. $prevLastH = $this->lasth;
  22744. // store some info for multicolumn mode
  22745. if ($this->rtl) {
  22746. $this->colxshift['x'] = $this->w - $this->x - $this->rMargin;
  22747. } else {
  22748. $this->colxshift['x'] = $this->x - $this->lMargin;
  22749. }
  22750. $this->colxshift['s'] = $cellspacing;
  22751. $this->colxshift['p'] = $current_cell_padding;
  22752. // ****** write the cell content ******
  22753. $this->MultiCell($cellw, $cellh, $cell_content, false, $lalign, false, 2, '', '', true, 0, true, true, 0, 'T', false);
  22754. // restore some values
  22755. $this->colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  22756. $this->lasth = $prevLastH;
  22757. $this->cell_padding = $old_cell_padding;
  22758. $dom[$trid]['cellpos'][($cellid - 1)]['endx'] = $this->x;
  22759. // update the end of row position
  22760. if ($rowspan <= 1) {
  22761. if (isset($dom[$trid]['endy'])) {
  22762. if (($this->page == $dom[$trid]['endpage']) AND ($this->current_column == $dom[$trid]['endcolumn'])) {
  22763. $dom[$trid]['endy'] = max($this->y, $dom[$trid]['endy']);
  22764. } elseif (($this->page > $dom[$trid]['endpage']) OR ($this->current_column > $dom[$trid]['endcolumn'])) {
  22765. $dom[$trid]['endy'] = $this->y;
  22766. }
  22767. } else {
  22768. $dom[$trid]['endy'] = $this->y;
  22769. }
  22770. if (isset($dom[$trid]['endpage'])) {
  22771. $dom[$trid]['endpage'] = max($this->page, $dom[$trid]['endpage']);
  22772. } else {
  22773. $dom[$trid]['endpage'] = $this->page;
  22774. }
  22775. if (isset($dom[$trid]['endcolumn'])) {
  22776. $dom[$trid]['endcolumn'] = max($this->current_column, $dom[$trid]['endcolumn']);
  22777. } else {
  22778. $dom[$trid]['endcolumn'] = $this->current_column;
  22779. }
  22780. } else {
  22781. // account for row-spanned cells
  22782. $dom[$table_el]['rowspans'][($trsid - 1)]['endx'] = $this->x;
  22783. $dom[$table_el]['rowspans'][($trsid - 1)]['endy'] = $this->y;
  22784. $dom[$table_el]['rowspans'][($trsid - 1)]['endpage'] = $this->page;
  22785. $dom[$table_el]['rowspans'][($trsid - 1)]['endcolumn'] = $this->current_column;
  22786. }
  22787. if (isset($dom[$table_el]['rowspans'])) {
  22788. // update endy and endpage on rowspanned cells
  22789. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  22790. if ($trwsp['rowspan'] > 0) {
  22791. if (isset($dom[$trid]['endpage'])) {
  22792. if (($trwsp['endpage'] == $dom[$trid]['endpage']) AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
  22793. $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  22794. } elseif (($trwsp['endpage'] < $dom[$trid]['endpage']) OR ($trwsp['endcolumn'] < $dom[$trid]['endcolumn'])) {
  22795. $dom[$table_el]['rowspans'][$k]['endy'] = $dom[$trid]['endy'];
  22796. $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[$trid]['endpage'];
  22797. $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[$trid]['endcolumn'];
  22798. } else {
  22799. $dom[$trid]['endy'] = $this->pagedim[$dom[$trid]['endpage']]['hk'] - $this->pagedim[$dom[$trid]['endpage']]['bm'];
  22800. }
  22801. }
  22802. }
  22803. }
  22804. }
  22805. $this->x += ($cellspacingx / 2);
  22806. } else {
  22807. // opening tag (or self-closing tag)
  22808. if (!isset($opentagpos)) {
  22809. if ($this->inxobj) {
  22810. // we are inside an XObject template
  22811. $opentagpos = strlen($this->xobjects[$this->xobjid]['outdata']);
  22812. } elseif (!$this->InFooter) {
  22813. if (isset($this->footerlen[$this->page])) {
  22814. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  22815. } else {
  22816. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  22817. }
  22818. $opentagpos = $this->footerpos[$this->page];
  22819. }
  22820. }
  22821. $dom = $this->openHTMLTagHandler($dom, $key, $cell);
  22822. }
  22823. } else { // closing tag
  22824. $prev_numpages = $this->numpages;
  22825. $old_bordermrk = $this->bordermrk[$this->page];
  22826. $dom = $this->closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney);
  22827. if ($this->bordermrk[$this->page] > $old_bordermrk) {
  22828. $startlinepos += ($this->bordermrk[$this->page] - $old_bordermrk);
  22829. }
  22830. if ($prev_numpages > $this->numpages) {
  22831. $startlinepage = $this->page;
  22832. }
  22833. }
  22834. } elseif (strlen($dom[$key]['value']) > 0) {
  22835. // print list-item
  22836. if (!$this->empty_string($this->lispacer) AND ($this->lispacer != '^')) {
  22837. $this->SetFont($pfontname, $pfontstyle, $pfontsize);
  22838. $this->resetLastH();
  22839. $minstartliney = $this->y;
  22840. $maxbottomliney = ($startliney + ($this->FontSize * $this->cell_height_ratio));
  22841. $this->putHtmlListBullet($this->listnum, $this->lispacer, $pfontsize);
  22842. $this->SetFont($curfontname, $curfontstyle, $curfontsize);
  22843. $this->resetLastH();
  22844. if (is_numeric($pfontsize) AND ($pfontsize > 0) AND is_numeric($curfontsize) AND ($curfontsize > 0) AND ($pfontsize != $curfontsize)) {
  22845. $pfontascent = $this->getFontAscent($pfontname, $pfontstyle, $pfontsize);
  22846. $pfontdescent = $this->getFontDescent($pfontname, $pfontstyle, $pfontsize);
  22847. $this->y += ((($pfontsize - $curfontsize) * $this->cell_height_ratio / $this->k) + $pfontascent - $curfontascent - $pfontdescent + $curfontdescent) / 2;
  22848. $minstartliney = min($this->y, $minstartliney);
  22849. $maxbottomliney = max(($this->y + (($pfontsize * $this->cell_height_ratio) / $this->k)), $maxbottomliney);
  22850. }
  22851. }
  22852. // text
  22853. $this->htmlvspace = 0;
  22854. if ((!$this->premode) AND $this->isRTLTextDir()) {
  22855. // reverse spaces order
  22856. $lsp = ''; // left spaces
  22857. $rsp = ''; // right spaces
  22858. if (preg_match('/^('.$this->re_space['p'].'+)/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
  22859. $lsp = $matches[1];
  22860. }
  22861. if (preg_match('/('.$this->re_space['p'].'+)$/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
  22862. $rsp = $matches[1];
  22863. }
  22864. $dom[$key]['value'] = $rsp.$this->stringTrim($dom[$key]['value']).$lsp;
  22865. }
  22866. if ($newline) {
  22867. if (!$this->premode) {
  22868. $prelen = strlen($dom[$key]['value']);
  22869. if ($this->isRTLTextDir()) {
  22870. // right trim except non-breaking space
  22871. $dom[$key]['value'] = $this->stringRightTrim($dom[$key]['value']);
  22872. } else {
  22873. // left trim except non-breaking space
  22874. $dom[$key]['value'] = $this->stringLeftTrim($dom[$key]['value']);
  22875. }
  22876. $postlen = strlen($dom[$key]['value']);
  22877. if (($postlen == 0) AND ($prelen > 0)) {
  22878. $dom[$key]['trimmed_space'] = true;
  22879. }
  22880. }
  22881. $newline = false;
  22882. $firstblock = true;
  22883. } else {
  22884. $firstblock = false;
  22885. // replace empty multiple spaces string with a single space
  22886. $dom[$key]['value'] = preg_replace('/^'.$this->re_space['p'].'+$/'.$this->re_space['m'], chr(32), $dom[$key]['value']);
  22887. }
  22888. $strrest = '';
  22889. if ($this->rtl) {
  22890. $this->x -= $this->textindent;
  22891. } else {
  22892. $this->x += $this->textindent;
  22893. }
  22894. if (!isset($dom[$key]['trimmed_space']) OR !$dom[$key]['trimmed_space']) {
  22895. $strlinelen = $this->GetStringWidth($dom[$key]['value']);
  22896. if (!empty($this->HREF) AND (isset($this->HREF['url']))) {
  22897. // HTML <a> Link
  22898. $hrefcolor = '';
  22899. if (isset($dom[($dom[$key]['parent'])]['fgcolor']) AND ($dom[($dom[$key]['parent'])]['fgcolor'] !== false)) {
  22900. $hrefcolor = $dom[($dom[$key]['parent'])]['fgcolor'];
  22901. }
  22902. $hrefstyle = -1;
  22903. if (isset($dom[($dom[$key]['parent'])]['fontstyle']) AND ($dom[($dom[$key]['parent'])]['fontstyle'] !== false)) {
  22904. $hrefstyle = $dom[($dom[$key]['parent'])]['fontstyle'];
  22905. }
  22906. $strrest = $this->addHtmlLink($this->HREF['url'], $dom[$key]['value'], $wfill, true, $hrefcolor, $hrefstyle, true);
  22907. } else {
  22908. $wadj = 0; // space to leave for block continuity
  22909. if ($this->rtl) {
  22910. $cwa = ($this->x - $this->lMargin);
  22911. } else {
  22912. $cwa = ($this->w - $this->rMargin - $this->x);
  22913. }
  22914. if (($strlinelen < $cwa) AND (isset($dom[($key + 1)])) AND ($dom[($key + 1)]['tag']) AND (!$dom[($key + 1)]['block'])) {
  22915. // check the next text blocks for continuity
  22916. $nkey = ($key + 1);
  22917. $write_block = true;
  22918. $same_textdir = true;
  22919. $tmp_fontname = $this->FontFamily;
  22920. $tmp_fontstyle = $this->FontStyle;
  22921. $tmp_fontsize = $this->FontSizePt;
  22922. while ($write_block AND isset($dom[$nkey])) {
  22923. if ($dom[$nkey]['tag']) {
  22924. if ($dom[$nkey]['block']) {
  22925. // end of block
  22926. $write_block = false;
  22927. }
  22928. $tmp_fontname = isset($dom[$nkey]['fontname']) ? $dom[$nkey]['fontname'] : $this->FontFamily;
  22929. $tmp_fontstyle = isset($dom[$nkey]['fontstyle']) ? $dom[$nkey]['fontstyle'] : $this->FontStyle;
  22930. $tmp_fontsize = isset($dom[$nkey]['fontsize']) ? $dom[$nkey]['fontsize'] : $this->FontSizePt;
  22931. $same_textdir = ($dom[$nkey]['dir'] == $dom[$key]['dir']);
  22932. } else {
  22933. $nextstr = preg_split('/'.$this->re_space['p'].'+/'.$this->re_space['m'], $dom[$nkey]['value']);
  22934. if (isset($nextstr[0]) AND $same_textdir) {
  22935. $wadj += $this->GetStringWidth($nextstr[0], $tmp_fontname, $tmp_fontstyle, $tmp_fontsize);
  22936. if (isset($nextstr[1])) {
  22937. $write_block = false;
  22938. }
  22939. }
  22940. }
  22941. ++$nkey;
  22942. }
  22943. }
  22944. if (($wadj > 0) AND (($strlinelen + $wadj) >= $cwa)) {
  22945. $wadj = 0;
  22946. $nextstr = preg_split('/'.$this->re_space['p'].'/'.$this->re_space['m'], $dom[$key]['value']);
  22947. $numblks = count($nextstr);
  22948. if ($numblks > 1) {
  22949. // try to split on blank spaces
  22950. $wadj = ($cwa - $strlinelen + $this->GetStringWidth($nextstr[($numblks - 1)]));
  22951. } else {
  22952. // set the entire block on new line
  22953. $wadj = $this->GetStringWidth($nextstr[0]);
  22954. }
  22955. }
  22956. // check for reversed text direction
  22957. if (($wadj > 0) AND (($this->rtl AND ($this->tmprtl === 'L')) OR (!$this->rtl AND ($this->tmprtl === 'R')))) {
  22958. // LTR text on RTL direction or RTL text on LTR direction
  22959. $reverse_dir = true;
  22960. $this->rtl = !$this->rtl;
  22961. $revshift = ($strlinelen + $wadj + 0.000001); // add little quantity for rounding problems
  22962. if ($this->rtl) {
  22963. $this->x += $revshift;
  22964. } else {
  22965. $this->x -= $revshift;
  22966. }
  22967. $xws = $this->x;
  22968. }
  22969. // ****** write only until the end of the line and get the rest ******
  22970. $strrest = $this->Write($this->lasth, $dom[$key]['value'], '', $wfill, '', false, 0, true, $firstblock, 0, $wadj);
  22971. // restore default direction
  22972. if ($reverse_dir AND ($wadj == 0)) {
  22973. $this->x = $xws;
  22974. $this->rtl = !$this->rtl;
  22975. $reverse_dir = false;
  22976. }
  22977. }
  22978. }
  22979. $this->textindent = 0;
  22980. if (strlen($strrest) > 0) {
  22981. // store the remaining string on the previous $key position
  22982. $this->newline = true;
  22983. if ($strrest == $dom[$key]['value']) {
  22984. // used to avoid infinite loop
  22985. ++$loop;
  22986. } else {
  22987. $loop = 0;
  22988. }
  22989. $dom[$key]['value'] = $strrest;
  22990. if ($cell) {
  22991. if ($this->rtl) {
  22992. $this->x -= $this->cell_padding['R'];
  22993. } else {
  22994. $this->x += $this->cell_padding['L'];
  22995. }
  22996. }
  22997. if ($loop < 3) {
  22998. --$key;
  22999. }
  23000. } else {
  23001. $loop = 0;
  23002. // add the positive font spacing of the last character (if any)
  23003. if ($this->font_spacing > 0) {
  23004. if ($this->rtl) {
  23005. $this->x -= $this->font_spacing;
  23006. } else {
  23007. $this->x += $this->font_spacing;
  23008. }
  23009. }
  23010. }
  23011. }
  23012. ++$key;
  23013. 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')) {
  23014. // check if we are on a new page or on a new column
  23015. if ((!$undo) AND (($this->y < $this->start_transaction_y) OR (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['endy'] < $this->start_transaction_y)))) {
  23016. // we are on a new page or on a new column and the total object height is less than the available vertical space.
  23017. // restore previous object
  23018. $this->rollbackTransaction(true);
  23019. // restore previous values
  23020. foreach ($this_method_vars as $vkey => $vval) {
  23021. $$vkey = $vval;
  23022. }
  23023. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  23024. $pre_y = $this->y;
  23025. if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
  23026. $startliney = $this->y;
  23027. }
  23028. $undo = true; // avoid infinite loop
  23029. } else {
  23030. $undo = false;
  23031. }
  23032. }
  23033. } // end for each $key
  23034. // align the last line
  23035. if (isset($startlinex)) {
  23036. $yshift = ($minstartliney - $startliney);
  23037. if (($yshift > 0) OR ($this->page > $startlinepage)) {
  23038. $yshift = 0;
  23039. }
  23040. $t_x = 0;
  23041. // the last line must be shifted to be aligned as requested
  23042. $linew = abs($this->endlinex - $startlinex);
  23043. if ($this->inxobj) {
  23044. // we are inside an XObject template
  23045. $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
  23046. if (isset($opentagpos)) {
  23047. $midpos = $opentagpos;
  23048. } else {
  23049. $midpos = 0;
  23050. }
  23051. if ($midpos > 0) {
  23052. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
  23053. $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  23054. } else {
  23055. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  23056. $pend = '';
  23057. }
  23058. } else {
  23059. $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
  23060. if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  23061. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  23062. $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
  23063. } elseif (isset($opentagpos)) {
  23064. $midpos = $opentagpos;
  23065. } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  23066. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  23067. $midpos = $this->footerpos[$startlinepage];
  23068. } else {
  23069. $midpos = 0;
  23070. }
  23071. if ($midpos > 0) {
  23072. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
  23073. $pend = substr($this->getPageBuffer($startlinepage), $midpos);
  23074. } else {
  23075. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
  23076. $pend = '';
  23077. }
  23078. }
  23079. if ((isset($plalign) AND ((($plalign == 'C') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
  23080. // calculate shifting amount
  23081. $tw = $w;
  23082. if ($this->lMargin != $prevlMargin) {
  23083. $tw += ($prevlMargin - $this->lMargin);
  23084. }
  23085. if ($this->rMargin != $prevrMargin) {
  23086. $tw += ($prevrMargin - $this->rMargin);
  23087. }
  23088. $one_space_width = $this->GetStringWidth(chr(32));
  23089. $no = 0; // number of spaces on a line contained on a single block
  23090. if ($this->isRTLTextDir()) { // RTL
  23091. // remove left space if exist
  23092. $pos1 = $this->revstrpos($pmid, '[(');
  23093. if ($pos1 > 0) {
  23094. $pos1 = intval($pos1);
  23095. if ($this->isUnicodeFont()) {
  23096. $pos2 = intval($this->revstrpos($pmid, '[('.chr(0).chr(32)));
  23097. $spacelen = 2;
  23098. } else {
  23099. $pos2 = intval($this->revstrpos($pmid, '[('.chr(32)));
  23100. $spacelen = 1;
  23101. }
  23102. if ($pos1 == $pos2) {
  23103. $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
  23104. if (substr($pmid, $pos1, 4) == '[()]') {
  23105. $linew -= $one_space_width;
  23106. } elseif ($pos1 == strpos($pmid, '[(')) {
  23107. $no = 1;
  23108. }
  23109. }
  23110. }
  23111. } else { // LTR
  23112. // remove right space if exist
  23113. $pos1 = $this->revstrpos($pmid, ')]');
  23114. if ($pos1 > 0) {
  23115. $pos1 = intval($pos1);
  23116. if ($this->isUnicodeFont()) {
  23117. $pos2 = intval($this->revstrpos($pmid, chr(0).chr(32).')]')) + 2;
  23118. $spacelen = 2;
  23119. } else {
  23120. $pos2 = intval($this->revstrpos($pmid, chr(32).')]')) + 1;
  23121. $spacelen = 1;
  23122. }
  23123. if ($pos1 == $pos2) {
  23124. $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
  23125. $linew -= $one_space_width;
  23126. }
  23127. }
  23128. }
  23129. $mdiff = ($tw - $linew);
  23130. if ($plalign == 'C') {
  23131. if ($this->rtl) {
  23132. $t_x = -($mdiff / 2);
  23133. } else {
  23134. $t_x = ($mdiff / 2);
  23135. }
  23136. } elseif ($plalign == 'R') {
  23137. // right alignment on LTR document
  23138. $t_x = $mdiff;
  23139. } elseif ($plalign == 'L') {
  23140. // left alignment on RTL document
  23141. $t_x = -$mdiff;
  23142. }
  23143. } // end if startlinex
  23144. if (($t_x != 0) OR ($yshift < 0)) {
  23145. // shift the line
  23146. $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k), ($yshift * $this->k));
  23147. $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
  23148. $endlinepos = strlen($pstart);
  23149. if ($this->inxobj) {
  23150. // we are inside an XObject template
  23151. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
  23152. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  23153. if ($pak >= $pask) {
  23154. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  23155. $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  23156. }
  23157. }
  23158. } else {
  23159. $this->setPageBuffer($startlinepage, $pstart.$pend);
  23160. // shift the annotations and links
  23161. if (isset($this->PageAnnots[$this->page])) {
  23162. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  23163. if ($pak >= $pask) {
  23164. $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  23165. $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  23166. }
  23167. }
  23168. }
  23169. }
  23170. $this->y -= $yshift;
  23171. $yshift = 0;
  23172. }
  23173. }
  23174. // restore previous values
  23175. $this->setGraphicVars($gvars);
  23176. if ($this->num_columns > 1) {
  23177. $this->selectColumn();
  23178. } elseif ($this->page > $prevPage) {
  23179. $this->lMargin = $this->pagedim[$this->page]['olm'];
  23180. $this->rMargin = $this->pagedim[$this->page]['orm'];
  23181. }
  23182. // restore previous list state
  23183. $this->cell_height_ratio = $prev_cell_height_ratio;
  23184. $this->listnum = $prev_listnum;
  23185. $this->listordered = $prev_listordered;
  23186. $this->listcount = $prev_listcount;
  23187. $this->lispacer = $prev_lispacer;
  23188. if ($ln AND (!($cell AND ($dom[$key-1]['value'] == 'table')))) {
  23189. $this->Ln($this->lasth);
  23190. if ($this->y < $maxbottomliney) {
  23191. $this->y = $maxbottomliney;
  23192. }
  23193. }
  23194. unset($dom);
  23195. }
  23196. /**
  23197. * Process opening tags.
  23198. * @param $dom (array) html dom array
  23199. * @param $key (int) current element id
  23200. * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
  23201. * @return $dom array
  23202. * @protected
  23203. */
  23204. protected function openHTMLTagHandler($dom, $key, $cell) {
  23205. $tag = $dom[$key];
  23206. $parent = $dom[($dom[$key]['parent'])];
  23207. $firsttag = ($key == 1);
  23208. // check for text direction attribute
  23209. if (isset($tag['dir'])) {
  23210. $this->setTempRTL($tag['dir']);
  23211. } else {
  23212. $this->tmprtl = false;
  23213. }
  23214. if ($tag['block']) {
  23215. $hbz = 0; // distance from y to line bottom
  23216. $hb = 0; // vertical space between block tags
  23217. // calculate vertical space for block tags
  23218. if (isset($this->tagvspaces[$tag['value']][0]['h']) AND ($this->tagvspaces[$tag['value']][0]['h'] >= 0)) {
  23219. $cur_h = $this->tagvspaces[$tag['value']][0]['h'];
  23220. } elseif (isset($tag['fontsize'])) {
  23221. $cur_h = ($tag['fontsize'] / $this->k) * $this->cell_height_ratio;
  23222. } else {
  23223. $cur_h = $this->FontSize * $this->cell_height_ratio;
  23224. }
  23225. if (isset($this->tagvspaces[$tag['value']][0]['n'])) {
  23226. $n = $this->tagvspaces[$tag['value']][0]['n'];
  23227. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  23228. $n = 0.6;
  23229. } else {
  23230. $n = 1;
  23231. }
  23232. if ((!isset($this->tagvspaces[$tag['value']])) AND (in_array($tag['value'], array('div', 'dt', 'dd', 'li', 'br')))) {
  23233. $hb = 0;
  23234. } else {
  23235. $hb = ($n * $cur_h);
  23236. }
  23237. if (($this->htmlvspace <= 0) AND ($n > 0)) {
  23238. if (isset($parent['fontsize'])) {
  23239. $hbz = (($parent['fontsize'] / $this->k) * $this->cell_height_ratio);
  23240. } else {
  23241. $hbz = $this->FontSize * $this->cell_height_ratio;
  23242. }
  23243. }
  23244. if (isset($dom[($key - 1)]) AND ($dom[($key - 1)]['value'] == 'table')) {
  23245. // fix vertical space after table
  23246. $hbz = 0;
  23247. }
  23248. }
  23249. // Opening tag
  23250. switch($tag['value']) {
  23251. case 'table': {
  23252. $cp = 0;
  23253. $cs = 0;
  23254. $dom[$key]['rowspans'] = array();
  23255. if (!isset($dom[$key]['attribute']['nested']) OR ($dom[$key]['attribute']['nested'] != 'true')) {
  23256. $this->htmlvspace = 0;
  23257. // set table header
  23258. if (!$this->empty_string($dom[$key]['thead'])) {
  23259. // set table header
  23260. $this->thead = $dom[$key]['thead'];
  23261. if (!isset($this->theadMargins) OR (empty($this->theadMargins))) {
  23262. $this->theadMargins = array();
  23263. $this->theadMargins['cell_padding'] = $this->cell_padding;
  23264. $this->theadMargins['lmargin'] = $this->lMargin;
  23265. $this->theadMargins['rmargin'] = $this->rMargin;
  23266. $this->theadMargins['page'] = $this->page;
  23267. $this->theadMargins['cell'] = $cell;
  23268. }
  23269. }
  23270. }
  23271. // store current margins and page
  23272. $dom[$key]['old_cell_padding'] = $this->cell_padding;
  23273. if (isset($tag['attribute']['cellpadding'])) {
  23274. $pad = $this->getHTMLUnitToUnits($tag['attribute']['cellpadding'], 1, 'px');
  23275. $this->SetCellPadding($pad);
  23276. } elseif (isset($tag['padding'])) {
  23277. $this->cell_padding = $tag['padding'];
  23278. }
  23279. if (isset($tag['attribute']['cellspacing'])) {
  23280. $cs = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
  23281. } elseif (isset($tag['border-spacing'])) {
  23282. $cs = $tag['border-spacing']['V'];
  23283. }
  23284. $prev_y = $this->y;
  23285. if ($this->checkPageBreak(((2 * $cp) + (2 * $cs) + $this->lasth), '', false) OR ($this->y < $prev_y)) {
  23286. $this->inthead = true;
  23287. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  23288. $this->checkPageBreak($this->PageBreakTrigger + 1);
  23289. }
  23290. break;
  23291. }
  23292. case 'tr': {
  23293. // array of columns positions
  23294. $dom[$key]['cellpos'] = array();
  23295. break;
  23296. }
  23297. case 'hr': {
  23298. if ((isset($tag['height'])) AND ($tag['height'] != '')) {
  23299. $hrHeight = $this->getHTMLUnitToUnits($tag['height'], 1, 'px');
  23300. } else {
  23301. $hrHeight = $this->GetLineWidth();
  23302. }
  23303. $this->addHTMLVertSpace($hbz, ($hrHeight / 2), $cell, $firsttag);
  23304. $x = $this->GetX();
  23305. $y = $this->GetY();
  23306. $wtmp = $this->w - $this->lMargin - $this->rMargin;
  23307. if ($cell) {
  23308. $wtmp -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  23309. }
  23310. if ((isset($tag['width'])) AND ($tag['width'] != '')) {
  23311. $hrWidth = $this->getHTMLUnitToUnits($tag['width'], $wtmp, 'px');
  23312. } else {
  23313. $hrWidth = $wtmp;
  23314. }
  23315. $prevlinewidth = $this->GetLineWidth();
  23316. $this->SetLineWidth($hrHeight);
  23317. $this->Line($x, $y, $x + $hrWidth, $y);
  23318. $this->SetLineWidth($prevlinewidth);
  23319. $this->addHTMLVertSpace(($hrHeight / 2), 0, $cell, !isset($dom[($key + 1)]));
  23320. break;
  23321. }
  23322. case 'a': {
  23323. if (array_key_exists('href', $tag['attribute'])) {
  23324. $this->HREF['url'] = $tag['attribute']['href'];
  23325. }
  23326. break;
  23327. }
  23328. case 'img': {
  23329. if (isset($tag['attribute']['src'])) {
  23330. if ($tag['attribute']['src']{0} === '@') {
  23331. // data stream
  23332. $tag['attribute']['src'] = '@'.base64_decode(substr($tag['attribute']['src'], 1));
  23333. $type = '';
  23334. } else {
  23335. // check for images without protocol
  23336. if (preg_match('%^/{2}%', $tag['attribute']['src'])) {
  23337. $tag['attribute']['src'] = 'http:'.$tag['attribute']['src'];
  23338. }
  23339. // replace relative path with real server path
  23340. if (($tag['attribute']['src'][0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
  23341. $findroot = strpos($tag['attribute']['src'], $_SERVER['DOCUMENT_ROOT']);
  23342. if (($findroot === false) OR ($findroot > 1)) {
  23343. if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
  23344. $tag['attribute']['src'] = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$tag['attribute']['src'];
  23345. } else {
  23346. $tag['attribute']['src'] = $_SERVER['DOCUMENT_ROOT'].$tag['attribute']['src'];
  23347. }
  23348. }
  23349. }
  23350. $tag['attribute']['src'] = htmlspecialchars_decode(urldecode($tag['attribute']['src']));
  23351. $type = $this->getImageFileType($tag['attribute']['src']);
  23352. $testscrtype = @parse_url($tag['attribute']['src']);
  23353. if (!isset($testscrtype['query']) OR empty($testscrtype['query'])) {
  23354. // convert URL to server path
  23355. $tag['attribute']['src'] = str_replace(K_PATH_URL, K_PATH_MAIN, $tag['attribute']['src']);
  23356. }
  23357. }
  23358. if (!isset($tag['width'])) {
  23359. $tag['width'] = 0;
  23360. }
  23361. if (!isset($tag['height'])) {
  23362. $tag['height'] = 0;
  23363. }
  23364. //if (!isset($tag['attribute']['align'])) {
  23365. // the only alignment supported is "bottom"
  23366. // further development is required for other modes.
  23367. $tag['attribute']['align'] = 'bottom';
  23368. //}
  23369. switch($tag['attribute']['align']) {
  23370. case 'top': {
  23371. $align = 'T';
  23372. break;
  23373. }
  23374. case 'middle': {
  23375. $align = 'M';
  23376. break;
  23377. }
  23378. case 'bottom': {
  23379. $align = 'B';
  23380. break;
  23381. }
  23382. default: {
  23383. $align = 'B';
  23384. break;
  23385. }
  23386. }
  23387. $prevy = $this->y;
  23388. $xpos = $this->x;
  23389. $imglink = '';
  23390. if (isset($this->HREF['url']) AND !$this->empty_string($this->HREF['url'])) {
  23391. $imglink = $this->HREF['url'];
  23392. if ($imglink{0} == '#') {
  23393. // convert url to internal link
  23394. $lnkdata = explode(',', $imglink);
  23395. if (isset($lnkdata[0])) {
  23396. $page = intval(substr($lnkdata[0], 1));
  23397. if (empty($page) OR ($page <= 0)) {
  23398. $page = $this->page;
  23399. }
  23400. if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
  23401. $lnky = floatval($lnkdata[1]);
  23402. } else {
  23403. $lnky = 0;
  23404. }
  23405. $imglink = $this->AddLink();
  23406. $this->SetLink($imglink, $lnky, $page);
  23407. }
  23408. }
  23409. }
  23410. $border = 0;
  23411. if (isset($tag['border']) AND !empty($tag['border'])) {
  23412. // currently only support 1 (frame) or a combination of 'LTRB'
  23413. $border = $tag['border'];
  23414. }
  23415. $iw = '';
  23416. if (isset($tag['width'])) {
  23417. $iw = $this->getHTMLUnitToUnits($tag['width'], 1, 'px', false);
  23418. }
  23419. $ih = '';
  23420. if (isset($tag['height'])) {
  23421. $ih = $this->getHTMLUnitToUnits($tag['height'], 1, 'px', false);
  23422. }
  23423. if (($type == 'eps') OR ($type == 'ai')) {
  23424. $this->ImageEps($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, $imglink, true, $align, '', $border, true);
  23425. } elseif ($type == 'svg') {
  23426. $this->ImageSVG($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, $imglink, $align, '', $border, true);
  23427. } else {
  23428. $this->Image($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, '', $imglink, $align, false, 300, '', false, false, $border, false, false, true);
  23429. }
  23430. switch($align) {
  23431. case 'T': {
  23432. $this->y = $prevy;
  23433. break;
  23434. }
  23435. case 'M': {
  23436. $this->y = (($this->img_rb_y + $prevy - ($tag['fontsize'] / $this->k)) / 2) ;
  23437. break;
  23438. }
  23439. case 'B': {
  23440. $this->y = $this->img_rb_y - ($tag['fontsize'] / $this->k);
  23441. break;
  23442. }
  23443. }
  23444. }
  23445. break;
  23446. }
  23447. case 'dl': {
  23448. ++$this->listnum;
  23449. if ($this->listnum == 1) {
  23450. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  23451. } else {
  23452. $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
  23453. }
  23454. break;
  23455. }
  23456. case 'dt': {
  23457. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  23458. break;
  23459. }
  23460. case 'dd': {
  23461. if ($this->rtl) {
  23462. $this->rMargin += $this->listindent;
  23463. } else {
  23464. $this->lMargin += $this->listindent;
  23465. }
  23466. ++$this->listindentlevel;
  23467. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  23468. break;
  23469. }
  23470. case 'ul':
  23471. case 'ol': {
  23472. ++$this->listnum;
  23473. if ($tag['value'] == 'ol') {
  23474. $this->listordered[$this->listnum] = true;
  23475. } else {
  23476. $this->listordered[$this->listnum] = false;
  23477. }
  23478. if (isset($tag['attribute']['start'])) {
  23479. $this->listcount[$this->listnum] = intval($tag['attribute']['start']) - 1;
  23480. } else {
  23481. $this->listcount[$this->listnum] = 0;
  23482. }
  23483. if ($this->rtl) {
  23484. $this->rMargin += $this->listindent;
  23485. $this->x -= $this->listindent;
  23486. } else {
  23487. $this->lMargin += $this->listindent;
  23488. $this->x += $this->listindent;
  23489. }
  23490. ++$this->listindentlevel;
  23491. if ($this->listnum == 1) {
  23492. if ($key > 1) {
  23493. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  23494. }
  23495. } else {
  23496. $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
  23497. }
  23498. break;
  23499. }
  23500. case 'li': {
  23501. if ($key > 2) {
  23502. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  23503. }
  23504. if ($this->listordered[$this->listnum]) {
  23505. // ordered item
  23506. if (isset($parent['attribute']['type']) AND !$this->empty_string($parent['attribute']['type'])) {
  23507. $this->lispacer = $parent['attribute']['type'];
  23508. } elseif (isset($parent['listtype']) AND !$this->empty_string($parent['listtype'])) {
  23509. $this->lispacer = $parent['listtype'];
  23510. } elseif (isset($this->lisymbol) AND !$this->empty_string($this->lisymbol)) {
  23511. $this->lispacer = $this->lisymbol;
  23512. } else {
  23513. $this->lispacer = '#';
  23514. }
  23515. ++$this->listcount[$this->listnum];
  23516. if (isset($tag['attribute']['value'])) {
  23517. $this->listcount[$this->listnum] = intval($tag['attribute']['value']);
  23518. }
  23519. } else {
  23520. // unordered item
  23521. if (isset($parent['attribute']['type']) AND !$this->empty_string($parent['attribute']['type'])) {
  23522. $this->lispacer = $parent['attribute']['type'];
  23523. } elseif (isset($parent['listtype']) AND !$this->empty_string($parent['listtype'])) {
  23524. $this->lispacer = $parent['listtype'];
  23525. } elseif (isset($this->lisymbol) AND !$this->empty_string($this->lisymbol)) {
  23526. $this->lispacer = $this->lisymbol;
  23527. } else {
  23528. $this->lispacer = '!';
  23529. }
  23530. }
  23531. break;
  23532. }
  23533. case 'blockquote': {
  23534. if ($this->rtl) {
  23535. $this->rMargin += $this->listindent;
  23536. } else {
  23537. $this->lMargin += $this->listindent;
  23538. }
  23539. ++$this->listindentlevel;
  23540. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  23541. break;
  23542. }
  23543. case 'br': {
  23544. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  23545. break;
  23546. }
  23547. case 'div': {
  23548. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  23549. break;
  23550. }
  23551. case 'p': {
  23552. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  23553. break;
  23554. }
  23555. case 'pre': {
  23556. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  23557. $this->premode = true;
  23558. break;
  23559. }
  23560. case 'sup': {
  23561. $this->SetXY($this->GetX(), $this->GetY() - ((0.7 * $this->FontSizePt) / $this->k));
  23562. break;
  23563. }
  23564. case 'sub': {
  23565. $this->SetXY($this->GetX(), $this->GetY() + ((0.3 * $this->FontSizePt) / $this->k));
  23566. break;
  23567. }
  23568. case 'h1':
  23569. case 'h2':
  23570. case 'h3':
  23571. case 'h4':
  23572. case 'h5':
  23573. case 'h6': {
  23574. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  23575. break;
  23576. }
  23577. // Form fields (since 4.8.000 - 2009-09-07)
  23578. case 'form': {
  23579. if (isset($tag['attribute']['action'])) {
  23580. $this->form_action = $tag['attribute']['action'];
  23581. } else {
  23582. $this->form_action = K_PATH_URL.$_SERVER['SCRIPT_NAME'];
  23583. }
  23584. if (isset($tag['attribute']['enctype'])) {
  23585. $this->form_enctype = $tag['attribute']['enctype'];
  23586. } else {
  23587. $this->form_enctype = 'application/x-www-form-urlencoded';
  23588. }
  23589. if (isset($tag['attribute']['method'])) {
  23590. $this->form_mode = $tag['attribute']['method'];
  23591. } else {
  23592. $this->form_mode = 'post';
  23593. }
  23594. break;
  23595. }
  23596. case 'input': {
  23597. if (isset($tag['attribute']['name']) AND !$this->empty_string($tag['attribute']['name'])) {
  23598. $name = $tag['attribute']['name'];
  23599. } else {
  23600. break;
  23601. }
  23602. $prop = array();
  23603. $opt = array();
  23604. if (isset($tag['attribute']['readonly']) AND !$this->empty_string($tag['attribute']['readonly'])) {
  23605. $prop['readonly'] = true;
  23606. }
  23607. if (isset($tag['attribute']['value']) AND !$this->empty_string($tag['attribute']['value'])) {
  23608. $value = $tag['attribute']['value'];
  23609. }
  23610. if (isset($tag['attribute']['maxlength']) AND !$this->empty_string($tag['attribute']['maxlength'])) {
  23611. $opt['maxlen'] = intval($tag['attribute']['maxlength']);
  23612. }
  23613. $h = $this->FontSize * $this->cell_height_ratio;
  23614. if (isset($tag['attribute']['size']) AND !$this->empty_string($tag['attribute']['size'])) {
  23615. $w = intval($tag['attribute']['size']) * $this->GetStringWidth(chr(32)) * 2;
  23616. } else {
  23617. $w = $h;
  23618. }
  23619. if (isset($tag['attribute']['checked']) AND (($tag['attribute']['checked'] == 'checked') OR ($tag['attribute']['checked'] == 'true'))) {
  23620. $checked = true;
  23621. } else {
  23622. $checked = false;
  23623. }
  23624. if (isset($tag['align'])) {
  23625. switch ($tag['align']) {
  23626. case 'C': {
  23627. $opt['q'] = 1;
  23628. break;
  23629. }
  23630. case 'R': {
  23631. $opt['q'] = 2;
  23632. break;
  23633. }
  23634. case 'L':
  23635. default: {
  23636. break;
  23637. }
  23638. }
  23639. }
  23640. switch ($tag['attribute']['type']) {
  23641. case 'text': {
  23642. if (isset($value)) {
  23643. $opt['v'] = $value;
  23644. }
  23645. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  23646. break;
  23647. }
  23648. case 'password': {
  23649. if (isset($value)) {
  23650. $opt['v'] = $value;
  23651. }
  23652. $prop['password'] = 'true';
  23653. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  23654. break;
  23655. }
  23656. case 'checkbox': {
  23657. if (!isset($value)) {
  23658. break;
  23659. }
  23660. $this->CheckBox($name, $w, $checked, $prop, $opt, $value, '', '', false);
  23661. break;
  23662. }
  23663. case 'radio': {
  23664. if (!isset($value)) {
  23665. break;
  23666. }
  23667. $this->RadioButton($name, $w, $prop, $opt, $value, $checked, '', '', false);
  23668. break;
  23669. }
  23670. case 'submit': {
  23671. if (!isset($value)) {
  23672. $value = 'submit';
  23673. }
  23674. $w = $this->GetStringWidth($value) * 1.5;
  23675. $h *= 1.6;
  23676. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  23677. $action = array();
  23678. $action['S'] = 'SubmitForm';
  23679. $action['F'] = $this->form_action;
  23680. if ($this->form_enctype != 'FDF') {
  23681. $action['Flags'] = array('ExportFormat');
  23682. }
  23683. if ($this->form_mode == 'get') {
  23684. $action['Flags'] = array('GetMethod');
  23685. }
  23686. $this->Button($name, $w, $h, $value, $action, $prop, $opt, '', '', false);
  23687. break;
  23688. }
  23689. case 'reset': {
  23690. if (!isset($value)) {
  23691. $value = 'reset';
  23692. }
  23693. $w = $this->GetStringWidth($value) * 1.5;
  23694. $h *= 1.6;
  23695. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  23696. $this->Button($name, $w, $h, $value, array('S'=>'ResetForm'), $prop, $opt, '', '', false);
  23697. break;
  23698. }
  23699. case 'file': {
  23700. $prop['fileSelect'] = 'true';
  23701. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  23702. if (!isset($value)) {
  23703. $value = '*';
  23704. }
  23705. $w = $this->GetStringWidth($value) * 2;
  23706. $h *= 1.2;
  23707. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  23708. $jsaction = 'var f=this.getField(\''.$name.'\'); f.browseForFileToSubmit();';
  23709. $this->Button('FB_'.$name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  23710. break;
  23711. }
  23712. case 'hidden': {
  23713. if (isset($value)) {
  23714. $opt['v'] = $value;
  23715. }
  23716. $opt['f'] = array('invisible', 'hidden');
  23717. $this->TextField($name, 0, 0, $prop, $opt, '', '', false);
  23718. break;
  23719. }
  23720. case 'image': {
  23721. // THIS TYPE MUST BE FIXED
  23722. if (isset($tag['attribute']['src']) AND !$this->empty_string($tag['attribute']['src'])) {
  23723. $img = $tag['attribute']['src'];
  23724. } else {
  23725. break;
  23726. }
  23727. $value = 'img';
  23728. //$opt['mk'] = array('i'=>$img, 'tp'=>1, 'if'=>array('sw'=>'A', 's'=>'A', 'fb'=>false));
  23729. if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
  23730. $jsaction = $tag['attribute']['onclick'];
  23731. } else {
  23732. $jsaction = '';
  23733. }
  23734. $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  23735. break;
  23736. }
  23737. case 'button': {
  23738. if (!isset($value)) {
  23739. $value = ' ';
  23740. }
  23741. $w = $this->GetStringWidth($value) * 1.5;
  23742. $h *= 1.6;
  23743. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  23744. if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
  23745. $jsaction = $tag['attribute']['onclick'];
  23746. } else {
  23747. $jsaction = '';
  23748. }
  23749. $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  23750. break;
  23751. }
  23752. }
  23753. break;
  23754. }
  23755. case 'textarea': {
  23756. $prop = array();
  23757. $opt = array();
  23758. if (isset($tag['attribute']['readonly']) AND !$this->empty_string($tag['attribute']['readonly'])) {
  23759. $prop['readonly'] = true;
  23760. }
  23761. if (isset($tag['attribute']['name']) AND !$this->empty_string($tag['attribute']['name'])) {
  23762. $name = $tag['attribute']['name'];
  23763. } else {
  23764. break;
  23765. }
  23766. if (isset($tag['attribute']['value']) AND !$this->empty_string($tag['attribute']['value'])) {
  23767. $opt['v'] = $tag['attribute']['value'];
  23768. }
  23769. if (isset($tag['attribute']['cols']) AND !$this->empty_string($tag['attribute']['cols'])) {
  23770. $w = intval($tag['attribute']['cols']) * $this->GetStringWidth(chr(32)) * 2;
  23771. } else {
  23772. $w = 40;
  23773. }
  23774. if (isset($tag['attribute']['rows']) AND !$this->empty_string($tag['attribute']['rows'])) {
  23775. $h = intval($tag['attribute']['rows']) * $this->FontSize * $this->cell_height_ratio;
  23776. } else {
  23777. $h = 10;
  23778. }
  23779. $prop['multiline'] = 'true';
  23780. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  23781. break;
  23782. }
  23783. case 'select': {
  23784. $h = $this->FontSize * $this->cell_height_ratio;
  23785. if (isset($tag['attribute']['size']) AND !$this->empty_string($tag['attribute']['size'])) {
  23786. $h *= ($tag['attribute']['size'] + 1);
  23787. }
  23788. $prop = array();
  23789. $opt = array();
  23790. if (isset($tag['attribute']['name']) AND !$this->empty_string($tag['attribute']['name'])) {
  23791. $name = $tag['attribute']['name'];
  23792. } else {
  23793. break;
  23794. }
  23795. $w = 0;
  23796. if (isset($tag['attribute']['opt']) AND !$this->empty_string($tag['attribute']['opt'])) {
  23797. $options = explode('#!NwL!#', $tag['attribute']['opt']);
  23798. $values = array();
  23799. foreach ($options as $val) {
  23800. if (strpos($val, '#!TaB!#') !== false) {
  23801. $opts = explode('#!TaB!#', $val);
  23802. $values[] = $opts;
  23803. $w = max($w, $this->GetStringWidth($opts[1]));
  23804. } else {
  23805. $values[] = $val;
  23806. $w = max($w, $this->GetStringWidth($val));
  23807. }
  23808. }
  23809. } else {
  23810. break;
  23811. }
  23812. $w *= 2;
  23813. if (isset($tag['attribute']['multiple']) AND ($tag['attribute']['multiple']='multiple')) {
  23814. $prop['multipleSelection'] = 'true';
  23815. $this->ListBox($name, $w, $h, $values, $prop, $opt, '', '', false);
  23816. } else {
  23817. $this->ComboBox($name, $w, $h, $values, $prop, $opt, '', '', false);
  23818. }
  23819. break;
  23820. }
  23821. case 'tcpdf': {
  23822. if (defined('K_TCPDF_CALLS_IN_HTML') AND (K_TCPDF_CALLS_IN_HTML === true)) {
  23823. // Special tag used to call TCPDF methods
  23824. if (isset($tag['attribute']['method'])) {
  23825. $tcpdf_method = $tag['attribute']['method'];
  23826. if (method_exists($this, $tcpdf_method)) {
  23827. if (isset($tag['attribute']['params']) AND (!empty($tag['attribute']['params']))) {
  23828. $params = unserialize(urldecode($tag['attribute']['params']));
  23829. call_user_func_array(array($this, $tcpdf_method), $params);
  23830. } else {
  23831. $this->$tcpdf_method();
  23832. }
  23833. $this->newline = true;
  23834. }
  23835. }
  23836. }
  23837. break;
  23838. }
  23839. default: {
  23840. break;
  23841. }
  23842. }
  23843. // define tags that support borders and background colors
  23844. $bordertags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table');
  23845. if (in_array($tag['value'], $bordertags)) {
  23846. // set border
  23847. $dom[$key]['borderposition'] = $this->getBorderStartPosition();
  23848. }
  23849. if ($dom[$key]['self'] AND isset($dom[$key]['attribute']['pagebreakafter'])) {
  23850. $pba = $dom[$key]['attribute']['pagebreakafter'];
  23851. // check for pagebreak
  23852. if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
  23853. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  23854. $this->checkPageBreak($this->PageBreakTrigger + 1);
  23855. }
  23856. if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  23857. OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  23858. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  23859. $this->checkPageBreak($this->PageBreakTrigger + 1);
  23860. }
  23861. }
  23862. return $dom;
  23863. }
  23864. /**
  23865. * Process closing tags.
  23866. * @param $dom (array) html dom array
  23867. * @param $key (int) current element id
  23868. * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
  23869. * @param $maxbottomliney (int) maximum y value of current line
  23870. * @return $dom array
  23871. * @protected
  23872. */
  23873. protected function closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney=0) {
  23874. $tag = $dom[$key];
  23875. $parent = $dom[($dom[$key]['parent'])];
  23876. $lasttag = ((!isset($dom[($key + 1)])) OR ((!isset($dom[($key + 2)])) AND ($dom[($key + 1)]['value'] == 'marker')));
  23877. $in_table_head = false;
  23878. // maximum x position (used to draw borders)
  23879. if ($this->rtl) {
  23880. $xmax = $this->w;
  23881. } else {
  23882. $xmax = 0;
  23883. }
  23884. if ($tag['block']) {
  23885. $hbz = 0; // distance from y to line bottom
  23886. $hb = 0; // vertical space between block tags
  23887. // calculate vertical space for block tags
  23888. if (isset($this->tagvspaces[$tag['value']][1]['h']) AND ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) {
  23889. $pre_h = $this->tagvspaces[$tag['value']][1]['h'];
  23890. } elseif (isset($parent['fontsize'])) {
  23891. $pre_h = (($parent['fontsize'] / $this->k) * $this->cell_height_ratio);
  23892. } else {
  23893. $pre_h = $this->FontSize * $this->cell_height_ratio;
  23894. }
  23895. if (isset($this->tagvspaces[$tag['value']][1]['n'])) {
  23896. $n = $this->tagvspaces[$tag['value']][1]['n'];
  23897. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  23898. $n = 0.6;
  23899. } else {
  23900. $n = 1;
  23901. }
  23902. if ((!isset($this->tagvspaces[$tag['value']])) AND ($tag['value'] == 'div')) {
  23903. $hb = 0;
  23904. } else {
  23905. $hb = ($n * $pre_h);
  23906. }
  23907. if ($maxbottomliney > $this->PageBreakTrigger) {
  23908. $hbz = ($this->FontSize * $this->cell_height_ratio);
  23909. } elseif ($this->y < $maxbottomliney) {
  23910. $hbz = ($maxbottomliney - $this->y);
  23911. }
  23912. }
  23913. // Closing tag
  23914. switch($tag['value']) {
  23915. case 'tr': {
  23916. $table_el = $dom[($dom[$key]['parent'])]['parent'];
  23917. if (!isset($parent['endy'])) {
  23918. $dom[($dom[$key]['parent'])]['endy'] = $this->y;
  23919. $parent['endy'] = $this->y;
  23920. }
  23921. if (!isset($parent['endpage'])) {
  23922. $dom[($dom[$key]['parent'])]['endpage'] = $this->page;
  23923. $parent['endpage'] = $this->page;
  23924. }
  23925. if (!isset($parent['endcolumn'])) {
  23926. $dom[($dom[$key]['parent'])]['endcolumn'] = $this->current_column;
  23927. $parent['endcolumn'] = $this->current_column;
  23928. }
  23929. // update row-spanned cells
  23930. if (isset($dom[$table_el]['rowspans'])) {
  23931. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  23932. $dom[$table_el]['rowspans'][$k]['rowspan'] -= 1;
  23933. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  23934. if (($dom[$table_el]['rowspans'][$k]['endpage'] == $parent['endpage']) AND ($dom[$table_el]['rowspans'][$k]['endcolumn'] == $parent['endcolumn'])) {
  23935. $dom[($dom[$key]['parent'])]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $parent['endy']);
  23936. } elseif (($dom[$table_el]['rowspans'][$k]['endpage'] > $parent['endpage']) OR ($dom[$table_el]['rowspans'][$k]['endcolumn'] > $parent['endcolumn'])) {
  23937. $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  23938. $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  23939. $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  23940. }
  23941. }
  23942. }
  23943. // report new endy and endpage to the rowspanned cells
  23944. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  23945. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  23946. $dom[$table_el]['rowspans'][$k]['endpage'] = max($dom[$table_el]['rowspans'][$k]['endpage'], $dom[($dom[$key]['parent'])]['endpage']);
  23947. $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  23948. $dom[$table_el]['rowspans'][$k]['endcolumn'] = max($dom[$table_el]['rowspans'][$k]['endcolumn'], $dom[($dom[$key]['parent'])]['endcolumn']);
  23949. $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  23950. $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $dom[($dom[$key]['parent'])]['endy']);
  23951. $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  23952. }
  23953. }
  23954. // update remaining rowspanned cells
  23955. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  23956. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  23957. $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[($dom[$key]['parent'])]['endpage'];
  23958. $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[($dom[$key]['parent'])]['endcolumn'];
  23959. $dom[$table_el]['rowspans'][$k]['endy'] = $dom[($dom[$key]['parent'])]['endy'];
  23960. }
  23961. }
  23962. }
  23963. $this->setPage($dom[($dom[$key]['parent'])]['endpage']);
  23964. if ($this->num_columns > 1) {
  23965. $this->selectColumn($dom[($dom[$key]['parent'])]['endcolumn']);
  23966. }
  23967. $this->y = $dom[($dom[$key]['parent'])]['endy'];
  23968. if (isset($dom[$table_el]['attribute']['cellspacing'])) {
  23969. $this->y += $this->getHTMLUnitToUnits($dom[$table_el]['attribute']['cellspacing'], 1, 'px');
  23970. } elseif (isset($dom[$table_el]['border-spacing'])) {
  23971. $this->y += $dom[$table_el]['border-spacing']['V'];
  23972. }
  23973. $this->Ln(0, $cell);
  23974. if ($this->current_column == $parent['startcolumn']) {
  23975. $this->x = $parent['startx'];
  23976. }
  23977. // account for booklet mode
  23978. if ($this->page > $parent['startpage']) {
  23979. if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$parent['startpage']]['orm'])) {
  23980. $this->x -= ($this->pagedim[$this->page]['orm'] - $this->pagedim[$parent['startpage']]['orm']);
  23981. } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$parent['startpage']]['olm'])) {
  23982. $this->x += ($this->pagedim[$this->page]['olm'] - $this->pagedim[$parent['startpage']]['olm']);
  23983. }
  23984. }
  23985. break;
  23986. }
  23987. case 'tablehead':
  23988. // closing tag used for the thead part
  23989. $in_table_head = true;
  23990. $this->inthead = false;
  23991. case 'table': {
  23992. $table_el = $parent;
  23993. // set default border
  23994. if (isset($table_el['attribute']['border']) AND ($table_el['attribute']['border'] > 0)) {
  23995. // set default border
  23996. $border = array('LTRB' => array('width' => $this->getCSSBorderWidth($table_el['attribute']['border']), 'cap'=>'square', 'join'=>'miter', 'dash'=> 0, 'color'=>array(0,0,0)));
  23997. } else {
  23998. $border = 0;
  23999. }
  24000. $default_border = $border;
  24001. // fix bottom line alignment of last line before page break
  24002. foreach ($dom[($dom[$key]['parent'])]['trids'] as $j => $trkey) {
  24003. // update row-spanned cells
  24004. if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  24005. foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
  24006. if (isset($prevtrkey) AND ($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] > 0)) {
  24007. $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] = $trkey;
  24008. }
  24009. if ($dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] == $trkey) {
  24010. $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] -= 1;
  24011. }
  24012. }
  24013. }
  24014. if (isset($prevtrkey) AND ($dom[$trkey]['startpage'] > $dom[$prevtrkey]['endpage'])) {
  24015. $pgendy = $this->pagedim[$dom[$prevtrkey]['endpage']]['hk'] - $this->pagedim[$dom[$prevtrkey]['endpage']]['bm'];
  24016. $dom[$prevtrkey]['endy'] = $pgendy;
  24017. // update row-spanned cells
  24018. if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  24019. foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
  24020. if (($trwsp['trid'] == $trkey) AND ($trwsp['mrowspan'] > 1) AND ($trwsp['endpage'] == $dom[$prevtrkey]['endpage'])) {
  24021. $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'] = $pgendy;
  24022. $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] = -1;
  24023. }
  24024. }
  24025. }
  24026. }
  24027. $prevtrkey = $trkey;
  24028. $table_el = $dom[($dom[$key]['parent'])];
  24029. }
  24030. // for each row
  24031. if (count($table_el['trids']) > 0) {
  24032. unset($xmax);
  24033. }
  24034. foreach ($table_el['trids'] as $j => $trkey) {
  24035. $parent = $dom[$trkey];
  24036. if (!isset($xmax)) {
  24037. $xmax = $parent['cellpos'][(count($parent['cellpos']) - 1)]['endx'];
  24038. }
  24039. // for each cell on the row
  24040. foreach ($parent['cellpos'] as $k => $cellpos) {
  24041. if (isset($cellpos['rowspanid']) AND ($cellpos['rowspanid'] >= 0)) {
  24042. $cellpos['startx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['startx'];
  24043. $cellpos['endx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['endx'];
  24044. $endy = $table_el['rowspans'][($cellpos['rowspanid'])]['endy'];
  24045. $startpage = $table_el['rowspans'][($cellpos['rowspanid'])]['startpage'];
  24046. $endpage = $table_el['rowspans'][($cellpos['rowspanid'])]['endpage'];
  24047. $startcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['startcolumn'];
  24048. $endcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['endcolumn'];
  24049. } else {
  24050. $endy = $parent['endy'];
  24051. $startpage = $parent['startpage'];
  24052. $endpage = $parent['endpage'];
  24053. $startcolumn = $parent['startcolumn'];
  24054. $endcolumn = $parent['endcolumn'];
  24055. }
  24056. if ($this->num_columns == 0) {
  24057. $this->num_columns = 1;
  24058. }
  24059. if (isset($cellpos['border'])) {
  24060. $border = $cellpos['border'];
  24061. }
  24062. if (isset($cellpos['bgcolor']) AND ($cellpos['bgcolor']) !== false) {
  24063. $this->SetFillColorArray($cellpos['bgcolor']);
  24064. $fill = true;
  24065. } else {
  24066. $fill = false;
  24067. }
  24068. $x = $cellpos['startx'];
  24069. $y = $parent['starty'];
  24070. $starty = $y;
  24071. $w = abs($cellpos['endx'] - $cellpos['startx']);
  24072. // get border modes
  24073. $border_start = $this->getBorderMode($border, $position='start');
  24074. $border_end = $this->getBorderMode($border, $position='end');
  24075. $border_middle = $this->getBorderMode($border, $position='middle');
  24076. // design borders around HTML cells.
  24077. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  24078. $ccode = '';
  24079. $this->setPage($page);
  24080. if ($this->num_columns < 2) {
  24081. // single-column mode
  24082. $this->x = $x;
  24083. $this->y = $this->tMargin;
  24084. }
  24085. // account for margin changes
  24086. if ($page > $startpage) {
  24087. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  24088. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  24089. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  24090. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  24091. }
  24092. }
  24093. if ($startpage == $endpage) { // single page
  24094. $deltacol = 0;
  24095. $deltath = 0;
  24096. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  24097. $this->selectColumn($column);
  24098. if ($startcolumn == $endcolumn) { // single column
  24099. $cborder = $border;
  24100. $h = $endy - $parent['starty'];
  24101. $this->y = $y;
  24102. $this->x = $x;
  24103. } elseif ($column == $startcolumn) { // first column
  24104. $cborder = $border_start;
  24105. $this->y = $starty;
  24106. $this->x = $x;
  24107. $h = $this->h - $this->y - $this->bMargin;
  24108. if ($this->rtl) {
  24109. $deltacol = $this->x + $this->rMargin - $this->w;
  24110. } else {
  24111. $deltacol = $this->x - $this->lMargin;
  24112. }
  24113. } elseif ($column == $endcolumn) { // end column
  24114. $cborder = $border_end;
  24115. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  24116. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  24117. }
  24118. $this->x += $deltacol;
  24119. $h = $endy - $this->y;
  24120. } else { // middle column
  24121. $cborder = $border_middle;
  24122. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  24123. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  24124. }
  24125. $this->x += $deltacol;
  24126. $h = $this->h - $this->y - $this->bMargin;
  24127. }
  24128. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  24129. } // end for each column
  24130. } elseif ($page == $startpage) { // first page
  24131. $deltacol = 0;
  24132. $deltath = 0;
  24133. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  24134. $this->selectColumn($column);
  24135. if ($column == $startcolumn) { // first column
  24136. $cborder = $border_start;
  24137. $this->y = $starty;
  24138. $this->x = $x;
  24139. $h = $this->h - $this->y - $this->bMargin;
  24140. if ($this->rtl) {
  24141. $deltacol = $this->x + $this->rMargin - $this->w;
  24142. } else {
  24143. $deltacol = $this->x - $this->lMargin;
  24144. }
  24145. } else { // middle column
  24146. $cborder = $border_middle;
  24147. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  24148. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  24149. }
  24150. $this->x += $deltacol;
  24151. $h = $this->h - $this->y - $this->bMargin;
  24152. }
  24153. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  24154. } // end for each column
  24155. } elseif ($page == $endpage) { // last page
  24156. $deltacol = 0;
  24157. $deltath = 0;
  24158. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  24159. $this->selectColumn($column);
  24160. if ($column == $endcolumn) { // end column
  24161. $cborder = $border_end;
  24162. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  24163. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  24164. }
  24165. $this->x += $deltacol;
  24166. $h = $endy - $this->y;
  24167. } else { // middle column
  24168. $cborder = $border_middle;
  24169. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  24170. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  24171. }
  24172. $this->x += $deltacol;
  24173. $h = $this->h - $this->y - $this->bMargin;
  24174. }
  24175. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  24176. } // end for each column
  24177. } else { // middle page
  24178. $deltacol = 0;
  24179. $deltath = 0;
  24180. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  24181. $this->selectColumn($column);
  24182. $cborder = $border_middle;
  24183. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  24184. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  24185. }
  24186. $this->x += $deltacol;
  24187. $h = $this->h - $this->y - $this->bMargin;
  24188. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  24189. } // end for each column
  24190. }
  24191. if ($cborder OR $fill) {
  24192. $offsetlen = strlen($ccode);
  24193. // draw border and fill
  24194. if ($this->inxobj) {
  24195. // we are inside an XObject template
  24196. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  24197. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  24198. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  24199. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  24200. } else {
  24201. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  24202. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  24203. }
  24204. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  24205. $pstart = substr($pagebuff, 0, $pagemark);
  24206. $pend = substr($pagebuff, $pagemark);
  24207. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  24208. } else {
  24209. // draw border and fill
  24210. if (end($this->transfmrk[$this->page]) !== false) {
  24211. $pagemarkkey = key($this->transfmrk[$this->page]);
  24212. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  24213. } elseif ($this->InFooter) {
  24214. $pagemark = $this->footerpos[$this->page];
  24215. } else {
  24216. $pagemark = $this->intmrk[$this->page];
  24217. }
  24218. $pagebuff = $this->getPageBuffer($this->page);
  24219. $pstart = substr($pagebuff, 0, $pagemark);
  24220. $pend = substr($pagebuff, $pagemark);
  24221. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  24222. }
  24223. }
  24224. } // end for each page
  24225. // restore default border
  24226. $border = $default_border;
  24227. } // end for each cell on the row
  24228. if (isset($table_el['attribute']['cellspacing'])) {
  24229. $this->y += $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing'], 1, 'px');
  24230. } elseif (isset($table_el['border-spacing'])) {
  24231. $this->y += $table_el['border-spacing']['V'];
  24232. }
  24233. $this->Ln(0, $cell);
  24234. $this->x = $parent['startx'];
  24235. if ($endpage > $startpage) {
  24236. if (($this->rtl) AND ($this->pagedim[$endpage]['orm'] != $this->pagedim[$startpage]['orm'])) {
  24237. $this->x += ($this->pagedim[$endpage]['orm'] - $this->pagedim[$startpage]['orm']);
  24238. } elseif ((!$this->rtl) AND ($this->pagedim[$endpage]['olm'] != $this->pagedim[$startpage]['olm'])) {
  24239. $this->x += ($this->pagedim[$endpage]['olm'] - $this->pagedim[$startpage]['olm']);
  24240. }
  24241. }
  24242. }
  24243. if (!$in_table_head) { // we are not inside a thead section
  24244. $this->cell_padding = $table_el['old_cell_padding'];
  24245. // reset row height
  24246. $this->resetLastH();
  24247. if (($this->page == ($this->numpages - 1)) AND ($this->pageopen[$this->numpages])) {
  24248. $plendiff = ($this->pagelen[$this->numpages] - $this->emptypagemrk[$this->numpages]);
  24249. if (($plendiff > 0) AND ($plendiff < 60)) {
  24250. $pagediff = substr($this->getPageBuffer($this->numpages), $this->emptypagemrk[$this->numpages], $plendiff);
  24251. if (substr($pagediff, 0, 5) == 'BT /F') {
  24252. // the difference is only a font setting
  24253. $plendiff = 0;
  24254. }
  24255. }
  24256. if ($plendiff == 0) {
  24257. // remove last blank page
  24258. $this->deletePage($this->numpages);
  24259. }
  24260. }
  24261. if (isset($this->theadMargins['top'])) {
  24262. // restore top margin
  24263. $this->tMargin = $this->theadMargins['top'];
  24264. }
  24265. if (!isset($table_el['attribute']['nested']) OR ($table_el['attribute']['nested'] != 'true')) {
  24266. // reset main table header
  24267. $this->thead = '';
  24268. $this->theadMargins = array();
  24269. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  24270. }
  24271. }
  24272. $parent = $table_el;
  24273. break;
  24274. }
  24275. case 'a': {
  24276. $this->HREF = '';
  24277. break;
  24278. }
  24279. case 'sup': {
  24280. $this->SetXY($this->GetX(), $this->GetY() + ((0.7 * $parent['fontsize']) / $this->k));
  24281. break;
  24282. }
  24283. case 'sub': {
  24284. $this->SetXY($this->GetX(), $this->GetY() - ((0.3 * $parent['fontsize']) / $this->k));
  24285. break;
  24286. }
  24287. case 'div': {
  24288. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  24289. break;
  24290. }
  24291. case 'blockquote': {
  24292. if ($this->rtl) {
  24293. $this->rMargin -= $this->listindent;
  24294. } else {
  24295. $this->lMargin -= $this->listindent;
  24296. }
  24297. --$this->listindentlevel;
  24298. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  24299. break;
  24300. }
  24301. case 'p': {
  24302. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  24303. break;
  24304. }
  24305. case 'pre': {
  24306. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  24307. $this->premode = false;
  24308. break;
  24309. }
  24310. case 'dl': {
  24311. --$this->listnum;
  24312. if ($this->listnum <= 0) {
  24313. $this->listnum = 0;
  24314. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  24315. } else {
  24316. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  24317. }
  24318. $this->resetLastH();
  24319. break;
  24320. }
  24321. case 'dt': {
  24322. $this->lispacer = '';
  24323. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  24324. break;
  24325. }
  24326. case 'dd': {
  24327. $this->lispacer = '';
  24328. if ($this->rtl) {
  24329. $this->rMargin -= $this->listindent;
  24330. } else {
  24331. $this->lMargin -= $this->listindent;
  24332. }
  24333. --$this->listindentlevel;
  24334. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  24335. break;
  24336. }
  24337. case 'ul':
  24338. case 'ol': {
  24339. --$this->listnum;
  24340. $this->lispacer = '';
  24341. if ($this->rtl) {
  24342. $this->rMargin -= $this->listindent;
  24343. } else {
  24344. $this->lMargin -= $this->listindent;
  24345. }
  24346. --$this->listindentlevel;
  24347. if ($this->listnum <= 0) {
  24348. $this->listnum = 0;
  24349. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  24350. } else {
  24351. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  24352. }
  24353. $this->resetLastH();
  24354. break;
  24355. }
  24356. case 'li': {
  24357. $this->lispacer = '';
  24358. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  24359. break;
  24360. }
  24361. case 'h1':
  24362. case 'h2':
  24363. case 'h3':
  24364. case 'h4':
  24365. case 'h5':
  24366. case 'h6': {
  24367. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  24368. break;
  24369. }
  24370. // Form fields (since 4.8.000 - 2009-09-07)
  24371. case 'form': {
  24372. $this->form_action = '';
  24373. $this->form_enctype = 'application/x-www-form-urlencoded';
  24374. break;
  24375. }
  24376. default : {
  24377. break;
  24378. }
  24379. }
  24380. // draw border and background (if any)
  24381. $this->drawHTMLTagBorder($parent, $xmax);
  24382. if (isset($dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'])) {
  24383. $pba = $dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'];
  24384. // check for pagebreak
  24385. if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
  24386. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  24387. $this->checkPageBreak($this->PageBreakTrigger + 1);
  24388. }
  24389. if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  24390. OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  24391. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  24392. $this->checkPageBreak($this->PageBreakTrigger + 1);
  24393. }
  24394. }
  24395. $this->tmprtl = false;
  24396. return $dom;
  24397. }
  24398. /**
  24399. * Add vertical spaces if needed.
  24400. * @param $hbz (string) Distance between current y and line bottom.
  24401. * @param $hb (string) The height of the break.
  24402. * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
  24403. * @param $firsttag (boolean) set to true when the tag is the first.
  24404. * @param $lasttag (boolean) set to true when the tag is the last.
  24405. * @protected
  24406. */
  24407. protected function addHTMLVertSpace($hbz=0, $hb=0, $cell=false, $firsttag=false, $lasttag=false) {
  24408. if ($firsttag) {
  24409. $this->Ln(0, $cell);
  24410. $this->htmlvspace = 0;
  24411. return;
  24412. }
  24413. if ($lasttag) {
  24414. $this->Ln($hbz, $cell);
  24415. $this->htmlvspace = 0;
  24416. return;
  24417. }
  24418. if ($hb < $this->htmlvspace) {
  24419. $hd = 0;
  24420. } else {
  24421. $hd = $hb - $this->htmlvspace;
  24422. $this->htmlvspace = $hb;
  24423. }
  24424. $this->Ln(($hbz + $hd), $cell);
  24425. }
  24426. /**
  24427. * Return the starting coordinates to draw an html border
  24428. * @return array containing top-left border coordinates
  24429. * @protected
  24430. * @since 5.7.000 (2010-08-03)
  24431. */
  24432. protected function getBorderStartPosition() {
  24433. if ($this->rtl) {
  24434. $xmax = $this->lMargin;
  24435. } else {
  24436. $xmax = $this->w - $this->rMargin;
  24437. }
  24438. return array('page' => $this->page, 'column' => $this->current_column, 'x' => $this->x, 'y' => $this->y, 'xmax' => $xmax);
  24439. }
  24440. /**
  24441. * Draw an HTML block border and fill
  24442. * @param $tag (array) array of tag properties.
  24443. * @param $xmax (int) end X coordinate for border.
  24444. * @protected
  24445. * @since 5.7.000 (2010-08-03)
  24446. */
  24447. protected function drawHTMLTagBorder($tag, $xmax) {
  24448. if (!isset($tag['borderposition'])) {
  24449. // nothing to draw
  24450. return;
  24451. }
  24452. $prev_x = $this->x;
  24453. $prev_y = $this->y;
  24454. $prev_lasth = $this->lasth;
  24455. $border = 0;
  24456. $fill = false;
  24457. $this->lasth = 0;
  24458. if (isset($tag['border']) AND !empty($tag['border'])) {
  24459. // get border style
  24460. $border = $tag['border'];
  24461. if (!$this->empty_string($this->thead) AND (!$this->inthead)) {
  24462. // border for table header
  24463. $border = $this->getBorderMode($border, $position='middle');
  24464. }
  24465. }
  24466. if (isset($tag['bgcolor']) AND ($tag['bgcolor'] !== false)) {
  24467. // get background color
  24468. $old_bgcolor = $this->bgcolor;
  24469. $this->SetFillColorArray($tag['bgcolor']);
  24470. $fill = true;
  24471. }
  24472. if (!$border AND !$fill) {
  24473. // nothing to draw
  24474. return;
  24475. }
  24476. if (isset($tag['attribute']['cellspacing'])) {
  24477. $clsp = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
  24478. $cellspacing = array('H' => $clsp, 'V' => $clsp);
  24479. } elseif (isset($tag['border-spacing'])) {
  24480. $cellspacing = $tag['border-spacing'];
  24481. } else {
  24482. $cellspacing = array('H' => 0, 'V' => 0);
  24483. }
  24484. if (($tag['value'] != 'table') AND (is_array($border)) AND (!empty($border))) {
  24485. // draw the border externally respect the sqare edge.
  24486. $border['mode'] = 'ext';
  24487. }
  24488. if ($this->rtl) {
  24489. if ($xmax >= $tag['borderposition']['x']) {
  24490. $xmax = $tag['borderposition']['xmax'];
  24491. }
  24492. $w = ($tag['borderposition']['x'] - $xmax);
  24493. } else {
  24494. if ($xmax <= $tag['borderposition']['x']) {
  24495. $xmax = $tag['borderposition']['xmax'];
  24496. }
  24497. $w = ($xmax - $tag['borderposition']['x']);
  24498. }
  24499. if ($w <= 0) {
  24500. return;
  24501. }
  24502. $w += $cellspacing['H'];
  24503. $startpage = $tag['borderposition']['page'];
  24504. $startcolumn = $tag['borderposition']['column'];
  24505. $x = $tag['borderposition']['x'];
  24506. $y = $tag['borderposition']['y'];
  24507. $endpage = $this->page;
  24508. $starty = $tag['borderposition']['y'] - $cellspacing['V'];
  24509. $currentY = $this->y;
  24510. $this->x = $x;
  24511. // get latest column
  24512. $endcolumn = $this->current_column;
  24513. if ($this->num_columns == 0) {
  24514. $this->num_columns = 1;
  24515. }
  24516. // get border modes
  24517. $border_start = $this->getBorderMode($border, $position='start');
  24518. $border_end = $this->getBorderMode($border, $position='end');
  24519. $border_middle = $this->getBorderMode($border, $position='middle');
  24520. // temporary disable page regions
  24521. $temp_page_regions = $this->page_regions;
  24522. $this->page_regions = array();
  24523. // design borders around HTML cells.
  24524. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  24525. $ccode = '';
  24526. $this->setPage($page);
  24527. if ($this->num_columns < 2) {
  24528. // single-column mode
  24529. $this->x = $x;
  24530. $this->y = $this->tMargin;
  24531. }
  24532. // account for margin changes
  24533. if ($page > $startpage) {
  24534. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  24535. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  24536. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  24537. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  24538. }
  24539. }
  24540. if ($startpage == $endpage) {
  24541. // single page
  24542. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  24543. $this->selectColumn($column);
  24544. if ($startcolumn == $endcolumn) { // single column
  24545. $cborder = $border;
  24546. $h = ($currentY - $y) + $cellspacing['V'];
  24547. $this->y = $starty;
  24548. } elseif ($column == $startcolumn) { // first column
  24549. $cborder = $border_start;
  24550. $this->y = $starty;
  24551. $h = $this->h - $this->y - $this->bMargin;
  24552. } elseif ($column == $endcolumn) { // end column
  24553. $cborder = $border_end;
  24554. $h = $currentY - $this->y;
  24555. } else { // middle column
  24556. $cborder = $border_middle;
  24557. $h = $this->h - $this->y - $this->bMargin;
  24558. }
  24559. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  24560. } // end for each column
  24561. } elseif ($page == $startpage) { // first page
  24562. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  24563. $this->selectColumn($column);
  24564. if ($column == $startcolumn) { // first column
  24565. $cborder = $border_start;
  24566. $this->y = $starty;
  24567. $h = $this->h - $this->y - $this->bMargin;
  24568. } else { // middle column
  24569. $cborder = $border_middle;
  24570. $h = $this->h - $this->y - $this->bMargin;
  24571. }
  24572. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  24573. } // end for each column
  24574. } elseif ($page == $endpage) { // last page
  24575. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  24576. $this->selectColumn($column);
  24577. if ($column == $endcolumn) {
  24578. // end column
  24579. $cborder = $border_end;
  24580. $h = $currentY - $this->y;
  24581. } else {
  24582. // middle column
  24583. $cborder = $border_middle;
  24584. $h = $this->h - $this->y - $this->bMargin;
  24585. }
  24586. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  24587. } // end for each column
  24588. } else { // middle page
  24589. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  24590. $this->selectColumn($column);
  24591. $cborder = $border_middle;
  24592. $h = $this->h - $this->y - $this->bMargin;
  24593. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  24594. } // end for each column
  24595. }
  24596. if ($cborder OR $fill) {
  24597. $offsetlen = strlen($ccode);
  24598. // draw border and fill
  24599. if ($this->inxobj) {
  24600. // we are inside an XObject template
  24601. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  24602. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  24603. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  24604. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  24605. } else {
  24606. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  24607. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  24608. }
  24609. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  24610. $pstart = substr($pagebuff, 0, $pagemark);
  24611. $pend = substr($pagebuff, $pagemark);
  24612. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  24613. } else {
  24614. if (end($this->transfmrk[$this->page]) !== false) {
  24615. $pagemarkkey = key($this->transfmrk[$this->page]);
  24616. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  24617. } elseif ($this->InFooter) {
  24618. $pagemark = $this->footerpos[$this->page];
  24619. } else {
  24620. $pagemark = $this->intmrk[$this->page];
  24621. }
  24622. $pagebuff = $this->getPageBuffer($this->page);
  24623. $pstart = substr($pagebuff, 0, $pagemark);
  24624. $pend = substr($pagebuff, $pagemark);
  24625. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  24626. $this->bordermrk[$this->page] += $offsetlen;
  24627. $this->cntmrk[$this->page] += $offsetlen;
  24628. }
  24629. }
  24630. } // end for each page
  24631. // restore page regions
  24632. $this->page_regions = $temp_page_regions;
  24633. if (isset($old_bgcolor)) {
  24634. // restore background color
  24635. $this->SetFillColorArray($old_bgcolor);
  24636. }
  24637. // restore pointer position
  24638. $this->x = $prev_x;
  24639. $this->y = $prev_y;
  24640. $this->lasth = $prev_lasth;
  24641. }
  24642. /**
  24643. * Set the default bullet to be used as LI bullet symbol
  24644. * @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')
  24645. * @public
  24646. * @since 4.0.028 (2008-09-26)
  24647. */
  24648. public function setLIsymbol($symbol='!') {
  24649. // check for custom image symbol
  24650. if (substr($symbol, 0, 4) == 'img|') {
  24651. $this->lisymbol = $symbol;
  24652. return;
  24653. }
  24654. $symbol = strtolower($symbol);
  24655. switch ($symbol) {
  24656. case '!' :
  24657. case '#' :
  24658. case 'disc' :
  24659. case 'circle' :
  24660. case 'square' :
  24661. case '1':
  24662. case 'decimal':
  24663. case 'decimal-leading-zero':
  24664. case 'i':
  24665. case 'lower-roman':
  24666. case 'I':
  24667. case 'upper-roman':
  24668. case 'a':
  24669. case 'lower-alpha':
  24670. case 'lower-latin':
  24671. case 'A':
  24672. case 'upper-alpha':
  24673. case 'upper-latin':
  24674. case 'lower-greek': {
  24675. $this->lisymbol = $symbol;
  24676. break;
  24677. }
  24678. default : {
  24679. $this->lisymbol = '';
  24680. }
  24681. }
  24682. }
  24683. /**
  24684. * Set the booklet mode for double-sided pages.
  24685. * @param $booklet (boolean) true set the booklet mode on, false otherwise.
  24686. * @param $inner (float) Inner page margin.
  24687. * @param $outer (float) Outer page margin.
  24688. * @public
  24689. * @since 4.2.000 (2008-10-29)
  24690. */
  24691. public function SetBooklet($booklet=true, $inner=-1, $outer=-1) {
  24692. $this->booklet = $booklet;
  24693. if ($inner >= 0) {
  24694. $this->lMargin = $inner;
  24695. }
  24696. if ($outer >= 0) {
  24697. $this->rMargin = $outer;
  24698. }
  24699. }
  24700. /**
  24701. * Swap the left and right margins.
  24702. * @param $reverse (boolean) if true swap left and right margins.
  24703. * @protected
  24704. * @since 4.2.000 (2008-10-29)
  24705. */
  24706. protected function swapMargins($reverse=true) {
  24707. if ($reverse) {
  24708. // swap left and right margins
  24709. $mtemp = $this->original_lMargin;
  24710. $this->original_lMargin = $this->original_rMargin;
  24711. $this->original_rMargin = $mtemp;
  24712. $deltam = $this->original_lMargin - $this->original_rMargin;
  24713. $this->lMargin += $deltam;
  24714. $this->rMargin -= $deltam;
  24715. }
  24716. }
  24717. /**
  24718. * Set the vertical spaces for HTML tags.
  24719. * The array must have the following structure (example):
  24720. * $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1)));
  24721. * The first array level contains the tag names,
  24722. * the second level contains 0 for opening tags or 1 for closing tags,
  24723. * the third level contains the vertical space unit (h) and the number spaces to add (n).
  24724. * If the h parameter is not specified, default values are used.
  24725. * @param $tagvs (array) array of tags and relative vertical spaces.
  24726. * @public
  24727. * @since 4.2.001 (2008-10-30)
  24728. */
  24729. public function setHtmlVSpace($tagvs) {
  24730. $this->tagvspaces = $tagvs;
  24731. }
  24732. /**
  24733. * Set custom width for list indentation.
  24734. * @param $width (float) width of the indentation. Use negative value to disable it.
  24735. * @public
  24736. * @since 4.2.007 (2008-11-12)
  24737. */
  24738. public function setListIndentWidth($width) {
  24739. return $this->customlistindent = floatval($width);
  24740. }
  24741. /**
  24742. * Set the top/bottom cell sides to be open or closed when the cell cross the page.
  24743. * @param $isopen (boolean) if true keeps the top/bottom border open for the cell sides that cross the page.
  24744. * @public
  24745. * @since 4.2.010 (2008-11-14)
  24746. */
  24747. public function setOpenCell($isopen) {
  24748. $this->opencell = $isopen;
  24749. }
  24750. /**
  24751. * Set the color and font style for HTML links.
  24752. * @param $color (array) RGB array of colors
  24753. * @param $fontstyle (string) additional font styles to add
  24754. * @public
  24755. * @since 4.4.003 (2008-12-09)
  24756. */
  24757. public function setHtmlLinksStyle($color=array(0,0,255), $fontstyle='U') {
  24758. $this->htmlLinkColorArray = $color;
  24759. $this->htmlLinkFontStyle = $fontstyle;
  24760. }
  24761. /**
  24762. * Convert HTML string containing value and unit of measure to user's units or points.
  24763. * @param $htmlval (string) string containing values and unit
  24764. * @param $refsize (string) reference value in points
  24765. * @param $defaultunit (string) default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  24766. * @param $points (boolean) if true returns points, otherwise returns value in user's units
  24767. * @return float value in user's unit or point if $points=true
  24768. * @public
  24769. * @since 4.4.004 (2008-12-10)
  24770. */
  24771. public function getHTMLUnitToUnits($htmlval, $refsize=1, $defaultunit='px', $points=false) {
  24772. $supportedunits = array('%', 'em', 'ex', 'px', 'in', 'cm', 'mm', 'pc', 'pt');
  24773. $retval = 0;
  24774. $value = 0;
  24775. $unit = 'px';
  24776. $k = $this->k;
  24777. if ($points) {
  24778. $k = 1;
  24779. }
  24780. if (in_array($defaultunit, $supportedunits)) {
  24781. $unit = $defaultunit;
  24782. }
  24783. if (is_numeric($htmlval)) {
  24784. $value = floatval($htmlval);
  24785. } elseif (preg_match('/([0-9\.\-\+]+)/', $htmlval, $mnum)) {
  24786. $value = floatval($mnum[1]);
  24787. if (preg_match('/([a-z%]+)/', $htmlval, $munit)) {
  24788. if (in_array($munit[1], $supportedunits)) {
  24789. $unit = $munit[1];
  24790. }
  24791. }
  24792. }
  24793. switch ($unit) {
  24794. // percentage
  24795. case '%': {
  24796. $retval = (($value * $refsize) / 100);
  24797. break;
  24798. }
  24799. // relative-size
  24800. case 'em': {
  24801. $retval = ($value * $refsize);
  24802. break;
  24803. }
  24804. // height of lower case 'x' (about half the font-size)
  24805. case 'ex': {
  24806. $retval = $value * ($refsize / 2);
  24807. break;
  24808. }
  24809. // absolute-size
  24810. case 'in': {
  24811. $retval = ($value * $this->dpi) / $k;
  24812. break;
  24813. }
  24814. // centimeters
  24815. case 'cm': {
  24816. $retval = ($value / 2.54 * $this->dpi) / $k;
  24817. break;
  24818. }
  24819. // millimeters
  24820. case 'mm': {
  24821. $retval = ($value / 25.4 * $this->dpi) / $k;
  24822. break;
  24823. }
  24824. // one pica is 12 points
  24825. case 'pc': {
  24826. $retval = ($value * 12) / $k;
  24827. break;
  24828. }
  24829. // points
  24830. case 'pt': {
  24831. $retval = $value / $k;
  24832. break;
  24833. }
  24834. // pixels
  24835. case 'px': {
  24836. $retval = $this->pixelsToUnits($value);
  24837. break;
  24838. }
  24839. }
  24840. return $retval;
  24841. }
  24842. /**
  24843. * Returns the Roman representation of an integer number
  24844. * @param $number (int) number to convert
  24845. * @return string roman representation of the specified number
  24846. * @since 4.4.004 (2008-12-10)
  24847. * @public
  24848. */
  24849. public function intToRoman($number) {
  24850. $roman = '';
  24851. while ($number >= 1000) {
  24852. $roman .= 'M';
  24853. $number -= 1000;
  24854. }
  24855. while ($number >= 900) {
  24856. $roman .= 'CM';
  24857. $number -= 900;
  24858. }
  24859. while ($number >= 500) {
  24860. $roman .= 'D';
  24861. $number -= 500;
  24862. }
  24863. while ($number >= 400) {
  24864. $roman .= 'CD';
  24865. $number -= 400;
  24866. }
  24867. while ($number >= 100) {
  24868. $roman .= 'C';
  24869. $number -= 100;
  24870. }
  24871. while ($number >= 90) {
  24872. $roman .= 'XC';
  24873. $number -= 90;
  24874. }
  24875. while ($number >= 50) {
  24876. $roman .= 'L';
  24877. $number -= 50;
  24878. }
  24879. while ($number >= 40) {
  24880. $roman .= 'XL';
  24881. $number -= 40;
  24882. }
  24883. while ($number >= 10) {
  24884. $roman .= 'X';
  24885. $number -= 10;
  24886. }
  24887. while ($number >= 9) {
  24888. $roman .= 'IX';
  24889. $number -= 9;
  24890. }
  24891. while ($number >= 5) {
  24892. $roman .= 'V';
  24893. $number -= 5;
  24894. }
  24895. while ($number >= 4) {
  24896. $roman .= 'IV';
  24897. $number -= 4;
  24898. }
  24899. while ($number >= 1) {
  24900. $roman .= 'I';
  24901. --$number;
  24902. }
  24903. return $roman;
  24904. }
  24905. /**
  24906. * Output an HTML list bullet or ordered item symbol
  24907. * @param $listdepth (int) list nesting level
  24908. * @param $listtype (string) type of list
  24909. * @param $size (float) current font size
  24910. * @protected
  24911. * @since 4.4.004 (2008-12-10)
  24912. */
  24913. protected function putHtmlListBullet($listdepth, $listtype='', $size=10) {
  24914. if ($this->state != 2) {
  24915. return;
  24916. }
  24917. $size /= $this->k;
  24918. $fill = '';
  24919. $bgcolor = $this->bgcolor;
  24920. $color = $this->fgcolor;
  24921. $strokecolor = $this->strokecolor;
  24922. $width = 0;
  24923. $textitem = '';
  24924. $tmpx = $this->x;
  24925. $lspace = $this->GetStringWidth(' ');
  24926. if ($listtype == '^') {
  24927. // special symbol used for avoid justification of rect bullet
  24928. $this->lispacer = '';
  24929. return;
  24930. } elseif ($listtype == '!') {
  24931. // set default list type for unordered list
  24932. $deftypes = array('disc', 'circle', 'square');
  24933. $listtype = $deftypes[($listdepth - 1) % 3];
  24934. } elseif ($listtype == '#') {
  24935. // set default list type for ordered list
  24936. $listtype = 'decimal';
  24937. } elseif (substr($listtype, 0, 4) == 'img|') {
  24938. // custom image type ('img|type|width|height|image.ext')
  24939. $img = explode('|', $listtype);
  24940. $listtype = 'img';
  24941. }
  24942. switch ($listtype) {
  24943. // unordered types
  24944. case 'none': {
  24945. break;
  24946. }
  24947. case 'disc': {
  24948. $r = $size / 6;
  24949. $lspace += (2 * $r);
  24950. if ($this->rtl) {
  24951. $this->x += $lspace;
  24952. } else {
  24953. $this->x -= $lspace;
  24954. }
  24955. $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), $r, 0, 360, 'F', array(), $color, 8);
  24956. break;
  24957. }
  24958. case 'circle': {
  24959. $r = $size / 6;
  24960. $lspace += (2 * $r);
  24961. if ($this->rtl) {
  24962. $this->x += $lspace;
  24963. } else {
  24964. $this->x -= $lspace;
  24965. }
  24966. $prev_line_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor;
  24967. $new_line_style = array('width' => ($r / 3), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'phase' => 0, 'color'=>$color);
  24968. $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), ($r * (1 - (1/6))), 0, 360, 'D', $new_line_style, array(), 8);
  24969. $this->_out($prev_line_style); // restore line settings
  24970. break;
  24971. }
  24972. case 'square': {
  24973. $l = $size / 3;
  24974. $lspace += $l;
  24975. if ($this->rtl) {;
  24976. $this->x += $lspace;
  24977. } else {
  24978. $this->x -= $lspace;
  24979. }
  24980. $this->Rect($this->x, ($this->y + (($this->lasth - $l) / 2)), $l, $l, 'F', array(), $color);
  24981. break;
  24982. }
  24983. case 'img': {
  24984. // 1=>type, 2=>width, 3=>height, 4=>image.ext
  24985. $lspace += $img[2];
  24986. if ($this->rtl) {;
  24987. $this->x += $lspace;
  24988. } else {
  24989. $this->x -= $lspace;
  24990. }
  24991. $imgtype = strtolower($img[1]);
  24992. $prev_y = $this->y;
  24993. switch ($imgtype) {
  24994. case 'svg': {
  24995. $this->ImageSVG($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', 'T', '', 0, false);
  24996. break;
  24997. }
  24998. case 'ai':
  24999. case 'eps': {
  25000. $this->ImageEps($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', true, 'T', '', 0, false);
  25001. break;
  25002. }
  25003. default: {
  25004. $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);
  25005. break;
  25006. }
  25007. }
  25008. $this->y = $prev_y;
  25009. break;
  25010. }
  25011. // ordered types
  25012. // $this->listcount[$this->listnum];
  25013. // $textitem
  25014. case '1':
  25015. case 'decimal': {
  25016. $textitem = $this->listcount[$this->listnum];
  25017. break;
  25018. }
  25019. case 'decimal-leading-zero': {
  25020. $textitem = sprintf('%02d', $this->listcount[$this->listnum]);
  25021. break;
  25022. }
  25023. case 'i':
  25024. case 'lower-roman': {
  25025. $textitem = strtolower($this->intToRoman($this->listcount[$this->listnum]));
  25026. break;
  25027. }
  25028. case 'I':
  25029. case 'upper-roman': {
  25030. $textitem = $this->intToRoman($this->listcount[$this->listnum]);
  25031. break;
  25032. }
  25033. case 'a':
  25034. case 'lower-alpha':
  25035. case 'lower-latin': {
  25036. $textitem = chr(97 + $this->listcount[$this->listnum] - 1);
  25037. break;
  25038. }
  25039. case 'A':
  25040. case 'upper-alpha':
  25041. case 'upper-latin': {
  25042. $textitem = chr(65 + $this->listcount[$this->listnum] - 1);
  25043. break;
  25044. }
  25045. case 'lower-greek': {
  25046. $textitem = $this->unichr(945 + $this->listcount[$this->listnum] - 1);
  25047. break;
  25048. }
  25049. /*
  25050. // Types to be implemented (special handling)
  25051. case 'hebrew': {
  25052. break;
  25053. }
  25054. case 'armenian': {
  25055. break;
  25056. }
  25057. case 'georgian': {
  25058. break;
  25059. }
  25060. case 'cjk-ideographic': {
  25061. break;
  25062. }
  25063. case 'hiragana': {
  25064. break;
  25065. }
  25066. case 'katakana': {
  25067. break;
  25068. }
  25069. case 'hiragana-iroha': {
  25070. break;
  25071. }
  25072. case 'katakana-iroha': {
  25073. break;
  25074. }
  25075. */
  25076. default: {
  25077. $textitem = $this->listcount[$this->listnum];
  25078. }
  25079. }
  25080. if (!$this->empty_string($textitem)) {
  25081. // Check whether we need a new page or new column
  25082. $prev_y = $this->y;
  25083. $h = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  25084. if ($this->checkPageBreak($h) OR ($this->y < $prev_y)) {
  25085. $tmpx = $this->x;
  25086. }
  25087. // print ordered item
  25088. if ($this->rtl) {
  25089. $textitem = '.'.$textitem;
  25090. } else {
  25091. $textitem = $textitem.'.';
  25092. }
  25093. $lspace += $this->GetStringWidth($textitem);
  25094. if ($this->rtl) {
  25095. $this->x += $lspace;
  25096. } else {
  25097. $this->x -= $lspace;
  25098. }
  25099. $this->Write($this->lasth, $textitem, '', false, '', false, 0, false);
  25100. }
  25101. $this->x = $tmpx;
  25102. $this->lispacer = '^';
  25103. // restore colors
  25104. $this->SetFillColorArray($bgcolor);
  25105. $this->SetDrawColorArray($strokecolor);
  25106. $this->SettextColorArray($color);
  25107. }
  25108. /**
  25109. * Returns current graphic variables as array.
  25110. * @return array of graphic variables
  25111. * @protected
  25112. * @since 4.2.010 (2008-11-14)
  25113. */
  25114. protected function getGraphicVars() {
  25115. $grapvars = array(
  25116. 'FontFamily' => $this->FontFamily,
  25117. 'FontStyle' => $this->FontStyle,
  25118. 'FontSizePt' => $this->FontSizePt,
  25119. 'rMargin' => $this->rMargin,
  25120. 'lMargin' => $this->lMargin,
  25121. 'cell_padding' => $this->cell_padding,
  25122. 'cell_margin' => $this->cell_margin,
  25123. 'LineWidth' => $this->LineWidth,
  25124. 'linestyleWidth' => $this->linestyleWidth,
  25125. 'linestyleCap' => $this->linestyleCap,
  25126. 'linestyleJoin' => $this->linestyleJoin,
  25127. 'linestyleDash' => $this->linestyleDash,
  25128. 'textrendermode' => $this->textrendermode,
  25129. 'textstrokewidth' => $this->textstrokewidth,
  25130. 'DrawColor' => $this->DrawColor,
  25131. 'FillColor' => $this->FillColor,
  25132. 'TextColor' => $this->TextColor,
  25133. 'ColorFlag' => $this->ColorFlag,
  25134. 'bgcolor' => $this->bgcolor,
  25135. 'fgcolor' => $this->fgcolor,
  25136. 'htmlvspace' => $this->htmlvspace,
  25137. 'listindent' => $this->listindent,
  25138. 'listindentlevel' => $this->listindentlevel,
  25139. 'listnum' => $this->listnum,
  25140. 'listordered' => $this->listordered,
  25141. 'listcount' => $this->listcount,
  25142. 'lispacer' => $this->lispacer,
  25143. 'cell_height_ratio' => $this->cell_height_ratio,
  25144. 'font_stretching' => $this->font_stretching,
  25145. 'font_spacing' => $this->font_spacing,
  25146. 'alpha' => $this->alpha,
  25147. // extended
  25148. 'lasth' => $this->lasth,
  25149. 'tMargin' => $this->tMargin,
  25150. 'bMargin' => $this->bMargin,
  25151. 'AutoPageBreak' => $this->AutoPageBreak,
  25152. 'PageBreakTrigger' => $this->PageBreakTrigger,
  25153. 'x' => $this->x,
  25154. 'y' => $this->y,
  25155. 'w' => $this->w,
  25156. 'h' => $this->h,
  25157. 'wPt' => $this->wPt,
  25158. 'hPt' => $this->hPt,
  25159. 'fwPt' => $this->fwPt,
  25160. 'fhPt' => $this->fhPt,
  25161. 'page' => $this->page,
  25162. 'current_column' => $this->current_column,
  25163. 'num_columns' => $this->num_columns
  25164. );
  25165. return $grapvars;
  25166. }
  25167. /**
  25168. * Set graphic variables.
  25169. * @param $gvars (array) array of graphic variablesto restore
  25170. * @param $extended (boolean) if true restore extended graphic variables
  25171. * @protected
  25172. * @since 4.2.010 (2008-11-14)
  25173. */
  25174. protected function setGraphicVars($gvars, $extended=false) {
  25175. if ($this->state != 2) {
  25176. return;
  25177. }
  25178. $this->FontFamily = $gvars['FontFamily'];
  25179. $this->FontStyle = $gvars['FontStyle'];
  25180. $this->FontSizePt = $gvars['FontSizePt'];
  25181. $this->rMargin = $gvars['rMargin'];
  25182. $this->lMargin = $gvars['lMargin'];
  25183. $this->cell_padding = $gvars['cell_padding'];
  25184. $this->cell_margin = $gvars['cell_margin'];
  25185. $this->LineWidth = $gvars['LineWidth'];
  25186. $this->linestyleWidth = $gvars['linestyleWidth'];
  25187. $this->linestyleCap = $gvars['linestyleCap'];
  25188. $this->linestyleJoin = $gvars['linestyleJoin'];
  25189. $this->linestyleDash = $gvars['linestyleDash'];
  25190. $this->textrendermode = $gvars['textrendermode'];
  25191. $this->textstrokewidth = $gvars['textstrokewidth'];
  25192. $this->DrawColor = $gvars['DrawColor'];
  25193. $this->FillColor = $gvars['FillColor'];
  25194. $this->TextColor = $gvars['TextColor'];
  25195. $this->ColorFlag = $gvars['ColorFlag'];
  25196. $this->bgcolor = $gvars['bgcolor'];
  25197. $this->fgcolor = $gvars['fgcolor'];
  25198. $this->htmlvspace = $gvars['htmlvspace'];
  25199. $this->listindent = $gvars['listindent'];
  25200. $this->listindentlevel = $gvars['listindentlevel'];
  25201. $this->listnum = $gvars['listnum'];
  25202. $this->listordered = $gvars['listordered'];
  25203. $this->listcount = $gvars['listcount'];
  25204. $this->lispacer = $gvars['lispacer'];
  25205. $this->cell_height_ratio = $gvars['cell_height_ratio'];
  25206. $this->font_stretching = $gvars['font_stretching'];
  25207. $this->font_spacing = $gvars['font_spacing'];
  25208. $this->alpha = $gvars['alpha'];
  25209. if ($extended) {
  25210. // restore extended values
  25211. $this->lasth = $gvars['lasth'];
  25212. $this->tMargin = $gvars['tMargin'];
  25213. $this->bMargin = $gvars['bMargin'];
  25214. $this->AutoPageBreak = $gvars['AutoPageBreak'];
  25215. $this->PageBreakTrigger = $gvars['PageBreakTrigger'];
  25216. $this->x = $gvars['x'];
  25217. $this->y = $gvars['y'];
  25218. $this->w = $gvars['w'];
  25219. $this->h = $gvars['h'];
  25220. $this->wPt = $gvars['wPt'];
  25221. $this->hPt = $gvars['hPt'];
  25222. $this->fwPt = $gvars['fwPt'];
  25223. $this->fhPt = $gvars['fhPt'];
  25224. $this->page = $gvars['page'];
  25225. $this->current_column = $gvars['current_column'];
  25226. $this->num_columns = $gvars['num_columns'];
  25227. }
  25228. $this->_out(''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor.'');
  25229. if (!$this->empty_string($this->FontFamily)) {
  25230. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  25231. }
  25232. }
  25233. /**
  25234. * Returns a temporary filename for caching object on filesystem.
  25235. * @param $name (string) prefix to add to filename
  25236. * @return string filename.
  25237. * @since 4.5.000 (2008-12-31)
  25238. * @protected
  25239. */
  25240. protected function getObjFilename($name) {
  25241. return tempnam(K_PATH_CACHE, $name.'_');
  25242. }
  25243. /**
  25244. * Writes data to a temporary file on filesystem.
  25245. * @param $filename (string) file name
  25246. * @param $data (mixed) data to write on file
  25247. * @param $append (boolean) if true append data, false replace.
  25248. * @since 4.5.000 (2008-12-31)
  25249. * @protected
  25250. */
  25251. protected function writeDiskCache($filename, $data, $append=false) {
  25252. if ($append) {
  25253. $fmode = 'ab+';
  25254. } else {
  25255. $fmode = 'wb+';
  25256. }
  25257. $f = @fopen($filename, $fmode);
  25258. if (!$f) {
  25259. $this->Error('Unable to write cache file: '.$filename);
  25260. } else {
  25261. fwrite($f, $data);
  25262. fclose($f);
  25263. }
  25264. // update file length (needed for transactions)
  25265. if (!isset($this->cache_file_length['_'.$filename])) {
  25266. $this->cache_file_length['_'.$filename] = strlen($data);
  25267. } else {
  25268. $this->cache_file_length['_'.$filename] += strlen($data);
  25269. }
  25270. }
  25271. /**
  25272. * Read data from a temporary file on filesystem.
  25273. * @param $filename (string) file name
  25274. * @return mixed retrieved data
  25275. * @since 4.5.000 (2008-12-31)
  25276. * @protected
  25277. */
  25278. protected function readDiskCache($filename) {
  25279. return file_get_contents($filename);
  25280. }
  25281. /**
  25282. * Set buffer content (always append data).
  25283. * @param $data (string) data
  25284. * @protected
  25285. * @since 4.5.000 (2009-01-02)
  25286. */
  25287. protected function setBuffer($data) {
  25288. $this->bufferlen += strlen($data);
  25289. if ($this->diskcache) {
  25290. if (!isset($this->buffer) OR $this->empty_string($this->buffer)) {
  25291. $this->buffer = $this->getObjFilename('buffer');
  25292. }
  25293. $this->writeDiskCache($this->buffer, $data, true);
  25294. } else {
  25295. $this->buffer .= $data;
  25296. }
  25297. }
  25298. /**
  25299. * Replace the buffer content
  25300. * @param $data (string) data
  25301. * @protected
  25302. * @since 5.5.000 (2010-06-22)
  25303. */
  25304. protected function replaceBuffer($data) {
  25305. $this->bufferlen = strlen($data);
  25306. if ($this->diskcache) {
  25307. if (!isset($this->buffer) OR $this->empty_string($this->buffer)) {
  25308. $this->buffer = $this->getObjFilename('buffer');
  25309. }
  25310. $this->writeDiskCache($this->buffer, $data, false);
  25311. } else {
  25312. $this->buffer = $data;
  25313. }
  25314. }
  25315. /**
  25316. * Get buffer content.
  25317. * @return string buffer content
  25318. * @protected
  25319. * @since 4.5.000 (2009-01-02)
  25320. */
  25321. protected function getBuffer() {
  25322. if ($this->diskcache) {
  25323. return $this->readDiskCache($this->buffer);
  25324. } else {
  25325. return $this->buffer;
  25326. }
  25327. }
  25328. /**
  25329. * Set page buffer content.
  25330. * @param $page (int) page number
  25331. * @param $data (string) page data
  25332. * @param $append (boolean) if true append data, false replace.
  25333. * @protected
  25334. * @since 4.5.000 (2008-12-31)
  25335. */
  25336. protected function setPageBuffer($page, $data, $append=false) {
  25337. if ($this->diskcache) {
  25338. if (!isset($this->pages[$page])) {
  25339. $this->pages[$page] = $this->getObjFilename('page'.$page);
  25340. }
  25341. $this->writeDiskCache($this->pages[$page], $data, $append);
  25342. } else {
  25343. if ($append) {
  25344. $this->pages[$page] .= $data;
  25345. } else {
  25346. $this->pages[$page] = $data;
  25347. }
  25348. }
  25349. if ($append AND isset($this->pagelen[$page])) {
  25350. $this->pagelen[$page] += strlen($data);
  25351. } else {
  25352. $this->pagelen[$page] = strlen($data);
  25353. }
  25354. }
  25355. /**
  25356. * Get page buffer content.
  25357. * @param $page (int) page number
  25358. * @return string page buffer content or false in case of error
  25359. * @protected
  25360. * @since 4.5.000 (2008-12-31)
  25361. */
  25362. protected function getPageBuffer($page) {
  25363. if ($this->diskcache) {
  25364. return $this->readDiskCache($this->pages[$page]);
  25365. } elseif (isset($this->pages[$page])) {
  25366. return $this->pages[$page];
  25367. }
  25368. return false;
  25369. }
  25370. /**
  25371. * Set image buffer content.
  25372. * @param $image (string) image key
  25373. * @param $data (array) image data
  25374. * @return int image index number
  25375. * @protected
  25376. * @since 4.5.000 (2008-12-31)
  25377. */
  25378. protected function setImageBuffer($image, $data) {
  25379. if (($data['i'] = array_search($image, $this->imagekeys)) === FALSE) {
  25380. $this->imagekeys[$this->numimages] = $image;
  25381. $data['i'] = $this->numimages;
  25382. ++$this->numimages;
  25383. }
  25384. if ($this->diskcache) {
  25385. if (!isset($this->images[$image])) {
  25386. $this->images[$image] = $this->getObjFilename('image'.$image);
  25387. }
  25388. $this->writeDiskCache($this->images[$image], serialize($data));
  25389. } else {
  25390. $this->images[$image] = $data;
  25391. }
  25392. return $data['i'];
  25393. }
  25394. /**
  25395. * Set image buffer content for a specified sub-key.
  25396. * @param $image (string) image key
  25397. * @param $key (string) image sub-key
  25398. * @param $data (array) image data
  25399. * @protected
  25400. * @since 4.5.000 (2008-12-31)
  25401. */
  25402. protected function setImageSubBuffer($image, $key, $data) {
  25403. if (!isset($this->images[$image])) {
  25404. $this->setImageBuffer($image, array());
  25405. }
  25406. if ($this->diskcache) {
  25407. $tmpimg = $this->getImageBuffer($image);
  25408. $tmpimg[$key] = $data;
  25409. $this->writeDiskCache($this->images[$image], serialize($tmpimg));
  25410. } else {
  25411. $this->images[$image][$key] = $data;
  25412. }
  25413. }
  25414. /**
  25415. * Get image buffer content.
  25416. * @param $image (string) image key
  25417. * @return string image buffer content or false in case of error
  25418. * @protected
  25419. * @since 4.5.000 (2008-12-31)
  25420. */
  25421. protected function getImageBuffer($image) {
  25422. if ($this->diskcache AND isset($this->images[$image])) {
  25423. return unserialize($this->readDiskCache($this->images[$image]));
  25424. } elseif (isset($this->images[$image])) {
  25425. return $this->images[$image];
  25426. }
  25427. return false;
  25428. }
  25429. /**
  25430. * Set font buffer content.
  25431. * @param $font (string) font key
  25432. * @param $data (array) font data
  25433. * @protected
  25434. * @since 4.5.000 (2009-01-02)
  25435. */
  25436. protected function setFontBuffer($font, $data) {
  25437. if ($this->diskcache) {
  25438. if (!isset($this->fonts[$font])) {
  25439. $this->fonts[$font] = $this->getObjFilename('font');
  25440. }
  25441. $this->writeDiskCache($this->fonts[$font], serialize($data));
  25442. } else {
  25443. $this->fonts[$font] = $data;
  25444. }
  25445. if (!in_array($font, $this->fontkeys)) {
  25446. $this->fontkeys[] = $font;
  25447. // store object ID for current font
  25448. ++$this->n;
  25449. $this->font_obj_ids[$font] = $this->n;
  25450. $this->setFontSubBuffer($font, 'n', $this->n);
  25451. }
  25452. }
  25453. /**
  25454. * Set font buffer content.
  25455. * @param $font (string) font key
  25456. * @param $key (string) font sub-key
  25457. * @param $data (array) font data
  25458. * @protected
  25459. * @since 4.5.000 (2009-01-02)
  25460. */
  25461. protected function setFontSubBuffer($font, $key, $data) {
  25462. if (!isset($this->fonts[$font])) {
  25463. $this->setFontBuffer($font, array());
  25464. }
  25465. if ($this->diskcache) {
  25466. $tmpfont = $this->getFontBuffer($font);
  25467. $tmpfont[$key] = $data;
  25468. $this->writeDiskCache($this->fonts[$font], serialize($tmpfont));
  25469. } else {
  25470. $this->fonts[$font][$key] = $data;
  25471. }
  25472. }
  25473. /**
  25474. * Get font buffer content.
  25475. * @param $font (string) font key
  25476. * @return string font buffer content or false in case of error
  25477. * @protected
  25478. * @since 4.5.000 (2009-01-02)
  25479. */
  25480. protected function getFontBuffer($font) {
  25481. if ($this->diskcache AND isset($this->fonts[$font])) {
  25482. return unserialize($this->readDiskCache($this->fonts[$font]));
  25483. } elseif (isset($this->fonts[$font])) {
  25484. return $this->fonts[$font];
  25485. }
  25486. return false;
  25487. }
  25488. /**
  25489. * Move a page to a previous position.
  25490. * @param $frompage (int) number of the source page
  25491. * @param $topage (int) number of the destination page (must be less than $frompage)
  25492. * @return true in case of success, false in case of error.
  25493. * @public
  25494. * @since 4.5.000 (2009-01-02)
  25495. */
  25496. public function movePage($frompage, $topage) {
  25497. if (($frompage > $this->numpages) OR ($frompage <= $topage)) {
  25498. return false;
  25499. }
  25500. if ($frompage == $this->page) {
  25501. // close the page before moving it
  25502. $this->endPage();
  25503. }
  25504. // move all page-related states
  25505. $tmppage = $this->getPageBuffer($frompage);
  25506. $tmppagedim = $this->pagedim[$frompage];
  25507. $tmppagelen = $this->pagelen[$frompage];
  25508. $tmpintmrk = $this->intmrk[$frompage];
  25509. $tmpbordermrk = $this->bordermrk[$frompage];
  25510. $tmpcntmrk = $this->cntmrk[$frompage];
  25511. $tmppageobjects = $this->pageobjects[$frompage];
  25512. if (isset($this->footerpos[$frompage])) {
  25513. $tmpfooterpos = $this->footerpos[$frompage];
  25514. }
  25515. if (isset($this->footerlen[$frompage])) {
  25516. $tmpfooterlen = $this->footerlen[$frompage];
  25517. }
  25518. if (isset($this->transfmrk[$frompage])) {
  25519. $tmptransfmrk = $this->transfmrk[$frompage];
  25520. }
  25521. if (isset($this->PageAnnots[$frompage])) {
  25522. $tmpannots = $this->PageAnnots[$frompage];
  25523. }
  25524. if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
  25525. for ($i = $frompage; $i > $topage; --$i) {
  25526. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $frompage)) {
  25527. --$this->pagegroups[$this->newpagegroup[$i]];
  25528. break;
  25529. }
  25530. }
  25531. for ($i = $topage; $i > 0; --$i) {
  25532. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $topage)) {
  25533. ++$this->pagegroups[$this->newpagegroup[$i]];
  25534. break;
  25535. }
  25536. }
  25537. }
  25538. for ($i = $frompage; $i > $topage; --$i) {
  25539. $j = $i - 1;
  25540. // shift pages down
  25541. $this->setPageBuffer($i, $this->getPageBuffer($j));
  25542. $this->pagedim[$i] = $this->pagedim[$j];
  25543. $this->pagelen[$i] = $this->pagelen[$j];
  25544. $this->intmrk[$i] = $this->intmrk[$j];
  25545. $this->bordermrk[$i] = $this->bordermrk[$j];
  25546. $this->cntmrk[$i] = $this->cntmrk[$j];
  25547. $this->pageobjects[$i] = $this->pageobjects[$j];
  25548. if (isset($this->footerpos[$j])) {
  25549. $this->footerpos[$i] = $this->footerpos[$j];
  25550. } elseif (isset($this->footerpos[$i])) {
  25551. unset($this->footerpos[$i]);
  25552. }
  25553. if (isset($this->footerlen[$j])) {
  25554. $this->footerlen[$i] = $this->footerlen[$j];
  25555. } elseif (isset($this->footerlen[$i])) {
  25556. unset($this->footerlen[$i]);
  25557. }
  25558. if (isset($this->transfmrk[$j])) {
  25559. $this->transfmrk[$i] = $this->transfmrk[$j];
  25560. } elseif (isset($this->transfmrk[$i])) {
  25561. unset($this->transfmrk[$i]);
  25562. }
  25563. if (isset($this->PageAnnots[$j])) {
  25564. $this->PageAnnots[$i] = $this->PageAnnots[$j];
  25565. } elseif (isset($this->PageAnnots[$i])) {
  25566. unset($this->PageAnnots[$i]);
  25567. }
  25568. if (isset($this->newpagegroup[$j])) {
  25569. $this->newpagegroup[$i] = $this->newpagegroup[$j];
  25570. unset($this->newpagegroup[$j]);
  25571. }
  25572. if ($this->currpagegroup == $j) {
  25573. $this->currpagegroup = $i;
  25574. }
  25575. }
  25576. $this->setPageBuffer($topage, $tmppage);
  25577. $this->pagedim[$topage] = $tmppagedim;
  25578. $this->pagelen[$topage] = $tmppagelen;
  25579. $this->intmrk[$topage] = $tmpintmrk;
  25580. $this->bordermrk[$topage] = $tmpbordermrk;
  25581. $this->cntmrk[$topage] = $tmpcntmrk;
  25582. $this->pageobjects[$topage] = $tmppageobjects;
  25583. if (isset($tmpfooterpos)) {
  25584. $this->footerpos[$topage] = $tmpfooterpos;
  25585. } elseif (isset($this->footerpos[$topage])) {
  25586. unset($this->footerpos[$topage]);
  25587. }
  25588. if (isset($tmpfooterlen)) {
  25589. $this->footerlen[$topage] = $tmpfooterlen;
  25590. } elseif (isset($this->footerlen[$topage])) {
  25591. unset($this->footerlen[$topage]);
  25592. }
  25593. if (isset($tmptransfmrk)) {
  25594. $this->transfmrk[$topage] = $tmptransfmrk;
  25595. } elseif (isset($this->transfmrk[$topage])) {
  25596. unset($this->transfmrk[$topage]);
  25597. }
  25598. if (isset($tmpannots)) {
  25599. $this->PageAnnots[$topage] = $tmpannots;
  25600. } elseif (isset($this->PageAnnots[$topage])) {
  25601. unset($this->PageAnnots[$topage]);
  25602. }
  25603. // adjust outlines
  25604. $tmpoutlines = $this->outlines;
  25605. foreach ($tmpoutlines as $key => $outline) {
  25606. if (($outline['p'] >= $topage) AND ($outline['p'] < $frompage)) {
  25607. $this->outlines[$key]['p'] = ($outline['p'] + 1);
  25608. } elseif ($outline['p'] == $frompage) {
  25609. $this->outlines[$key]['p'] = $topage;
  25610. }
  25611. }
  25612. // adjust dests
  25613. $tmpdests = $this->dests;
  25614. foreach ($tmpdests as $key => $dest) {
  25615. if (($dest['p'] >= $topage) AND ($dest['p'] < $frompage)) {
  25616. $this->dests[$key]['p'] = ($dest['p'] + 1);
  25617. } elseif ($dest['p'] == $frompage) {
  25618. $this->dests[$key]['p'] = $topage;
  25619. }
  25620. }
  25621. // adjust links
  25622. $tmplinks = $this->links;
  25623. foreach ($tmplinks as $key => $link) {
  25624. if (($link[0] >= $topage) AND ($link[0] < $frompage)) {
  25625. $this->links[$key][0] = ($link[0] + 1);
  25626. } elseif ($link[0] == $frompage) {
  25627. $this->links[$key][0] = $topage;
  25628. }
  25629. }
  25630. // adjust javascript
  25631. $tmpjavascript = $this->javascript;
  25632. global $jfrompage, $jtopage;
  25633. $jfrompage = $frompage;
  25634. $jtopage = $topage;
  25635. $this->javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/',
  25636. create_function('$matches', 'global $jfrompage, $jtopage;
  25637. $pagenum = intval($matches[3]) + 1;
  25638. if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) {
  25639. $newpage = ($pagenum + 1);
  25640. } elseif ($pagenum == $jfrompage) {
  25641. $newpage = $jtopage;
  25642. } else {
  25643. $newpage = $pagenum;
  25644. }
  25645. --$newpage;
  25646. return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript);
  25647. // return to last page
  25648. $this->lastPage(true);
  25649. return true;
  25650. }
  25651. /**
  25652. * Remove the specified page.
  25653. * @param $page (int) page to remove
  25654. * @return true in case of success, false in case of error.
  25655. * @public
  25656. * @since 4.6.004 (2009-04-23)
  25657. */
  25658. public function deletePage($page) {
  25659. if (($page < 1) OR ($page > $this->numpages)) {
  25660. return false;
  25661. }
  25662. // delete current page
  25663. unset($this->pages[$page]);
  25664. unset($this->pagedim[$page]);
  25665. unset($this->pagelen[$page]);
  25666. unset($this->intmrk[$page]);
  25667. unset($this->bordermrk[$page]);
  25668. unset($this->cntmrk[$page]);
  25669. foreach ($this->pageobjects[$page] as $oid) {
  25670. if (isset($this->offsets[$oid])){
  25671. unset($this->offsets[$oid]);
  25672. }
  25673. }
  25674. unset($this->pageobjects[$page]);
  25675. if (isset($this->footerpos[$page])) {
  25676. unset($this->footerpos[$page]);
  25677. }
  25678. if (isset($this->footerlen[$page])) {
  25679. unset($this->footerlen[$page]);
  25680. }
  25681. if (isset($this->transfmrk[$page])) {
  25682. unset($this->transfmrk[$page]);
  25683. }
  25684. if (isset($this->PageAnnots[$page])) {
  25685. unset($this->PageAnnots[$page]);
  25686. }
  25687. if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
  25688. for ($i = $page; $i > 0; --$i) {
  25689. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $page)) {
  25690. --$this->pagegroups[$this->newpagegroup[$i]];
  25691. break;
  25692. }
  25693. }
  25694. }
  25695. if (isset($this->pageopen[$page])) {
  25696. unset($this->pageopen[$page]);
  25697. }
  25698. if ($page < $this->numpages) {
  25699. // update remaining pages
  25700. for ($i = $page; $i < $this->numpages; ++$i) {
  25701. $j = $i + 1;
  25702. // shift pages
  25703. $this->setPageBuffer($i, $this->getPageBuffer($j));
  25704. $this->pagedim[$i] = $this->pagedim[$j];
  25705. $this->pagelen[$i] = $this->pagelen[$j];
  25706. $this->intmrk[$i] = $this->intmrk[$j];
  25707. $this->bordermrk[$i] = $this->bordermrk[$j];
  25708. $this->cntmrk[$i] = $this->cntmrk[$j];
  25709. $this->pageobjects[$i] = $this->pageobjects[$j];
  25710. if (isset($this->footerpos[$j])) {
  25711. $this->footerpos[$i] = $this->footerpos[$j];
  25712. } elseif (isset($this->footerpos[$i])) {
  25713. unset($this->footerpos[$i]);
  25714. }
  25715. if (isset($this->footerlen[$j])) {
  25716. $this->footerlen[$i] = $this->footerlen[$j];
  25717. } elseif (isset($this->footerlen[$i])) {
  25718. unset($this->footerlen[$i]);
  25719. }
  25720. if (isset($this->transfmrk[$j])) {
  25721. $this->transfmrk[$i] = $this->transfmrk[$j];
  25722. } elseif (isset($this->transfmrk[$i])) {
  25723. unset($this->transfmrk[$i]);
  25724. }
  25725. if (isset($this->PageAnnots[$j])) {
  25726. $this->PageAnnots[$i] = $this->PageAnnots[$j];
  25727. } elseif (isset($this->PageAnnots[$i])) {
  25728. unset($this->PageAnnots[$i]);
  25729. }
  25730. if (isset($this->newpagegroup[$j])) {
  25731. $this->newpagegroup[$i] = $this->newpagegroup[$j];
  25732. unset($this->newpagegroup[$j]);
  25733. }
  25734. if ($this->currpagegroup == $j) {
  25735. $this->currpagegroup = $i;
  25736. }
  25737. if (isset($this->pageopen[$j])) {
  25738. $this->pageopen[$i] = $this->pageopen[$j];
  25739. } elseif (isset($this->pageopen[$i])) {
  25740. unset($this->pageopen[$i]);
  25741. }
  25742. }
  25743. // remove last page
  25744. unset($this->pages[$this->numpages]);
  25745. unset($this->pagedim[$this->numpages]);
  25746. unset($this->pagelen[$this->numpages]);
  25747. unset($this->intmrk[$this->numpages]);
  25748. unset($this->bordermrk[$this->numpages]);
  25749. unset($this->cntmrk[$this->numpages]);
  25750. foreach ($this->pageobjects[$this->numpages] as $oid) {
  25751. if (isset($this->offsets[$oid])){
  25752. unset($this->offsets[$oid]);
  25753. }
  25754. }
  25755. unset($this->pageobjects[$this->numpages]);
  25756. if (isset($this->footerpos[$this->numpages])) {
  25757. unset($this->footerpos[$this->numpages]);
  25758. }
  25759. if (isset($this->footerlen[$this->numpages])) {
  25760. unset($this->footerlen[$this->numpages]);
  25761. }
  25762. if (isset($this->transfmrk[$this->numpages])) {
  25763. unset($this->transfmrk[$this->numpages]);
  25764. }
  25765. if (isset($this->PageAnnots[$this->numpages])) {
  25766. unset($this->PageAnnots[$this->numpages]);
  25767. }
  25768. if (isset($this->newpagegroup[$this->numpages])) {
  25769. unset($this->newpagegroup[$this->numpages]);
  25770. }
  25771. if ($this->currpagegroup == $this->numpages) {
  25772. $this->currpagegroup = ($this->numpages - 1);
  25773. }
  25774. if (isset($this->pagegroups[$this->numpages])) {
  25775. unset($this->pagegroups[$this->numpages]);
  25776. }
  25777. if (isset($this->pageopen[$this->numpages])) {
  25778. unset($this->pageopen[$this->numpages]);
  25779. }
  25780. }
  25781. --$this->numpages;
  25782. $this->page = $this->numpages;
  25783. // adjust outlines
  25784. $tmpoutlines = $this->outlines;
  25785. foreach ($tmpoutlines as $key => $outline) {
  25786. if ($outline['p'] > $page) {
  25787. $this->outlines[$key]['p'] = $outline['p'] - 1;
  25788. } elseif ($outline['p'] == $page) {
  25789. unset($this->outlines[$key]);
  25790. }
  25791. }
  25792. // adjust dests
  25793. $tmpdests = $this->dests;
  25794. foreach ($tmpdests as $key => $dest) {
  25795. if ($dest['p'] > $page) {
  25796. $this->dests[$key]['p'] = $dest['p'] - 1;
  25797. } elseif ($dest['p'] == $page) {
  25798. unset($this->dests[$key]);
  25799. }
  25800. }
  25801. // adjust links
  25802. $tmplinks = $this->links;
  25803. foreach ($tmplinks as $key => $link) {
  25804. if ($link[0] > $page) {
  25805. $this->links[$key][0] = $link[0] - 1;
  25806. } elseif ($link[0] == $page) {
  25807. unset($this->links[$key]);
  25808. }
  25809. }
  25810. // adjust javascript
  25811. $tmpjavascript = $this->javascript;
  25812. global $jpage;
  25813. $jpage = $page;
  25814. $this->javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/',
  25815. create_function('$matches', 'global $jpage;
  25816. $pagenum = intval($matches[3]) + 1;
  25817. if ($pagenum >= $jpage) {
  25818. $newpage = ($pagenum - 1);
  25819. } elseif ($pagenum == $jpage) {
  25820. $newpage = 1;
  25821. } else {
  25822. $newpage = $pagenum;
  25823. }
  25824. --$newpage;
  25825. return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript);
  25826. // return to last page
  25827. $this->lastPage(true);
  25828. return true;
  25829. }
  25830. /**
  25831. * Clone the specified page to a new page.
  25832. * @param $page (int) number of page to copy (0 = current page)
  25833. * @return true in case of success, false in case of error.
  25834. * @public
  25835. * @since 4.9.015 (2010-04-20)
  25836. */
  25837. public function copyPage($page=0) {
  25838. if ($page == 0) {
  25839. // default value
  25840. $page = $this->page;
  25841. }
  25842. if (($page < 1) OR ($page > $this->numpages)) {
  25843. return false;
  25844. }
  25845. // close the last page
  25846. $this->endPage();
  25847. // copy all page-related states
  25848. ++$this->numpages;
  25849. $this->page = $this->numpages;
  25850. $this->setPageBuffer($this->page, $this->getPageBuffer($page));
  25851. $this->pagedim[$this->page] = $this->pagedim[$page];
  25852. $this->pagelen[$this->page] = $this->pagelen[$page];
  25853. $this->intmrk[$this->page] = $this->intmrk[$page];
  25854. $this->bordermrk[$this->page] = $this->bordermrk[$page];
  25855. $this->cntmrk[$this->page] = $this->cntmrk[$page];
  25856. $this->pageobjects[$this->page] = $this->pageobjects[$page];
  25857. $this->pageopen[$this->page] = false;
  25858. if (isset($this->footerpos[$page])) {
  25859. $this->footerpos[$this->page] = $this->footerpos[$page];
  25860. }
  25861. if (isset($this->footerlen[$page])) {
  25862. $this->footerlen[$this->page] = $this->footerlen[$page];
  25863. }
  25864. if (isset($this->transfmrk[$page])) {
  25865. $this->transfmrk[$this->page] = $this->transfmrk[$page];
  25866. }
  25867. if (isset($this->PageAnnots[$page])) {
  25868. $this->PageAnnots[$this->page] = $this->PageAnnots[$page];
  25869. }
  25870. if (isset($this->newpagegroup[$page])) {
  25871. // start a new group
  25872. $this->newpagegroup[$this->page] = sizeof($this->newpagegroup) + 1;
  25873. $this->currpagegroup = $this->newpagegroup[$this->page];
  25874. $this->pagegroups[$this->currpagegroup] = 1;
  25875. } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) {
  25876. ++$this->pagegroups[$this->currpagegroup];
  25877. }
  25878. // copy outlines
  25879. $tmpoutlines = $this->outlines;
  25880. foreach ($tmpoutlines as $key => $outline) {
  25881. if ($outline['p'] == $page) {
  25882. $this->outlines[] = array('t' => $outline['t'], 'l' => $outline['l'], 'x' => $outline['x'], 'y' => $outline['y'], 'p' => $this->page, 's' => $outline['s'], 'c' => $outline['c']);
  25883. }
  25884. }
  25885. // copy links
  25886. $tmplinks = $this->links;
  25887. foreach ($tmplinks as $key => $link) {
  25888. if ($link[0] == $page) {
  25889. $this->links[] = array($this->page, $link[1]);
  25890. }
  25891. }
  25892. // return to last page
  25893. $this->lastPage(true);
  25894. return true;
  25895. }
  25896. /**
  25897. * Output a Table of Content Index (TOC).
  25898. * This method must be called after all Bookmarks were set.
  25899. * Before calling this method you have to open the page using the addTOCPage() method.
  25900. * After calling this method you have to call endTOCPage() to close the TOC page.
  25901. * You can override this method to achieve different styles.
  25902. * @param $page (int) page number where this TOC should be inserted (leave empty for current page).
  25903. * @param $numbersfont (string) set the font for page numbers (please use monospaced font for better alignment).
  25904. * @param $filler (string) string used to fill the space between text and page number.
  25905. * @param $toc_name (string) name to use for TOC bookmark.
  25906. * @param $style (string) Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
  25907. * @param $color (array) RGB color array for bookmark title (values from 0 to 255).
  25908. * @public
  25909. * @author Nicola Asuni
  25910. * @since 4.5.000 (2009-01-02)
  25911. * @see addTOCPage(), endTOCPage(), addHTMLTOC()
  25912. */
  25913. public function addTOC($page='', $numbersfont='', $filler='.', $toc_name='TOC', $style='', $color=array(0,0,0)) {
  25914. $fontsize = $this->FontSizePt;
  25915. $fontfamily = $this->FontFamily;
  25916. $fontstyle = $this->FontStyle;
  25917. $w = $this->w - $this->lMargin - $this->rMargin;
  25918. $spacer = $this->GetStringWidth(chr(32)) * 4;
  25919. $lmargin = $this->lMargin;
  25920. $rmargin = $this->rMargin;
  25921. $x_start = $this->GetX();
  25922. $page_first = $this->page;
  25923. $current_page = $this->page;
  25924. $page_fill_start = false;
  25925. $page_fill_end = false;
  25926. $current_column = $this->current_column;
  25927. if ($this->empty_string($numbersfont)) {
  25928. $numbersfont = $this->default_monospaced_font;
  25929. }
  25930. if ($this->empty_string($filler)) {
  25931. $filler = ' ';
  25932. }
  25933. if ($this->empty_string($page)) {
  25934. $gap = ' ';
  25935. } else {
  25936. $gap = '';
  25937. if ($page < 1) {
  25938. $page = 1;
  25939. }
  25940. }
  25941. $this->SetFont($numbersfont, $fontstyle, $fontsize);
  25942. $numwidth = $this->GetStringWidth('00000');
  25943. $maxpage = 0; //used for pages on attached documents
  25944. foreach ($this->outlines as $key => $outline) {
  25945. // check for extra pages (used for attachments)
  25946. if (($this->page > $page_first) AND ($outline['p'] >= $this->numpages)) {
  25947. $outline['p'] += ($this->page - $page_first);
  25948. }
  25949. if ($this->rtl) {
  25950. $aligntext = 'R';
  25951. $alignnum = 'L';
  25952. } else {
  25953. $aligntext = 'L';
  25954. $alignnum = 'R';
  25955. }
  25956. if ($outline['l'] == 0) {
  25957. $this->SetFont($fontfamily, $outline['s'].'B', $fontsize);
  25958. } else {
  25959. $this->SetFont($fontfamily, $outline['s'], $fontsize - $outline['l']);
  25960. }
  25961. $this->SetTextColorArray($outline['c']);
  25962. // check for page break
  25963. $this->checkPageBreak((2 * $this->FontSize * $this->cell_height_ratio));
  25964. // set margins and X position
  25965. if (($this->page == $current_page) AND ($this->current_column == $current_column)) {
  25966. $this->lMargin = $lmargin;
  25967. $this->rMargin = $rmargin;
  25968. } else {
  25969. if ($this->current_column != $current_column) {
  25970. if ($this->rtl) {
  25971. $x_start = $this->w - $this->columns[$this->current_column]['x'];
  25972. } else {
  25973. $x_start = $this->columns[$this->current_column]['x'];
  25974. }
  25975. }
  25976. $lmargin = $this->lMargin;
  25977. $rmargin = $this->rMargin;
  25978. $current_page = $this->page;
  25979. $current_column = $this->current_column;
  25980. }
  25981. $this->SetX($x_start);
  25982. $indent = ($spacer * $outline['l']);
  25983. if ($this->rtl) {
  25984. $this->x -= $indent;
  25985. $this->rMargin = $this->w - $this->x;
  25986. } else {
  25987. $this->x += $indent;
  25988. $this->lMargin = $this->x;
  25989. }
  25990. $link = $this->AddLink();
  25991. $this->SetLink($link, $outline['y'], $outline['p']);
  25992. // write the text
  25993. if ($this->rtl) {
  25994. $txt = ' '.$outline['t'];
  25995. } else {
  25996. $txt = $outline['t'].' ';
  25997. }
  25998. $this->Write(0, $txt, $link, false, $aligntext, false, 0, false, false, 0, $numwidth, '');
  25999. if ($this->rtl) {
  26000. $tw = $this->x - $this->lMargin;
  26001. } else {
  26002. $tw = $this->w - $this->rMargin - $this->x;
  26003. }
  26004. $this->SetFont($numbersfont, $fontstyle, $fontsize);
  26005. if ($this->empty_string($page)) {
  26006. $pagenum = $outline['p'];
  26007. } else {
  26008. // placemark to be replaced with the correct number
  26009. $pagenum = '{#'.($outline['p']).'}';
  26010. if ($this->isUnicodeFont()) {
  26011. $pagenum = '{'.$pagenum.'}';
  26012. }
  26013. $maxpage = max($maxpage, $outline['p']);
  26014. }
  26015. $fw = ($tw - $this->GetStringWidth($pagenum.$filler));
  26016. $numfills = floor($fw / $this->GetStringWidth($filler));
  26017. if ($numfills > 0) {
  26018. $rowfill = str_repeat($filler, $numfills);
  26019. } else {
  26020. $rowfill = '';
  26021. }
  26022. if ($this->rtl) {
  26023. $pagenum = $pagenum.$gap.$rowfill;
  26024. } else {
  26025. $pagenum = $rowfill.$gap.$pagenum;
  26026. }
  26027. // write the number
  26028. $this->Cell($tw, 0, $pagenum, 0, 1, $alignnum, 0, $link, 0);
  26029. }
  26030. $page_last = $this->getPage();
  26031. $numpages = ($page_last - $page_first + 1);
  26032. // account for booklet mode
  26033. if ($this->booklet) {
  26034. // check if a blank page is required before TOC
  26035. $page_fill_start = ((($page_first % 2) == 0) XOR (($page % 2) == 0));
  26036. $page_fill_end = (!((($numpages % 2) == 0) XOR ($page_fill_start)));
  26037. if ($page_fill_start) {
  26038. // add a page at the end (to be moved before TOC)
  26039. $this->addPage();
  26040. ++$page_last;
  26041. ++$numpages;
  26042. }
  26043. if ($page_fill_end) {
  26044. // add a page at the end
  26045. $this->addPage();
  26046. ++$page_last;
  26047. ++$numpages;
  26048. }
  26049. }
  26050. $maxpage = max($maxpage, $page_last);
  26051. if (!$this->empty_string($page)) {
  26052. for ($p = $page_first; $p <= $page_last; ++$p) {
  26053. // get page data
  26054. $temppage = $this->getPageBuffer($p);
  26055. for ($n = 1; $n <= $maxpage; ++$n) {
  26056. // update page numbers
  26057. $a = '{#'.$n.'}';
  26058. // get page number aliases
  26059. $pnalias = $this->getInternalPageNumberAliases($a);
  26060. // calculate replacement number
  26061. if (($n >= $page) AND ($n <= $this->numpages)) {
  26062. $np = $n + $numpages;
  26063. } else {
  26064. $np = $n;
  26065. }
  26066. $na = $this->formatTOCPageNumber(($this->starting_page_number + $np - 1));
  26067. $nu = $this->UTF8ToUTF16BE($na, false);
  26068. // replace aliases with numbers
  26069. foreach ($pnalias['u'] as $u) {
  26070. $sfill = str_repeat($filler, max(0, (strlen($u) - strlen($nu.' '))));
  26071. if ($this->rtl) {
  26072. $nr = $nu.$this->UTF8ToUTF16BE(' '.$sfill);
  26073. } else {
  26074. $nr = $this->UTF8ToUTF16BE($sfill.' ').$nu;
  26075. }
  26076. $temppage = str_replace($u, $nr, $temppage);
  26077. }
  26078. foreach ($pnalias['a'] as $a) {
  26079. $sfill = str_repeat($filler, max(0, (strlen($a) - strlen($na.' '))));
  26080. if ($this->rtl) {
  26081. $nr = $na.' '.$sfill;
  26082. } else {
  26083. $nr = $sfill.' '.$na;
  26084. }
  26085. $temppage = str_replace($a, $nr, $temppage);
  26086. }
  26087. }
  26088. // save changes
  26089. $this->setPageBuffer($p, $temppage);
  26090. }
  26091. // move pages
  26092. $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
  26093. if ($page_fill_start) {
  26094. $this->movePage($page_last, $page_first);
  26095. }
  26096. for ($i = 0; $i < $numpages; ++$i) {
  26097. $this->movePage($page_last, $page);
  26098. }
  26099. }
  26100. }
  26101. /**
  26102. * Output a Table Of Content Index (TOC) using HTML templates.
  26103. * This method must be called after all Bookmarks were set.
  26104. * Before calling this method you have to open the page using the addTOCPage() method.
  26105. * After calling this method you have to call endTOCPage() to close the TOC page.
  26106. * @param $page (int) page number where this TOC should be inserted (leave empty for current page).
  26107. * @param $toc_name (string) name to use for TOC bookmark.
  26108. * @param $templates (array) array of html templates. Use: "#TOC_DESCRIPTION#" for bookmark title, "#TOC_PAGE_NUMBER#" for page number.
  26109. * @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)
  26110. * @param $style (string) Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
  26111. * @param $color (array) RGB color array for title (values from 0 to 255).
  26112. * @public
  26113. * @author Nicola Asuni
  26114. * @since 5.0.001 (2010-05-06)
  26115. * @see addTOCPage(), endTOCPage(), addTOC()
  26116. */
  26117. public function addHTMLTOC($page='', $toc_name='TOC', $templates=array(), $correct_align=true, $style='', $color=array(0,0,0)) {
  26118. $filler = ' ';
  26119. $prev_htmlLinkColorArray = $this->htmlLinkColorArray;
  26120. $prev_htmlLinkFontStyle = $this->htmlLinkFontStyle;
  26121. // set new style for link
  26122. $this->htmlLinkColorArray = array();
  26123. $this->htmlLinkFontStyle = '';
  26124. $page_first = $this->getPage();
  26125. $page_fill_start = false;
  26126. $page_fill_end = false;
  26127. // get the font type used for numbers in each template
  26128. $current_font = $this->FontFamily;
  26129. foreach ($templates as $level => $html) {
  26130. $dom = $this->getHtmlDomArray($html);
  26131. foreach ($dom as $key => $value) {
  26132. if ($value['value'] == '#TOC_PAGE_NUMBER#') {
  26133. $this->SetFont($dom[($key - 1)]['fontname']);
  26134. $templates['F'.$level] = $this->isUnicodeFont();
  26135. }
  26136. }
  26137. }
  26138. $this->SetFont($current_font);
  26139. $maxpage = 0; //used for pages on attached documents
  26140. foreach ($this->outlines as $key => $outline) {
  26141. // get HTML template
  26142. $row = $templates[$outline['l']];
  26143. if ($this->empty_string($page)) {
  26144. $pagenum = $outline['p'];
  26145. } else {
  26146. // placemark to be replaced with the correct number
  26147. $pagenum = '{#'.($outline['p']).'}';
  26148. if ($templates['F'.$outline['l']]) {
  26149. $pagenum = '{'.$pagenum.'}';
  26150. }
  26151. $maxpage = max($maxpage, $outline['p']);
  26152. }
  26153. // replace templates with current values
  26154. $row = str_replace('#TOC_DESCRIPTION#', $outline['t'], $row);
  26155. $row = str_replace('#TOC_PAGE_NUMBER#', $pagenum, $row);
  26156. // add link to page
  26157. $row = '<a href="#'.$outline['p'].','.$outline['y'].'">'.$row.'</a>';
  26158. // write bookmark entry
  26159. $this->writeHTML($row, false, false, true, false, '');
  26160. }
  26161. // restore link styles
  26162. $this->htmlLinkColorArray = $prev_htmlLinkColorArray;
  26163. $this->htmlLinkFontStyle = $prev_htmlLinkFontStyle;
  26164. // move TOC page and replace numbers
  26165. $page_last = $this->getPage();
  26166. $numpages = ($page_last - $page_first + 1);
  26167. // account for booklet mode
  26168. if ($this->booklet) {
  26169. // check if a blank page is required before TOC
  26170. $page_fill_start = ((($page_first % 2) == 0) XOR (($page % 2) == 0));
  26171. $page_fill_end = (!((($numpages % 2) == 0) XOR ($page_fill_start)));
  26172. if ($page_fill_start) {
  26173. // add a page at the end (to be moved before TOC)
  26174. $this->addPage();
  26175. ++$page_last;
  26176. ++$numpages;
  26177. }
  26178. if ($page_fill_end) {
  26179. // add a page at the end
  26180. $this->addPage();
  26181. ++$page_last;
  26182. ++$numpages;
  26183. }
  26184. }
  26185. $maxpage = max($maxpage, $page_last);
  26186. if (!$this->empty_string($page)) {
  26187. for ($p = $page_first; $p <= $page_last; ++$p) {
  26188. // get page data
  26189. $temppage = $this->getPageBuffer($p);
  26190. for ($n = 1; $n <= $maxpage; ++$n) {
  26191. // update page numbers
  26192. $a = '{#'.$n.'}';
  26193. // get page number aliases
  26194. $pnalias = $this->getInternalPageNumberAliases($a);
  26195. // calculate replacement number
  26196. if ($n >= $page) {
  26197. $np = $n + $numpages;
  26198. } else {
  26199. $np = $n;
  26200. }
  26201. $na = $this->formatTOCPageNumber(($this->starting_page_number + $np - 1));
  26202. $nu = $this->UTF8ToUTF16BE($na, false);
  26203. // replace aliases with numbers
  26204. foreach ($pnalias['u'] as $u) {
  26205. if ($correct_align) {
  26206. $sfill = str_repeat($filler, (strlen($u) - strlen($nu.' ')));
  26207. if ($this->rtl) {
  26208. $nr = $nu.$this->UTF8ToUTF16BE(' '.$sfill);
  26209. } else {
  26210. $nr = $this->UTF8ToUTF16BE($sfill.' ').$nu;
  26211. }
  26212. } else {
  26213. $nr = $nu;
  26214. }
  26215. $temppage = str_replace($u, $nr, $temppage);
  26216. }
  26217. foreach ($pnalias['a'] as $a) {
  26218. if ($correct_align) {
  26219. $sfill = str_repeat($filler, (strlen($a) - strlen($na.' ')));
  26220. if ($this->rtl) {
  26221. $nr = $na.' '.$sfill;
  26222. } else {
  26223. $nr = $sfill.' '.$na;
  26224. }
  26225. } else {
  26226. $nr = $na;
  26227. }
  26228. $temppage = str_replace($a, $nr, $temppage);
  26229. }
  26230. }
  26231. // save changes
  26232. $this->setPageBuffer($p, $temppage);
  26233. }
  26234. // move pages
  26235. $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
  26236. if ($page_fill_start) {
  26237. $this->movePage($page_last, $page_first);
  26238. }
  26239. for ($i = 0; $i < $numpages; ++$i) {
  26240. $this->movePage($page_last, $page);
  26241. }
  26242. }
  26243. }
  26244. /**
  26245. * Stores a copy of the current TCPDF object used for undo operation.
  26246. * @public
  26247. * @since 4.5.029 (2009-03-19)
  26248. */
  26249. public function startTransaction() {
  26250. if (isset($this->objcopy)) {
  26251. // remove previous copy
  26252. $this->commitTransaction();
  26253. }
  26254. // record current page number and Y position
  26255. $this->start_transaction_page = $this->page;
  26256. $this->start_transaction_y = $this->y;
  26257. // clone current object
  26258. $this->objcopy = $this->objclone($this);
  26259. }
  26260. /**
  26261. * Delete the copy of the current TCPDF object used for undo operation.
  26262. * @public
  26263. * @since 4.5.029 (2009-03-19)
  26264. */
  26265. public function commitTransaction() {
  26266. if (isset($this->objcopy)) {
  26267. $this->objcopy->_destroy(true, true);
  26268. unset($this->objcopy);
  26269. }
  26270. }
  26271. /**
  26272. * This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction().
  26273. * @param $self (boolean) if true restores current class object to previous state without the need of reassignment via the returned value.
  26274. * @return TCPDF object.
  26275. * @public
  26276. * @since 4.5.029 (2009-03-19)
  26277. */
  26278. public function rollbackTransaction($self=false) {
  26279. if (isset($this->objcopy)) {
  26280. if (isset($this->objcopy->diskcache) AND $this->objcopy->diskcache) {
  26281. // truncate files to previous values
  26282. foreach ($this->objcopy->cache_file_length as $file => $length) {
  26283. $file = substr($file, 1);
  26284. $handle = fopen($file, 'r+');
  26285. ftruncate($handle, $length);
  26286. }
  26287. }
  26288. $this->_destroy(true, true);
  26289. if ($self) {
  26290. $objvars = get_object_vars($this->objcopy);
  26291. foreach ($objvars as $key => $value) {
  26292. $this->$key = $value;
  26293. }
  26294. }
  26295. return $this->objcopy;
  26296. }
  26297. return $this;
  26298. }
  26299. /**
  26300. * Creates a copy of a class object
  26301. * @param $object (object) class object to be cloned
  26302. * @return cloned object
  26303. * @public
  26304. * @since 4.5.029 (2009-03-19)
  26305. */
  26306. public function objclone($object) {
  26307. return @clone($object);
  26308. }
  26309. /**
  26310. * Determine whether a string is empty.
  26311. * @param $str (string) string to be checked
  26312. * @return boolean true if string is empty
  26313. * @public
  26314. * @since 4.5.044 (2009-04-16)
  26315. */
  26316. public function empty_string($str) {
  26317. return (is_null($str) OR (is_string($str) AND (strlen($str) == 0)));
  26318. }
  26319. /**
  26320. * Find position of last occurrence of a substring in a string
  26321. * @param $haystack (string) The string to search in.
  26322. * @param $needle (string) substring to search.
  26323. * @param $offset (int) May be specified to begin searching an arbitrary number of characters into the string.
  26324. * @return Returns the position where the needle exists. Returns FALSE if the needle was not found.
  26325. * @public
  26326. * @since 4.8.038 (2010-03-13)
  26327. */
  26328. public function revstrpos($haystack, $needle, $offset = 0) {
  26329. $length = strlen($haystack);
  26330. $offset = ($offset > 0)?($length - $offset):abs($offset);
  26331. $pos = strpos(strrev($haystack), strrev($needle), $offset);
  26332. return ($pos === false)?false:($length - $pos - strlen($needle));
  26333. }
  26334. // --- MULTI COLUMNS METHODS -----------------------
  26335. /**
  26336. * Set multiple columns of the same size
  26337. * @param $numcols (int) number of columns (set to zero to disable columns mode)
  26338. * @param $width (int) column width
  26339. * @param $y (int) column starting Y position (leave empty for current Y position)
  26340. * @public
  26341. * @since 4.9.001 (2010-03-28)
  26342. */
  26343. public function setEqualColumns($numcols=0, $width=0, $y='') {
  26344. $this->columns = array();
  26345. if ($numcols < 2) {
  26346. $numcols = 0;
  26347. $this->columns = array();
  26348. } else {
  26349. // maximum column width
  26350. $maxwidth = ($this->w - $this->original_lMargin - $this->original_rMargin) / $numcols;
  26351. if (($width == 0) OR ($width > $maxwidth)) {
  26352. $width = $maxwidth;
  26353. }
  26354. if ($this->empty_string($y)) {
  26355. $y = $this->y;
  26356. }
  26357. // space between columns
  26358. $space = (($this->w - $this->original_lMargin - $this->original_rMargin - ($numcols * $width)) / ($numcols - 1));
  26359. // fill the columns array (with, space, starting Y position)
  26360. for ($i = 0; $i < $numcols; ++$i) {
  26361. $this->columns[$i] = array('w' => $width, 's' => $space, 'y' => $y);
  26362. }
  26363. }
  26364. $this->num_columns = $numcols;
  26365. $this->current_column = 0;
  26366. $this->column_start_page = $this->page;
  26367. $this->selectColumn(0);
  26368. }
  26369. /**
  26370. * Remove columns and reset page margins.
  26371. * @public
  26372. * @since 5.9.072 (2011-04-26)
  26373. */
  26374. public function resetColumns() {
  26375. $this->lMargin = $this->original_lMargin;
  26376. $this->rMargin = $this->original_rMargin;
  26377. $this->setEqualColumns();
  26378. }
  26379. /**
  26380. * Set columns array.
  26381. * Each column is represented by an array of arrays with the following keys: (w = width, s = space between columns, y = column top position).
  26382. * @param $columns (array)
  26383. * @public
  26384. * @since 4.9.001 (2010-03-28)
  26385. */
  26386. public function setColumnsArray($columns) {
  26387. $this->columns = $columns;
  26388. $this->num_columns = count($columns);
  26389. $this->current_column = 0;
  26390. $this->column_start_page = $this->page;
  26391. $this->selectColumn(0);
  26392. }
  26393. /**
  26394. * Set position at a given column
  26395. * @param $col (int) column number (from 0 to getNumberOfColumns()-1); empty string = current column.
  26396. * @public
  26397. * @since 4.9.001 (2010-03-28)
  26398. */
  26399. public function selectColumn($col='') {
  26400. if (is_string($col)) {
  26401. $col = $this->current_column;
  26402. } elseif ($col >= $this->num_columns) {
  26403. $col = 0;
  26404. }
  26405. $xshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  26406. $enable_thead = false;
  26407. if ($this->num_columns > 1) {
  26408. if ($col != $this->current_column) {
  26409. // move Y pointer at the top of the column
  26410. if ($this->column_start_page == $this->page) {
  26411. $this->y = $this->columns[$col]['y'];
  26412. } else {
  26413. $this->y = $this->tMargin;
  26414. }
  26415. // Avoid to write table headers more than once
  26416. if (($this->page > $this->maxselcol['page']) OR (($this->page == $this->maxselcol['page']) AND ($col > $this->maxselcol['column']))) {
  26417. $enable_thead = true;
  26418. $this->maxselcol['page'] = $this->page;
  26419. $this->maxselcol['column'] = $col;
  26420. }
  26421. }
  26422. $xshift = $this->colxshift;
  26423. // set X position of the current column by case
  26424. $listindent = ($this->listindentlevel * $this->listindent);
  26425. // calculate column X position
  26426. $colpos = 0;
  26427. for ($i = 0; $i < $col; ++$i) {
  26428. $colpos += ($this->columns[$i]['w'] + $this->columns[$i]['s']);
  26429. }
  26430. if ($this->rtl) {
  26431. $x = $this->w - $this->original_rMargin - $colpos;
  26432. $this->rMargin = ($this->w - $x + $listindent);
  26433. $this->lMargin = ($x - $this->columns[$col]['w']);
  26434. $this->x = $x - $listindent;
  26435. } else {
  26436. $x = $this->original_lMargin + $colpos;
  26437. $this->lMargin = ($x + $listindent);
  26438. $this->rMargin = ($this->w - $x - $this->columns[$col]['w']);
  26439. $this->x = $x + $listindent;
  26440. }
  26441. $this->columns[$col]['x'] = $x;
  26442. }
  26443. $this->current_column = $col;
  26444. // fix for HTML mode
  26445. $this->newline = true;
  26446. // print HTML table header (if any)
  26447. if ((!$this->empty_string($this->thead)) AND (!$this->inthead)) {
  26448. if ($enable_thead) {
  26449. // print table header
  26450. $this->writeHTML($this->thead, false, false, false, false, '');
  26451. $this->y += $xshift['s']['V'];
  26452. // store end of header position
  26453. if (!isset($this->columns[$col]['th'])) {
  26454. $this->columns[$col]['th'] = array();
  26455. }
  26456. $this->columns[$col]['th']['\''.$this->page.'\''] = $this->y;
  26457. $this->lasth = 0;
  26458. } elseif (isset($this->columns[$col]['th']['\''.$this->page.'\''])) {
  26459. $this->y = $this->columns[$col]['th']['\''.$this->page.'\''];
  26460. }
  26461. }
  26462. // account for an html table cell over multiple columns
  26463. if ($this->rtl) {
  26464. $this->rMargin += $xshift['x'];
  26465. $this->x -= ($xshift['x'] + $xshift['p']['R']);
  26466. } else {
  26467. $this->lMargin += $xshift['x'];
  26468. $this->x += $xshift['x'] + $xshift['p']['L'];
  26469. }
  26470. }
  26471. /**
  26472. * Return the current column number
  26473. * @return int current column number
  26474. * @public
  26475. * @since 5.5.011 (2010-07-08)
  26476. */
  26477. public function getColumn() {
  26478. return $this->current_column;
  26479. }
  26480. /**
  26481. * Return the current number of columns.
  26482. * @return int number of columns
  26483. * @public
  26484. * @since 5.8.018 (2010-08-25)
  26485. */
  26486. public function getNumberOfColumns() {
  26487. return $this->num_columns;
  26488. }
  26489. /**
  26490. * Serialize an array of parameters to be used with TCPDF tag in HTML code.
  26491. * @param $pararray (array) parameters array
  26492. * @return sting containing serialized data
  26493. * @public
  26494. * @since 4.9.006 (2010-04-02)
  26495. */
  26496. public function serializeTCPDFtagParameters($pararray) {
  26497. return urlencode(serialize($pararray));
  26498. }
  26499. /**
  26500. * Set Text rendering mode.
  26501. * @param $stroke (int) outline size in user units (0 = disable).
  26502. * @param $fill (boolean) if true fills the text (default).
  26503. * @param $clip (boolean) if true activate clipping mode
  26504. * @public
  26505. * @since 4.9.008 (2009-04-02)
  26506. */
  26507. public function setTextRenderingMode($stroke=0, $fill=true, $clip=false) {
  26508. // Ref.: PDF 32000-1:2008 - 9.3.6 Text Rendering Mode
  26509. // convert text rendering parameters
  26510. if ($stroke < 0) {
  26511. $stroke = 0;
  26512. }
  26513. if ($fill === true) {
  26514. if ($stroke > 0) {
  26515. if ($clip === true) {
  26516. // Fill, then stroke text and add to path for clipping
  26517. $textrendermode = 6;
  26518. } else {
  26519. // Fill, then stroke text
  26520. $textrendermode = 2;
  26521. }
  26522. $textstrokewidth = $stroke;
  26523. } else {
  26524. if ($clip === true) {
  26525. // Fill text and add to path for clipping
  26526. $textrendermode = 4;
  26527. } else {
  26528. // Fill text
  26529. $textrendermode = 0;
  26530. }
  26531. }
  26532. } else {
  26533. if ($stroke > 0) {
  26534. if ($clip === true) {
  26535. // Stroke text and add to path for clipping
  26536. $textrendermode = 5;
  26537. } else {
  26538. // Stroke text
  26539. $textrendermode = 1;
  26540. }
  26541. $textstrokewidth = $stroke;
  26542. } else {
  26543. if ($clip === true) {
  26544. // Add text to path for clipping
  26545. $textrendermode = 7;
  26546. } else {
  26547. // Neither fill nor stroke text (invisible)
  26548. $textrendermode = 3;
  26549. }
  26550. }
  26551. }
  26552. $this->textrendermode = $textrendermode;
  26553. $this->textstrokewidth = $stroke;
  26554. }
  26555. /**
  26556. * Set parameters for drop shadow effect for text.
  26557. * @param $params (array) Array of parameters: enabled (boolean) set to true to enable shadow; depth_w (float) shadow width in user units; depth_h (float) shadow height in user units; color (array) shadow color or false to use the stroke color; opacity (float) Alpha value: real value from 0 (transparent) to 1 (opaque); blend_mode (string) blend mode, one of the following: Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity.
  26558. * @since 5.9.174 (2012-07-25)
  26559. * @public
  26560. */
  26561. public function setTextShadow($params=array('enabled'=>false, 'depth_w'=>0, 'depth_h'=>0, 'color'=>false, 'opacity'=>1, 'blend_mode'=>'Normal')) {
  26562. if (isset($params['enabled'])) {
  26563. $this->txtshadow['enabled'] = $params['enabled']?true:false;
  26564. } else {
  26565. $this->txtshadow['enabled'] = false;
  26566. }
  26567. if (isset($params['depth_w'])) {
  26568. $this->txtshadow['depth_w'] = floatval($params['depth_w']);
  26569. } else {
  26570. $this->txtshadow['depth_w'] = 0;
  26571. }
  26572. if (isset($params['depth_h'])) {
  26573. $this->txtshadow['depth_h'] = floatval($params['depth_h']);
  26574. } else {
  26575. $this->txtshadow['depth_h'] = 0;
  26576. }
  26577. if (isset($params['color']) AND ($params['color'] !== false) AND is_array($params['color'])) {
  26578. $this->txtshadow['color'] = $params['color'];
  26579. } else {
  26580. $this->txtshadow['color'] = $this->strokecolor;
  26581. }
  26582. if (isset($params['opacity'])) {
  26583. $this->txtshadow['opacity'] = min(1, max(0, floatval($params['opacity'])));
  26584. } else {
  26585. $this->txtshadow['opacity'] = 1;
  26586. }
  26587. if (isset($params['blend_mode']) AND in_array($params['blend_mode'], array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge', 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion', 'Hue', 'Saturation', 'Color', 'Luminosity'))) {
  26588. $this->txtshadow['blend_mode'] = $params['blend_mode'];
  26589. } else {
  26590. $this->txtshadow['blend_mode'] = 'Normal';
  26591. }
  26592. if ((($this->txtshadow['depth_w'] == 0) AND ($this->txtshadow['depth_h'] == 0)) OR ($this->txtshadow['opacity'] == 0)) {
  26593. $this->txtshadow['enabled'] = false;
  26594. }
  26595. }
  26596. /**
  26597. * Return the text shadow parameters array.
  26598. * @return Array of parameters.
  26599. * @since 5.9.174 (2012-07-25)
  26600. * @public
  26601. */
  26602. public function getTextShadow() {
  26603. return $this->txtshadow;
  26604. }
  26605. /**
  26606. * Returns an array of chars containing soft hyphens.
  26607. * @param $word (array) array of chars
  26608. * @param $patterns (array) Array of hypenation patterns.
  26609. * @param $dictionary (array) Array of words to be returned without applying the hyphenation algoritm.
  26610. * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens.
  26611. * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens.
  26612. * @param $charmin (int) Minimum word length to apply the hyphenation algoritm.
  26613. * @param $charmax (int) Maximum length of broken piece of word.
  26614. * @return array text with soft hyphens
  26615. * @author Nicola Asuni
  26616. * @since 4.9.012 (2010-04-12)
  26617. * @protected
  26618. */
  26619. protected function hyphenateWord($word, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
  26620. $hyphenword = array(); // hyphens positions
  26621. $numchars = count($word);
  26622. if ($numchars <= $charmin) {
  26623. return $word;
  26624. }
  26625. $word_string = $this->UTF8ArrSubString($word);
  26626. // some words will be returned as-is
  26627. $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})(\]?)$/';
  26628. if (preg_match($pattern, $word_string) > 0) {
  26629. // email
  26630. return $word;
  26631. }
  26632. $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})(\]?)$/';
  26633. if (preg_match($pattern, $word_string) > 0) {
  26634. // URL
  26635. return $word;
  26636. }
  26637. if (isset($dictionary[$word_string])) {
  26638. return $this->UTF8StringToArray($dictionary[$word_string]);
  26639. }
  26640. // suround word with '_' characters
  26641. $tmpword = array_merge(array(95), $word, array(95));
  26642. $tmpnumchars = $numchars + 2;
  26643. $maxpos = $tmpnumchars - $charmin;
  26644. for ($pos = 0; $pos < $maxpos; ++$pos) {
  26645. $imax = min(($tmpnumchars - $pos), $charmax);
  26646. for ($i = $charmin; $i <= $imax; ++$i) {
  26647. $subword = strtolower($this->UTF8ArrSubString($tmpword, $pos, $pos + $i));
  26648. if (isset($patterns[$subword])) {
  26649. $pattern = $this->UTF8StringToArray($patterns[$subword]);
  26650. $pattern_length = count($pattern);
  26651. $digits = 1;
  26652. for ($j = 0; $j < $pattern_length; ++$j) {
  26653. // check if $pattern[$j] is a number
  26654. if (($pattern[$j] >= 48) AND ($pattern[$j] <= 57)) {
  26655. if ($j == 0) {
  26656. $zero = $pos - 1;
  26657. } else {
  26658. $zero = $pos + $j - $digits;
  26659. }
  26660. if (!isset($hyphenword[$zero]) OR ($hyphenword[$zero] != $pattern[$j])) {
  26661. $hyphenword[$zero] = $this->unichr($pattern[$j]);
  26662. }
  26663. ++$digits;
  26664. }
  26665. }
  26666. }
  26667. }
  26668. }
  26669. $inserted = 0;
  26670. $maxpos = $numchars - $rightmin;
  26671. for ($i = $leftmin; $i <= $maxpos; ++$i) {
  26672. if (isset($hyphenword[$i]) AND (($hyphenword[$i] % 2) != 0)) {
  26673. // 173 = soft hyphen character
  26674. array_splice($word, $i + $inserted, 0, 173);
  26675. ++$inserted;
  26676. }
  26677. }
  26678. return $word;
  26679. }
  26680. /**
  26681. * Returns an array of hyphenation patterns.
  26682. * @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/
  26683. * @return array of hyphenation patterns
  26684. * @author Nicola Asuni
  26685. * @since 4.9.012 (2010-04-12)
  26686. * @public
  26687. */
  26688. public function getHyphenPatternsFromTEX($file) {
  26689. // TEX patterns are available at:
  26690. // http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
  26691. $data = file_get_contents($file);
  26692. $patterns = array();
  26693. // remove comments
  26694. $data = preg_replace('/\%[^\n]*/', '', $data);
  26695. // extract the patterns part
  26696. preg_match('/\\\\patterns\{([^\}]*)\}/i', $data, $matches);
  26697. $data = trim(substr($matches[0], 10, -1));
  26698. // extract each pattern
  26699. $patterns_array = preg_split('/[\s]+/', $data);
  26700. // create new language array of patterns
  26701. $patterns = array();
  26702. foreach($patterns_array as $val) {
  26703. if (!$this->empty_string($val)) {
  26704. $val = trim($val);
  26705. $val = str_replace('\'', '\\\'', $val);
  26706. $key = preg_replace('/[0-9]+/', '', $val);
  26707. $patterns[$key] = $val;
  26708. }
  26709. }
  26710. return $patterns;
  26711. }
  26712. /**
  26713. * Returns text with soft hyphens.
  26714. * @param $text (string) text to process
  26715. * @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/
  26716. * @param $dictionary (array) Array of words to be returned without applying the hyphenation algoritm.
  26717. * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens.
  26718. * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens.
  26719. * @param $charmin (int) Minimum word length to apply the hyphenation algoritm.
  26720. * @param $charmax (int) Maximum length of broken piece of word.
  26721. * @return array text with soft hyphens
  26722. * @author Nicola Asuni
  26723. * @since 4.9.012 (2010-04-12)
  26724. * @public
  26725. */
  26726. public function hyphenateText($text, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
  26727. $text = $this->unhtmlentities($text);
  26728. $word = array(); // last word
  26729. $txtarr = array(); // text to be returned
  26730. $intag = false; // true if we are inside an HTML tag
  26731. if (!is_array($patterns)) {
  26732. $patterns = $this->getHyphenPatternsFromTEX($patterns);
  26733. }
  26734. // get array of characters
  26735. $unichars = $this->UTF8StringToArray($text);
  26736. // for each char
  26737. foreach ($unichars as $char) {
  26738. if ((!$intag) AND $this->unicode->uni_type[$char] == 'L') {
  26739. // letter character
  26740. $word[] = $char;
  26741. } else {
  26742. // other type of character
  26743. if (!$this->empty_string($word)) {
  26744. // hypenate the word
  26745. $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
  26746. $word = array();
  26747. }
  26748. $txtarr[] = $char;
  26749. if (chr($char) == '<') {
  26750. // we are inside an HTML tag
  26751. $intag = true;
  26752. } elseif ($intag AND (chr($char) == '>')) {
  26753. // end of HTML tag
  26754. $intag = false;
  26755. }
  26756. }
  26757. }
  26758. if (!$this->empty_string($word)) {
  26759. // hypenate the word
  26760. $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
  26761. }
  26762. // convert char array to string and return
  26763. return $this->UTF8ArrSubString($txtarr);
  26764. }
  26765. /**
  26766. * Enable/disable rasterization of vector images using ImageMagick library.
  26767. * @param $mode (boolean) if true enable rasterization, false otherwise.
  26768. * @public
  26769. * @since 5.0.000 (2010-04-27)
  26770. */
  26771. public function setRasterizeVectorImages($mode) {
  26772. $this->rasterize_vector_images = $mode;
  26773. }
  26774. /**
  26775. * Get the Path-Painting Operators.
  26776. * @param $style (string) Style of rendering. Possible values are:
  26777. * <ul>
  26778. * <li>S or D: Stroke the path.</li>
  26779. * <li>s or d: Close and stroke the path.</li>
  26780. * <li>f or F: Fill the path, using the nonzero winding number rule to determine the region to fill.</li>
  26781. * <li>f* or F*: Fill the path, using the even-odd rule to determine the region to fill.</li>
  26782. * <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>
  26783. * <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>
  26784. * <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>
  26785. * <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>
  26786. * <li>CNZ: Clipping mode using the even-odd rule to determine which regions lie inside the clipping path.</li>
  26787. * <li>CEO: Clipping mode using the nonzero winding number rule to determine which regions lie inside the clipping path</li>
  26788. * <li>n: End the path object without filling or stroking it.</li>
  26789. * </ul>
  26790. * @param $default (string) default style
  26791. * @author Nicola Asuni
  26792. * @since 5.0.000 (2010-04-30)
  26793. * @protected
  26794. */
  26795. protected function getPathPaintOperator($style, $default='S') {
  26796. $op = '';
  26797. switch($style) {
  26798. case 'S':
  26799. case 'D': {
  26800. $op = 'S';
  26801. break;
  26802. }
  26803. case 's':
  26804. case 'd': {
  26805. $op = 's';
  26806. break;
  26807. }
  26808. case 'f':
  26809. case 'F': {
  26810. $op = 'f';
  26811. break;
  26812. }
  26813. case 'f*':
  26814. case 'F*': {
  26815. $op = 'f*';
  26816. break;
  26817. }
  26818. case 'B':
  26819. case 'FD':
  26820. case 'DF': {
  26821. $op = 'B';
  26822. break;
  26823. }
  26824. case 'B*':
  26825. case 'F*D':
  26826. case 'DF*': {
  26827. $op = 'B*';
  26828. break;
  26829. }
  26830. case 'b':
  26831. case 'fd':
  26832. case 'df': {
  26833. $op = 'b';
  26834. break;
  26835. }
  26836. case 'b*':
  26837. case 'f*d':
  26838. case 'df*': {
  26839. $op = 'b*';
  26840. break;
  26841. }
  26842. case 'CNZ': {
  26843. $op = 'W n';
  26844. break;
  26845. }
  26846. case 'CEO': {
  26847. $op = 'W* n';
  26848. break;
  26849. }
  26850. case 'n': {
  26851. $op = 'n';
  26852. break;
  26853. }
  26854. default: {
  26855. if (!empty($default)) {
  26856. $op = $this->getPathPaintOperator($default, '');
  26857. } else {
  26858. $op = '';
  26859. }
  26860. }
  26861. }
  26862. return $op;
  26863. }
  26864. /**
  26865. * Enable or disable default option for font subsetting.
  26866. * @param $enable (boolean) if true enable font subsetting by default.
  26867. * @author Nicola Asuni
  26868. * @public
  26869. * @since 5.3.002 (2010-06-07)
  26870. */
  26871. public function setFontSubsetting($enable=true) {
  26872. if ($this->pdfa_mode) {
  26873. $this->font_subsetting = false;
  26874. } else {
  26875. $this->font_subsetting = $enable ? true : false;
  26876. }
  26877. }
  26878. /**
  26879. * Return the default option for font subsetting.
  26880. * @return boolean default font subsetting state.
  26881. * @author Nicola Asuni
  26882. * @public
  26883. * @since 5.3.002 (2010-06-07)
  26884. */
  26885. public function getFontSubsetting() {
  26886. return $this->font_subsetting;
  26887. }
  26888. /**
  26889. * Left trim the input string
  26890. * @param $str (string) string to trim
  26891. * @param $replace (string) string that replace spaces.
  26892. * @return left trimmed string
  26893. * @author Nicola Asuni
  26894. * @public
  26895. * @since 5.8.000 (2010-08-11)
  26896. */
  26897. public function stringLeftTrim($str, $replace='') {
  26898. return preg_replace('/^'.$this->re_space['p'].'+/'.$this->re_space['m'], $replace, $str);
  26899. }
  26900. /**
  26901. * Right trim the input string
  26902. * @param $str (string) string to trim
  26903. * @param $replace (string) string that replace spaces.
  26904. * @return right trimmed string
  26905. * @author Nicola Asuni
  26906. * @public
  26907. * @since 5.8.000 (2010-08-11)
  26908. */
  26909. public function stringRightTrim($str, $replace='') {
  26910. return preg_replace('/'.$this->re_space['p'].'+$/'.$this->re_space['m'], $replace, $str);
  26911. }
  26912. /**
  26913. * Trim the input string
  26914. * @param $str (string) string to trim
  26915. * @param $replace (string) string that replace spaces.
  26916. * @return trimmed string
  26917. * @author Nicola Asuni
  26918. * @public
  26919. * @since 5.8.000 (2010-08-11)
  26920. */
  26921. public function stringTrim($str, $replace='') {
  26922. $str = $this->stringLeftTrim($str, $replace);
  26923. $str = $this->stringRightTrim($str, $replace);
  26924. return $str;
  26925. }
  26926. /**
  26927. * Return true if the current font is unicode type.
  26928. * @return true for unicode font, false otherwise.
  26929. * @author Nicola Asuni
  26930. * @public
  26931. * @since 5.8.002 (2010-08-14)
  26932. */
  26933. public function isUnicodeFont() {
  26934. return (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0'));
  26935. }
  26936. /**
  26937. * Return normalized font name
  26938. * @param $fontfamily (string) property string containing font family names
  26939. * @return string normalized font name
  26940. * @author Nicola Asuni
  26941. * @public
  26942. * @since 5.8.004 (2010-08-17)
  26943. */
  26944. public function getFontFamilyName($fontfamily) {
  26945. // remove spaces and symbols
  26946. $fontfamily = preg_replace('/[^a-z0-9_\,]/', '', strtolower($fontfamily));
  26947. // extract all font names
  26948. $fontslist = preg_split('/[,]/', $fontfamily);
  26949. // find first valid font name
  26950. foreach ($fontslist as $font) {
  26951. // replace font variations
  26952. $font = preg_replace('/italic$/', 'I', $font);
  26953. $font = preg_replace('/oblique$/', 'I', $font);
  26954. $font = preg_replace('/bold([I]?)$/', 'B\\1', $font);
  26955. // replace common family names and core fonts
  26956. $pattern = array();
  26957. $replacement = array();
  26958. $pattern[] = '/^serif|^cursive|^fantasy|^timesnewroman/';
  26959. $replacement[] = 'times';
  26960. $pattern[] = '/^sansserif/';
  26961. $replacement[] = 'helvetica';
  26962. $pattern[] = '/^monospace/';
  26963. $replacement[] = 'courier';
  26964. $font = preg_replace($pattern, $replacement, $font);
  26965. if (in_array(strtolower($font), $this->fontlist) OR in_array($font, $this->fontkeys)) {
  26966. return $font;
  26967. }
  26968. }
  26969. // return current font as default
  26970. return $this->CurrentFont['fontkey'];
  26971. }
  26972. /**
  26973. * Start a new XObject Template.
  26974. * 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).
  26975. * 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.
  26976. * Note: X,Y coordinates will be reset to 0,0.
  26977. * @param $w (int) Template width in user units (empty string or zero = page width less margins).
  26978. * @param $h (int) Template height in user units (empty string or zero = page height less margins).
  26979. * @param $group (mixed) Set transparency group. Can be a boolean value or an array specifying optional parameters: 'CS' (solour space name), 'I' (boolean flag to indicate isolated group) and 'K' (boolean flag to indicate knockout group).
  26980. * @return int the XObject Template ID in case of success or false in case of error.
  26981. * @author Nicola Asuni
  26982. * @public
  26983. * @since 5.8.017 (2010-08-24)
  26984. * @see endTemplate(), printTemplate()
  26985. */
  26986. public function startTemplate($w=0, $h=0, $group=false) {
  26987. if ($this->inxobj) {
  26988. // we are already inside an XObject template
  26989. return false;
  26990. }
  26991. $this->inxobj = true;
  26992. ++$this->n;
  26993. // XObject ID
  26994. $this->xobjid = 'XT'.$this->n;
  26995. // object ID
  26996. $this->xobjects[$this->xobjid] = array('n' => $this->n);
  26997. // store current graphic state
  26998. $this->xobjects[$this->xobjid]['gvars'] = $this->getGraphicVars();
  26999. // initialize data
  27000. $this->xobjects[$this->xobjid]['intmrk'] = 0;
  27001. $this->xobjects[$this->xobjid]['transfmrk'] = array();
  27002. $this->xobjects[$this->xobjid]['outdata'] = '';
  27003. $this->xobjects[$this->xobjid]['xobjects'] = array();
  27004. $this->xobjects[$this->xobjid]['images'] = array();
  27005. $this->xobjects[$this->xobjid]['fonts'] = array();
  27006. $this->xobjects[$this->xobjid]['annotations'] = array();
  27007. $this->xobjects[$this->xobjid]['extgstates'] = array();
  27008. $this->xobjects[$this->xobjid]['gradients'] = array();
  27009. $this->xobjects[$this->xobjid]['spot_colors'] = array();
  27010. // set new environment
  27011. $this->num_columns = 1;
  27012. $this->current_column = 0;
  27013. $this->SetAutoPageBreak(false);
  27014. if (($w === '') OR ($w <= 0)) {
  27015. $w = $this->w - $this->lMargin - $this->rMargin;
  27016. }
  27017. if (($h === '') OR ($h <= 0)) {
  27018. $h = $this->h - $this->tMargin - $this->bMargin;
  27019. }
  27020. $this->xobjects[$this->xobjid]['x'] = 0;
  27021. $this->xobjects[$this->xobjid]['y'] = 0;
  27022. $this->xobjects[$this->xobjid]['w'] = $w;
  27023. $this->xobjects[$this->xobjid]['h'] = $h;
  27024. $this->w = $w;
  27025. $this->h = $h;
  27026. $this->wPt = $this->w * $this->k;
  27027. $this->hPt = $this->h * $this->k;
  27028. $this->fwPt = $this->wPt;
  27029. $this->fhPt = $this->hPt;
  27030. $this->x = 0;
  27031. $this->y = 0;
  27032. $this->lMargin = 0;
  27033. $this->rMargin = 0;
  27034. $this->tMargin = 0;
  27035. $this->bMargin = 0;
  27036. // set group mode
  27037. $this->xobjects[$this->xobjid]['group'] = $group;
  27038. return $this->xobjid;
  27039. }
  27040. /**
  27041. * End the current XObject Template started with startTemplate() and restore the previous graphic state.
  27042. * 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).
  27043. * 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.
  27044. * @return int the XObject Template ID in case of success or false in case of error.
  27045. * @author Nicola Asuni
  27046. * @public
  27047. * @since 5.8.017 (2010-08-24)
  27048. * @see startTemplate(), printTemplate()
  27049. */
  27050. public function endTemplate() {
  27051. if (!$this->inxobj) {
  27052. // we are not inside a template
  27053. return false;
  27054. }
  27055. $this->inxobj = false;
  27056. // restore previous graphic state
  27057. $this->setGraphicVars($this->xobjects[$this->xobjid]['gvars'], true);
  27058. return $this->xobjid;
  27059. }
  27060. /**
  27061. * Print an XObject Template.
  27062. * You can print an XObject Template inside the currently opened Template.
  27063. * 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).
  27064. * 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.
  27065. * @param $id (string) The ID of XObject Template to print.
  27066. * @param $x (int) X position in user units (empty string = current x position)
  27067. * @param $y (int) Y position in user units (empty string = current y position)
  27068. * @param $w (int) Width in user units (zero = remaining page width)
  27069. * @param $h (int) Height in user units (zero = remaining page height)
  27070. * @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>
  27071. * @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>
  27072. * @param $fitonpage (boolean) If true the template is resized to not exceed page dimensions.
  27073. * @author Nicola Asuni
  27074. * @public
  27075. * @since 5.8.017 (2010-08-24)
  27076. * @see startTemplate(), endTemplate()
  27077. */
  27078. public function printTemplate($id, $x='', $y='', $w=0, $h=0, $align='', $palign='', $fitonpage=false) {
  27079. if ($this->state != 2) {
  27080. return;
  27081. }
  27082. if (!isset($this->xobjects[$id])) {
  27083. $this->Error('The XObject Template \''.$id.'\' doesn\'t exist!');
  27084. }
  27085. if ($this->inxobj) {
  27086. if ($id == $this->xobjid) {
  27087. // close current template
  27088. $this->endTemplate();
  27089. } else {
  27090. // use the template as resource for the template currently opened
  27091. $this->xobjects[$this->xobjid]['xobjects'][$id] = $this->xobjects[$id];
  27092. }
  27093. }
  27094. // set default values
  27095. if ($x === '') {
  27096. $x = $this->x;
  27097. }
  27098. if ($y === '') {
  27099. $y = $this->y;
  27100. }
  27101. // check page for no-write regions and adapt page margins if necessary
  27102. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  27103. $ow = $this->xobjects[$id]['w'];
  27104. $oh = $this->xobjects[$id]['h'];
  27105. // calculate template width and height on document
  27106. if (($w <= 0) AND ($h <= 0)) {
  27107. $w = $ow;
  27108. $h = $oh;
  27109. } elseif ($w <= 0) {
  27110. $w = $h * $ow / $oh;
  27111. } elseif ($h <= 0) {
  27112. $h = $w * $oh / $ow;
  27113. }
  27114. // fit the template on available space
  27115. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  27116. // set page alignment
  27117. $rb_y = $y + $h;
  27118. // set alignment
  27119. if ($this->rtl) {
  27120. if ($palign == 'L') {
  27121. $xt = $this->lMargin;
  27122. } elseif ($palign == 'C') {
  27123. $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  27124. } elseif ($palign == 'R') {
  27125. $xt = $this->w - $this->rMargin - $w;
  27126. } else {
  27127. $xt = $x - $w;
  27128. }
  27129. $rb_x = $xt;
  27130. } else {
  27131. if ($palign == 'L') {
  27132. $xt = $this->lMargin;
  27133. } elseif ($palign == 'C') {
  27134. $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  27135. } elseif ($palign == 'R') {
  27136. $xt = $this->w - $this->rMargin - $w;
  27137. } else {
  27138. $xt = $x;
  27139. }
  27140. $rb_x = $xt + $w;
  27141. }
  27142. // print XObject Template + Transformation matrix
  27143. $this->StartTransform();
  27144. // translate and scale
  27145. $sx = ($w / $this->xobjects[$id]['w']);
  27146. $sy = ($h / $this->xobjects[$id]['h']);
  27147. $tm = array();
  27148. $tm[0] = $sx;
  27149. $tm[1] = 0;
  27150. $tm[2] = 0;
  27151. $tm[3] = $sy;
  27152. $tm[4] = $xt * $this->k;
  27153. $tm[5] = ($this->h - $h - $y) * $this->k;
  27154. $this->Transform($tm);
  27155. // set object
  27156. $this->_out('/'.$id.' Do');
  27157. $this->StopTransform();
  27158. // add annotations
  27159. if (!empty($this->xobjects[$id]['annotations'])) {
  27160. foreach ($this->xobjects[$id]['annotations'] as $annot) {
  27161. // transform original coordinates
  27162. $coordlt = $this->getTransformationMatrixProduct($tm, array(1, 0, 0, 1, ($annot['x'] * $this->k), (-$annot['y'] * $this->k)));
  27163. $ax = ($coordlt[4] / $this->k);
  27164. $ay = ($this->h - $h - ($coordlt[5] / $this->k));
  27165. $coordrb = $this->getTransformationMatrixProduct($tm, array(1, 0, 0, 1, (($annot['x'] + $annot['w']) * $this->k), ((-$annot['y'] - $annot['h']) * $this->k)));
  27166. $aw = ($coordrb[4] / $this->k) - $ax;
  27167. $ah = ($this->h - $h - ($coordrb[5] / $this->k)) - $ay;
  27168. $this->Annotation($ax, $ay, $aw, $ah, $annot['text'], $annot['opt'], $annot['spaces']);
  27169. }
  27170. }
  27171. // set pointer to align the next text/objects
  27172. switch($align) {
  27173. case 'T': {
  27174. $this->y = $y;
  27175. $this->x = $rb_x;
  27176. break;
  27177. }
  27178. case 'M': {
  27179. $this->y = $y + round($h/2);
  27180. $this->x = $rb_x;
  27181. break;
  27182. }
  27183. case 'B': {
  27184. $this->y = $rb_y;
  27185. $this->x = $rb_x;
  27186. break;
  27187. }
  27188. case 'N': {
  27189. $this->SetY($rb_y);
  27190. break;
  27191. }
  27192. default:{
  27193. break;
  27194. }
  27195. }
  27196. }
  27197. /**
  27198. * Set the percentage of character stretching.
  27199. * @param $perc (int) percentage of stretching (100 = no stretching)
  27200. * @author Nicola Asuni
  27201. * @public
  27202. * @since 5.9.000 (2010-09-29)
  27203. */
  27204. public function setFontStretching($perc=100) {
  27205. $this->font_stretching = $perc;
  27206. }
  27207. /**
  27208. * Get the percentage of character stretching.
  27209. * @return float stretching value
  27210. * @author Nicola Asuni
  27211. * @public
  27212. * @since 5.9.000 (2010-09-29)
  27213. */
  27214. public function getFontStretching() {
  27215. return $this->font_stretching;
  27216. }
  27217. /**
  27218. * Set the amount to increase or decrease the space between characters in a text.
  27219. * @param $spacing (float) amount to increase or decrease the space between characters in a text (0 = default spacing)
  27220. * @author Nicola Asuni
  27221. * @public
  27222. * @since 5.9.000 (2010-09-29)
  27223. */
  27224. public function setFontSpacing($spacing=0) {
  27225. $this->font_spacing = $spacing;
  27226. }
  27227. /**
  27228. * Get the amount to increase or decrease the space between characters in a text.
  27229. * @return int font spacing (tracking) value
  27230. * @author Nicola Asuni
  27231. * @public
  27232. * @since 5.9.000 (2010-09-29)
  27233. */
  27234. public function getFontSpacing() {
  27235. return $this->font_spacing;
  27236. }
  27237. /**
  27238. * Return an array of no-write page regions
  27239. * @return array of no-write page regions
  27240. * @author Nicola Asuni
  27241. * @public
  27242. * @since 5.9.003 (2010-10-13)
  27243. * @see setPageRegions(), addPageRegion()
  27244. */
  27245. public function getPageRegions() {
  27246. return $this->page_regions;
  27247. }
  27248. /**
  27249. * Set no-write regions on page.
  27250. * 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.
  27251. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  27252. * You can set multiple regions for the same page.
  27253. * @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.
  27254. * @author Nicola Asuni
  27255. * @public
  27256. * @since 5.9.003 (2010-10-13)
  27257. * @see addPageRegion(), getPageRegions()
  27258. */
  27259. public function setPageRegions($regions=array()) {
  27260. // empty current regions array
  27261. $this->page_regions = array();
  27262. // add regions
  27263. foreach ($regions as $data) {
  27264. $this->addPageRegion($data);
  27265. }
  27266. }
  27267. /**
  27268. * Add a single no-write region on selected page.
  27269. * 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.
  27270. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  27271. * You can set multiple regions for the same page.
  27272. * @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).
  27273. * @author Nicola Asuni
  27274. * @public
  27275. * @since 5.9.003 (2010-10-13)
  27276. * @see setPageRegions(), getPageRegions()
  27277. */
  27278. public function addPageRegion($region) {
  27279. if (!isset($region['page']) OR empty($region['page'])) {
  27280. $region['page'] = $this->page;
  27281. }
  27282. if (isset($region['xt']) AND isset($region['xb']) AND ($region['xt'] > 0) AND ($region['xb'] > 0)
  27283. AND isset($region['yt']) AND isset($region['yb']) AND ($region['yt'] >= 0) AND ($region['yt'] < $region['yb'])
  27284. AND isset($region['side']) AND (($region['side'] == 'L') OR ($region['side'] == 'R'))) {
  27285. $this->page_regions[] = $region;
  27286. }
  27287. }
  27288. /**
  27289. * Remove a single no-write region.
  27290. * @param $key (int) region key
  27291. * @author Nicola Asuni
  27292. * @public
  27293. * @since 5.9.003 (2010-10-13)
  27294. * @see setPageRegions(), getPageRegions()
  27295. */
  27296. public function removePageRegion($key) {
  27297. if (isset($this->page_regions[$key])) {
  27298. unset($this->page_regions[$key]);
  27299. }
  27300. }
  27301. /**
  27302. * Check page for no-write regions and adapt current coordinates and page margins if necessary.
  27303. * 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.
  27304. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  27305. * @param $h (float) height of the text/image/object to print in user units
  27306. * @param $x (float) current X coordinate in user units
  27307. * @param $y (float) current Y coordinate in user units
  27308. * @return array($x, $y)
  27309. * @author Nicola Asuni
  27310. * @protected
  27311. * @since 5.9.003 (2010-10-13)
  27312. */
  27313. protected function checkPageRegions($h, $x, $y) {
  27314. // set default values
  27315. if ($x === '') {
  27316. $x = $this->x;
  27317. }
  27318. if ($y === '') {
  27319. $y = $this->y;
  27320. }
  27321. if (!$this->check_page_regions OR empty($this->page_regions)) {
  27322. // no page regions defined
  27323. return array($x, $y);
  27324. }
  27325. if (empty($h)) {
  27326. $h = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  27327. }
  27328. // check for page break
  27329. if ($this->checkPageBreak($h, $y)) {
  27330. // the content will be printed on a new page
  27331. $x = $this->x;
  27332. $y = $this->y;
  27333. }
  27334. if ($this->num_columns > 1) {
  27335. if ($this->rtl) {
  27336. $this->lMargin = ($this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']);
  27337. } else {
  27338. $this->rMargin = ($this->w - $this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']);
  27339. }
  27340. } else {
  27341. if ($this->rtl) {
  27342. $this->lMargin = max($this->clMargin, $this->original_lMargin);
  27343. } else {
  27344. $this->rMargin = max($this->crMargin, $this->original_rMargin);
  27345. }
  27346. }
  27347. // adjust coordinates and page margins
  27348. foreach ($this->page_regions as $regid => $regdata) {
  27349. if ($regdata['page'] == $this->page) {
  27350. // check region boundaries
  27351. if (($y > ($regdata['yt'] - $h)) AND ($y <= $regdata['yb'])) {
  27352. // Y is inside the region
  27353. $minv = ($regdata['xb'] - $regdata['xt']) / ($regdata['yb'] - $regdata['yt']); // inverse of angular coefficient
  27354. $yt = max($y, $regdata['yt']);
  27355. $yb = min(($yt + $h), $regdata['yb']);
  27356. $xt = (($yt - $regdata['yt']) * $minv) + $regdata['xt'];
  27357. $xb = (($yb - $regdata['yt']) * $minv) + $regdata['xt'];
  27358. if ($regdata['side'] == 'L') { // left side
  27359. $new_margin = max($xt, $xb);
  27360. if ($this->lMargin < $new_margin) {
  27361. if ($this->rtl) {
  27362. // adjust left page margin
  27363. $this->lMargin = max(0, $new_margin);
  27364. }
  27365. if ($x < $new_margin) {
  27366. // adjust x position
  27367. $x = $new_margin;
  27368. if ($new_margin > ($this->w - $this->rMargin)) {
  27369. // adjust y position
  27370. $y = $regdata['yb'] - $h;
  27371. }
  27372. }
  27373. }
  27374. } elseif ($regdata['side'] == 'R') { // right side
  27375. $new_margin = min($xt, $xb);
  27376. if (($this->w - $this->rMargin) > $new_margin) {
  27377. if (!$this->rtl) {
  27378. // adjust right page margin
  27379. $this->rMargin = max(0, ($this->w - $new_margin));
  27380. }
  27381. if ($x > $new_margin) {
  27382. // adjust x position
  27383. $x = $new_margin;
  27384. if ($new_margin > $this->lMargin) {
  27385. // adjust y position
  27386. $y = $regdata['yb'] - $h;
  27387. }
  27388. }
  27389. }
  27390. }
  27391. }
  27392. }
  27393. }
  27394. return array($x, $y);
  27395. }
  27396. // --- SVG METHODS ---------------------------------------------------------
  27397. /**
  27398. * Embedd a Scalable Vector Graphics (SVG) image.
  27399. * NOTE: SVG standard is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  27400. * @param $file (string) Name of the SVG file or a '@' character followed by the SVG data string.
  27401. * @param $x (float) Abscissa of the upper-left corner.
  27402. * @param $y (float) Ordinate of the upper-left corner.
  27403. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  27404. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  27405. * @param $link (mixed) URL or identifier returned by AddLink().
  27406. * @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.
  27407. * @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>
  27408. * @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)))
  27409. * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
  27410. * @author Nicola Asuni
  27411. * @since 5.0.000 (2010-05-02)
  27412. * @public
  27413. */
  27414. public function ImageSVG($file, $x='', $y='', $w=0, $h=0, $link='', $align='', $palign='', $border=0, $fitonpage=false) {
  27415. if ($this->state != 2) {
  27416. return;
  27417. }
  27418. if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
  27419. // convert SVG to raster image using GD or ImageMagick libraries
  27420. return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
  27421. }
  27422. if ($file{0} === '@') { // image from string
  27423. $this->svgdir = '';
  27424. $svgdata = substr($file, 1);
  27425. } else { // SVG file
  27426. $this->svgdir = dirname($file);
  27427. $svgdata = file_get_contents($file);
  27428. }
  27429. if ($svgdata === false) {
  27430. $this->Error('SVG file not found: '.$file);
  27431. }
  27432. if ($x === '') {
  27433. $x = $this->x;
  27434. }
  27435. if ($y === '') {
  27436. $y = $this->y;
  27437. }
  27438. // check page for no-write regions and adapt page margins if necessary
  27439. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  27440. $k = $this->k;
  27441. $ox = 0;
  27442. $oy = 0;
  27443. $ow = $w;
  27444. $oh = $h;
  27445. $aspect_ratio_align = 'xMidYMid';
  27446. $aspect_ratio_ms = 'meet';
  27447. $regs = array();
  27448. // get original image width and height
  27449. preg_match('/<svg([^\>]*)>/si', $svgdata, $regs);
  27450. if (isset($regs[1]) AND !empty($regs[1])) {
  27451. $tmp = array();
  27452. if (preg_match('/[\s]+x[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  27453. $ox = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
  27454. }
  27455. $tmp = array();
  27456. if (preg_match('/[\s]+y[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  27457. $oy = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
  27458. }
  27459. $tmp = array();
  27460. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  27461. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  27462. }
  27463. $tmp = array();
  27464. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  27465. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  27466. }
  27467. $tmp = array();
  27468. $view_box = array();
  27469. if (preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.\-]+)[\s]+([0-9\.\-]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $regs[1], $tmp)) {
  27470. if (count($tmp) == 5) {
  27471. array_shift($tmp);
  27472. foreach ($tmp as $key => $val) {
  27473. $view_box[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
  27474. }
  27475. $ox = $view_box[0];
  27476. $oy = $view_box[1];
  27477. }
  27478. // get aspect ratio
  27479. $tmp = array();
  27480. if (preg_match('/[\s]+preserveAspectRatio[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  27481. $aspect_ratio = preg_split('/[\s]+/si', $tmp[1]);
  27482. switch (count($aspect_ratio)) {
  27483. case 3: {
  27484. $aspect_ratio_align = $aspect_ratio[1];
  27485. $aspect_ratio_ms = $aspect_ratio[2];
  27486. break;
  27487. }
  27488. case 2: {
  27489. $aspect_ratio_align = $aspect_ratio[0];
  27490. $aspect_ratio_ms = $aspect_ratio[1];
  27491. break;
  27492. }
  27493. case 1: {
  27494. $aspect_ratio_align = $aspect_ratio[0];
  27495. $aspect_ratio_ms = 'meet';
  27496. break;
  27497. }
  27498. }
  27499. }
  27500. }
  27501. }
  27502. // calculate image width and height on document
  27503. if (($w <= 0) AND ($h <= 0)) {
  27504. // convert image size to document unit
  27505. $w = $ow;
  27506. $h = $oh;
  27507. } elseif ($w <= 0) {
  27508. $w = $h * $ow / $oh;
  27509. } elseif ($h <= 0) {
  27510. $h = $w * $oh / $ow;
  27511. }
  27512. // fit the image on available space
  27513. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  27514. if ($this->rasterize_vector_images) {
  27515. // convert SVG to raster image using GD or ImageMagick libraries
  27516. return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
  27517. }
  27518. // set alignment
  27519. $this->img_rb_y = $y + $h;
  27520. // set alignment
  27521. if ($this->rtl) {
  27522. if ($palign == 'L') {
  27523. $ximg = $this->lMargin;
  27524. } elseif ($palign == 'C') {
  27525. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  27526. } elseif ($palign == 'R') {
  27527. $ximg = $this->w - $this->rMargin - $w;
  27528. } else {
  27529. $ximg = $x - $w;
  27530. }
  27531. $this->img_rb_x = $ximg;
  27532. } else {
  27533. if ($palign == 'L') {
  27534. $ximg = $this->lMargin;
  27535. } elseif ($palign == 'C') {
  27536. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  27537. } elseif ($palign == 'R') {
  27538. $ximg = $this->w - $this->rMargin - $w;
  27539. } else {
  27540. $ximg = $x;
  27541. }
  27542. $this->img_rb_x = $ximg + $w;
  27543. }
  27544. // store current graphic vars
  27545. $gvars = $this->getGraphicVars();
  27546. // store SVG position and scale factors
  27547. $svgoffset_x = ($ximg - $ox) * $this->k;
  27548. $svgoffset_y = -($y - $oy) * $this->k;
  27549. if (isset($view_box[2]) AND ($view_box[2] > 0) AND ($view_box[3] > 0)) {
  27550. $ow = $view_box[2];
  27551. $oh = $view_box[3];
  27552. } else {
  27553. if ($ow <= 0) {
  27554. $ow = $w;
  27555. }
  27556. if ($oh <= 0) {
  27557. $oh = $h;
  27558. }
  27559. }
  27560. $svgscale_x = $w / $ow;
  27561. $svgscale_y = $h / $oh;
  27562. // scaling and alignment
  27563. if ($aspect_ratio_align != 'none') {
  27564. // store current scaling values
  27565. $svgscale_old_x = $svgscale_x;
  27566. $svgscale_old_y = $svgscale_y;
  27567. // force uniform scaling
  27568. if ($aspect_ratio_ms == 'slice') {
  27569. // the entire viewport is covered by the viewBox
  27570. if ($svgscale_x > $svgscale_y) {
  27571. $svgscale_y = $svgscale_x;
  27572. } elseif ($svgscale_x < $svgscale_y) {
  27573. $svgscale_x = $svgscale_y;
  27574. }
  27575. } else { // meet
  27576. // the entire viewBox is visible within the viewport
  27577. if ($svgscale_x < $svgscale_y) {
  27578. $svgscale_y = $svgscale_x;
  27579. } elseif ($svgscale_x > $svgscale_y) {
  27580. $svgscale_x = $svgscale_y;
  27581. }
  27582. }
  27583. // correct X alignment
  27584. switch (substr($aspect_ratio_align, 1, 3)) {
  27585. case 'Min': {
  27586. // do nothing
  27587. break;
  27588. }
  27589. case 'Max': {
  27590. $svgoffset_x += (($w * $this->k) - ($ow * $this->k * $svgscale_x));
  27591. break;
  27592. }
  27593. default:
  27594. case 'Mid': {
  27595. $svgoffset_x += ((($w * $this->k) - ($ow * $this->k * $svgscale_x)) / 2);
  27596. break;
  27597. }
  27598. }
  27599. // correct Y alignment
  27600. switch (substr($aspect_ratio_align, 5)) {
  27601. case 'Min': {
  27602. // do nothing
  27603. break;
  27604. }
  27605. case 'Max': {
  27606. $svgoffset_y -= (($h * $this->k) - ($oh * $this->k * $svgscale_y));
  27607. break;
  27608. }
  27609. default:
  27610. case 'Mid': {
  27611. $svgoffset_y -= ((($h * $this->k) - ($oh * $this->k * $svgscale_y)) / 2);
  27612. break;
  27613. }
  27614. }
  27615. }
  27616. // store current page break mode
  27617. $page_break_mode = $this->AutoPageBreak;
  27618. $page_break_margin = $this->getBreakMargin();
  27619. $cell_padding = $this->cell_padding;
  27620. $this->SetCellPadding(0);
  27621. $this->SetAutoPageBreak(false);
  27622. // save the current graphic state
  27623. $this->_out('q'.$this->epsmarker);
  27624. // set initial clipping mask
  27625. $this->Rect($x, $y, $w, $h, 'CNZ', array(), array());
  27626. // scale and translate
  27627. $e = $ox * $this->k * (1 - $svgscale_x);
  27628. $f = ($this->h - $oy) * $this->k * (1 - $svgscale_y);
  27629. $this->_out(sprintf('%F %F %F %F %F %F cm', $svgscale_x, 0, 0, $svgscale_y, ($e + $svgoffset_x), ($f + $svgoffset_y)));
  27630. // creates a new XML parser to be used by the other XML functions
  27631. $this->parser = xml_parser_create('UTF-8');
  27632. // the following function allows to use parser inside object
  27633. xml_set_object($this->parser, $this);
  27634. // disable case-folding for this XML parser
  27635. xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
  27636. // sets the element handler functions for the XML parser
  27637. xml_set_element_handler($this->parser, 'startSVGElementHandler', 'endSVGElementHandler');
  27638. // sets the character data handler function for the XML parser
  27639. xml_set_character_data_handler($this->parser, 'segSVGContentHandler');
  27640. // start parsing an XML document
  27641. if (!xml_parse($this->parser, $svgdata)) {
  27642. $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));
  27643. $this->Error($error_message);
  27644. }
  27645. // free this XML parser
  27646. xml_parser_free($this->parser);
  27647. // restore previous graphic state
  27648. $this->_out($this->epsmarker.'Q');
  27649. // restore graphic vars
  27650. $this->setGraphicVars($gvars);
  27651. $this->lasth = $gvars['lasth'];
  27652. if (!empty($border)) {
  27653. $bx = $this->x;
  27654. $by = $this->y;
  27655. $this->x = $ximg;
  27656. if ($this->rtl) {
  27657. $this->x += $w;
  27658. }
  27659. $this->y = $y;
  27660. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  27661. $this->x = $bx;
  27662. $this->y = $by;
  27663. }
  27664. if ($link) {
  27665. $this->Link($ximg, $y, $w, $h, $link, 0);
  27666. }
  27667. // set pointer to align the next text/objects
  27668. switch($align) {
  27669. case 'T':{
  27670. $this->y = $y;
  27671. $this->x = $this->img_rb_x;
  27672. break;
  27673. }
  27674. case 'M':{
  27675. $this->y = $y + round($h/2);
  27676. $this->x = $this->img_rb_x;
  27677. break;
  27678. }
  27679. case 'B':{
  27680. $this->y = $this->img_rb_y;
  27681. $this->x = $this->img_rb_x;
  27682. break;
  27683. }
  27684. case 'N':{
  27685. $this->SetY($this->img_rb_y);
  27686. break;
  27687. }
  27688. default:{
  27689. // restore pointer to starting position
  27690. $this->x = $gvars['x'];
  27691. $this->y = $gvars['y'];
  27692. $this->page = $gvars['page'];
  27693. $this->current_column = $gvars['current_column'];
  27694. $this->tMargin = $gvars['tMargin'];
  27695. $this->bMargin = $gvars['bMargin'];
  27696. $this->w = $gvars['w'];
  27697. $this->h = $gvars['h'];
  27698. $this->wPt = $gvars['wPt'];
  27699. $this->hPt = $gvars['hPt'];
  27700. $this->fwPt = $gvars['fwPt'];
  27701. $this->fhPt = $gvars['fhPt'];
  27702. break;
  27703. }
  27704. }
  27705. $this->endlinex = $this->img_rb_x;
  27706. // restore page break
  27707. $this->SetAutoPageBreak($page_break_mode, $page_break_margin);
  27708. $this->cell_padding = $cell_padding;
  27709. }
  27710. /**
  27711. * Get the tranformation matrix from SVG transform attribute
  27712. * @param $attribute (string) transformation
  27713. * @return array of transformations
  27714. * @author Nicola Asuni
  27715. * @since 5.0.000 (2010-05-02)
  27716. * @protected
  27717. */
  27718. protected function getSVGTransformMatrix($attribute) {
  27719. // identity matrix
  27720. $tm = array(1, 0, 0, 1, 0, 0);
  27721. $transform = array();
  27722. if (preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)[\s]*\(([^\)]+)\)/si', $attribute, $transform, PREG_SET_ORDER) > 0) {
  27723. foreach ($transform as $key => $data) {
  27724. if (!empty($data[2])) {
  27725. $a = 1;
  27726. $b = 0;
  27727. $c = 0;
  27728. $d = 1;
  27729. $e = 0;
  27730. $f = 0;
  27731. $regs = array();
  27732. switch ($data[1]) {
  27733. case 'matrix': {
  27734. 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)) {
  27735. $a = $regs[1];
  27736. $b = $regs[2];
  27737. $c = $regs[3];
  27738. $d = $regs[4];
  27739. $e = $regs[5];
  27740. $f = $regs[6];
  27741. }
  27742. break;
  27743. }
  27744. case 'translate': {
  27745. if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  27746. $e = $regs[1];
  27747. $f = $regs[2];
  27748. } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  27749. $e = $regs[1];
  27750. }
  27751. break;
  27752. }
  27753. case 'scale': {
  27754. if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  27755. $a = $regs[1];
  27756. $d = $regs[2];
  27757. } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  27758. $a = $regs[1];
  27759. $d = $a;
  27760. }
  27761. break;
  27762. }
  27763. case 'rotate': {
  27764. if (preg_match('/([0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  27765. $ang = deg2rad($regs[1]);
  27766. $x = $regs[2];
  27767. $y = $regs[3];
  27768. $a = cos($ang);
  27769. $b = sin($ang);
  27770. $c = -$b;
  27771. $d = $a;
  27772. $e = ($x * (1 - $a)) - ($y * $c);
  27773. $f = ($y * (1 - $d)) - ($x * $b);
  27774. } elseif (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
  27775. $ang = deg2rad($regs[1]);
  27776. $a = cos($ang);
  27777. $b = sin($ang);
  27778. $c = -$b;
  27779. $d = $a;
  27780. $e = 0;
  27781. $f = 0;
  27782. }
  27783. break;
  27784. }
  27785. case 'skewX': {
  27786. if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
  27787. $c = tan(deg2rad($regs[1]));
  27788. }
  27789. break;
  27790. }
  27791. case 'skewY': {
  27792. if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
  27793. $b = tan(deg2rad($regs[1]));
  27794. }
  27795. break;
  27796. }
  27797. }
  27798. $tm = $this->getTransformationMatrixProduct($tm, array($a, $b, $c, $d, $e, $f));
  27799. }
  27800. }
  27801. }
  27802. return $tm;
  27803. }
  27804. /**
  27805. * Get the product of two SVG tranformation matrices
  27806. * @param $ta (array) first SVG tranformation matrix
  27807. * @param $tb (array) second SVG tranformation matrix
  27808. * @return transformation array
  27809. * @author Nicola Asuni
  27810. * @since 5.0.000 (2010-05-02)
  27811. * @protected
  27812. */
  27813. protected function getTransformationMatrixProduct($ta, $tb) {
  27814. $tm = array();
  27815. $tm[0] = ($ta[0] * $tb[0]) + ($ta[2] * $tb[1]);
  27816. $tm[1] = ($ta[1] * $tb[0]) + ($ta[3] * $tb[1]);
  27817. $tm[2] = ($ta[0] * $tb[2]) + ($ta[2] * $tb[3]);
  27818. $tm[3] = ($ta[1] * $tb[2]) + ($ta[3] * $tb[3]);
  27819. $tm[4] = ($ta[0] * $tb[4]) + ($ta[2] * $tb[5]) + $ta[4];
  27820. $tm[5] = ($ta[1] * $tb[4]) + ($ta[3] * $tb[5]) + $ta[5];
  27821. return $tm;
  27822. }
  27823. /**
  27824. * Convert SVG transformation matrix to PDF.
  27825. * @param $tm (array) original SVG transformation matrix
  27826. * @return array transformation matrix
  27827. * @protected
  27828. * @since 5.0.000 (2010-05-02)
  27829. */
  27830. protected function convertSVGtMatrix($tm) {
  27831. $a = $tm[0];
  27832. $b = -$tm[1];
  27833. $c = -$tm[2];
  27834. $d = $tm[3];
  27835. $e = $this->getHTMLUnitToUnits($tm[4], 1, $this->svgunit, false) * $this->k;
  27836. $f = -$this->getHTMLUnitToUnits($tm[5], 1, $this->svgunit, false) * $this->k;
  27837. $x = 0;
  27838. $y = $this->h * $this->k;
  27839. $e = ($x * (1 - $a)) - ($y * $c) + $e;
  27840. $f = ($y * (1 - $d)) - ($x * $b) + $f;
  27841. return array($a, $b, $c, $d, $e, $f);
  27842. }
  27843. /**
  27844. * Apply SVG graphic transformation matrix.
  27845. * @param $tm (array) original SVG transformation matrix
  27846. * @protected
  27847. * @since 5.0.000 (2010-05-02)
  27848. */
  27849. protected function SVGTransform($tm) {
  27850. $this->Transform($this->convertSVGtMatrix($tm));
  27851. }
  27852. /**
  27853. * Apply the requested SVG styles (*** TO BE COMPLETED ***)
  27854. * @param $svgstyle (array) array of SVG styles to apply
  27855. * @param $prevsvgstyle (array) array of previous SVG style
  27856. * @param $x (int) X origin of the bounding box
  27857. * @param $y (int) Y origin of the bounding box
  27858. * @param $w (int) width of the bounding box
  27859. * @param $h (int) height of the bounding box
  27860. * @param $clip_function (string) clip function
  27861. * @param $clip_params (array) array of parameters for clipping function
  27862. * @return object style
  27863. * @author Nicola Asuni
  27864. * @since 5.0.000 (2010-05-02)
  27865. * @protected
  27866. */
  27867. protected function setSVGStyles($svgstyle, $prevsvgstyle, $x=0, $y=0, $w=1, $h=1, $clip_function='', $clip_params=array()) {
  27868. if ($this->state != 2) {
  27869. return;
  27870. }
  27871. $objstyle = '';
  27872. $minlen = (0.01 / $this->k); // minimum acceptable length (3 point)
  27873. if (!isset($svgstyle['opacity'])) {
  27874. return $objstyle;
  27875. }
  27876. // clip-path
  27877. $regs = array();
  27878. if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['clip-path'], $regs)) {
  27879. $clip_path = $this->svgclippaths[$regs[1]];
  27880. foreach ($clip_path as $cp) {
  27881. $this->startSVGElementHandler('clip-path', $cp['name'], $cp['attribs'], $cp['tm']);
  27882. }
  27883. }
  27884. // opacity
  27885. if ($svgstyle['opacity'] != 1) {
  27886. $this->setAlpha($svgstyle['opacity'], 'Normal', $svgstyle['opacity'], false);
  27887. }
  27888. // color
  27889. $fill_color = $this->convertHTMLColorToDec($svgstyle['color']);
  27890. $this->SetFillColorArray($fill_color);
  27891. // text color
  27892. $text_color = $this->convertHTMLColorToDec($svgstyle['text-color']);
  27893. $this->SetTextColorArray($text_color);
  27894. // clip
  27895. if (preg_match('/rect\(([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)\)/si', $svgstyle['clip'], $regs)) {
  27896. $top = (isset($regs[1])?$this->getHTMLUnitToUnits($regs[1], 0, $this->svgunit, false):0);
  27897. $right = (isset($regs[2])?$this->getHTMLUnitToUnits($regs[2], 0, $this->svgunit, false):0);
  27898. $bottom = (isset($regs[3])?$this->getHTMLUnitToUnits($regs[3], 0, $this->svgunit, false):0);
  27899. $left = (isset($regs[4])?$this->getHTMLUnitToUnits($regs[4], 0, $this->svgunit, false):0);
  27900. $cx = $x + $left;
  27901. $cy = $y + $top;
  27902. $cw = $w - $left - $right;
  27903. $ch = $h - $top - $bottom;
  27904. if ($svgstyle['clip-rule'] == 'evenodd') {
  27905. $clip_rule = 'CNZ';
  27906. } else {
  27907. $clip_rule = 'CEO';
  27908. }
  27909. $this->Rect($cx, $cy, $cw, $ch, $clip_rule, array(), array());
  27910. }
  27911. // fill
  27912. $regs = array();
  27913. if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['fill'], $regs)) {
  27914. // gradient
  27915. $gradient = $this->svggradients[$regs[1]];
  27916. if (isset($gradient['xref'])) {
  27917. // reference to another gradient definition
  27918. $newgradient = $this->svggradients[$gradient['xref']];
  27919. $newgradient['coords'] = $gradient['coords'];
  27920. $newgradient['mode'] = $gradient['mode'];
  27921. $newgradient['gradientUnits'] = $gradient['gradientUnits'];
  27922. if (isset($gradient['gradientTransform'])) {
  27923. $newgradient['gradientTransform'] = $gradient['gradientTransform'];
  27924. }
  27925. $gradient = $newgradient;
  27926. }
  27927. //save current Graphic State
  27928. $this->_out('q');
  27929. //set clipping area
  27930. if (!empty($clip_function) AND method_exists($this, $clip_function)) {
  27931. $bbox = call_user_func_array(array($this, $clip_function), $clip_params);
  27932. if (is_array($bbox) AND (count($bbox) == 4)) {
  27933. list($x, $y, $w, $h) = $bbox;
  27934. }
  27935. }
  27936. if ($gradient['mode'] == 'measure') {
  27937. if (isset($gradient['gradientTransform']) AND !empty($gradient['gradientTransform'])) {
  27938. $gtm = $gradient['gradientTransform'];
  27939. // apply transformation matrix
  27940. $xa = ($gtm[0] * $gradient['coords'][0]) + ($gtm[2] * $gradient['coords'][1]) + $gtm[4];
  27941. $ya = ($gtm[1] * $gradient['coords'][0]) + ($gtm[3] * $gradient['coords'][1]) + $gtm[5];
  27942. $xb = ($gtm[0] * $gradient['coords'][2]) + ($gtm[2] * $gradient['coords'][3]) + $gtm[4];
  27943. $yb = ($gtm[1] * $gradient['coords'][2]) + ($gtm[3] * $gradient['coords'][3]) + $gtm[5];
  27944. if (isset($gradient['coords'][4])) {
  27945. $gradient['coords'][4] = sqrt(pow(($gtm[0] * $gradient['coords'][4]), 2) + pow(($gtm[1] * $gradient['coords'][4]), 2));
  27946. }
  27947. $gradient['coords'][0] = $xa;
  27948. $gradient['coords'][1] = $ya;
  27949. $gradient['coords'][2] = $xb;
  27950. $gradient['coords'][3] = $yb;
  27951. }
  27952. // convert SVG coordinates to user units
  27953. $gradient['coords'][0] = $this->getHTMLUnitToUnits($gradient['coords'][0], 0, $this->svgunit, false);
  27954. $gradient['coords'][1] = $this->getHTMLUnitToUnits($gradient['coords'][1], 0, $this->svgunit, false);
  27955. $gradient['coords'][2] = $this->getHTMLUnitToUnits($gradient['coords'][2], 0, $this->svgunit, false);
  27956. $gradient['coords'][3] = $this->getHTMLUnitToUnits($gradient['coords'][3], 0, $this->svgunit, false);
  27957. if (isset($gradient['coords'][4])) {
  27958. $gradient['coords'][4] = $this->getHTMLUnitToUnits($gradient['coords'][4], 0, $this->svgunit, false);
  27959. }
  27960. if ($w <= $minlen) {
  27961. $w = $minlen;
  27962. }
  27963. if ($h <= $minlen) {
  27964. $h = $minlen;
  27965. }
  27966. // shift units
  27967. if ($gradient['gradientUnits'] == 'objectBoundingBox') {
  27968. // convert to SVG coordinate system
  27969. $gradient['coords'][0] += $x;
  27970. $gradient['coords'][1] += $y;
  27971. $gradient['coords'][2] += $x;
  27972. $gradient['coords'][3] += $y;
  27973. }
  27974. // calculate percentages
  27975. $gradient['coords'][0] = (($gradient['coords'][0] - $x) / $w);
  27976. $gradient['coords'][1] = (($gradient['coords'][1] - $y) / $h);
  27977. $gradient['coords'][2] = (($gradient['coords'][2] - $x) / $w);
  27978. $gradient['coords'][3] = (($gradient['coords'][3] - $y) / $h);
  27979. if (isset($gradient['coords'][4])) {
  27980. $gradient['coords'][4] /= $w;
  27981. }
  27982. } elseif ($gradient['mode'] == 'percentage') {
  27983. foreach($gradient['coords'] as $key => $val) {
  27984. $gradient['coords'][$key] = (intval($val) / 100);
  27985. if ($val < 0) {
  27986. $gradient['coords'][$key] = 0;
  27987. } elseif ($val > 1) {
  27988. $gradient['coords'][$key] = 1;
  27989. }
  27990. }
  27991. }
  27992. if (($gradient['type'] == 2) AND ($gradient['coords'][0] == $gradient['coords'][2]) AND ($gradient['coords'][1] == $gradient['coords'][3])) {
  27993. // single color (no shading)
  27994. $gradient['coords'][0] = 1;
  27995. $gradient['coords'][1] = 0;
  27996. $gradient['coords'][2] = 0.999;
  27997. $gradient['coords'][3] = 0;
  27998. }
  27999. // swap Y coordinates
  28000. $tmp = $gradient['coords'][1];
  28001. $gradient['coords'][1] = $gradient['coords'][3];
  28002. $gradient['coords'][3] = $tmp;
  28003. // set transformation map for gradient
  28004. if ($gradient['type'] == 3) {
  28005. // circular gradient
  28006. $cy = $this->h - $y - ($gradient['coords'][1] * ($w + $h));
  28007. $this->_out(sprintf('%F 0 0 %F %F %F cm', ($w * $this->k), ($w * $this->k), ($x * $this->k), ($cy * $this->k)));
  28008. } else {
  28009. $this->_out(sprintf('%F 0 0 %F %F %F cm', ($w * $this->k), ($h * $this->k), ($x * $this->k), (($this->h - ($y + $h)) * $this->k)));
  28010. }
  28011. if (count($gradient['stops']) > 1) {
  28012. $this->Gradient($gradient['type'], $gradient['coords'], $gradient['stops'], array(), false);
  28013. }
  28014. } elseif ($svgstyle['fill'] != 'none') {
  28015. $fill_color = $this->convertHTMLColorToDec($svgstyle['fill']);
  28016. if ($svgstyle['fill-opacity'] != 1) {
  28017. $this->setAlpha($this->alpha['CA'], 'Normal', $svgstyle['fill-opacity'], false);
  28018. }
  28019. $this->SetFillColorArray($fill_color);
  28020. if ($svgstyle['fill-rule'] == 'evenodd') {
  28021. $objstyle .= 'F*';
  28022. } else {
  28023. $objstyle .= 'F';
  28024. }
  28025. }
  28026. // stroke
  28027. if ($svgstyle['stroke'] != 'none') {
  28028. if ($svgstyle['stroke-opacity'] != 1) {
  28029. $this->setAlpha($svgstyle['stroke-opacity'], 'Normal', $this->alpha['ca'], false);
  28030. }
  28031. $stroke_style = array(
  28032. 'color' => $this->convertHTMLColorToDec($svgstyle['stroke']),
  28033. 'width' => $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false),
  28034. 'cap' => $svgstyle['stroke-linecap'],
  28035. 'join' => $svgstyle['stroke-linejoin']
  28036. );
  28037. if (isset($svgstyle['stroke-dasharray']) AND !empty($svgstyle['stroke-dasharray']) AND ($svgstyle['stroke-dasharray'] != 'none')) {
  28038. $stroke_style['dash'] = $svgstyle['stroke-dasharray'];
  28039. }
  28040. $this->SetLineStyle($stroke_style);
  28041. $objstyle .= 'D';
  28042. }
  28043. // font
  28044. $regs = array();
  28045. if (!empty($svgstyle['font'])) {
  28046. if (preg_match('/font-family[\s]*:[\s]*([^\;\"]*)/si', $svgstyle['font'], $regs)) {
  28047. $font_family = $this->getFontFamilyName($regs[1]);
  28048. } else {
  28049. $font_family = $svgstyle['font-family'];
  28050. }
  28051. if (preg_match('/font-size[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  28052. $font_size = trim($regs[1]);
  28053. } else {
  28054. $font_size = $svgstyle['font-size'];
  28055. }
  28056. if (preg_match('/font-style[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  28057. $font_style = trim($regs[1]);
  28058. } else {
  28059. $font_style = $svgstyle['font-style'];
  28060. }
  28061. if (preg_match('/font-weight[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  28062. $font_weight = trim($regs[1]);
  28063. } else {
  28064. $font_weight = $svgstyle['font-weight'];
  28065. }
  28066. if (preg_match('/font-stretch[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  28067. $font_stretch = trim($regs[1]);
  28068. } else {
  28069. $font_stretch = $svgstyle['font-stretch'];
  28070. }
  28071. if (preg_match('/letter-spacing[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  28072. $font_spacing = trim($regs[1]);
  28073. } else {
  28074. $font_spacing = $svgstyle['letter-spacing'];
  28075. }
  28076. } else {
  28077. $font_family = $this->getFontFamilyName($svgstyle['font-family']);
  28078. $font_size = $svgstyle['font-size'];
  28079. $font_style = $svgstyle['font-style'];
  28080. $font_weight = $svgstyle['font-weight'];
  28081. $font_stretch = $svgstyle['font-stretch'];
  28082. $font_spacing = $svgstyle['letter-spacing'];
  28083. }
  28084. $font_size = $this->getHTMLUnitToUnits($font_size, $prevsvgstyle['font-size'], $this->svgunit, false) * $this->k;
  28085. $font_stretch = $this->getCSSFontStretching($font_stretch, $svgstyle['font-stretch']);
  28086. $font_spacing = $this->getCSSFontSpacing($font_spacing, $svgstyle['letter-spacing']);
  28087. switch ($font_style) {
  28088. case 'italic': {
  28089. $font_style = 'I';
  28090. break;
  28091. }
  28092. case 'oblique': {
  28093. $font_style = 'I';
  28094. break;
  28095. }
  28096. default:
  28097. case 'normal': {
  28098. $font_style = '';
  28099. break;
  28100. }
  28101. }
  28102. switch ($font_weight) {
  28103. case 'bold':
  28104. case 'bolder': {
  28105. $font_style .= 'B';
  28106. break;
  28107. }
  28108. }
  28109. switch ($svgstyle['text-decoration']) {
  28110. case 'underline': {
  28111. $font_style .= 'U';
  28112. break;
  28113. }
  28114. case 'overline': {
  28115. $font_style .= 'O';
  28116. break;
  28117. }
  28118. case 'line-through': {
  28119. $font_style .= 'D';
  28120. break;
  28121. }
  28122. default:
  28123. case 'none': {
  28124. break;
  28125. }
  28126. }
  28127. $this->SetFont($font_family, $font_style, $font_size);
  28128. $this->setFontStretching($font_stretch);
  28129. $this->setFontSpacing($font_spacing);
  28130. return $objstyle;
  28131. }
  28132. /**
  28133. * Draws an SVG path
  28134. * @param $d (string) attribute d of the path SVG element
  28135. * @param $style (string) Style of rendering. Possible values are:
  28136. * <ul>
  28137. * <li>D or empty string: Draw (default).</li>
  28138. * <li>F: Fill.</li>
  28139. * <li>F*: Fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  28140. * <li>DF or FD: Draw and fill.</li>
  28141. * <li>DF* or FD*: Draw and fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  28142. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  28143. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  28144. * </ul>
  28145. * @return array of container box measures (x, y, w, h)
  28146. * @author Nicola Asuni
  28147. * @since 5.0.000 (2010-05-02)
  28148. * @protected
  28149. */
  28150. protected function SVGPath($d, $style='') {
  28151. if ($this->state != 2) {
  28152. return;
  28153. }
  28154. // set fill/stroke style
  28155. $op = $this->getPathPaintOperator($style, '');
  28156. if (empty($op)) {
  28157. return;
  28158. }
  28159. $paths = array();
  28160. $d = preg_replace('/([0-9ACHLMQSTVZ])([\-\+])/si', '\\1 \\2', $d);
  28161. preg_match_all('/([ACHLMQSTVZ])[\s]*([^ACHLMQSTVZ\"]*)/si', $d, $paths, PREG_SET_ORDER);
  28162. $x = 0;
  28163. $y = 0;
  28164. $x1 = 0;
  28165. $y1 = 0;
  28166. $x2 = 0;
  28167. $y2 = 0;
  28168. $xmin = 2147483647;
  28169. $xmax = 0;
  28170. $ymin = 2147483647;
  28171. $ymax = 0;
  28172. $relcoord = false;
  28173. $minlen = (0.01 / $this->k); // minimum acceptable length (3 point)
  28174. $firstcmd = true; // used to print first point
  28175. // draw curve pieces
  28176. foreach ($paths as $key => $val) {
  28177. // get curve type
  28178. $cmd = trim($val[1]);
  28179. if (strtolower($cmd) == $cmd) {
  28180. // use relative coordinated instead of absolute
  28181. $relcoord = true;
  28182. $xoffset = $x;
  28183. $yoffset = $y;
  28184. } else {
  28185. $relcoord = false;
  28186. $xoffset = 0;
  28187. $yoffset = 0;
  28188. }
  28189. $params = array();
  28190. if (isset($val[2])) {
  28191. // get curve parameters
  28192. $rawparams = preg_split('/([\,\s]+)/si', trim($val[2]));
  28193. $params = array();
  28194. foreach ($rawparams as $ck => $cp) {
  28195. $params[$ck] = $this->getHTMLUnitToUnits($cp, 0, $this->svgunit, false);
  28196. if (abs($params[$ck]) < $minlen) {
  28197. // aproximate little values to zero
  28198. $params[$ck] = 0;
  28199. }
  28200. }
  28201. }
  28202. // store current origin point
  28203. $x0 = $x;
  28204. $y0 = $y;
  28205. switch (strtoupper($cmd)) {
  28206. case 'M': { // moveto
  28207. foreach ($params as $ck => $cp) {
  28208. if (($ck % 2) == 0) {
  28209. $x = $cp + $xoffset;
  28210. } else {
  28211. $y = $cp + $yoffset;
  28212. if ($firstcmd OR (abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  28213. if ($ck == 1) {
  28214. $this->_outPoint($x, $y);
  28215. $firstcmd = false;
  28216. } else {
  28217. $this->_outLine($x, $y);
  28218. }
  28219. $x0 = $x;
  28220. $y0 = $y;
  28221. }
  28222. $xmin = min($xmin, $x);
  28223. $ymin = min($ymin, $y);
  28224. $xmax = max($xmax, $x);
  28225. $ymax = max($ymax, $y);
  28226. if ($relcoord) {
  28227. $xoffset = $x;
  28228. $yoffset = $y;
  28229. }
  28230. }
  28231. }
  28232. break;
  28233. }
  28234. case 'L': { // lineto
  28235. foreach ($params as $ck => $cp) {
  28236. if (($ck % 2) == 0) {
  28237. $x = $cp + $xoffset;
  28238. } else {
  28239. $y = $cp + $yoffset;
  28240. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  28241. $this->_outLine($x, $y);
  28242. $x0 = $x;
  28243. $y0 = $y;
  28244. }
  28245. $xmin = min($xmin, $x);
  28246. $ymin = min($ymin, $y);
  28247. $xmax = max($xmax, $x);
  28248. $ymax = max($ymax, $y);
  28249. if ($relcoord) {
  28250. $xoffset = $x;
  28251. $yoffset = $y;
  28252. }
  28253. }
  28254. }
  28255. break;
  28256. }
  28257. case 'H': { // horizontal lineto
  28258. foreach ($params as $ck => $cp) {
  28259. $x = $cp + $xoffset;
  28260. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  28261. $this->_outLine($x, $y);
  28262. $x0 = $x;
  28263. $y0 = $y;
  28264. }
  28265. $xmin = min($xmin, $x);
  28266. $xmax = max($xmax, $x);
  28267. if ($relcoord) {
  28268. $xoffset = $x;
  28269. }
  28270. }
  28271. break;
  28272. }
  28273. case 'V': { // vertical lineto
  28274. foreach ($params as $ck => $cp) {
  28275. $y = $cp + $yoffset;
  28276. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  28277. $this->_outLine($x, $y);
  28278. $x0 = $x;
  28279. $y0 = $y;
  28280. }
  28281. $ymin = min($ymin, $y);
  28282. $ymax = max($ymax, $y);
  28283. if ($relcoord) {
  28284. $yoffset = $y;
  28285. }
  28286. }
  28287. break;
  28288. }
  28289. case 'C': { // curveto
  28290. foreach ($params as $ck => $cp) {
  28291. $params[$ck] = $cp;
  28292. if ((($ck + 1) % 6) == 0) {
  28293. $x1 = $params[($ck - 5)] + $xoffset;
  28294. $y1 = $params[($ck - 4)] + $yoffset;
  28295. $x2 = $params[($ck - 3)] + $xoffset;
  28296. $y2 = $params[($ck - 2)] + $yoffset;
  28297. $x = $params[($ck - 1)] + $xoffset;
  28298. $y = $params[($ck)] + $yoffset;
  28299. $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
  28300. $xmin = min($xmin, $x, $x1, $x2);
  28301. $ymin = min($ymin, $y, $y1, $y2);
  28302. $xmax = max($xmax, $x, $x1, $x2);
  28303. $ymax = max($ymax, $y, $y1, $y2);
  28304. if ($relcoord) {
  28305. $xoffset = $x;
  28306. $yoffset = $y;
  28307. }
  28308. }
  28309. }
  28310. break;
  28311. }
  28312. case 'S': { // shorthand/smooth curveto
  28313. foreach ($params as $ck => $cp) {
  28314. $params[$ck] = $cp;
  28315. if ((($ck + 1) % 4) == 0) {
  28316. if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'C') OR (strtoupper($paths[($key - 1)][1]) == 'S'))) {
  28317. $x1 = (2 * $x) - $x2;
  28318. $y1 = (2 * $y) - $y2;
  28319. } else {
  28320. $x1 = $x;
  28321. $y1 = $y;
  28322. }
  28323. $x2 = $params[($ck - 3)] + $xoffset;
  28324. $y2 = $params[($ck - 2)] + $yoffset;
  28325. $x = $params[($ck - 1)] + $xoffset;
  28326. $y = $params[($ck)] + $yoffset;
  28327. $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
  28328. $xmin = min($xmin, $x, $x1, $x2);
  28329. $ymin = min($ymin, $y, $y1, $y2);
  28330. $xmax = max($xmax, $x, $x1, $x2);
  28331. $ymax = max($ymax, $y, $y1, $y2);
  28332. if ($relcoord) {
  28333. $xoffset = $x;
  28334. $yoffset = $y;
  28335. }
  28336. }
  28337. }
  28338. break;
  28339. }
  28340. case 'Q': { // quadratic Bézier curveto
  28341. foreach ($params as $ck => $cp) {
  28342. $params[$ck] = $cp;
  28343. if ((($ck + 1) % 4) == 0) {
  28344. // convert quadratic points to cubic points
  28345. $x1 = $params[($ck - 3)] + $xoffset;
  28346. $y1 = $params[($ck - 2)] + $yoffset;
  28347. $xa = ($x + (2 * $x1)) / 3;
  28348. $ya = ($y + (2 * $y1)) / 3;
  28349. $x = $params[($ck - 1)] + $xoffset;
  28350. $y = $params[($ck)] + $yoffset;
  28351. $xb = ($x + (2 * $x1)) / 3;
  28352. $yb = ($y + (2 * $y1)) / 3;
  28353. $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
  28354. $xmin = min($xmin, $x, $xa, $xb);
  28355. $ymin = min($ymin, $y, $ya, $yb);
  28356. $xmax = max($xmax, $x, $xa, $xb);
  28357. $ymax = max($ymax, $y, $ya, $yb);
  28358. if ($relcoord) {
  28359. $xoffset = $x;
  28360. $yoffset = $y;
  28361. }
  28362. }
  28363. }
  28364. break;
  28365. }
  28366. case 'T': { // shorthand/smooth quadratic Bézier curveto
  28367. foreach ($params as $ck => $cp) {
  28368. $params[$ck] = $cp;
  28369. if (($ck % 2) != 0) {
  28370. if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'Q') OR (strtoupper($paths[($key - 1)][1]) == 'T'))) {
  28371. $x1 = (2 * $x) - $x1;
  28372. $y1 = (2 * $y) - $y1;
  28373. } else {
  28374. $x1 = $x;
  28375. $y1 = $y;
  28376. }
  28377. // convert quadratic points to cubic points
  28378. $xa = ($x + (2 * $x1)) / 3;
  28379. $ya = ($y + (2 * $y1)) / 3;
  28380. $x = $params[($ck - 1)] + $xoffset;
  28381. $y = $params[($ck)] + $yoffset;
  28382. $xb = ($x + (2 * $x1)) / 3;
  28383. $yb = ($y + (2 * $y1)) / 3;
  28384. $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
  28385. $xmin = min($xmin, $x, $xa, $xb);
  28386. $ymin = min($ymin, $y, $ya, $yb);
  28387. $xmax = max($xmax, $x, $xa, $xb);
  28388. $ymax = max($ymax, $y, $ya, $yb);
  28389. if ($relcoord) {
  28390. $xoffset = $x;
  28391. $yoffset = $y;
  28392. }
  28393. }
  28394. }
  28395. break;
  28396. }
  28397. case 'A': { // elliptical arc
  28398. foreach ($params as $ck => $cp) {
  28399. $params[$ck] = $cp;
  28400. if ((($ck + 1) % 7) == 0) {
  28401. $x0 = $x;
  28402. $y0 = $y;
  28403. $rx = abs($params[($ck - 6)]);
  28404. $ry = abs($params[($ck - 5)]);
  28405. $ang = -$rawparams[($ck - 4)];
  28406. $angle = deg2rad($ang);
  28407. $fa = $rawparams[($ck - 3)]; // large-arc-flag
  28408. $fs = $rawparams[($ck - 2)]; // sweep-flag
  28409. $x = $params[($ck - 1)] + $xoffset;
  28410. $y = $params[$ck] + $yoffset;
  28411. if ((abs($x0 - $x) < $minlen) AND (abs($y0 - $y) < $minlen)) {
  28412. // endpoints are almost identical
  28413. $xmin = min($xmin, $x);
  28414. $ymin = min($ymin, $y);
  28415. $xmax = max($xmax, $x);
  28416. $ymax = max($ymax, $y);
  28417. } else {
  28418. $cos_ang = cos($angle);
  28419. $sin_ang = sin($angle);
  28420. $a = (($x0 - $x) / 2);
  28421. $b = (($y0 - $y) / 2);
  28422. $xa = ($a * $cos_ang) - ($b * $sin_ang);
  28423. $ya = ($a * $sin_ang) + ($b * $cos_ang);
  28424. $rx2 = $rx * $rx;
  28425. $ry2 = $ry * $ry;
  28426. $xa2 = $xa * $xa;
  28427. $ya2 = $ya * $ya;
  28428. $delta = ($xa2 / $rx2) + ($ya2 / $ry2);
  28429. if ($delta > 1) {
  28430. $rx *= sqrt($delta);
  28431. $ry *= sqrt($delta);
  28432. $rx2 = $rx * $rx;
  28433. $ry2 = $ry * $ry;
  28434. }
  28435. $numerator = (($rx2 * $ry2) - ($rx2 * $ya2) - ($ry2 * $xa2));
  28436. if ($numerator < 0) {
  28437. $root = 0;
  28438. } else {
  28439. $root = sqrt($numerator / (($rx2 * $ya2) + ($ry2 * $xa2)));
  28440. }
  28441. if ($fa == $fs){
  28442. $root *= -1;
  28443. }
  28444. $cax = $root * (($rx * $ya) / $ry);
  28445. $cay = -$root * (($ry * $xa) / $rx);
  28446. // coordinates of ellipse center
  28447. $cx = ($cax * $cos_ang) - ($cay * $sin_ang) + (($x0 + $x) / 2);
  28448. $cy = ($cax * $sin_ang) + ($cay * $cos_ang) + (($y0 + $y) / 2);
  28449. // get angles
  28450. $angs = $this->getVectorsAngle(1, 0, (($xa - $cax) / $rx), (($cay - $ya) / $ry));
  28451. $dang = $this->getVectorsAngle((($xa - $cax) / $rx), (($ya - $cay) / $ry), ((-$xa - $cax) / $rx), ((-$ya - $cay) / $ry));
  28452. if (($fs == 0) AND ($dang > 0)) {
  28453. $dang -= (2 * M_PI);
  28454. } elseif (($fs == 1) AND ($dang < 0)) {
  28455. $dang += (2 * M_PI);
  28456. }
  28457. $angf = $angs - $dang;
  28458. if ((($fs == 0) AND ($angs > $angf)) OR (($fs == 1) AND ($angs < $angf))) {
  28459. // reverse angles
  28460. $tmp = $angs;
  28461. $angs = $angf;
  28462. $angf = $tmp;
  28463. }
  28464. $angs = round(rad2deg($angs), 6);
  28465. $angf = round(rad2deg($angf), 6);
  28466. // covent angles to positive values
  28467. if (($angs < 0) AND ($angf < 0)) {
  28468. $angs += 360;
  28469. $angf += 360;
  28470. }
  28471. $pie = false;
  28472. if (($key == 0) AND (isset($paths[($key + 1)][1])) AND (trim($paths[($key + 1)][1]) == 'z')) {
  28473. $pie = true;
  28474. }
  28475. list($axmin, $aymin, $axmax, $aymax) = $this->_outellipticalarc($cx, $cy, $rx, $ry, $ang, $angs, $angf, $pie, 2, false, ($fs == 0), true);
  28476. $xmin = min($xmin, $x, $axmin);
  28477. $ymin = min($ymin, $y, $aymin);
  28478. $xmax = max($xmax, $x, $axmax);
  28479. $ymax = max($ymax, $y, $aymax);
  28480. }
  28481. if ($relcoord) {
  28482. $xoffset = $x;
  28483. $yoffset = $y;
  28484. }
  28485. }
  28486. }
  28487. break;
  28488. }
  28489. case 'Z': {
  28490. $this->_out('h');
  28491. break;
  28492. }
  28493. }
  28494. $firstcmd = false;
  28495. } // end foreach
  28496. if (!empty($op)) {
  28497. $this->_out($op);
  28498. }
  28499. return array($xmin, $ymin, ($xmax - $xmin), ($ymax - $ymin));
  28500. }
  28501. /**
  28502. * Returns the angle in radiants between two vectors
  28503. * @param $x1 (int) X coordinate of first vector point
  28504. * @param $y1 (int) Y coordinate of first vector point
  28505. * @param $x2 (int) X coordinate of second vector point
  28506. * @param $y2 (int) Y coordinate of second vector point
  28507. * @author Nicola Asuni
  28508. * @since 5.0.000 (2010-05-04)
  28509. * @protected
  28510. */
  28511. protected function getVectorsAngle($x1, $y1, $x2, $y2) {
  28512. $dprod = ($x1 * $x2) + ($y1 * $y2);
  28513. $dist1 = sqrt(($x1 * $x1) + ($y1 * $y1));
  28514. $dist2 = sqrt(($x2 * $x2) + ($y2 * $y2));
  28515. $angle = acos($dprod / ($dist1 * $dist2));
  28516. if (is_nan($angle)) {
  28517. $angle = M_PI;
  28518. }
  28519. if ((($x1 * $y2) - ($x2 * $y1)) < 0) {
  28520. $angle *= -1;
  28521. }
  28522. return $angle;
  28523. }
  28524. /**
  28525. * Sets the opening SVG element handler function for the XML parser. (*** TO BE COMPLETED ***)
  28526. * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
  28527. * @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.
  28528. * @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.
  28529. * @param $ctm (array) tranformation matrix for clipping mode (starting transformation matrix).
  28530. * @author Nicola Asuni
  28531. * @since 5.0.000 (2010-05-02)
  28532. * @protected
  28533. */
  28534. protected function startSVGElementHandler($parser, $name, $attribs, $ctm=array()) {
  28535. // check if we are in clip mode
  28536. if ($this->svgclipmode) {
  28537. $this->svgclippaths[$this->svgclipid][] = array('name' => $name, 'attribs' => $attribs, 'tm' => $this->svgcliptm[$this->svgclipid]);
  28538. return;
  28539. }
  28540. if ($this->svgdefsmode AND !in_array($name, array('clipPath', 'linearGradient', 'radialGradient', 'stop'))) {
  28541. if (!isset($attribs['id'])) {
  28542. $attribs['id'] = 'DF_'.(count($this->svgdefs) + 1);
  28543. }
  28544. $this->svgdefs[$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
  28545. return;
  28546. }
  28547. $clipping = false;
  28548. if ($parser == 'clip-path') {
  28549. // set clipping mode
  28550. $clipping = true;
  28551. }
  28552. // get styling properties
  28553. $prev_svgstyle = $this->svgstyles[(count($this->svgstyles) - 1)]; // previous style
  28554. $svgstyle = $this->svgstyles[0]; // set default style
  28555. if ($clipping AND !isset($attribs['fill']) AND (!isset($attribs['style']) OR (!preg_match('/[;\"\s]{1}fill[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval)))) {
  28556. // default fill attribute for clipping
  28557. $attribs['fill'] = 'none';
  28558. }
  28559. if (isset($attribs['style']) AND !$this->empty_string($attribs['style'])) {
  28560. // fix style for regular expression
  28561. $attribs['style'] = ';'.$attribs['style'];
  28562. }
  28563. foreach ($prev_svgstyle as $key => $val) {
  28564. if (in_array($key, $this->svginheritprop)) {
  28565. // inherit previous value
  28566. $svgstyle[$key] = $val;
  28567. }
  28568. if (isset($attribs[$key]) AND !$this->empty_string($attribs[$key])) {
  28569. // specific attribute settings
  28570. if ($attribs[$key] == 'inherit') {
  28571. $svgstyle[$key] = $val;
  28572. } else {
  28573. $svgstyle[$key] = $attribs[$key];
  28574. }
  28575. } elseif (isset($attribs['style']) AND !$this->empty_string($attribs['style'])) {
  28576. // CSS style syntax
  28577. $attrval = array();
  28578. if (preg_match('/[;\"\s]{1}'.$key.'[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval) AND isset($attrval[1])) {
  28579. if ($attrval[1] == 'inherit') {
  28580. $svgstyle[$key] = $val;
  28581. } else {
  28582. $svgstyle[$key] = $attrval[1];
  28583. }
  28584. }
  28585. }
  28586. }
  28587. // transformation matrix
  28588. if (!empty($ctm)) {
  28589. $tm = $ctm;
  28590. } else {
  28591. //$tm = $this->svgstyles[(count($this->svgstyles) - 1)]['transfmatrix'];
  28592. $tm = array(1,0,0,1,0,0);
  28593. }
  28594. if (isset($attribs['transform']) AND !empty($attribs['transform'])) {
  28595. $tm = $this->getTransformationMatrixProduct($tm, $this->getSVGTransformMatrix($attribs['transform']));
  28596. }
  28597. $svgstyle['transfmatrix'] = $tm;
  28598. $invisible = false;
  28599. if (($svgstyle['visibility'] == 'hidden') OR ($svgstyle['visibility'] == 'collapse') OR ($svgstyle['display'] == 'none')) {
  28600. // the current graphics element is invisible (nothing is painted)
  28601. $invisible = true;
  28602. }
  28603. // process tag
  28604. switch($name) {
  28605. case 'defs': {
  28606. $this->svgdefsmode = true;
  28607. break;
  28608. }
  28609. // clipPath
  28610. case 'clipPath': {
  28611. if ($invisible) {
  28612. break;
  28613. }
  28614. $this->svgclipmode = true;
  28615. if (!isset($attribs['id'])) {
  28616. $attribs['id'] = 'CP_'.(count($this->svgcliptm) + 1);
  28617. }
  28618. $this->svgclipid = $attribs['id'];
  28619. $this->svgclippaths[$this->svgclipid] = array();
  28620. $this->svgcliptm[$this->svgclipid] = $tm;
  28621. break;
  28622. }
  28623. case 'svg': {
  28624. // start of SVG object
  28625. break;
  28626. }
  28627. case 'g': {
  28628. // group together related graphics elements
  28629. array_push($this->svgstyles, $svgstyle);
  28630. $this->StartTransform();
  28631. $this->SVGTransform($tm);
  28632. $this->setSVGStyles($svgstyle, $prev_svgstyle);
  28633. break;
  28634. }
  28635. case 'linearGradient': {
  28636. if ($this->pdfa_mode) {
  28637. break;
  28638. }
  28639. if (!isset($attribs['id'])) {
  28640. $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
  28641. }
  28642. $this->svggradientid = $attribs['id'];
  28643. $this->svggradients[$this->svggradientid] = array();
  28644. $this->svggradients[$this->svggradientid]['type'] = 2;
  28645. $this->svggradients[$this->svggradientid]['stops'] = array();
  28646. if (isset($attribs['gradientUnits'])) {
  28647. $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  28648. } else {
  28649. $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  28650. }
  28651. //$attribs['spreadMethod']
  28652. if (((!isset($attribs['x1'])) AND (!isset($attribs['y1'])) AND (!isset($attribs['x2'])) AND (!isset($attribs['y2'])))
  28653. OR ((isset($attribs['x1']) AND (substr($attribs['x1'], -1) == '%'))
  28654. OR (isset($attribs['y1']) AND (substr($attribs['y1'], -1) == '%'))
  28655. OR (isset($attribs['x2']) AND (substr($attribs['x2'], -1) == '%'))
  28656. OR (isset($attribs['y2']) AND (substr($attribs['y2'], -1) == '%')))) {
  28657. $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  28658. } else {
  28659. $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  28660. }
  28661. $x1 = (isset($attribs['x1'])?$attribs['x1']:'0');
  28662. $y1 = (isset($attribs['y1'])?$attribs['y1']:'0');
  28663. $x2 = (isset($attribs['x2'])?$attribs['x2']:'100');
  28664. $y2 = (isset($attribs['y2'])?$attribs['y2']:'0');
  28665. if (isset($attribs['gradientTransform'])) {
  28666. $this->svggradients[$this->svggradientid]['gradientTransform'] = $this->getSVGTransformMatrix($attribs['gradientTransform']);
  28667. }
  28668. $this->svggradients[$this->svggradientid]['coords'] = array($x1, $y1, $x2, $y2);
  28669. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  28670. // gradient is defined on another place
  28671. $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  28672. }
  28673. break;
  28674. }
  28675. case 'radialGradient': {
  28676. if ($this->pdfa_mode) {
  28677. break;
  28678. }
  28679. if (!isset($attribs['id'])) {
  28680. $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
  28681. }
  28682. $this->svggradientid = $attribs['id'];
  28683. $this->svggradients[$this->svggradientid] = array();
  28684. $this->svggradients[$this->svggradientid]['type'] = 3;
  28685. $this->svggradients[$this->svggradientid]['stops'] = array();
  28686. if (isset($attribs['gradientUnits'])) {
  28687. $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  28688. } else {
  28689. $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  28690. }
  28691. //$attribs['spreadMethod']
  28692. if (((!isset($attribs['cx'])) AND (!isset($attribs['cy'])))
  28693. OR ((isset($attribs['cx']) AND (substr($attribs['cx'], -1) == '%'))
  28694. OR (isset($attribs['cy']) AND (substr($attribs['cy'], -1) == '%')) )) {
  28695. $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  28696. } else {
  28697. $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  28698. }
  28699. $cx = (isset($attribs['cx']) ? $attribs['cx'] : 0.5);
  28700. $cy = (isset($attribs['cy']) ? $attribs['cy'] : 0.5);
  28701. $fx = (isset($attribs['fx']) ? $attribs['fx'] : $cx);
  28702. $fy = (isset($attribs['fy']) ? $attribs['fy'] : $cy);
  28703. $r = (isset($attribs['r']) ? $attribs['r'] : 0.5);
  28704. if (isset($attribs['gradientTransform'])) {
  28705. $this->svggradients[$this->svggradientid]['gradientTransform'] = $this->getSVGTransformMatrix($attribs['gradientTransform']);
  28706. }
  28707. $this->svggradients[$this->svggradientid]['coords'] = array($cx, $cy, $fx, $fy, $r);
  28708. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  28709. // gradient is defined on another place
  28710. $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  28711. }
  28712. break;
  28713. }
  28714. case 'stop': {
  28715. // gradient stops
  28716. if (substr($attribs['offset'], -1) == '%') {
  28717. $offset = floatval(substr($attribs['offset'], -1)) / 100;
  28718. } else {
  28719. $offset = floatval($attribs['offset']);
  28720. if ($offset > 1) {
  28721. $offset /= 100;
  28722. }
  28723. }
  28724. $stop_color = isset($svgstyle['stop-color'])?$this->convertHTMLColorToDec($svgstyle['stop-color']):'black';
  28725. $opacity = isset($svgstyle['stop-opacity'])?$svgstyle['stop-opacity']:1;
  28726. $this->svggradients[$this->svggradientid]['stops'][] = array('offset' => $offset, 'color' => $stop_color, 'opacity' => $opacity);
  28727. break;
  28728. }
  28729. // paths
  28730. case 'path': {
  28731. if ($invisible) {
  28732. break;
  28733. }
  28734. if (isset($attribs['d'])) {
  28735. $d = trim($attribs['d']);
  28736. if (!empty($d)) {
  28737. if ($clipping) {
  28738. $this->SVGTransform($tm);
  28739. $this->SVGPath($d, 'CNZ');
  28740. } else {
  28741. $this->StartTransform();
  28742. $this->SVGTransform($tm);
  28743. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, 0, 0, 1, 1, 'SVGPath', array($d, 'CNZ'));
  28744. if (!empty($obstyle)) {
  28745. $this->SVGPath($d, $obstyle);
  28746. }
  28747. $this->StopTransform();
  28748. }
  28749. }
  28750. }
  28751. break;
  28752. }
  28753. // shapes
  28754. case 'rect': {
  28755. if ($invisible) {
  28756. break;
  28757. }
  28758. $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
  28759. $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
  28760. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
  28761. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
  28762. $rx = (isset($attribs['rx'])?$this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false):0);
  28763. $ry = (isset($attribs['ry'])?$this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false):$rx);
  28764. if ($clipping) {
  28765. $this->SVGTransform($tm);
  28766. $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ', array(), array());
  28767. } else {
  28768. $this->StartTransform();
  28769. $this->SVGTransform($tm);
  28770. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'RoundedRectXY', array($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ'));
  28771. if (!empty($obstyle)) {
  28772. $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', $obstyle, array(), array());
  28773. }
  28774. $this->StopTransform();
  28775. }
  28776. break;
  28777. }
  28778. case 'circle': {
  28779. if ($invisible) {
  28780. break;
  28781. }
  28782. $r = (isset($attribs['r']) ? $this->getHTMLUnitToUnits($attribs['r'], 0, $this->svgunit, false) : 0);
  28783. $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false) : (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : 0));
  28784. $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false) : (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : 0));
  28785. $x = ($cx - $r);
  28786. $y = ($cy - $r);
  28787. $w = (2 * $r);
  28788. $h = $w;
  28789. if ($clipping) {
  28790. $this->SVGTransform($tm);
  28791. $this->Circle($cx, $cy, $r, 0, 360, 'CNZ', array(), array(), 8);
  28792. } else {
  28793. $this->StartTransform();
  28794. $this->SVGTransform($tm);
  28795. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Circle', array($cx, $cy, $r, 0, 360, 'CNZ'));
  28796. if (!empty($obstyle)) {
  28797. $this->Circle($cx, $cy, $r, 0, 360, $obstyle, array(), array(), 8);
  28798. }
  28799. $this->StopTransform();
  28800. }
  28801. break;
  28802. }
  28803. case 'ellipse': {
  28804. if ($invisible) {
  28805. break;
  28806. }
  28807. $rx = (isset($attribs['rx']) ? $this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false) : 0);
  28808. $ry = (isset($attribs['ry']) ? $this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false) : 0);
  28809. $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false) : (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : 0));
  28810. $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false) : (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : 0));
  28811. $x = ($cx - $rx);
  28812. $y = ($cy - $ry);
  28813. $w = (2 * $rx);
  28814. $h = (2 * $ry);
  28815. if ($clipping) {
  28816. $this->SVGTransform($tm);
  28817. $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ', array(), array(), 8);
  28818. } else {
  28819. $this->StartTransform();
  28820. $this->SVGTransform($tm);
  28821. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Ellipse', array($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ'));
  28822. if (!empty($obstyle)) {
  28823. $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, $obstyle, array(), array(), 8);
  28824. }
  28825. $this->StopTransform();
  28826. }
  28827. break;
  28828. }
  28829. case 'line': {
  28830. if ($invisible) {
  28831. break;
  28832. }
  28833. $x1 = (isset($attribs['x1'])?$this->getHTMLUnitToUnits($attribs['x1'], 0, $this->svgunit, false):0);
  28834. $y1 = (isset($attribs['y1'])?$this->getHTMLUnitToUnits($attribs['y1'], 0, $this->svgunit, false):0);
  28835. $x2 = (isset($attribs['x2'])?$this->getHTMLUnitToUnits($attribs['x2'], 0, $this->svgunit, false):0);
  28836. $y2 = (isset($attribs['y2'])?$this->getHTMLUnitToUnits($attribs['y2'], 0, $this->svgunit, false):0);
  28837. $x = $x1;
  28838. $y = $y1;
  28839. $w = abs($x2 - $x1);
  28840. $h = abs($y2 - $y1);
  28841. if (!$clipping) {
  28842. $this->StartTransform();
  28843. $this->SVGTransform($tm);
  28844. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Line', array($x1, $y1, $x2, $y2));
  28845. $this->Line($x1, $y1, $x2, $y2);
  28846. $this->StopTransform();
  28847. }
  28848. break;
  28849. }
  28850. case 'polyline':
  28851. case 'polygon': {
  28852. if ($invisible) {
  28853. break;
  28854. }
  28855. $points = (isset($attribs['points'])?$attribs['points']:'0 0');
  28856. $points = trim($points);
  28857. // note that point may use a complex syntax not covered here
  28858. $points = preg_split('/[\,\s]+/si', $points);
  28859. if (count($points) < 4) {
  28860. break;
  28861. }
  28862. $p = array();
  28863. $xmin = 2147483647;
  28864. $xmax = 0;
  28865. $ymin = 2147483647;
  28866. $ymax = 0;
  28867. foreach ($points as $key => $val) {
  28868. $p[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
  28869. if (($key % 2) == 0) {
  28870. // X coordinate
  28871. $xmin = min($xmin, $p[$key]);
  28872. $xmax = max($xmax, $p[$key]);
  28873. } else {
  28874. // Y coordinate
  28875. $ymin = min($ymin, $p[$key]);
  28876. $ymax = max($ymax, $p[$key]);
  28877. }
  28878. }
  28879. $x = $xmin;
  28880. $y = $ymin;
  28881. $w = ($xmax - $xmin);
  28882. $h = ($ymax - $ymin);
  28883. if ($name == 'polyline') {
  28884. $this->StartTransform();
  28885. $this->SVGTransform($tm);
  28886. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'PolyLine', array($p, 'CNZ'));
  28887. if (!empty($obstyle)) {
  28888. $this->PolyLine($p, $obstyle, array(), array());
  28889. }
  28890. $this->StopTransform();
  28891. } else { // polygon
  28892. if ($clipping) {
  28893. $this->SVGTransform($tm);
  28894. $this->Polygon($p, 'CNZ', array(), array(), true);
  28895. } else {
  28896. $this->StartTransform();
  28897. $this->SVGTransform($tm);
  28898. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Polygon', array($p, 'CNZ'));
  28899. if (!empty($obstyle)) {
  28900. $this->Polygon($p, $obstyle, array(), array(), true);
  28901. }
  28902. $this->StopTransform();
  28903. }
  28904. }
  28905. break;
  28906. }
  28907. // image
  28908. case 'image': {
  28909. if ($invisible) {
  28910. break;
  28911. }
  28912. if (!isset($attribs['xlink:href']) OR empty($attribs['xlink:href'])) {
  28913. break;
  28914. }
  28915. $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
  28916. $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
  28917. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
  28918. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
  28919. $img = $attribs['xlink:href'];
  28920. if (!$clipping) {
  28921. $this->StartTransform();
  28922. $this->SVGTransform($tm);
  28923. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h);
  28924. if (preg_match('/^data:image\/[^;]+;base64,/', $img, $m) > 0) {
  28925. // embedded image encoded as base64
  28926. $img = '@'.base64_decode(substr($img, strlen($m[0])));
  28927. } else {
  28928. // fix image path
  28929. if (!$this->empty_string($this->svgdir) AND (($img{0} == '.') OR (basename($img) == $img))) {
  28930. // replace relative path with full server path
  28931. $img = $this->svgdir.'/'.$img;
  28932. }
  28933. if (($img[0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
  28934. $findroot = strpos($img, $_SERVER['DOCUMENT_ROOT']);
  28935. if (($findroot === false) OR ($findroot > 1)) {
  28936. if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
  28937. $img = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$img;
  28938. } else {
  28939. $img = $_SERVER['DOCUMENT_ROOT'].$img;
  28940. }
  28941. }
  28942. }
  28943. $img = urldecode($img);
  28944. $testscrtype = @parse_url($img);
  28945. if (!isset($testscrtype['query']) OR empty($testscrtype['query'])) {
  28946. // convert URL to server path
  28947. $img = str_replace(K_PATH_URL, K_PATH_MAIN, $img);
  28948. }
  28949. }
  28950. // get image type
  28951. $imgtype = $this->getImageFileType($img);
  28952. if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  28953. $this->ImageEps($img, $x, $y, $w, $h);
  28954. } elseif ($imgtype == 'svg') {
  28955. $this->ImageSVG($img, $x, $y, $w, $h);
  28956. } else {
  28957. $this->Image($img, $x, $y, $w, $h);
  28958. }
  28959. $this->StopTransform();
  28960. }
  28961. break;
  28962. }
  28963. // text
  28964. case 'text':
  28965. case 'tspan': {
  28966. // only basic support - advanced features must be implemented
  28967. $this->svgtextmode['invisible'] = $invisible;
  28968. if ($invisible) {
  28969. break;
  28970. }
  28971. array_push($this->svgstyles, $svgstyle);
  28972. if (isset($attribs['x'])) {
  28973. $x = $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false);
  28974. } elseif ($name == 'tspan') {
  28975. $x = $this->x;
  28976. } else {
  28977. $x = 0;
  28978. }
  28979. if (isset($attribs['y'])) {
  28980. $y = $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false);
  28981. } elseif ($name == 'tspan') {
  28982. $y = $this->y;
  28983. } else {
  28984. $y = 0;
  28985. }
  28986. $svgstyle['text-color'] = $svgstyle['fill'];
  28987. $this->svgtext = '';
  28988. if (isset($svgstyle['text-anchor'])) {
  28989. $this->svgtextmode['text-anchor'] = $svgstyle['text-anchor'];
  28990. } else {
  28991. $this->svgtextmode['text-anchor'] = 'start';
  28992. }
  28993. if (isset($svgstyle['direction'])) {
  28994. if ($svgstyle['direction'] == 'rtl') {
  28995. $this->svgtextmode['rtl'] = true;
  28996. } else {
  28997. $this->svgtextmode['rtl'] = false;
  28998. }
  28999. } else {
  29000. $this->svgtextmode['rtl'] = false;
  29001. }
  29002. if (isset($svgstyle['stroke']) AND ($svgstyle['stroke'] != 'none') AND isset($svgstyle['stroke-width']) AND ($svgstyle['stroke-width'] > 0)) {
  29003. $this->svgtextmode['stroke'] = $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false);
  29004. } else {
  29005. $this->svgtextmode['stroke'] = false;
  29006. }
  29007. $this->StartTransform();
  29008. $this->SVGTransform($tm);
  29009. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, 1, 1);
  29010. $this->x = $x;
  29011. $this->y = $y;
  29012. break;
  29013. }
  29014. // use
  29015. case 'use': {
  29016. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  29017. $svgdefid = substr($attribs['xlink:href'], 1);
  29018. if (isset($this->svgdefs[$svgdefid])) {
  29019. $use = $this->svgdefs[$svgdefid];
  29020. if (isset($attribs['xlink:href'])) {
  29021. unset($attribs['xlink:href']);
  29022. }
  29023. if (isset($attribs['id'])) {
  29024. unset($attribs['id']);
  29025. }
  29026. $attribs = array_merge($attribs, $use['attribs']);
  29027. $this->startSVGElementHandler($parser, $use['name'], $attribs);
  29028. }
  29029. }
  29030. break;
  29031. }
  29032. default: {
  29033. break;
  29034. }
  29035. } // end of switch
  29036. }
  29037. /**
  29038. * Sets the closing SVG element handler function for the XML parser.
  29039. * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
  29040. * @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.
  29041. * @author Nicola Asuni
  29042. * @since 5.0.000 (2010-05-02)
  29043. * @protected
  29044. */
  29045. protected function endSVGElementHandler($parser, $name) {
  29046. switch($name) {
  29047. case 'defs': {
  29048. $this->svgdefsmode = false;
  29049. break;
  29050. }
  29051. // clipPath
  29052. case 'clipPath': {
  29053. $this->svgclipmode = false;
  29054. break;
  29055. }
  29056. case 'g': {
  29057. // ungroup: remove last style from array
  29058. array_pop($this->svgstyles);
  29059. $this->StopTransform();
  29060. break;
  29061. }
  29062. case 'text':
  29063. case 'tspan': {
  29064. if ($this->svgtextmode['invisible']) {
  29065. // This implementation must be fixed to following the rule:
  29066. // 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.
  29067. break;
  29068. }
  29069. // print text
  29070. $text = $this->svgtext;
  29071. //$text = $this->stringTrim($text);
  29072. $textlen = $this->GetStringWidth($text);
  29073. if ($this->svgtextmode['text-anchor'] != 'start') {
  29074. // check if string is RTL text
  29075. if ($this->svgtextmode['text-anchor'] == 'end') {
  29076. if ($this->svgtextmode['rtl']) {
  29077. $this->x += $textlen;
  29078. } else {
  29079. $this->x -= $textlen;
  29080. }
  29081. } elseif ($this->svgtextmode['text-anchor'] == 'middle') {
  29082. if ($this->svgtextmode['rtl']) {
  29083. $this->x += ($textlen / 2);
  29084. } else {
  29085. $this->x -= ($textlen / 2);
  29086. }
  29087. }
  29088. }
  29089. $textrendermode = $this->textrendermode;
  29090. $textstrokewidth = $this->textstrokewidth;
  29091. $this->setTextRenderingMode($this->svgtextmode['stroke'], true, false);
  29092. if ($name == 'text') {
  29093. // store current coordinates
  29094. $tmpx = $this->x;
  29095. $tmpy = $this->y;
  29096. }
  29097. $this->Cell($textlen, 0, $text, 0, 0, '', false, '', 0, false, 'L', 'T');
  29098. if ($name == 'text') {
  29099. // restore coordinates
  29100. $this->x = $tmpx;
  29101. $this->y = $tmpy;
  29102. }
  29103. // restore previous rendering mode
  29104. $this->textrendermode = $textrendermode;
  29105. $this->textstrokewidth = $textstrokewidth;
  29106. $this->svgtext = '';
  29107. $this->StopTransform();
  29108. array_pop($this->svgstyles);
  29109. break;
  29110. }
  29111. default: {
  29112. break;
  29113. }
  29114. }
  29115. }
  29116. /**
  29117. * Sets the character data handler function for the XML parser.
  29118. * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
  29119. * @param $data (string) The second parameter, data, contains the character data as a string.
  29120. * @author Nicola Asuni
  29121. * @since 5.0.000 (2010-05-02)
  29122. * @protected
  29123. */
  29124. protected function segSVGContentHandler($parser, $data) {
  29125. $this->svgtext .= $data;
  29126. }
  29127. // --- END SVG METHODS -----------------------------------------------------
  29128. } // END OF TCPDF CLASS
  29129. //============================================================+
  29130. // END OF FILE
  29131. //============================================================+