mpdf.php 1.2 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839
  1. <?php
  2. // ******************************************************************************
  3. // Software: mPDF, Unicode-HTML Free PDF generator *
  4. // Version: 5.4 based on *
  5. // FPDF by Olivier PLATHEY *
  6. // HTML2FPDF by Renato Coelho *
  7. // Date: 2012-02-14 *
  8. // Author: Ian Back <ianb@bpm1.com> *
  9. // License: GPL *
  10. // *
  11. // Changes: See changelog.txt *
  12. // ******************************************************************************
  13. define('mPDF_VERSION','5.4');
  14. //Scale factor
  15. define('_MPDFK', (72/25.4)); // Will only use mm
  16. /*-- HTML-CSS --*/
  17. define('AUTOFONT_CJK',1);
  18. define('AUTOFONT_THAIVIET',2);
  19. define('AUTOFONT_RTL',4);
  20. define('AUTOFONT_INDIC',8);
  21. define('AUTOFONT_ALL',15);
  22. define('_BORDER_ALL',15);
  23. define('_BORDER_TOP',8);
  24. define('_BORDER_RIGHT',4);
  25. define('_BORDER_BOTTOM',2);
  26. define('_BORDER_LEFT',1);
  27. /*-- END HTML-CSS --*/
  28. if (!defined('_MPDF_PATH')) define('_MPDF_PATH', dirname(preg_replace('/\\\\/','/',__FILE__)) . '/');
  29. if (!defined('_MPDF_URI')) define('_MPDF_URI',_MPDF_PATH);
  30. require_once(_MPDF_PATH.'includes/functions.php');
  31. require_once(_MPDF_PATH.'config_cp.php');
  32. if (!defined('_JPGRAPH_PATH')) define("_JPGRAPH_PATH", _MPDF_PATH.'jpgraph/');
  33. if (!defined('_MPDF_TEMP_PATH')) define("_MPDF_TEMP_PATH", _MPDF_PATH.'tmp/');
  34. if (!defined('_MPDF_TTFONTPATH')) { define('_MPDF_TTFONTPATH',_MPDF_PATH.'ttfonts/'); }
  35. if (!defined('_MPDF_TTFONTDATAPATH')) { define('_MPDF_TTFONTDATAPATH',_MPDF_PATH.'ttfontdata/'); }
  36. $errorlevel=error_reporting();
  37. $errorlevel=error_reporting($errorlevel & ~E_NOTICE);
  38. //error_reporting(E_ALL);
  39. // mPDF 5.3.76
  40. if(function_exists("date_default_timezone_set")) {
  41. if (ini_get("date.timezone")=="") { date_default_timezone_set("Europe/London"); }
  42. }
  43. if (!function_exists("mb_strlen")) { die("Error - mPDF requires mb_string functions. Ensure that PHP is compiled with php_mbstring.dll enabled."); }
  44. if (!defined('PHP_VERSION_ID')) {
  45. $version = explode('.', PHP_VERSION);
  46. define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
  47. }
  48. // mPDF 5.3.79 Machine dependent number of bytes used to pack "double" into binary (used in cacheTables)
  49. $test = pack("d", 134455.474557333333666);
  50. define("_DSIZE", strlen($test));
  51. class mPDF
  52. {
  53. ///////////////////////////////
  54. // EXTERNAL (PUBLIC) VARIABLES
  55. // Define these in config.php
  56. ///////////////////////////////
  57. var $cacheTables; // mPDF 5.3.79
  58. var $bookmarkStyles; // mPDF 5.3.39
  59. var $useActiveForms;
  60. var $repackageTTF;
  61. var $allowCJKorphans;
  62. var $allowCJKoverflow;
  63. var $CJKleading;
  64. var $CJKfollowing;
  65. var $CJKoverflow;
  66. var $useKerning;
  67. var $restrictColorSpace;
  68. var $bleedMargin;
  69. var $crossMarkMargin;
  70. var $cropMarkMargin;
  71. var $cropMarkLength;
  72. var $nonPrintMargin;
  73. var $PDFX;
  74. var $PDFXauto;
  75. var $PDFA;
  76. var $PDFAauto;
  77. var $ICCProfile;
  78. var $printers_info;
  79. var $iterationCounter;
  80. var $smCapsScale;
  81. var $smCapsStretch;
  82. var $backupSubsFont;
  83. var $backupSIPFont;
  84. var $debugfonts;
  85. var $useAdobeCJK;
  86. var $percentSubset;
  87. var $maxTTFFilesize;
  88. var $BMPonly;
  89. var $tableMinSizePriority;
  90. var $dpi;
  91. var $watermarkImgAlphaBlend;
  92. var $watermarkImgBehind;
  93. var $justifyB4br;
  94. var $packTableData;
  95. var $pgsIns;
  96. var $simpleTables;
  97. var $enableImports;
  98. var $debug;
  99. var $showStats;
  100. var $setAutoTopMargin;
  101. var $setAutoBottomMargin;
  102. var $autoMarginPadding;
  103. var $collapseBlockMargins;
  104. var $falseBoldWeight;
  105. var $normalLineheight;
  106. var $progressBar;
  107. var $incrementFPR1;
  108. var $incrementFPR2;
  109. var $incrementFPR3;
  110. var $incrementFPR4;
  111. var $hyphenate;
  112. var $hyphenateTables;
  113. var $SHYlang;
  114. var $SHYleftmin;
  115. var $SHYrightmin;
  116. var $SHYcharmin;
  117. var $SHYcharmax;
  118. var $SHYlanguages;
  119. // PageNumber Conditional Text
  120. var $pagenumPrefix;
  121. var $pagenumSuffix;
  122. var $nbpgPrefix;
  123. var $nbpgSuffix;
  124. var $showImageErrors;
  125. var $allow_output_buffering;
  126. var $autoPadding;
  127. var $useGraphs;
  128. var $autoFontGroupSize;
  129. var $tabSpaces;
  130. var $useLang;
  131. var $restoreBlockPagebreaks;
  132. var $watermarkTextAlpha;
  133. var $watermarkImageAlpha;
  134. var $watermark_size;
  135. var $watermark_pos;
  136. var $annotSize;
  137. var $annotMargin;
  138. var $annotOpacity;
  139. var $title2annots;
  140. var $keepColumns;
  141. var $keep_table_proportions;
  142. var $ignore_table_widths;
  143. var $ignore_table_percents;
  144. var $list_align_style;
  145. var $list_number_suffix;
  146. var $useSubstitutions;
  147. var $CSSselectMedia;
  148. var $forcePortraitHeaders;
  149. var $forcePortraitMargins;
  150. var $displayDefaultOrientation;
  151. var $ignore_invalid_utf8;
  152. var $allowedCSStags;
  153. var $onlyCoreFonts;
  154. var $allow_charset_conversion;
  155. var $jSWord;
  156. var $jSmaxChar;
  157. var $jSmaxCharLast;
  158. var $jSmaxWordLast;
  159. var $orphansAllowed;
  160. var $max_colH_correction;
  161. var $table_error_report;
  162. var $table_error_report_param;
  163. var $biDirectional;
  164. var $text_input_as_HTML;
  165. var $anchor2Bookmark;
  166. var $list_indent_first_level;
  167. var $shrink_tables_to_fit;
  168. var $allow_html_optional_endtags;
  169. var $img_dpi;
  170. var $defaultheaderfontsize;
  171. var $defaultheaderfontstyle;
  172. var $defaultheaderline;
  173. var $defaultfooterfontsize;
  174. var $defaultfooterfontstyle;
  175. var $defaultfooterline;
  176. var $header_line_spacing;
  177. var $footer_line_spacing;
  178. var $pregUHCchars;
  179. var $pregSJISchars;
  180. var $pregCJKchars;
  181. var $pregASCIIchars1;
  182. var $pregASCIIchars2;
  183. var $pregASCIIchars3;
  184. var $pregVIETchars;
  185. var $pregVIETPluschars;
  186. var $pregRTLchars;
  187. var $pregHEBchars;
  188. var $pregARABICchars;
  189. var $pregNonARABICchars;
  190. // INDIC
  191. var $pregHIchars;
  192. var $pregBNchars;
  193. var $pregPAchars;
  194. var $pregGUchars;
  195. var $pregORchars;
  196. var $pregTAchars;
  197. var $pregTEchars;
  198. var $pregKNchars;
  199. var $pregMLchars;
  200. var $pregSHchars;
  201. var $pregINDextra;
  202. var $mirrorMargins;
  203. var $default_lineheight_correction;
  204. var $watermarkText;
  205. var $watermarkImage;
  206. var $showWatermarkText;
  207. var $showWatermarkImage;
  208. var $fontsizes;
  209. // Aliases for backward compatability
  210. var $UnvalidatedText; // alias = $watermarkText
  211. var $TopicIsUnvalidated; // alias = $showWatermarkText
  212. var $useOddEven; // alias = $mirrorMargins
  213. var $useSubstitutionsMB; // alias = $useSubstitutions
  214. //////////////////////
  215. // CLASS OBJECTS
  216. //////////////////////
  217. // mPDF 5.3.89
  218. var $grad;
  219. var $bmp;
  220. var $wmf;
  221. var $tocontents;
  222. var $form;
  223. var $directw;
  224. //////////////////////
  225. // INTERNAL VARIABLES
  226. //////////////////////
  227. var $textshadow; // mPDF 5.3.A2
  228. var $colsums; // mPDF 5.3.92
  229. // mPDF 5.3.61
  230. var $spanborder;
  231. var $spanborddet;
  232. var $visibility; // mPDF 5.3.41
  233. var $useRC128encryption;
  234. var $uniqid;
  235. var $kerning;
  236. var $fixedlSpacing;
  237. var $minwSpacing;
  238. var $lSpacingCSS;
  239. var $wSpacingCSS;
  240. var $listDir;
  241. var $spotColorIDs;
  242. var $SVGcolors;
  243. var $spotColors;
  244. var $defTextColor;
  245. var $defDrawColor;
  246. var $defFillColor;
  247. var $tableBackgrounds;
  248. var $inlineDisplayOff;
  249. var $kt_y00;
  250. var $kt_p00;
  251. var $upperCase;
  252. var $checkSIP;
  253. var $checkSMP;
  254. var $checkCJK;
  255. var $tableCJK;
  256. var $watermarkImgAlpha;
  257. var $PDFAXwarnings;
  258. var $MetadataRoot;
  259. var $OutputIntentRoot;
  260. var $InfoRoot;
  261. var $current_filename;
  262. var $parsers;
  263. var $current_parser;
  264. var $_obj_stack;
  265. var $_don_obj_stack;
  266. var $_current_obj_id;
  267. var $tpls;
  268. var $tpl;
  269. var $tplprefix;
  270. var $_res;
  271. var $pdf_version;
  272. var $noImageFile;
  273. var $lastblockbottommargin;
  274. var $baselineC;
  275. var $subPos;
  276. var $subArrMB;
  277. var $ReqFontStyle;
  278. var $tableClipPath ;
  279. var $forceExactLineheight;
  280. var $listOcc;
  281. var $fullImageHeight;
  282. var $inFixedPosBlock; // Internal flag for position:fixed block
  283. var $fixedPosBlock; // Buffer string for position:fixed block
  284. var $fixedPosBlockDepth;
  285. var $fixedPosBlockBBox;
  286. var $fixedPosBlockSave;
  287. var $maxPosL;
  288. var $maxPosR;
  289. var $loaded;
  290. var $extraFontSubsets;
  291. var $docTemplateStart; // Internal flag for page (page no. -1) that docTemplate starts on
  292. var $time0;
  293. // Classes
  294. var $indic;
  295. var $barcode;
  296. var $SHYpatterns;
  297. var $loadedSHYpatterns;
  298. var $loadedSHYdictionary;
  299. var $SHYdictionary;
  300. var $SHYdictionaryWords;
  301. var $spanbgcolorarray;
  302. var $default_font;
  303. var $list_lineheight;
  304. var $headerbuffer;
  305. var $lastblocklevelchange;
  306. var $nestedtablejustfinished;
  307. var $linebreakjustfinished;
  308. var $cell_border_dominance_L;
  309. var $cell_border_dominance_R;
  310. var $cell_border_dominance_T;
  311. var $cell_border_dominance_B;
  312. var $tbCSSlvl;
  313. var $listCSSlvl;
  314. var $table_keep_together;
  315. var $plainCell_properties;
  316. var $inherit_lineheight;
  317. var $listitemtype;
  318. var $shrin_k1;
  319. var $outerfilled;
  320. var $blockContext;
  321. var $floatDivs;
  322. var $tablecascadeCSS;
  323. var $listcascadeCSS;
  324. var $patterns;
  325. var $pageBackgrounds;
  326. var $bodyBackgroundGradient;
  327. var $bodyBackgroundImage;
  328. var $bodyBackgroundColor;
  329. var $writingHTMLheader; // internal flag - used both for writing HTMLHeaders/Footers and FixedPos block
  330. var $writingHTMLfooter;
  331. var $autoFontGroups;
  332. var $angle;
  333. var $gradients;
  334. var $kwt_Reference;
  335. var $kwt_BMoutlines;
  336. var $kwt_toc;
  337. var $tbrot_Reference;
  338. var $tbrot_BMoutlines;
  339. var $tbrot_toc;
  340. var $col_Reference;
  341. var $col_BMoutlines;
  342. var $col_toc;
  343. var $currentGraphId;
  344. var $graphs;
  345. var $floatbuffer;
  346. var $floatmargins;
  347. var $bullet;
  348. var $bulletarray;
  349. var $rtlAsArabicFarsi; // DEPRACATED
  350. var $currentLang;
  351. var $default_lang;
  352. var $default_available_fonts;
  353. var $pageTemplate;
  354. var $docTemplate;
  355. var $docTemplateContinue;
  356. var $arabGlyphs;
  357. var $arabHex;
  358. var $persianGlyphs;
  359. var $persianHex;
  360. var $arabVowels;
  361. var $arabPrevLink;
  362. var $arabNextLink;
  363. var $formobjects; // array of Form Objects for WMF
  364. var $InlineProperties;
  365. var $InlineAnnots;
  366. var $ktAnnots;
  367. var $tbrot_Annots;
  368. var $kwt_Annots;
  369. var $columnAnnots;
  370. var $columnForms;
  371. var $PageAnnots;
  372. var $pageDim; // Keep track of page wxh for orientation changes - set in _beginpage, used in _putannots
  373. var $breakpoints;
  374. var $tableLevel;
  375. var $tbctr;
  376. var $innermostTableLevel;
  377. var $saveTableCounter;
  378. var $cellBorderBuffer;
  379. var $saveHTMLFooter_height;
  380. var $saveHTMLFooterE_height;
  381. var $firstPageBoxHeader;
  382. var $firstPageBoxHeaderEven;
  383. var $firstPageBoxFooter;
  384. var $firstPageBoxFooterEven;
  385. var $page_box;
  386. var $show_marks; // crop or cross marks
  387. var $basepathIsLocal;
  388. var $use_kwt;
  389. var $kwt;
  390. var $kwt_height;
  391. var $kwt_y0;
  392. var $kwt_x0;
  393. var $kwt_buffer;
  394. var $kwt_Links;
  395. var $kwt_moved;
  396. var $kwt_saved;
  397. var $PageNumSubstitutions;
  398. var $table_borders_separate;
  399. var $base_table_properties;
  400. var $borderstyles;
  401. var $listjustfinished;
  402. var $blockjustfinished;
  403. var $orig_bMargin;
  404. var $orig_tMargin;
  405. var $orig_lMargin;
  406. var $orig_rMargin;
  407. var $orig_hMargin;
  408. var $orig_fMargin;
  409. var $pageheaders;
  410. var $pagefooters;
  411. var $pageHTMLheaders;
  412. var $pageHTMLfooters;
  413. var $saveHTMLHeader;
  414. var $saveHTMLFooter;
  415. var $HTMLheaderPageLinks;
  416. var $HTMLheaderPageAnnots;
  417. var $HTMLheaderPageForms;
  418. // See config_fonts.php for these next 5 values
  419. var $available_unifonts;
  420. var $sans_fonts;
  421. var $serif_fonts;
  422. var $mono_fonts;
  423. var $defaultSubsFont;
  424. // List of ALL available CJK fonts (incl. styles) (Adobe add-ons) hw removed
  425. var $available_CJK_fonts;
  426. var $cascadeCSS;
  427. var $HTMLHeader;
  428. var $HTMLFooter;
  429. var $HTMLHeaderE;
  430. var $HTMLFooterE;
  431. var $bufferoutput;
  432. var $showdefaultpagenos; // DEPRACATED -left for backward compatability
  433. // CJK fonts
  434. var $Big5_widths;
  435. var $GB_widths;
  436. var $SJIS_widths;
  437. var $UHC_widths;
  438. // SetProtection
  439. var $encrypted; //whether document is protected
  440. var $Uvalue; //U entry in pdf document
  441. var $Ovalue; //O entry in pdf document
  442. var $Pvalue; //P entry in pdf document
  443. var $enc_obj_id; //encryption object id
  444. var $last_rc4_key; //last RC4 key encrypted (cached for optimisation)
  445. var $last_rc4_key_c; //last RC4 computed key
  446. var $encryption_key;
  447. var $padding; //used for encryption
  448. // Bookmark
  449. var $BMoutlines;
  450. var $OutlineRoot;
  451. // INDEX
  452. var $ColActive;
  453. var $Reference;
  454. var $CurrCol;
  455. var $NbCol;
  456. var $y0; //Top ordinate of columns
  457. var $ColL;
  458. var $ColWidth;
  459. var $ColGap;
  460. // COLUMNS
  461. var $ColR;
  462. var $ChangeColumn;
  463. var $columnbuffer;
  464. var $ColDetails;
  465. var $columnLinks;
  466. var $colvAlign;
  467. // Substitutions
  468. var $substitute; // Array of substitution strings e.g. <ttz>112</ttz>
  469. var $entsearch; // Array of HTML entities (>ASCII 127) to substitute
  470. var $entsubstitute; // Array of substitution decimal unicode for the Hi entities
  471. // Default values if no style sheet offered (cf. http://www.w3.org/TR/CSS21/sample.html)
  472. var $defaultCSS;
  473. var $linemaxfontsize;
  474. var $lineheight_correction;
  475. var $lastoptionaltag; // Save current block item which HTML specifies optionsl endtag
  476. var $pageoutput;
  477. var $charset_in;
  478. var $blk;
  479. var $blklvl;
  480. var $ColumnAdjust;
  481. var $ws; // Word spacing
  482. var $HREF;
  483. var $pgwidth;
  484. var $fontlist;
  485. var $oldx;
  486. var $oldy;
  487. var $B;
  488. var $U; //underlining flag
  489. var $S; // SmallCaps flag
  490. var $I;
  491. var $tdbegin;
  492. var $table;
  493. var $cell;
  494. var $col;
  495. var $row;
  496. var $divbegin;
  497. var $divalign;
  498. var $divwidth;
  499. var $divheight;
  500. var $divrevert;
  501. var $spanbgcolor;
  502. var $spanlvl;
  503. var $listlvl;
  504. var $listnum;
  505. var $listtype;
  506. var $listoccur;
  507. var $listlist;
  508. var $listitem;
  509. var $pjustfinished;
  510. var $ignorefollowingspaces;
  511. var $SUP;
  512. var $SUB;
  513. var $SMALL;
  514. var $BIG;
  515. var $toupper;
  516. var $tolower;
  517. var $capitalize;
  518. var $dash_on;
  519. var $dotted_on;
  520. var $strike;
  521. var $CSS;
  522. var $textbuffer;
  523. var $currentfontstyle;
  524. var $currentfontfamily;
  525. var $currentfontsize;
  526. var $colorarray;
  527. var $bgcolorarray;
  528. var $internallink;
  529. var $enabledtags;
  530. var $lineheight;
  531. var $basepath;
  532. var $outlineparam;
  533. var $outline_on;
  534. var $specialcontent;
  535. var $selectoption;
  536. var $objectbuffer;
  537. // Table Rotation
  538. var $table_rotate;
  539. var $tbrot_maxw;
  540. var $tbrot_maxh;
  541. var $tablebuffer;
  542. var $tbrot_align;
  543. var $tbrot_Links;
  544. var $divbuffer; // Buffer used when keeping DIV on one page
  545. var $keep_block_together; // Keep a Block from page-break-inside: avoid
  546. var $ktLinks; // Keep-together Block links array
  547. var $ktBlock; // Keep-together Block array
  548. var $ktForms;
  549. var $ktReference;
  550. var $ktBMoutlines;
  551. var $_kttoc;
  552. var $tbrot_y0;
  553. var $tbrot_x0;
  554. var $tbrot_w;
  555. var $tbrot_h;
  556. var $mb_enc;
  557. var $directionality;
  558. var $extgstates; // Used for alpha channel - Transparency (Watermark)
  559. var $mgl;
  560. var $mgt;
  561. var $mgr;
  562. var $mgb;
  563. var $tts;
  564. var $ttz;
  565. var $tta;
  566. var $headerDetails;
  567. var $footerDetails;
  568. // Best to alter the below variables using default stylesheet above
  569. var $page_break_after_avoid;
  570. var $margin_bottom_collapse;
  571. var $list_indent;
  572. var $list_align;
  573. var $list_margin_bottom;
  574. var $default_font_size; // in pts
  575. var $original_default_font_size; // used to save default sizes when using table default
  576. var $original_default_font;
  577. var $watermark_font;
  578. var $defaultAlign;
  579. // TABLE
  580. var $defaultTableAlign;
  581. var $tablethead;
  582. var $thead_font_weight;
  583. var $thead_font_style;
  584. var $thead_font_smCaps;
  585. var $thead_valign_default;
  586. var $thead_textalign_default;
  587. var $tabletfoot;
  588. var $tfoot_font_weight;
  589. var $tfoot_font_style;
  590. var $tfoot_font_smCaps;
  591. var $tfoot_valign_default;
  592. var $tfoot_textalign_default;
  593. var $trow_text_rotate;
  594. var $cellPaddingL;
  595. var $cellPaddingR;
  596. var $cellPaddingT;
  597. var $cellPaddingB;
  598. var $table_lineheight;
  599. var $table_border_attr_set;
  600. var $table_border_css_set;
  601. var $shrin_k; // factor with which to shrink tables - used internally - do not change
  602. var $shrink_this_table_to_fit; // 0 or false to disable; value (if set) gives maximum factor to reduce fontsize
  603. var $MarginCorrection; // corrects for OddEven Margins
  604. var $margin_footer;
  605. var $margin_header;
  606. var $tabletheadjustfinished;
  607. var $usingCoreFont;
  608. var $charspacing;
  609. //Private properties FROM FPDF
  610. var $DisplayPreferences;
  611. var $outlines;
  612. var $flowingBlockAttr;
  613. var $page; //current page number
  614. var $n; //current object number
  615. var $offsets; //array of object offsets
  616. var $buffer; //buffer holding in-memory PDF
  617. var $pages; //array containing pages
  618. var $state; //current document state
  619. var $compress; //compression flag
  620. var $DefOrientation; //default orientation
  621. var $CurOrientation; //current orientation
  622. var $OrientationChanges; //array indicating orientation changes
  623. var $k; //scale factor (number of points in user unit)
  624. var $fwPt;
  625. var $fhPt; //dimensions of page format in points
  626. var $fw;
  627. var $fh; //dimensions of page format in user unit
  628. var $wPt;
  629. var $hPt; //current dimensions of page in points
  630. var $w;
  631. var $h; //current dimensions of page in user unit
  632. var $lMargin; //left margin
  633. var $tMargin; //top margin
  634. var $rMargin; //right margin
  635. var $bMargin; //page break margin
  636. var $cMarginL; //cell margin Left
  637. var $cMarginR; //cell margin Right
  638. var $cMarginT; //cell margin Left
  639. var $cMarginB; //cell margin Right
  640. var $DeflMargin; //Default left margin
  641. var $DefrMargin; //Default right margin
  642. var $x;
  643. var $y; //current position in user unit for cell positioning
  644. var $lasth; //height of last cell printed
  645. var $LineWidth; //line width in user unit
  646. var $CoreFonts; //array of standard font names
  647. var $fonts; //array of used fonts
  648. var $FontFiles; //array of font files
  649. var $images; //array of used images
  650. var $PageLinks; //array of links in pages
  651. var $links; //array of internal links
  652. var $FontFamily; //current font family
  653. var $FontStyle; //current font style
  654. var $CurrentFont; //current font info
  655. var $FontSizePt; //current font size in points
  656. var $FontSize; //current font size in user unit
  657. var $DrawColor; //commands for drawing color
  658. var $FillColor; //commands for filling color
  659. var $TextColor; //commands for text color
  660. var $ColorFlag; //indicates whether fill and text colors are different
  661. var $autoPageBreak; //automatic page breaking
  662. var $PageBreakTrigger; //threshold used to trigger page breaks
  663. var $InFooter; //flag set when processing footer
  664. var $InHTMLFooter;
  665. var $processingFooter; //flag set when processing footer - added for columns
  666. var $processingHeader; //flag set when processing header - added for columns
  667. var $ZoomMode; //zoom display mode
  668. var $LayoutMode; //layout display mode
  669. var $title; //title
  670. var $subject; //subject
  671. var $author; //author
  672. var $keywords; //keywords
  673. var $creator; //creator
  674. var $aliasNbPg; //alias for total number of pages
  675. var $aliasNbPgGp; //alias for total number of pages in page group
  676. var $aliasNbPgHex;
  677. var $aliasNbPgGpHex;
  678. var $ispre;
  679. var $outerblocktags;
  680. var $innerblocktags;
  681. // **********************************
  682. // **********************************
  683. // **********************************
  684. // **********************************
  685. // **********************************
  686. // **********************************
  687. // **********************************
  688. // **********************************
  689. // **********************************
  690. function mPDF($mode='',$format='A4',$default_font_size=0,$default_font='',$mgl=15,$mgr=15,$mgt=16,$mgb=16,$mgh=9,$mgf=9, $orientation='P') {
  691. // mPDF 5.3.89 5.3.99
  692. /*-- BACKGROUNDS --*/
  693. if (!class_exists('grad', false)) { include(_MPDF_PATH.'classes/grad.php'); }
  694. if (empty($this->grad)) { $this->grad = new grad($this); }
  695. /*-- END BACKGROUNDS --*/
  696. /*-- FORMS --*/
  697. if (!class_exists('form', false)) { include(_MPDF_PATH.'classes/form.php'); }
  698. if (empty($this->form)) { $this->form = new form($this); }
  699. /*-- END FORMS --*/
  700. $this->time0 = microtime(true);
  701. //Some checks
  702. $this->_dochecks();
  703. // Set up Aliases for backwards compatability
  704. $this->UnvalidatedText =& $this->watermarkText;
  705. $this->TopicIsUnvalidated =& $this->showWatermarkText;
  706. $this->AliasNbPg =& $this->aliasNbPg;
  707. $this->AliasNbPgGp =& $this->aliasNbPgGp;
  708. $this->BiDirectional =& $this->biDirectional;
  709. $this->Anchor2Bookmark =& $this->anchor2Bookmark;
  710. $this->KeepColumns =& $this->keepColumns;
  711. $this->useOddEven =& $this->mirrorMargins;
  712. $this->useSubstitutionsMB =& $this->useSubstitutions;
  713. $this->visibility='visible'; // mPDF 5.3.41
  714. //Initialization of properties
  715. $this->spotColors=array();
  716. $this->spotColorIDs = array();
  717. $this->tableBackgrounds = array();
  718. $this->kt_y00 = '';
  719. $this->kt_p00 = '';
  720. $this->iterationCounter = false;
  721. $this->BMPonly = array();
  722. $this->page=0;
  723. $this->n=2;
  724. $this->buffer='';
  725. $this->objectbuffer = array();
  726. $this->pages=array();
  727. $this->OrientationChanges=array();
  728. $this->state=0;
  729. $this->fonts=array();
  730. $this->FontFiles=array();
  731. $this->images=array();
  732. $this->links=array();
  733. $this->InFooter=false;
  734. $this->processingFooter=false;
  735. $this->processingHeader=false;
  736. $this->lasth=0;
  737. $this->FontFamily='';
  738. $this->FontStyle='';
  739. $this->FontSizePt=9;
  740. $this->U=false;
  741. // Small Caps
  742. $this->upperCase = array();
  743. $this->S = false;
  744. $this->smCapsScale = 1;
  745. $this->smCapsStretch = 100;
  746. $this->defTextColor = $this->TextColor = $this->SetTColor($this->ConvertColor(0),true);
  747. $this->defDrawColor = $this->DrawColor = $this->SetDColor($this->ConvertColor(0),true);
  748. $this->defFillColor = $this->FillColor = $this->SetFColor($this->ConvertColor(255),true);
  749. //SVG color names array
  750. //http://www.w3schools.com/css/css_colornames.asp
  751. $this->SVGcolors = array('antiquewhite'=>'#FAEBD7','aqua'=>'#00FFFF','aquamarine'=>'#7FFFD4','beige'=>'#F5F5DC','black'=>'#000000',
  752. 'blue'=>'#0000FF','brown'=>'#A52A2A','cadetblue'=>'#5F9EA0','chocolate'=>'#D2691E','cornflowerblue'=>'#6495ED','crimson'=>'#DC143C',
  753. 'darkblue'=>'#00008B','darkgoldenrod'=>'#B8860B','darkgreen'=>'#006400','darkmagenta'=>'#8B008B','darkorange'=>'#FF8C00',
  754. 'darkred'=>'#8B0000','darkseagreen'=>'#8FBC8F','darkslategray'=>'#2F4F4F','darkviolet'=>'#9400D3','deepskyblue'=>'#00BFFF',
  755. 'dodgerblue'=>'#1E90FF','firebrick'=>'#B22222','forestgreen'=>'#228B22','fuchsia'=>'#FF00FF','gainsboro'=>'#DCDCDC','gold'=>'#FFD700',
  756. 'gray'=>'#808080','green'=>'#008000','greenyellow'=>'#ADFF2F','hotpink'=>'#FF69B4','indigo'=>'#4B0082','khaki'=>'#F0E68C',
  757. 'lavenderblush'=>'#FFF0F5','lemonchiffon'=>'#FFFACD','lightcoral'=>'#F08080','lightgoldenrodyellow'=>'#FAFAD2','lightgreen'=>'#90EE90',
  758. 'lightsalmon'=>'#FFA07A','lightskyblue'=>'#87CEFA','lightslategray'=>'#778899','lightyellow'=>'#FFFFE0','lime'=>'#00FF00','limegreen'=>'#32CD32',
  759. 'magenta'=>'#FF00FF','maroon'=>'#800000','mediumaquamarine'=>'#66CDAA','mediumorchid'=>'#BA55D3','mediumseagreen'=>'#3CB371',
  760. 'mediumspringgreen'=>'#00FA9A','mediumvioletred'=>'#C71585','midnightblue'=>'#191970','mintcream'=>'#F5FFFA','moccasin'=>'#FFE4B5','navy'=>'#000080',
  761. 'olive'=>'#808000','orange'=>'#FFA500','orchid'=>'#DA70D6','palegreen'=>'#98FB98',
  762. 'palevioletred'=>'#D87093','peachpuff'=>'#FFDAB9','pink'=>'#FFC0CB','powderblue'=>'#B0E0E6','purple'=>'#800080',
  763. 'red'=>'#FF0000','royalblue'=>'#4169E1','salmon'=>'#FA8072','seagreen'=>'#2E8B57','sienna'=>'#A0522D','silver'=>'#C0C0C0','skyblue'=>'#87CEEB',
  764. 'slategray'=>'#708090','springgreen'=>'#00FF7F','steelblue'=>'#4682B4','tan'=>'#D2B48C','teal'=>'#008080','thistle'=>'#D8BFD8','turquoise'=>'#40E0D0',
  765. 'violetred'=>'#D02090','white'=>'#FFFFFF','yellow'=>'#FFFF00',
  766. 'aliceblue'=>'#f0f8ff', 'azure'=>'#f0ffff', 'bisque'=>'#ffe4c4', 'blanchedalmond'=>'#ffebcd', 'blueviolet'=>'#8a2be2', 'burlywood'=>'#deb887',
  767. 'chartreuse'=>'#7fff00', 'coral'=>'#ff7f50', 'cornsilk'=>'#fff8dc', 'cyan'=>'#00ffff', 'darkcyan'=>'#008b8b', 'darkgray'=>'#a9a9a9',
  768. 'darkgrey'=>'#a9a9a9', 'darkkhaki'=>'#bdb76b', 'darkolivegreen'=>'#556b2f', 'darkorchid'=>'#9932cc', 'darksalmon'=>'#e9967a',
  769. 'darkslateblue'=>'#483d8b', 'darkslategrey'=>'#2f4f4f', 'darkturquoise'=>'#00ced1', 'deeppink'=>'#ff1493', 'dimgray'=>'#696969',
  770. 'dimgrey'=>'#696969', 'floralwhite'=>'#fffaf0', 'ghostwhite'=>'#f8f8ff', 'goldenrod'=>'#daa520', 'grey'=>'#808080', 'honeydew'=>'#f0fff0',
  771. 'indianred'=>'#cd5c5c', 'ivory'=>'#fffff0', 'lavender'=>'#e6e6fa', 'lawngreen'=>'#7cfc00', 'lightblue'=>'#add8e6', 'lightcyan'=>'#e0ffff',
  772. 'lightgray'=>'#d3d3d3', 'lightgrey'=>'#d3d3d3', 'lightpink'=>'#ffb6c1', 'lightseagreen'=>'#20b2aa', 'lightslategrey'=>'#778899',
  773. 'lightsteelblue'=>'#b0c4de', 'linen'=>'#faf0e6', 'mediumblue'=>'#0000cd', 'mediumpurple'=>'#9370db', 'mediumslateblue'=>'#7b68ee',
  774. 'mediumturquoise'=>'#48d1cc', 'mistyrose'=>'#ffe4e1', 'navajowhite'=>'#ffdead', 'oldlace'=>'#fdf5e6', 'olivedrab'=>'#6b8e23', 'orangered'=>'#ff4500',
  775. 'palegoldenrod'=>'#eee8aa', 'paleturquoise'=>'#afeeee', 'papayawhip'=>'#ffefd5', 'peru'=>'#cd853f', 'plum'=>'#dda0dd', 'rosybrown'=>'#bc8f8f',
  776. 'saddlebrown'=>'#8b4513', 'sandybrown'=>'#f4a460', 'seashell'=>'#fff5ee', 'slateblue'=>'#6a5acd', 'slategrey'=>'#708090', 'snow'=>'#fffafa',
  777. 'tomato'=>'#ff6347', 'violet'=>'#ee82ee', 'wheat'=>'#f5deb3', 'whitesmoke'=>'#f5f5f5', 'yellowgreen'=>'#9acd32');
  778. $this->ColorFlag=false;
  779. $this->extgstates = array();
  780. $this->mb_enc='windows-1252';
  781. $this->directionality='ltr';
  782. $this->defaultAlign = 'L';
  783. $this->defaultTableAlign = 'L';
  784. $this->fixedPosBlockSave = array();
  785. $this->extraFontSubsets = 0;
  786. $this->SHYpatterns = array();
  787. $this->loadedSHYdictionary = false;
  788. $this->SHYdictionary = array();
  789. $this->SHYdictionaryWords = array();
  790. $this->blockContext = 1;
  791. $this->floatDivs = array();
  792. $this->DisplayPreferences='';
  793. $this->tablecascadeCSS = array();
  794. $this->listcascadeCSS = array();
  795. $this->patterns = array(); // Tiling patterns used for backgrounds
  796. $this->pageBackgrounds = array();
  797. $this->writingHTMLheader = false; // internal flag - used both for writing HTMLHeaders/Footers and FixedPos block
  798. $this->writingHTMLfooter = false; // internal flag - used both for writing HTMLHeaders/Footers and FixedPos block
  799. $this->gradients = array();
  800. $this->kwt_Reference = array();
  801. $this->kwt_BMoutlines = array();
  802. $this->kwt_toc = array();
  803. $this->tbrot_Reference = array();
  804. $this->tbrot_BMoutlines = array();
  805. $this->tbrot_toc = array();
  806. $this->col_Reference = array();
  807. $this->col_BMoutlines = array();
  808. $this->col_toc = array();
  809. $this->graphs = array();
  810. $this->pgsIns = array();
  811. $this->PDFAXwarnings = array();
  812. $this->inlineDisplayOff = false;
  813. $this->kerning = false;
  814. $this->lSpacingCSS = '';
  815. $this->wSpacingCSS = '';
  816. $this->fixedlSpacing = false;
  817. $this->minwSpacing = 0;
  818. $this->baselineC = 0.35; // Baseline for text
  819. $this->noImageFile = str_replace("\\","/",dirname(__FILE__)) . '/includes/no_image.jpg';
  820. $this->subPos = 0;
  821. $this->forceExactLineheight = false;
  822. $this->listOcc = 0;
  823. $this->normalLineheight = 1.3;
  824. // These are intended as configuration variables, and should be set in config.php - which will override these values;
  825. // set here as failsafe as will cause an error if not defined
  826. $this->incrementFPR1 = 10;
  827. $this->incrementFPR2 = 10;
  828. $this->incrementFPR3 = 10;
  829. $this->incrementFPR4 = 10;
  830. $this->fullImageHeight = false;
  831. $this->floatbuffer = array();
  832. $this->floatmargins = array();
  833. $this->autoFontGroups = 0;
  834. $this->formobjects=array(); // array of Form Objects for WMF
  835. $this->InlineProperties=array();
  836. $this->InlineAnnots=array();
  837. $this->ktAnnots=array();
  838. $this->tbrot_Annots=array();
  839. $this->kwt_Annots=array();
  840. $this->columnAnnots=array();
  841. $this->pageDim=array();
  842. $this->breakpoints = array(); // used in columnbuffer
  843. $this->tableLevel=0;
  844. $this->tbctr=array(); // counter for nested tables at each level
  845. $this->page_box = array();
  846. $this->show_marks = ''; // crop or cross marks
  847. $this->kwt = false;
  848. $this->kwt_height = 0;
  849. $this->kwt_y0 = 0;
  850. $this->kwt_x0 = 0;
  851. $this->kwt_buffer = array();
  852. $this->kwt_Links = array();
  853. $this->kwt_moved = false;
  854. $this->kwt_saved = false;
  855. $this->PageNumSubstitutions = array();
  856. $this->base_table_properties=array();
  857. $this->borderstyles = array('inset','groove','outset','ridge','dotted','dashed','solid','double');
  858. $this->tbrot_align = 'C';
  859. $this->pageheaders=array();
  860. $this->pagefooters=array();
  861. $this->pageHTMLheaders=array();
  862. $this->pageHTMLfooters=array();
  863. $this->HTMLheaderPageLinks = array();
  864. $this->HTMLheaderPageAnnots = array();
  865. $this->ktForms = array();
  866. $this->HTMLheaderPageForms = array();
  867. $this->columnForms = array();
  868. $this->tbrotForms = array();
  869. $this->useRC128encryption = false;
  870. $this->uniqid = '';
  871. $this->cascadeCSS = array();
  872. $this->bufferoutput = false;
  873. $this->encrypted=false; //whether document is protected
  874. $this->BMoutlines=array();
  875. $this->ColActive=0; //Flag indicating that columns are on (the index is being processed)
  876. $this->Reference=array(); //Array containing the references
  877. $this->CurrCol=0; //Current column number
  878. $this->ColL = array(0); // Array of Left pos of columns - absolute - needs Margin correction for Odd-Even
  879. $this->ColR = array(0); // Array of Right pos of columns - absolute pos - needs Margin correction for Odd-Even
  880. $this->ChangeColumn = 0;
  881. $this->columnbuffer = array();
  882. $this->ColDetails = array(); // Keeps track of some column details
  883. $this->columnLinks = array(); // Cross references PageLinks
  884. $this->substitute = array(); // Array of substitution strings e.g. <ttz>112</ttz>
  885. $this->entsearch = array(); // Array of HTML entities (>ASCII 127) to substitute
  886. $this->entsubstitute = array(); // Array of substitution decimal unicode for the Hi entities
  887. $this->lastoptionaltag = '';
  888. $this->charset_in = '';
  889. $this->blk = array();
  890. $this->blklvl = 0;
  891. $this->tts = false;
  892. $this->ttz = false;
  893. $this->tta = false;
  894. $this->ispre=false;
  895. $this->checkSIP = false;
  896. $this->checkSMP = false;
  897. $this->checkCJK = false;
  898. $this->tableCJK = false;
  899. $this->headerDetails=array();
  900. $this->footerDetails=array();
  901. $this->page_break_after_avoid = false;
  902. $this->margin_bottom_collapse = false;
  903. $this->tablethead = 0;
  904. $this->tabletfoot = 0;
  905. $this->table_border_attr_set = 0;
  906. $this->table_border_css_set = 0;
  907. $this->shrin_k = 1.0;
  908. $this->shrink_this_table_to_fit = 0;
  909. $this->MarginCorrection = 0;
  910. $this->tabletheadjustfinished = false;
  911. $this->usingCoreFont = false;
  912. $this->charspacing=0;
  913. $this->outlines=array();
  914. $this->autoPageBreak = true;
  915. require(_MPDF_PATH.'config.php'); // config data
  916. $this->_setPageSize($format, $orientation);
  917. $this->DefOrientation=$orientation;
  918. $this->margin_header=$mgh;
  919. $this->margin_footer=$mgf;
  920. $bmargin=$mgb;
  921. $this->DeflMargin = $mgl;
  922. $this->DefrMargin = $mgr;
  923. $this->orig_tMargin = $mgt;
  924. $this->orig_bMargin = $bmargin;
  925. $this->orig_lMargin = $this->DeflMargin;
  926. $this->orig_rMargin = $this->DefrMargin;
  927. $this->orig_hMargin = $this->margin_header;
  928. $this->orig_fMargin = $this->margin_footer;
  929. if ($this->setAutoTopMargin=='pad') { $mgt += $this->margin_header; }
  930. if ($this->setAutoBottomMargin=='pad') { $mgb += $this->margin_footer; }
  931. $this->SetMargins($this->DeflMargin,$this->DefrMargin,$mgt); // sets l r t margin
  932. //Automatic page break
  933. $this->SetAutoPageBreak($this->autoPageBreak,$bmargin); // sets $this->bMargin & PageBreakTrigger
  934. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  935. //Interior cell margin (1 mm) ? not used
  936. $this->cMarginL = 1;
  937. $this->cMarginR = 1;
  938. //Line width (0.2 mm)
  939. $this->LineWidth=.567/_MPDFK;
  940. //To make the function Footer() work - replaces {nb} with page number
  941. $this->AliasNbPages();
  942. $this->AliasNbPageGroups();
  943. $this->aliasNbPgHex = '{nbHEXmarker}';
  944. $this->aliasNbPgGpHex = '{nbpgHEXmarker}';
  945. //Enable all tags as default
  946. $this->DisableTags();
  947. //Full width display mode
  948. $this->SetDisplayMode(100); // fullwidth? 'fullpage'
  949. //Compression
  950. $this->SetCompression(true);
  951. //Set default display preferences
  952. $this->SetDisplayPreferences('');
  953. // Font data
  954. require(_MPDF_PATH.'config_fonts.php');
  955. // Available fonts
  956. $this->available_unifonts = array();
  957. foreach ($this->fontdata AS $f => $fs) {
  958. if (isset($fs['R']) && $fs['R']) { $this->available_unifonts[] = $f; }
  959. if (isset($fs['B']) && $fs['B']) { $this->available_unifonts[] = $f.'B'; }
  960. if (isset($fs['I']) && $fs['I']) { $this->available_unifonts[] = $f.'I'; }
  961. if (isset($fs['BI']) && $fs['BI']) { $this->available_unifonts[] = $f.'BI'; }
  962. }
  963. $this->default_available_fonts = $this->available_unifonts;
  964. $optcore = false;
  965. $onlyCoreFonts = false;
  966. if (preg_match('/([\-+])aCJK/i',$mode, $m)) {
  967. preg_replace('/([\-+])aCJK/i','',$mode);
  968. if ($m[1]=='+') { $this->useAdobeCJK = true; }
  969. else { $this->useAdobeCJK = false; }
  970. }
  971. if (strlen($mode)==1) {
  972. if ($mode=='s') { $this->percentSubset = 100; $mode = ''; }
  973. else if ($mode=='c') { $onlyCoreFonts = true; $mode = ''; }
  974. }
  975. else if (substr($mode,-2)=='-s') {
  976. $this->percentSubset = 100;
  977. $mode = substr($mode,0,strlen($mode)-2);
  978. }
  979. else if (substr($mode,-2)=='-c') {
  980. $onlyCoreFonts = true;
  981. $mode = substr($mode,0,strlen($mode)-2);
  982. }
  983. else if (substr($mode,-2)=='-x') {
  984. $optcore = true;
  985. $mode = substr($mode,0,strlen($mode)-2);
  986. }
  987. // Autodetect if mode is a language_country string (en-GB or en_GB or en)
  988. if ((strlen($mode) == 5 && $mode != 'UTF-8') || strlen($mode) == 2) {
  989. list ($coreSuitable,$mpdf_pdf_unifonts) = GetLangOpts($mode, $this->useAdobeCJK);
  990. if ($coreSuitable && $optcore) { $onlyCoreFonts = true; }
  991. if ($mpdf_pdf_unifonts) {
  992. $this->RestrictUnicodeFonts($mpdf_pdf_unifonts);
  993. $this->default_available_fonts = $mpdf_pdf_unifonts;
  994. }
  995. $this->currentLang = $mode;
  996. $this->default_lang = $mode;
  997. }
  998. $this->onlyCoreFonts = $onlyCoreFonts;
  999. if ($this->onlyCoreFonts) {
  1000. $this->setMBencoding('windows-1252'); // sets $this->mb_enc
  1001. }
  1002. else {
  1003. $this->setMBencoding('UTF-8'); // sets $this->mb_enc
  1004. }
  1005. @mb_regex_encoding('UTF-8'); // mPDF 5.3.07 // required only for mb_ereg... and mb_split functions
  1006. // Adobe CJK fonts
  1007. $this->available_CJK_fonts = array('gb','big5','sjis','uhc','gbB','big5B','sjisB','uhcB','gbI','big5I','sjisI','uhcI',
  1008. 'gbBI','big5BI','sjisBI','uhcBI');
  1009. //Standard fonts
  1010. $this->CoreFonts=array('ccourier'=>'Courier','ccourierB'=>'Courier-Bold','ccourierI'=>'Courier-Oblique','ccourierBI'=>'Courier-BoldOblique',
  1011. 'chelvetica'=>'Helvetica','chelveticaB'=>'Helvetica-Bold','chelveticaI'=>'Helvetica-Oblique','chelveticaBI'=>'Helvetica-BoldOblique',
  1012. 'ctimes'=>'Times-Roman','ctimesB'=>'Times-Bold','ctimesI'=>'Times-Italic','ctimesBI'=>'Times-BoldItalic',
  1013. 'csymbol'=>'Symbol','czapfdingbats'=>'ZapfDingbats');
  1014. $this->fontlist=array("ctimes","ccourier","chelvetica","csymbol","czapfdingbats");
  1015. // Substitutions
  1016. $this->setHiEntitySubstitutions();
  1017. if ($this->onlyCoreFonts) {
  1018. $this->useSubstitutions = true;
  1019. $this->SetSubstitutions();
  1020. }
  1021. else { $this->useSubstitutions = false; }
  1022. /*-- HTML-CSS --*/
  1023. if (file_exists(_MPDF_PATH.'mpdf.css')) {
  1024. $css = file_get_contents(_MPDF_PATH.'mpdf.css');
  1025. $css2 = $this->ReadDefaultCSS($css);
  1026. $this->defaultCSS = $this->array_merge_recursive_unique($this->defaultCSS,$css2);
  1027. }
  1028. /*-- END HTML-CSS --*/
  1029. if ($default_font=='') {
  1030. if ($this->onlyCoreFonts) {
  1031. if (in_array(strtolower($this->defaultCSS['BODY']['FONT-FAMILY']),$this->mono_fonts)) { $default_font = 'ccourier'; }
  1032. else if (in_array(strtolower($this->defaultCSS['BODY']['FONT-FAMILY']),$this->sans_fonts)) { $default_font = 'chelvetica'; }
  1033. else { $default_font = 'ctimes'; }
  1034. }
  1035. else { $default_font = $this->defaultCSS['BODY']['FONT-FAMILY']; }
  1036. }
  1037. if (!$default_font_size) {
  1038. $mmsize = $this->ConvertSize($this->defaultCSS['BODY']['FONT-SIZE']);
  1039. $default_font_size = $mmsize*(_MPDFK);
  1040. }
  1041. if ($default_font) { $this->SetDefaultFont($default_font); }
  1042. if ($default_font_size) { $this->SetDefaultFontSize($default_font_size); }
  1043. $this->SetLineHeight(); // lineheight is in mm
  1044. $this->SetFColor($this->ConvertColor(255));
  1045. $this->HREF='';
  1046. $this->oldy=-1;
  1047. $this->B=0;
  1048. $this->U=false;
  1049. $this->S=false;
  1050. $this->I=0;
  1051. $this->listlvl=0;
  1052. $this->listnum=0;
  1053. $this->listtype='';
  1054. $this->listoccur=array();
  1055. $this->listlist=array();
  1056. $this->listitem=array();
  1057. $this->tdbegin=false;
  1058. $this->table=array();
  1059. $this->cell=array();
  1060. $this->col=-1;
  1061. $this->row=-1;
  1062. $this->cellBorderBuffer = array();
  1063. $this->divbegin=false;
  1064. $this->divalign='';
  1065. $this->divwidth=0;
  1066. $this->divheight=0;
  1067. $this->spanbgcolor=false;
  1068. $this->divrevert=false;
  1069. // mPDF 5.3.61
  1070. $this->spanborder=false;
  1071. $this->spanborddet=array();
  1072. $this->blockjustfinished=false;
  1073. $this->listjustfinished=false;
  1074. $this->ignorefollowingspaces = true; //in order to eliminate exceeding left-side spaces
  1075. $this->toupper=false;
  1076. $this->tolower=false;
  1077. $this->capitalize=false;
  1078. $this->dash_on=false;
  1079. $this->dotted_on=false;
  1080. $this->SUP=false;
  1081. $this->SUB=false;
  1082. $this->strike=false;
  1083. $this->textshadow=''; // mPDF 5.3.A2
  1084. $this->currentfontfamily='';
  1085. $this->currentfontsize='';
  1086. $this->currentfontstyle='';
  1087. $this->colorarray=array();
  1088. $this->spanbgcolorarray=array();
  1089. $this->textbuffer=array();
  1090. $this->CSS=array();
  1091. $this->internallink=array();
  1092. $this->basepath = "";
  1093. $this->SetBasePath('');
  1094. $this->outlineparam = array();
  1095. $this->outline_on = false;
  1096. $this->specialcontent = '';
  1097. $this->selectoption = array();
  1098. /*-- IMPORTS --*/
  1099. $this->tpls = array();
  1100. $this->tpl = 0;
  1101. $this->tplprefix = "/TPL";
  1102. $this->res = array();
  1103. if ($this->enableImports) {
  1104. $this->SetImportUse();
  1105. }
  1106. /*-- END IMPORTS --*/
  1107. if ($this->progressBar) { $this->StartProgressBarOutput($this->progressBar) ; } // *PROGRESS-BAR*
  1108. }
  1109. function _setPageSize($format, &$orientation) {
  1110. //Page format
  1111. if(is_string($format))
  1112. {
  1113. if ($format=='') { $format = 'A4'; }
  1114. $pfo = 'P';
  1115. if(preg_match('/([0-9a-zA-Z]*)-L/i',$format,$m)) { // e.g. A4-L = A4 landscape
  1116. $format=$m[1];
  1117. $pfo='L';
  1118. }
  1119. $format = $this->_getPageFormat($format);
  1120. if (!$format) { $this->Error('Unknown page format: '.$format); }
  1121. else { $orientation = $pfo; }
  1122. $this->fwPt=$format[0];
  1123. $this->fhPt=$format[1];
  1124. }
  1125. else
  1126. {
  1127. if (!$format[0] || !$format[1]) { $this->Error('Invalid page format: '.$format[0].' '.$format[1]); }
  1128. $this->fwPt=$format[0]*_MPDFK;
  1129. $this->fhPt=$format[1]*_MPDFK;
  1130. }
  1131. $this->fw=$this->fwPt/_MPDFK;
  1132. $this->fh=$this->fhPt/_MPDFK;
  1133. //Page orientation
  1134. $orientation=strtolower($orientation);
  1135. if($orientation=='p' or $orientation=='portrait')
  1136. {
  1137. $orientation='P';
  1138. $this->wPt=$this->fwPt;
  1139. $this->hPt=$this->fhPt;
  1140. }
  1141. elseif($orientation=='l' or $orientation=='landscape')
  1142. {
  1143. $orientation='L';
  1144. $this->wPt=$this->fhPt;
  1145. $this->hPt=$this->fwPt;
  1146. }
  1147. else $this->Error('Incorrect orientation: '.$orientation);
  1148. $this->CurOrientation=$orientation;
  1149. $this->w=$this->wPt/_MPDFK;
  1150. $this->h=$this->hPt/_MPDFK;
  1151. }
  1152. function _getPageFormat($format) {
  1153. switch (strtoupper($format)) {
  1154. case '4A0': {$format = array(4767.87,6740.79); break;}
  1155. case '2A0': {$format = array(3370.39,4767.87); break;}
  1156. case 'A0': {$format = array(2383.94,3370.39); break;}
  1157. case 'A1': {$format = array(1683.78,2383.94); break;}
  1158. case 'A2': {$format = array(1190.55,1683.78); break;}
  1159. case 'A3': {$format = array(841.89,1190.55); break;}
  1160. case 'A4': default: {$format = array(595.28,841.89); break;}
  1161. case 'A5': {$format = array(419.53,595.28); break;}
  1162. case 'A6': {$format = array(297.64,419.53); break;}
  1163. case 'A7': {$format = array(209.76,297.64); break;}
  1164. case 'A8': {$format = array(147.40,209.76); break;}
  1165. case 'A9': {$format = array(104.88,147.40); break;}
  1166. case 'A10': {$format = array(73.70,104.88); break;}
  1167. case 'B0': {$format = array(2834.65,4008.19); break;}
  1168. case 'B1': {$format = array(2004.09,2834.65); break;}
  1169. case 'B2': {$format = array(1417.32,2004.09); break;}
  1170. case 'B3': {$format = array(1000.63,1417.32); break;}
  1171. case 'B4': {$format = array(708.66,1000.63); break;}
  1172. case 'B5': {$format = array(498.90,708.66); break;}
  1173. case 'B6': {$format = array(354.33,498.90); break;}
  1174. case 'B7': {$format = array(249.45,354.33); break;}
  1175. case 'B8': {$format = array(175.75,249.45); break;}
  1176. case 'B9': {$format = array(124.72,175.75); break;}
  1177. case 'B10': {$format = array(87.87,124.72); break;}
  1178. case 'C0': {$format = array(2599.37,3676.54); break;}
  1179. case 'C1': {$format = array(1836.85,2599.37); break;}
  1180. case 'C2': {$format = array(1298.27,1836.85); break;}
  1181. case 'C3': {$format = array(918.43,1298.27); break;}
  1182. case 'C4': {$format = array(649.13,918.43); break;}
  1183. case 'C5': {$format = array(459.21,649.13); break;}
  1184. case 'C6': {$format = array(323.15,459.21); break;}
  1185. case 'C7': {$format = array(229.61,323.15); break;}
  1186. case 'C8': {$format = array(161.57,229.61); break;}
  1187. case 'C9': {$format = array(113.39,161.57); break;}
  1188. case 'C10': {$format = array(79.37,113.39); break;}
  1189. case 'RA0': {$format = array(2437.80,3458.27); break;}
  1190. case 'RA1': {$format = array(1729.13,2437.80); break;}
  1191. case 'RA2': {$format = array(1218.90,1729.13); break;}
  1192. case 'RA3': {$format = array(864.57,1218.90); break;}
  1193. case 'RA4': {$format = array(609.45,864.57); break;}
  1194. case 'SRA0': {$format = array(2551.18,3628.35); break;}
  1195. case 'SRA1': {$format = array(1814.17,2551.18); break;}
  1196. case 'SRA2': {$format = array(1275.59,1814.17); break;}
  1197. case 'SRA3': {$format = array(907.09,1275.59); break;}
  1198. case 'SRA4': {$format = array(637.80,907.09); break;}
  1199. case 'LETTER': {$format = array(612.00,792.00); break;}
  1200. case 'LEGAL': {$format = array(612.00,1008.00); break;}
  1201. case 'LEDGER': {$format = array(279.00,432.00); break;} // mPDF 5.3.38
  1202. case 'TABLOID': {$format = array(279.00,432.00); break;} // mPDF 5.3.38
  1203. case 'EXECUTIVE': {$format = array(521.86,756.00); break;}
  1204. case 'FOLIO': {$format = array(612.00,936.00); break;}
  1205. case 'B': {$format=array(362.83,561.26 ); break;} // 'B' format paperback size 128x198mm
  1206. case 'A': {$format=array(314.65,504.57 ); break;} // 'A' format paperback size 111x178mm
  1207. case 'DEMY': {$format=array(382.68,612.28 ); break;} // 'Demy' format paperback size 135x216mm
  1208. case 'ROYAL': {$format=array(433.70,663.30 ); break;} // 'Royal' format paperback size 153x234mm
  1209. default: $format = false;
  1210. }
  1211. return $format;
  1212. }
  1213. /*-- PROGRESS-BAR --*/
  1214. function StartProgressBarOutput($mode=1) {
  1215. // must be relative path, or URI (not a file system path)
  1216. if (!defined('_MPDF_URI')) {
  1217. $this->progressBar = false;
  1218. if ($this->debug) { $this->Error("You need to define _MPDF_URI to use the progress bar!"); }
  1219. else return false;
  1220. }
  1221. $this->progressBar = $mode;
  1222. if ($this->progbar_altHTML) {
  1223. echo $this->progbar_altHTML;
  1224. }
  1225. else {
  1226. echo '<html>
  1227. <head>
  1228. <title>mPDF File Progress</title>
  1229. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  1230. <link rel="stylesheet" type="text/css" href="'._MPDF_URI.'progbar.css" />
  1231. </head>
  1232. <body>
  1233. <div class="main">
  1234. <div class="heading">'.$this->progbar_heading.'</div>
  1235. <div class="demo">
  1236. ';
  1237. if ($this->progressBar==2) { echo ' <table width="100%"><tr><td style="width: 50%;">
  1238. <span class="barheading">Writing HTML code</span> <br/>
  1239. <div class="progressBar">
  1240. <div id="element1" class="innerBar">&nbsp;</div>
  1241. </div>
  1242. <span class="code" id="box1"></span>
  1243. </td><td style="width: 50%;">
  1244. <span class="barheading">Autosizing elements</span> <br/>
  1245. <div class="progressBar">
  1246. <div id="element4" class="innerBar">&nbsp;</div>
  1247. </div>
  1248. <span class="code" id="box4"></span>
  1249. <br/><br/>
  1250. <span class="barheading">Writing Tables</span> <br/>
  1251. <div class="progressBar">
  1252. <div id="element7" class="innerBar">&nbsp;</div>
  1253. </div>
  1254. <span class="code" id="box7"></span>
  1255. </td></tr>
  1256. <tr><td><br /><br /></td><td></td></tr>
  1257. <tr><td style="width: 50%;">
  1258. '; }
  1259. echo ' <span class="barheading">Writing PDF file</span> <br/>
  1260. <div class="progressBar">
  1261. <div id="element2" class="innerBar">&nbsp;</div>
  1262. </div>
  1263. <span class="code" id="box2"></span>
  1264. ';
  1265. if ($this->progressBar==2) { echo '
  1266. </td><td style="width: 50%;">
  1267. <span class="barheading">Memory usage</span> <br/>
  1268. <div class="progressBar">
  1269. <div id="element5" class="innerBar">&nbsp;</div>
  1270. </div>
  1271. <span id="box5">0</span> '.ini_get("memory_limit").'<br />
  1272. <br/><br/>
  1273. <span class="barheading">Memory usage (peak)</span> <br/>
  1274. <div class="progressBar">
  1275. <div id="element6" class="innerBar">&nbsp;</div>
  1276. </div>
  1277. <span id="box6">0</span> '.ini_get("memory_limit").'<br />
  1278. </td></tr>
  1279. </table>
  1280. '; }
  1281. echo ' <br/><br/>
  1282. <span id="box3"></span>
  1283. </div>
  1284. ';
  1285. }
  1286. ob_flush();
  1287. flush();
  1288. }
  1289. function UpdateProgressBar($el,$val,$txt='') {
  1290. // $val should be a string - 5 = actual value, +15 = increment
  1291. if ($this->progressBar<2) {
  1292. if ($el>3) { return; }
  1293. else if ($el ==1) { $el = 2; }
  1294. }
  1295. echo '<script type="text/javascript">';
  1296. if ($val) { echo ' document.getElementById(\'element'.$el.'\').style.width=\''.$val.'%\'; '; }
  1297. if ($txt) { echo ' document.getElementById(\'box'.$el.'\').innerHTML=\''.$txt.'\'; '; }
  1298. if ($this->progressBar==2) {
  1299. $m = round(memory_get_usage(true)/1048576); // mPDF 5.3.72
  1300. $m2 = round(memory_get_peak_usage(true)/1048576); // mPDF 5.3.72
  1301. $mem = $m * 100 / (ini_get("memory_limit")+0);
  1302. $mem2 = $m2 * 100 / (ini_get("memory_limit")+0);
  1303. echo ' document.getElementById(\'element5\').style.width=\''.$mem.'%\'; ';
  1304. echo ' document.getElementById(\'element6\').style.width=\''.$mem2.'%\'; ';
  1305. echo ' document.getElementById(\'box5\').innerHTML=\''.$m.'MB / \'; ';
  1306. echo ' document.getElementById(\'box6\').innerHTML=\''.$m2.'MB / \'; ';
  1307. }
  1308. echo '</script>'."\n";
  1309. ob_flush();
  1310. flush();
  1311. }
  1312. /*-- END PROGRESS-BAR --*/
  1313. function RestrictUnicodeFonts($res) {
  1314. // $res = array of (Unicode) fonts to restrict to: e.g. norasi|norasiB - language specific
  1315. if (count($res)) { // Leave full list of available fonts if passed blank array
  1316. $this->available_unifonts = $res;
  1317. }
  1318. else { $this->available_unifonts = $this->default_available_fonts; }
  1319. if (count($this->available_unifonts) == 0) { $this->available_unifonts[] = $this->default_available_fonts[0]; }
  1320. $this->available_unifonts = array_values($this->available_unifonts);
  1321. }
  1322. function setMBencoding($enc) {
  1323. // mPDF 5.3.07
  1324. if ($this->mb_enc != $enc) {
  1325. $this->mb_enc = $enc;
  1326. mb_internal_encoding($this->mb_enc);
  1327. }
  1328. }
  1329. function SetMargins($left,$right,$top) {
  1330. //Set left, top and right margins
  1331. $this->lMargin=$left;
  1332. $this->rMargin=$right;
  1333. $this->tMargin=$top;
  1334. }
  1335. function ResetMargins() {
  1336. //ReSet left, top margins
  1337. if (($this->forcePortraitHeaders || $this->forcePortraitMargins) && $this->DefOrientation=='P' && $this->CurOrientation=='L') {
  1338. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  1339. $this->tMargin=$this->orig_rMargin;
  1340. $this->bMargin=$this->orig_lMargin;
  1341. }
  1342. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS
  1343. $this->tMargin=$this->orig_lMargin;
  1344. $this->bMargin=$this->orig_rMargin;
  1345. }
  1346. $this->lMargin=$this->DeflMargin;
  1347. $this->rMargin=$this->DefrMargin;
  1348. $this->MarginCorrection = 0;
  1349. $this->PageBreakTrigger=$this->h-$this->bMargin;
  1350. }
  1351. else if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  1352. $this->lMargin=$this->DefrMargin;
  1353. $this->rMargin=$this->DeflMargin;
  1354. $this->MarginCorrection = $this->DefrMargin-$this->DeflMargin;
  1355. }
  1356. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS
  1357. $this->lMargin=$this->DeflMargin;
  1358. $this->rMargin=$this->DefrMargin;
  1359. if ($this->mirrorMargins) { $this->MarginCorrection = $this->DeflMargin-$this->DefrMargin; }
  1360. }
  1361. $this->x=$this->lMargin;
  1362. }
  1363. function SetLeftMargin($margin) {
  1364. //Set left margin
  1365. $this->lMargin=$margin;
  1366. if($this->page>0 and $this->x<$margin) $this->x=$margin;
  1367. }
  1368. function SetTopMargin($margin) {
  1369. //Set top margin
  1370. $this->tMargin=$margin;
  1371. }
  1372. function SetRightMargin($margin) {
  1373. //Set right margin
  1374. $this->rMargin=$margin;
  1375. }
  1376. function SetAutoPageBreak($auto,$margin=0) {
  1377. //Set auto page break mode and triggering margin
  1378. $this->autoPageBreak=$auto;
  1379. $this->bMargin=$margin;
  1380. $this->PageBreakTrigger=$this->h-$margin;
  1381. }
  1382. function SetDisplayMode($zoom,$layout='continuous') {
  1383. //Set display mode in viewer
  1384. if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom))
  1385. $this->ZoomMode=$zoom;
  1386. else
  1387. $this->Error('Incorrect zoom display mode: '.$zoom);
  1388. if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='twoleft' or $layout=='tworight' or $layout=='default')
  1389. $this->LayoutMode=$layout;
  1390. else
  1391. $this->Error('Incorrect layout display mode: '.$layout);
  1392. }
  1393. function SetCompression($compress) {
  1394. //Set page compression
  1395. if(function_exists('gzcompress')) $this->compress=$compress;
  1396. else $this->compress=false;
  1397. }
  1398. function SetTitle($title) {
  1399. //Title of document // Arrives as UTF-8
  1400. $this->title = $title;
  1401. }
  1402. function SetSubject($subject) {
  1403. //Subject of document
  1404. $this->subject= $subject;
  1405. }
  1406. function SetAuthor($author) {
  1407. //Author of document
  1408. $this->author= $author;
  1409. }
  1410. function SetKeywords($keywords) {
  1411. //Keywords of document
  1412. $this->keywords= $keywords;
  1413. }
  1414. function SetCreator($creator) {
  1415. //Creator of document
  1416. $this->creator= $creator;
  1417. }
  1418. function SetAnchor2Bookmark($x) {
  1419. $this->anchor2Bookmark = $x;
  1420. }
  1421. function AliasNbPages($alias='{nb}') {
  1422. //Define an alias for total number of pages
  1423. $this->aliasNbPg=$alias;
  1424. }
  1425. function AliasNbPageGroups($alias='{nbpg}') {
  1426. //Define an alias for total number of pages in a group
  1427. $this->aliasNbPgGp=$alias;
  1428. }
  1429. function SetAlpha($alpha, $bm='Normal', $return=false, $mode='B') {
  1430. // alpha: real value from 0 (transparent) to 1 (opaque)
  1431. // bm: blend mode, one of the following:
  1432. // Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn,
  1433. // HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity
  1434. // set alpha for stroking (CA) and non-stroking (ca) operations
  1435. // mode determines F (fill) S (stroke) B (both)
  1436. if (($this->PDFA || $this->PDFX) && $alpha!=1) {
  1437. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "Image opacity must be 100% (Opacity changed to 100%)"; }
  1438. $alpha = 1;
  1439. }
  1440. $a = array('BM'=>'/'.$bm);
  1441. if ($mode=='F' || $mode='B') $a['ca'] = $alpha;
  1442. if ($mode=='S' || $mode='B') $a['CA'] = $alpha;
  1443. $gs = $this->AddExtGState($a);
  1444. if ($return) { return sprintf('/GS%d gs', $gs); }
  1445. else { $this->_out(sprintf('/GS%d gs', $gs)); }
  1446. }
  1447. function AddExtGState($parms) {
  1448. $n = count($this->extgstates);
  1449. // check if graphics state already exists
  1450. for ($i=1; $i<=$n; $i++) {
  1451. if (count($this->extgstates[$i]['parms']) == count($parms)) {
  1452. $same = true;
  1453. foreach($this->extgstates[$i]['parms'] AS $k=>$v) {
  1454. if (!isset($parms[$k]) || $parms[$k] != $v) { $same = false; break; }
  1455. }
  1456. if ($same) { return $i; }
  1457. }
  1458. }
  1459. $n++;
  1460. $this->extgstates[$n]['parms'] = $parms;
  1461. return $n;
  1462. }
  1463. // mPDF 5.3.41
  1464. function SetVisibility($v) {
  1465. if (($this->PDFA || $this->PDFX) && $this->visibility!='visible') { $this->PDFAXwarnings[] = "Cannot set visibility to anything other than full when using PDFA or PDFX"; return ''; }
  1466. else if (!$this->PDFA && !$this->PDFX) // mPDF 5.3.45
  1467. $this->pdf_version='1.5';
  1468. if($this->visibility!='visible') {
  1469. $this->_out('EMC');
  1470. $this->hasOC = true; // mPDF 5.3.45
  1471. }
  1472. if($v=='printonly')
  1473. $this->_out('/OC /OC1 BDC');
  1474. elseif($v=='screenonly')
  1475. $this->_out('/OC /OC2 BDC');
  1476. elseif($v=='hidden')
  1477. $this->_out('/OC /OC3 BDC');
  1478. elseif($v!='visible')
  1479. $this->Error('Incorrect visibility: '.$v);
  1480. $this->visibility=$v;
  1481. }
  1482. function Error($msg) {
  1483. //Fatal error
  1484. header('Content-Type: text/html; charset=utf-8');
  1485. die('<B>mPDF error: </B>'.$msg);
  1486. }
  1487. function Open() {
  1488. //Begin document
  1489. if($this->state==0) $this->_begindoc();
  1490. }
  1491. function Close() {
  1492. if ($this->progressBar) { $this->UpdateProgressBar(2,'2','Closing last page'); } // *PROGRESS-BAR*
  1493. //Terminate document
  1494. if($this->state==3) return;
  1495. if($this->page==0) $this->AddPage($this->CurOrientation);
  1496. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); } // *TABLES*
  1497. if ($this->tablebuffer) { $this->printtablebuffer(); } // *TABLES*
  1498. /*-- COLUMNS --*/
  1499. if ($this->ColActive) {
  1500. $this->SetColumns(0);
  1501. $this->ColActive = 0;
  1502. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  1503. }
  1504. /*-- END COLUMNS --*/
  1505. if (count($this->divbuffer)) { $this->printdivbuffer(); }
  1506. // BODY Backgrounds
  1507. $s = '';
  1508. $s .= $this->PrintBodyBackgrounds();
  1509. $s .= $this->PrintPageBackgrounds();
  1510. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$s."\n".'\\1', $this->pages[$this->page]);
  1511. $this->pageBackgrounds = array();
  1512. // mPDF 5.3.41
  1513. if($this->visibility!='visible')
  1514. $this->SetVisibility('visible');
  1515. if (!$this->tocontents || !$this->tocontents->TOCmark) { //Page footer
  1516. $this->InFooter=true;
  1517. $this->Footer();
  1518. $this->InFooter=false;
  1519. }
  1520. if ($this->tocontents && ($this->tocontents->TOCmark || count($this->tocontents->m_TOC))) { $this->tocontents->insertTOC(); } // *TOC*
  1521. //Close page
  1522. $this->_endpage();
  1523. //Close document
  1524. $this->_enddoc();
  1525. }
  1526. /*-- BACKGROUNDS --*/
  1527. function _resizeBackgroundImage($imw, $imh, $cw, $ch, $resize=0, $repx, $repy) {
  1528. $cw = $cw*_MPDFK;
  1529. $ch = $ch*_MPDFK;
  1530. if (!$resize) { return array($imw, $imh, $repx, $repy); }
  1531. if ($resize==1 && $imw > $cw) {
  1532. $h = $imh * $cw/$imw;
  1533. $repx = false;
  1534. return array($cw, $h, $repx, $repy);
  1535. }
  1536. else if ($resize==2 && $imh > $ch) {
  1537. $w = $imw * $ch/$imh;
  1538. $repy = false;
  1539. return array($w, $ch, $repx, $repy);
  1540. }
  1541. else if ($resize==3) {
  1542. $w = $imw;
  1543. $h = $imh;
  1544. $saverepx = $repx;
  1545. if ($w > $cw) {
  1546. $h = $h * $cw/$w;
  1547. $w = $cw;
  1548. $repx = false;
  1549. }
  1550. if ($h > $ch) {
  1551. $w = $w * $ch/$h;
  1552. $h = $ch;
  1553. $repy = false;
  1554. $repx = $saverepx;
  1555. }
  1556. return array($w, $h, $repx, $repy);
  1557. }
  1558. else if ($resize==4) {
  1559. $h = $imh * $cw/$imw;
  1560. $repx = false;
  1561. return array($cw, $h, $repx, $repy);
  1562. }
  1563. else if ($resize==5) {
  1564. $w = $imw * $ch/$imh;
  1565. $repy = false;
  1566. return array($w, $ch, $repx, $repy);
  1567. }
  1568. else if ($resize==6) {
  1569. $repx = false;
  1570. $repy = false;
  1571. return array($cw, $ch, $repx, $repy);
  1572. }
  1573. return array($imw, $imh, $repx, $repy);
  1574. }
  1575. function SetBackground(&$properties, &$maxwidth) {
  1576. if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/',$properties['BACKGROUND-IMAGE'])) {
  1577. return array('gradient'=>$properties['BACKGROUND-IMAGE']);
  1578. }
  1579. else {
  1580. $file = $properties['BACKGROUND-IMAGE'];
  1581. $sizesarray = $this->Image($file,0,0,0,0,'','',false, false, false, false, true);
  1582. if (isset($sizesarray['IMAGE_ID'])) {
  1583. $image_id = $sizesarray['IMAGE_ID'];
  1584. $orig_w = $sizesarray['WIDTH']*_MPDFK; // in user units i.e. mm
  1585. $orig_h = $sizesarray['HEIGHT']*_MPDFK; // (using $this->img_dpi)
  1586. if (isset($properties['BACKGROUND-IMAGE-RESOLUTION'])) {
  1587. if (preg_match('/from-image/i', $properties['BACKGROUND-IMAGE-RESOLUTION']) && isset($sizesarray['set-dpi']) && $sizesarray['set-dpi']>0) {
  1588. $orig_w *= $this->img_dpi / $sizesarray['set-dpi'];
  1589. $orig_h *= $this->img_dpi / $sizesarray['set-dpi'];
  1590. }
  1591. else if (preg_match('/(\d+)dpi/i', $properties['BACKGROUND-IMAGE-RESOLUTION'], $m)) {
  1592. $dpi = $m[1];
  1593. if ($dpi > 0) {
  1594. $orig_w *= $this->img_dpi / $dpi;
  1595. $orig_h *= $this->img_dpi / $dpi;
  1596. }
  1597. }
  1598. }
  1599. $x_repeat = true;
  1600. $y_repeat = true;
  1601. if (isset($properties['BACKGROUND-REPEAT'])) {
  1602. if ($properties['BACKGROUND-REPEAT']=='no-repeat' || $properties['BACKGROUND-REPEAT']=='repeat-x') { $y_repeat = false; }
  1603. if ($properties['BACKGROUND-REPEAT']=='no-repeat' || $properties['BACKGROUND-REPEAT']=='repeat-y') { $x_repeat = false; }
  1604. }
  1605. $x_pos = 0;
  1606. $y_pos = 0;
  1607. if (isset($properties['BACKGROUND-POSITION'])) {
  1608. $ppos = preg_split('/\s+/',$properties['BACKGROUND-POSITION']);
  1609. $x_pos = $ppos[0];
  1610. $y_pos = $ppos[1];
  1611. if (!stristr($x_pos ,'%') ) { $x_pos = $this->ConvertSize($x_pos ,$maxwidth,$this->FontSize); }
  1612. if (!stristr($y_pos ,'%') ) { $y_pos = $this->ConvertSize($y_pos ,$maxwidth,$this->FontSize); }
  1613. }
  1614. if (isset($properties['BACKGROUND-IMAGE-RESIZE'])) { $resize = $properties['BACKGROUND-IMAGE-RESIZE']; }
  1615. else { $resize = 0; }
  1616. if (isset($properties['BACKGROUND-IMAGE-OPACITY'])) { $opacity = $properties['BACKGROUND-IMAGE-OPACITY']; }
  1617. else { $opacity = 1; }
  1618. return array('image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$sizesarray['itype']);
  1619. }
  1620. }
  1621. return false;
  1622. }
  1623. /*-- END BACKGROUNDS --*/
  1624. function PrintBodyBackgrounds() {
  1625. $s = '';
  1626. $clx = 0;
  1627. $cly = 0;
  1628. $clw = $this->w;
  1629. $clh = $this->h;
  1630. // If using bleed and trim margins in paged media
  1631. if ($this->pageDim[$this->page]['outer_width_LR'] || $this->pageDim[$this->page]['outer_width_TB']) {
  1632. $clx = $this->pageDim[$this->page]['outer_width_LR'] - $this->pageDim[$this->page]['bleedMargin'];
  1633. $cly = $this->pageDim[$this->page]['outer_width_TB'] - $this->pageDim[$this->page]['bleedMargin'];
  1634. $clw = $this->w - 2*$clx;
  1635. $clh = $this->h - 2*$cly;
  1636. }
  1637. if ($this->bodyBackgroundColor) {
  1638. $s .= 'q ' .$this->SetFColor($this->bodyBackgroundColor, true)."\n";
  1639. // mPDF 5.3.74
  1640. if ($this->bodyBackgroundColor{0}==5) { // RGBa
  1641. $s .= $this->SetAlpha(ord($this->bodyBackgroundColor{4})/100, 'Normal', true, 'F')."\n";
  1642. }
  1643. else if ($this->bodyBackgroundColor{0}==6) { // CMYKa
  1644. $s .= $this->SetAlpha(ord($this->bodyBackgroundColor{5})/100, 'Normal', true, 'F')."\n";
  1645. }
  1646. $s .= sprintf('%.3F %.3F %.3F %.3F re f Q', ($clx*_MPDFK), ($cly*_MPDFK),$clw*_MPDFK,$clh*_MPDFK)."\n";
  1647. }
  1648. /*-- BACKGROUNDS --*/
  1649. if ($this->bodyBackgroundGradient) {
  1650. $g = $this->grad->parseBackgroundGradient($this->bodyBackgroundGradient);
  1651. if ($g) {
  1652. $s .= $this->grad->Gradient($clx, $cly, $clw, $clh, (isset($g['gradtype']) ? $g['gradtype'] : null), $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true);
  1653. }
  1654. }
  1655. if ($this->bodyBackgroundImage) {
  1656. if ( $this->bodyBackgroundImage['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $this->bodyBackgroundImage['gradient'])) {
  1657. $g = $this->grad->parseMozGradient( $this->bodyBackgroundImage['gradient']);
  1658. if ($g) {
  1659. $s .= $this->grad->Gradient($clx, $cly, $clw, $clh, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true);
  1660. }
  1661. }
  1662. else if ($this->bodyBackgroundImage['image_id']) { // Background pattern
  1663. $n = count($this->patterns)+1;
  1664. // If using resize, uses TrimBox (not including the bleed)
  1665. list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this->_resizeBackgroundImage($this->bodyBackgroundImage['orig_w'], $this->bodyBackgroundImage['orig_h'], $clw, $clh, $this->bodyBackgroundImage['resize'], $this->bodyBackgroundImage['x_repeat'], $this->bodyBackgroundImage['y_repeat']);
  1666. $this->patterns[$n] = array('x'=>$clx, 'y'=>$cly, 'w'=>$clw, 'h'=>$clh, 'pgh'=>$this->h, 'image_id'=>$this->bodyBackgroundImage['image_id'], 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$this->bodyBackgroundImage['x_pos'], 'y_pos'=>$this->bodyBackgroundImage['y_pos'], 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'itype'=>$this->bodyBackgroundImage['itype']);
  1667. // mPDF 5.3.12
  1668. if (($this->bodyBackgroundImage['opacity']>0 || $this->bodyBackgroundImage['opacity']==='0') && $this->bodyBackgroundImage['opacity']<1) { $opac = $this->SetAlpha($this->bodyBackgroundImage['opacity'],'Normal',true); }
  1669. else { $opac = ''; }
  1670. $s .= sprintf('q /Pattern cs /P%d scn %s %.3F %.3F %.3F %.3F re f Q', $n, $opac, ($clx*_MPDFK), ($cly*_MPDFK),$clw*_MPDFK, $clh*_MPDFK) ."\n";
  1671. }
  1672. }
  1673. /*-- END BACKGROUNDS --*/
  1674. return $s;
  1675. }
  1676. function PrintPageBackgrounds($adjustmenty=0) {
  1677. $s = '';
  1678. ksort($this->pageBackgrounds);
  1679. foreach($this->pageBackgrounds AS $bl=>$pbs) {
  1680. foreach ($pbs AS $pb) {
  1681. // mPDF 5.3.A1
  1682. if ((!isset($pb['image_id']) && !isset($pb['gradient'])) || isset($pb['shadowonly'])) { // Background colour or boxshadow
  1683. // mPDF 5.3.42 VISIBILITY
  1684. if($pb['visibility']!='visible') {
  1685. if($pb['visibility']=='printonly')
  1686. $s .= '/OC /OC1 BDC'."\n";
  1687. else if($pb['visibility']=='screenonly')
  1688. $s .= '/OC /OC2 BDC'."\n";
  1689. else if($pb['visibility']=='hidden')
  1690. $s .= '/OC /OC3 BDC'."\n";
  1691. }
  1692. // mPDF 5.3.A1
  1693. // Box shadow
  1694. if (isset($pb['shadow']) && $pb['shadow']) { $s .= $pb['shadow']."\n"; }
  1695. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1696. $s .= 'q '.$this->SetFColor($pb['col'], true)."\n";
  1697. // mPDF 5.3.74
  1698. if ($pb['col']{0}==5) { // RGBa
  1699. $s .= $this->SetAlpha(ord($pb['col']{4})/100, 'Normal', true, 'F')."\n";
  1700. }
  1701. else if ($pb['col']{0}==6) { // CMYKa
  1702. $s .= $this->SetAlpha(ord($pb['col']{5})/100, 'Normal', true, 'F')."\n";
  1703. }
  1704. $s .= sprintf('%.3F %.3F %.3F %.3F re f Q',$pb['x']*_MPDFK,($this->h-$pb['y'])*_MPDFK,$pb['w']*_MPDFK,-$pb['h']*_MPDFK)."\n";
  1705. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1706. // mPDF 5.3.42
  1707. if($pb['visibility']!='visible')
  1708. $s .= 'EMC'."\n";
  1709. }
  1710. }
  1711. /*-- BACKGROUNDS --*/
  1712. foreach ($pbs AS $pb) {
  1713. // mPDF 5.3.42 VISIBILITY
  1714. if($pb['visibility']!='visible') {
  1715. if($pb['visibility']=='printonly')
  1716. $s .= '/OC /OC1 BDC'."\n";
  1717. else if($pb['visibility']=='screenonly')
  1718. $s .= '/OC /OC2 BDC'."\n";
  1719. else if($pb['visibility']=='hidden')
  1720. $s .= '/OC /OC3 BDC'."\n";
  1721. }
  1722. if (isset($pb['gradient']) && $pb['gradient']) {
  1723. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1724. $s .= $this->grad->Gradient($pb['x'], $pb['y'], $pb['w'], $pb['h'], $pb['gradtype'], $pb['stops'], $pb['colorspace'], $pb['coords'], $pb['extend'], true);
  1725. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1726. }
  1727. else if (isset($pb['image_id']) && $pb['image_id']) { // Background pattern
  1728. $pb['y'] -= $adjustmenty;
  1729. $pb['h'] += $adjustmenty;
  1730. $n = count($this->patterns)+1;
  1731. list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this->_resizeBackgroundImage($pb['orig_w'], $pb['orig_h'], $pb['w'], $pb['h'], $pb['resize'], $pb['x_repeat'], $pb['y_repeat']);
  1732. $this->patterns[$n] = array('x'=>$pb['x'], 'y'=>$pb['y'], 'w'=>$pb['w'], 'h'=>$pb['h'], 'pgh'=>$this->h, 'image_id'=>$pb['image_id'], 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$pb['x_pos'], 'y_pos'=>$pb['y_pos'], 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'itype'=>$pb['itype']);
  1733. $x = $pb['x']*_MPDFK;
  1734. $y = ($this->h - $pb['y'])*_MPDFK;
  1735. $w = $pb['w']*_MPDFK;
  1736. $h = -$pb['h']*_MPDFK;
  1737. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1738. if ($this->writingHTMLfooter || $this->writingHTMLheader) {
  1739. $iw = $pb['orig_w']/_MPDFK;
  1740. $ih = $pb['orig_h']/_MPDFK;
  1741. $w = $pb['w'];
  1742. $h = $pb['h'];
  1743. $x0 = $pb['x'];
  1744. $y0 = $pb['y'];
  1745. // Number to repeat
  1746. if ($pb['x_repeat']) { $nx = ceil($w/$iw); }
  1747. else { $nx = 1; }
  1748. if ($pb['y_repeat']) { $ny = ceil($h/$ih); }
  1749. else { $ny = 1; }
  1750. $x_pos = $pb['x_pos'];
  1751. if (stristr($x_pos ,'%') ) {
  1752. $x_pos += 0;
  1753. $x_pos /= 100;
  1754. $x_pos = ($w * $x_pos) - ($iw * $x_pos);
  1755. }
  1756. $y_pos = $pb['y_pos'];
  1757. if (stristr($y_pos ,'%') ) {
  1758. $y_pos += 0;
  1759. $y_pos /= 100;
  1760. $y_pos = ($h * $y_pos) - ($ih * $y_pos);
  1761. }
  1762. if ($nx>1) {
  1763. while($x_pos>0) { $x_pos -= $iw; }
  1764. }
  1765. if ($ny>1) {
  1766. while($y_pos>0) { $y_pos -= $ih; }
  1767. }
  1768. for($xi=0;$xi<$nx;$xi++) {
  1769. for($yi=0;$yi<$ny;$yi++) {
  1770. $x = $x0 + $x_pos + ($iw*$xi);
  1771. $y = $y0 + $y_pos + ($ih*$yi);
  1772. if ($pb['opacity']>0 && $pb['opacity']<1) { $opac = $this->SetAlpha($pb['opacity'],'Normal',true); }
  1773. else { $opac = ''; }
  1774. $s .= sprintf("q %s %.3F 0 0 %.3F %.3F %.3F cm /I%d Do Q", $opac,$iw*_MPDFK,$ih*_MPDFK,$x*_MPDFK,($this->h-($y+$ih))*_MPDFK,$pb['image_id']) ."\n";
  1775. }
  1776. }
  1777. }
  1778. else {
  1779. // mPDF 5.3.12
  1780. if (($pb['opacity']>0 || $pb['opacity']==='0') && $pb['opacity']<1) { $opac = $this->SetAlpha($pb['opacity'],'Normal',true); }
  1781. else { $opac = ''; }
  1782. $s .= sprintf('q /Pattern cs /P%d scn %s %.3F %.3F %.3F %.3F re f Q', $n, $opac, $x, $y, $w, $h) ."\n";
  1783. }
  1784. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1785. }
  1786. // mPDF 5.3.42 VISIBILITY
  1787. if($pb['visibility']!='visible')
  1788. $s .= 'EMC'."\n";
  1789. }
  1790. /*-- END BACKGROUNDS --*/
  1791. }
  1792. return $s;
  1793. }
  1794. function PrintTableBackgrounds($adjustmenty=0) {
  1795. $s = '';
  1796. /*-- BACKGROUNDS --*/
  1797. ksort($this->tableBackgrounds);
  1798. foreach($this->tableBackgrounds AS $bl=>$pbs) {
  1799. foreach ($pbs AS $pb) {
  1800. if ((!isset($pb['gradient']) || !$pb['gradient']) && (!isset($pb['image_id']) || !$pb['image_id'])) {
  1801. $s .= 'q '.$this->SetFColor($pb['col'], true)."\n"; // mPDF 5.3.68
  1802. // mPDF 5.3.68
  1803. // mPDF 5.3.74
  1804. if ($pb['col']{0}==5) { // RGBa
  1805. $s .= $this->SetAlpha(ord($pb['col']{4})/100, 'Normal', true, 'F')."\n";
  1806. }
  1807. else if ($pb['col']{0}==6) { // CMYKa
  1808. $s .= $this->SetAlpha(ord($pb['col']{5})/100, 'Normal', true, 'F')."\n";
  1809. }
  1810. $s .= sprintf('%.3F %.3F %.3F %.3F re %s Q',$pb['x']*_MPDFK,($this->h-$pb['y'])*_MPDFK,$pb['w']*_MPDFK,-$pb['h']*_MPDFK,'f')."\n"; // mPDF 5.3.68
  1811. }
  1812. if (isset($pb['gradient']) && $pb['gradient']) {
  1813. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1814. $s .= $this->grad->Gradient($pb['x'], $pb['y'], $pb['w'], $pb['h'], $pb['gradtype'], $pb['stops'], $pb['colorspace'], $pb['coords'], $pb['extend'], true);
  1815. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1816. }
  1817. if (isset($pb['image_id']) && $pb['image_id']) { // Background pattern
  1818. $pb['y'] -= $adjustmenty;
  1819. $pb['h'] += $adjustmenty;
  1820. $n = count($this->patterns)+1;
  1821. list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this->_resizeBackgroundImage($pb['orig_w'], $pb['orig_h'], $pb['w'], $pb['h'], $pb['resize'], $pb['x_repeat'], $pb['y_repeat']);
  1822. $this->patterns[$n] = array('x'=>$pb['x'], 'y'=>$pb['y'], 'w'=>$pb['w'], 'h'=>$pb['h'], 'pgh'=>$this->h, 'image_id'=>$pb['image_id'], 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$pb['x_pos'], 'y_pos'=>$pb['y_pos'], 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'itype'=>$pb['itype']);
  1823. $x = $pb['x']*_MPDFK;
  1824. $y = ($this->h - $pb['y'])*_MPDFK;
  1825. $w = $pb['w']*_MPDFK;
  1826. $h = -$pb['h']*_MPDFK;
  1827. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1828. if ($pb['opacity']>0 && $pb['opacity']<1) { $opac = $this->SetAlpha($pb['opacity'],'Normal',true); }
  1829. else { $opac = ''; }
  1830. $s .= sprintf('q /Pattern cs /P%d scn %s %.3F %.3F %.3F %.3F re f Q', $n, $opac, $x, $y, $w, $h) ."\n";
  1831. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1832. }
  1833. }
  1834. }
  1835. /*-- END BACKGROUNDS --*/
  1836. return $s;
  1837. }
  1838. // Depracated - can use AddPage for all
  1839. function AddPages($orientation='',$condition='', $resetpagenum='', $pagenumstyle='', $suppress='',$mgl='',$mgr='',$mgt='',$mgb='',$mgh='',$mgf='',$ohname='',$ehname='',$ofname='',$efname='',$ohvalue=0,$ehvalue=0,$ofvalue=0,$efvalue=0,$pagesel='',$newformat='')
  1840. {
  1841. $this->AddPage($orientation,$condition,$resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf, $ohname, $ehname, $ofname, $efname, $ohvalue, $ehvalue, $ofvalue, $efvalue,$pagesel,$newformat);
  1842. }
  1843. function AddPageByArray($a) {
  1844. if (!is_array($a)) { $a = array(); }
  1845. // mPDF 5.3.26
  1846. $orientation = (isset($a['orientation']) ? $a['orientation'] : '');
  1847. $condition = (isset($a['condition']) ? $a['condition'] : (isset($a['type']) ? $a['type'] : ''));
  1848. $resetpagenum = (isset($a['resetpagenum']) ? $a['resetpagenum'] : '');
  1849. $pagenumstyle = (isset($a['pagenumstyle']) ? $a['pagenumstyle'] : '');
  1850. $suppress = (isset($a['suppress']) ? $a['suppress'] : '');
  1851. $mgl = (isset($a['mgl']) ? $a['mgl'] : (isset($a['margin-left']) ? $a['margin-left'] : ''));
  1852. $mgr = (isset($a['mgr']) ? $a['mgr'] : (isset($a['margin-right']) ? $a['margin-right'] : ''));
  1853. $mgt = (isset($a['mgt']) ? $a['mgt'] : (isset($a['margin-top']) ? $a['margin-top'] : ''));
  1854. $mgb = (isset($a['mgb']) ? $a['mgb'] : (isset($a['margin-bottom']) ? $a['margin-bottom'] : ''));
  1855. $mgh = (isset($a['mgh']) ? $a['mgh'] : (isset($a['margin-header']) ? $a['margin-header'] : ''));
  1856. $mgf = (isset($a['mgf']) ? $a['mgf'] : (isset($a['margin-footer']) ? $a['margin-footer'] : ''));
  1857. $ohname = (isset($a['ohname']) ? $a['ohname'] : (isset($a['odd-header-name']) ? $a['odd-header-name'] : ''));
  1858. $ehname = (isset($a['ehname']) ? $a['ehname'] : (isset($a['even-header-name']) ? $a['even-header-name'] : ''));
  1859. $ofname = (isset($a['ofname']) ? $a['ofname'] : (isset($a['odd-footer-name']) ? $a['odd-footer-name'] : ''));
  1860. $efname = (isset($a['efname']) ? $a['efname'] : (isset($a['even-footer-name']) ? $a['even-footer-name'] : ''));
  1861. $ohvalue = (isset($a['ohvalue']) ? $a['ohvalue'] : (isset($a['odd-header-value']) ? $a['odd-header-value'] : 0));
  1862. $ehvalue = (isset($a['ehvalue']) ? $a['ehvalue'] : (isset($a['even-header-value']) ? $a['even-header-value'] : 0));
  1863. $ofvalue = (isset($a['ofvalue']) ? $a['ofvalue'] : (isset($a['odd-footer-value']) ? $a['odd-footer-value'] : 0));
  1864. $efvalue = (isset($a['efvalue']) ? $a['efvalue'] : (isset($a['even-footer-value']) ? $a['even-footer-value'] : 0));
  1865. $pagesel = (isset($a['pagesel']) ? $a['pagesel'] : (isset($a['pageselector']) ? $a['pageselector'] : ''));
  1866. $newformat = (isset($a['newformat']) ? $a['newformat'] : (isset($a['sheet-size']) ? $a['sheet-size'] : ''));
  1867. $this->AddPage($orientation,$condition,$resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf, $ohname, $ehname, $ofname, $efname, $ohvalue, $ehvalue, $ofvalue, $efvalue,$pagesel,$newformat);
  1868. }
  1869. function AddPage($orientation='',$condition='', $resetpagenum='', $pagenumstyle='', $suppress='',$mgl='',$mgr='',$mgt='',$mgb='',$mgh='',$mgf='',$ohname='',$ehname='',$ofname='',$efname='',$ohvalue=0,$ehvalue=0,$ofvalue=0,$efvalue=0,$pagesel='',$newformat='')
  1870. {
  1871. /*-- CSS-FLOAT --*/
  1872. // Float DIV
  1873. // Cannot do with columns on, or if any change in page orientation/margins etc.
  1874. // If next page already exists - i.e background /headers and footers already written
  1875. if ($this->state > 0 && $this->page < count($this->pages)) {
  1876. $bak_cml = $this->cMarginL;
  1877. $bak_cmr = $this->cMarginR;
  1878. $bak_dw = $this->divwidth;
  1879. // Paint Div Border if necessary
  1880. if ($this->blklvl > 0) {
  1881. $save_tr = $this->table_rotate; // *TABLES*
  1882. $this->table_rotate = 0; // *TABLES*
  1883. if ($this->y == $this->blk[$this->blklvl]['y0']) { $this->blk[$this->blklvl]['startpage']++; }
  1884. if (($this->y > $this->blk[$this->blklvl]['y0']) || $this->flowingBlockAttr['is_table'] ) { $toplvl = $this->blklvl; }
  1885. else { $toplvl = $this->blklvl-1; }
  1886. $sy = $this->y;
  1887. for ($bl=1;$bl<=$toplvl;$bl++) {
  1888. $this->PaintDivBB('pagebottom',0,$bl);
  1889. }
  1890. $this->y = $sy;
  1891. $this->table_rotate = $save_tr; // *TABLES*
  1892. }
  1893. $s = $this->PrintPageBackgrounds();
  1894. // Writes after the marker so not overwritten later by page background etc.
  1895. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  1896. $this->pageBackgrounds = array();
  1897. $family=$this->FontFamily;
  1898. $style=$this->FontStyle.($this->U ? 'U' : '').($this->S ? 'S' : '');
  1899. $size=$this->FontSizePt;
  1900. $lw=$this->LineWidth;
  1901. $dc=$this->DrawColor;
  1902. $fc=$this->FillColor;
  1903. $tc=$this->TextColor;
  1904. $cf=$this->ColorFlag;
  1905. $this->printfloatbuffer();
  1906. //Move to next page
  1907. $this->page++;
  1908. $this->ResetMargins();
  1909. $this->SetAutoPageBreak($this->autoPageBreak,$this->bMargin);
  1910. $this->x=$this->lMargin;
  1911. $this->y=$this->tMargin;
  1912. $this->FontFamily='';
  1913. $this->_out('2 J');
  1914. $this->LineWidth=$lw;
  1915. $this->_out(sprintf('%.3F w',$lw*_MPDFK));
  1916. if($family) $this->SetFont($family,$style,$size,true,true);
  1917. $this->DrawColor=$dc;
  1918. if($dc!=$this->defDrawColor) $this->_out($dc);
  1919. $this->FillColor=$fc;
  1920. if($fc!=$this->defFillColor) $this->_out($fc);
  1921. $this->TextColor=$tc;
  1922. $this->ColorFlag=$cf;
  1923. for($bl=1;$bl<=$this->blklvl;$bl++) {
  1924. $this->blk[$bl]['y0'] = $this->y;
  1925. // Don't correct more than once for background DIV containing a Float
  1926. if (!isset($this->blk[$bl]['marginCorrected'][$this->page])) { $this->blk[$bl]['x0'] += $this->MarginCorrection; }
  1927. $this->blk[$bl]['marginCorrected'][$this->page] = true;
  1928. }
  1929. $this->cMarginL = $bak_cml;
  1930. $this->cMarginR = $bak_cmr;
  1931. $this->divwidth = $bak_dw;
  1932. return '';
  1933. }
  1934. /*-- END CSS-FLOAT --*/
  1935. //Start a new page
  1936. if($this->state==0) $this->Open();
  1937. $bak_cml = $this->cMarginL;
  1938. $bak_cmr = $this->cMarginR;
  1939. $bak_dw = $this->divwidth;
  1940. $bak_lh = $this->lineheight;
  1941. $orientation = substr(strtoupper($orientation),0,1);
  1942. $condition = strtoupper($condition);
  1943. if ($condition == 'NEXT-EVEN') { // always adds at least one new page to create an Even page
  1944. if (!$this->mirrorMargins) { $condition = ''; }
  1945. else {
  1946. if ($pagesel) { $pbch = $pagesel; $pagesel = ''; } // *CSS-PAGE*
  1947. else { $pbch = false; } // *CSS-PAGE*
  1948. $this->AddPage($this->CurOrientation,'O');
  1949. if ($pbch ) { $pagesel = $pbch; } // *CSS-PAGE*
  1950. $condition = '';
  1951. }
  1952. }
  1953. if ($condition == 'NEXT-ODD') { // always adds at least one new page to create an Odd page
  1954. if (!$this->mirrorMargins) { $condition = ''; }
  1955. else {
  1956. if ($pagesel) { $pbch = $pagesel; $pagesel = ''; } // *CSS-PAGE*
  1957. else { $pbch = false; } // *CSS-PAGE*
  1958. $this->AddPage($this->CurOrientation,'E');
  1959. if ($pbch ) { $pagesel = $pbch; } // *CSS-PAGE*
  1960. $condition = '';
  1961. }
  1962. }
  1963. if ($condition == 'E') { // only adds new page if needed to create an Even page
  1964. if (!$this->mirrorMargins || ($this->page)%2==0) { return false; }
  1965. }
  1966. if ($condition == 'O') { // only adds new page if needed to create an Odd page
  1967. if (!$this->mirrorMargins || ($this->page)%2==1) { return false; }
  1968. }
  1969. if ($resetpagenum || $pagenumstyle || $suppress) {
  1970. $this->PageNumSubstitutions[] = array('from'=>($this->page+1), 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=>$suppress);
  1971. }
  1972. $save_tr = $this->table_rotate; // *TABLES*
  1973. $this->table_rotate = 0; // *TABLES*
  1974. $save_kwt = $this->kwt;
  1975. $this->kwt = 0;
  1976. // Paint Div Border if necessary
  1977. //PAINTS BACKGROUND COLOUR OR BORDERS for DIV - DISABLED FOR COLUMNS (cf. AcceptPageBreak) AT PRESENT in ->PaintDivBB
  1978. if (!$this->ColActive && $this->blklvl > 0) {
  1979. if (isset($this->blk[$this->blklvl]['y0']) && $this->y == $this->blk[$this->blklvl]['y0']) {
  1980. if (isset($this->blk[$this->blklvl]['startpage'])) { $this->blk[$this->blklvl]['startpage']++; }
  1981. else { $this->blk[$this->blklvl]['startpage'] = 1; }
  1982. }
  1983. if ((isset($this->blk[$this->blklvl]['y0']) && $this->y > $this->blk[$this->blklvl]['y0']) || $this->flowingBlockAttr['is_table'] ) { $toplvl = $this->blklvl; }
  1984. else { $toplvl = $this->blklvl-1; }
  1985. $sy = $this->y;
  1986. for ($bl=1;$bl<=$toplvl;$bl++) {
  1987. $this->PaintDivBB('pagebottom',0,$bl);
  1988. }
  1989. $this->y = $sy;
  1990. // RESET block y0 and x0 - see below
  1991. }
  1992. // BODY Backgrounds
  1993. if ($this->page > 0) {
  1994. $s = '';
  1995. $s .= $this->PrintBodyBackgrounds();
  1996. $s .= $this->PrintPageBackgrounds();
  1997. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$s."\n".'\\1', $this->pages[$this->page]);
  1998. $this->pageBackgrounds = array();
  1999. }
  2000. $save_kt = $this->keep_block_together;
  2001. $this->keep_block_together = 0;
  2002. $save_cols = false;
  2003. /*-- COLUMNS --*/
  2004. if ($this->ColActive) {
  2005. $save_cols = true;
  2006. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  2007. $this->SetColumns(0);
  2008. }
  2009. /*-- END COLUMNS --*/
  2010. // mPDF 5.3.41
  2011. $save_vis = $this->visibility;
  2012. if($this->visibility!='visible')
  2013. $this->SetVisibility('visible');
  2014. $family=$this->FontFamily;
  2015. $style=$this->FontStyle.($this->U ? 'U' : '').($this->S ? 'S' : '');
  2016. $size=$this->FontSizePt;
  2017. $this->ColumnAdjust = true; // enables column height adjustment for the page
  2018. $lw=$this->LineWidth;
  2019. $dc=$this->DrawColor;
  2020. $fc=$this->FillColor;
  2021. $tc=$this->TextColor;
  2022. $cf=$this->ColorFlag;
  2023. if($this->page>0)
  2024. {
  2025. //Page footer
  2026. $this->InFooter=true;
  2027. $this->Reset();
  2028. $this->pageoutput[$this->page] = array();
  2029. $this->Footer();
  2030. //Close page
  2031. $this->_endpage();
  2032. }
  2033. //Start new page
  2034. $this->_beginpage($orientation,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat);
  2035. if ($this->docTemplate) {
  2036. $pagecount = $this->SetSourceFile($this->docTemplate);
  2037. if (($this->page - $this->docTemplateStart) > $pagecount) {
  2038. if ($this->docTemplateContinue) {
  2039. $tplIdx = $this->ImportPage($pagecount);
  2040. $this->UseTemplate($tplIdx);
  2041. }
  2042. }
  2043. else {
  2044. $tplIdx = $this->ImportPage(($this->page - $this->docTemplateStart));
  2045. $this->UseTemplate($tplIdx);
  2046. }
  2047. }
  2048. if ($this->pageTemplate) {
  2049. $this->UseTemplate($this->pageTemplate);
  2050. }
  2051. // Tiling Patterns
  2052. $this->_out('___PAGE___START'.date('jY'));
  2053. $this->_out('___BACKGROUND___PATTERNS'.date('jY'));
  2054. $this->_out('___HEADER___MARKER'.date('jY'));
  2055. $this->pageBackgrounds = array();
  2056. //Set line cap style to square
  2057. $this->SetLineCap(2);
  2058. //Set line width
  2059. $this->LineWidth=$lw;
  2060. $this->_out(sprintf('%.3F w',$lw*_MPDFK));
  2061. //Set font
  2062. if($family) $this->SetFont($family,$style,$size,true,true); // forces write
  2063. //Set colors
  2064. $this->DrawColor=$dc;
  2065. if($dc!=$this->defDrawColor) $this->_out($dc);
  2066. $this->FillColor=$fc;
  2067. if($fc!=$this->defFillColor) $this->_out($fc);
  2068. $this->TextColor=$tc;
  2069. $this->ColorFlag=$cf;
  2070. //Page header
  2071. $this->Header();
  2072. //Restore line width
  2073. if($this->LineWidth!=$lw)
  2074. {
  2075. $this->LineWidth=$lw;
  2076. $this->_out(sprintf('%.3F w',$lw*_MPDFK));
  2077. }
  2078. //Restore font
  2079. if($family) $this->SetFont($family,$style,$size,true,true); // forces write
  2080. //Restore colors
  2081. if($this->DrawColor!=$dc)
  2082. {
  2083. $this->DrawColor=$dc;
  2084. $this->_out($dc);
  2085. }
  2086. if($this->FillColor!=$fc)
  2087. {
  2088. $this->FillColor=$fc;
  2089. $this->_out($fc);
  2090. }
  2091. $this->TextColor=$tc;
  2092. $this->ColorFlag=$cf;
  2093. $this->InFooter=false;
  2094. // mPDF 5.3.41
  2095. if($save_vis!='visible')
  2096. $this->SetVisibility($save_vis);
  2097. /*-- COLUMNS --*/
  2098. if ($save_cols) {
  2099. // Restore columns
  2100. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  2101. }
  2102. if ($this->ColActive) { $this->SetCol(0); }
  2103. /*-- END COLUMNS --*/
  2104. //RESET BLOCK BORDER TOP
  2105. if (!$this->ColActive) {
  2106. for($bl=1;$bl<=$this->blklvl;$bl++) {
  2107. $this->blk[$bl]['y0'] = $this->y;
  2108. if (isset($this->blk[$bl]['x0'])) { $this->blk[$bl]['x0'] += $this->MarginCorrection; }
  2109. else { $this->blk[$bl]['x0'] = $this->MarginCorrection; }
  2110. // Added mPDF 3.0 Float DIV
  2111. $this->blk[$bl]['marginCorrected'][$this->page] = true;
  2112. }
  2113. }
  2114. $this->table_rotate = $save_tr; // *TABLES*
  2115. $this->kwt = $save_kwt;
  2116. $this->keep_block_together = $save_kt ;
  2117. $this->cMarginL = $bak_cml;
  2118. $this->cMarginR = $bak_cmr;
  2119. $this->divwidth = $bak_dw;
  2120. $this->lineheight = $bak_lh;
  2121. }
  2122. function PageNo() {
  2123. //Get current page number
  2124. return $this->page;
  2125. }
  2126. function AddSpotColorsFromFile($file) {
  2127. $colors = @file($file) or die("Cannot load spot colors file - ".$file);
  2128. foreach($colors AS $sc) {
  2129. list($name, $c, $m, $y, $k) = preg_split("/\t/",$sc);
  2130. $c = intval($c);
  2131. $m = intval($m);
  2132. $y = intval($y);
  2133. $k = intval($k);
  2134. $this->AddSpotColor($name, $c, $m, $y, $k);
  2135. }
  2136. }
  2137. function AddSpotColor($name, $c, $m, $y, $k) {
  2138. $name = strtoupper(trim($name));
  2139. if(!isset($this->spotColors[$name])) {
  2140. $i=count($this->spotColors)+1;
  2141. $this->spotColors[$name]=array('i'=>$i,'c'=>$c,'m'=>$m,'y'=>$y,'k'=>$k);
  2142. $this->spotColorIDs[$i]=$name;
  2143. }
  2144. }
  2145. function SetColor($col, $type='') {
  2146. $out = '';
  2147. // mPDF 5.3.74
  2148. if ($col{0}==3 || $col{0}==5) { // RGB / RGBa
  2149. $out = sprintf('%.3F %.3F %.3F rg',ord($col{1})/255,ord($col{2})/255,ord($col{3})/255);
  2150. }
  2151. else if ($col{0}==1) { // GRAYSCALE
  2152. $out = sprintf('%.3F g',ord($col{1})/255);
  2153. }
  2154. else if ($col{0}==2) { // SPOT COLOR
  2155. $out = sprintf('/CS%d cs %.3F scn',ord($col{1}),ord($col{2})/100);
  2156. }
  2157. else if ($col{0}==4 || $col{0}==6) { // CMYK / CMYKa
  2158. $out = sprintf('%.3F %.3F %.3F %.3F k', ord($col{1})/100, ord($col{2})/100, ord($col{3})/100, ord($col{4})/100);
  2159. }
  2160. if ($type=='Draw') { $out = strtoupper($out); } // e.g. rg => RG
  2161. else if ($type=='CodeOnly') { $out = preg_replace('/\s(rg|g|k)/','',$out); }
  2162. return $out;
  2163. }
  2164. function SetDColor($col, $return=false) {
  2165. $out = $this->SetColor($col, 'Draw');
  2166. if ($return) { return $out; }
  2167. if ($out=='') { return ''; }
  2168. $this->DrawColor = $out;
  2169. if($this->page>0 && ((isset($this->pageoutput[$this->page]['DrawColor']) && $this->pageoutput[$this->page]['DrawColor'] != $this->DrawColor) || !isset($this->pageoutput[$this->page]['DrawColor']) || $this->keep_block_together)) { $this->_out($this->DrawColor); }
  2170. $this->pageoutput[$this->page]['DrawColor'] = $this->DrawColor;
  2171. }
  2172. function SetFColor($col, $return=false) {
  2173. $out = $this->SetColor($col, 'Fill');
  2174. if ($return) { return $out; }
  2175. if ($out=='') { return ''; }
  2176. $this->FillColor = $out;
  2177. $this->ColorFlag = ($out != $this->TextColor);
  2178. if($this->page>0 && ((isset($this->pageoutput[$this->page]['FillColor']) && $this->pageoutput[$this->page]['FillColor'] != $this->FillColor) || !isset($this->pageoutput[$this->page]['FillColor']) || $this->keep_block_together)) { $this->_out($this->FillColor); }
  2179. $this->pageoutput[$this->page]['FillColor'] = $this->FillColor;
  2180. }
  2181. function SetTColor($col, $return=false) {
  2182. $out = $this->SetColor($col, 'Text');
  2183. if ($return) { return $out; }
  2184. if ($out=='') { return ''; }
  2185. $this->TextColor = $out;
  2186. $this->ColorFlag = ($this->FillColor != $out);
  2187. }
  2188. function SetDrawColor($r,$g=-1,$b=-1,$col4=-1, $return=false) {
  2189. //Set color for all stroking operations
  2190. $col = array();
  2191. if(($r==0 and $g==0 and $b==0 && $col4 == -1) or $g==-1) { $col = $this->ConvertColor($r); }
  2192. else if ($col4 == -1) { $col = $this->ConvertColor('rgb('.$r.','.$g.','.$b.')'); }
  2193. else { $col = $this->ConvertColor('cmyk('.$r.','.$g.','.$b.','.$col4.')'); }
  2194. $out = $this->SetDColor($col, $return);
  2195. return $out;
  2196. }
  2197. function SetFillColor($r,$g=-1,$b=-1,$col4=-1, $return=false) {
  2198. //Set color for all filling operations
  2199. $col = array();
  2200. if(($r==0 and $g==0 and $b==0 && $col4 == -1) or $g==-1) { $col = $this->ConvertColor($r); }
  2201. else if ($col4 == -1) { $col = $this->ConvertColor('rgb('.$r.','.$g.','.$b.')'); }
  2202. else { $col = $this->ConvertColor('cmyk('.$r.','.$g.','.$b.','.$col4.')'); }
  2203. $out = $this->SetFColor($col, $return);
  2204. return $out;
  2205. }
  2206. function SetTextColor($r,$g=-1,$b=-1,$col4=-1, $return=false) {
  2207. //Set color for text
  2208. $col = array();
  2209. if(($r==0 and $g==0 and $b==0 && $col4 == -1) or $g==-1) { $col = $this->ConvertColor($r); }
  2210. else if ($col4 == -1) { $col = $this->ConvertColor('rgb('.$r.','.$g.','.$b.')'); }
  2211. else { $col = $this->ConvertColor('cmyk('.$r.','.$g.','.$b.','.$col4.')'); }
  2212. $out = $this->SetTColor($col, $return);
  2213. return $out;
  2214. }
  2215. function _getCharWidth(&$cw, $u, $isdef=true) {
  2216. if ($u==0) { $w = false; }
  2217. else { $w = (ord($cw[$u*2]) << 8) + ord($cw[$u*2+1]); }
  2218. if ($w == 65535) { return 0; }
  2219. else if ($w) { return $w; }
  2220. else if ($isdef) { return false; }
  2221. else { return 0; }
  2222. }
  2223. function _charDefined(&$cw, $u) {
  2224. if ($u==0) { return false; }
  2225. $w = (ord($cw[$u*2]) << 8) + ord($cw[$u*2+1]);
  2226. if ($w) { return true; }
  2227. else { return false; }
  2228. }
  2229. // mPDF 5.3.04
  2230. function GetCharWidthCore($c) {
  2231. //Get width of a single character in the current Core font
  2232. $c = (string)$c;
  2233. $w = 0;
  2234. // Soft Hyphens chr(173)
  2235. if ($c == chr(173) && $this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  2236. return 0; // mPDF 5.3.07
  2237. }
  2238. else if ($this->S && isset($this->upperCase[ord($c)])) {
  2239. $charw = $this->CurrentFont['cw'][chr($this->upperCase[ord($c)])];
  2240. if ($charw!==false) {
  2241. $charw = $charw*$this->smCapsScale * $this->smCapsStretch/100;
  2242. $w+=$charw;
  2243. }
  2244. }
  2245. else if (isset($this->CurrentFont['cw'][$c])) {
  2246. $w += $this->CurrentFont['cw'][$c];
  2247. }
  2248. else if (isset($this->CurrentFont['cw'][ord($c)])) {
  2249. $w += $this->CurrentFont['cw'][ord($c)];
  2250. }
  2251. $w *= ($this->FontSize/ 1000);
  2252. if ($this->minwSpacing || $this->fixedlSpacing) {
  2253. if ($c==' ') $nb_spaces = 1;
  2254. else $nb_spaces = 0;
  2255. $w += $this->fixedlSpacing + ($nb_spaces * $this->minwSpacing);
  2256. }
  2257. return ($w);
  2258. }
  2259. // mPDF 5.3.04
  2260. function GetCharWidthNonCore($c, $addSubset=true) {
  2261. //Get width of a single character in the current Non-Core font
  2262. $c = (string)$c;
  2263. $w = 0;
  2264. $unicode = $this->UTF8StringToArray($c, $addSubset); // mPDF 5.3.06
  2265. $char = $unicode[0];
  2266. /*-- CJK-FONTS --*/
  2267. if ($this->CurrentFont['type'] == 'Type0') { // CJK Adobe fonts
  2268. if ($char == 173) { return 0; } // Soft Hyphens // mPDF 5.3.07
  2269. elseif (isset($this->CurrentFont['cw'][$char])) { $w+=$this->CurrentFont['cw'][$char]; }
  2270. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2271. else { $w += 500; }
  2272. }
  2273. else {
  2274. /*-- END CJK-FONTS --*/
  2275. if ($char == 173) { return 0; } // Soft Hyphens // mPDF 5.3.07
  2276. else if ($this->S && isset($this->upperCase[$char])) {
  2277. $charw = $this->_getCharWidth($this->CurrentFont['cw'],$this->upperCase[$char]);
  2278. if ($charw!==false) {
  2279. $charw = $charw*$this->smCapsScale * $this->smCapsStretch/100;
  2280. $w+=$charw;
  2281. }
  2282. elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; }
  2283. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2284. else { $w += 500; }
  2285. }
  2286. else {
  2287. $charw = $this->_getCharWidth($this->CurrentFont['cw'],$char);
  2288. if ($charw!==false) { $w+=$charw; }
  2289. elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; }
  2290. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2291. else { $w += 500; }
  2292. }
  2293. } // *CJK-FONTS*
  2294. $w *= ($this->FontSize/ 1000);
  2295. if ($this->minwSpacing || $this->fixedlSpacing) {
  2296. if ($c==' ') $nb_spaces = 1;
  2297. else $nb_spaces = 0;
  2298. $w += $this->fixedlSpacing + ($nb_spaces * $this->minwSpacing);
  2299. }
  2300. return ($w);
  2301. }
  2302. // mPDF 5.3.04
  2303. function GetCharWidth($c, $addSubset=true) {
  2304. if (!$this->usingCoreFont) {
  2305. return $this->GetCharWidthNonCore($c, $addSubset);
  2306. }
  2307. else {
  2308. return $this->GetCharWidthCore($c);
  2309. }
  2310. }
  2311. function GetStringWidth($s, $addSubset=true) {
  2312. //Get width of a string in the current font
  2313. $s = (string)$s;
  2314. $cw = &$this->CurrentFont['cw'];
  2315. $w = 0;
  2316. $kerning = 0;
  2317. $lastchar = 0;
  2318. // mPDF 5.3.04
  2319. $nb_carac = 0;
  2320. $nb_spaces = 0;
  2321. // mPDF ITERATION
  2322. if ($this->iterationCounter) $s = preg_replace('/{iteration ([a-zA-Z0-9_]+)}/', '\\1', $s);
  2323. if (!$this->usingCoreFont) {
  2324. // mPDF 5.3.04
  2325. $s = str_replace("\xc2\xad",'',$s );
  2326. $unicode = $this->UTF8StringToArray($s, $addSubset);
  2327. // mPDF 5.3.04
  2328. if ($this->minwSpacing || $this->fixedlSpacing) {
  2329. $nb_carac = count($unicode);
  2330. $nb_spaces = mb_substr_count($s,' ', $this->mb_enc);
  2331. }
  2332. /*-- CJK-FONTS --*/
  2333. if ($this->CurrentFont['type'] == 'Type0') { // CJK Adobe fonts
  2334. foreach($unicode as $char) {
  2335. if (isset($cw[$char])) { $w+=$cw[$char]; }
  2336. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2337. else { $w += 500; }
  2338. }
  2339. }
  2340. else {
  2341. /*-- END CJK-FONTS --*/
  2342. foreach($unicode as $char) {
  2343. if ($this->S && isset($this->upperCase[$char])) {
  2344. $charw = $this->_getCharWidth($cw,$this->upperCase[$char]);
  2345. if ($charw!==false) {
  2346. $charw = $charw*$this->smCapsScale * $this->smCapsStretch/100;
  2347. $w+=$charw;
  2348. }
  2349. elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; }
  2350. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2351. else { $w += 500; }
  2352. }
  2353. else {
  2354. $charw = $this->_getCharWidth($cw,$char);
  2355. if ($charw!==false) { $w+=$charw; }
  2356. elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; }
  2357. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2358. else { $w += 500; }
  2359. if ($this->kerning && $this->useKerning && $lastchar) {
  2360. if (isset($this->CurrentFont['kerninfo'][$lastchar][$char])) {
  2361. $kerning += $this->CurrentFont['kerninfo'][$lastchar][$char];
  2362. }
  2363. }
  2364. $lastchar = $char;
  2365. }
  2366. }
  2367. } // *CJK-FONTS*
  2368. }
  2369. else {
  2370. // mPDF 5.3.04
  2371. if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  2372. $s = str_replace(chr(173),'',$s );
  2373. }
  2374. $nb_carac = $l = strlen($s);
  2375. // mPDF 5.3.04
  2376. if ($this->minwSpacing || $this->fixedlSpacing) {
  2377. $nb_spaces = substr_count($s,' ');
  2378. }
  2379. for($i=0; $i<$l; $i++) {
  2380. if ($this->S && isset($this->upperCase[ord($s[$i])])) {
  2381. $charw = $cw[chr($this->upperCase[ord($s[$i])])];
  2382. if ($charw!==false) {
  2383. $charw = $charw*$this->smCapsScale * $this->smCapsStretch/100;
  2384. $w+=$charw;
  2385. }
  2386. }
  2387. else if (isset($cw[$s[$i]])) {
  2388. $w += $cw[$s[$i]];
  2389. }
  2390. else if (isset($cw[ord($s[$i])])) {
  2391. $w += $cw[ord($s[$i])];
  2392. }
  2393. if ($this->kerning && $this->useKerning && $i>0) { // mPDF 5.3.04
  2394. if (isset($this->CurrentFont['kerninfo'][$s[($i-1)]][$s[$i]])) {
  2395. $kerning += $this->CurrentFont['kerninfo'][$s[($i-1)]][$s[$i]];
  2396. }
  2397. }
  2398. }
  2399. }
  2400. unset($cw);
  2401. if ($this->kerning && $this->useKerning) { $w += $kerning; }
  2402. $w *= ($this->FontSize/ 1000);
  2403. // mPDF 5.3.04
  2404. $w += (($nb_carac + $nb_spaces) * $this->fixedlSpacing) + ($nb_spaces * $this->minwSpacing);
  2405. return ($w);
  2406. }
  2407. function SetLineWidth($width) {
  2408. //Set line width
  2409. $this->LineWidth=$width;
  2410. $lwout = (sprintf('%.3F w',$width*_MPDFK));
  2411. if($this->page>0 && ((isset($this->pageoutput[$this->page]['LineWidth']) && $this->pageoutput[$this->page]['LineWidth'] != $lwout) || !isset($this->pageoutput[$this->page]['LineWidth']) || $this->keep_block_together)) {
  2412. $this->_out($lwout);
  2413. }
  2414. $this->pageoutput[$this->page]['LineWidth'] = $lwout;
  2415. }
  2416. function Line($x1,$y1,$x2,$y2) {
  2417. //Draw a line
  2418. $this->_out(sprintf('%.3F %.3F m %.3F %.3F l S',$x1*_MPDFK,($this->h-$y1)*_MPDFK,$x2*_MPDFK,($this->h-$y2)*_MPDFK));
  2419. }
  2420. function Arrow($x1,$y1,$x2,$y2,$headsize=3,$fill='B',$angle=25) {
  2421. //F == fill //S == stroke //B == stroke and fill
  2422. // angle = splay of arrowhead - 1 - 89 degrees
  2423. if($fill=='F') $fill='f';
  2424. elseif($fill=='FD' or $fill=='DF' or $fill=='B') $fill='B';
  2425. else $fill='S';
  2426. $a = atan2(($y2-$y1),($x2-$x1));
  2427. $b = $a + deg2rad($angle);
  2428. $c = $a - deg2rad($angle);
  2429. $x3 = $x2 - ($headsize* cos($b));
  2430. $y3 = $this->h-($y2 - ($headsize* sin($b)));
  2431. $x4 = $x2 - ($headsize* cos($c));
  2432. $y4 = $this->h-($y2 - ($headsize* sin($c)));
  2433. $x5 = $x3-($x3-$x4)/2; // mid point of base of arrowhead - to join arrow line to
  2434. $y5 = $y3-($y3-$y4)/2;
  2435. $s = '';
  2436. $s.=sprintf('%.3F %.3F m %.3F %.3F l S',$x1*_MPDFK,($this->h-$y1)*_MPDFK,$x5*_MPDFK,$y5*_MPDFK);
  2437. $this->_out($s);
  2438. $s = '';
  2439. $s.=sprintf('%.3F %.3F m %.3F %.3F l %.3F %.3F l %.3F %.3F l %.3F %.3F l ',$x5*_MPDFK,$y5*_MPDFK,$x3*_MPDFK,$y3*_MPDFK,$x2*_MPDFK,($this->h-$y2)*_MPDFK,$x4*_MPDFK,$y4*_MPDFK,$x5*_MPDFK,$y5*_MPDFK);
  2440. $s.=$fill;
  2441. $this->_out($s);
  2442. }
  2443. function Rect($x,$y,$w,$h,$style='') {
  2444. //Draw a rectangle
  2445. if($style=='F') $op='f';
  2446. elseif($style=='FD' or $style=='DF') $op='B';
  2447. else $op='S';
  2448. $this->_out(sprintf('%.3F %.3F %.3F %.3F re %s',$x*_MPDFK,($this->h-$y)*_MPDFK,$w*_MPDFK,-$h*_MPDFK,$op));
  2449. }
  2450. function AddFont($family,$style='') {
  2451. if(empty($family)) { return; }
  2452. $family = strtolower($family);
  2453. $style=strtoupper($style);
  2454. $style=str_replace('U','',$style);
  2455. if($style=='IB') $style='BI';
  2456. $fontkey = $family.$style;
  2457. // check if the font has been already added
  2458. if(isset($this->fonts[$fontkey])) {
  2459. return;
  2460. }
  2461. /*-- CJK-FONTS --*/
  2462. if (in_array($family,$this->available_CJK_fonts)) {
  2463. if (empty($this->Big5_widths)) { require(_MPDF_PATH . 'includes/CJKdata.php'); }
  2464. $this->AddCJKFont($family); // don't need to add style
  2465. return;
  2466. }
  2467. /*-- END CJK-FONTS --*/
  2468. if ($this->usingCoreFont) { die("mPDF Error - problem with Font management"); }
  2469. $stylekey = $style;
  2470. if (!$style) { $stylekey = 'R'; }
  2471. if (!isset($this->fontdata[$family][$stylekey]) || !$this->fontdata[$family][$stylekey]) {
  2472. die('mPDF Error - Font is not supported - '.$family.' '.$style);
  2473. }
  2474. $name = '';
  2475. $originalsize = 0;
  2476. $sip = false;
  2477. $smp = false;
  2478. $haskerninfo = false;
  2479. $BMPselected = false;
  2480. @include(_MPDF_TTFONTDATAPATH.$fontkey.'.mtx.php');
  2481. $ttffile = '';
  2482. if (defined('_MPDF_SYSTEM_TTFONTS')) {
  2483. $ttffile = _MPDF_SYSTEM_TTFONTS.$this->fontdata[$family][$stylekey];
  2484. if (!file_exists($ttffile)) { $ttffile = ''; }
  2485. }
  2486. if (!$ttffile) {
  2487. $ttffile = _MPDF_TTFONTPATH.$this->fontdata[$family][$stylekey];
  2488. if (!file_exists($ttffile)) { die("mPDF Error - cannot find TTF TrueType font file - ".$ttffile); }
  2489. }
  2490. $ttfstat = stat($ttffile);
  2491. if (isset($this->fontdata[$family]['TTCfontID'][$stylekey])) { $TTCfontID = $this->fontdata[$family]['TTCfontID'][$stylekey]; }
  2492. else { $TTCfontID = 0; }
  2493. $BMPonly = false;
  2494. if (in_array($family,$this->BMPonly)) { $BMPonly = true; }
  2495. $regenerate = false;
  2496. if ($BMPonly && !$BMPselected) { $regenerate = true; }
  2497. else if (!$BMPonly && $BMPselected) { $regenerate = true; }
  2498. if ($this->useKerning && !$haskerninfo) { $regenerate = true; }
  2499. if (!isset($name) || $originalsize != $ttfstat['size'] || $regenerate) {
  2500. $mqr=$this->_getMQR();
  2501. if ($mqr) { set_magic_quotes_runtime(0); }
  2502. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  2503. $ttf = new TTFontFile();
  2504. $ttf->getMetrics($ttffile, $TTCfontID, $this->debugfonts, $BMPonly, $this->useKerning);
  2505. $cw = $ttf->charWidths;
  2506. $kerninfo = $ttf->kerninfo;
  2507. $haskerninfo = true;
  2508. $name = preg_replace('/[ ()]/','',$ttf->fullName);
  2509. $sip = $ttf->sipset;
  2510. $smp = $ttf->smpset;
  2511. $desc= array('Ascent'=>round($ttf->ascent),
  2512. 'Descent'=>round($ttf->descent),
  2513. 'CapHeight'=>round($ttf->capHeight),
  2514. 'Flags'=>$ttf->flags,
  2515. 'FontBBox'=>'['.round($ttf->bbox[0])." ".round($ttf->bbox[1])." ".round($ttf->bbox[2])." ".round($ttf->bbox[3]).']',
  2516. 'ItalicAngle'=>$ttf->italicAngle,
  2517. 'StemV'=>round($ttf->stemV),
  2518. 'MissingWidth'=>round($ttf->defaultWidth));
  2519. $panose = '';
  2520. if (count($ttf->panose)) { $panose = $ttf->sFamilyClass.' '.$ttf->sFamilySubClass.' '.implode(' ',$ttf->panose); }
  2521. $up = round($ttf->underlinePosition);
  2522. $ut = round($ttf->underlineThickness);
  2523. $originalsize = $ttfstat['size']+0;
  2524. $type = 'TTF';
  2525. //Generate metrics .php file
  2526. $s='<?php'."\n";
  2527. $s.='$name=\''.$name."';\n";
  2528. $s.='$type=\''.$type."';\n";
  2529. $s.='$desc='.var_export($desc,true).";\n";
  2530. $s.='$up='.$up.";\n";
  2531. $s.='$ut='.$ut.";\n";
  2532. $s.='$ttffile=\''.$ttffile."';\n";
  2533. $s.='$TTCfontID=\''.$TTCfontID."';\n";
  2534. $s.='$originalsize='.$originalsize.";\n";
  2535. if ($sip) $s.='$sip=true;'."\n";
  2536. else $s.='$sip=false;'."\n";
  2537. if ($smp) $s.='$smp=true;'."\n";
  2538. else $s.='$smp=false;'."\n";
  2539. if ($BMPonly) $s.='$BMPselected=true;'."\n";
  2540. else $s.='$BMPselected=false;'."\n";
  2541. $s.='$fontkey=\''.$fontkey."';\n";
  2542. $s.='$panose=\''.$panose."';\n";
  2543. if ($this->useKerning) {
  2544. $s.='$kerninfo='.var_export($kerninfo,true).";\n";
  2545. $s.='$haskerninfo=true;'."\n";
  2546. }
  2547. else $s.='$haskerninfo=false;'."\n";
  2548. $s.="?>";
  2549. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  2550. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.mtx.php',"w");
  2551. fwrite($fh,$s,strlen($s));
  2552. fclose($fh);
  2553. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.cw.dat',"wb");
  2554. fwrite($fh,$cw,strlen($cw));
  2555. fclose($fh);
  2556. @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.cgm');
  2557. @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.z');
  2558. @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.cw127.php');
  2559. @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.cw');
  2560. }
  2561. else if ($this->debugfonts) { $this->Error('Cannot write to the font caching directory - '._MPDF_TTFONTDATAPATH); }
  2562. unset($ttf);
  2563. if ($mqr) { set_magic_quotes_runtime($mqr); }
  2564. }
  2565. else {
  2566. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$fontkey.'.cw.dat');
  2567. }
  2568. if (isset($this->fontdata[$family]['indic']) && $this->fontdata[$family]['indic']) { $indic = true; }
  2569. else { $indic = false; }
  2570. if (isset($this->fontdata[$family]['sip-ext']) && $this->fontdata[$family]['sip-ext']) { $sipext = $this->fontdata[$family]['sip-ext']; }
  2571. else { $sipext = ''; }
  2572. $i = count($this->fonts)+$this->extraFontSubsets+1;
  2573. if ($sip || $smp) {
  2574. $this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'panose'=>$panose, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'ttffile'=>$ttffile, 'fontkey'=>$fontkey, 'subsets'=>array(0=>range(0,127)), 'subsetfontids'=>array($i), 'used'=>false, 'indic'=>$indic, 'sip'=>$sip, 'sipext'=>$sipext, 'smp'=>$smp, 'TTCfontID' => $TTCfontID);
  2575. }
  2576. else {
  2577. // mPDF 5.3.31
  2578. $ss = array();
  2579. for ($s=32; $s<128; $s++) { $ss[$s] = $s; }
  2580. $this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'panose'=>$panose, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'ttffile'=>$ttffile, 'fontkey'=>$fontkey, 'subset'=>$ss, 'used'=>false, 'indic'=>$indic, 'sip'=>$sip, 'sipext'=>$sipext, 'smp'=>$smp, 'TTCfontID' => $TTCfontID);
  2581. }
  2582. if ($this->useKerning && $haskerninfo) { $this->fonts[$fontkey]['kerninfo'] = $kerninfo; }
  2583. $this->FontFiles[$fontkey]=array('length1'=>$originalsize, 'type'=>"TTF", 'ttffile'=>$ttffile, 'sip'=>$sip, 'smp'=>$smp);
  2584. unset($cw);
  2585. }
  2586. function SetFont($family,$style='',$size=0, $write=true, $forcewrite=false) {
  2587. $family=strtolower($family);
  2588. // mPDF 5.3.22
  2589. if (!$this->onlyCoreFonts) {
  2590. if ($family == 'sans' || $family == 'sans-serif') { $family = $this->sans_fonts[0]; }
  2591. if ($family == 'serif') { $family = $this->serif_fonts[0]; }
  2592. if ($family == 'mono' || $family == 'monospace') { $family = $this->mono_fonts[0]; }
  2593. }
  2594. // mPDF 5.3.22
  2595. if (isset($this->fonttrans[$family]) && $this->fonttrans[$family]) { $family = $this->fonttrans[$family]; }
  2596. if($family=='') {
  2597. if ($this->FontFamily) { $family=$this->FontFamily; }
  2598. else if ($this->default_font) { $family=$this->default_font; }
  2599. else { $this->Error("No font or default font set!"); }
  2600. }
  2601. $this->ReqFontStyle = $style; // required or requested style - used later for artificial bold/italic
  2602. if (($family == 'csymbol') || ($family == 'czapfdingbats') || ($family == 'ctimes') || ($family == 'ccourier') || ($family == 'chelvetica')) {
  2603. if ($this->PDFA || $this->PDFX) {
  2604. if ($family == 'csymbol' || $family == 'czapfdingbats') {
  2605. $this->Error("Symbol and Zapfdingbats cannot be embedded in mPDF (required for PDFA1-b or PDFX/1-a).");
  2606. }
  2607. if ($family == 'ctimes' || $family == 'ccourier' || $family == 'chelvetica') {
  2608. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "Core Adobe font ".ucfirst($family)." cannot be embedded in mPDF, which is required for PDFA1-b or PDFX/1-a. (Embedded font will be substituted.)"; }
  2609. if ($family == 'chelvetica') { $family = 'sans'; }
  2610. if ($family == 'ctimes') { $family = 'serif'; }
  2611. if ($family == 'ccourier') { $family = 'mono'; }
  2612. }
  2613. $this->usingCoreFont = false;
  2614. }
  2615. else { $this->usingCoreFont = true; }
  2616. if($family=='csymbol' || $family=='czapfdingbats') { $style=''; } // mPDF 5.3.05
  2617. }
  2618. else { $this->usingCoreFont = false; }
  2619. // mPDF 5.3.05
  2620. $this->U=false;
  2621. $this->S=false;
  2622. if ($style) {
  2623. $style=strtoupper($style);
  2624. if(strpos($style,'U')!==false) {
  2625. $this->U=true;
  2626. $style=str_replace('U','',$style);
  2627. }
  2628. if(strpos($style,'S')!==false) {
  2629. $this->S=true;
  2630. // Small Caps
  2631. if (empty($this->upperCase)) { @include(_MPDF_PATH.'includes/upperCase.php'); } // mPDF 5.3.99
  2632. $style=str_replace('S','',$style);
  2633. }
  2634. if ($style=='IB') $style='BI';
  2635. }
  2636. if ($size==0) $size=$this->FontSizePt;
  2637. $fontkey=$family.$style;
  2638. $stylekey = $style;
  2639. if (!$stylekey) { $stylekey = "R"; }
  2640. if (!$this->onlyCoreFonts && !$this->usingCoreFont) {
  2641. // mPDF 5.3.05
  2642. if(!isset($this->fonts[$fontkey]) || count($this->default_available_fonts) != count($this->available_unifonts) ) { // not already added
  2643. /*-- CJK-FONTS --*/
  2644. // CJK fonts
  2645. if (in_array($fontkey,$this->available_CJK_fonts)) {
  2646. if(!isset($this->fonts[$fontkey])) { // already added
  2647. if (empty($this->Big5_widths)) { require(_MPDF_PATH . 'includes/CJKdata.php'); }
  2648. $this->AddCJKFont($family); // don't need to add style
  2649. }
  2650. }
  2651. // Test to see if requested font/style is available - or substitute
  2652. else
  2653. /*-- END CJK-FONTS --*/
  2654. if (!in_array($fontkey,$this->available_unifonts)) {
  2655. // If font[nostyle] exists - set it
  2656. if (in_array($family,$this->available_unifonts)) {
  2657. $style = '';
  2658. }
  2659. // Else if only one font available - set it (assumes if only one font available it will not have a style)
  2660. else if (count($this->available_unifonts) == 1) {
  2661. $family = $this->available_unifonts[0];
  2662. $style = '';
  2663. }
  2664. else {
  2665. $found = 0;
  2666. // else substitute font of similar type
  2667. if (in_array($family,$this->sans_fonts)) {
  2668. $i = array_intersect($this->sans_fonts,$this->available_unifonts);
  2669. if (count($i)) {
  2670. $i = array_values($i);
  2671. // with requested style if possible
  2672. if (!in_array(($i[0].$style),$this->available_unifonts)) {
  2673. $style = '';
  2674. }
  2675. $family = $i[0];
  2676. $found = 1;
  2677. }
  2678. }
  2679. else if (in_array($family,$this->serif_fonts)) {
  2680. $i = array_intersect($this->serif_fonts,$this->available_unifonts);
  2681. if (count($i)) {
  2682. $i = array_values($i);
  2683. // with requested style if possible
  2684. if (!in_array(($i[0].$style),$this->available_unifonts)) {
  2685. $style = '';
  2686. }
  2687. $family = $i[0];
  2688. $found = 1;
  2689. }
  2690. }
  2691. else if (in_array($family,$this->mono_fonts)) {
  2692. $i = array_intersect($this->mono_fonts,$this->available_unifonts);
  2693. if (count($i)) {
  2694. $i = array_values($i);
  2695. // with requested style if possible
  2696. if (!in_array(($i[0].$style),$this->available_unifonts)) {
  2697. $style = '';
  2698. }
  2699. $family = $i[0];
  2700. $found = 1;
  2701. }
  2702. }
  2703. if (!$found) {
  2704. // set first available font
  2705. $fs = $this->available_unifonts[0];
  2706. preg_match('/^([a-z_0-9\-]+)([BI]{0,2})$/',$fs,$fas); // Allow "-"
  2707. // with requested style if possible
  2708. $ws = $fas[1].$style;
  2709. if (in_array($ws,$this->available_unifonts)) {
  2710. $family = $fas[1]; // leave $style as is
  2711. }
  2712. else if (in_array($fas[1],$this->available_unifonts)) {
  2713. // or without style
  2714. $family = $fas[1];
  2715. $style = '';
  2716. }
  2717. else {
  2718. // or with the style specified
  2719. $family = $fas[1];
  2720. $style = $fas[2];
  2721. }
  2722. }
  2723. }
  2724. $fontkey = $family.$style;
  2725. }
  2726. }
  2727. // try to add font (if not already added)
  2728. $this->AddFont($family, $style);
  2729. //Test if font is already selected
  2730. if($this->FontFamily == $family && $this->FontFamily == $this->currentfontfamily && $this->FontStyle == $style && $this->FontStyle == $this->currentfontstyle && $this->FontSizePt == $size && $this->FontSizePt == $this->currentfontsize && !$forcewrite) {
  2731. return $family;
  2732. }
  2733. $fontkey = $family.$style;
  2734. //Select it
  2735. $this->FontFamily = $family;
  2736. $this->FontStyle = $style;
  2737. $this->FontSizePt = $size;
  2738. $this->FontSize = $size / _MPDFK;
  2739. $this->CurrentFont = &$this->fonts[$fontkey];
  2740. if ($write) {
  2741. $fontout = (sprintf('BT /F%d %.3F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  2742. if($this->page>0 && ((isset($this->pageoutput[$this->page]['Font']) && $this->pageoutput[$this->page]['Font'] != $fontout) || !isset($this->pageoutput[$this->page]['Font']) || $this->keep_block_together)) { $this->_out($fontout); }
  2743. $this->pageoutput[$this->page]['Font'] = $fontout;
  2744. }
  2745. // Added - currentfont (lowercase) used in HTML2PDF
  2746. $this->currentfontfamily=$family;
  2747. $this->currentfontsize=$size;
  2748. $this->currentfontstyle=$style.($this->U ? 'U' : '').($this->S ? 'S' : '');
  2749. $this->setMBencoding('UTF-8');
  2750. }
  2751. else { // if using core fonts
  2752. if ($this->PDFA || $this->PDFX) {
  2753. $this->Error('Core Adobe fonts cannot be embedded in mPDF (required for PDFA1-b or PDFX/1-a) - cannot use option to use core fonts.');
  2754. }
  2755. $this->setMBencoding('windows-1252');
  2756. //Test if font is already selected
  2757. if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size) && !$forcewrite) {
  2758. return $family;
  2759. }
  2760. if (!isset($this->CoreFonts[$fontkey])) {
  2761. if (in_array($family,$this->serif_fonts)) { $family = 'ctimes'; }
  2762. else if (in_array($family,$this->mono_fonts)) { $family = 'ccourier'; }
  2763. else { $family = 'chelvetica'; }
  2764. $this->usingCoreFont = true;
  2765. $fontkey = $family.$style;
  2766. }
  2767. if(!isset($this->fonts[$fontkey])) {
  2768. // STANDARD CORE FONTS
  2769. if (isset($this->CoreFonts[$fontkey])) {
  2770. //Load metric file
  2771. $file=$family;
  2772. if($family=='ctimes' || $family=='chelvetica' || $family=='ccourier') { $file.=strtolower($style); }
  2773. $file.='.php';
  2774. include(_MPDF_PATH.'font/'.$file);
  2775. if(!isset($cw)) { $this->Error('Could not include font metric file'); }
  2776. $i=count($this->fonts)+$this->extraFontSubsets+1;
  2777. $this->fonts[$fontkey]=array('i'=>$i,'type'=>'core','name'=>$this->CoreFonts[$fontkey],'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw);
  2778. if ($this->useKerning) { $this->fonts[$fontkey]['kerninfo'] = $kerninfo; }
  2779. }
  2780. else {
  2781. die('mPDF error - Font not defined');
  2782. }
  2783. }
  2784. //Test if font is already selected
  2785. if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size) && !$forcewrite) {
  2786. return $family;
  2787. }
  2788. //Select it
  2789. $this->FontFamily=$family;
  2790. $this->FontStyle=$style;
  2791. $this->FontSizePt=$size;
  2792. $this->FontSize=$size/_MPDFK;
  2793. $this->CurrentFont=&$this->fonts[$fontkey];
  2794. if ($write) {
  2795. $fontout = (sprintf('BT /F%d %.3F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  2796. if($this->page>0 && ((isset($this->pageoutput[$this->page]['Font']) && $this->pageoutput[$this->page]['Font'] != $fontout) || !isset($this->pageoutput[$this->page]['Font']) || $this->keep_block_together)) { $this->_out($fontout); }
  2797. $this->pageoutput[$this->page]['Font'] = $fontout;
  2798. }
  2799. // Added - currentfont (lowercase) used in HTML2PDF
  2800. $this->currentfontfamily=$family;
  2801. $this->currentfontsize=$size;
  2802. $this->currentfontstyle=$style.($this->U ? 'U' : '').($this->S ? 'S' : '');
  2803. }
  2804. return $family;
  2805. }
  2806. function SetFontSize($size,$write=true) {
  2807. //Set font size in points
  2808. if($this->FontSizePt==$size) return;
  2809. $this->FontSizePt=$size;
  2810. $this->FontSize=$size/_MPDFK;
  2811. $this->currentfontsize=$size;
  2812. if ($write) {
  2813. $fontout = (sprintf('BT /F%d %.3F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  2814. // Edited mPDF 3.0
  2815. if($this->page>0 && ((isset($this->pageoutput[$this->page]['Font']) && $this->pageoutput[$this->page]['Font'] != $fontout) || !isset($this->pageoutput[$this->page]['Font']) || $this->keep_block_together)) { $this->_out($fontout); }
  2816. $this->pageoutput[$this->page]['Font'] = $fontout;
  2817. }
  2818. }
  2819. function AddLink() {
  2820. //Create a new internal link
  2821. $n=count($this->links)+1;
  2822. $this->links[$n]=array(0,0);
  2823. return $n;
  2824. }
  2825. function SetLink($link,$y=0,$page=-1) {
  2826. //Set destination of internal link
  2827. if($y==-1) $y=$this->y;
  2828. if($page==-1) $page=$this->page;
  2829. $this->links[$link]=array($page,$y);
  2830. }
  2831. function Link($x,$y,$w,$h,$link) {
  2832. $l = array($x*_MPDFK,$this->hPt-$y*_MPDFK,$w*_MPDFK,$h*_MPDFK,$link);
  2833. if ($this->keep_block_together) { // Save to array - don't write yet
  2834. $this->ktLinks[$this->page][]= $l;
  2835. return;
  2836. }
  2837. else if ($this->table_rotate) { // *TABLES*
  2838. $this->tbrot_Links[$this->page][]= $l; // *TABLES*
  2839. return; // *TABLES*
  2840. } // *TABLES*
  2841. else if ($this->kwt) {
  2842. $this->kwt_Links[$this->page][]= $l;
  2843. return;
  2844. }
  2845. if ($this->writingHTMLheader || $this->writingHTMLfooter) {
  2846. $this->HTMLheaderPageLinks[]= $l;
  2847. return;
  2848. }
  2849. //Put a link on the page
  2850. $this->PageLinks[$this->page][]= $l;
  2851. // Save cross-reference to Column buffer
  2852. $ref = count($this->PageLinks[$this->page])-1; // *COLUMNS*
  2853. $this->columnLinks[$this->CurrCol][INTVAL($this->x)][INTVAL($this->y)] = $ref; // *COLUMNS*
  2854. }
  2855. function Text($x,$y,$txt) {
  2856. // Output a string
  2857. // Called (internally) by Watermark and _tableWrite [rotated cells]
  2858. // Expects input to be mb_encoded if necessary and RTL reversed
  2859. // ARTIFICIAL BOLD AND ITALIC
  2860. $s = 'q ';
  2861. if ($this->falseBoldWeight && strpos($this->ReqFontStyle,"B") !== false && strpos($this->FontStyle,"B") === false) {
  2862. $s .= '2 Tr 1 J 1 j ';
  2863. $s .= sprintf('%.3F w ',($this->FontSize/130)*_MPDFK*$this->falseBoldWeight);
  2864. $tc = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  2865. if($this->FillColor!=$tc) { $s .= $tc.' '; } // stroke (outline) = same colour as text(fill)
  2866. }
  2867. if (strpos($this->ReqFontStyle,"I") !== false && strpos($this->FontStyle,"I") === false) {
  2868. $aix = '1 0 0.261799 1 %.3F %.3F Tm';
  2869. }
  2870. else { $aix = '%.3F %.3F Td'; }
  2871. if($this->ColorFlag) $s.=$this->TextColor.' ';
  2872. $this->CurrentFont['used']= true;
  2873. if ($this->CurrentFont['type']=='TTF' && ($this->CurrentFont['sip'] || $this->CurrentFont['smp'])) {
  2874. $txt2 = str_replace(chr(194).chr(160),chr(32),$txt);
  2875. $txt2 = $this->UTF8toSubset($txt2);
  2876. $s.=sprintf('BT '.$aix.' %s Tj ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$txt2);
  2877. }
  2878. else if (!$this->usingCoreFont) { // mPDF 5.3.22
  2879. $txt2 = str_replace(chr(194).chr(160),chr(32),$txt);
  2880. $this->UTF8StringToArray($txt2); // this is just to add chars to subset list
  2881. if ($this->kerning && $this->useKerning) { $s .= $this->_kern($txt2, '', $aix, $x, $y); }
  2882. else {
  2883. //Convert string to UTF-16BE without BOM
  2884. $txt2= $this->UTF8ToUTF16BE($txt2, false);
  2885. $s.=sprintf('BT '.$aix.' (%s) Tj ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$this->_escape($txt2));
  2886. }
  2887. }
  2888. else {
  2889. $txt2 = str_replace(chr(160),chr(32),$txt);
  2890. if ($this->kerning && $this->useKerning) { $s .= $this->_kern($txt2, '', $aix, $x, $y); }
  2891. else {
  2892. $s.=sprintf('BT '.$aix.' (%s) Tj ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$this->_escape($txt2));
  2893. }
  2894. }
  2895. if($this->U && $txt!='') {
  2896. // mPDF 5.3.34
  2897. $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  2898. if($this->FillColor!=$c) { $s.= ' '.$c.' '; }
  2899. if (isset($this->CurrentFont['up'])) { $up=$this->CurrentFont['up']; }
  2900. else { $up = -100; }
  2901. $adjusty = (-$up/1000* $this->FontSize);
  2902. if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; }
  2903. else { $ut = 60/1000* $this->FontSize; }
  2904. $olw = $this->LineWidth;
  2905. $s.=' '.(sprintf(' %.3F w',$ut*_MPDFK));
  2906. $s.=' '.$this->_dounderline($x,$y + $adjusty,$txt);
  2907. $s.=' '.(sprintf(' %.3F w',$olw*_MPDFK));
  2908. if($this->FillColor!=$c) { $s.= ' '.$this->FillColor.' '; }
  2909. }
  2910. // STRIKETHROUGH // mPDF 5.3.54
  2911. if($this->strike && $txt!='') {
  2912. $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  2913. if($this->FillColor!=$c) { $s.= ' '.$c.' '; }
  2914. //Superscript and Subscript Y coordinate adjustment (now for striked-through texts)
  2915. if (isset($this->CurrentFont['desc']['CapHeight'])) { $ch=$this->CurrentFont['desc']['CapHeight']; }
  2916. else { $ch = 700; }
  2917. $adjusty = (-$ch/1000* $this->FontSize) * 0.35;
  2918. if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; }
  2919. else { $ut = 60/1000* $this->FontSize; }
  2920. $olw = $this->LineWidth;
  2921. $s.=' '.(sprintf(' %.3F w',$ut*_MPDFK));
  2922. $s.=' '.$this->_dounderline($x,$y+$adjusty,$txt);
  2923. $s.=' '.(sprintf(' %.3F w',$olw*_MPDFK));
  2924. if($this->FillColor!=$c) { $s.= ' '.$this->FillColor.' '; }
  2925. }
  2926. $s .= 'Q';
  2927. $this->_out($s);
  2928. }
  2929. /*-- DIRECTW --*/
  2930. function WriteText($x,$y,$txt) {
  2931. // Output a string using Text() but does encoding and text reversing of RTL
  2932. $txt = $this->purify_utf8_text($txt);
  2933. if ($this->text_input_as_HTML) {
  2934. $txt = $this->all_entities_to_utf8($txt);
  2935. }
  2936. if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); } // mPDF 5.3.22
  2937. // DIRECTIONALITY
  2938. if (preg_match("/([".$this->pregRTLchars."])/u", $txt)) { $this->biDirectional = true; } // *RTL*
  2939. $this->magic_reverse_dir($txt, true, $this->directionality); // *RTL*
  2940. // Font-specific ligature substitution for Indic fonts
  2941. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($txt); // *INDIC*
  2942. $this->Text($x,$y,$txt);
  2943. }
  2944. function WriteCell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='', $currentx=0) {
  2945. //Output a cell using Cell() but does encoding and text reversing of RTL
  2946. $txt = $this->purify_utf8_text($txt);
  2947. if ($this->text_input_as_HTML) {
  2948. $txt = $this->all_entities_to_utf8($txt);
  2949. }
  2950. if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); } // mPDF 5.3.07 // mPDF 5.3.22
  2951. // DIRECTIONALITY
  2952. if (preg_match("/([".$this->pregRTLchars."])/u", $txt)) { $this->biDirectional = true; } // *RTL*
  2953. $this->magic_reverse_dir($txt, true, $this->directionality); // *RTL*
  2954. // Font-specific ligature substitution for Indic fonts
  2955. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($txt); // *INDIC*
  2956. $this->Cell($w,$h,$txt,$border,$ln,$align,$fill,$link, $currentx);
  2957. }
  2958. /*-- END DIRECTW --*/
  2959. function ResetSpacing() {
  2960. if ($this->ws != 0) { $this->_out('BT 0 Tw ET'); }
  2961. $this->ws=0;
  2962. if ($this->charspacing != 0) { $this->_out('BT 0 Tc ET'); }
  2963. $this->charspacing=0;
  2964. }
  2965. function SetSpacing($cs,$ws) {
  2966. if (intval($cs*1000)==0) { $cs = 0; }
  2967. if ($cs) { $this->_out(sprintf('BT %.3F Tc ET',$cs)); }
  2968. else if ($this->charspacing != 0) { $this->_out('BT 0 Tc ET'); }
  2969. $this->charspacing=$cs;
  2970. if (intval($ws*1000)==0) { $ws = 0; }
  2971. if ($ws) { $this->_out(sprintf('BT %.3F Tw ET',$ws)); }
  2972. else if ($this->ws != 0) { $this->_out('BT 0 Tw ET'); }
  2973. $this->ws=$ws;
  2974. }
  2975. // WORD SPACING
  2976. function GetJspacing($nc,$ns,$w,$inclCursive) {
  2977. $ws = 0;
  2978. $charspacing = 0;
  2979. $ww = $this->jSWord;
  2980. $ncx = $nc-1;
  2981. if ($nc == 0) { return array(0,0); }
  2982. else if ($nc==1) { $charspacing = $w; }
  2983. // Only word spacing allowed / possible
  2984. else if ($this->fixedlSpacing !== false || $inclCursive) {
  2985. if ($ns) { $ws = $w / $ns; }
  2986. }
  2987. else if (!$ns) {
  2988. $charspacing = $w / ($ncx );
  2989. if (($this->jSmaxChar > 0) && ($charspacing > $this->jSmaxChar)) {
  2990. $charspacing = $this->jSmaxChar;
  2991. }
  2992. }
  2993. else if ($ns == ($ncx )) {
  2994. $charspacing = $w / $ns;
  2995. }
  2996. else {
  2997. if ($this->usingCoreFont) {
  2998. $cs = ($w * (1 - $this->jSWord)) / ($ncx );
  2999. if (($this->jSmaxChar > 0) && ($cs > $this->jSmaxChar)) {
  3000. $cs = $this->jSmaxChar;
  3001. $ww = 1 - (($cs * ($ncx ))/$w);
  3002. }
  3003. $charspacing = $cs;
  3004. $ws = ($w * ($ww) ) / $ns;
  3005. }
  3006. else {
  3007. $cs = ($w * (1 - $this->jSWord)) / ($ncx -$ns);
  3008. if (($this->jSmaxChar > 0) && ($cs > $this->jSmaxChar)) {
  3009. $cs = $this->jSmaxChar;
  3010. $ww = 1 - (($cs * ($ncx -$ns))/$w);
  3011. }
  3012. $charspacing = $cs;
  3013. $ws = (($w * ($ww) ) / $ns) - $charspacing;
  3014. }
  3015. }
  3016. return array($charspacing,$ws);
  3017. }
  3018. function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='', $currentx=0, $lcpaddingL=0, $lcpaddingR=0, $valign='M', $spanfill=0, $abovefont=0, $belowfont=0, $exactWidth=false) { // mPDF 5.3.07
  3019. //Output a cell
  3020. // Expects input to be mb_encoded if necessary and RTL reversed
  3021. // NON_BREAKING SPACE
  3022. if ($this->usingCoreFont) {
  3023. $txt = str_replace(chr(160),chr(32),$txt);
  3024. }
  3025. else {
  3026. $txt = str_replace(chr(194).chr(160),chr(32),$txt);
  3027. }
  3028. $oldcolumn = $this->CurrCol;
  3029. // Automatic page break
  3030. // Allows PAGE-BREAK-AFTER = avoid to work
  3031. if (!$this->tableLevel && (($this->y+$this->divheight>$this->PageBreakTrigger) || ($this->y+$h>$this->PageBreakTrigger) ||
  3032. ($this->y+($h*2)>$this->PageBreakTrigger && $this->blk[$this->blklvl]['page_break_after_avoid'])) and !$this->InFooter and $this->AcceptPageBreak()) {
  3033. $x=$this->x;//Current X position
  3034. // WORD SPACING
  3035. $ws=$this->ws;//Word Spacing
  3036. $charspacing=$this->charspacing;//Character Spacing
  3037. $this->ResetSpacing();
  3038. $this->AddPage($this->CurOrientation);
  3039. // Added to correct for OddEven Margins
  3040. $x += $this->MarginCorrection;
  3041. if ($currentx) {
  3042. $currentx += $this->MarginCorrection;
  3043. }
  3044. $this->x=$x;
  3045. // WORD SPACING
  3046. $this->SetSpacing($charspacing,$ws);
  3047. }
  3048. // Test: to put line through centre of cell: $this->Line($this->x,$this->y+($h/2),$this->x+50,$this->y+($h/2));
  3049. /*-- COLUMNS --*/
  3050. // COLS
  3051. // COLUMN CHANGE
  3052. if ($this->CurrCol != $oldcolumn) {
  3053. if ($currentx) {
  3054. $currentx += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  3055. }
  3056. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  3057. }
  3058. // COLUMNS Update/overwrite the lowest bottom of printing y value for a column
  3059. if ($this->ColActive) {
  3060. if ($h) { $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y+$h; }
  3061. else { $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y+$this->divheight; }
  3062. }
  3063. /*-- END COLUMNS --*/
  3064. // KEEP BLOCK TOGETHER Update/overwrite the lowest bottom of printing y value on first page
  3065. if ($this->keep_block_together) {
  3066. if ($h) { $this->ktBlock[$this->page]['bottom_margin'] = $this->y+$h; }
  3067. // else { $this->ktBlock[$this->page]['bottom_margin'] = $this->y+$this->divheight; }
  3068. }
  3069. if($w==0) $w = $this->w-$this->rMargin-$this->x;
  3070. $s='';
  3071. if($fill==1 && $this->FillColor) {
  3072. if((isset($this->pageoutput[$this->page]['FillColor']) && $this->pageoutput[$this->page]['FillColor'] != $this->FillColor) || !isset($this->pageoutput[$this->page]['FillColor']) || $this->keep_block_together) { $s .= $this->FillColor.' '; }
  3073. $this->pageoutput[$this->page]['FillColor'] = $this->FillColor;
  3074. }
  3075. $boxtop = $this->y;
  3076. $boxheight = $h;
  3077. $boxbottom = $this->y+$h;
  3078. if($txt!='') {
  3079. // FONT SIZE - this determines the baseline caculation
  3080. if ($this->linemaxfontsize && !$this->processingHeader) { $bfs = $this->linemaxfontsize; }
  3081. else { $bfs = $this->FontSize; }
  3082. //Calculate baseline Superscript and Subscript Y coordinate adjustment
  3083. $bfx = $this->baselineC;
  3084. $baseline = $bfx*$bfs;
  3085. if($this->SUP) { $baseline += ($bfx-1.05)*$this->FontSize; }
  3086. else if($this->SUB) { $baseline += ($bfx + 0.04)*$this->FontSize; }
  3087. else if($this->bullet) { $baseline += ($bfx-0.7)*$this->FontSize; }
  3088. // Vertical align (for Images)
  3089. if ($abovefont || $belowfont) { // from flowing block - valign always M
  3090. $va = $abovefont + (0.5*$bfs);
  3091. }
  3092. else if ($this->lineheight_correction) {
  3093. if ($valign == 'T') { $va = (0.5 * $bfs * $this->lineheight_correction); }
  3094. else if ($valign == 'B') { $va = $h-(0.5 * $bfs * $this->lineheight_correction); }
  3095. else { $va = 0.5*$h; } // Middle
  3096. }
  3097. else {
  3098. if ($valign == 'T') { $va = (0.5 * $bfs * $this->default_lineheight_correction); }
  3099. else if ($valign == 'B') { $va = $h-(0.5 * $bfs * $this->default_lineheight_correction); }
  3100. else { $va = 0.5*$h; } // Middle
  3101. }
  3102. // ONLY SET THESE IF WANT TO CONFINE BORDER +/- FILL TO FIT FONTSIZE - NOT FULL CELL AS IS ORIGINAL FUNCTION
  3103. // spanfill or spanborder are set in FlowingBlock functions
  3104. // mPDF 5.3.52
  3105. if ($spanfill || !empty($this->spanborddet) || $link!='') { // mPDF 5.3.71
  3106. $exth = 0.2; // Add to fontsize to increase height of background / link / border
  3107. $boxtop = $this->y+$baseline+$va-($this->FontSize*(1+$exth/2)*(0.5+$bfx));
  3108. $boxheight = $this->FontSize * (1+$exth);
  3109. $boxbottom = $boxtop + $boxheight;
  3110. }
  3111. }
  3112. // mPDF 5.3.61
  3113. $bbw = $tbw = $lbw = $rbw = 0; // Border widths
  3114. if (!empty($this->spanborddet)) {
  3115. // mPDF 5.3.76
  3116. if (!isset($this->spanborddet['B'])) { $this->spanborddet['B'] = array('s' => 0, 'style' => '', 'w' => 0); }
  3117. if (!isset($this->spanborddet['T'])) { $this->spanborddet['T'] = array('s' => 0, 'style' => '', 'w' => 0); }
  3118. if (!isset($this->spanborddet['L'])) { $this->spanborddet['L'] = array('s' => 0, 'style' => '', 'w' => 0); }
  3119. if (!isset($this->spanborddet['R'])) { $this->spanborddet['R'] = array('s' => 0, 'style' => '', 'w' => 0); }
  3120. // mPDF 5.3.61
  3121. $bbw = $this->spanborddet['B']['w'];
  3122. $tbw = $this->spanborddet['T']['w'];
  3123. $lbw = $this->spanborddet['L']['w'];
  3124. $rbw = $this->spanborddet['R']['w'];
  3125. }
  3126. if($fill==1 || $border==1 || !empty($this->spanborddet)) { // mPDF 5.3.61
  3127. // mPDF 5.3.61
  3128. if (!empty($this->spanborddet)) {
  3129. if ($fill==1) {
  3130. $s.=sprintf('%.3F %.3F %.3F %.3F re f ',($this->x-$lbw)*_MPDFK,($this->h-$boxtop+$tbw)*_MPDFK,($w+$lbw+$rbw)*_MPDFK,(-$boxheight-$tbw-$bbw)*_MPDFK);
  3131. }
  3132. $s.= ' q ';
  3133. $dashon = 3;
  3134. $dashoff = 3.5;
  3135. $dot = 2.5;
  3136. if($tbw) { // mPDF 5.3.76
  3137. $short = 0;
  3138. if ($this->spanborddet['T']['style'] == 'dashed') {
  3139. $s.=sprintf(' 0 j 0 J [%.3F %.3F] 0 d ',$tbw*$dashon*_MPDFK,$tbw*$dashoff*_MPDFK);
  3140. }
  3141. else if ($this->spanborddet['T']['style'] == 'dotted') {
  3142. $s.=sprintf(' 1 j 1 J [%.3F %.3F] %.3F d ',0.001,$tbw*$dot*_MPDFK,-$tbw/2*_MPDFK);
  3143. $short = $tbw/2;
  3144. }
  3145. else {
  3146. $s.=' 0 j 0 J [] 0 d ';
  3147. }
  3148. $c = $this->SetDColor($this->spanborddet['T']['c'],true);
  3149. if ($this->spanborddet['T']['style'] == 'double') {
  3150. $s.=sprintf(' %s %.3F w ',$c,$tbw/3*_MPDFK);
  3151. $xadj = $xadj2 = 0;
  3152. if ($this->spanborddet['L']['style'] == 'double') { $xadj = $this->spanborddet['L']['w']*2/3; }
  3153. if ($this->spanborddet['R']['style'] == 'double') { $xadj2 = $this->spanborddet['R']['w']*2/3; }
  3154. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw)*_MPDFK,($this->h-$boxtop+$tbw*5/6)*_MPDFK,($this->x+$w+$rbw-$short)*_MPDFK,($this->h-$boxtop+$tbw*5/6)*_MPDFK);
  3155. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw+$xadj)*_MPDFK,($this->h-$boxtop+$tbw/6)*_MPDFK,($this->x+$w+$rbw-$short-$xadj2)*_MPDFK,($this->h-$boxtop+$tbw/6)*_MPDFK);
  3156. }
  3157. else {
  3158. $s.=sprintf(' %s %.3F w ',$c,$tbw*_MPDFK);
  3159. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw)*_MPDFK,($this->h-$boxtop+$tbw/2)*_MPDFK,($this->x+$w+$rbw-$short)*_MPDFK,($this->h-$boxtop+$tbw/2)*_MPDFK);
  3160. }
  3161. }
  3162. if($bbw) { // mPDF 5.3.76
  3163. $short = 0;
  3164. if ($this->spanborddet['B']['style'] == 'dashed') {
  3165. $s.=sprintf(' 0 j 0 J [%.3F %.3F] 0 d ',$bbw*$dashon*_MPDFK,$bbw*$dashoff*_MPDFK);
  3166. }
  3167. else if ($this->spanborddet['B']['style'] == 'dotted') {
  3168. $s.=sprintf(' 1 j 1 J [%.3F %.3F] %.3F d ',0.001,$bbw*$dot*_MPDFK,-$bbw/2*_MPDFK);
  3169. $short = $bbw/2;
  3170. }
  3171. else {
  3172. $s.=' 0 j 0 J [] 0 d ';
  3173. }
  3174. $c = $this->SetDColor($this->spanborddet['B']['c'],true);
  3175. if ($this->spanborddet['B']['style'] == 'double') {
  3176. $s.=sprintf(' %s %.3F w ',$c,$bbw/3*_MPDFK);
  3177. $xadj = $xadj2 = 0;
  3178. if ($this->spanborddet['L']['style'] == 'double') { $xadj = $this->spanborddet['L']['w']*2/3; }
  3179. if ($this->spanborddet['R']['style'] == 'double') { $xadj2 = $this->spanborddet['R']['w']*2/3; }
  3180. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw+$xadj)*_MPDFK,($this->h-$boxbottom-$bbw/6)*_MPDFK,($this->x+$w+$rbw-$short-$xadj2)*_MPDFK,($this->h-$boxbottom-$bbw/6)*_MPDFK);
  3181. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw)*_MPDFK,($this->h-$boxbottom-$bbw*5/6)*_MPDFK,($this->x+$w+$rbw-$short)*_MPDFK,($this->h-$boxbottom-$bbw*5/6)*_MPDFK);
  3182. }
  3183. else {
  3184. $s.=sprintf(' %s %.3F w ',$c,$bbw*_MPDFK);
  3185. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw)*_MPDFK,($this->h-$boxbottom-$bbw/2)*_MPDFK,($this->x+$w+$rbw-$short)*_MPDFK,($this->h-$boxbottom-$bbw/2)*_MPDFK);
  3186. }
  3187. }
  3188. if($lbw) { // mPDF 5.3.76
  3189. $short = 0;
  3190. if ($this->spanborddet['L']['style'] == 'dashed') {
  3191. $s.=sprintf(' 0 j 0 J [%.3F %.3F] 0 d ',$lbw*$dashon*_MPDFK,$lbw*$dashoff*_MPDFK);
  3192. }
  3193. else if ($this->spanborddet['L']['style'] == 'dotted') {
  3194. $s.=sprintf(' 1 j 1 J [%.3F %.3F] %.3F d ',0.001,$lbw*$dot*_MPDFK,-$lbw/2*_MPDFK);
  3195. $short = $lbw/2;
  3196. }
  3197. else {
  3198. $s.=' 0 j 0 J [] 0 d ';
  3199. }
  3200. $c = $this->SetDColor($this->spanborddet['L']['c'],true);
  3201. if ($this->spanborddet['L']['style'] == 'double') {
  3202. $s.=sprintf(' %s %.3F w ',$c,$lbw/3*_MPDFK);
  3203. $yadj = $yadj2 = 0;
  3204. if ($this->spanborddet['T']['style'] == 'double') { $yadj = $this->spanborddet['T']['w']*2/3; }
  3205. if ($this->spanborddet['B']['style'] == 'double') { $yadj2 = $this->spanborddet['B']['w']*2/3; }
  3206. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw/6)*_MPDFK,($this->h-$boxtop+$tbw-$yadj)*_MPDFK,($this->x-$lbw/6)*_MPDFK,($this->h-$boxbottom-$bbw+$short+$yadj2)*_MPDFK);
  3207. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw*5/6)*_MPDFK,($this->h-$boxtop+$tbw)*_MPDFK,($this->x-$lbw*5/6)*_MPDFK,($this->h-$boxbottom-$bbw+$short)*_MPDFK);
  3208. }
  3209. else {
  3210. $s.=sprintf(' %s %.3F w ',$c,$lbw*_MPDFK);
  3211. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw/2)*_MPDFK,($this->h-$boxtop+$tbw)*_MPDFK,($this->x-$lbw/2)*_MPDFK,($this->h-$boxbottom-$bbw+$short)*_MPDFK);
  3212. }
  3213. }
  3214. if($rbw) { // mPDF 5.3.76
  3215. $short = 0;
  3216. if ($this->spanborddet['R']['style'] == 'dashed') {
  3217. $s.=sprintf(' 0 j 0 J [%.3F %.3F] 0 d ',$rbw*$dashon*_MPDFK,$rbw*$dashoff*_MPDFK);
  3218. }
  3219. else if ($this->spanborddet['R']['style'] == 'dotted') {
  3220. $s.=sprintf(' 1 j 1 J [%.3F %.3F] %.3F d ',0.001,$rbw*$dot*_MPDFK,-$rbw/2*_MPDFK);
  3221. $short = $rbw/2;
  3222. }
  3223. else {
  3224. $s.=' 0 j 0 J [] 0 d ';
  3225. }
  3226. $c = $this->SetDColor($this->spanborddet['R']['c'],true);
  3227. if ($this->spanborddet['R']['style'] == 'double') {
  3228. $s.=sprintf(' %s %.3F w ',$c,$rbw/3*_MPDFK);
  3229. $yadj = $yadj2 = 0;
  3230. if ($this->spanborddet['T']['style'] == 'double') { $yadj = $this->spanborddet['T']['w']*2/3; }
  3231. if ($this->spanborddet['B']['style'] == 'double') { $yadj2 = $this->spanborddet['B']['w']*2/3; }
  3232. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x+$w+$rbw/6)*_MPDFK,($this->h-$boxtop+$tbw-$yadj)*_MPDFK,($this->x+$w+$rbw/6)*_MPDFK,($this->h-$boxbottom-$bbw+$short+$yadj2)*_MPDFK);
  3233. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x+$w+$rbw*5/6)*_MPDFK,($this->h-$boxtop+$tbw)*_MPDFK,($this->x+$w+$rbw*5/6)*_MPDFK,($this->h-$boxbottom-$bbw+$short)*_MPDFK);
  3234. }
  3235. else {
  3236. $s.=sprintf(' %s %.3F w ',$c,$rbw*_MPDFK);
  3237. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x+$w+$rbw/2)*_MPDFK,($this->h-$boxtop+$tbw)*_MPDFK,($this->x+$w+$rbw/2)*_MPDFK,($this->h-$boxbottom-$bbw+$short)*_MPDFK);
  3238. }
  3239. }
  3240. $s.= ' Q ';
  3241. }
  3242. else {
  3243. if ($fill==1) $op=($border==1) ? 'B' : 'f';
  3244. else $op='S';
  3245. $s.=sprintf('%.3F %.3F %.3F %.3F re %s ',$this->x*_MPDFK,($this->h-$boxtop)*_MPDFK,$w*_MPDFK,-$boxheight*_MPDFK,$op);
  3246. }
  3247. }
  3248. if(is_string($border)) {
  3249. $x=$this->x;
  3250. $y=$this->y;
  3251. if(is_int(strpos($border,'L')))
  3252. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',$x*_MPDFK,($this->h-$boxtop)*_MPDFK,$x*_MPDFK,($this->h-($boxbottom))*_MPDFK);
  3253. if(is_int(strpos($border,'T')))
  3254. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',$x*_MPDFK,($this->h-$boxtop)*_MPDFK,($x+$w)*_MPDFK,($this->h-$boxtop)*_MPDFK);
  3255. if(is_int(strpos($border,'R')))
  3256. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($x+$w)*_MPDFK,($this->h-$boxtop)*_MPDFK,($x+$w)*_MPDFK,($this->h-($boxbottom))*_MPDFK);
  3257. if(is_int(strpos($border,'B')))
  3258. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',$x*_MPDFK,($this->h-($boxbottom))*_MPDFK,($x+$w)*_MPDFK,($this->h-($boxbottom))*_MPDFK);
  3259. }
  3260. if($txt!='') {
  3261. if ($exactWidth) // mPDF 5.3.07
  3262. $stringWidth = $w;
  3263. else // mPDF 5.3.07 // mPDF 5.3.20
  3264. $stringWidth = $this->GetStringWidth($txt) + ( $this->charspacing * mb_strlen( $txt, $this->mb_enc ) / _MPDFK )
  3265. + ( $this->ws * mb_substr_count( $txt, ' ', $this->mb_enc ) / _MPDFK );
  3266. // Set x OFFSET FOR PRINTING
  3267. if($align=='R') {
  3268. $dx=$w-$this->cMarginR - $stringWidth - $lcpaddingR;
  3269. }
  3270. elseif($align=='C') {
  3271. $dx=(($w - $stringWidth )/2);
  3272. }
  3273. elseif($align=='L' or $align=='J') $dx=$this->cMarginL + $lcpaddingL;
  3274. else $dx = 0;
  3275. if($this->ColorFlag) $s .='q '.$this->TextColor.' ';
  3276. // OUTLINE
  3277. if($this->outline_on && !$this->S) {
  3278. $s .=' '.sprintf('%.3F w',$this->LineWidth*_MPDFK).' ';
  3279. $s .=" $this->DrawColor ";
  3280. $s .=" 2 Tr ";
  3281. }
  3282. else if ($this->falseBoldWeight && strpos($this->ReqFontStyle,"B") !== false && strpos($this->FontStyle,"B") === false && !$this->S) { // can't use together with OUTLINE or Small Caps
  3283. $s .= ' 2 Tr 1 J 1 j ';
  3284. $s .= ' '.sprintf('%.3F w',($this->FontSize/130)*_MPDFK*$this->falseBoldWeight).' ';
  3285. $tc = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  3286. if($this->FillColor!=$tc) { $s .= ' '.$tc.' '; } // stroke (outline) = same colour as text(fill)
  3287. }
  3288. if (strpos($this->ReqFontStyle,"I") !== false && strpos($this->FontStyle,"I") === false) { // Artificial italic
  3289. $aix = '1 0 0.261799 1 %.3F %.3F Tm ';
  3290. }
  3291. else { $aix = '%.3F %.3F Td '; }
  3292. // THE TEXT
  3293. // mPDF 5.3.A2 Capture in substring $sub
  3294. $sub = '';
  3295. $this->CurrentFont['used']= true;
  3296. // WORD SPACING
  3297. // IF multibyte - Tw has no effect - need to use alternative method - do word spacing using an adjustment before each space
  3298. if ($this->ws && !$this->usingCoreFont && !$this->CurrentFont['sip'] && !$this->CurrentFont['smp'] && !$this->S) {
  3299. $sub .= ' BT 0 Tw ET ';
  3300. if ($this->kerning && $this->useKerning) { $sub .= $this->_kern($txt, 'MBTw', $aix, ($this->x+$dx), ($this->y+$baseline+$va)); }
  3301. else {
  3302. $space = " ";
  3303. //Convert string to UTF-16BE without BOM
  3304. $space= $this->UTF8ToUTF16BE($space , false);
  3305. $space=$this->_escape($space );
  3306. $sub .=sprintf('BT '.$aix,($this->x+$dx)*_MPDFK,($this->h-($this->y+$baseline+$va))*_MPDFK);
  3307. $t = explode(' ',$txt);
  3308. $sub .=sprintf(' %.3F Tc [',$this->charspacing);
  3309. $numt = count($t); // mPDF 5.3.07
  3310. for($i=0;$i<$numt;$i++) { // mPDF 5.3.07
  3311. $tx = $t[$i];
  3312. //Convert string to UTF-16BE without BOM
  3313. $tx = $this->UTF8ToUTF16BE($tx , false);
  3314. $tx = $this->_escape($tx);
  3315. $sub .=sprintf('(%s) ',$tx);
  3316. if (($i+1)<$numt) { // mPDF 5.3.07
  3317. $adj = -($this->ws)*1000/$this->FontSizePt;
  3318. $sub .=sprintf('%d(%s) ',$adj,$space);
  3319. }
  3320. }
  3321. $sub .='] TJ ';
  3322. $sub .=' ET';
  3323. }
  3324. }
  3325. else {
  3326. $txt2= $txt;
  3327. if ($this->CurrentFont['type']=='TTF' && ($this->CurrentFont['sip'] || $this->CurrentFont['smp'])) {
  3328. if ($this->S) { $sub .= $this->_smallCaps($txt2, 'SIPSMP', $aix, $dx, _MPDFK, $baseline, $va); }
  3329. else {
  3330. $txt2 = $this->UTF8toSubset($txt2);
  3331. $sub .=sprintf('BT '.$aix.' %s Tj ET',($this->x+$dx)*_MPDFK,($this->h-($this->y+$baseline+$va))*_MPDFK,$txt2);
  3332. }
  3333. }
  3334. else {
  3335. if ($this->S) { $sub .= $this->_smallCaps($txt2, '', $aix, $dx, _MPDFK, $baseline, $va); }
  3336. else if ($this->kerning && $this->useKerning) { $sub .= $this->_kern($txt2, '', $aix, ($this->x+$dx), ($this->y+$baseline+$va)); }
  3337. else {
  3338. if (!$this->usingCoreFont) {
  3339. $txt2 = $this->UTF8ToUTF16BE($txt2, false);
  3340. }
  3341. $txt2=$this->_escape($txt2);
  3342. $sub .=sprintf('BT '.$aix.' (%s) Tj ET',($this->x+$dx)*_MPDFK,($this->h-($this->y+$baseline+$va))*_MPDFK,$txt2);
  3343. }
  3344. }
  3345. }
  3346. // UNDERLINE
  3347. if($this->U) {
  3348. $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  3349. if($this->FillColor!=$c) { $sub .= ' '.$c.' '; }
  3350. if (isset($this->CurrentFont['up'])) { $up=$this->CurrentFont['up']; }
  3351. else { $up = -100; }
  3352. $adjusty = (-$up/1000* $this->FontSize);
  3353. if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; }
  3354. else { $ut = 60/1000* $this->FontSize; }
  3355. $olw = $this->LineWidth;
  3356. $sub .=' '.(sprintf(' %.3F w 0 j 0 J ',$ut*_MPDFK)); // mPDF 5.3.61
  3357. $sub .=' '.$this->_dounderline($this->x+$dx,$this->y+$baseline+$va+$adjusty,$txt);
  3358. $sub .=' '.(sprintf(' %.3F w 2 j 2 J ',$olw*_MPDFK)); // mPDF 5.3.61
  3359. if($this->FillColor!=$c) { $sub .= ' '.$this->FillColor.' '; }
  3360. }
  3361. // STRIKETHROUGH
  3362. if($this->strike) {
  3363. $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  3364. if($this->FillColor!=$c) { $sub .= ' '.$c.' '; }
  3365. //Superscript and Subscript Y coordinate adjustment (now for striked-through texts)
  3366. if (isset($this->CurrentFont['desc']['CapHeight'])) { $ch=$this->CurrentFont['desc']['CapHeight']; }
  3367. else { $ch = 700; }
  3368. $adjusty = (-$ch/1000* $this->FontSize) * 0.35;
  3369. if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; }
  3370. else { $ut = 60/1000* $this->FontSize; }
  3371. $olw = $this->LineWidth;
  3372. $sub .=' '.(sprintf(' %.3F w 0 j 0 J ',$ut*_MPDFK)); // mPDF 5.3.61
  3373. $sub .=' '.$this->_dounderline($this->x+$dx,$this->y+$baseline+$va+$adjusty,$txt);
  3374. $sub .=' '.(sprintf(' %.3F w 2 j 2 J ',$olw*_MPDFK)); // mPDF 5.3.54 // mPDF 5.3.61
  3375. if($this->FillColor!=$c) { $sub .= ' '.$this->FillColor.' '; }
  3376. }
  3377. // mPDF 5.3.A2
  3378. // TEXT SHADOW
  3379. if ($this->textshadow) { // First to process is last in CSS comma separated shadows
  3380. foreach($this->textshadow AS $ts) {
  3381. $s .= ' q ';
  3382. $s .= $this->SetTColor($ts['col'], true)."\n";
  3383. if ($ts['col']{0}==5 && ord($ts['col']{4})<100) { // RGBa
  3384. $s .= $this->SetAlpha(ord($ts['col']{4})/100, 'Normal', true, 'F')."\n";
  3385. }
  3386. else if ($ts['col']{0}==6 && ord($ts['col']{5})<100) { // CMYKa
  3387. $s .= $this->SetAlpha(ord($ts['col']{5})/100, 'Normal', true, 'F')."\n";
  3388. }
  3389. else if ($ts['col']{0}==1 && $ts['col']{2}==1 && ord($ts['col']{3})<100) { // Gray
  3390. $s .= $this->SetAlpha(ord($ts['col']{3})/100, 'Normal', true, 'F')."\n";
  3391. }
  3392. $s .= sprintf(' q 1 0 0 1 %.4F %.4F cm', $ts['x']*_MPDFK, -$ts['y']*_MPDFK)."\n";
  3393. $s .= $sub;
  3394. $s .= ' Q ';
  3395. $s .= ' Q ';
  3396. }
  3397. }
  3398. $s .= $sub;
  3399. // COLOR
  3400. if($this->ColorFlag) $s .=' Q';
  3401. // LINK
  3402. if($link!='') {
  3403. // mPDF 5.3.16
  3404. // Use same co-ordinates as span FILL above
  3405. $this->Link($this->x,$boxtop,$w,$boxheight,$link);
  3406. // Use this to add some padding/spacing around the textbox for the LINK
  3407. // Use same spacing as span FILL above
  3408. // $hsp = $this->FontSize/7;
  3409. // $vsp = $this->FontSize/10;
  3410. // $this->Link($this->x-$hsp,$boxtop-$vsp,$w+2*$hsp,$boxheight+2*$vsp,$link);
  3411. }
  3412. }
  3413. if($s) $this->_out($s);
  3414. // WORD SPACING
  3415. if ($this->ws && !$this->usingCoreFont) {
  3416. $this->_out(sprintf('BT %.3F Tc ET',$this->charspacing));
  3417. }
  3418. $this->lasth=$h;
  3419. if( strpos($txt,"\n") !== false) $ln=1; // cell recognizes \n from <BR> tag
  3420. if($ln>0)
  3421. {
  3422. //Go to next line
  3423. $this->y += $h;
  3424. if($ln==1) {
  3425. //Move to next line
  3426. if ($currentx != 0) { $this->x=$currentx; }
  3427. else { $this->x=$this->lMargin; }
  3428. }
  3429. }
  3430. else $this->x+=$w;
  3431. }
  3432. function _kern($txt, $mode, $aix, $x, $y) {
  3433. if ($mode == 'MBTw') { // Multibyte requiring word spacing
  3434. $space = ' ';
  3435. //Convert string to UTF-16BE without BOM
  3436. $space= $this->UTF8ToUTF16BE($space , false);
  3437. $space=$this->_escape($space );
  3438. $s = sprintf(' BT '.$aix,$x*_MPDFK,($this->h-$y)*_MPDFK);
  3439. $t = explode(' ',$txt);
  3440. for($i=0;$i<count($t);$i++) {
  3441. $tx = $t[$i];
  3442. $tj = '(';
  3443. $unicode = $this->UTF8StringToArray($tx);
  3444. for($ti=0;$ti<count($unicode);$ti++) {
  3445. if ($ti > 0 && isset($this->CurrentFont['kerninfo'][$unicode[($ti-1)]][$unicode[$ti]])) {
  3446. $kern = -$this->CurrentFont['kerninfo'][$unicode[($ti-1)]][$unicode[$ti]];
  3447. $tj .= sprintf(')%d(',$kern);
  3448. }
  3449. $tc = code2utf($unicode[$ti]);
  3450. $tc = $this->UTF8ToUTF16BE($tc, false);
  3451. $tj .= $this->_escape($tc);
  3452. }
  3453. $tj .= ')';
  3454. $s.=sprintf(' %.3F Tc [%s] TJ',$this->charspacing,$tj);
  3455. if (($i+1)<count($t)) {
  3456. $s.=sprintf(' %.3F Tc (%s) Tj',$this->ws+$this->charspacing,$space);
  3457. }
  3458. }
  3459. $s.=' ET ';
  3460. }
  3461. else if (!$this->usingCoreFont) {
  3462. $s = '';
  3463. $tj = '(';
  3464. $unicode = $this->UTF8StringToArray($txt);
  3465. for($i=0;$i<count($unicode);$i++) {
  3466. if ($i > 0 && isset($this->CurrentFont['kerninfo'][$unicode[($i-1)]][$unicode[$i]])) {
  3467. $kern = -$this->CurrentFont['kerninfo'][$unicode[($i-1)]][$unicode[$i]];
  3468. $tj .= sprintf(')%d(',$kern);
  3469. }
  3470. $tx = code2utf($unicode[$i]);
  3471. $tx = $this->UTF8ToUTF16BE($tx, false);
  3472. $tj .= $this->_escape($tx);
  3473. }
  3474. $tj .= ')';
  3475. $s.=sprintf(' BT '.$aix.' [%s] TJ ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$tj);
  3476. }
  3477. else { // CORE Font
  3478. $s = '';
  3479. $tj = '(';
  3480. $l = strlen($txt);
  3481. for($i=0;$i<$l;$i++) {
  3482. if ($i > 0 && isset($this->CurrentFont['kerninfo'][$txt[($i-1)]][$txt[$i]])) {
  3483. $kern = -$this->CurrentFont['kerninfo'][$txt[($i-1)]][$txt[$i]];
  3484. $tj .= sprintf(')%d(',$kern);
  3485. }
  3486. $tj .= $this->_escape($txt[$i]);
  3487. }
  3488. $tj .= ')';
  3489. $s.=sprintf(' BT '.$aix.' [%s] TJ ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$tj);
  3490. }
  3491. return $s;
  3492. }
  3493. function _smallCaps($txt, $mode, $aix, $dx, $k, $baseline, $va) { // mPDF 5.3.76
  3494. $upp = false;
  3495. $str = array();
  3496. $bits = array();
  3497. if (!$this->usingCoreFont) {
  3498. $unicode = $this->UTF8StringToArray($txt);
  3499. foreach($unicode as $char) {
  3500. if ($this->ws && $char == 32) { // space
  3501. if (count($str)) { $bits[] = array($upp, $str, false); }
  3502. $bits[] = array(false, array(32), true);
  3503. $str = array();
  3504. $upp = false;
  3505. }
  3506. else if (isset($this->upperCase[$char])) {
  3507. if (!$upp) {
  3508. if (count($str)) { $bits[] = array($upp, $str, false); }
  3509. $str = array();
  3510. }
  3511. $str[] = $this->upperCase[$char];
  3512. if ((!isset($this->CurrentFont['sip']) || !$this->CurrentFont['sip']) && (!isset($this->CurrentFont['smp']) || !$this->CurrentFont['smp'])) {
  3513. $this->CurrentFont['subset'][$this->upperCase[$char]] = $this->upperCase[$char];
  3514. }
  3515. $upp = true;
  3516. }
  3517. else {
  3518. if ($upp) {
  3519. if (count($str)) { $bits[] = array($upp, $str, false); }
  3520. $str = array();
  3521. }
  3522. $str[] = $char;
  3523. $upp = false;
  3524. }
  3525. }
  3526. }
  3527. else {
  3528. for($i=0;$i<strlen($txt);$i++) {
  3529. if (isset($this->upperCase[ord($txt[$i])]) && $this->upperCase[ord($txt[$i])] < 256) {
  3530. if (!$upp) {
  3531. if (count($str)) { $bits[] = array($upp, $str, false); }
  3532. $str = array();
  3533. }
  3534. $str[] = $this->upperCase[ord($txt[$i])];
  3535. $upp = true;
  3536. }
  3537. else {
  3538. if ($upp) {
  3539. if (count($str)) { $bits[] = array($upp, $str, false); }
  3540. $str = array();
  3541. }
  3542. $str[] = ord($txt[$i]);
  3543. $upp = false;
  3544. }
  3545. }
  3546. }
  3547. if (count($str)) { $bits[] = array($upp, $str, false); }
  3548. $fid = $this->CurrentFont['i'];
  3549. $s=sprintf(' BT '.$aix,($this->x+$dx)*$k,($this->h-($this->y+$baseline+$va))*$k); // mPDF 5.3.76
  3550. foreach($bits AS $b) {
  3551. if ($b[0]) { $upp = true; }
  3552. else { $upp = false; }
  3553. $size = count ($b[1]);
  3554. $txt = '';
  3555. for ($i = 0; $i < $size; $i++) {
  3556. $txt .= code2utf($b[1][$i]);
  3557. }
  3558. if ($this->usingCoreFont) {
  3559. $txt = utf8_decode($txt);
  3560. }
  3561. if ($mode == 'SIPSMP') {
  3562. $txt = $this->UTF8toSubset($txt);
  3563. }
  3564. else {
  3565. if (!$this->usingCoreFont) {
  3566. $txt = $this->UTF8ToUTF16BE($txt, false);
  3567. }
  3568. $txt=$this->_escape($txt);
  3569. $txt = '('.$txt.')';
  3570. }
  3571. if ($b[2]) { // space
  3572. $s.=sprintf(' /F%d %.3F Tf %d Tz', $fid, $this->FontSizePt, 100);
  3573. $s.=sprintf(' %.3F Tc', ($this->charspacing+$this->ws));
  3574. $s.=sprintf(' %s Tj', $txt);
  3575. }
  3576. else if ($upp) {
  3577. $s.=sprintf(' /F%d %.3F Tf', $fid, $this->FontSizePt*$this->smCapsScale);
  3578. $s.=sprintf(' %d Tz', $this->smCapsStretch);
  3579. $s.=sprintf(' %.3F Tc', ($this->charspacing*100/$this->smCapsStretch));
  3580. $s.=sprintf(' %s Tj', $txt);
  3581. }
  3582. else {
  3583. $s.=sprintf(' /F%d %.3F Tf %d Tz', $fid, $this->FontSizePt, 100);
  3584. $s.=sprintf(' %.3F Tc', ($this->charspacing));
  3585. $s.=sprintf(' %s Tj', $txt);
  3586. }
  3587. }
  3588. $s.=' ET ';
  3589. return $s;
  3590. }
  3591. function MultiCell($w,$h,$txt,$border=0,$align='',$fill=0,$link='',$directionality='ltr',$encoded=false)
  3592. {
  3593. // Parameter (pre-)encoded - When called internally from ToC or textarea: mb_encoding already done - but not reverse RTL/Indic
  3594. if (!$encoded) {
  3595. $txt = $this->purify_utf8_text($txt);
  3596. if ($this->text_input_as_HTML) {
  3597. $txt = $this->all_entities_to_utf8($txt);
  3598. }
  3599. if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  3600. // Font-specific ligature substitution for Indic fonts
  3601. else if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { // *INDIC*
  3602. $this->ConvertIndic($tmp); // *INDIC*
  3603. } // *INDIC*
  3604. if (preg_match("/([".$this->pregRTLchars."])/u", $txt)) { $this->biDirectional = true; } // *RTL*
  3605. }
  3606. if (!$align) { $align = $this->defaultAlign; }
  3607. //Output text with automatic or explicit line breaks
  3608. $cw=&$this->CurrentFont['cw'];
  3609. if($w==0) $w=$this->w-$this->rMargin-$this->x;
  3610. $wmax = ($w - ($this->cMarginL+$this->cMarginR));
  3611. if ($this->usingCoreFont) {
  3612. $s=str_replace("\r",'',$txt);
  3613. $nb=strlen($s);
  3614. while($nb>0 and $s[$nb-1]=="\n") $nb--;
  3615. }
  3616. else {
  3617. $s=str_replace("\r",'',$txt);
  3618. $nb=mb_strlen($s, $this->mb_enc );
  3619. while($nb>0 and mb_substr($s,$nb-1,1,$this->mb_enc )=="\n") $nb--;
  3620. }
  3621. $b=0;
  3622. if($border) {
  3623. if($border==1) {
  3624. $border='LTRB';
  3625. $b='LRT';
  3626. $b2='LR';
  3627. }
  3628. else {
  3629. $b2='';
  3630. if(is_int(strpos($border,'L'))) $b2.='L';
  3631. if(is_int(strpos($border,'R'))) $b2.='R';
  3632. $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2;
  3633. }
  3634. }
  3635. $sep=-1;
  3636. $i=0;
  3637. $j=0;
  3638. $l=0;
  3639. $ns=0;
  3640. $nl=1;
  3641. if (!$this->usingCoreFont) {
  3642. $checkCursive=false;
  3643. if ($this->biDirectional) { $checkCursive=true; } // *RTL*
  3644. else if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { $checkCursive=true; } // *INDIC*
  3645. while($i<$nb) {
  3646. //Get next character
  3647. $c = mb_substr($s,$i,1,$this->mb_enc );
  3648. if($c == "\n") {
  3649. //Explicit line break
  3650. // WORD SPACING
  3651. $this->ResetSpacing();
  3652. $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc));
  3653. // DIRECTIONALITY
  3654. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3655. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3656. $i++;
  3657. $sep=-1;
  3658. $j=$i;
  3659. $l=0;
  3660. $ns=0;
  3661. $nl++;
  3662. if($border and $nl==2) $b=$b2;
  3663. continue;
  3664. }
  3665. if($c == " ") {
  3666. $sep=$i;
  3667. $ls=$l;
  3668. $ns++;
  3669. }
  3670. $l += $this->GetCharWidthNonCore($c); // mPDF 5.3.04
  3671. if($l>$wmax) {
  3672. //Automatic line break
  3673. if($sep==-1) { // Only one word
  3674. if($i==$j) $i++;
  3675. // WORD SPACING
  3676. $this->ResetSpacing();
  3677. $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc));
  3678. // DIRECTIONALITY
  3679. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3680. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3681. }
  3682. else {
  3683. $tmp = rtrim(mb_substr($s,$j,$sep-$j,$this->mb_enc));
  3684. if($align=='J') {
  3685. //////////////////////////////////////////
  3686. // JUSTIFY J using Unicode fonts (Word spacing doesn't work)
  3687. // WORD SPACING UNICODE
  3688. // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly
  3689. $tmp = str_replace(chr(194).chr(160),chr(32),$tmp );
  3690. $len_ligne = $this->GetStringWidth($tmp );
  3691. $nb_carac = mb_strlen( $tmp , $this->mb_enc ) ;
  3692. $nb_spaces = mb_substr_count( $tmp ,' ', $this->mb_enc ) ;
  3693. $inclCursive=false;
  3694. if ($checkCursive) {
  3695. if (preg_match("/([".$this->pregRTLchars."])/u", $tmp)) { $inclCursive = true; } // *RTL*
  3696. if (preg_match("/([".$this->pregHIchars.$this->pregBNchars.$this->pregPAchars."])/u", $tmp)) { $inclCursive = true; } // *INDIC*
  3697. }
  3698. list($charspacing,$ws) = $this->GetJspacing($nb_carac,$nb_spaces,((($wmax) - $len_ligne) * _MPDFK),$inclCursive);
  3699. $this->SetSpacing($charspacing,$ws);
  3700. //////////////////////////////////////////
  3701. }
  3702. // DIRECTIONALITY
  3703. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3704. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3705. $i=$sep+1;
  3706. }
  3707. $sep=-1;
  3708. $j=$i;
  3709. $l=0;
  3710. $ns=0;
  3711. $nl++;
  3712. if($border and $nl==2) $b=$b2;
  3713. }
  3714. else $i++;
  3715. }
  3716. //Last chunk
  3717. // WORD SPACING
  3718. $this->ResetSpacing();
  3719. }
  3720. else {
  3721. while($i<$nb) {
  3722. //Get next character
  3723. $c=$s[$i];
  3724. if($c == "\n") {
  3725. //Explicit line break
  3726. // WORD SPACING
  3727. $this->ResetSpacing();
  3728. $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link);
  3729. $i++;
  3730. $sep=-1;
  3731. $j=$i;
  3732. $l=0;
  3733. $ns=0;
  3734. $nl++;
  3735. if($border and $nl==2) $b=$b2;
  3736. continue;
  3737. }
  3738. if($c == " ") {
  3739. $sep=$i;
  3740. $ls=$l;
  3741. $ns++;
  3742. }
  3743. $l += $this->GetCharWidthCore($c); // mPDF 5.3.04
  3744. if($l>$wmax) {
  3745. //Automatic line break
  3746. if($sep==-1) {
  3747. if($i==$j) $i++;
  3748. // WORD SPACING
  3749. $this->ResetSpacing();
  3750. $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link);
  3751. }
  3752. else {
  3753. if($align=='J') {
  3754. $tmp = rtrim(substr($s,$j,$sep-$j));
  3755. //////////////////////////////////////////
  3756. // JUSTIFY J using Unicode fonts (Word spacing doesn't work)
  3757. // WORD SPACING NON_UNICDOE/CJK
  3758. // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly
  3759. $tmp = str_replace(chr(160),chr(32),$tmp);
  3760. $len_ligne = $this->GetStringWidth($tmp );
  3761. $nb_carac = strlen( $tmp ) ;
  3762. $nb_spaces = substr_count( $tmp ,' ' ) ;
  3763. list($charspacing,$ws) = $this->GetJspacing($nb_carac,$nb_spaces,((($wmax) - $len_ligne) * _MPDFK),false);
  3764. $this->SetSpacing($charspacing,$ws);
  3765. //////////////////////////////////////////
  3766. }
  3767. $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill,$link);
  3768. $i=$sep+1;
  3769. }
  3770. $sep=-1;
  3771. $j=$i;
  3772. $l=0;
  3773. $ns=0;
  3774. $nl++;
  3775. if($border and $nl==2) $b=$b2;
  3776. }
  3777. else $i++;
  3778. }
  3779. //Last chunk
  3780. // WORD SPACING
  3781. $this->ResetSpacing();
  3782. }
  3783. //Last chunk
  3784. if($border and is_int(strpos($border,'B'))) $b.='B';
  3785. if (!$this->usingCoreFont) {
  3786. $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc));
  3787. // DIRECTIONALITY
  3788. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3789. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3790. }
  3791. else { $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link); }
  3792. $this->x=$this->lMargin;
  3793. }
  3794. /*-- DIRECTW --*/
  3795. function Write($h,$txt,$currentx=0,$link='',$directionality='ltr',$align='') {
  3796. if (!class_exists('directw', false)) { include(_MPDF_PATH.'classes/directw.php'); }
  3797. if (empty($this->directw)) { $this->directw = new directw($this); }
  3798. $this->directw->Write($h,$txt,$currentx,$link,$directionality,$align);
  3799. }
  3800. /*-- END DIRECTW --*/
  3801. /*-- HTML-CSS --*/
  3802. function saveInlineProperties() {
  3803. $saved = array();
  3804. $saved[ 'family' ] = $this->FontFamily;
  3805. $saved[ 'style' ] = $this->FontStyle;
  3806. $saved[ 'sizePt' ] = $this->FontSizePt;
  3807. $saved[ 'size' ] = $this->FontSize;
  3808. $saved[ 'HREF' ] = $this->HREF;
  3809. $saved[ 'underline' ] = $this->U;
  3810. $saved[ 'smCaps' ] = $this->S;
  3811. $saved[ 'strike' ] = $this->strike;
  3812. $saved[ 'textshadow' ] = $this->textshadow; // mPDF 5.3.A2
  3813. $saved[ 'SUP' ] = $this->SUP;
  3814. $saved[ 'SUB' ] = $this->SUB;
  3815. $saved[ 'linewidth' ] = $this->LineWidth;
  3816. $saved[ 'drawcolor' ] = $this->DrawColor;
  3817. $saved[ 'is_outline' ] = $this->outline_on;
  3818. $saved[ 'outlineparam' ] = $this->outlineparam;
  3819. $saved[ 'toupper' ] = $this->toupper;
  3820. $saved[ 'tolower' ] = $this->tolower;
  3821. $saved[ 'capitalize' ] = $this->capitalize;
  3822. $saved[ 'fontkerning' ] = $this->kerning;
  3823. $saved[ 'lSpacingCSS' ] = $this->lSpacingCSS;
  3824. $saved[ 'wSpacingCSS' ] = $this->wSpacingCSS;
  3825. $saved[ 'I' ] = $this->I;
  3826. $saved[ 'B' ] = $this->B;
  3827. $saved[ 'colorarray' ] = $this->colorarray;
  3828. $saved[ 'bgcolorarray' ] = $this->spanbgcolorarray;
  3829. $saved[ 'border' ] = $this->spanborddet; // mPDF 5.3.61
  3830. $saved[ 'color' ] = $this->TextColor;
  3831. $saved[ 'bgcolor' ] = $this->FillColor;
  3832. $saved['lang'] = $this->currentLang;
  3833. $saved['display_off'] = $this->inlineDisplayOff;
  3834. return $saved;
  3835. }
  3836. function restoreInlineProperties( &$saved) {
  3837. $FontFamily = $saved[ 'family' ];
  3838. $this->FontStyle = $saved[ 'style' ];
  3839. $this->FontSizePt = $saved[ 'sizePt' ];
  3840. $this->FontSize = $saved[ 'size' ];
  3841. $this->currentLang = $saved['lang'];
  3842. if ($this->useLang && !$this->usingCoreFont) {
  3843. if ($this->currentLang != $this->default_lang && ((strlen($this->currentLang) == 5 && $this->currentLang != 'UTF-8') || strlen($this->currentLang ) == 2)) {
  3844. list ($coreSuitable,$mpdf_pdf_unifonts) = GetLangOpts($this->currentLang, $this->useAdobeCJK);
  3845. if ($mpdf_pdf_unifonts) { $this->RestrictUnicodeFonts($mpdf_pdf_unifonts); }
  3846. else { $this->RestrictUnicodeFonts($this->default_available_fonts ); }
  3847. }
  3848. else {
  3849. $this->RestrictUnicodeFonts($this->default_available_fonts );
  3850. }
  3851. }
  3852. $this->ColorFlag = ($this->FillColor != $this->TextColor); //Restore ColorFlag as well
  3853. $this->HREF = $saved[ 'HREF' ];
  3854. $this->U = $saved[ 'underline' ];
  3855. $this->S = $saved[ 'smCaps' ];
  3856. $this->strike = $saved[ 'strike' ];
  3857. $this->textshadow = $saved[ 'textshadow' ]; // mPDF 5.3.A2
  3858. $this->SUP = $saved[ 'SUP' ];
  3859. $this->SUB = $saved[ 'SUB' ];
  3860. $this->LineWidth = $saved[ 'linewidth' ];
  3861. $this->DrawColor = $saved[ 'drawcolor' ];
  3862. $this->outline_on = $saved[ 'is_outline' ];
  3863. $this->outlineparam = $saved[ 'outlineparam' ];
  3864. $this->inlineDisplayOff = $saved['display_off'];
  3865. $this->toupper = $saved[ 'toupper' ];
  3866. $this->tolower = $saved[ 'tolower' ];
  3867. $this->capitalize = $saved[ 'capitalize' ];
  3868. $this->kerning = $saved[ 'fontkerning' ];
  3869. $this->lSpacingCSS = $saved[ 'lSpacingCSS' ];
  3870. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') {
  3871. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  3872. }
  3873. else { $this->fixedlSpacing = false; }
  3874. $this->wSpacingCSS = $saved[ 'wSpacingCSS' ];
  3875. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  3876. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  3877. }
  3878. else { $this->minwSpacing = 0; }
  3879. $this->SetFont($FontFamily, $saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : ''),$saved[ 'sizePt' ],false);
  3880. $this->currentfontstyle = $saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : '');
  3881. $this->currentfontsize = $saved[ 'sizePt' ];
  3882. $this->SetStylesArray(array('S'=>$this->S, 'U'=>$this->U, 'B'=>$saved[ 'B' ], 'I'=>$saved[ 'I' ]));
  3883. $this->TextColor = $saved[ 'color' ];
  3884. $this->FillColor = $saved[ 'bgcolor' ];
  3885. $this->colorarray = $saved[ 'colorarray' ];
  3886. $cor = $saved[ 'colorarray' ];
  3887. if ($cor) $this->SetTColor($cor);
  3888. $this->spanbgcolorarray = $saved[ 'bgcolorarray' ];
  3889. $cor = $saved[ 'bgcolorarray' ];
  3890. if ($cor) $this->SetFColor($cor);
  3891. $this->spanborddet = $saved[ 'border' ]; // mPDF 5.3.61
  3892. }
  3893. // Used when ColActive for tables - updated to return first block with background fill OR borders
  3894. function GetFirstBlockFill() {
  3895. // Returns the first blocklevel that uses a bgcolor fill
  3896. $startfill = 0;
  3897. for ($i=1;$i<=$this->blklvl;$i++) {
  3898. if ($this->blk[$i]['bgcolor'] || $this->blk[$i]['border_left']['w'] || $this->blk[$i]['border_right']['w'] || $this->blk[$i]['border_top']['w'] || $this->blk[$i]['border_bottom']['w'] ) {
  3899. $startfill = $i;
  3900. break;
  3901. }
  3902. }
  3903. return $startfill;
  3904. }
  3905. function SetBlockFill($blvl) {
  3906. if ($this->blk[$blvl]['bgcolor']) {
  3907. $this->SetFColor($this->blk[$blvl]['bgcolorarray']);
  3908. return 1;
  3909. }
  3910. else {
  3911. $this->SetFColor($this->ConvertColor(255));
  3912. return 0;
  3913. }
  3914. }
  3915. //-------------------------FLOWING BLOCK------------------------------------//
  3916. //The following functions were originally written by Damon Kohler //
  3917. //--------------------------------------------------------------------------//
  3918. function saveFont() {
  3919. $saved = array();
  3920. $saved[ 'family' ] = $this->FontFamily;
  3921. $saved[ 'style' ] = $this->FontStyle;
  3922. $saved[ 'sizePt' ] = $this->FontSizePt;
  3923. $saved[ 'size' ] = $this->FontSize;
  3924. $saved[ 'curr' ] = &$this->CurrentFont;
  3925. $saved[ 'color' ] = $this->TextColor;
  3926. $saved[ 'spanbgcolor' ] = $this->spanbgcolor;
  3927. $saved[ 'spanbgcolorarray' ] = $this->spanbgcolorarray;
  3928. $saved[ 'bord' ] = $this->spanborder; // mPDF 5.3.61
  3929. $saved[ 'border' ] = $this->spanborddet; // mPDF 5.3.61
  3930. $saved[ 'HREF' ] = $this->HREF;
  3931. $saved[ 'underline' ] = $this->U;
  3932. $saved[ 'smCaps' ] = $this->S;
  3933. $saved[ 'strike' ] = $this->strike;
  3934. $saved[ 'textshadow' ] = $this->textshadow; // mPDF 5.3.A2
  3935. $saved[ 'SUP' ] = $this->SUP;
  3936. $saved[ 'SUB' ] = $this->SUB;
  3937. $saved[ 'linewidth' ] = $this->LineWidth;
  3938. $saved[ 'drawcolor' ] = $this->DrawColor;
  3939. $saved[ 'is_outline' ] = $this->outline_on;
  3940. $saved[ 'outlineparam' ] = $this->outlineparam;
  3941. $saved[ 'ReqFontStyle' ] = $this->ReqFontStyle;
  3942. $saved[ 'fontkerning' ] = $this->kerning;
  3943. $saved[ 'fixedlSpacing' ] = $this->fixedlSpacing;
  3944. $saved[ 'minwSpacing' ] = $this->minwSpacing;
  3945. return $saved;
  3946. }
  3947. function restoreFont( &$saved, $write=true) {
  3948. if (!isset($saved) || empty($saved)) return;
  3949. $this->FontFamily = $saved[ 'family' ];
  3950. $this->FontStyle = $saved[ 'style' ];
  3951. $this->FontSizePt = $saved[ 'sizePt' ];
  3952. $this->FontSize = $saved[ 'size' ];
  3953. $this->CurrentFont = &$saved[ 'curr' ];
  3954. $this->TextColor = $saved[ 'color' ];
  3955. $this->spanbgcolor = $saved[ 'spanbgcolor' ];
  3956. $this->spanbgcolorarray = $saved[ 'spanbgcolorarray' ];
  3957. $this->spanborder = $saved[ 'bord' ]; // mPDF 5.3.61
  3958. $this->spanborddet = $saved[ 'border' ]; // mPDF 5.3.61
  3959. $this->ColorFlag = ($this->FillColor != $this->TextColor); //Restore ColorFlag as well
  3960. $this->HREF = $saved[ 'HREF' ];
  3961. $this->U = $saved[ 'underline' ];
  3962. $this->S = $saved[ 'smCaps' ];
  3963. $this->kerning = $saved[ 'fontkerning' ];
  3964. $this->fixedlSpacing = $saved[ 'fixedlSpacing' ];
  3965. $this->minwSpacing = $saved[ 'minwSpacing' ];
  3966. $this->strike = $saved[ 'strike' ];
  3967. $this->textshadow = $saved[ 'textshadow' ]; // mPDF 5.3.A2
  3968. $this->SUP = $saved[ 'SUP' ];
  3969. $this->SUB = $saved[ 'SUB' ];
  3970. $this->LineWidth = $saved[ 'linewidth' ];
  3971. $this->DrawColor = $saved[ 'drawcolor' ];
  3972. $this->outline_on = $saved[ 'is_outline' ];
  3973. $this->outlineparam = $saved[ 'outlineparam' ];
  3974. if ($write) {
  3975. $this->SetFont($saved[ 'family' ],$saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : ''),$saved[ 'sizePt' ],true,true); // force output
  3976. $fontout = (sprintf('BT /F%d %.3F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  3977. if($this->page>0 && ((isset($this->pageoutput[$this->page]['Font']) && $this->pageoutput[$this->page]['Font'] != $fontout) || !isset($this->pageoutput[$this->page]['Font']) || $this->keep_block_together)) { $this->_out($fontout); }
  3978. $this->pageoutput[$this->page]['Font'] = $fontout;
  3979. }
  3980. else
  3981. $this->SetFont($saved[ 'family' ],$saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : ''),$saved[ 'sizePt' ]);
  3982. $this->ReqFontStyle = $saved[ 'ReqFontStyle' ];
  3983. }
  3984. function newFlowingBlock( $w, $h, $a = '', $is_table = false, $is_list = false, $blockstate = 0, $newblock=true, $blockdir='ltr')
  3985. {
  3986. if (!$a) {
  3987. if ($blockdir=='rtl') { $a = 'R'; }
  3988. else { $a = 'L'; }
  3989. }
  3990. $this->flowingBlockAttr[ 'width' ] = ($w * _MPDFK);
  3991. // line height in user units
  3992. $this->flowingBlockAttr[ 'is_table' ] = $is_table;
  3993. $this->flowingBlockAttr[ 'is_list' ] = $is_list;
  3994. $this->flowingBlockAttr[ 'height' ] = $h;
  3995. $this->flowingBlockAttr[ 'lineCount' ] = 0;
  3996. $this->flowingBlockAttr[ 'align' ] = $a;
  3997. $this->flowingBlockAttr[ 'font' ] = array();
  3998. $this->flowingBlockAttr[ 'content' ] = array();
  3999. $this->flowingBlockAttr[ 'contentB' ] = array(); // mPDF 5.3.61
  4000. $this->flowingBlockAttr[ 'contentWidth' ] = 0;
  4001. $this->flowingBlockAttr[ 'blockstate' ] = $blockstate;
  4002. $this->flowingBlockAttr[ 'newblock' ] = $newblock;
  4003. $this->flowingBlockAttr[ 'valign' ] = 'M';
  4004. $this->flowingBlockAttr['blockdir'] = $blockdir;
  4005. }
  4006. function finishFlowingBlock($endofblock=false, $next='') {
  4007. $currentx = $this->x;
  4008. //prints out the last chunk
  4009. $is_table = $this->flowingBlockAttr[ 'is_table' ];
  4010. $is_list = $this->flowingBlockAttr[ 'is_list' ];
  4011. $maxWidth =& $this->flowingBlockAttr[ 'width' ];
  4012. $lineHeight =& $this->flowingBlockAttr[ 'height' ];
  4013. $align =& $this->flowingBlockAttr[ 'align' ];
  4014. $content =& $this->flowingBlockAttr[ 'content' ];
  4015. $contentB =& $this->flowingBlockAttr[ 'contentB' ]; // mPDF 5.3.61
  4016. $font =& $this->flowingBlockAttr[ 'font' ];
  4017. $contentWidth =& $this->flowingBlockAttr[ 'contentWidth' ];
  4018. $lineCount =& $this->flowingBlockAttr[ 'lineCount' ];
  4019. $valign =& $this->flowingBlockAttr[ 'valign' ];
  4020. $blockstate = $this->flowingBlockAttr[ 'blockstate' ];
  4021. $newblock = $this->flowingBlockAttr[ 'newblock' ];
  4022. $blockdir = $this->flowingBlockAttr['blockdir'];
  4023. // *********** BLOCK BACKGROUND COLOR *****************//
  4024. if ($this->blk[$this->blklvl]['bgcolor'] && !$is_table) {
  4025. $fill = 0;
  4026. }
  4027. else {
  4028. $this->SetFColor($this->ConvertColor(255));
  4029. $fill = 0;
  4030. }
  4031. // Always right trim!
  4032. // Right trim content and adjust width if need to justify (later)
  4033. // mPDF 5.3.76
  4034. if (isset($content[count($content)-1]) && preg_match('/[ ]+$/',$content[count($content)-1], $m)) {
  4035. $strip = strlen($m[0]);
  4036. $content[count($content)-1] = substr($content[count($content)-1],0,(strlen($content[count($content)-1])-$strip));
  4037. $this->restoreFont( $font[ count($content)-1 ],false );
  4038. $contentWidth -= $this->GetStringWidth($m[0]) * _MPDFK;
  4039. }
  4040. // the amount of space taken up so far in user units
  4041. $usedWidth = 0;
  4042. // COLS
  4043. $oldcolumn = $this->CurrCol;
  4044. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4045. // Print out each chunk
  4046. /*-- TABLES --*/
  4047. if ($is_table) {
  4048. $ipaddingL = 0;
  4049. $ipaddingR = 0;
  4050. $paddingL = 0;
  4051. $paddingR = 0;
  4052. }
  4053. else {
  4054. /*-- END TABLES --*/
  4055. $ipaddingL = $this->blk[$this->blklvl]['padding_left'];
  4056. $ipaddingR = $this->blk[$this->blklvl]['padding_right'];
  4057. $paddingL = ($ipaddingL * _MPDFK);
  4058. $paddingR = ($ipaddingR * _MPDFK);
  4059. $this->cMarginL = $this->blk[$this->blklvl]['border_left']['w'];
  4060. $this->cMarginR = $this->blk[$this->blklvl]['border_right']['w'];
  4061. // Added mPDF 3.0 Float DIV
  4062. $fpaddingR = 0;
  4063. $fpaddingL = 0;
  4064. /*-- CSS-FLOAT --*/
  4065. if (count($this->floatDivs)) {
  4066. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  4067. if ($r_exists) { $fpaddingR = $r_width; }
  4068. if ($l_exists) { $fpaddingL = $l_width; }
  4069. }
  4070. /*-- END CSS-FLOAT --*/
  4071. $usey = $this->y + 0.002;
  4072. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  4073. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  4074. }
  4075. /*-- CSS-IMAGE-FLOAT --*/
  4076. // If float exists at this level
  4077. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  4078. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  4079. /*-- END CSS-IMAGE-FLOAT --*/
  4080. } // *TABLES*
  4081. // Set Current lineheight (correction factor)
  4082. $lhfixed = false;
  4083. /*-- LISTS --*/
  4084. if ($is_list) {
  4085. if (preg_match('/([0-9.,]+)mm/',$this->list_lineheight[$this->listlvl][$this->listOcc],$am)) {
  4086. $lhfixed = true;
  4087. $def_fontsize = $this->InlineProperties['LISTITEM'][$this->listlvl][$this->listOcc][$this->listnum]['size'];
  4088. $this->lineheight_correction = $am[1] / $def_fontsize ;
  4089. }
  4090. else {
  4091. $this->lineheight_correction = $this->list_lineheight[$this->listlvl][$this->listOcc];
  4092. }
  4093. }
  4094. else
  4095. /*-- END LISTS --*/
  4096. /*-- TABLES --*/
  4097. if ($is_table) {
  4098. if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight,$am)) {
  4099. $lhfixed = true;
  4100. $def_fontsize = $this->FontSize; // needs to be default font-size for block ****
  4101. $this->lineheight_correction = $lineHeight / $def_fontsize ;
  4102. }
  4103. else {
  4104. $this->lineheight_correction = $this->table_lineheight;
  4105. }
  4106. }
  4107. else
  4108. /*-- END TABLES --*/
  4109. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  4110. if (preg_match('/([0-9.,]+)mm/',$this->blk[$this->blklvl]['line_height'],$am)) {
  4111. $lhfixed = true;
  4112. $def_fontsize = $this->blk[$this->blklvl]['InlineProperties']['size']; // needs to be default font-size for block ****
  4113. $this->lineheight_correction = $am[1] / $def_fontsize ;
  4114. }
  4115. else {
  4116. $this->lineheight_correction = $this->blk[$this->blklvl]['line_height'];
  4117. }
  4118. }
  4119. else {
  4120. $this->lineheight_correction = $this->normalLineheight;
  4121. }
  4122. // correct lineheight to maximum fontsize
  4123. if ($lhfixed) { $maxlineHeight = $this->lineheight; }
  4124. else { $maxlineHeight = 0; }
  4125. $this->forceExactLineheight = true;
  4126. $maxfontsize = 0;
  4127. // While we're at it, check if contains cursive text
  4128. $checkCursive=false;
  4129. if ($this->biDirectional) { $checkCursive=true; } // *RTL*
  4130. foreach ( $content as $k => $chunk )
  4131. {
  4132. $this->restoreFont( $font[ $k ],false );
  4133. if (!isset($this->objectbuffer[$k])) {
  4134. // Soft Hyphens chr(173)
  4135. if (!$this->usingCoreFont) {
  4136. $content[$k] = $chunk = str_replace("\xc2\xad",'',$chunk );
  4137. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { $checkCursive=true; } // *INDIC*
  4138. }
  4139. else if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  4140. $content[$k] = $chunk = str_replace(chr(173),'',$chunk );
  4141. }
  4142. // Special case of sub/sup carried over on its own to last line
  4143. if (($this->SUB || $this->SUP) && count($content)==1) { $actfs = $this->FontSize*100/55; } // 55% is font change for sub/sup
  4144. else { $actfs = $this->FontSize; }
  4145. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$actfs * $this->lineheight_correction ); }
  4146. if ($lhfixed && ($actfs > $def_fontsize || ($actfs > ($lineHeight * $this->lineheight_correction) && $is_list))) {
  4147. $this->forceExactLineheight = false;
  4148. }
  4149. $maxfontsize = max($maxfontsize,$actfs);
  4150. }
  4151. }
  4152. if(isset($font[count($font)-1])) {
  4153. $lastfontreqstyle = $font[count($font)-1]['ReqFontStyle'];
  4154. $lastfontstyle = $font[count($font)-1]['style'];
  4155. }
  4156. else {
  4157. $lastfontreqstyle=null;
  4158. $lastfontstyle=null;
  4159. }
  4160. if ($blockdir == 'ltr' && strpos($lastfontreqstyle,"I") !== false && strpos($lastfontstyle,"I") === false) { // Artificial italic
  4161. $lastitalic = $this->FontSize*0.15*_MPDFK;
  4162. }
  4163. else { $lastitalic = 0; }
  4164. /*-- LISTS --*/
  4165. if ($is_list && is_array($this->bulletarray) && count($this->bulletarray)) {
  4166. $actfs = $this->bulletarray['fontsize'];
  4167. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$actfs * $this->lineheight_correction ); }
  4168. if ($lhfixed && $actfs > $def_fontsize) { $this->forceExactLineheight = false; }
  4169. $maxfontsize = max($maxfontsize,$actfs);
  4170. }
  4171. /*-- END LISTS --*/
  4172. // when every text item checked i.e. $maxfontsize is set properly
  4173. $af = 0; // Above font
  4174. $bf = 0; // Below font
  4175. $mta = 0; // Maximum top-aligned
  4176. $mba = 0; // Maximum bottom-aligned
  4177. foreach ( $content as $k => $chunk )
  4178. {
  4179. if (isset($this->objectbuffer[$k])) {
  4180. $oh = $this->objectbuffer[$k]['OUTER-HEIGHT'];
  4181. $va = $this->objectbuffer[$k]['vertical-align']; // = $objattr['vertical-align'] = set as M,T,B,S
  4182. if ($lhfixed && $oh > $def_fontsize) { $this->forceExactLineheight = false; }
  4183. if ($va == 'BS') { // (BASELINE default)
  4184. $af = max($af, ($oh - ($maxfontsize * (0.5 + $this->baselineC))));
  4185. }
  4186. else if ($va == 'M') {
  4187. $af = max($af, ($oh - $maxfontsize)/2);
  4188. $bf = max($bf, ($oh - $maxfontsize)/2);
  4189. }
  4190. else if ($va == 'TT') {
  4191. $bf = max($bf, ($oh - $maxfontsize));
  4192. }
  4193. else if ($va == 'TB') {
  4194. $af = max($af, ($oh - $maxfontsize));
  4195. }
  4196. else if ($va == 'T') {
  4197. $mta = max($mta, $oh);
  4198. }
  4199. else if ($va == 'B') {
  4200. $mba = max($mba, $oh);
  4201. }
  4202. }
  4203. }
  4204. if ((!$lhfixed || !$this->forceExactLineheight) && ($af > (($maxlineHeight - $maxfontsize)/2) || $bf > (($maxlineHeight - $maxfontsize)/2))) {
  4205. $maxlineHeight = $maxfontsize + $af + $bf;
  4206. }
  4207. else if (!$lhfixed) { $af = $bf = ($maxlineHeight - $maxfontsize)/2; }
  4208. if ($mta > $maxlineHeight) {
  4209. $bf += ($mta - $maxlineHeight);
  4210. $maxlineHeight = $mta;
  4211. }
  4212. if ($mba > $maxlineHeight) {
  4213. $af += ($mba - $maxlineHeight);
  4214. $maxlineHeight = $mba;
  4215. }
  4216. $lineHeight = $maxlineHeight;
  4217. // If NOT images, and maxfontsize NOT > lineHeight - this value determines text baseline positioning
  4218. if ($lhfixed && $af==0 && $bf==0 && $maxfontsize<=($def_fontsize * $this->lineheight_correction * 0.8 )) {
  4219. $this->linemaxfontsize = $def_fontsize;
  4220. }
  4221. else { $this->linemaxfontsize = $maxfontsize; }
  4222. // Get PAGEBREAK TO TEST for height including the bottom border/padding
  4223. $check_h = max($this->divheight,$lineHeight);
  4224. // This fixes a proven bug...
  4225. if ($endofblock && $newblock && $blockstate==0 && !$content) { $check_h = 0; }
  4226. // but ? needs to fix potentially more widespread...
  4227. // if (!$content) { $check_h = 0; }
  4228. if ($this->blklvl > 0 && !$is_table) {
  4229. if ($endofblock && $blockstate > 1) {
  4230. if ($this->blk[$this->blklvl]['page_break_after_avoid']) { $check_h += $lineHeight; }
  4231. $check_h += ($this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w']);
  4232. }
  4233. if (($newblock && ($blockstate==1 || $blockstate==3) && $lineCount == 0) || ($endofblock && $blockstate > 1 && $lineCount == 0)) {
  4234. $check_h += ($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['border_top']['w']);
  4235. }
  4236. }
  4237. // Force PAGE break if column height cannot take check-height
  4238. if ($this->ColActive && $check_h > ($this->PageBreakTrigger - $this->y0)) {
  4239. $this->SetCol($this->NbCol-1);
  4240. }
  4241. // PAGEBREAK
  4242. //'If' below used in order to fix "first-line of other page with justify on" bug
  4243. if(!$is_table && ($this->y+$check_h) > $this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) {
  4244. $bak_x=$this->x;//Current X position
  4245. // WORD SPACING
  4246. $ws=$this->ws;//Word Spacing
  4247. $charspacing=$this->charspacing;//Character Spacing
  4248. $this->ResetSpacing();
  4249. $this->AddPage($this->CurOrientation);
  4250. $this->x=$bak_x;
  4251. // Added to correct for OddEven Margins
  4252. $currentx += $this->MarginCorrection;
  4253. $this->x += $this->MarginCorrection;
  4254. // WORD SPACING
  4255. $this->SetSpacing($charspacing,$ws);
  4256. }
  4257. if ($this->keep_block_together && !$is_table && $this->kt_p00 < $this->page && ($this->y+$check_h) > $this->kt_y00) {
  4258. $this->printdivbuffer();
  4259. $this->keep_block_together = 0;
  4260. }
  4261. /*-- COLUMNS --*/
  4262. // COLS
  4263. // COLUMN CHANGE
  4264. if ($this->CurrCol != $oldcolumn) {
  4265. $currentx += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  4266. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  4267. $oldcolumn = $this->CurrCol;
  4268. }
  4269. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; }
  4270. /*-- END COLUMNS --*/
  4271. // TOP MARGIN
  4272. if ($newblock && ($blockstate==1 || $blockstate==3) && ($this->blk[$this->blklvl]['margin_top']) && $lineCount == 0 && !$is_table && !$is_list) {
  4273. $this->DivLn($this->blk[$this->blklvl]['margin_top'],$this->blklvl-1,true,$this->blk[$this->blklvl]['margin_collapse']);
  4274. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4275. }
  4276. if ($newblock && ($blockstate==1 || $blockstate==3) && $lineCount == 0 && !$is_table && !$is_list) {
  4277. $this->blk[$this->blklvl]['y0'] = $this->y;
  4278. $this->blk[$this->blklvl]['startpage'] = $this->page;
  4279. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4280. }
  4281. // ADDED for Paragraph_indent
  4282. $WidthCorrection = 0;
  4283. if (($newblock) && ($blockstate==1 || $blockstate==3) && isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!$is_table) && (!$is_list) && ($align != 'C')) {
  4284. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  4285. $WidthCorrection = ($ti*_MPDFK);
  4286. }
  4287. // PADDING and BORDER spacing/fill
  4288. if (($newblock) && ($blockstate==1 || $blockstate==3) && (($this->blk[$this->blklvl]['padding_top']) || ($this->blk[$this->blklvl]['border_top'])) && ($lineCount == 0) && (!$is_table) && (!$is_list)) {
  4289. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  4290. $this->DivLn($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'],-3,true,false,1);
  4291. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4292. $this->x = $currentx;
  4293. }
  4294. // Added mPDF 3.0 Float DIV
  4295. $fpaddingR = 0;
  4296. $fpaddingL = 0;
  4297. /*-- CSS-FLOAT --*/
  4298. if (count($this->floatDivs)) {
  4299. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  4300. if ($r_exists) { $fpaddingR = $r_width; }
  4301. if ($l_exists) { $fpaddingL = $l_width; }
  4302. }
  4303. /*-- END CSS-FLOAT --*/
  4304. $usey = $this->y + 0.002;
  4305. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  4306. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  4307. }
  4308. /*-- CSS-IMAGE-FLOAT --*/
  4309. // If float exists at this level
  4310. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  4311. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  4312. /*-- END CSS-IMAGE-FLOAT --*/
  4313. if ($content) {
  4314. // In FinishFlowing Block no lines are justified as it is always last line
  4315. // but if orphansAllowed have allowed content width to go over max width, use J charspacing to compress line
  4316. // JUSTIFICATION J - NOT!
  4317. $nb_carac = 0;
  4318. $nb_spaces = 0;
  4319. $jcharspacing = 0;
  4320. $jws = 0;
  4321. $inclCursive=false;
  4322. foreach ( $content as $k => $chunk ) {
  4323. if (!isset($this->objectbuffer[$k]) || (isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) {
  4324. if ($this->usingCoreFont) {
  4325. $chunk = str_replace(chr(160),chr(32),$chunk );
  4326. }
  4327. else {
  4328. $chunk = str_replace(chr(194).chr(160),chr(32),$chunk );
  4329. }
  4330. $nb_carac += mb_strlen( $chunk, $this->mb_enc );
  4331. $nb_spaces += mb_substr_count( $chunk,' ', $this->mb_enc );
  4332. if ($checkCursive) {
  4333. if (preg_match("/([".$this->pregRTLchars."])/u", $chunk)) { $inclCursive = true; } // *RTL*
  4334. if (preg_match("/([".$this->pregHIchars.$this->pregBNchars.$this->pregPAchars."])/u", $chunk)) { $inclCursive = true; } // *INDIC*
  4335. }
  4336. }
  4337. }
  4338. // if it's justified, we need to find the char/word spacing (or if orphans have allowed length of line to go over the maxwidth)
  4339. // If "orphans" in fact is just a final space - ignore this
  4340. if (((($contentWidth + $lastitalic) > $maxWidth) && ($content[count($content)-1] != ' ') ) ||
  4341. (!$endofblock && $align=='J' && ($next=='image' || $next=='select' || $next=='input' || $next=='textarea' || ($next=='br' && $this->justifyB4br)))
  4342. ) {
  4343. // WORD SPACING
  4344. list($jcharspacing,$jws) = $this->GetJspacing($nb_carac,$nb_spaces,($maxWidth-$lastitalic-$contentWidth-$WidthCorrection-(($this->cMarginL+$this->cMarginR)*_MPDFK)-($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) )),$inclCursive);
  4345. }
  4346. // Check if will fit at word/char spacing of previous line - if so continue it
  4347. // but only allow a maximum of $this->jSmaxWordLast and $this->jSmaxCharLast
  4348. else if ($contentWidth < ($maxWidth - $lastitalic-$WidthCorrection - (($this->cMarginL+$this->cMarginR)* _MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK))) && !$this->fixedlSpacing) {
  4349. if ($this->ws > $this->jSmaxWordLast) {
  4350. $jws = $this->jSmaxWordLast;
  4351. }
  4352. if ($this->charspacing > $this->jSmaxCharLast) {
  4353. $jcharspacing = $this->jSmaxCharLast;
  4354. }
  4355. $check = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* _MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) ) - ( $jcharspacing * $nb_carac) - ( $jws * $nb_spaces);
  4356. if ($check <= 0) {
  4357. $jcharspacing = 0;
  4358. $jws = 0;
  4359. }
  4360. }
  4361. $empty = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* _MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) );
  4362. $empty -= ($jcharspacing * $nb_carac);
  4363. $empty -= ($jws * $nb_spaces);
  4364. $empty /= _MPDFK;
  4365. if (!$is_table) {
  4366. $this->maxPosR = max($this->maxPosR , ($this->w - $this->rMargin - $this->blk[$this->blklvl]['outer_right_margin'] - $empty));
  4367. $this->maxPosL = min($this->maxPosL , ($this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $empty));
  4368. }
  4369. $arraysize = count($content);
  4370. $margins = ($this->cMarginL+$this->cMarginR) + ($ipaddingL+$ipaddingR + $fpaddingR + $fpaddingR );
  4371. if (!$is_table) { $this->DivLn($lineHeight,$this->blklvl,false); } // false -> don't advance y
  4372. // DIRECTIONALITY RTL
  4373. $all_rtl = false;
  4374. $contains_rtl = false;
  4375. /*-- RTL --*/
  4376. if ($blockdir == 'rtl' || $this->biDirectional) {
  4377. $all_rtl = true;
  4378. foreach ( $content as $k => $chunk ) {
  4379. $reversed = $this->magic_reverse_dir($chunk, false, $blockdir);
  4380. if ($reversed > 0) { $contains_rtl = true; }
  4381. if ($reversed < 2) { $all_rtl = false; }
  4382. $content[$k] = $chunk;
  4383. }
  4384. if (($blockdir =='rtl' && $contains_rtl) || $all_rtl) {
  4385. $content = array_reverse($content,false);
  4386. $contentB = array_reverse($contentB,false); // mPDF 5.3.61
  4387. }
  4388. }
  4389. /*-- END RTL --*/
  4390. $this->x = $currentx + $this->cMarginL + $ipaddingL + $fpaddingL;
  4391. if ($align == 'R') { $this->x += $empty; }
  4392. else if ($align == 'J' && $blockdir == 'rtl') { $this->x += $empty; }
  4393. else if ($align == 'C') { $this->x += ($empty / 2); }
  4394. // Paragraph INDENT
  4395. $WidthCorrection = 0;
  4396. if (($newblock) && ($blockstate==1 || $blockstate==3) && isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!$is_table) && (!$is_list) && ($align !='C')) {
  4397. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  4398. $this->x += $ti;
  4399. }
  4400. foreach ( $content as $k => $chunk )
  4401. {
  4402. // FOR IMAGES
  4403. if ((($blockdir == 'rtl') && ($contains_rtl )) || $all_rtl ) { $dirk = $arraysize-1 - $k; } else { $dirk = $k; }
  4404. $va = 'M'; // default for text
  4405. if (isset($this->objectbuffer[$dirk]) && $this->objectbuffer[$dirk]) {
  4406. $xadj = $this->x - $this->objectbuffer[$dirk]['OUTER-X'];
  4407. $this->objectbuffer[$dirk]['OUTER-X'] += $xadj;
  4408. $this->objectbuffer[$dirk]['BORDER-X'] += $xadj;
  4409. $this->objectbuffer[$dirk]['INNER-X'] += $xadj;
  4410. $va = $this->objectbuffer[$dirk]['vertical-align'];
  4411. $yadj = $this->y - $this->objectbuffer[$dirk]['OUTER-Y'];
  4412. if ($va == 'BS') {
  4413. $yadj += $af + ($this->linemaxfontsize * (0.5 + $this->baselineC)) - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  4414. }
  4415. else if ($va == 'M' || $va == '') {
  4416. $yadj += $af + ($this->linemaxfontsize /2) - ($this->objectbuffer[$dirk]['OUTER-HEIGHT']/2);
  4417. }
  4418. else if ($va == 'TB') {
  4419. $yadj += $af + $this->linemaxfontsize - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  4420. }
  4421. else if ($va == 'TT') {
  4422. $yadj += $af;
  4423. }
  4424. else if ($va == 'B') {
  4425. $yadj += $af + $this->linemaxfontsize + $bf - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  4426. }
  4427. else if ($va == 'T') {
  4428. $yadj += 0;
  4429. }
  4430. $this->objectbuffer[$dirk]['OUTER-Y'] += $yadj;
  4431. $this->objectbuffer[$dirk]['BORDER-Y'] += $yadj;
  4432. $this->objectbuffer[$dirk]['INNER-Y'] += $yadj;
  4433. }
  4434. // DIRECTIONALITY RTL
  4435. if ((($blockdir == 'rtl') && ($contains_rtl )) || $all_rtl ) { $this->restoreFont( $font[ $arraysize-1 - $k ] ); }
  4436. else { $this->restoreFont( $font[ $k ] ); }
  4437. $this->SetSpacing(($this->fixedlSpacing*_MPDFK)+$jcharspacing,($this->fixedlSpacing+$this->minwSpacing)*_MPDFK+$jws);
  4438. $this->fixedlSpacing = false;
  4439. $this->minwSpacing = 0;
  4440. // *********** SPAN BACKGROUND COLOR ***************** //
  4441. if (isset($this->spanbgcolor) && $this->spanbgcolor) {
  4442. $cor = $this->spanbgcolorarray;
  4443. $this->SetFColor($cor);
  4444. $save_fill = $fill; $spanfill = 1; $fill = 1;
  4445. }
  4446. // mPDF 5.3.61
  4447. if (!empty($this->spanborddet)) {
  4448. if (strpos($contentB[$k],'L')!==false && isset($this->spanborddet['L'])) $this->x += $this->spanborddet['L']['w'];
  4449. if (strpos($contentB[$k],'L')===false) $this->spanborddet['L']['s'] = $this->spanborddet['L']['w'] = 0;
  4450. if (strpos($contentB[$k],'R')===false) $this->spanborddet['R']['s'] = $this->spanborddet['R']['w'] = 0;
  4451. }
  4452. // WORD SPACING
  4453. $stringWidth = $this->GetStringWidth($chunk ) + ( $this->charspacing * mb_strlen($chunk,$this->mb_enc ) / _MPDFK )
  4454. + ( $this->ws * mb_substr_count($chunk,' ',$this->mb_enc ) / _MPDFK );
  4455. if (isset($this->objectbuffer[$dirk])) {
  4456. if ($this->objectbuffer[$dirk]['type']=='dottab') {
  4457. $this->objectbuffer[$dirk]['OUTER-WIDTH'] +=$empty;
  4458. }
  4459. $stringWidth = $this->objectbuffer[$dirk]['OUTER-WIDTH'];
  4460. }
  4461. if ($stringWidth==0) { $stringWidth = 0.000001; }
  4462. if ($k == $arraysize-1) $this->Cell( $stringWidth, $lineHeight, $chunk, '', 1, '', $fill, $this->HREF , $currentx,0,0,'M', $fill, $af, $bf, true ); //mono-style line or last part (skips line) // mPDF 5.3.07
  4463. else $this->Cell( $stringWidth, $lineHeight, $chunk, '', 0, '', $fill, $this->HREF, 0, 0,0,'M', $fill, $af, $bf, true );//first or middle part // mPDF 5.3.07
  4464. // mPDF 5.3.61
  4465. if (!empty($this->spanborddet)) {
  4466. if (strpos($contentB[$k],'R')!==false && $k != $arraysize-1) $this->x += $this->spanborddet['R']['w'];
  4467. }
  4468. // *********** SPAN BACKGROUND COLOR OFF - RESET BLOCK BGCOLOR ***************** //
  4469. if (isset($spanfill) && $spanfill) {
  4470. $fill = $save_fill; $spanfill = 0;
  4471. if ($fill) { $this->SetFColor($bcor); }
  4472. }
  4473. }
  4474. $this->printobjectbuffer($is_table, $blockdir);
  4475. $this->objectbuffer = array();
  4476. $this->ResetSpacing();
  4477. /*-- LISTS --*/
  4478. // LIST BULLETS/NUMBERS
  4479. if ($is_list && is_array($this->bulletarray) && ($lineCount == 0) ) {
  4480. $savedFont = $this->saveFont();
  4481. $bull = $this->bulletarray;
  4482. if (isset($bull['level']) && isset($bull['occur']) && isset($this->InlineProperties['LIST'][$bull['level']][$bull['occur']])) {
  4483. $this->restoreInlineProperties($this->InlineProperties['LIST'][$bull['level']][$bull['occur']]);
  4484. }
  4485. if (isset($bull['level']) && isset($bull['occur']) && isset($bull['num']) && isset($this->InlineProperties['LISTITEM'][$bull['level']][$bull['occur']][$bull['num']]) && $this->InlineProperties['LISTITEM'][$bull['level']][$bull['occur']][$bull['num']]) { $this->restoreInlineProperties($this->InlineProperties['LISTITEM'][$bull['level']][$bull['occur']][$bull['num']]); }
  4486. if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') {
  4487. $this->bullet = true;
  4488. $this->SetFont('czapfdingbats','',$this->FontSizePt/2.5);
  4489. }
  4490. else { $this->SetFont($this->FontFamily,$this->FontStyle,$this->FontSizePt,true,true); } // force output
  4491. //Output bullet
  4492. $this->x = $currentx;
  4493. if (isset($bull['x'])) { $this->x += $bull['x']; }
  4494. $this->y -= $lineHeight;
  4495. if (is_array($bull['col'])) { $this->SetTColor($bull['col']); }
  4496. if (isset($bull['txt'])) { $this->Cell($bull['w'], $lineHeight,$bull['txt'],'','',$bull['align'],0,'',0,-$this->cMarginL, -$this->cMarginR ); }
  4497. if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') {
  4498. $this->bullet = false;
  4499. }
  4500. $this->x = $currentx; // Reset
  4501. $this->y += $lineHeight;
  4502. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4503. $this->restoreFont( $savedFont );
  4504. // $font = array( $savedFont );
  4505. $this->bulletarray = array(); // prevents repeat of bullet/number if <li>....<br />.....</li>
  4506. }
  4507. /*-- END LISTS --*/
  4508. } // END IF CONTENT
  4509. /*-- CSS-IMAGE-FLOAT --*/
  4510. // Update values if set to skipline
  4511. if ($this->floatmargins) { $this->_advanceFloatMargins(); }
  4512. if ($endofblock && $blockstate>1) {
  4513. // If float exists at this level
  4514. if (isset($this->floatmargins['R']['y1'])) { $fry1 = $this->floatmargins['R']['y1']; }
  4515. else { $fry1 = 0; }
  4516. if (isset($this->floatmargins['L']['y1'])) { $fly1 = $this->floatmargins['L']['y1']; }
  4517. else { $fly1 = 0; }
  4518. if ($this->y < $fry1 || $this->y < $fly1) {
  4519. $drop = max($fry1,$fly1) - $this->y;
  4520. $this->DivLn($drop);
  4521. $this->x = $currentx;
  4522. }
  4523. }
  4524. /*-- END CSS-IMAGE-FLOAT --*/
  4525. // PADDING and BORDER spacing/fill
  4526. if ($endofblock && ($blockstate > 1) && ($this->blk[$this->blklvl]['padding_bottom'] || $this->blk[$this->blklvl]['border_bottom'] || $this->blk[$this->blklvl]['css_set_height']) && (!$is_table) && (!$is_list)) {
  4527. // If CSS height set, extend bottom - if on same page as block started, and CSS HEIGHT > actual height,
  4528. // and does not force pagebreak
  4529. $extra = 0;
  4530. if ($this->blk[$this->blklvl]['css_set_height'] && $this->blk[$this->blklvl]['startpage']==$this->page) {
  4531. // predicted height
  4532. $h1 = ($this->y-$this->blk[$this->blklvl]['y0']) + $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'];
  4533. if ($h1 < ($this->blk[$this->blklvl]['css_set_height']+$this->blk[$this->blklvl]['padding_bottom']+$this->blk[$this->blklvl]['padding_top'])) { $extra = ($this->blk[$this->blklvl]['css_set_height']+$this->blk[$this->blklvl]['padding_bottom']+$this->blk[$this->blklvl]['padding_top']) - $h1; }
  4534. if($this->y + $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $extra > $this->PageBreakTrigger) {
  4535. $extra = $this->PageBreakTrigger - ($this->y + $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w']);
  4536. }
  4537. }
  4538. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  4539. $this->DivLn($this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $extra,-3,true,false,2);
  4540. $this->x = $currentx;
  4541. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4542. }
  4543. // SET Bottom y1 of block (used for painting borders)
  4544. if (($endofblock) && ($blockstate > 1) && (!$is_table) && (!$is_list)) {
  4545. $this->blk[$this->blklvl]['y1'] = $this->y;
  4546. }
  4547. // BOTTOM MARGIN
  4548. if (($endofblock) && ($blockstate > 1) && ($this->blk[$this->blklvl]['margin_bottom']) && (!$is_table) && (!$is_list)) {
  4549. if($this->y+$this->blk[$this->blklvl]['margin_bottom'] < $this->PageBreakTrigger and !$this->InFooter) {
  4550. $this->DivLn($this->blk[$this->blklvl]['margin_bottom'],$this->blklvl-1,true,$this->blk[$this->blklvl]['margin_collapse']);
  4551. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4552. }
  4553. }
  4554. // Reset lineheight
  4555. $lineHeight = $this->divheight;
  4556. }
  4557. function printobjectbuffer($is_table=false, $blockdir=false) {
  4558. if (!$blockdir) { $blockdir = $this->directionality; }
  4559. if ($is_table && $this->shrin_k > 1) { $k = $this->shrin_k; }
  4560. else { $k = 1; }
  4561. $save_y = $this->y;
  4562. $save_x = $this->x;
  4563. $save_currentfontfamily = $this->FontFamily;
  4564. $save_currentfontsize = $this->FontSizePt;
  4565. $save_currentfontstyle = $this->FontStyle.($this->U ? 'U' : '').($this->S ? 'S' : '');
  4566. if ($blockdir == 'rtl') { $rtlalign = 'R'; } else { $rtlalign = 'L'; }
  4567. foreach ($this->objectbuffer AS $ib => $objattr) {
  4568. if ($objattr['type'] == 'bookmark' || $objattr['type'] == 'indexentry' || $objattr['type'] == 'toc') {
  4569. $x = $objattr['OUTER-X'];
  4570. $y = $objattr['OUTER-Y'];
  4571. $this->y = $y - $this->FontSize/2;
  4572. $this->x = $x;
  4573. if ($objattr['type'] == 'bookmark' ) { $this->Bookmark($objattr['CONTENT'],$objattr['bklevel'] ,$y - $this->FontSize); } // *BOOKMARKS*
  4574. if ($objattr['type'] == 'indexentry') { $this->IndexEntry($objattr['CONTENT']); } // *INDEX*
  4575. if ($objattr['type'] == 'toc') { $this->TOC_Entry($objattr['CONTENT'], $objattr['toclevel'], $objattr['toc_id']); } // *TOC*
  4576. }
  4577. /*-- ANNOTATIONS --*/
  4578. else if ($objattr['type'] == 'annot') {
  4579. if ($objattr['POS-X']) { $x = $objattr['POS-X']; }
  4580. else if ($this->annotMargin<>0) { $x = -$objattr['OUTER-X']; }
  4581. else { $x = $objattr['OUTER-X']; }
  4582. if ($objattr['POS-Y']) { $y = $objattr['POS-Y']; }
  4583. else { $y = $objattr['OUTER-Y'] - $this->FontSize/2; }
  4584. // Create a dummy entry in the _out/columnBuffer with position sensitive data,
  4585. // linking $y-1 in the Columnbuffer with entry in $this->columnAnnots
  4586. // and when columns are split in length will not break annotation from current line
  4587. $this->y = $y-1;
  4588. $this->x = $x-1;
  4589. $this->Line($x-1,$y-1,$x-1,$y-1);
  4590. $this->Annotation($objattr['CONTENT'], $x , $y , $objattr['ICON'], $objattr['AUTHOR'], $objattr['SUBJECT'], $objattr['OPACITY'], $objattr['COLOR'], $objattr['POPUP'], $objattr['FILE']);
  4591. }
  4592. /*-- END ANNOTATIONS --*/
  4593. else {
  4594. $y = $objattr['OUTER-Y'];
  4595. $x = $objattr['OUTER-X'];
  4596. $w = $objattr['OUTER-WIDTH'];
  4597. $h = $objattr['OUTER-HEIGHT'];
  4598. if (isset($objattr['text'])) { $texto = $objattr['text']; }
  4599. $this->y = $y;
  4600. $this->x = $x;
  4601. if (isset($objattr['fontfamily'])) { $this->SetFont($objattr['fontfamily'],'',$objattr['fontsize'] ); }
  4602. }
  4603. // HR
  4604. if ($objattr['type'] == 'hr') {
  4605. $this->SetDColor($objattr['color']);
  4606. switch($objattr['align']) {
  4607. case 'C':
  4608. $empty = $objattr['OUTER-WIDTH'] - $objattr['INNER-WIDTH'];
  4609. $empty /= 2;
  4610. $x += $empty;
  4611. break;
  4612. case 'R':
  4613. $empty = $objattr['OUTER-WIDTH'] - $objattr['INNER-WIDTH'];
  4614. $x += $empty;
  4615. break;
  4616. }
  4617. $oldlinewidth = $this->LineWidth;
  4618. $this->SetLineWidth($objattr['linewidth']/$k );
  4619. $this->y += ($objattr['linewidth']/2) + $objattr['margin_top']/$k;
  4620. $this->Line($x,$this->y,$x+$objattr['INNER-WIDTH'],$this->y);
  4621. $this->SetLineWidth($oldlinewidth);
  4622. $this->SetDColor($this->ConvertColor(0));
  4623. }
  4624. // IMAGE
  4625. if ($objattr['type'] == 'image') {
  4626. // mPDF 5.3.42 VISIBILITY // mPDF 5.3.49
  4627. if(isset($objattr['visibility']) && $objattr['visibility']!='visible' && $objattr['visibility']) {
  4628. $this->SetVisibility($objattr['visibility']);
  4629. }
  4630. if (isset($objattr['opacity'])) { $this->SetAlpha($objattr['opacity']); }
  4631. $rotate = 0;
  4632. $obiw = $objattr['INNER-WIDTH'];
  4633. $obih = $objattr['INNER-HEIGHT'];
  4634. $sx = $objattr['INNER-WIDTH']*_MPDFK / $objattr['orig_w'];
  4635. $sy = abs($objattr['INNER-HEIGHT'])*_MPDFK / abs($objattr['orig_h']);
  4636. $sx = ($objattr['INNER-WIDTH']*_MPDFK / $objattr['orig_w']);
  4637. $sy = ($objattr['INNER-HEIGHT']*_MPDFK / $objattr['orig_h']);
  4638. if (isset($objattr['ROTATE'])) { $rotate = $objattr['ROTATE']; }
  4639. if ($rotate==90) {
  4640. // Clockwise
  4641. $obiw = $objattr['INNER-HEIGHT'];
  4642. $obih = $objattr['INNER-WIDTH'];
  4643. $tr = $this->transformTranslate(0, -$objattr['INNER-WIDTH'], true) ;
  4644. $tr .= ' '. $this->transformRotate(90, $objattr['INNER-X'],($objattr['INNER-Y'] +$objattr['INNER-WIDTH'] ),true) ;
  4645. $sx = $obiw*_MPDFK / $objattr['orig_h'];
  4646. $sy = $obih*_MPDFK / $objattr['orig_w'];
  4647. }
  4648. else if ($rotate==-90 || $rotate==270) {
  4649. // AntiClockwise
  4650. $obiw = $objattr['INNER-HEIGHT'];
  4651. $obih = $objattr['INNER-WIDTH'];
  4652. $tr = $this->transformTranslate($objattr['INNER-WIDTH'], ($objattr['INNER-HEIGHT']-$objattr['INNER-WIDTH']), true) ;
  4653. $tr .= ' '. $this->transformRotate(-90, $objattr['INNER-X'],($objattr['INNER-Y'] +$objattr['INNER-WIDTH'] ),true) ;
  4654. $sx = $obiw*_MPDFK / $objattr['orig_h'];
  4655. $sy = $obih*_MPDFK / $objattr['orig_w'];
  4656. }
  4657. else if ($rotate==180) {
  4658. // Mirror
  4659. $tr = $this->transformTranslate($objattr['INNER-WIDTH'], -$objattr['INNER-HEIGHT'], true) ;
  4660. $tr .= ' '. $this->transformRotate(180, $objattr['INNER-X'],($objattr['INNER-Y'] +$objattr['INNER-HEIGHT'] ),true) ;
  4661. }
  4662. else { $tr = ''; }
  4663. $tr = trim($tr);
  4664. if ($tr) { $tr .= ' '; }
  4665. $gradmask = '';
  4666. /*-- BACKGROUNDS --*/
  4667. if (isset($objattr['GRADIENT-MASK'])) {
  4668. $g = $this->grad->parseMozGradient( $objattr['GRADIENT-MASK'] );
  4669. if ($g) {
  4670. $dummy = $this->grad->Gradient($objattr['INNER-X'], $objattr['INNER-Y'], $obiw, $obih, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true, true);
  4671. $gradmask = '/TGS'.count($this->gradients).' gs ';
  4672. // $this->_out("q ".$tr.$this->grad->Gradient($objattr['INNER-X'], $objattr['INNER-Y'], $obiw, $obih, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true)." Q");
  4673. }
  4674. }
  4675. /*-- END BACKGROUNDS --*/
  4676. /*-- IMAGES-WMF --*/
  4677. if (isset($objattr['itype']) && $objattr['itype']=='wmf') {
  4678. $outstring = sprintf('q '.$tr.'%.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q', $sx, -$sy, $objattr['INNER-X']*_MPDFK-$sx*$objattr['wmf_x'], (($this->h-$objattr['INNER-Y'])*_MPDFK)+$sy*$objattr['wmf_y'], $objattr['ID']);
  4679. }
  4680. else
  4681. /*-- END IMAGES-WMF --*/
  4682. if (isset($objattr['itype']) && $objattr['itype']=='svg') {
  4683. $outstring = sprintf('q '.$tr.'%.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q', $sx, -$sy, $objattr['INNER-X']*_MPDFK-$sx*$objattr['wmf_x'], (($this->h-$objattr['INNER-Y'])*_MPDFK)+$sy*$objattr['wmf_y'], $objattr['ID']);
  4684. }
  4685. else {
  4686. $outstring = sprintf("q ".$tr."%.3F 0 0 %.3F %.3F %.3F cm ".$gradmask."/I%d Do Q",$obiw*_MPDFK, $obih*_MPDFK, $objattr['INNER-X'] *_MPDFK, ($this->h-($objattr['INNER-Y'] +$obih ))*_MPDFK,$objattr['ID'] );
  4687. }
  4688. $this->_out($outstring);
  4689. // LINK
  4690. if (isset($objattr['link'])) $this->Link($objattr['INNER-X'],$objattr['INNER-Y'],$objattr['INNER-WIDTH'],$objattr['INNER-HEIGHT'],$objattr['link']);
  4691. if (isset($objattr['opacity'])) { $this->SetAlpha(1); }
  4692. if ((isset($objattr['border_top']) && $objattr['border_top']>0) || (isset($objattr['border_left']) && $objattr['border_left']>0) || (isset($objattr['border_right']) && $objattr['border_right']>0) || (isset($objattr['border_bottom']) && $objattr['border_bottom']>0)) { $this->PaintImgBorder($objattr,$is_table); }
  4693. // mPDF 5.3.42 VISIBILITY // mPDF 5.3.49
  4694. if(isset($objattr['visibility']) && $objattr['visibility']!='visible' && $objattr['visibility']) {
  4695. $this->SetVisibility('visible');
  4696. }
  4697. }
  4698. /*-- BARCODES --*/
  4699. // BARCODE
  4700. if ($objattr['type'] == 'barcode') {
  4701. $bgcol = $this->ConvertColor(255);
  4702. if (isset($objattr['bgcolor']) && $objattr['bgcolor']) { // mPDF 5.3.A4
  4703. $bgcol = $objattr['bgcolor'];
  4704. }
  4705. $col = $this->ConvertColor(0);
  4706. if (isset($objattr['color']) && $objattr['color']) { // mPDF 5.3.A4
  4707. $col = $objattr['color'];
  4708. }
  4709. $this->SetFColor($bgcol);
  4710. $this->Rect($objattr['BORDER-X'], $objattr['BORDER-Y'], $objattr['BORDER-WIDTH'], $objattr['BORDER-HEIGHT'], 'F');
  4711. $this->SetFColor($this->ConvertColor(255));
  4712. if (isset($objattr['BORDER-WIDTH'])) { $this->PaintImgBorder($objattr,$is_table); }
  4713. if ($objattr['btype'] == 'EAN13' || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN' || $objattr['btype'] == 'UPCA' || $objattr['btype'] == 'UPCE' || $objattr['btype'] == 'EAN8') {
  4714. $this->WriteBarcode($objattr['code'], $objattr['showtext'], $objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize'], 0, 0, 0, 0, 0, $objattr['bheight'], $bgcol, $col, $objattr['btype'], $objattr['bsupp'], $objattr['bsupp_code'], $k);
  4715. }
  4716. // QR-code
  4717. else if ($objattr['btype']=='QR') {
  4718. if (!class_exists('QRcode', false)) {
  4719. include(_MPDF_PATH.'qrcode/qrcode.class.php');
  4720. }
  4721. $this->qrcode = new QRcode($objattr['code'], $objattr['errorlevel']);
  4722. $this->qrcode->displayFPDF($this, $objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize']*25, array(255,255,255), array(0,0,0));
  4723. }
  4724. else {
  4725. $this->WriteBarcode2($objattr['code'], $objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize'], $objattr['bheight'], $bgcol, $col, $objattr['btype'], $objattr['pr_ratio'], $k);
  4726. }
  4727. }
  4728. /*-- END BARCODES --*/
  4729. // mPDF 5.3.A5
  4730. // TEXT CIRCLE
  4731. if ($objattr['type'] == 'textcircle') {
  4732. $bgcol = $this->ConvertColor(255);
  4733. if (isset($objattr['bgcolor']) && $objattr['bgcolor']) {
  4734. $bgcol = $objattr['bgcolor'];
  4735. }
  4736. $col = $this->ConvertColor(0);
  4737. if (isset($objattr['color']) && $objattr['color']) {
  4738. $col = $objattr['color'];
  4739. }
  4740. $this->SetTColor($col);
  4741. $this->SetFColor($bgcol);
  4742. $this->Rect($objattr['BORDER-X'], $objattr['BORDER-Y'], $objattr['BORDER-WIDTH'], $objattr['BORDER-HEIGHT'], 'F');
  4743. $this->SetFColor($this->ConvertColor(255));
  4744. if (isset($objattr['BORDER-WIDTH'])) { $this->PaintImgBorder($objattr,$is_table); }
  4745. if (!class_exists('directw', false)) { include(_MPDF_PATH.'classes/directw.php'); }
  4746. if (empty($this->directw)) { $this->directw = new directw($this); }
  4747. $save_lmfs = $this->linemaxfontsize;
  4748. $this->linemaxfontsize = 0;
  4749. if (isset($objattr['top-text'])) {
  4750. $this->directw->CircularText($objattr['INNER-X']+$objattr['INNER-WIDTH']/2, $objattr['INNER-Y']+$objattr['INNER-HEIGHT']/2, $objattr['r']/$k, $objattr['top-text'], 'top', $objattr['fontfamily'], $objattr['fontsize']/$k, $objattr['fontstyle'], $objattr['space-width'], $objattr['char-width']);
  4751. }
  4752. if (isset($objattr['bottom-text'])) {
  4753. $this->directw->CircularText($objattr['INNER-X']+$objattr['INNER-WIDTH']/2, $objattr['INNER-Y']+$objattr['INNER-HEIGHT']/2, $objattr['r']/$k, $objattr['bottom-text'], 'bottom', $objattr['fontfamily'], $objattr['fontsize']/$k, $objattr['fontstyle'], $objattr['space-width'], $objattr['char-width']);
  4754. }
  4755. $this->linemaxfontsize = $save_lmfs;
  4756. }
  4757. $this->ResetSpacing();
  4758. // DOT-TAB
  4759. if ($objattr['type'] == 'dottab') {
  4760. $sp = $this->GetStringWidth(' ');
  4761. $nb=floor(($w-2*$sp)/$this->GetStringWidth('.'));
  4762. if ($nb>0) { $dots=' '.str_repeat('.',$nb).' '; }
  4763. else { $dots=' '; }
  4764. $col = $this->ConvertColor(0);
  4765. if (isset($objattr['colorarray']) && is_array($objattr['colorarray'])) {
  4766. $col = $objattr['colorarray'];
  4767. }
  4768. $this->SetTColor($col);
  4769. // mPDF 5.3.A3
  4770. $save_sbd = $this->spanborddet;
  4771. $save_u = $this->U;
  4772. $save_s = $this->strike;
  4773. $this->spanborddet = '';
  4774. $this->U = false;
  4775. $this->strike = false;
  4776. $this->Cell($w,$h,$dots,0,0,'C');
  4777. $this->spanborddet = $save_sbd;
  4778. $this->U = $save_u;
  4779. $this->strike = $save_s;
  4780. // mPDF 5.0
  4781. $this->SetTColor($this->ConvertColor(0));
  4782. }
  4783. /*-- FORMS --*/
  4784. // TEXT/PASSWORD INPUT
  4785. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'TEXT' || $objattr['subtype'] == 'PASSWORD')) {
  4786. $this->form->print_ob_text($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir);
  4787. }
  4788. // TEXTAREA
  4789. if ($objattr['type'] == 'textarea') {
  4790. $this->form->print_ob_textarea($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir);
  4791. }
  4792. // SELECT
  4793. if ($objattr['type'] == 'select') {
  4794. $this->form->print_ob_select($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir);
  4795. }
  4796. // INPUT/BUTTON as IMAGE
  4797. if ($objattr['type'] == 'input' && $objattr['subtype'] == 'IMAGE') {
  4798. $this->form->print_ob_imageinput($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir);
  4799. }
  4800. // BUTTON
  4801. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'SUBMIT' || $objattr['subtype'] == 'RESET' || $objattr['subtype'] == 'BUTTON')) {
  4802. $this->form->print_ob_button($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir);
  4803. }
  4804. // CHECKBOX
  4805. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'CHECKBOX')) {
  4806. $this->form->print_ob_checkbox($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir,$x,$y);
  4807. }
  4808. // RADIO
  4809. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'RADIO')) {
  4810. $this->form->print_ob_radio($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir,$x,$y);
  4811. }
  4812. /*-- END FORMS --*/
  4813. }
  4814. $this->SetFont($save_currentfontfamily,$save_currentfontstyle,$save_currentfontsize);
  4815. $this->y = $save_y;
  4816. $this->x = $save_x;
  4817. unset($content);
  4818. }
  4819. function WriteFlowingBlock( $s)
  4820. {
  4821. $currentx = $this->x;
  4822. $is_table = $this->flowingBlockAttr[ 'is_table' ];
  4823. $is_list = $this->flowingBlockAttr[ 'is_list' ];
  4824. // width of all the content so far in points
  4825. $contentWidth =& $this->flowingBlockAttr[ 'contentWidth' ];
  4826. // cell width in points
  4827. $maxWidth =& $this->flowingBlockAttr[ 'width' ];
  4828. $lineCount =& $this->flowingBlockAttr[ 'lineCount' ];
  4829. // line height in user units
  4830. $lineHeight =& $this->flowingBlockAttr[ 'height' ];
  4831. $align =& $this->flowingBlockAttr[ 'align' ];
  4832. $content =& $this->flowingBlockAttr[ 'content' ];
  4833. $contentB =& $this->flowingBlockAttr[ 'contentB' ]; // mPDF 5.3.61
  4834. $font =& $this->flowingBlockAttr[ 'font' ];
  4835. $valign =& $this->flowingBlockAttr[ 'valign' ];
  4836. $blockstate = $this->flowingBlockAttr[ 'blockstate' ];
  4837. $newblock = $this->flowingBlockAttr[ 'newblock' ];
  4838. $blockdir = $this->flowingBlockAttr['blockdir'];
  4839. // *********** BLOCK BACKGROUND COLOR ***************** //
  4840. if ($this->blk[$this->blklvl]['bgcolor'] && !$is_table) {
  4841. $fill = 0;
  4842. }
  4843. else {
  4844. $this->SetFColor($this->ConvertColor(255));
  4845. $fill = 0;
  4846. }
  4847. $font[] = $this->saveFont();
  4848. $content[] = '';
  4849. $contentB[] = ''; // mPDF 5.3.61
  4850. $currContent =& $content[ count( $content ) - 1 ];
  4851. // where the line should be cutoff if it is to be justified
  4852. $cutoffWidth = $contentWidth;
  4853. $curlyquote = mb_convert_encoding("\xe2\x80\x9e",$this->mb_enc,'UTF-8');
  4854. $curlylowquote = mb_convert_encoding("\xe2\x80\x9d",$this->mb_enc,'UTF-8');
  4855. $CJKoverflow = false;
  4856. // COLS
  4857. $oldcolumn = $this->CurrCol;
  4858. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4859. /*-- TABLES --*/
  4860. if ($is_table) {
  4861. $ipaddingL = 0;
  4862. $ipaddingR = 0;
  4863. $paddingL = 0;
  4864. $paddingR = 0;
  4865. $cpaddingadjustL = 0;
  4866. $cpaddingadjustR = 0;
  4867. // Added mPDF 3.0
  4868. $fpaddingR = 0;
  4869. $fpaddingL = 0;
  4870. }
  4871. else {
  4872. /*-- END TABLES --*/
  4873. $ipaddingL = $this->blk[$this->blklvl]['padding_left'];
  4874. $ipaddingR = $this->blk[$this->blklvl]['padding_right'];
  4875. $paddingL = ($ipaddingL * _MPDFK);
  4876. $paddingR = ($ipaddingR * _MPDFK);
  4877. $this->cMarginL = $this->blk[$this->blklvl]['border_left']['w'];
  4878. $cpaddingadjustL = -$this->cMarginL;
  4879. $this->cMarginR = $this->blk[$this->blklvl]['border_right']['w'];
  4880. $cpaddingadjustR = -$this->cMarginR;
  4881. // Added mPDF 3.0 Float DIV
  4882. $fpaddingR = 0;
  4883. $fpaddingL = 0;
  4884. /*-- CSS-FLOAT --*/
  4885. if (count($this->floatDivs)) {
  4886. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  4887. if ($r_exists) { $fpaddingR = $r_width; }
  4888. if ($l_exists) { $fpaddingL = $l_width; }
  4889. }
  4890. /*-- END CSS-FLOAT --*/
  4891. $usey = $this->y + 0.002;
  4892. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  4893. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  4894. }
  4895. /*-- CSS-IMAGE-FLOAT --*/
  4896. // If float exists at this level
  4897. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  4898. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  4899. /*-- END CSS-IMAGE-FLOAT --*/
  4900. } // *TABLES*
  4901. //OBJECTS - IMAGES & FORM Elements (NB has already skipped line/page if required - in printbuffer)
  4902. if (substr($s,0,3) == "\xbb\xa4\xac") { //identifier has been identified!
  4903. $objattr = $this->_getObjAttr($s);
  4904. $h_corr = 0;
  4905. if ($is_table) { // *TABLES*
  4906. $maximumW = ($maxWidth/_MPDFK) - ($this->cellPaddingL + $this->cMarginL + $this->cellPaddingR + $this->cMarginR); // *TABLES*
  4907. } // *TABLES*
  4908. else { // *TABLES*
  4909. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) && (!$is_table)) { $h_corr = $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w']; }
  4910. $maximumW = ($maxWidth/_MPDFK) - ($this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_right'] + $this->blk[$this->blklvl]['border_right']['w'] + $fpaddingL + $fpaddingR );
  4911. } // *TABLES*
  4912. $objattr = $this->inlineObject($objattr['type'],$this->lMargin + $fpaddingL + ($contentWidth/_MPDFK),($this->y + $h_corr), $objattr, $this->lMargin,($contentWidth/_MPDFK),$maximumW,$lineHeight,true,$is_table);
  4913. // SET LINEHEIGHT for this line ================ RESET AT END
  4914. $lineHeight = MAX($lineHeight,$objattr['OUTER-HEIGHT']);
  4915. $this->objectbuffer[count($content)-1] = $objattr;
  4916. // if (isset($objattr['vertical-align'])) { $valign = $objattr['vertical-align']; }
  4917. // else { $valign = ''; }
  4918. $contentWidth += ($objattr['OUTER-WIDTH'] * _MPDFK);
  4919. return;
  4920. }
  4921. // mPDF 5.3.61
  4922. $lbw = $rbw = 0; // Border widths
  4923. if (!empty($this->spanborddet)) {
  4924. if (isset($this->spanborddet['L'])) $lbw = $this->spanborddet['L']['w'];
  4925. if (isset($this->spanborddet['R'])) $rbw = $this->spanborddet['R']['w'];
  4926. }
  4927. if ($this->usingCoreFont) {
  4928. $tmp = strlen( $s );
  4929. }
  4930. else {
  4931. $tmp = mb_strlen( $s, $this->mb_enc );
  4932. }
  4933. $orphs = 0;
  4934. $check = 0;
  4935. // for every character in the string
  4936. for ( $i = 0; $i < $tmp; $i++ ) {
  4937. // extract the current character
  4938. // get the width of the character in points
  4939. if ($this->usingCoreFont) {
  4940. $c = $s[$i];
  4941. // Soft Hyphens chr(173)
  4942. // mPDF 5.3.07
  4943. $cw = ($this->GetCharWidthCore($c) * _MPDFK); // mPDF 5.3.04
  4944. if ($this->kerning && $this->useKerning && $i > 0) {
  4945. if (isset($this->CurrentFont['kerninfo'][$s[($i-1)]][$c])) {
  4946. $cw += ($this->CurrentFont['kerninfo'][$s[($i-1)]][$c] * $this->FontSizePt / 1000 );
  4947. }
  4948. }
  4949. }
  4950. else {
  4951. $c = mb_substr($s,$i,1,$this->mb_enc );
  4952. $cw = ($this->GetCharWidthNonCore($c, false) * _MPDFK); // mPDF 5.3.04
  4953. if ($this->kerning && $this->useKerning && $i > 0) {
  4954. $lastc = mb_substr($s,($i-1),1,$this->mb_enc );
  4955. $ulastc = $this->UTF8StringToArray($lastc, false);
  4956. $uc = $this->UTF8StringToArray($c, false);
  4957. if (isset($this->CurrentFont['kerninfo'][$ulastc[0]][$uc[0]])) {
  4958. $cw += ($this->CurrentFont['kerninfo'][$ulastc[0]][$uc[0]] * $this->FontSizePt / 1000 );
  4959. }
  4960. }
  4961. }
  4962. // mPDF 5.3.61
  4963. if ($i==0) {
  4964. $cw += $lbw*_MPDFK;
  4965. $contentB[(count($contentB)-1)] .= 'L';
  4966. }
  4967. if ($i==($tmp-1)) {
  4968. $cw += $rbw*_MPDFK;
  4969. $contentB[(count($contentB)-1)] .= 'R';
  4970. }
  4971. if ($c==' ') { $check = 1; }
  4972. // CHECK for ORPHANS
  4973. else if ($c=='.' || $c==',' || $c==')' || $c==']' || $c==';' || $c==':' || $c=='!' || $c=='?'|| $c=='"' || $c==$curlyquote || $c==$curlylowquote) {$check++; }
  4974. /*-- CJK-FONTS --*/
  4975. else if ($this->checkCJK) { // mPDF 5.3.07
  4976. if ((!$is_table && $this->CJKfollowing && preg_match("/[".$this->CJKfollowing."]/u", $c)) || ($is_table && preg_match("/[".$this->CJKoverflow ."]/u", $c))) { $check++; }
  4977. else { $check = 0; }
  4978. }
  4979. /*-- END CJK-FONTS --*/
  4980. else { $check = 0; }
  4981. // There's an orphan '. ' or ', ' or <sup>32</sup> about to be cut off at the end of line
  4982. if($check==1) {
  4983. $currContent .= $c;
  4984. $cutoffWidth = $contentWidth;
  4985. $contentWidth += $cw;
  4986. continue;
  4987. }
  4988. if(($this->SUP || $this->SUB) && ($orphs < $this->orphansAllowed)) { // ? disable orphans in table if borders used
  4989. $currContent .= $c;
  4990. $cutoffWidth = $contentWidth;
  4991. $contentWidth += $cw;
  4992. $orphs++;
  4993. continue;
  4994. }
  4995. else { $orphs = 0; }
  4996. // ADDED for Paragraph_indent
  4997. $WidthCorrection = 0;
  4998. if (($newblock) && ($blockstate==1 || $blockstate==3) && isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!$is_table) && (!$is_list) && ($align != 'C')) {
  4999. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  5000. $WidthCorrection = ($ti*_MPDFK);
  5001. }
  5002. // Added mPDF 3.0 Float DIV
  5003. $fpaddingR = 0;
  5004. $fpaddingL = 0;
  5005. /*-- CSS-FLOAT --*/
  5006. if (count($this->floatDivs)) {
  5007. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  5008. if ($r_exists) { $fpaddingR = $r_width; }
  5009. if ($l_exists) { $fpaddingL = $l_width; }
  5010. }
  5011. /*-- END CSS-FLOAT --*/
  5012. $usey = $this->y + 0.002;
  5013. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  5014. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  5015. }
  5016. /*-- CSS-IMAGE-FLOAT --*/
  5017. // If float exists at this level
  5018. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  5019. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  5020. /*-- END CSS-IMAGE-FLOAT --*/
  5021. // try adding another char
  5022. if (( $contentWidth + $cw > $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*_MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) ) + 0.001)) {// 0.001 is to correct for deviations converting mm=>pts
  5023. // it won't fit, output what we already have
  5024. $lineCount++;
  5025. // contains any content that didn't make it into this print
  5026. $savedContent = '';
  5027. $savedContentB = ''; // mPDF 5.3.61
  5028. $savedFont = array();
  5029. $savedObj = array();
  5030. // cut off and save any partial words at the end of the string
  5031. $words = explode( ' ', $currContent );
  5032. ///////////////////
  5033. // HYPHENATION
  5034. $currWord = $words[count($words)-1] ;
  5035. $success = false;
  5036. /*-- HYPHENATION --*/
  5037. // Soft Hyphens chr(173)
  5038. if ((!$this->usingCoreFont && preg_match("/\xc2\xad/",$currWord)) || ($this->usingCoreFont && preg_match("/".chr(173)."/",$currWord) && ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats')) ) {
  5039. $rem = $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*_MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) );
  5040. list($success,$pre,$post,$prelength) = $this->softHyphenate($currWord, (($rem-$cutoffWidth)/_MPDFK -$this->GetCharWidthNonCore(" ", false)) ); // mPDF 5.3.04
  5041. }
  5042. if (!$success && ($this->hyphenate || ($this->hyphenateTables && $is_table))) {
  5043. // Look ahead to get current word
  5044. for($ac = $i; $ac<(mb_strlen($s)-1); $ac++) {
  5045. $addc = mb_substr($s,$ac,1,$this->mb_enc );
  5046. if ($addc == ' ') { break; }
  5047. $currWord .= $addc;
  5048. }
  5049. $rem = $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*_MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) );
  5050. list($success,$pre,$post,$prelength) = $this->hyphenateWord($currWord, (($rem-$cutoffWidth)/_MPDFK -$this->GetCharWidth(" ", false)) );
  5051. }
  5052. if ($success) {
  5053. $already = array_pop( $words );
  5054. $forward = mb_substr($already,$prelength,mb_strlen($already, $this->mb_enc), $this->mb_enc);
  5055. $words[] = $pre.'-';
  5056. $words[] = $forward;
  5057. $currContent = mb_substr($currContent,0,mb_strlen($currContent, $this->mb_enc)+1-mb_strlen($post, $this->mb_enc), $this->mb_enc) . '-';
  5058. }
  5059. /*-- END HYPHENATION --*/
  5060. // if it looks like we didn't finish any words for this chunk
  5061. if ( count( $words ) == 1 ) {
  5062. // TO correct for error when word too wide for page - but only when one long word from left to right margin
  5063. if (count($content) == 1 && $currContent != ' ') {
  5064. /////////////////////////////////////////////////////////////////////////////////////
  5065. $lastchar = mb_substr($words[0],mb_strlen($words[0], $this->mb_enc)-1, 1, $this->mb_enc);
  5066. /*-- CJK-FONTS --*/
  5067. // mPDF 5.3.07
  5068. if ($this->checkCJK) {
  5069. // Last character that fits is not allowed to end a line - move lastchar(s) to start of next line
  5070. if (!$is_table && preg_match("/[".$this->CJKleading."]/u", $lastchar)) {
  5071. //move lastchar(s) to next line
  5072. $m0 = $lastchar;
  5073. $m1 = $c;
  5074. while(preg_match("/[".$this->CJKleading."]/u", $m0) && mb_strlen($words[0], $this->mb_enc)>2) {
  5075. // trim last letter off word[0]
  5076. $words[0] = mb_substr($words[0],0,mb_strlen($words[0], $this->mb_enc)-1, $this->mb_enc);
  5077. // and add it to savedContent for next line
  5078. $savedContent = $m0.$savedContent;
  5079. $m1 = $lastchar;
  5080. $lastchar = mb_substr($words[0],mb_strlen($words[0], $this->mb_enc)-1, 1, $this->mb_enc);
  5081. $m0 = $lastchar;
  5082. }
  5083. }
  5084. // Next character is not allowed to start a new line - move lastchar(s) to next line
  5085. else if (!$is_table && preg_match("/[".$this->CJKfollowing."]/u", $c)) {
  5086. // try squeezing another character(s) onto this line = Oikomi
  5087. if ($this->allowCJKorphans) {
  5088. $lookahead = mb_substr($s,$i+1,1,$this->mb_enc );
  5089. //if lookahead is not another following char
  5090. if ($lookahead && !preg_match("/[".$this->CJKfollowing."]/u", $lookahead)) {
  5091. $currContent .= $c;
  5092. $cutoffWidth = $contentWidth;
  5093. $contentWidth += $cw;
  5094. if ($this->allowCJKoverflow && !$is_table && preg_match("/[".$this->CJKoverflow."]/u", $c)) { $CJKoverflow = true; }
  5095. continue;
  5096. }
  5097. }
  5098. // or move lastchar(s) to next line to keep $c company = Oidashi
  5099. $m0 = $lastchar;
  5100. $m1 = $c;
  5101. while(preg_match("/[".$this->CJKfollowing."]/u", $m1) && mb_strlen($words[0], $this->mb_enc)>2) {
  5102. // trim last letter off word[0]
  5103. $words[0] = mb_substr($words[0],0,mb_strlen($words[0], $this->mb_enc)-1, $this->mb_enc);
  5104. // and add it to savedContent for next line
  5105. $savedContent = $m0.$savedContent;
  5106. $m1 = $lastchar;
  5107. $lastchar = mb_substr($words[0],mb_strlen($words[0], $this->mb_enc)-1, 1, $this->mb_enc);
  5108. $m0 = $lastchar;
  5109. }
  5110. }
  5111. }
  5112. /*-- END CJK-FONTS --*/
  5113. $lastContent = $words[0];
  5114. $savedFont = $this->saveFont();
  5115. // replace the current content with the cropped version
  5116. $currContent = rtrim( $lastContent );
  5117. }
  5118. else {
  5119. // save and crop off the content currently on the stack
  5120. $savedContent = array_pop( $content );
  5121. $savedContentB = $contentB[(count($contentB)-1)]; // mPDF 5.3.61
  5122. $savedFont = array_pop( $font );
  5123. // trim any trailing spaces off the last bit of content
  5124. $currContent =& $content[ count( $content ) - 1 ];
  5125. $currContent = rtrim( $currContent );
  5126. }
  5127. }
  5128. else { // otherwise, we need to find which bit to cut off
  5129. $lastContent = '';
  5130. for ( $w = 0; $w < count( $words ) - 1; $w++) { $lastContent .= $words[ $w ]." "; }
  5131. $savedContent = $words[ count( $words ) - 1 ];
  5132. $savedFont = $this->saveFont();
  5133. // replace the current content with the cropped version
  5134. $currContent = rtrim( $lastContent );
  5135. }
  5136. // CJK - strip CJK space at end of line
  5137. // &#x3000; = \xe3\x80\x80 = CJK space
  5138. if ($this->checkCJK) { $currContent = preg_replace("/\xe3\x80\x80$/",'',$currContent) ; } // *CJK-FONTS*
  5139. if (isset($this->objectbuffer[(count($content)-1)]) && $this->objectbuffer[(count($content)-1)]['type']=='dottab') {
  5140. $savedObj = array_pop( $this->objectbuffer );
  5141. $contentWidth -= ($this->objectbuffer[(count($content)-1)]['OUTER-WIDTH'] * _MPDFK);
  5142. }
  5143. // Set Current lineheight (correction factor)
  5144. $lhfixed = false;
  5145. /*-- LISTS --*/
  5146. if ($is_list) {
  5147. if (preg_match('/([0-9.,]+)mm/',$this->list_lineheight[$this->listlvl][$this->listOcc],$am)) {
  5148. $lhfixed = true;
  5149. $def_fontsize = $this->InlineProperties['LISTITEM'][$this->listlvl][$this->listOcc][$this->listnum]['size'];
  5150. $this->lineheight_correction = $am[1] / $def_fontsize ;
  5151. }
  5152. else {
  5153. $this->lineheight_correction = $this->list_lineheight[$this->listlvl][$this->listOcc];
  5154. }
  5155. }
  5156. else
  5157. /*-- END LISTS --*/
  5158. /*-- TABLES --*/
  5159. if ($is_table) {
  5160. if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight,$am)) {
  5161. $lhfixed = true;
  5162. $def_fontsize = $this->FontSize; // needs to be default font-size for block ****
  5163. $this->lineheight_correction = $lineHeight / $def_fontsize ;
  5164. }
  5165. else {
  5166. $this->lineheight_correction = $this->table_lineheight;
  5167. }
  5168. }
  5169. else
  5170. /*-- END TABLES --*/
  5171. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  5172. if (preg_match('/([0-9.,]+)mm/',$this->blk[$this->blklvl]['line_height'],$am)) {
  5173. $lhfixed = true;
  5174. $def_fontsize = $this->blk[$this->blklvl]['InlineProperties']['size']; // needs to be default font-size for block ****
  5175. $this->lineheight_correction = $am[1] / $def_fontsize ;
  5176. }
  5177. else {
  5178. $this->lineheight_correction = $this->blk[$this->blklvl]['line_height'];
  5179. }
  5180. }
  5181. else {
  5182. $this->lineheight_correction = $this->normalLineheight;
  5183. }
  5184. // update $contentWidth and $cutoffWidth since they changed with cropping
  5185. // Also correct lineheight to maximum fontsize (not for tables)
  5186. $contentWidth = 0;
  5187. // correct lineheight to maximum fontsize
  5188. if ($lhfixed) { $maxlineHeight = $this->lineheight; }
  5189. else { $maxlineHeight = 0; }
  5190. $this->forceExactLineheight = true;
  5191. $maxfontsize = 0;
  5192. // While we're at it, check for cursive text
  5193. $checkCursive=false;
  5194. if ($this->biDirectional) { $checkCursive=true; } // *RTL*
  5195. foreach ( $content as $k => $chunk )
  5196. {
  5197. $this->restoreFont( $font[ $k ]);
  5198. if (!isset($this->objectbuffer[$k])) {
  5199. if (!$this->usingCoreFont) {
  5200. $content[$k] = $chunk = str_replace("\xc2\xad",'',$chunk );
  5201. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { $checkCursive=true; } // *INDIC*
  5202. }
  5203. // Soft Hyphens chr(173)
  5204. else if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  5205. $content[$k] = $chunk = str_replace(chr(173),'',$chunk );
  5206. }
  5207. $contentWidth += $this->GetStringWidth( $chunk ) * _MPDFK;
  5208. // mPDF 5.3.61
  5209. if (!empty($this->spanborddet)) {
  5210. if (strpos($contentB[$k],'L')!==false) $contentWidth += $this->spanborddet['L']['w'] * _MPDFK;
  5211. if (strpos($contentB[$k],'R')!==false) $contentWidth += $this->spanborddet['R']['w'] * _MPDFK;
  5212. }
  5213. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$this->FontSize * $this->lineheight_correction ); }
  5214. if ($lhfixed && ($this->FontSize > $def_fontsize || ($this->FontSize > ($lineHeight * $this->lineheight_correction) && $is_list))) {
  5215. $this->forceExactLineheight = false;
  5216. }
  5217. $maxfontsize = max($maxfontsize,$this->FontSize);
  5218. }
  5219. }
  5220. $lastfontreqstyle = $font[count($font)-1]['ReqFontStyle'];
  5221. $lastfontstyle = $font[count($font)-1]['style'];
  5222. if ($blockdir == 'ltr' && strpos($lastfontreqstyle,"I") !== false && strpos($lastfontstyle,"I") === false) { // Artificial italic
  5223. $lastitalic = $this->FontSize*0.15*_MPDFK;
  5224. }
  5225. else { $lastitalic = 0; }
  5226. /*-- LISTS --*/
  5227. if ($is_list && is_array($this->bulletarray) && $this->bulletarray) {
  5228. $actfs = $this->bulletarray['fontsize'];
  5229. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$actfs * $this->lineheight_correction ); }
  5230. if ($lhfixed && $actfs > $def_fontsize) { $this->forceExactLineheight = false; }
  5231. $maxfontsize = max($maxfontsize,$actfs);
  5232. }
  5233. /*-- END LISTS --*/
  5234. // when every text item checked i.e. $maxfontsize is set properly
  5235. $af = 0; // Above font
  5236. $bf = 0; // Below font
  5237. $mta = 0; // Maximum top-aligned
  5238. $mba = 0; // Maximum bottom-aligned
  5239. foreach ( $content as $k => $chunk ) {
  5240. if (isset($this->objectbuffer[$k]) && $this->objectbuffer[$k]) {
  5241. $contentWidth += $this->objectbuffer[$k]['OUTER-WIDTH'] * _MPDFK;
  5242. $oh = $this->objectbuffer[$k]['OUTER-HEIGHT'];
  5243. $va = $this->objectbuffer[$k]['vertical-align']; // = $objattr['vertical-align'] = set as M,T,B,S
  5244. if ($lhfixed && $oh > $def_fontsize) { $this->forceExactLineheight = false; }
  5245. if ($va == 'BS') { // (BASELINE default)
  5246. $af = max($af, ($oh - ($maxfontsize * (0.5 + $this->baselineC))));
  5247. }
  5248. else if ($va == 'M') {
  5249. $af = max($af, ($oh - $maxfontsize)/2);
  5250. $bf = max($bf, ($oh - $maxfontsize)/2);
  5251. }
  5252. else if ($va == 'TT') {
  5253. $bf = max($bf, ($oh - $maxfontsize));
  5254. }
  5255. else if ($va == 'TB') {
  5256. $af = max($af, ($oh - $maxfontsize));
  5257. }
  5258. else if ($va == 'T') {
  5259. $mta = max($mta, $oh);
  5260. }
  5261. else if ($va == 'B') {
  5262. $mba = max($mba, $oh);
  5263. }
  5264. }
  5265. }
  5266. if ((!$lhfixed || !$this->forceExactLineheight) && ($af > (($maxlineHeight - $maxfontsize)/2) || $bf > (($maxlineHeight - $maxfontsize)/2))) {
  5267. $maxlineHeight = $maxfontsize + $af + $bf;
  5268. }
  5269. else if (!$lhfixed) { $af = $bf = ($maxlineHeight - $maxfontsize)/2; }
  5270. if ($mta > $maxlineHeight) {
  5271. $bf += ($mta - $maxlineHeight);
  5272. $maxlineHeight = $mta;
  5273. }
  5274. if ($mba > $maxlineHeight) {
  5275. $af += ($mba - $maxlineHeight);
  5276. $maxlineHeight = $mba;
  5277. }
  5278. $lineHeight = $maxlineHeight;
  5279. $cutoffWidth = $contentWidth;
  5280. // If NOT images, and maxfontsize NOT > lineHeight - this value determines text baseline positioning
  5281. if ($lhfixed && $af==0 && $bf==0 && $maxfontsize<=($def_fontsize * $this->lineheight_correction * 0.8 )) {
  5282. $this->linemaxfontsize = $def_fontsize;
  5283. }
  5284. else { $this->linemaxfontsize = $maxfontsize; }
  5285. $inclCursive=false;
  5286. foreach ( $content as $k => $chunk ) {
  5287. if (!isset($this->objectbuffer[$k]) || (isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) {
  5288. if ($this->usingCoreFont) {
  5289. $content[$k] = str_replace(chr(160),chr(32),$chunk );
  5290. }
  5291. else {
  5292. $content[$k] = str_replace(chr(194).chr(160),chr(32),$chunk );
  5293. if ($checkCursive) {
  5294. if (preg_match("/([".$this->pregRTLchars."])/u", $chunk)) { $inclCursive = true; } // *RTL*
  5295. if (preg_match("/([".$this->pregHIchars.$this->pregBNchars.$this->pregPAchars."])/u", $chunk)) { $inclCursive = true; } // *INDIC*
  5296. }
  5297. }
  5298. }
  5299. }
  5300. // JUSTIFICATION J
  5301. $jcharspacing = 0;
  5302. $jws = 0;
  5303. $nb_carac = 0;
  5304. $nb_spaces = 0;
  5305. // if it's justified, we need to find the char/word spacing (or if orphans have allowed length of line to go over the maxwidth)
  5306. if(( $align == 'J' ) || (($cutoffWidth + $lastitalic > $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*_MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) ) + 0.001) && !$CJKoverflow)) { // 0.001 is to correct for deviations converting mm=>pts
  5307. // JUSTIFY J (Use character spacing)
  5308. // WORD SPACING
  5309. foreach ( $content as $k => $chunk ) {
  5310. if (!isset($this->objectbuffer[$k]) || (isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) {
  5311. $nb_carac += mb_strlen( $chunk, $this->mb_enc ) ;
  5312. $nb_spaces += mb_substr_count( $chunk,' ', $this->mb_enc ) ;
  5313. }
  5314. }
  5315. list($jcharspacing,$jws) = $this->GetJspacing($nb_carac,$nb_spaces,($maxWidth-$lastitalic-$cutoffWidth-$WidthCorrection-(($this->cMarginL+$this->cMarginR)*_MPDFK)-($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) )),$inclCursive);
  5316. }
  5317. // WORD SPACING
  5318. $empty = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* _MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) );
  5319. $empty -= ($jcharspacing * $nb_carac);
  5320. $empty -= ($jws * $nb_spaces);
  5321. $empty /= _MPDFK;
  5322. $b = ''; //do not use borders
  5323. // Get PAGEBREAK TO TEST for height including the top border/padding
  5324. $check_h = max($this->divheight,$lineHeight);
  5325. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($this->blklvl > 0) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5326. $check_h += ($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['border_top']['w']);
  5327. }
  5328. if ($this->ColActive && $check_h > ($this->PageBreakTrigger - $this->y0)) {
  5329. $this->SetCol($this->NbCol-1);
  5330. }
  5331. // PAGEBREAK
  5332. // 'If' below used in order to fix "first-line of other page with justify on" bug
  5333. if(!$is_table && ($this->y+$check_h) > $this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) {
  5334. $bak_x=$this->x;//Current X position
  5335. // WORD SPACING
  5336. $ws=$this->ws;//Word Spacing
  5337. $charspacing=$this->charspacing;//Character Spacing
  5338. $this->ResetSpacing();
  5339. $this->AddPage($this->CurOrientation);
  5340. $this->x = $bak_x;
  5341. // Added to correct for OddEven Margins
  5342. $currentx += $this->MarginCorrection;
  5343. $this->x += $this->MarginCorrection;
  5344. // WORD SPACING
  5345. $this->SetSpacing($charspacing,$ws);
  5346. }
  5347. if ($this->keep_block_together && !$is_table && $this->kt_p00 < $this->page && ($this->y+$check_h) > $this->kt_y00) {
  5348. $this->printdivbuffer();
  5349. $this->keep_block_together = 0;
  5350. }
  5351. /*-- COLUMNS --*/
  5352. // COLS
  5353. // COLUMN CHANGE
  5354. if ($this->CurrCol != $oldcolumn) {
  5355. $currentx += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  5356. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  5357. $oldcolumn = $this->CurrCol;
  5358. }
  5359. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5360. /*-- END COLUMNS --*/
  5361. // TOP MARGIN
  5362. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($this->blk[$this->blklvl]['margin_top']) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5363. $this->DivLn($this->blk[$this->blklvl]['margin_top'],$this->blklvl-1,true,$this->blk[$this->blklvl]['margin_collapse']);
  5364. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5365. }
  5366. // Update y0 for top of block (used to paint border)
  5367. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5368. $this->blk[$this->blklvl]['y0'] = $this->y;
  5369. $this->blk[$this->blklvl]['startpage'] = $this->page;
  5370. }
  5371. // TOP PADDING and BORDER spacing/fill
  5372. if (($newblock) && ($blockstate==1 || $blockstate==3) && (($this->blk[$this->blklvl]['padding_top']) || ($this->blk[$this->blklvl]['border_top'])) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5373. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  5374. $this->DivLn($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'],-3,true,false,1);
  5375. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5376. }
  5377. $arraysize = count($content);
  5378. $margins = ($this->cMarginL+$this->cMarginR) + ($ipaddingL+$ipaddingR + $fpaddingR + $fpaddingR );
  5379. // PAINT BACKGROUND FOR THIS LINE
  5380. if (!$is_table) { $this->DivLn($lineHeight,$this->blklvl,false); } // false -> don't advance y
  5381. $this->x = $currentx + $this->cMarginL + $ipaddingL + $fpaddingL ;
  5382. if ($align == 'R') { $this->x += $empty; }
  5383. else if ($align == 'C') { $this->x += ($empty / 2); }
  5384. // Paragraph INDENT
  5385. if (isset($this->blk[$this->blklvl]['text_indent']) && ($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 1) && (!$is_table) && ($blockdir !='rtl') && ($align !='C')) {
  5386. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  5387. $this->x += $ti;
  5388. }
  5389. // DIRECTIONALITY RTL
  5390. $all_rtl = false;
  5391. $contains_rtl = false;
  5392. /*-- RTL --*/
  5393. if ($blockdir == 'rtl' || $this->biDirectional) {
  5394. $all_rtl = true;
  5395. foreach ( $content as $k => $chunk ) {
  5396. $reversed = $this->magic_reverse_dir($chunk, false, $blockdir);
  5397. if ($reversed > 0) { $contains_rtl = true; }
  5398. if ($reversed < 2) { $all_rtl = false; }
  5399. $content[$k] = $chunk;
  5400. }
  5401. if (($blockdir =='rtl' && $contains_rtl) || $all_rtl) {
  5402. $content = array_reverse($content,false);
  5403. $contentB = array_reverse($contentB,false); // mPDF 5.3.61
  5404. }
  5405. }
  5406. /*-- END RTL --*/
  5407. foreach ( $content as $k => $chunk ) {
  5408. // FOR IMAGES - UPDATE POSITION
  5409. if (($blockdir =='rtl' && $contains_rtl) || $all_rtl) { $dirk = $arraysize-1 - $k ; } else { $dirk = $k; }
  5410. $va = 'M'; // default for text
  5411. if (isset($this->objectbuffer[$dirk]) && $this->objectbuffer[$dirk]) {
  5412. $xadj = $this->x - $this->objectbuffer[$dirk]['OUTER-X'] ;
  5413. $this->objectbuffer[$dirk]['OUTER-X'] += $xadj;
  5414. $this->objectbuffer[$dirk]['BORDER-X'] += $xadj;
  5415. $this->objectbuffer[$dirk]['INNER-X'] += $xadj;
  5416. $va = $this->objectbuffer[$dirk]['vertical-align'];
  5417. $yadj = $this->y - $this->objectbuffer[$dirk]['OUTER-Y'];
  5418. if ($va == 'BS') {
  5419. $yadj += $af + ($this->linemaxfontsize * (0.5 + $this->baselineC)) - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  5420. }
  5421. else if ($va == 'M' || $va == '') {
  5422. $yadj += $af + ($this->linemaxfontsize /2) - ($this->objectbuffer[$dirk]['OUTER-HEIGHT']/2);
  5423. }
  5424. else if ($va == 'TB') {
  5425. $yadj += $af + $this->linemaxfontsize - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  5426. }
  5427. else if ($va == 'TT') {
  5428. $yadj += $af;
  5429. }
  5430. else if ($va == 'B') {
  5431. $yadj += $af + $this->linemaxfontsize + $bf - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  5432. }
  5433. else if ($va == 'T') {
  5434. $yadj += 0;
  5435. }
  5436. $this->objectbuffer[$dirk]['OUTER-Y'] += $yadj;
  5437. $this->objectbuffer[$dirk]['BORDER-Y'] += $yadj;
  5438. $this->objectbuffer[$dirk]['INNER-Y'] += $yadj;
  5439. }
  5440. // DIRECTIONALITY RTL
  5441. if ((($blockdir == 'rtl') && ($contains_rtl )) || ($all_rtl )) { $this->restoreFont($font[$arraysize-1 - $k]); }
  5442. else { $this->restoreFont( $font[ $k ] ); }
  5443. $this->SetSpacing(($this->fixedlSpacing*_MPDFK)+$jcharspacing,($this->fixedlSpacing+$this->minwSpacing)*_MPDFK+$jws);
  5444. // Now unset these values so they don't influence GetStringwidth below or in fn. Cell
  5445. $this->fixedlSpacing = false;
  5446. $this->minwSpacing = 0;
  5447. // *********** SPAN BACKGROUND COLOR ***************** //
  5448. if ($this->spanbgcolor) {
  5449. $cor = $this->spanbgcolorarray;
  5450. $this->SetFColor($cor);
  5451. $save_fill = $fill; $spanfill = 1; $fill = 1;
  5452. }
  5453. // mPDF 5.3.61
  5454. if (!empty($this->spanborddet)) {
  5455. if (strpos($contentB[$k],'L')!==false) $this->x += $this->spanborddet['L']['w'];
  5456. if (strpos($contentB[$k],'L')===false) $this->spanborddet['L']['s'] = $this->spanborddet['L']['w'] = 0;
  5457. if (strpos($contentB[$k],'R')===false) $this->spanborddet['R']['s'] = $this->spanborddet['R']['w'] = 0;
  5458. }
  5459. // WORD SPACING
  5460. $stringWidth = $this->GetStringWidth($chunk );
  5461. $stringWidth += ( $this->charspacing * mb_strlen($chunk,$this->mb_enc ) / _MPDFK );
  5462. $stringWidth += ( $this->ws * mb_substr_count($chunk,' ',$this->mb_enc ) / _MPDFK );
  5463. if (isset($this->objectbuffer[$dirk])) { $stringWidth = $this->objectbuffer[$dirk]['OUTER-WIDTH']; }
  5464. if ($stringWidth==0) { $stringWidth = 0.000001; }
  5465. if ($k == $arraysize-1) {
  5466. $stringWidth -= ( $this->charspacing / _MPDFK );
  5467. $this->Cell( $stringWidth, $lineHeight, $chunk, '', 1, '', $fill, $this->HREF, $currentx,0,0,'M', $fill, $af, $bf, true ); //mono-style line or last part (skips line) // mPDF 5.3.07
  5468. }
  5469. else $this->Cell( $stringWidth, $lineHeight, $chunk, '', 0, '', $fill, $this->HREF, 0, 0,0,'M', $fill, $af, $bf, true );//first or middle part // mPDF 5.3.07
  5470. // mPDF 5.3.61
  5471. if (!empty($this->spanborddet)) {
  5472. if (strpos($contentB[$k],'R')!==false && $k != $arraysize-1) $this->x += $this->spanborddet['R']['w'];
  5473. }
  5474. // *********** SPAN BACKGROUND COLOR OFF - RESET BLOCK BGCOLOR ***************** //
  5475. if (isset($spanfill) && $spanfill) {
  5476. $fill = $save_fill; $spanfill = 0;
  5477. if ($fill) { $this->SetFColor($bcor); }
  5478. }
  5479. }
  5480. if (!$is_table) {
  5481. $this->maxPosR = max($this->maxPosR , ($this->w - $this->rMargin - $this->blk[$this->blklvl]['outer_right_margin']));
  5482. $this->maxPosL = min($this->maxPosL , ($this->lMargin + $this->blk[$this->blklvl]['outer_left_margin']));
  5483. }
  5484. // move on to the next line, reset variables, tack on saved content and current char
  5485. $this->printobjectbuffer($is_table, $blockdir);
  5486. $this->objectbuffer = array();
  5487. /*-- LISTS --*/
  5488. // LIST BULLETS/NUMBERS
  5489. if ($is_list && is_array($this->bulletarray) && ($lineCount == 1) ) {
  5490. $this->ResetSpacing();
  5491. $bull = $this->bulletarray;
  5492. if (isset($bull['level']) && isset($bull['occur']) && isset($this->InlineProperties['LIST'][$bull['level']][$bull['occur']])) {
  5493. $this->restoreInlineProperties($this->InlineProperties['LIST'][$bull['level']][$bull['occur']]);
  5494. }
  5495. if (isset($bull['level']) && isset($bull['occur']) && isset($bull['num']) && isset($this->InlineProperties['LISTITEM'][$bull['level']][$bull['occur']][$bull['num']]) && $this->InlineProperties['LISTITEM'][$bull['level']][$bull['occur']][$bull['num']]) { $this->restoreInlineProperties($this->InlineProperties['LISTITEM'][$bull['level']][$bull['occur']][$bull['num']]); }
  5496. if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') {
  5497. $this->bullet = true;
  5498. $this->SetFont('czapfdingbats','',$this->FontSizePt/2.5);
  5499. }
  5500. else { $this->SetFont($this->FontFamily,$this->FontStyle,$this->FontSizePt,true,true); } // force output
  5501. //Output bullet
  5502. $this->x = $currentx;
  5503. if (isset($bull['x'])) { $this->x += $bull['x']; }
  5504. $this->y -= $lineHeight;
  5505. if (is_array($bull['col'])) { $this->SetTColor($bull['col']); }
  5506. if (isset($bull['txt'])) { $this->Cell($bull['w'], $lineHeight,$bull['txt'],'','',$bull['align'],0,'',0,-$this->cMarginL, -$this->cMarginR ); }
  5507. if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') {
  5508. $this->bullet = false;
  5509. }
  5510. $this->x = $currentx; // Reset
  5511. $this->y += $lineHeight;
  5512. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5513. $this->bulletarray = array(); // prevents repeat of bullet/number if <li>....<br />.....</li>
  5514. }
  5515. /*-- END LISTS --*/
  5516. /*-- CSS-IMAGE-FLOAT --*/
  5517. // Update values if set to skipline
  5518. if ($this->floatmargins) { $this->_advanceFloatMargins(); }
  5519. /*-- END CSS-IMAGE-FLOAT --*/
  5520. // Reset lineheight
  5521. $lineHeight = $this->divheight;
  5522. $valign = 'M';
  5523. $this->restoreFont( $savedFont );
  5524. // mPDF 5.3.61
  5525. $lbw = $rbw = 0; // Border widths
  5526. if (!empty($this->spanborddet)) {
  5527. $lbw = $this->spanborddet['L']['w'];
  5528. $rbw = $this->spanborddet['R']['w'];
  5529. }
  5530. $font = array();
  5531. $content = array();
  5532. $contentB = array(); // mPDF 5.3.61
  5533. $contentWidth = 0;
  5534. if (!empty($savedObj)) {
  5535. $this->objectbuffer[] = $savedObj;
  5536. $font[] = $savedFont;
  5537. $content[] = '';
  5538. $contentB[] = '';
  5539. $contentWidth += $savedObj['OUTER-WIDTH'] * _MPDFK;
  5540. }
  5541. $font[] = $savedFont;
  5542. $content[] = $savedContent . $c;
  5543. $contentB[] = $savedContentB ; // mPDF 5.3.61
  5544. $currContent =& $content[ (count($content)-1) ];
  5545. // CJK - strip CJK space at end of line
  5546. // &#x3000; = \xe3\x80\x80 = CJK space
  5547. if ($this->checkCJK && $currContent == "\xe3\x80\x80") { $currContent = '' ; } // *CJK-FONTS*
  5548. $contentWidth += $this->GetStringWidth( $currContent ) * _MPDFK;
  5549. // mPDF 5.3.61
  5550. if (strpos($savedContentB,'L')!==false) $contentWidth += $lbw;
  5551. $cutoffWidth = $contentWidth;
  5552. $CJKoverflow = false;
  5553. }
  5554. // another character will fit, so add it on
  5555. else {
  5556. $contentWidth += $cw;
  5557. $currContent .= $c;
  5558. }
  5559. }
  5560. unset($content);
  5561. unset($contentB); // mPDF 5.3.61
  5562. }
  5563. //----------------------END OF FLOWING BLOCK------------------------------------//
  5564. /*-- CSS-IMAGE-FLOAT --*/
  5565. // Update values if set to skipline
  5566. function _advanceFloatMargins() {
  5567. // Update floatmargins - L
  5568. if (isset($this->floatmargins['L']) && $this->floatmargins['L']['skipline'] && $this->floatmargins['L']['y0'] != $this->y) {
  5569. $yadj = $this->y - $this->floatmargins['L']['y0'];
  5570. $this->floatmargins['L']['y0'] = $this->y;
  5571. $this->floatmargins['L']['y1'] += $yadj;
  5572. // Update objattr in floatbuffer
  5573. if ($this->floatbuffer[$this->floatmargins['L']['id']]['border_left']['w']) {
  5574. $this->floatbuffer[$this->floatmargins['L']['id']]['BORDER-Y'] += $yadj;
  5575. }
  5576. $this->floatbuffer[$this->floatmargins['L']['id']]['INNER-Y'] += $yadj;
  5577. $this->floatbuffer[$this->floatmargins['L']['id']]['OUTER-Y'] += $yadj;
  5578. // Unset values
  5579. $this->floatbuffer[$this->floatmargins['L']['id']]['skipline'] = false;
  5580. $this->floatmargins['L']['skipline'] = false;
  5581. $this->floatmargins['L']['id'] = '';
  5582. }
  5583. // Update floatmargins - R
  5584. if (isset($this->floatmargins['R']) && $this->floatmargins['R']['skipline'] && $this->floatmargins['R']['y0'] != $this->y) {
  5585. $yadj = $this->y - $this->floatmargins['R']['y0'];
  5586. $this->floatmargins['R']['y0'] = $this->y;
  5587. $this->floatmargins['R']['y1'] += $yadj;
  5588. // Update objattr in floatbuffer
  5589. if ($this->floatbuffer[$this->floatmargins['R']['id']]['border_left']['w']) {
  5590. $this->floatbuffer[$this->floatmargins['R']['id']]['BORDER-Y'] += $yadj;
  5591. }
  5592. $this->floatbuffer[$this->floatmargins['R']['id']]['INNER-Y'] += $yadj;
  5593. $this->floatbuffer[$this->floatmargins['R']['id']]['OUTER-Y'] += $yadj;
  5594. // Unset values
  5595. $this->floatbuffer[$this->floatmargins['R']['id']]['skipline'] = false;
  5596. $this->floatmargins['R']['skipline'] = false;
  5597. $this->floatmargins['R']['id'] = '';
  5598. }
  5599. }
  5600. /*-- END CSS-IMAGE-FLOAT --*/
  5601. ////////////////////////////////////////////////////////////////////////////////
  5602. // ADDED forcewrap - to call from inline OBJECT functions to breakwords if necessary in cell
  5603. ////////////////////////////////////////////////////////////////////////////////
  5604. function WordWrap(&$text, $maxwidth, $forcewrap = 0) {
  5605. $biggestword=0;
  5606. $toonarrow=false;
  5607. $text = trim($text);
  5608. if ($text==='') return 0;
  5609. $space = $this->GetCharWidth(' ',false); // mPDF 5.3.04
  5610. $lines = explode("\n", $text);
  5611. $text = '';
  5612. $count = 0;
  5613. foreach ($lines as $line) {
  5614. $words = explode(' ', $line);
  5615. $width = 0;
  5616. foreach ($words as $word) {
  5617. $word = trim($word);
  5618. $wordwidth = $this->GetStringWidth($word);
  5619. //Warn user that maxwidth is insufficient
  5620. if ($wordwidth > $maxwidth + 0.0001) {
  5621. if ($wordwidth > $biggestword) { $biggestword = $wordwidth; }
  5622. $toonarrow=true;
  5623. // ADDED
  5624. if ($forcewrap) {
  5625. while($wordwidth > $maxwidth) {
  5626. $chw = 0; // check width
  5627. for ( $i = 0; $i < mb_strlen($word, $this->mb_enc ); $i++ ) {
  5628. $chw = $this->GetStringWidth(mb_substr($word,0,$i+1,$this->mb_enc ));
  5629. if ($chw > $maxwidth ) {
  5630. if ($text) {
  5631. $text = rtrim($text)."\n".mb_substr($word,0,$i,$this->mb_enc );
  5632. $count++;
  5633. }
  5634. else {
  5635. $text = mb_substr($word,0,$i,$this->mb_enc );
  5636. }
  5637. $word = mb_substr($word,$i,mb_strlen($word, $this->mb_enc )-$i,$this->mb_enc );
  5638. $wordwidth = $this->GetStringWidth($word);
  5639. $width = $maxwidth;
  5640. break;
  5641. }
  5642. }
  5643. }
  5644. }
  5645. }
  5646. if ($width + $wordwidth < $maxwidth - 0.0001) {
  5647. $width += $wordwidth + $space;
  5648. $text .= $word.' ';
  5649. }
  5650. else {
  5651. $width = $wordwidth + $space;
  5652. $text = rtrim($text)."\n".$word.' ';
  5653. $count++;
  5654. }
  5655. }
  5656. $text .= "\n";
  5657. $count++;
  5658. }
  5659. $text = rtrim($text);
  5660. //Return -(wordsize) if word is bigger than maxwidth
  5661. // ADDED
  5662. if ($forcewrap) { return $count; }
  5663. if (($toonarrow) && ($this->table_error_report)) {
  5664. $this->Error("Word is too long to fit in table - ".$this->table_error_report_param);
  5665. }
  5666. if ($toonarrow) return -$biggestword;
  5667. else return $count;
  5668. }
  5669. /*-- END HTML-CSS --*/
  5670. function _SetTextRendering($mode) {
  5671. if (!(($mode == 0) || ($mode == 1) || ($mode == 2)))
  5672. $this->Error("Text rendering mode should be 0, 1 or 2 (value : $mode)");
  5673. $tr = ($mode.' Tr');
  5674. if($this->page>0 && ((isset($this->pageoutput[$this->page]['TextRendering']) && $this->pageoutput[$this->page]['TextRendering'] != $tr) || !isset($this->pageoutput[$this->page]['TextRendering']) || $this->keep_block_together)) { $this->_out($tr); }
  5675. $this->pageoutput[$this->page]['TextRendering'] = $tr;
  5676. }
  5677. function SetTextOutline($width, $col=0) {
  5678. if ($width == false) //Now resets all values
  5679. {
  5680. $this->outline_on = false;
  5681. $this->SetLineWidth(0.2);
  5682. $this->SetDColor($this->ConvertColor(0));
  5683. $this->_SetTextRendering(0);
  5684. $tr = ('0 Tr');
  5685. if($this->page>0 && ((isset($this->pageoutput[$this->page]['TextRendering']) && $this->pageoutput[$this->page]['TextRendering'] != $tr) || !isset($this->pageoutput[$this->page]['TextRendering']) || $this->keep_block_together)) { $this->_out($tr); }
  5686. $this->pageoutput[$this->page]['TextRendering'] = $tr;
  5687. }
  5688. else
  5689. {
  5690. $this->SetLineWidth($width);
  5691. $this->SetDColor($col);
  5692. $tr = ('2 Tr');
  5693. if($this->page>0 && ((isset($this->pageoutput[$this->page]['TextRendering']) && $this->pageoutput[$this->page]['TextRendering'] != $tr) || !isset($this->pageoutput[$this->page]['TextRendering']) || $this->keep_block_together)) { $this->_out($tr); }
  5694. $this->pageoutput[$this->page]['TextRendering'] = $tr;
  5695. }
  5696. }
  5697. function Image($file,$x,$y,$w=0,$h=0,$type='',$link='',$paint=true, $constrain=true, $watermark=false, $shownoimg=true, $allowvector=true) {
  5698. $orig_srcpath = $file;
  5699. $this->GetFullPath($file);
  5700. $info=$this->_getImage($file, true, $allowvector, $orig_srcpath );
  5701. if(!$info && $paint) {
  5702. $info = $this->_getImage($this->noImageFile);
  5703. if ($info) {
  5704. $file = $this->noImageFile;
  5705. $w = ($info['w'] * (25.4/$this->dpi)); // 14 x 16px
  5706. $h = ($info['h'] * (25.4/$this->dpi)); // 14 x 16px
  5707. }
  5708. }
  5709. if(!$info) return false;
  5710. //Automatic width and height calculation if needed
  5711. if($w==0 and $h==0) {
  5712. /*-- IMAGES-WMF --*/
  5713. if ($info['type']=='wmf') {
  5714. // WMF units are twips (1/20pt)
  5715. // divide by 20 to get points
  5716. // divide by k to get user units
  5717. $w = abs($info['w'])/(20*_MPDFK);
  5718. $h = abs($info['h']) / (20*_MPDFK);
  5719. }
  5720. else
  5721. /*-- END IMAGES-WMF --*/
  5722. if ($info['type']=='svg') {
  5723. // returned SVG units are pts
  5724. // divide by k to get user units (mm)
  5725. $w = abs($info['w'])/_MPDFK;
  5726. $h = abs($info['h']) /_MPDFK;
  5727. }
  5728. else {
  5729. //Put image at default image dpi
  5730. $w=($info['w']/_MPDFK) * (72/$this->img_dpi);
  5731. $h=($info['h']/_MPDFK) * (72/$this->img_dpi);
  5732. }
  5733. }
  5734. if($w==0) $w=abs($h*$info['w']/$info['h']);
  5735. if($h==0) $h=abs($w*$info['h']/$info['w']);
  5736. /*-- WATERMARK --*/
  5737. if ($watermark) {
  5738. $maxw = $this->w;
  5739. $maxh = $this->h;
  5740. // Size = D PF or array
  5741. if (is_array($this->watermark_size)) {
  5742. $w = $this->watermark_size[0];
  5743. $h = $this->watermark_size[1];
  5744. }
  5745. else if (!is_string($this->watermark_size)) {
  5746. $maxw -= $this->watermark_size*2;
  5747. $maxh -= $this->watermark_size*2;
  5748. $w = $maxw;
  5749. $h=abs($w*$info['h']/$info['w']);
  5750. if ($h > $maxh ) {
  5751. $h = $maxh ; $w=abs($h*$info['w']/$info['h']);
  5752. }
  5753. }
  5754. else if ($this->watermark_size == 'F') {
  5755. if ($this->ColActive) { $maxw = $this->w - ($this->DeflMargin + $this->DefrMargin); }
  5756. else { $maxw = $this->pgwidth; }
  5757. $maxh = $this->h - ($this->tMargin + $this->bMargin);
  5758. $w = $maxw;
  5759. $h=abs($w*$info['h']/$info['w']);
  5760. if ($h > $maxh ) {
  5761. $h = $maxh ; $w=abs($h*$info['w']/$info['h']);
  5762. }
  5763. }
  5764. else if ($this->watermark_size == 'P') { // Default P
  5765. $w = $maxw;
  5766. $h=abs($w*$info['h']/$info['w']);
  5767. if ($h > $maxh ) {
  5768. $h = $maxh ; $w=abs($h*$info['w']/$info['h']);
  5769. }
  5770. }
  5771. // Automatically resize to maximum dimensions of page if too large
  5772. if ($w > $maxw) {
  5773. $w = $maxw;
  5774. $h=abs($w*$info['h']/$info['w']);
  5775. }
  5776. if ($h > $maxh ) {
  5777. $h = $maxh ;
  5778. $w=abs($h*$info['w']/$info['h']);
  5779. }
  5780. // Position
  5781. if (is_array($this->watermark_pos)) {
  5782. $x = $this->watermark_pos[0];
  5783. $y = $this->watermark_pos[1];
  5784. }
  5785. else if ($this->watermark_pos == 'F') { // centred on printable area
  5786. if ($this->ColActive) { // *COLUMNS*
  5787. if (($this->mirrorMargins) && (($this->page)%2==0)) { $xadj = $this->DeflMargin-$this->DefrMargin; } // *COLUMNS*
  5788. else { $xadj = 0; } // *COLUMNS*
  5789. $x = ($this->DeflMargin - $xadj + ($this->w - ($this->DeflMargin + $this->DefrMargin))/2) - ($w/2); // *COLUMNS*
  5790. } // *COLUMNS*
  5791. else { // *COLUMNS*
  5792. $x = ($this->lMargin + ($this->pgwidth)/2) - ($w/2);
  5793. } // *COLUMNS*
  5794. $y = ($this->tMargin + ($this->h - ($this->tMargin + $this->bMargin))/2) - ($h/2);
  5795. }
  5796. else { // default P - centred on whole page
  5797. $x = ($this->w/2) - ($w/2);
  5798. $y = ($this->h/2) - ($h/2);
  5799. }
  5800. /*-- IMAGES-WMF --*/
  5801. if ($info['type']=='wmf') {
  5802. $sx = $w*_MPDFK / $info['w'];
  5803. $sy = -$h*_MPDFK / $info['h'];
  5804. $outstring = sprintf('q %.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q', $sx, $sy, $x*_MPDFK-$sx*$info['x'], (($this->h-$y)*_MPDFK)-$sy*$info['y'], $info['i']);
  5805. }
  5806. else
  5807. /*-- END IMAGES-WMF --*/
  5808. if ($info['type']=='svg') {
  5809. $sx = $w*_MPDFK / $info['w'];
  5810. $sy = -$h*_MPDFK / $info['h'];
  5811. $outstring = sprintf('q %.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q', $sx, $sy, $x*_MPDFK-$sx*$info['x'], (($this->h-$y)*_MPDFK)-$sy*$info['y'], $info['i']);
  5812. }
  5813. else {
  5814. $outstring = sprintf("q %.3F 0 0 %.3F %.3F %.3F cm /I%d Do Q",$w*_MPDFK,$h*_MPDFK,$x*_MPDFK,($this->h-($y+$h))*_MPDFK,$info['i']);
  5815. }
  5816. if ($this->watermarkImgBehind) {
  5817. $outstring = $this->watermarkImgAlpha . "\n" . $outstring . "\n" . $this->SetAlpha(1, 'Normal', true) . "\n";
  5818. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$outstring."\n".'\\1', $this->pages[$this->page]);
  5819. }
  5820. else { $this->_out($outstring); }
  5821. return 0;
  5822. } // end of IF watermark
  5823. /*-- END WATERMARK --*/
  5824. if ($constrain) {
  5825. // Automatically resize to maximum dimensions of page if too large
  5826. if (isset($this->blk[$this->blklvl]['inner_width']) && $this->blk[$this->blklvl]['inner_width']) { $maxw = $this->blk[$this->blklvl]['inner_width']; }
  5827. else { $maxw = $this->pgwidth; }
  5828. if ($w > $maxw) {
  5829. $w = $maxw;
  5830. $h=abs($w*$info['h']/$info['w']);
  5831. }
  5832. if ($h > $this->h - ($this->tMargin + $this->bMargin + 1)) { // see below - +10 to avoid drawing too close to border of page
  5833. $h = $this->h - ($this->tMargin + $this->bMargin + 1) ;
  5834. if ($this->fullImageHeight) { $h = $this->fullImageHeight; }
  5835. $w=abs($h*$info['w']/$info['h']);
  5836. }
  5837. //Avoid drawing out of the paper(exceeding width limits).
  5838. //if ( ($x + $w) > $this->fw ) {
  5839. if ( ($x + $w) > $this->w ) {
  5840. $x = $this->lMargin;
  5841. $y += 5;
  5842. }
  5843. $changedpage = false;
  5844. $oldcolumn = $this->CurrCol;
  5845. //Avoid drawing out of the page.
  5846. if($y+$h>$this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) {
  5847. $this->AddPage($this->CurOrientation);
  5848. // Added to correct for OddEven Margins
  5849. $x=$x +$this->MarginCorrection;
  5850. $y = $tMargin + $this->margin_header;
  5851. $changedpage = true;
  5852. }
  5853. /*-- COLUMNS --*/
  5854. // COLS
  5855. // COLUMN CHANGE
  5856. if ($this->CurrCol != $oldcolumn) {
  5857. $y = $this->y0;
  5858. $x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  5859. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  5860. }
  5861. /*-- END COLUMNS --*/
  5862. } // end of IF constrain
  5863. /*-- IMAGES-WMF --*/
  5864. if ($info['type']=='wmf') {
  5865. $sx = $w*_MPDFK / $info['w'];
  5866. $sy = -$h*_MPDFK / $info['h'];
  5867. $outstring = sprintf('q %.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q', $sx, $sy, $x*_MPDFK-$sx*$info['x'], (($this->h-$y)*_MPDFK)-$sy*$info['y'], $info['i']);
  5868. }
  5869. else
  5870. /*-- END IMAGES-WMF --*/
  5871. if ($info['type']=='svg') {
  5872. $sx = $w*_MPDFK / $info['w'];
  5873. $sy = -$h*_MPDFK / $info['h'];
  5874. $outstring = sprintf('q %.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q', $sx, $sy, $x*_MPDFK-$sx*$info['x'], (($this->h-$y)*_MPDFK)-$sy*$info['y'], $info['i']);
  5875. }
  5876. else {
  5877. $outstring = sprintf("q %.3F 0 0 %.3F %.3F %.3F cm /I%d Do Q",$w*_MPDFK,$h*_MPDFK,$x*_MPDFK,($this->h-($y+$h))*_MPDFK,$info['i']);
  5878. }
  5879. if($paint) {
  5880. $this->_out($outstring);
  5881. if($link) $this->Link($x,$y,$w,$h,$link);
  5882. // Avoid writing text on top of the image. // THIS WAS OUTSIDE THE if ($paint) bit!!!!!!!!!!!!!!!!
  5883. $this->y = $y + $h;
  5884. }
  5885. //Return width-height array
  5886. $sizesarray['WIDTH'] = $w;
  5887. $sizesarray['HEIGHT'] = $h;
  5888. $sizesarray['X'] = $x; //Position before painting image
  5889. $sizesarray['Y'] = $y; //Position before painting image
  5890. $sizesarray['OUTPUT'] = $outstring;
  5891. $sizesarray['IMAGE_ID'] = $info['i'];
  5892. $sizesarray['itype'] = $info['type'];
  5893. $sizesarray['set-dpi'] = $info['set-dpi'];
  5894. return $sizesarray;
  5895. }
  5896. //=============================================================
  5897. //=============================================================
  5898. //=============================================================
  5899. //=============================================================
  5900. //=============================================================
  5901. /*-- HTML-CSS --*/
  5902. function _getObjAttr($t) {
  5903. $c = explode("\xbb\xa4\xac",$t,2);
  5904. $c = explode(",",$c[1],2);
  5905. foreach($c as $v) {
  5906. $v = explode("=",$v,2);
  5907. $sp[$v[0]] = $v[1];
  5908. }
  5909. return (unserialize($sp['objattr']));
  5910. }
  5911. function inlineObject($type,$x,$y,$objattr,$Lmargin,$widthUsed,$maxWidth,$lineHeight,$paint=false,$is_table=false)
  5912. {
  5913. if ($is_table) { $k = $this->shrin_k; } else { $k = 1; }
  5914. // NB $x is only used when paint=true
  5915. // Lmargin not used
  5916. $w = 0;
  5917. if (isset($objattr['width'])) { $w = $objattr['width']/$k; }
  5918. $h = 0;
  5919. if (isset($objattr['height'])) { $h = abs($objattr['height']/$k); }
  5920. $widthLeft = $maxWidth - $widthUsed;
  5921. $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 10) ;
  5922. if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; }
  5923. // For Images
  5924. if (isset($objattr['border_left'])) {
  5925. $extraWidth = ($objattr['border_left']['w'] + $objattr['border_right']['w'] + $objattr['margin_left']+ $objattr['margin_right'])/$k;
  5926. $extraHeight = ($objattr['border_top']['w'] + $objattr['border_bottom']['w'] + $objattr['margin_top']+ $objattr['margin_bottom'])/$k;
  5927. if ($type == 'image' || $type == 'barcode' || $type == 'textcircle') { // mPDF 5.3.A5
  5928. $extraWidth += ($objattr['padding_left'] + $objattr['padding_right'])/$k;
  5929. $extraHeight += ($objattr['padding_top'] + $objattr['padding_bottom'])/$k;
  5930. }
  5931. }
  5932. if (!isset($objattr['vertical-align'])) { $objattr['vertical-align'] = 'M'; }
  5933. if ($type == 'image' || (isset($objattr['subtype']) && $objattr['subtype'] == 'IMAGE')) {
  5934. if (isset($objattr['itype']) && ($objattr['itype'] == 'wmf' || $objattr['itype'] == 'svg')) {
  5935. $file = $objattr['file'];
  5936. $info=$this->formobjects[$file];
  5937. }
  5938. else if (isset($objattr['file'])) {
  5939. $file = $objattr['file'];
  5940. $info=$this->images[$file];
  5941. }
  5942. }
  5943. if ($type == 'annot' || $type == 'bookmark' || $type == 'indexentry' || $type == 'toc') {
  5944. $w = 0.00001;
  5945. $h = 0.00001;
  5946. }
  5947. // TEST whether need to skipline
  5948. if (!$paint) {
  5949. if ($type == 'hr') { // always force new line
  5950. if (($y + $h + $lineHeight > $this->PageBreakTrigger) && !$this->InFooter && !$is_table) { return array(-2, $w ,$h ); } // New page + new line
  5951. else { return array(1, $w ,$h ); } // new line
  5952. }
  5953. else {
  5954. if ($widthUsed > 0 && $w > $widthLeft && (!$is_table || $type != 'image')) { // New line needed
  5955. if (($y + $h + $lineHeight > $this->PageBreakTrigger) && !$this->InFooter) { return array(-2,$w ,$h ); } // New page + new line
  5956. return array(1,$w ,$h ); // new line
  5957. }
  5958. else if ($widthUsed > 0 && $w > $widthLeft && $is_table) { // New line needed in TABLE
  5959. return array(1,$w ,$h ); // new line
  5960. }
  5961. // Will fit on line but NEW PAGE REQUIRED
  5962. else if (($y + $h > $this->PageBreakTrigger) && !$this->InFooter && !$is_table) { return array(-1,$w ,$h ); }
  5963. else { return array(0,$w ,$h ); }
  5964. }
  5965. }
  5966. if ($type == 'annot' || $type == 'bookmark' || $type == 'indexentry' || $type == 'toc') {
  5967. $w = 0.00001;
  5968. $h = 0.00001;
  5969. $objattr['BORDER-WIDTH'] = 0;
  5970. $objattr['BORDER-HEIGHT'] = 0;
  5971. $objattr['BORDER-X'] = $x;
  5972. $objattr['BORDER-Y'] = $y;
  5973. $objattr['INNER-WIDTH'] = 0;
  5974. $objattr['INNER-HEIGHT'] = 0;
  5975. $objattr['INNER-X'] = $x;
  5976. $objattr['INNER-Y'] = $y;
  5977. }
  5978. if ($type == 'image') {
  5979. // Automatically resize to width remaining
  5980. if ($w > $widthLeft && !$is_table) {
  5981. $w = $widthLeft ;
  5982. $h=abs($w*$info['h']/$info['w']);
  5983. }
  5984. $img_w = $w - $extraWidth ;
  5985. $img_h = $h - $extraHeight ;
  5986. $objattr['BORDER-WIDTH'] = $img_w + $objattr['padding_left']/$k + $objattr['padding_right']/$k + (($objattr['border_left']['w']/$k + $objattr['border_right']['w']/$k)/2) ;
  5987. $objattr['BORDER-HEIGHT'] = $img_h + $objattr['padding_top']/$k + $objattr['padding_bottom']/$k + (($objattr['border_top']['w']/$k + $objattr['border_bottom']['w']/$k)/2) ;
  5988. $objattr['BORDER-X'] = $x + $objattr['margin_left']/$k + (($objattr['border_left']['w']/$k)/2) ;
  5989. $objattr['BORDER-Y'] = $y + $objattr['margin_top']/$k + (($objattr['border_top']['w']/$k)/2) ;
  5990. $objattr['INNER-WIDTH'] = $img_w;
  5991. $objattr['INNER-HEIGHT'] = $img_h;
  5992. $objattr['INNER-X'] = $x + $objattr['padding_left']/$k + $objattr['margin_left']/$k + ($objattr['border_left']['w']/$k);
  5993. $objattr['INNER-Y'] = $y + $objattr['padding_top']/$k + $objattr['margin_top']/$k + ($objattr['border_top']['w']/$k) ;
  5994. $objattr['ID'] = $info['i'];
  5995. }
  5996. if ($type == 'input' && $objattr['subtype'] == 'IMAGE') {
  5997. $img_w = $w - $extraWidth ;
  5998. $img_h = $h - $extraHeight ;
  5999. $objattr['BORDER-WIDTH'] = $img_w + (($objattr['border_left']['w']/$k + $objattr['border_right']['w']/$k)/2) ;
  6000. $objattr['BORDER-HEIGHT'] = $img_h + (($objattr['border_top']['w']/$k + $objattr['border_bottom']['w']/$k)/2) ;
  6001. $objattr['BORDER-X'] = $x + $objattr['margin_left']/$k + (($objattr['border_left']['w']/$k)/2) ;
  6002. $objattr['BORDER-Y'] = $y + $objattr['margin_top']/$k + (($objattr['border_top']['w']/$k)/2) ;
  6003. $objattr['INNER-WIDTH'] = $img_w;
  6004. $objattr['INNER-HEIGHT'] = $img_h;
  6005. $objattr['INNER-X'] = $x + $objattr['margin_left']/$k + ($objattr['border_left']['w']/$k);
  6006. $objattr['INNER-Y'] = $y + $objattr['margin_top']/$k + ($objattr['border_top']['w']/$k) ;
  6007. $objattr['ID'] = $info['i'];
  6008. }
  6009. if ($type == 'barcode' || $type == 'textcircle') { // mPDF 5.3.A5
  6010. $b_w = $w - $extraWidth ;
  6011. $b_h = $h - $extraHeight ;
  6012. $objattr['BORDER-WIDTH'] = $b_w + $objattr['padding_left']/$k + $objattr['padding_right']/$k + (($objattr['border_left']['w']/$k + $objattr['border_right']['w']/$k)/2) ;
  6013. $objattr['BORDER-HEIGHT'] = $b_h + $objattr['padding_top']/$k + $objattr['padding_bottom']/$k + (($objattr['border_top']['w']/$k + $objattr['border_bottom']['w']/$k)/2) ;
  6014. $objattr['BORDER-X'] = $x + $objattr['margin_left']/$k + (($objattr['border_left']['w']/$k)/2) ;
  6015. $objattr['BORDER-Y'] = $y + $objattr['margin_top']/$k + (($objattr['border_top']['w']/$k)/2) ;
  6016. $objattr['INNER-X'] = $x + $objattr['padding_left']/$k + $objattr['margin_left']/$k + ($objattr['border_left']['w']/$k);
  6017. $objattr['INNER-Y'] = $y + $objattr['padding_top']/$k + $objattr['margin_top']/$k + ($objattr['border_top']['w']/$k) ;
  6018. $objattr['INNER-WIDTH'] = $b_w;
  6019. $objattr['INNER-HEIGHT'] = $b_h;
  6020. }
  6021. if ($type == 'textarea') {
  6022. // Automatically resize to width remaining
  6023. if ($w > $widthLeft && !$is_table) {
  6024. $w = $widthLeft ;
  6025. }
  6026. if (($y + $h > $this->PageBreakTrigger) && !$this->InFooter) {
  6027. $h=$this->h - $y - $this->bMargin;
  6028. }
  6029. }
  6030. if ($type == 'hr') {
  6031. if ($is_table) {
  6032. $objattr['INNER-WIDTH'] = $maxWidth * $objattr['W-PERCENT']/100;
  6033. $objattr['width'] = $objattr['INNER-WIDTH'];
  6034. $w = $maxWidth;
  6035. }
  6036. else {
  6037. if ($w>$maxWidth) { $w = $maxWidth; }
  6038. $objattr['INNER-WIDTH'] = $w;
  6039. $w = $maxWidth;
  6040. }
  6041. }
  6042. if (($type == 'select') || ($type == 'input' && ($objattr['subtype'] == 'TEXT' || $objattr['subtype'] == 'PASSWORD'))) {
  6043. // Automatically resize to width remaining
  6044. if ($w > $widthLeft && !$is_table) {
  6045. $w = $widthLeft;
  6046. }
  6047. }
  6048. if ($type == 'textarea' || $type == 'select' || $type == 'input') {
  6049. if (isset($objattr['fontsize'])) $objattr['fontsize'] /= $k;
  6050. if (isset($objattr['linewidth'])) $objattr['linewidth'] /= $k;
  6051. }
  6052. if (!isset($objattr['BORDER-Y'])) { $objattr['BORDER-Y'] = 0; }
  6053. if (!isset($objattr['BORDER-X'])) { $objattr['BORDER-X'] = 0; }
  6054. if (!isset($objattr['INNER-Y'])) { $objattr['INNER-Y'] = 0; }
  6055. if (!isset($objattr['INNER-X'])) { $objattr['INNER-X'] = 0; }
  6056. //Return width-height array
  6057. $objattr['OUTER-WIDTH'] = $w;
  6058. $objattr['OUTER-HEIGHT'] = $h;
  6059. $objattr['OUTER-X'] = $x;
  6060. $objattr['OUTER-Y'] = $y;
  6061. return $objattr;
  6062. }
  6063. /*-- END HTML-CSS --*/
  6064. //=============================================================
  6065. //=============================================================
  6066. //=============================================================
  6067. //=============================================================
  6068. //=============================================================
  6069. function SetLineJoin($mode=0)
  6070. {
  6071. $s=sprintf('%d j',$mode);
  6072. if($this->page>0 && ((isset($this->pageoutput[$this->page]['LineJoin']) && $this->pageoutput[$this->page]['LineJoin'] != $s) || !isset($this->pageoutput[$this->page]['LineJoin']) || $this->keep_block_together)) { $this->_out($s); }
  6073. $this->pageoutput[$this->page]['LineJoin'] = $s;
  6074. }
  6075. function SetLineCap($mode=2) {
  6076. $s=sprintf('%d J',$mode);
  6077. if($this->page>0 && ((isset($this->pageoutput[$this->page]['LineCap']) && $this->pageoutput[$this->page]['LineCap'] != $s) || !isset($this->pageoutput[$this->page]['LineCap']) || $this->keep_block_together)) { $this->_out($s); }
  6078. $this->pageoutput[$this->page]['LineCap'] = $s;
  6079. }
  6080. function SetDash($black=false,$white=false)
  6081. {
  6082. if($black and $white) $s=sprintf('[%.3F %.3F] 0 d',$black*_MPDFK,$white*_MPDFK);
  6083. else $s='[] 0 d';
  6084. if($this->page>0 && ((isset($this->pageoutput[$this->page]['Dash']) && $this->pageoutput[$this->page]['Dash'] != $s) || !isset($this->pageoutput[$this->page]['Dash']) || $this->keep_block_together)) { $this->_out($s); }
  6085. $this->pageoutput[$this->page]['Dash'] = $s;
  6086. }
  6087. function SetDisplayPreferences($preferences) {
  6088. // String containing any or none of /HideMenubar/HideToolbar/HideWindowUI/DisplayDocTitle/CenterWindow/FitWindow
  6089. $this->DisplayPreferences .= $preferences;
  6090. }
  6091. function Ln($h='',$collapsible=0)
  6092. {
  6093. // Added collapsible to allow collapsible top-margin on new page
  6094. //Line feed; default value is last cell height
  6095. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  6096. if ($collapsible && ($this->y==$this->tMargin) && (!$this->ColActive)) { $h = 0; }
  6097. if(is_string($h)) $this->y+=$this->lasth;
  6098. else $this->y+=$h;
  6099. }
  6100. /*-- HTML-CSS --*/
  6101. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  6102. function DivLn($h,$level=-3,$move_y=true,$collapsible=false,$state=0) {
  6103. // this->x is returned as it was
  6104. // adds lines (y) where DIV bgcolors are filled in
  6105. // allows .00001 as nominal height used for bookmarks/annotations etc.
  6106. if ($collapsible && (sprintf("%0.4f", $this->y)==sprintf("%0.4f", $this->tMargin)) && (!$this->ColActive)) { return; }
  6107. if ($collapsible && (sprintf("%0.4f", $this->y)==sprintf("%0.4f", $this->y0)) && ($this->ColActive) && $this->CurrCol == 0) { return; } // *COLUMNS*
  6108. // Still use this method if columns or page-break-inside: avoid, as it allows repositioning later
  6109. // otherwise, now uses PaintDivBB()
  6110. if (!$this->ColActive && !$this->keep_block_together && !$this->kwt) {
  6111. if ($move_y && !$this->ColActive) { $this->y += $h; }
  6112. return;
  6113. }
  6114. if ($level == -3) { $level = $this->blklvl; }
  6115. $firstblockfill = $this->GetFirstBlockFill();
  6116. if ($firstblockfill && $this->blklvl > 0 && $this->blklvl >= $firstblockfill) {
  6117. $last_x = 0;
  6118. $last_w = 0;
  6119. $last_fc = $this->FillColor;
  6120. $bak_x = $this->x;
  6121. $bak_h = $this->divheight;
  6122. $this->divheight = 0; // Temporarily turn off divheight - as Cell() uses it to check for PageBreak
  6123. for ($blvl=$firstblockfill;$blvl<=$level;$blvl++) {
  6124. $this->SetBlockFill($blvl);
  6125. $this->x = $this->lMargin + $this->blk[$blvl]['outer_left_margin'];
  6126. if ($last_x != $this->lMargin + $this->blk[$blvl]['outer_left_margin'] || $last_w != $this->blk[$blvl]['width'] || $last_fc != $this->FillColor) {
  6127. $x = $this->x;
  6128. $this->Cell( ($this->blk[$blvl]['width']), $h, '', '', 0, '', 1);
  6129. if (!$this->keep_block_together && !$this->writingHTMLheader && !$this->writingHTMLfooter) {
  6130. $this->x = $x;
  6131. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  6132. if ($blvl == $this->blklvl) { $this->PaintDivLnBorder($state,$blvl,$h); }
  6133. else { $this->PaintDivLnBorder(0,$blvl,$h); }
  6134. }
  6135. }
  6136. $last_x = $this->lMargin + $this->blk[$blvl]['outer_left_margin'];
  6137. $last_w = $this->blk[$blvl]['width'];
  6138. $last_fc = $this->FillColor;
  6139. }
  6140. // Reset current block fill
  6141. if (isset($this->blk[$this->blklvl]['bgcolorarray'])) {
  6142. $bcor = $this->blk[$this->blklvl]['bgcolorarray'];
  6143. $this->SetFColor($bcor);
  6144. }
  6145. $this->x = $bak_x;
  6146. $this->divheight = $bak_h;
  6147. }
  6148. if ($move_y) { $this->y += $h; }
  6149. }
  6150. /*-- END HTML-CSS --*/
  6151. function SetX($x)
  6152. {
  6153. //Set x position
  6154. if($x >= 0) $this->x=$x;
  6155. else $this->x = $this->w + $x;
  6156. }
  6157. function SetY($y)
  6158. {
  6159. //Set y position and reset x
  6160. $this->x=$this->lMargin;
  6161. if($y>=0)
  6162. $this->y=$y;
  6163. else
  6164. $this->y=$this->h+$y;
  6165. }
  6166. function SetXY($x,$y)
  6167. {
  6168. //Set x and y positions
  6169. $this->SetY($y);
  6170. $this->SetX($x);
  6171. }
  6172. function Output($name='',$dest='')
  6173. {
  6174. //Output PDF to some destination
  6175. if ($this->showStats) {
  6176. echo '<div>Generated in '.sprintf('%.2F',(microtime(true) - $this->time0)).' seconds</div>';
  6177. }
  6178. //Finish document if necessary
  6179. if ($this->progressBar) { $this->UpdateProgressBar(1,'100','Finished'); } // *PROGRESS-BAR*
  6180. if($this->state < 3) $this->Close();
  6181. if ($this->progressBar) { $this->UpdateProgressBar(2,'100','Finished'); } // *PROGRESS-BAR*
  6182. // fn. error_get_last is only in PHP>=5.2
  6183. if ($this->debug && function_exists('error_get_last') && error_get_last()) {
  6184. $e = error_get_last();
  6185. if (($e['type'] < 2048 && $e['type'] != 8) || (intval($e['type']) & intval(ini_get("error_reporting")))) {
  6186. echo "<p>Error message detected - PDF file generation aborted.</p>";
  6187. echo $e['message'].'<br />';
  6188. echo 'File: '.$e['file'].'<br />';
  6189. echo 'Line: '.$e['line'].'<br />';
  6190. exit;
  6191. }
  6192. }
  6193. if (($this->PDFA || $this->PDFX) && $this->encrypted) { $this->Error("PDFA1-b or PDFX/1-a does not permit encryption of documents."); }
  6194. if (count($this->PDFAXwarnings) && (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto))) {
  6195. if ($this->PDFA) {
  6196. echo '<div>WARNING - This file could not be generated as it stands as a PDFA1-b compliant file.</div>';
  6197. echo '<div>These issues can be automatically fixed by mPDF using <i>$mpdf-&gt;PDFAauto=true;</i></div>';
  6198. echo '<div>Action that mPDF will take to automatically force PDFA1-b compliance are shown in brackets.</div>';
  6199. }
  6200. else {
  6201. echo '<div>WARNING - This file could not be generated as it stands as a PDFX/1-a compliant file.</div>';
  6202. echo '<div>These issues can be automatically fixed by mPDF using <i>$mpdf-&gt;PDFXauto=true;</i></div>';
  6203. echo '<div>Action that mPDF will take to automatically force PDFX/1-a compliance are shown in brackets.</div>';
  6204. }
  6205. echo '<div>Warning(s) generated:</div><ul>';
  6206. $this->PDFAXwarnings = array_unique($this->PDFAXwarnings);
  6207. foreach($this->PDFAXwarnings AS $w) {
  6208. echo '<li>'.$w.'</li>';
  6209. }
  6210. echo '</ul>';
  6211. exit;
  6212. }
  6213. if ($this->showStats) {
  6214. echo '<div>Compiled in '.sprintf('%.2F',(microtime(true) - $this->time0)).' seconds (total)</div>';
  6215. echo '<div>Peak Memory usage '.number_format((memory_get_peak_usage(true)/(1024*1024)),2).' MB</div>';
  6216. echo '<div>PDF file size '.number_format((strlen($this->buffer)/1024)).' kB</div>';
  6217. echo '<div>Number of fonts '.count($this->fonts).'</div>';
  6218. exit;
  6219. }
  6220. if(is_bool($dest)) $dest=$dest ? 'D' : 'F';
  6221. $dest=strtoupper($dest);
  6222. if($dest=='') {
  6223. if($name=='') {
  6224. $name='mpdf.pdf';
  6225. $dest='I';
  6226. }
  6227. else { $dest='F'; }
  6228. }
  6229. /*-- PROGRESS-BAR --*/
  6230. if ($this->progressBar && ($dest=='D' || $dest=='I')) {
  6231. if($name=='') { $name='mpdf.pdf'; }
  6232. $tempfile = '_tempPDF'.RAND(1,10000);
  6233. //Save to local file
  6234. $f=fopen(_MPDF_TEMP_PATH.$tempfile.'.pdf','wb');
  6235. if(!$f) $this->Error('Unable to create temporary output file: '.$tempfile.'.pdf');
  6236. fwrite($f,$this->buffer,strlen($this->buffer));
  6237. fclose($f);
  6238. $this->UpdateProgressBar(3,'','Finished');
  6239. echo '<script type="text/javascript">
  6240. var form = document.createElement("form");
  6241. form.setAttribute("method", "post");
  6242. form.setAttribute("action", "'._MPDF_URI.'includes/out.php");
  6243. var hiddenField = document.createElement("input");
  6244. hiddenField.setAttribute("type", "hidden");
  6245. hiddenField.setAttribute("name", "filename");
  6246. hiddenField.setAttribute("value", "'.$tempfile.'");
  6247. form.appendChild(hiddenField);
  6248. var hiddenField = document.createElement("input");
  6249. hiddenField.setAttribute("type", "hidden");
  6250. hiddenField.setAttribute("name", "dest");
  6251. hiddenField.setAttribute("value", "'.$dest.'");
  6252. form.appendChild(hiddenField);
  6253. var hiddenField = document.createElement("input");
  6254. hiddenField.setAttribute("type", "hidden");
  6255. hiddenField.setAttribute("name", "opname");
  6256. hiddenField.setAttribute("value", "'.$name.'");
  6257. form.appendChild(hiddenField);
  6258. var hiddenField = document.createElement("input");
  6259. hiddenField.setAttribute("type", "hidden");
  6260. hiddenField.setAttribute("name", "path");
  6261. hiddenField.setAttribute("value", "'.urlencode(_MPDF_TEMP_PATH).'");
  6262. form.appendChild(hiddenField);
  6263. document.body.appendChild(form);
  6264. form.submit();
  6265. </script>
  6266. </div>
  6267. </body>
  6268. </html>';
  6269. exit;
  6270. }
  6271. else {
  6272. if ($this->progressBar) { $this->UpdateProgressBar(3,'','Finished'); }
  6273. /*-- END PROGRESS-BAR --*/
  6274. switch($dest) {
  6275. case 'I':
  6276. if ($this->debug && !$this->allow_output_buffering && ob_get_contents()) { echo "<p>Output has already been sent from the script - PDF file generation aborted.</p>"; exit; }
  6277. //Send to standard output
  6278. if(PHP_SAPI!='cli') {
  6279. //We send to a browser
  6280. header('Content-Type: application/pdf');
  6281. if(headers_sent())
  6282. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  6283. if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
  6284. // don't use length if server using compression
  6285. header('Content-Length: '.strlen($this->buffer));
  6286. }
  6287. header('Content-disposition: inline; filename="'.$name.'"');
  6288. header('Cache-Control: public, must-revalidate, max-age=0');
  6289. header('Pragma: public');
  6290. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
  6291. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  6292. }
  6293. echo $this->buffer;
  6294. break;
  6295. case 'D':
  6296. //Download file
  6297. header('Content-Description: File Transfer');
  6298. if (headers_sent())
  6299. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  6300. header('Content-Transfer-Encoding: binary');
  6301. header('Cache-Control: public, must-revalidate, max-age=0');
  6302. header('Pragma: public');
  6303. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
  6304. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  6305. header('Content-Type: application/force-download');
  6306. header('Content-Type: application/octet-stream', false);
  6307. header('Content-Type: application/download', false);
  6308. header('Content-Type: application/pdf', false);
  6309. if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
  6310. // don't use length if server using compression
  6311. header('Content-Length: '.strlen($this->buffer));
  6312. }
  6313. header('Content-disposition: attachment; filename="'.$name.'"');
  6314. echo $this->buffer;
  6315. break;
  6316. case 'F':
  6317. //Save to local file
  6318. $f=fopen($name,'wb');
  6319. if(!$f) $this->Error('Unable to create output file: '.$name);
  6320. fwrite($f,$this->buffer,strlen($this->buffer));
  6321. fclose($f);
  6322. break;
  6323. case 'S':
  6324. //Return as a string
  6325. return $this->buffer;
  6326. default:
  6327. $this->Error('Incorrect output destination: '.$dest);
  6328. }
  6329. } // *PROGRESS-BAR*
  6330. //======================================================================================================
  6331. // mPDF 5.3.79
  6332. // DELETE OLD TMP FILES - Housekeeping
  6333. // Delete any files in tmp/ directory that are >1 hrs old
  6334. $interval = 3600;
  6335. if ($handle = opendir(preg_replace('/\/$/','',_MPDF_TEMP_PATH))) {
  6336. while (false !== ($file = readdir($handle))) {
  6337. if (((filemtime(_MPDF_TEMP_PATH.$file)+$interval) < time()) && ($file != "..") && ($file != ".")) {
  6338. unlink(_MPDF_TEMP_PATH.$file);
  6339. }
  6340. }
  6341. closedir($handle);
  6342. }
  6343. //==============================================================================================================
  6344. return '';
  6345. }
  6346. // *****************************************************************************
  6347. // *
  6348. // Protected methods *
  6349. // *
  6350. // *****************************************************************************
  6351. function _dochecks()
  6352. {
  6353. //Check for locale-related bug
  6354. if(1.1==1)
  6355. $this->Error('Don\'t alter the locale before including mPDF');
  6356. //Check for decimal separator
  6357. if(sprintf('%.1f',1.0)!='1.0')
  6358. setlocale(LC_NUMERIC,'C');
  6359. }
  6360. function _begindoc()
  6361. {
  6362. //Start document
  6363. $this->state=1;
  6364. $this->_out('%PDF-'.$this->pdf_version);
  6365. $this->_out('%'.chr(226).chr(227).chr(207).chr(211)); // 4 chars > 128 to show binary file
  6366. }
  6367. /*-- HTMLHEADERS-FOOTERS --*/
  6368. function _puthtmlheaders() {
  6369. $this->state=2;
  6370. $nb=$this->page;
  6371. for($n=1;$n<=$nb;$n++) {
  6372. if ($this->mirrorMargins && $n%2==0) { $OE = 'E'; } // EVEN
  6373. else { $OE = 'O'; }
  6374. $this->page = $n;
  6375. if (isset($this->saveHTMLHeader[$n][$OE])) {
  6376. $html = $this->saveHTMLHeader[$n][$OE]['html'];
  6377. $this->lMargin = $this->saveHTMLHeader[$n][$OE]['ml'];
  6378. $this->rMargin = $this->saveHTMLHeader[$n][$OE]['mr'];
  6379. $this->tMargin = $this->saveHTMLHeader[$n][$OE]['mh'];
  6380. $this->bMargin = $this->saveHTMLHeader[$n][$OE]['mf'];
  6381. $this->margin_header = $this->saveHTMLHeader[$n][$OE]['mh'];
  6382. $this->margin_footer = $this->saveHTMLHeader[$n][$OE]['mf'];
  6383. $this->w = $this->saveHTMLHeader[$n][$OE]['pw'];
  6384. $this->h = $this->saveHTMLHeader[$n][$OE]['ph'];
  6385. $rotate = (isset($this->saveHTMLHeader[$n][$OE]['rotate']) ? $this->saveHTMLHeader[$n][$OE]['rotate'] : null);
  6386. $this->Reset();
  6387. $this->pageoutput[$n] = array();
  6388. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  6389. $this->x = $this->lMargin;
  6390. $this->y = $this->margin_header;
  6391. $html = str_replace('{PAGENO}',$this->pagenumPrefix.$this->docPageNum($n).$this->pagenumSuffix,$html);
  6392. $html = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->docPageNumTotal($n).$this->nbpgSuffix,$html ); // {nbpg}
  6393. $html = str_replace($this->aliasNbPg,$nb,$html ); // {nb}
  6394. $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );
  6395. $this->HTMLheaderPageLinks = array();
  6396. $this->HTMLheaderPageAnnots = array();
  6397. $this->HTMLheaderPageForms = array();
  6398. $this->pageBackgrounds = array();
  6399. $this->writingHTMLheader = true;
  6400. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  6401. $this->writingHTMLheader = false;
  6402. $this->Reset();
  6403. $this->pageoutput[$n] = array();
  6404. $s = $this->PrintPageBackgrounds();
  6405. $this->headerbuffer = $s . $this->headerbuffer;
  6406. $os = '';
  6407. if ($rotate) {
  6408. $os .= sprintf('q 0 -1 1 0 0 %.3F cm ',($this->w*_MPDFK));
  6409. }
  6410. $os .= $this->headerbuffer ;
  6411. if ($rotate) {
  6412. $os .= ' Q' . "\n";
  6413. }
  6414. // Writes over the page background but behind any other output on page
  6415. $os = preg_replace('/\\\\/','\\\\\\\\',$os);
  6416. $this->pages[$n] = preg_replace('/(___HEADER___MARKER'.date('jY').')/', "\n".$os."\n".'\\1', $this->pages[$n]);
  6417. $lks = $this->HTMLheaderPageLinks;
  6418. foreach($lks AS $lk) {
  6419. if ($rotate) {
  6420. $lw = $lk[2];
  6421. $lh = $lk[3];
  6422. $lk[2] = $lh;
  6423. $lk[3] = $lw; // swap width and height
  6424. $ax = $lk[0]/_MPDFK;
  6425. $ay = $lk[1]/_MPDFK;
  6426. $bx = $ay-($lh/_MPDFK);
  6427. $by = $this->w-$ax;
  6428. $lk[0] = $bx*_MPDFK;
  6429. $lk[1] = ($this->h-$by)*_MPDFK - $lw;
  6430. }
  6431. $this->PageLinks[$n][]=$lk;
  6432. }
  6433. /*-- FORMS --*/
  6434. foreach($this->HTMLheaderPageForms AS $f) {
  6435. $this->form->forms[$f['n']] = $f;
  6436. }
  6437. /*-- END FORMS --*/
  6438. }
  6439. if (isset($this->saveHTMLFooter[$n][$OE])) {
  6440. $html = $this->saveHTMLFooter[$this->page][$OE]['html'];
  6441. $this->lMargin = $this->saveHTMLFooter[$n][$OE]['ml'];
  6442. $this->rMargin = $this->saveHTMLFooter[$n][$OE]['mr'];
  6443. $this->tMargin = $this->saveHTMLFooter[$n][$OE]['mh'];
  6444. $this->bMargin = $this->saveHTMLFooter[$n][$OE]['mf'];
  6445. $this->margin_header = $this->saveHTMLFooter[$n][$OE]['mh'];
  6446. $this->margin_footer = $this->saveHTMLFooter[$n][$OE]['mf'];
  6447. $this->w = $this->saveHTMLFooter[$n][$OE]['pw'];
  6448. $this->h = $this->saveHTMLFooter[$n][$OE]['ph'];
  6449. $rotate = (isset($this->saveHTMLFooter[$n][$OE]['rotate']) ? $this->saveHTMLFooter[$n][$OE]['rotate'] : null);
  6450. $this->Reset();
  6451. $this->pageoutput[$n] = array();
  6452. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  6453. $this->x = $this->lMargin;
  6454. $top_y = $this->y = $this->h - $this->margin_footer;
  6455. // if bottom-margin==0, corrects to avoid division by zero
  6456. if ($this->y == $this->h) { $top_y = $this->y = ($this->h - 0.1); }
  6457. $html = str_replace('{PAGENO}',$this->pagenumPrefix.$this->docPageNum($n).$this->pagenumSuffix,$html);
  6458. $html = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->docPageNumTotal($n).$this->nbpgSuffix,$html ); // {nbpg}
  6459. $html = str_replace($this->aliasNbPg,$nb,$html ); // {nb}
  6460. $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );
  6461. $this->HTMLheaderPageLinks = array();
  6462. $this->HTMLheaderPageAnnots = array();
  6463. $this->HTMLheaderPageForms = array();
  6464. $this->pageBackgrounds = array();
  6465. $this->writingHTMLfooter = true;
  6466. $this->InFooter = true;
  6467. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  6468. $this->writingHTMLfooter = false;
  6469. $this->InFooter = false;
  6470. $this->Reset();
  6471. $this->pageoutput[$n] = array();
  6472. $fheight = $this->y - $top_y;
  6473. $adj = -$fheight;
  6474. $s = $this->PrintPageBackgrounds(-$adj);
  6475. $this->headerbuffer = $s . $this->headerbuffer;
  6476. $os = '';
  6477. $os .= $this->StartTransform(true)."\n";
  6478. if ($rotate) {
  6479. $os .= sprintf('q 0 -1 1 0 0 %.3F cm ',($this->w*_MPDFK));
  6480. }
  6481. $os .= $this->transformTranslate(0, $adj, true)."\n";
  6482. $os .= $this->headerbuffer ;
  6483. if ($rotate) {
  6484. $os .= ' Q' . "\n";
  6485. }
  6486. $os .= $this->StopTransform(true)."\n";
  6487. // Writes over the page background but behind any other output on page
  6488. $os = preg_replace('/\\\\/','\\\\\\\\',$os);
  6489. $this->pages[$n] = preg_replace('/(___HEADER___MARKER'.date('jY').')/', "\n".$os."\n".'\\1', $this->pages[$n]);
  6490. $lks = $this->HTMLheaderPageLinks;
  6491. foreach($lks AS $lk) {
  6492. $lk[1] -= $adj*_MPDFK;
  6493. if ($rotate) {
  6494. $lw = $lk[2];
  6495. $lh = $lk[3];
  6496. $lk[2] = $lh;
  6497. $lk[3] = $lw; // swap width and height
  6498. $ax = $lk[0]/_MPDFK;
  6499. $ay = $lk[1]/_MPDFK;
  6500. $bx = $ay-($lh/_MPDFK);
  6501. $by = $this->w-$ax;
  6502. $lk[0] = $bx*_MPDFK;
  6503. $lk[1] = ($this->h-$by)*_MPDFK - $lw;
  6504. }
  6505. $this->PageLinks[$n][]=$lk;
  6506. }
  6507. /*-- FORMS --*/
  6508. foreach($this->HTMLheaderPageForms AS $f) {
  6509. $f['y'] += $adj;
  6510. $this->form->forms[$f['n']] = $f;
  6511. }
  6512. /*-- END FORMS --*/
  6513. }
  6514. }
  6515. $this->page=$nb;
  6516. $this->state=1;
  6517. }
  6518. /*-- END HTMLHEADERS-FOOTERS --*/
  6519. function _putpages()
  6520. {
  6521. $nb=$this->page;
  6522. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  6523. if($this->DefOrientation=='P') {
  6524. $defwPt=$this->fwPt;
  6525. $defhPt=$this->fhPt;
  6526. }
  6527. else {
  6528. $defwPt=$this->fhPt;
  6529. $defhPt=$this->fwPt;
  6530. }
  6531. $annotid=(3+2*$nb);
  6532. // Active Forms
  6533. $totaladdnum = 0;
  6534. for($n=1;$n<=$nb;$n++) {
  6535. if (isset($this->PageLinks[$n])) { $totaladdnum += count($this->PageLinks[$n]); }
  6536. /*-- ANNOTATIONS --*/
  6537. if (isset($this->PageAnnots[$n])) {
  6538. foreach ($this->PageAnnots[$n] as $k => $pl) {
  6539. if (!empty($pl['opt']['popup']) || !empty($pl['opt']['file'])) { $totaladdnum += 2 ; }
  6540. else { $totaladdnum++; }
  6541. }
  6542. }
  6543. /*-- END ANNOTATIONS --*/
  6544. /*-- FORMS --*/
  6545. if ( count($this->form->forms) > 0 ) {
  6546. $this->form->countPageForms($n, $totaladdnum);
  6547. }
  6548. /*-- END FORMS --*/
  6549. }
  6550. /*-- FORMS --*/
  6551. // Make a note in the radio button group of the obj_id it will have
  6552. $ctr = 0;
  6553. if (count($this->form->form_radio_groups)) {
  6554. foreach($this->form->form_radio_groups AS $name=>$frg) {
  6555. $this->form->form_radio_groups[$name]['obj_id'] = $annotid + $totaladdnum + $ctr;
  6556. $ctr++;
  6557. }
  6558. }
  6559. /*-- END FORMS --*/
  6560. // mPDF 5.3.99
  6561. // Select unused fonts (usually default font)
  6562. $unused = array();
  6563. foreach($this->fonts as $fk=>$font) {
  6564. if (!$font['used'] && ($font['type']=='TTF')) {
  6565. $unused[] = $fk;
  6566. }
  6567. }
  6568. for($n=1;$n<=$nb;$n++)
  6569. {
  6570. $thispage = $this->pages[$n]; // mPDF 5.3.99
  6571. unset($this->pages[$n]); // mPDF 5.3.99
  6572. if(isset($this->OrientationChanges[$n])) {
  6573. $hPt=$this->pageDim[$n]['w']*_MPDFK;
  6574. $wPt=$this->pageDim[$n]['h']*_MPDFK;
  6575. $owidthPt_LR = $this->pageDim[$n]['outer_width_TB']*_MPDFK;
  6576. $owidthPt_TB = $this->pageDim[$n]['outer_width_LR']*_MPDFK;
  6577. }
  6578. else {
  6579. $wPt=$this->pageDim[$n]['w']*_MPDFK;
  6580. $hPt=$this->pageDim[$n]['h']*_MPDFK;
  6581. $owidthPt_LR = $this->pageDim[$n]['outer_width_LR']*_MPDFK;
  6582. $owidthPt_TB = $this->pageDim[$n]['outer_width_TB']*_MPDFK;
  6583. }
  6584. // mPDF 5.3.99
  6585. // Remove references to unused fonts (usually default font)
  6586. foreach($unused as $fk) {
  6587. if ($this->fonts[$fk]['sip'] || $this->fonts[$fk]['smp']) {
  6588. foreach($this->fonts[$fk]['subsetfontids'] AS $k => $fid) {
  6589. $thispage = preg_replace('/\s\/F'.$fid.' \d[\d.]* Tf\s/is',' ',$thispage);
  6590. }
  6591. }
  6592. else {
  6593. $thispage = preg_replace('/\s\/F'.$this->fonts[$fk]['i'].' \d[\d.]* Tf\s/is',' ',$thispage);
  6594. }
  6595. }
  6596. //Replace number of pages
  6597. if(!empty($this->aliasNbPg)) {
  6598. if (!$this->onlyCoreFonts) { $s1 = $this->UTF8ToUTF16BE($this->aliasNbPg, false); } // mPDF 5.3.22
  6599. $s2 = $this->aliasNbPg;
  6600. if (!$this->onlyCoreFonts) { $r1 = $this->UTF8ToUTF16BE($nb, false); } // mPDF 5.3.22
  6601. $r2 = $nb;
  6602. if (preg_match_all('/{mpdfheadernbpg (C|R) ff=(\S*) fs=(\S*) fz=(.*?)}/',$thispage,$m)) {
  6603. for($hi=0;$hi<count($m[0]);$hi++) {
  6604. $pos = $m[1][$hi];
  6605. $hff = $m[2][$hi];
  6606. $hfst = $m[3][$hi];
  6607. $hfsz = $m[4][$hi];
  6608. $this->SetFont($hff,$hfst,$hfsz, false);
  6609. $x1 = $this->GetStringWidth($this->aliasNbPg);
  6610. $x2 = $this->GetStringWidth($nb);
  6611. $xadj = $x1 - $x2;
  6612. if ($pos=='C') { $xadj /= 2; }
  6613. $rep = sprintf(' q 1 0 0 1 %.3F 0 cm ', $xadj*_MPDFK);
  6614. $thispage = str_replace($m[0][$hi], $rep, $thispage);
  6615. }
  6616. }
  6617. if (!$this->onlyCoreFonts) { $thispage=str_replace($s1,$r1,$thispage); } // mPDF 5.3.22
  6618. $thispage=str_replace($s2,$r2,$thispage); // mPDF 5.3.22
  6619. // And now for any SMP/SIP fonts subset using <HH> format
  6620. $r = '';
  6621. $nstr = "$nb";
  6622. for($i=0;$i<strlen($nstr);$i++) {
  6623. $r .= sprintf("%02s", strtoupper(dechex(intval($nstr[$i])+48)));
  6624. }
  6625. $thispage=str_replace($this->aliasNbPgHex,$r,$thispage);
  6626. }
  6627. //Replace number of pages in group
  6628. if(!empty($this->aliasNbPgGp)) {
  6629. if (!$this->onlyCoreFonts) { $s1 = $this->UTF8ToUTF16BE($this->aliasNbPgGp, false); } // mPDF 5.3.22
  6630. $s2 = $this->aliasNbPgGp;
  6631. $nbt = $this->docPageNumTotal($n);
  6632. if (!$this->onlyCoreFonts) { $r1 = $this->UTF8ToUTF16BE($nbt, false); } // mPDF 5.3.22
  6633. $r2 = $nbt;
  6634. if (preg_match_all('/{mpdfheadernbpggp (C|R) ff=(\S*) fs=(\S*) fz=(.*?)}/',$thispage,$m)) {
  6635. for($hi=0;$hi<count($m[0]);$hi++) {
  6636. $pos = $m[1][$hi];
  6637. $hff = $m[2][$hi];
  6638. $hfst = $m[3][$hi];
  6639. $hfsz = $m[4][$hi];
  6640. $this->SetFont($hff,$hfst,$hfsz, false);
  6641. $x1 = $this->GetStringWidth($this->aliasNbPgGp);
  6642. $x2 = $this->GetStringWidth($nbt);
  6643. $xadj = $x1 - $x2;
  6644. if ($pos=='C') { $xadj /= 2; }
  6645. $rep = sprintf(' q 1 0 0 1 %.3F 0 cm ', $xadj*_MPDFK);
  6646. $thispage = str_replace($m[0][$hi], $rep, $thispage);
  6647. }
  6648. }
  6649. if (!$this->onlyCoreFonts) { $thispage=str_replace($s1,$r1,$thispage); } // mPDF 5.3.22
  6650. $thispage=str_replace($s2,$r2,$thispage);
  6651. // And now for any SMP/SIP fonts subset using <HH> format
  6652. $r = '';
  6653. $nstr = "$nbt";
  6654. for($i=0;$i<strlen($nstr);$i++) {
  6655. $r .= sprintf("%02s", strtoupper(dechex(intval($nstr[$i])+48)));
  6656. }
  6657. $thispage=str_replace($this->aliasNbPgGpHex,$r,$thispage);
  6658. }
  6659. $thispage = preg_replace('/(\s*___BACKGROUND___PATTERNS'.date('jY').'\s*)/', " ", $thispage);
  6660. $thispage = preg_replace('/(\s*___HEADER___MARKER'.date('jY').'\s*)/', " ", $thispage);
  6661. $thispage = preg_replace('/(\s*___PAGE___START'.date('jY').'\s*)/', " ", $thispage);
  6662. $thispage = preg_replace('/(\s*___TABLE___BACKGROUNDS'.date('jY').'\s*)/', " ", $thispage);
  6663. //Page
  6664. $this->_newobj();
  6665. $this->_out('<</Type /Page');
  6666. $this->_out('/Parent 1 0 R');
  6667. if(isset($this->OrientationChanges[$n])) {
  6668. $this->_out(sprintf('/MediaBox [0 0 %.3F %.3F]',$hPt,$wPt));
  6669. //If BleedBox is defined, it must be larger than the TrimBox, but smaller than the MediaBox
  6670. $bleedMargin = $this->pageDim[$n]['bleedMargin']*_MPDFK;
  6671. if ($bleedMargin && ($owidthPt_TB || $owidthPt_LR)) {
  6672. $x0 = $owidthPt_TB-$bleedMargin;
  6673. $y0 = $owidthPt_LR-$bleedMargin;
  6674. $x1 = $hPt-$owidthPt_TB+$bleedMargin;
  6675. $y1 = $wPt-$owidthPt_LR+$bleedMargin;
  6676. $this->_out(sprintf('/BleedBox [%.3F %.3F %.3F %.3F]', $x0, $y0, $x1, $y1));
  6677. }
  6678. $this->_out(sprintf('/TrimBox [%.3F %.3F %.3F %.3F]', $owidthPt_TB, $owidthPt_LR, ($hPt-$owidthPt_TB), ($wPt-$owidthPt_LR)));
  6679. if (isset($this->OrientationChanges[$n]) && $this->displayDefaultOrientation) {
  6680. if ($this->DefOrientation=='P') { $this->_out('/Rotate 270'); }
  6681. else { $this->_out('/Rotate 90'); }
  6682. }
  6683. }
  6684. //else if($wPt != $defwPt || $hPt != $defhPt) {
  6685. else {
  6686. $this->_out(sprintf('/MediaBox [0 0 %.3F %.3F]',$wPt,$hPt));
  6687. $bleedMargin = $this->pageDim[$n]['bleedMargin']*_MPDFK;
  6688. if ($bleedMargin && ($owidthPt_TB || $owidthPt_LR)) {
  6689. $x0 = $owidthPt_LR-$bleedMargin;
  6690. $y0 = $owidthPt_TB-$bleedMargin;
  6691. $x1 = $wPt-$owidthPt_LR+$bleedMargin;
  6692. $y1 = $hPt-$owidthPt_TB+$bleedMargin;
  6693. $this->_out(sprintf('/BleedBox [%.3F %.3F %.3F %.3F]', $x0, $y0, $x1, $y1));
  6694. }
  6695. $this->_out(sprintf('/TrimBox [%.3F %.3F %.3F %.3F]', $owidthPt_LR, $owidthPt_TB, ($wPt-$owidthPt_LR), ($hPt-$owidthPt_TB)));
  6696. }
  6697. $this->_out('/Resources 2 0 R');
  6698. // Important to keep in RGB colorSpace when using transparency
  6699. if (!$this->PDFA && !$this->PDFX) {
  6700. if ($this->restrictColorSpace == 3)
  6701. $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceCMYK >> ');
  6702. else if ($this->restrictColorSpace == 1)
  6703. $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceGray >> ');
  6704. else
  6705. $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceRGB >> ');
  6706. }
  6707. $annotsnum = 0;
  6708. if (isset($this->PageLinks[$n])) { $annotsnum += count($this->PageLinks[$n]); }
  6709. /*-- ANNOTATIONS --*/
  6710. if (isset($this->PageAnnots[$n])) {
  6711. foreach ($this->PageAnnots[$n] as $k => $pl) {
  6712. if (!empty($pl['opt']['popup']) || !empty($pl['opt']['file'])) { $annotsnum += 2 ; }
  6713. else { $annotsnum++; }
  6714. $this->PageAnnots[$n][$k]['pageobj'] = $this->n;
  6715. }
  6716. }
  6717. /*-- END ANNOTATIONS --*/
  6718. /*-- FORMS --*/
  6719. // Active Forms
  6720. $formsnum = 0;
  6721. if ( count($this->form->forms) > 0 ) {
  6722. foreach( $this->form->forms as $val ) {
  6723. if ( $val['page'] == $n )
  6724. $formsnum++;
  6725. }
  6726. }
  6727. /*-- END FORMS --*/
  6728. if ($annotsnum || $formsnum) {
  6729. $s = '/Annots [ ';
  6730. for($i=0;$i<$annotsnum;$i++) {
  6731. $s .= ($annotid + $i) . ' 0 R ';
  6732. }
  6733. $annotid += $annotsnum;
  6734. /*-- FORMS --*/
  6735. if ( count($this->form->forms) > 0 ) {
  6736. $this->form->addFormIds($n, $s, $annotid);
  6737. }
  6738. /*-- END FORMS --*/
  6739. $s .= '] ';
  6740. $this->_out($s);
  6741. }
  6742. $this->_out('/Contents '.($this->n+1).' 0 R>>');
  6743. $this->_out('endobj');
  6744. //Page content
  6745. $this->_newobj();
  6746. $p=($this->compress) ? gzcompress($thispage) : $thispage;
  6747. $this->_out('<<'.$filter.'/Length '.strlen($p).'>>');
  6748. $this->_putstream($p);
  6749. $this->_out('endobj');
  6750. }
  6751. $this->_putannots($n);
  6752. //Pages root
  6753. $this->offsets[1]=strlen($this->buffer);
  6754. $this->_out('1 0 obj');
  6755. $this->_out('<</Type /Pages');
  6756. $kids='/Kids [';
  6757. for($i=0;$i<$nb;$i++)
  6758. $kids.=(3+2*$i).' 0 R ';
  6759. $this->_out($kids.']');
  6760. $this->_out('/Count '.$nb);
  6761. $this->_out(sprintf('/MediaBox [0 0 %.3F %.3F]',$defwPt,$defhPt));
  6762. $this->_out('>>');
  6763. $this->_out('endobj');
  6764. }
  6765. function _putannots($n) {
  6766. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  6767. $nb=$this->page;
  6768. for($n=1;$n<=$nb;$n++)
  6769. {
  6770. $annotobjs = array();
  6771. if(isset($this->PageLinks[$n]) || isset($this->PageAnnots[$n]) || count($this->form->forms) > 0 ) {
  6772. $wPt=$this->pageDim[$n]['w']*_MPDFK;
  6773. $hPt=$this->pageDim[$n]['h']*_MPDFK;
  6774. //Links
  6775. if(isset($this->PageLinks[$n])) {
  6776. foreach($this->PageLinks[$n] as $key => $pl) {
  6777. $this->_newobj();
  6778. $annot='';
  6779. $rect=sprintf('%.3F %.3F %.3F %.3F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
  6780. $annot .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.']';
  6781. $annot .= ' /Contents '.$this->_UTF16BEtextstring($pl[4]);
  6782. $annot .= ' /NM '.$this->_textstring(sprintf('%04u-%04u', $n, $key));
  6783. $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis'));
  6784. $annot .= ' /Border [0 0 0]';
  6785. // mPDF 5.3.16 5.3.52 Use this (instead of /Border) to specify border around link
  6786. // $annot .= ' /BS <</W 1'; // Width on points; 0 = no line
  6787. // $annot .= ' /S /D'; // style - [S]olid, [D]ashed, [B]eveled, [I]nset, [U]nderline
  6788. // $annot .= ' /D [3 2]'; // Dash array - if dashed
  6789. // $annot .= ' >>';
  6790. // $annot .= ' /C [1 0 0]'; // Color RGB
  6791. if ($this->PDFA || $this->PDFX) { $annot .= ' /F 28'; }
  6792. if (strpos($pl[4],'@')===0) {
  6793. $p=substr($pl[4],1);
  6794. // $h=isset($this->OrientationChanges[$p]) ? $wPt : $hPt;
  6795. $htarg=$this->pageDim[$p]['h']*_MPDFK;
  6796. $annot.=sprintf(' /Dest [%d 0 R /XYZ 0 %.3F null]>>',1+2*$p,$htarg);
  6797. }
  6798. else if(is_string($pl[4])) {
  6799. $annot .= ' /A <</S /URI /URI '.$this->_textstring($pl[4]).'>> >>';
  6800. }
  6801. else {
  6802. $l=$this->links[$pl[4]];
  6803. // may not be set if #link points to non-existent target
  6804. if (isset($this->pageDim[$l[0]]['h'])) { $htarg=$this->pageDim[$l[0]]['h']*_MPDFK; }
  6805. else { $htarg=$this->h*_MPDFK; } // doesn't really matter
  6806. $annot.=sprintf(' /Dest [%d 0 R /XYZ 0 %.3F null]>>',1+2*$l[0],$htarg-$l[1]*_MPDFK);
  6807. }
  6808. $this->_out($annot);
  6809. $this->_out('endobj');
  6810. }
  6811. }
  6812. /*-- ANNOTATIONS --*/
  6813. if(isset($this->PageAnnots[$n])) {
  6814. foreach ($this->PageAnnots[$n] as $key => $pl) {
  6815. if ($pl['opt']['file']) { $FileAttachment=true; }
  6816. else { $FileAttachment=false; }
  6817. $this->_newobj();
  6818. $annot='';
  6819. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  6820. $x = $pl['x'];
  6821. if ($this->annotMargin <> 0 || $x==0 || $x<0) { // Odd page
  6822. $x = ($wPt/_MPDFK) - $this->annotMargin;
  6823. }
  6824. $w = $h = 0;
  6825. $a = $x * _MPDFK;
  6826. $b = $hPt - ($pl['y'] * _MPDFK);
  6827. $annot .= '<</Type /Annot ';
  6828. if ($FileAttachment) {
  6829. $annot .= '/Subtype /FileAttachment';
  6830. // Need to set a size for FileAttachment icons
  6831. if ($pl['opt']['icon']=='Paperclip') { $w=8.235; $h=20; } // 7,17
  6832. else if ($pl['opt']['icon']=='Tag') { $w=20; $h=16; }
  6833. else if ($pl['opt']['icon']=='Graph') { $w=20; $h=20; }
  6834. else { $w=14; $h=20; } // PushPin
  6835. $f = $pl['opt']['file'];
  6836. $f = preg_replace('/^.*\//', '', $f);
  6837. $f = preg_replace('/[^a-zA-Z0-9._]/', '', $f);
  6838. $annot .= '/FS <</Type /Filespec /F ('.$f.')';
  6839. $annot .= '/EF <</F '.($this->n+1).' 0 R>>';
  6840. $annot .= '>>';
  6841. }
  6842. else {
  6843. $annot .= '/Subtype /Text';
  6844. }
  6845. $rect = sprintf('%.3F %.3F %.3F %.3F', $a, $b-$h, $a+$w, $b);
  6846. $annot .= '/Rect ['.$rect.']';
  6847. // contents = description of file in free text
  6848. $annot .= ' /Contents '.$this->_UTF16BEtextstring($pl['txt']);
  6849. $annot .= ' /NM '.$this->_textstring(sprintf('%04u-%04u', $n, (2000 + $key)));
  6850. $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis'));
  6851. $annot .= ' /CreationDate '.$this->_textstring('D:'.date('YmdHis'));
  6852. $annot .= ' /Border [0 0 0]';
  6853. if ($this->PDFA || $this->PDFX) {
  6854. $annot .= ' /F 28';
  6855. $annot .= ' /CA 1';
  6856. }
  6857. else if ($pl['opt']['ca']>0) { $annot .= ' /CA '.$pl['opt']['ca']; }
  6858. $annotcolor = ' /C [';
  6859. // mPDF 5.3.74
  6860. if (isset($pl['opt']['c']) AND $pl['opt']['c']) {
  6861. $col = $pl['opt']['c'];
  6862. if ($col{0}==3 || $col{0}==5) { $annotcolor .= sprintf("%.3F %.3F %.3F", ord($col{1})/255,ord($col{2})/255,ord($col{3})/255); }
  6863. else if ($col{0}==1) { $annotcolor .= sprintf("%.3F", ord($col{1})/255); }
  6864. else if ($col{0}==4 || $col{0}==6) { $annotcolor .= sprintf("%.3F %.3F %.3F %.3F", ord($col{1})/100,ord($col{2})/100,ord($col{3})/100,ord($col{4})/100); }
  6865. else { $annotcolor .= '1 1 0'; }
  6866. }
  6867. else { $annotcolor .= '1 1 0'; }
  6868. $annotcolor .= ']';
  6869. $annot .= $annotcolor;
  6870. // Usually Author
  6871. // Use as Title for fileattachment
  6872. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  6873. $annot .= ' /T '.$this->_UTF16BEtextstring($pl['opt']['t']);
  6874. }
  6875. if ($FileAttachment) {
  6876. $iconsapp = array('Paperclip', 'Graph', 'PushPin', 'Tag');
  6877. }
  6878. else { $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph'); }
  6879. if (isset($pl['opt']['icon']) AND in_array($pl['opt']['icon'], $iconsapp)) {
  6880. $annot .= ' /Name /'.$pl['opt']['icon'];
  6881. }
  6882. else if ($FileAttachment) { $annot .= ' /Name /PushPin'; }
  6883. else { $annot .= ' /Name /Note'; }
  6884. if (!$FileAttachment) {
  6885. // /Subj is PDF 1.5 spec.
  6886. if (isset($pl['opt']['subj']) && !$this->PDFA && !$this->PDFX) {
  6887. $annot .= ' /Subj '.$this->_UTF16BEtextstring($pl['opt']['subj']);
  6888. }
  6889. if (!empty($pl['opt']['popup'])) {
  6890. $annot .= ' /Open true';
  6891. $annot .= ' /Popup '.($this->n+1).' 0 R';
  6892. }
  6893. else { $annot .= ' /Open false'; }
  6894. }
  6895. $annot .= ' /P '.$pl['pageobj'].' 0 R';
  6896. $annot .= '>>';
  6897. $this->_out($annot);
  6898. $this->_out('endobj');
  6899. if ($FileAttachment) {
  6900. $file = @file_get_contents($pl['opt']['file']) or die('mPDF Error: Cannot access file attachment - '.$pl['opt']['file']);
  6901. $filestream = gzcompress($file);
  6902. $this->_newobj();
  6903. $this->_out('<</Type /EmbeddedFile');
  6904. $this->_out('/Length '.strlen($filestream));
  6905. $this->_out('/Filter /FlateDecode');
  6906. $this->_out('>>');
  6907. $this->_putstream($filestream);
  6908. $this->_out('endobj');
  6909. }
  6910. else if (!empty($pl['opt']['popup'])) {
  6911. $this->_newobj();
  6912. $annot='';
  6913. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][0])) { $x = $pl['opt']['popup'][0] * _MPDFK; }
  6914. else { $x = $pl['x'] * _MPDFK; }
  6915. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][1])) { $y = $hPt - ($pl['opt']['popup'][1] * _MPDFK); }
  6916. else { $y = $hPt - ($pl['y'] * _MPDFK); }
  6917. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][2])) { $w = $pl['opt']['popup'][2] * _MPDFK; }
  6918. else { $w = 180; }
  6919. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][3])) { $h = $pl['opt']['popup'][3] * _MPDFK; }
  6920. else { $h = 120; }
  6921. $rect = sprintf('%.3F %.3F %.3F %.3F', $x, $y-$h, $x+$w, $y);
  6922. $annot .= '<</Type /Annot /Subtype /Popup /Rect ['.$rect.']';
  6923. $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis'));
  6924. if ($this->PDFA || $this->PDFX) { $annot .= ' /F 28'; }
  6925. $annot .= ' /Parent '.($this->n-1).' 0 R';
  6926. $annot .= '>>';
  6927. $this->_out($annot);
  6928. $this->_out('endobj');
  6929. }
  6930. }
  6931. }
  6932. /*-- END ANNOTATIONS --*/
  6933. /*-- FORMS --*/
  6934. // Active Forms
  6935. if ( count($this->form->forms) > 0 ) {
  6936. $this->form->_putFormItems($n, $hPt);
  6937. }
  6938. /*-- END FORMS --*/
  6939. }
  6940. }
  6941. /*-- FORMS --*/
  6942. // Active Forms - Radio Button Group entries
  6943. // Output Radio Button Group form entries (radio_on_obj_id already determined)
  6944. if (count($this->form->form_radio_groups)) {
  6945. $this->form->_putRadioItems($n);
  6946. }
  6947. /*-- END FORMS --*/
  6948. }
  6949. /*-- ANNOTATIONS --*/
  6950. function Annotation($text, $x=0, $y=0, $icon='Note', $author='', $subject='', $opacity=0, $colarray=false, $popup='', $file='') {
  6951. // mPDF 5.3.94
  6952. if (is_array($colarray) && count($colarray)==3) { $colarray = $this->ConvertColor('rgb('.$colarray[0].','.$colarray[1].','.$colarray[2].')'); }
  6953. if ($colarray === false) { $colarray = $this->ConvertColor('yellow'); }
  6954. if ($x==0) { $x = $this->x; }
  6955. if ($y==0) { $y = $this->y; }
  6956. $page = $this->page;
  6957. if ($page < 1) { // Document has not been started - assume it's for first page
  6958. $page = 1;
  6959. if ($x==0) { $x = $this->lMargin; }
  6960. if ($y==0) { $y = $this->tMargin; }
  6961. }
  6962. if ($this->PDFA || $this->PDFX) {
  6963. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "Annotation markers cannot be semi-transparent in PDFA1-b or PDFX/1-a, so they may make underlying text unreadable. (Annotation markers moved to right margin)"; }
  6964. $x = ($this->w) - $this->rMargin*0.66;
  6965. }
  6966. if (!$this->annotMargin) { $y -= $this->FontSize / 2; }
  6967. if (!$opacity && $this->annotMargin) { $opacity = 1; }
  6968. else if (!$opacity) { $opacity = $this->annotOpacity; }
  6969. $an = array('txt' => $text, 'x' => $x, 'y' => $y, 'opt' => array('Icon'=>$icon, 'T'=>$author, 'Subj'=>$subject, 'C'=>$colarray, 'CA'=>$opacity, 'popup'=>$popup, 'file'=>$file));
  6970. if ($this->keep_block_together) { // Save to array - don't write yet
  6971. $this->ktAnnots[$this->page][]= $an;
  6972. return;
  6973. }
  6974. else if ($this->table_rotate) {
  6975. $this->tbrot_Annots[$this->page][]= $an;
  6976. return;
  6977. }
  6978. else if ($this->kwt) {
  6979. $this->kwt_Annots[$this->page][]= $an;
  6980. return;
  6981. }
  6982. // mPDF 5.0
  6983. if ($this->writingHTMLheader || $this->writingHTMLfooter) {
  6984. $this->HTMLheaderPageAnnots[]= $an;
  6985. return;
  6986. }
  6987. //Put an Annotation on the page
  6988. $this->PageAnnots[$page][] = $an;
  6989. /*-- COLUMNS --*/
  6990. // Save cross-reference to Column buffer
  6991. $ref = count($this->PageAnnots[$this->page])-1;
  6992. $this->columnAnnots[$this->CurrCol][INTVAL($this->x)][INTVAL($this->y)] = $ref;
  6993. /*-- END COLUMNS --*/
  6994. }
  6995. /*-- END ANNOTATIONS --*/
  6996. function _putfonts() {
  6997. $nf=$this->n;
  6998. $mqr=$this->_getMQR();
  6999. if ($mqr) { set_magic_quotes_runtime(0); }
  7000. foreach($this->FontFiles as $fontkey=>$info) {
  7001. // TrueType embedded
  7002. if (isset($info['type']) && $info['type']=='TTF' && !$info['sip'] && !$info['smp']) {
  7003. $used = true;
  7004. $asSubset = false;
  7005. foreach($this->fonts AS $k=>$f) {
  7006. if ($f['fontkey'] == $fontkey && $f['type']=='TTF') {
  7007. $used = $f['used'];
  7008. if ($used) {
  7009. $nChars = (ord($f['cw'][0]) << 8) + ord($f['cw'][1]);
  7010. $usage = intval(count($f['subset'])*100 / $nChars);
  7011. $fsize = $info['length1'];
  7012. // Always subset the very large TTF files
  7013. if ($fsize > ($this->maxTTFFilesize *1024)) { $asSubset = true; }
  7014. else if ($usage < $this->percentSubset) { $asSubset = true; }
  7015. }
  7016. if ($this->PDFA || $this->PDFX) $asSubset = false; // mPDF 5.3.45
  7017. $this->fonts[$k]['asSubset'] = $asSubset;
  7018. break;
  7019. }
  7020. }
  7021. if ($used && !$asSubset) {
  7022. //Font file embedding
  7023. $this->_newobj();
  7024. $this->FontFiles[$fontkey]['n']=$this->n;
  7025. $font='';
  7026. $originalsize = $info['length1'];
  7027. if ($this->repackageTTF || $this->fonts[$fontkey]['TTCfontID']>0) {
  7028. // First see if there is a cached compressed file
  7029. if (file_exists(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.z')) {
  7030. $f=fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.z','rb');
  7031. if(!$f) { $this->Error('Font file .ps.z not found'); }
  7032. while(!feof($f)) { $font .= fread($f, 2048); }
  7033. fclose($f);
  7034. include(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.php'); // sets $originalsize (of repackaged font)
  7035. }
  7036. else {
  7037. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  7038. $ttf = new TTFontFile();
  7039. $font = $ttf->repackageTTF($this->FontFiles[$fontkey]['ttffile'], $this->fonts[$fontkey]['TTCfontID'], $this->debugfonts);
  7040. $originalsize = strlen($font);
  7041. $font = gzcompress($font);
  7042. unset($ttf);
  7043. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7044. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.z',"wb");
  7045. fwrite($fh,$font,strlen($font));
  7046. fclose($fh);
  7047. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.php',"wb");
  7048. $len = "<?php \n";
  7049. $len.='$originalsize='.$originalsize.";\n";
  7050. $len.="?>";
  7051. fwrite($fh,$len,strlen($len));
  7052. fclose($fh);
  7053. }
  7054. }
  7055. }
  7056. else {
  7057. // First see if there is a cached compressed file
  7058. if (file_exists(_MPDF_TTFONTDATAPATH.$fontkey.'.z')) {
  7059. $f=fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.z','rb');
  7060. if(!$f) { $this->Error('Font file not found'); }
  7061. while(!feof($f)) { $font .= fread($f, 2048); }
  7062. fclose($f);
  7063. }
  7064. else {
  7065. $f=fopen($this->FontFiles[$fontkey]['ttffile'],'rb');
  7066. if(!$f) { $this->Error('Font file not found'); }
  7067. while(!feof($f)) { $font .= fread($f, 2048); }
  7068. fclose($f);
  7069. $font = gzcompress($font);
  7070. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7071. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.z',"wb");
  7072. fwrite($fh,$font,strlen($font));
  7073. fclose($fh);
  7074. }
  7075. }
  7076. }
  7077. $this->_out('<</Length '.strlen($font));
  7078. $this->_out('/Filter /FlateDecode');
  7079. $this->_out('/Length1 '.$originalsize);
  7080. $this->_out('>>');
  7081. $this->_putstream($font);
  7082. $this->_out('endobj');
  7083. }
  7084. }
  7085. }
  7086. $nfonts = count($this->fonts);
  7087. $fctr = 1;
  7088. foreach($this->fonts as $k=>$font) {
  7089. //Font objects
  7090. $type=$font['type'];
  7091. $name=$font['name'];
  7092. if ((!isset($font['used']) || !$font['used']) && $type=='TTF') { continue; }
  7093. if ($this->progressBar) { $this->UpdateProgressBar(2,intval($fctr*100/$nfonts),'Writing Fonts'); $fctr++; } // *PROGRESS-BAR*
  7094. if (isset($font['asSubset'])) { $asSubset = $font['asSubset']; }
  7095. else { $asSubset = ''; }
  7096. /*-- CJK-FONTS --*/
  7097. if($type=='Type0') { // = Adobe CJK Fonts
  7098. $this->fonts[$k]['n']=$this->n+1;
  7099. $this->_newobj();
  7100. $this->_out('<</Type /Font');
  7101. $this->_putType0($font);
  7102. }
  7103. else
  7104. /*-- END CJK-FONTS --*/
  7105. if($type=='core') {
  7106. //Standard font
  7107. $this->fonts[$k]['n']=$this->n+1;
  7108. if ($this->PDFA || $this->PDFX) { $this->Error('Core fonts are not allowed in PDF/A1-b or PDFX/1-a files (Times, Helvetica, Courier etc.)'); }
  7109. $this->_newobj();
  7110. $this->_out('<</Type /Font');
  7111. $this->_out('/BaseFont /'.$name);
  7112. $this->_out('/Subtype /Type1');
  7113. if($name!='Symbol' && $name!='ZapfDingbats') {
  7114. $this->_out('/Encoding /WinAnsiEncoding');
  7115. }
  7116. $this->_out('>>');
  7117. $this->_out('endobj');
  7118. }
  7119. // TrueType embedded SUBSETS for SIP (CJK extB containing Supplementary Ideographic Plane 2)
  7120. // Or Unicode Plane 1 - Supplementary Multilingual Plane
  7121. else if ($type=='TTF' && ($font['sip'] || $font['smp'])) {
  7122. if (!$font['used']) { continue; }
  7123. $ssfaid="AA";
  7124. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  7125. $ttf = new TTFontFile();
  7126. for($sfid=0;$sfid<count($font['subsetfontids']);$sfid++) {
  7127. $this->fonts[$k]['n'][$sfid]=$this->n+1; // NB an array for subset
  7128. $subsetname = 'MPDF'.$ssfaid.'+'.$font['name'];
  7129. $ssfaid++;
  7130. $subset = $font['subsets'][$sfid];
  7131. unset($subset[0]);
  7132. $ttfontstream = $ttf->makeSubsetSIP($font['ttffile'], $subset, $font['TTCfontID'], $this->debugfonts);
  7133. $ttfontsize = strlen($ttfontstream);
  7134. $fontstream = gzcompress($ttfontstream);
  7135. $widthstring = '';
  7136. $toUnistring = '';
  7137. foreach($font['subsets'][$sfid] AS $cp=>$u) {
  7138. $w = $this->_getCharWidth($font['cw'], $u);
  7139. if ($w !== false) {
  7140. $widthstring .= $w.' ';
  7141. }
  7142. else {
  7143. $widthstring .= round($ttf->defaultWidth).' ';
  7144. }
  7145. if ($u > 65535) {
  7146. $utf8 = chr(($u>>18)+240).chr((($u>>12)&63)+128).chr((($u>>6)&63)+128) .chr(($u&63)+128);
  7147. $utf16 = mb_convert_encoding($utf8, 'UTF-16BE', 'UTF-8');
  7148. $l1 = ord($utf16[0]);
  7149. $h1 = ord($utf16[1]);
  7150. $l2 = ord($utf16[2]);
  7151. $h2 = ord($utf16[3]);
  7152. $toUnistring .= sprintf("<%02s> <%02s%02s%02s%02s>\n", strtoupper(dechex($cp)), strtoupper(dechex($l1)), strtoupper(dechex($h1)), strtoupper(dechex($l2)), strtoupper(dechex($h2)));
  7153. }
  7154. else {
  7155. $toUnistring .= sprintf("<%02s> <%04s>\n", strtoupper(dechex($cp)), strtoupper(dechex($u)));
  7156. }
  7157. }
  7158. //Additional Type1 or TrueType font
  7159. $this->_newobj();
  7160. $this->_out('<</Type /Font');
  7161. $this->_out('/BaseFont /'.$subsetname);
  7162. $this->_out('/Subtype /TrueType');
  7163. $this->_out('/FirstChar 0 /LastChar '.(count($font['subsets'][$sfid])-1));
  7164. $this->_out('/Widths '.($this->n+1).' 0 R');
  7165. $this->_out('/FontDescriptor '.($this->n+2).' 0 R');
  7166. $this->_out('/ToUnicode '.($this->n + 3).' 0 R');
  7167. $this->_out('>>');
  7168. $this->_out('endobj');
  7169. //Widths
  7170. $this->_newobj();
  7171. $this->_out('['.$widthstring.']');
  7172. $this->_out('endobj');
  7173. //Descriptor
  7174. $this->_newobj();
  7175. $s='<</Type /FontDescriptor /FontName /'.$subsetname."\n";
  7176. foreach($font['desc'] as $kd=>$v) {
  7177. if ($kd == 'Flags') { $v = $v | 4; $v = $v & ~32; } // SYMBOLIC font flag
  7178. $s.=' /'.$kd.' '.$v."\n";
  7179. }
  7180. $s.='/FontFile2 '.($this->n + 2).' 0 R';
  7181. $this->_out($s.'>>');
  7182. $this->_out('endobj');
  7183. // ToUnicode
  7184. // mPDF 5.3.35
  7185. $this->_newobj();
  7186. $toUni = "/CIDInit /ProcSet findresource begin\n";
  7187. $toUni .= "12 dict begin\n";
  7188. $toUni .= "begincmap\n";
  7189. $toUni .= "/CIDSystemInfo\n";
  7190. $toUni .= "<</Registry (Adobe)\n";
  7191. $toUni .= "/Ordering (UCS)\n";
  7192. $toUni .= "/Supplement 0\n";
  7193. $toUni .= ">> def\n";
  7194. $toUni .= "/CMapName /Adobe-Identity-UCS def\n";
  7195. $toUni .= "/CMapType 2 def\n";
  7196. $toUni .= "1 begincodespacerange\n";
  7197. $toUni .= "<00> <FF>\n";
  7198. $toUni .= "endcodespacerange\n";
  7199. $toUni .= count($font['subsets'][$sfid])." beginbfchar\n";
  7200. $toUni .= $toUnistring;
  7201. $toUni .= "endbfchar\n";
  7202. $toUni .= "endcmap\n";
  7203. $toUni .= "CMapName currentdict /CMap defineresource pop\n";
  7204. $toUni .= "end\n";
  7205. $toUni .= "end\n";
  7206. $this->_out('<</Length '.(strlen($toUni)).'>>');
  7207. $this->_putstream($toUni);
  7208. $this->_out('endobj');
  7209. //Font file
  7210. $this->_newobj();
  7211. $this->_out('<</Length '.strlen($fontstream));
  7212. $this->_out('/Filter /FlateDecode');
  7213. $this->_out('/Length1 '.$ttfontsize);
  7214. $this->_out('>>');
  7215. $this->_putstream($fontstream);
  7216. $this->_out('endobj');
  7217. } // foreach subset
  7218. unset($ttf);
  7219. }
  7220. // TrueType embedded SUBSETS or FULL
  7221. else if ($type=='TTF') {
  7222. $this->fonts[$k]['n']=$this->n+1;
  7223. if ($asSubset ) {
  7224. $ssfaid="A";
  7225. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  7226. $ttf = new TTFontFile();
  7227. $fontname = 'MPDFA'.$ssfaid.'+'.$font['name'];
  7228. $subset = $font['subset'];
  7229. unset($subset[0]);
  7230. $ttfontstream = $ttf->makeSubset($font['ttffile'], $subset, $font['TTCfontID'], $this->debugfonts);
  7231. $ttfontsize = strlen($ttfontstream);
  7232. $fontstream = gzcompress($ttfontstream);
  7233. $codeToGlyph = $ttf->codeToGlyph;
  7234. unset($codeToGlyph[0]);
  7235. }
  7236. else { $fontname = $font['name']; }
  7237. // Type0 Font
  7238. // A composite font - a font composed of other fonts, organized hierarchically
  7239. $this->_newobj();
  7240. $this->_out('<</Type /Font');
  7241. $this->_out('/Subtype /Type0');
  7242. $this->_out('/BaseFont /'.$fontname.'');
  7243. $this->_out('/Encoding /Identity-H');
  7244. $this->_out('/DescendantFonts ['.($this->n + 1).' 0 R]');
  7245. $this->_out('/ToUnicode '.($this->n + 2).' 0 R');
  7246. $this->_out('>>');
  7247. $this->_out('endobj');
  7248. // CIDFontType2
  7249. // A CIDFont whose glyph descriptions are based on TrueType font technology
  7250. $this->_newobj();
  7251. $this->_out('<</Type /Font');
  7252. $this->_out('/Subtype /CIDFontType2');
  7253. $this->_out('/BaseFont /'.$fontname.'');
  7254. $this->_out('/CIDSystemInfo '.($this->n + 2).' 0 R');
  7255. $this->_out('/FontDescriptor '.($this->n + 3).' 0 R');
  7256. if (isset($font['desc']['MissingWidth'])){
  7257. $this->_out('/DW '.$font['desc']['MissingWidth'].'');
  7258. }
  7259. if (!$asSubset && file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw')) {
  7260. $w = '';
  7261. $w=file_get_contents(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw');
  7262. $this->_out($w);
  7263. }
  7264. else {
  7265. $this->_putTTfontwidths($font, $asSubset, $ttf->maxUni);
  7266. }
  7267. $this->_out('/CIDToGIDMap '.($this->n + 4).' 0 R');
  7268. $this->_out('>>');
  7269. $this->_out('endobj');
  7270. // ToUnicode
  7271. // mPDF 5.3.35
  7272. $this->_newobj();
  7273. $toUni = "/CIDInit /ProcSet findresource begin\n";
  7274. $toUni .= "12 dict begin\n";
  7275. $toUni .= "begincmap\n";
  7276. $toUni .= "/CIDSystemInfo\n";
  7277. $toUni .= "<</Registry (Adobe)\n";
  7278. $toUni .= "/Ordering (UCS)\n";
  7279. $toUni .= "/Supplement 0\n";
  7280. $toUni .= ">> def\n";
  7281. $toUni .= "/CMapName /Adobe-Identity-UCS def\n";
  7282. $toUni .= "/CMapType 2 def\n";
  7283. $toUni .= "1 begincodespacerange\n";
  7284. $toUni .= "<0000> <FFFF>\n";
  7285. $toUni .= "endcodespacerange\n";
  7286. $toUni .= "1 beginbfrange\n";
  7287. $toUni .= "<0000> <FFFF> <0000>\n";
  7288. $toUni .= "endbfrange\n";
  7289. $toUni .= "endcmap\n";
  7290. $toUni .= "CMapName currentdict /CMap defineresource pop\n";
  7291. $toUni .= "end\n";
  7292. $toUni .= "end\n";
  7293. $this->_out('<</Length '.(strlen($toUni)).'>>');
  7294. $this->_putstream($toUni);
  7295. $this->_out('endobj');
  7296. // CIDSystemInfo dictionary
  7297. $this->_newobj();
  7298. $this->_out('<</Registry (Adobe)');
  7299. $this->_out('/Ordering (UCS)');
  7300. $this->_out('/Supplement 0');
  7301. $this->_out('>>');
  7302. $this->_out('endobj');
  7303. // Font descriptor
  7304. $this->_newobj();
  7305. $this->_out('<</Type /FontDescriptor');
  7306. $this->_out('/FontName /'.$fontname);
  7307. foreach($font['desc'] as $kd=>$v) {
  7308. if ($asSubset && $kd == 'Flags') { $v = $v | 4; $v = $v & ~32; } // SYMBOLIC font flag
  7309. $this->_out(' /'.$kd.' '.$v);
  7310. }
  7311. if ($font['panose']) {
  7312. $this->_out(' /Style << /Panose <'.$font['panose'].'> >>');
  7313. }
  7314. if ($asSubset ) {
  7315. $this->_out('/FontFile2 '.($this->n + 2).' 0 R');
  7316. }
  7317. else if ($font['fontkey']) {
  7318. // obj ID of a stream containing a TrueType font program
  7319. $this->_out('/FontFile2 '.$this->FontFiles[$font['fontkey']]['n'].' 0 R');
  7320. }
  7321. $this->_out('>>');
  7322. $this->_out('endobj');
  7323. // Embed CIDToGIDMap
  7324. // A specification of the mapping from CIDs to glyph indices
  7325. if ($asSubset ) {
  7326. $cidtogidmap = '';
  7327. $cidtogidmap = str_pad('', 256*256*2, "\x00");
  7328. foreach($codeToGlyph as $cc=>$glyph) {
  7329. $cidtogidmap[$cc*2] = chr($glyph >> 8);
  7330. $cidtogidmap[$cc*2 + 1] = chr($glyph & 0xFF);
  7331. }
  7332. $cidtogidmap = gzcompress($cidtogidmap);
  7333. }
  7334. else {
  7335. // First see if there is a cached CIDToGIDMapfile
  7336. $cidtogidmap = '';
  7337. if (file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cgm')) {
  7338. $f=fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cgm','rb');
  7339. while(!feof($f)) { $cidtogidmap .= fread($f, 2048); }
  7340. fclose($f);
  7341. }
  7342. else {
  7343. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  7344. $ttf = new TTFontFile();
  7345. $charToGlyph = $ttf->getCTG($font['ttffile'], $font['TTCfontID'], $this->debugfonts);
  7346. $cidtogidmap = str_pad('', 256*256*2, "\x00");
  7347. foreach($charToGlyph as $cc=>$glyph) {
  7348. $cidtogidmap[$cc*2] = chr($glyph >> 8);
  7349. $cidtogidmap[$cc*2 + 1] = chr($glyph & 0xFF);
  7350. }
  7351. unset($ttf);
  7352. $cidtogidmap = gzcompress($cidtogidmap);
  7353. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7354. $fh = fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cgm',"wb");
  7355. fwrite($fh,$cidtogidmap,strlen($cidtogidmap));
  7356. fclose($fh);
  7357. }
  7358. }
  7359. }
  7360. $this->_newobj();
  7361. $this->_out('<</Length '.strlen($cidtogidmap).'');
  7362. $this->_out('/Filter /FlateDecode');
  7363. $this->_out('>>');
  7364. $this->_putstream($cidtogidmap);
  7365. $this->_out('endobj');
  7366. //Font file
  7367. if ($asSubset ) {
  7368. $this->_newobj();
  7369. $this->_out('<</Length '.strlen($fontstream));
  7370. $this->_out('/Filter /FlateDecode');
  7371. $this->_out('/Length1 '.$ttfontsize);
  7372. $this->_out('>>');
  7373. $this->_putstream($fontstream);
  7374. $this->_out('endobj');
  7375. unset($ttf);
  7376. }
  7377. }
  7378. else { $this->Error('Unsupported font type: '.$type.' ('.$name.')'); }
  7379. }
  7380. if ($mqr) { set_magic_quotes_runtime($mqr); }
  7381. }
  7382. function _putTTfontwidths(&$font, $asSubset, $maxUni) {
  7383. if ($asSubset && file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php')) {
  7384. include(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php') ;
  7385. $startcid = 128;
  7386. }
  7387. else {
  7388. $rangeid = 0;
  7389. $range = array();
  7390. $prevcid = -2;
  7391. $prevwidth = -1;
  7392. $interval = false;
  7393. $startcid = 1;
  7394. }
  7395. if ($asSubset) { $cwlen = $maxUni + 1; }
  7396. else { $cwlen = (strlen($font['cw'])/2); }
  7397. // for each character
  7398. for ($cid=$startcid; $cid<$cwlen; $cid++) {
  7399. if ($cid==128 && $asSubset && (!file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php'))) {
  7400. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7401. $fh = fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php',"wb");
  7402. $cw127='<?php'."\n";
  7403. $cw127.='$rangeid='.$rangeid.";\n";
  7404. $cw127.='$prevcid='.$prevcid.";\n";
  7405. $cw127.='$prevwidth='.$prevwidth.";\n";
  7406. if ($interval) { $cw127.='$interval=true'.";\n"; }
  7407. else { $cw127.='$interval=false'.";\n"; }
  7408. $cw127.='$range='.var_export($range,true).";\n";
  7409. $cw127.="?>";
  7410. fwrite($fh,$cw127,strlen($cw127));
  7411. fclose($fh);
  7412. }
  7413. }
  7414. if ($font['cw'][$cid*2] == "\00" && $font['cw'][$cid*2+1] == "\00") { continue; }
  7415. $width = (ord($font['cw'][$cid*2]) << 8) + ord($font['cw'][$cid*2+1]);
  7416. if ($width == 65535) { $width = 0; }
  7417. if ($asSubset && $cid > 255 && (!isset($font['subset'][$cid]) || !$font['subset'][$cid])) {
  7418. continue;
  7419. }
  7420. if (!isset($font['dw']) || (isset($font['dw']) && $width != $font['dw'])) {
  7421. if ($cid == ($prevcid + 1)) {
  7422. // consecutive CID
  7423. if ($width == $prevwidth) {
  7424. if ($width == $range[$rangeid][0]) {
  7425. $range[$rangeid][] = $width;
  7426. } else {
  7427. array_pop($range[$rangeid]);
  7428. // new range
  7429. $rangeid = $prevcid;
  7430. $range[$rangeid] = array();
  7431. $range[$rangeid][] = $prevwidth;
  7432. $range[$rangeid][] = $width;
  7433. }
  7434. $interval = true;
  7435. $range[$rangeid]['interval'] = true;
  7436. } else {
  7437. if ($interval) {
  7438. // new range
  7439. $rangeid = $cid;
  7440. $range[$rangeid] = array();
  7441. $range[$rangeid][] = $width;
  7442. } else {
  7443. $range[$rangeid][] = $width;
  7444. }
  7445. $interval = false;
  7446. }
  7447. } else {
  7448. // new range
  7449. $rangeid = $cid;
  7450. $range[$rangeid] = array();
  7451. $range[$rangeid][] = $width;
  7452. $interval = false;
  7453. }
  7454. $prevcid = $cid;
  7455. $prevwidth = $width;
  7456. }
  7457. }
  7458. $w = $this->_putfontranges($range);
  7459. $this->_out($w);
  7460. if (!$asSubset) {
  7461. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7462. $fh = fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw',"wb");
  7463. fwrite($fh,$w,strlen($w));
  7464. fclose($fh);
  7465. }
  7466. }
  7467. }
  7468. function _putfontranges(&$range) {
  7469. // optimize ranges
  7470. $prevk = -1;
  7471. $nextk = -1;
  7472. $prevint = false;
  7473. foreach ($range as $k => $ws) {
  7474. $cws = count($ws);
  7475. if (($k == $nextk) AND (!$prevint) AND ((!isset($ws['interval'])) OR ($cws < 4))) {
  7476. if (isset($range[$k]['interval'])) {
  7477. unset($range[$k]['interval']);
  7478. }
  7479. $range[$prevk] = array_merge($range[$prevk], $range[$k]);
  7480. unset($range[$k]);
  7481. } else {
  7482. $prevk = $k;
  7483. }
  7484. $nextk = $k + $cws;
  7485. if (isset($ws['interval'])) {
  7486. if ($cws > 3) {
  7487. $prevint = true;
  7488. } else {
  7489. $prevint = false;
  7490. }
  7491. unset($range[$k]['interval']);
  7492. --$nextk;
  7493. } else {
  7494. $prevint = false;
  7495. }
  7496. }
  7497. // output data
  7498. $w = '';
  7499. foreach ($range as $k => $ws) {
  7500. if (count(array_count_values($ws)) == 1) {
  7501. // interval mode is more compact
  7502. $w .= ' '.$k.' '.($k + count($ws) - 1).' '.$ws[0];
  7503. } else {
  7504. // range mode
  7505. $w .= ' '.$k.' [ '.implode(' ', $ws).' ]' . "\n";
  7506. }
  7507. }
  7508. return '/W ['.$w.' ]';
  7509. }
  7510. function _putfontwidths(&$font, $cidoffset=0) {
  7511. ksort($font['cw']);
  7512. unset($font['cw'][65535]);
  7513. $rangeid = 0;
  7514. $range = array();
  7515. $prevcid = -2;
  7516. $prevwidth = -1;
  7517. $interval = false;
  7518. // for each character
  7519. foreach ($font['cw'] as $cid => $width) {
  7520. $cid -= $cidoffset;
  7521. if (!isset($font['dw']) || (isset($font['dw']) && $width != $font['dw'])) {
  7522. if ($cid == ($prevcid + 1)) {
  7523. // consecutive CID
  7524. if ($width == $prevwidth) {
  7525. if ($width == $range[$rangeid][0]) {
  7526. $range[$rangeid][] = $width;
  7527. } else {
  7528. array_pop($range[$rangeid]);
  7529. // new range
  7530. $rangeid = $prevcid;
  7531. $range[$rangeid] = array();
  7532. $range[$rangeid][] = $prevwidth;
  7533. $range[$rangeid][] = $width;
  7534. }
  7535. $interval = true;
  7536. $range[$rangeid]['interval'] = true;
  7537. } else {
  7538. if ($interval) {
  7539. // new range
  7540. $rangeid = $cid;
  7541. $range[$rangeid] = array();
  7542. $range[$rangeid][] = $width;
  7543. } else {
  7544. $range[$rangeid][] = $width;
  7545. }
  7546. $interval = false;
  7547. }
  7548. } else {
  7549. // new range
  7550. $rangeid = $cid;
  7551. $range[$rangeid] = array();
  7552. $range[$rangeid][] = $width;
  7553. $interval = false;
  7554. }
  7555. $prevcid = $cid;
  7556. $prevwidth = $width;
  7557. }
  7558. }
  7559. $this->_out($this->_putfontranges($range));
  7560. }
  7561. /*-- CJK-FONTS --*/
  7562. // from class PDF_Chinese CJK EXTENSIONS
  7563. function _putType0(&$font)
  7564. {
  7565. //Type0
  7566. $this->_out('/Subtype /Type0');
  7567. $this->_out('/BaseFont /'.$font['name'].'-'.$font['CMap']);
  7568. $this->_out('/Encoding /'.$font['CMap']);
  7569. $this->_out('/DescendantFonts ['.($this->n+1).' 0 R]');
  7570. $this->_out('>>');
  7571. $this->_out('endobj');
  7572. //CIDFont
  7573. $this->_newobj();
  7574. $this->_out('<</Type /Font');
  7575. $this->_out('/Subtype /CIDFontType0');
  7576. $this->_out('/BaseFont /'.$font['name']);
  7577. $cidinfo = '/Registry '.$this->_textstring('Adobe');
  7578. $cidinfo .= ' /Ordering '.$this->_textstring($font['registry']['ordering']);
  7579. $cidinfo .= ' /Supplement '.$font['registry']['supplement'];
  7580. $this->_out('/CIDSystemInfo <<'.$cidinfo.'>>');
  7581. $this->_out('/FontDescriptor '.($this->n+1).' 0 R');
  7582. if (isset($font['MissingWidth'])){
  7583. $this->_out('/DW '.$font['MissingWidth'].'');
  7584. }
  7585. $this->_putfontwidths($font, 31);
  7586. $this->_out('>>');
  7587. $this->_out('endobj');
  7588. //Font descriptor
  7589. $this->_newobj();
  7590. $s = '<</Type /FontDescriptor /FontName /'.$font['name'];
  7591. foreach ($font['desc'] as $k => $v) {
  7592. if ($k != 'Style') {
  7593. $s .= ' /'.$k.' '.$v.'';
  7594. }
  7595. }
  7596. $this->_out($s.'>>');
  7597. $this->_out('endobj');
  7598. }
  7599. /*-- END CJK-FONTS --*/
  7600. function _putimages()
  7601. {
  7602. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  7603. reset($this->images);
  7604. while(list($file,$info)=each($this->images)) {
  7605. $this->_newobj();
  7606. $this->images[$file]['n']=$this->n;
  7607. $this->_out('<</Type /XObject');
  7608. $this->_out('/Subtype /Image');
  7609. $this->_out('/Width '.$info['w']);
  7610. $this->_out('/Height '.$info['h']);
  7611. if (isset($info['masked'])) {
  7612. $this->_out('/SMask '.($this->n - 1).' 0 R');
  7613. }
  7614. if($info['cs']=='Indexed') {
  7615. if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3)) { $this->Error("PDFA1-b and PDFX/1-a files do not permit using mixed colour space (".$file.")."); }
  7616. $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]');
  7617. }
  7618. else {
  7619. $this->_out('/ColorSpace /'.$info['cs']);
  7620. if($info['cs']=='DeviceCMYK') {
  7621. if ($this->PDFA && $this->restrictColorSpace!=3) { $this->Error("PDFA1-b does not permit Images using mixed colour space (".$file.")."); }
  7622. if($info['type']=='jpg') { $this->_out('/Decode [1 0 1 0 1 0 1 0]'); }
  7623. }
  7624. else if ($info['cs']=='DeviceRGB' && ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3))) { $this->Error("PDFA1-b and PDFX/1-a files do not permit using mixed colour space (".$file.")."); }
  7625. }
  7626. $this->_out('/BitsPerComponent '.$info['bpc']);
  7627. if (isset($info['f']) && $info['f']) { $this->_out('/Filter /'.$info['f']); }
  7628. if(isset($info['parms'])) { $this->_out($info['parms']); }
  7629. if(isset($info['trns']) and is_array($info['trns'])) {
  7630. $trns='';
  7631. for($i=0;$i<count($info['trns']);$i++)
  7632. $trns.=$info['trns'][$i].' '.$info['trns'][$i].' ';
  7633. $this->_out('/Mask ['.$trns.']');
  7634. }
  7635. $this->_out('/Length '.strlen($info['data']).'>>');
  7636. $this->_putstream($info['data']);
  7637. unset($this->images[$file]['data']);
  7638. $this->_out('endobj');
  7639. //Palette
  7640. if($info['cs']=='Indexed') {
  7641. $this->_newobj();
  7642. $pal=($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  7643. $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>');
  7644. $this->_putstream($pal);
  7645. $this->_out('endobj');
  7646. }
  7647. }
  7648. }
  7649. function _putinfo()
  7650. {
  7651. $this->_out('/Producer '.$this->_UTF16BEtextstring('mPDF '.mPDF_VERSION));
  7652. if(!empty($this->title))
  7653. $this->_out('/Title '.$this->_UTF16BEtextstring($this->title));
  7654. if(!empty($this->subject))
  7655. $this->_out('/Subject '.$this->_UTF16BEtextstring($this->subject));
  7656. if(!empty($this->author))
  7657. $this->_out('/Author '.$this->_UTF16BEtextstring($this->author));
  7658. if(!empty($this->keywords))
  7659. $this->_out('/Keywords '.$this->_UTF16BEtextstring($this->keywords));
  7660. if(!empty($this->creator))
  7661. $this->_out('/Creator '.$this->_UTF16BEtextstring($this->creator));
  7662. $z = date('O'); // +0200
  7663. $offset = substr($z,0,3)."'".substr($z,3,2)."'";
  7664. $this->_out('/CreationDate '.$this->_textstring(date('YmdHis').$offset));
  7665. $this->_out('/ModDate '.$this->_textstring(date('YmdHis').$offset));
  7666. if ($this->PDFX) {
  7667. $this->_out('/Trapped/False');
  7668. $this->_out('/GTS_PDFXVersion(PDF/X-1a:2003)');
  7669. }
  7670. }
  7671. function _putmetadata() {
  7672. $this->_newobj();
  7673. $this->MetadataRoot = $this->n;
  7674. $Producer = 'mPDF '.mPDF_VERSION;
  7675. $z = date('O'); // +0200
  7676. $offset = substr($z,0,3).':'.substr($z,3,2);
  7677. $CreationDate = date('Y-m-d\TH:i:s').$offset; // 2006-03-10T10:47:26-05:00 2006-06-19T09:05:17Z
  7678. $uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff),
  7679. mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000,
  7680. mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) );
  7681. $m = '<?xpacket begin="'.chr(239).chr(187).chr(191).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n"; // begin = FEFF BOM
  7682. $m .= ' <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="3.1-701">'."\n";
  7683. $m .= ' <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n";
  7684. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n";
  7685. $m .= ' <pdf:Producer>'.$Producer.'</pdf:Producer>'."\n";
  7686. if(!empty($this->keywords)) { $m .= ' <pdf:Keywords>'.$this->keywords.'</pdf:Keywords>'."\n"; }
  7687. $m .= ' </rdf:Description>'."\n";
  7688. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n";
  7689. $m .= ' <xmp:CreateDate>'.$CreationDate.'</xmp:CreateDate>'."\n";
  7690. $m .= ' <xmp:ModifyDate>'.$CreationDate.'</xmp:ModifyDate>'."\n";
  7691. $m .= ' <xmp:MetadataDate>'.$CreationDate.'</xmp:MetadataDate>'."\n";
  7692. if(!empty($this->creator)) { $m .= ' <xmp:CreatorTool>'.$this->creator.'</xmp:CreatorTool>'."\n"; }
  7693. $m .= ' </rdf:Description>'."\n";
  7694. // DC elements
  7695. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
  7696. $m .= ' <dc:format>application/pdf</dc:format>'."\n";
  7697. if(!empty($this->title)) {
  7698. $m .= ' <dc:title>
  7699. <rdf:Alt>
  7700. <rdf:li xml:lang="x-default">'.$this->title.'</rdf:li>
  7701. </rdf:Alt>
  7702. </dc:title>'."\n";
  7703. }
  7704. if(!empty($this->keywords)) {
  7705. $m .= ' <dc:subject>
  7706. <rdf:Bag>
  7707. <rdf:li>'.$this->keywords.'</rdf:li>
  7708. </rdf:Bag>
  7709. </dc:subject>'."\n";
  7710. }
  7711. if(!empty($this->subject)) {
  7712. $m .= ' <dc:description>
  7713. <rdf:Alt>
  7714. <rdf:li xml:lang="x-default">'.$this->subject.'</rdf:li>
  7715. </rdf:Alt>
  7716. </dc:description>'."\n";
  7717. }
  7718. if(!empty($this->author)) {
  7719. $m .= ' <dc:creator>
  7720. <rdf:Seq>
  7721. <rdf:li>'.$this->author.'</rdf:li>
  7722. </rdf:Seq>
  7723. </dc:creator>'."\n";
  7724. }
  7725. $m .= ' </rdf:Description>'."\n";
  7726. // This bit is specific to PDFX-1a
  7727. if ($this->PDFX) {
  7728. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:pdfx="http://ns.adobe.com/pdfx/1.3/" pdfx:Apag_PDFX_Checkup="1.3" pdfx:GTS_PDFXConformance="PDF/X-1a:2003" pdfx:GTS_PDFXVersion="PDF/X-1:2003"/>'."\n";
  7729. }
  7730. // This bit is specific to PDFA-1b
  7731. else if ($this->PDFA) {
  7732. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/" >'."\n";
  7733. $m .= ' <pdfaid:part>1</pdfaid:part>'."\n";
  7734. $m .= ' <pdfaid:conformance>B</pdfaid:conformance>'."\n";
  7735. $m .= ' <pdfaid:amd>2005</pdfaid:amd>'."\n";
  7736. $m .= ' </rdf:Description>'."\n";
  7737. }
  7738. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n";
  7739. $m .= ' <xmpMM:DocumentID>uuid:'.$uuid.'</xmpMM:DocumentID>'."\n";
  7740. $m .= ' </rdf:Description>'."\n";
  7741. $m .= ' </rdf:RDF>'."\n";
  7742. $m .= ' </x:xmpmeta>'."\n";
  7743. $m .= str_repeat(str_repeat(' ',100)."\n",20); // 2-4kB whitespace padding required
  7744. $m .= '<?xpacket end="w"?>'; // "r" read only
  7745. $this->_out('<</Type/Metadata/Subtype/XML/Length '.strlen($m).'>>');
  7746. $this->_putstream($m);
  7747. $this->_out('endobj');
  7748. }
  7749. function _putoutputintent() {
  7750. $this->_newobj();
  7751. $this->OutputIntentRoot = $this->n;
  7752. $this->_out('<</Type /OutputIntent');
  7753. if ($this->PDFA) {
  7754. $this->_out('/S /GTS_PDFA1');
  7755. if ($this->ICCProfile) {
  7756. $this->_out('/Info ('.preg_replace('/_/',' ',$this->ICCProfile).')');
  7757. $this->_out('/OutputConditionIdentifier (Custom)');
  7758. $this->_out('/OutputCondition ()');
  7759. }
  7760. else {
  7761. $this->_out('/Info (sRGB IEC61966-2.1)');
  7762. $this->_out('/OutputConditionIdentifier (sRGB IEC61966-2.1)');
  7763. $this->_out('/OutputCondition ()');
  7764. }
  7765. $this->_out('/DestOutputProfile '.($this->n+1).' 0 R');
  7766. }
  7767. else if ($this->PDFX) { // always a CMYK profile
  7768. $this->_out('/S /GTS_PDFX');
  7769. if ($this->ICCProfile) {
  7770. $this->_out('/Info ('.preg_replace('/_/',' ',$this->ICCProfile).')');
  7771. $this->_out('/OutputConditionIdentifier (Custom)');
  7772. $this->_out('/OutputCondition ()');
  7773. $this->_out('/DestOutputProfile '.($this->n+1).' 0 R');
  7774. }
  7775. else {
  7776. $this->_out('/Info (CGATS TR 001)');
  7777. $this->_out('/OutputConditionIdentifier (CGATS TR 001)');
  7778. $this->_out('/OutputCondition (CGATS TR 001 (SWOP))');
  7779. $this->_out('/RegistryName (http://www.color.org)');
  7780. }
  7781. }
  7782. $this->_out('>>');
  7783. $this->_out('endobj');
  7784. if ($this->PDFX && !$this->ICCProfile) { return; } // no ICCProfile embedded
  7785. $this->_newobj();
  7786. if ($this->ICCProfile)
  7787. $s = file_get_contents(_MPDF_PATH.'iccprofiles/'.$this->ICCProfile.'.icc');
  7788. else
  7789. $s = file_get_contents(_MPDF_PATH.'iccprofiles/sRGB_IEC61966-2-1.icc');
  7790. if ($this->compress) { $s = gzcompress($s); }
  7791. $this->_out('<<');
  7792. if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace == 3)) { $this->_out('/N 4'); }
  7793. else { $this->_out('/N 3'); }
  7794. if ($this->compress)
  7795. $this->_out('/Filter /FlateDecode ');
  7796. $this->_out('/Length '.strlen($s).'>>');
  7797. $this->_putstream($s);
  7798. $this->_out('endobj');
  7799. }
  7800. function _putcatalog() {
  7801. $this->_out('/Type /Catalog');
  7802. $this->_out('/Pages 1 0 R');
  7803. if($this->ZoomMode=='fullpage') $this->_out('/OpenAction [3 0 R /Fit]');
  7804. elseif($this->ZoomMode=='fullwidth') $this->_out('/OpenAction [3 0 R /FitH null]');
  7805. elseif($this->ZoomMode=='real') $this->_out('/OpenAction [3 0 R /XYZ null null 1]');
  7806. elseif(!is_string($this->ZoomMode)) $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']');
  7807. else $this->_out('/OpenAction [3 0 R /XYZ null null null]');
  7808. if($this->LayoutMode=='single') $this->_out('/PageLayout /SinglePage');
  7809. elseif($this->LayoutMode=='continuous') $this->_out('/PageLayout /OneColumn');
  7810. elseif($this->LayoutMode=='twoleft') $this->_out('/PageLayout /TwoColumnLeft');
  7811. elseif($this->LayoutMode=='tworight') $this->_out('/PageLayout /TwoColumnRight');
  7812. elseif($this->LayoutMode=='two') {
  7813. if ($this->mirrorMargins) { $this->_out('/PageLayout /TwoColumnRight'); }
  7814. else { $this->_out('/PageLayout /TwoColumnLeft'); }
  7815. }
  7816. /*-- BOOKMARKS --*/
  7817. if(count($this->BMoutlines)>0) {
  7818. $this->_out('/Outlines '.$this->OutlineRoot.' 0 R');
  7819. $this->_out('/PageMode /UseOutlines');
  7820. }
  7821. /*-- END BOOKMARKS --*/
  7822. if(is_int(strpos($this->DisplayPreferences,'FullScreen'))) $this->_out('/PageMode /FullScreen');
  7823. // Metadata
  7824. if ($this->PDFA || $this->PDFX) {
  7825. $this->_out('/Metadata '.$this->MetadataRoot.' 0 R');
  7826. }
  7827. // OutputIntents
  7828. if ($this->PDFA || $this->PDFX || $this->ICCProfile) {
  7829. $this->_out('/OutputIntents ['.$this->OutputIntentRoot.' 0 R]');
  7830. }
  7831. /*-- FORMS --*/
  7832. if (count($this->form->forms)>0) {
  7833. $this->form->_putFormsCatalog();
  7834. }
  7835. /*-- END FORMS --*/
  7836. if ( isset($this->js) ) {
  7837. $this->_out('/Names << /JavaScript '.($this->n_js).' 0 R >> ');
  7838. }
  7839. if($this->DisplayPreferences || $this->directionality == 'rtl' || $this->mirrorMargins) {
  7840. $this->_out('/ViewerPreferences<<');
  7841. if(is_int(strpos($this->DisplayPreferences,'HideMenubar'))) $this->_out('/HideMenubar true');
  7842. if(is_int(strpos($this->DisplayPreferences,'HideToolbar'))) $this->_out('/HideToolbar true');
  7843. if(is_int(strpos($this->DisplayPreferences,'HideWindowUI'))) $this->_out('/HideWindowUI true');
  7844. if(is_int(strpos($this->DisplayPreferences,'DisplayDocTitle'))) $this->_out('/DisplayDocTitle true');
  7845. if(is_int(strpos($this->DisplayPreferences,'CenterWindow'))) $this->_out('/CenterWindow true');
  7846. if(is_int(strpos($this->DisplayPreferences,'FitWindow'))) $this->_out('/FitWindow true');
  7847. // /PrintScaling is PDF 1.6 spec.
  7848. if(is_int(strpos($this->DisplayPreferences,'NoPrintScaling')) && !$this->PDFA && !$this->PDFX)
  7849. $this->_out('/PrintScaling /None');
  7850. if($this->directionality == 'rtl') $this->_out('/Direction /R2L');
  7851. // /Duplex is PDF 1.7 spec.
  7852. if($this->mirrorMargins && !$this->PDFA && !$this->PDFX) {
  7853. // if ($this->DefOrientation=='P') $this->_out('/Duplex /DuplexFlipShortEdge');
  7854. $this->_out('/Duplex /DuplexFlipLongEdge'); // PDF v1.7+
  7855. }
  7856. $this->_out('>>');
  7857. }
  7858. if ($this->hasOC) { // mPDF 5.3.45
  7859. // mPDF 5.3.41 Visibility
  7860. $p=$this->n_ocg_print.' 0 R';
  7861. $v=$this->n_ocg_view.' 0 R';
  7862. $h=$this->n_ocg_hidden.' 0 R';
  7863. $as="<</Event /Print /OCGs [$p $v $h] /Category [/Print]>> <</Event /View /OCGs [$p $v $h] /Category [/View]>>";
  7864. $this->_out("/OCProperties <</OCGs [$p $v $h] /D <</ON [$p] /OFF [$v] /OFF [$h] /AS [$as]>>>>");
  7865. }
  7866. }
  7867. // Inactive function left for backwards compatability
  7868. function SetUserRights($enable=true, $annots="", $form="", $signature="") {
  7869. // Does nothing
  7870. }
  7871. function _enddoc() {
  7872. if ($this->progressBar) { $this->UpdateProgressBar(2,'10','Writing Headers & Footers'); } // *PROGRESS-BAR*
  7873. $this->_puthtmlheaders(); // *HTMLHEADERS-FOOTERS*
  7874. if ($this->progressBar) { $this->UpdateProgressBar(2,'20','Writing Pages'); } // *PROGRESS-BAR*
  7875. // Remove references to unused fonts (usually default font)
  7876. foreach($this->fonts as $fk=>$font) {
  7877. if (!$font['used'] && ($font['type']=='TTF')) {
  7878. if ($font['sip'] || $font['smp']) {
  7879. foreach($font['subsetfontids'] AS $k => $fid) {
  7880. foreach($this->pages AS $pn=>$page) {
  7881. $this->pages[$pn] = preg_replace('/\s\/F'.$fid.' \d[\d.]* Tf\s/is',' ',$this->pages[$pn]);
  7882. }
  7883. }
  7884. }
  7885. else {
  7886. foreach($this->pages AS $pn=>$page) {
  7887. $this->pages[$pn] = preg_replace('/\s\/F'.$font['i'].' \d[\d.]* Tf\s/is',' ',$this->pages[$pn]);
  7888. }
  7889. }
  7890. }
  7891. }
  7892. $this->_putpages();
  7893. if ($this->progressBar) { $this->UpdateProgressBar(2,'30','Writing document resources'); } // *PROGRESS-BAR*
  7894. $this->_putresources();
  7895. //Info
  7896. $this->_newobj();
  7897. $this->InfoRoot = $this->n;
  7898. $this->_out('<<');
  7899. if ($this->progressBar) { $this->UpdateProgressBar(2,'80','Writing document info'); } // *PROGRESS-BAR*
  7900. $this->_putinfo();
  7901. $this->_out('>>');
  7902. $this->_out('endobj');
  7903. // METADATA
  7904. if ($this->PDFA || $this->PDFX) { $this->_putmetadata(); }
  7905. // OUTPUTINTENT
  7906. if ($this->PDFA || $this->PDFX || $this->ICCProfile) { $this->_putoutputintent(); }
  7907. //Catalog
  7908. $this->_newobj();
  7909. $this->_out('<<');
  7910. if ($this->progressBar) { $this->UpdateProgressBar(2,'90','Writing document catalog'); } // *PROGRESS-BAR*
  7911. $this->_putcatalog();
  7912. $this->_out('>>');
  7913. $this->_out('endobj');
  7914. //Cross-ref
  7915. $o=strlen($this->buffer);
  7916. $this->_out('xref');
  7917. $this->_out('0 '.($this->n+1));
  7918. $this->_out('0000000000 65535 f ');
  7919. for($i=1; $i <= $this->n ; $i++)
  7920. $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i]));
  7921. //Trailer
  7922. $this->_out('trailer');
  7923. $this->_out('<<');
  7924. $this->_puttrailer();
  7925. $this->_out('>>');
  7926. $this->_out('startxref');
  7927. $this->_out($o);
  7928. $this->buffer .= '%%EOF';
  7929. $this->state=3;
  7930. /*-- IMPORTS --*/
  7931. if ($this->enableImports && count($this->parsers) > 0) {
  7932. foreach ($this->parsers as $k => $_){
  7933. $this->parsers[$k]->closeFile();
  7934. $this->parsers[$k] = null;
  7935. unset($this->parsers[$k]);
  7936. }
  7937. }
  7938. /*-- END IMPORTS --*/
  7939. }
  7940. function _beginpage($orientation,$mgl='',$mgr='',$mgt='',$mgb='',$mgh='',$mgf='',$ohname='',$ehname='',$ofname='',$efname='',$ohvalue=0,$ehvalue=0,$ofvalue=0,$efvalue=0,$pagesel='',$newformat='') {
  7941. if (!($pagesel && $this->page==1 && (sprintf("%0.4f", $this->y)==sprintf("%0.4f", $this->tMargin)))) {
  7942. $this->page++;
  7943. $this->pages[$this->page]='';
  7944. }
  7945. $this->state=2;
  7946. $resetHTMLHeadersrequired = false;
  7947. if ($newformat) { $this->_setPageSize($newformat, $orientation); }
  7948. /*-- CSS-PAGE --*/
  7949. // Paged media (page-box)
  7950. if ($pagesel || (isset($this->page_box['using']) && $this->page_box['using'])) {
  7951. if ($pagesel || $this->page==1) { $first = true; }
  7952. else { $first = false; }
  7953. if ($this->mirrorMargins && ($this->page % 2==0)) { $oddEven = 'E'; }
  7954. else { $oddEven = 'O'; }
  7955. if ($pagesel) { $psel = $pagesel; }
  7956. else if ($this->page_box['current']) { $psel = $this->page_box['current']; }
  7957. else { $psel = ''; }
  7958. list($orientation,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$hname,$fname,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat) = $this->SetPagedMediaCSS($psel, $first, $oddEven);
  7959. if ($this->mirrorMargins && ($this->page % 2==0)) {
  7960. if ($hname) { $ehvalue = 1; $ehname = $hname; } else { $ehvalue = -1; }
  7961. if ($fname) { $efvalue = 1; $efname = $fname; } else { $efvalue = -1; }
  7962. }
  7963. else {
  7964. if ($hname) { $ohvalue = 1; $ohname = $hname; } else { $ohvalue = -1; }
  7965. if ($fname) { $ofvalue = 1; $ofname = $fname; } else { $ofvalue = -1; }
  7966. }
  7967. if ($resetpagenum || $pagenumstyle || $suppress) {
  7968. $this->PageNumSubstitutions[] = array('from'=>($this->page), 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=>$suppress);
  7969. }
  7970. // PAGED MEDIA - CROP / CROSS MARKS from @PAGE
  7971. $this->show_marks = $marks;
  7972. // Background color
  7973. if (isset($bg['BACKGROUND-COLOR'])) {
  7974. $cor = $this->ConvertColor($bg['BACKGROUND-COLOR']);
  7975. if ($cor) {
  7976. $this->bodyBackgroundColor = $cor;
  7977. }
  7978. }
  7979. else { $this->bodyBackgroundColor = false; }
  7980. /*-- BACKGROUNDS --*/
  7981. if (isset($bg['BACKGROUND-GRADIENT'])) {
  7982. $this->bodyBackgroundGradient = $bg['BACKGROUND-GRADIENT'];
  7983. }
  7984. else { $this->bodyBackgroundGradient = false; }
  7985. // Tiling Patterns
  7986. if (isset($bg['BACKGROUND-IMAGE']) && $bg['BACKGROUND-IMAGE']) {
  7987. $ret = $this->SetBackground($bg, $this->pgwidth);
  7988. if ($ret) { $this->bodyBackgroundImage = $ret; }
  7989. }
  7990. else { $this->bodyBackgroundImage = false; }
  7991. /*-- END BACKGROUNDS --*/
  7992. $this->page_box['current'] = $psel;
  7993. $this->page_box['using'] = true;
  7994. }
  7995. /*-- END CSS-PAGE --*/
  7996. //Page orientation
  7997. if(!$orientation)
  7998. $orientation=$this->DefOrientation;
  7999. else {
  8000. $orientation=strtoupper(substr($orientation,0,1));
  8001. if($orientation!=$this->DefOrientation)
  8002. $this->OrientationChanges[$this->page]=true;
  8003. }
  8004. if($orientation!=$this->CurOrientation || $newformat) {
  8005. //Change orientation
  8006. if($orientation=='P') {
  8007. $this->wPt=$this->fwPt;
  8008. $this->hPt=$this->fhPt;
  8009. $this->w=$this->fw;
  8010. $this->h=$this->fh;
  8011. if (($this->forcePortraitHeaders || $this->forcePortraitMargins) && $this->DefOrientation=='P') {
  8012. $this->tMargin = $this->orig_tMargin;
  8013. $this->bMargin = $this->orig_bMargin;
  8014. $this->DeflMargin = $this->orig_lMargin;
  8015. $this->DefrMargin = $this->orig_rMargin;
  8016. $this->margin_header = $this->orig_hMargin;
  8017. $this->margin_footer = $this->orig_fMargin;
  8018. }
  8019. else { $resetHTMLHeadersrequired = true; } // *HTMLHEADERS-FOOTERS*
  8020. }
  8021. else {
  8022. $this->wPt=$this->fhPt;
  8023. $this->hPt=$this->fwPt;
  8024. $this->w=$this->fh;
  8025. $this->h=$this->fw;
  8026. if (($this->forcePortraitHeaders || $this->forcePortraitMargins) && $this->DefOrientation=='P') {
  8027. $this->tMargin = $this->orig_lMargin;
  8028. $this->bMargin = $this->orig_rMargin;
  8029. $this->DeflMargin = $this->orig_bMargin;
  8030. $this->DefrMargin = $this->orig_tMargin;
  8031. $this->margin_header = $this->orig_hMargin;
  8032. $this->margin_footer = $this->orig_fMargin;
  8033. }
  8034. else { $resetHTMLHeadersrequired = true; } // *HTMLHEADERS-FOOTERS*
  8035. }
  8036. $this->CurOrientation=$orientation;
  8037. $this->ResetMargins();
  8038. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  8039. $this->PageBreakTrigger=$this->h-$this->bMargin;
  8040. }
  8041. $this->pageDim[$this->page]['w']=$this->w ;
  8042. $this->pageDim[$this->page]['h']=$this->h ;
  8043. $this->pageDim[$this->page]['outer_width_LR'] = isset($this->page_box['outer_width_LR']) ? $this->page_box['outer_width_LR'] : 0;
  8044. $this->pageDim[$this->page]['outer_width_TB'] = isset($this->page_box['outer_width_TB']) ? $this->page_box['outer_width_TB'] : 0;
  8045. if (!isset($this->page_box['outer_width_LR']) && !isset($this->page_box['outer_width_TB'])) {
  8046. $this->pageDim[$this->page]['bleedMargin'] = 0;
  8047. }
  8048. else if ($this->bleedMargin <= $this->page_box['outer_width_LR'] && $this->bleedMargin <= $this->page_box['outer_width_TB']) {
  8049. $this->pageDim[$this->page]['bleedMargin'] = $this->bleedMargin;
  8050. }
  8051. else {
  8052. $this->pageDim[$this->page]['bleedMargin'] = min($this->page_box['outer_width_LR'], $this->page_box['outer_width_TB'])-0.01;
  8053. }
  8054. // If Page Margins are re-defined
  8055. // strlen()>0 is used to pick up (integer) 0, (string) '0', or set value
  8056. if ((strlen($mgl)>0 && $this->DeflMargin != $mgl) || (strlen($mgr)>0 && $this->DefrMargin != $mgr) || (strlen($mgt)>0 && $this->tMargin != $mgt) || (strlen($mgb)>0 && $this->bMargin != $mgb) || (strlen($mgh)>0 && $this->margin_header!=$mgh) || (strlen($mgf)>0 && $this->margin_footer!=$mgf)) {
  8057. if (strlen($mgl)>0) $this->DeflMargin = $mgl;
  8058. if (strlen($mgr)>0) $this->DefrMargin = $mgr;
  8059. if (strlen($mgt)>0) $this->tMargin = $mgt;
  8060. if (strlen($mgb)>0) $this->bMargin = $mgb;
  8061. if (strlen($mgh)>0) $this->margin_header=$mgh;
  8062. if (strlen($mgf)>0) $this->margin_footer=$mgf;
  8063. $this->ResetMargins();
  8064. $this->SetAutoPageBreak($this->autoPageBreak,$this->bMargin);
  8065. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  8066. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8067. }
  8068. $this->ResetMargins();
  8069. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  8070. $this->SetAutoPageBreak($this->autoPageBreak,$this->bMargin);
  8071. // Reset column top margin
  8072. $this->y0 = $this->tMargin;
  8073. $this->x=$this->lMargin;
  8074. $this->y=$this->tMargin;
  8075. $this->FontFamily='';
  8076. // HEADERS AND FOOTERS
  8077. if ($ohvalue<0 || strtoupper($ohvalue)=='OFF') {
  8078. $this->HTMLHeader = '';
  8079. $this->headerDetails['odd'] = array();
  8080. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8081. }
  8082. else if ($ohname && $ohvalue>0) {
  8083. /*-- HTMLHEADERS-FOOTERS --*/
  8084. if (preg_match('/^html_(.*)$/i',$ohname,$n)) {
  8085. if (isset($this->pageHTMLheaders[$n[1]])) { $this->HTMLHeader = $this->pageHTMLheaders[$n[1]]; }
  8086. else { $this->HTMLHeader = ''; }
  8087. $this->headerDetails['odd'] = array();
  8088. $resetHTMLHeadersrequired = true;
  8089. }
  8090. else {
  8091. /*-- END HTMLHEADERS-FOOTERS --*/
  8092. if (isset($this->pageheaders[$ohname])) { $this->headerDetails['odd'] = $this->pageheaders[$ohname]; }
  8093. else if ($ohname!='_default') { $this->headerDetails['odd'] = array(); }
  8094. $this->HTMLHeader = '';
  8095. /*-- HTMLHEADERS-FOOTERS --*/
  8096. $resetHTMLHeadersrequired = false;
  8097. }
  8098. /*-- END HTMLHEADERS-FOOTERS --*/
  8099. }
  8100. if ($ehvalue<0 || strtoupper($ehvalue)=='OFF') {
  8101. $this->HTMLHeaderE = '';
  8102. $this->headerDetails['even'] = array();
  8103. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8104. }
  8105. else if ($ehname && $ehvalue>0) {
  8106. /*-- HTMLHEADERS-FOOTERS --*/
  8107. if (preg_match('/^html_(.*)$/i',$ehname,$n)) {
  8108. if (isset($this->pageHTMLheaders[$n[1]])) { $this->HTMLHeaderE = $this->pageHTMLheaders[$n[1]]; }
  8109. else { $this->HTMLHeaderE = ''; }
  8110. $this->headerDetails['even'] = array();
  8111. $resetHTMLHeadersrequired = true;
  8112. }
  8113. else {
  8114. /*-- END HTMLHEADERS-FOOTERS --*/
  8115. if (isset($this->pageheaders[$ehname])) { $this->headerDetails['even'] = $this->pageheaders[$ehname]; }
  8116. else if ($ehname!='_default') { $this->headerDetails['even'] = array(); }
  8117. $this->HTMLHeaderE = '';
  8118. /*-- HTMLHEADERS-FOOTERS --*/
  8119. $resetHTMLHeadersrequired = false;
  8120. }
  8121. /*-- END HTMLHEADERS-FOOTERS --*/
  8122. }
  8123. if ($ofvalue<0 || strtoupper($ofvalue)=='OFF') {
  8124. $this->HTMLFooter = '';
  8125. $this->footerDetails['odd'] = array();
  8126. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8127. }
  8128. else if ($ofname && $ofvalue>0) {
  8129. /*-- HTMLHEADERS-FOOTERS --*/
  8130. if (preg_match('/^html_(.*)$/i',$ofname,$n)) {
  8131. if (isset($this->pageHTMLfooters[$n[1]])) { $this->HTMLFooter = $this->pageHTMLfooters[$n[1]]; }
  8132. else { $this->HTMLFooter = ''; }
  8133. $this->footerDetails['odd'] = array();
  8134. $resetHTMLHeadersrequired = true;
  8135. }
  8136. else {
  8137. /*-- END HTMLHEADERS-FOOTERS --*/
  8138. if (isset($this->pagefooters[$ofname])) { $this->footerDetails['odd'] = $this->pagefooters[$ofname]; }
  8139. else if ($ofname!='_default') { $this->footerDetails['odd'] = array(); }
  8140. $this->HTMLFooter = '';
  8141. /*-- HTMLHEADERS-FOOTERS --*/
  8142. $resetHTMLHeadersrequired = true;
  8143. }
  8144. /*-- END HTMLHEADERS-FOOTERS --*/
  8145. }
  8146. if ($efvalue<0 || strtoupper($efvalue)=='OFF') {
  8147. $this->HTMLFooterE = '';
  8148. $this->footerDetails['even'] = array();
  8149. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8150. }
  8151. else if ($efname && $efvalue>0) {
  8152. /*-- HTMLHEADERS-FOOTERS --*/
  8153. if (preg_match('/^html_(.*)$/i',$efname,$n)) {
  8154. if (isset($this->pageHTMLfooters[$n[1]])) { $this->HTMLFooterE = $this->pageHTMLfooters[$n[1]]; }
  8155. else { $this->HTMLFooterE = ''; }
  8156. $this->footerDetails['even'] = array();
  8157. $resetHTMLHeadersrequired = true;
  8158. }
  8159. else {
  8160. /*-- END HTMLHEADERS-FOOTERS --*/
  8161. if (isset($this->pagefooters[$efname])) { $this->footerDetails['even'] = $this->pagefooters[$efname]; }
  8162. else if ($efname!='_default') { $this->footerDetails['even'] = array(); }
  8163. $this->HTMLFooterE = '';
  8164. /*-- HTMLHEADERS-FOOTERS --*/
  8165. $resetHTMLHeadersrequired = true;
  8166. }
  8167. /*-- END HTMLHEADERS-FOOTERS --*/
  8168. }
  8169. /*-- HTMLHEADERS-FOOTERS --*/
  8170. if ($resetHTMLHeadersrequired) {
  8171. $this->SetHTMLHeader($this->HTMLHeader );
  8172. $this->SetHTMLHeader($this->HTMLHeaderE ,'E');
  8173. $this->SetHTMLFooter($this->HTMLFooter );
  8174. $this->SetHTMLFooter($this->HTMLFooterE ,'E');
  8175. }
  8176. /*-- END HTMLHEADERS-FOOTERS --*/
  8177. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  8178. $this->_setAutoHeaderHeight($this->headerDetails['even'], $this->HTMLHeaderE);
  8179. $this->_setAutoFooterHeight($this->footerDetails['even'], $this->HTMLFooterE);
  8180. }
  8181. else { // ODD or DEFAULT
  8182. $this->_setAutoHeaderHeight($this->headerDetails['odd'], $this->HTMLHeader);
  8183. $this->_setAutoFooterHeight($this->footerDetails['odd'], $this->HTMLFooter);
  8184. }
  8185. // Reset column top margin
  8186. $this->y0 = $this->tMargin;
  8187. $this->x=$this->lMargin;
  8188. $this->y=$this->tMargin;
  8189. }
  8190. function _setAutoHeaderHeight(&$det, &$htmlh) {
  8191. if ($this->setAutoTopMargin=='pad') {
  8192. if ($htmlh['h']) { $h = $htmlh['h']; }
  8193. else if ($det) { $h = $this->_getHFHeight($det,'H'); }
  8194. else { $h = 0; }
  8195. $this->tMargin = $this->margin_header + $h + $this->orig_tMargin;
  8196. }
  8197. else if ($this->setAutoTopMargin=='stretch') {
  8198. if ($htmlh['h']) { $h = $htmlh['h']; }
  8199. else if ($det) { $h = $this->_getHFHeight($det,'H'); }
  8200. else { $h = 0; }
  8201. $this->tMargin = max($this->orig_tMargin, $this->margin_header + $h + $this->autoMarginPadding);
  8202. }
  8203. }
  8204. function _setAutoFooterHeight(&$det, &$htmlf) {
  8205. if ($this->setAutoBottomMargin=='pad') {
  8206. if ($htmlf['h']) { $h = $htmlf['h']; }
  8207. else if ($det) { $h = $this->_getHFHeight($det,'F'); }
  8208. else { $h = 0; }
  8209. $this->bMargin = $this->margin_footer + $h + $this->orig_bMargin;
  8210. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  8211. }
  8212. else if ($this->setAutoBottomMargin=='stretch') {
  8213. if ($htmlf['h']) { $h = $htmlf['h']; }
  8214. else if ($det) { $h = $this->_getHFHeight($det,'F'); }
  8215. else { $h = 0; }
  8216. $this->bMargin = max($this->orig_bMargin, $this->margin_footer + $h + $this->autoMarginPadding);
  8217. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  8218. }
  8219. }
  8220. function _getHFHeight(&$det,$end) {
  8221. $h = 0;
  8222. if(count($det)) {
  8223. foreach(array('L','C','R') AS $pos) {
  8224. if (isset($det[$pos]['content']) && $det[$pos]['content']) {
  8225. if (isset($det[$pos]['font-size']) && $det[$pos]['font-size']) { $hfsz = $det[$pos]['font-size']; }
  8226. else { $hfsz = $this->default_font_size; }
  8227. $h = max($h,$hfsz/_MPDFK);
  8228. }
  8229. }
  8230. if ($det['line'] && $end=='H') { $h += $h/_MPDFK*$this->header_line_spacing; }
  8231. else if ($det['line'] && $end=='F') { $h += $h/_MPDFK*$this->footer_line_spacing; }
  8232. }
  8233. return $h;
  8234. }
  8235. function _endpage() {
  8236. /*-- CSS-IMAGE-FLOAT --*/
  8237. $this->printfloatbuffer();
  8238. /*-- END CSS-IMAGE-FLOAT --*/
  8239. // mPDF 5.3.41
  8240. if($this->visibility!='visible')
  8241. $this->SetVisibility('visible');
  8242. //End of page contents
  8243. $this->state=1;
  8244. }
  8245. function _newobj($obj_id=false,$onlynewobj=false) {
  8246. if (!$obj_id) {
  8247. $obj_id = ++$this->n;
  8248. }
  8249. //Begin a new object
  8250. if (!$onlynewobj) {
  8251. $this->offsets[$obj_id] = strlen($this->buffer);
  8252. $this->_out($obj_id.' 0 obj');
  8253. $this->_current_obj_id = $obj_id; // for later use with encryption
  8254. }
  8255. }
  8256. function _dounderline($x,$y,$txt) {
  8257. // Now print line exactly where $y secifies - called from Text() and Cell() - adjust position there
  8258. // WORD SPACING
  8259. $w =($this->GetStringWidth($txt)*_MPDFK) + ($this->charspacing * mb_strlen( $txt, $this->mb_enc ))
  8260. + ( $this->ws * mb_substr_count( $txt, ' ', $this->mb_enc ));
  8261. //Draw a line
  8262. return sprintf('%.3F %.3F m %.3F %.3F l S',$x*_MPDFK,($this->h-$y)*_MPDFK,($x*_MPDFK)+$w,($this->h-$y)*_MPDFK);
  8263. }
  8264. function _imageError($file, $firsttime, $msg) {
  8265. // Save re-trying image URL's which have already failed
  8266. $this->failedimages[$file] = true;
  8267. if ($firsttime && ($this->showImageErrors || $this->debug)) {
  8268. $this->Error("IMAGE Error (".$file."): ".$msg);
  8269. }
  8270. return false;
  8271. }
  8272. function _getImage(&$file, $firsttime=true, $allowvector=true, $orig_srcpath=false) {
  8273. // firsttime i.e. whether to add to this->images - use false when calling iteratively
  8274. // mPDF 5.3.95
  8275. $file = urldecode($file);
  8276. if ($orig_srcpath) { $orig_srcpath = urldecode($orig_srcpath); }
  8277. // Image Data passed directly as var:varname
  8278. if (preg_match('/var:\s*(.*)/',$file, $v)) {
  8279. $data = $this->$v[1];
  8280. $file = md5($data);
  8281. }
  8282. $ppUx = 0;
  8283. if ($firsttime && preg_match('/(.*\/)([^\/]*)/',$file,$fm)) {
  8284. if (strlen($fm[2])) { $file = $fm[1].preg_replace('/ /','%20',$fm[2]); }
  8285. }
  8286. if ($orig_srcpath && isset($this->images[$orig_srcpath])) { $file=$orig_srcpath; return $this->images[$orig_srcpath]; }
  8287. if (isset($this->images[$file])) { return $this->images[$file]; }
  8288. else if ($orig_srcpath && isset($this->formobjects[$orig_srcpath])) { $file=$orig_srcpath; return $this->formobjects[$file]; }
  8289. else if (isset($this->formobjects[$file])) { return $this->formobjects[$file]; }
  8290. // Save re-trying image URL's which have already failed
  8291. else if ($firsttime && isset($this->failedimages[$file])) { return $this->_imageError($file, $firsttime, ''); }
  8292. if (empty($data)) {
  8293. $type = '';
  8294. $data = '';
  8295. $mqr=$this->_getMQR();
  8296. if ($mqr) { set_magic_quotes_runtime(0); }
  8297. if ($orig_srcpath && $this->basepathIsLocal && $check = @fopen($orig_srcpath,"rb")) {
  8298. fclose($check);
  8299. $file=$orig_srcpath;
  8300. $data = file_get_contents($file);
  8301. $type = $this->_imageTypeFromString($data);
  8302. }
  8303. if (!$data && $check = @fopen($file,"rb")) {
  8304. fclose($check);
  8305. $data = file_get_contents($file);
  8306. $type = $this->_imageTypeFromString($data);
  8307. }
  8308. if ((!$data || !$type) && !ini_get('allow_url_fopen')) { // only worth trying if remote file and !ini_get('allow_url_fopen')
  8309. $this->file_get_contents_by_socket($file, $data); // needs full url?? even on local (never needed for local)
  8310. if ($data) { $type = $this->_imageTypeFromString($data); }
  8311. }
  8312. if ((!$data || !$type) && !ini_get('allow_url_fopen') && function_exists("curl_init")) {
  8313. $this->file_get_contents_by_curl($file, $data); // needs full url?? even on local (never needed for local)
  8314. if ($data) { $type = $this->_imageTypeFromString($data); }
  8315. }
  8316. if ($mqr) { set_magic_quotes_runtime($mqr); }
  8317. }
  8318. if (!$data) { return $this->_imageError($file, $firsttime, 'Could not find image file'); }
  8319. if (empty($type)) { $type = $this->_imageTypeFromString($data); }
  8320. if (($type == 'wmf' || $type == 'svg') && !$allowvector) { return $this->_imageError($file, $firsttime, 'WMF or SVG image file not supported in this context'); }
  8321. // SVG
  8322. if ($type == 'svg') {
  8323. if (!class_exists('SVG', false)) { include(_MPDF_PATH .'classes/svg.php'); }
  8324. $svg = new SVG($this);
  8325. $family=$this->FontFamily;
  8326. $style=$this->FontStyle;
  8327. $size=$this->FontSizePt;
  8328. $info = $svg->ImageSVG($data);
  8329. //Restore font
  8330. if($family) $this->SetFont($family,$style,$size,false);
  8331. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing SVG file'); }
  8332. $info['type']='svg';
  8333. $info['i']=count($this->formobjects)+1;
  8334. $this->formobjects[$file]=$info;
  8335. return $info;
  8336. }
  8337. // JPEG
  8338. if ($type == 'jpeg' || $type == 'jpg') {
  8339. $hdr = $this->_jpgHeaderFromString($data);
  8340. if (!$hdr) { return $this->_imageError($file, $firsttime, 'Error parsing JPG header'); }
  8341. $a = $this->_jpgDataFromHeader($hdr);
  8342. $j = strpos($data,'JFIF');
  8343. if ($j) {
  8344. //Read resolution
  8345. $unitSp=ord(substr($data,($j+7),1));
  8346. if ($unitSp > 0) {
  8347. $ppUx=$this->_twobytes2int(substr($data,($j+8),2)); // horizontal pixels per meter, usually set to zero
  8348. if ($unitSp == 2) { // = dots per cm (if == 1 set as dpi)
  8349. $ppUx=round($ppUx/10 *25.4);
  8350. }
  8351. }
  8352. }
  8353. if ($a[2] == 'DeviceCMYK' && (($this->PDFA && $this->restrictColorSpace!=3) || $this->restrictColorSpace==2)) {
  8354. // convert to RGB image
  8355. if (!function_exists("gd_info")) { $this->Error("JPG image may not use CMYK color space (".$file.")."); }
  8356. if ($this->PDFA && !$this->PDFAauto) { $this->PDFAXwarnings[] = "JPG image may not use CMYK color space - ".$file." - (Image converted to RGB. NB This will alter the colour profile of the image.)"; }
  8357. $im = @imagecreatefromstring($data);
  8358. if ($im) {
  8359. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png';
  8360. imageinterlace($im, false);
  8361. $check = @imagepng($im, $tempfile);
  8362. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse JPG(CMYK) image'); }
  8363. $info = $this->_getImage($tempfile, false);
  8364. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse JPG(CMYK) image'); }
  8365. imagedestroy($im);
  8366. unlink($tempfile);
  8367. $info['type']='jpg';
  8368. if ($firsttime) {
  8369. $info['i']=count($this->images)+1;
  8370. $this->images[$file]=$info;
  8371. }
  8372. return $info;
  8373. }
  8374. else { return $this->_imageError($file, $firsttime, 'Error creating GD image file from JPG(CMYK) image'); }
  8375. }
  8376. else if ($a[2] == 'DeviceRGB' && ($this->PDFX || $this->restrictColorSpace==3)) {
  8377. // Convert to CMYK image stream - nominally returned as type='png'
  8378. $info = $this->_convImage($data, $a[2], 'DeviceCMYK', $a[0], $a[1], $ppUx, false);
  8379. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "JPG image may not use RGB color space - ".$file." - (Image converted to CMYK. NB This will alter the colour profile of the image.)"; }
  8380. }
  8381. else if (($a[2] == 'DeviceRGB' || $a[2] == 'DeviceCMYK') && $this->restrictColorSpace==1) {
  8382. // Convert to Grayscale image stream - nominally returned as type='png'
  8383. $info = $this->_convImage($data, $a[2], 'DeviceGray', $a[0], $a[1], $ppUx, false);
  8384. }
  8385. else {
  8386. $info = array('w'=>$a[0],'h'=>$a[1],'cs'=>$a[2],'bpc'=>$a[3],'f'=>'DCTDecode','data'=>$data, 'type'=>'jpg');
  8387. if ($ppUx) { $info['set-dpi'] = $ppUx; }
  8388. }
  8389. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing or converting JPG image'); }
  8390. if ($firsttime) {
  8391. $info['i']=count($this->images)+1;
  8392. $this->images[$file]=$info;
  8393. }
  8394. return $info;
  8395. }
  8396. // PNG
  8397. else if ($type == 'png') {
  8398. //Check signature
  8399. if(substr($data,0,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
  8400. return $this->_imageError($file, $firsttime, 'Error parsing PNG identifier');
  8401. }
  8402. //Read header chunk
  8403. if(substr($data,12,4)!='IHDR') {
  8404. return $this->_imageError($file, $firsttime, 'Incorrect PNG file (no IHDR block found)');
  8405. }
  8406. $w=$this->_fourbytes2int(substr($data,16,4));
  8407. $h=$this->_fourbytes2int(substr($data,20,4));
  8408. $bpc=ord(substr($data,24,1));
  8409. $errpng = false;
  8410. $pngalpha = false;
  8411. if($bpc>8) { $errpng = 'not 8-bit depth'; }
  8412. $ct=ord(substr($data,25,1));
  8413. if($ct==0) { $colspace='DeviceGray'; }
  8414. elseif($ct==2) { $colspace='DeviceRGB'; }
  8415. elseif($ct==3) { $colspace='Indexed'; }
  8416. elseif($ct==4) { $colspace='DeviceGray'; $errpng = 'alpha channel'; $pngalpha = true; }
  8417. else { $colspace='DeviceRGB'; $errpng = 'alpha channel'; $pngalpha = true; }
  8418. if(ord(substr($data,26,1))!=0) { $errpng = 'compression method'; }
  8419. if(ord(substr($data,27,1))!=0) { $errpng = 'filter method'; }
  8420. if(ord(substr($data,28,1))!=0) { $errpng = 'interlaced file'; }
  8421. $j = strpos($data,'pHYs');
  8422. if ($j) {
  8423. //Read resolution
  8424. $unitSp=ord(substr($data,($j+12),1));
  8425. if ($unitSp == 1) {
  8426. $ppUx=$this->_fourbytes2int(substr($data,($j+4),4)); // horizontal pixels per meter, usually set to zero
  8427. $ppUx=round($ppUx/1000 *25.4);
  8428. }
  8429. }
  8430. if (($colspace == 'DeviceRGB' || $colspace == 'Indexed') && ($this->PDFX || $this->restrictColorSpace==3)) {
  8431. // Convert to CMYK image stream - nominally returned as type='png'
  8432. $info = $this->_convImage($data, $colspace, 'DeviceCMYK', $w, $h, $ppUx, $pngalpha);
  8433. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "PNG image may not use RGB color space - ".$file." - (Image converted to CMYK. NB This will alter the colour profile of the image.)"; }
  8434. }
  8435. else if (($colspace == 'DeviceRGB' || $colspace == 'Indexed') && $this->restrictColorSpace==1) {
  8436. // Convert to Grayscale image stream - nominally returned as type='png'
  8437. $info = $this->_convImage($data, $colspace, 'DeviceGray', $w, $h, $ppUx, $pngalpha);
  8438. }
  8439. else if (($this->PDFA || $this->PDFX) && $pngalpha) {
  8440. // Remove alpha channel
  8441. if ($this->restrictColorSpace==1) { // Grayscale
  8442. $info = $this->_convImage($data, $colspace, 'DeviceGray', $w, $h, $ppUx, $pngalpha);
  8443. }
  8444. else if ($this->restrictColorSpace==3) { // CMYK
  8445. $info = $this->_convImage($data, $colspace, 'DeviceCMYK', $w, $h, $ppUx, $pngalpha);
  8446. }
  8447. else if ($this->PDFA ) { // RGB
  8448. $info = $this->_convImage($data, $colspace, 'DeviceRGB', $w, $h, $ppUx, $pngalpha);
  8449. }
  8450. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "Transparency (alpha channel) not permitted in PDFA or PDFX files - ".$file." - (Image converted to one without transparency.)"; }
  8451. }
  8452. else if ($errpng || $pngalpha) {
  8453. if (function_exists('gd_info')) { $gd = gd_info(); }
  8454. else {$gd = array(); }
  8455. if (!isset($gd['PNG Support'])) { return $this->_imageError($file, $firsttime, 'GD library required for PNG image ('.$errpng.')'); }
  8456. $im = imagecreatefromstring($data);
  8457. if (!$im) { return $this->_imageError($file, $firsttime, 'Error creating GD image from PNG file ('.$errpng.')'); }
  8458. $w = imagesx($im);
  8459. $h = imagesy($im);
  8460. if ($im) {
  8461. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png';
  8462. // Alpha channel set
  8463. if ($pngalpha) {
  8464. if ($this->PDFA) { $this->Error("PDFA1-b does not permit images with alpha channel transparency (".$file.")."); }
  8465. $imgalpha = imagecreate($w, $h);
  8466. // generate gray scale pallete
  8467. for ($c = 0; $c < 256; ++$c) { ImageColorAllocate($imgalpha, $c, $c, $c); }
  8468. // extract alpha channel
  8469. $gammacorr = 2.2; // gamma correction // mPDF 5.3.07
  8470. for ($xpx = 0; $xpx < $w; ++$xpx) {
  8471. for ($ypx = 0; $ypx < $h; ++$ypx) {
  8472. // mPDF 5.3.07
  8473. //$colorindex = imagecolorat($im, $xpx, $ypx);
  8474. //$col = imagecolorsforindex($im, $colorindex);
  8475. //$gamma2 = (pow((((127 - $col['alpha']) * 255 / 127) / 255), $gammacorr) * 255);
  8476. $alpha = (imagecolorat($im, $xpx, $ypx) & 0x7F000000) >> 24;
  8477. if ($alpha < 127) {
  8478. if ($alpha==0) { $gamma = 255; }
  8479. else
  8480. $gamma = (pow((((127 - $alpha) * 255 / 127) / 255), $gammacorr) * 255);
  8481. imagesetpixel($imgalpha, $xpx, $ypx, $gamma);
  8482. }
  8483. }
  8484. }
  8485. // create temp alpha file
  8486. $tempfile_alpha = _MPDF_TEMP_PATH.'_tempMskPNG'.RAND(1,10000).'.png';
  8487. if (!is_writable($tempfile_alpha)) {
  8488. ob_start();
  8489. $check = @imagepng($imgalpha);
  8490. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse PNG image'); }
  8491. imagedestroy($imgalpha);
  8492. $this->_tempimg = ob_get_contents();
  8493. $this->_tempimglnk = 'var:_tempimg';
  8494. ob_end_clean();
  8495. // extract image without alpha channel
  8496. $imgplain = imagecreatetruecolor($w, $h);
  8497. imagecopy($imgplain, $im, 0, 0, 0, 0, $w, $h);
  8498. // create temp image file
  8499. $minfo = $this->_getImage($this->_tempimglnk, false);
  8500. if (!$minfo) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse PNG image'); }
  8501. ob_start();
  8502. $check = @imagepng($imgplain);
  8503. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse PNG image'); }
  8504. $this->_tempimg = ob_get_contents();
  8505. $this->_tempimglnk = 'var:_tempimg';
  8506. ob_end_clean();
  8507. $info = $this->_getImage($this->_tempimglnk, false);
  8508. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse PNG image'); }
  8509. imagedestroy($imgplain);
  8510. $imgmask = count($this->images)+1;
  8511. $minfo['cs'] = 'DeviceGray';
  8512. $minfo['i']=$imgmask ;
  8513. $this->images[$tempfile_alpha] = $minfo;
  8514. }
  8515. else {
  8516. $check = @imagepng($imgalpha, $tempfile_alpha);
  8517. if (!$check) { return $this->_imageError($file, $firsttime, 'Failed to create temporary image file ('.$tempfile_alpha.') parsing PNG image with alpha channel ('.$errpng.')'); }
  8518. imagedestroy($imgalpha);
  8519. // extract image without alpha channel
  8520. $imgplain = imagecreatetruecolor($w, $h);
  8521. imagecopy($imgplain, $im, 0, 0, 0, 0, $w, $h);
  8522. // create temp image file
  8523. $check = @imagepng($imgplain, $tempfile);
  8524. if (!$check) { return $this->_imageError($file, $firsttime, 'Failed to create temporary image file ('.$tempfile.') parsing PNG image with alpha channel ('.$errpng.')'); }
  8525. imagedestroy($imgplain);
  8526. // embed mask image
  8527. $minfo = $this->_getImage($tempfile_alpha, false);
  8528. unlink($tempfile_alpha);
  8529. if (!$minfo) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile_alpha.') created with GD library to parse PNG image'); }
  8530. $imgmask = count($this->images)+1;
  8531. $minfo['cs'] = 'DeviceGray';
  8532. $minfo['i']=$imgmask ;
  8533. $this->images[$tempfile_alpha] = $minfo;
  8534. // embed image, masked with previously embedded mask
  8535. $info = $this->_getImage($tempfile, false);
  8536. unlink($tempfile);
  8537. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse PNG image'); }
  8538. }
  8539. $info['masked'] = $imgmask;
  8540. if ($ppUx) { $info['set-dpi'] = $ppUx; }
  8541. $info['type']='png';
  8542. if ($firsttime) {
  8543. $info['i']=count($this->images)+1;
  8544. $this->images[$file]=$info;
  8545. }
  8546. return $info;
  8547. }
  8548. else { // No alpha/transparency set
  8549. imagealphablending($im, false);
  8550. imagesavealpha($im, false);
  8551. imageinterlace($im, false);
  8552. if (!is_writable($tempfile)) {
  8553. ob_start();
  8554. $check = @imagepng($im);
  8555. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse PNG image'); }
  8556. $this->_tempimg = ob_get_contents();
  8557. $this->_tempimglnk = 'var:_tempimg';
  8558. ob_end_clean();
  8559. $info = $this->_getImage($this->_tempimglnk, false);
  8560. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse PNG image'); }
  8561. imagedestroy($im);
  8562. }
  8563. else {
  8564. $check = @imagepng($im, $tempfile );
  8565. if (!$check) { return $this->_imageError($file, $firsttime, 'Failed to create temporary image file ('.$tempfile.') parsing PNG image ('.$errpng.')'); }
  8566. imagedestroy($im);
  8567. $info = $this->_getImage($tempfile, false) ;
  8568. unlink($tempfile );
  8569. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse PNG image'); }
  8570. }
  8571. if ($ppUx) { $info['set-dpi'] = $ppUx; }
  8572. $info['type']='png';
  8573. if ($firsttime) {
  8574. $info['i']=count($this->images)+1;
  8575. $this->images[$file]=$info;
  8576. }
  8577. return $info;
  8578. }
  8579. }
  8580. }
  8581. else {
  8582. $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';
  8583. //Scan chunks looking for palette, transparency and image data
  8584. $pal='';
  8585. $trns='';
  8586. $pngdata='';
  8587. $p = 33;
  8588. do {
  8589. $n=$this->_fourbytes2int(substr($data,$p,4)); $p += 4;
  8590. $type=substr($data,$p,4); $p += 4;
  8591. if($type=='PLTE') {
  8592. //Read palette
  8593. $pal=substr($data,$p,$n); $p += $n;
  8594. $p += 4;
  8595. }
  8596. elseif($type=='tRNS') {
  8597. //Read transparency info
  8598. $t=substr($data,$p,$n); $p += $n;
  8599. if($ct==0) $trns=array(ord(substr($t,1,1)));
  8600. elseif($ct==2) $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1)));
  8601. else
  8602. {
  8603. $pos=strpos($t,chr(0));
  8604. if(is_int($pos)) $trns=array($pos);
  8605. }
  8606. $p += 4;
  8607. }
  8608. elseif($type=='IDAT') {
  8609. $pngdata.=substr($data,$p,$n); $p += $n;
  8610. $p += 4;
  8611. }
  8612. elseif($type=='IEND') { break; }
  8613. else if (preg_match('/[a-zA-Z]{4}/',$type)) { $p += $n+4; }
  8614. else { return $this->_imageError($file, $firsttime, 'Error parsing PNG image data'); }
  8615. }
  8616. while($n);
  8617. if (!$pngdata) { return $this->_imageError($file, $firsttime, 'Error parsing PNG image data - no IDAT data found'); }
  8618. if($colspace=='Indexed' and empty($pal)) { return $this->_imageError($file, $firsttime, 'Error parsing PNG image data - missing colour palette'); }
  8619. $info = array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$pngdata);
  8620. $info['type']='png';
  8621. if ($ppUx) { $info['set-dpi'] = $ppUx; }
  8622. }
  8623. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing or converting PNG image'); }
  8624. if ($firsttime) {
  8625. $info['i']=count($this->images)+1;
  8626. $this->images[$file]=$info;
  8627. }
  8628. return $info;
  8629. }
  8630. // GIF
  8631. else if ($type == 'gif') {
  8632. if (function_exists('gd_info')) { $gd = gd_info(); }
  8633. else {$gd = array(); }
  8634. if (isset($gd['GIF Read Support']) && $gd['GIF Read Support']) {
  8635. $im = @imagecreatefromstring($data);
  8636. if ($im) {
  8637. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png';
  8638. imagealphablending($im, false);
  8639. imagesavealpha($im, false);
  8640. imageinterlace($im, false);
  8641. if (!is_writable($tempfile)) {
  8642. ob_start();
  8643. $check = @imagepng($im);
  8644. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse GIF image'); }
  8645. $this->_tempimg = ob_get_contents();
  8646. $this->_tempimglnk = 'var:_tempimg';
  8647. ob_end_clean();
  8648. $info = $this->_getImage($this->_tempimglnk, false);
  8649. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse GIF image'); }
  8650. imagedestroy($im);
  8651. }
  8652. else {
  8653. $check = @imagepng($im, $tempfile);
  8654. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse GIF image'); }
  8655. $info = $this->_getImage($tempfile, false);
  8656. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse GIF image'); }
  8657. imagedestroy($im);
  8658. unlink($tempfile);
  8659. }
  8660. $info['type']='gif';
  8661. if ($firsttime) {
  8662. $info['i']=count($this->images)+1;
  8663. $this->images[$file]=$info;
  8664. }
  8665. return $info;
  8666. }
  8667. else { return $this->_imageError($file, $firsttime, 'Error creating GD image file from GIF image'); }
  8668. }
  8669. if (!class_exists('gif', false)) {
  8670. include_once(_MPDF_PATH.'classes/gif.php');
  8671. }
  8672. $gif=new CGIF();
  8673. $h=0;
  8674. $w=0;
  8675. $gif->loadFile($data, 0);
  8676. if(isset($gif->m_img->m_gih->m_bLocalClr) && $gif->m_img->m_gih->m_bLocalClr) {
  8677. $nColors = $gif->m_img->m_gih->m_nTableSize;
  8678. $pal = $gif->m_img->m_gih->m_colorTable->toString();
  8679. if($bgColor != -1) {
  8680. $bgColor = $gif->m_img->m_gih->m_colorTable->colorIndex($bgColor);
  8681. }
  8682. $colspace='Indexed';
  8683. } elseif(isset($gif->m_gfh->m_bGlobalClr) && $gif->m_gfh->m_bGlobalClr) {
  8684. $nColors = $gif->m_gfh->m_nTableSize;
  8685. $pal = $gif->m_gfh->m_colorTable->toString();
  8686. if((isset($bgColor)) and $bgColor != -1) {
  8687. $bgColor = $gif->m_gfh->m_colorTable->colorIndex($bgColor);
  8688. }
  8689. $colspace='Indexed';
  8690. } else {
  8691. $nColors = 0;
  8692. $bgColor = -1;
  8693. $colspace='DeviceGray';
  8694. $pal='';
  8695. }
  8696. $trns='';
  8697. if(isset($gif->m_img->m_bTrans) && $gif->m_img->m_bTrans && ($nColors > 0)) {
  8698. $trns=array($gif->m_img->m_nTrans);
  8699. }
  8700. $gifdata=$gif->m_img->m_data;
  8701. $w=$gif->m_gfh->m_nWidth;
  8702. $h=$gif->m_gfh->m_nHeight;
  8703. $gif->ClearData();
  8704. if($colspace=='Indexed' and empty($pal)) {
  8705. return $this->_imageError($file, $firsttime, 'Error parsing GIF image - missing colour palette');
  8706. }
  8707. if ($this->compress) {
  8708. $gifdata=gzcompress($gifdata);
  8709. $info = array( 'w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>8, 'f'=>'FlateDecode', 'pal'=>$pal, 'trns'=>$trns, 'data'=>$gifdata);
  8710. }
  8711. else {
  8712. $info = array( 'w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>8, 'pal'=>$pal, 'trns'=>$trns, 'data'=>$gifdata);
  8713. }
  8714. $info['type']='gif';
  8715. if ($firsttime) {
  8716. $info['i']=count($this->images)+1;
  8717. $this->images[$file]=$info;
  8718. }
  8719. return $info;
  8720. }
  8721. /*-- IMAGES-BMP --*/
  8722. // BMP (Windows Bitmap)
  8723. else if ($type == 'bmp') {
  8724. // mPDF 5.3.89
  8725. if (!class_exists('bmp', false)) { include(_MPDF_PATH.'classes/bmp.php'); }
  8726. if (empty($this->bmp)) { $this->bmp = new bmp($this); }
  8727. $info = $this->bmp->_getBMPimage($data, $file);
  8728. if (isset($info['error'])) {
  8729. return $this->_imageError($file, $firsttime, $info['error']);
  8730. }
  8731. if ($firsttime) {
  8732. $info['i']=count($this->images)+1;
  8733. $this->images[$file]=$info;
  8734. }
  8735. return $info;
  8736. }
  8737. /*-- END IMAGES-BMP --*/
  8738. /*-- IMAGES-WMF --*/
  8739. // WMF
  8740. else if ($type == 'wmf') {
  8741. // mPDF 5.3.89
  8742. if (!class_exists('wmf', false)) { include(_MPDF_PATH.'classes/wmf.php'); }
  8743. if (empty($this->wmf)) { $this->wmf = new wmf($this); }
  8744. $wmfres = $this->wmf->_getWMFimage($data);
  8745. if ($wmfres[0]==0) {
  8746. if ($wmfres[1]) { return $this->_imageError($file, $firsttime, $wmfres[1]); }
  8747. return $this->_imageError($file, $firsttime, 'Error parsing WMF image');
  8748. }
  8749. $info = array('x'=>$wmfres[2][0],'y'=>$wmfres[2][1],'w'=>$wmfres[3][0],'h'=>$wmfres[3][1],'data'=>$wmfres[1]);
  8750. $info['i']=count($this->formobjects)+1;
  8751. $info['type']='wmf';
  8752. $this->formobjects[$file]=$info;
  8753. return $info;
  8754. }
  8755. /*-- END IMAGES-WMF --*/
  8756. // UNKNOWN TYPE - try GD imagecreatefromstring
  8757. else {
  8758. if (function_exists('gd_info')) { $gd = gd_info(); }
  8759. else {$gd = array(); }
  8760. if (isset($gd['PNG Support']) && $gd['PNG Support']) {
  8761. $im = @imagecreatefromstring($data);
  8762. if (!$im) { return $this->_imageError($file, $firsttime, 'Error parsing image file - image type not recognised, and not supported by GD imagecreate'); }
  8763. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png';
  8764. imagealphablending($im, false);
  8765. imagesavealpha($im, false);
  8766. imageinterlace($im, false);
  8767. $check = @imagepng($im, $tempfile);
  8768. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse unknown image type'); }
  8769. $info = $this->_getImage($tempfile, false);
  8770. imagedestroy($im);
  8771. unlink($tempfile);
  8772. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse unknown image type'); }
  8773. $info['type']='png';
  8774. if ($firsttime) {
  8775. $info['i']=count($this->images)+1;
  8776. $this->images[$file]=$info;
  8777. }
  8778. return $info;
  8779. }
  8780. }
  8781. return $this->_imageError($file, $firsttime, 'Error parsing image file - image type not recognised');
  8782. }
  8783. //==============================================================
  8784. function _convImage(&$data, $colspace, $targetcs, $w, $h, $dpi, $mask) {
  8785. if ($this->PDFA || $this->PDFX) { $mask=false; }
  8786. $im = @imagecreatefromstring($data);
  8787. $info = array();
  8788. if ($im) {
  8789. $imgdata = '';
  8790. $mimgdata = '';
  8791. $minfo = array();
  8792. //Read transparency info
  8793. $trns=array();
  8794. $trnsrgb = false;
  8795. if (!$this->PDFA && !$this->PDFX) {
  8796. $p = strpos($data,'tRNS');
  8797. if ($p) {
  8798. $n=$this->_fourbytes2int(substr($data,($p-4),4));
  8799. $t = substr($data,($p+4),$n);
  8800. if ($colspace=='DeviceGray') {
  8801. $trns=array(ord(substr($t,1,1)));
  8802. $trnsrgb = array($trns[0],$trns[0],$trns[0]);
  8803. }
  8804. else if ($colspace=='DeviceRGB') {
  8805. $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1)));
  8806. $trnsrgb = $trns;
  8807. if ($targetcs=='DeviceCMYK') {
  8808. $col = $this->rgb2cmyk(array(3,$trns[0],$trns[1],$trns[2]));
  8809. $c1 = intval($col[1]*2.55);
  8810. $c2 = intval($col[2]*2.55);
  8811. $c3 = intval($col[3]*2.55);
  8812. $c4 = intval($col[4]*2.55);
  8813. $trns = array($c1,$c2,$c3,$c4);
  8814. }
  8815. else if ($targetcs=='DeviceGray') {
  8816. $c = intval(($trns[0] * .21) + ($trns[1] * .71) + ($trns[2] * .07));
  8817. $trns = array($c);
  8818. }
  8819. }
  8820. else { // Indexed
  8821. $pos = strpos($t,chr(0));
  8822. if (is_int($pos)) {
  8823. $pal = imagecolorsforindex($im, $pos);
  8824. $r = $pal['red'];
  8825. $g = $pal['green'];
  8826. $b = $pal['blue'];
  8827. $trns=array($r,$g,$b); // ****
  8828. $trnsrgb = $trns;
  8829. if ($targetcs=='DeviceCMYK') {
  8830. $col = $this->rgb2cmyk(array(3,$r,$g,$b));
  8831. $c1 = intval($col[1]*2.55);
  8832. $c2 = intval($col[2]*2.55);
  8833. $c3 = intval($col[3]*2.55);
  8834. $c4 = intval($col[4]*2.55);
  8835. $trns = array($c1,$c2,$c3,$c4);
  8836. }
  8837. else if ($targetcs=='DeviceGray') {
  8838. $c = intval(($r * .21) + ($g * .71) + ($b * .07));
  8839. $trns = array($c);
  8840. }
  8841. }
  8842. }
  8843. }
  8844. }
  8845. for ($i = 0; $i < $h; $i++) {
  8846. for ($j = 0; $j < $w; $j++) {
  8847. $rgb = imagecolorat($im, $j, $i);
  8848. $r = ($rgb >> 16) & 0xFF;
  8849. $g = ($rgb >> 8) & 0xFF;
  8850. $b = $rgb & 0xFF;
  8851. if ($colspace=='Indexed') {
  8852. $pal = imagecolorsforindex($im, $rgb);
  8853. $r = $pal['red'];
  8854. $g = $pal['green'];
  8855. $b = $pal['blue'];
  8856. }
  8857. if ($targetcs=='DeviceCMYK') {
  8858. $col = $this->rgb2cmyk(array(3,$r,$g,$b));
  8859. $c1 = intval($col[1]*2.55);
  8860. $c2 = intval($col[2]*2.55);
  8861. $c3 = intval($col[3]*2.55);
  8862. $c4 = intval($col[4]*2.55);
  8863. if ($trnsrgb) {
  8864. // original pixel was not set as transparent but processed color does match
  8865. if ($trnsrgb!=array($r,$g,$b) && $trns==array($c1,$c2,$c3,$c4)) {
  8866. if ($c4==0) { $c4=1; } else { $c4--; }
  8867. }
  8868. }
  8869. $imgdata .= chr($c1).chr($c2).chr($c3).chr($c4);
  8870. }
  8871. else if ($targetcs=='DeviceGray') {
  8872. $c = intval(($r * .21) + ($g * .71) + ($b * .07));
  8873. if ($trnsrgb) {
  8874. // original pixel was not set as transparent but processed color does match
  8875. if ($trnsrgb!=array($r,$g,$b) && $trns==array($c)) {
  8876. if ($c==0) { $c=1; } else { $c--; }
  8877. }
  8878. }
  8879. $imgdata .= chr($c);
  8880. }
  8881. else if ($targetcs=='DeviceRGB') {
  8882. $imgdata .= chr($r).chr($g).chr($b);
  8883. }
  8884. if ($mask) {
  8885. $col = imagecolorsforindex($im, $rgb);
  8886. $gammacorr = 2.2; // gamma correction
  8887. $gamma = intval((pow((((127 - $col['alpha']) * 255 / 127) / 255), $gammacorr) * 255));
  8888. $mimgdata .= chr($gamma);
  8889. }
  8890. }
  8891. }
  8892. if ($targetcs=='DeviceGray') { $ncols = 1; }
  8893. else if ($targetcs=='DeviceRGB') { $ncols = 3; }
  8894. else if ($targetcs=='DeviceCMYK') { $ncols = 4; }
  8895. $imgdata = gzcompress($imgdata);
  8896. $info = array('w'=>$w,'h'=>$h,'cs'=>$targetcs,'bpc'=>8,'f'=>'FlateDecode','data'=>$imgdata, 'type'=>'png',
  8897. 'parms'=>'/DecodeParms <</Colors '.$ncols.' /BitsPerComponent 8 /Columns '.$w.'>>');
  8898. if ($dpi) { $info['set-dpi'] = $dpi; }
  8899. if ($mask) {
  8900. $mimgdata = gzcompress($mimgdata);
  8901. $minfo = array('w'=>$w,'h'=>$h,'cs'=>'DeviceGray','bpc'=>8,'f'=>'FlateDecode','data'=>$mimgdata, 'type'=>'png',
  8902. 'parms'=>'/DecodeParms <</Colors '.$ncols.' /BitsPerComponent 8 /Columns '.$w.'>>');
  8903. if ($dpi) { $minfo['set-dpi'] = $dpi; }
  8904. $tempfile = '_tempImgPNG'.RAND(1,10000).'.png';
  8905. $imgmask = count($this->images)+1;
  8906. $minfo['i']=$imgmask ;
  8907. $this->images[$tempfile] = $minfo;
  8908. $info['masked'] = $imgmask;
  8909. }
  8910. else if ($trns) { $info['trns'] = $trns; }
  8911. imagedestroy($im);
  8912. }
  8913. return $info;
  8914. }
  8915. function _fourbytes2int($s) {
  8916. //Read a 4-byte integer from string
  8917. return (ord($s[0])<<24) + (ord($s[1])<<16) + (ord($s[2])<<8) + ord($s[3]);
  8918. }
  8919. function _twobytes2int($s) {
  8920. //Read a 2-byte integer from string
  8921. return (ord(substr($s, 0, 1))<<8) + ord(substr($s, 1, 1));
  8922. }
  8923. function _jpgHeaderFromString(&$data) {
  8924. $p = 4;
  8925. $p += $this->_twobytes2int(substr($data, $p, 2)); // Length of initial marker block
  8926. $marker = substr($data, $p, 2);
  8927. while($marker != chr(255).chr(192) && $marker != chr(255).chr(194) && $p<strlen($data)) {
  8928. // Start of frame marker (FFC0) or (FFC2) mPDF 4.4.004
  8929. $p += ($this->_twobytes2int(substr($data, $p+2, 2))) + 2; // Length of marker block
  8930. $marker = substr($data, $p, 2);
  8931. }
  8932. if ($marker != chr(255).chr(192) && $marker != chr(255).chr(194)) { return false; }
  8933. return substr($data, $p+2, 10);
  8934. }
  8935. function _jpgDataFromHeader($hdr) {
  8936. $bpc = ord(substr($hdr, 2, 1));
  8937. if (!$bpc) { $bpc = 8; }
  8938. $h = $this->_twobytes2int(substr($hdr, 3, 2));
  8939. $w = $this->_twobytes2int(substr($hdr, 5, 2));
  8940. $channels = ord(substr($hdr, 7, 1));
  8941. if ($channels==3) { $colspace='DeviceRGB'; }
  8942. elseif($channels==4) { $colspace='DeviceCMYK'; }
  8943. else { $colspace='DeviceGray'; }
  8944. return array($w, $h, $colspace, $bpc);
  8945. }
  8946. function file_get_contents_by_curl($url, &$data) {
  8947. $timeout = 5;
  8948. $ch = curl_init($url);
  8949. curl_setopt($ch, CURLOPT_HEADER, 0);
  8950. curl_setopt($ch, CURLOPT_NOBODY, 0);
  8951. curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
  8952. curl_setopt ( $ch , CURLOPT_CONNECTTIMEOUT , $timeout );
  8953. $data = curl_exec($ch);
  8954. curl_close($ch);
  8955. }
  8956. function file_get_contents_by_socket($url, &$data) {
  8957. $timeout = 1;
  8958. $p = parse_url($url);
  8959. $file = $p['path'];
  8960. if ($p['query']) { $file .= '?'.$p['query']; }
  8961. if(!($fh = @fsockopen($p['host'], 80, $errno, $errstr, $timeout))) { return false; }
  8962. $getstring =
  8963. "GET ".$file." HTTP/1.0 \r\n" .
  8964. "Host: ".$p['host']." \r\n" .
  8965. "Connection: close\r\n\r\n";
  8966. fwrite($fh, $getstring);
  8967. // Get rid of HTTP header
  8968. $s = fgets($fh, 1024);
  8969. if (!$s) { return false; }
  8970. $httpheader .= $s;
  8971. while (!feof($fh)) {
  8972. $s = fgets($fh, 1024);
  8973. if ( $s == "\r\n" ) { break; }
  8974. }
  8975. $data = '';
  8976. while (!feof($fh)) {
  8977. $data .= fgets($fh, 1024);
  8978. }
  8979. fclose($fh);
  8980. }
  8981. //==============================================================
  8982. function _imageTypeFromString(&$data) {
  8983. $type = '';
  8984. if (substr($data, 6, 4)== 'JFIF' || substr($data, 6, 4)== 'Exif') {
  8985. $type = 'jpeg';
  8986. }
  8987. else if (substr($data, 0, 6)== "GIF87a" || substr($data, 0, 6)== "GIF89a") {
  8988. $type = 'gif';
  8989. }
  8990. else if (substr($data, 0, 8)== chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
  8991. $type = 'png';
  8992. }
  8993. /*-- IMAGES-WMF --*/
  8994. else if (substr($data, 0, 4)== chr(215).chr(205).chr(198).chr(154)) {
  8995. $type = 'wmf';
  8996. }
  8997. /*-- END IMAGES-WMF --*/
  8998. else if (preg_match('/<svg.*<\/svg>/is',$data)) {
  8999. $type = 'svg';
  9000. }
  9001. // BMP images
  9002. else if (substr($data, 0, 2)== "BM") {
  9003. $type = 'bmp';
  9004. }
  9005. return $type;
  9006. }
  9007. //==============================================================
  9008. // Moved outside WMF as also needed for SVG
  9009. function _putformobjects() {
  9010. reset($this->formobjects);
  9011. while(list($file,$info)=each($this->formobjects)) {
  9012. $this->_newobj();
  9013. $this->formobjects[$file]['n']=$this->n;
  9014. $this->_out('<</Type /XObject');
  9015. $this->_out('/Subtype /Form');
  9016. $this->_out('/Group '.($this->n+1).' 0 R');
  9017. $this->_out('/BBox ['.$info['x'].' '.$info['y'].' '.($info['w']+$info['x']).' '.($info['h']+$info['y']).']');
  9018. if ($this->compress)
  9019. $this->_out('/Filter /FlateDecode');
  9020. $data=($this->compress) ? gzcompress($info['data']) : $info['data'];
  9021. $this->_out('/Length '.strlen($data).'>>');
  9022. $this->_putstream($data);
  9023. unset($this->formobjects[$file]['data']);
  9024. $this->_out('endobj');
  9025. // Required for SVG transparency (opacity) to work
  9026. $this->_newobj();
  9027. $this->_out('<</Type /Group');
  9028. $this->_out('/S /Transparency');
  9029. $this->_out('>>');
  9030. $this->_out('endobj');
  9031. }
  9032. }
  9033. function _freadint($f)
  9034. {
  9035. //Read a 4-byte integer from file
  9036. $i=ord(fread($f,1))<<24;
  9037. $i+=ord(fread($f,1))<<16;
  9038. $i+=ord(fread($f,1))<<8;
  9039. $i+=ord(fread($f,1));
  9040. return $i;
  9041. }
  9042. function _UTF16BEtextstring($s) {
  9043. $s = $this->UTF8ToUTF16BE($s, true);
  9044. /*-- ENCRYPTION --*/
  9045. if ($this->encrypted) {
  9046. $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
  9047. }
  9048. /*-- END ENCRYPTION --*/
  9049. return '('. $this->_escape($s).')';
  9050. }
  9051. function _textstring($s) {
  9052. /*-- ENCRYPTION --*/
  9053. if ($this->encrypted) {
  9054. $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
  9055. }
  9056. /*-- END ENCRYPTION --*/
  9057. return '('. $this->_escape($s).')';
  9058. }
  9059. function _escape($s)
  9060. {
  9061. // the chr(13) substitution fixes the Bugs item #1421290.
  9062. return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
  9063. }
  9064. function _putstream($s) {
  9065. /*-- ENCRYPTION --*/
  9066. if ($this->encrypted) {
  9067. $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
  9068. }
  9069. /*-- END ENCRYPTION --*/
  9070. $this->_out('stream');
  9071. $this->_out($s);
  9072. $this->_out('endstream');
  9073. }
  9074. function _out($s,$ln=true) {
  9075. if($this->state==2) {
  9076. if ($this->bufferoutput) {
  9077. $this->headerbuffer.= $s."\n";
  9078. }
  9079. /*-- COLUMNS --*/
  9080. else if (($this->ColActive) && !$this->processingHeader && !$this->processingFooter) {
  9081. // Captures everything in buffer for columns; Almost everything is sent from fn. Cell() except:
  9082. // Images sent from Image() or
  9083. // later sent as _out($textto) in printbuffer
  9084. // Line()
  9085. if (preg_match('/q \d+\.\d\d+ 0 0 (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ cm \/(I|FO)\d+ Do Q/',$s,$m)) { // Image data
  9086. $h = ($m[1]/_MPDFK);
  9087. // Update/overwrite the lowest bottom of printing y value for a column
  9088. $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y+$h;
  9089. }
  9090. /*-- TABLES --*/
  9091. else if (preg_match('/\d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ ([\-]{0,1}\d+\.\d\d+) re/',$s,$m) && $this->tableLevel>0) { // Rect in table
  9092. $h = ($m[1]/_MPDFK);
  9093. // Update/overwrite the lowest bottom of printing y value for a column
  9094. $this->ColDetails[$this->CurrCol]['bottom_margin'] = max($this->ColDetails[$this->CurrCol]['bottom_margin'],($this->y+$h));
  9095. }
  9096. /*-- END TABLES --*/
  9097. else { // Td Text Set in Cell()
  9098. if (isset($this->ColDetails[$this->CurrCol]['bottom_margin'])) { $h = $this->ColDetails[$this->CurrCol]['bottom_margin'] - $this->y; }
  9099. else { $h = 0; }
  9100. }
  9101. if ($h < 0) { $h = -$h; }
  9102. $this->columnbuffer[] = array(
  9103. 's' => $s, // Text string to output
  9104. 'col' => $this->CurrCol, // Column when printed
  9105. 'x' => $this->x, // x when printed
  9106. 'y' => $this->y, // this->y when printed (after column break)
  9107. 'h' => $h // actual y at bottom when printed = y+h
  9108. );
  9109. }
  9110. /*-- END COLUMNS --*/
  9111. /*-- TABLES --*/
  9112. else if ($this->table_rotate && !$this->processingHeader && !$this->processingFooter) {
  9113. // Captures eveything in buffer for rotated tables;
  9114. $this->tablebuffer .= $s . "\n";
  9115. }
  9116. /*-- END TABLES --*/
  9117. else if ($this->kwt && !$this->processingHeader && !$this->processingFooter) {
  9118. // Captures eveything in buffer for keep-with-table (h1-6);
  9119. $this->kwt_buffer[] = array(
  9120. 's' => $s, // Text string to output
  9121. 'x' => $this->x, // x when printed
  9122. 'y' => $this->y, // y when printed
  9123. );
  9124. }
  9125. else if (($this->keep_block_together) && !$this->processingHeader && !$this->processingFooter) {
  9126. if (!isset($this->ktBlock[$this->page]['bottom_margin'])) {
  9127. $this->ktBlock[$this->page]['bottom_margin'] = $this->y;
  9128. }
  9129. // Captures eveything in buffer;
  9130. if (preg_match('/q \d+\.\d\d+ 0 0 (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ cm \/(I|FO)\d+ Do Q/',$s,$m)) { // Image data
  9131. $h = ($m[1]/_MPDFK);
  9132. // Update/overwrite the lowest bottom of printing y value for Keep together block
  9133. $this->ktBlock[$this->page]['bottom_margin'] = $this->y+$h;
  9134. }
  9135. else { // Td Text Set in Cell()
  9136. if (isset($this->ktBlock[$this->page]['bottom_margin'])) { $h = $this->ktBlock[$this->page]['bottom_margin'] - $this->y; }
  9137. else { $h = 0; }
  9138. }
  9139. if ($h < 0) { $h = -$h; }
  9140. $this->divbuffer[] = array(
  9141. 'page' => $this->page,
  9142. 's' => $s, // Text string to output
  9143. 'x' => $this->x, // x when printed
  9144. 'y' => $this->y, // y when printed (after column break)
  9145. 'h' => $h // actual y at bottom when printed = y+h
  9146. );
  9147. }
  9148. else {
  9149. $this->pages[$this->page] .= $s.($ln == true ? "\n" : '');
  9150. }
  9151. }
  9152. else {
  9153. $this->buffer .= $s.($ln == true ? "\n" : '');
  9154. }
  9155. }
  9156. /*-- WATERMARK --*/
  9157. // add a watermark
  9158. function watermark( $texte, $angle=45, $fontsize=96, $alpha=0.2 ) {
  9159. if ($this->PDFA || $this->PDFX) { $this->Error('PDFA and PDFX do not permit transparency, so mPDF does not allow Watermarks!'); }
  9160. if (!$this->watermark_font) { $this->watermark_font = $this->default_font; }
  9161. $this->SetFont( $this->watermark_font, "B", $fontsize, false ); // Don't output
  9162. $texte= $this->purify_utf8_text($texte);
  9163. if ($this->text_input_as_HTML) {
  9164. $texte= $this->all_entities_to_utf8($texte);
  9165. }
  9166. if ($this->usingCoreFont) { $texte = mb_convert_encoding($texte,$this->mb_enc,'UTF-8'); }
  9167. // DIRECTIONALITY
  9168. $this->magic_reverse_dir($texte, true, $this->directionality); // *RTL*
  9169. // Font-specific ligature substitution for Indic fonts
  9170. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($texte); // *INDIC*
  9171. $this->SetAlpha($alpha);
  9172. $this->SetTColor($this->ConvertColor(0));
  9173. $szfont = $fontsize;
  9174. $loop = 0;
  9175. $maxlen = (min($this->w,$this->h) ); // sets max length of text as 7/8 width/height of page
  9176. while ( $loop == 0 )
  9177. {
  9178. $this->SetFont( $this->watermark_font, "B", $szfont, false ); // Don't output
  9179. $offset = ((sin(deg2rad($angle))) * ($szfont/_MPDFK));
  9180. $strlen = $this->GetStringWidth($texte);
  9181. if ( $strlen > $maxlen - $offset )
  9182. $szfont --;
  9183. else
  9184. $loop ++;
  9185. }
  9186. $this->SetFont( $this->watermark_font, "B", $szfont-0.1, true, true); // Output The -0.1 is because SetFont above is not written to PDF
  9187. // Repeating it will not output anything as mPDF thinks it is set
  9188. $adj = ((cos(deg2rad($angle))) * ($strlen/2));
  9189. $opp = ((sin(deg2rad($angle))) * ($strlen/2));
  9190. $wx = ($this->w/2) - $adj + $offset/3;
  9191. $wy = ($this->h/2) + $opp;
  9192. $this->Rotate($angle,$wx,$wy);
  9193. $this->Text($wx,$wy,$texte);
  9194. $this->Rotate(0);
  9195. $this->SetTColor($this->ConvertColor(0));
  9196. $this->SetAlpha(1);
  9197. }
  9198. function watermarkImg( $src, $alpha=0.2 ) {
  9199. if ($this->PDFA || $this->PDFX) { $this->Error('PDFA and PDFX do not permit transparency, so mPDF does not allow Watermarks!'); }
  9200. if ($this->watermarkImgBehind) { $this->watermarkImgAlpha = $this->SetAlpha($alpha, 'Normal', true); }
  9201. else { $this->SetAlpha($alpha, $this->watermarkImgAlphaBlend); }
  9202. $this->Image($src,0,0,0,0,'','', true, true, true);
  9203. if (!$this->watermarkImgBehind) { $this->SetAlpha(1); }
  9204. }
  9205. /*-- END WATERMARK --*/
  9206. function Rotate($angle,$x=-1,$y=-1)
  9207. {
  9208. if($x==-1)
  9209. $x=$this->x;
  9210. if($y==-1)
  9211. $y=$this->y;
  9212. if($this->angle!=0)
  9213. $this->_out('Q');
  9214. $this->angle=$angle;
  9215. if($angle!=0)
  9216. {
  9217. $angle*=M_PI/180;
  9218. $c=cos($angle);
  9219. $s=sin($angle);
  9220. $cx=$x*_MPDFK;
  9221. $cy=($this->h-$y)*_MPDFK;
  9222. $this->_out(sprintf('q %.5F %.5F %.5F %.5F %.3F %.3F cm 1 0 0 1 %.3F %.3F cm',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy));
  9223. }
  9224. }
  9225. // mPDF 5.3.40 5.3.51 5.3.53
  9226. function CircularText($x, $y, $r, $text, $align='top', $fontfamily='', $fontsize=0, $fontstyle='', $kerning=120, $fontwidth=100) {
  9227. if (!class_exists('directw', false)) { include(_MPDF_PATH.'classes/directw.php'); }
  9228. if (empty($this->directw)) { $this->directw = new directw($this); }
  9229. $this->directw->CircularText($x, $y, $r, $text, $align, $fontfamily, $fontsize, $fontstyle, $kerning, $fontwidth);
  9230. }
  9231. // From Invoice
  9232. function RoundedRect($x, $y, $w, $h, $r, $style = '')
  9233. {
  9234. $hp = $this->h;
  9235. if($style=='F')
  9236. $op='f';
  9237. elseif($style=='FD' or $style=='DF')
  9238. $op='B';
  9239. else
  9240. $op='S';
  9241. $MyArc = 4/3 * (sqrt(2) - 1);
  9242. $this->_out(sprintf('%.3F %.3F m',($x+$r)*_MPDFK,($hp-$y)*_MPDFK ));
  9243. $xc = $x+$w-$r ;
  9244. $yc = $y+$r;
  9245. $this->_out(sprintf('%.3F %.3F l', $xc*_MPDFK,($hp-$y)*_MPDFK ));
  9246. $this->_Arc($xc + $r*$MyArc, $yc - $r, $xc + $r, $yc - $r*$MyArc, $xc + $r, $yc);
  9247. $xc = $x+$w-$r ;
  9248. $yc = $y+$h-$r;
  9249. $this->_out(sprintf('%.3F %.3F l',($x+$w)*_MPDFK,($hp-$yc)*_MPDFK));
  9250. $this->_Arc($xc + $r, $yc + $r*$MyArc, $xc + $r*$MyArc, $yc + $r, $xc, $yc + $r);
  9251. $xc = $x+$r ;
  9252. $yc = $y+$h-$r;
  9253. $this->_out(sprintf('%.3F %.3F l',$xc*_MPDFK,($hp-($y+$h))*_MPDFK));
  9254. $this->_Arc($xc - $r*$MyArc, $yc + $r, $xc - $r, $yc + $r*$MyArc, $xc - $r, $yc);
  9255. $xc = $x+$r ;
  9256. $yc = $y+$r;
  9257. $this->_out(sprintf('%.3F %.3F l',($x)*_MPDFK,($hp-$yc)*_MPDFK ));
  9258. $this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r);
  9259. $this->_out($op);
  9260. }
  9261. function _Arc($x1, $y1, $x2, $y2, $x3, $y3)
  9262. {
  9263. $h = $this->h;
  9264. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', $x1*_MPDFK, ($h-$y1)*_MPDFK,
  9265. $x2*_MPDFK, ($h-$y2)*_MPDFK, $x3*_MPDFK, ($h-$y3)*_MPDFK));
  9266. }
  9267. //====================================================
  9268. /*-- DIRECTW --*/
  9269. function Shaded_box( $text,$font='',$fontstyle='B',$szfont='',$width='70%',$style='DF',$radius=2.5,$fill='#FFFFFF',$color='#000000',$pad=2 ) {
  9270. // F (shading - no line),S (line, no shading),DF (both)
  9271. if (!class_exists('directw', false)) { include(_MPDF_PATH.'classes/directw.php'); }
  9272. if (empty($this->directw)) { $this->directw = new directw($this); }
  9273. $this->directw->Shaded_box( $text,$font,$fontstyle,$szfont,$width,$style,$radius,$fill,$color,$pad);
  9274. }
  9275. /*-- END DIRECTW --*/
  9276. function UTF8StringToArray($str, $addSubset=true) {
  9277. $out = array();
  9278. $len = strlen($str);
  9279. for ($i = 0; $i < $len; $i++) {
  9280. $uni = -1;
  9281. $h = ord($str[$i]);
  9282. if ( $h <= 0x7F )
  9283. $uni = $h;
  9284. elseif ( $h >= 0xC2 ) {
  9285. if ( ($h <= 0xDF) && ($i < $len -1) )
  9286. $uni = ($h & 0x1F) << 6 | (ord($str[++$i]) & 0x3F);
  9287. elseif ( ($h <= 0xEF) && ($i < $len -2) )
  9288. $uni = ($h & 0x0F) << 12 | (ord($str[++$i]) & 0x3F) << 6 | (ord($str[++$i]) & 0x3F);
  9289. elseif ( ($h <= 0xF4) && ($i < $len -3) )
  9290. $uni = ($h & 0x0F) << 18 | (ord($str[++$i]) & 0x3F) << 12 | (ord($str[++$i]) & 0x3F) << 6 | (ord($str[++$i]) & 0x3F);
  9291. }
  9292. if ($uni >= 0) {
  9293. $out[] = $uni;
  9294. if ($addSubset && isset($this->CurrentFont['subset'])) {
  9295. $this->CurrentFont['subset'][$uni] = $uni;
  9296. }
  9297. }
  9298. }
  9299. return $out;
  9300. }
  9301. //Convert utf-8 string to <HHHHHH> for Font Subsets
  9302. function UTF8toSubset($str) {
  9303. $ret = '<';
  9304. $str = preg_replace('/'.preg_quote($this->aliasNbPg,'/').'/', chr(7), $str );
  9305. $str = preg_replace('/'.preg_quote($this->aliasNbPgGp,'/').'/', chr(8), $str );
  9306. $unicode = $this->UTF8StringToArray($str);
  9307. $orig_fid = $this->CurrentFont['subsetfontids'][0];
  9308. $last_fid = $this->CurrentFont['subsetfontids'][0];
  9309. foreach($unicode as $c) {
  9310. if ($c == 7 || $c == 8) {
  9311. if ($orig_fid != $last_fid) {
  9312. $ret .= '> Tj /F'.$orig_fid.' '.$this->FontSizePt.' Tf <';
  9313. $last_fid = $orig_fid;
  9314. }
  9315. if ($c == 7) { $ret .= $this->aliasNbPgHex; }
  9316. else { $ret .= $this->aliasNbPgGpHex; }
  9317. continue;
  9318. }
  9319. for ($i=0; $i<99; $i++) {
  9320. // return c as decimal char
  9321. $init = array_search($c, $this->CurrentFont['subsets'][$i]);
  9322. if ($init!==false) {
  9323. if ($this->CurrentFont['subsetfontids'][$i] != $last_fid) {
  9324. $ret .= '> Tj /F'.$this->CurrentFont['subsetfontids'][$i].' '.$this->FontSizePt.' Tf <';
  9325. $last_fid = $this->CurrentFont['subsetfontids'][$i];
  9326. }
  9327. $ret .= sprintf("%02s", strtoupper(dechex($init)));
  9328. break;
  9329. }
  9330. // TrueType embedded SUBSETS
  9331. else if (count($this->CurrentFont['subsets'][$i]) < 255) {
  9332. $n = count($this->CurrentFont['subsets'][$i]);
  9333. $this->CurrentFont['subsets'][$i][$n] = $c;
  9334. if ($this->CurrentFont['subsetfontids'][$i] != $last_fid) {
  9335. $ret .= '> Tj /F'.$this->CurrentFont['subsetfontids'][$i].' '.$this->FontSizePt.' Tf <';
  9336. $last_fid = $this->CurrentFont['subsetfontids'][$i];
  9337. }
  9338. $ret .= sprintf("%02s", strtoupper(dechex($n)));
  9339. break;
  9340. }
  9341. else if (!isset($this->CurrentFont['subsets'][($i+1)])) {
  9342. // TrueType embedded SUBSETS
  9343. $this->CurrentFont['subsets'][($i+1)] = array(0=>0);
  9344. $new_fid = count($this->fonts)+$this->extraFontSubsets+1;
  9345. $this->CurrentFont['subsetfontids'][($i+1)] = $new_fid;
  9346. $this->extraFontSubsets++;
  9347. }
  9348. }
  9349. }
  9350. $ret .= '>';
  9351. if ($last_fid != $orig_fid) {
  9352. $ret .= ' Tj /F'.$orig_fid.' '.$this->FontSizePt.' Tf <> ';
  9353. }
  9354. return $ret;
  9355. }
  9356. // Converts UTF-8 strings to UTF16-BE.
  9357. function UTF8ToUTF16BE($str, $setbom=true) {
  9358. if ($this->checkSIP && preg_match("/([\x{20000}-\x{2FFFF}])/u", $str)) {
  9359. if (!in_array($this->currentfontfamily, array('gb','big5','sjis','uhc','gbB','big5B','sjisB','uhcB','gbI','big5I','sjisI','uhcI',
  9360. 'gbBI','big5BI','sjisBI','uhcBI'))) {
  9361. $str = preg_replace("/[\x{20000}-\x{2FFFF}]/u", chr(0), $str);
  9362. }
  9363. }
  9364. if ($this->checkSMP && preg_match("/([\x{10000}-\x{1FFFF}])/u", $str )) {
  9365. $str = preg_replace("/[\x{10000}-\x{1FFFF}]/u", chr(0), $str );
  9366. }
  9367. $outstr = ""; // string to be returned
  9368. if ($setbom) {
  9369. $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
  9370. }
  9371. $outstr .= mb_convert_encoding($str, 'UTF-16BE', 'UTF-8');
  9372. return $outstr;
  9373. }
  9374. // ====================================================
  9375. // ====================================================
  9376. /*-- CJK-FONTS --*/
  9377. // from class PDF_Chinese CJK EXTENSIONS
  9378. function AddCIDFont($family,$style,$name,&$cw,$CMap,$registry,$desc)
  9379. {
  9380. $fontkey=strtolower($family).strtoupper($style);
  9381. if(isset($this->fonts[$fontkey]))
  9382. $this->Error("Font already added: $family $style");
  9383. $i=count($this->fonts)+$this->extraFontSubsets+1;
  9384. $name=str_replace(' ','',$name);
  9385. if ($family == 'sjis') { $up = -120; } else { $up = -130; }
  9386. // ? 'up' and 'ut' do not seem to be referenced anywhere
  9387. $this->fonts[$fontkey]=array('i'=>$i,'type'=>'Type0','name'=>$name,'up'=>$up,'ut'=>40,'cw'=>$cw,'CMap'=>$CMap,'registry'=>$registry,'MissingWidth'=>1000,'desc'=>$desc);
  9388. }
  9389. function AddCJKFont($family) {
  9390. if ($this->PDFA || $this->PDFX) {
  9391. $this->Error("Adobe CJK fonts cannot be embedded in mPDF (required for PDFA1-b and PDFX/1-a).");
  9392. }
  9393. if ($family == 'big5') { $this->AddBig5Font(); }
  9394. else if ($family == 'gb') { $this->AddGBFont(); }
  9395. else if ($family == 'sjis') { $this->AddSJISFont(); }
  9396. else if ($family == 'uhc') { $this->AddUHCFont(); }
  9397. }
  9398. function AddBig5Font()
  9399. {
  9400. //Add Big5 font with proportional Latin
  9401. $family='big5';
  9402. $name='MSungStd-Light-Acro';
  9403. $cw=$this->Big5_widths;
  9404. $CMap='UniCNS-UTF16-H';
  9405. $registry=array('ordering'=>'CNS1','supplement'=>4);
  9406. $desc = array(
  9407. 'Ascent' => 880,
  9408. 'Descent' => -120,
  9409. 'CapHeight' => 880,
  9410. 'Flags' => 6,
  9411. 'FontBBox' => '[-160 -249 1015 1071]',
  9412. 'ItalicAngle' => 0,
  9413. 'StemV' => 93,
  9414. );
  9415. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  9416. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  9417. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  9418. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  9419. }
  9420. function AddGBFont()
  9421. {
  9422. //Add GB font with proportional Latin
  9423. $family='gb';
  9424. $name='STSongStd-Light-Acro';
  9425. $cw=$this->GB_widths;
  9426. $CMap='UniGB-UTF16-H';
  9427. $registry=array('ordering'=>'GB1','supplement'=>4);
  9428. $desc = array(
  9429. 'Ascent' => 752,
  9430. 'Descent' => -271,
  9431. 'CapHeight' => 737,
  9432. 'Flags' => 6,
  9433. 'FontBBox' => '[-25 -254 1000 880]',
  9434. 'ItalicAngle' => 0,
  9435. 'StemV' => 58,
  9436. 'Style' => '<< /Panose <000000000400000000000000> >>',
  9437. );
  9438. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  9439. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  9440. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  9441. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  9442. }
  9443. function AddSJISFont()
  9444. {
  9445. //Add SJIS font with proportional Latin
  9446. $family='sjis';
  9447. $name='KozMinPro-Regular-Acro';
  9448. $cw=$this->SJIS_widths;
  9449. $CMap='UniJIS-UTF16-H';
  9450. $registry=array('ordering'=>'Japan1','supplement'=>5);
  9451. $desc = array(
  9452. 'Ascent' => 880,
  9453. 'Descent' => -120,
  9454. 'CapHeight' => 740,
  9455. 'Flags' => 6,
  9456. 'FontBBox' => '[-195 -272 1110 1075]',
  9457. 'ItalicAngle' => 0,
  9458. 'StemV' => 86,
  9459. 'XHeight' => 502,
  9460. );
  9461. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  9462. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  9463. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  9464. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  9465. }
  9466. function AddUHCFont()
  9467. {
  9468. //Add UHC font with proportional Latin
  9469. $family='uhc';
  9470. $name='HYSMyeongJoStd-Medium-Acro';
  9471. $cw=$this->UHC_widths;
  9472. $CMap='UniKS-UTF16-H';
  9473. $registry=array('ordering'=>'Korea1','supplement'=>2);
  9474. $desc = array(
  9475. 'Ascent' => 880,
  9476. 'Descent' => -120,
  9477. 'CapHeight' => 720,
  9478. 'Flags' => 6,
  9479. 'FontBBox' => '[-28 -148 1001 880]',
  9480. 'ItalicAngle' => 0,
  9481. 'StemV' => 60,
  9482. 'Style' => '<< /Panose <000000000600000000000000> >>',
  9483. );
  9484. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  9485. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  9486. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  9487. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  9488. }
  9489. /*-- END CJK-FONTS --*/
  9490. //////////////////////////////////////////////////////////////////////////////
  9491. //////////////////////////////////////////////////////////////////////////////
  9492. //////////////////////////////////////////////////////////////////////////////
  9493. //////////////////////////////////////////////////////////////////////////////
  9494. //////////////////////////////////////////////////////////////////////////////
  9495. //////////////////////////////////////////////////////////////////////////////
  9496. //////////////////////////////////////////////////////////////////////////////
  9497. function SetAutoFont($af = AUTOFONT_ALL) {
  9498. if ($this->onlyCoreFonts) { return false; }
  9499. if (!$af && $af !== 0) { $af = AUTOFONT_ALL; }
  9500. $this->autoFontGroups = $af;
  9501. if ($this->autoFontGroups ) {
  9502. $this->useLang = true;
  9503. }
  9504. }
  9505. function SetDefaultFont($font) {
  9506. // Disallow embedded fonts to be used as defaults in PDFA
  9507. if ($this->PDFA || $this->PDFX) {
  9508. if (strtolower($font) == 'ctimes') { $font = 'serif'; }
  9509. if (strtolower($font) == 'ccourier') { $font = 'monospace'; }
  9510. if (strtolower($font) == 'chelvetica') { $font = 'sans-serif'; }
  9511. }
  9512. $font = $this->SetFont($font); // returns substituted font if necessary
  9513. $this->default_font = $font;
  9514. $this->original_default_font = $font;
  9515. if (!$this->watermark_font ) { $this->watermark_font = $font; } // *WATERMARK*
  9516. $this->defaultCSS['BODY']['FONT-FAMILY'] = $font;
  9517. $this->CSS['BODY']['FONT-FAMILY'] = $font;
  9518. }
  9519. function SetDefaultFontSize($fontsize) {
  9520. $this->default_font_size = $fontsize;
  9521. $this->original_default_font_size = $fontsize;
  9522. $this->SetFontSize($fontsize);
  9523. $this->defaultCSS['BODY']['FONT-SIZE'] = $fontsize . 'pt';
  9524. $this->CSS['BODY']['FONT-SIZE'] = $fontsize . 'pt';
  9525. }
  9526. function SetDefaultBodyCSS($prop, $val) {
  9527. if ($prop) {
  9528. $this->defaultCSS['BODY'][strtoupper($prop)] = $val;
  9529. $this->CSS['BODY'][strtoupper($prop)] = $val;
  9530. }
  9531. }
  9532. function SetDirectionality($dir='ltr') {
  9533. /*-- RTL --*/
  9534. if (strtolower($dir) == 'rtl') {
  9535. if ($this->directionality != 'rtl') {
  9536. // Swop L/R Margins so page 1 RTL is an 'even' page
  9537. $tmp = $this->DeflMargin;
  9538. $this->DeflMargin = $this->DefrMargin;
  9539. $this->DefrMargin = $tmp;
  9540. $this->orig_lMargin = $this->DeflMargin;
  9541. $this->orig_rMargin = $this->DefrMargin;
  9542. $this->SetMargins($this->DeflMargin,$this->DefrMargin,$this->tMargin);
  9543. }
  9544. $this->directionality = 'rtl';
  9545. $this->defaultAlign = 'R';
  9546. $this->defaultTableAlign = 'R';
  9547. }
  9548. else {
  9549. /*-- END RTL --*/
  9550. $this->directionality = 'ltr';
  9551. $this->defaultAlign = 'L';
  9552. $this->defaultTableAlign = 'L';
  9553. } // *RTL*
  9554. $this->CSS['BODY']['DIRECTION'] = $this->directionality;
  9555. }
  9556. // Added to set line-height-correction
  9557. function SetLineHeightCorrection($val) {
  9558. if ($val > 0) { $this->default_lineheight_correction = $val; }
  9559. else { $this->default_lineheight_correction = 1.2; }
  9560. }
  9561. // Set a (fixed) lineheight to an actual value - either to named fontsize(pts) or default
  9562. function SetLineHeight($FontPt='',$spacing = '') {
  9563. if ($this->shrin_k > 1) { $k = $this->shrin_k; }
  9564. else { $k = 1; }
  9565. if ($spacing > 0) {
  9566. if (preg_match('/mm/',$spacing)) {
  9567. $this->lineheight = ($spacing + 0.0) / $k; // convert to number
  9568. }
  9569. else {
  9570. if ($FontPt) { $this->lineheight = (($FontPt/_MPDFK) *$spacing); }
  9571. else { $this->lineheight = (($this->FontSizePt/_MPDFK) *$spacing); }
  9572. }
  9573. }
  9574. else {
  9575. if ($FontPt) { $this->lineheight = (($FontPt/_MPDFK) *$this->normalLineheight); }
  9576. else { $this->lineheight = (($this->FontSizePt/_MPDFK) *$this->normalLineheight); }
  9577. }
  9578. }
  9579. function _computeLineheight($lh, $fs='') {
  9580. if ($this->shrin_k > 1) { $k = $this->shrin_k; }
  9581. else { $k = 1; }
  9582. if (!$fs) { $fs = $this->FontSize; }
  9583. if (preg_match('/mm/',$lh)) {
  9584. return (($lh + 0.0) / $k); // convert to number
  9585. }
  9586. else if ($lh > 0) {
  9587. return ($fs * $lh);
  9588. }
  9589. else if (isset($this->normalLineheight)) { return ($fs * $this->normalLineheight); }
  9590. else return ($fs * $this->default_lineheight_correction);
  9591. }
  9592. function SetBasePath($str='') {
  9593. if ( isset($_SERVER['HTTP_HOST']) ) { $host = $_SERVER['HTTP_HOST']; }
  9594. else if ( isset($_SERVER['SERVER_NAME']) ) { $host = $_SERVER['SERVER_NAME']; }
  9595. else { $host = ''; }
  9596. if (!$str) {
  9597. if ($_SERVER['SCRIPT_NAME']) { $currentPath = dirname($_SERVER['SCRIPT_NAME']); }
  9598. else { $currentPath = dirname($_SERVER['PHP_SELF']); }
  9599. $currentPath = str_replace("\\","/",$currentPath);
  9600. if ($currentPath == '/') { $currentPath = ''; }
  9601. if ($host) { $currpath = 'http://' . $host . $currentPath .'/'; }
  9602. else { $currpath = ''; }
  9603. $this->basepath = $currpath;
  9604. $this->basepathIsLocal = true;
  9605. return;
  9606. }
  9607. $str = preg_replace('/\?.*/','',$str);
  9608. if (!preg_match('/(http|https|ftp):\/\/.*\//i',$str)) { $str .= '/'; }
  9609. $str .= 'xxx'; // in case $str ends in / e.g. http://www.bbc.co.uk/
  9610. $this->basepath = dirname($str) . "/"; // returns e.g. e.g. http://www.google.com/dir1/dir2/dir3/
  9611. $this->basepath = str_replace("\\","/",$this->basepath); //If on Windows
  9612. $tr = parse_url($this->basepath);
  9613. if (isset($tr['host']) && ($tr['host'] == $host)) { $this->basepathIsLocal = true; }
  9614. else { $this->basepathIsLocal = false; }
  9615. }
  9616. function GetFullPath(&$path,$basepath='') {
  9617. // When parsing CSS need to pass temporary basepath - so links are relative to current stylesheet
  9618. if (!$basepath) { $basepath = $this->basepath; }
  9619. //Fix path value
  9620. $path = str_replace("\\","/",$path); //If on Windows
  9621. //Get link info and obtain its absolute path
  9622. $regexp = '|^./|'; // Inadvertently corrects "./path/etc" and "//www.domain.com/etc"
  9623. $path = preg_replace($regexp,'',$path);
  9624. if(substr($path,0,1) == '#') { return; }
  9625. if (stristr($path,"mailto:") !== false) { return; }
  9626. if (strpos($path,"../") !== false ) { //It is a Relative Link
  9627. $backtrackamount = substr_count($path,"../");
  9628. $maxbacktrack = substr_count($basepath,"/") - 1;
  9629. $filepath = str_replace("../",'',$path);
  9630. $path = $basepath;
  9631. //If it is an invalid relative link, then make it go to directory root
  9632. if ($backtrackamount > $maxbacktrack) $backtrackamount = $maxbacktrack;
  9633. //Backtrack some directories
  9634. for( $i = 0 ; $i < $backtrackamount + 1 ; $i++ ) $path = substr( $path, 0 , strrpos($path,"/") );
  9635. $path = $path . "/" . $filepath; //Make it an absolute path
  9636. }
  9637. else if( strpos($path,":/") === false || strpos($path,":/") > 10) { //It is a Local Link
  9638. if (substr($path,0,1) == "/") {
  9639. $tr = parse_url($basepath);
  9640. $root = $tr['scheme'].'://'.$tr['host'];
  9641. $path = $root . $path;
  9642. }
  9643. else { $path = $basepath . $path; }
  9644. }
  9645. //Do nothing if it is an Absolute Link
  9646. }
  9647. // Used for external CSS files
  9648. function _get_file($path) {
  9649. // If local file try using local path (? quicker, but also allowed even if allow_url_fopen false)
  9650. $contents = '';
  9651. $contents = @file_get_contents($path);
  9652. if ($contents) { return $contents; }
  9653. if ($this->basepathIsLocal) {
  9654. $tr = parse_url($path);
  9655. $lp=getenv("SCRIPT_NAME");
  9656. $ap=realpath($lp);
  9657. $ap=str_replace("\\","/",$ap);
  9658. $docroot=substr($ap,0,strpos($ap,$lp));
  9659. // WriteHTML parses all paths to full URLs; may be local file name
  9660. if ($tr['scheme'] && $tr['host'] && $_SERVER["DOCUMENT_ROOT"] ) {
  9661. $localpath = $_SERVER["DOCUMENT_ROOT"] . $tr['path'];
  9662. }
  9663. // DOCUMENT_ROOT is not returned on IIS
  9664. else if ($docroot) {
  9665. $localpath = $docroot . $tr['path'];
  9666. }
  9667. else { $localpath = $path; }
  9668. $contents = @file_get_contents($localpath);
  9669. }
  9670. // if not use full URL
  9671. else if (!$contents && !ini_get('allow_url_fopen') && function_exists("curl_init")) {
  9672. $ch = curl_init($path);
  9673. curl_setopt($ch, CURLOPT_HEADER, 0);
  9674. curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
  9675. $contents = curl_exec($ch);
  9676. curl_close($ch);
  9677. }
  9678. return $contents;
  9679. }
  9680. function docPageNum($num = 0, $extras = false) {
  9681. if ($num < 1) { $num = $this->page; }
  9682. $type = '1'; // set default decimal
  9683. $ppgno = $num;
  9684. $suppress = 0;
  9685. $offset = 0;
  9686. $lastreset = 0;
  9687. foreach($this->PageNumSubstitutions AS $psarr) {
  9688. if ($num >= $psarr['from']) {
  9689. if ($psarr['reset']) {
  9690. if ($psarr['reset']>1) { $offset = $psarr['reset']-1; }
  9691. $ppgno = $num - $psarr['from'] + 1 + $offset;
  9692. $lastreset = $psarr['from'];
  9693. }
  9694. if ($psarr['type']) { $type = $psarr['type']; }
  9695. if (strtoupper($psarr['suppress'])=='ON' || $psarr['suppress']==1) { $suppress = 1; }
  9696. else if (strtoupper($psarr['suppress'])=='OFF') { $suppress = 0; }
  9697. }
  9698. }
  9699. if ($suppress) { return ''; }
  9700. foreach($this->pgsIns AS $k=>$v) {
  9701. if ($k>$lastreset && $k<$num) {
  9702. $ppgno -= $v;
  9703. }
  9704. }
  9705. if ($type=='A') { $ppgno = $this->dec2alpha($ppgno,true); }
  9706. else if ($type=='a') { $ppgno = $this->dec2alpha($ppgno,false);}
  9707. else if ($type=='I') { $ppgno = $this->dec2roman($ppgno,true); }
  9708. else if ($type=='i') { $ppgno = $this->dec2roman($ppgno,false); }
  9709. if ($extras) { $ppgno = $this->pagenumPrefix . $ppgno . $this->pagenumSuffix; }
  9710. return $ppgno;
  9711. }
  9712. function docPageSettings($num = 0) {
  9713. // Returns current type (numberstyle), suppression state for this page number;
  9714. // reset is only returned if set for this page number
  9715. if ($num < 1) { $num = $this->page; }
  9716. $type = '1'; // set default decimal
  9717. $ppgno = $num;
  9718. $suppress = 0;
  9719. $offset = 0;
  9720. $reset = '';
  9721. foreach($this->PageNumSubstitutions AS $psarr) {
  9722. if ($num >= $psarr['from']) {
  9723. if ($psarr['reset']) {
  9724. if ($psarr['reset']>1) { $offset = $psarr['reset']-1; }
  9725. $ppgno = $num - $psarr['from'] + 1 + $offset;
  9726. }
  9727. if ($psarr['type']) { $type = $psarr['type']; }
  9728. if (strtoupper($psarr['suppress'])=='ON' || $psarr['suppress']==1) { $suppress = 1; }
  9729. else if (strtoupper($psarr['suppress'])=='OFF') { $suppress = 0; }
  9730. }
  9731. if ($num == $psarr['from']) { $reset = $psarr['reset']; }
  9732. }
  9733. if ($suppress) { $suppress = 'on'; }
  9734. else { $suppress = 'off'; }
  9735. return array($type, $suppress, $reset);
  9736. }
  9737. function docPageNumTotal($num = 0, $extras = false) {
  9738. if ($num < 1) { $num = $this->page; }
  9739. $type = '1'; // set default decimal
  9740. $ppgstart = 1;
  9741. $ppgend = count($this->pages)+1;
  9742. $suppress = 0;
  9743. $offset = 0;
  9744. foreach($this->PageNumSubstitutions AS $psarr) {
  9745. if ($num >= $psarr['from']) {
  9746. if ($psarr['reset']) {
  9747. if ($psarr['reset']>1) { $offset = $psarr['reset']-1; }
  9748. $ppgstart = $psarr['from'] + $offset;
  9749. $ppgend = count($this->pages)+1 + $offset;
  9750. }
  9751. if ($psarr['type']) { $type = $psarr['type']; }
  9752. if (strtoupper($psarr['suppress'])=='ON' || $psarr['suppress']==1) { $suppress = 1; }
  9753. else if (strtoupper($psarr['suppress'])=='OFF') { $suppress = 0; }
  9754. }
  9755. if ($num < $psarr['from']) {
  9756. if ($psarr['reset']) {
  9757. $ppgend = $psarr['from'] + $offset;
  9758. break;
  9759. }
  9760. }
  9761. }
  9762. if ($suppress) { return ''; }
  9763. $ppgno = $ppgend-$ppgstart+$offset;
  9764. if ($extras) { $ppgno = $this->nbpgPrefix . $ppgno . $this->nbpgSuffix; }
  9765. return $ppgno;
  9766. }
  9767. function RestartDocTemplate() {
  9768. $this->docTemplateStart = $this->page;
  9769. }
  9770. //Page header
  9771. function Header($content='') {
  9772. $this->cMarginL = 0;
  9773. $this->cMarginR = 0;
  9774. /*-- HTMLHEADERS-FOOTERS --*/
  9775. if (($this->mirrorMargins && ($this->page%2==0) && $this->HTMLHeaderE) || ($this->mirrorMargins && ($this->page%2==1) && $this->HTMLHeader) || (!$this->mirrorMargins && $this->HTMLHeader)) {
  9776. $this->writeHTMLHeaders();
  9777. return;
  9778. }
  9779. /*-- END HTMLHEADERS-FOOTERS --*/
  9780. $this->processingHeader=true;
  9781. $h = $this->headerDetails;
  9782. if(count($h)) {
  9783. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  9784. $this->_out(sprintf('q 0 -1 1 0 0 %.3F cm ',($this->h*_MPDFK)));
  9785. $yadj = $this->w - $this->h;
  9786. $headerpgwidth = $this->h - $this->orig_lMargin - $this->orig_rMargin;
  9787. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  9788. $headerlmargin = $this->orig_rMargin;
  9789. }
  9790. else {
  9791. $headerlmargin = $this->orig_lMargin;
  9792. }
  9793. }
  9794. else {
  9795. $yadj = 0;
  9796. $headerpgwidth = $this->pgwidth;
  9797. $headerlmargin = $this->lMargin;
  9798. }
  9799. $this->y = $this->margin_header - $yadj ;
  9800. $this->SetTColor($this->ConvertColor(0));
  9801. $this->SUP = false;
  9802. $this->SUB = false;
  9803. $this->bullet = false;
  9804. // only show pagenumber if numbering on
  9805. $pgno = $this->docPageNum($this->page, true);
  9806. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  9807. $side = 'even';
  9808. }
  9809. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS = DEFAULT
  9810. $side = 'odd';
  9811. }
  9812. $maxfontheight = 0;
  9813. foreach(array('L','C','R') AS $pos) {
  9814. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  9815. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  9816. else { $hfsz = $this->default_font_size; }
  9817. $maxfontheight = max($maxfontheight,$hfsz);
  9818. }
  9819. }
  9820. // LEFT-CENTER-RIGHT
  9821. foreach(array('L','C','R') AS $pos) {
  9822. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  9823. $hd = str_replace('{PAGENO}',$pgno,$h[$side][$pos]['content']);
  9824. $hd = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->aliasNbPgGp.$this->nbpgSuffix,$hd);
  9825. $hd = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$hd);
  9826. if (isset($h[$side][$pos]['font-family']) && $h[$side][$pos]['font-family']) { $hff = $h[$side][$pos]['font-family']; }
  9827. else { $hff = $this->original_default_font; }
  9828. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  9829. else { $hfsz = $this->original_default_font_size; } // pts
  9830. $maxfontheight = max($maxfontheight,$hfsz);
  9831. $hfst = '';
  9832. if (isset($h[$side][$pos]['font-style']) && $h[$side][$pos]['font-style']) {
  9833. $hfst = $h[$side][$pos]['font-style'];
  9834. }
  9835. if (isset($h[$side][$pos]['color']) && $h[$side][$pos]['color']) {
  9836. $hfcol = $h[$side][$pos]['color'];
  9837. $cor = $this->ConvertColor($hfcol);
  9838. if ($cor) { $this->SetTColor($cor); }
  9839. }
  9840. else { $hfcol = ''; }
  9841. $this->SetFont($hff,$hfst,$hfsz,true,true);
  9842. $this->x = $headerlmargin ;
  9843. $this->y = $this->margin_header - $yadj ;
  9844. $hd = $this->purify_utf8_text($hd);
  9845. if ($this->text_input_as_HTML) {
  9846. $hd = $this->all_entities_to_utf8($hd);
  9847. }
  9848. // CONVERT CODEPAGE
  9849. if ($this->usingCoreFont) { $hd = mb_convert_encoding($hd,$this->mb_enc,'UTF-8'); }
  9850. // DIRECTIONALITY RTL
  9851. $this->magic_reverse_dir($hd, true, $this->directionality); // *RTL*
  9852. // Font-specific ligature substitution for Indic fonts
  9853. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($hd); // *INDIC*
  9854. $align = $pos;
  9855. /*-- RTL --*/
  9856. if ($this->directionality == 'rtl') {
  9857. if ($pos == 'L') { $align = 'R'; }
  9858. else if ($pos == 'R') { $align = 'L'; }
  9859. }
  9860. /*-- END RTL --*/
  9861. if ($pos!='L' && (strpos($hd,$this->aliasNbPg)!==false || strpos($hd,$this->aliasNbPgGp)!==false)) {
  9862. if (strpos($hd,$this->aliasNbPgGp)!==false) { $type= 'nbpggp'; } else { $type= 'nbpg'; }
  9863. $this->_out('{mpdfheader'.$type.' '.$pos.' ff='.$hff.' fs='.$hfst.' fz='.$hfsz.'}');
  9864. $this->Cell($headerpgwidth ,$maxfontheight/_MPDFK ,$hd,0,0,$align,0,'',0,0,0,'M');
  9865. $this->_out('Q');
  9866. }
  9867. else {
  9868. $this->Cell($headerpgwidth ,$maxfontheight/_MPDFK ,$hd,0,0,$align,0,'',0,0,0,'M');
  9869. }
  9870. if ($hfcol) { $this->SetTColor($this->ConvertColor(0)); }
  9871. }
  9872. }
  9873. //Return Font to normal
  9874. $this->SetFont($this->default_font,'',$this->original_default_font_size);
  9875. // LINE
  9876. if (isset($h[$side]['line']) && $h[$side]['line']) {
  9877. $this->SetLineWidth(0.1);
  9878. $this->SetDColor($this->ConvertColor(0));
  9879. $this->Line($headerlmargin , $this->margin_header + ($maxfontheight*(1+$this->header_line_spacing)/_MPDFK) - $yadj , $headerlmargin + $headerpgwidth, $this->margin_header + ($maxfontheight*(1+$this->header_line_spacing)/_MPDFK) - $yadj );
  9880. }
  9881. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  9882. $this->_out('Q');
  9883. }
  9884. }
  9885. $this->SetY($this->tMargin);
  9886. if ($this->ColActive) { $this->pgwidth = $this->ColWidth; } // *COLUMNS*
  9887. $this->processingHeader=false;
  9888. }
  9889. /*-- TABLES --*/
  9890. function TableHeaderFooter($content='',$tablestartpage='',$tablestartcolumn ='',$horf = 'H',$level, $firstSpread=true, $finalSpread=true) { // mPDF 5.3.36
  9891. if(($horf=='H' || $horf=='F') && !empty($content)) { // mPDF 5.3.62
  9892. $table = &$this->table[1][1];
  9893. // Advance down page by half width of top border
  9894. if ($horf=='H') { // Only if header
  9895. if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2 + $table['border_details']['T']['w'] + $table['padding']['T']; }
  9896. else { $adv = $table['max_cell_border_width']['T'] /2 ; }
  9897. if ($adv) {
  9898. if ($this->table_rotate) {
  9899. $this->y += ($adv);
  9900. }
  9901. else {
  9902. $this->DivLn($adv,$this->blklvl,true);
  9903. }
  9904. }
  9905. }
  9906. if ($horf=='F') { // Table Footer
  9907. $firstrow = count($table['cells']) - $table['footernrows']; // mPDF 5.3.62
  9908. $lastrow = count($table['cells']) - 1;
  9909. }
  9910. else { // Table Header
  9911. $firstrow = 0;
  9912. $lastrow = $table['headernrows'] - 1; // mPDF 5.3.62
  9913. }
  9914. $topy = $content[$firstrow][0]['y']-$this->y;
  9915. for ($i=$firstrow ; $i<=$lastrow; $i++) {
  9916. $y = $this->y;
  9917. /*-- COLUMNS --*/
  9918. // If outside columns, this is done in PaintDivBB
  9919. if ($this->ColActive) {
  9920. //OUTER FILL BGCOLOR of DIVS
  9921. if ($this->blklvl > 0) {
  9922. $firstblockfill = $this->GetFirstBlockFill();
  9923. if ($firstblockfill && $this->blklvl >= $firstblockfill) {
  9924. $divh = $content[$i][0]['h'];
  9925. $bak_x = $this->x;
  9926. $this->DivLn($divh,-3,false);
  9927. // Reset current block fill
  9928. $bcor = $this->blk[$this->blklvl]['bgcolorarray'];
  9929. $this->SetFColor($bcor);
  9930. $this->x = $bak_x;
  9931. }
  9932. }
  9933. }
  9934. /*-- END COLUMNS --*/
  9935. $colctr = 0;
  9936. foreach($content[$i] as $tablehf) {
  9937. $colctr++;
  9938. $y = $tablehf['y'] - $topy;
  9939. $this->y = $y;
  9940. //Set some cell values
  9941. $x = $tablehf['x'];
  9942. if (($this->mirrorMargins) && ($tablestartpage == 'ODD') && (($this->page)%2==0)) { // EVEN
  9943. $x = $x +$this->MarginCorrection;
  9944. }
  9945. else if (($this->mirrorMargins) && ($tablestartpage == 'EVEN') && (($this->page)%2==1)) { // ODD
  9946. $x = $x +$this->MarginCorrection;
  9947. }
  9948. /*-- COLUMNS --*/
  9949. // Added to correct for Columns
  9950. if ($this->ColActive) {
  9951. if ($this->directionality == 'rtl') { // *RTL*
  9952. $x -= ($this->CurrCol - $tablestartcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  9953. } // *RTL*
  9954. else { // *RTL*
  9955. $x += ($this->CurrCol - $tablestartcolumn) * ($this->ColWidth+$this->ColGap);
  9956. } // *RTL*
  9957. }
  9958. /*-- END COLUMNS --*/
  9959. if ($colctr==1) { $x0 = $x; }
  9960. // mPDF ITERATION
  9961. if ($this->iterationCounter) {
  9962. foreach($tablehf['textbuffer'] AS $k=>$t) { // mPDF 5.3.78
  9963. if (preg_match('/{iteration ([a-zA-Z0-9_]+)}/',$t, $m)) {
  9964. $vname = '__'.$m[1].'_';
  9965. if (!isset($this->$vname)) { $this->$vname = 1; }
  9966. else { $this->$vname++; }
  9967. $tablehf['textbuffer'][$k][0] = preg_replace('/{iteration '.$m[1].'}/', $this->$vname, $tablehf['textbuffer'][$k][0]);
  9968. }
  9969. }
  9970. }
  9971. $w = $tablehf['w'];
  9972. $h = $tablehf['h'];
  9973. $va = $tablehf['va'];
  9974. $R = $tablehf['R'];
  9975. $mih = $tablehf['mih'];
  9976. $border = $tablehf['border'];
  9977. $border_details = $tablehf['border_details'];
  9978. $padding = $tablehf['padding'];
  9979. $this->tabletheadjustfinished = true;
  9980. $textbuffer = $tablehf['textbuffer'];
  9981. $align = $tablehf['a'];
  9982. //Align
  9983. $this->divalign=$align;
  9984. $this->x = $x;
  9985. if ($this->ColActive) {
  9986. if ($table['borders_separate']) {
  9987. $tablefill = isset($table['bgcolor'][-1]) ? $table['bgcolor'][-1] : 0;
  9988. if ($tablefill) {
  9989. $color = $this->ConvertColor($tablefill);
  9990. if ($color) {
  9991. $xadj = ($table['border_spacing_H']/2);
  9992. $yadj = ($table['border_spacing_V']/2);
  9993. $wadj = $table['border_spacing_H'];
  9994. $hadj = $table['border_spacing_V'];
  9995. if ($i == $firstrow && $horf=='H') { // Top
  9996. $yadj += $table['padding']['T'] + $table['border_details']['T']['w'] ;
  9997. $hadj += $table['padding']['T'] + $table['border_details']['T']['w'] ;
  9998. }
  9999. if (($i == ($lastrow) || (isset($tablehf['rowspan']) && ($i+$tablehf['rowspan']) == ($lastrow+1)) || (!isset($tablehf['rowspan']) && ($i+1) == ($lastrow+1))) && $horf=='F') { // Bottom
  10000. $hadj += $table['padding']['B'] + $table['border_details']['B']['w'] ;
  10001. }
  10002. if ($colctr == 1) { // Left
  10003. $xadj += $table['padding']['L'] + $table['border_details']['L']['w'] ;
  10004. $wadj += $table['padding']['L'] + $table['border_details']['L']['w'] ;
  10005. }
  10006. if ($colctr == count($content[$i]) ) { // Right
  10007. $wadj += $table['padding']['R'] + $table['border_details']['R']['w'] ;
  10008. }
  10009. $this->SetFColor($color);
  10010. $this->Rect($x - $xadj, $y - $yadj, $w + $wadj, $h + $hadj, 'F');
  10011. }
  10012. }
  10013. }
  10014. }
  10015. if ($table['empty_cells']!='hide' || !empty($textbuffer) || !$table['borders_separate']) { $paintcell = true; }
  10016. else { $paintcell = false; }
  10017. //Vertical align
  10018. if ($R && INTVAL($R) > 0 && isset($va) && $va!='B') { $va='B';}
  10019. if (!isset($va) || empty($va) || $va=='M') $this->y += ($h-$mih)/2;
  10020. elseif (isset($va) && $va=='B') $this->y += $h-$mih;
  10021. //TABLE ROW OR CELL FILL BGCOLOR
  10022. $fill = 0;
  10023. if (isset($tablehf['bgcolor']) && $tablehf['bgcolor'] && $tablehf['bgcolor']!='transparent') {
  10024. $fill = $tablehf['bgcolor'];
  10025. $leveladj = 6;
  10026. }
  10027. else if (isset($content[$i][0]['trbgcolor']) && $content[$i][0]['trbgcolor'] && $content[$i][0]['trbgcolor']!='transparent') { // Row color
  10028. $fill = $content[$i][0]['trbgcolor'];
  10029. $leveladj = 3;
  10030. }
  10031. if ($fill && $paintcell) {
  10032. $color = $this->ConvertColor($fill);
  10033. if ($color) {
  10034. if ($table['borders_separate']) {
  10035. if ($this->ColActive) {
  10036. $this->SetFColor($color);
  10037. $this->Rect($x+ ($table['border_spacing_H']/2), $y+ ($table['border_spacing_V']/2), $w- $table['border_spacing_H'], $h- $table['border_spacing_V'], 'F');
  10038. }
  10039. else {
  10040. $this->tableBackgrounds[$level*9+$leveladj][] = array('gradient'=>false, 'x'=>($x + ($table['border_spacing_H']/2)), 'y'=>($y + ($table['border_spacing_V']/2)), 'w'=>($w - $table['border_spacing_H']), 'h'=>($h - $table['border_spacing_V']), 'col'=>$color);
  10041. }
  10042. }
  10043. else {
  10044. if ($this->ColActive) {
  10045. $this->SetFColor($color);
  10046. $this->Rect($x, $y, $w, $h, 'F');
  10047. }
  10048. else {
  10049. $this->tableBackgrounds[$level*9+$leveladj][] = array('gradient'=>false, 'x'=>$x, 'y'=>$y, 'w'=>$w, 'h'=>$h, 'col'=>$color);
  10050. }
  10051. }
  10052. }
  10053. }
  10054. /*-- BACKGROUNDS --*/
  10055. if (isset($tablehf['gradient']) && $tablehf['gradient'] && $paintcell){
  10056. $g = $this->grad->parseBackgroundGradient($tablehf['gradient']);
  10057. if ($g) {
  10058. if ($table['borders_separate']) {
  10059. $px = $x+ ($table['border_spacing_H']/2);
  10060. $py = $y+ ($table['border_spacing_V']/2);
  10061. $pw = $w- $table['border_spacing_H'];
  10062. $ph = $h- $table['border_spacing_V'];
  10063. }
  10064. else {
  10065. $px = $x;
  10066. $py = $y;
  10067. $pw = $w;
  10068. $ph = $h;
  10069. }
  10070. if ($this->ColActive) {
  10071. $this->grad->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']);
  10072. }
  10073. else {
  10074. $this->tableBackgrounds[$level*9+7][] = array('gradient'=>true, 'x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  10075. }
  10076. }
  10077. }
  10078. if (isset($tablehf['background-image']) && $paintcell){
  10079. if ($tablehf['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $tablehf['background-image']['gradient'] )) {
  10080. $g = $this->grad->parseMozGradient( $tablehf['background-image']['gradient'] );
  10081. if ($g) {
  10082. if ($table['borders_separate']) {
  10083. $px = $x+ ($table['border_spacing_H']/2);
  10084. $py = $y+ ($table['border_spacing_V']/2);
  10085. $pw = $w- $table['border_spacing_H'];
  10086. $ph = $h- $table['border_spacing_V'];
  10087. }
  10088. else {
  10089. $px = $x;
  10090. $py = $y;
  10091. $pw = $w;
  10092. $ph = $h;
  10093. }
  10094. if ($this->ColActive) {
  10095. $this->grad->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']);
  10096. }
  10097. else {
  10098. $this->tableBackgrounds[$level*9+7][] = array('gradient'=>true, 'x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  10099. }
  10100. }
  10101. }
  10102. else if ($tablehf['background-image']['image_id']) { // Background pattern
  10103. $n = count($this->patterns)+1;
  10104. if ($table['borders_separate']) {
  10105. $px = $x+ ($table['border_spacing_H']/2);
  10106. $py = $y+ ($table['border_spacing_V']/2);
  10107. $pw = $w- $table['border_spacing_H'];
  10108. $ph = $h- $table['border_spacing_V'];
  10109. }
  10110. else {
  10111. $px = $x;
  10112. $py = $y;
  10113. $pw = $w;
  10114. $ph = $h;
  10115. }
  10116. if ($this->ColActive) {
  10117. list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this->_resizeBackgroundImage($tablehf['background-image']['orig_w'], $tablehf['background-image']['orig_h'], $pw, $ph, $tablehf['background-image']['resize'], $tablehf['background-image']['x_repeat'] , $tablehf['background-image']['y_repeat']);
  10118. $this->patterns[$n] = array('x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'pgh'=>$this->h, 'image_id'=>$tablehf['background-image']['image_id'], 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$tablehf['background-image']['x_pos'] , 'y_pos'=>$tablehf['background-image']['y_pos'] , 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'itype'=>$tablehf['background-image']['itype']);
  10119. if ($tablehf['background-image']['opacity']>0 && $tablehf['background-image']['opacity']<1) { $opac = $this->SetAlpha($tablehf['background-image']['opacity'],'Normal',true); }
  10120. else { $opac = ''; }
  10121. $this->_out(sprintf('q /Pattern cs /P%d scn %s %.3F %.3F %.3F %.3F re f Q', $n, $opac, $px*_MPDFK, ($this->h-$py)*_MPDFK, $pw*_MPDFK, -$ph*_MPDFK));
  10122. }
  10123. else { // mPDF 5.3.99
  10124. $this->tableBackgrounds[$level*9+8][] = array('x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'image_id'=>$tablehf['background-image']['image_id'], 'orig_w'=>$tablehf['background-image']['orig_w'], 'orig_h'=>$tablehf['background-image']['orig_h'], 'x_pos'=>$tablehf['background-image']['x_pos'], 'y_pos'=>$tablehf['background-image']['y_pos'], 'x_repeat'=>$tablehf['background-image']['x_repeat'], 'y_repeat'=>$tablehf['background-image']['y_repeat'], 'clippath'=>'', 'resize'=>$tablehf['background-image']['resize'], 'opacity'=>$tablehf['background-image']['opacity'], 'itype'=>$tablehf['background-image']['itype']);
  10125. }
  10126. }
  10127. }
  10128. /*-- END BACKGROUNDS --*/
  10129. //Cell Border
  10130. if ($table['borders_separate'] && $paintcell && $border) {
  10131. $this->_tableRect($x+ ($table['border_spacing_H']/2)+($border_details['L']['w'] /2), $y+ ($table['border_spacing_V']/2)+($border_details['T']['w'] /2), $w-$table['border_spacing_H']-($border_details['L']['w'] /2)-($border_details['R']['w'] /2), $h- $table['border_spacing_V']-($border_details['T']['w'] /2)-($border_details['B']['w']/2), $border, $border_details, false, $table['borders_separate']);
  10132. }
  10133. else if ($paintcell && $border) {
  10134. $this->_tableRect($x, $y, $w, $h, $border, $border_details, true, $table['borders_separate']); // true causes buffer
  10135. }
  10136. //Print cell content
  10137. //$this->divheight = $this->table_lineheight*$this->lineheight;
  10138. if (!empty($textbuffer)) {
  10139. if ($horf=='F' && preg_match('/{colsum([0-9]*)[_]*}/', $textbuffer[0][0], $m)) { // mPDF 5.3.92
  10140. $rep = sprintf("%01.".intval($m[1])."f", $this->colsums[$colctr-1]);
  10141. $textbuffer[0][0] = preg_replace('/{colsum[0-9_]*}/', $rep ,$textbuffer[0][0]);
  10142. }
  10143. if ($R) {
  10144. $cellPtSize = $textbuffer[0][11] / $this->shrin_k;
  10145. if (!$cellPtSize) { $cellPtSize = $this->default_font_size; }
  10146. $cellFontHeight = ($cellPtSize/_MPDFK);
  10147. $opx = $this->x;
  10148. $opy = $this->y;
  10149. $angle = INTVAL($R);
  10150. // Only allow 45 - 90 degrees (when bottom-aligned) or -90
  10151. if ($angle > 90) { $angle = 90; }
  10152. else if ($angle > 0 && (isset($va) && $va!='B')) { $angle = 90; }
  10153. else if ($angle > 0 && $angle <45) { $angle = 45; }
  10154. else if ($angle < 0) { $angle = -90; }
  10155. $offset = ((sin(deg2rad($angle))) * 0.37 * $cellFontHeight);
  10156. if (isset($align) && $align =='R') {
  10157. $this->x += ($w) + ($offset) - ($cellFontHeight/3) - ($padding['R'] + $border_details['R']['w']);
  10158. }
  10159. else if (!isset($align ) || $align =='C') {
  10160. $this->x += ($w/2) + ($offset);
  10161. }
  10162. else {
  10163. $this->x += ($offset) + ($cellFontHeight/3)+($padding['L'] + $border_details['L']['w']);
  10164. }
  10165. // mPDF 5.3.78
  10166. $str = '';
  10167. foreach($tablehf['textbuffer'] AS $t) { $str .= $t[0].' '; }
  10168. $str = trim($str);
  10169. if (!isset($va) || $va=='M') {
  10170. $this->y -= ($h-$mih)/2; //Undo what was added earlier VERTICAL ALIGN
  10171. if ($angle > 0) { $this->y += (($h-$mih)/2)+($padding['T'] + $border_details['T']['w']) + ($mih-($padding['T'] + $border_details['T']['w']+$border_details['B']['w']+$padding['B'])); }
  10172. else if ($angle < 0) { $this->y += (($h-$mih)/2)+($padding['T'] + $border_details['T']['w']); }
  10173. }
  10174. else if (isset($va) && $va=='B') {
  10175. $this->y -= $h-$mih; //Undo what was added earlier VERTICAL ALIGN
  10176. if ($angle > 0) { $this->y += $h-($border_details['B']['w']+$padding['B']); }
  10177. else if ($angle < 0) { $this->y += $h-$mih+($padding['T'] + $border_details['T']['w']); }
  10178. }
  10179. else if (isset($va) && $va=='T') {
  10180. if ($angle > 0) { $this->y += $mih-($border_details['B']['w']+$padding['B']); }
  10181. else if ($angle < 0) { $this->y += ($padding['T'] + $border_details['T']['w']); }
  10182. }
  10183. $this->Rotate($angle,$this->x,$this->y);
  10184. $s_fs = $this->FontSizePt;
  10185. $s_f = $this->FontFamily;
  10186. $s_st = $this->FontStyle;
  10187. // mPDF 5.3.54
  10188. if (!empty($textbuffer[0][3])) { //Font Color
  10189. $cor = $textbuffer[0][3];
  10190. $this->SetTColor($cor);
  10191. }
  10192. $s_str = $this->strike;
  10193. $this->strike = $textbuffer[0][8]; //Strikethrough
  10194. $this->SetFont($textbuffer[0][4],$textbuffer[0][2],$cellPtSize,true,true);
  10195. $this->Text($this->x,$this->y,$str);
  10196. $this->Rotate(0);
  10197. $this->SetFont($s_f,$s_st,$s_fs,true,true);
  10198. $this->SetTColor(0); // mPDF 5.3.54
  10199. $this->strike = $s_str; // mPDF 5.3.54
  10200. $this->x = $opx;
  10201. $this->y = $opy;
  10202. }
  10203. else {
  10204. if ($table['borders_separate']) { // NB twice border width
  10205. $xadj = $border_details['L']['w'] + $padding['L'] +($table['border_spacing_H']/2);
  10206. $wadj = $border_details['L']['w'] + $border_details['R']['w'] + $padding['L'] +$padding['R'] + $table['border_spacing_H'];
  10207. $yadj = $border_details['T']['w'] + $padding['T'] + ($table['border_spacing_H']/2);
  10208. }
  10209. else {
  10210. $xadj = $border_details['L']['w']/2 + $padding['L'];
  10211. $wadj = ($border_details['L']['w'] + $border_details['R']['w'])/2 + $padding['L'] + $padding['R'];
  10212. $yadj = $border_details['T']['w']/2 + $padding['T'];
  10213. }
  10214. $this->divwidth=$w-($wadj);
  10215. $this->x += $xadj;
  10216. $this->y += $yadj;
  10217. $this->printbuffer($textbuffer,'',true);
  10218. }
  10219. }
  10220. $textbuffer = array();
  10221. /*-- BACKGROUNDS --*/
  10222. if (!$this->ColActive) {
  10223. if (isset($content[$i][0]['trgradients']) && ($colctr==1 || $table['borders_separate'])) {
  10224. $g = $this->grad->parseBackgroundGradient($content[$i][0]['trgradients']);
  10225. if ($g) {
  10226. $gx = $x0;
  10227. $gy = $y;
  10228. $gh = $h;
  10229. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  10230. if ($table['borders_separate']) {
  10231. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  10232. $s = '';
  10233. $clx = $x+ ($table['border_spacing_H']/2);
  10234. $cly = $y+ ($table['border_spacing_V']/2);
  10235. $clw = $w- $table['border_spacing_H'];
  10236. $clh = $h- $table['border_spacing_V'];
  10237. // Set clipping path
  10238. $s = ' q 0 w '; // Line width=0
  10239. $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc
  10240. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL
  10241. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR
  10242. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR
  10243. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL
  10244. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  10245. $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx + ($table['border_spacing_H']/2), 'y'=>$gy + ($table['border_spacing_V']/2), 'w'=>$gw - $table['border_spacing_V'], 'h'=>$gh - $table['border_spacing_H'], 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>$s);
  10246. }
  10247. else {
  10248. $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx, 'y'=>$gy, 'w'=>$gw, 'h'=>$gh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  10249. }
  10250. }
  10251. }
  10252. if (isset($content[$i][0]['trbackground-images']) && ($colctr==1 || $table['borders_separate'])) {
  10253. if ($content[$i][0]['trbackground-images']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $content[$i][0]['trbackground-images']['gradient'] )) {
  10254. $g = $this->grad->parseMozGradient( $content[$i][0]['trbackground-images']['gradient'] );
  10255. if ($g) {
  10256. $gx = $x0;
  10257. $gy = $y;
  10258. $gh = $h;
  10259. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  10260. if ($table['borders_separate']) {
  10261. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  10262. $s = '';
  10263. $clx = $x+ ($table['border_spacing_H']/2);
  10264. $cly = $y+ ($table['border_spacing_V']/2);
  10265. $clw = $w- $table['border_spacing_H'];
  10266. $clh = $h- $table['border_spacing_V'];
  10267. // Set clipping path
  10268. $s = ' q 0 w '; // Line width=0
  10269. $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc
  10270. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL
  10271. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR
  10272. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR
  10273. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL
  10274. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  10275. $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx + ($table['border_spacing_H']/2), 'y'=>$gy + ($table['border_spacing_V']/2), 'w'=>$gw - $table['border_spacing_V'], 'h'=>$gh - $table['border_spacing_H'], 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>$s);
  10276. }
  10277. else {
  10278. $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx, 'y'=>$gy, 'w'=>$gw, 'h'=>$gh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  10279. }
  10280. }
  10281. }
  10282. else {
  10283. $image_id = $content[$i][0]['trbackground-images']['image_id'];
  10284. $orig_w = $content[$i][0]['trbackground-images']['orig_w'];
  10285. $orig_h = $content[$i][0]['trbackground-images']['orig_h'];
  10286. $x_pos = $content[$i][0]['trbackground-images']['x_pos'];
  10287. $y_pos = $content[$i][0]['trbackground-images']['y_pos'];
  10288. $x_repeat = $content[$i][0]['trbackground-images']['x_repeat'];
  10289. $y_repeat = $content[$i][0]['trbackground-images']['y_repeat'];
  10290. $resize = $content[$i][0]['trbackground-images']['resize'];
  10291. $opacity = $content[$i][0]['trbackground-images']['opacity'];
  10292. $itype = $content[$i][0]['trbackground-images']['itype']; // mPDF 5.3.99
  10293. $clippath = '';
  10294. $gx = $x0;
  10295. $gy = $y;
  10296. $gh = $h;
  10297. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  10298. if ($table['borders_separate']) {
  10299. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  10300. $s = '';
  10301. $clx = $x+ ($table['border_spacing_H']/2);
  10302. $cly = $y+ ($table['border_spacing_V']/2);
  10303. $clw = $w- $table['border_spacing_H'];
  10304. $clh = $h- $table['border_spacing_V'];
  10305. // Set clipping path
  10306. $s = ' q 0 w '; // Line width=0
  10307. $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc
  10308. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL
  10309. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR
  10310. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR
  10311. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL
  10312. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  10313. $this->tableBackgrounds[$level*9+5][] = array('x'=>$gx + ($table['border_spacing_H']/2), 'y'=>$gy + ($table['border_spacing_V']/2), 'w'=>$gw - $table['border_spacing_V'], 'h'=>$gh - $table['border_spacing_H'], 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>$s, 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$itype);
  10314. }
  10315. else {
  10316. $this->tableBackgrounds[$level*9+5][] = array('x'=>$gx, 'y'=>$gy, 'w'=>$gw, 'h'=>$gh, 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>'', 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$itype);
  10317. }
  10318. }
  10319. }
  10320. }
  10321. /*-- END BACKGROUNDS --*/
  10322. // TABLE BORDER - if separate OR collapsed and only table border
  10323. // mPDF 5.3.15
  10324. if (($table['borders_separate'] || ($this->simpleTables && !$table['simple']['border'])) && $table['border']) {
  10325. $halfspaceL = $table['padding']['L'] + ($table['border_spacing_H']/2);
  10326. $halfspaceR = $table['padding']['R'] + ($table['border_spacing_H']/2);
  10327. $halfspaceT = $table['padding']['T'] + ($table['border_spacing_V']/2);
  10328. $halfspaceB = $table['padding']['B'] + ($table['border_spacing_V']/2);
  10329. $tbx = $x;
  10330. $tby = $y;
  10331. $tbw = $w;
  10332. $tbh = $h;
  10333. $tab_bord = 0;
  10334. $corner = '';
  10335. if ($i == $firstrow && $horf=='H') { // Top
  10336. $tby -= $halfspaceT + ($table['border_details']['T']['w']/2);
  10337. $tbh += $halfspaceT + ($table['border_details']['T']['w']/2);
  10338. $this->setBorder($tab_bord , _BORDER_TOP);
  10339. $corner .= 'T';
  10340. }
  10341. // mPDF 5.3.15
  10342. if (($i == ($lastrow) || (isset($tablehf['rowspan']) && ($i+$tablehf['rowspan']) == ($lastrow+1))) && $horf=='F') { // Bottom
  10343. $tbh += $halfspaceB + ($table['border_details']['B']['w']/2);
  10344. $this->setBorder($tab_bord , _BORDER_BOTTOM);
  10345. $corner .= 'B';
  10346. }
  10347. if ($colctr == 1 && $firstSpread) { // Left // mPDF 5.3.36
  10348. $tbx -= $halfspaceL + ($table['border_details']['L']['w']/2);
  10349. $tbw += $halfspaceL + ($table['border_details']['L']['w']/2);
  10350. $this->setBorder($tab_bord , _BORDER_LEFT);
  10351. $corner .= 'L';
  10352. }
  10353. if ($colctr == count($content[$i]) && $finalSpread) { // Right // mPDF 5.3.36
  10354. $tbw += $halfspaceR + ($table['border_details']['R']['w']/2);
  10355. $this->setBorder($tab_bord , _BORDER_RIGHT);
  10356. $corner .= 'R';
  10357. }
  10358. $this->_tableRect($tbx, $tby, $tbw, $tbh, $tab_bord , $table['border_details'], false, $table['borders_separate'], 'table', $corner, $table['border_spacing_V'], $table['border_spacing_H'] );
  10359. }
  10360. }// end column $content
  10361. $this->y = $y + $h; //Update y coordinate
  10362. }// end row $i
  10363. unset($table );
  10364. $this->colsums = array(); // mPDF 5.3.92
  10365. }
  10366. }
  10367. /*-- END TABLES --*/
  10368. /*-- HTMLHEADERS-FOOTERS --*/
  10369. function SetHTMLHeader($header='',$OE='',$write=false) {
  10370. $height = 0;
  10371. if (is_array($header) && isset($header['html']) && $header['html']) {
  10372. $Hhtml = $header['html'];
  10373. if ($this->setAutoTopMargin) {
  10374. if (isset($header['h'])) { $height = $header['h']; }
  10375. else { $height = $this->_gethtmlheight($Hhtml); }
  10376. }
  10377. }
  10378. else if (!is_array($header) && $header) {
  10379. $Hhtml = $header;
  10380. if ($this->setAutoTopMargin) { $height = $this->_gethtmlheight($Hhtml); }
  10381. }
  10382. else { $Hhtml = ''; }
  10383. if ($OE != 'E') { $OE = 'O'; }
  10384. if ($OE == 'E') {
  10385. if ($Hhtml) {
  10386. $this->HTMLHeaderE['html'] = $Hhtml;
  10387. $this->HTMLHeaderE['h'] = $height;
  10388. }
  10389. else { $this->HTMLHeaderE = ''; }
  10390. }
  10391. else {
  10392. if ($Hhtml) {
  10393. $this->HTMLHeader['html'] = $Hhtml;
  10394. $this->HTMLHeader['h'] = $height;
  10395. }
  10396. else { $this->HTMLHeader = ''; }
  10397. }
  10398. if (!$this->mirrorMargins && $OE == 'E') { return; }
  10399. if ($Hhtml=='') { return; }
  10400. if ($OE == 'E') {
  10401. $this->headerDetails['even'] = array(); // override and clear any other non-HTML header/footer
  10402. }
  10403. else {
  10404. $this->headerDetails['odd'] = array(); // override and clear any non-HTML other header/footer
  10405. }
  10406. if ($this->setAutoTopMargin=='pad') {
  10407. $this->tMargin = $this->margin_header + $height + $this->orig_tMargin;
  10408. if (isset($this->saveHTMLHeader[$this->page][$OE]['mt'])) { $this->saveHTMLHeader[$this->page][$OE]['mt'] = $this->tMargin; }
  10409. }
  10410. else if ($this->setAutoTopMargin=='stretch') {
  10411. $this->tMargin = max($this->orig_tMargin, $this->margin_header + $height + $this->autoMarginPadding);
  10412. if (isset($this->saveHTMLHeader[$this->page][$OE]['mt'])) { $this->saveHTMLHeader[$this->page][$OE]['mt'] = $this->tMargin; }
  10413. }
  10414. if ($write && $this->state!=0 && (($this->mirrorMargins && $OE == 'E' && ($this->page)%2==0) || ($this->mirrorMargins && $OE != 'E' && ($this->page)%2==1) || !$this->mirrorMargins)) { $this->writeHTMLHeaders(); }
  10415. }
  10416. function SetHTMLFooter($footer='',$OE='') {
  10417. $height = 0;
  10418. if (is_array($footer) && isset($footer['html']) && $footer['html']) {
  10419. $Fhtml = $footer['html'];
  10420. if ($this->setAutoBottomMargin) {
  10421. if (isset($footer['h'])) { $height = $footer['h']; }
  10422. else { $height = $this->_gethtmlheight($Fhtml); }
  10423. }
  10424. }
  10425. else if (!is_array($footer) && $footer) {
  10426. $Fhtml = $footer;
  10427. if ($this->setAutoBottomMargin) { $height = $this->_gethtmlheight($Fhtml); }
  10428. }
  10429. else { $Fhtml = ''; }
  10430. if ($OE != 'E') { $OE = 'O'; }
  10431. if ($OE == 'E') {
  10432. if ($Fhtml) {
  10433. $this->HTMLFooterE['html'] = $Fhtml;
  10434. $this->HTMLFooterE['h'] = $height;
  10435. }
  10436. else { $this->HTMLFooterE = ''; }
  10437. }
  10438. else {
  10439. if ($Fhtml) {
  10440. $this->HTMLFooter['html'] = $Fhtml;
  10441. $this->HTMLFooter['h'] = $height;
  10442. }
  10443. else { $this->HTMLFooter = ''; }
  10444. }
  10445. if (!$this->mirrorMargins && $OE == 'E') { return; }
  10446. if ($Fhtml=='') { return false; }
  10447. if ($OE == 'E') {
  10448. $this->footerDetails['even'] = array(); // override and clear any other header/footer
  10449. }
  10450. else {
  10451. $this->footerDetails['odd'] = array(); // override and clear any other header/footer
  10452. }
  10453. if ($this->setAutoBottomMargin=='pad') {
  10454. $this->bMargin = $this->margin_footer + $height + $this->orig_bMargin;
  10455. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  10456. if (isset($this->saveHTMLHeader[$this->page][$OE]['mb'])) { $this->saveHTMLHeader[$this->page][$OE]['mb'] = $this->bMargin; }
  10457. }
  10458. else if ($this->setAutoBottomMargin=='stretch') {
  10459. $this->bMargin = max($this->orig_bMargin, $this->margin_footer + $height + $this->autoMarginPadding);
  10460. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  10461. if (isset($this->saveHTMLHeader[$this->page][$OE]['mb'])) { $this->saveHTMLHeader[$this->page][$OE]['mb'] = $this->bMargin; }
  10462. }
  10463. }
  10464. function _getHtmlHeight($html) {
  10465. $save_state = $this->state;
  10466. if($this->state==0) {
  10467. $this->AddPage($this->CurOrientation);
  10468. }
  10469. $this->state = 2;
  10470. $this->Reset();
  10471. $this->pageoutput[$this->page] = array();
  10472. $save_x = $this->x;
  10473. $save_y = $this->y;
  10474. $this->x = $this->lMargin;
  10475. $this->y = $this->margin_header;
  10476. $html = str_replace('{PAGENO}',$this->pagenumPrefix.$this->docPageNum($this->page).$this->pagenumSuffix,$html);
  10477. $html = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->docPageNumTotal($this->page).$this->nbpgSuffix,$html );
  10478. $html = str_replace($this->aliasNbPg,$this->page,$html );
  10479. $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );
  10480. $this->HTMLheaderPageLinks = array();
  10481. $this->HTMLheaderPageAnnots = array();
  10482. $this->HTMLheaderPageForms = array();
  10483. $savepb = $this->pageBackgrounds;
  10484. $this->writingHTMLheader = true;
  10485. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  10486. $this->writingHTMLheader = false;
  10487. $h = ($this->y - $this->margin_header);
  10488. $this->Reset();
  10489. $this->pageoutput[$this->page] = array();
  10490. $this->headerbuffer = '';
  10491. $this->pageBackgrounds = $savepb;
  10492. $this->x = $save_x;
  10493. $this->y = $save_y;
  10494. $this->state = $save_state;
  10495. if($save_state==0) {
  10496. unset($this->pages[1]);
  10497. $this->page = 0;
  10498. }
  10499. return $h;
  10500. }
  10501. // Called internally from Header
  10502. function writeHTMLHeaders() {
  10503. if ($this->mirrorMargins && ($this->page)%2==0) { $OE = 'E'; } // EVEN
  10504. else { $OE = 'O'; }
  10505. if ($OE == 'E') {
  10506. $this->saveHTMLHeader[$this->page][$OE]['html'] = $this->HTMLHeaderE['html'] ;
  10507. }
  10508. else {
  10509. $this->saveHTMLHeader[$this->page][$OE]['html'] = $this->HTMLHeader['html'] ;
  10510. }
  10511. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  10512. $this->saveHTMLHeader[$this->page][$OE]['rotate'] = true;
  10513. $this->saveHTMLHeader[$this->page][$OE]['ml'] = $this->tMargin;
  10514. $this->saveHTMLHeader[$this->page][$OE]['mr'] = $this->bMargin;
  10515. $this->saveHTMLHeader[$this->page][$OE]['mh'] = $this->margin_header;
  10516. $this->saveHTMLHeader[$this->page][$OE]['mf'] = $this->margin_footer;
  10517. $this->saveHTMLHeader[$this->page][$OE]['pw'] = $this->h;
  10518. $this->saveHTMLHeader[$this->page][$OE]['ph'] = $this->w;
  10519. }
  10520. else {
  10521. $this->saveHTMLHeader[$this->page][$OE]['ml'] = $this->lMargin;
  10522. $this->saveHTMLHeader[$this->page][$OE]['mr'] = $this->rMargin;
  10523. $this->saveHTMLHeader[$this->page][$OE]['mh'] = $this->margin_header;
  10524. $this->saveHTMLHeader[$this->page][$OE]['mf'] = $this->margin_footer;
  10525. $this->saveHTMLHeader[$this->page][$OE]['pw'] = $this->w;
  10526. $this->saveHTMLHeader[$this->page][$OE]['ph'] = $this->h;
  10527. }
  10528. }
  10529. function writeHTMLFooters() {
  10530. if ($this->mirrorMargins && ($this->page)%2==0) { $OE = 'E'; } // EVEN
  10531. else { $OE = 'O'; }
  10532. if ($OE == 'E') {
  10533. $this->saveHTMLFooter[$this->page][$OE]['html'] = $this->HTMLFooterE['html'] ;
  10534. }
  10535. else {
  10536. $this->saveHTMLFooter[$this->page][$OE]['html'] = $this->HTMLFooter['html'] ;
  10537. }
  10538. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  10539. $this->saveHTMLFooter[$this->page][$OE]['rotate'] = true;
  10540. $this->saveHTMLFooter[$this->page][$OE]['ml'] = $this->tMargin;
  10541. $this->saveHTMLFooter[$this->page][$OE]['mr'] = $this->bMargin;
  10542. $this->saveHTMLFooter[$this->page][$OE]['mt'] = $this->rMargin;
  10543. $this->saveHTMLFooter[$this->page][$OE]['mb'] = $this->lMargin;
  10544. $this->saveHTMLFooter[$this->page][$OE]['mh'] = $this->margin_header;
  10545. $this->saveHTMLFooter[$this->page][$OE]['mf'] = $this->margin_footer;
  10546. $this->saveHTMLFooter[$this->page][$OE]['pw'] = $this->h;
  10547. $this->saveHTMLFooter[$this->page][$OE]['ph'] = $this->w;
  10548. }
  10549. else {
  10550. $this->saveHTMLFooter[$this->page][$OE]['ml'] = $this->lMargin;
  10551. $this->saveHTMLFooter[$this->page][$OE]['mr'] = $this->rMargin;
  10552. $this->saveHTMLFooter[$this->page][$OE]['mt'] = $this->tMargin;
  10553. $this->saveHTMLFooter[$this->page][$OE]['mb'] = $this->bMargin;
  10554. $this->saveHTMLFooter[$this->page][$OE]['mh'] = $this->margin_header;
  10555. $this->saveHTMLFooter[$this->page][$OE]['mf'] = $this->margin_footer;
  10556. $this->saveHTMLFooter[$this->page][$OE]['pw'] = $this->w;
  10557. $this->saveHTMLFooter[$this->page][$OE]['ph'] = $this->h;
  10558. }
  10559. }
  10560. /*-- END HTMLHEADERS-FOOTERS --*/
  10561. function DefHeaderByName($name,$arr) {
  10562. if (!$name) { $name = '_default'; }
  10563. $this->pageheaders[$name] = $arr;
  10564. }
  10565. function DefFooterByName($name,$arr) {
  10566. if (!$name) { $name = '_default'; }
  10567. $this->pagefooters[$name] = $arr;
  10568. }
  10569. function SetHeaderByName($name,$side='O',$write=false) {
  10570. if (!$name) { $name = '_default'; }
  10571. if ($side=='E') { $this->headerDetails['even'] = $this->pageheaders[$name]; }
  10572. else { $this->headerDetails['odd'] = $this->pageheaders[$name]; }
  10573. if ($write) { $this->Header(); }
  10574. }
  10575. function SetFooterByName($name,$side='O') {
  10576. if (!$name) { $name = '_default'; }
  10577. if ($side=='E') { $this->footerDetails['even'] = $this->pagefooters[$name]; }
  10578. else { $this->footerDetails['odd'] = $this->pagefooters[$name]; }
  10579. }
  10580. /*-- HTMLHEADERS-FOOTERS --*/
  10581. function DefHTMLHeaderByName($name,$html) {
  10582. if (!$name) { $name = '_default'; }
  10583. $this->pageHTMLheaders[$name]['html'] = $html;
  10584. $this->pageHTMLheaders[$name]['h'] = $this->_gethtmlheight($html);
  10585. }
  10586. function DefHTMLFooterByName($name,$html) {
  10587. if (!$name) { $name = '_default'; }
  10588. $this->pageHTMLfooters[$name]['html'] = $html;
  10589. $this->pageHTMLfooters[$name]['h'] = $this->_gethtmlheight($html);
  10590. }
  10591. function SetHTMLHeaderByName($name,$side='O',$write=false) {
  10592. if (!$name) { $name = '_default'; }
  10593. $this->SetHTMLHeader($this->pageHTMLheaders[$name],$side,$write);
  10594. }
  10595. function SetHTMLFooterByName($name,$side='O') {
  10596. if (!$name) { $name = '_default'; }
  10597. $this->SetHTMLFooter($this->pageHTMLfooters[$name],$side,$write);
  10598. }
  10599. /*-- END HTMLHEADERS-FOOTERS --*/
  10600. function SetHeader($Harray=array(),$side='',$write=false) {
  10601. if (is_string($Harray)) {
  10602. if (strlen($Harray)==0) {
  10603. if ($side=='O') { $this->headerDetails['odd'] = array(); }
  10604. else if ($side=='E') { $this->headerDetails['even'] = array(); }
  10605. else { $this->headerDetails = array(); }
  10606. }
  10607. else if (strpos($Harray,'|') || strpos($Harray,'|')===0) {
  10608. $hdet = explode('|',$Harray);
  10609. $this->headerDetails = array (
  10610. 'odd' => array (
  10611. 'L' => array ('content' => $hdet[0], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10612. 'C' => array ('content' => $hdet[1], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10613. 'R' => array ('content' => $hdet[2], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10614. 'line' => $this->defaultheaderline,
  10615. ),
  10616. 'even' => array (
  10617. 'R' => array ('content' => $hdet[0], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10618. 'C' => array ('content' => $hdet[1], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10619. 'L' => array ('content' => $hdet[2], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10620. 'line' => $this->defaultheaderline,
  10621. )
  10622. );
  10623. }
  10624. else {
  10625. $this->headerDetails = array (
  10626. 'odd' => array (
  10627. 'R' => array ('content' => $Harray, 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10628. 'line' => $this->defaultheaderline,
  10629. ),
  10630. 'even' => array (
  10631. 'L' => array ('content' => $Harray, 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10632. 'line' => $this->defaultheaderline,
  10633. )
  10634. );
  10635. }
  10636. }
  10637. else if (is_array($Harray)) {
  10638. if ($side=='O') { $this->headerDetails['odd'] = $Harray; }
  10639. else if ($side=='E') { $this->headerDetails['even'] = $Harray; }
  10640. else { $this->headerDetails = $Harray; }
  10641. }
  10642. /*-- HTMLHEADERS-FOOTERS --*/
  10643. // Overwrite any HTML Header previously set
  10644. if ($side=='E') { $this->SetHTMLHeader('','E'); }
  10645. else if ($side=='O') { $this->SetHTMLHeader(''); }
  10646. else {
  10647. $this->SetHTMLHeader('');
  10648. $this->SetHTMLHeader('','E');
  10649. }
  10650. /*-- END HTMLHEADERS-FOOTERS --*/
  10651. if ($write) {
  10652. $save_y = $this->y;
  10653. $this->Header();
  10654. $this->SetY($save_y) ;
  10655. }
  10656. }
  10657. function SetFooter($Farray=array(),$side='') {
  10658. if (is_string($Farray)) {
  10659. if (strlen($Farray)==0) {
  10660. if ($side=='O') { $this->footerDetails['odd'] = array(); }
  10661. else if ($side=='E') { $this->footerDetails['even'] = array(); }
  10662. else { $this->footerDetails = array(); }
  10663. }
  10664. else if (strpos($Farray,'|') || strpos($Farray,'|')===0) {
  10665. $fdet = explode('|',$Farray);
  10666. $this->footerDetails = array (
  10667. 'odd' => array (
  10668. 'L' => array ('content' => $fdet[0], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10669. 'C' => array ('content' => $fdet[1], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10670. 'R' => array ('content' => $fdet[2], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10671. 'line' => $this->defaultfooterline,
  10672. ),
  10673. 'even' => array (
  10674. 'R' => array ('content' => $fdet[0], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10675. 'C' => array ('content' => $fdet[1], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10676. 'L' => array ('content' => $fdet[2], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10677. 'line' => $this->defaultfooterline,
  10678. )
  10679. );
  10680. }
  10681. else {
  10682. $this->footerDetails = array (
  10683. 'odd' => array (
  10684. 'R' => array ('content' => $Farray, 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10685. 'line' => $this->defaultfooterline,
  10686. ),
  10687. 'even' => array (
  10688. 'L' => array ('content' => $Farray, 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10689. 'line' => $this->defaultfooterline,
  10690. )
  10691. );
  10692. }
  10693. }
  10694. else if (is_array($Farray)) {
  10695. if ($side=='O') { $this->footerDetails['odd'] = $Farray; }
  10696. else if ($side=='E') { $this->footerDetails['even'] = $Farray; }
  10697. else { $this->footerDetails = $Farray; }
  10698. }
  10699. /*-- HTMLHEADERS-FOOTERS --*/
  10700. // Overwrite any HTML Footer previously set
  10701. if ($side=='E') { $this->SetHTMLFooter('','E'); }
  10702. else if ($side=='O') { $this->SetHTMLFooter(''); }
  10703. else {
  10704. $this->SetHTMLFooter('');
  10705. $this->SetHTMLFooter('','E');
  10706. }
  10707. /*-- END HTMLHEADERS-FOOTERS --*/
  10708. }
  10709. /*-- WATERMARK --*/
  10710. function setUnvalidatedText($txt='', $alpha=-1) {
  10711. if ($alpha>=0) $this->watermarkTextAlpha = $alpha;
  10712. $this->watermarkText = $txt;
  10713. }
  10714. function SetWatermarkText($txt='', $alpha=-1) {
  10715. if ($alpha>=0) $this->watermarkTextAlpha = $alpha;
  10716. $this->watermarkText = $txt;
  10717. }
  10718. function SetWatermarkImage($src, $alpha=-1, $size='D', $pos='F') {
  10719. if ($alpha>=0) $this->watermarkImageAlpha = $alpha;
  10720. $this->watermarkImage = $src;
  10721. $this->watermark_size = $size;
  10722. $this->watermark_pos = $pos;
  10723. }
  10724. /*-- END WATERMARK --*/
  10725. //Page footer
  10726. function Footer() {
  10727. /*-- CSS-PAGE --*/
  10728. // PAGED MEDIA - CROP / CROSS MARKS from @PAGE
  10729. if ($this->show_marks == 'CROP' || $this->show_marks == 'CROPCROSS') {
  10730. // Show TICK MARKS
  10731. $this->SetLineWidth(0.1); // = 0.1 mm
  10732. $this->SetDColor($this->ConvertColor(0));
  10733. $l = $this->cropMarkLength;
  10734. $m = $this->cropMarkMargin; // Distance of crop mark from margin
  10735. $b = $this->nonPrintMargin; // Non-printable border at edge of paper sheet
  10736. $ax1 = $b;
  10737. $bx = $this->page_box['outer_width_LR'] - $m;
  10738. $ax = max($ax1, $bx-$l);
  10739. $cx1 = $this->w - $b;
  10740. $dx = $this->w - $this->page_box['outer_width_LR'] + $m;
  10741. $cx = min($cx1, $dx+$l);
  10742. $ay1 = $b;
  10743. $by = $this->page_box['outer_width_TB'] - $m;
  10744. $ay = max($ay1, $by-$l);
  10745. $cy1 = $this->h - $b;
  10746. $dy = $this->h - $this->page_box['outer_width_TB'] + $m;
  10747. $cy = min($cy1, $dy+$l);
  10748. $this->Line($ax, $this->page_box['outer_width_TB'], $bx, $this->page_box['outer_width_TB']);
  10749. $this->Line($cx, $this->page_box['outer_width_TB'], $dx, $this->page_box['outer_width_TB']);
  10750. $this->Line($ax, $this->h - $this->page_box['outer_width_TB'], $bx, $this->h - $this->page_box['outer_width_TB']);
  10751. $this->Line($cx, $this->h - $this->page_box['outer_width_TB'], $dx, $this->h - $this->page_box['outer_width_TB']);
  10752. $this->Line($this->page_box['outer_width_LR'], $ay, $this->page_box['outer_width_LR'], $by);
  10753. $this->Line($this->page_box['outer_width_LR'], $cy, $this->page_box['outer_width_LR'], $dy);
  10754. $this->Line($this->w - $this->page_box['outer_width_LR'], $ay, $this->w - $this->page_box['outer_width_LR'], $by);
  10755. $this->Line($this->w - $this->page_box['outer_width_LR'], $cy, $this->w - $this->page_box['outer_width_LR'], $dy);
  10756. if ($this->printers_info) {
  10757. $hd = date('Y-m-d H:i').' Page '.$this->page.' of {nb}';
  10758. $this->SetTColor($this->ConvertColor(0));
  10759. $this->SetFont('arial','',7.5,true,true);
  10760. $this->x = $this->page_box['outer_width_LR'] + 1.5;
  10761. $this->y = 1;
  10762. $this->Cell($headerpgwidth ,$this->FontSize,$hd,0,0,'L',0,'',0,0,0,'M');
  10763. $this->SetFont($this->default_font,'',$this->original_default_font_size);
  10764. }
  10765. }
  10766. if ($this->show_marks == 'CROSS' || $this->show_marks == 'CROPCROSS') {
  10767. $this->SetLineWidth(0.1); // = 0.1 mm
  10768. $this->SetDColor($this->ConvertColor(0));
  10769. $l = 14 /2; // longer length of the cross line (half)
  10770. $w = 6 /2; // shorter width of the cross line (half)
  10771. $r = 1.2; // radius of circle
  10772. $m = $this->crossMarkMargin; // Distance of cross mark from margin
  10773. $x1 = $this->page_box['outer_width_LR'] - $m;
  10774. $x2 = $this->w - $this->page_box['outer_width_LR'] + $m;
  10775. $y1 = $this->page_box['outer_width_TB'] - $m;
  10776. $y2 = $this->h - $this->page_box['outer_width_TB'] + $m;
  10777. // Left
  10778. $this->Circle($x1, $this->h/2, $r, 'S') ;
  10779. $this->Line($x1-$w, $this->h/2, $x1+$w, $this->h/2);
  10780. $this->Line($x1, $this->h/2-$l, $x1, $this->h/2+$l);
  10781. // Right
  10782. $this->Circle($x2, $this->h/2, $r, 'S') ;
  10783. $this->Line($x2-$w, $this->h/2, $x2+$w, $this->h/2);
  10784. $this->Line($x2, $this->h/2-$l, $x2, $this->h/2+$l);
  10785. // Top
  10786. $this->Circle($this->w/2, $y1, $r, 'S') ;
  10787. $this->Line($this->w/2, $y1-$w, $this->w/2, $y1+$w);
  10788. $this->Line($this->w/2-$l, $y1, $this->w/2+$l, $y1);
  10789. // Bottom
  10790. $this->Circle($this->w/2, $y2, $r, 'S') ;
  10791. $this->Line($this->w/2, $y2-$w, $this->w/2, $y2+$w);
  10792. $this->Line($this->w/2-$l, $y2, $this->w/2+$l, $y2);
  10793. }
  10794. // If @page set non-HTML headers/footers named, they were not read until later in the HTML code - so now set them
  10795. if ($this->page==1) {
  10796. if ($this->firstPageBoxHeader) {
  10797. $this->headerDetails['odd'] = $this->pageheaders[$this->firstPageBoxHeader];
  10798. $this->Header();
  10799. }
  10800. if ($this->firstPageBoxFooter) {
  10801. $this->footerDetails['odd'] = $this->pagefooters[$this->firstPageBoxFooter];
  10802. }
  10803. $this->firstPageBoxHeader='';
  10804. $this->firstPageBoxFooter='';
  10805. }
  10806. /*-- END CSS-PAGE --*/
  10807. /*-- HTMLHEADERS-FOOTERS --*/
  10808. if (($this->mirrorMargins && ($this->page%2==0) && $this->HTMLFooterE) || ($this->mirrorMargins && ($this->page%2==1) && $this->HTMLFooter) || (!$this->mirrorMargins && $this->HTMLFooter)) {
  10809. $this->writeHTMLFooters();
  10810. /*-- WATERMARK --*/
  10811. if (($this->watermarkText) && ($this->showWatermarkText)) {
  10812. $this->watermark( $this->watermarkText, 45, 120, $this->watermarkTextAlpha); // Watermark text
  10813. }
  10814. if (($this->watermarkImage) && ($this->showWatermarkImage)) {
  10815. $this->watermarkImg( $this->watermarkImage, $this->watermarkImageAlpha); // Watermark image
  10816. }
  10817. /*-- END WATERMARK --*/
  10818. return;
  10819. }
  10820. /*-- END HTMLHEADERS-FOOTERS --*/
  10821. $this->processingHeader=true;
  10822. $this->ResetMargins(); // necessary after columns
  10823. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  10824. /*-- WATERMARK --*/
  10825. if (($this->watermarkText) && ($this->showWatermarkText)) {
  10826. $this->watermark( $this->watermarkText, 45, 120, $this->watermarkTextAlpha); // Watermark text
  10827. }
  10828. if (($this->watermarkImage) && ($this->showWatermarkImage)) {
  10829. $this->watermarkImg( $this->watermarkImage, $this->watermarkImageAlpha); // Watermark image
  10830. }
  10831. /*-- END WATERMARK --*/
  10832. $h = $this->footerDetails;
  10833. if(count($h)) {
  10834. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  10835. $this->_out(sprintf('q 0 -1 1 0 0 %.3F cm ',($this->h*_MPDFK)));
  10836. $headerpgwidth = $this->h - $this->orig_lMargin - $this->orig_rMargin;
  10837. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  10838. $headerlmargin = $this->orig_rMargin;
  10839. }
  10840. else {
  10841. $headerlmargin = $this->orig_lMargin;
  10842. }
  10843. }
  10844. else {
  10845. $yadj = 0;
  10846. $headerpgwidth = $this->pgwidth;
  10847. $headerlmargin = $this->lMargin;
  10848. }
  10849. $this->SetY(-$this->margin_footer);
  10850. $this->SetTColor($this->ConvertColor(0));
  10851. $this->SUP = false;
  10852. $this->SUB = false;
  10853. $this->bullet = false;
  10854. // only show pagenumber if numbering on
  10855. $pgno = $this->docPageNum($this->page, true);
  10856. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  10857. $side = 'even';
  10858. }
  10859. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS = DEFAULT
  10860. $side = 'odd';
  10861. }
  10862. $maxfontheight = 0;
  10863. foreach(array('L','C','R') AS $pos) {
  10864. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  10865. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  10866. else { $hfsz = $this->default_font_size; }
  10867. $maxfontheight = max($maxfontheight,$hfsz);
  10868. }
  10869. }
  10870. // LEFT-CENTER-RIGHT
  10871. foreach(array('L','C','R') AS $pos) {
  10872. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  10873. $hd = str_replace('{PAGENO}',$pgno,$h[$side][$pos]['content']);
  10874. $hd = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->aliasNbPgGp.$this->nbpgSuffix,$hd);
  10875. $hd = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$hd);
  10876. if (isset($h[$side][$pos]['font-family']) && $h[$side][$pos]['font-family']) { $hff = $h[$side][$pos]['font-family']; }
  10877. else { $hff = $this->original_default_font; }
  10878. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  10879. else { $hfsz = $this->original_default_font_size; }
  10880. $maxfontheight = max($maxfontheight,$hfsz);
  10881. if (isset($h[$side][$pos]['font-style']) && $h[$side][$pos]['font-style']) { $hfst = $h[$side][$pos]['font-style']; }
  10882. else { $hfst = ''; }
  10883. if (isset($h[$side][$pos]['color']) && $h[$side][$pos]['color']) {
  10884. $hfcol = $h[$side][$pos]['color'];
  10885. $cor = $this->ConvertColor($hfcol);
  10886. if ($cor) { $this->SetTColor($cor); }
  10887. }
  10888. else { $hfcol = ''; }
  10889. $this->SetFont($hff,$hfst,$hfsz,true,true);
  10890. $this->x = $headerlmargin ;
  10891. $this->y = $this->h - $this->margin_footer - ($maxfontheight/_MPDFK);
  10892. $hd = $this->purify_utf8_text($hd);
  10893. if ($this->text_input_as_HTML) {
  10894. $hd = $this->all_entities_to_utf8($hd);
  10895. }
  10896. // CONVERT CODEPAGE
  10897. if ($this->usingCoreFont) { $hd = mb_convert_encoding($hd,$this->mb_enc,'UTF-8'); }
  10898. // DIRECTIONALITY RTL
  10899. $this->magic_reverse_dir($hd, true, $this->directionality); // *RTL*
  10900. // Font-specific ligature substitution for Indic fonts
  10901. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($hd); // *INDIC*
  10902. $align = $pos;
  10903. if ($this->directionality == 'rtl') {
  10904. if ($pos == 'L') { $align = 'R'; }
  10905. else if ($pos == 'R') { $align = 'L'; }
  10906. }
  10907. if ($pos!='L' && (strpos($hd,$this->aliasNbPg)!==false || strpos($hd,$this->aliasNbPgGp)!==false)) {
  10908. if (strpos($hd,$this->aliasNbPgGp)!==false) { $type= 'nbpggp'; } else { $type= 'nbpg'; }
  10909. $this->_out('{mpdfheader'.$type.' '.$pos.' ff='.$hff.' fs='.$hfst.' fz='.$hfsz.'}');
  10910. $this->Cell($headerpgwidth ,$maxfontheight/_MPDFK ,$hd,0,0,$align,0,'',0,0,0,'M');
  10911. $this->_out('Q');
  10912. }
  10913. else {
  10914. $this->Cell($headerpgwidth ,$maxfontheight/_MPDFK ,$hd,0,0,$align,0,'',0,0,0,'M');
  10915. }
  10916. if ($hfcol) { $this->SetTColor($this->ConvertColor(0)); }
  10917. }
  10918. }
  10919. // Return Font to normal
  10920. $this->SetFont($this->default_font,'',$this->original_default_font_size);
  10921. // LINE
  10922. if (isset($h[$side]['line']) && $h[$side]['line']) {
  10923. $this->SetLineWidth(0.1);
  10924. $this->SetDColor($this->ConvertColor(0));
  10925. $this->Line($headerlmargin , $this->y-($maxfontheight*($this->footer_line_spacing)/_MPDFK), $headerlmargin +$headerpgwidth, $this->y-($maxfontheight*($this->footer_line_spacing)/_MPDFK));
  10926. }
  10927. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  10928. $this->_out('Q');
  10929. }
  10930. }
  10931. $this->processingHeader=false;
  10932. }
  10933. /*-- HYPHENATION --*/
  10934. ///////////////////
  10935. ///////////////////
  10936. // HYPHENATION
  10937. ///////////////////
  10938. // Soft hyphs
  10939. function softHyphenate($word, $maxWidth) {
  10940. // Don't hyphenate web addresses
  10941. if (preg_match('/^(http:|www\.)/',$word)) { return array(false,'','',''); }
  10942. // Get dictionary
  10943. $poss = array();
  10944. $softhyphens = array();
  10945. $offset = 0;
  10946. $p = true;
  10947. if ($this->usingCoreFont) {
  10948. $wl = strlen($word);
  10949. }
  10950. else {
  10951. $wl = mb_strlen($word,'UTF-8');
  10952. }
  10953. while($offset < $wl) {
  10954. // Soft Hyphens chr(173)
  10955. if (!$this->usingCoreFont) {
  10956. $p = mb_strpos($word, "\xc2\xad", $offset, 'UTF-8');
  10957. }
  10958. else if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  10959. $p = strpos($word, chr(173), $offset);
  10960. }
  10961. if ($p !== false) { $poss[] = $p - count($poss); }
  10962. else { break; }
  10963. $offset = $p+1;
  10964. }
  10965. $success = false;
  10966. foreach($poss AS $i) {
  10967. if ($this->usingCoreFont) {
  10968. $a = substr($word,0,$i);
  10969. if ($this->GetStringWidth($a.'-') > $maxWidth) { break ; }
  10970. $pre = $a;
  10971. $post = substr($word,$i,strlen($word));
  10972. $prelength = strlen($pre);
  10973. }
  10974. else {
  10975. $a = mb_substr($word,0,$i,'UTF-8');
  10976. if ($this->GetStringWidth($a.'-') > $maxWidth) { break ; }
  10977. $pre = $a;
  10978. $post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8');
  10979. $prelength = mb_strlen($pre, 'UTF-8');
  10980. }
  10981. $success = true;
  10982. }
  10983. return array($success,$pre,$post,$prelength);
  10984. }
  10985. ///////////////////
  10986. // Word hyphenation
  10987. function hyphenateWord($word, $maxWidth) {
  10988. // Do everything inside this function in utf-8
  10989. // Don't hyphenate web addresses
  10990. if (preg_match('/^(http:|www\.)/',$word)) { return array(false,'','',''); }
  10991. // Get dictionary
  10992. if (!$this->loadedSHYdictionary) {
  10993. if (file_exists(_MPDF_PATH.'patterns/dictionary.txt')) {
  10994. $this->SHYdictionary = file(_MPDF_PATH.'patterns/dictionary.txt',FILE_SKIP_EMPTY_LINES);
  10995. foreach($this->SHYdictionary as $entry) {
  10996. $entry = trim($entry);
  10997. $poss = array();
  10998. $offset = 0;
  10999. $p = true;
  11000. $wl = mb_strlen($entry ,'UTF-8');
  11001. while($offset < $wl) {
  11002. $p = mb_strpos($entry, '/', $offset, 'UTF-8');
  11003. if ($p !== false) { $poss[] = $p - count($poss); }
  11004. else { break; }
  11005. $offset = $p+1;
  11006. }
  11007. if (count($poss)) { $this->SHYdictionaryWords[str_replace('/', '', mb_strtolower($entry))] = $poss; }
  11008. }
  11009. }
  11010. $this->loadedSHYdictionary = true;
  11011. }
  11012. if (!in_array($this->SHYlang,$this->SHYlanguages)) { return array(false,'','',''); }
  11013. // If no pattern loaded or not the best one
  11014. if (count($this->SHYpatterns) < 1 || ($this->loadedSHYpatterns && $this->loadedSHYpatterns != $this->SHYlang)) {
  11015. include(_MPDF_PATH."patterns/" . $this->SHYlang . ".php");
  11016. $patterns = explode(' ', $patterns);
  11017. $new_patterns = array();
  11018. for($i = 0; $i < count($patterns); $i++) {
  11019. $value = $patterns[$i];
  11020. $new_patterns[preg_replace('/[0-9]/', '', $value)] = $value;
  11021. }
  11022. $this->SHYpatterns = $new_patterns;
  11023. $this->loadedSHYpatterns = $this->SHYlang;
  11024. }
  11025. if ($this->usingCoreFont) { $word = mb_convert_encoding($word,'UTF-8',$this->mb_enc); }
  11026. $prepre = '';
  11027. $postpost = '';
  11028. $startpunctuation = "\xc2\xab\xc2\xbf\xe2\x80\x98\xe2\x80\x9b\xe2\x80\x9c\xe2\x80\x9f";
  11029. $endpunctuation = "\xe2\x80\x9e\xe2\x80\x9d\xe2\x80\x9a\xe2\x80\x99\xc2\xbb";
  11030. $pre = '';
  11031. $post = '';
  11032. if (preg_match('/^(["\''.$startpunctuation .'])+(.{'.$this->SHYcharmin.',})$/u',$word,$m)) {
  11033. $prepre = $m[1];
  11034. $word = $m[2];
  11035. }
  11036. if (preg_match('/^(.{'.$this->SHYcharmin.',})([\'\.,;:!?"'.$endpunctuation .']+)$/u',$word,$m)) {
  11037. $word = $m[1];
  11038. $postpost = $m[2];
  11039. }
  11040. if(mb_strlen($word,'UTF-8') < $this->SHYcharmin) {
  11041. return array(false,'','','');
  11042. }
  11043. $success = false;
  11044. if(isset($this->SHYdictionaryWords[mb_strtolower($word)])) {
  11045. foreach($this->SHYdictionaryWords[mb_strtolower($word)] AS $i) {
  11046. $a = $prepre . mb_substr($word,0,$i,'UTF-8');
  11047. if ($this->usingCoreFont) { $testa = mb_convert_encoding($a,$this->mb_enc,'UTF-8'); }
  11048. else { $testa = $a; }
  11049. if ($this->GetStringWidth($testa.'-') > $maxWidth) { break ; }
  11050. $pre = $a;
  11051. $post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8') . $postpost;
  11052. $success = true;
  11053. }
  11054. }
  11055. if (!$success) {
  11056. $text_word = '_' . $word . '_';
  11057. $word_length = mb_strlen($text_word,'UTF-8');
  11058. $single_character = preg_split('//u', $text_word);
  11059. $text_word = mb_strtolower($text_word,'UTF-8');
  11060. $hyphenated_word = array();
  11061. $numb3rs = array('0' => true, '1' => true, '2' => true, '3' => true, '4' => true, '5' => true, '6' => true, '7' => true, '8' => true, '9' => true);
  11062. for($position = 0; $position <= ($word_length - $this->SHYcharmin); $position++) {
  11063. $maxwins = min(($word_length - $position), $this->SHYcharmax);
  11064. for($win = $this->SHYcharmin; $win <= $maxwins; $win++) {
  11065. if(isset($this->SHYpatterns[mb_substr($text_word, $position, $win,'UTF-8')])) {
  11066. $pattern = $this->SHYpatterns[mb_substr($text_word, $position, $win,'UTF-8')];
  11067. $digits = 1;
  11068. $pattern_length = mb_strlen($pattern,'UTF-8');
  11069. for($i = 0; $i < $pattern_length; $i++) {
  11070. $char = $pattern[$i];
  11071. if(isset($numb3rs[$char])) {
  11072. $zero = ($i == 0) ? $position - 1 : $position + $i - $digits;
  11073. if(!isset($hyphenated_word[$zero]) || $hyphenated_word[$zero] != $char) $hyphenated_word[$zero] = $char;
  11074. $digits++;
  11075. }
  11076. }
  11077. }
  11078. }
  11079. }
  11080. for($i = $this->SHYleftmin; $i <= (mb_strlen($word,'UTF-8') - $this->SHYrightmin); $i++) {
  11081. if(isset($hyphenated_word[$i]) && $hyphenated_word[$i] % 2 != 0) {
  11082. $a = $prepre . mb_substr($word,0,$i,'UTF-8');
  11083. if ($this->usingCoreFont) { $testa = mb_convert_encoding($a,$this->mb_enc,'UTF-8'); }
  11084. else { $testa = $a; }
  11085. if ($this->GetStringWidth($testa.'-') > $maxWidth + 0.0001) { break ; }
  11086. $pre = $a;
  11087. $post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8') . $postpost;
  11088. $success = true;
  11089. }
  11090. }
  11091. }
  11092. if ($this->usingCoreFont) {
  11093. $pre = mb_convert_encoding($pre,$this->mb_enc,'UTF-8');
  11094. $post = mb_convert_encoding($post,$this->mb_enc,'UTF-8');
  11095. $prelength = strlen($pre);
  11096. }
  11097. else {
  11098. $prelength = mb_strlen($pre);
  11099. }
  11100. return array($success,$pre,$post,$prelength);
  11101. }
  11102. /*-- END HYPHENATION --*/
  11103. /*-- HTML-CSS --*/
  11104. ///////////////////
  11105. /// HTML parser ///
  11106. ///////////////////
  11107. function WriteHTML($html,$sub=0,$init=true,$close=true) {
  11108. // $sub ADDED - 0 = default; 1=headerCSS only; 2=HTML body (parts) only; 3 - HTML parses only
  11109. // 4 - writes HTML headers
  11110. // $close Leaves buffers etc. in current state, so that it can continue a block etc.
  11111. // $init - Clears and sets buffers to Top level block etc.
  11112. if (empty($html)) { $html = ''; }
  11113. if ($this->progressBar) { $this->UpdateProgressBar(1,0,'Parsing CSS & Headers'); } // *PROGRESS-BAR*
  11114. if ($init) {
  11115. $this->headerbuffer='';
  11116. $this->textbuffer = array();
  11117. $this->fixedPosBlockSave = array();
  11118. }
  11119. if ($sub == 1) { $html = '<style> '.$html.' </style>'; } // stylesheet only
  11120. if ($this->allow_charset_conversion) {
  11121. if ($sub < 1) {
  11122. $this->ReadCharset($html);
  11123. }
  11124. if ($this->charset_in) {
  11125. $success = iconv($this->charset_in,'UTF-8//TRANSLIT',$html);
  11126. if ($success) { $html = $success; }
  11127. }
  11128. }
  11129. $html = $this->purify_utf8($html,false);
  11130. if ($init) {
  11131. $this->blklvl = 0;
  11132. $this->lastblocklevelchange = 0;
  11133. $this->blk = array();
  11134. $this->initialiseBlock($this->blk[0]);
  11135. $this->blk[0]['width'] =& $this->pgwidth;
  11136. $this->blk[0]['inner_width'] =& $this->pgwidth;
  11137. $this->blk[0]['blockContext'] = $this->blockContext;
  11138. }
  11139. $zproperties = array();
  11140. if ($sub < 2) {
  11141. $this->ReadMetaTags($html);
  11142. // NB default stylesheet now in mPDF.css - read on initialising class
  11143. $html = $this->ReadCSS($html);
  11144. if ($this->useLang && !$this->usingCoreFont && preg_match('/<html [^>]*lang=[\'\"](.*?)[\'\"]/ism',$html,$m)) {
  11145. $html_lang = $m[1];
  11146. }
  11147. if (preg_match('/<html [^>]*dir=[\'\"]\s*rtl\s*[\'\"]/ism',$html)) {
  11148. $zproperties['DIRECTION'] = 'rtl';
  11149. }
  11150. // allow in-line CSS for body tag to be parsed // Get <body> tag inline CSS
  11151. if (preg_match('/<body([^>]*)>(.*?)<\/body>/ism',$html,$m) || preg_match('/<body([^>]*)>(.*)$/ism',$html,$m)) {
  11152. $html = $m[2];
  11153. // Changed to allow style="background: url('bg.jpg')"
  11154. if (preg_match('/style=[\"](.*?)[\"]/ism',$m[1],$mm) || preg_match('/style=[\'](.*?)[\']/ism',$m[1],$mm)) {
  11155. $zproperties = $this->readInlineCSS($mm[1]);
  11156. }
  11157. if (preg_match('/dir=[\'\"]\s*rtl\s*[\'\"]/ism',$m[1])) {
  11158. $zproperties['DIRECTION'] = 'rtl';
  11159. }
  11160. if (isset($html_lang) && $html_lang) { $zproperties['LANG'] = $html_lang; } // mPDF 5.3.99
  11161. if ($this->useLang && !$this->onlyCoreFonts && preg_match('/lang=[\'\"](.*?)[\'\"]/ism',$m[1],$mm)) { // mPDF 5.3.22
  11162. $zproperties['LANG'] = $mm[1];
  11163. }
  11164. }
  11165. }
  11166. $properties = $this->MergeCSS('BLOCK','BODY','');
  11167. if ($zproperties) { $properties = $this->array_merge_recursive_unique($properties,$zproperties); }
  11168. if (isset($properties['DIRECTION']) && $properties['DIRECTION']) {
  11169. $this->CSS['BODY']['DIRECTION'] = $properties['DIRECTION'];
  11170. }
  11171. if (!isset($this->CSS['BODY']['DIRECTION'])) {
  11172. $this->CSS['BODY']['DIRECTION'] = $this->directionality;
  11173. }
  11174. else { $this->SetDirectionality($this->CSS['BODY']['DIRECTION']); }
  11175. $this->setCSS($properties,'','BODY');
  11176. $this->blk[0]['InlineProperties'] = $this->saveInlineProperties();
  11177. if ($sub == 1) { return ''; }
  11178. if (!isset($this->CSS['BODY'])) { $this->CSS['BODY'] = array(); }
  11179. /*-- BACKGROUNDS --*/
  11180. if (isset($properties['BACKGROUND-GRADIENT'])) {
  11181. $this->bodyBackgroundGradient = $properties['BACKGROUND-GRADIENT'];
  11182. }
  11183. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE']) {
  11184. $ret = $this->SetBackground($properties, $this->pgwidth);
  11185. if ($ret) { $this->bodyBackgroundImage = $ret; }
  11186. }
  11187. /*-- END BACKGROUNDS --*/
  11188. /*-- CSS-PAGE --*/
  11189. // If page-box is set
  11190. if ($this->state==0 && isset($this->CSS['@PAGE']) && $this->CSS['@PAGE'] ) {
  11191. $this->page_box['current'] = '';
  11192. $this->page_box['using'] = true;
  11193. list($pborientation,$pbmgl,$pbmgr,$pbmgt,$pbmgb,$pbmgh,$pbmgf,$hname,$fname,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat) = $this->SetPagedMediaCSS('', false, 'O');
  11194. $this->DefOrientation = $this->CurOrientation = $pborientation;
  11195. $this->orig_lMargin = $this->DeflMargin = $pbmgl;
  11196. $this->orig_rMargin = $this->DefrMargin = $pbmgr;
  11197. $this->orig_tMargin = $this->tMargin = $pbmgt;
  11198. $this->orig_bMargin = $this->bMargin = $pbmgb;
  11199. $this->orig_hMargin = $this->margin_header = $pbmgh;
  11200. $this->orig_fMargin = $this->margin_footer = $pbmgf;
  11201. list($pborientation,$pbmgl,$pbmgr,$pbmgt,$pbmgb,$pbmgh,$pbmgf,$hname,$fname,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat) = $this->SetPagedMediaCSS('', true, 'O'); // first page
  11202. $this->show_marks = $marks;
  11203. if ($hname && !preg_match('/^html_(.*)$/i',$hname)) $this->firstPageBoxHeader = $hname;
  11204. if ($fname && !preg_match('/^html_(.*)$/i',$fname)) $this->firstPageBoxFooter = $fname;
  11205. }
  11206. /*-- END CSS-PAGE --*/
  11207. $parseonly = false;
  11208. $this->bufferoutput = false;
  11209. if ($sub == 3) {
  11210. $parseonly = true;
  11211. // Close any open block tags
  11212. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  11213. // Output any text left in buffer
  11214. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); }
  11215. $this->textbuffer=array();
  11216. }
  11217. else if ($sub == 4) {
  11218. // Close any open block tags
  11219. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  11220. // Output any text left in buffer
  11221. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); }
  11222. $this->bufferoutput = true;
  11223. $this->textbuffer=array();
  11224. $this->headerbuffer='';
  11225. $properties = $this->MergeCSS('BLOCK','BODY','');
  11226. $this->setCSS($properties,'','BODY');
  11227. }
  11228. mb_internal_encoding('UTF-8');
  11229. $html = $this->AdjustHTML($html, $this->tabSpaces); //Try to make HTML look more like XHTML // mPDF 5.3.60 / 99
  11230. if ($this->autoFontGroups) { $html = $this->AutoFont($html); }
  11231. /*-- HTMLHEADERS-FOOTERS --*/
  11232. preg_match_all('/<htmlpageheader([^>]*)>(.*?)<\/htmlpageheader>/si',$html,$h);
  11233. for($i=0;$i<count($h[1]);$i++) {
  11234. if (preg_match('/name=[\'|\"](.*?)[\'|\"]/',$h[1][$i],$n)) {
  11235. $this->pageHTMLheaders[$n[1]]['html'] = $h[2][$i];
  11236. $this->pageHTMLheaders[$n[1]]['h'] = $this->_gethtmlheight($h[2][$i]);
  11237. }
  11238. }
  11239. preg_match_all('/<htmlpagefooter([^>]*)>(.*?)<\/htmlpagefooter>/si',$html,$f);
  11240. for($i=0;$i<count($f[1]);$i++) {
  11241. if (preg_match('/name=[\'|\"](.*?)[\'|\"]/',$f[1][$i],$n)) {
  11242. $this->pageHTMLfooters[$n[1]]['html'] = $f[2][$i];
  11243. $this->pageHTMLfooters[$n[1]]['h'] = $this->_gethtmlheight($f[2][$i]);
  11244. }
  11245. }
  11246. /*-- END HTMLHEADERS-FOOTERS --*/
  11247. $html = preg_replace('/<htmlpageheader.*?<\/htmlpageheader>/si','',$html);
  11248. $html = preg_replace('/<htmlpagefooter.*?<\/htmlpagefooter>/si','',$html);
  11249. if($this->state==0 && $sub!=1 && $sub!=3 && $sub!=4) {
  11250. $this->AddPage($this->CurOrientation);
  11251. }
  11252. /*-- HTMLHEADERS-FOOTERS --*/
  11253. if (isset($hname) && preg_match('/^html_(.*)$/i',$hname,$n)) $this->SetHTMLHeader($this->pageHTMLheaders[$n[1]],'O',true);
  11254. if (isset($fname) && preg_match('/^html_(.*)$/i',$fname,$n)) $this->SetHTMLFooter($this->pageHTMLfooters[$n[1]],'O');
  11255. /*-- END HTMLHEADERS-FOOTERS --*/
  11256. $html=str_replace('<?','< ',$html); //Fix '<?XML' bug from HTML code generated by MS Word
  11257. // mPDF 5.3.18
  11258. $this->checkSIP = false;
  11259. $this->checkSMP = false;
  11260. $this->checkCJK = false;
  11261. if ($this->onlyCoreFonts) { $html = $this->SubstituteChars($html); }
  11262. else { // mPDF 5.3.18
  11263. if (preg_match("/([".$this->pregRTLchars."])/u", $html)) { $this->biDirectional = true; } // *RTL*
  11264. if (preg_match("/([\x{20000}-\x{2FFFF}])/u", $html)) { $this->checkSIP = true; }
  11265. if (preg_match("/([\x{10000}-\x{1FFFF}])/u", $html)) { $this->checkSMP = true; }
  11266. /*-- CJK-FONTS --*/
  11267. if (preg_match("/([".$this->pregCJKchars."])/u", $html)) { $this->checkCJK = true; }
  11268. /*-- END CJK-FONTS --*/
  11269. }
  11270. // Don't allow non-breaking spaces that are converted to substituted chars or will break anyway and mess up table width calc.
  11271. $html = str_replace('<tta>160</tta>',chr(32),$html);
  11272. $html = str_replace('</tta><tta>','|',$html);
  11273. $html = str_replace('</tts><tts>','|',$html);
  11274. $html = str_replace('</ttz><ttz>','|',$html);
  11275. //Add new supported tags in the DisableTags function
  11276. $html=strip_tags($html,$this->enabledtags); //remove all unsupported tags, but the ones inside the 'enabledtags' string
  11277. //Explode the string in order to parse the HTML code
  11278. $a=preg_split('/<(.*?)>/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
  11279. // ? more accurate regexp that allows e.g. <a name="Silly <name>">
  11280. // if changing - also change in fn.SubstituteChars()
  11281. // $a = preg_split ('/<((?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+)>/ms', $html, -1, PREG_SPLIT_DELIM_CAPTURE);
  11282. if ($this->mb_enc) {
  11283. mb_internal_encoding($this->mb_enc);
  11284. }
  11285. $pbc = 0;
  11286. if ($this->progressBar) { $this->UpdateProgressBar(1,0); } // *PROGRESS-BAR*
  11287. $this->subPos = -1;
  11288. $cnt = count($a);
  11289. for($i=0;$i<$cnt; $i++) {
  11290. $e = $a[$i];
  11291. if($i%2==0) {
  11292. //TEXT
  11293. if ($this->blk[$this->blklvl]['hide']) { continue; }
  11294. if ($this->inlineDisplayOff) { continue; }
  11295. if ($this->inFixedPosBlock) { $this->fixedPosBlock .= $e; continue; } // *CSS-POSITION*
  11296. if (strlen($e) == 0) { continue; }
  11297. $e = strcode2utf($e);
  11298. $e = $this->lesser_entity_decode($e);
  11299. if ($this->usingCoreFont) {
  11300. // mPDF 5.3.22
  11301. // If core font is selected in document which is not onlyCoreFonts - substitute with non-core font
  11302. if ($this->useSubstitutions && !$this->onlyCoreFonts && $this->subPos<$i && !$this->specialcontent) {
  11303. $cnt += $this->SubstituteCharsNonCore($a, $i, $e);
  11304. }
  11305. // CONVERT ENCODING
  11306. $e = mb_convert_encoding($e,$this->mb_enc,'UTF-8');
  11307. if ($this->toupper) { $e = strtoupper($e); }
  11308. if ($this->tolower) { $e = strtolower($e); }
  11309. if ($this->capitalize) { $e = ucwords($e); }
  11310. }
  11311. // mPDF 5.3.21
  11312. else {
  11313. if ($this->checkSIP && $this->CurrentFont['sipext'] && $this->subPos<$i && !$this->specialcontent) {
  11314. $cnt += $this->SubstituteCharsSIP($a, $i, $e);
  11315. }
  11316. if ($this->useSubstitutions && !$this->onlyCoreFonts && $this->CurrentFont['type']!='Type0' && $this->subPos<$i && !$this->specialcontent) {
  11317. $cnt += $this->SubstituteCharsMB($a, $i, $e);
  11318. }
  11319. if ($this->biDirectional) { // *RTL*
  11320. $e = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $e); // *RTL*
  11321. } // *RTL*
  11322. // Font-specific ligature substitution for Indic fonts
  11323. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($e); // *INDIC*
  11324. if ($this->toupper) { $e = mb_strtoupper($e,$this->mb_enc); }
  11325. if ($this->tolower) { $e = mb_strtolower($e,$this->mb_enc); }
  11326. if ($this->capitalize) { $e = mb_convert_case($e, MB_CASE_TITLE, "UTF-8"); }
  11327. }
  11328. if (($this->tts) || ($this->ttz) || ($this->tta)) {
  11329. $es = explode('|',$e);
  11330. $e = '';
  11331. foreach($es AS $val) {
  11332. $e .= chr($val);
  11333. }
  11334. }
  11335. //Adjust lineheight
  11336. // FORM ELEMENTS
  11337. if ($this->specialcontent) {
  11338. /*-- FORMS --*/
  11339. //SELECT tag (form element)
  11340. if ($this->specialcontent == "type=select") {
  11341. $e = ltrim($e);
  11342. $stringwidth = $this->GetStringWidth($e);
  11343. if (!isset($this->selectoption['MAXWIDTH']) || $stringwidth > $this->selectoption['MAXWIDTH']) { $this->selectoption['MAXWIDTH'] = $stringwidth; }
  11344. if (!isset($this->selectoption['SELECTED']) || $this->selectoption['SELECTED'] == '') { $this->selectoption['SELECTED'] = $e; }
  11345. // mPDD 1.4 Active Forms
  11346. if (isset($this->selectoption['ACTIVE']) && $this->selectoption['ACTIVE']) {
  11347. $this->selectoption['ITEMS'][]=array('exportValue'=>$this->selectoption['currentVAL'], 'content'=>$e, 'selected'=>$this->selectoption['currentSEL']);
  11348. }
  11349. }
  11350. // TEXTAREA
  11351. else {
  11352. $objattr = unserialize($this->specialcontent);
  11353. $objattr['text'] = $e;
  11354. $te = "\xbb\xa4\xactype=textarea,objattr=".serialize($objattr)."\xbb\xa4\xac";
  11355. if ($this->tdbegin) {
  11356. $this->_saveCellTextBuffer($te, $this->HREF); // mPDF 5.3.99
  11357. }
  11358. else {
  11359. $this->_saveTextBuffer($te, $this->HREF); // mPDF 5.3.99
  11360. }
  11361. }
  11362. /*-- END FORMS --*/
  11363. }
  11364. // TABLE
  11365. else if ($this->tableLevel) {
  11366. /*-- TABLES --*/
  11367. if ($this->tdbegin) {
  11368. if (($this->ignorefollowingspaces) && !$this->ispre) { $e = ltrim($e); }
  11369. if ($e || $e==='0') {
  11370. if (($this->blockjustfinished || $this->listjustfinished) && $this->cell[$this->row][$this->col]['s']>0) {
  11371. $this->_saveCellTextBuffer("\n"); // mPDF 5.3.99
  11372. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  11373. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  11374. }
  11375. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  11376. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  11377. }
  11378. $this->cell[$this->row][$this->col]['s'] = 0;// reset
  11379. }
  11380. $this->blockjustfinished=false;
  11381. $this->listjustfinished=false;
  11382. // mPDF 5.3.76
  11383. $this->_saveCellTextBuffer($e, $this->HREF); // mPDF 5.3.99
  11384. if (!isset($this->cell[$this->row][$this->col]['R']) || !$this->cell[$this->row][$this->col]['R']) {
  11385. if (isset($this->cell[$this->row][$this->col]['s'])) {
  11386. $this->cell[$this->row][$this->col]['s'] += $this->GetStringWidth($e, false);
  11387. }
  11388. else { $this->cell[$this->row][$this->col]['s'] = $this->GetStringWidth($e, false); }
  11389. // mPDF 5.3.61
  11390. if (!empty($this->spanborddet)) {
  11391. $this->cell[$this->row][$this->col]['s'] += $this->spanborddet['L']['w'] + $this->spanborddet['R']['w'];
  11392. }
  11393. }
  11394. if ($this->checkCJK && preg_match("/([".$this->pregCJKchars."])/u", $e)) { $this->tableCJK = true; } // *CJK-FONTS*
  11395. if ($this->tableLevel==1 && $this->useGraphs) {
  11396. $this->graphs[$this->currentGraphId]['data'][$this->row][$this->col] = $e;
  11397. }
  11398. $this->nestedtablejustfinished = false;
  11399. $this->linebreakjustfinished=false;
  11400. }
  11401. }
  11402. /*-- END TABLES --*/
  11403. }
  11404. // ALL ELSE
  11405. else {
  11406. if ($this->ignorefollowingspaces and !$this->ispre) { $e = ltrim($e); }
  11407. if ($e || $e==='0') $this->_saveTextBuffer($e, $this->HREF); // mPDF 5.3.99
  11408. }
  11409. }
  11410. else { // TAG **
  11411. if($e[0]=='/') {
  11412. /*-- PROGRESS-BAR --*/
  11413. if ($this->progressBar) { // 10% increments
  11414. if (intval($i*10/$cnt) != $pbc) { $pbc = intval($i*10/$cnt); $this->UpdateProgressBar(1,$pbc*10,$tag); }
  11415. }
  11416. /*-- END PROGRESS-BAR --*/
  11417. // Check for tags where HTML specifies optional end tags,
  11418. // and/or does not allow nesting e.g. P inside P, or
  11419. $endtag = strtoupper(substr($e,1));
  11420. if($this->blk[$this->blklvl]['hide']) {
  11421. if (in_array($endtag, $this->outerblocktags) || in_array($endtag, $this->innerblocktags)) {
  11422. unset($this->blk[$this->blklvl]);
  11423. $this->blklvl--;
  11424. }
  11425. continue;
  11426. }
  11427. /*-- CSS-POSITION --*/
  11428. if ($this->inFixedPosBlock) {
  11429. if (in_array($endtag, $this->outerblocktags) || in_array($endtag, $this->innerblocktags)) { $this->fixedPosBlockDepth--; }
  11430. if ($this->fixedPosBlockDepth == 0) {
  11431. $this->fixedPosBlockSave[] = array($this->fixedPosBlock, $this->fixedPosBlockBBox, $this->page);
  11432. $this->fixedPosBlock = '';
  11433. $this->inFixedPosBlock = false;
  11434. continue;
  11435. }
  11436. $this->fixedPosBlock .= '<'.$e.'>';
  11437. continue;
  11438. }
  11439. /*-- END CSS-POSITION --*/
  11440. if ($this->allow_html_optional_endtags && !$parseonly) {
  11441. if (($endtag == 'DIV' || $endtag =='FORM' || $endtag =='CENTER') && $this->lastoptionaltag == 'P') { $this->CloseTag($this->lastoptionaltag ); }
  11442. if ($this->lastoptionaltag == 'LI' && $endtag == 'OL') { $this->CloseTag($this->lastoptionaltag ); }
  11443. if ($this->lastoptionaltag == 'LI' && $endtag == 'UL') { $this->CloseTag($this->lastoptionaltag ); }
  11444. if ($this->lastoptionaltag == 'DD' && $endtag == 'DL') { $this->CloseTag($this->lastoptionaltag ); }
  11445. if ($this->lastoptionaltag == 'DT' && $endtag == 'DL') { $this->CloseTag($this->lastoptionaltag ); }
  11446. if ($this->lastoptionaltag == 'OPTION' && $endtag == 'SELECT') { $this->CloseTag($this->lastoptionaltag ); }
  11447. /*-- TABLES --*/
  11448. if ($endtag == 'TABLE') {
  11449. if ($this->lastoptionaltag == 'THEAD' || $this->lastoptionaltag == 'TBODY' || $this->lastoptionaltag == 'TFOOT') {
  11450. $this->CloseTag($this->lastoptionaltag);
  11451. }
  11452. if ($this->lastoptionaltag == 'TR') { $this->CloseTag('TR'); }
  11453. if ($this->lastoptionaltag == 'TD' || $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); }
  11454. }
  11455. if ($endtag == 'THEAD' || $endtag == 'TBODY' || $endtag == 'TFOOT') {
  11456. if ($this->lastoptionaltag == 'TR') { $this->CloseTag('TR'); }
  11457. if ($this->lastoptionaltag == 'TD' || $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); }
  11458. }
  11459. if ($endtag == 'TR') {
  11460. if ($this->lastoptionaltag == 'TD' || $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); }
  11461. }
  11462. /*-- END TABLES --*/
  11463. }
  11464. $this->CloseTag($endtag);
  11465. }
  11466. else { // OPENING TAG
  11467. if($this->blk[$this->blklvl]['hide']) {
  11468. if (strpos($e,' ')) { $te = strtoupper(substr($e,0,strpos($e,' '))); }
  11469. else { $te = strtoupper($e); }
  11470. if (in_array($te, $this->outerblocktags) || in_array($te, $this->innerblocktags)) {
  11471. $this->blklvl++;
  11472. $this->blk[$this->blklvl]['hide']=true;
  11473. }
  11474. continue;
  11475. }
  11476. /*-- CSS-POSITION --*/
  11477. if ($this->inFixedPosBlock) {
  11478. if (strpos($e,' ')) { $te = strtoupper(substr($e,0,strpos($e,' '))); }
  11479. else { $te = strtoupper($e); }
  11480. $this->fixedPosBlock .= '<'.$e.'>';
  11481. if (in_array($te, $this->outerblocktags) || in_array($te, $this->innerblocktags)) { $this->fixedPosBlockDepth++; }
  11482. continue;
  11483. }
  11484. /*-- END CSS-POSITION --*/
  11485. $regexp = '|=\'(.*?)\'|s'; // eliminate single quotes, if any
  11486. $e = preg_replace($regexp,"=\"\$1\"",$e);
  11487. // changes anykey=anyvalue to anykey="anyvalue" (only do this inside tags)
  11488. if (substr($e,0,10)!='pageheader' && substr($e,0,10)!='pagefooter') {
  11489. $regexp = '| (\\w+?)=([^\\s>"]+)|si';
  11490. $e = preg_replace($regexp," \$1=\"\$2\"",$e);
  11491. }
  11492. $e = preg_replace('/ (\\S+?)\s*=\s*"/i', " \\1=\"", $e);
  11493. //Fix path values, if needed
  11494. $orig_srcpath = '';
  11495. if ((stristr($e,"href=") !== false) or (stristr($e,"src=") !== false) ) {
  11496. $regexp = '/ (href|src)\s*=\s*"(.*?)"/i';
  11497. preg_match($regexp,$e,$auxiliararray);
  11498. if (isset($auxiliararray[2])) { $path = $auxiliararray[2]; }
  11499. else { $path = ''; }
  11500. if (trim($path) != '' && !(stristr($e,"src=") !== false && substr($path,0,4)=='var:')) {
  11501. $orig_srcpath = $path;
  11502. $this->GetFullPath($path);
  11503. $regexp = '/ (href|src)="(.*?)"/i';
  11504. $e = preg_replace($regexp,' \\1="'.$path.'"',$e);
  11505. }
  11506. }//END of Fix path values
  11507. //Extract attributes
  11508. $contents=array();
  11509. // Changed to allow style="background: url('bg.jpg')"
  11510. preg_match_all('/\\S*=["][^"]*["]/',$e,$contents1);
  11511. preg_match_all('/\\S*=[\'][^\']*[\']/',$e,$contents2);
  11512. $contents = array_merge($contents1, $contents2);
  11513. preg_match('/\\S+/',$e,$a2);
  11514. $tag=strtoupper($a2[0]);
  11515. $attr=array();
  11516. if ($orig_srcpath) { $attr['ORIG_SRC'] = $orig_srcpath; }
  11517. if (!empty($contents)) {
  11518. foreach($contents[0] as $v) {
  11519. // Changed to allow style="background: url('bg.jpg')"
  11520. if(preg_match('/^([^=]*)=["]?([^"]*)["]?$/',$v,$a3) || preg_match('/^([^=]*)=[\']?([^\']*)[\']?$/',$v,$a3)) {
  11521. if (strtoupper($a3[1])=='ID' || strtoupper($a3[1])=='CLASS') { // 4.2.013 Omits STYLE
  11522. $attr[strtoupper($a3[1])]=trim(strtoupper($a3[2]));
  11523. }
  11524. // includes header-style-right etc. used for <pageheader>
  11525. else if (preg_match('/^(HEADER|FOOTER)-STYLE/i',$a3[1])) {
  11526. $attr[strtoupper($a3[1])]=trim(strtoupper($a3[2]));
  11527. }
  11528. else {
  11529. $attr[strtoupper($a3[1])]=trim($a3[2]);
  11530. }
  11531. }
  11532. }
  11533. }
  11534. $this->OpenTag($tag,$attr);
  11535. /*-- CSS-POSITION --*/
  11536. if ($this->inFixedPosBlock) {
  11537. $this->fixedPosBlockBBox = array($tag,$attr, $this->x, $this->y);
  11538. $this->fixedPosBlock = '';
  11539. $this->fixedPosBlockDepth = 1;
  11540. }
  11541. /*-- END CSS-POSITION --*/
  11542. }
  11543. } // end TAG
  11544. } //end of foreach($a as $i=>$e)
  11545. if ($close) {
  11546. // Close any open block tags
  11547. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  11548. // Output any text left in buffer
  11549. if (count($this->textbuffer) && !$parseonly) { $this->printbuffer($this->textbuffer); }
  11550. if (!$parseonly) $this->textbuffer=array();
  11551. /*-- CSS-FLOAT --*/
  11552. // If ended with a float, need to move to end page
  11553. $currpos = $this->page*1000 + $this->y;
  11554. if (isset($this->blk[$this->blklvl]['float_endpos']) && $this->blk[$this->blklvl]['float_endpos'] > $currpos) {
  11555. $old_page = $this->page;
  11556. $new_page = intval($this->blk[$this->blklvl]['float_endpos'] /1000);
  11557. if ($old_page != $new_page) {
  11558. $s = $this->PrintPageBackgrounds();
  11559. // Writes after the marker so not overwritten later by page background etc.
  11560. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  11561. $this->pageBackgrounds = array();
  11562. $this->page = $new_page;
  11563. $this->ResetMargins();
  11564. $this->Reset();
  11565. $this->pageoutput[$this->page] = array();
  11566. }
  11567. $this->y = (($this->blk[$this->blklvl]['float_endpos'] *1000) % 1000000)/1000; // mod changes operands to integers before processing
  11568. }
  11569. /*-- END CSS-FLOAT --*/
  11570. /*-- CSS-IMAGE-FLOAT --*/
  11571. $this->printfloatbuffer();
  11572. /*-- END CSS-IMAGE-FLOAT --*/
  11573. //Create Internal Links, if needed
  11574. if (!empty($this->internallink) ) {
  11575. foreach($this->internallink as $k=>$v) {
  11576. if (strpos($k,"#") !== false ) { continue; } //ignore
  11577. $ypos = $v['Y'];
  11578. $pagenum = $v['PAGE'];
  11579. $sharp = "#";
  11580. while (array_key_exists($sharp.$k,$this->internallink)) {
  11581. $internallink = $this->internallink[$sharp.$k];
  11582. $this->SetLink($internallink,$ypos,$pagenum);
  11583. $sharp .= "#";
  11584. }
  11585. }
  11586. }
  11587. $this->linemaxfontsize = '';
  11588. $this->lineheight_correction = $this->default_lineheight_correction;
  11589. $this->bufferoutput = false;
  11590. /*-- CSS-POSITION --*/
  11591. if (count($this->fixedPosBlockSave) && $sub != 4) {
  11592. foreach($this->fixedPosBlockSave AS $fpbs) {
  11593. $old_page = $this->page;
  11594. $this->page = $fpbs[2];
  11595. $this->WriteFixedPosHTML($fpbs[0], 0, 0, 100, 100,'auto', $fpbs[1]); // 0,0,10,10 are overwritten by bbox
  11596. $this->page = $old_page;
  11597. }
  11598. }
  11599. /*-- END CSS-POSITION --*/
  11600. }
  11601. }
  11602. /*-- CSS-POSITION --*/
  11603. function WriteFixedPosHTML($html='',$x, $y, $w, $h, $overflow='visible', $bounding=array()) {
  11604. // $overflow can be 'hidden', 'visible' or 'auto' - 'auto' causes autofit to size
  11605. // Annotations disabled - enabled in mPDF 5.0
  11606. // Links do work
  11607. // Will always go on current page (or start Page 1 if required)
  11608. // Probably INCOMPATIBLE WITH keep with table, columns etc.
  11609. // Called externally or interally via <div style="position: [fixed|absolute]">
  11610. // When used internally, $x $y $w $h and $overflow are all overridden by $bounding
  11611. $overflow = strtolower($overflow);
  11612. if($this->state==0) {
  11613. $this->AddPage($this->CurOrientation);
  11614. }
  11615. $save_y = $this->y;
  11616. $save_x = $this->x;
  11617. $this->fullImageHeight = $this->h;
  11618. $save_cols = false;
  11619. /*-- COLUMNS --*/
  11620. if ($this->ColActive) {
  11621. $save_cols = true;
  11622. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  11623. $this->SetColumns(0);
  11624. }
  11625. /*-- END COLUMNS --*/
  11626. $save_annots = $this->title2annots; // *ANNOTATIONS*
  11627. $this->writingHTMLheader = true; // a FIX to stop pagebreaks etc.
  11628. $this->writingHTMLfooter = true;
  11629. $this->InFooter = true; // suppresses autopagebreaks
  11630. $save_bgs = $this->pageBackgrounds;
  11631. $checkinnerhtml = preg_replace('/\s/','',$html);
  11632. if ($w > $this->w) { $x = 0; $w = $this->w; }
  11633. if ($h > $this->h) { $y = 0; $h = $this->h; }
  11634. if ($x > $this->w) { $x = $this->w - $w; }
  11635. if ($y > $this->h) { $y = $this->h - $h; }
  11636. if (!empty($bounding)) {
  11637. // $cont_ containing block = full physical page (position: absolute) or page inside margins (position: fixed)
  11638. // $bbox_ Bounding box is the <div> which is positioned absolutely/fixed
  11639. // top/left/right/bottom/width/height/background*/border*/padding*/margin* are taken from bounding
  11640. // font*[family/size/style/weight]/line-height/text*[align/decoration/transform/indent]/color are transferred to $inner
  11641. // as an enclosing <div> (after having checked ID/CLASS)
  11642. // $x, $y, $w, $h are inside of $bbox_ = containing box for $inner_
  11643. // $inner_ InnerHTML is the contents of that block to be output
  11644. $tag = $bounding[0];
  11645. $attr = $bounding[1];
  11646. $orig_x0 = $bounding[2];
  11647. $orig_y0 = $bounding[3];
  11648. // As in WriteHTML() initialising
  11649. $this->blklvl = 0;
  11650. $this->lastblocklevelchange = 0;
  11651. $this->blk = array();
  11652. $this->initialiseBlock($this->blk[0]);
  11653. $this->blk[0]['width'] =& $this->pgwidth;
  11654. $this->blk[0]['inner_width'] =& $this->pgwidth;
  11655. $this->blk[0]['blockContext'] = $this->blockContext;
  11656. $properties = $this->MergeCSS('BLOCK','BODY','');
  11657. $this->setCSS($properties,'','BODY');
  11658. $this->blklvl = 1;
  11659. $this->initialiseBlock($this->blk[1]);
  11660. $this->blk[1]['tag'] = $tag;
  11661. $this->blk[1]['attr'] = $attr;
  11662. $this->Reset();
  11663. $p = $this->MergeCSS('BLOCK',$tag,$attr);
  11664. if (isset($p['ROTATE']) && ($p['ROTATE']==90 || $p['ROTATE']==-90)) { $rotate = $p['ROTATE']; }
  11665. else { $rotate = 0; }
  11666. if (isset($p['OVERFLOW'])) { $overflow = strtolower($p['OVERFLOW']); }
  11667. if (strtolower($p['POSITION']) == 'fixed') {
  11668. $cont_w = $this->pgwidth; // $this->blk[0]['inner_width'];
  11669. $cont_h = $this->h - $this->tMargin - $this->bMargin;
  11670. $cont_x = $this->lMargin;
  11671. $cont_y = $this->tMargin;
  11672. }
  11673. else {
  11674. $cont_w = $this->w; // ABSOLUTE;
  11675. $cont_h = $this->h;
  11676. $cont_x = 0;
  11677. $cont_y = 0;
  11678. }
  11679. // Pass on in-line properties to the innerhtml
  11680. $css = '';
  11681. if (isset($p['TEXT-ALIGN'])) { $css .= 'text-align: '.strtolower($p['TEXT-ALIGN']).'; '; }
  11682. if (isset($p['TEXT-TRANSFORM'])) { $css .= 'text-transform: '.strtolower($p['TEXT-TRANSFORM']).'; '; }
  11683. if (isset($p['TEXT-INDENT'])) { $css .= 'text-indent: '.strtolower($p['TEXT-INDENT']).'; '; }
  11684. if (isset($p['TEXT-DECORATION'])) { $css .= 'text-decoration: '.strtolower($p['TEXT-DECORATION']).'; '; }
  11685. if (isset($p['FONT-FAMILY'])) { $css .= 'font-family: '.strtolower($p['FONT-FAMILY']).'; '; }
  11686. if (isset($p['FONT-STYLE'])) { $css .= 'font-style: '.strtolower($p['FONT-STYLE']).'; '; }
  11687. if (isset($p['FONT-WEIGHT'])) { $css .= 'font-weight: '.strtolower($p['FONT-WEIGHT']).'; '; }
  11688. if (isset($p['FONT-SIZE'])) { $css .= 'font-size: '.strtolower($p['FONT-SIZE']).'; '; }
  11689. if (isset($p['LINE-HEIGHT'])) { $css .= 'line-height: '.strtolower($p['LINE-HEIGHT']).'; '; }
  11690. if (isset($p['TEXT-ALIGN'])) { $css .= 'text-align: '.strtolower($p['TEXT-ALIGN']).'; '; }
  11691. if (isset($p['TEXT-SHADOW'])) { $css .= 'text-shadow: '.strtolower($p['TEXT-SHADOW']).'; '; } // mPDF 5.3.A4
  11692. if (isset($p['FONT-VARIANT'])) { $css .= 'font-variant: '.strtolower($p['FONT-VARIANT']).'; '; }
  11693. if (isset($p['COLOR'])) { $css .= 'color: '.strtolower($p['COLOR']).'; '; }
  11694. if ($css) {
  11695. $html = '<div style="'.$css.'">'.$html.'</div>';
  11696. }
  11697. // Copy over (only) the properties to set for border and background
  11698. $pb = array();
  11699. $pb['MARGIN-TOP'] = $p['MARGIN-TOP'];
  11700. $pb['MARGIN-RIGHT'] = $p['MARGIN-RIGHT'];
  11701. $pb['MARGIN-BOTTOM'] = $p['MARGIN-BOTTOM'];
  11702. $pb['MARGIN-LEFT'] = $p['MARGIN-LEFT'];
  11703. $pb['PADDING-TOP'] = $p['PADDING-TOP'];
  11704. $pb['PADDING-RIGHT'] = $p['PADDING-RIGHT'];
  11705. $pb['PADDING-BOTTOM'] = $p['PADDING-BOTTOM'];
  11706. $pb['PADDING-LEFT'] = $p['PADDING-LEFT'];
  11707. $pb['BORDER-TOP'] = $p['BORDER-TOP'];
  11708. $pb['BORDER-RIGHT'] = $p['BORDER-RIGHT'];
  11709. $pb['BORDER-BOTTOM'] = $p['BORDER-BOTTOM'];
  11710. $pb['BORDER-LEFT'] = $p['BORDER-LEFT'];
  11711. // mPDF 5.3.66
  11712. $pb['BORDER-TOP-LEFT-RADIUS-H'] = $p['BORDER-TOP-LEFT-RADIUS-H'];
  11713. $pb['BORDER-TOP-LEFT-RADIUS-V'] = $p['BORDER-TOP-LEFT-RADIUS-V'];
  11714. $pb['BORDER-TOP-RIGHT-RADIUS-H'] = $p['BORDER-TOP-RIGHT-RADIUS-H'];
  11715. $pb['BORDER-TOP-RIGHT-RADIUS-V'] = $p['BORDER-TOP-RIGHT-RADIUS-V'];
  11716. $pb['BORDER-BOTTOM-LEFT-RADIUS-H'] = $p['BORDER-BOTTOM-LEFT-RADIUS-H'];
  11717. $pb['BORDER-BOTTOM-LEFT-RADIUS-V'] = $p['BORDER-BOTTOM-LEFT-RADIUS-V'];
  11718. $pb['BORDER-BOTTOM-RIGHT-RADIUS-H'] = $p['BORDER-BOTTOM-RIGHT-RADIUS-H'];
  11719. $pb['BORDER-BOTTOM-RIGHT-RADIUS-V'] = $p['BORDER-BOTTOM-RIGHT-RADIUS-V'];
  11720. if (isset($p['BACKGROUND-COLOR'])) { $pb['BACKGROUND-COLOR'] = $p['BACKGROUND-COLOR']; }
  11721. if (isset($p['BOX-SHADOW'])) { $pb['BOX-SHADOW'] = $p['BOX-SHADOW']; } // mPDF 5.3.A4
  11722. /*-- BACKGROUNDS --*/
  11723. if (isset($p['BACKGROUND-IMAGE'])) { $pb['BACKGROUND-IMAGE'] = $p['BACKGROUND-IMAGE']; }
  11724. if (isset($p['BACKGROUND-IMAGE-RESIZE'])) { $pb['BACKGROUND-IMAGE-RESIZE'] = $p['BACKGROUND-IMAGE-RESIZE']; }
  11725. if (isset($p['BACKGROUND-IMAGE-OPACITY'])) { $pb['BACKGROUND-IMAGE-OPACITY'] = $p['BACKGROUND-IMAGE-OPACITY']; }
  11726. if (isset($p['BACKGROUND-REPEAT'])) { $pb['BACKGROUND-REPEAT'] = $p['BACKGROUND-REPEAT']; }
  11727. if (isset($p['BACKGROUND-POSITION'])) { $pb['BACKGROUND-POSITION'] = $p['BACKGROUND-POSITION']; }
  11728. if (isset($p['BACKGROUND-GRADIENT'])) { $pb['BACKGROUND-GRADIENT'] = $p['BACKGROUND-GRADIENT']; }
  11729. /*-- END BACKGROUNDS --*/
  11730. $this->setCSS($pb,'BLOCK',$tag);
  11731. //================================================================
  11732. $bbox_br = $this->blk[1]['border_right']['w'];
  11733. $bbox_bl = $this->blk[1]['border_left']['w'];
  11734. $bbox_bt = $this->blk[1]['border_top']['w'];
  11735. $bbox_bb = $this->blk[1]['border_bottom']['w'];
  11736. $bbox_pr = $this->blk[1]['padding_right'];
  11737. $bbox_pl = $this->blk[1]['padding_left'];
  11738. $bbox_pt = $this->blk[1]['padding_top'];
  11739. $bbox_pb = $this->blk[1]['padding_bottom'];
  11740. $bbox_mr = $this->blk[1]['margin_right'];
  11741. if (strtolower($p['MARGIN-RIGHT'])=='auto') { $bbox_mr = 'auto'; }
  11742. $bbox_ml = $this->blk[1]['margin_left'];
  11743. if (strtolower($p['MARGIN-LEFT'])=='auto') { $bbox_ml = 'auto'; }
  11744. $bbox_mt = $this->blk[1]['margin_top'];
  11745. if (strtolower($p['MARGIN-TOP'])=='auto') { $bbox_mt = 'auto'; }
  11746. $bbox_mb = $this->blk[1]['margin_bottom'];
  11747. if (strtolower($p['MARGIN-BOTTOM'])=='auto') { $bbox_mb = 'auto'; }
  11748. if (isset($p['LEFT']) && strtolower($p['LEFT'])!='auto') { $bbox_left = $this->ConvertSize($p['LEFT'], $cont_w, $this->FontSize,false); }
  11749. else { $bbox_left = 'auto'; }
  11750. if (isset($p['TOP']) && strtolower($p['TOP'])!='auto') { $bbox_top = $this->ConvertSize($p['TOP'], $cont_h, $this->FontSize,false); }
  11751. else { $bbox_top = 'auto'; }
  11752. if (isset($p['RIGHT']) && strtolower($p['RIGHT'])!='auto') { $bbox_right = $this->ConvertSize($p['RIGHT'], $cont_w, $this->FontSize,false); }
  11753. else { $bbox_right = 'auto'; }
  11754. if (isset($p['BOTTOM']) && strtolower($p['BOTTOM'])!='auto') { $bbox_bottom = $this->ConvertSize($p['BOTTOM'], $cont_h, $this->FontSize,false); }
  11755. else { $bbox_bottom = 'auto'; }
  11756. if (isset($p['WIDTH']) && strtolower($p['WIDTH'])!='auto') { $inner_w = $this->ConvertSize($p['WIDTH'], $cont_w, $this->FontSize,false); }
  11757. else { $inner_w = 'auto'; }
  11758. if (isset($p['HEIGHT']) && strtolower($p['HEIGHT'])!='auto') { $inner_h = $this->ConvertSize($p['HEIGHT'], $cont_h, $this->FontSize,false); }
  11759. else { $inner_h = 'auto'; }
  11760. // If bottom or right pos are set and not left / top - save this to adjust rotated block later
  11761. if ($rotate) {
  11762. if ($bbox_left === 'auto' && $bbox_right !== 'auto') { $rot_rpos = $bbox_right; }
  11763. else { $rot_rpos = false; }
  11764. if ($bbox_top === 'auto' && $bbox_bottom !== 'auto') { $rot_bpos = $bbox_bottom; }
  11765. else { $rot_bpos = false; }
  11766. }
  11767. //================================================================
  11768. if ($checkinnerhtml=='' && $inner_h==='auto') { $inner_h = 0.0001; }
  11769. if ($checkinnerhtml=='' && $inner_w==='auto') { $inner_w = 2*$this->GetCharWidth('W',false); } // mPDF 5.3.04
  11770. //================================================================
  11771. // Algorithm from CSS2.1 See http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-height
  11772. // mPD 5.3.14
  11773. // Special case (not CSS) if all not specified, centre vertically on page
  11774. if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom==='auto' && $bbox_mt==='auto' && $bbox_mb==='auto') {
  11775. $bbox_top_orig = $bbox_top;
  11776. if ($bbox_mt==='auto') { $bbox_mt = 0; }
  11777. if ($bbox_mb==='auto') { $bbox_mb = 0; }
  11778. $bbox_top = $orig_y0 - $bbox_mt - $cont_y;
  11779. // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto'
  11780. }
  11781. // mPD 5.3.14
  11782. else if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom==='auto') {
  11783. $bbox_top_orig = $bbox_top = $orig_y0 - $cont_y;
  11784. if ($bbox_mt==='auto') { $bbox_mt = 0; }
  11785. if ($bbox_mb==='auto') { $bbox_mb = 0; }
  11786. // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto'
  11787. }
  11788. else if ($bbox_top!=='auto' && $inner_h!=='auto' && $bbox_bottom!=='auto') {
  11789. if ($bbox_mt==='auto' && $bbox_mb==='auto') {
  11790. $x = $cont_h - $bbox_top - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_bottom;
  11791. $bbox_mt = $bbox_mb = ($x/2);
  11792. }
  11793. else if ($bbox_mt==='auto') {
  11794. $bbox_mt = $cont_h - $bbox_top - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  11795. }
  11796. else if ($bbox_mb==='auto') {
  11797. $bbox_mb = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_bottom;
  11798. }
  11799. else {
  11800. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt;
  11801. }
  11802. }
  11803. else {
  11804. if ($bbox_mt==='auto') { $bbox_mt = 0; }
  11805. if ($bbox_mb==='auto') { $bbox_mb = 0; }
  11806. if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom!=='auto') {
  11807. // solve for $bbox_top when content_h known - $inner_h=='auto' && $bbox_top =='auto'
  11808. }
  11809. else if ($bbox_top==='auto' && $bbox_bottom==='auto' && $inner_h!=='auto') {
  11810. $bbox_top = $orig_y0 - $bbox_mt - $cont_y;
  11811. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt;
  11812. }
  11813. else if ($inner_h==='auto' && $bbox_bottom==='auto' && $bbox_top!=='auto') {
  11814. // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto'
  11815. }
  11816. else if ($bbox_top==='auto' && $inner_h!=='auto' && $bbox_bottom!=='auto') {
  11817. $bbox_top = $cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt - $bbox_bottom;
  11818. }
  11819. else if ($inner_h==='auto' && $bbox_top!=='auto' && $bbox_bottom!=='auto') {
  11820. $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mt - $bbox_bottom;
  11821. }
  11822. else if ($bbox_bottom==='auto' && $bbox_top!=='auto' && $inner_h!=='auto') {
  11823. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt;
  11824. }
  11825. }
  11826. // THEN DO SAME FOR WIDTH
  11827. // http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-width
  11828. if ($bbox_left==='auto' && $inner_w==='auto' && $bbox_right==='auto') {
  11829. if ($bbox_ml==='auto') { $bbox_ml = 0; }
  11830. if ($bbox_mr==='auto') { $bbox_mr = 0; }
  11831. // IF containing element RTL, should set $bbox_right
  11832. $bbox_left = $orig_x0 - $bbox_ml - $cont_x;
  11833. // solve for $bbox_right when content_w known - $inner_w=='auto' && $bbox_right=='auto'
  11834. }
  11835. else if ($bbox_left!=='auto' && $inner_w!=='auto' && $bbox_right!=='auto') {
  11836. if ($bbox_ml==='auto' && $bbox_mr==='auto') {
  11837. $x = $cont_w - $bbox_left - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_right;
  11838. $bbox_ml = $bbox_mr = ($x/2);
  11839. }
  11840. else if ($bbox_ml==='auto') {
  11841. $bbox_ml = $cont_w - $bbox_left - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_mr - $bbox_right;
  11842. }
  11843. else if ($bbox_mr==='auto') {
  11844. $bbox_mr = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_right;
  11845. }
  11846. else {
  11847. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  11848. }
  11849. }
  11850. else {
  11851. if ($bbox_ml==='auto') { $bbox_ml = 0; }
  11852. if ($bbox_mr==='auto') { $bbox_mr = 0; }
  11853. if ($bbox_left==='auto' && $inner_w==='auto' && $bbox_right!=='auto') {
  11854. // solve for $bbox_left when content_w known - $inner_w=='auto' && $bbox_left =='auto'
  11855. }
  11856. else if ($bbox_left==='auto' && $bbox_right==='auto' && $inner_w!=='auto') {
  11857. // IF containing element RTL, should set $bbox_right
  11858. $bbox_left = $orig_x0 - $bbox_ml - $cont_x;
  11859. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  11860. }
  11861. else if ($inner_w==='auto' && $bbox_right==='auto' && $bbox_left!=='auto') {
  11862. // solve for $bbox_right when content_w known - $inner_w=='auto' && $bbox_right=='auto'
  11863. }
  11864. else if ($bbox_left==='auto' && $inner_w!=='auto' && $bbox_right!=='auto') {
  11865. $bbox_left = $cont_w - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right;
  11866. }
  11867. else if ($inner_w==='auto' && $bbox_left!=='auto' && $bbox_right!=='auto') {
  11868. $inner_w = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right;
  11869. }
  11870. else if ($bbox_right==='auto' && $bbox_left!=='auto' && $inner_w!=='auto') {
  11871. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  11872. }
  11873. }
  11874. //================================================================
  11875. //================================================================
  11876. /*-- BACKGROUNDS --*/
  11877. if (isset($pb['BACKGROUND-IMAGE']) && $pb['BACKGROUND-IMAGE']) {
  11878. $ret = $this->SetBackground($pb, $this->blk[1]['inner_width']);
  11879. if ($ret) { $this->blk[1]['background-image'] = $ret; }
  11880. }
  11881. /*-- END BACKGROUNDS --*/
  11882. //================================================================
  11883. $y = $cont_y + $bbox_top + $bbox_mt + $bbox_bt + $bbox_pt;
  11884. $h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  11885. $x = $cont_x + $bbox_left + $bbox_ml + $bbox_bl + $bbox_pl;
  11886. $w = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $bbox_pr - $bbox_br - $bbox_mr - $bbox_right;
  11887. // Set (temporary) values for x y w h to do first paint, if values are auto
  11888. if ($inner_h==='auto' && $bbox_top==='auto') {
  11889. $y = $cont_y + $bbox_mt + $bbox_bt + $bbox_pt;
  11890. $h = $cont_h - ($bbox_bottom + $bbox_mt + $bbox_mb + $bbox_bt + $bbox_bb + $bbox_pt + $bbox_pb);
  11891. }
  11892. else if ($inner_h==='auto' && $bbox_bottom==='auto') {
  11893. $y = $cont_y + $bbox_top + $bbox_mt + $bbox_bt + $bbox_pt;
  11894. $h = $cont_h - ($bbox_top + $bbox_mt + $bbox_mb + $bbox_bt + $bbox_bb + $bbox_pt + $bbox_pb);
  11895. }
  11896. if ($inner_w==='auto' && $bbox_left==='auto') {
  11897. $x = $cont_x + $bbox_ml + $bbox_bl + $bbox_pl;
  11898. $w = $cont_w - ($bbox_right + $bbox_ml + $bbox_mr + $bbox_bl + $bbox_br + $bbox_pl + $bbox_pr);
  11899. }
  11900. else if ($inner_w==='auto' && $bbox_right==='auto') {
  11901. $x = $cont_x + $bbox_left + $bbox_ml + $bbox_bl + $bbox_pl;
  11902. $w = $cont_w - ($bbox_left + $bbox_ml + $bbox_mr + $bbox_bl + $bbox_br + $bbox_pl + $bbox_pr);
  11903. }
  11904. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  11905. $bbox_x = $cont_x + $bbox_left + $bbox_ml;
  11906. $saved_block1 = $this->blk[1];
  11907. unset($p);
  11908. unset($pb);
  11909. //================================================================
  11910. if ($inner_w==='auto') { // do a first write
  11911. $this->lMargin=$x;
  11912. $this->rMargin=$this->w - $w - $x;
  11913. // SET POSITION & FONT VALUES
  11914. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  11915. $this->pageoutput[$this->page]=array();
  11916. $this->x = $x;
  11917. $this->y = $y;
  11918. $this->HTMLheaderPageLinks = array();
  11919. $this->HTMLheaderPageAnnots = array();
  11920. $this->HTMLheaderPageForms = array();
  11921. $this->pageBackgrounds = array();
  11922. $this->maxPosR = 0;
  11923. $this->maxPosL = $this->w; // For RTL
  11924. $this->WriteHTML($html , 4);
  11925. $inner_w = $this->maxPosR - $this->lMargin;
  11926. if ($bbox_right==='auto') {
  11927. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  11928. }
  11929. else if ($bbox_left==='auto') {
  11930. $bbox_left = $cont_w - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right;
  11931. $bbox_x = $cont_x + $bbox_left + $bbox_ml ;
  11932. $inner_x = $bbox_x + $bbox_bl + $bbox_pl;
  11933. $x = $inner_x;
  11934. }
  11935. $w = $inner_w;
  11936. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  11937. $bbox_x = $cont_x + $bbox_left + $bbox_ml;
  11938. }
  11939. if ($inner_h==='auto') { // do a first write
  11940. $this->lMargin=$x;
  11941. $this->rMargin=$this->w - $w - $x;
  11942. // SET POSITION & FONT VALUES
  11943. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  11944. $this->pageoutput[$this->page]=array();
  11945. $this->x = $x;
  11946. $this->y = $y;
  11947. $this->HTMLheaderPageLinks = array();
  11948. $this->HTMLheaderPageAnnots = array();
  11949. $this->HTMLheaderPageForms = array();
  11950. $this->pageBackgrounds = array();
  11951. $this->WriteHTML($html , 4);
  11952. $inner_h = $this->y - $y;
  11953. if ($overflow!='hidden' && $overflow!='visible') { // constrained
  11954. if (($this->y + $bbox_pb + $bbox_bb) > ($cont_y + $cont_h)) {
  11955. $adj = ($this->y + $bbox_pb + $bbox_bb) - ($cont_y + $cont_h);
  11956. $inner_h -= $adj;
  11957. }
  11958. }
  11959. if ($bbox_bottom==='auto' && $bbox_top_orig==='auto') {
  11960. $bbox_bottom = $bbox_top = ($cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb)/2;
  11961. if ($overflow!='hidden' && $overflow!='visible') { // constrained
  11962. if ($bbox_top < 0) {
  11963. $bbox_top = 0;
  11964. $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  11965. }
  11966. }
  11967. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  11968. $inner_y = $bbox_y + $bbox_bt + $bbox_pt;
  11969. $y = $inner_y;
  11970. }
  11971. else if ($bbox_bottom==='auto') {
  11972. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb;
  11973. }
  11974. else if ($bbox_top==='auto') {
  11975. $bbox_top = $cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  11976. if ($overflow!='hidden' && $overflow!='visible') { // constrained
  11977. if ($bbox_top < 0) {
  11978. $bbox_top = 0;
  11979. $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  11980. }
  11981. }
  11982. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  11983. $inner_y = $bbox_y + $bbox_bt + $bbox_pt;
  11984. $y = $inner_y;
  11985. }
  11986. $h = $inner_h;
  11987. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  11988. $bbox_x = $cont_x + $bbox_left + $bbox_ml;
  11989. }
  11990. $inner_w = $w;
  11991. $inner_h = $h;
  11992. }
  11993. $this->lMargin=$x;
  11994. $this->rMargin=$this->w - $w - $x;
  11995. // SET POSITION & FONT VALUES
  11996. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  11997. $this->pageoutput[$this->page]=array();
  11998. $this->x = $x;
  11999. $this->y = $y;
  12000. $this->HTMLheaderPageLinks = array();
  12001. $this->HTMLheaderPageAnnots = array();
  12002. $this->HTMLheaderPageForms = array();
  12003. $this->pageBackgrounds = array();
  12004. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  12005. $actual_h = $this->y - $y;
  12006. $use_w = $w;
  12007. $use_h = $h;
  12008. $ratio = $actual_h / $use_w;
  12009. if ($overflow!='hidden' && $overflow!='visible') {
  12010. $target = $h/$w;
  12011. if (($ratio / $target ) > 1) {
  12012. $nl = CEIL($actual_h / $this->lineheight);
  12013. $l = $use_w * $nl;
  12014. $est_w = sqrt(($l * $this->lineheight) / $target) * 0.8;
  12015. $use_w += ($est_w - $use_w) - ($w/100);
  12016. }
  12017. $bpcstart = ($ratio / $target);
  12018. $bpcctr = 1;
  12019. while(($ratio / $target ) > 1) {
  12020. if ($this->progressBar) { $this->UpdateProgressBar(4,intval(100/($ratio/$target)),('Auto-sizing fixed-position block: '.$bpcctr++)); } // *PROGRESS-BAR*
  12021. $this->x = $x;
  12022. $this->y = $y;
  12023. if (($ratio / $target) > 1.5 || ($ratio / $target) < 0.6) {
  12024. $use_w += ($w/$this->incrementFPR1);
  12025. }
  12026. else if (($ratio / $target) > 1.2 || ($ratio / $target) < 0.85) {
  12027. $use_w += ($w/$this->incrementFPR2);
  12028. }
  12029. else if (($ratio / $target) > 1.1 || ($ratio / $target) < 0.91) {
  12030. $use_w += ($w/$this->incrementFPR3);
  12031. }
  12032. else {
  12033. $use_w += ($w/$this->incrementFPR4);
  12034. }
  12035. $use_h = $use_w * $target ;
  12036. $this->rMargin=$this->w - $use_w - $x;
  12037. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  12038. $this->HTMLheaderPageLinks = array();
  12039. $this->HTMLheaderPageAnnots = array();
  12040. $this->HTMLheaderPageForms = array();
  12041. $this->pageBackgrounds = array();
  12042. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  12043. $actual_h = $this->y - $y;
  12044. $ratio = $actual_h / $use_w;
  12045. }
  12046. if ($this->progressBar) { $this->UpdateProgressBar(4,'100',' '); } // *PROGRESS-BAR*
  12047. }
  12048. $shrink_f = $w/$use_w;
  12049. //================================================================
  12050. $this->pages[$this->page] .= '___BEFORE_BORDERS___';
  12051. $block_s = $this->PrintPageBackgrounds(); // Save to print later inside clipping path
  12052. $this->pageBackgrounds = array();
  12053. //================================================================
  12054. if ($rotate) {
  12055. $prerotw = $bbox_bl + $bbox_pl + $inner_w + $bbox_pr + $bbox_br;
  12056. $preroth = $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb;
  12057. $rot_start = " q\n";
  12058. if ($rotate == 90) {
  12059. if ($rot_rpos !== false) { $adjw = $prerotw; } // width before rotation
  12060. else { $adjw = $preroth; } // height before rotation
  12061. if ($rot_bpos !== false) { $adjh = -$prerotw + $preroth; }
  12062. else { $adjh = 0; }
  12063. }
  12064. else {
  12065. if ($rot_rpos !== false) { $adjw = $prerotw - $preroth; }
  12066. else { $adjw = 0; }
  12067. if ($rot_bpos !== false) { $adjh = $preroth; } // height before rotation
  12068. else { $adjh = $prerotw; } // width before rotation
  12069. }
  12070. $rot_start .= $this->transformTranslate($adjw, $adjh, true)."\n";
  12071. $rot_start .= $this->transformRotate($rotate, $bbox_x, $bbox_y, true)."\n";
  12072. $rot_end = " Q\n";
  12073. }
  12074. else {
  12075. $rot_start = '';
  12076. $rot_end = '';
  12077. }
  12078. //================================================================
  12079. if (!empty($bounding)) {
  12080. // WHEN HEIGHT // BOTTOM EDGE IS KNOWN and $this->y is set to the bottom
  12081. // Re-instate saved $this->blk[1]
  12082. $this->blk[1] = $saved_block1;
  12083. // These are only needed when painting border/background
  12084. $this->blk[1]['width'] = $bbox_w = $cont_w - $bbox_left - $bbox_ml - $bbox_mr - $bbox_right;
  12085. $this->blk[1]['x0'] = $bbox_x;
  12086. $this->blk[1]['y0'] = $bbox_y;
  12087. $this->blk[1]['startpage'] = $this->page;
  12088. $this->blk[1]['y1'] = $bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb ;
  12089. $this->_out($rot_start); // mPDF 5.0
  12090. $this->PaintDivBB('',0,1); // Prints borders and sets backgrounds in $this->pageBackgrounds
  12091. $this->_out($rot_end);
  12092. }
  12093. $s = $this->PrintPageBackgrounds();
  12094. $s = $rot_start.$s.$rot_end;
  12095. $this->pages[$this->page] = preg_replace('/___BEFORE_BORDERS___/', "\n".$s."\n", $this->pages[$this->page]);
  12096. $this->pageBackgrounds = array();
  12097. $this->_out($rot_start);
  12098. // Clipping Output
  12099. if ($overflow=='hidden') {
  12100. //Bounding rectangle to clip
  12101. $clip_y1 = $this->y;
  12102. if (!empty($bounding) && ($this->y + $bbox_pb + $bbox_bb) > ($bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb )) {
  12103. $clip_y1 = ($bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb ) - ($bbox_pb + $bbox_bb);
  12104. }
  12105. //$op = 'W* n'; // Clipping
  12106. $op = 'W n'; // Clipping alternative mode
  12107. $this->_out("q");
  12108. $ch = $clip_y1 - $y;
  12109. $this->_out(sprintf('%.3F %.3F %.3F %.3F re %s',$x*_MPDFK,($this->h-$y)*_MPDFK,$w*_MPDFK,-$ch*_MPDFK,$op));
  12110. if (!empty($block_s)) {
  12111. $tmp = "q\n".sprintf('%.3F %.3F %.3F %.3F re %s',$x*_MPDFK,($this->h-$y)*_MPDFK,$w*_MPDFK,-$ch*_MPDFK,$op);
  12112. $tmp .= "\n".$block_s."\nQ";
  12113. $block_s = $tmp ;
  12114. }
  12115. }
  12116. if (!empty($block_s)) {
  12117. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12118. $tmp = "q\n".$this->transformScale(($shrink_f*100),($shrink_f*100), $x, $y, true);
  12119. $tmp .= "\n".$block_s."\nQ";
  12120. $block_s = $tmp ;
  12121. }
  12122. $this->_out($block_s);
  12123. }
  12124. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12125. $this->StartTransform();
  12126. $this->transformScale(($shrink_f*100),($shrink_f*100), $x, $y);
  12127. }
  12128. $this->_out($this->headerbuffer);
  12129. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12130. $this->StopTransform();
  12131. }
  12132. if ($overflow=='hidden') {
  12133. //End clipping
  12134. $this->_out("Q");
  12135. }
  12136. $this->_out($rot_end);
  12137. // Page Links
  12138. foreach($this->HTMLheaderPageLinks AS $lk) {
  12139. if ($rotate) {
  12140. $tmp = $lk[2]; // Switch h - w
  12141. $lk[2] = $lk[3];
  12142. $lk[3] = $tmp;
  12143. $lx1 = (($lk[0]/_MPDFK));
  12144. $ly1 = (($this->h-($lk[1]/_MPDFK)));
  12145. if ($rotate == 90) {
  12146. $adjx = -($lx1-$bbox_x) + ($preroth - ($ly1-$bbox_y));
  12147. $adjy = -($ly1-$bbox_y) + ($lx1-$bbox_x);
  12148. $lk[2] = -$lk[2];
  12149. }
  12150. else if ($rotate == -90) {
  12151. $adjx = -($lx1-$bbox_x) + ($ly1-$bbox_y);
  12152. $adjy = -($ly1-$bbox_y) - ($lx1-$bbox_x) + $prerotw;
  12153. $lk[3] = -$lk[3];
  12154. }
  12155. if ($rot_rpos !== false) { $adjx += $prerotw - $preroth; }
  12156. if ($rot_bpos !== false) { $adjy += $preroth - $prerotw; }
  12157. $lx1 += $adjx;
  12158. $ly1 += $adjy;
  12159. $lk[0] = $lx1*_MPDFK;
  12160. $lk[1] = ($this->h-$ly1)*_MPDFK;
  12161. }
  12162. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12163. $lx1 = (($lk[0]/_MPDFK)-$x);
  12164. $lx2 = $x + ($lx1 * $shrink_f);
  12165. $lk[0] = $lx2*_MPDFK;
  12166. $ly1 = (($this->h-($lk[1]/_MPDFK))-$y);
  12167. $ly2 = $y + ($ly1 * $shrink_f);
  12168. $lk[1] = ($this->h-$ly2)*_MPDFK;
  12169. $lk[2] *= $shrink_f; // width
  12170. $lk[3] *= $shrink_f; // height
  12171. }
  12172. $this->PageLinks[$this->page][]=$lk;
  12173. }
  12174. foreach($this->HTMLheaderPageForms AS $n=>$f) {
  12175. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12176. $f['x'] = $x + (($f['x'] -$x) * $shrink_f);
  12177. $f['y'] = $y + (($f['y'] -$y) * $shrink_f);
  12178. $f['w'] *= $shrink_f;
  12179. $f['h'] *= $shrink_f;
  12180. $f['style']['fontsize'] *= $shrink_f;
  12181. }
  12182. $this->form->forms[$f['n']] = $f;
  12183. }
  12184. // Page Annotations
  12185. foreach($this->HTMLheaderPageAnnots AS $lk) {
  12186. if ($rotate) {
  12187. if ($rotate == 90) {
  12188. $adjx = -($lk['x']-$bbox_x) + ($preroth - ($lk['y']-$bbox_y));
  12189. $adjy = -($lk['y']-$bbox_y) + ($lk['x']-$bbox_x);
  12190. }
  12191. else if ($rotate == -90) {
  12192. $adjx = -($lk['x']-$bbox_x) + ($lk['y']-$bbox_y);
  12193. $adjy = -($lk['y']-$bbox_y) - ($lk['x']-$bbox_x) + $prerotw;
  12194. }
  12195. if ($rot_rpos !== false) { $adjx += $prerotw - $preroth; }
  12196. if ($rot_bpos !== false) { $adjy += $preroth - $prerotw; }
  12197. $lk['x'] += $adjx;
  12198. $lk['y'] += $adjy;
  12199. }
  12200. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12201. $lk['x'] = $x + (($lk['x']-$x) * $shrink_f);
  12202. $lk['y'] = $y + (($lk['y']-$y) * $shrink_f);
  12203. }
  12204. $this->PageAnnots[$this->page][]=$lk;
  12205. }
  12206. // Restore
  12207. $this->headerbuffer = '';
  12208. $this->HTMLheaderPageLinks = array();
  12209. $this->HTMLheaderPageAnnots = array();
  12210. $this->HTMLheaderPageForms = array();
  12211. $this->pageBackgrounds = $save_bgs;
  12212. $this->writingHTMLheader = false;
  12213. $this->writingHTMLfooter = false;
  12214. $this->fullImageHeight = false;
  12215. $this->ResetMargins();
  12216. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  12217. $this->SetXY($save_x,$save_y) ;
  12218. $this->title2annots = $save_annots; // *ANNOTATIONS*
  12219. $this->InFooter = false; // turns back on autopagebreaks
  12220. $this->pageoutput[$this->page]=array();
  12221. $this->pageoutput[$this->page]['Font']='';
  12222. /*-- COLUMNS --*/
  12223. if ($save_cols) {
  12224. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  12225. }
  12226. /*-- END COLUMNS --*/
  12227. }
  12228. /*-- END CSS-POSITION --*/
  12229. function initialiseBlock(&$blk) {
  12230. $blk['margin_top'] = 0;
  12231. $blk['margin_left'] = 0;
  12232. $blk['margin_bottom'] = 0;
  12233. $blk['margin_right'] = 0;
  12234. $blk['padding_top'] = 0;
  12235. $blk['padding_left'] = 0;
  12236. $blk['padding_bottom'] = 0;
  12237. $blk['padding_right'] = 0;
  12238. $blk['border_top']['w'] = 0;
  12239. $blk['border_left']['w'] = 0;
  12240. $blk['border_bottom']['w'] = 0;
  12241. $blk['border_right']['w'] = 0;
  12242. $blk['hide'] = false;
  12243. $blk['outer_left_margin'] = 0;
  12244. $blk['outer_right_margin'] = 0;
  12245. $blk['cascadeCSS'] = array();
  12246. $blk['block-align'] = false;
  12247. $blk['bgcolor'] = false;
  12248. $blk['page_break_after_avoid'] = false;
  12249. $blk['keep_block_together'] = false;
  12250. $blk['float'] = false;
  12251. $blk['line_height'] = '';
  12252. $blk['margin_collapse'] = false;
  12253. }
  12254. function border_details($bd) {
  12255. $prop = preg_split('/\s+/',trim($bd));
  12256. if (isset($this->blk[$this->blklvl]['inner_width'])) { $refw = $this->blk[$this->blklvl]['inner_width']; }
  12257. else if (isset($this->blk[$this->blklvl-1]['inner_width'])) { $refw = $this->blk[$this->blklvl-1]['inner_width']; }
  12258. else { $refw = $this->w; }
  12259. if ( count($prop) == 1 ) {
  12260. $bsize = $this->ConvertSize($prop[0],$refw,$this->FontSize,false);
  12261. if ($bsize > 0) {
  12262. return array('s' => 1, 'w' => $bsize, 'c' => $this->ConvertColor(0), 'style'=>'solid');
  12263. }
  12264. else { return array('w' => 0, 's' => 0); }
  12265. }
  12266. else if (count($prop) == 2 ) {
  12267. // 1px solid
  12268. if (in_array($prop[1],$this->borderstyles) || $prop[1] == 'none' || $prop[1] == 'hidden' ) { $prop[2] = ''; }
  12269. // solid #000000
  12270. else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $prop[0] = ''; $prop[1] = $prop[0]; $prop[2] = $prop[1]; }
  12271. // 1px #000000
  12272. else { $prop[1] = ''; $prop[2] = $prop[1]; }
  12273. }
  12274. else if ( count($prop) == 3 ) {
  12275. // Change #000000 1px solid to 1px solid #000000 (proper)
  12276. if (substr($prop[0],0,1) == '#') { $tmp = $prop[0]; $prop[0] = $prop[1]; $prop[1] = $prop[2]; $prop[2] = $tmp; }
  12277. // Change solid #000000 1px to 1px solid #000000 (proper)
  12278. else if (substr($prop[0],1,1) == '#') { $tmp = $prop[1]; $prop[0] = $prop[2]; $prop[1] = $prop[0]; $prop[2] = $tmp; }
  12279. // Change solid 1px #000000 to 1px solid #000000 (proper)
  12280. else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) {
  12281. $tmp = $prop[0]; $prop[0] = $prop[1]; $prop[1] = $tmp;
  12282. }
  12283. }
  12284. else { return array(); }
  12285. // Size
  12286. $bsize = $this->ConvertSize($prop[0],$refw,$this->FontSize,false);
  12287. //color
  12288. $coul = $this->ConvertColor($prop[2]); // returns array
  12289. // Style
  12290. $prop[1] = strtolower($prop[1]);
  12291. if (in_array($prop[1],$this->borderstyles) && $bsize > 0) { $on = 1; }
  12292. else if ($prop[1] == 'hidden') { $on = 1; $bsize = 0; $coul = ''; }
  12293. else if ($prop[1] == 'none') { $on = 0; $bsize = 0; $coul = ''; }
  12294. else { $on = 0; $bsize = 0; $coul = ''; $prop[1] = ''; }
  12295. return array('s' => $on, 'w' => $bsize, 'c' => $coul, 'style'=> $prop[1] );
  12296. }
  12297. function _fix_borderStr($bd) {
  12298. $prop = preg_split('/\s+/',trim($bd));
  12299. $w = 'medium';
  12300. $c = '#000000';
  12301. $s = 'none';
  12302. if ( count($prop) == 1 ) {
  12303. // solid
  12304. if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $s = $prop[0]; }
  12305. // #000000
  12306. else if (is_array($this->ConvertColor($prop[0]))) { $c = $prop[0]; }
  12307. // 1px
  12308. else { $w = $prop[0]; }
  12309. }
  12310. else if (count($prop) == 2 ) {
  12311. // 1px solid
  12312. if (in_array($prop[1],$this->borderstyles) || $prop[1] == 'none' || $prop[1] == 'hidden' ) { $w = $prop[0]; $s = $prop[1]; }
  12313. // solid #000000
  12314. else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $s = $prop[0]; $c = $prop[1]; }
  12315. // 1px #000000
  12316. else { $w = $prop[0]; $c = $prop[1]; }
  12317. }
  12318. else if ( count($prop) == 3 ) {
  12319. // Change #000000 1px solid to 1px solid #000000 (proper)
  12320. if (substr($prop[0],0,1) == '#') { $c = $prop[0]; $w = $prop[1]; $s = $prop[2]; }
  12321. // Change solid #000000 1px to 1px solid #000000 (proper)
  12322. else if (substr($prop[0],1,1) == '#') { $s = $prop[0]; $c = $prop[1]; $w = $prop[2]; }
  12323. // Change solid 1px #000000 to 1px solid #000000 (proper)
  12324. else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) {
  12325. $s = $prop[0]; $w = $prop[1]; $c = $prop[2];
  12326. }
  12327. else { $w = $prop[0]; $s = $prop[1]; $c = $prop[2]; }
  12328. }
  12329. else { return ''; }
  12330. $s = strtolower($s);
  12331. return $w.' '.$s.' '.$c;
  12332. }
  12333. // NEW FUNCTION FOR CSS MARGIN or PADDING called from SetCSS
  12334. function fixCSS($prop) {
  12335. if (!is_array($prop) || (count($prop)==0)) return array();
  12336. $newprop = array();
  12337. foreach($prop AS $k => $v) {
  12338. if ($k != 'BACKGROUND-IMAGE' && $k != 'BACKGROUND' && $k != 'ODD-HEADER-NAME' && $k != 'EVEN-HEADER-NAME' && $k != 'ODD-FOOTER-NAME' && $k != 'EVEN-FOOTER-NAME' && $k != 'HEADER' && $k != 'FOOTER') {
  12339. $v = strtolower($v);
  12340. }
  12341. if ($k == 'FONT') {
  12342. $s = trim($v);
  12343. preg_match_all('/\"(.*?)\"/',$s,$ff);
  12344. if (count($ff[1])) {
  12345. foreach($ff[1] AS $ffp) {
  12346. $w = preg_split('/\s+/',$ffp);
  12347. $s = preg_replace('/\"'.$ffp.'\"/',$w[0],$s);
  12348. }
  12349. }
  12350. preg_match_all('/\'(.*?)\'/',$s,$ff);
  12351. if (count($ff[1])) {
  12352. foreach($ff[1] AS $ffp) {
  12353. $w = preg_split('/\s+/',$ffp);
  12354. $s = preg_replace('/\''.$ffp.'\'/',$w[0],$s);
  12355. }
  12356. }
  12357. $s = preg_replace('/\s*,\s*/',',',$s);
  12358. $bits = preg_split('/\s+/',$s);
  12359. if (count($bits)>1) {
  12360. $k = 'FONT-FAMILY'; $v = $bits[(count($bits)-1)];
  12361. $fs = $bits[(count($bits)-2)];
  12362. if (preg_match('/(.*?)\/(.*)/',$fs, $fsp)) {
  12363. $newprop['FONT-SIZE'] = $fsp[1];
  12364. $newprop['LINE-HEIGHT'] = $fsp[2];
  12365. }
  12366. else { $newprop['FONT-SIZE'] = $fs; }
  12367. if (preg_match('/(italic|oblique)/i',$s)) { $newprop['FONT-STYLE'] = 'italic'; }
  12368. else { $newprop['FONT-STYLE'] = 'normal'; }
  12369. if (preg_match('/bold/i',$s)) { $newprop['FONT-WEIGHT'] = 'bold'; }
  12370. else { $newprop['FONT-WEIGHT'] = 'normal'; }
  12371. if (preg_match('/small-caps/i',$s)) { $newprop['TEXT-TRANSFORM'] = 'uppercase'; }
  12372. }
  12373. }
  12374. if ($k == 'FONT-FAMILY') {
  12375. $aux_fontlist = explode(",",$v);
  12376. $found = 0;
  12377. foreach($aux_fontlist AS $f) {
  12378. $fonttype = trim($f);
  12379. $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
  12380. $fonttype = preg_replace('/ /','',$fonttype);
  12381. $v = strtolower(trim($fonttype));
  12382. if (isset($this->fonttrans[$v]) && $this->fonttrans[$v]) { $v = $this->fonttrans[$v]; }
  12383. if ((!$this->onlyCoreFonts && in_array($v,$this->available_unifonts)) ||
  12384. in_array($v,array('ccourier','ctimes','chelvetica')) || /* mPDF 5.3.21 & 22 */
  12385. ($this->onlyCoreFonts && in_array($v,array('courier','times','helvetica','arial'))) ||
  12386. in_array($v, array('sjis','uhc','big5','gb'))) {
  12387. $newprop[$k] = $v;
  12388. $found = 1;
  12389. break;
  12390. }
  12391. }
  12392. if (!$found) {
  12393. foreach($aux_fontlist AS $f) {
  12394. $fonttype = trim($f);
  12395. $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
  12396. $fonttype = preg_replace('/ /','',$fonttype);
  12397. $v = strtolower(trim($fonttype));
  12398. if (isset($this->fonttrans[$v]) && $this->fonttrans[$v]) { $v = $this->fonttrans[$v]; }
  12399. if (in_array($v,$this->sans_fonts) || in_array($v,$this->serif_fonts) || in_array($v,$this->mono_fonts) ) {
  12400. $newprop[$k] = $v;
  12401. break;
  12402. }
  12403. }
  12404. }
  12405. }
  12406. else if ($k == 'MARGIN') {
  12407. $tmp = $this->expand24($v);
  12408. $newprop['MARGIN-TOP'] = $tmp['T'];
  12409. $newprop['MARGIN-RIGHT'] = $tmp['R'];
  12410. $newprop['MARGIN-BOTTOM'] = $tmp['B'];
  12411. $newprop['MARGIN-LEFT'] = $tmp['L'];
  12412. }
  12413. /*-- BORDER-RADIUS --*/
  12414. else if ($k == 'BORDER-RADIUS' || $k == 'BORDER-TOP-LEFT-RADIUS' || $k == 'BORDER-TOP-RIGHT-RADIUS' || $k == 'BORDER-BOTTOM-LEFT-RADIUS' || $k == 'BORDER-BOTTOM-RIGHT-RADIUS') {
  12415. $tmp = $this->border_radius_expand($v,$k);
  12416. if (isset($tmp['TL-H'])) $newprop['BORDER-TOP-LEFT-RADIUS-H'] = $tmp['TL-H'];
  12417. if (isset($tmp['TL-V'])) $newprop['BORDER-TOP-LEFT-RADIUS-V'] = $tmp['TL-V'];
  12418. if (isset($tmp['TR-H'])) $newprop['BORDER-TOP-RIGHT-RADIUS-H'] = $tmp['TR-H'];
  12419. if (isset($tmp['TR-V'])) $newprop['BORDER-TOP-RIGHT-RADIUS-V'] = $tmp['TR-V'];
  12420. if (isset($tmp['BL-H'])) $newprop['BORDER-BOTTOM-LEFT-RADIUS-H'] = $tmp['BL-H'];
  12421. if (isset($tmp['BL-V'])) $newprop['BORDER-BOTTOM-LEFT-RADIUS-V'] = $tmp['BL-V'];
  12422. if (isset($tmp['BR-H'])) $newprop['BORDER-BOTTOM-RIGHT-RADIUS-H'] = $tmp['BR-H'];
  12423. if (isset($tmp['BR-V'])) $newprop['BORDER-BOTTOM-RIGHT-RADIUS-V'] = $tmp['BR-V'];
  12424. }
  12425. /*-- END BORDER-RADIUS --*/
  12426. else if ($k == 'PADDING') {
  12427. $tmp = $this->expand24($v);
  12428. $newprop['PADDING-TOP'] = $tmp['T'];
  12429. $newprop['PADDING-RIGHT'] = $tmp['R'];
  12430. $newprop['PADDING-BOTTOM'] = $tmp['B'];
  12431. $newprop['PADDING-LEFT'] = $tmp['L'];
  12432. }
  12433. else if ($k == 'BORDER') {
  12434. if ($v == '1') { $v = '1px solid #000000'; }
  12435. else { $v = $this->_fix_borderStr($v); }
  12436. $newprop['BORDER-TOP'] = $v;
  12437. $newprop['BORDER-RIGHT'] = $v;
  12438. $newprop['BORDER-BOTTOM'] = $v;
  12439. $newprop['BORDER-LEFT'] = $v;
  12440. }
  12441. else if ($k == 'BORDER-TOP') {
  12442. $newprop['BORDER-TOP'] = $this->_fix_borderStr($v);
  12443. }
  12444. else if ($k == 'BORDER-RIGHT') {
  12445. $newprop['BORDER-RIGHT'] = $this->_fix_borderStr($v);
  12446. }
  12447. else if ($k == 'BORDER-BOTTOM') {
  12448. $newprop['BORDER-BOTTOM'] = $this->_fix_borderStr($v);
  12449. }
  12450. else if ($k == 'BORDER-LEFT') {
  12451. $newprop['BORDER-LEFT'] = $this->_fix_borderStr($v);
  12452. }
  12453. else if ($k == 'BORDER-STYLE') {
  12454. $e = $this->expand24($v);
  12455. $newprop['BORDER-TOP-STYLE'] = $e['T'];
  12456. $newprop['BORDER-RIGHT-STYLE'] = $e['R'];
  12457. $newprop['BORDER-BOTTOM-STYLE'] = $e['B'];
  12458. $newprop['BORDER-LEFT-STYLE'] = $e['L'];
  12459. }
  12460. else if ($k == 'BORDER-WIDTH') {
  12461. $e = $this->expand24($v);
  12462. $newprop['BORDER-TOP-WIDTH'] = $e['T'];
  12463. $newprop['BORDER-RIGHT-WIDTH'] = $e['R'];
  12464. $newprop['BORDER-BOTTOM-WIDTH'] = $e['B'];
  12465. $newprop['BORDER-LEFT-WIDTH'] = $e['L'];
  12466. }
  12467. else if ($k == 'BORDER-COLOR') {
  12468. $e = $this->expand24($v);
  12469. $newprop['BORDER-TOP-COLOR'] = $e['T'];
  12470. $newprop['BORDER-RIGHT-COLOR'] = $e['R'];
  12471. $newprop['BORDER-BOTTOM-COLOR'] = $e['B'];
  12472. $newprop['BORDER-LEFT-COLOR'] = $e['L'];
  12473. }
  12474. else if ($k == 'BORDER-SPACING') {
  12475. $prop = preg_split('/\s+/',trim($v));
  12476. if (count($prop) == 1 ) {
  12477. $newprop['BORDER-SPACING-H'] = $prop[0];
  12478. $newprop['BORDER-SPACING-V'] = $prop[0];
  12479. }
  12480. else if (count($prop) == 2 ) {
  12481. $newprop['BORDER-SPACING-H'] = $prop[0];
  12482. $newprop['BORDER-SPACING-V'] = $prop[1];
  12483. }
  12484. }
  12485. else if ($k == 'SIZE') {
  12486. $prop = preg_split('/\s+/',trim($v));
  12487. if (preg_match('/(auto|portrait|landscape)/',$prop[0])) {
  12488. $newprop['SIZE'] = strtoupper($prop[0]);
  12489. }
  12490. else if (count($prop) == 1 ) {
  12491. $newprop['SIZE']['W'] = $this->ConvertSize($prop[0]);
  12492. $newprop['SIZE']['H'] = $this->ConvertSize($prop[0]);
  12493. }
  12494. else if (count($prop) == 2 ) {
  12495. $newprop['SIZE']['W'] = $this->ConvertSize($prop[0]);
  12496. $newprop['SIZE']['H'] = $this->ConvertSize($prop[1]);
  12497. }
  12498. }
  12499. else if ($k == 'SHEET-SIZE') {
  12500. $prop = preg_split('/\s+/',trim($v));
  12501. if (count($prop) == 2 ) {
  12502. $newprop['SHEET-SIZE'] = array($this->ConvertSize($prop[0]), $this->ConvertSize($prop[1]));
  12503. }
  12504. else {
  12505. if(preg_match('/([0-9a-zA-Z]*)-L/i',$v,$m)) { // e.g. A4-L = A$ landscape
  12506. $ft = $this->_getPageFormat($m[1]);
  12507. $format = array($ft[1],$ft[0]);
  12508. }
  12509. else { $format = $this->_getPageFormat($v); }
  12510. if ($format) { $newprop['SHEET-SIZE'] = array($format[0]/_MPDFK, $format[1]/_MPDFK); }
  12511. }
  12512. }
  12513. else if ($k == 'BACKGROUND') {
  12514. $bg = $this->parseCSSbackground($v);
  12515. if ($bg['c']) { $newprop['BACKGROUND-COLOR'] = $bg['c']; }
  12516. else { $newprop['BACKGROUND-COLOR'] = 'transparent'; }
  12517. /*-- BACKGROUNDS --*/
  12518. if ($bg['i']) {
  12519. $newprop['BACKGROUND-IMAGE'] = $bg['i'];
  12520. if ($bg['r']) { $newprop['BACKGROUND-REPEAT'] = $bg['r']; }
  12521. if ($bg['p']) { $newprop['BACKGROUND-POSITION'] = $bg['p']; }
  12522. }
  12523. else { $newprop['BACKGROUND-IMAGE'] = ''; }
  12524. /*-- END BACKGROUNDS --*/
  12525. }
  12526. /*-- BACKGROUNDS --*/
  12527. else if ($k == 'BACKGROUND-IMAGE') {
  12528. if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient\(.*\)/i',$v,$m)) {
  12529. $newprop['BACKGROUND-IMAGE'] = $m[0];
  12530. continue;
  12531. }
  12532. if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)/i',$v,$m)) {
  12533. $newprop['BACKGROUND-IMAGE'] = $m[1];
  12534. }
  12535. else if (strtolower($v)=='none') { $newprop['BACKGROUND-IMAGE'] = ''; }
  12536. }
  12537. else if ($k == 'BACKGROUND-REPEAT') {
  12538. if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/i',$v,$m)) {
  12539. $newprop['BACKGROUND-REPEAT'] = strtolower($m[1]);
  12540. }
  12541. }
  12542. else if ($k == 'BACKGROUND-POSITION') {
  12543. $s = $v;
  12544. $bits = preg_split('/\s+/',trim($s));
  12545. // These should be Position x1 or x2
  12546. if (count($bits)==1) {
  12547. if (preg_match('/bottom/',$bits[0])) { $bg['p'] = '50% 100%'; }
  12548. else if (preg_match('/top/',$bits[0])) { $bg['p'] = '50% 0%'; }
  12549. else { $bg['p'] = $bits[0] . ' 50%'; }
  12550. }
  12551. else if (count($bits)==2) {
  12552. // Can be either right center or center right
  12553. if (preg_match('/(top|bottom)/',$bits[0]) || preg_match('/(left|right)/',$bits[1])) {
  12554. $bg['p'] = $bits[1] . ' '.$bits[0];
  12555. }
  12556. else {
  12557. $bg['p'] = $bits[0] . ' '.$bits[1];
  12558. }
  12559. }
  12560. if ($bg['p']) {
  12561. $bg['p'] = preg_replace('/(left|top)/','0%',$bg['p']);
  12562. $bg['p'] = preg_replace('/(right|bottom)/','100%',$bg['p']);
  12563. $bg['p'] = preg_replace('/(center)/','50%',$bg['p']);
  12564. if (!preg_match('/[\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)* [\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)*/',$bg['p'])) {
  12565. $bg['p'] = false;
  12566. }
  12567. }
  12568. if ($bg['p']) { $newprop['BACKGROUND-POSITION'] = $bg['p']; }
  12569. }
  12570. /*-- END BACKGROUNDS --*/
  12571. else if ($k == 'IMAGE-ORIENTATION') {
  12572. if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i',$v,$m)) {
  12573. $angle = $m[1] + 0;
  12574. if (strtolower($m[2])=='deg') { $angle = $angle; }
  12575. else if (strtolower($m[2])=='grad') { $angle *= (360/400); }
  12576. else if (strtolower($m[2])=='rad') { $angle = rad2deg($angle); }
  12577. while($angle < 0) { $angle += 360; }
  12578. $angle = ($angle % 360);
  12579. $angle /= 90;
  12580. $angle = round($angle) * 90;
  12581. $newprop['IMAGE-ORIENTATION'] = $angle;
  12582. }
  12583. }
  12584. else {
  12585. $newprop[$k] = $v;
  12586. }
  12587. }
  12588. return $newprop;
  12589. }
  12590. // mPDF 5.3.A1
  12591. function setCSSboxshadow($v) {
  12592. $sh = array();
  12593. $c = preg_match_all('/(rgba|rgb|cmyka|cmyk|hsla|hsl)\(.*?\)/',$v,$x);
  12594. for($i=0; $i<$c; $i++) {
  12595. $col = preg_replace('/,/','*',$x[0][$i]);
  12596. $v = preg_replace('/'.preg_quote($x[0][$i],'/').'/',$col,$v);
  12597. }
  12598. $ss = explode(',',$v);
  12599. foreach ($ss AS $s) {
  12600. $new = array('inset'=>false, 'blur'=>0, 'spread'=>0);
  12601. if (preg_match('/inset/i',$s)) { $new['inset'] = true; $s = preg_replace('/\s*inset\s*/','',$s); }
  12602. $p = explode(' ',trim($s));
  12603. if (isset($p[0])) { $new['x'] = $this->ConvertSize(trim($p[0]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); }
  12604. if (isset($p[1])) { $new['y'] = $this->ConvertSize(trim($p[1]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); }
  12605. if (isset($p[2])) {
  12606. if (preg_match('/^\s*[\.\-0-9]/',$p[2])) {
  12607. $new['blur'] = $this->ConvertSize(trim($p[2]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  12608. }
  12609. else { $new['col'] = $this->ConvertColor(preg_replace('/\*/',',',$p[2])); }
  12610. if (isset($p[3])) {
  12611. if (preg_match('/^\s*[\.\-0-9]/',$p[3])) {
  12612. $new['spread'] = $this->ConvertSize(trim($p[3]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  12613. }
  12614. else { $new['col'] = $this->ConvertColor(preg_replace('/\*/',',',$p[3])); }
  12615. if (isset($p[4])) {
  12616. $new['col'] = $this->ConvertColor(preg_replace('/\*/',',',$p[4]));
  12617. }
  12618. }
  12619. }
  12620. if (!$new['col']) { $new['col'] = $this->ConvertColor('#888888'); }
  12621. if (isset($new['y'])) { array_unshift($sh, $new); }
  12622. }
  12623. return $sh;
  12624. }
  12625. // mPDF 5.3.A2
  12626. function setCSStextshadow($v) {
  12627. $sh = array();
  12628. $c = preg_match_all('/(rgba|rgb|cmyka|cmyk|hsla|hsl)\(.*?\)/',$v,$x);
  12629. for($i=0; $i<$c; $i++) {
  12630. $col = preg_replace('/,/','*',$x[0][$i]);
  12631. $v = preg_replace('/'.preg_quote($x[0][$i],'/').'/',$col,$v);
  12632. }
  12633. $ss = explode(',',$v);
  12634. foreach ($ss AS $s) {
  12635. $new = array('blur'=>0);
  12636. $p = explode(' ',trim($s));
  12637. if (isset($p[0])) { $new['x'] = $this->ConvertSize(trim($p[0]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); }
  12638. if (isset($p[1])) { $new['y'] = $this->ConvertSize(trim($p[1]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); }
  12639. if (isset($p[2])) {
  12640. if (preg_match('/^\s*[\.\-0-9]/',$p[2])) {
  12641. $new['blur'] = $this->ConvertSize(trim($p[2]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  12642. }
  12643. else { $new['col'] = $this->ConvertColor(preg_replace('/\*/',',',$p[2])); }
  12644. if (isset($p[3])) {
  12645. $new['col'] = $this->ConvertColor(preg_replace('/\*/',',',$p[3]));
  12646. }
  12647. }
  12648. if (!$new['col']) { $new['col'] = $this->ConvertColor('#888888'); }
  12649. if (isset($new['y'])) { array_unshift($sh, $new); }
  12650. }
  12651. return $sh;
  12652. }
  12653. function parseCSSbackground($s) {
  12654. $bg = array('c'=>false, 'i'=>false, 'r'=>false, 'p'=>false, );
  12655. /*-- BACKGROUNDS --*/
  12656. if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient\(.*\)/i',$s,$m)) {
  12657. $bg['i'] = $m[0];
  12658. }
  12659. else
  12660. /*-- END BACKGROUNDS --*/
  12661. if (preg_match('/url\(/i',$s)) {
  12662. // If color, set and strip it off
  12663. if (preg_match('/^\s*(#[0-9a-fA-F]{3,6}|(rgba|rgb|cmyka|cmyk|hsla|hsl|spot)\(.*?\)|[a-zA-Z]{3,})\s+(url\(.*)/i',$s,$m)) { // mPDF 5.3.68
  12664. $bg['c'] = strtolower($m[1]);
  12665. $s = $m[3]; // mPDF 5.3.74
  12666. }
  12667. /*-- BACKGROUNDS --*/
  12668. if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)\s*(.*)/i',$s,$m)) {
  12669. $bg['i'] = $m[1];
  12670. $s = strtolower($m[2]);
  12671. if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/',$s,$m)) {
  12672. $bg['r'] = $m[1];
  12673. }
  12674. // Remove repeat, attachment (discarded) and also any inherit
  12675. $s = preg_replace('/(repeat-x|repeat-y|no-repeat|repeat|scroll|fixed|inherit)/','',$s);
  12676. $bits = preg_split('/\s+/',trim($s));
  12677. // These should be Position x1 or x2
  12678. if (count($bits)==1) {
  12679. if (preg_match('/bottom/',$bits[0])) { $bg['p'] = '50% 100%'; }
  12680. else if (preg_match('/top/',$bits[0])) { $bg['p'] = '50% 0%'; }
  12681. else { $bg['p'] = $bits[0] . ' 50%'; }
  12682. }
  12683. else if (count($bits)==2) {
  12684. // Can be either right center or center right
  12685. if (preg_match('/(top|bottom)/',$bits[0]) || preg_match('/(left|right)/',$bits[1])) {
  12686. $bg['p'] = $bits[1] . ' '.$bits[0];
  12687. }
  12688. else {
  12689. $bg['p'] = $bits[0] . ' '.$bits[1];
  12690. }
  12691. }
  12692. if ($bg['p']) {
  12693. $bg['p'] = preg_replace('/(left|top)/','0%',$bg['p']);
  12694. $bg['p'] = preg_replace('/(right|bottom)/','100%',$bg['p']);
  12695. $bg['p'] = preg_replace('/(center)/','50%',$bg['p']);
  12696. if (!preg_match('/[\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)* [\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)*/',$bg['p'])) {
  12697. $bg['p'] = false;
  12698. }
  12699. }
  12700. }
  12701. /*-- END BACKGROUNDS --*/
  12702. }
  12703. else if (preg_match('/^\s*(#[0-9a-fA-F]{3,6}|(rgba|rgb|cmyka|cmyk|hsla|hsl|spot)\(.*?\)|[a-zA-Z]{3,})/i',$s,$m)) { $bg['c'] = strtolower($m[1]); } // mPDF 5.3.68
  12704. return ($bg);
  12705. }
  12706. function expand24($mp) {
  12707. $prop = preg_split('/\s+/',trim($mp));
  12708. if (count($prop) == 1 ) {
  12709. return array('T' => $prop[0], 'R' => $prop[0], 'B' => $prop[0], 'L'=> $prop[0]);
  12710. }
  12711. if (count($prop) == 2 ) {
  12712. return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[0], 'L'=> $prop[1]);
  12713. }
  12714. if (count($prop) == 3 ) {
  12715. return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L'=> $prop[1]);
  12716. }
  12717. if (count($prop) == 4 ) {
  12718. return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L'=> $prop[3]);
  12719. }
  12720. return array();
  12721. }
  12722. /*-- BORDER-RADIUS --*/
  12723. function border_radius_expand($val,$k) {
  12724. $b = array();
  12725. if ($k == 'BORDER-RADIUS') {
  12726. $hv = explode('/',trim($val));
  12727. $prop = preg_split('/\s+/',trim($hv[0]));
  12728. if (count($prop)==1) {
  12729. $b['TL-H'] = $b['TR-H'] = $b['BR-H'] = $b['BL-H'] = $prop[0];
  12730. }
  12731. else if (count($prop)==2) {
  12732. $b['TL-H'] = $b['BR-H'] = $prop[0];
  12733. $b['TR-H'] = $b['BL-H'] = $prop[1];
  12734. }
  12735. else if (count($prop)==3) {
  12736. $b['TL-H'] = $prop[0];
  12737. $b['TR-H'] = $b['BL-H'] = $prop[1];
  12738. $b['BR-H'] = $prop[2];
  12739. }
  12740. else if (count($prop)==4) {
  12741. $b['TL-H'] = $prop[0];
  12742. $b['TR-H'] = $prop[1];
  12743. $b['BR-H'] = $prop[2];
  12744. $b['BL-H'] = $prop[3];
  12745. }
  12746. if (count($hv)==2) {
  12747. $prop = preg_split('/\s+/',trim($hv[1]));
  12748. if (count($prop)==1) {
  12749. $b['TL-V'] = $b['TR-V'] = $b['BR-V'] = $b['BL-V'] = $prop[0];
  12750. }
  12751. else if (count($prop)==2) {
  12752. $b['TL-V'] = $b['BR-V'] = $prop[0];
  12753. $b['TR-V'] = $b['BL-V'] = $prop[1];
  12754. }
  12755. else if (count($prop)==3) {
  12756. $b['TL-V'] = $prop[0];
  12757. $b['TR-V'] = $b['BL-V'] = $prop[1];
  12758. $b['BR-V'] = $prop[2];
  12759. }
  12760. else if (count($prop)==4) {
  12761. $b['TL-V'] = $prop[0];
  12762. $b['TR-V'] = $prop[1];
  12763. $b['BR-V'] = $prop[2];
  12764. $b['BL-V'] = $prop[3];
  12765. }
  12766. }
  12767. else {
  12768. $b['TL-V'] = $b['TL-H'];
  12769. $b['TR-V'] = $b['TR-H'];
  12770. $b['BL-V'] = $b['BL-H'];
  12771. $b['BR-V'] = $b['BR-H'];
  12772. }
  12773. return $b;
  12774. }
  12775. // Parse 2
  12776. $h = 0;
  12777. $v = 0;
  12778. $prop = preg_split('/\s+/',trim($val));
  12779. if (count($prop)==1) { $h = $v = $val; }
  12780. else { $h = $prop[0]; $v = $prop[1]; }
  12781. if ($h==0 || $v==0) { $h = $v = 0; }
  12782. if ($k == 'BORDER-TOP-LEFT-RADIUS') {
  12783. $b['TL-H'] = $h;
  12784. $b['TL-V'] = $v;
  12785. }
  12786. else if ($k == 'BORDER-TOP-RIGHT-RADIUS') {
  12787. $b['TR-H'] = $h;
  12788. $b['TR-V'] = $v;
  12789. }
  12790. else if ($k == 'BORDER-BOTTOM-LEFT-RADIUS') {
  12791. $b['BL-H'] = $h;
  12792. $b['BL-V'] = $v;
  12793. }
  12794. else if ($k == 'BORDER-BOTTOM-RIGHT-RADIUS') {
  12795. $b['BR-H'] = $h;
  12796. $b['BR-V'] = $v;
  12797. }
  12798. return $b;
  12799. }
  12800. /*-- END BORDER-RADIUS --*/
  12801. /*-- END HTML-CSS --*/
  12802. // Return either a number (factor) - based on current set fontsize (if % or em) - or exact lineheight (with 'mm' after it)
  12803. function fixLineheight($v) {
  12804. $lh = false;
  12805. if (preg_match('/^[0-9\.,]*$/',$v) && $v >= 0) { return ($v + 0); }
  12806. else if (strtoupper($v) == 'NORMAL') {
  12807. return $this->normalLineheight;
  12808. }
  12809. else {
  12810. $tlh = $this->ConvertSize($v,$this->FontSize,$this->FontSize,true);
  12811. if ($tlh) { return ($tlh.'mm'); }
  12812. }
  12813. return $this->normalLineheight;
  12814. }
  12815. /*-- BORDER-RADIUS --*/
  12816. function _borderPadding($a, $b, &$px, &$py) {
  12817. // $px and py are padding long axis (x) and short axis (y)
  12818. $added = 0; // extra padding
  12819. $x = $a-$px;
  12820. $y = $b-$py;
  12821. // Check if Falls within ellipse of border radius
  12822. if ( ( (($x+$added)*($x+$added))/($a*$a) + (($y+$added)*($y+$added))/($b*$b) ) <=1 ) { return false; }
  12823. $t = atan2($y,$x);
  12824. $newx = $b / sqrt((($b*$b)/($a*$a)) + ( tan($t) * tan($t) ) );
  12825. $newy = $a / sqrt((($a*$a)/($b*$b)) + ( (1/tan($t)) * (1/tan($t)) ) );
  12826. $px = max($px, $a - $newx + $added);
  12827. $py = max($py, $b - $newy + $added);
  12828. }
  12829. /*-- END BORDER-RADIUS --*/
  12830. /*-- TABLES --*/
  12831. function setBorderDominance($prop, $val) {
  12832. if (isset($prop['BORDER-LEFT']) && $prop['BORDER-LEFT']) { $this->cell_border_dominance_L = $val; }
  12833. if (isset($prop['BORDER-RIGHT']) && $prop['BORDER-RIGHT']) { $this->cell_border_dominance_R = $val; }
  12834. if (isset($prop['BORDER-TOP']) && $prop['BORDER-TOP']) { $this->cell_border_dominance_T = $val; }
  12835. if (isset($prop['BORDER-BOTTOM']) && $prop['BORDER-BOTTOM']) { $this->cell_border_dominance_B = $val; }
  12836. }
  12837. /*-- END TABLES --*/
  12838. /*-- HTML-CSS --*/
  12839. function _mergeCSS($p, &$t) { // mPDF 5.3.82 $p changed to &$p
  12840. // Save Cascading CSS e.g. "div.topic p" at this block level
  12841. if (isset($p) && $p) {
  12842. if ($t) {
  12843. $t = $this->array_merge_recursive_unique($t, $p); // mPDF 5.3.96
  12844. }
  12845. else { $t = $p; }
  12846. }
  12847. }
  12848. // for CSS handling
  12849. function array_merge_recursive_unique($array1, $array2) {
  12850. $arrays = func_get_args();
  12851. $narrays = count($arrays);
  12852. $ret = $arrays[0];
  12853. for ($i = 1; $i < $narrays; $i ++) {
  12854. foreach ($arrays[$i] as $key => $value) {
  12855. if (((string) $key) === ((string) intval($key))) { // integer or string as integer key - append
  12856. $ret[] = $value;
  12857. }
  12858. else { // string key - merge
  12859. if (is_array($value) && isset($ret[$key])) {
  12860. $ret[$key] = $this->array_merge_recursive_unique($ret[$key], $value);
  12861. }
  12862. else {
  12863. $ret[$key] = $value;
  12864. }
  12865. }
  12866. }
  12867. }
  12868. return $ret;
  12869. }
  12870. function _mergeFullCSS($p, &$t, $tag, $classes, $id) { // mPDF 5.3.82 $p changed to &$p
  12871. $this->_mergeCSS($p[$tag], $t);
  12872. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  12873. foreach($classes AS $class) {
  12874. $this->_mergeCSS($p['CLASS>>'.$class], $t);
  12875. }
  12876. // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
  12877. // mPDF 5.3.82
  12878. if ($tag=='TR' && isset($p) && $p) {
  12879. foreach($p AS $k=>$val) {
  12880. if (preg_match('/'.$tag.'>>SELECTORNTHCHILD>>(.*)/',$k, $m)) {
  12881. $select = false;
  12882. if ($tag=='TR') {
  12883. $row = $this->row; // mPDF 5.3.84
  12884. $thnr = (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead']) ? count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead']) : 0);
  12885. $tfnr = (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) ? count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) : 0);
  12886. if ($this->tabletfoot) { $row -= $thnr; }
  12887. else if (!$this->tablethead) { $row -= ($thnr + $tfnr); }
  12888. if ($m[1]=='ODD' && ($row % 2) == 0) { $select = true; }
  12889. else if ($m[1]=='EVEN' && ($row % 2) == 1) { $select = true; }
  12890. else if (preg_match('/(\d+)N\+(\d+)/',$m[1],$a)) {
  12891. if ((($row + 1) % $a[1]) == $a[2]) { $select = true; }
  12892. }
  12893. }
  12894. else if ($tag=='TD' || $tag=='TH') {
  12895. if ($m[1]=='ODD' && ($this->col % 2) == 0) { $select = true; }
  12896. else if ($m[1]=='EVEN' && ($this->col % 2) == 1) { $select = true; }
  12897. else if (preg_match('/(\d+)N\+(\d+)/',$m[1],$a)) {
  12898. if ((($this->col + 1) % $a[1]) == $a[2]) { $select = true; }
  12899. }
  12900. }
  12901. if ($select) {
  12902. $this->_mergeCSS($p[$tag.'>>SELECTORNTHCHILD>>'.$m[1]], $t);
  12903. }
  12904. }
  12905. }
  12906. }
  12907. // STYLESHEET CLASS e.g. #smallone{} #redletter{}
  12908. if (isset($id) && $id) {
  12909. $this->_mergeCSS($p['ID>>'.$id], $t);
  12910. }
  12911. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  12912. foreach($classes AS $class) {
  12913. $this->_mergeCSS($p[$tag.'>>CLASS>>'.$class], $t);
  12914. }
  12915. // STYLESHEET CLASS e.g. #smallone{} #redletter{}
  12916. if (isset($id)) {
  12917. $this->_mergeCSS($p[$tag.'>>ID>>'.$id], $t);
  12918. }
  12919. }
  12920. function _set_mergedCSS(&$m, &$p, $d=true, $bd=false) {
  12921. if (isset($m)) {
  12922. if ((isset($m['depth']) && $m['depth']>1) || $d==false) { // include check for 'depth'
  12923. if ($bd) { $this->setBorderDominance($m, $bd); } // *TABLES*
  12924. if (is_array($m)) {
  12925. $p = array_merge($p,$m);
  12926. $this->_mergeBorders($p,$m);
  12927. }
  12928. }
  12929. }
  12930. }
  12931. function _mergeBorders(&$b, &$a) { // Merges $a['BORDER-TOP-STYLE'] to $b['BORDER-TOP'] etc.
  12932. foreach(array('TOP','RIGHT','BOTTOM','LEFT') AS $side) {
  12933. foreach(array('STYLE','WIDTH','COLOR') AS $el) {
  12934. if (isset($a['BORDER-'.$side.'-'.$el])) { // e.g. $b['BORDER-TOP-STYLE']
  12935. $s = trim($a['BORDER-'.$side.'-'.$el]);
  12936. if (isset($b['BORDER-'.$side])) { // e.g. $b['BORDER-TOP']
  12937. $p = trim($b['BORDER-'.$side]);
  12938. }
  12939. else { $p = ''; }
  12940. if ($el=='STYLE') {
  12941. if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 '.$s.' \\3', $p); }
  12942. else { $b['BORDER-'.$side] = '0px '.$s.' #000000'; }
  12943. }
  12944. else if ($el=='WIDTH') {
  12945. if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', $s.' \\2 \\3', $p); }
  12946. else { $b['BORDER-'.$side] = $s.' none #000000'; }
  12947. }
  12948. else if ($el=='COLOR') {
  12949. if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 \\2 '.$s, $p); }
  12950. else { $b['BORDER-'.$side] = '0px none '.$s; }
  12951. }
  12952. }
  12953. }
  12954. }
  12955. }
  12956. function MergeCSS($inherit,$tag,$attr) {
  12957. $p = array();
  12958. $zp = array();
  12959. $classes = array();
  12960. if (isset($attr['CLASS'])) {
  12961. $classes = preg_split('/\s+/',$attr['CLASS']);
  12962. }
  12963. if (!isset($attr['ID'])) { $attr['ID']=''; }
  12964. //===============================================
  12965. /*-- TABLES --*/
  12966. // Set Inherited properties
  12967. if ($inherit == 'TOPTABLE') { // $tag = TABLE
  12968. //===============================================
  12969. // Save Cascading CSS e.g. "div.topic p" at this block level
  12970. if (isset($this->blk[$this->blklvl]['cascadeCSS'])) {
  12971. $this->tablecascadeCSS[0] = $this->blk[$this->blklvl]['cascadeCSS'];
  12972. }
  12973. else {
  12974. $this->tablecascadeCSS[0] = $this->cascadeCSS;
  12975. }
  12976. }
  12977. //===============================================
  12978. // Set Inherited properties
  12979. if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') {
  12980. //Cascade everything from last level that is not an actual property, or defined by current tag/attributes
  12981. if (isset($this->tablecascadeCSS[$this->tbCSSlvl-1]) && is_array($this->tablecascadeCSS[$this->tbCSSlvl-1])) {
  12982. foreach($this->tablecascadeCSS[$this->tbCSSlvl-1] AS $k=>$v) {
  12983. $this->tablecascadeCSS[$this->tbCSSlvl][$k] = $v;
  12984. }
  12985. }
  12986. $this->_mergeFullCSS($this->cascadeCSS, $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID']);
  12987. //===============================================
  12988. // Cascading forward CSS e.g. "table.topic td" for this table in $this->tablecascadeCSS
  12989. //===============================================
  12990. // STYLESHEET TAG e.g. table
  12991. $this->_mergeFullCSS($this->tablecascadeCSS[$this->tbCSSlvl-1], $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID']);
  12992. //===============================================
  12993. }
  12994. /*-- END TABLES --*/
  12995. //===============================================
  12996. /*-- LISTS --*/
  12997. // Set Inherited properties
  12998. if ($inherit == 'TOPLIST') { // $tag = UL,OL
  12999. //===============================================
  13000. // Save Cascading CSS e.g. "div.topic p" at this block level
  13001. if (isset($this->blk[$this->blklvl]['cascadeCSS'])) {
  13002. $this->listcascadeCSS[0] = $this->blk[$this->blklvl]['cascadeCSS'];
  13003. }
  13004. else {
  13005. $this->listcascadeCSS[0] = $this->cascadeCSS;
  13006. }
  13007. }
  13008. //===============================================
  13009. // Set Inherited properties
  13010. if ($inherit == 'TOPLIST' || $inherit == 'LIST') {
  13011. //Cascade everything from last level that is not an actual property, or defined by current tag/attributes
  13012. if (isset($this->listcascadeCSS[$this->listCSSlvl-1]) && is_array($this->listcascadeCSS[$this->listCSSlvl-1])) {
  13013. foreach($this->listcascadeCSS[$this->listCSSlvl-1] AS $k=>$v) {
  13014. $this->listcascadeCSS[$this->listCSSlvl][$k] = $v;
  13015. }
  13016. }
  13017. $this->_mergeFullCSS($this->cascadeCSS, $this->listcascadeCSS[$this->listCSSlvl], $tag, $classes, $attr['ID']);
  13018. //===============================================
  13019. // Cascading forward CSS e.g. "table.topic td" for this list in $this->listcascadeCSS
  13020. //===============================================
  13021. // STYLESHEET TAG e.g. table
  13022. $this->_mergeFullCSS($this->listcascadeCSS[$this->listCSSlvl-1], $this->listcascadeCSS[$this->listCSSlvl], $tag, $classes, $attr['ID']);
  13023. //===============================================
  13024. }
  13025. /*-- END LISTS --*/
  13026. //===============================================
  13027. // Set Inherited properties
  13028. if ($inherit == 'BLOCK') {
  13029. if (isset($this->blk[$this->blklvl-1]['cascadeCSS']) && is_array($this->blk[$this->blklvl-1]['cascadeCSS'])) {
  13030. foreach($this->blk[$this->blklvl-1]['cascadeCSS'] AS $k=>$v) {
  13031. $this->blk[$this->blklvl]['cascadeCSS'][$k] = $v;
  13032. }
  13033. }
  13034. //===============================================
  13035. // Save Cascading CSS e.g. "div.topic p" at this block level
  13036. $this->_mergeFullCSS($this->cascadeCSS, $this->blk[$this->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID']);
  13037. //===============================================
  13038. // Cascading forward CSS
  13039. //===============================================
  13040. $this->_mergeFullCSS($this->blk[$this->blklvl-1]['cascadeCSS'], $this->blk[$this->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID']);
  13041. //===============================================
  13042. // Block properties
  13043. if (isset($this->blk[$this->blklvl-1]['margin_collapse']) && $this->blk[$this->blklvl-1]['margin_collapse']) { $p['MARGIN-COLLAPSE'] = 'COLLAPSE'; } // custom tag, but follows CSS principle that border-collapse is inherited
  13044. if (isset($this->blk[$this->blklvl-1]['line_height']) && $this->blk[$this->blklvl-1]['line_height']) { $p['LINE-HEIGHT'] = $this->blk[$this->blklvl-1]['line_height']; }
  13045. if (isset($this->blk[$this->blklvl-1]['direction']) && $this->blk[$this->blklvl-1]['direction']) { $p['DIRECTION'] = $this->blk[$this->blklvl-1]['direction']; }
  13046. if (isset($this->blk[$this->blklvl-1]['align']) && $this->blk[$this->blklvl-1]['align']) {
  13047. if ($this->blk[$this->blklvl-1]['align'] == 'L') { $p['TEXT-ALIGN'] = 'left'; }
  13048. else if ($this->blk[$this->blklvl-1]['align'] == 'J') { $p['TEXT-ALIGN'] = 'justify'; }
  13049. else if ($this->blk[$this->blklvl-1]['align'] == 'R') { $p['TEXT-ALIGN'] = 'right'; }
  13050. else if ($this->blk[$this->blklvl-1]['align'] == 'C') { $p['TEXT-ALIGN'] = 'center'; }
  13051. }
  13052. if ($this->ColActive || $this->keep_block_together) {
  13053. if (isset($this->blk[$this->blklvl-1]['bgcolor']) && $this->blk[$this->blklvl-1]['bgcolor']) { // Doesn't officially inherit, but default value is transparent (?=inherited)
  13054. $cor = $this->blk[$this->blklvl-1]['bgcolorarray' ];
  13055. $p['BACKGROUND-COLOR'] = $this->_colAtoString($cor);
  13056. }
  13057. }
  13058. if (isset($this->blk[$this->blklvl-1]['text_indent']) && ($this->blk[$this->blklvl-1]['text_indent'] || $this->blk[$this->blklvl-1]['text_indent']===0)) { $p['TEXT-INDENT'] = $this->blk[$this->blklvl-1]['text_indent']; }
  13059. if (isset($this->blk[$this->blklvl-1]['InlineProperties'])) {
  13060. $biilp = $this->blk[$this->blklvl-1]['InlineProperties'];
  13061. }
  13062. else { $biilp = null; }
  13063. if (isset($biilp[ 'family' ]) && $biilp[ 'family' ]) { $p['FONT-FAMILY'] = $biilp[ 'family' ]; }
  13064. if (isset($biilp[ 'I' ]) && $biilp[ 'I' ]) { $p['FONT-STYLE'] = 'italic'; }
  13065. if (isset($biilp[ 'sizePt' ]) && $biilp[ 'sizePt' ]) { $p['FONT-SIZE'] = $biilp[ 'sizePt' ] . 'pt'; }
  13066. if (isset($biilp[ 'B' ]) && $biilp[ 'B' ]) { $p['FONT-WEIGHT'] = 'bold'; }
  13067. if (isset($biilp[ 'colorarray' ]) && $biilp[ 'colorarray' ]) {
  13068. $cor = $biilp[ 'colorarray' ];
  13069. $p['COLOR'] = $this->_colAtoString($cor);
  13070. }
  13071. if (isset($biilp[ 'fontkerning' ])) {
  13072. if ($biilp[ 'fontkerning' ]) { $p['FONT-KERNING'] = 'normal'; }
  13073. else { $p['FONT-KERNING'] = 'none'; }
  13074. }
  13075. if (isset($biilp[ 'lSpacingCSS' ]) && $biilp[ 'lSpacingCSS' ]) { $p['LETTER-SPACING'] = $biilp[ 'lSpacingCSS' ]; }
  13076. if (isset($biilp[ 'wSpacingCSS' ]) && $biilp[ 'wSpacingCSS' ]) { $p['WORD-SPACING'] = $biilp[ 'wSpacingCSS' ]; }
  13077. if (isset($biilp[ 'toupper' ]) && $biilp[ 'toupper' ]) { $p['TEXT-TRANSFORM'] = 'uppercase'; }
  13078. else if (isset($biilp[ 'tolower' ]) && $biilp[ 'tolower' ]) { $p['TEXT-TRANSFORM'] = 'lowercase'; }
  13079. else if (isset($biilp[ 'capitalize' ]) && $biilp[ 'capitalize' ]) { $p['TEXT-TRANSFORM'] = 'capitalize'; }
  13080. // CSS says text-decoration is not inherited, but IE7 does??
  13081. if (isset($biilp[ 'underline' ]) && $biilp[ 'underline' ]) { $p['TEXT-DECORATION'] = 'underline'; }
  13082. if (isset($biilp[ 'smCaps' ]) && $biilp[ 'smCaps' ]) { $p['FONT-VARIANT'] = 'small-caps'; }
  13083. }
  13084. //===============================================
  13085. //===============================================
  13086. /*-- LISTS --*/
  13087. // Set Inherited properties
  13088. if ($inherit == 'TOPLIST') {
  13089. if ($this->listCSSlvl == 1) {
  13090. $bilp = $this->blk[$this->blklvl]['InlineProperties'];
  13091. if (isset($bilp[ 'family' ]) && $bilp[ 'family' ]) { $p['FONT-FAMILY'] = $bilp[ 'family' ]; }
  13092. if (isset($bilp[ 'I' ]) && $bilp[ 'I' ]) { $p['FONT-STYLE'] = 'italic'; }
  13093. if (isset($bilp[ 'sizePt' ]) && $bilp[ 'sizePt' ]) { $p['FONT-SIZE'] = $bilp[ 'sizePt' ] . 'pt'; }
  13094. if (isset($bilp[ 'B' ]) && $bilp[ 'B' ]) { $p['FONT-WEIGHT'] = 'bold'; }
  13095. if (isset($bilp[ 'colorarray' ]) && $bilp[ 'colorarray' ]) {
  13096. $cor = $bilp[ 'colorarray' ];
  13097. $p['COLOR'] = $this->_colAtoString($cor);
  13098. }
  13099. if (isset($bilp[ 'toupper' ]) && $bilp[ 'toupper' ]) { $p['TEXT-TRANSFORM'] = 'uppercase'; }
  13100. else if (isset($bilp[ 'tolower' ]) && $bilp[ 'tolower' ]) { $p['TEXT-TRANSFORM'] = 'lowercase'; }
  13101. else if (isset($bilp[ 'capitalize' ]) && $bilp[ 'capitalize' ]) { $p['TEXT-TRANSFORM'] = 'capitalize'; }
  13102. if (isset($bilp[ 'fontkerning' ])) {
  13103. if ($bilp[ 'fontkerning' ]) { $p['FONT-KERNING'] = 'normal'; }
  13104. else { $p['FONT-KERNING'] = 'none'; }
  13105. }
  13106. if (isset($bilp[ 'lSpacingCSS' ]) && $bilp[ 'lSpacingCSS' ]) { $p['LETTER-SPACING'] = $bilp[ 'lSpacingCSS' ]; }
  13107. if (isset($bilp[ 'wSpacingCSS' ]) && $bilp[ 'wSpacingCSS' ]) { $p['WORD-SPACING'] = $bilp[ 'wSpacingCSS' ]; }
  13108. // CSS says text-decoration is not inherited, but IE7 does??
  13109. if (isset($bilp[ 'underline' ]) && $bilp[ 'underline' ]) { $p['TEXT-DECORATION'] = 'underline'; }
  13110. if (isset($bilp[ 'smCaps' ]) && $bilp[ 'smCaps' ]) { $p['FONT-VARIANT'] = 'small-caps'; }
  13111. if ($tag=='LI') { // mPDF 5.3.99
  13112. // Note to self - this should never work, as TOPLIST is not called when LI (see code removed in v5.3)
  13113. $this->Error("If you see this message, please report this as a bug to the mPDF Forum.");
  13114. }
  13115. }
  13116. }
  13117. /*-- END LISTS --*/
  13118. //===============================================
  13119. //===============================================
  13120. // DEFAULT for this TAG set in DefaultCSS
  13121. if (isset($this->defaultCSS[$tag])) {
  13122. $zp = $this->fixCSS($this->defaultCSS[$tag]);
  13123. if (is_array($zp)) { // Default overwrites Inherited
  13124. $p = array_merge($p,$zp); // !! Note other way round !!
  13125. $this->_mergeBorders($p,$zp);
  13126. }
  13127. }
  13128. //===============================================
  13129. /*-- TABLES --*/
  13130. // cellPadding overwrites TD/TH default but not specific CSS set on cell
  13131. if (($tag=='TD' || $tag=='TH') && isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding']) && ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'] || $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding']===0)) {
  13132. $p['PADDING-LEFT'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'];
  13133. $p['PADDING-RIGHT'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'];
  13134. $p['PADDING-TOP'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'];
  13135. $p['PADDING-BOTTOM'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'];
  13136. }
  13137. /*-- END TABLES --*/
  13138. //===============================================
  13139. // STYLESHEET TAG e.g. h1 p div table
  13140. if (isset($this->CSS[$tag]) && $this->CSS[$tag]) {
  13141. $zp = $this->CSS[$tag];
  13142. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  13143. if (is_array($zp)) {
  13144. $p = array_merge($p,$zp);
  13145. $this->_mergeBorders($p,$zp);
  13146. }
  13147. }
  13148. //===============================================
  13149. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  13150. foreach($classes AS $class) {
  13151. $zp = array();
  13152. if (isset($this->CSS['CLASS>>'.$class]) && $this->CSS['CLASS>>'.$class]) { $zp = $this->CSS['CLASS>>'.$class]; }
  13153. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  13154. if (is_array($zp)) {
  13155. $p = array_merge($p,$zp);
  13156. $this->_mergeBorders($p,$zp);
  13157. }
  13158. }
  13159. //===============================================
  13160. /*-- TABLES --*/
  13161. // mPDF 5.3.82
  13162. // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
  13163. if ($tag=='TR' || $tag=='TD' || $tag=='TH') {
  13164. foreach($this->CSS AS $k=>$val) {
  13165. if (preg_match('/'.$tag.'>>SELECTORNTHCHILD>>(.*)/',$k, $m)) {
  13166. $select = false;
  13167. if ($tag=='TR') {
  13168. $row = $this->row; // mPDF 5.3.84
  13169. $thnr = (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead']) ? count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead']) : 0);
  13170. $tfnr = (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) ? count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) : 0);
  13171. if ($this->tabletfoot) { $row -= $thnr; }
  13172. else if (!$this->tablethead) { $row -= ($thnr + $tfnr); }
  13173. if ($m[1]=='ODD' && ($row % 2) == 0) { $select = true; }
  13174. else if ($m[1]=='EVEN' && ($row % 2) == 1) { $select = true; }
  13175. else if (preg_match('/(\d+)N\+(\d+)/',$m[1],$a)) {
  13176. if ((($row + 1) % $a[1]) == $a[2]) { $select = true; }
  13177. }
  13178. }
  13179. else if ($tag=='TD' || $tag=='TH') {
  13180. if ($m[1]=='ODD' && ($this->col % 2) == 0) { $select = true; }
  13181. else if ($m[1]=='EVEN' && ($this->col % 2) == 1) { $select = true; }
  13182. else if (preg_match('/(\d+)N\+(\d+)/',$m[1],$a)) {
  13183. if ((($this->col+1) % $a[1]) == $a[2]) { $select = true; }
  13184. }
  13185. }
  13186. if ($select) {
  13187. $zp = $this->CSS[$tag.'>>SELECTORNTHCHILD>>'.$m[1]];
  13188. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); }
  13189. if (is_array($zp)) {
  13190. $p = array_merge($p,$zp);
  13191. $this->_mergeBorders($p,$zp);
  13192. }
  13193. }
  13194. }
  13195. }
  13196. }
  13197. /*-- END TABLES --*/
  13198. //===============================================
  13199. // STYLESHEET ID e.g. #smallone{} #redletter{}
  13200. if (isset($attr['ID']) && isset($this->CSS['ID>>'.$attr['ID']]) && $this->CSS['ID>>'.$attr['ID']]) {
  13201. $zp = $this->CSS['ID>>'.$attr['ID']];
  13202. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  13203. if (is_array($zp)) {
  13204. $p = array_merge($p,$zp);
  13205. $this->_mergeBorders($p,$zp);
  13206. }
  13207. }
  13208. //===============================================
  13209. // STYLESHEET CLASS e.g. p.smallone{} div.redletter{}
  13210. foreach($classes AS $class) {
  13211. $zp = array();
  13212. if (isset($this->CSS[$tag.'>>CLASS>>'.$class]) && $this->CSS[$tag.'>>CLASS>>'.$class]) { $zp = $this->CSS[$tag.'>>CLASS>>'.$class]; }
  13213. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  13214. if (is_array($zp)) {
  13215. $p = array_merge($p,$zp);
  13216. $this->_mergeBorders($p,$zp);
  13217. }
  13218. }
  13219. //===============================================
  13220. // STYLESHEET CLASS e.g. p#smallone{} div#redletter{}
  13221. if (isset($attr['ID']) && isset($this->CSS[$tag.'>>ID>>'.$attr['ID']]) && $this->CSS[$tag.'>>ID>>'.$attr['ID']]) {
  13222. $zp = $this->CSS[$tag.'>>ID>>'.$attr['ID']];
  13223. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  13224. if (is_array($zp)) {
  13225. $p = array_merge($p,$zp);
  13226. $this->_mergeBorders($p,$zp);
  13227. }
  13228. }
  13229. //===============================================
  13230. // Cascaded e.g. div.class p only works for block level
  13231. if ($inherit == 'BLOCK') {
  13232. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS'][$tag], $p);
  13233. foreach($classes AS $class) {
  13234. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS']['CLASS>>'.$class], $p);
  13235. }
  13236. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS']['ID>>'.$attr['ID']], $p);
  13237. foreach($classes AS $class) {
  13238. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS'][$tag.'>>CLASS>>'.$class], $p);
  13239. }
  13240. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS'][$tag.'>>ID>>'.$attr['ID']], $p);
  13241. }
  13242. else if ($inherit == 'INLINE') {
  13243. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS'][$tag], $p);
  13244. foreach($classes AS $class) {
  13245. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS']['CLASS>>'.$class], $p);
  13246. }
  13247. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS']['ID>>'.$attr['ID']], $p);
  13248. foreach($classes AS $class) {
  13249. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS'][$tag.'>>CLASS>>'.$class], $p);
  13250. }
  13251. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS'][$tag.'>>ID>>'.$attr['ID']], $p);
  13252. }
  13253. /*-- TABLES --*/
  13254. else if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') { // NB looks at $this->tablecascadeCSS-1 for cascading CSS
  13255. // false, 9 = don't check for 'depth' and do set border dominance
  13256. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag], $p, false, 9);
  13257. foreach($classes AS $class) {
  13258. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1]['CLASS>>'.$class], $p, false, 9);
  13259. }
  13260. // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
  13261. // mPDF 5.3.82
  13262. if ($tag=='TR' || $tag=='TD' || $tag=='TH') {
  13263. foreach($this->tablecascadeCSS[$this->tbCSSlvl-1] AS $k=>$val) {
  13264. if (preg_match('/'.$tag.'>>SELECTORNTHCHILD>>(.*)/',$k, $m)) {
  13265. $select = false;
  13266. if ($tag=='TR') {
  13267. $row = $this->row; // mPDF 5.3.84
  13268. $thnr = (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead']) ? count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead']) : 0);
  13269. $tfnr = (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) ? count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) : 0);
  13270. if ($this->tabletfoot) { $row -= $thnr; }
  13271. else if (!$this->tablethead) { $row -= ($thnr + $tfnr); }
  13272. if ($m[1]=='ODD' && ($row % 2) == 0) { $select = true; }
  13273. else if ($m[1]=='EVEN' && ($row % 2) == 1) { $select = true; }
  13274. else if (preg_match('/(\d+)N\+(\d+)/',$m[1],$a)) {
  13275. if ((($row + 1) % $a[1]) == $a[2]) { $select = true; }
  13276. }
  13277. }
  13278. else if ($tag=='TD' || $tag=='TH') {
  13279. if ($m[1]=='ODD' && ($this->col % 2) == 0) { $select = true; }
  13280. else if ($m[1]=='EVEN' && ($this->col % 2) == 1) { $select = true; }
  13281. else if (preg_match('/(\d+)N\+(\d+)/',$m[1],$a)) {
  13282. if ((($this->col + 1) % $a[1]) == $a[2]) { $select = true; }
  13283. }
  13284. }
  13285. if ($select) {
  13286. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>SELECTORNTHCHILD>>'.$m[1]], $p, false, 9);
  13287. }
  13288. }
  13289. }
  13290. }
  13291. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1]['ID>>'.$attr['ID']], $p, false, 9);
  13292. foreach($classes AS $class) {
  13293. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>CLASS>>'.$class], $p, false, 9);
  13294. }
  13295. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>ID>>'.$attr['ID']], $p, false, 9);
  13296. }
  13297. /*-- END TABLES --*/
  13298. //===============================================
  13299. /*-- LISTS --*/
  13300. else if ($inherit == 'TOPLIST' || $inherit == 'LIST') { // NB looks at $this->listcascadeCSS-1 for cascading CSS
  13301. // false = don't check for 'depth'
  13302. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1][$tag], $p, false);
  13303. foreach($classes AS $class) {
  13304. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1]['CLASS>>'.$class], $p, false);
  13305. }
  13306. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1]['ID>>'.$attr['ID']], $p, false);
  13307. foreach($classes AS $class) {
  13308. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1][$tag.'>>CLASS>>'.$class], $p, false);
  13309. }
  13310. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1][$tag.'>>ID>>'.$attr['ID']], $p, false);
  13311. }
  13312. /*-- END LISTS --*/
  13313. //===============================================
  13314. //===============================================
  13315. // INLINE STYLE e.g. style="CSS:property"
  13316. if (isset($attr['STYLE'])) {
  13317. $zp = $this->readInlineCSS($attr['STYLE']);
  13318. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  13319. if (is_array($zp)) {
  13320. $p = array_merge($p,$zp);
  13321. $this->_mergeBorders($p,$zp);
  13322. }
  13323. }
  13324. //===============================================
  13325. //===============================================
  13326. // INLINE ATTRIBUTES e.g. .. ALIGN="CENTER">
  13327. if (isset($attr['LANG']) and $attr['LANG']!='') {
  13328. $p['LANG'] = $attr['LANG'];
  13329. }
  13330. if (isset($attr['COLOR']) and $attr['COLOR']!='') {
  13331. $p['COLOR'] = $attr['COLOR'];
  13332. }
  13333. if ($tag != 'INPUT') {
  13334. if (isset($attr['WIDTH']) and $attr['WIDTH']!='') {
  13335. $p['WIDTH'] = $attr['WIDTH'];
  13336. }
  13337. if (isset($attr['HEIGHT']) and $attr['HEIGHT']!='') {
  13338. $p['HEIGHT'] = $attr['HEIGHT'];
  13339. }
  13340. }
  13341. if ($tag == 'FONT') {
  13342. if (isset($attr['FACE'])) {
  13343. $p['FONT-FAMILY'] = $attr['FACE'];
  13344. }
  13345. if (isset($attr['SIZE']) and $attr['SIZE']!='') {
  13346. $s = '';
  13347. if ($attr['SIZE'] === '+1') { $s = '120%'; }
  13348. else if ($attr['SIZE'] === '-1') { $s = '86%'; }
  13349. else if ($attr['SIZE'] === '1') { $s = 'XX-SMALL'; }
  13350. else if ($attr['SIZE'] == '2') { $s = 'X-SMALL'; }
  13351. else if ($attr['SIZE'] == '3') { $s = 'SMALL'; }
  13352. else if ($attr['SIZE'] == '4') { $s = 'MEDIUM'; }
  13353. else if ($attr['SIZE'] == '5') { $s = 'LARGE'; }
  13354. else if ($attr['SIZE'] == '6') { $s = 'X-LARGE'; }
  13355. else if ($attr['SIZE'] == '7') { $s = 'XX-LARGE'; }
  13356. if ($s) $p['FONT-SIZE'] = $s;
  13357. }
  13358. }
  13359. if (isset($attr['VALIGN']) and $attr['VALIGN']!='') {
  13360. $p['VERTICAL-ALIGN'] = $attr['VALIGN'];
  13361. }
  13362. if (isset($attr['VSPACE']) and $attr['VSPACE']!='') {
  13363. $p['MARGIN-TOP'] = $attr['VSPACE'];
  13364. $p['MARGIN-BOTTOM'] = $attr['VSPACE'];
  13365. }
  13366. if (isset($attr['HSPACE']) and $attr['HSPACE']!='') {
  13367. $p['MARGIN-LEFT'] = $attr['HSPACE'];
  13368. $p['MARGIN-RIGHT'] = $attr['HSPACE'];
  13369. }
  13370. //===============================================
  13371. return $p;
  13372. }
  13373. /*-- CSS-PAGE --*/
  13374. function SetPagedMediaCSS($name='', $first, $oddEven) {
  13375. if ($oddEven == 'E') {
  13376. if ($this->directionality=='rtl') { $side = 'R'; }
  13377. else { $side = 'L'; }
  13378. }
  13379. else {
  13380. if ($this->directionality=='rtl') { $side = 'L'; }
  13381. else { $side = 'R'; }
  13382. }
  13383. $name = strtoupper($name);
  13384. $p = array();
  13385. $p['SIZE'] = 'AUTO';
  13386. // Uses mPDF original margins as default
  13387. $p['MARGIN-RIGHT'] = strval($this->orig_rMargin).'mm';
  13388. $p['MARGIN-LEFT'] = strval($this->orig_lMargin).'mm';
  13389. $p['MARGIN-TOP'] = strval($this->orig_tMargin).'mm';
  13390. $p['MARGIN-BOTTOM'] = strval($this->orig_bMargin).'mm';
  13391. $p['MARGIN-HEADER'] = strval($this->orig_hMargin).'mm';
  13392. $p['MARGIN-FOOTER'] = strval($this->orig_fMargin).'mm';
  13393. // Basic page + selector
  13394. if (isset($this->CSS['@PAGE'])) { $zp = $this->CSS['@PAGE']; }
  13395. else { $zp = array(); }
  13396. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13397. if (isset($p['EVEN-HEADER-NAME']) && $oddEven=='E') {
  13398. $p['HEADER'] = $p['EVEN-HEADER-NAME']; unset($p['EVEN-HEADER-NAME']);
  13399. }
  13400. if (isset($p['ODD-HEADER-NAME']) && $oddEven!='E') {
  13401. $p['HEADER'] = $p['ODD-HEADER-NAME']; unset($p['ODD-HEADER-NAME']);
  13402. }
  13403. if (isset($p['EVEN-FOOTER-NAME']) && $oddEven=='E') {
  13404. $p['FOOTER'] = $p['EVEN-FOOTER-NAME']; unset($p['EVEN-FOOTER-NAME']);
  13405. }
  13406. if (isset($p['ODD-FOOTER-NAME']) && $oddEven!='E') {
  13407. $p['FOOTER'] = $p['ODD-FOOTER-NAME']; unset($p['ODD-FOOTER-NAME']);
  13408. }
  13409. // If right/Odd page
  13410. if (isset($this->CSS['@PAGE>>PSEUDO>>RIGHT']) && $side=='R') {
  13411. $zp = $this->CSS['@PAGE>>PSEUDO>>RIGHT'];
  13412. }
  13413. else { $zp = array(); }
  13414. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  13415. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  13416. // Disallow margin-left or -right on :LEFT or :RIGHT
  13417. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  13418. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  13419. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13420. // If left/Even page
  13421. if (isset($this->CSS['@PAGE>>PSEUDO>>LEFT']) && $side=='L') {
  13422. $zp = $this->CSS['@PAGE>>PSEUDO>>LEFT'];
  13423. }
  13424. else { $zp = array(); }
  13425. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  13426. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  13427. // Disallow margin-left or -right on :LEFT or :RIGHT
  13428. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  13429. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  13430. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13431. // If first page
  13432. if (isset($this->CSS['@PAGE>>PSEUDO>>FIRST']) && $first) { $zp = $this->CSS['@PAGE>>PSEUDO>>FIRST']; }
  13433. else { $zp = array(); }
  13434. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  13435. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  13436. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13437. // If named page
  13438. if ($name) {
  13439. if (isset($this->CSS['@PAGE>>NAMED>>'.$name])) { $zp = $this->CSS['@PAGE>>NAMED>>'.$name]; }
  13440. else { $zp = array(); }
  13441. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13442. if (isset($p['EVEN-HEADER-NAME']) && $oddEven=='E') {
  13443. $p['HEADER'] = $p['EVEN-HEADER-NAME']; unset($p['EVEN-HEADER-NAME']);
  13444. }
  13445. if (isset($p['ODD-HEADER-NAME']) && $oddEven!='E') {
  13446. $p['HEADER'] = $p['ODD-HEADER-NAME']; unset($p['ODD-HEADER-NAME']);
  13447. }
  13448. if (isset($p['EVEN-FOOTER-NAME']) && $oddEven=='E') {
  13449. $p['FOOTER'] = $p['EVEN-FOOTER-NAME']; unset($p['EVEN-FOOTER-NAME']);
  13450. }
  13451. if (isset($p['ODD-FOOTER-NAME']) && $oddEven!='E') {
  13452. $p['FOOTER'] = $p['ODD-FOOTER-NAME']; unset($p['ODD-FOOTER-NAME']);
  13453. }
  13454. // If named right/Odd page
  13455. if (isset($this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>RIGHT']) && $side=='R') { $zp = $this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>RIGHT']; }
  13456. else { $zp = array(); }
  13457. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  13458. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  13459. // Disallow margin-left or -right on :LEFT or :RIGHT
  13460. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  13461. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  13462. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13463. // If named left/Even page
  13464. if (isset($this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>LEFT']) && $side=='L') { $zp = $this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>LEFT']; }
  13465. else { $zp = array(); }
  13466. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  13467. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  13468. // Disallow margin-left or -right on :LEFT or :RIGHT
  13469. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  13470. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  13471. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13472. // If named first page
  13473. if (isset($this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>FIRST']) && $first) { $zp = $this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>FIRST']; }
  13474. else { $zp = array(); }
  13475. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  13476. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  13477. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13478. }
  13479. $orientation = $mgl = $mgr = $mgt = $mgb = $mgh = $mgf = '';
  13480. $header = $footer = '';
  13481. $resetpagenum = $pagenumstyle = $suppress = '';
  13482. $marks = '';
  13483. $bg = array();
  13484. $newformat = '';
  13485. if (isset($p['SHEET-SIZE']) && is_array($p['SHEET-SIZE'])) {
  13486. $newformat = $p['SHEET-SIZE'];
  13487. if ($newformat[0] > $newformat[1]) { // landscape
  13488. $newformat = array_reverse($newformat);
  13489. $p['ORIENTATION'] = 'L';
  13490. }
  13491. else { $p['ORIENTATION'] = 'P'; }
  13492. $this->_setPageSize($newformat, $p['ORIENTATION']);
  13493. }
  13494. if (isset($p['SIZE']) && is_array($p['SIZE']) && !$newformat) {
  13495. if ($p['SIZE']['W'] > $p['SIZE']['H']) { $p['ORIENTATION'] = 'L'; }
  13496. else { $p['ORIENTATION'] = 'P'; }
  13497. }
  13498. if (is_array($p['SIZE'])) {
  13499. if ($p['SIZE']['W'] > $this->fw) { $p['SIZE']['W'] = $this->fw; } // mPD 4.2 use fw not fPt
  13500. if ($p['SIZE']['H'] > $this->fh) { $p['SIZE']['H'] = $this->fh; }
  13501. if (($p['ORIENTATION']==$this->DefOrientation && !$newformat) || ($newformat && $p['ORIENTATION']=='P')) {
  13502. $outer_width_LR = ($this->fw - $p['SIZE']['W'])/2;
  13503. $outer_width_TB = ($this->fh - $p['SIZE']['H'])/2;
  13504. }
  13505. else {
  13506. $outer_width_LR = ($this->fh - $p['SIZE']['W'])/2;
  13507. $outer_width_TB = ($this->fw - $p['SIZE']['H'])/2;
  13508. }
  13509. $pgw = $p['SIZE']['W'];
  13510. $pgh = $p['SIZE']['H'];
  13511. }
  13512. else { // AUTO LANDSCAPE PORTRAIT
  13513. $outer_width_LR = 0;
  13514. $outer_width_TB = 0;
  13515. if (!$newformat) {
  13516. if (strtoupper($p['SIZE']) == 'AUTO') { $p['ORIENTATION']=$this->DefOrientation; }
  13517. else if (strtoupper($p['SIZE']) == 'LANDSCAPE') { $p['ORIENTATION']='L'; }
  13518. else { $p['ORIENTATION']='P'; }
  13519. }
  13520. if (($p['ORIENTATION']==$this->DefOrientation && !$newformat) || ($newformat && $p['ORIENTATION']=='P')) {
  13521. $pgw = $this->fw;
  13522. $pgh = $this->fh;
  13523. }
  13524. else {
  13525. $pgw = $this->fh;
  13526. $pgh = $this->fw;
  13527. }
  13528. }
  13529. if (isset($p['HEADER']) && $p['HEADER']) { $header = $p['HEADER']; }
  13530. if (isset($p['FOOTER']) && $p['FOOTER']) { $footer = $p['FOOTER']; }
  13531. if (isset($p['RESETPAGENUM']) && $p['RESETPAGENUM']) { $resetpagenum = $p['RESETPAGENUM']; }
  13532. if (isset($p['PAGENUMSTYLE']) && $p['PAGENUMSTYLE']) { $pagenumstyle = $p['PAGENUMSTYLE']; }
  13533. if (isset($p['SUPPRESS']) && $p['SUPPRESS']) { $suppress = $p['SUPPRESS']; }
  13534. if (preg_match('/cross/i', $p['MARKS']) && preg_match('/crop/i', $p['MARKS'])) { $marks = 'CROPCROSS'; }
  13535. else if (strtoupper($p['MARKS']) == 'CROP') { $marks = 'CROP'; }
  13536. else if (strtoupper($p['MARKS']) == 'CROSS') { $marks = 'CROSS'; }
  13537. if (isset($p['BACKGROUND-COLOR']) && $p['BACKGROUND-COLOR']) { $bg['BACKGROUND-COLOR'] = $p['BACKGROUND-COLOR']; }
  13538. /*-- BACKGROUNDS --*/
  13539. if (isset($p['BACKGROUND-GRADIENT']) && $p['BACKGROUND-GRADIENT']) { $bg['BACKGROUND-GRADIENT'] = $p['BACKGROUND-GRADIENT']; }
  13540. if (isset($p['BACKGROUND-IMAGE']) && $p['BACKGROUND-IMAGE']) { $bg['BACKGROUND-IMAGE'] = $p['BACKGROUND-IMAGE']; }
  13541. if (isset($p['BACKGROUND-REPEAT']) && $p['BACKGROUND-REPEAT']) { $bg['BACKGROUND-REPEAT'] = $p['BACKGROUND-REPEAT']; }
  13542. if (isset($p['BACKGROUND-POSITION']) && $p['BACKGROUND-POSITION']) { $bg['BACKGROUND-POSITION'] = $p['BACKGROUND-POSITION']; }
  13543. if (isset($p['BACKGROUND-IMAGE-RESIZE']) && $p['BACKGROUND-IMAGE-RESIZE']) { $bg['BACKGROUND-IMAGE-RESIZE'] = $p['BACKGROUND-IMAGE-RESIZE']; }
  13544. if (isset($p['BACKGROUND-IMAGE-OPACITY'])) { $bg['BACKGROUND-IMAGE-OPACITY'] = $p['BACKGROUND-IMAGE-OPACITY']; } // mPDF 5.3.12
  13545. /*-- END BACKGROUNDS --*/
  13546. if (isset($p['MARGIN-LEFT'])) { $mgl = $this->ConvertSize($p['MARGIN-LEFT'],$pgw) + $outer_width_LR; }
  13547. if (isset($p['MARGIN-RIGHT'])) { $mgr = $this->ConvertSize($p['MARGIN-RIGHT'],$pgw) + $outer_width_LR; }
  13548. if (isset($p['MARGIN-BOTTOM'])) { $mgb = $this->ConvertSize($p['MARGIN-BOTTOM'],$pgh) + $outer_width_TB; }
  13549. if (isset($p['MARGIN-TOP'])) { $mgt = $this->ConvertSize($p['MARGIN-TOP'],$pgh) + $outer_width_TB; }
  13550. if (isset($p['MARGIN-HEADER'])) { $mgh = $this->ConvertSize($p['MARGIN-HEADER'],$pgh) + $outer_width_TB; }
  13551. if (isset($p['MARGIN-FOOTER'])) { $mgf = $this->ConvertSize($p['MARGIN-FOOTER'],$pgh) + $outer_width_TB; }
  13552. if (isset($p['ORIENTATION']) && $p['ORIENTATION']) { $orientation = $p['ORIENTATION']; }
  13553. $this->page_box['outer_width_LR'] = $outer_width_LR; // Used in MARKS:crop etc.
  13554. $this->page_box['outer_width_TB'] = $outer_width_TB;
  13555. return array($orientation,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$header,$footer,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat);
  13556. }
  13557. /*-- END CSS-PAGE --*/
  13558. function PreviewBlockCSS($tag,$attr) {
  13559. // Looks ahead from current block level to a new level
  13560. $p = array();
  13561. $zp = array();
  13562. $oldcascadeCSS = $this->blk[$this->blklvl]['cascadeCSS'];
  13563. $classes = array();
  13564. if (isset($attr['CLASS'])) { $classes = preg_split('/\s+/',$attr['CLASS']); }
  13565. //===============================================
  13566. // DEFAULT for this TAG set in DefaultCSS
  13567. if (isset($this->defaultCSS[$tag])) {
  13568. $zp = $this->fixCSS($this->defaultCSS[$tag]);
  13569. if (is_array($zp)) { $p = array_merge($zp,$p); } // Inherited overwrites default
  13570. }
  13571. // STYLESHEET TAG e.g. h1 p div table
  13572. if (isset($this->CSS[$tag])) {
  13573. $zp = $this->CSS[$tag];
  13574. if (is_array($zp)) { $p = array_merge($p,$zp); }
  13575. }
  13576. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  13577. foreach($classes AS $class) {
  13578. $zp = array();
  13579. if (isset($this->CSS['CLASS>>'.$class])) { $zp = $this->CSS['CLASS>>'.$class]; }
  13580. if (is_array($zp)) { $p = array_merge($p,$zp); }
  13581. }
  13582. // STYLESHEET ID e.g. #smallone{} #redletter{}
  13583. if (isset($attr['ID']) && isset($this->CSS['ID>>'.$attr['ID']])) {
  13584. $zp = $this->CSS['ID>>'.$attr['ID']];
  13585. if (is_array($zp)) { $p = array_merge($p,$zp); }
  13586. }
  13587. // STYLESHEET CLASS e.g. p.smallone{} div.redletter{}
  13588. foreach($classes AS $class) {
  13589. $zp = array();
  13590. if (isset($this->CSS[$tag.'>>CLASS>>'.$class])) { $zp = $this->CSS[$tag.'>>CLASS>>'.$class]; }
  13591. if (is_array($zp)) { $p = array_merge($p,$zp); }
  13592. }
  13593. // STYLESHEET CLASS e.g. p#smallone{} div#redletter{}
  13594. if (isset($attr['ID']) && isset($this->CSS[$tag.'>>ID>>'.$attr['ID']])) {
  13595. $zp = $this->CSS[$tag.'>>ID>>'.$attr['ID']];
  13596. if (is_array($zp)) { $p = array_merge($p,$zp); }
  13597. }
  13598. //===============================================
  13599. // STYLESHEET TAG e.g. div h1 div p
  13600. $this->_set_mergedCSS($oldcascadeCSS[$tag], $p);
  13601. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  13602. foreach($classes AS $class) {
  13603. $this->_set_mergedCSS($oldcascadeCSS['CLASS>>'.$class], $p);
  13604. }
  13605. // STYLESHEET CLASS e.g. #smallone{} #redletter{}
  13606. if (isset($attr['ID'])) {
  13607. $this->_set_mergedCSS($oldcascadeCSS['ID>>'.$attr['ID']], $p);
  13608. }
  13609. // STYLESHEET CLASS e.g. div.smallone{} p.redletter{}
  13610. foreach($classes AS $class) {
  13611. $this->_set_mergedCSS($oldcascadeCSS[$tag.'>>CLASS>>'.$class], $p);
  13612. }
  13613. // STYLESHEET CLASS e.g. div#smallone{} p#redletter{}
  13614. if (isset($attr['ID'])) {
  13615. $this->_set_mergedCSS($oldcascadeCSS[$tag.'>>ID>>'.$attr['ID']], $p);
  13616. }
  13617. //===============================================
  13618. // INLINE STYLE e.g. style="CSS:property"
  13619. if (isset($attr['STYLE'])) {
  13620. $zp = $this->readInlineCSS($attr['STYLE']);
  13621. if (is_array($zp)) { $p = array_merge($p,$zp); }
  13622. }
  13623. //===============================================
  13624. return $p;
  13625. }
  13626. /*-- CSS-FLOAT --*/
  13627. // Added mPDF 3.0 Float DIV - CLEAR
  13628. function ClearFloats($clear, $blklvl=0) {
  13629. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($blklvl,true);
  13630. $end = $currpos = ($this->page*1000 + $this->y);
  13631. if ($clear == 'BOTH' && ($l_exists || $r_exists)) {
  13632. $this->pageoutput[$this->page] = array();
  13633. $end = max($l_max, $r_max, $currpos);
  13634. }
  13635. else if ($clear == 'RIGHT' && $r_exists) {
  13636. $this->pageoutput[$this->page] = array();
  13637. $end = max($r_max, $currpos);
  13638. }
  13639. else if ($clear == 'LEFT' && $l_exists ) {
  13640. $this->pageoutput[$this->page] = array();
  13641. $end = max($l_max, $currpos);
  13642. }
  13643. else { return; }
  13644. $old_page = $this->page;
  13645. $new_page = intval($end/1000);
  13646. if ($old_page != $new_page) {
  13647. $s = $this->PrintPageBackgrounds();
  13648. // Writes after the marker so not overwritten later by page background etc.
  13649. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  13650. $this->pageBackgrounds = array();
  13651. $this->page = $new_page;
  13652. }
  13653. $this->ResetMargins();
  13654. $this->pageoutput[$this->page] = array();
  13655. $this->y = (($end*1000) % 1000000)/1000; // mod changes operands to integers before processing
  13656. }
  13657. // Added mPDF 3.0 Float DIV
  13658. function GetFloatDivInfo($blklvl=0,$clear=false) {
  13659. // If blklvl specified, only returns floats at that level - for ClearFloats
  13660. $l_exists = false;
  13661. $r_exists = false;
  13662. $l_max = 0;
  13663. $r_max = 0;
  13664. $l_width = 0;
  13665. $r_width = 0;
  13666. if (count($this->floatDivs)) {
  13667. $currpos = ($this->page*1000 + $this->y);
  13668. foreach($this->floatDivs AS $f) {
  13669. if (($clear && $f['blockContext'] == $this->blk[$blklvl]['blockContext']) || (!$clear && $currpos >= $f['startpos'] && $currpos < ($f['endpos']-0.001) && $f['blklvl'] > $blklvl && $f['blockContext'] == $this->blk[$blklvl]['blockContext'])) {
  13670. if ($f['side']=='L') {
  13671. $l_exists= true;
  13672. $l_max = max($l_max, $f['endpos']);
  13673. $l_width = max($l_width , $f['w']);
  13674. }
  13675. if ($f['side']=='R') {
  13676. $r_exists= true;
  13677. $r_max = max($r_max, $f['endpos']);
  13678. $r_width = max($r_width , $f['w']);
  13679. }
  13680. }
  13681. }
  13682. }
  13683. return array($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width);
  13684. }
  13685. /*-- END CSS-FLOAT --*/
  13686. function OpenTag($tag,$attr)
  13687. {
  13688. // What this gets: < $tag $attr['WIDTH']="90px" > does not get content here </closeTag here>
  13689. // Correct tags where HTML specifies optional end tags,
  13690. // and/or does not allow nesting e.g. P inside P, or
  13691. if ($this->allow_html_optional_endtags) {
  13692. if (($tag == 'P' || $tag == 'DIV' || $tag == 'H1' || $tag == 'H2' || $tag == 'H3' || $tag == 'H4' || $tag == 'H5' || $tag == 'H6' || $tag == 'UL' || $tag == 'OL' || $tag == 'TABLE' || $tag=='PRE' || $tag=='FORM' || $tag=='ADDRESS' || $tag=='BLOCKQUOTE' || $tag=='CENTER' || $tag=='DL' || $tag == 'HR' ) && $this->lastoptionaltag == 'P') { $this->CloseTag($this->lastoptionaltag ); }
  13693. if ($tag == 'DD' && $this->lastoptionaltag == 'DD') { $this->CloseTag($this->lastoptionaltag ); }
  13694. if ($tag == 'DD' && $this->lastoptionaltag == 'DT') { $this->CloseTag($this->lastoptionaltag ); }
  13695. if ($tag == 'DT' && $this->lastoptionaltag == 'DD') { $this->CloseTag($this->lastoptionaltag ); }
  13696. if ($tag == 'DT' && $this->lastoptionaltag == 'DT') { $this->CloseTag($this->lastoptionaltag ); }
  13697. if ($tag == 'LI' && $this->lastoptionaltag == 'LI') { $this->CloseTag($this->lastoptionaltag ); }
  13698. if (($tag == 'TD' || $tag == 'TH') && $this->lastoptionaltag == 'TD') { $this->CloseTag($this->lastoptionaltag ); } // *TABLES*
  13699. if (($tag == 'TD' || $tag == 'TH') && $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); } // *TABLES*
  13700. if ($tag == 'TR' && $this->lastoptionaltag == 'TR') { $this->CloseTag($this->lastoptionaltag ); } // *TABLES*
  13701. if ($tag == 'TR' && $this->lastoptionaltag == 'TD') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); $this->CloseTag('THEAD'); } // *TABLES*
  13702. if ($tag == 'TR' && $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); $this->CloseTag('THEAD'); } // *TABLES*
  13703. if ($tag == 'OPTION' && $this->lastoptionaltag == 'OPTION') { $this->CloseTag($this->lastoptionaltag ); }
  13704. }
  13705. $align = array('left'=>'L','center'=>'C','right'=>'R','top'=>'T','text-top'=>'TT','middle'=>'M','baseline'=>'BS','bottom'=>'B','text-bottom'=>'TB','justify'=>'J');
  13706. $this->ignorefollowingspaces=false;
  13707. //Opening tag
  13708. switch($tag){
  13709. case 'DOTTAB':
  13710. $objattr = array();
  13711. $objattr['type'] = 'dottab';
  13712. $dots=str_repeat('.', 3)." "; // minimum number of dots
  13713. $objattr['width'] = $this->GetStringWidth($dots);
  13714. $objattr['margin_top'] = 0;
  13715. $objattr['margin_bottom'] = 0;
  13716. $objattr['margin_left'] = 0;
  13717. $objattr['margin_right'] = 0;
  13718. $objattr['height'] = 0;
  13719. $objattr['colorarray'] = $this->colorarray;
  13720. $objattr['border_top']['w'] = 0;
  13721. $objattr['border_bottom']['w'] = 0;
  13722. $objattr['border_left']['w'] = 0;
  13723. $objattr['border_right']['w'] = 0;
  13724. $e = "\xbb\xa4\xactype=dottab,objattr=".serialize($objattr)."\xbb\xa4\xac";
  13725. /*-- TABLES --*/
  13726. // Output it to buffers
  13727. if ($this->tableLevel) {
  13728. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  13729. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  13730. }
  13731. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  13732. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  13733. }
  13734. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  13735. $this->_saveCellTextBuffer($e); // mPDF 5.3.99
  13736. }
  13737. else {
  13738. /*-- END TABLES --*/
  13739. $this->_saveTextBuffer($e); // mPDF 5.3.99
  13740. } // *TABLES*
  13741. break;
  13742. case 'PAGEHEADER':
  13743. case 'PAGEFOOTER':
  13744. $this->ignorefollowingspaces = true;
  13745. if ($attr['NAME']) { $pname = $attr['NAME']; }
  13746. else { $pname = '_default'; }
  13747. if ($tag=='PAGEHEADER') { $p = &$this->pageheaders[$pname]; }
  13748. else { $p = &$this->pagefooters[$pname]; }
  13749. $p['L']=array();
  13750. $p['C']=array();
  13751. $p['R']=array();
  13752. $p['L']['font-style'] = '';
  13753. $p['C']['font-style'] = '';
  13754. $p['R']['font-style'] = '';
  13755. if (isset($attr['CONTENT-LEFT'])) {
  13756. $p['L']['content'] = $attr['CONTENT-LEFT'];
  13757. }
  13758. if (isset($attr['CONTENT-CENTER'])) {
  13759. $p['C']['content'] = $attr['CONTENT-CENTER'];
  13760. }
  13761. if (isset($attr['CONTENT-RIGHT'])) {
  13762. $p['R']['content'] = $attr['CONTENT-RIGHT'];
  13763. }
  13764. if (isset($attr['HEADER-STYLE']) || isset($attr['FOOTER-STYLE'])) { // font-family,size,weight,style,color
  13765. if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE']); }
  13766. else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE']); }
  13767. if (isset($properties['FONT-FAMILY'])) {
  13768. $p['L']['font-family'] = $properties['FONT-FAMILY'];
  13769. $p['C']['font-family'] = $properties['FONT-FAMILY'];
  13770. $p['R']['font-family'] = $properties['FONT-FAMILY'];
  13771. }
  13772. if (isset($properties['FONT-SIZE'])) {
  13773. $p['L']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK;
  13774. $p['C']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK;
  13775. $p['R']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK;
  13776. }
  13777. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='bold') { // mPDF 5.3.86
  13778. $p['L']['font-style'] = 'B';
  13779. $p['C']['font-style'] = 'B';
  13780. $p['R']['font-style'] = 'B';
  13781. }
  13782. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='italic') { // mPDF 5.3.86
  13783. $p['L']['font-style'] .= 'I';
  13784. $p['C']['font-style'] .= 'I';
  13785. $p['R']['font-style'] .= 'I';
  13786. }
  13787. if (isset($properties['COLOR'])) {
  13788. $p['L']['color'] = $properties['COLOR'];
  13789. $p['C']['color'] = $properties['COLOR'];
  13790. $p['R']['color'] = $properties['COLOR'];
  13791. }
  13792. }
  13793. if (isset($attr['HEADER-STYLE-LEFT']) || isset($attr['FOOTER-STYLE-LEFT'])) {
  13794. if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE-LEFT']); }
  13795. else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE-LEFT']); }
  13796. if (isset($properties['FONT-FAMILY'])) { $p['L']['font-family'] = $properties['FONT-FAMILY']; }
  13797. if (isset($properties['FONT-SIZE'])) { $p['L']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK; }
  13798. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='bold') { $p['L']['font-style'] ='B'; } // mPDF 5.3.86
  13799. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='italic') { $p['L']['font-style'] .='I'; } // mPDF 5.3.86
  13800. if (isset($properties['COLOR'])) { $p['L']['color'] = $properties['COLOR']; }
  13801. }
  13802. if (isset($attr['HEADER-STYLE-CENTER']) || isset($attr['FOOTER-STYLE-CENTER'])) {
  13803. if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE-CENTER']); }
  13804. else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE-CENTER']); }
  13805. if (isset($properties['FONT-FAMILY'])) { $p['C']['font-family'] = $properties['FONT-FAMILY']; }
  13806. if (isset($properties['FONT-SIZE'])) { $p['C']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK; }
  13807. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='bold') { $p['C']['font-style'] = 'B'; } // mPDF 5.3.86
  13808. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='italic') { $p['C']['font-style'] .= 'I'; } // mPDF 5.3.86
  13809. if (isset($properties['COLOR'])) { $p['C']['color'] = $properties['COLOR']; }
  13810. }
  13811. if (isset($attr['HEADER-STYLE-RIGHT']) || isset($attr['FOOTER-STYLE-RIGHT'])) {
  13812. if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE-RIGHT']); }
  13813. else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE-RIGHT']); }
  13814. if (isset($properties['FONT-FAMILY'])) { $p['R']['font-family'] = $properties['FONT-FAMILY']; }
  13815. if (isset($properties['FONT-SIZE'])) { $p['R']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK; }
  13816. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='bold') { $p['R']['font-style'] = 'B'; } // mPDF 5.3.86
  13817. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='italic') { $p['R']['font-style'] .= 'I'; } // mPDF 5.3.86
  13818. if (isset($properties['COLOR'])) { $p['R']['color'] = $properties['COLOR']; }
  13819. }
  13820. if (isset($attr['LINE']) && $attr['LINE']) { // 0|1|on|off
  13821. if ($attr['LINE']=='1' || strtoupper($attr['LINE'])=='ON') { $lineset=1; }
  13822. else { $lineset=0; }
  13823. $p['line'] = $lineset;
  13824. }
  13825. break;
  13826. /*-- HTMLHEADERS-FOOTERS --*/
  13827. case 'SETHTMLPAGEHEADER':
  13828. case 'SETHTMLPAGEFOOTER':
  13829. $this->ignorefollowingspaces = true;
  13830. if (isset($attr['NAME']) && $attr['NAME']) { $pname = $attr['NAME']; }
  13831. else { $pname = '_default'; }
  13832. if (isset($attr['PAGE']) && $attr['PAGE']) { // O|odd|even|E|ALL|[blank]
  13833. if (strtoupper($attr['PAGE'])=='O' || strtoupper($attr['PAGE'])=='ODD') { $side='odd'; }
  13834. else if (strtoupper($attr['PAGE'])=='E' || strtoupper($attr['PAGE'])=='EVEN') { $side='even'; }
  13835. else if (strtoupper($attr['PAGE'])=='ALL') { $side='both'; }
  13836. else { $side='odd'; }
  13837. }
  13838. else { $side='odd'; }
  13839. if (isset($attr['VALUE']) && $attr['VALUE']) { // -1|1|on|off
  13840. if ($attr['VALUE']=='1' || strtoupper($attr['VALUE'])=='ON') { $set=1; }
  13841. else if ($attr['VALUE']=='-1' || strtoupper($attr['VALUE'])=='OFF') { $set=0; }
  13842. else { $set=1; }
  13843. }
  13844. else { $set=1; }
  13845. if (isset($attr['SHOW-THIS-PAGE']) && $attr['SHOW-THIS-PAGE'] && $tag=='SETHTMLPAGEHEADER') { $write = 1; }
  13846. else { $write = 0; }
  13847. if ($side=='odd' || $side=='both') {
  13848. if ($set && $tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader($this->pageHTMLheaders[$pname],'O',$write); }
  13849. else if ($set && $tag=='SETHTMLPAGEFOOTER') { $this->SetHTMLFooter($this->pageHTMLfooters[$pname],'O'); }
  13850. else if ($tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader('','O'); }
  13851. else { $this->SetHTMLFooter('','O'); }
  13852. }
  13853. if ($side=='even' || $side=='both') {
  13854. if ($set && $tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader($this->pageHTMLheaders[$pname],'E',$write); }
  13855. else if ($set && $tag=='SETHTMLPAGEFOOTER') { $this->SetHTMLFooter($this->pageHTMLfooters[$pname],'E'); }
  13856. else if ($tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader('','E'); }
  13857. else { $this->SetHTMLFooter('','E'); }
  13858. }
  13859. break;
  13860. /*-- END HTMLHEADERS-FOOTERS --*/
  13861. case 'SETPAGEHEADER':
  13862. case 'SETPAGEFOOTER':
  13863. $this->ignorefollowingspaces = true;
  13864. if (isset($attr['NAME']) && $attr['NAME']) { $pname = $attr['NAME']; }
  13865. else { $pname = '_default'; }
  13866. if (isset($attr['PAGE']) && $attr['PAGE']) { // O|odd|even|E|ALL|[blank]
  13867. if (strtoupper($attr['PAGE'])=='O' || strtoupper($attr['PAGE'])=='ODD') { $side='odd'; }
  13868. else if (strtoupper($attr['PAGE'])=='E' || strtoupper($attr['PAGE'])=='EVEN') { $side='even'; }
  13869. else if (strtoupper($attr['PAGE'])=='ALL') { $side='both'; }
  13870. else { $side='odd'; }
  13871. }
  13872. else { $side='odd'; }
  13873. if (isset($attr['VALUE']) && $attr['VALUE']) { // -1|1|on|off
  13874. if ($attr['VALUE']=='1' || strtoupper($attr['VALUE'])=='ON') { $set=1; }
  13875. else if ($attr['VALUE']=='-1' || strtoupper($attr['VALUE'])=='OFF') { $set=0; }
  13876. else { $set=1; }
  13877. }
  13878. else { $set=1; }
  13879. if ($side=='odd' || $side=='both') {
  13880. if ($set && $tag=='SETPAGEHEADER') { $this->headerDetails['odd'] = $this->pageheaders[$pname]; }
  13881. else if ($set && $tag=='SETPAGEFOOTER') { $this->footerDetails['odd'] = $this->pagefooters[$pname]; }
  13882. else if ($tag=='SETPAGEHEADER') { $this->headerDetails['odd'] = array(); }
  13883. else { $this->footerDetails['odd'] = array(); }
  13884. if (!$this->mirrorMargins || ($this->page)%2!=0) { // ODD
  13885. if ($tag=='SETPAGEHEADER') { $this->_setAutoHeaderHeight($this->headerDetails['odd'],$this->HTMLHeader); }
  13886. if ($tag=='SETPAGEFOOTER') { $this->_setAutoFooterHeight($this->footerDetails['odd'],$this->HTMLFooter); }
  13887. }
  13888. }
  13889. if ($side=='even' || $side=='both') {
  13890. if ($set && $tag=='SETPAGEHEADER') { $this->headerDetails['even'] = $this->pageheaders[$pname]; }
  13891. else if ($set && $tag=='SETPAGEFOOTER') { $this->footerDetails['even'] = $this->pagefooters[$pname]; }
  13892. else if ($tag=='SETPAGEHEADER') { $this->headerDetails['even'] = array(); }
  13893. else { $this->footerDetails['even'] = array(); }
  13894. if ($this->mirrorMargins && ($this->page)%2==0) { // EVEN
  13895. if ($tag=='SETPAGEHEADER') { $this->_setAutoHeaderHeight($this->headerDetails['even'],$this->HTMLHeaderE); }
  13896. if ($tag=='SETPAGEFOOTER') { $this->_setAutoFooterHeight($this->footerDetails['even'],$this->HTMLFooterE); }
  13897. }
  13898. }
  13899. if (isset($attr['SHOW-THIS-PAGE']) && $attr['SHOW-THIS-PAGE'] && $tag=='SETPAGEHEADER') {
  13900. $this->Header();
  13901. }
  13902. break;
  13903. /*-- TOC --*/
  13904. case 'TOC': //added custom-tag - set Marker for insertion later of ToC
  13905. if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); }
  13906. if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); }
  13907. $this->tocontents->openTagTOC($attr);
  13908. break;
  13909. case 'TOCPAGEBREAK': // custom-tag - set Marker for insertion later of ToC AND adds PAGEBREAK
  13910. if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); }
  13911. if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); }
  13912. list($isbreak,$toc_id) = $this->tocontents->openTagTOCPAGEBREAK($attr);
  13913. if ($isbreak) break;
  13914. // No break - continues as PAGEBREAK...
  13915. /*-- END TOC --*/
  13916. case 'PAGE_BREAK': //custom-tag
  13917. case 'PAGEBREAK': //custom-tag
  13918. case 'NEWPAGE': //custom-tag
  13919. case 'FORMFEED': //custom-tag
  13920. $save_blklvl = $this->blklvl;
  13921. $save_blk = $this->blk;
  13922. $save_silp = $this->saveInlineProperties();
  13923. $save_spanlvl = $this->spanlvl;
  13924. $save_ilp = $this->InlineProperties;
  13925. // Close any open block tags
  13926. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  13927. if(!empty($this->textbuffer)) { //Output previously buffered content
  13928. $this->printbuffer($this->textbuffer);
  13929. $this->textbuffer=array();
  13930. }
  13931. $this->ignorefollowingspaces = true;
  13932. $save_cols = false;
  13933. /*-- COLUMNS --*/
  13934. if ($this->ColActive) {
  13935. $save_cols = true;
  13936. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  13937. $this->SetColumns(0);
  13938. }
  13939. /*-- END COLUMNS --*/
  13940. if (isset($attr['SHEET-SIZE']) && $tag != 'FORMFEED' && !$this->restoreBlockPageBreaks) {
  13941. // Convert to same types as accepted in initial mPDF() A4, A4-L, or array(w,h)
  13942. $prop = preg_split('/\s+/',trim($attr['SHEET-SIZE']));
  13943. if (count($prop) == 2 ) {
  13944. $newformat = array($this->ConvertSize($prop[0]), $this->ConvertSize($prop[1]));
  13945. }
  13946. else { $newformat = $attr['SHEET-SIZE']; }
  13947. }
  13948. else { $newformat = ''; }
  13949. $mgr = $mgl = $mgt = $mgb = $mgh = $mgf = '';
  13950. if (isset($attr['MARGIN-RIGHT'])) { $mgr = $this->ConvertSize($attr['MARGIN-RIGHT'],$this->w,$this->FontSize,false); }
  13951. if (isset($attr['MARGIN-LEFT'])) { $mgl = $this->ConvertSize($attr['MARGIN-LEFT'],$this->w,$this->FontSize,false); }
  13952. if (isset($attr['MARGIN-TOP'])) { $mgt = $this->ConvertSize($attr['MARGIN-TOP'],$this->w,$this->FontSize,false); }
  13953. if (isset($attr['MARGIN-BOTTOM'])) { $mgb = $this->ConvertSize($attr['MARGIN-BOTTOM'],$this->w,$this->FontSize,false); }
  13954. if (isset($attr['MARGIN-HEADER'])) { $mgh = $this->ConvertSize($attr['MARGIN-HEADER'],$this->w,$this->FontSize,false); }
  13955. if (isset($attr['MARGIN-FOOTER'])) { $mgf = $this->ConvertSize($attr['MARGIN-FOOTER'],$this->w,$this->FontSize,false); }
  13956. $ohname = $ehname = $ofname = $efname = '';
  13957. if (isset($attr['ODD-HEADER-NAME'])) { $ohname = $attr['ODD-HEADER-NAME']; }
  13958. if (isset($attr['EVEN-HEADER-NAME'])) { $ehname = $attr['EVEN-HEADER-NAME']; }
  13959. if (isset($attr['ODD-FOOTER-NAME'])) { $ofname = $attr['ODD-FOOTER-NAME']; }
  13960. if (isset($attr['EVEN-FOOTER-NAME'])) { $efname = $attr['EVEN-FOOTER-NAME']; }
  13961. $ohvalue = $ehvalue = $ofvalue = $efvalue = 0;
  13962. if (isset($attr['ODD-HEADER-VALUE']) && ($attr['ODD-HEADER-VALUE']=='1' || strtoupper($attr['ODD-HEADER-VALUE'])=='ON')) { $ohvalue = 1; }
  13963. else if (isset($attr['ODD-HEADER-VALUE']) && ($attr['ODD-HEADER-VALUE']=='-1' || strtoupper($attr['ODD-HEADER-VALUE'])=='OFF')) { $ohvalue = -1; }
  13964. if (isset($attr['EVEN-HEADER-VALUE']) && ($attr['EVEN-HEADER-VALUE']=='1' || strtoupper($attr['EVEN-HEADER-VALUE'])=='ON')) { $ehvalue = 1; }
  13965. else if (isset($attr['EVEN-HEADER-VALUE']) && ($attr['EVEN-HEADER-VALUE']=='-1' || strtoupper($attr['EVEN-HEADER-VALUE'])=='OFF')) { $ehvalue = -1; }
  13966. if (isset($attr['ODD-FOOTER-VALUE']) && ($attr['ODD-FOOTER-VALUE']=='1' || strtoupper($attr['ODD-FOOTER-VALUE'])=='ON')) { $ofvalue = 1; }
  13967. else if (isset($attr['ODD-FOOTER-VALUE']) && ($attr['ODD-FOOTER-VALUE']=='-1' || strtoupper($attr['ODD-FOOTER-VALUE'])=='OFF')) { $ofvalue = -1; }
  13968. if (isset($attr['EVEN-FOOTER-VALUE']) && ($attr['EVEN-FOOTER-VALUE']=='1' || strtoupper($attr['EVEN-FOOTER-VALUE'])=='ON')) { $efvalue = 1; }
  13969. else if (isset($attr['EVEN-FOOTER-VALUE']) && ($attr['EVEN-FOOTER-VALUE']=='-1' || strtoupper($attr['EVEN-FOOTER-VALUE'])=='OFF')) { $efvalue = -1; }
  13970. if (isset($attr['ORIENTATION']) && (strtoupper($attr['ORIENTATION'])=='L' || strtoupper($attr['ORIENTATION'])=='LANDSCAPE')) { $orient = 'L'; }
  13971. else if (isset($attr['ORIENTATION']) && (strtoupper($attr['ORIENTATION'])=='P' || strtoupper($attr['ORIENTATION'])=='PORTRAIT')) { $orient = 'P'; }
  13972. else { $orient = $this->CurOrientation; }
  13973. if (isset($attr['PAGE-SELECTOR']) && $attr['PAGE-SELECTOR']) { $pagesel = $attr['PAGE-SELECTOR']; }
  13974. else { $pagesel = ''; }
  13975. $resetpagenum = '';
  13976. $pagenumstyle = '';
  13977. $suppress = '';
  13978. if (isset($attr['RESETPAGENUM'])) { $resetpagenum = $attr['RESETPAGENUM']; }
  13979. if (isset($attr['PAGENUMSTYLE'])) { $pagenumstyle = $attr['PAGENUMSTYLE']; }
  13980. if (isset($attr['SUPPRESS'])) { $suppress = $attr['SUPPRESS']; }
  13981. if ($tag == 'TOCPAGEBREAK') { $type = 'NEXT-ODD'; }
  13982. else if(isset($attr['TYPE'])) { $type = strtoupper($attr['TYPE']); }
  13983. else { $type = ''; }
  13984. if ($type == 'E' || $type == 'EVEN') { $this->AddPage($orient,'E', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); }
  13985. else if ($type == 'O' || $type == 'ODD') { $this->AddPage($orient,'O', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); }
  13986. else if ($type == 'NEXT-ODD') { $this->AddPage($orient,'NEXT-ODD', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); }
  13987. else if ($type == 'NEXT-EVEN') { $this->AddPage($orient,'NEXT-EVEN', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); }
  13988. else { $this->AddPage($orient,'', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); }
  13989. /*-- TOC --*/
  13990. if ($tag == 'TOCPAGEBREAK') {
  13991. if ($toc_id) { $this->tocontents->m_TOC[$toc_id]['TOCmark'] = $this->page; }
  13992. else { $this->tocontents->TOCmark = $this->page; }
  13993. }
  13994. /*-- END TOC --*/
  13995. /*-- COLUMNS --*/
  13996. if ($save_cols) {
  13997. // Restore columns
  13998. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  13999. }
  14000. /*-- END COLUMNS --*/
  14001. if (($tag == 'FORMFEED' || $this->restoreBlockPagebreaks) && !$this->tableLevel && !$this->listlvl) {
  14002. $this->blk = $save_blk;
  14003. // Re-open block tags
  14004. $t = $this->blk[0]['tag'];
  14005. $a = $this->blk[0]['attr'];
  14006. $this->blklvl = 0;
  14007. for ($b=0; $b<=$save_blklvl;$b++) {
  14008. $tc = $t;
  14009. $ac = $a;
  14010. $t = $this->blk[$b+1]['tag'];
  14011. $a = $this->blk[$b+1]['attr'];
  14012. unset($this->blk[$b+1]);
  14013. $this->OpenTag($tc,$ac);
  14014. }
  14015. $this->spanlvl = $save_spanlvl;
  14016. $this->InlineProperties = $save_ilp;
  14017. $this->restoreInlineProperties($save_silp);
  14018. }
  14019. break;
  14020. /*-- TOC --*/
  14021. case 'TOCENTRY':
  14022. if (isset($attr['CONTENT']) && $attr['CONTENT']) {
  14023. $objattr = array();
  14024. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  14025. $objattr['type'] = 'toc';
  14026. if (isset($attr['LEVEL']) && $attr['LEVEL']) { $objattr['toclevel'] = $attr['LEVEL']; } else { $objattr['toclevel'] = 0; }
  14027. if (isset($attr['NAME']) && $attr['NAME']) { $objattr['toc_id'] = $attr['NAME']; } else { $objattr['toc_id'] = 0; }
  14028. $e = "\xbb\xa4\xactype=toc,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14029. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  14030. else { // *TABLES*
  14031. $this->textbuffer[] = array($e);
  14032. } // *TABLES*
  14033. }
  14034. break;
  14035. /*-- END TOC --*/
  14036. /*-- INDEX --*/
  14037. case 'INDEXENTRY':
  14038. if (isset($attr['CONTENT']) && $attr['CONTENT']) {
  14039. if (isset($attr['XREF']) && $attr['XREF']) {
  14040. $this->IndexEntry(htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES),$attr['XREF']);
  14041. break;
  14042. }
  14043. $objattr = array();
  14044. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  14045. $objattr['type'] = 'indexentry';
  14046. $e = "\xbb\xa4\xactype=indexentry,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14047. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  14048. else { // *TABLES*
  14049. $this->textbuffer[] = array($e);
  14050. } // *TABLES*
  14051. }
  14052. break;
  14053. case 'INDEXINSERT':
  14054. if (isset($attr['FONT-SIZE'])) { $reffontsize = $attr['FONT-SIZE']; } else { $reffontsize = ''; }
  14055. if (isset($attr['LINE-SPACING']) && $attr['LINE-SPACING']) { $linespacing = $attr['LINE-SPACING']; } else { $linespacing = ''; }
  14056. if (isset($attr['DIV-FONT-SIZE']) && $attr['DIV-FONT-SIZE']) { $divlettfontsize = $attr['DIV-FONT-SIZE']; } else { $divlettfontsize = ''; }
  14057. if (isset($attr['FONT']) && $attr['FONT']) { $reffont = $attr['FONT']; } else { $reffont = ''; }
  14058. if (isset($attr['DIV-FONT']) && $attr['DIV-FONT']) { $divlettfont = $attr['DIV-FONT']; } else { $divlettfont = ''; }
  14059. if (isset($attr['COLS']) && $attr['COLS']) { $cols = $attr['COLS']; } else { $cols = 1; }
  14060. if (isset($attr['OFFSET']) && $attr['OFFSET']) { $offset = $attr['OFFSET']; } else { $offset = 3; }
  14061. if (isset($attr['GAP']) && $attr['GAP']) { $gap = $attr['GAP']; } else { $gap = 5; }
  14062. if (isset($attr['USEDIVLETTERS']) && (strtoupper($attr['USEDIVLETTERS'])=='OFF' || $attr['USEDIVLETTERS']==-1 || $attr['USEDIVLETTERS']==='0')) { $usedivletters = 0; }
  14063. else { $usedivletters = 1; }
  14064. if (isset($attr['LINKS']) && (strtoupper($attr['LINKS'])=='ON' || $attr['LINKS']==1)) { $links = true; }
  14065. else { $links = false; }
  14066. $this->CreateIndex($cols, $reffontsize, $linespacing, $offset, $usedivletters, $divlettfontsize, $gap, $reffont,$divlettfont, $links);
  14067. break;
  14068. /*-- END INDEX --*/
  14069. /*-- WATERMARK --*/
  14070. case 'WATERMARKTEXT':
  14071. if (isset($attr['CONTENT']) && $attr['CONTENT']) { $txt = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES); } else { $txt = ''; }
  14072. if (isset($attr['ALPHA']) && $attr['ALPHA']>0) { $alpha = $attr['ALPHA']; } else { $alpha = -1; }
  14073. $this->SetWatermarkText($txt, $alpha);
  14074. break;
  14075. case 'WATERMARKIMAGE':
  14076. if (isset($attr['SRC'])) { $src = $attr['SRC']; } else { $src = ''; }
  14077. if (isset($attr['ALPHA']) && $attr['ALPHA']>0) { $alpha = $attr['ALPHA']; } else { $alpha = -1; }
  14078. if (isset($attr['SIZE']) && $attr['SIZE']) {
  14079. $size = $attr['SIZE'];
  14080. if (strpos($size,',')) { $size = explode(',',$size); }
  14081. }
  14082. else { $size = 'D'; }
  14083. if (isset($attr['POS']) && $attr['POS']) {
  14084. $pos = $attr['POS'];
  14085. if (strpos($pos,',')) { $pos = explode(',',$pos); }
  14086. }
  14087. else { $pos = 'P'; }
  14088. $this->SetWatermarkImage($src, $alpha, $size, $pos);
  14089. break;
  14090. /*-- END WATERMARK --*/
  14091. /*-- BOOKMARKS --*/
  14092. case 'BOOKMARK':
  14093. if (isset($attr['CONTENT'])) {
  14094. $objattr = array();
  14095. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  14096. $objattr['type'] = 'bookmark';
  14097. if (isset($attr['LEVEL']) && $attr['LEVEL']) { $objattr['bklevel'] = $attr['LEVEL']; } else { $objattr['bklevel'] = 0; }
  14098. $e = "\xbb\xa4\xactype=bookmark,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14099. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  14100. else { // *TABLES*
  14101. $this->textbuffer[] = array($e);
  14102. } // *TABLES*
  14103. }
  14104. break;
  14105. /*-- END BOOKMARKS --*/
  14106. /*-- ANNOTATIONS --*/
  14107. case 'ANNOTATION':
  14108. //if (isset($attr['CONTENT']) && !$this->writingHTMLheader && !$this->writingHTMLfooter) { // Stops annotations in FixedPos
  14109. if (isset($attr['CONTENT'])) {
  14110. $objattr = array();
  14111. $objattr['margin_top'] = 0;
  14112. $objattr['margin_bottom'] = 0;
  14113. $objattr['margin_left'] = 0;
  14114. $objattr['margin_right'] = 0;
  14115. $objattr['width'] = 0;
  14116. $objattr['height'] = 0;
  14117. $objattr['border_top']['w'] = 0;
  14118. $objattr['border_bottom']['w'] = 0;
  14119. $objattr['border_left']['w'] = 0;
  14120. $objattr['border_right']['w'] = 0;
  14121. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  14122. $objattr['type'] = 'annot';
  14123. $objattr['POPUP'] = '';
  14124. }
  14125. else { break; }
  14126. if (isset($attr['POS-X'])) { $objattr['POS-X'] = $attr['POS-X']; } else { $objattr['POS-X'] = 0; }
  14127. if (isset($attr['POS-Y'])) { $objattr['POS-Y'] = $attr['POS-Y']; } else { $objattr['POS-Y'] = 0; }
  14128. if (isset($attr['ICON'])) { $objattr['ICON'] = $attr['ICON']; } else { $objattr['ICON'] = 'Note'; }
  14129. if (isset($attr['AUTHOR'])) { $objattr['AUTHOR'] = $attr['AUTHOR']; }
  14130. else if (isset($attr['TITLE'])) { $objattr['AUTHOR'] = $attr['TITLE']; } else { $objattr['AUTHOR'] = ''; }
  14131. if (isset($attr['FILE'])) { $objattr['FILE'] = $attr['FILE']; } else { $objattr['FILE'] = ''; }
  14132. if (isset($attr['SUBJECT'])) { $objattr['SUBJECT'] = $attr['SUBJECT']; } else { $objattr['SUBJECT'] = ''; }
  14133. if (isset($attr['OPACITY']) && $attr['OPACITY']>0 && $attr['OPACITY']<=1) { $objattr['OPACITY'] = $attr['OPACITY']; }
  14134. else if ($this->annotMargin) { $objattr['OPACITY'] = 1; }
  14135. else { $objattr['OPACITY'] = $this->annotOpacity; }
  14136. if (isset($attr['COLOR'])) {
  14137. $cor = $this->ConvertColor($attr['COLOR']);
  14138. if ($cor) { $objattr['COLOR'] = $cor; }
  14139. else { $objattr['COLOR'] = $this->ConvertColor('yellow'); }
  14140. }
  14141. else { $objattr['COLOR'] = $this->ConvertColor('yellow'); }
  14142. if (isset($attr['POPUP']) && !empty($attr['POPUP'])) {
  14143. $pop = preg_split('/\s+/',trim($attr['POPUP']));
  14144. if (count($pop)>1) { $objattr['POPUP'] = $pop; }
  14145. else { $objattr['POPUP'] = true; }
  14146. }
  14147. $e = "\xbb\xa4\xactype=annot,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14148. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  14149. else { // *TABLES*
  14150. $this->textbuffer[] = array($e);
  14151. } // *TABLES*
  14152. break;
  14153. /*-- END ANNOTATIONS --*/
  14154. /*-- COLUMNS --*/
  14155. case 'COLUMNS': //added custom-tag
  14156. if (isset($attr['COLUMN-COUNT']) && ($attr['COLUMN-COUNT'] || $attr['COLUMN-COUNT']==='0')) {
  14157. // Close any open block tags
  14158. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  14159. if(!empty($this->textbuffer)) { //Output previously buffered content
  14160. $this->printbuffer($this->textbuffer);
  14161. $this->textbuffer=array();
  14162. }
  14163. if (isset($attr['VALIGN']) && $attr['VALIGN']) {
  14164. if ($attr['VALIGN'] == 'J') { $valign = 'J'; }
  14165. else { $valign = $align[$attr['VALIGN']]; }
  14166. }
  14167. else { $valign = ''; }
  14168. if (isset($attr['COLUMN-GAP']) && $attr['COLUMN-GAP']) { $this->SetColumns($attr['COLUMN-COUNT'],$valign,$attr['COLUMN-GAP']); }
  14169. else { $this->SetColumns($attr['COLUMN-COUNT'],$valign); }
  14170. }
  14171. $this->ignorefollowingspaces = true;
  14172. break;
  14173. case 'COLUMN_BREAK': //custom-tag
  14174. case 'COLUMNBREAK': //custom-tag
  14175. case 'NEWCOLUMN': //custom-tag
  14176. $this->ignorefollowingspaces = true;
  14177. $this->NewColumn();
  14178. $this->ColumnAdjust = false; // disables all column height adjustment for the page.
  14179. break;
  14180. /*-- END COLUMNS --*/
  14181. case 'BDO':
  14182. // $this->biDirectional = true;
  14183. break;
  14184. case 'TTZ':
  14185. $this->ttz = true;
  14186. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  14187. $this->setCSS(array('FONT-FAMILY'=>'czapfdingbats','FONT-WEIGHT'=>'normal','FONT-STYLE'=>'normal'),'INLINE');
  14188. break;
  14189. case 'TTS':
  14190. $this->tts = true;
  14191. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  14192. $this->setCSS(array('FONT-FAMILY'=>'csymbol','FONT-WEIGHT'=>'normal','FONT-STYLE'=>'normal'),'INLINE');
  14193. break;
  14194. case 'TTA':
  14195. $this->tta = true;
  14196. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  14197. if (in_array($this->FontFamily,$this->mono_fonts)) {
  14198. $this->setCSS(array('FONT-FAMILY'=>'ccourier'),'INLINE');
  14199. }
  14200. else if (in_array($this->FontFamily,$this->serif_fonts)) {
  14201. $this->setCSS(array('FONT-FAMILY'=>'ctimes'),'INLINE');
  14202. }
  14203. else {
  14204. $this->setCSS(array('FONT-FAMILY'=>'chelvetica'),'INLINE');
  14205. }
  14206. break;
  14207. // INLINE PHRASES OR STYLES
  14208. case 'SUB':
  14209. case 'SUP':
  14210. case 'ACRONYM':
  14211. case 'BIG':
  14212. case 'SMALL':
  14213. case 'INS':
  14214. case 'S':
  14215. case 'STRIKE':
  14216. case 'DEL':
  14217. case 'STRONG':
  14218. case 'CITE':
  14219. case 'Q':
  14220. case 'EM':
  14221. case 'B':
  14222. case 'I':
  14223. case 'U':
  14224. case 'SAMP':
  14225. case 'CODE':
  14226. case 'KBD':
  14227. case 'TT':
  14228. case 'VAR':
  14229. case 'FONT':
  14230. case 'SPAN':
  14231. /*-- ANNOTATIONS --*/
  14232. if ($this->title2annots && isset($attr['TITLE'])) {
  14233. $objattr = array();
  14234. $objattr['margin_top'] = 0;
  14235. $objattr['margin_bottom'] = 0;
  14236. $objattr['margin_left'] = 0;
  14237. $objattr['margin_right'] = 0;
  14238. $objattr['width'] = 0;
  14239. $objattr['height'] = 0;
  14240. $objattr['border_top']['w'] = 0;
  14241. $objattr['border_bottom']['w'] = 0;
  14242. $objattr['border_left']['w'] = 0;
  14243. $objattr['border_right']['w'] = 0;
  14244. $objattr['CONTENT'] = $attr['TITLE'];
  14245. $objattr['type'] = 'annot';
  14246. $objattr['POS-X'] = 0;
  14247. $objattr['POS-Y'] = 0;
  14248. $objattr['ICON'] = 'Comment';
  14249. $objattr['AUTHOR'] = '';
  14250. $objattr['SUBJECT'] = '';
  14251. $objattr['OPACITY'] = $this->annotOpacity;
  14252. $objattr['COLOR'] = $this->ConvertColor('yellow');
  14253. $annot = "\xbb\xa4\xactype=annot,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14254. }
  14255. /*-- END ANNOTATIONS --*/
  14256. if ($tag == 'SPAN') {
  14257. $this->spanlvl++;
  14258. $this->InlineProperties['SPAN'][$this->spanlvl] = $this->saveInlineProperties();
  14259. if (isset($annot)) { $this->InlineAnnots[$tag][$this->spanlvl] = $annot; } // *ANNOTATIONS*
  14260. }
  14261. else {
  14262. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  14263. if (isset($annot)) { $this->InlineAnnots[$tag] = $annot; } // *ANNOTATIONS*
  14264. }
  14265. $properties = $this->MergeCSS('INLINE',$tag,$attr);
  14266. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  14267. break;
  14268. case 'A':
  14269. if (isset($attr['NAME']) and $attr['NAME'] != '') {
  14270. $e = '';
  14271. /*-- BOOKMARKS --*/
  14272. if ($this->anchor2Bookmark) {
  14273. $objattr = array();
  14274. $objattr['CONTENT'] = htmlspecialchars_decode($attr['NAME'],ENT_QUOTES);
  14275. $objattr['type'] = 'bookmark';
  14276. if (isset($attr['LEVEL']) && $attr['LEVEL']) { $objattr['bklevel'] = $attr['LEVEL']; } else { $objattr['bklevel'] = 0; }
  14277. $e = "\xbb\xa4\xactype=bookmark,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14278. }
  14279. /*-- END BOOKMARKS --*/
  14280. if($this->tableLevel) { // *TABLES*
  14281. $this->_saveCellTextBuffer($e, '', $attr['NAME']); // mPDF 5.3.99 // *TABLES*
  14282. } // *TABLES*
  14283. else { // *TABLES*
  14284. $this->_saveTextBuffer($e, '', $attr['NAME']); // mPDF 5.3.99 //an internal link (adds a space for recognition)
  14285. } // *TABLES*
  14286. }
  14287. if (isset($attr['HREF'])) {
  14288. $this->InlineProperties['A'] = $this->saveInlineProperties();
  14289. $properties = $this->MergeCSS('',$tag,$attr);
  14290. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  14291. $this->HREF=htmlspecialchars_decode(urldecode($attr['HREF'])); // mPDF 5.3.95
  14292. }
  14293. break;
  14294. case 'BR':
  14295. // Added mPDF 3.0 Float DIV - CLEAR
  14296. if (isset($attr['STYLE'])) {
  14297. $properties = $this->readInlineCSS($attr['STYLE']);
  14298. if (isset($properties['CLEAR'])) { $this->ClearFloats(strtoupper($properties['CLEAR']),$this->blklvl); } // *CSS-FLOAT*
  14299. }
  14300. /*-- TABLES --*/
  14301. if($this->tableLevel) {
  14302. if ($this->blockjustfinished || $this->listjustfinished) {
  14303. $this->_saveCellTextBuffer("\n"); // mPDF 5.3.99
  14304. }
  14305. $this->_saveCellTextBuffer("\n"); // mPDF 5.3.99
  14306. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  14307. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14308. }
  14309. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  14310. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14311. }
  14312. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  14313. }
  14314. else {
  14315. /*-- END TABLES --*/
  14316. if (count($this->textbuffer)) {
  14317. $this->textbuffer[count($this->textbuffer)-1][0] = preg_replace('/ $/','',$this->textbuffer[count($this->textbuffer)-1][0]);
  14318. }
  14319. $this->_saveTextBuffer("\n"); // mPDF 5.3.99
  14320. } // *TABLES*
  14321. $this->ignorefollowingspaces = true;
  14322. $this->blockjustfinished=false;
  14323. $this->listjustfinished=false;
  14324. $this->linebreakjustfinished=true;
  14325. break;
  14326. // *********** BLOCKS ********************
  14327. //NB $outerblocktags = array('DIV','FORM','CENTER','DL');
  14328. //NB $innerblocktags = array('P','BLOCKQUOTE','ADDRESS','PRE',''H1','H2','H3','H4','H5','H6','DT','DD');
  14329. case 'PRE':
  14330. $this->ispre=true; // ADDED - Prevents left trim of textbuffer in printbuffer()
  14331. case 'DIV':
  14332. case 'FORM':
  14333. case 'CENTER':
  14334. case 'BLOCKQUOTE':
  14335. case 'ADDRESS':
  14336. case 'CAPTION': // mPDF 5.3.56
  14337. case 'P':
  14338. case 'H1':
  14339. case 'H2':
  14340. case 'H3':
  14341. case 'H4':
  14342. case 'H5':
  14343. case 'H6':
  14344. case 'DL':
  14345. case 'DT':
  14346. case 'DD':
  14347. $p = $this->PreviewBlockCSS($tag,$attr);
  14348. if(isset($p['DISPLAY']) && strtolower($p['DISPLAY'])=='none') {
  14349. $this->blklvl++;
  14350. $this->blk[$this->blklvl]['hide'] = true;
  14351. return;
  14352. }
  14353. // mPDF 5.3.56
  14354. if($tag == 'CAPTION') {
  14355. // position is written in AdjstHTML
  14356. if (isset($attr['POSITION']) && strtolower($attr['POSITION'])=='bottom') { $divpos = 'B'; }
  14357. else { $divpos = 'T'; }
  14358. if (isset($attr['ALIGN']) && strtolower($attr['ALIGN'])=='bottom') { $cappos = 'B'; }
  14359. else if (isset($p['CAPTION-SIDE']) && strtolower($p['CAPTION-SIDE'])=='bottom') { $cappos = 'B'; }
  14360. else { $cappos = 'T'; }
  14361. if (isset($attr['ALIGN'])) { unset($attr['ALIGN']); } // mPDF 5.3.A8
  14362. if ($cappos != $divpos) {
  14363. $this->blklvl++;
  14364. $this->blk[$this->blklvl]['hide'] = true;
  14365. return;
  14366. }
  14367. }
  14368. /*-- FORMS --*/
  14369. if($tag == 'FORM') {
  14370. if (isset($attr['METHOD']) && strtolower($attr['METHOD'])=='get') { $this->form->formMethod = 'GET'; }
  14371. else { $this->form->formMethod = 'POST'; }
  14372. if (isset($attr['ACTION'])) { $this->form->formAction = $attr['ACTION']; }
  14373. else { $this->form->formAction = ''; }
  14374. }
  14375. /*-- END FORMS --*/
  14376. /*-- CSS-POSITION --*/
  14377. if ((isset($p['POSITION']) && (strtolower($p['POSITION'])=='fixed' || strtolower($p['POSITION'])=='absolute')) && $this->blklvl==0) {
  14378. if ($this->inFixedPosBlock) {
  14379. $this->Error("Cannot nest block with position:fixed or position:absolute");
  14380. }
  14381. $this->inFixedPosBlock = true;
  14382. return;
  14383. }
  14384. /*-- END CSS-POSITION --*/
  14385. // Start Block
  14386. $this->ignorefollowingspaces = true;
  14387. if ($this->blockjustfinished && !count($this->textbuffer) && $this->y != $this->tMargin && $this->collapseBlockMargins) { $lastbottommargin = $this->lastblockbottommargin; }
  14388. else { $lastbottommargin = 0; }
  14389. $this->lastblockbottommargin = 0;
  14390. $this->blockjustfinished=false;
  14391. /*-- LISTS --*/
  14392. if ($this->listlvl>0) { return; }
  14393. /*-- END LISTS --*/
  14394. $this->InlineProperties = array();
  14395. $this->spanlvl = 0;
  14396. $this->listjustfinished=false;
  14397. $this->divbegin=true;
  14398. $this->linebreakjustfinished=false;
  14399. /*-- TABLES --*/
  14400. if ($this->tableLevel) {
  14401. // If already something on the line
  14402. if ($this->cell[$this->row][$this->col]['s'] > 0 && !$this->nestedtablejustfinished ) {
  14403. $this->_saveCellTextBuffer("\n"); // mPDF 5.3.99
  14404. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  14405. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14406. }
  14407. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  14408. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14409. }
  14410. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  14411. }
  14412. // Cannot set block properties inside table - use Bold to indicate h1-h6
  14413. if ($tag == 'CENTER' && $this->tdbegin) { $this->cell[$this->row][$this->col]['a'] = $align['center']; }
  14414. $this->InlineProperties['BLOCKINTABLE'] = $this->saveInlineProperties();
  14415. $properties = $this->MergeCSS('',$tag,$attr);
  14416. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  14417. break;
  14418. }
  14419. /*-- END TABLES --*/
  14420. if ($tag == 'P' || $tag == 'DT' || $tag == 'DD') { $this->lastoptionaltag = $tag; } // Save current HTML specified optional endtag
  14421. else { $this->lastoptionaltag = ''; }
  14422. if ($this->lastblocklevelchange == 1) { $blockstate = 1; } // Top margins/padding only
  14423. else if ($this->lastblocklevelchange < 1) { $blockstate = 0; } // NO margins/padding
  14424. $this->printbuffer($this->textbuffer,$blockstate);
  14425. $this->textbuffer=array();
  14426. // mPDF 5.3.03
  14427. $save_blklvl = $this->blklvl;
  14428. $save_blk = $this->blk;
  14429. $save_silp = $this->saveInlineProperties();
  14430. $save_spanlvl = $this->spanlvl;
  14431. $save_ilp = $this->InlineProperties;
  14432. $this->blklvl++;
  14433. $currblk =& $this->blk[$this->blklvl];
  14434. $this->initialiseBlock($currblk);
  14435. $prevblk =& $this->blk[$this->blklvl-1];
  14436. $currblk['tag'] = $tag;
  14437. $currblk['attr'] = $attr;
  14438. $this->Reset();
  14439. $properties = $this->MergeCSS('BLOCK',$tag,$attr);
  14440. $pagesel = '';
  14441. /*-- CSS-PAGE --*/
  14442. if (isset($properties['PAGE'])) { $pagesel = $properties['PAGE']; }
  14443. /*-- END CSS-PAGE --*/
  14444. // If page-box has changed AND/OR PAGE-BREAK-BEFORE
  14445. $save_cols = false;
  14446. if (($pagesel && $pagesel != $this->page_box['current']) || (isset($properties['PAGE-BREAK-BEFORE']) && $properties['PAGE-BREAK-BEFORE'])) {
  14447. if ($this->blklvl>1) {
  14448. // Close any open block tags
  14449. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  14450. // Output any text left in buffer
  14451. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); $this->textbuffer=array(); }
  14452. }
  14453. /*-- COLUMNS --*/
  14454. if ($this->ColActive) {
  14455. $save_cols = true;
  14456. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  14457. $this->SetColumns(0);
  14458. }
  14459. /*-- END COLUMNS --*/
  14460. // Must Add new page if changed page properties
  14461. if (isset($properties['PAGE-BREAK-BEFORE'])) {
  14462. if (strtoupper($properties['PAGE-BREAK-BEFORE']) == 'RIGHT') { $this->AddPage($this->CurOrientation,'NEXT-ODD','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  14463. else if (strtoupper($properties['PAGE-BREAK-BEFORE']) == 'LEFT') { $this->AddPage($this->CurOrientation,'NEXT-EVEN','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  14464. else if (strtoupper($properties['PAGE-BREAK-BEFORE']) == 'ALWAYS') { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  14465. else if ($this->page_box['current'] != $pagesel) { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); } // *CSS-PAGE*
  14466. }
  14467. /*-- CSS-PAGE --*/
  14468. else if ($pagesel != $this->page_box['current']) { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  14469. /*-- END CSS-PAGE --*/
  14470. // if using htmlheaders, the headers need to be rewritten when new page
  14471. // done by calling WriteHTML() within resethtmlheaders
  14472. // so block is reset to 0 - now we need to resurrect it
  14473. // As in WriteHTML() initialising
  14474. // mPDF 5.3.03
  14475. if (!($this->restoreBlockPagebreaks && isset($properties['PAGE-BREAK-BEFORE']) && $properties['PAGE-BREAK-BEFORE'])) {
  14476. $this->blklvl = 0;
  14477. $this->lastblocklevelchange = 0;
  14478. $this->blk = array();
  14479. $this->initialiseBlock($this->blk[0]);
  14480. $this->blk[0]['width'] =& $this->pgwidth;
  14481. $this->blk[0]['inner_width'] =& $this->pgwidth;
  14482. $this->blk[0]['blockContext'] = $this->blockContext;
  14483. $properties = $this->MergeCSS('BLOCK','BODY','');
  14484. $this->setCSS($properties,'','BODY');
  14485. $this->blklvl++;
  14486. $currblk =& $this->blk[$this->blklvl];
  14487. $prevblk =& $this->blk[$this->blklvl-1];
  14488. $this->initialiseBlock($currblk);
  14489. $currblk['tag'] = $tag;
  14490. $currblk['attr'] = $attr;
  14491. $this->Reset();
  14492. $properties = $this->MergeCSS('BLOCK',$tag,$attr);
  14493. }
  14494. /*-- COLUMNS --*/
  14495. if ($save_cols) {
  14496. // Restore columns
  14497. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  14498. }
  14499. /*-- END COLUMNS --*/
  14500. // mPDF 5.3.03
  14501. if ($this->restoreBlockPagebreaks && isset($properties['PAGE-BREAK-BEFORE']) && $properties['PAGE-BREAK-BEFORE']) {
  14502. $this->blk = $save_blk;
  14503. // Re-open block tags
  14504. $t = $this->blk[0]['tag'];
  14505. $a = $this->blk[0]['attr'];
  14506. $this->blklvl = 0;
  14507. for ($b=0; $b<=$save_blklvl;$b++) {
  14508. $tc = $t;
  14509. $ac = $a;
  14510. $t = $this->blk[$b+1]['tag'];
  14511. $a = $this->blk[$b+1]['attr'];
  14512. unset($this->blk[$b+1]);
  14513. $this->OpenTag($tc,$ac);
  14514. }
  14515. $this->spanlvl = $save_spanlvl;
  14516. $this->InlineProperties = $save_ilp;
  14517. $this->restoreInlineProperties($save_silp);
  14518. }
  14519. }
  14520. if (isset($properties['PAGE-BREAK-INSIDE']) && strtoupper($properties['PAGE-BREAK-INSIDE']) == 'AVOID' && !$this->ColActive && !$this->keep_block_together) {
  14521. $currblk['keep_block_together'] = 1;
  14522. $this->kt_y00 = $this->y;
  14523. $this->kt_p00 = $this->page;
  14524. $this->keep_block_together = 1;
  14525. $this->divbuffer = array();
  14526. $this->ktLinks = array();
  14527. $this->ktAnnots = array();
  14528. $this->ktForms = array();
  14529. $this->ktBlock = array();
  14530. $this->ktReference = array();
  14531. $this->ktBMoutlines = array();
  14532. $this->_kttoc = array();
  14533. }
  14534. // mPDF 5.3.76
  14535. if ($lastbottommargin && isset($properties['MARGIN-TOP']) && $properties['MARGIN-TOP'] && empty($properties['FLOAT'])) { $currblk['lastbottommargin'] = $lastbottommargin; }
  14536. $this->setCSS($properties,'BLOCK',$tag); //name(id/class/style) found in the CSS array!
  14537. $currblk['InlineProperties'] = $this->saveInlineProperties();
  14538. // mPDF 5.3.42 VISIBILITY
  14539. if (isset($properties['VISIBILITY'])) {
  14540. $v = strtolower($properties['VISIBILITY']);
  14541. if (($v == 'hidden' || $v == 'printonly' || $v == 'screenonly') && $this->visibility=='visible' && !$this->tableLevel) {
  14542. $currblk['visibility'] = $v;
  14543. $this->SetVisibility($v);
  14544. }
  14545. }
  14546. if(isset($attr['DIR']) && $attr['DIR']) { $currblk['direction'] = strtolower($attr['DIR']); }
  14547. if(isset($attr['ALIGN']) && $attr['ALIGN']) { $currblk['block-align'] = $align[strtolower($attr['ALIGN'])]; }
  14548. if (isset($properties['HEIGHT'])) {
  14549. $currblk['css_set_height'] = $this->ConvertSize($properties['HEIGHT'],($this->h - $this->tMargin - $this->bMargin),$this->FontSize,false);
  14550. if (($currblk['css_set_height'] + $this->y) > $this->PageBreakTrigger && $this->y > $this->tMargin+5 && $currblk['css_set_height'] < ($this->h - ($this->tMargin + $this->bMargin))) { $this->AddPage($this->CurOrientation); }
  14551. }
  14552. else { $currblk['css_set_height'] = false; }
  14553. // Added mPDF 3.0 Float DIV
  14554. if (isset($prevblk['blockContext'])) { $currblk['blockContext'] = $prevblk['blockContext'] ; } // *CSS-FLOAT*
  14555. if (isset($properties['CLEAR'])) { $this->ClearFloats(strtoupper($properties['CLEAR']), $this->blklvl-1); } // *CSS-FLOAT*
  14556. $container_w = $prevblk['inner_width'];
  14557. $bdr = $currblk['border_right']['w'];
  14558. $bdl = $currblk['border_left']['w'];
  14559. $pdr = $currblk['padding_right'];
  14560. $pdl = $currblk['padding_left'];
  14561. if (isset($currblk['css_set_width'])) { $setwidth = $currblk['css_set_width']; }
  14562. else { $setwidth = 0; }
  14563. /*-- CSS-FLOAT --*/
  14564. if (isset($properties['FLOAT']) && strtoupper($properties['FLOAT']) == 'RIGHT' && !$this->ColActive) {
  14565. // Cancel Keep-Block-together
  14566. $currblk['keep_block_together'] = false;
  14567. $this->kt_y00 = '';
  14568. $this->keep_block_together = 0;
  14569. $this->blockContext++;
  14570. $currblk['blockContext'] = $this->blockContext;
  14571. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14572. // DIV is too narrow for text to fit!
  14573. $maxw = $container_w - $l_width - $r_width;
  14574. if (($setwidth + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) > $maxw || ($maxw - ($currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr)) < (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04
  14575. // Too narrow to fit - try to move down past L or R float
  14576. if ($l_max < $r_max && ($setwidth + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) <= ($container_w - $r_width) && (($container_w - $r_width) - ($currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr)) > (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04
  14577. $this->ClearFloats('LEFT', $this->blklvl-1);
  14578. }
  14579. else if ($r_max < $l_max && ($setwidth + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) <= ($container_w - $l_width) && (($container_w - $l_width) - ($currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr)) > (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04
  14580. $this->ClearFloats('RIGHT', $this->blklvl-1);
  14581. }
  14582. else { $this->ClearFloats('BOTH', $this->blklvl-1); }
  14583. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14584. }
  14585. if ($r_exists) { $currblk['margin_right'] += $r_width; }
  14586. $currblk['float'] = 'R';
  14587. $currblk['float_start_y'] = $this->y;
  14588. if ($currblk['css_set_width']) {
  14589. $currblk['margin_left'] = $container_w - ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_right']);
  14590. $currblk['float_width'] = ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_right']);
  14591. }
  14592. else {
  14593. // *** If no width set - would need to buffer and keep track of max width, then Right-align if not full width
  14594. // and do borders and backgrounds - For now - just set to maximum width left
  14595. if ($l_exists) { $currblk['margin_left'] += $l_width; }
  14596. $currblk['css_set_width'] = $container_w - ($currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr);
  14597. $currblk['float_width'] = ($currblk['css_set_width'] + $bdl + $pdl + $bdr + $pdr + $currblk['margin_right']);
  14598. }
  14599. }
  14600. else if (isset($properties['FLOAT']) && strtoupper($properties['FLOAT']) == 'LEFT' && !$this->ColActive) {
  14601. // Cancel Keep-Block-together
  14602. $currblk['keep_block_together'] = false;
  14603. $this->kt_y00 = '';
  14604. $this->keep_block_together = 0;
  14605. $this->blockContext++;
  14606. $currblk['blockContext'] = $this->blockContext;
  14607. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14608. // DIV is too narrow for text to fit!
  14609. $maxw = $container_w - $l_width - $r_width;
  14610. if (($setwidth + $currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr) > $maxw || ($maxw - ($currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr)) < (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04
  14611. // Too narrow to fit - try to move down past L or R float
  14612. if ($l_max < $r_max && ($setwidth + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) <= ($container_w - $r_width) && (($container_w - $r_width) - ($currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr)) > (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04
  14613. $this->ClearFloats('LEFT', $this->blklvl-1);
  14614. }
  14615. else if ($r_max < $l_max && ($setwidth + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) <= ($container_w - $l_width) && (($container_w - $l_width) - ($currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr)) > (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04
  14616. $this->ClearFloats('RIGHT', $this->blklvl-1);
  14617. }
  14618. else { $this->ClearFloats('BOTH', $this->blklvl-1); }
  14619. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14620. }
  14621. if ($l_exists) { $currblk['margin_left'] += $l_width; }
  14622. $currblk['float'] = 'L';
  14623. $currblk['float_start_y'] = $this->y;
  14624. if ($setwidth) {
  14625. $currblk['margin_right'] = $container_w - ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_left']);
  14626. $currblk['float_width'] = ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_left']);
  14627. }
  14628. else {
  14629. // *** If no width set - would need to buffer and keep track of max width, then Right-align if not full width
  14630. // and do borders and backgrounds - For now - just set to maximum width left
  14631. if ($r_exists) { $currblk['margin_right'] += $r_width; }
  14632. $currblk['css_set_width'] = $container_w - ($currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr);
  14633. $currblk['float_width'] = ($currblk['css_set_width'] + $bdl + $pdl + $bdr + $pdr + $currblk['margin_left']);
  14634. }
  14635. }
  14636. else {
  14637. // Don't allow overlap - if floats present - adjust padding to avoid overlap with Floats
  14638. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14639. $maxw = $container_w - $l_width - $r_width;
  14640. if (($setwidth + $currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) > $maxw || ($maxw - ($currblk['margin_right'] + $currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr)) < (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04
  14641. // Too narrow to fit - try to move down past L or R float
  14642. if ($l_max < $r_max && ($setwidth + $currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) <= ($container_w - $r_width) && (($container_w - $r_width) - ($currblk['margin_right'] + $currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr)) > (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04
  14643. $this->ClearFloats('LEFT', $this->blklvl-1);
  14644. }
  14645. else if ($r_max < $l_max && ($setwidth + $currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) <= ($container_w - $l_width) && (($container_w - $l_width) - ($currblk['margin_right'] + $currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr)) > (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04
  14646. $this->ClearFloats('RIGHT', $this->blklvl-1);
  14647. }
  14648. else { $this->ClearFloats('BOTH', $this->blklvl-1); }
  14649. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14650. }
  14651. if ($r_exists) { $currblk['padding_right'] = max(($r_width-$currblk['margin_right']-$bdr), $pdr); }
  14652. if ($l_exists) { $currblk['padding_left'] = max(($l_width-$currblk['margin_left']-$bdl), $pdl); }
  14653. }
  14654. /*-- END CSS-FLOAT --*/
  14655. /*-- BORDER-RADIUS --*/
  14656. // Automatically increase padding if required for border-radius
  14657. if ($this->autoPadding && !$this->ColActive && !$this->keep_block_together) {
  14658. if ($currblk['border_radius_TL_H']>$currblk['padding_left'] && $currblk['border_radius_TL_V']>$currblk['padding_top']) {
  14659. if ($currblk['border_radius_TL_H']>$currblk['border_radius_TL_V']) {
  14660. $this->_borderPadding($currblk['border_radius_TL_H'],$currblk['border_radius_TL_V'], $currblk['padding_left'], $currblk['padding_top']);
  14661. }
  14662. else {
  14663. $this->_borderPadding($currblk['border_radius_TL_V'],$currblk['border_radius_TL_H'], $currblk['padding_top'], $currblk['padding_left']);
  14664. }
  14665. }
  14666. if ($currblk['border_radius_TR_H']>$currblk['padding_right'] && $currblk['border_radius_TR_V']>$currblk['padding_top']) {
  14667. if ($currblk['border_radius_TR_H']>$currblk['border_radius_TR_V']) {
  14668. $this->_borderPadding($currblk['border_radius_TR_H'],$currblk['border_radius_TR_V'], $currblk['padding_right'], $currblk['padding_top']);
  14669. }
  14670. else {
  14671. $this->_borderPadding($currblk['border_radius_TR_V'],$currblk['border_radius_TR_H'], $currblk['padding_top'], $currblk['padding_right']);
  14672. }
  14673. }
  14674. if ($currblk['border_radius_BL_H']>$currblk['padding_left'] && $currblk['border_radius_BL_V']>$currblk['padding_bottom']) {
  14675. if ($currblk['border_radius_BL_H']>$currblk['border_radius_BL_V']) {
  14676. $this->_borderPadding($currblk['border_radius_BL_H'],$currblk['border_radius_BL_V'], $currblk['padding_left'], $currblk['padding_bottom']);
  14677. }
  14678. else {
  14679. $this->_borderPadding($currblk['border_radius_BL_V'],$currblk['border_radius_BL_H'], $currblk['padding_bottom'], $currblk['padding_left']);
  14680. }
  14681. }
  14682. if ($currblk['border_radius_BR_H']>$currblk['padding_right'] && $currblk['border_radius_BR_V']>$currblk['padding_bottom']) {
  14683. if ($currblk['border_radius_BR_H']>$currblk['border_radius_BR_V']) {
  14684. $this->_borderPadding($currblk['border_radius_BR_H'],$currblk['border_radius_BR_V'], $currblk['padding_right'], $currblk['padding_bottom']);
  14685. }
  14686. else {
  14687. $this->_borderPadding($currblk['border_radius_BR_V'],$currblk['border_radius_BR_H'], $currblk['padding_bottom'], $currblk['padding_right']);
  14688. }
  14689. }
  14690. }
  14691. /*-- END BORDER-RADIUS --*/
  14692. // Hanging indent - if negative indent: ensure padding is >= indent
  14693. if(!isset($currblk['text_indent'])) { $currblk['text_indent'] = null; }
  14694. if(!isset($currblk['inner_width'])) { $currblk['inner_width'] = null; }
  14695. $cbti = $this->ConvertSize($currblk['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  14696. if ($cbti < 0) {
  14697. $hangind = -($cbti);
  14698. if ($currblk['direction'] == 'rtl') { // *RTL*
  14699. $currblk['padding_right'] = max($currblk['padding_right'],$hangind); // *RTL*
  14700. } // *RTL*
  14701. else { // *RTL*
  14702. $currblk['padding_left'] = max($currblk['padding_left'],$hangind);
  14703. } // *RTL*
  14704. }
  14705. if (isset($currblk['css_set_width'])) {
  14706. if (isset($properties['MARGIN-LEFT']) && isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-LEFT'])=='auto' && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  14707. // Try to reduce margins to accomodate - if still too wide, set margin-right/left=0 (reduces width)
  14708. $anyextra = $prevblk['inner_width'] - ($currblk['css_set_width'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right']);
  14709. if ($anyextra>0) {
  14710. $currblk['margin_left'] = $currblk['margin_right'] = $anyextra /2;
  14711. }
  14712. else {
  14713. $currblk['margin_left'] = $currblk['margin_right'] = 0;
  14714. }
  14715. }
  14716. else if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  14717. // Try to reduce margin-left to accomodate - if still too wide, set margin-left=0 (reduces width)
  14718. $currblk['margin_left'] = $prevblk['inner_width'] - ($currblk['css_set_width'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right'] + $currblk['margin_right']);
  14719. if ($currblk['margin_left'] < 0) {
  14720. $currblk['margin_left'] = 0;
  14721. }
  14722. }
  14723. else if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  14724. // Try to reduce margin-right to accomodate - if still too wide, set margin-right=0 (reduces width)
  14725. $currblk['margin_right'] = $prevblk['inner_width'] - ($currblk['css_set_width'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right'] + $currblk['margin_left']);
  14726. if ($currblk['margin_right'] < 0) {
  14727. $currblk['margin_right'] = 0;
  14728. }
  14729. }
  14730. else {
  14731. if ($currblk['direction'] == 'rtl') { // *RTL*
  14732. // Try to reduce margin-left to accomodate - if still too wide, set margin-left=0 (reduces width)
  14733. $currblk['margin_left'] = $prevblk['inner_width'] - ($currblk['css_set_width'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right'] + $currblk['margin_right']); // *RTL*
  14734. if ($currblk['margin_left'] < 0) { // *RTL*
  14735. $currblk['margin_left'] = 0; // *RTL*
  14736. } // *RTL*
  14737. } // *RTL*
  14738. else { // *RTL*
  14739. // Try to reduce margin-right to accomodate - if still too wide, set margin-right=0 (reduces width)
  14740. $currblk['margin_right'] = $prevblk['inner_width'] - ($currblk['css_set_width'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right'] + $currblk['margin_left']);
  14741. if ($currblk['margin_right'] < 0) {
  14742. $currblk['margin_right'] = 0;
  14743. }
  14744. } // *RTL*
  14745. }
  14746. }
  14747. $currblk['outer_left_margin'] = $prevblk['outer_left_margin'] + $currblk['margin_left'] + $prevblk['border_left']['w'] + $prevblk['padding_left'];
  14748. $currblk['outer_right_margin'] = $prevblk['outer_right_margin'] + $currblk['margin_right'] + $prevblk['border_right']['w'] + $prevblk['padding_right'];
  14749. $currblk['width'] = $this->pgwidth - ($currblk['outer_right_margin'] + $currblk['outer_left_margin']);
  14750. $currblk['inner_width'] = $currblk['width'] - ($currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right']);
  14751. // Check DIV is not now too narrow to fit text
  14752. $mw = 2*$this->GetCharWidth('W',false); // mPDF 5.3.04
  14753. if ($currblk['inner_width'] < $mw) {
  14754. $currblk['padding_left'] = 0;
  14755. $currblk['padding_right'] = 0;
  14756. $currblk['border_left']['w'] = 0.2;
  14757. $currblk['border_right']['w'] = 0.2;
  14758. $currblk['margin_left'] = 0;
  14759. $currblk['margin_right'] = 0;
  14760. $currblk['outer_left_margin'] = $prevblk['outer_left_margin'] + $currblk['margin_left'] + $prevblk['border_left']['w'] + $prevblk['padding_left'];
  14761. $currblk['outer_right_margin'] = $prevblk['outer_right_margin'] + $currblk['margin_right'] + $prevblk['border_right']['w'] + $prevblk['padding_right'];
  14762. $currblk['width'] = $this->pgwidth - ($currblk['outer_right_margin'] + $currblk['outer_left_margin']);
  14763. $currblk['inner_width'] = $this->pgwidth - ($currblk['outer_right_margin'] + $currblk['outer_left_margin'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right']);
  14764. // if ($currblk['inner_width'] < $mw) { $this->Error("DIV is too narrow for text to fit!"); }
  14765. }
  14766. $this->x = $this->lMargin + $currblk['outer_left_margin'];
  14767. /*-- BACKGROUNDS --*/
  14768. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->kwt && !$this->ColActive && !$this->keep_block_together) {
  14769. $ret = $this->SetBackground($properties, $currblk['inner_width']);
  14770. if ($ret) { $currblk['background-image'] = $ret; }
  14771. }
  14772. /*-- END BACKGROUNDS --*/
  14773. /*-- TABLES --*/
  14774. if ($this->use_kwt && isset($attr['KEEP-WITH-TABLE']) && !$this->ColActive && !$this->keep_block_together) {
  14775. $this->kwt = true;
  14776. $this->kwt_y0 = $this->y;
  14777. $this->kwt_x0 = $this->x;
  14778. $this->kwt_height = 0;
  14779. $this->kwt_buffer = array();
  14780. $this->kwt_Links = array();
  14781. $this->kwt_Annots = array();
  14782. $this->kwt_moved = false;
  14783. $this->kwt_saved = false;
  14784. $this->kwt_Reference = array();
  14785. $this->kwt_BMoutlines = array();
  14786. $this->kwt_toc = array();
  14787. }
  14788. else {
  14789. /*-- END TABLES --*/
  14790. $this->kwt = false;
  14791. } // *TABLES*
  14792. //Save x,y coords in case we need to print borders...
  14793. $currblk['y0'] = $this->y;
  14794. $currblk['x0'] = $this->x;
  14795. $currblk['startpage'] = $this->page;
  14796. $this->oldy = $this->y;
  14797. $this->lastblocklevelchange = 1 ;
  14798. break;
  14799. case 'HR':
  14800. // Added mPDF 3.0 Float DIV - CLEAR
  14801. if (isset($attr['STYLE'])) {
  14802. $properties = $this->readInlineCSS($attr['STYLE']);
  14803. if (isset($properties['CLEAR'])) { $this->ClearFloats(strtoupper($properties['CLEAR']),$this->blklvl); } // *CSS-FLOAT*
  14804. }
  14805. $this->ignorefollowingspaces = true;
  14806. $objattr = array();
  14807. $objattr['margin_top'] = 0;
  14808. $objattr['margin_bottom'] = 0;
  14809. $objattr['margin_left'] = 0;
  14810. $objattr['margin_right'] = 0;
  14811. $objattr['width'] = 0;
  14812. $objattr['height'] = 0;
  14813. $objattr['border_top']['w'] = 0;
  14814. $objattr['border_bottom']['w'] = 0;
  14815. $objattr['border_left']['w'] = 0;
  14816. $objattr['border_right']['w'] = 0;
  14817. $properties = $this->MergeCSS('',$tag,$attr);
  14818. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top'] = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14819. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14820. if (isset($properties['WIDTH'])) { $objattr['width'] = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width']); }
  14821. if (isset($properties['TEXT-ALIGN'])) { $objattr['align'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  14822. if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  14823. $objattr['align'] = 'R';
  14824. }
  14825. if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  14826. $objattr['align'] = 'L';
  14827. if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto' && isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  14828. $objattr['align'] = 'C';
  14829. }
  14830. }
  14831. if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  14832. if (isset($properties['HEIGHT'])) { $objattr['linewidth'] = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14833. if(isset($attr['WIDTH']) && $attr['WIDTH'] != '') $objattr['width'] = $this->ConvertSize($attr['WIDTH'],$this->blk[$this->blklvl]['inner_width']);
  14834. if(isset($attr['ALIGN']) && $attr['ALIGN'] != '') $objattr['align'] = $align[strtolower($attr['ALIGN'])];
  14835. if(isset($attr['COLOR']) && $attr['COLOR'] != '') $objattr['color'] = $this->ConvertColor($attr['COLOR']);
  14836. /*-- TABLES --*/
  14837. if ($this->tableLevel) {
  14838. $objattr['W-PERCENT'] = 100;
  14839. if (isset($properties['WIDTH']) && stristr($properties['WIDTH'],'%')) {
  14840. $properties['WIDTH'] += 0; //make "90%" become simply "90"
  14841. $objattr['W-PERCENT'] = $properties['WIDTH'];
  14842. }
  14843. if (isset($attr['WIDTH']) && stristr($attr['WIDTH'],'%')) {
  14844. $attr['WIDTH'] += 0; //make "90%" become simply "90"
  14845. $objattr['W-PERCENT'] = $attr['WIDTH'];
  14846. }
  14847. }
  14848. /*-- END TABLES --*/
  14849. $objattr['type'] = 'hr';
  14850. $objattr['height'] = $objattr['linewidth'] + $objattr['margin_top'] + $objattr['margin_bottom'];
  14851. $e = "\xbb\xa4\xactype=image,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14852. // Clear properties - tidy up
  14853. $properties = array();
  14854. /*-- TABLES --*/
  14855. // Output it to buffers
  14856. if ($this->tableLevel) {
  14857. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  14858. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14859. }
  14860. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  14861. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14862. }
  14863. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  14864. $this->_saveCellTextBuffer($e, $this->HREF); // mPDF 5.3.99
  14865. }
  14866. else {
  14867. /*-- END TABLES --*/
  14868. $this->_saveTextBuffer($e, $this->HREF); // mPDF 5.3.99
  14869. } // *TABLES*
  14870. break;
  14871. /*-- BARCODES --*/
  14872. case 'BARCODE':
  14873. if(isset($attr['CODE']) && $attr['CODE']) {
  14874. $objattr = array();
  14875. $objattr['margin_top'] = 0;
  14876. $objattr['margin_bottom'] = 0;
  14877. $objattr['margin_left'] = 0;
  14878. $objattr['margin_right'] = 0;
  14879. $objattr['padding_top'] = 0;
  14880. $objattr['padding_bottom'] = 0;
  14881. $objattr['padding_left'] = 0;
  14882. $objattr['padding_right'] = 0;
  14883. $objattr['width'] = 0;
  14884. $objattr['height'] = 0;
  14885. $objattr['border_top']['w'] = 0;
  14886. $objattr['border_bottom']['w'] = 0;
  14887. $objattr['border_left']['w'] = 0;
  14888. $objattr['border_right']['w'] = 0;
  14889. $objattr['code'] = $attr['CODE'];
  14890. if(isset($attr['TYPE'])) {
  14891. $objattr['btype'] = trim(strtoupper($attr['TYPE']));
  14892. }
  14893. else { $objattr['btype'] = 'EAN13'; } // default
  14894. if (preg_match('/^(EAN13|ISBN|ISSN|EAN8|UPCA|UPCE)P([25])$/',$objattr['btype'],$m)) {
  14895. $objattr['btype'] = $m[1];
  14896. $objattr['bsupp'] = $m[2];
  14897. if (preg_match('/^(\S+)\s+(.*)$/',$objattr['code'],$mm)) {
  14898. $objattr['code'] = $mm[1];
  14899. $objattr['bsupp_code'] = $mm[2];
  14900. }
  14901. }
  14902. else { $objattr['bsupp'] = 0; }
  14903. if(isset($attr['TEXT']) && $attr['TEXT']==1) { $objattr['showtext'] = 1; }
  14904. else { $objattr['showtext'] = 0; }
  14905. if(isset($attr['SIZE']) && $attr['SIZE']>0) { $objattr['bsize'] = $attr['SIZE']; }
  14906. else { $objattr['bsize'] = 1; }
  14907. if(isset($attr['HEIGHT']) && $attr['HEIGHT']>0) { $objattr['bheight'] = $attr['HEIGHT']; }
  14908. else { $objattr['bheight'] = 1; }
  14909. if(isset($attr['PR']) && $attr['PR']>0) { $objattr['pr_ratio'] = $attr['PR']; }
  14910. else { $objattr['pr_ratio'] = ''; }
  14911. $properties = $this->MergeCSS('',$tag,$attr);
  14912. if(isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY'])=='none') {
  14913. return;
  14914. }
  14915. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14916. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14917. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14918. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14919. if (isset($properties['PADDING-TOP'])) { $objattr['padding_top']=$this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14920. if (isset($properties['PADDING-BOTTOM'])) { $objattr['padding_bottom'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14921. if (isset($properties['PADDING-LEFT'])) { $objattr['padding_left'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14922. if (isset($properties['PADDING-RIGHT'])) { $objattr['padding_right'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14923. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  14924. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  14925. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  14926. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  14927. if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  14928. if (isset($properties['COLOR']) && $properties['COLOR'] != '') { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  14929. else { $objattr['color'] = false; }
  14930. if (isset($properties['BACKGROUND-COLOR']) && $properties['BACKGROUND-COLOR'] != '') { $objattr['bgcolor'] = $this->ConvertColor($properties['BACKGROUND-COLOR']); }
  14931. else { $objattr['bgcolor'] = false; }
  14932. if (!class_exists('PDFBarcode', false)) {
  14933. include(_MPDF_PATH.'classes/barcode.php');
  14934. }
  14935. $this->barcode = new PDFBarcode();
  14936. if ($objattr['btype'] == 'EAN13' || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN' || $objattr['btype'] == 'UPCA' || $objattr['btype'] == 'UPCE' || $objattr['btype'] == 'EAN8') {
  14937. $code = preg_replace('/\-/','',$objattr['code']);
  14938. if ($objattr['btype'] == 'ISSN' || $objattr['btype'] == 'ISBN') {
  14939. $arrcode = $this->barcode->getBarcodeArray($code, 'EAN13');
  14940. }
  14941. else { $arrcode = $this->barcode->getBarcodeArray($code, $objattr['btype'] ); }
  14942. if ($arrcode === false) { $this->Error('Error in barcode string.'); }
  14943. if ($objattr['bsupp'] == 2 || $objattr['bsupp'] == 5) { // EAN-2 or -5 Supplement
  14944. $supparrcode = $this->barcode->getBarcodeArray($objattr['bsupp_code'], 'EAN'.$objattr['bsupp'] );
  14945. $w = ($arrcode["maxw"] + $arrcode['lightmL'] + $arrcode['lightmR'] + $supparrcode["maxw"] + $supparrcode['sepM']) * $arrcode['nom-X'] * $objattr['bsize'];
  14946. }
  14947. else {
  14948. $w = ($arrcode["maxw"] + $arrcode['lightmL'] + $arrcode['lightmR']) * $arrcode['nom-X'] * $objattr['bsize'];
  14949. }
  14950. $h = $arrcode['nom-H'] * $objattr['bsize'] * $objattr['bheight'];
  14951. // Add height for ISBN string + margin from top of bars
  14952. if (($objattr['showtext'] && $objattr['btype'] == 'EAN13') || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN') {
  14953. $tisbnm = 1.5 * $objattr['bsize']; // Top margin between TOP TEXT (isbn - if shown) & bars
  14954. $isbn_fontsize = 2.1 * $objattr['bsize'];
  14955. $h += $isbn_fontsize + $tisbnm ;
  14956. }
  14957. }
  14958. // QR-code
  14959. else if ($objattr['btype'] == 'QR') {
  14960. $w = $h = $objattr['bsize']*25; // Factor of 25mm (default)
  14961. $objattr['errorlevel'] = 'L';
  14962. if (isset($attr['ERROR'])) { $objattr['errorlevel'] = $attr['ERROR']; }
  14963. }
  14964. else if ($objattr['btype'] == 'IMB' || $objattr['btype'] == 'RM4SCC' || $objattr['btype'] == 'KIX' || $objattr['btype'] == 'POSTNET' || $objattr['btype'] == 'PLANET') {
  14965. $arrcode = $this->barcode->getBarcodeArray($objattr['code'], $objattr['btype'] );
  14966. if ($arrcode === false) { $this->Error('Error in barcode string.'); }
  14967. $w = ($arrcode["maxw"] * $arrcode['nom-X'] * $objattr['bsize']) + $arrcode['quietL'] + $arrcode['quietR'];
  14968. $h = ($arrcode['nom-H'] * $objattr['bsize']) + (2*$arrcode['quietTB']);
  14969. }
  14970. else if (in_array($objattr['btype'], array('C128A','C128B','C128C','EAN128A','EAN128B','EAN128C','C39','C39+','C39E','C39E+','S25','S25+','I25','I25+','I25B','I25B+','C93','MSI','MSI+','CODABAR','CODE11'))) {
  14971. $arrcode = $this->barcode->getBarcodeArray($objattr['code'], $objattr['btype'], $objattr['pr_ratio'] );
  14972. if ($arrcode === false) { $this->Error('Error in barcode string.'); }
  14973. $w = ($arrcode["maxw"] + $arrcode['lightmL'] + $arrcode['lightmR']) * $arrcode['nom-X'] * $objattr['bsize'];
  14974. $h = ((2*$arrcode['lightTB'] * $arrcode['nom-X']) + $arrcode['nom-H']) * $objattr['bsize'] * $objattr['bheight'];
  14975. }
  14976. else { break; }
  14977. $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  14978. $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  14979. $objattr['type'] = 'barcode';
  14980. $objattr['height'] = $h + $extraheight;
  14981. $objattr['width'] = $w + $extrawidth;
  14982. $objattr['barcode_height'] = $h;
  14983. $objattr['barcode_width'] = $w;
  14984. /*-- CSS-IMAGE-FLOAT --*/
  14985. if (!$this->ColActive && !$this->tableLevel && !$this->listlvl && !$this->kwt && !$this->keep_block_together) {
  14986. if (isset($properties['FLOAT']) && (strtoupper($properties['FLOAT']) == 'RIGHT' || strtoupper($properties['FLOAT']) == 'LEFT')) {
  14987. $objattr['float'] = substr(strtoupper($properties['FLOAT']),0,1);
  14988. }
  14989. }
  14990. /*-- END CSS-IMAGE-FLOAT --*/
  14991. $e = "\xbb\xa4\xactype=barcode,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14992. // Clear properties - tidy up
  14993. $properties = array();
  14994. /*-- TABLES --*/
  14995. // Output it to buffers
  14996. if ($this->tableLevel) {
  14997. $this->_saveCellTextBuffer($e, $this->HREF); // mPDF 5.3.99
  14998. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  14999. }
  15000. else {
  15001. /*-- END TABLES --*/
  15002. $this->_saveTextBuffer($e, $this->HREF); // mPDF 5.3.99
  15003. } // *TABLES*
  15004. }
  15005. break;
  15006. /*-- END BARCODES --*/
  15007. // *********** FORM ELEMENTS ********************
  15008. /*-- FORMS --*/
  15009. case 'SELECT':
  15010. $this->lastoptionaltag = ''; // Save current HTML specified optional endtag
  15011. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  15012. $properties = $this->MergeCSS('',$tag,$attr);
  15013. if (isset($properties['FONT-FAMILY'])) {
  15014. $this->SetFont($properties['FONT-FAMILY'],$this->FontStyle,0,false);
  15015. }
  15016. if (isset($properties['FONT-SIZE'])) {
  15017. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/_MPDFK);
  15018. $this->SetFontSize($mmsize*_MPDFK,false);
  15019. }
  15020. if (isset($attr['SPELLCHECK']) && strtolower($attr['SPELLCHECK'])=='true') {
  15021. $this->selectoption['SPELLCHECK'] = true;
  15022. }
  15023. if (isset($properties['COLOR'])) { $this->selectoption['COLOR'] = $this->ConvertColor($properties['COLOR']); }
  15024. $this->specialcontent = "type=select";
  15025. if(isset($attr['DISABLED'])) { $this->selectoption['DISABLED'] = $attr['DISABLED']; }
  15026. if(isset($attr['READONLY'])) { $this->selectoption['READONLY'] = $attr['READONLY']; }
  15027. if(isset($attr['REQUIRED'])) { $this->selectoption['REQUIRED'] = $attr['REQUIRED']; }
  15028. if(isset($attr['EDITABLE'])) { $this->selectoption['EDITABLE'] = $attr['EDITABLE']; }
  15029. if(isset($attr['TITLE'])) { $this->selectoption['TITLE'] = $attr['TITLE']; }
  15030. if(isset($attr['MULTIPLE'])) { $this->selectoption['MULTIPLE'] = $attr['MULTIPLE']; }
  15031. if(isset($attr['SIZE']) && $attr['SIZE']>1) { $this->selectoption['SIZE'] = $attr['SIZE']; }
  15032. if ($this->useActiveForms) {
  15033. if(isset($attr['NAME'])) { $this->selectoption['NAME'] = $attr['NAME']; }
  15034. if (isset($attr['ONCHANGE'])) { $this->selectoption['ONCHANGE'] = $attr['ONCHANGE']; }
  15035. }
  15036. $properties = array();
  15037. break;
  15038. case 'OPTION':
  15039. $this->lastoptionaltag = 'OPTION'; // Save current HTML specified optional endtag
  15040. $this->selectoption['ACTIVE'] = true;
  15041. $this->selectoption['currentSEL'] = false;
  15042. if (empty($this->selectoption)) {
  15043. $this->selectoption['MAXWIDTH'] = '';
  15044. $this->selectoption['SELECTED'] = '';
  15045. }
  15046. if (isset($attr['SELECTED'])) {
  15047. $this->selectoption['SELECTED'] = '';
  15048. $this->selectoption['currentSEL'] = true;
  15049. }
  15050. // mPDF 5.3.46
  15051. if(isset($attr['VALUE'])) {
  15052. $attr['VALUE'] = strcode2utf($attr['VALUE']);
  15053. $attr['VALUE'] = $this->lesser_entity_decode($attr['VALUE']); // mPDF 5.3.58
  15054. if ($this->onlyCoreFonts)
  15055. $attr['VALUE'] = mb_convert_encoding($attr['VALUE'], $this->mb_enc,'UTF-8');
  15056. // mPDF 5.3.58
  15057. }
  15058. $this->selectoption['currentVAL'] = $attr['VALUE'];
  15059. break;
  15060. case 'TEXTAREA':
  15061. $objattr = array();
  15062. $objattr['margin_top'] = 0;
  15063. $objattr['margin_bottom'] = 0;
  15064. $objattr['margin_left'] = 0;
  15065. $objattr['margin_right'] = 0;
  15066. $objattr['width'] = 0;
  15067. $objattr['height'] = 0;
  15068. $objattr['border_top']['w'] = 0;
  15069. $objattr['border_bottom']['w'] = 0;
  15070. $objattr['border_left']['w'] = 0;
  15071. $objattr['border_right']['w'] = 0;
  15072. if(isset($attr['DISABLED'])) { $objattr['disabled'] = true; }
  15073. if(isset($attr['READONLY'])) { $objattr['readonly'] = true; }
  15074. if(isset($attr['REQUIRED'])) { $objattr['required'] = true; }
  15075. if(isset($attr['SPELLCHECK']) && strtolower($attr['SPELLCHECK'])=='true') { $objattr['spellcheck'] = true; }
  15076. if(isset($attr['TITLE'])) { $objattr['title'] = $attr['TITLE']; }
  15077. if ($this->onlyCoreFonts)
  15078. $objattr['title'] = mb_convert_encoding($objattr['title'], $this->mb_enc,'UTF-8');
  15079. if ($this->useActiveForms) {
  15080. if(isset($attr['NAME'])) { $objattr['fieldname'] = $attr['NAME']; }
  15081. $this->form->form_element_spacing['textarea']['outer']['v'] = 0;
  15082. $this->form->form_element_spacing['textarea']['inner']['v'] = 0;
  15083. // mPDF 5.3.25
  15084. if (isset($attr['ONCALCULATE'])) { $objattr['onCalculate'] = $attr['ONCALCULATE']; }
  15085. else if (isset($attr['ONCHANGE'])) { $objattr['onCalculate'] = $attr['ONCHANGE']; }
  15086. if (isset($attr['ONVALIDATE'])) { $objattr['onValidate'] = $attr['ONVALIDATE']; }
  15087. if (isset($attr['ONKEYSTROKE'])) { $objattr['onKeystroke'] = $attr['ONKEYSTROKE']; }
  15088. if (isset($attr['ONFORMAT'])) { $objattr['onFormat'] = $attr['ONFORMAT']; } // mPDF 5.3.37
  15089. }
  15090. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  15091. $properties = $this->MergeCSS('',$tag,$attr);
  15092. if (isset($properties['FONT-FAMILY'])) {
  15093. $this->SetFont($properties['FONT-FAMILY'],'',0,false);
  15094. }
  15095. if (isset($properties['FONT-SIZE'])) {
  15096. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/_MPDFK);
  15097. $this->SetFontSize($mmsize*_MPDFK,false);
  15098. }
  15099. if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  15100. $objattr['fontfamily'] = $this->FontFamily;
  15101. $objattr['fontsize'] = $this->FontSizePt;
  15102. if ($this->useActiveForms) {
  15103. if(isset($attr['ALIGN'])) { $objattr['text_align'] = $align[strtolower($attr['ALIGN'])]; }
  15104. else if(isset($properties['TEXT-ALIGN'])) { $objattr['text_align'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  15105. if (isset($properties['OVERFLOW']) && strtolower($properties['OVERFLOW'])=='hidden') { $objattr['donotscroll'] = true; }
  15106. if (isset($properties['BORDER-TOP-COLOR'])) { $objattr['border-col'] = $this->ConvertColor($properties['BORDER-TOP-COLOR']); }
  15107. if (isset($properties['BACKGROUND-COLOR'])) { $objattr['background-col'] = $this->ConvertColor($properties['BACKGROUND-COLOR']); }
  15108. }
  15109. $this->SetLineHeight('',$this->form->textarea_lineheight);
  15110. $formLineHeight = $this->lineheight;
  15111. $w = 0;
  15112. $h = 0;
  15113. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15114. if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15115. if ($properties['VERTICAL-ALIGN']) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  15116. $colsize = 20; //HTML default value
  15117. $rowsize = 2; //HTML default value
  15118. if (isset($attr['COLS'])) $colsize = intval($attr['COLS']);
  15119. if (isset($attr['ROWS'])) $rowsize = intval($attr['ROWS']);
  15120. $charsize = $this->GetCharWidth('w',false); // mPDF 5.3.04
  15121. if ($w) { $colsize = round(($w-($this->form->form_element_spacing['textarea']['outer']['h']*2)-($this->form->form_element_spacing['textarea']['inner']['h']*2))/$charsize); }
  15122. if ($h) { $rowsize = round(($h-($this->form->form_element_spacing['textarea']['outer']['v']*2)-($this->form->form_element_spacing['textarea']['inner']['v']*2))/$formLineHeight); }
  15123. $objattr['type'] = 'textarea';
  15124. $objattr['width'] = ($colsize * $charsize) + ($this->form->form_element_spacing['textarea']['outer']['h']*2)+($this->form->form_element_spacing['textarea']['inner']['h']*2);
  15125. $objattr['height'] = ($rowsize * $formLineHeight) + ($this->form->form_element_spacing['textarea']['outer']['v']*2)+($this->form->form_element_spacing['textarea']['inner']['v']*2);
  15126. $objattr['rows'] = $rowsize;
  15127. $objattr['cols'] = $colsize;
  15128. $this->specialcontent = serialize($objattr);
  15129. if ($this->tableLevel) { // *TABLES*
  15130. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ; // *TABLES*
  15131. } // *TABLES*
  15132. // Clear properties - tidy up
  15133. $properties = array();
  15134. break;
  15135. // *********** FORM - INPUT ********************
  15136. case 'INPUT':
  15137. if (!isset($attr['TYPE'])) $attr['TYPE'] == 'TEXT';
  15138. $objattr = array();
  15139. $objattr['margin_top'] = 0;
  15140. $objattr['margin_bottom'] = 0;
  15141. $objattr['margin_left'] = 0;
  15142. $objattr['margin_right'] = 0;
  15143. $objattr['width'] = 0;
  15144. $objattr['height'] = 0;
  15145. $objattr['border_top']['w'] = 0;
  15146. $objattr['border_bottom']['w'] = 0;
  15147. $objattr['border_left']['w'] = 0;
  15148. $objattr['border_right']['w'] = 0;
  15149. $objattr['type'] = 'input';
  15150. if(isset($attr['DISABLED'])) { $objattr['disabled'] = true; }
  15151. if(isset($attr['READONLY'])) { $objattr['readonly'] = true; }
  15152. if(isset($attr['REQUIRED'])) { $objattr['required'] = true; }
  15153. if(isset($attr['SPELLCHECK']) && strtolower($attr['SPELLCHECK'])=='true') { $objattr['spellcheck'] = true; }
  15154. if(isset($attr['TITLE'])) { $objattr['title'] = $attr['TITLE']; }
  15155. else if(isset($attr['ALT'])) { $objattr['title'] = $attr['ALT']; }
  15156. // mPDF 5.3.46
  15157. else $objattr['title'] = '';
  15158. $objattr['title'] = strcode2utf($objattr['title']);
  15159. $objattr['title'] = $this->lesser_entity_decode($objattr['title']); // mPDF 5.3.58
  15160. if ($this->onlyCoreFonts)
  15161. $objattr['title'] = mb_convert_encoding($objattr['title'], $this->mb_enc,'UTF-8');
  15162. if ($this->useActiveForms) {
  15163. if(isset($attr['NAME'])) { $objattr['fieldname'] = $attr['NAME']; }
  15164. }
  15165. // mPDF 5.3.46
  15166. if(isset($attr['VALUE'])) {
  15167. $attr['VALUE'] = strcode2utf($attr['VALUE']);
  15168. $attr['VALUE'] = $this->lesser_entity_decode($attr['VALUE']); // mPDF 5.3.58
  15169. if ($this->onlyCoreFonts)
  15170. $attr['VALUE'] = mb_convert_encoding($attr['VALUE'], $this->mb_enc,'UTF-8');
  15171. $objattr['value'] = $attr['VALUE'];
  15172. }
  15173. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  15174. $properties = $this->MergeCSS('',$tag,$attr);
  15175. $objattr['vertical-align'] = '';
  15176. if (isset($properties['FONT-FAMILY'])) {
  15177. $this->SetFont($properties['FONT-FAMILY'],$this->FontStyle,0,false);
  15178. }
  15179. if (isset($properties['FONT-SIZE'])) {
  15180. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],($this->default_font_size/_MPDFK));
  15181. $this->SetFontSize($mmsize*_MPDFK,false);
  15182. }
  15183. if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  15184. $objattr['fontfamily'] = $this->FontFamily;
  15185. $objattr['fontsize'] = $this->FontSizePt;
  15186. if ($this->useActiveForms) {
  15187. if(isset($attr['ALIGN'])) { $objattr['text_align'] = $align[strtolower($attr['ALIGN'])]; }
  15188. else if(isset($properties['TEXT-ALIGN'])) { $objattr['text_align'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  15189. if (isset($properties['BORDER-TOP-COLOR'])) { $objattr['border-col'] = $this->ConvertColor($properties['BORDER-TOP-COLOR']); }
  15190. if (isset($properties['BACKGROUND-COLOR'])) { $objattr['background-col'] = $this->ConvertColor($properties['BACKGROUND-COLOR']); }
  15191. }
  15192. $type = '';
  15193. $texto='';
  15194. $height = $this->FontSize;
  15195. $width = 0;
  15196. $spacesize = $this->GetCharWidth(' ',false); // mPDF 5.3.04
  15197. $w = 0;
  15198. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width']);
  15199. if ($properties['VERTICAL-ALIGN']) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  15200. switch(strtoupper($attr['TYPE'])){
  15201. case 'HIDDEN':
  15202. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  15203. if ($this->useActiveForms) {
  15204. $this->form->SetFormText( 0, 0, $objattr['fieldname'], $objattr['value'], $objattr['value'], '', 0, '', true );
  15205. }
  15206. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  15207. unset($this->InlineProperties[$tag]);
  15208. break 2;
  15209. case 'CHECKBOX': //Draw Checkbox
  15210. $type = 'CHECKBOX';
  15211. if (isset($attr['CHECKED'])) { $objattr['checked'] = true; }
  15212. else { $objattr['checked'] = false; }
  15213. $width = $this->FontSize;
  15214. $height = $this->FontSize;
  15215. break;
  15216. case 'RADIO': //Draw Radio button
  15217. $type = 'RADIO';
  15218. if (isset($attr['CHECKED'])) $objattr['checked'] = true;
  15219. $width = $this->FontSize;
  15220. $height = $this->FontSize;
  15221. break;
  15222. /*-- IMAGES-CORE --*/
  15223. case 'IMAGE': // Draw an Image button
  15224. if(isset($attr['SRC'])) {
  15225. $type = 'IMAGE';
  15226. $srcpath = $attr['SRC'];
  15227. $orig_srcpath = $attr['ORIG_SRC'];
  15228. // VSPACE and HSPACE converted to margins in MergeCSS
  15229. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15230. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15231. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15232. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15233. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  15234. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  15235. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  15236. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  15237. $objattr['padding_top'] = 0;
  15238. $objattr['padding_bottom'] = 0;
  15239. $objattr['padding_left'] = 0;
  15240. $objattr['padding_right'] = 0;
  15241. if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  15242. $w = 0;
  15243. $h = 0;
  15244. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width']);
  15245. if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width']);
  15246. $extraheight = $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  15247. $extrawidth = $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  15248. // Image file
  15249. $info=$this->_getImage($srcpath, true, true, $orig_srcpath);
  15250. if(!$info) {
  15251. $info = $this->_getImage($this->noImageFile);
  15252. if ($info) {
  15253. $srcpath = $this->noImageFile;
  15254. $w = ($info['w'] * (25.4/$this->dpi));
  15255. $h = ($info['h'] * (25.4/$this->dpi));
  15256. }
  15257. }
  15258. if(!$info) break;
  15259. if ($info['cs']=='Indexed') { $objattr['Indexed'] = true; }
  15260. $objattr['file'] = $srcpath;
  15261. //Default width and height calculation if needed
  15262. if($w==0 and $h==0) {
  15263. /*-- IMAGES-WMF --*/
  15264. if ($info['type']=='wmf') {
  15265. // WMF units are twips (1/20pt)
  15266. // divide by 20 to get points
  15267. // divide by k to get user units
  15268. $w = abs($info['w'])/(20*_MPDFK);
  15269. $h = abs($info['h']) / (20*_MPDFK);
  15270. }
  15271. else
  15272. /*-- END IMAGES-WMF --*/
  15273. if ($info['type']=='svg') {
  15274. // SVG units are pixels
  15275. $w = abs($info['w'])/_MPDFK;
  15276. $h = abs($info['h'])/_MPDFK;
  15277. }
  15278. else {
  15279. //Put image at default image dpi
  15280. $w=($info['w']/_MPDFK) * (72/$this->img_dpi);
  15281. $h=($info['h']/_MPDFK) * (72/$this->img_dpi);
  15282. }
  15283. if (isset($properties['IMAGE-RESOLUTION'])) {
  15284. if (preg_match('/from-image/i', $properties['IMAGE-RESOLUTION']) && isset($info['set-dpi']) && $info['set-dpi']>0) {
  15285. $w *= $this->img_dpi / $info['set-dpi'];
  15286. $h *= $this->img_dpi / $info['set-dpi'];
  15287. }
  15288. else if (preg_match('/(\d+)dpi/i', $properties['IMAGE-RESOLUTION'], $m)) {
  15289. $dpi = $m[1];
  15290. if ($dpi > 0) {
  15291. $w *= $this->img_dpi / $dpi;
  15292. $h *= $this->img_dpi / $dpi;
  15293. }
  15294. }
  15295. }
  15296. }
  15297. // IF WIDTH OR HEIGHT SPECIFIED
  15298. if($w==0) $w=$h*$info['w']/$info['h'];
  15299. if($h==0) $h=$w*$info['h']/$info['w'];
  15300. // Resize to maximum dimensions of page
  15301. $maxWidth = $this->blk[$this->blklvl]['inner_width'];
  15302. $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 10) ;
  15303. if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; }
  15304. if ($w + $extrawidth > $maxWidth ) {
  15305. $w = $maxWidth - $extrawidth;
  15306. $h=$w*$info['h']/$info['w'];
  15307. }
  15308. if ($h + $extraheight > $maxHeight ) {
  15309. $h = $maxHeight - $extraheight;
  15310. $w=$h*$info['w']/$info['h'];
  15311. }
  15312. $height = $h + $extraheight;
  15313. $width = $w + $extrawidth;
  15314. $objattr['type'] = 'image';
  15315. $objattr['itype'] = $info['type'];
  15316. $objattr['orig_h'] = $info['h'];
  15317. $objattr['orig_w'] = $info['w'];
  15318. /*-- IMAGES-WMF --*/
  15319. if ($info['type']=='wmf') {
  15320. $objattr['wmf_x'] = $info['x'];
  15321. $objattr['wmf_y'] = $info['y'];
  15322. }
  15323. else
  15324. /*-- END IMAGES-WMF --*/
  15325. if ($info['type']=='svg') {
  15326. $objattr['wmf_x'] = $info['x'];
  15327. $objattr['wmf_y'] = $info['y'];
  15328. }
  15329. $objattr['height'] = $h + $extraheight;
  15330. $objattr['width'] = $w + $extrawidth;
  15331. $objattr['image_height'] = $h;
  15332. $objattr['image_width'] = $w;
  15333. $objattr['ID'] = $info['i'];
  15334. $texto = 'X';
  15335. if ($this->useActiveForms) {
  15336. if (isset($attr['ONCLICK'])) { $objattr['onClick'] = $attr['ONCLICK']; }
  15337. $objattr['type'] = 'input';
  15338. $type = 'IMAGE';
  15339. }
  15340. break;
  15341. }
  15342. /*-- END IMAGES-CORE --*/
  15343. case 'BUTTON': // Draw a button
  15344. case 'SUBMIT':
  15345. case 'RESET':
  15346. $type = strtoupper($attr['TYPE']);
  15347. if ($type=='IMAGE') { $type = 'BUTTON'; } // src path not found
  15348. if(isset($attr['NOPRINT'])) { $objattr['noprint'] = true; }
  15349. // mPDF 5.3.46
  15350. if (!isset($attr['VALUE'])) {
  15351. $objattr['value'] = ucfirst(strtolower($type));
  15352. }
  15353. $texto = " " . $objattr['value'] . " ";
  15354. $width = $this->GetStringWidth($texto) + ($this->form->form_element_spacing['button']['outer']['h']*2)+($this->form->form_element_spacing['button']['inner']['h']*2);
  15355. $height = $this->FontSize + ($this->form->form_element_spacing['button']['outer']['v']*2)+($this->form->form_element_spacing['button']['inner']['v']*2);
  15356. if ($this->useActiveForms) {
  15357. if (isset($attr['ONCLICK'])) { $objattr['onClick'] = $attr['ONCLICK']; }
  15358. }
  15359. break;
  15360. case 'PASSWORD':
  15361. case 'TEXT':
  15362. default:
  15363. if ($type == '') { $type = 'TEXT'; }
  15364. if(strtoupper($attr['TYPE'])=='PASSWORD') { $type = 'PASSWORD'; }
  15365. if (isset($attr['VALUE'])) {
  15366. if ($type == 'PASSWORD') {
  15367. $num_stars = mb_strlen($attr['VALUE'],$this->mb_enc );
  15368. $texto = str_repeat('*',$num_stars);
  15369. }
  15370. else { $texto = $attr['VALUE']; }
  15371. }
  15372. $xw = ($this->form->form_element_spacing['input']['outer']['h']*2)+($this->form->form_element_spacing['input']['inner']['h']*2);
  15373. $xh = ($this->form->form_element_spacing['input']['outer']['v']*2)+($this->form->form_element_spacing['input']['inner']['v']*2);
  15374. if ($w) { $width = $w + $xw; }
  15375. else { $width = (20 * $spacesize) + $xw; } // Default width in chars
  15376. if (isset($attr['SIZE']) and ctype_digit($attr['SIZE']) ) $width = ($attr['SIZE'] * $spacesize) + $xw;
  15377. $height = $this->FontSize + $xh;
  15378. if (isset($attr['MAXLENGTH']) and ctype_digit($attr['MAXLENGTH']) ) $objattr['maxlength'] = $attr['MAXLENGTH'];
  15379. if ($this->useActiveForms) {
  15380. // mPDF 5.3.25
  15381. if (isset($attr['ONCALCULATE'])) { $objattr['onCalculate'] = $attr['ONCALCULATE']; }
  15382. else if (isset($attr['ONCHANGE'])) { $objattr['onCalculate'] = $attr['ONCHANGE']; }
  15383. if (isset($attr['ONVALIDATE'])) { $objattr['onValidate'] = $attr['ONVALIDATE']; }
  15384. if (isset($attr['ONKEYSTROKE'])) { $objattr['onKeystroke'] = $attr['ONKEYSTROKE']; }
  15385. if (isset($attr['ONFORMAT'])) { $objattr['onFormat'] = $attr['ONFORMAT']; } // mPDF 5.3.37
  15386. }
  15387. break;
  15388. }
  15389. $objattr['subtype'] = $type;
  15390. $objattr['text'] = $texto;
  15391. $objattr['width'] = $width;
  15392. $objattr['height'] = $height;
  15393. $e = "\xbb\xa4\xactype=input,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15394. // Clear properties - tidy up
  15395. $properties = array();
  15396. /*-- TABLES --*/
  15397. // Output it to buffers
  15398. if ($this->tableLevel) {
  15399. $this->_saveCellTextBuffer($e, $this->HREF); // mPDF 5.3.99
  15400. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  15401. }
  15402. else {
  15403. /*-- END TABLES --*/
  15404. $this->_saveTextBuffer($e, $this->HREF); // mPDF 5.3.99
  15405. } // *TABLES*
  15406. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  15407. unset($this->InlineProperties[$tag]);
  15408. break; // END of INPUT
  15409. /*-- END FORMS --*/
  15410. // *********** GRAPH ********************
  15411. case 'JPGRAPH':
  15412. if (!$this->useGraphs) { break; }
  15413. if ($attr['TABLE']) { $gid = strtoupper($attr['TABLE']); }
  15414. else { $gid = '0'; }
  15415. if (!is_array($this->graphs[$gid]) || count($this->graphs[$gid])==0 ) { break; }
  15416. include_once(_MPDF_PATH.'graph.php');
  15417. $this->graphs[$gid]['attr'] = $attr;
  15418. if (isset($this->graphs[$gid]['attr']['WIDTH']) && $this->graphs[$gid]['attr']['WIDTH']) {
  15419. $this->graphs[$gid]['attr']['cWIDTH']=$this->ConvertSize($this->graphs[$gid]['attr']['WIDTH'],$pgwidth);
  15420. } // mm
  15421. if (isset($this->graphs[$gid]['attr']['HEIGHT']) && $this->graphs[$gid]['attr']['HEIGHT']) {
  15422. $this->graphs[$gid]['attr']['cHEIGHT']=$this->ConvertSize($this->graphs[$gid]['attr']['HEIGHT'],$pgwidth);
  15423. }
  15424. $graph_img = print_graph($this->graphs[$gid],$this->blk[$this->blklvl]['inner_width']);
  15425. if ($graph_img) {
  15426. if(isset($attr['ROTATE'])) {
  15427. if ($attr['ROTATE']==90 || $attr['ROTATE']==-90) {
  15428. $tmpw = $graph_img['w'];
  15429. $graph_img['w']= $graph_img['h'];
  15430. $graph_img['h']= $tmpw;
  15431. }
  15432. }
  15433. $attr['SRC'] = $graph_img['file'];
  15434. $attr['WIDTH'] = $graph_img['w'];
  15435. $attr['HEIGHT'] = $graph_img['h'];
  15436. }
  15437. else { break; }
  15438. // *********** IMAGE ********************
  15439. /*-- IMAGES-CORE --*/
  15440. case 'IMG':
  15441. if ($this->progressBar) { $this->UpdateProgressBar(1,'','IMG'); } // *PROGRESS-BAR*
  15442. $objattr = array();
  15443. $objattr['margin_top'] = 0;
  15444. $objattr['margin_bottom'] = 0;
  15445. $objattr['margin_left'] = 0;
  15446. $objattr['margin_right'] = 0;
  15447. $objattr['padding_top'] = 0;
  15448. $objattr['padding_bottom'] = 0;
  15449. $objattr['padding_left'] = 0;
  15450. $objattr['padding_right'] = 0;
  15451. $objattr['width'] = 0;
  15452. $objattr['height'] = 0;
  15453. $objattr['border_top']['w'] = 0;
  15454. $objattr['border_bottom']['w'] = 0;
  15455. $objattr['border_left']['w'] = 0;
  15456. $objattr['border_right']['w'] = 0;
  15457. if(isset($attr['SRC'])) {
  15458. $srcpath = $attr['SRC'];
  15459. $orig_srcpath = $attr['ORIG_SRC'];
  15460. $properties = $this->MergeCSS('',$tag,$attr);
  15461. if(isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY'])=='none') {
  15462. return;
  15463. }
  15464. // mPDF 5.3.42 VISIBILITY
  15465. $objattr['visibility'] = 'visible';
  15466. if (isset($properties['VISIBILITY'])) {
  15467. $v = strtolower($properties['VISIBILITY']);
  15468. if (($v == 'hidden' || $v == 'printonly' || $v == 'screenonly') && $this->visibility=='visible') {
  15469. $objattr['visibility'] = $v;
  15470. }
  15471. }
  15472. // VSPACE and HSPACE converted to margins in MergeCSS
  15473. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15474. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15475. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15476. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15477. if (isset($properties['PADDING-TOP'])) { $objattr['padding_top']=$this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15478. if (isset($properties['PADDING-BOTTOM'])) { $objattr['padding_bottom'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15479. if (isset($properties['PADDING-LEFT'])) { $objattr['padding_left'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15480. if (isset($properties['PADDING-RIGHT'])) { $objattr['padding_right'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15481. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  15482. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  15483. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  15484. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  15485. if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  15486. $w = 0;
  15487. $h = 0;
  15488. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15489. if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15490. if(isset($attr['WIDTH'])) $w = $this->ConvertSize($attr['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15491. if(isset($attr['HEIGHT'])) $h = $this->ConvertSize($attr['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15492. if (isset($properties['OPACITY']) && $properties['OPACITY'] > 0 && $properties['OPACITY'] <= 1) { $objattr['opacity'] = $properties['OPACITY']; }
  15493. if ($this->HREF) { // mPDF 5.3.78
  15494. if (strpos($this->HREF,".") === false && strpos($this->HREF,"@") !== 0) {
  15495. $href = $this->HREF;
  15496. while(array_key_exists($href,$this->internallink)) $href="#".$href;
  15497. $this->internallink[$href] = $this->AddLink();
  15498. $objattr['link'] = $this->internallink[$href];
  15499. }
  15500. else { $objattr['link'] = $this->HREF; }
  15501. }
  15502. $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  15503. $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  15504. /*-- BACKGROUNDS --*/
  15505. if(isset($properties['GRADIENT-MASK']) && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/',$properties['GRADIENT-MASK'])) {
  15506. $objattr['GRADIENT-MASK'] = $properties['GRADIENT-MASK'];
  15507. }
  15508. /*-- END BACKGROUNDS --*/
  15509. // Image file
  15510. $info=$this->_getImage($srcpath, true, true, $orig_srcpath);
  15511. if(!$info) {
  15512. $info = $this->_getImage($this->noImageFile);
  15513. if ($info) {
  15514. $srcpath = $this->noImageFile;
  15515. $w = ($info['w'] * (25.4/$this->dpi));
  15516. $h = ($info['h'] * (25.4/$this->dpi));
  15517. }
  15518. }
  15519. if(!$info) break;
  15520. if(isset($attr['ROTATE'])) { $image_orientation = $attr['ROTATE']; }
  15521. else if(isset($properties['IMAGE-ORIENTATION'])) { $image_orientation = $properties['IMAGE-ORIENTATION']; }
  15522. else { $image_orientation = 0; }
  15523. if($image_orientation) {
  15524. if ($image_orientation==90 || $image_orientation==-90 || $image_orientation==270) {
  15525. $tmpw = $info['w'];
  15526. $info['w'] = $info['h'];
  15527. $info['h'] = $tmpw;
  15528. }
  15529. $objattr['ROTATE'] = $image_orientation;
  15530. }
  15531. $objattr['file'] = $srcpath;
  15532. //Default width and height calculation if needed
  15533. if($w==0 and $h==0) {
  15534. /*-- IMAGES-WMF --*/
  15535. if ($info['type']=='wmf') {
  15536. // WMF units are twips (1/20pt)
  15537. // divide by 20 to get points
  15538. // divide by k to get user units
  15539. $w = abs($info['w'])/(20*_MPDFK);
  15540. $h = abs($info['h']) / (20*_MPDFK);
  15541. }
  15542. else
  15543. /*-- END IMAGES-WMF --*/
  15544. if ($info['type']=='svg') {
  15545. // SVG units are pixels
  15546. $w = abs($info['w'])/_MPDFK;
  15547. $h = abs($info['h'])/_MPDFK;
  15548. }
  15549. else {
  15550. //Put image at default image dpi
  15551. $w=($info['w']/_MPDFK) * (72/$this->img_dpi);
  15552. $h=($info['h']/_MPDFK) * (72/$this->img_dpi);
  15553. }
  15554. if (isset($properties['IMAGE-RESOLUTION'])) {
  15555. if (preg_match('/from-image/i', $properties['IMAGE-RESOLUTION']) && isset($info['set-dpi']) && $info['set-dpi']>0) {
  15556. $w *= $this->img_dpi / $info['set-dpi'];
  15557. $h *= $this->img_dpi / $info['set-dpi'];
  15558. }
  15559. else if (preg_match('/(\d+)dpi/i', $properties['IMAGE-RESOLUTION'], $m)) {
  15560. $dpi = $m[1];
  15561. if ($dpi > 0) {
  15562. $w *= $this->img_dpi / $dpi;
  15563. $h *= $this->img_dpi / $dpi;
  15564. }
  15565. }
  15566. }
  15567. }
  15568. // IF WIDTH OR HEIGHT SPECIFIED
  15569. if($w==0) $w=abs($h*$info['w']/$info['h']);
  15570. if($h==0) $h=abs($w*$info['h']/$info['w']);
  15571. // Resize to maximum dimensions of page
  15572. $maxWidth = $this->blk[$this->blklvl]['inner_width'];
  15573. $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 1) ;
  15574. if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; }
  15575. if ($w + $extrawidth > $maxWidth ) {
  15576. $w = $maxWidth - $extrawidth;
  15577. $h=abs($w*$info['h']/$info['w']);
  15578. }
  15579. if ($h + $extraheight > $maxHeight ) {
  15580. $h = $maxHeight - $extraheight;
  15581. $w=abs($h*$info['w']/$info['h']);
  15582. }
  15583. $objattr['type'] = 'image';
  15584. $objattr['itype'] = $info['type'];
  15585. $objattr['orig_h'] = $info['h'];
  15586. $objattr['orig_w'] = $info['w'];
  15587. /*-- IMAGES-WMF --*/
  15588. if ($info['type']=='wmf') {
  15589. $objattr['wmf_x'] = $info['x'];
  15590. $objattr['wmf_y'] = $info['y'];
  15591. }
  15592. else
  15593. /*-- END IMAGES-WMF --*/
  15594. if ($info['type']=='svg') {
  15595. $objattr['wmf_x'] = $info['x'];
  15596. $objattr['wmf_y'] = $info['y'];
  15597. }
  15598. $objattr['height'] = $h + $extraheight;
  15599. $objattr['width'] = $w + $extrawidth;
  15600. $objattr['image_height'] = $h;
  15601. $objattr['image_width'] = $w;
  15602. /*-- CSS-IMAGE-FLOAT --*/
  15603. if (!$this->ColActive && !$this->tableLevel && !$this->listlvl && !$this->kwt && !$this->keep_block_together) {
  15604. if (isset($properties['FLOAT']) && (strtoupper($properties['FLOAT']) == 'RIGHT' || strtoupper($properties['FLOAT']) == 'LEFT')) {
  15605. $objattr['float'] = substr(strtoupper($properties['FLOAT']),0,1);
  15606. }
  15607. }
  15608. /*-- END CSS-IMAGE-FLOAT --*/
  15609. $e = "\xbb\xa4\xactype=image,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15610. // Clear properties - tidy up
  15611. $properties = array();
  15612. /*-- TABLES --*/
  15613. // Output it to buffers
  15614. if ($this->tableLevel) {
  15615. $this->_saveCellTextBuffer($e, $this->HREF); // mPDF 5.3.99
  15616. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  15617. }
  15618. else {
  15619. /*-- END TABLES --*/
  15620. $this->_saveTextBuffer($e, $this->HREF); // mPDF 5.3.99
  15621. } // *TABLES*
  15622. /*-- ANNOTATIONS --*/
  15623. if ($this->title2annots && isset($attr['TITLE'])) {
  15624. $objattr = array();
  15625. $objattr['margin_top'] = 0;
  15626. $objattr['margin_bottom'] = 0;
  15627. $objattr['margin_left'] = 0;
  15628. $objattr['margin_right'] = 0;
  15629. $objattr['width'] = 0;
  15630. $objattr['height'] = 0;
  15631. $objattr['border_top']['w'] = 0;
  15632. $objattr['border_bottom']['w'] = 0;
  15633. $objattr['border_left']['w'] = 0;
  15634. $objattr['border_right']['w'] = 0;
  15635. $objattr['CONTENT'] = $attr['TITLE'];
  15636. $objattr['type'] = 'annot';
  15637. $objattr['POS-X'] = 0;
  15638. $objattr['POS-Y'] = 0;
  15639. $objattr['ICON'] = 'Comment';
  15640. $objattr['AUTHOR'] = '';
  15641. $objattr['SUBJECT'] = '';
  15642. $objattr['OPACITY'] = $this->annotOpacity;
  15643. $objattr['COLOR'] = $this->ConvertColor('yellow');
  15644. $e = "\xbb\xa4\xactype=annot,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15645. if($this->tableLevel) { // *TABLES*
  15646. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); // *TABLES*
  15647. } // *TABLES*
  15648. else { // *TABLES*
  15649. $this->textbuffer[] = array($e);
  15650. } // *TABLES*
  15651. }
  15652. /*-- END ANNOTATIONS --*/
  15653. }
  15654. break;
  15655. /*-- END IMAGES-CORE --*/
  15656. // *********** CIRCULAR TEXT = TEXTCIRCLE ********************
  15657. // mPDF 5.3.A5
  15658. case 'TEXTCIRCLE':
  15659. $objattr = array();
  15660. $objattr['margin_top'] = 0;
  15661. $objattr['margin_bottom'] = 0;
  15662. $objattr['margin_left'] = 0;
  15663. $objattr['margin_right'] = 0;
  15664. $objattr['padding_top'] = 0;
  15665. $objattr['padding_bottom'] = 0;
  15666. $objattr['padding_left'] = 0;
  15667. $objattr['padding_right'] = 0;
  15668. $objattr['width'] = 0;
  15669. $objattr['height'] = 0;
  15670. $objattr['border_top']['w'] = 0;
  15671. $objattr['border_bottom']['w'] = 0;
  15672. $objattr['border_left']['w'] = 0;
  15673. $objattr['border_right']['w'] = 0;
  15674. $objattr['top-text'] = '';
  15675. $objattr['bottom-text'] = '';
  15676. $objattr['r'] = 20; // radius (default value here for safety)
  15677. $objattr['space-width'] = 120;
  15678. $objattr['char-width'] = 100;
  15679. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  15680. $properties = $this->MergeCSS('',$tag,$attr);
  15681. if(isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY'])=='none') {
  15682. return;
  15683. }
  15684. if (isset($attr['R'])) { $objattr['r']=$this->ConvertSize($attr['R'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15685. if(isset($attr['TOP-TEXT'])) {
  15686. $objattr['top-text'] = strcode2utf($attr['TOP-TEXT']);
  15687. $objattr['top-text'] = $this->lesser_entity_decode($objattr['top-text']);
  15688. if ($this->onlyCoreFonts)
  15689. $objattr['top-text'] = mb_convert_encoding($objattr['top-text'], $this->mb_enc,'UTF-8');
  15690. }
  15691. if(isset($attr['BOTTOM-TEXT'])) {
  15692. $objattr['bottom-text'] = strcode2utf($attr['BOTTOM-TEXT']);
  15693. $objattr['bottom-text'] = $this->lesser_entity_decode($objattr['bottom-text']);
  15694. if ($this->onlyCoreFonts)
  15695. $objattr['bottom-text'] = mb_convert_encoding($objattr['bottom-text'], $this->mb_enc,'UTF-8');
  15696. }
  15697. if(isset($attr['SPACE-WIDTH']) && $attr['SPACE-WIDTH']) { $objattr['space-width'] = $attr['SPACE-WIDTH']; }
  15698. if(isset($attr['CHAR-WIDTH']) && $attr['CHAR-WIDTH']) { $objattr['char-width'] = $attr['CHAR-WIDTH']; }
  15699. // VISIBILITY
  15700. $objattr['visibility'] = 'visible';
  15701. if (isset($properties['VISIBILITY'])) {
  15702. $v = strtolower($properties['VISIBILITY']);
  15703. if (($v == 'hidden' || $v == 'printonly' || $v == 'screenonly') && $this->visibility=='visible') {
  15704. $objattr['visibility'] = $v;
  15705. }
  15706. }
  15707. if (isset($properties['FONT-FAMILY'])) {
  15708. $this->SetFont($properties['FONT-FAMILY'],$this->FontStyle,0,false);
  15709. }
  15710. if (isset($properties['FONT-SIZE'])) {
  15711. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],($this->default_font_size/_MPDFK));
  15712. $this->SetFontSize($mmsize*_MPDFK,false);
  15713. }
  15714. if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  15715. $objattr['fontfamily'] = $this->FontFamily;
  15716. $objattr['fontsize'] = $this->FontSizePt;
  15717. $objattr['fontstyle'] = '';
  15718. if (isset($properties['FONT-WEIGHT'])) {
  15719. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $objattr['fontstyle'] .= 'B'; }
  15720. }
  15721. if (isset($properties['FONT-STYLE'])) {
  15722. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $objattr['fontstyle'] .= 'I'; }
  15723. }
  15724. // VSPACE and HSPACE converted to margins in MergeCSS
  15725. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15726. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15727. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15728. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15729. if (isset($properties['PADDING-TOP'])) { $objattr['padding_top']=$this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15730. if (isset($properties['PADDING-BOTTOM'])) { $objattr['padding_bottom'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15731. if (isset($properties['PADDING-LEFT'])) { $objattr['padding_left'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15732. if (isset($properties['PADDING-RIGHT'])) { $objattr['padding_right'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15733. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  15734. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  15735. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  15736. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  15737. if (isset($properties['OPACITY']) && $properties['OPACITY'] > 0 && $properties['OPACITY'] <= 1) { $objattr['opacity'] = $properties['OPACITY']; }
  15738. if (isset($properties['BACKGROUND-COLOR']) && $properties['BACKGROUND-COLOR'] != '') { $objattr['bgcolor'] = $this->ConvertColor($properties['BACKGROUND-COLOR']); }
  15739. else { $objattr['bgcolor'] = false; }
  15740. if ($this->HREF) { // mPDF 5.3.78
  15741. if (strpos($this->HREF,".") === false && strpos($this->HREF,"@") !== 0) {
  15742. $href = $this->HREF;
  15743. while(array_key_exists($href,$this->internallink)) $href="#".$href;
  15744. $this->internallink[$href] = $this->AddLink();
  15745. $objattr['link'] = $this->internallink[$href];
  15746. }
  15747. else { $objattr['link'] = $this->HREF; }
  15748. }
  15749. $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  15750. $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  15751. $w = $objattr['r']*2;
  15752. $h = $w;
  15753. $objattr['height'] = $h + $extraheight;
  15754. $objattr['width'] = $w + $extrawidth;
  15755. $objattr['type'] = 'textcircle';
  15756. $e = "\xbb\xa4\xactype=image,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15757. // Clear properties - tidy up
  15758. $properties = array();
  15759. /*-- TABLES --*/
  15760. // Output it to buffers
  15761. if ($this->tableLevel) {
  15762. $this->_saveCellTextBuffer($e, $this->HREF);
  15763. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  15764. }
  15765. else {
  15766. /*-- END TABLES --*/
  15767. $this->_saveTextBuffer($e, $this->HREF);
  15768. } // *TABLES*
  15769. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  15770. unset($this->InlineProperties[$tag]);
  15771. break;
  15772. /*-- TABLES --*/
  15773. case 'TABLE': // TABLE-BEGIN
  15774. $this->tdbegin = false;
  15775. $this->lastoptionaltag = '';
  15776. // Disable vertical justification in columns
  15777. if ($this->ColActive) { $this->colvAlign = ''; } // *COLUMNS*
  15778. if ($this->lastblocklevelchange == 1) { $blockstate = 1; } // Top margins/padding only
  15779. else if ($this->lastblocklevelchange < 1) { $blockstate = 0; } // NO margins/padding
  15780. // called from block after new div e.g. <div> ... <table> ... Outputs block top margin/border and padding
  15781. if (count($this->textbuffer) == 0 && $this->lastblocklevelchange == 1 && !$this->tableLevel && !$this->kwt) {
  15782. $this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,1,true, $this->blk[$this->blklvl]['direction']);
  15783. $this->finishFlowingBlock(true); // true = END of flowing block
  15784. }
  15785. else if (!$this->tableLevel && count($this->textbuffer)) { $this->printbuffer($this->textbuffer,$blockstate); }
  15786. $this->textbuffer=array();
  15787. $this->lastblocklevelchange = -1;
  15788. if ($this->tableLevel) { // i.e. now a nested table coming...
  15789. // Save current level table
  15790. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['baseProperties']= $this->base_table_properties;
  15791. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] = $this->cell;
  15792. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currrow'] = $this->row;
  15793. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currcol'] = $this->col;
  15794. }
  15795. $this->tableLevel++;
  15796. $this->tbCSSlvl++;
  15797. if ($this->tableLevel>1) { // inherit table properties from cell in which nested
  15798. $this->base_table_properties['FONT-KERNING'] = $this->kerning ;
  15799. $this->base_table_properties['LETTER-SPACING'] = $this->lSpacingCSS ;
  15800. $this->base_table_properties['WORD-SPACING'] = $this->wSpacingCSS ;
  15801. }
  15802. if (isset($this->tbctr[$this->tableLevel])) { $this->tbctr[$this->tableLevel]++; }
  15803. else { $this->tbctr[$this->tableLevel] = 1; }
  15804. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['level'] = $this->tableLevel;
  15805. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['levelid'] = $this->tbctr[$this->tableLevel];
  15806. if ($this->tableLevel > $this->innermostTableLevel) { $this->innermostTableLevel = $this->tableLevel; }
  15807. if ($this->tableLevel > 1) {
  15808. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nestedpos'] = array($this->row,$this->col,$this->tbctr[($this->tableLevel-1)]);
  15809. }
  15810. //++++++++++++++++++++++++++++
  15811. $this->cell = array();
  15812. $this->col=-1; //int
  15813. $this->row=-1; //int
  15814. $table = &$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]];
  15815. // mPDF 5.3.79
  15816. // New table - any level
  15817. if ($this->cacheTables) {
  15818. $this->packTableData = true; // required for cacheTables
  15819. $this->simpleTables = false; // Cannot co-exist with cacheTables
  15820. $table['cache'] = _MPDF_TEMP_PATH.'_tempTblCache'.RAND(1,1000000).'.dat';
  15821. $fh = fopen($table['cache'] , "wb") or $this->Error("When using cacheTables, you must have read/write access to cache files (".$table['cache'] .")");
  15822. fwrite($fh, "\x00");
  15823. fclose($fh);
  15824. $table['ptr'] = 1 ; // Must not be 0
  15825. }
  15826. $table['direction'] = $this->directionality;
  15827. $table['bgcolor'] = false;
  15828. $table['va'] = false;
  15829. $table['txta'] = false;
  15830. $table['topntail'] = false;
  15831. $table['thead-underline'] = false;
  15832. $table['border'] = false;
  15833. $table['border_details']['R']['w'] = 0;
  15834. $table['border_details']['L']['w'] = 0;
  15835. $table['border_details']['T']['w'] = 0;
  15836. $table['border_details']['B']['w'] = 0;
  15837. $table['border_details']['R']['style'] = '';
  15838. $table['border_details']['L']['style'] = '';
  15839. $table['border_details']['T']['style'] = '';
  15840. $table['border_details']['B']['style'] = '';
  15841. $table['max_cell_border_width']['R'] = 0;
  15842. $table['max_cell_border_width']['L'] = 0;
  15843. $table['max_cell_border_width']['T'] = 0;
  15844. $table['max_cell_border_width']['B'] = 0;
  15845. $table['padding']['L'] = false;
  15846. $table['padding']['R'] = false;
  15847. $table['padding']['T'] = false;
  15848. $table['padding']['B'] = false;
  15849. $table['margin']['L'] = false;
  15850. $table['margin']['R'] = false;
  15851. $table['margin']['T'] = false;
  15852. $table['margin']['B'] = false;
  15853. $table['a'] = false;
  15854. $table['border_spacing_H'] = false;
  15855. $table['border_spacing_V'] = false;
  15856. $this->Reset();
  15857. $this->InlineProperties = array();
  15858. $this->spanlvl = 0;
  15859. $table['nc'] = $table['nr'] = 0;
  15860. $this->tablethead = 0;
  15861. $this->tabletfoot = 0;
  15862. $this->tabletheadjustfinished = false;
  15863. if ($this->blockjustfinished && !count($this->textbuffer) && $this->y != $this->tMargin && $this->collapseBlockMargins && $this->tableLevel==1) { $lastbottommargin = $this->lastblockbottommargin; }
  15864. else { $lastbottommargin = 0; }
  15865. $this->lastblockbottommargin = 0;
  15866. $this->blockjustfinished=false;
  15867. if ($this->tableLevel==1) {
  15868. $this->tableCJK = false;
  15869. $this->table_lineheight = $this->normalLineheight;
  15870. $table['headernrows'] = 0; // mPDF 5.3.62
  15871. $table['footernrows'] = 0; // mPDF 5.3.62
  15872. $this->base_table_properties = array();
  15873. }
  15874. // ADDED CSS FUNCIONS FOR TABLE
  15875. if ($this->tbCSSlvl==1) {
  15876. $properties = $this->MergeCSS('TOPTABLE',$tag,$attr);
  15877. }
  15878. else {
  15879. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  15880. }
  15881. $w = '';
  15882. if (isset($properties['WIDTH'])) { $w = $properties['WIDTH']; }
  15883. if(isset($properties['DIRECTION']) && $properties['DIRECTION']) { $table['direction'] = strtolower($properties['DIRECTION']); }
  15884. if(isset($attr['DIR']) && $attr['DIR']) { $table['direction'] = strtolower($attr['DIR']); }
  15885. else if (!isset($table['direction'])){ $table['direction'] = $this->blk[$this->blklvl]['direction']; }
  15886. if (isset($properties['BACKGROUND-COLOR'])) { $table['bgcolor'][-1] = $properties['BACKGROUND-COLOR']; }
  15887. else if (isset($properties['BACKGROUND'])) { $table['bgcolor'][-1] = $properties['BACKGROUND']; }
  15888. if (isset($properties['VERTICAL-ALIGN'])) { $table['va'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  15889. if (isset($properties['TEXT-ALIGN'])) { $table['txta'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  15890. if (isset($properties['AUTOSIZE']) && $properties['AUTOSIZE'] && $this->tableLevel ==1) {
  15891. $this->shrink_this_table_to_fit = $properties['AUTOSIZE'];
  15892. if ($this->shrink_this_table_to_fit < 1) { $this->shrink_this_table_to_fit = 0; }
  15893. }
  15894. if (isset($properties['ROTATE']) && $properties['ROTATE'] && $this->tableLevel ==1) {
  15895. $this->table_rotate = $properties['ROTATE'];
  15896. }
  15897. if (isset($properties['TOPNTAIL'])) { $table['topntail'] = $properties['TOPNTAIL']; }
  15898. if (isset($properties['THEAD-UNDERLINE'])) { $table['thead-underline'] = $properties['THEAD-UNDERLINE']; }
  15899. if (isset($properties['BORDER'])) {
  15900. $bord = $this->border_details($properties['BORDER']);
  15901. if ($bord['s']) {
  15902. $table['border'] = _BORDER_ALL;
  15903. $table['border_details']['R'] = $bord;
  15904. $table['border_details']['L'] = $bord;
  15905. $table['border_details']['T'] = $bord;
  15906. $table['border_details']['B'] = $bord;
  15907. }
  15908. }
  15909. if (isset($properties['BORDER-RIGHT'])) {
  15910. if ($table['direction'] == 'rtl') { // *RTL*
  15911. $table['border_details']['R'] = $this->border_details($properties['BORDER-LEFT']); // *RTL*
  15912. } // *RTL*
  15913. else { // *RTL*
  15914. $table['border_details']['R'] = $this->border_details($properties['BORDER-RIGHT']);
  15915. } // *RTL*
  15916. $this->setBorder($table['border'], _BORDER_RIGHT, $table['border_details']['R']['s']);
  15917. }
  15918. if (isset($properties['BORDER-LEFT'])) {
  15919. if ($table['direction'] == 'rtl') { // *RTL*
  15920. $table['border_details']['L'] = $this->border_details($properties['BORDER-RIGHT']); // *RTL*
  15921. } // *RTL*
  15922. else { // *RTL*
  15923. $table['border_details']['L'] = $this->border_details($properties['BORDER-LEFT']);
  15924. } // *RTL*
  15925. $this->setBorder($table['border'], _BORDER_LEFT, $table['border_details']['L']['s']);
  15926. }
  15927. if (isset($properties['BORDER-BOTTOM'])) {
  15928. $table['border_details']['B'] = $this->border_details($properties['BORDER-BOTTOM']);
  15929. $this->setBorder($table['border'], _BORDER_BOTTOM, $table['border_details']['B']['s']);
  15930. }
  15931. if (isset($properties['BORDER-TOP'])) {
  15932. $table['border_details']['T'] = $this->border_details($properties['BORDER-TOP']);
  15933. $this->setBorder($table['border'], _BORDER_TOP, $table['border_details']['T']['s']);
  15934. }
  15935. if ($table['border']){
  15936. $this->table_border_css_set = 1;
  15937. }
  15938. else {
  15939. $this->table_border_css_set = 0;
  15940. }
  15941. if (isset($properties['FONT-FAMILY'])) {
  15942. $this->default_font = $properties['FONT-FAMILY'];
  15943. $this->SetFont($this->default_font,'',0,false);
  15944. $this->base_table_properties['FONT-FAMILY'] = $properties['FONT-FAMILY'];
  15945. }
  15946. if (isset($properties['FONT-SIZE'])) {
  15947. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/_MPDFK);
  15948. if ($mmsize) {
  15949. $this->default_font_size = $mmsize*(_MPDFK);
  15950. $this->SetFontSize($this->default_font_size,false);
  15951. $this->base_table_properties['FONT-SIZE'] = $properties['FONT-SIZE'];
  15952. }
  15953. }
  15954. if (isset($properties['FONT-WEIGHT'])) {
  15955. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->base_table_properties['FONT-WEIGHT'] = 'BOLD'; }
  15956. }
  15957. if (isset($properties['FONT-STYLE'])) {
  15958. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->base_table_properties['FONT-STYLE'] = 'ITALIC'; }
  15959. }
  15960. if (isset($properties['COLOR'])) {
  15961. $this->base_table_properties['COLOR'] = $properties['COLOR'];
  15962. }
  15963. if (isset($properties['FONT-KERNING'])) {
  15964. $this->base_table_properties['FONT-KERNING'] = $properties['FONT-KERNING'];
  15965. }
  15966. if (isset($properties['LETTER-SPACING'])) {
  15967. $this->base_table_properties['LETTER-SPACING'] = $properties['LETTER-SPACING'];
  15968. }
  15969. if (isset($properties['WORD-SPACING'])) {
  15970. $this->base_table_properties['WORD-SPACING'] = $properties['WORD-SPACING'];
  15971. }
  15972. if (isset($properties['PADDING-LEFT'])) {
  15973. $table['padding']['L'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15974. }
  15975. if (isset($properties['PADDING-RIGHT'])) {
  15976. $table['padding']['R'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15977. }
  15978. if (isset($properties['PADDING-TOP'])) {
  15979. $table['padding']['T'] = $this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15980. }
  15981. if (isset($properties['PADDING-BOTTOM'])) {
  15982. $table['padding']['B'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15983. }
  15984. if (isset($properties['MARGIN-TOP'])) {
  15985. if ($lastbottommargin) {
  15986. $tmp = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15987. if ($tmp > $lastbottommargin) { $properties['MARGIN-TOP'] -= $lastbottommargin; }
  15988. else { $properties['MARGIN-TOP'] = 0; }
  15989. }
  15990. $table['margin']['T'] = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15991. }
  15992. if (isset($properties['MARGIN-BOTTOM'])) {
  15993. $table['margin']['B'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15994. }
  15995. if (isset($properties['MARGIN-LEFT'])) {
  15996. $table['margin']['L'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15997. }
  15998. if (isset($properties['MARGIN-RIGHT'])) {
  15999. $table['margin']['R'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16000. }
  16001. if (isset($properties['MARGIN-LEFT']) && isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-LEFT'])=='auto' && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  16002. $table['a'] = 'C';
  16003. }
  16004. else if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  16005. $table['a'] = 'R';
  16006. }
  16007. else if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  16008. $table['a'] = 'L';
  16009. }
  16010. if (isset($properties['LINE-HEIGHT']) && $this->tableLevel==1) {
  16011. $this->table_lineheight = $this->fixLineheight($properties['LINE-HEIGHT']);
  16012. if (!$this->table_lineheight) { $this->table_lineheight = $this->normalLineheight; }
  16013. }
  16014. if (isset($properties['BORDER-COLLAPSE']) && strtoupper($properties['BORDER-COLLAPSE'])=='SEPARATE') {
  16015. $table['borders_separate'] = true;
  16016. }
  16017. else {
  16018. $table['borders_separate'] = false;
  16019. }
  16020. if (isset($properties['BORDER-SPACING-H'])) {
  16021. $table['border_spacing_H'] = $this->ConvertSize($properties['BORDER-SPACING-H'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16022. }
  16023. if (isset($properties['BORDER-SPACING-V'])) {
  16024. $table['border_spacing_V'] = $this->ConvertSize($properties['BORDER-SPACING-V'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16025. }
  16026. if (isset($properties['EMPTY-CELLS'])) {
  16027. $table['empty_cells'] = strtolower($properties['EMPTY-CELLS']); // 'hide' or 'show'
  16028. }
  16029. else { $table['empty_cells'] = ''; }
  16030. if (isset($properties['PAGE-BREAK-INSIDE']) && strtoupper($properties['PAGE-BREAK-INSIDE'])=='AVOID' && $this->tableLevel==1 && !$this->writingHTMLfooter) {
  16031. $this->table_keep_together = true;
  16032. }
  16033. else if ($this->tableLevel==1) {
  16034. $this->table_keep_together = false;
  16035. }
  16036. // mPDF 5.3.55
  16037. if (isset($properties['PAGE-BREAK-AFTER']) && $this->tableLevel==1) {
  16038. $table['page_break_after'] = strtoupper($properties['PAGE-BREAK-AFTER']);
  16039. }
  16040. /*-- BACKGROUNDS --*/
  16041. if (isset($properties['BACKGROUND-GRADIENT']) && !$this->kwt && !$this->ColActive) { $table['gradient'] = $properties['BACKGROUND-GRADIENT']; }
  16042. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->kwt && !$this->ColActive) {
  16043. $ret = $this->SetBackground($properties, $currblk['inner_width']);
  16044. if ($ret) { $table['background-image'] = $ret; }
  16045. }
  16046. /*-- END BACKGROUNDS --*/
  16047. if (isset($properties['OVERFLOW'])) {
  16048. $table['overflow'] = strtolower($properties['OVERFLOW']); // 'hidden' 'wrap' or 'visible' or 'auto'
  16049. if (($this->ColActive || $this->tableLevel>1) && $table['overflow']=='visible') { unset($table['overflow']); } // mPDF 5.3.36
  16050. }
  16051. $properties = array();
  16052. if (!$table['borders_separate']) { $table['border_spacing_H'] = $table['border_spacing_V'] = 0; }
  16053. else if (isset($attr['CELLSPACING'])) {
  16054. $table['border_spacing_H'] = $table['border_spacing_V'] = $this->ConvertSize($attr['CELLSPACING'],$this->blk[$this->blklvl]['inner_width']);
  16055. }
  16056. if (isset($attr['CELLPADDING'])) {
  16057. $table['cell_padding'] = $attr['CELLPADDING'];
  16058. }
  16059. else {
  16060. $table['cell_padding'] = false;
  16061. }
  16062. if (isset($attr['BORDER'])) {
  16063. $this->table_border_attr_set = 1;
  16064. if ($attr['BORDER']=='1') {
  16065. $bord = $this->border_details('#000000 1px solid');
  16066. if ($bord['s']) {
  16067. $table['border'] = _BORDER_ALL;
  16068. $table['border_details']['R'] = $bord;
  16069. $table['border_details']['L'] = $bord;
  16070. $table['border_details']['T'] = $bord;
  16071. $table['border_details']['B'] = $bord;
  16072. }
  16073. }
  16074. }
  16075. else {
  16076. $this->table_border_attr_set = 0;
  16077. }
  16078. if (isset($attr['ALIGN'])) { $table['a'] = $align[strtolower($attr['ALIGN'])]; }
  16079. if (!$table['a']) {
  16080. if ($table['direction'] == 'rtl' ) { $table['a'] = 'R'; }
  16081. else { $table['a'] = 'L'; }
  16082. }
  16083. if (isset($attr['BGCOLOR'])) { $table['bgcolor'][-1] = $attr['BGCOLOR']; }
  16084. if (isset($attr['WIDTH']) && $attr['WIDTH']) { $w = $attr['WIDTH']; }
  16085. if ($w) { // set here or earlier in $properties
  16086. $maxwidth = $this->blk[$this->blklvl]['inner_width'];
  16087. if ($table['borders_separate']) {
  16088. $tblblw = $table['margin']['L'] + $table['margin']['R'] + $table['border_details']['L']['w']/2 + $table['border_details']['R']['w']/2;
  16089. }
  16090. else {
  16091. $tblblw = $table['margin']['L'] + $table['margin']['R'] + $table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2;
  16092. }
  16093. if (strpos($w,'%') && $this->tableLevel == 1 && !$this->ignore_table_percents ) {
  16094. // % needs to be of inner box without table margins etc.
  16095. $maxwidth -= $tblblw ;
  16096. $wmm = $this->ConvertSize($w,$maxwidth,$this->FontSize,false);
  16097. $table['w'] = $wmm + $tblblw ;
  16098. }
  16099. if (strpos($w,'%') && $this->tableLevel > 1 && !$this->ignore_table_percents && $this->keep_table_proportions) {
  16100. $table['wpercent'] = $w + 0; // makes 80% -> 80
  16101. }
  16102. if (!strpos($w,'%') && !$this->ignore_table_widths ) {
  16103. $wmm = $this->ConvertSize($w,$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16104. $table['w'] = $wmm + $tblblw ;
  16105. }
  16106. if (!$this->keep_table_proportions) {
  16107. if (isset($table['w']) && $table['w'] > $this->blk[$this->blklvl]['inner_width']) { $table['w'] = $this->blk[$this->blklvl]['inner_width']; }
  16108. }
  16109. }
  16110. if (isset($attr['AUTOSIZE']) && $this->tableLevel==1) {
  16111. $this->shrink_this_table_to_fit = $attr['AUTOSIZE'];
  16112. if ($this->shrink_this_table_to_fit < 1) { $this->shrink_this_table_to_fit = 1; }
  16113. }
  16114. if (isset($attr['ROTATE']) && $this->tableLevel==1) {
  16115. $this->table_rotate = $attr['ROTATE'];
  16116. }
  16117. //++++++++++++++++++++++++++++
  16118. // keeping block together on one page
  16119. // Autosize is now forced therefore keep block together disabled
  16120. if ($this->keep_block_together) {
  16121. $this->keep_block_together = 0;
  16122. $this->printdivbuffer();
  16123. $this->blk[$this->blklvl]['keep_block_together'] = 0;
  16124. }
  16125. if ($this->table_rotate) {
  16126. $this->tbrot_Links = array();
  16127. $this->tbrot_Annots = array();
  16128. $this->tbrotForms = array();
  16129. $this->tbrot_Reference = array();
  16130. $this->tbrot_BMoutlines = array();
  16131. $this->tbrot_toc = array();
  16132. }
  16133. if ($this->kwt) {
  16134. if ($this->table_rotate) { $this->table_keep_together = true; }
  16135. $this->kwt = false;
  16136. $this->kwt_saved = true;
  16137. }
  16138. if ($this->tableLevel==1 && $this->useGraphs) {
  16139. if (isset($attr['ID']) && $attr['ID']) { $this->currentGraphId = strtoupper($attr['ID']); }
  16140. else { $this->currentGraphId = '0'; }
  16141. $this->graphs[$this->currentGraphId] = array();
  16142. }
  16143. //++++++++++++++++++++++++++++
  16144. $this->plainCell_properties = array();
  16145. unset($table); // mPDF 5.3.76
  16146. break;
  16147. case 'THEAD':
  16148. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16149. $this->tbCSSlvl++;
  16150. $this->tablethead = 1;
  16151. $this->tabletfoot = 0;
  16152. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  16153. if (isset($properties['FONT-WEIGHT'])) {
  16154. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->thead_font_weight = 'B'; }
  16155. else { $this->thead_font_weight = ''; }
  16156. }
  16157. if (isset($properties['FONT-STYLE'])) {
  16158. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->thead_font_style = 'I'; }
  16159. else { $this->thead_font_style = ''; }
  16160. }
  16161. if (isset($properties['FONT-VARIANT'])) {
  16162. if (strtoupper($properties['FONT-VARIANT']) == 'SMALL-CAPS') { $this->thead_font_smCaps = 'S'; }
  16163. else { $this->thead_font_smCaps = ''; }
  16164. }
  16165. if (isset($properties['VERTICAL-ALIGN'])) {
  16166. $this->thead_valign_default = $properties['VERTICAL-ALIGN'];
  16167. }
  16168. if (isset($properties['TEXT-ALIGN'])) {
  16169. $this->thead_textalign_default = $properties['TEXT-ALIGN'];
  16170. }
  16171. $properties = array();
  16172. break;
  16173. case 'TFOOT':
  16174. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16175. $this->tbCSSlvl++;
  16176. $this->tabletfoot = 1;
  16177. $this->tablethead = 0;
  16178. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  16179. if (isset($properties['FONT-WEIGHT'])) {
  16180. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->tfoot_font_weight = 'B'; }
  16181. else { $this->tfoot_font_weight = ''; }
  16182. }
  16183. if (isset($properties['FONT-STYLE'])) {
  16184. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->tfoot_font_style = 'I'; }
  16185. else { $this->tfoot_font_style = ''; }
  16186. }
  16187. if (isset($properties['FONT-VARIANT'])) {
  16188. if (strtoupper($properties['FONT-VARIANT']) == 'SMALL-CAPS') { $this->tfoot_font_smCaps = 'S'; }
  16189. else { $this->tfoot_font_smCaps = ''; }
  16190. }
  16191. if (isset($properties['VERTICAL-ALIGN'])) {
  16192. $this->tfoot_valign_default = $properties['VERTICAL-ALIGN'];
  16193. }
  16194. if (isset($properties['TEXT-ALIGN'])) {
  16195. $this->tfoot_textalign_default = $properties['TEXT-ALIGN'];
  16196. }
  16197. $properties = array();
  16198. break;
  16199. case 'TBODY':
  16200. $this->tablethead = 0;
  16201. $this->tabletfoot = 0;
  16202. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16203. $this->tbCSSlvl++;
  16204. $this->MergeCSS('TABLE',$tag,$attr);
  16205. break;
  16206. case 'TR':
  16207. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16208. $this->tbCSSlvl++;
  16209. $this->row++;
  16210. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr']++;
  16211. $this->col = -1;
  16212. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  16213. if (!$this->simpleTables && (!isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['borders_separate']) || !$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['borders_separate'])) {
  16214. if (isset($properties['BORDER-LEFT']) && $properties['BORDER-LEFT']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-left'][$this->row] = $properties['BORDER-LEFT']; }
  16215. if (isset($properties['BORDER-RIGHT']) && $properties['BORDER-RIGHT']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-right'][$this->row] = $properties['BORDER-RIGHT']; }
  16216. if (isset($properties['BORDER-TOP']) && $properties['BORDER-TOP']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-top'][$this->row] = $properties['BORDER-TOP']; }
  16217. if (isset($properties['BORDER-BOTTOM']) && $properties['BORDER-BOTTOM']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-bottom'][$this->row] = $properties['BORDER-BOTTOM']; }
  16218. }
  16219. if (isset($properties['BACKGROUND-COLOR'])) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$this->row] = $properties['BACKGROUND-COLOR']; }
  16220. /*-- BACKGROUNDS --*/
  16221. if (isset($properties['BACKGROUND-GRADIENT']) && !$this->kwt && !$this->ColActive) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'][$this->row] = $properties['BACKGROUND-GRADIENT']; }
  16222. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->kwt && !$this->ColActive) {
  16223. $ret = $this->SetBackground($properties, $currblk['inner_width']);
  16224. if ($ret) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'][$this->row] = $ret; }
  16225. }
  16226. /*-- END BACKGROUNDS --*/
  16227. if (isset($properties['TEXT-ROTATE'])) {
  16228. $this->trow_text_rotate = $properties['TEXT-ROTATE'];
  16229. }
  16230. if (isset($attr['TEXT-ROTATE'])) $this->trow_text_rotate = $attr['TEXT-ROTATE'];
  16231. if (isset($attr['BGCOLOR'])) $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$this->row] = $attr['BGCOLOR'];
  16232. if ($this->tablethead) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead'][$this->row] = true; }
  16233. if ($this->tabletfoot) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'][$this->row] = true; }
  16234. $properties = array();
  16235. break;
  16236. // mPDF 5.3.75
  16237. case 'TH':
  16238. case 'TD':
  16239. $this->ignorefollowingspaces = true;
  16240. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16241. $this->tbCSSlvl++;
  16242. $this->InlineProperties = array();
  16243. $this->spanlvl = 0;
  16244. $this->tdbegin = true;
  16245. $this->col++;
  16246. while (isset($this->cell[$this->row][$this->col])) { $this->col++; }
  16247. //Update number column
  16248. if ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'] < $this->col+1) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'] = $this->col+1; }
  16249. $table = &$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]];
  16250. // mPDF 5.3.77
  16251. $c = array('a' => false,
  16252. 'R' => false,
  16253. 'nowrap' => false,
  16254. 'bgcolor' => false,
  16255. 'padding' => array('L' => false,
  16256. 'R' => false,
  16257. 'T' => false,
  16258. 'B' => false
  16259. )
  16260. );
  16261. if ($this->simpleTables && $this->row==0 && $this->col==0){
  16262. $table['simple']['border'] = false;
  16263. $table['simple']['border_details']['R']['w'] = 0;
  16264. $table['simple']['border_details']['L']['w'] = 0;
  16265. $table['simple']['border_details']['T']['w'] = 0;
  16266. $table['simple']['border_details']['B']['w'] = 0;
  16267. $table['simple']['border_details']['R']['style'] = '';
  16268. $table['simple']['border_details']['L']['style'] = '';
  16269. $table['simple']['border_details']['T']['style'] = '';
  16270. $table['simple']['border_details']['B']['style'] = '';
  16271. }
  16272. else if (!$this->simpleTables) {
  16273. $c['border'] = false;
  16274. $c['border_details']['R']['w'] = 0;
  16275. $c['border_details']['L']['w'] = 0;
  16276. $c['border_details']['T']['w'] = 0;
  16277. $c['border_details']['B']['w'] = 0;
  16278. $c['border_details']['mbw']['BL'] = 0;
  16279. $c['border_details']['mbw']['BR'] = 0;
  16280. $c['border_details']['mbw']['RT'] = 0;
  16281. $c['border_details']['mbw']['RB'] = 0;
  16282. $c['border_details']['mbw']['TL'] = 0;
  16283. $c['border_details']['mbw']['TR'] = 0;
  16284. $c['border_details']['mbw']['LT'] = 0;
  16285. $c['border_details']['mbw']['LB'] = 0;
  16286. $c['border_details']['R']['style'] = '';
  16287. $c['border_details']['L']['style'] = '';
  16288. $c['border_details']['T']['style'] = '';
  16289. $c['border_details']['B']['style'] = '';
  16290. $c['border_details']['R']['s'] = 0;
  16291. $c['border_details']['L']['s'] = 0;
  16292. $c['border_details']['T']['s'] = 0;
  16293. $c['border_details']['B']['s'] = 0;
  16294. $c['border_details']['R']['c'] = $this->ConvertColor(0);
  16295. $c['border_details']['L']['c'] = $this->ConvertColor(0);
  16296. $c['border_details']['T']['c'] = $this->ConvertColor(0);
  16297. $c['border_details']['B']['c'] = $this->ConvertColor(0);
  16298. $c['border_details']['R']['dom'] = 0;
  16299. $c['border_details']['L']['dom'] = 0;
  16300. $c['border_details']['T']['dom'] = 0;
  16301. $c['border_details']['B']['dom'] = 0;
  16302. }
  16303. if ($table['va']) { $c['va'] = $table['va']; }
  16304. if ($table['txta']) { $c['a'] = $table['txta']; }
  16305. if ($this->table_border_attr_set) {
  16306. if ($table['border_details']) {
  16307. if (!$this->simpleTables){
  16308. $c['border_details']['R'] = $table['border_details']['R'];
  16309. $c['border_details']['L'] = $table['border_details']['L'];
  16310. $c['border_details']['T'] = $table['border_details']['T'];
  16311. $c['border_details']['B'] = $table['border_details']['B'];
  16312. $c['border'] = $table['border'];
  16313. $c['border_details']['L']['dom'] = 1;
  16314. $c['border_details']['R']['dom'] = 1;
  16315. $c['border_details']['T']['dom'] = 1;
  16316. $c['border_details']['B']['dom'] = 1;
  16317. }
  16318. else if ($this->simpleTables && $this->row==0 && $this->col==0){
  16319. $table['simple']['border_details']['R'] = $table['border_details']['R'];
  16320. $table['simple']['border_details']['L'] = $table['border_details']['L'];
  16321. $table['simple']['border_details']['T'] = $table['border_details']['T'];
  16322. $table['simple']['border_details']['B'] = $table['border_details']['B'];
  16323. $table['simple']['border'] = $table['border'];
  16324. }
  16325. }
  16326. }
  16327. // INHERITED THEAD CSS Properties
  16328. if ($this->tablethead) {
  16329. if ($this->thead_valign_default) $c['va'] = $align[strtolower($this->thead_valign_default)];
  16330. if ($this->thead_textalign_default) $c['a'] = $align[strtolower($this->thead_textalign_default)];
  16331. if ($this->thead_font_weight == 'B') { $this->SetStyle('B',true); }
  16332. if ($this->thead_font_style == 'I') { $this->SetStyle('I',true); }
  16333. if ($this->thead_font_smCaps == 'S') { $this->SetStyle('S',true); } // mPDF 5.3.76
  16334. }
  16335. // INHERITED TFOOT CSS Properties
  16336. if ($this->tabletfoot) {
  16337. if ($this->tfoot_valign_default) $c['va'] = $align[strtolower($this->tfoot_valign_default)];
  16338. if ($this->tfoot_textalign_default) $c['a'] = $align[strtolower($this->tfoot_textalign_default)];
  16339. if ($this->tfoot_font_weight == 'B') { $this->SetStyle('B',true); }
  16340. if ($this->tfoot_font_style == 'I') { $this->SetStyle('I',true); }
  16341. if ($this->tfoot_font_style == 'S') { $this->SetStyle('S',true); }
  16342. }
  16343. if ($this->trow_text_rotate){
  16344. $c['R'] = $this->trow_text_rotate;
  16345. }
  16346. $this->cell_border_dominance_L = 0;
  16347. $this->cell_border_dominance_R = 0;
  16348. $this->cell_border_dominance_T = 0;
  16349. $this->cell_border_dominance_B = 0;
  16350. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  16351. $properties = $this->array_merge_recursive_unique($this->base_table_properties, $properties);
  16352. if (isset($properties['FONT-KERNING']) && (strtoupper($properties['FONT-KERNING'])=='NORMAL' || strtoupper($properties['FONT-KERNING'])=='AUTO')) {
  16353. $this->kerning = true;
  16354. }
  16355. else { $this->kerning = false; }
  16356. if (isset($properties['LETTER-SPACING']) && ($properties['LETTER-SPACING'] || $properties['LETTER-SPACING']==='0') && strtoupper($properties['LETTER-SPACING']) != 'NORMAL') {
  16357. $this->lSpacingCSS = strtoupper($properties['LETTER-SPACING']);
  16358. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  16359. }
  16360. else {
  16361. $this->lSpacingCSS = '';
  16362. $this->fixedlSpacing = false;
  16363. }
  16364. if (isset($properties['WORD-SPACING']) && strtoupper($properties['WORD-SPACING']) != 'NORMAL') {
  16365. $this->wSpacingCSS = strtoupper($properties['WORD-SPACING']);
  16366. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  16367. }
  16368. else {
  16369. $this->minwSpacing = 0;
  16370. $this->wSpacingCSS = '';
  16371. }
  16372. if (isset($properties['BACKGROUND-COLOR'])) { $c['bgcolor'] = $properties['BACKGROUND-COLOR']; }
  16373. else if (isset($properties['BACKGROUND'])) { $c['bgcolor'] = $properties['BACKGROUND']; }
  16374. /*-- BACKGROUNDS --*/
  16375. if (isset($properties['BACKGROUND-GRADIENT'])) { $c['gradient'] = $properties['BACKGROUND-GRADIENT']; }
  16376. else { $c['gradient'] = false; }
  16377. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->keep_block_together) {
  16378. $ret = $this->SetBackground($properties, $this->blk[$this->blklvl]['inner_width']);
  16379. if ($ret) { $c['background-image'] = $ret; }
  16380. }
  16381. /*-- END BACKGROUNDS --*/
  16382. if (isset($properties['VERTICAL-ALIGN'])) { $c['va']=$align[strtolower($properties['VERTICAL-ALIGN'])]; }
  16383. if (isset($properties['TEXT-ALIGN'])) { $c['a'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  16384. if (isset($properties['TEXT-ROTATE']) && ($properties['TEXT-ROTATE'] || $properties['TEXT-ROTATE']==="0")){
  16385. $c['R'] = $properties['TEXT-ROTATE'];
  16386. }
  16387. if (isset($properties['BORDER'])) {
  16388. $bord = $this->border_details($properties['BORDER']);
  16389. if ($bord['s']) {
  16390. if (!$this->simpleTables){
  16391. $c['border'] = _BORDER_ALL;
  16392. $c['border_details']['R'] = $bord;
  16393. $c['border_details']['L'] = $bord;
  16394. $c['border_details']['T'] = $bord;
  16395. $c['border_details']['B'] = $bord;
  16396. $c['border_details']['L']['dom'] = $this->cell_border_dominance_L;
  16397. $c['border_details']['R']['dom'] = $this->cell_border_dominance_R;
  16398. $c['border_details']['T']['dom'] = $this->cell_border_dominance_T;
  16399. $c['border_details']['B']['dom'] = $this->cell_border_dominance_B;
  16400. }
  16401. else if ($this->simpleTables && $this->row==0 && $this->col==0){
  16402. $table['simple']['border'] = _BORDER_ALL;
  16403. $table['simple']['border_details']['R'] = $bord;
  16404. $table['simple']['border_details']['L'] = $bord;
  16405. $table['simple']['border_details']['T'] = $bord;
  16406. $table['simple']['border_details']['B'] = $bord;
  16407. }
  16408. }
  16409. }
  16410. if (!$this->simpleTables){
  16411. if (isset($properties['BORDER-RIGHT']) && $properties['BORDER-RIGHT']) {
  16412. $c['border_details']['R'] = $this->border_details($properties['BORDER-RIGHT']);
  16413. $this->setBorder($c['border'], _BORDER_RIGHT, $c['border_details']['R']['s']);
  16414. $c['border_details']['R']['dom'] = $this->cell_border_dominance_R;
  16415. }
  16416. if (isset($properties['BORDER-LEFT']) && $properties['BORDER-LEFT']) {
  16417. $c['border_details']['L'] = $this->border_details($properties['BORDER-LEFT']);
  16418. $this->setBorder($c['border'], _BORDER_LEFT, $c['border_details']['L']['s']);
  16419. $c['border_details']['L']['dom'] = $this->cell_border_dominance_L;
  16420. }
  16421. if (isset($properties['BORDER-BOTTOM']) && $properties['BORDER-BOTTOM']) {
  16422. $c['border_details']['B'] = $this->border_details($properties['BORDER-BOTTOM']);
  16423. $this->setBorder($c['border'], _BORDER_BOTTOM, $c['border_details']['B']['s']);
  16424. $c['border_details']['B']['dom'] = $this->cell_border_dominance_B;
  16425. }
  16426. if (isset($properties['BORDER-TOP']) && $properties['BORDER-TOP']) {
  16427. $c['border_details']['T'] = $this->border_details($properties['BORDER-TOP']);
  16428. $this->setBorder($c['border'], _BORDER_TOP, $c['border_details']['T']['s']);
  16429. $c['border_details']['T']['dom'] = $this->cell_border_dominance_T;
  16430. }
  16431. }
  16432. else if ($this->simpleTables && $this->row==0 && $this->col==0){
  16433. if (isset($properties['BORDER-LEFT']) && $properties['BORDER-LEFT']) {
  16434. $bord = $this->border_details($properties['BORDER-LEFT']);
  16435. if ($bord['s']) { $table['simple']['border'] = _BORDER_ALL; }
  16436. else { $table['simple']['border'] = 0; }
  16437. $table['simple']['border_details']['R'] = $bord;
  16438. $table['simple']['border_details']['L'] = $bord;
  16439. $table['simple']['border_details']['T'] = $bord;
  16440. $table['simple']['border_details']['B'] = $bord;
  16441. }
  16442. }
  16443. // mPDF 5.3.15
  16444. if ($this->simpleTables && $this->row==0 && $this->col==0 && !$table['borders_separate'] && $table['simple']['border'] ){
  16445. $table['border_details'] = $table['simple']['border_details'];
  16446. $table['border'] = $table['simple']['border'];
  16447. }
  16448. // mPDF 5.3.78
  16449. // Border set on TR (if collapsed only)
  16450. if (!$table['borders_separate'] && !$this->simpleTables && isset($table['trborder-left'][$this->row])) {
  16451. if ($this->col==0) {
  16452. $left = $this->border_details($table['trborder-left'][$this->row]);
  16453. $c['border_details']['L'] = $left;
  16454. $this->setBorder($c['border'], _BORDER_LEFT, $c['border_details']['L']['s']);
  16455. }
  16456. $c['border_details']['B'] = $this->border_details($table['trborder-bottom'][$this->row]);
  16457. $this->setBorder($c['border'], _BORDER_BOTTOM, $c['border_details']['B']['s']);
  16458. $c['border_details']['T'] = $this->border_details($table['trborder-top'][$this->row]);
  16459. $this->setBorder($c['border'], _BORDER_TOP, $c['border_details']['T']['s']);
  16460. }
  16461. if ($this->packTableData && !$this->simpleTables) {
  16462. $c['borderbin'] = $this->_packCellBorder($c);
  16463. unset($c['border']);
  16464. unset($c['border_details']);
  16465. }
  16466. if (isset($properties['PADDING-LEFT'])) {
  16467. $c['padding']['L'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16468. }
  16469. if (isset($properties['PADDING-RIGHT'])) {
  16470. $c['padding']['R'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16471. }
  16472. if (isset($properties['PADDING-BOTTOM'])) {
  16473. $c['padding']['B'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16474. }
  16475. if (isset($properties['PADDING-TOP'])) {
  16476. $c['padding']['T'] = $this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16477. }
  16478. $w = '';
  16479. if (isset($properties['WIDTH'])) { $w = $properties['WIDTH']; }
  16480. if (isset($attr['WIDTH'])) { $w = $attr['WIDTH']; }
  16481. if ($w) {
  16482. if (strpos($w,'%') && !$this->ignore_table_percents ) { $c['wpercent'] = $w + 0; } // makes 80% -> 80
  16483. else if (!strpos($w,'%') && !$this->ignore_table_widths ) { $c['w'] = $this->ConvertSize($w,$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  16484. }
  16485. if (isset($properties['HEIGHT']) && !strpos($properties['HEIGHT'],'%')) { $c['h'] = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } // mPDF 5.3.57
  16486. if (isset($properties['COLOR'])) {
  16487. $cor = $this->ConvertColor($properties['COLOR']);
  16488. if ($cor) {
  16489. $this->colorarray = $cor;
  16490. $this->SetTColor($cor);
  16491. }
  16492. }
  16493. if (isset($properties['FONT-FAMILY'])) {
  16494. $this->SetFont($properties['FONT-FAMILY'],'',0,false);
  16495. }
  16496. if (isset($properties['FONT-SIZE'])) {
  16497. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/_MPDFK);
  16498. if ($mmsize) {
  16499. $this->SetFontSize($mmsize*(_MPDFK),false);
  16500. }
  16501. }
  16502. $c['dfs'] = $this->FontSize; // Default Font size
  16503. if (isset($properties['FONT-WEIGHT'])) {
  16504. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->SetStyle('B',true); }
  16505. }
  16506. if (isset($properties['FONT-STYLE'])) {
  16507. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->SetStyle('I',true); }
  16508. }
  16509. if (isset($properties['FONT-VARIANT'])) {
  16510. if (strtoupper($properties['FONT-VARIANT']) == 'SMALL-CAPS') { $this->SetStyle('S',true); }
  16511. }
  16512. // mPDF 5.3.34
  16513. if (isset($properties['TEXT-DECORATION'])) {
  16514. if (strtoupper($properties['TEXT-DECORATION']) == 'LINE-THROUGH') { $this->strike = true; }
  16515. else if (strtoupper($properties['TEXT-DECORATION']) == 'UNDERLINE') { $this->SetStyle('U',true); }
  16516. }
  16517. // mPDF 5.3.A2
  16518. if (isset($properties['TEXT-SHADOW'])) {
  16519. $ts = $this->setCSStextshadow($properties['TEXT-SHADOW']);
  16520. if ($ts) { $this->textshadow = $ts; }
  16521. }
  16522. // mPDF 5.3.80
  16523. if (isset($properties['TEXT-TRANSFORM'])) {
  16524. if (strtoupper($properties['TEXT-TRANSFORM']) == 'CAPITALIZE') { $this->capitalize = true; }
  16525. else if (strtoupper($properties['TEXT-TRANSFORM']) == 'UPPERCASE') { $this->toupper = true; }
  16526. else if (strtoupper($properties['TEXT-TRANSFORM']) == 'LOWERCASE') { $this->tolower = true; }
  16527. }
  16528. if (isset($properties['WHITE-SPACE'])) {
  16529. if (strtoupper($properties['WHITE-SPACE']) == 'NOWRAP') { $c['nowrap']= 1; }
  16530. }
  16531. $properties = array();
  16532. if (isset($attr['HEIGHT']) && !strpos($attr['HEIGHT'],'%')) $c['h'] = $this->ConvertSize($attr['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); // mPDF 5.3.57
  16533. if (isset($attr['ALIGN'])) $c['a'] = $align[strtolower($attr['ALIGN'])];
  16534. if (!$c['a']) {
  16535. if (isset($table['direction']) && $table['direction'] == 'rtl' ) { $c['a'] = 'R'; }
  16536. else { $c['a'] = 'L'; }
  16537. }
  16538. if (isset($attr['VALIGN'])) $c['va'] = $align[strtolower($attr['VALIGN'])];
  16539. if (isset($attr['BGCOLOR'])) $c['bgcolor'] = $attr['BGCOLOR'];
  16540. if (isset($attr['TEXT-ROTATE'])) {
  16541. $c['R'] = $attr['TEXT-ROTATE'];
  16542. }
  16543. if (isset($attr['NOWRAP']) && $attr['NOWRAP']) $c['nowrap']= 1;
  16544. // mPDF 5.3.77
  16545. $this->cell[$this->row][$this->col] = $c;
  16546. unset($c);
  16547. $this->cell[$this->row][$this->col]['s'] = 0 ;
  16548. $cs = $rs = 1;
  16549. if (isset($attr['COLSPAN']) && $attr['COLSPAN']>1) $cs = $this->cell[$this->row][$this->col]['colspan'] = $attr['COLSPAN'];
  16550. if ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'] < $this->col+$cs) {
  16551. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'] = $this->col+$cs;
  16552. } // mPDF 5.3.79 following code moved outside if...
  16553. for($l=$this->col; $l < $this->col+$cs ;$l++) {
  16554. if ($l-$this->col) $this->cell[$this->row][$l] = 0;
  16555. }
  16556. if (isset($attr['ROWSPAN']) && $attr['ROWSPAN']>1) $rs = $this->cell[$this->row][$this->col]['rowspan'] = $attr['ROWSPAN'];
  16557. for ($k=$this->row ; $k < $this->row+$rs ;$k++) {
  16558. for($l=$this->col; $l < $this->col+$cs ;$l++) {
  16559. if ($k-$this->row || $l-$this->col) $this->cell[$k][$l] = 0;
  16560. }
  16561. }
  16562. unset($table); // mPDF 5.3.76
  16563. break;
  16564. /*-- END TABLES --*/
  16565. /*-- LISTS --*/
  16566. // *********** LISTS ********************
  16567. case 'OL':
  16568. case 'UL':
  16569. $this->listjustfinished = false;
  16570. if ($this->blockjustfinished && !count($this->textbuffer) && $this->y != $this->tMargin && $this->collapseBlockMargins) { $lastbottommargin = $this->lastblockbottommargin; }
  16571. else { $lastbottommargin = 0; }
  16572. $this->lastblockbottommargin = 0;
  16573. $this->blockjustfinished=false;
  16574. $this->linebreakjustfinished=false;
  16575. $this->lastoptionaltag = ''; // Save current HTML specified optional endtag
  16576. $this->listCSSlvl++;
  16577. if((!$this->tableLevel) && ($this->listlvl == 0)) {
  16578. $blockstate = 0;
  16579. //if ($this->lastblocklevelchange == 1) { $blockstate = -1; } // Top margins/padding only
  16580. //else if ($this->lastblocklevelchange < 1) { $blockstate = 0; } // NO margins/padding
  16581. // called from block after new div e.g. <div> ... <ol> ... Outputs block top margin/border and padding
  16582. if (count($this->textbuffer) == 0 && $this->lastblocklevelchange == 1 && !$this->tableLevel && !$this->kwt) {
  16583. $this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,1,true, $this->blk[$this->blklvl]['direction']);
  16584. $this->finishFlowingBlock(true); // true = END of flowing block
  16585. }
  16586. else if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer,$blockstate); }
  16587. $this->textbuffer=array();
  16588. $this->lastblocklevelchange = -1;
  16589. }
  16590. // ol and ul types are mixed here
  16591. if ($this->listlvl == 0) {
  16592. $this->list_indent = array();
  16593. $this->list_align = array();
  16594. $this->list_lineheight = array();
  16595. $this->InlineProperties['LIST'] = array();
  16596. $this->InlineProperties['LISTITEM'] = array();
  16597. }
  16598. /*-- TABLES --*/
  16599. // A simple list for inside a table
  16600. if($this->tableLevel) {
  16601. $this->list_indent[$this->listlvl] = 0; // mm default indent for each level
  16602. if ($tag == 'OL') $this->listtype = '1';
  16603. else if ($tag == 'UL') $this->listtype = 'disc';
  16604. if ($this->listlvl > 0) {
  16605. $this->listlist[$this->listlvl]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  16606. }
  16607. $this->listlvl++;
  16608. $this->listnum = 0; // reset
  16609. $this->listlist[$this->listlvl] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
  16610. break;
  16611. }
  16612. /*-- END TABLES --*/
  16613. if (($this->PDFA || $this->PDFX) && $tag == 'UL') {
  16614. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "List bullets cannot use core font Zapfdingbats in PDFA1-b or PDFX/1-a. (Substitute characters from current font used if available, otherwise substitutes hyphen '-')"; }
  16615. }
  16616. if ($this->listCSSlvl==1) {
  16617. $properties = $this->MergeCSS('TOPLIST',$tag,$attr);
  16618. }
  16619. else {
  16620. $properties = $this->MergeCSS('LIST',$tag,$attr);
  16621. }
  16622. if (!empty($properties)) $this->setCSS($properties,'LIST'); // mPDF 5.3.65
  16623. // List-type
  16624. $this->listtype = '';
  16625. if (isset($attr['TYPE']) && $attr['TYPE']) { $this->listtype = $attr['TYPE']; }
  16626. else if (isset($properties['LIST-STYLE-TYPE'])) {
  16627. $this->listtype = $this->_getListStyle($properties['LIST-STYLE-TYPE']);
  16628. }
  16629. else if (isset($properties['LIST-STYLE'])) {
  16630. $this->listtype = $this->_getListStyle($properties['LIST-STYLE']);
  16631. }
  16632. if (!$this->listtype) {
  16633. if ($tag == 'OL') $this->listtype = '1';
  16634. if ($tag == 'UL') {
  16635. if ($this->listlvl % 3 == 0) $this->listtype = 'disc';
  16636. elseif ($this->listlvl % 3 == 1) $this->listtype = 'circle';
  16637. else $this->listtype = 'square';
  16638. }
  16639. }
  16640. if ($this->listlvl == 0) {
  16641. $this->inherit_lineheight = 0;
  16642. $this->listlvl++; // first depth level
  16643. $this->listnum = 0; // reset
  16644. $this->listDir = (isset($this->blk[$this->blklvl]['direction']) ? $this->blk[$this->blklvl]['direction'] : null);
  16645. $occur = $this->listoccur[$this->listlvl] = 1;
  16646. $this->listlist[$this->listlvl][1] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
  16647. }
  16648. else {
  16649. if (!empty($this->textbuffer))
  16650. {
  16651. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  16652. $this->listnum++;
  16653. }
  16654. // Save current lineheight to inherit
  16655. $this->textbuffer = array();
  16656. $occur = $this->listoccur[$this->listlvl];
  16657. $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  16658. $this->listlvl++;
  16659. $this->listnum = 0; // reset
  16660. if (!isset($this->listoccur[$this->listlvl]) || $this->listoccur[$this->listlvl] == 0) $this->listoccur[$this->listlvl] = 1;
  16661. else $this->listoccur[$this->listlvl]++;
  16662. $occur = $this->listoccur[$this->listlvl];
  16663. $this->listlist[$this->listlvl][$occur] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
  16664. }
  16665. // TOP LEVEL ONLY
  16666. if ($this->listlvl == 1) {
  16667. if (isset($properties['MARGIN-TOP'])) {
  16668. if ($lastbottommargin) {
  16669. $tmp = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16670. if ($tmp > $lastbottommargin) { $properties['MARGIN-TOP'] -= $lastbottommargin; }
  16671. else { $properties['MARGIN-TOP'] = 0; }
  16672. }
  16673. $this->DivLn($this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false),$this->blklvl,true,1); // collapsible
  16674. }
  16675. if (isset($properties['MARGIN-BOTTOM'])) {
  16676. $this->list_margin_bottom = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16677. }
  16678. if (isset($this->blk[$this->blklvl]['line_height'])) {
  16679. $this->list_lineheight[$this->listlvl][$occur] = $this->blk[$this->blklvl]['line_height'];
  16680. }
  16681. if (isset($properties['DIRECTION']) && $properties['DIRECTION']) { $this->listDir = strtolower($properties['DIRECTION']); }
  16682. if (isset($attr['DIR']) && $attr['DIR']) { $this->listDir = strtolower($attr['DIR']); }
  16683. }
  16684. $this->list_indent[$this->listlvl][$occur] = 5; // mm default indent for each level
  16685. if (isset($properties['TEXT-INDENT'])) { $this->list_indent[$this->listlvl][$occur] = $this->ConvertSize($properties['TEXT-INDENT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  16686. if (isset($properties['TEXT-ALIGN'])) {
  16687. $this->list_align[$this->listlvl][$occur] = $align[strtolower($properties['TEXT-ALIGN'])];
  16688. }
  16689. if (isset($properties['LINE-HEIGHT'])) {
  16690. $this->list_lineheight[$this->listlvl][$occur] = $this->fixLineheight($properties['LINE-HEIGHT']);
  16691. }
  16692. else if ($this->listlvl>1 && isset($this->list_lineheight[($this->listlvl - 1)][1])) {
  16693. $this->list_lineheight[$this->listlvl][$occur] = end($this->list_lineheight[($this->listlvl - 1)]);
  16694. }
  16695. if (!isset($this->list_lineheight[$this->listlvl][$occur]) || !$this->list_lineheight[$this->listlvl][$occur]) {
  16696. $this->list_lineheight[$this->listlvl][$occur] = $this->normalLineheight;
  16697. }
  16698. $this->InlineProperties['LIST'][$this->listlvl][$occur] = $this->saveInlineProperties();
  16699. $properties = array();
  16700. break;
  16701. case 'LI':
  16702. // Start Block
  16703. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16704. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  16705. /*-- TABLES --*/
  16706. // A simple list for inside a table
  16707. if($this->tableLevel) {
  16708. $this->blockjustfinished=false;
  16709. // If already something in the Cell
  16710. if ((isset($this->cell[$this->row][$this->col]['maxs']) && $this->cell[$this->row][$this->col]['maxs'] > 0 ) || $this->cell[$this->row][$this->col]['s'] > 0 ) {
  16711. $this->_saveCellTextBuffer("\n"); // mPDF 5.3.99
  16712. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  16713. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  16714. }
  16715. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  16716. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  16717. }
  16718. $this->cell[$this->row][$this->col]['s'] = 0 ;
  16719. }
  16720. if ($this->listlvl == 0) { //in case of malformed HTML code. Example:(...)</p><li>Content</li><p>Paragraph1</p>(...)
  16721. $this->listlvl++; // first depth level
  16722. $this->listnum = 0; // reset
  16723. $this->listlist[$this->listlvl] = array('TYPE'=>'disc','MAXNUM'=>$this->listnum);
  16724. }
  16725. $this->listnum++;
  16726. switch($this->listlist[$this->listlvl]['TYPE']) {
  16727. case 'A':
  16728. $blt = $this->dec2alpha($this->listnum,true).$this->list_number_suffix;
  16729. break;
  16730. case 'a':
  16731. $blt = $this->dec2alpha($this->listnum,false).$this->list_number_suffix;
  16732. break;
  16733. case 'I':
  16734. $blt = $this->dec2roman($this->listnum,true).$this->list_number_suffix;
  16735. break;
  16736. case 'i':
  16737. $blt = $this->dec2roman($this->listnum,false).$this->list_number_suffix;
  16738. break;
  16739. case '1':
  16740. $blt = $this->listnum.$this->list_number_suffix;
  16741. break;
  16742. default:
  16743. if ($this->listlvl % 3 == 1 && $this->_charDefined($this->CurrentFont['cw'],8226)) { $blt = "\xe2\x80\xa2"; } // &#8226;
  16744. else if ($this->listlvl % 3 == 2 && $this->_charDefined($this->CurrentFont['cw'],9900)) { $blt = "\xe2\x9a\xac"; } // &#9900;
  16745. else if ($this->listlvl % 3 == 0 && $this->_charDefined($this->CurrentFont['cw'],9642)) { $blt = "\xe2\x96\xaa"; } // &#9642;
  16746. else { $blt = '-'; }
  16747. break;
  16748. }
  16749. // change to &nbsp; spaces
  16750. if ($this->usingCoreFont) {
  16751. $ls = str_repeat(chr(160).chr(160),($this->listlvl-1)*2) . $blt . ' ';
  16752. }
  16753. else {
  16754. $ls = str_repeat("\xc2\xa0\xc2\xa0",($this->listlvl-1)*2) . $blt . ' ';
  16755. }
  16756. $this->_saveCellTextBuffer($ls, $this->HREF); // mPDF 5.3.99
  16757. $this->cell[$this->row][$this->col]['s'] += $this->GetStringWidth($ls);
  16758. break;
  16759. }
  16760. /*-- END TABLES --*/
  16761. //Observation: </LI> is ignored
  16762. if ($this->listlvl == 0) { //in case of malformed HTML code. Example:(...)</p><li>Content</li><p>Paragraph1</p>(...)
  16763. //First of all, skip a line
  16764. $this->listlvl++; // first depth level
  16765. $this->listnum = 0; // reset
  16766. $this->listoccur[$this->listlvl] = 1;
  16767. $this->listlist[$this->listlvl][1] = array('TYPE'=>'disc','MAXNUM'=>$this->listnum);
  16768. }
  16769. if ($this->listnum == 0) {
  16770. $this->listnum++;
  16771. $this->textbuffer = array();
  16772. }
  16773. else {
  16774. if (!empty($this->textbuffer)) {
  16775. if (!$this->listjustfinished) { // mPDF 5.3.11
  16776. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  16777. $this->listnum++;
  16778. }
  16779. else { // mPDF 5.3.10
  16780. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype, true);
  16781. }
  16782. }
  16783. $this->textbuffer = array();
  16784. }
  16785. $this->listjustfinished = false; // mPDF 5.3.11
  16786. $this->listCSSlvl++;
  16787. $properties = $this->MergeCSS('LIST',$tag,$attr);
  16788. if (!empty($properties)) $this->setCSS($properties,'LIST'); // mPDF 5.3.98
  16789. $this->InlineProperties['LISTITEM'][$this->listlvl][$this->listoccur[$this->listlvl]][$this->listnum] = $this->saveInlineProperties();
  16790. // List-type
  16791. if (isset($attr['TYPE']) && $attr['TYPE']) { $this->listitemtype = $attr['TYPE']; }
  16792. else if (isset($properties['LIST-STYLE-TYPE'])) {
  16793. $this->listitemtype = $this->_getListStyle($properties['LIST-STYLE-TYPE']);
  16794. }
  16795. else if (isset($properties['LIST-STYLE'])) {
  16796. $this->listitemtype = $this->_getListStyle($properties['LIST-STYLE']);
  16797. }
  16798. else $this->listitemtype = '';
  16799. break;
  16800. /*-- END LISTS --*/
  16801. }//end of switch
  16802. }
  16803. /*-- LISTS --*/
  16804. function _getListStyle($ls) {
  16805. if (stristr($ls,'decimal')) { return '1'; }
  16806. /* CSS3 list-styles numeric (selected) + I added tamil
  16807. arabic-indic | bengali | devanagari | gujarati | gurmukhi | kannada | malayalam | oriya | persian | telugu | thai | urdu
  16808. */
  16809. else if (preg_match('/(disc|circle|square|arabic-indic|bengali|devanagari|gujarati|gurmukhi|kannada|malayalam|oriya|persian|tamil|telugu|thai|urdu)/i',$ls,$m)) {
  16810. return strtolower(trim($m[1]));
  16811. }
  16812. else if (stristr($ls,'lower-roman')) { return 'i'; }
  16813. else if (stristr($ls,'upper-roman')) { return 'I'; }
  16814. else if (stristr($ls,'lower-latin')|| stristr($ls,'lower-alpha')) { return 'a'; }
  16815. else if (stristr($ls,'upper-latin') || stristr($ls,'upper-alpha')) { return 'A'; }
  16816. else if (stristr($ls,'none')) { return 'none'; }
  16817. else if (preg_match('/U\+([a-fA-F0-9]+)/i',$ls)) { return $ls; }
  16818. else { return ''; }
  16819. }
  16820. /*-- END LISTS --*/
  16821. function CloseTag($tag)
  16822. {
  16823. $this->ignorefollowingspaces = false; //Eliminate exceeding left-side spaces
  16824. //Closing tag
  16825. if($tag=='OPTION') { $this->selectoption['ACTIVE'] = false; $this->lastoptionaltag = ''; }
  16826. if($tag=='TTS' or $tag=='TTA' or $tag=='TTZ') {
  16827. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  16828. unset($this->InlineProperties[$tag]);
  16829. $ltag = strtolower($tag);
  16830. $this->$ltag = false;
  16831. }
  16832. if($tag=='FONT' || $tag=='SPAN' || $tag=='CODE' || $tag=='KBD' || $tag=='SAMP' || $tag=='TT' || $tag=='VAR'
  16833. || $tag=='INS' || $tag=='STRONG' || $tag=='CITE' || $tag=='SUB' || $tag=='SUP' || $tag=='S' || $tag=='STRIKE' || $tag=='DEL'
  16834. || $tag=='Q' || $tag=='EM' || $tag=='B' || $tag=='I' || $tag=='U' | $tag=='SMALL' || $tag=='BIG' || $tag=='ACRONYM') {
  16835. if ($tag == 'SPAN') {
  16836. if (isset($this->InlineProperties['SPAN'][$this->spanlvl]) && $this->InlineProperties['SPAN'][$this->spanlvl]) { $this->restoreInlineProperties($this->InlineProperties['SPAN'][$this->spanlvl]); }
  16837. unset($this->InlineProperties['SPAN'][$this->spanlvl]);
  16838. if (isset($this->InlineAnnots['SPAN'][$this->spanlvl]) && $this->InlineAnnots['SPAN'][$this->spanlvl]) { $annot = $this->InlineAnnots['SPAN'][$this->spanlvl]; } // *ANNOTATIONS*
  16839. unset($this->InlineAnnots['SPAN'][$this->spanlvl]); // *ANNOTATIONS*
  16840. $this->spanlvl--;
  16841. }
  16842. else {
  16843. if (isset($this->InlineProperties[$tag]) && $this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  16844. unset($this->InlineProperties[$tag]);
  16845. if (isset($this->InlineAnnots[$tag]) && $this->InlineAnnots[$tag]) { $annot = $this->InlineAnnots[$tag]; } // *ANNOTATIONS*
  16846. unset($this->InlineAnnots[$tag]); // *ANNOTATIONS*
  16847. }
  16848. /*-- ANNOTATIONS --*/
  16849. if (isset($annot)) {
  16850. if($this->tableLevel) { // *TABLES*
  16851. $this->cell[$this->row][$this->col]['textbuffer'][] = array($annot); // *TABLES*
  16852. } // *TABLES*
  16853. else { // *TABLES*
  16854. $this->textbuffer[] = array($annot);
  16855. } // *TABLES*
  16856. }
  16857. /*-- END ANNOTATIONS --*/
  16858. }
  16859. if($tag=='A') {
  16860. $this->HREF='';
  16861. if (isset($this->InlineProperties['A'])) { $this->restoreInlineProperties($this->InlineProperties['A']); }
  16862. unset($this->InlineProperties['A']);
  16863. }
  16864. /*-- FORMS --*/
  16865. // *********** FORM ELEMENTS ********************
  16866. if($tag=='TEXTAREA') {
  16867. $this->specialcontent = '';
  16868. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  16869. unset($this->InlineProperties[$tag]);
  16870. }
  16871. if($tag=='SELECT') {
  16872. $this->lastoptionaltag = '';
  16873. $texto = '';
  16874. if (isset($this->selectoption['SELECTED'])) { $texto = $this->selectoption['SELECTED']; }
  16875. if ($this->useActiveForms) { $w = $this->selectoption['MAXWIDTH']; }
  16876. else { $w = $this->GetStringWidth($texto); }
  16877. if ($w == 0) { $w = 5; }
  16878. $objattr['type'] = 'select';
  16879. $objattr['text'] = $texto;
  16880. if (isset($this->selectoption['NAME'])) { $objattr['fieldname'] = $this->selectoption['NAME']; }
  16881. if (isset($this->selectoption['READONLY'])) { $objattr['readonly'] = true; }
  16882. if (isset($this->selectoption['REQUIRED'])) { $objattr['required'] = true; }
  16883. if (isset($this->selectoption['SPELLCHECK'])) { $objattr['spellcheck'] = true; }
  16884. if (isset($this->selectoption['EDITABLE'])) { $objattr['editable'] = true; }
  16885. if (isset($this->selectoption['ONCHANGE'])) { $objattr['onChange'] = $this->selectoption['ONCHANGE']; }
  16886. if (isset($this->selectoption['ITEMS'])) { $objattr['items'] = $this->selectoption['ITEMS']; }
  16887. if (isset($this->selectoption['MULTIPLE'])) { $objattr['multiple'] = $this->selectoption['MULTIPLE']; }
  16888. if (isset($this->selectoption['DISABLED'])) { $objattr['disabled'] = $this->selectoption['DISABLED']; }
  16889. if (isset($this->selectoption['TITLE'])) { $objattr['title'] = $this->selectoption['TITLE']; }
  16890. if (isset($this->selectoption['COLOR'])) { $objattr['color'] = $this->selectoption['COLOR']; }
  16891. if (isset($this->selectoption['SIZE'])) { $objattr['size'] = $this->selectoption['SIZE']; }
  16892. if (isset($objattr['size']) && $objattr['size']>1) { $rows=$objattr['size']; } else { $rows = 1; }
  16893. $objattr['fontfamily'] = $this->FontFamily;
  16894. $objattr['fontsize'] = $this->FontSizePt;
  16895. $objattr['width'] = $w + ($this->form->form_element_spacing['select']['outer']['h']*2)+($this->form->form_element_spacing['select']['inner']['h']*2) + ($this->FontSize*1.4);
  16896. $objattr['height'] = ($this->FontSize*$rows) + ($this->form->form_element_spacing['select']['outer']['v']*2)+($this->form->form_element_spacing['select']['inner']['v']*2);
  16897. $e = "\xbb\xa4\xactype=select,objattr=".serialize($objattr)."\xbb\xa4\xac";
  16898. // Clear properties - tidy up
  16899. $properties = array();
  16900. // Output it to buffers
  16901. if ($this->tableLevel) { // *TABLES*
  16902. $this->_saveCellTextBuffer($e, $this->HREF); // mPDF 5.3.99
  16903. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ; // *TABLES*
  16904. } // *TABLES*
  16905. else { // *TABLES*
  16906. $this->_saveTextBuffer($e, $this->HREF); // mPDF 5.3.99
  16907. } // *TABLES*
  16908. $this->selectoption = array();
  16909. $this->specialcontent = '';
  16910. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  16911. unset($this->InlineProperties[$tag]);
  16912. }
  16913. /*-- END FORMS --*/
  16914. // *********** BLOCKS ********************
  16915. if($tag=='P' || $tag=='DIV' || $tag=='H1' || $tag=='H2' || $tag=='H3' || $tag=='H4' || $tag=='H5' || $tag=='H6' || $tag=='PRE'
  16916. || $tag=='FORM' || $tag=='ADDRESS' || $tag=='BLOCKQUOTE' || $tag=='CENTER' || $tag=='DT' || $tag=='DD' || $tag=='DL' || $tag=='CAPTION' ) {
  16917. // mPDF 5.3.56
  16918. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  16919. $this->blockjustfinished=true;
  16920. $this->lastblockbottommargin = $this->blk[$this->blklvl]['margin_bottom'];
  16921. /*-- LISTS --*/
  16922. if ($this->listlvl>0) { return; }
  16923. /*-- END LISTS --*/
  16924. /*-- TABLES --*/
  16925. if($this->tableLevel) {
  16926. if ($this->linebreakjustfinished) { $this->blockjustfinished=false; }
  16927. if (isset($this->InlineProperties['BLOCKINTABLE'])) {
  16928. if ($this->InlineProperties['BLOCKINTABLE']) { $this->restoreInlineProperties($this->InlineProperties['BLOCKINTABLE']); }
  16929. unset($this->InlineProperties['BLOCKINTABLE']);
  16930. }
  16931. if($tag=='PRE') { $this->ispre=false; }
  16932. return;
  16933. }
  16934. /*-- END TABLES --*/
  16935. $this->lastoptionaltag = '';
  16936. $this->divbegin=false;
  16937. $this->linebreakjustfinished=false;
  16938. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  16939. /*-- CSS-FLOAT --*/
  16940. // If float contained in a float, need to extend bottom to allow for it
  16941. $currpos = $this->page*1000 + $this->y;
  16942. if (isset($this->blk[$this->blklvl]['float_endpos']) && $this->blk[$this->blklvl]['float_endpos'] > $currpos) {
  16943. $old_page = $this->page;
  16944. $new_page = intval($this->blk[$this->blklvl]['float_endpos'] /1000);
  16945. if ($old_page != $new_page) {
  16946. $s = $this->PrintPageBackgrounds();
  16947. // Writes after the marker so not overwritten later by page background etc.
  16948. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  16949. $this->pageBackgrounds = array();
  16950. $this->page = $new_page;
  16951. $this->ResetMargins();
  16952. $this->Reset();
  16953. $this->pageoutput[$this->page] = array();
  16954. }
  16955. $this->y = (($this->blk[$this->blklvl]['float_endpos'] *1000) % 1000000)/1000; // mod changes operands to integers before processing
  16956. }
  16957. /*-- END CSS-FLOAT --*/
  16958. //Print content
  16959. if ($this->lastblocklevelchange == 1) { $blockstate = 3; } // Top & bottom margins/padding
  16960. else if ($this->lastblocklevelchange == -1) { $blockstate = 2; } // Bottom margins/padding only
  16961. else { $blockstate = 0; }
  16962. // called from after e.g. </table> </div> </div> ... Outputs block margin/border and padding
  16963. if (count($this->textbuffer) && $this->textbuffer[count($this->textbuffer)-1]) {
  16964. if (substr($this->textbuffer[count($this->textbuffer)-1][0],0,3) != "\xbb\xa4\xac") { // not special content
  16965. if ($this->usingCoreFont) {
  16966. $this->textbuffer[count($this->textbuffer)-1][0] = preg_replace('/[ ]+$/', '', $this->textbuffer[count($this->textbuffer)-1][0]);
  16967. }
  16968. else {
  16969. $this->textbuffer[count($this->textbuffer)-1][0] = preg_replace('/[ ]+$/u', '', $this->textbuffer[count($this->textbuffer)-1][0]); }
  16970. }
  16971. }
  16972. if (count($this->textbuffer) == 0 && $this->lastblocklevelchange != 0) {
  16973. //$this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,2,true, $this->blk[$this->blklvl]['direction']);
  16974. $this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,$blockstate,true, $this->blk[$this->blklvl]['direction']); // mPDF 5.3.29
  16975. $this->finishFlowingBlock(true); // true = END of flowing block
  16976. $this->PaintDivBB('',$blockstate);
  16977. }
  16978. else {
  16979. $this->printbuffer($this->textbuffer,$blockstate);
  16980. }
  16981. $this->textbuffer=array();
  16982. if ($this->blk[$this->blklvl]['keep_block_together']) {
  16983. $this->printdivbuffer();
  16984. }
  16985. if ($this->kwt) {
  16986. $this->kwt_height = $this->y - $this->kwt_y0;
  16987. }
  16988. /*-- CSS-IMAGE-FLOAT --*/
  16989. $this->printfloatbuffer();
  16990. /*-- END CSS-IMAGE-FLOAT --*/
  16991. if($tag=='PRE') { $this->ispre=false; }
  16992. /*-- CSS-FLOAT --*/
  16993. if ($this->blk[$this->blklvl]['float'] == 'R') {
  16994. // If width not set, here would need to adjust and output buffer
  16995. $s = $this->PrintPageBackgrounds();
  16996. // Writes after the marker so not overwritten later by page background etc.
  16997. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  16998. $this->pageBackgrounds = array();
  16999. $this->Reset();
  17000. $this->pageoutput[$this->page] = array();
  17001. for($i=($this->blklvl-1); $i >= 0; $i--) {
  17002. if (isset($this->blk[$i]['float_endpos'])) { $this->blk[$i]['float_endpos'] = max($this->blk[$i]['float_endpos'], ($this->page*1000 + $this->y)); }
  17003. else { $this->blk[$i]['float_endpos'] = $this->page*1000 + $this->y; }
  17004. }
  17005. $this->floatDivs[] = array(
  17006. 'side'=>'R',
  17007. 'startpage'=>$this->blk[$this->blklvl]['startpage'] ,
  17008. 'y0'=>$this->blk[$this->blklvl]['float_start_y'] ,
  17009. 'startpos'=> ($this->blk[$this->blklvl]['startpage']*1000 + $this->blk[$this->blklvl]['float_start_y']),
  17010. 'endpage'=>$this->page ,
  17011. 'y1'=>$this->y ,
  17012. 'endpos'=> ($this->page*1000 + $this->y),
  17013. 'w'=> $this->blk[$this->blklvl]['float_width'],
  17014. 'blklvl'=>$this->blklvl,
  17015. 'blockContext' => $this->blk[$this->blklvl-1]['blockContext']
  17016. );
  17017. $this->y = $this->blk[$this->blklvl]['float_start_y'] ;
  17018. $this->page = $this->blk[$this->blklvl]['startpage'] ;
  17019. $this->ResetMargins();
  17020. $this->pageoutput[$this->page] = array();
  17021. }
  17022. if ($this->blk[$this->blklvl]['float'] == 'L') {
  17023. // If width not set, here would need to adjust and output buffer
  17024. $s = $this->PrintPageBackgrounds();
  17025. // Writes after the marker so not overwritten later by page background etc.
  17026. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  17027. $this->pageBackgrounds = array();
  17028. $this->Reset();
  17029. $this->pageoutput[$this->page] = array();
  17030. for($i=($this->blklvl-1); $i >= 0; $i--) {
  17031. if (isset($this->blk[$i]['float_endpos'])) { $this->blk[$i]['float_endpos'] = max($this->blk[$i]['float_endpos'], ($this->page*1000 + $this->y)); }
  17032. else { $this->blk[$i]['float_endpos'] = $this->page*1000 + $this->y; }
  17033. }
  17034. $this->floatDivs[] = array(
  17035. 'side'=>'L',
  17036. 'startpage'=>$this->blk[$this->blklvl]['startpage'] ,
  17037. 'y0'=>$this->blk[$this->blklvl]['float_start_y'] ,
  17038. 'startpos'=> ($this->blk[$this->blklvl]['startpage']*1000 + $this->blk[$this->blklvl]['float_start_y']),
  17039. 'endpage'=>$this->page ,
  17040. 'y1'=>$this->y ,
  17041. 'endpos'=> ($this->page*1000 + $this->y),
  17042. 'w'=> $this->blk[$this->blklvl]['float_width'],
  17043. 'blklvl'=>$this->blklvl,
  17044. 'blockContext' => $this->blk[$this->blklvl-1]['blockContext']
  17045. );
  17046. $this->y = $this->blk[$this->blklvl]['float_start_y'] ;
  17047. $this->page = $this->blk[$this->blklvl]['startpage'] ;
  17048. $this->ResetMargins();
  17049. $this->pageoutput[$this->page] = array();
  17050. }
  17051. /*-- END CSS-FLOAT --*/
  17052. // mPDF 5.3.42 VISIBILITY
  17053. if (isset($this->blk[$this->blklvl]['visibility']) && $this->blk[$this->blklvl]['visibility']!='visible') {
  17054. $this->SetVisibility('visible');
  17055. }
  17056. // mPDF 5.3.03
  17057. if (isset($this->blk[$this->blklvl]['page_break_after'])) { $page_break_after = $this->blk[$this->blklvl]['page_break_after']; }
  17058. else { $page_break_after = ''; }
  17059. //Reset values
  17060. $this->Reset();
  17061. if ($this->blklvl > 0) { // ==0 SHOULDN'T HAPPEN - NOT XHTML
  17062. if ($this->blk[$this->blklvl]['tag'] == $tag) {
  17063. unset($this->blk[$this->blklvl]);
  17064. $this->blklvl--;
  17065. }
  17066. //else { echo $tag; exit; } // debug - forces error if incorrectly nested html tags
  17067. }
  17068. $this->lastblocklevelchange = -1 ;
  17069. // Reset Inline-type properties
  17070. if (isset($this->blk[$this->blklvl]['InlineProperties'])) { $this->restoreInlineProperties($this->blk[$this->blklvl]['InlineProperties']); }
  17071. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  17072. // mPDF 5.3.03
  17073. if ($page_break_after) {
  17074. $save_blklvl = $this->blklvl;
  17075. $save_blk = $this->blk;
  17076. $save_silp = $this->saveInlineProperties();
  17077. $save_spanlvl = $this->spanlvl;
  17078. $save_ilp = $this->InlineProperties;
  17079. if ($this->blklvl>1) {
  17080. // Close any open block tags
  17081. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  17082. // Output any text left in buffer
  17083. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); $this->textbuffer=array(); }
  17084. }
  17085. /*-- COLUMNS --*/
  17086. $save_cols = false;
  17087. if ($this->ColActive) {
  17088. $save_cols = true;
  17089. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  17090. $this->SetColumns(0);
  17091. }
  17092. /*-- END COLUMNS --*/
  17093. if ($page_break_after == 'RIGHT') { $this->AddPage($this->CurOrientation,'NEXT-ODD','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  17094. else if ($page_break_after == 'LEFT') { $this->AddPage($this->CurOrientation,'NEXT-EVEN','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  17095. else { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  17096. if (!$this->restoreBlockPagebreaks) {
  17097. $this->blklvl = 0;
  17098. $this->lastblocklevelchange = 0;
  17099. $this->blk = array();
  17100. $this->initialiseBlock($this->blk[0]);
  17101. $this->blk[0]['width'] =& $this->pgwidth;
  17102. $this->blk[0]['inner_width'] =& $this->pgwidth;
  17103. $this->blk[0]['blockContext'] = $this->blockContext;
  17104. $properties = $this->MergeCSS('BLOCK','BODY','');
  17105. $this->setCSS($properties,'','BODY');
  17106. $this->blklvl++;
  17107. $currblk =& $this->blk[$this->blklvl];
  17108. $prevblk =& $this->blk[$this->blklvl-1];
  17109. $this->initialiseBlock($currblk);
  17110. $currblk['tag'] = $tag;
  17111. $currblk['attr'] = $attr;
  17112. $this->Reset();
  17113. $properties = $this->MergeCSS('BLOCK',$tag,$attr);
  17114. }
  17115. /*-- COLUMNS --*/
  17116. if ($save_cols) {
  17117. // Restore columns
  17118. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  17119. }
  17120. /*-- END COLUMNS --*/
  17121. if ($this->restoreBlockPagebreaks && !$this->tableLevel && !$this->listlvl) {
  17122. $this->blk = $save_blk;
  17123. // Re-open block tags
  17124. $t = $this->blk[0]['tag'];
  17125. $a = $this->blk[0]['attr'];
  17126. $this->blklvl = 0;
  17127. for ($b=0; $b<=$save_blklvl;$b++) {
  17128. $tc = $t;
  17129. $ac = $a;
  17130. $t = $this->blk[$b+1]['tag'];
  17131. $a = $this->blk[$b+1]['attr'];
  17132. unset($this->blk[$b+1]);
  17133. $this->OpenTag($tc,$ac);
  17134. }
  17135. $this->spanlvl = $save_spanlvl;
  17136. $this->InlineProperties = $save_ilp;
  17137. $this->restoreInlineProperties($save_silp);
  17138. }
  17139. }
  17140. }
  17141. /*-- TABLES --*/
  17142. if($tag=='TH') $this->SetStyle('B',false);
  17143. if(($tag=='TH' or $tag=='TD') && $this->tableLevel) {
  17144. $this->lastoptionaltag = 'TR';
  17145. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  17146. $this->tbCSSlvl--;
  17147. if (!$this->tdbegin) { return; } // mPDF 5.3.79
  17148. $this->tdbegin = false;
  17149. // Added for correct calculation of cell column width - otherwise misses the last line if not end </p> etc.
  17150. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  17151. if (!is_array($this->cell[$this->row][$this->col])) { $this->Error("You may have an error in your HTML code e.g. &lt;/td&gt;&lt;/td&gt;"); }
  17152. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  17153. }
  17154. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  17155. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  17156. }
  17157. // Remove last <br> if at end of cell
  17158. if (isset($this->cell[$this->row][$this->col]['textbuffer'])) { $ntb = count($this->cell[$this->row][$this->col]['textbuffer']); }
  17159. else { $ntb = 0; }
  17160. if ($ntb>1 && $this->cell[$this->row][$this->col]['textbuffer'][$ntb-1][0] == "\n") {
  17161. unset($this->cell[$this->row][$this->col]['textbuffer'][$ntb-1]);
  17162. }
  17163. // mPDF 5.3.79
  17164. if ($this->cacheTables) {
  17165. $clen = $this->_cacheCell($this->cell[$this->row][$this->col], $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cache']);
  17166. $this->cell[$this->row][$this->col] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['ptr'];
  17167. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['ptr'] += $clen;
  17168. }
  17169. // mPDF 5.3.62
  17170. if ($this->tablethead) {
  17171. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead'][$this->row] = true;
  17172. if ($this->tableLevel==1) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['headernrows'] = max($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['headernrows'] , ($this->row+1)); }
  17173. }
  17174. if ($this->tabletfoot) {
  17175. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'][$this->row] = true;
  17176. if ($this->tableLevel==1) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['footernrows'] = max($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['footernrows'] , ($this->row+1 - $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['headernrows'] )); }
  17177. }
  17178. $this->Reset();
  17179. }
  17180. if($tag=='TR' && $this->tableLevel) {
  17181. // mPDF 5.3.78
  17182. // If Border set on TR - Update right border
  17183. if (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-left'][$this->row])) {
  17184. // mPDF 5.3.79
  17185. if ($this->cacheTables) {
  17186. $c = $this->_uncacheCell($this->cell[$this->row][$this->col], $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cache'], null);
  17187. }
  17188. else { $c =& $this->cell[$this->row][$this->col]; }
  17189. if ($c) {
  17190. if ($this->packTableData) {
  17191. $cell = $this->_unpackCellBorder($c['borderbin'] );
  17192. }
  17193. else { $cell = $c; }
  17194. $cell['border_details']['R'] = $this->border_details($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-right'][$this->row]);
  17195. $this->setBorder($cell['border'], _BORDER_RIGHT, $cell['border_details']['R']['s']);
  17196. if ($this->packTableData) {
  17197. $c['borderbin'] = $this->_packCellBorder($cell);
  17198. unset($c['border']);
  17199. unset($c['border_details']);
  17200. }
  17201. else { $c = $cell; }
  17202. }
  17203. // mPDF 5.3.79
  17204. if ($this->cacheTables) {
  17205. $fh = fopen($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cache'], "r+b");
  17206. $this->_cacheUpdateBorder($c, $fh, $this->cell[$this->row][$this->col]);
  17207. fclose($fh);
  17208. }
  17209. }
  17210. $this->lastoptionaltag = '';
  17211. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  17212. $this->tbCSSlvl--;
  17213. $this->trow_text_rotate = '';
  17214. $this->tabletheadjustfinished = false;
  17215. }
  17216. if($tag=='TBODY') {
  17217. $this->lastoptionaltag = '';
  17218. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  17219. $this->tbCSSlvl--;
  17220. }
  17221. if($tag=='THEAD') {
  17222. $this->lastoptionaltag = '';
  17223. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  17224. $this->tbCSSlvl--;
  17225. $this->tablethead = 0;
  17226. $this->tabletheadjustfinished = true;
  17227. $this->ResetStyles();
  17228. $this->thead_font_weight = '';
  17229. $this->thead_font_style = '';
  17230. $this->thead_font_smCaps = '';
  17231. $this->thead_valign_default = '';
  17232. $this->thead_textalign_default = '';
  17233. }
  17234. if($tag=='TFOOT') {
  17235. $this->lastoptionaltag = '';
  17236. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  17237. $this->tbCSSlvl--;
  17238. $this->tabletfoot = 0;
  17239. $this->ResetStyles();
  17240. $this->tfoot_font_weight = '';
  17241. $this->tfoot_font_style = '';
  17242. $this->tfoot_font_smCaps = '';
  17243. $this->tfoot_valign_default = '';
  17244. $this->tfoot_textalign_default = '';
  17245. }
  17246. if($tag=='TABLE') { // TABLE-END (
  17247. if ($this->progressBar) { $this->UpdateProgressBar(1,'','TABLE'); } // *PROGRESS-BAR*
  17248. if ($this->progressBar) { $this->UpdateProgressBar(7,0,''); } // *PROGRESS-BAR*
  17249. $this->lastoptionaltag = '';
  17250. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  17251. $this->tbCSSlvl--;
  17252. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  17253. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] = $this->cell;
  17254. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['wc'] = array_pad(array(),$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'],array('miw'=>0,'maw'=>0));
  17255. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['hr'] = array_pad(array(),$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr'],0);
  17256. // Move table footer <tfoot> row to end of table
  17257. if (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) && count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'])) {
  17258. $tfrows = array();
  17259. foreach($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'] AS $r=>$val) {
  17260. if ($val) { $tfrows[] = $r; }
  17261. }
  17262. $temp = array();
  17263. $temptf = array();
  17264. foreach($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] AS $k=>$row) {
  17265. if (in_array($k,$tfrows)) {
  17266. $temptf[] = $row;
  17267. }
  17268. else {
  17269. $temp[] = $row;
  17270. }
  17271. }
  17272. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'] = array();
  17273. for($i=count($temp) ; $i<(count($temp)+count($temptf)); $i++) {
  17274. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'][$i] = true;
  17275. }
  17276. // Update nestedpos row references
  17277. if (count($this->table[($this->tableLevel+1)])) {
  17278. foreach($this->table[($this->tableLevel+1)] AS $nid=>$nested) {
  17279. $this->table[($this->tableLevel+1)][$nid]['nestedpos'][0] -= count($temptf);
  17280. }
  17281. }
  17282. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] = array_merge($temp, $temptf);
  17283. // Update other arays set on row number
  17284. // [trbackground-images] [trgradients]
  17285. $temptrbgi = array();
  17286. $temptrbgg = array();
  17287. $temptrbgc = array();
  17288. $temptrbgc[-1] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][-1];
  17289. for($k=0; $k<$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr']; $k++) {
  17290. if (!in_array($k,$tfrows)) {
  17291. $temptrbgi[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'][$k];
  17292. $temptrbgg[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'][$k];
  17293. $temptrbgc[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$k];
  17294. }
  17295. }
  17296. for($k=0; $k<$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr']; $k++) {
  17297. if (in_array($k,$tfrows)) {
  17298. $temptrbgi[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'][$k];
  17299. $temptrbgg[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'][$k];
  17300. $temptrbgc[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$k];
  17301. }
  17302. }
  17303. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'] = $temptrbgi;
  17304. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'] = $temptrbgg;
  17305. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'] = $temptrbgc ;
  17306. // Should Update all other arays set on row number, but cell properties have been set so not needed
  17307. // [bgcolor] [trborder-left] [trborder-right] [trborder-top] [trborder-bottom]
  17308. }
  17309. if ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['direction']=='rtl') {
  17310. $this->_reverseTableDir($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]);
  17311. }
  17312. // Fix Borders *********************************************
  17313. $this->_fixTableBorders($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]);
  17314. if ($this->progressBar) { $this->UpdateProgressBar(7,10,' '); } // *PROGRESS-BAR*
  17315. if ($this->ColActive) { $this->table_rotate = 0; } // *COLUMNS*
  17316. if ($this->table_rotate <> 0) {
  17317. $this->tablebuffer = '';
  17318. // Max width for rotated table
  17319. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 1);
  17320. $this->tbrot_maxh = $this->blk[$this->blklvl]['inner_width'] ; // Max width for rotated table
  17321. $this->tbrot_align = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['a'] ;
  17322. }
  17323. $this->shrin_k = 1;
  17324. if ($this->shrink_tables_to_fit < 1) { $this->shrink_tables_to_fit = 1; }
  17325. if (!$this->shrink_this_table_to_fit) { $this->shrink_this_table_to_fit = $this->shrink_tables_to_fit; }
  17326. if ($this->tableLevel>1) {
  17327. // deal with nested table
  17328. $this->_tableColumnWidth($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]],true);
  17329. $tmiw = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['miw'];
  17330. $tmaw = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['maw'];
  17331. $tl = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['tl'];
  17332. // Go down to lower table level
  17333. $this->tableLevel--;
  17334. // Reset lower level table
  17335. $this->base_table_properties = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['baseProperties'];
  17336. $this->cell = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'];
  17337. $this->row = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currrow'];
  17338. $this->col = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currcol'];
  17339. $objattr = array();
  17340. $objattr['type'] = 'nestedtable';
  17341. $objattr['nestedcontent'] = $this->tbctr[($this->tableLevel+1)];
  17342. $objattr['table'] = $this->tbctr[$this->tableLevel];
  17343. $objattr['row'] = $this->row;
  17344. $objattr['col'] = $this->col;
  17345. $objattr['level'] = $this->tableLevel;
  17346. $e = "\xbb\xa4\xactype=nestedtable,objattr=".serialize($objattr)."\xbb\xa4\xac";
  17347. $this->_saveCellTextBuffer($e); // mPDF 5.3.99
  17348. $this->cell[$this->row][$this->col]['s'] += $tl ;
  17349. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  17350. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  17351. }
  17352. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  17353. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  17354. }
  17355. $this->cell[$this->row][$this->col]['s'] = 0;// reset
  17356. if ((isset($this->cell[$this->row][$this->col]['nestedmaw']) && $this->cell[$this->row][$this->col]['nestedmaw'] < $tmaw) || !isset($this->cell[$this->row][$this->col]['nestedmaw'])) { $this->cell[$this->row][$this->col]['nestedmaw'] = $tmaw ; }
  17357. if ((isset($this->cell[$this->row][$this->col]['nestedmiw']) && $this->cell[$this->row][$this->col]['nestedmiw'] < $tmiw) || !isset($this->cell[$this->row][$this->col]['nestedmiw'])) { $this->cell[$this->row][$this->col]['nestedmiw'] = $tmiw ; }
  17358. // mPDF 5.3.79 ?? Removed as Not needed for anything
  17359. // $this->cell[$this->row][$this->col]['nestedcontent'][] = $this->tbctr[($this->tableLevel+1)];
  17360. $this->tdbegin = true;
  17361. $this->nestedtablejustfinished = true;
  17362. $this->ignorefollowingspaces = true;
  17363. return;
  17364. }
  17365. $this->cMarginL = 0;
  17366. $this->cMarginR = 0;
  17367. $this->cMarginT = 0;
  17368. $this->cMarginB = 0;
  17369. $this->cellPaddingL = 0;
  17370. $this->cellPaddingR = 0;
  17371. $this->cellPaddingT = 0;
  17372. $this->cellPaddingB = 0;
  17373. // mPDF 5.3.36 // mPDF 5.3.76
  17374. if (isset($this->table[1][1]['overflow']) && $this->table[1][1]['overflow']=='visible') {
  17375. if ($this->kwt || $this->table_rotate || $this->table_keep_together || $this->ColActive) {
  17376. $this->kwt = false;
  17377. $this->table_rotate = 0;
  17378. $this->table_keep_together = false;
  17379. //die("mPDF Warning: You cannot use CSS overflow:visible together with any of these functions: 'Keep-with-table', rotated tables, page-break-inside:avoid, or columns");
  17380. }
  17381. $this->_tableColumnWidth($this->table[1][1],true);
  17382. $this->_tableWidth($this->table[1][1]);
  17383. }
  17384. else {
  17385. if (!$this->kwt_saved) { $this->kwt_height = 0; }
  17386. list($check,$tablemiw) = $this->_tableColumnWidth($this->table[1][1],true);
  17387. $save_table = $this->table;
  17388. // mPDF 5.3.79
  17389. if ($this->cacheTables) { $this->_backupCacheFiles(); }
  17390. $reset_to_minimum_width = false;
  17391. $added_page = false;
  17392. if ($check > 1) {
  17393. if ($check > $this->shrink_this_table_to_fit && $this->table_rotate) {
  17394. if ($this->y != $this->tMargin) { // mPDF 5.3.69
  17395. $this->AddPage($this->CurOrientation);
  17396. $this->kwt_moved = true;
  17397. }
  17398. $added_page = true;
  17399. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17400. //$check = $tablemiw/$this->tbrot_maxw; // undo any shrink
  17401. $check = 1; // undo any shrink
  17402. }
  17403. $reset_to_minimum_width = true;
  17404. }
  17405. if ($reset_to_minimum_width) {
  17406. $this->shrin_k = $check;
  17407. $this->default_font_size /= $this->shrin_k;
  17408. $this->SetFontSize($this->default_font_size, false );
  17409. $this->shrinkTable($this->table[1][1],$this->shrin_k);
  17410. $this->_tableColumnWidth($this->table[1][1],false); // repeat
  17411. // Starting at $this->innermostTableLevel
  17412. // Shrink table values - and redo columnWidth
  17413. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  17414. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  17415. $this->shrinkTable($this->table[$lvl][$nid],$this->shrin_k);
  17416. $this->_tableColumnWidth($this->table[$lvl][$nid],false);
  17417. }
  17418. }
  17419. }
  17420. // Set table cell widths for top level table
  17421. // Use $shrin_k to resize but don't change again
  17422. $this->SetLineHeight('',$this->table_lineheight);
  17423. // Top level table
  17424. $this->_tableWidth($this->table[1][1]);
  17425. } // mPDF 5.3.36
  17426. // mPDF 5.3.79
  17427. // Now work through any nested tables setting child table[w'] = parent cell['w']
  17428. // Now do nested tables _tableWidth
  17429. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  17430. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  17431. // HERE set child table width = cell width
  17432. list($parentrow, $parentcol, $parentnid) = $this->table[$lvl][$nid]['nestedpos'];
  17433. // mPDF 5.3.79
  17434. if ($this->cacheTables) {
  17435. $c = $this->_uncacheCell($this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol], $this->table[($lvl-1)][$parentnid]['cache'], null);
  17436. }
  17437. else
  17438. $c =& $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol];
  17439. if (isset($c['colspan']) && $c['colspan']> 1) {
  17440. $parentwidth = 0;
  17441. for($cs=0;$cs<$c['colspan'] ; $cs++) {
  17442. $parentwidth += $this->table[($lvl-1)][$parentnid]['wc'][$parentcol+$cs];
  17443. }
  17444. }
  17445. else { $parentwidth = $this->table[($lvl-1)][$parentnid]['wc'][$parentcol]; }
  17446. //$parentwidth -= ALLOW FOR PADDING ETC.in parent cell
  17447. if (!$this->simpleTables){
  17448. if ($this->packTableData) {
  17449. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  17450. }
  17451. else {
  17452. $br = $c['border_details']['R']['w'];
  17453. $bl = $c['border_details']['L']['w'];
  17454. }
  17455. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  17456. $parentwidth -= $br + $bl
  17457. + $c['padding']['L']
  17458. + $c['padding']['R']
  17459. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  17460. }
  17461. else {
  17462. $parentwidth -= $br/2 + $bl/2
  17463. + $c['padding']['L']
  17464. + $c['padding']['R'];
  17465. }
  17466. }
  17467. else if ($this->simpleTables){
  17468. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  17469. $parentwidth -= $this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']
  17470. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']
  17471. + $c['padding']['L']
  17472. + $c['padding']['R']
  17473. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  17474. }
  17475. else {
  17476. $parentwidth -= $this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']/2
  17477. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']/2
  17478. + $c['padding']['L']
  17479. + $c['padding']['R'];
  17480. }
  17481. }
  17482. if (isset($this->table[$lvl][$nid]['wpercent']) && $this->table[$lvl][$nid]['wpercent'] && $lvl>1) {
  17483. $this->table[$lvl][$nid]['w'] = $parentwidth;
  17484. }
  17485. else if ($parentwidth > $this->table[$lvl][$nid]['maw']) {
  17486. $this->table[$lvl][$nid]['w'] = $this->table[$lvl][$nid]['maw'];
  17487. }
  17488. else {
  17489. $this->table[$lvl][$nid]['w'] = $parentwidth;
  17490. }
  17491. unset($c); // mPDF 5.3.79
  17492. $this->_tableWidth($this->table[$lvl][$nid]);
  17493. }
  17494. }
  17495. // Starting at $this->innermostTableLevel
  17496. // Cascade back up nested tables: setting heights back up the tree
  17497. for($lvl=$this->innermostTableLevel;$lvl>0;$lvl--) {
  17498. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  17499. list($tableheight,$maxrowheight,$fullpage,$remainingpage, $maxfirstrowheight) = $this->_tableHeight($this->table[$lvl][$nid]); }
  17500. }
  17501. if ($this->progressBar) { $this->UpdateProgressBar(7,20,' '); } // *PROGRESS-BAR*
  17502. // mPDF 5.3.36
  17503. if ($this->table[1][1]['overflow']=='visible') {
  17504. if ($maxrowheight > $fullpage) { die("mPDF Warning: A Table row is greater than available height. You cannot use CSS overflow:visible"); }
  17505. if ($maxfirstrowheight > $remainingpage) { $this->AddPage($this->CurOrientation); }
  17506. $r = 0; $c = 0; $p = 0; $y = 0;
  17507. while (!$finished) {
  17508. list($finished,$r,$c,$p,$y,$y0) = $this->_tableWrite($this->table[1][1],true,$r,$c,$p,$y);
  17509. if (!$finished) {
  17510. $this->AddPage($this->CurOrientation); // mPDF 5.3.43
  17511. // If printed something on first spread, set same y
  17512. if ($r==0 && $y0 > -1) { $this->y = $y0; }
  17513. }
  17514. }
  17515. }
  17516. else {
  17517. $recalculate = 1;
  17518. $forcerecalc = false;
  17519. // RESIZING ALGORITHM
  17520. if ($maxrowheight > $fullpage) {
  17521. $recalculate = $this->tbsqrt($maxrowheight / $fullpage, 1);
  17522. $forcerecalc = true;
  17523. }
  17524. else if ($this->table_rotate) { // NB $remainingpage == $fullpage == the width of the page
  17525. if ($tableheight > $remainingpage) {
  17526. // If can fit on remainder of page whilst respecting autsize value..
  17527. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, 1)) <= $this->shrink_this_table_to_fit) {
  17528. $recalculate = $this->tbsqrt($tableheight / $remainingpage, 1);
  17529. }
  17530. else if (!$added_page) {
  17531. if ($this->y != $this->tMargin) { // mPDF 5.3.69
  17532. $this->AddPage($this->CurOrientation);
  17533. $this->kwt_moved = true;
  17534. }
  17535. $added_page = true;
  17536. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17537. // 0.001 to force it to recalculate
  17538. $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink
  17539. }
  17540. }
  17541. else { $recalculate = 1; }
  17542. }
  17543. else if ($this->table_keep_together || ($this->table[1][1]['nr']==1 && !$this->writingHTMLfooter)) {
  17544. if ($tableheight > $fullpage) {
  17545. if (($this->shrin_k * $this->tbsqrt($tableheight / $fullpage, 1)) <= $this->shrink_this_table_to_fit) {
  17546. $recalculate = $this->tbsqrt($tableheight / $fullpage, 1);
  17547. }
  17548. else if ($this->tableMinSizePriority) {
  17549. $this->table_keep_together = false;
  17550. $recalculate = 1.001;
  17551. }
  17552. else {
  17553. if ($this->y != $this->tMargin) { // mPDF 5.1
  17554. $this->AddPage($this->CurOrientation);
  17555. $this->kwt_moved = true;
  17556. }
  17557. $added_page = true;
  17558. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17559. $recalculate = $this->tbsqrt($tableheight / $fullpage, 1);
  17560. }
  17561. }
  17562. else if ($tableheight > $remainingpage) {
  17563. // If can fit on remainder of page whilst respecting autsize value..
  17564. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, 1)) <= $this->shrink_this_table_to_fit) {
  17565. $recalculate = $this->tbsqrt($tableheight / $remainingpage, 1);
  17566. }
  17567. else {
  17568. if ($this->y != $this->tMargin) {
  17569. $this->AddPage($this->CurOrientation);
  17570. $this->kwt_moved = true;
  17571. }
  17572. $added_page = true;
  17573. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17574. $recalculate = 1.001;
  17575. }
  17576. }
  17577. else { $recalculate = 1; }
  17578. }
  17579. else { $recalculate = 1; }
  17580. if ($recalculate > $this->shrink_this_table_to_fit && !$forcerecalc) { $recalculate = $this->shrink_this_table_to_fit; }
  17581. $iteration = 1;
  17582. // RECALCULATE
  17583. while($recalculate <> 1) {
  17584. $this->shrin_k1 = $recalculate ;
  17585. $this->shrin_k *= $recalculate ;
  17586. $this->default_font_size /= ($this->shrin_k1) ;
  17587. $this->SetFontSize($this->default_font_size, false );
  17588. $this->SetLineHeight('',$this->table_lineheight);
  17589. $this->table = $save_table;
  17590. // mPDF 5.3.79
  17591. if ($this->cacheTables) { $this->_restoreCacheFiles(); }
  17592. if ($this->shrin_k <> 1) { $this->shrinkTable($this->table[1][1],$this->shrin_k); }
  17593. $this->_tableColumnWidth($this->table[1][1],false); // repeat
  17594. // Starting at $this->innermostTableLevel
  17595. // Shrink table values - and redo columnWidth
  17596. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  17597. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  17598. if ($this->shrin_k <> 1) { $this->shrinkTable($this->table[$lvl][$nid],$this->shrin_k); }
  17599. $this->_tableColumnWidth($this->table[$lvl][$nid],false);
  17600. }
  17601. }
  17602. // Set table cell widths for top level table
  17603. // Top level table
  17604. $this->_tableWidth($this->table[1][1]);
  17605. // mPDF 5.3.79
  17606. // Now work through any nested tables setting child table[w'] = parent cell['w']
  17607. // Now do nested tables _tableWidth
  17608. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  17609. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  17610. // HERE set child table width = cell width
  17611. list($parentrow, $parentcol, $parentnid) = $this->table[$lvl][$nid]['nestedpos'];
  17612. // mPDF 5.3.79
  17613. if ($this->cacheTables) {
  17614. $c = $this->_uncacheCell($this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol], $this->table[($lvl-1)][$parentnid]['cache'], null);
  17615. }
  17616. else
  17617. $c =& $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol];
  17618. if (isset($c['colspan']) && $c['colspan']> 1) {
  17619. $parentwidth = 0;
  17620. for($cs=0;$cs<$c['colspan'] ; $cs++) {
  17621. $parentwidth += $this->table[($lvl-1)][$parentnid]['wc'][$parentcol+$cs];
  17622. }
  17623. }
  17624. else { $parentwidth = $this->table[($lvl-1)][$parentnid]['wc'][$parentcol]; }
  17625. //$parentwidth -= ALLOW FOR PADDING ETC.in parent cell
  17626. if (!$this->simpleTables){
  17627. if ($this->packTableData) {
  17628. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  17629. }
  17630. else {
  17631. $br = $c['border_details']['R']['w'];
  17632. $bl = $c['border_details']['L']['w'];
  17633. }
  17634. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  17635. $parentwidth -= $br + $bl
  17636. + $c['padding']['L']
  17637. + $c['padding']['R']
  17638. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  17639. }
  17640. else {
  17641. $parentwidth -= $br/2 + $bl/2
  17642. + $c['padding']['L']
  17643. + $c['padding']['R'];
  17644. }
  17645. }
  17646. else if ($this->simpleTables){
  17647. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  17648. $parentwidth -= $this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']
  17649. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']
  17650. + $c['padding']['L']
  17651. + $c['padding']['R']
  17652. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  17653. }
  17654. else {
  17655. $parentwidth -= ($this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']
  17656. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']) /2
  17657. + $c['padding']['L']
  17658. + $c['padding']['R'];
  17659. }
  17660. }
  17661. if (isset($this->table[$lvl][$nid]['wpercent']) && $this->table[$lvl][$nid]['wpercent'] && $lvl>1) {
  17662. $this->table[$lvl][$nid]['w'] = $parentwidth;
  17663. }
  17664. else if ($parentwidth > $this->table[$lvl][$nid]['maw']) {
  17665. $this->table[$lvl][$nid]['w'] = $this->table[$lvl][$nid]['maw'] ;
  17666. }
  17667. else {
  17668. $this->table[$lvl][$nid]['w'] = $parentwidth;
  17669. }
  17670. unset($c); // mPDF 5.3.79
  17671. $this->_tableWidth($this->table[$lvl][$nid]);
  17672. }
  17673. }
  17674. // Starting at $this->innermostTableLevel
  17675. // Cascade back up nested tables: setting heights back up the tree
  17676. for($lvl=$this->innermostTableLevel;$lvl>0;$lvl--) {
  17677. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  17678. list($tableheight,$maxrowheight,$fullpage,$remainingpage, $maxfirstrowheight) = $this->_tableHeight($this->table[$lvl][$nid]); }
  17679. }
  17680. // RESIZING ALGORITHM
  17681. if ($maxrowheight > $fullpage) { $recalculate = $this->tbsqrt($maxrowheight / $fullpage, $iteration); $iteration++; }
  17682. else if ($this->table_rotate && $tableheight > $remainingpage && !$added_page) {
  17683. // If can fit on remainder of page whilst respecting autosize value..
  17684. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, $iteration)) <= $this->shrink_this_table_to_fit) {
  17685. $recalculate = $this->tbsqrt($tableheight / $remainingpage, $iteration); $iteration++;
  17686. }
  17687. else {
  17688. if (!$added_page) {
  17689. $this->AddPage($this->CurOrientation);
  17690. $added_page = true;
  17691. $this->kwt_moved = true;
  17692. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17693. }
  17694. // 0.001 to force it to recalculate
  17695. $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink
  17696. }
  17697. }
  17698. else if ($this->table_keep_together || ($this->table[1][1]['nr']==1 && !$this->writingHTMLfooter)) {
  17699. if ($tableheight > $fullpage) {
  17700. if (($this->shrin_k * $this->tbsqrt($tableheight / $fullpage, $iteration)) <= $this->shrink_this_table_to_fit) {
  17701. $recalculate = $this->tbsqrt($tableheight / $fullpage, $iteration); $iteration++;
  17702. }
  17703. else if ($this->tableMinSizePriority) {
  17704. $this->table_keep_together = false;
  17705. $recalculate = (1 / $this->shrin_k) + 0.001;
  17706. }
  17707. else {
  17708. if (!$added_page && $this->y != $this->tMargin) {
  17709. $this->AddPage($this->CurOrientation);
  17710. $added_page = true;
  17711. $this->kwt_moved = true;
  17712. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17713. }
  17714. $recalculate = $this->tbsqrt($tableheight / $fullpage, $iteration); $iteration++;
  17715. }
  17716. }
  17717. else if ($tableheight > $remainingpage) {
  17718. // If can fit on remainder of page whilst respecting autosize value..
  17719. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, $iteration)) <= $this->shrink_this_table_to_fit) {
  17720. $recalculate = $this->tbsqrt($tableheight / $remainingpage, $iteration); $iteration++;
  17721. }
  17722. else {
  17723. if (!$added_page) {
  17724. $this->AddPage($this->CurOrientation);
  17725. $added_page = true;
  17726. $this->kwt_moved = true;
  17727. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17728. }
  17729. //$recalculate = $this->tbsqrt($tableheight / $fullpage, $iteration); $iteration++;
  17730. $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink
  17731. }
  17732. }
  17733. else { $recalculate = 1; }
  17734. }
  17735. else { $recalculate = 1; }
  17736. }
  17737. if ($maxfirstrowheight > $remainingpage && !$added_page && !$this->table_rotate && !$this->ColActive && !$this->table_keep_together && !$this->writingHTMLheader && !$this->writingHTMLfooter) {
  17738. $this->AddPage($this->CurOrientation);
  17739. $this->kwt_moved = true;
  17740. }
  17741. // keep-with-table: if page has advanced, print out buffer now, else done in fn. _Tablewrite()
  17742. if ($this->kwt_saved && $this->kwt_moved) {
  17743. $this->printkwtbuffer();
  17744. $this->kwt_moved = false;
  17745. $this->kwt_saved = false;
  17746. }
  17747. if ($this->progressBar) { $this->UpdateProgressBar(7,30,' '); } // *PROGRESS-BAR*
  17748. // Recursively writes all tables starting at top level
  17749. $this->_tableWrite($this->table[1][1]);
  17750. if ($this->table_rotate && $this->tablebuffer) {
  17751. $this->PageBreakTrigger=$this->h-$this->bMargin;
  17752. $save_tr = $this->table_rotate;
  17753. $save_y = $this->y;
  17754. $this->table_rotate = 0;
  17755. $this->y = $this->tbrot_y0;
  17756. $h = $this->tbrot_w;
  17757. $this->DivLn($h,$this->blklvl,true);
  17758. $this->table_rotate = $save_tr;
  17759. $this->y = $save_y;
  17760. $this->printtablebuffer();
  17761. }
  17762. $this->table_rotate = 0;
  17763. } // mPDF 5.3.36
  17764. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  17765. // mPDF 5.3.91
  17766. $this->maxPosR = max($this->maxPosR , ($this->x + $this->table[1][1]['w']));
  17767. $this->blockjustfinished=true;
  17768. $this->lastblockbottommargin = $this->table[1][1]['margin']['B'];
  17769. //Reset values
  17770. // mPDF 5.3.55
  17771. if (isset($this->table[1][1]['page_break_after'])) { $page_break_after = $this->table[1][1]['page_break_after']; }
  17772. else { $page_break_after = ''; }
  17773. // Keep-with-table
  17774. $this->kwt = false;
  17775. $this->kwt_y0 = 0;
  17776. $this->kwt_x0 = 0;
  17777. $this->kwt_height = 0;
  17778. $this->kwt_buffer = array();
  17779. $this->kwt_Links = array();
  17780. $this->kwt_Annots = array();
  17781. $this->kwt_moved = false;
  17782. $this->kwt_saved = false;
  17783. $this->kwt_Reference = array();
  17784. $this->kwt_BMoutlines = array();
  17785. $this->kwt_toc = array();
  17786. $this->shrin_k = 1;
  17787. $this->shrink_this_table_to_fit = 0;
  17788. unset($this->table);
  17789. $this->table=array(); //array
  17790. $this->tableLevel=0;
  17791. $this->tbctr=array();
  17792. $this->innermostTableLevel=0;
  17793. $this->tbCSSlvl = 0;
  17794. $this->tablecascadeCSS = array();
  17795. unset($this->cell);
  17796. $this->cell=array(); //array
  17797. $this->col=-1; //int
  17798. $this->row=-1; //int
  17799. $this->Reset();
  17800. $this->cellPaddingL = 0;
  17801. $this->cellPaddingT = 0;
  17802. $this->cellPaddingR = 0;
  17803. $this->cellPaddingB = 0;
  17804. $this->cMarginL = 0;
  17805. $this->cMarginT = 0;
  17806. $this->cMarginR = 0;
  17807. $this->cMarginB = 0;
  17808. $this->default_font_size = $this->original_default_font_size;
  17809. $this->default_font = $this->original_default_font;
  17810. $this->SetFontSize($this->default_font_size, false);
  17811. $this->SetFont($this->default_font,'',0,false);
  17812. $this->SetLineHeight();
  17813. if (isset($this->blk[$this->blklvl]['InlineProperties'])) { $this->restoreInlineProperties($this->blk[$this->blklvl]['InlineProperties']);}
  17814. if ($this->progressBar) { $this->UpdateProgressBar(7,100,' '); } // *PROGRESS-BAR*
  17815. // mPDF 5.3.55
  17816. if ($page_break_after) {
  17817. $save_blklvl = $this->blklvl;
  17818. $save_blk = $this->blk;
  17819. $save_silp = $this->saveInlineProperties();
  17820. $save_spanlvl = $this->spanlvl;
  17821. $save_ilp = $this->InlineProperties;
  17822. if ($this->blklvl>1) {
  17823. // Close any open block tags
  17824. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  17825. // Output any text left in buffer
  17826. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); $this->textbuffer=array(); }
  17827. }
  17828. /*-- COLUMNS --*/
  17829. $save_cols = false;
  17830. if ($this->ColActive) {
  17831. $save_cols = true;
  17832. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  17833. $this->SetColumns(0);
  17834. }
  17835. /*-- END COLUMNS --*/
  17836. if ($page_break_after == 'RIGHT') { $this->AddPage($this->CurOrientation,'NEXT-ODD','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  17837. else if ($page_break_after == 'LEFT') { $this->AddPage($this->CurOrientation,'NEXT-EVEN','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  17838. else { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  17839. if (!$this->restoreBlockPagebreaks) {
  17840. $this->blklvl = 0;
  17841. $this->lastblocklevelchange = 0;
  17842. $this->blk = array();
  17843. $this->initialiseBlock($this->blk[0]);
  17844. $this->blk[0]['width'] =& $this->pgwidth;
  17845. $this->blk[0]['inner_width'] =& $this->pgwidth;
  17846. $this->blk[0]['blockContext'] = $this->blockContext;
  17847. $properties = $this->MergeCSS('BLOCK','BODY','');
  17848. $this->setCSS($properties,'','BODY');
  17849. // mPDF 5.3.70
  17850. }
  17851. /*-- COLUMNS --*/
  17852. if ($save_cols) {
  17853. // Restore columns
  17854. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  17855. }
  17856. /*-- END COLUMNS --*/
  17857. if ($this->restoreBlockPagebreaks) {
  17858. $this->blk = $save_blk;
  17859. // Re-open block tags
  17860. $t = $this->blk[0]['tag'];
  17861. $a = $this->blk[0]['attr'];
  17862. $this->blklvl = 0;
  17863. for ($b=0; $b<=$save_blklvl;$b++) {
  17864. $tc = $t;
  17865. $ac = $a;
  17866. $t = $this->blk[$b+1]['tag'];
  17867. $a = $this->blk[$b+1]['attr'];
  17868. unset($this->blk[$b+1]);
  17869. $this->OpenTag($tc,$ac);
  17870. }
  17871. $this->spanlvl = $save_spanlvl;
  17872. $this->InlineProperties = $save_ilp;
  17873. $this->restoreInlineProperties($save_silp);
  17874. }
  17875. }
  17876. }
  17877. /*-- END TABLES --*/
  17878. /*-- LISTS --*/
  17879. // *********** LISTS ********************
  17880. if($tag=='LI') {
  17881. $this->lastoptionaltag = '';
  17882. unset($this->listcascadeCSS[$this->listCSSlvl]);
  17883. $this->listCSSlvl--;
  17884. if (isset($this->listoccur[$this->listlvl]) && isset($this->InlineProperties['LIST'][$this->listlvl][$this->listoccur[$this->listlvl]])) { $this->restoreInlineProperties($this->InlineProperties['LIST'][$this->listlvl][$this->listoccur[$this->listlvl]]); }
  17885. }
  17886. if(($tag=='UL') or ($tag=='OL')) {
  17887. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  17888. unset($this->listcascadeCSS[$this->listCSSlvl]);
  17889. $this->listCSSlvl--;
  17890. $this->lastoptionaltag = '';
  17891. /*-- TABLES --*/
  17892. // A simple list for inside a table
  17893. if($this->tableLevel) {
  17894. $this->listlist[$this->listlvl]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  17895. unset($this->listlist[$this->listlvl]);
  17896. $this->listlvl--;
  17897. if (isset($this->listlist[$this->listlvl]['MAXNUM'])) { $this->listnum = $this->listlist[$this->listlvl]['MAXNUM']; } // restore previous levels
  17898. if ($this->listlvl == 0) { $this->listjustfinished = true; }
  17899. return;
  17900. }
  17901. /*-- END TABLES --*/
  17902. if ($this->listlvl > 1) { // returning one level
  17903. $this->listjustfinished=true;
  17904. if (!empty($this->textbuffer)) {
  17905. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  17906. }
  17907. else {
  17908. $this->listnum--;
  17909. }
  17910. $this->textbuffer = array();
  17911. $occur = $this->listoccur[$this->listlvl];
  17912. $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  17913. $this->listlvl--;
  17914. $occur = $this->listoccur[$this->listlvl];
  17915. $this->listnum = $this->listlist[$this->listlvl][$occur]['MAXNUM']; // recover previous level's number
  17916. $this->listtype = $this->listlist[$this->listlvl][$occur]['TYPE']; // recover previous level's type
  17917. if ($this->InlineProperties['LIST'][$this->listlvl][$occur]) { $this->restoreInlineProperties($this->InlineProperties['LIST'][$this->listlvl][$occur]); }
  17918. }
  17919. else { // We are closing the last OL/UL tag
  17920. if (!empty($this->textbuffer)) {
  17921. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  17922. }
  17923. else {
  17924. $this->listnum--;
  17925. }
  17926. $occur = $this->listoccur[$this->listlvl];
  17927. $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum;
  17928. $this->textbuffer = array();
  17929. $this->listlvl--;
  17930. $this->printlistbuffer();
  17931. unset($this->InlineProperties['LIST']);
  17932. // SPACING AFTER LIST (Top level only)
  17933. $this->Ln(0);
  17934. if ($this->list_margin_bottom) {
  17935. $this->DivLn($this->list_margin_bottom,$this->blklvl,true,1); // collapsible
  17936. }
  17937. if (isset($this->blk[$this->blklvl]['InlineProperties'])) { $this->restoreInlineProperties($this->blk[$this->blklvl]['InlineProperties']);}
  17938. $this->listjustfinished = true;
  17939. $this->listCSSlvl = 0;
  17940. $this->listcascadeCSS = array();
  17941. $this->blockjustfinished=true;
  17942. $this->lastblockbottommargin = $this->list_margin_bottom;
  17943. }
  17944. }
  17945. /*-- END LISTS --*/
  17946. }
  17947. /*-- TABLES --*/
  17948. // This function determines the shrink factor when resizing tables
  17949. // val is the table_height / page_height_available
  17950. // returns a scaling factor used as $shrin_k to resize the table
  17951. // Overcompensating will be quicker but may unnecessarily shrink table too much
  17952. // Undercompensating means it will reiterate more times (taking more processing time)
  17953. function tbsqrt($val, $iteration=3) {
  17954. $k = 4; // Alters number of iterations until it returns $val itself - Must be > 2
  17955. // Probably best guess and most accurate
  17956. if ($iteration==1) return sqrt($val);
  17957. // Faster than using sqrt (because it won't undercompensate), and gives reasonable results
  17958. //return 1+(($val-1)/2);
  17959. $x = 2-(($iteration-2)/($k-2));
  17960. if ($x == 0) { $ret = $val+0.00001; }
  17961. else if ($x < 0) { $ret = 1 + ( pow(2, ($iteration-2-$k))/1000 ); }
  17962. else { $ret = 1+(($val-1)/$x); }
  17963. return $ret;
  17964. }
  17965. /*-- END TABLES --*/
  17966. /*-- LISTS --*/
  17967. function printlistbuffer() {
  17968. //Save x coordinate
  17969. $x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  17970. $this->cMarginL = 0;
  17971. $this->cMarginR = 0;
  17972. $currIndentLvl = -1;
  17973. $lastIndent = array();
  17974. $bak_page = $this->page;
  17975. $indent = 0;
  17976. foreach($this->listitem as $item)
  17977. {
  17978. // COLS
  17979. $oldcolumn = $this->CurrCol;
  17980. $this->bulletarray = array();
  17981. //Get list's buffered data
  17982. $this->listlvl = $lvl = $item[0];
  17983. $num = $item[1];
  17984. $this->textbuffer = $item[2];
  17985. $occur = $item[3];
  17986. if ($item[4]) { $type = $item[4]; } // listitemtype
  17987. else { $type = $this->listlist[$lvl][$occur]['TYPE']; }
  17988. $maxnum = $this->listlist[$lvl][$occur]['MAXNUM'];
  17989. $this->restoreInlineProperties($this->InlineProperties['LIST'][$lvl][$occur]);
  17990. $this->SetFont($this->FontFamily,$this->FontStyle,$this->FontSizePt,true,true); // force to write
  17991. $clh = $this->FontSize;
  17992. $this->SetLineHeight($this->FontSizePt,$this->list_lineheight[$lvl][$occur]);
  17993. $this->listOcc = $occur;
  17994. $this->listnum = $num;
  17995. if (isset($this->list_align[$this->listlvl][$occur])) { $this->divalign = $this->list_align[$this->listlvl][$occur]; }
  17996. else {
  17997. if (isset($this->blk[$this->blklvl]['direction']) && $this->blk[$this->blklvl]['direction']=='rtl') { $this->divalign = 'R'; }
  17998. else { $this->divalign = 'L'; }
  17999. }
  18000. // Set the bullet fontsize
  18001. $bullfs = $this->InlineProperties['LISTITEM'][$lvl][$occur][$num]['size'];
  18002. $space_width = $this->GetCharWidth(' ',false) * 1.5; // mPDF 5.3.04
  18003. //Set default width & height values
  18004. $this->divwidth = $this->blk[$this->blklvl]['inner_width'];
  18005. $this->divheight = $this->lineheight;
  18006. $typefont = $this->FontFamily;
  18007. if (preg_match('/U\+([a-fA-F0-9]+)/i',$type,$m)) {
  18008. if ($this->_charDefined($this->CurrentFont['cw'],hexdec($m[1]))) { $list_item_marker = codeHex2utf($m[1]); }
  18009. else { $list_item_marker = '-'; }
  18010. $blt_width = $this->GetStringWidth($list_item_marker);
  18011. $typefont = '';
  18012. if (preg_match('/rgb\(.*?\)/',$type,$m)) {
  18013. $list_item_color = $this->ConvertColor($m[0]);
  18014. }
  18015. }
  18016. else {
  18017. $list_item_color = false;
  18018. switch($type) //Format type
  18019. {
  18020. case '1':
  18021. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $num; }
  18022. else { $list_item_marker = $num . $this->list_number_suffix; }
  18023. $blt_width = $this->GetStringWidth(str_repeat('5',strlen($maxnum)).$this->list_number_suffix);
  18024. break;
  18025. case 'none':
  18026. $list_item_marker = '';
  18027. $blt_width = 0;
  18028. break;
  18029. case 'A':
  18030. $anum = $this->dec2alpha($num,true);
  18031. $maxnum = $this->dec2alpha($maxnum,true);
  18032. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; }
  18033. else { $list_item_marker = $anum . $this->list_number_suffix; }
  18034. $blt_width = $this->GetStringWidth(str_repeat('W',strlen($maxnum)).$this->list_number_suffix);
  18035. break;
  18036. case 'a':
  18037. $anum = $this->dec2alpha($num,false);
  18038. $maxnum = $this->dec2alpha($maxnum,false);
  18039. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; }
  18040. else { $list_item_marker = $anum . $this->list_number_suffix; }
  18041. $blt_width = $this->GetStringWidth(str_repeat('m',strlen($maxnum)).$this->list_number_suffix);
  18042. break;
  18043. case 'I':
  18044. $anum = $this->dec2roman($num,true);
  18045. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; }
  18046. else { $list_item_marker = $anum . $this->list_number_suffix; }
  18047. if ($maxnum>87) { $bbit = 87; }
  18048. else if ($maxnum>86) { $bbit = 86; }
  18049. else if ($maxnum>37) { $bbit = 38; }
  18050. else if ($maxnum>36) { $bbit = 37; }
  18051. else if ($maxnum>27) { $bbit = 28; }
  18052. else if ($maxnum>26) { $bbit = 27; }
  18053. else if ($maxnum>17) { $bbit = 18; }
  18054. else if ($maxnum>16) { $bbit = 17; }
  18055. else if ($maxnum>7) { $bbit = 8; }
  18056. else if ($maxnum>6) { $bbit = 7; }
  18057. else if ($maxnum>3) { $bbit = 4; }
  18058. else { $bbit = $maxnum; }
  18059. $maxlnum = $this->dec2roman($bbit,true);
  18060. $blt_width = $this->GetStringWidth($maxlnum.$this->list_number_suffix);
  18061. break;
  18062. case 'i':
  18063. $anum = $this->dec2roman($num,false);
  18064. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; }
  18065. else { $list_item_marker = $anum . $this->list_number_suffix; }
  18066. if ($maxnum>87) { $bbit = 87; }
  18067. else if ($maxnum>86) { $bbit = 86; }
  18068. else if ($maxnum>37) { $bbit = 38; }
  18069. else if ($maxnum>36) { $bbit = 37; }
  18070. else if ($maxnum>27) { $bbit = 28; }
  18071. else if ($maxnum>26) { $bbit = 27; }
  18072. else if ($maxnum>17) { $bbit = 18; }
  18073. else if ($maxnum>16) { $bbit = 17; }
  18074. else if ($maxnum>7) { $bbit = 8; }
  18075. else if ($maxnum>6) { $bbit = 7; }
  18076. else if ($maxnum>3) { $bbit = 4; }
  18077. else { $bbit = $maxnum; }
  18078. $maxlnum = $this->dec2roman($bbit,false);
  18079. $blt_width = $this->GetStringWidth($maxlnum.$this->list_number_suffix);
  18080. break;
  18081. case 'disc':
  18082. if ($this->PDFA || $this->PDFX) {
  18083. if ($this->_charDefined($this->CurrentFont['cw'],8226)) { $list_item_marker = "\xe2\x80\xa2"; } // &#8226;
  18084. else { $list_item_marker = '-'; }
  18085. $blt_width = $this->GetCharWidth($list_item_marker); // mPDF 5.3.04
  18086. break;
  18087. }
  18088. $list_item_marker = chr(108); // bullet disc in Zapfdingbats 'l'
  18089. $typefont = 'czapfdingbats';
  18090. $blt_width = (0.791 * $this->FontSize/2.5);
  18091. break;
  18092. case 'circle':
  18093. if ($this->PDFA || $this->PDFX) {
  18094. if ($this->_charDefined($this->CurrentFont['cw'],9900)) { $list_item_marker = "\xe2\x9a\xac"; } // &#9900;
  18095. else { $list_item_marker = '-'; }
  18096. $blt_width = $this->GetCharWidth($list_item_marker); // mPDF 5.3.04
  18097. break;
  18098. }
  18099. $list_item_marker = chr(109); // circle in Zapfdingbats 'm'
  18100. $typefont = 'czapfdingbats';
  18101. $blt_width = (0.873 * $this->FontSize/2.5);
  18102. break;
  18103. case 'square':
  18104. if ($this->PDFA || $this->PDFX) {
  18105. if ($this->_charDefined($this->CurrentFont['cw'],9642)) { $list_item_marker = "\xe2\x96\xaa"; } // &#9642;
  18106. else { $list_item_marker = '-'; }
  18107. $blt_width = $this->GetCharWidth($list_item_marker); // mPDF 5.3.04
  18108. break;
  18109. }
  18110. $list_item_marker = chr(110); //black square in Zapfdingbats font 'n'
  18111. $typefont = 'czapfdingbats';
  18112. $blt_width = (0.761 * $this->FontSize/2.5);
  18113. break;
  18114. /* CSS3 list-styles numeric + I added tamil
  18115. arabic-indic | bengali | cambodian | devanagari | gujarati | gurmukhi | kannada | khmer | lao | malayalam | mongolian | myanmar | oriya | persian | telugu | tibetan | thai | urdu
  18116. */
  18117. case 'arabic-indic':
  18118. $cp = 0x0660;
  18119. $rnum = $this->dec2other($num, $cp);
  18120. $list_item_marker = $this->list_number_suffix . $rnum; // RTL
  18121. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18122. break;
  18123. case 'persian':
  18124. case 'urdu':
  18125. $cp = 0x06F0;
  18126. $rnum = $this->dec2other($num, $cp);
  18127. $list_item_marker = $this->list_number_suffix . $rnum; // RTL
  18128. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18129. break;
  18130. case 'bengali':
  18131. $cp = 0x09E6;
  18132. $rnum = $this->dec2other($num, $cp);
  18133. $list_item_marker = $rnum . $this->list_number_suffix;
  18134. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18135. break;
  18136. case 'devanagari':
  18137. $cp = 0x0966;
  18138. $rnum = $this->dec2other($num, $cp);
  18139. $list_item_marker = $rnum . $this->list_number_suffix;
  18140. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18141. break;
  18142. case 'gujarati':
  18143. $cp = 0x0AE6;
  18144. $rnum = $this->dec2other($num, $cp);
  18145. $list_item_marker = $rnum . $this->list_number_suffix;
  18146. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18147. break;
  18148. case 'gurmukhi':
  18149. $cp = 0x0A66;
  18150. $rnum = $this->dec2other($num, $cp);
  18151. $list_item_marker = $rnum . $this->list_number_suffix;
  18152. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18153. break;
  18154. case 'kannada':
  18155. $cp = 0x0CE6;
  18156. $rnum = $this->dec2other($num, $cp);
  18157. $list_item_marker = $rnum . $this->list_number_suffix;
  18158. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18159. break;
  18160. case 'malayalam':
  18161. $cp = 0x0D66;
  18162. $rnum = $this->dec2other($num, $cp);
  18163. $list_item_marker = $rnum . $this->list_number_suffix;
  18164. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(6, $cp),strlen($maxnum)).$this->list_number_suffix);
  18165. break;
  18166. case 'oriya':
  18167. $cp = 0x0B66;
  18168. $rnum = $this->dec2other($num, $cp);
  18169. $list_item_marker = $rnum . $this->list_number_suffix;
  18170. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18171. break;
  18172. case 'telugu':
  18173. $cp = 0x0C66;
  18174. $rnum = $this->dec2other($num, $cp);
  18175. $list_item_marker = $rnum . $this->list_number_suffix;
  18176. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18177. break;
  18178. case 'tamil':
  18179. $cp = 0x0BE6;
  18180. $rnum = $this->dec2other($num, $cp);
  18181. $list_item_marker = $rnum . $this->list_number_suffix;
  18182. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(9, $cp),strlen($maxnum)).$this->list_number_suffix);
  18183. break;
  18184. case 'thai':
  18185. $cp = 0x0E50;
  18186. $rnum = $this->dec2other($num, $cp);
  18187. $list_item_marker = $rnum . $this->list_number_suffix;
  18188. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(5, $cp),strlen($maxnum)).$this->list_number_suffix);
  18189. break;
  18190. default:
  18191. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $num; }
  18192. else { $list_item_marker = $num . $this->list_number_suffix; }
  18193. $blt_width = $this->GetStringWidth(str_repeat('5',strlen($maxnum)).$this->list_number_suffix);
  18194. break;
  18195. }
  18196. }
  18197. if (isset($item[5]) && $item[5]) { $list_item_marker = ''; } // mPDF 5.3.11
  18198. if ($currIndentLvl < $lvl) {
  18199. if ($lvl > 1 || $this->list_indent_first_level) {
  18200. $indent += $this->list_indent[$lvl][$occur];
  18201. $lastIndent[$lvl] = $this->list_indent[$lvl][$occur];
  18202. }
  18203. }
  18204. else if ($currIndentLvl > $lvl) {
  18205. while ($currIndentLvl > $lvl) {
  18206. $indent -= $lastIndent[$currIndentLvl];
  18207. $currIndentLvl--;
  18208. }
  18209. }
  18210. $currIndentLvl = $lvl;
  18211. /*-- RTL --*/
  18212. if ($this->listDir == 'rtl') {
  18213. // list_align_style Determines alignment of numbers in numbered lists
  18214. if ($this->list_align_style == 'L') { $lalign = 'R'; }
  18215. else { $lalign = 'L'; }
  18216. $this->divwidth = $this->blk[$this->blklvl]['width'] - ($indent + $blt_width + $space_width) ;
  18217. $xb = $this->blk[$this->blklvl]['inner_width'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_left'] - $indent - $blt_width; //Bullet position (relative)
  18218. //Output bullet
  18219. $this->bulletarray = array('w'=>$blt_width,'h'=>$clh,'txt'=>$list_item_marker,'x'=>$xb,'align'=>$lalign,'font'=>$typefont,'level'=>$lvl, 'occur'=>$occur, 'num'=>$num, 'fontsize'=>$bullfs, 'col'=>$list_item_color );
  18220. $this->x = $x;
  18221. }
  18222. else {
  18223. /*-- END RTL --*/
  18224. if ($this->list_align_style == 'L') { $lalign = 'L'; }
  18225. else { $lalign = 'R'; }
  18226. $this->divwidth = $this->blk[$this->blklvl]['width'] - ($indent + $blt_width + $space_width) ;
  18227. $xb = $this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w'] - $blt_width - $space_width;
  18228. //Output bullet
  18229. $this->bulletarray = array('w'=>$blt_width,'h'=>$clh,'txt'=>$list_item_marker,'x'=>$xb,'align'=>$lalign,'font'=>$typefont,'level'=>$lvl, 'occur'=>$occur, 'num'=>$num, 'fontsize'=>$bullfs, 'col'=>$list_item_color );
  18230. $this->x = $x + $indent + $blt_width + $space_width;
  18231. } // *RTL*
  18232. //Print content
  18233. $this->printbuffer($this->textbuffer,'',false,true);
  18234. $this->textbuffer=array();
  18235. // Added to correct for OddEven Margins
  18236. if ($this->page != $bak_page) {
  18237. if (($this->page-$bak_page) % 2 == 1) {
  18238. $x += $this->MarginCorrection;
  18239. }
  18240. $bak_page = $this->page;
  18241. }
  18242. /*-- COLUMNS --*/
  18243. // OR COLUMN CHANGE
  18244. if ($this->CurrCol != $oldcolumn) {
  18245. if ($this->directionality == 'rtl') { // *RTL*
  18246. $x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  18247. } // *RTL*
  18248. else { // *RTL*
  18249. $x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  18250. } // *RTL*
  18251. $oldcolumn = $this->CurrCol;
  18252. }
  18253. /*-- END COLUMNS --*/
  18254. }
  18255. //Reset all used values
  18256. $this->listoccur = array();
  18257. $this->listitem = array();
  18258. $this->listlist = array();
  18259. $this->listlvl = 0;
  18260. $this->listnum = 0;
  18261. $this->listtype = '';
  18262. $this->textbuffer = array();
  18263. $this->divwidth = 0;
  18264. $this->divheight = 0;
  18265. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  18266. }
  18267. /*-- END LISTS --*/
  18268. // mPDF 5.3.99 // mPDF 5.3.A2
  18269. function _saveTextBuffer($t, $link = '', $intlink = '') {
  18270. $this->textbuffer[] = array($t,$link,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,$intlink,$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS,$this->spanborddet, $this->textshadow);
  18271. }
  18272. // mPDF 5.3.99 // mPDF 5.3.A2
  18273. function _saveCellTextBuffer($t, $link = '', $intlink = '') {
  18274. $this->cell[$this->row][$this->col]['textbuffer'][] = array($t,$link,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,$intlink,$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS,$this->spanborddet, $this->textshadow);
  18275. }
  18276. function printbuffer($arrayaux,$blockstate=0,$is_table=false,$is_list=false)
  18277. {
  18278. // $blockstate = 0; // NO margins/padding
  18279. // $blockstate = 1; // Top margins/padding only
  18280. // $blockstate = 2; // Bottom margins/padding only
  18281. // $blockstate = 3; // Top & bottom margins/padding
  18282. $this->spanbgcolorarray = ''; // mPDF 5.3.76
  18283. $this->spanbgcolor = false;
  18284. // mPDF 5.3.61
  18285. $this->spanborder = false;
  18286. $this->spanborddet = array();
  18287. $paint_ht_corr = 0;
  18288. /*-- CSS-FLOAT --*/
  18289. if (count($this->floatDivs)) {
  18290. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  18291. if (($this->blk[$this->blklvl]['inner_width']-$l_width-$r_width) < (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04
  18292. // Too narrow to fit - try to move down past L or R float
  18293. if ($l_max < $r_max && ($this->blk[$this->blklvl]['inner_width']-$r_width) > (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04
  18294. $this->ClearFloats('LEFT', $this->blklvl);
  18295. }
  18296. else if ($r_max < $l_max && ($this->blk[$this->blklvl]['inner_width']-$l_width) > (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04
  18297. $this->ClearFloats('RIGHT', $this->blklvl);
  18298. }
  18299. else { $this->ClearFloats('BOTH', $this->blklvl); }
  18300. }
  18301. }
  18302. /*-- END CSS-FLOAT --*/
  18303. $bak_y = $this->y;
  18304. $bak_x = $this->x;
  18305. $align = '';
  18306. if (!$is_table && !$is_list) {
  18307. if (isset($this->blk[$this->blklvl]['align']) && $this->blk[$this->blklvl]['align']) { $align = $this->blk[$this->blklvl]['align']; }
  18308. // Block-align is set by e.g. <.. align="center"> Takes priority for this block but not inherited
  18309. if (isset($this->blk[$this->blklvl]['block-align']) && $this->blk[$this->blklvl]['block-align']) { $align = $this->blk[$this->blklvl]['block-align']; }
  18310. // mPDF 5.3.76
  18311. if (isset($this->blk[$this->blklvl]['direction'])) $blockdir = $this->blk[$this->blklvl]['direction'];
  18312. else $blockdir = "";
  18313. $this->divwidth = $this->blk[$this->blklvl]['width'];
  18314. }
  18315. else {
  18316. $align = $this->divalign;
  18317. if ($is_table) { $blockdir = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['direction']; }
  18318. else { $blockdir = $this->listDir; }
  18319. }
  18320. $oldpage = $this->page;
  18321. // ADDED for Out of Block now done as Flowing Block
  18322. if ($this->divwidth == 0) {
  18323. $this->divwidth = $this->pgwidth;
  18324. }
  18325. if (!$is_table && !$is_list) { $this->SetLineHeight($this->FontSizePt,$this->blk[$this->blklvl]['line_height']); }
  18326. $this->divheight = $this->lineheight;
  18327. $old_height = $this->divheight;
  18328. // As a failsafe - if font has been set but not output to page
  18329. $this->SetFont($this->default_font,'',$this->default_font_size,true,true); // force output to page
  18330. $array_size = count($arrayaux);
  18331. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,true,$blockdir);
  18332. // Added - Otherwise <div><div><p> did not output top margins/padding for 1st/2nd div
  18333. if ($array_size == 0) { $this->finishFlowingBlock(true); } // true = END of flowing block
  18334. for($i=0;$i < $array_size; $i++)
  18335. {
  18336. // COLS
  18337. $oldcolumn = $this->CurrCol;
  18338. $vetor = $arrayaux[$i];
  18339. if ($i == 0 and $vetor[0] != "\n" and !$this->ispre) {
  18340. $vetor[0] = ltrim($vetor[0]);
  18341. }
  18342. // FIXED TO ALLOW IT TO SHOW '0'
  18343. if (empty($vetor[0]) && !($vetor[0]==='0') && empty($vetor[7])) { //Ignore empty text and not carrying an internal link
  18344. //Check if it is the last element. If so then finish printing the block
  18345. if ($i == ($array_size-1)) { $this->finishFlowingBlock(true); } // true = END of flowing block
  18346. continue;
  18347. }
  18348. //Activating buffer properties
  18349. if(isset($vetor[11]) and $vetor[11] != '') { // Font Size
  18350. if ($is_table && $this->shrin_k) {
  18351. $this->SetFontSize($vetor[11]/$this->shrin_k,false);
  18352. }
  18353. else {
  18354. $this->SetFontSize($vetor[11],false);
  18355. }
  18356. }
  18357. // mPDF 5.3.A2
  18358. if(isset($vetor[17]) && !empty($vetor[17])) { //TextShadow
  18359. $this->textshadow = $vetor[17];
  18360. }
  18361. // mPDF 5.3.61
  18362. if(isset($vetor[16]) && !empty($vetor[16])) { //Border
  18363. $this->spanborddet = $vetor[16];
  18364. $this->spanborder = true;
  18365. }
  18366. if(isset($vetor[15])) { // Word spacing
  18367. $this->wSpacingCSS = $vetor[15];
  18368. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  18369. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  18370. }
  18371. }
  18372. if(isset($vetor[14])) { // Letter spacing
  18373. $this->lSpacingCSS = $vetor[14];
  18374. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') {
  18375. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  18376. }
  18377. }
  18378. if(isset($vetor[13])) { // Font Kerning
  18379. $this->kerning = $vetor[13];
  18380. }
  18381. if(isset($vetor[10]) and !empty($vetor[10])) //Background color
  18382. {
  18383. $this->spanbgcolorarray = $vetor[10];
  18384. $this->spanbgcolor = true;
  18385. }
  18386. if(isset($vetor[9]) and !empty($vetor[9])) // Outline parameters
  18387. {
  18388. $cor = $vetor[9]['COLOR'];
  18389. $outlinewidth = $vetor[9]['WIDTH'];
  18390. $this->SetTextOutline($outlinewidth,$cor);
  18391. $this->outline_on = true;
  18392. }
  18393. if(isset($vetor[8]) and $vetor[8] === true) // strike-through the text
  18394. {
  18395. $this->strike = true;
  18396. }
  18397. if(isset($vetor[7]) and $vetor[7] != '') // internal link: <a name="anyvalue">
  18398. {
  18399. // mPDF 5.3.01
  18400. // if ($this->ColActive) { $ily = $this->y0; } else { $ily = $this->y; } // use top of columns
  18401. $ily = $this->y;
  18402. if ($this->keep_block_together) { $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page, "kt"=>true ); }
  18403. else if ($this->table_rotate) { $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page, "tbrot"=>true ); }
  18404. else if ($this->kwt) { $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page, "kwt"=>true ); }
  18405. else if ($this->ColActive) { $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page, "col"=>$this->CurrCol ); }
  18406. else
  18407. $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page );
  18408. if (empty($vetor[0])) { //Ignore empty text
  18409. //Check if it is the last element. If so then finish printing the block
  18410. if ($i == ($array_size-1)) { $this->finishFlowingBlock(true); } // true = END of flowing block
  18411. continue;
  18412. }
  18413. }
  18414. if(isset($vetor[6]) and $vetor[6] === true) // Subscript
  18415. {
  18416. $this->SUB = true;
  18417. }
  18418. if(isset($vetor[5]) and $vetor[5] === true) // Superscript
  18419. {
  18420. $this->SUP = true;
  18421. }
  18422. if(isset($vetor[4]) and $vetor[4] != '') { // Font Family
  18423. $font = $this->SetFont($vetor[4],$this->FontStyle,0,false);
  18424. }
  18425. if (!empty($vetor[3])) //Font Color
  18426. {
  18427. $cor = $vetor[3];
  18428. $this->SetTColor($cor);
  18429. }
  18430. if(isset($vetor[2]) and $vetor[2] != '') //Bold,Italic,Underline styles
  18431. {
  18432. $this->SetStyles($vetor[2]);
  18433. }
  18434. if(isset($vetor[12]) and $vetor[12] != '') { //Requested Bold,Italic,Underline
  18435. $this->ReqFontStyle = $vetor[12];
  18436. }
  18437. if(isset($vetor[1]) and $vetor[1] != '') //LINK
  18438. {
  18439. if (strpos($vetor[1],".") === false && strpos($vetor[1],"@") !== 0) //assuming every external link has a dot indicating extension (e.g: .html .txt .zip www.somewhere.com etc.)
  18440. {
  18441. //Repeated reference to same anchor?
  18442. while(array_key_exists($vetor[1],$this->internallink)) $vetor[1]="#".$vetor[1];
  18443. $this->internallink[$vetor[1]] = $this->AddLink();
  18444. $vetor[1] = $this->internallink[$vetor[1]];
  18445. }
  18446. $this->HREF = $vetor[1]; // HREF link style set here ******
  18447. }
  18448. // SPECIAL CONTENT - IMAGES & FORM OBJECTS
  18449. //Print-out special content
  18450. if (substr($vetor[0],0,3) == "\xbb\xa4\xac") { //identifier has been identified!
  18451. $objattr = $this->_getObjAttr($vetor[0]);
  18452. /*-- TABLES --*/
  18453. if ($objattr['type'] == 'nestedtable') {
  18454. // mPDF 5.3.79 NB Following code moved inside the if ...
  18455. if ($objattr['nestedcontent']) {
  18456. $level = $objattr['level'];
  18457. $table = &$this->table[$level][$objattr['table']];
  18458. // mPDF 5.3.79
  18459. if ($this->cacheTables) {
  18460. $fh = fopen($table['cache'], "r+b");
  18461. $cell = $this->_uncacheCell($table['cells'][$objattr['row']][$objattr['col']], '', $fh);
  18462. }
  18463. else {
  18464. $fh = null;
  18465. $cell = &$table['cells'][$objattr['row']][$objattr['col']];
  18466. }
  18467. $this->finishFlowingBlock(false,'nestedtable');
  18468. $save_dw = $this->divwidth ;
  18469. $save_buffer = $this->cellBorderBuffer;
  18470. $this->cellBorderBuffer = array();
  18471. $ncx = $this->x;
  18472. list($dummyx,$w) = $this->_tableGetWidth($table, $objattr['row'], $objattr['col'], $fh); // mPDF 5.3.79
  18473. $ntw = $this->table[($level+1)][$objattr['nestedcontent']]['w']; // nested table width
  18474. if (!$this->simpleTables){
  18475. if ($this->packTableData) {
  18476. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cell['borderbin']);
  18477. }
  18478. else {
  18479. $br = $cell['border_details']['R']['w'];
  18480. $bl = $cell['border_details']['L']['w'];
  18481. }
  18482. if ($table['borders_separate']) {
  18483. $innerw = $w - $bl - $br - $cell['padding']['L'] - $cell['padding']['R'] - $table['border_spacing_H'];
  18484. }
  18485. else {
  18486. $innerw = $w - $bl/2 - $br/2 - $cell['padding']['L'] - $cell['padding']['R'];
  18487. }
  18488. }
  18489. else if ($this->simpleTables){
  18490. if ($table['borders_separate']) {
  18491. $innerw = $w - $table['simple']['border_details']['L']['w'] - $table['simple']['border_details']['R']['w'] - $cell['padding']['L'] - $cell['padding']['R'] - $table['border_spacing_H'];
  18492. }
  18493. else {
  18494. $innerw = $w - $table['simple']['border_details']['L']['w']/2 - $table['simple']['border_details']['R']['w']/2 - $cell['padding']['L'] - $cell['padding']['R'];
  18495. }
  18496. }
  18497. if ($cell['a']=='C' || $this->table[($level+1)][$objattr['nestedcontent']]['a']=='C') {
  18498. $ncx += ($innerw-$ntw)/2;
  18499. }
  18500. elseif ($cell['a']=='R' || $this->table[($level+1)][$objattr['nestedcontent']]['a']=='R') {
  18501. $ncx += $innerw- $ntw;
  18502. }
  18503. $this->x = $ncx ;
  18504. // mPDF 5.3.79
  18505. if ($this->cacheTables) { fclose($fh); }
  18506. $this->_tableWrite($this->table[($level+1)][$objattr['nestedcontent']]);
  18507. $this->cellBorderBuffer = $save_buffer;
  18508. $this->x = $bak_x ;
  18509. $this->divwidth = $save_dw;
  18510. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,false,$blockdir);
  18511. }
  18512. }
  18513. else {
  18514. /*-- END TABLES --*/
  18515. if ($is_table) { // *TABLES*
  18516. $maxWidth = $this->divwidth; // *TABLES*
  18517. } // *TABLES*
  18518. else { // *TABLES*
  18519. $maxWidth = $this->divwidth - ($this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_right'] + $this->blk[$this->blklvl]['border_right']['w']);
  18520. } // *TABLES*
  18521. /*-- CSS-IMAGE-FLOAT --*/
  18522. // If float (already) exists at this level
  18523. if (isset($this->floatmargins['R']) && $this->y <= $this->floatmargins['R']['y1'] && $this->y >= $this->floatmargins['R']['y0']) { $maxWidth -= $this->floatmargins['R']['w']; }
  18524. if (isset($this->floatmargins['L']) && $this->y <= $this->floatmargins['L']['y1'] && $this->y >= $this->floatmargins['L']['y0']) { $maxWidth -= $this->floatmargins['L']['w']; }
  18525. /*-- END CSS-IMAGE-FLOAT --*/
  18526. list($skipln) = $this->inlineObject($objattr['type'], '', $this->y, $objattr,$this->lMargin, ($this->flowingBlockAttr['contentWidth']/_MPDFK), $maxWidth, $this->flowingBlockAttr['height'], false, $is_table);
  18527. // 1 -> New line needed because of width
  18528. // -1 -> Will fit width on line but NEW PAGE REQUIRED because of height
  18529. // -2 -> Will not fit on line therefore needs new line but thus NEW PAGE REQUIRED
  18530. $iby = $this->y;
  18531. $oldpage = $this->page;
  18532. $oldcol = $this->CurrCol;
  18533. if (($skipln == 1 || $skipln == -2) && !isset($objattr['float'])) {
  18534. $this->finishFlowingBlock(false,$objattr['type']);
  18535. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,false,$blockdir);
  18536. }
  18537. $thispage = $this->page;
  18538. if ($this->CurrCol!=$oldcol) { $changedcol = true; }
  18539. else { $changedcol=false; }
  18540. // the previous lines can already have triggered page break or column change
  18541. if (!$changedcol && $skipln <0 && $this->AcceptPageBreak() && $thispage==$oldpage) {
  18542. $this->AddPage($this->CurOrientation);
  18543. // Added to correct Images already set on line before page advanced
  18544. // i.e. if second inline image on line is higher than first and forces new page
  18545. if (count($this->objectbuffer)) {
  18546. $yadj = $iby - $this->y;
  18547. foreach($this->objectbuffer AS $ib=>$val) {
  18548. if ($this->objectbuffer[$ib]['OUTER-Y'] ) $this->objectbuffer[$ib]['OUTER-Y'] -= $yadj;
  18549. if ($this->objectbuffer[$ib]['BORDER-Y']) $this->objectbuffer[$ib]['BORDER-Y'] -= $yadj;
  18550. if ($this->objectbuffer[$ib]['INNER-Y']) $this->objectbuffer[$ib]['INNER-Y'] -= $yadj;
  18551. }
  18552. }
  18553. }
  18554. // Added to correct for OddEven Margins
  18555. if ($this->page != $oldpage) {
  18556. if (($this->page-$oldpage) % 2 == 1) {
  18557. $bak_x += $this->MarginCorrection;
  18558. }
  18559. $oldpage = $this->page;
  18560. $y = $this->tMargin - $paint_ht_corr ;
  18561. $this->oldy = $this->tMargin - $paint_ht_corr ;
  18562. $old_height = 0;
  18563. }
  18564. $this->x = $bak_x;
  18565. /*-- COLUMNS --*/
  18566. // COLS
  18567. // OR COLUMN CHANGE
  18568. if ($this->CurrCol != $oldcolumn) {
  18569. if ($this->directionality == 'rtl') { // *RTL*
  18570. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  18571. } // *RTL*
  18572. else { // *RTL*
  18573. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  18574. } // *RTL*
  18575. $this->x = $bak_x;
  18576. $oldcolumn = $this->CurrCol;
  18577. $y = $this->y0 - $paint_ht_corr ;
  18578. $this->oldy = $this->y0 - $paint_ht_corr ;
  18579. $old_height = 0;
  18580. }
  18581. /*-- END COLUMNS --*/
  18582. /*-- CSS-IMAGE-FLOAT --*/
  18583. if ($objattr['type'] == 'image' && isset($objattr['float'])) {
  18584. $fy = $this->y;
  18585. // DIV TOP MARGIN/BORDER/PADDING
  18586. if ($this->flowingBlockAttr['newblock'] && ($this->flowingBlockAttr['blockstate']==1 || $this->flowingBlockAttr['blockstate']==3) && $this->flowingBlockAttr['lineCount']== 0) {
  18587. $fy += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  18588. }
  18589. if ($objattr['float']=='R') {
  18590. $fx = $this->w - $this->rMargin - $objattr['width'] - ($this->blk[$this->blklvl]['outer_right_margin'] + $this->blk[$this->blklvl]['border_right']['w'] + $this->blk[$this->blklvl]['padding_right']);
  18591. }
  18592. else if ($objattr['float']=='L') {
  18593. $fx = $this->lMargin + ($this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_left']);
  18594. }
  18595. $w = $objattr['width'];
  18596. $h = abs($objattr['height']);
  18597. $widthLeft = $maxWidth - ($this->flowingBlockAttr['contentWidth']/_MPDFK);
  18598. $maxHeight = $this->h - ($this->tMargin + $this->margin_header + $this->bMargin + 10) ;
  18599. // For Images
  18600. $extraWidth = ($objattr['border_left']['w'] + $objattr['border_right']['w'] + $objattr['margin_left']+ $objattr['margin_right']);
  18601. $extraHeight = ($objattr['border_top']['w'] + $objattr['border_bottom']['w'] + $objattr['margin_top']+ $objattr['margin_bottom']);
  18602. if ($objattr['itype'] == 'wmf' || $objattr['itype'] == 'svg') {
  18603. $file = $objattr['file'];
  18604. $info=$this->formobjects[$file];
  18605. }
  18606. else {
  18607. $file = $objattr['file'];
  18608. $info=$this->images[$file];
  18609. }
  18610. $img_w = $w - $extraWidth ;
  18611. $img_h = $h - $extraHeight ;
  18612. if ($objattr['border_left']['w']) {
  18613. $objattr['BORDER-WIDTH'] = $img_w + (($objattr['border_left']['w'] + $objattr['border_right']['w'])/2) ;
  18614. $objattr['BORDER-HEIGHT'] = $img_h + (($objattr['border_top']['w'] + $objattr['border_bottom']['w'])/2) ;
  18615. $objattr['BORDER-X'] = $fx + $objattr['margin_left'] + (($objattr['border_left']['w'])/2) ;
  18616. $objattr['BORDER-Y'] = $fy + $objattr['margin_top'] + (($objattr['border_top']['w'])/2) ;
  18617. }
  18618. $objattr['INNER-WIDTH'] = $img_w;
  18619. $objattr['INNER-HEIGHT'] = $img_h;
  18620. $objattr['INNER-X'] = $fx + $objattr['margin_left'] + ($objattr['border_left']['w']);
  18621. $objattr['INNER-Y'] = $fy + $objattr['margin_top'] + ($objattr['border_top']['w']) ;
  18622. $objattr['ID'] = $info['i'];
  18623. $objattr['OUTER-WIDTH'] = $w;
  18624. $objattr['OUTER-HEIGHT'] = $h;
  18625. $objattr['OUTER-X'] = $fx;
  18626. $objattr['OUTER-Y'] = $fy;
  18627. if ($objattr['float']=='R') {
  18628. // If R float already exists at this level
  18629. $this->floatmargins['R']['skipline'] = false;
  18630. if (isset($this->floatmargins['R']['y1']) && $this->floatmargins['R']['y1'] > 0 && $fy < $this->floatmargins['R']['y1']) {
  18631. $this->WriteFlowingBlock($vetor[0]);
  18632. }
  18633. // If L float already exists at this level
  18634. else if (isset($this->floatmargins['L']['y1']) && $this->floatmargins['L']['y1'] > 0 && $fy < $this->floatmargins['L']['y1']) {
  18635. // Final check distance between floats is not now too narrow to fit text
  18636. $mw = 2*$this->GetCharWidth('W',false); // mPDF 5.3.04
  18637. if (($this->blk[$this->blklvl]['inner_width'] - $w - $this->floatmargins['L']['w']) < $mw) {
  18638. $this->WriteFlowingBlock($vetor[0]);
  18639. }
  18640. else {
  18641. $this->floatmargins['R']['x'] = $fx;
  18642. $this->floatmargins['R']['w'] = $w;
  18643. $this->floatmargins['R']['y0'] = $fy;
  18644. $this->floatmargins['R']['y1'] = $fy + $h;
  18645. if ($skipln == 1) {
  18646. $this->floatmargins['R']['skipline'] = true;
  18647. $this->floatmargins['R']['id'] = count($this->floatbuffer)+0;
  18648. $objattr['skipline'] = true;
  18649. }
  18650. $this->floatbuffer[] = $objattr;
  18651. }
  18652. }
  18653. else {
  18654. $this->floatmargins['R']['x'] = $fx;
  18655. $this->floatmargins['R']['w'] = $w;
  18656. $this->floatmargins['R']['y0'] = $fy;
  18657. $this->floatmargins['R']['y1'] = $fy + $h;
  18658. if ($skipln == 1) {
  18659. $this->floatmargins['R']['skipline'] = true;
  18660. $this->floatmargins['R']['id'] = count($this->floatbuffer)+0;
  18661. $objattr['skipline'] = true;
  18662. }
  18663. $this->floatbuffer[] = $objattr;
  18664. }
  18665. }
  18666. else if ($objattr['float']=='L') {
  18667. // If L float already exists at this level
  18668. $this->floatmargins['L']['skipline'] = false;
  18669. if (isset($this->floatmargins['L']['y1']) && $this->floatmargins['L']['y1'] > 0 && $fy < $this->floatmargins['L']['y1']) {
  18670. $this->floatmargins['L']['skipline'] = false;
  18671. $this->WriteFlowingBlock($vetor[0]);
  18672. }
  18673. // If R float already exists at this level
  18674. else if (isset($this->floatmargins['R']['y1']) && $this->floatmargins['R']['y1'] > 0 && $fy < $this->floatmargins['R']['y1']) {
  18675. // Final check distance between floats is not now too narrow to fit text
  18676. $mw = 2*$this->GetCharWidth('W',false); // mPDF 5.3.04
  18677. if (($this->blk[$this->blklvl]['inner_width'] - $w - $this->floatmargins['R']['w']) < $mw) {
  18678. $this->WriteFlowingBlock($vetor[0]);
  18679. }
  18680. else {
  18681. $this->floatmargins['L']['x'] = $fx + $w;
  18682. $this->floatmargins['L']['w'] = $w;
  18683. $this->floatmargins['L']['y0'] = $fy;
  18684. $this->floatmargins['L']['y1'] = $fy + $h;
  18685. if ($skipln == 1) {
  18686. $this->floatmargins['L']['skipline'] = true;
  18687. $this->floatmargins['L']['id'] = count($this->floatbuffer)+0;
  18688. $objattr['skipline'] = true;
  18689. }
  18690. $this->floatbuffer[] = $objattr;
  18691. }
  18692. }
  18693. else {
  18694. $this->floatmargins['L']['x'] = $fx + $w;
  18695. $this->floatmargins['L']['w'] = $w;
  18696. $this->floatmargins['L']['y0'] = $fy;
  18697. $this->floatmargins['L']['y1'] = $fy + $h;
  18698. if ($skipln == 1) {
  18699. $this->floatmargins['L']['skipline'] = true;
  18700. $this->floatmargins['L']['id'] = count($this->floatbuffer)+0;
  18701. $objattr['skipline'] = true;
  18702. }
  18703. $this->floatbuffer[] = $objattr;
  18704. }
  18705. }
  18706. }
  18707. else {
  18708. /*-- END CSS-IMAGE-FLOAT --*/
  18709. $this->WriteFlowingBlock($vetor[0]);
  18710. /*-- CSS-IMAGE-FLOAT --*/
  18711. }
  18712. /*-- END CSS-IMAGE-FLOAT --*/
  18713. } // *TABLES*
  18714. } // END If special content
  18715. else { //THE text
  18716. if ($this->tableLevel) { $paint_ht_corr = 0; } // To move the y up when new column/page started if div border needed
  18717. else { $paint_ht_corr = $this->blk[$this->blklvl]['border_top']['w']; }
  18718. if ($vetor[0] == "\n") { //We are reading a <BR> now turned into newline ("\n")
  18719. if ($this->flowingBlockAttr['content']) {
  18720. $this->finishFlowingBlock(false,'br');
  18721. }
  18722. else if ($is_table) {
  18723. $this->y+= $this->_computeLineheight($this->table_lineheight);
  18724. }
  18725. else if (!$is_table) {
  18726. $this->DivLn($this->lineheight);
  18727. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  18728. }
  18729. // Added to correct for OddEven Margins
  18730. if ($this->page != $oldpage) {
  18731. if (($this->page-$oldpage) % 2 == 1) {
  18732. $bak_x += $this->MarginCorrection;
  18733. }
  18734. $oldpage = $this->page;
  18735. $y = $this->tMargin - $paint_ht_corr ;
  18736. $this->oldy = $this->tMargin - $paint_ht_corr ;
  18737. $old_height = 0;
  18738. }
  18739. $this->x = $bak_x;
  18740. /*-- COLUMNS --*/
  18741. // COLS
  18742. // OR COLUMN CHANGE
  18743. if ($this->CurrCol != $oldcolumn) {
  18744. if ($this->directionality == 'rtl') { // *RTL*
  18745. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  18746. } // *RTL*
  18747. else { // *RTL*
  18748. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  18749. } // *RTL*
  18750. $this->x = $bak_x;
  18751. $oldcolumn = $this->CurrCol;
  18752. $y = $this->y0 - $paint_ht_corr ;
  18753. $this->oldy = $this->y0 - $paint_ht_corr ;
  18754. $old_height = 0;
  18755. }
  18756. /*-- END COLUMNS --*/
  18757. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,false,$blockdir);
  18758. }
  18759. else {
  18760. $this->WriteFlowingBlock( $vetor[0]);
  18761. // Added to correct for OddEven Margins
  18762. if ($this->page != $oldpage) {
  18763. if (($this->page-$oldpage) % 2 == 1) {
  18764. $bak_x += $this->MarginCorrection;
  18765. $this->x = $bak_x;
  18766. }
  18767. $oldpage = $this->page;
  18768. $y = $this->tMargin - $paint_ht_corr ;
  18769. $this->oldy = $this->tMargin - $paint_ht_corr ;
  18770. $old_height = 0;
  18771. }
  18772. /*-- COLUMNS --*/
  18773. // COLS
  18774. // OR COLUMN CHANGE
  18775. if ($this->CurrCol != $oldcolumn) {
  18776. if ($this->directionality == 'rtl') { // *RTL*
  18777. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  18778. } // *RTL*
  18779. else { // *RTL*
  18780. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  18781. } // *RTL*
  18782. $this->x = $bak_x;
  18783. $oldcolumn = $this->CurrCol;
  18784. $y = $this->y0 - $paint_ht_corr ;
  18785. $this->oldy = $this->y0 - $paint_ht_corr ;
  18786. $old_height = 0;
  18787. }
  18788. /*-- END COLUMNS --*/
  18789. }
  18790. }
  18791. //Check if it is the last element. If so then finish printing the block
  18792. if ($i == ($array_size-1)) {
  18793. $this->finishFlowingBlock(true); // true = END of flowing block
  18794. // Added to correct for OddEven Margins
  18795. if ($this->page != $oldpage) {
  18796. if (($this->page-$oldpage) % 2 == 1) {
  18797. $bak_x += $this->MarginCorrection;
  18798. $this->x = $bak_x;
  18799. }
  18800. $oldpage = $this->page;
  18801. $y = $this->tMargin - $paint_ht_corr ;
  18802. $this->oldy = $this->tMargin - $paint_ht_corr ;
  18803. $old_height = 0;
  18804. }
  18805. /*-- COLUMNS --*/
  18806. // COLS
  18807. // OR COLUMN CHANGE
  18808. if ($this->CurrCol != $oldcolumn) {
  18809. if ($this->directionality == 'rtl') { // *RTL*
  18810. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  18811. } // *RTL*
  18812. else { // *RTL*
  18813. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  18814. } // *RTL*
  18815. $this->x = $bak_x;
  18816. $oldcolumn = $this->CurrCol;
  18817. $y = $this->y0 - $paint_ht_corr ;
  18818. $this->oldy = $this->y0 - $paint_ht_corr ;
  18819. $old_height = 0;
  18820. }
  18821. /*-- END COLUMNS --*/
  18822. }
  18823. // RESETTING VALUES
  18824. $this->SetTColor($this->ConvertColor(0));
  18825. $this->SetDColor($this->ConvertColor(0));
  18826. $this->SetFColor($this->ConvertColor(255));
  18827. $this->colorarray = ''; // mPDF 5.3.76
  18828. $this->spanbgcolorarray = ''; // mPDF 5.3.76
  18829. $this->spanbgcolor = false;
  18830. // mPDF 5.3.61
  18831. $this->spanborder = false;
  18832. $this->spanborddet = array();
  18833. $this->HREF = '';
  18834. $this->outlineparam = array();
  18835. $this->SetTextOutline(false);
  18836. $this->outline_on = false;
  18837. $this->SUP = false;
  18838. $this->SUB = false;
  18839. $this->strike = false;
  18840. $this->textshadow = ''; // mPDF 5.3.A2
  18841. $this->currentfontfamily = '';
  18842. $this->currentfontsize = '';
  18843. $this->currentfontstyle = '';
  18844. /*-- TABLES --*/
  18845. if ($this->tableLevel) {
  18846. $this->SetLineHeight('',$this->table_lineheight); // *TABLES*
  18847. }
  18848. else
  18849. /*-- END TABLES --*/
  18850. /*-- LISTS --*/
  18851. if ($is_list && $this->list_lineheight[$this->listlvl][$this->listOcc]) { // mPDF 5.3.76
  18852. $this->SetLineHeight('',$this->list_lineheight[$this->listlvl][$this->listOcc]); // sets default line height
  18853. }
  18854. else
  18855. /*-- END LISTS --*/
  18856. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  18857. $this->SetLineHeight('',$this->blk[$this->blklvl]['line_height']); // sets default line height
  18858. }
  18859. $this->ResetStyles();
  18860. $this->toupper = false;
  18861. $this->tolower = false;
  18862. $this->capitalize = false;
  18863. $this->kerning = false;
  18864. $this->lSpacingCSS = '';
  18865. $this->wSpacingCSS = '';
  18866. $this->fixedlSpacing = false;
  18867. $this->minwSpacing = 0;
  18868. $this->SetDash();
  18869. $this->dash_on = false;
  18870. $this->dotted_on = false;
  18871. }//end of for(i=0;i<arraysize;i++)
  18872. // PAINT DIV BORDER // DISABLED IN COLUMNS AS DOESN'T WORK WHEN BROKEN ACROSS COLS??
  18873. if ((isset($this->blk[$this->blklvl]['border']) || isset($this->blk[$this->blklvl]['bgcolor']) || isset($this->blk[$this->blklvl]['box_shadow'])) && $blockstate && ($this->y != $this->oldy)) { // mPDF 5.3.A1
  18874. $bottom_y = $this->y; // Does not include Bottom Margin
  18875. if (isset($this->blk[$this->blklvl]['startpage']) && $this->blk[$this->blklvl]['startpage'] != $this->page && $blockstate != 1) {
  18876. $this->PaintDivBB('pagetop',$blockstate);
  18877. }
  18878. else if ($blockstate != 1) {
  18879. $this->PaintDivBB('',$blockstate);
  18880. }
  18881. $this->y = $bottom_y;
  18882. $this->x = $bak_x;
  18883. }
  18884. // Reset Font
  18885. $this->SetFontSize($this->default_font_size,false);
  18886. }
  18887. function _setDashBorder($style, $div, $cp, $side) {
  18888. if ($style == 'dashed' && (($side=='L' || $side=='R') || ($side=='T' && $div != 'pagetop' && !$cp) || ($side=='B' && $div!='pagebottom') )) {
  18889. $dashsize = 2; // final dash will be this + 1*linewidth
  18890. $dashsizek = 1.5; // ratio of Dash/Blank
  18891. $this->SetDash($dashsize,($dashsize/$dashsizek)+($this->LineWidth*2));
  18892. }
  18893. else if ($style == 'dotted' || ($side=='T' && ($div == 'pagetop' || $cp)) || ($side=='B' && $div == 'pagebottom')) {
  18894. //Round join and cap
  18895. $this->SetLineJoin(1);
  18896. $this->SetLineCap(1);
  18897. $this->SetDash(0.001,($this->LineWidth*3));
  18898. }
  18899. }
  18900. function _setBorderLine($b, $k=1) {
  18901. $this->SetLineWidth($b['w']/$k);
  18902. $this->SetDColor($b['c']);
  18903. if ($b['c'][0]==5) { // RGBa
  18904. $this->SetAlpha($b['c'][4], 'Normal', false, 'S')."\n";
  18905. }
  18906. else if ($b['c'][0]==6) { // CMYKa
  18907. $this->SetAlpha($b['c'][5], 'Normal', false, 'S')."\n";
  18908. }
  18909. }
  18910. function PaintDivBB($divider='',$blockstate=0,$blvl=0) {
  18911. // Borders & backgrounds are done elsewhere for columns - messes up the repositioning in printcolumnbuffer
  18912. if ($this->ColActive) { return ; } // *COLUMNS*
  18913. $save_y = $this->y;
  18914. if (!$blvl) { $blvl = $this->blklvl; }
  18915. $x0 = $x1 = $y0 = $y1 = 0;
  18916. // Added mPDF 3.0 Float DIV
  18917. if (isset($this->blk[$blvl]['bb_painted'][$this->page]) && $this->blk[$blvl]['bb_painted'][$this->page]) { return; } // *CSS-FLOAT*
  18918. if (isset($this->blk[$blvl]['x0'])) { $x0 = $this->blk[$blvl]['x0']; } // left
  18919. if (isset($this->blk[$blvl]['y1'])) { $y1 = $this->blk[$blvl]['y1']; } // bottom
  18920. // Added mPDF 3.0 Float DIV - ensures backgrounds/borders are drawn to bottom of page
  18921. if ($y1==0) {
  18922. if ($divider=='pagebottom') { $y1 = $this->h-$this->bMargin; }
  18923. else { $y1 = $this->y; }
  18924. }
  18925. if (isset($this->blk[$blvl]['startpage']) && $this->blk[$blvl]['startpage'] != $this->page) { $continuingpage = true; } else { $continuingpage = false; }
  18926. if (isset($this->blk[$blvl]['y0'])) { $y0 = $this->blk[$blvl]['y0']; }
  18927. $h = $y1 - $y0;
  18928. $w = $this->blk[$blvl]['width'];
  18929. $x1 = $x0 + $w;
  18930. // Set border-widths as used here
  18931. $border_top = $this->blk[$blvl]['border_top']['w'];
  18932. $border_bottom = $this->blk[$blvl]['border_bottom']['w'];
  18933. $border_left = $this->blk[$blvl]['border_left']['w'];
  18934. $border_right = $this->blk[$blvl]['border_right']['w'];
  18935. if (!$this->blk[$blvl]['border_top'] || $divider == 'pagetop' || $continuingpage) {
  18936. $border_top = 0;
  18937. }
  18938. if (!$this->blk[$blvl]['border_bottom'] || $blockstate == 1 || $divider == 'pagebottom') {
  18939. $border_bottom = 0;
  18940. }
  18941. $brTL_H = 0;
  18942. $brTL_V = 0;
  18943. $brTR_H = 0;
  18944. $brTR_V = 0;
  18945. $brBL_H = 0;
  18946. $brBL_V = 0;
  18947. $brBR_H = 0;
  18948. $brBR_V = 0;
  18949. $brset = false;
  18950. /*-- BORDER-RADIUS --*/
  18951. if (isset($this->blk[$blvl]['border_radius_TL_H'])) { $brTL_H = $this->blk[$blvl]['border_radius_TL_H']; $brset = true; }
  18952. if (isset($this->blk[$blvl]['border_radius_TL_V'])) { $brTL_V = $this->blk[$blvl]['border_radius_TL_V']; $brset = true; }
  18953. if (isset($this->blk[$blvl]['border_radius_TR_H'])) { $brTR_H = $this->blk[$blvl]['border_radius_TR_H']; $brset = true; }
  18954. if (isset($this->blk[$blvl]['border_radius_TR_V'])) { $brTR_V = $this->blk[$blvl]['border_radius_TR_V']; $brset = true; }
  18955. if (isset($this->blk[$blvl]['border_radius_BR_H'])) { $brBR_H = $this->blk[$blvl]['border_radius_BR_H']; $brset = true; }
  18956. if (isset($this->blk[$blvl]['border_radius_BR_V'])) { $brBR_V = $this->blk[$blvl]['border_radius_BR_V']; $brset = true; }
  18957. if (isset($this->blk[$blvl]['border_radius_BL_H'])) { $brBL_H = $this->blk[$blvl]['border_radius_BL_H']; $brset = true; }
  18958. if (isset($this->blk[$blvl]['border_radius_BL_V'])) { $brBL_V = $this->blk[$blvl]['border_radius_BL_V']; $brset = true; }
  18959. if (!$this->blk[$blvl]['border_top'] || $divider == 'pagetop' || $continuingpage || $this->keep_block_together) {
  18960. $brTL_H = 0;
  18961. $brTL_V = 0;
  18962. $brTR_H = 0;
  18963. $brTR_V = 0;
  18964. }
  18965. if (!$this->blk[$blvl]['border_bottom'] || $blockstate == 1 || $divider == 'pagebottom' || $this->keep_block_together) {
  18966. $brBL_H = 0;
  18967. $brBL_V = 0;
  18968. $brBR_H = 0;
  18969. $brBR_V = 0;
  18970. }
  18971. // Disallow border-radius if it is smaller than the border width.
  18972. if ($brTL_H < min($border_left, $border_top)) { $brTL_H = $brTL_V = 0; }
  18973. if ($brTL_V < min($border_left, $border_top)) { $brTL_V = $brTL_H = 0; }
  18974. if ($brTR_H < min($border_right, $border_top)) { $brTR_H = $brTR_V = 0; }
  18975. if ($brTR_V < min($border_right, $border_top)) { $brTR_V = $brTR_H = 0; }
  18976. if ($brBL_H < min($border_left, $border_bottom)) { $brBL_H = $brBL_V = 0; }
  18977. if ($brBL_V < min($border_left, $border_bottom)) { $brBL_V = $brBL_H = 0; }
  18978. if ($brBR_H < min($border_right, $border_bottom)) { $brBR_H = $brBR_V = 0; }
  18979. if ($brBR_V < min($border_right, $border_bottom)) { $brBR_V = $brBR_H = 0; }
  18980. // CHECK FOR radii that sum to > width or height of div ********
  18981. $f = min($h/($brTL_V + $brBL_V + 0.001), $h/($brTR_V + $brBR_V + 0.001), $w/($brTL_H + $brTR_H + 0.001), $w/($brBL_H + $brBR_H + 0.001));
  18982. if ($f < 1) {
  18983. $brTL_H *= $f;
  18984. $brTL_V *= $f;
  18985. $brTR_H *= $f;
  18986. $brTR_V *= $f;
  18987. $brBL_H *= $f;
  18988. $brBL_V *= $f;
  18989. $brBR_H *= $f;
  18990. $brBR_V *= $f;
  18991. }
  18992. /*-- END BORDER-RADIUS --*/
  18993. // BORDERS
  18994. if (isset($this->blk[$blvl]['y0']) && $this->blk[$blvl]['y0']) { $y0 = $this->blk[$blvl]['y0']; }
  18995. $h = $y1 - $y0;
  18996. $w = $this->blk[$blvl]['width'];
  18997. //if ($this->blk[$blvl]['border_top']) {
  18998. // Reinstate line above for dotted line divider when block border crosses a page
  18999. if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) {
  19000. $tbd = $this->blk[$blvl]['border_top'];
  19001. if (isset($tbd['s']) && $tbd['s']) {
  19002. $this->_setBorderLine($tbd);
  19003. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'T'); }
  19004. /*-- BORDER-RADIUS --*/
  19005. else if (($brTL_V && $brTL_H) || ($brTR_V && $brTR_H)) {
  19006. $this->SetLineJoin(0);
  19007. $this->SetLineCap(0);
  19008. }
  19009. if ($brTR_H && $brTR_V) {
  19010. $this->_out($this->_EllipseArc($x0 + $w - $brTR_H, $y0 + $brTR_V, $brTR_H - $border_top/2 , $brTR_V - $border_top/2 , 1, 2, true));
  19011. }
  19012. else {
  19013. /*-- END BORDER-RADIUS --*/
  19014. $this->_out(sprintf('%.3F %.3F m ',($x0 + $w - ($border_top/2))*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK));
  19015. /*-- BORDER-RADIUS --*/
  19016. }
  19017. if ($brTL_H && $brTL_V ) {
  19018. $this->_out(sprintf('%.3F %.3F l ',($x0 + ($border_top/2) + $brTL_H )*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK));
  19019. $this->_out($this->_EllipseArc($x0 + $brTL_H, $y0 + $brTL_V, $brTL_H - $border_top/2 , $brTL_V - $border_top/2 , 2, 1));
  19020. }
  19021. else {
  19022. /*-- END BORDER-RADIUS --*/
  19023. $this->_out(sprintf('%.3F %.3F l ',($x0 + ($border_top/2))*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK));
  19024. /*-- BORDER-RADIUS --*/
  19025. }
  19026. /*-- END BORDER-RADIUS --*/
  19027. $this->_out('S');
  19028. // Reset Corners and Dash off
  19029. $this->SetLineJoin(2);
  19030. $this->SetLineCap(2);
  19031. $this->SetDash();
  19032. }
  19033. }
  19034. //if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1) {
  19035. // Reinstate line above for dotted line divider when block border crosses a page
  19036. if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') {
  19037. $tbd = $this->blk[$blvl]['border_bottom'];
  19038. if (isset($tbd['s']) && $tbd['s']) {
  19039. $this->_setBorderLine($tbd);
  19040. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'B'); }
  19041. /*-- BORDER-RADIUS --*/
  19042. else if (($brBL_V && $brBL_H) || ($brBR_V && $brBR_H)) {
  19043. $this->SetLineJoin(0);
  19044. $this->SetLineCap(0);
  19045. }
  19046. if ($brBL_H && $brBL_V) {
  19047. $this->_out($this->_EllipseArc($x0 + $brBL_H, $y0 + $h - $brBL_V, $brBL_H - $border_bottom/2 , $brBL_V - $border_bottom/2 , 3, 2, true));
  19048. }
  19049. else {
  19050. /*-- END BORDER-RADIUS --*/
  19051. $this->_out(sprintf('%.3F %.3F m ',($x0 + ($border_bottom/2))*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK));
  19052. /*-- BORDER-RADIUS --*/
  19053. }
  19054. if ($brBR_H && $brBR_V ) {
  19055. $this->_out(sprintf('%.3F %.3F l ',($x0 + $w - ($border_bottom/2) - $brBR_H )*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK));
  19056. $this->_out($this->_EllipseArc($x0 + $w - $brBR_H, $y0 + $h - $brBR_V, $brBR_H - $border_bottom/2 , $brBR_V - $border_bottom/2 , 4, 1));
  19057. }
  19058. else {
  19059. /*-- END BORDER-RADIUS --*/
  19060. $this->_out(sprintf('%.3F %.3F l ',($x0 + $w - ($border_bottom/2) )*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK));
  19061. /*-- BORDER-RADIUS --*/
  19062. }
  19063. /*-- END BORDER-RADIUS --*/
  19064. $this->_out('S');
  19065. // Reset Corners and Dash off
  19066. $this->SetLineJoin(2);
  19067. $this->SetLineCap(2);
  19068. $this->SetDash();
  19069. }
  19070. }
  19071. if ($this->blk[$blvl]['border_left']) {
  19072. $tbd = $this->blk[$blvl]['border_left'];
  19073. if (isset($tbd['s']) && $tbd['s']) {
  19074. $this->_setBorderLine($tbd);
  19075. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'L'); }
  19076. /*-- BORDER-RADIUS --*/
  19077. else if (($brTL_V && $brTL_H) || ($brBL_V && $brBL_H)) {
  19078. $this->SetLineJoin(0);
  19079. $this->SetLineCap(0);
  19080. }
  19081. if ($brTL_V && $brTL_H) {
  19082. $this->_out($this->_EllipseArc($x0 + $brTL_H, $y0 + $brTL_V, $brTL_H - $border_left/2 , $brTL_V - $border_left/2, 2, 2, true));
  19083. }
  19084. else {
  19085. /*-- END BORDER-RADIUS --*/
  19086. $this->_out(sprintf('%.3F %.3F m ',($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + ($border_left/2)))*_MPDFK));
  19087. /*-- BORDER-RADIUS --*/
  19088. }
  19089. if ($brBL_V && $brBL_H ) {
  19090. $this->_out(sprintf('%.3F %.3F l ',($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + $h - ($border_left/2)- $brBL_V) )*_MPDFK));
  19091. $this->_out($this->_EllipseArc($x0 + $brBL_H, $y0 + $h - $brBL_V, $brBL_H - $border_left/2 , $brBL_V - $border_left/2, 3, 1));
  19092. }
  19093. else {
  19094. /*-- END BORDER-RADIUS --*/
  19095. $this->_out(sprintf('%.3F %.3F l ',($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + $h - ($border_left/2)) )*_MPDFK));
  19096. /*-- BORDER-RADIUS --*/
  19097. }
  19098. /*-- END BORDER-RADIUS --*/
  19099. $this->_out('S');
  19100. // Reset Corners and Dash off
  19101. $this->SetLineJoin(2);
  19102. $this->SetLineCap(2);
  19103. $this->SetDash();
  19104. }
  19105. }
  19106. if ($this->blk[$blvl]['border_right']) {
  19107. $tbd = $this->blk[$blvl]['border_right'];
  19108. if (isset($tbd['s']) && $tbd['s']) {
  19109. $this->_setBorderLine($tbd);
  19110. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'R'); }
  19111. /*-- BORDER-RADIUS --*/
  19112. else if (($brTR_V && $brTR_H) || ($brBR_V && $brBR_H)) {
  19113. $this->SetLineJoin(0);
  19114. $this->SetLineCap(0);
  19115. }
  19116. if ($brBR_V && $brBR_H) {
  19117. $this->_out($this->_EllipseArc($x0 + $w - $brBR_H, $y0 + $h - $brBR_V, $brBR_H - $border_right/2 , $brBR_V - $border_right/2, 4, 2, true));
  19118. }
  19119. else {
  19120. /*-- END BORDER-RADIUS --*/
  19121. $this->_out(sprintf('%.3F %.3F m ',($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + $h - ($border_right/2)))*_MPDFK));
  19122. /*-- BORDER-RADIUS --*/
  19123. }
  19124. if ($brTR_V && $brTR_H ) {
  19125. $this->_out(sprintf('%.3F %.3F l ',($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + ($border_right/2) + $brTR_V) )*_MPDFK));
  19126. $this->_out($this->_EllipseArc($x0 + $w - $brTR_H, $y0 + $brTR_V, $brTR_H - $border_right/2 , $brTR_V - $border_right/2, 1, 1));
  19127. }
  19128. else {
  19129. /*-- END BORDER-RADIUS --*/
  19130. $this->_out(sprintf('%.3F %.3F l ',($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + ($border_right/2)) )*_MPDFK));
  19131. /*-- BORDER-RADIUS --*/
  19132. }
  19133. /*-- END BORDER-RADIUS --*/
  19134. $this->_out('S');
  19135. // Reset Corners and Dash off
  19136. $this->SetLineJoin(2);
  19137. $this->SetLineCap(2);
  19138. $this->SetDash();
  19139. }
  19140. }
  19141. if (!$brset) { // not if border-radius used
  19142. $tbcol = $this->ConvertColor(255);
  19143. for($l=0; $l <= $blvl; $l++) {
  19144. if ($this->blk[$l]['bgcolor']) {
  19145. $tbcol = $this->blk[$l]['bgcolorarray'];
  19146. }
  19147. }
  19148. }
  19149. if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) {
  19150. $tbd = $this->blk[$blvl]['border_top'];
  19151. if (isset($tbd['s']) && $tbd['s']) {
  19152. if (!$brset && $tbd['style']=='double') {
  19153. $this->SetLineWidth($tbd['w']/3);
  19154. $this->SetDColor($tbcol);
  19155. $this->_out(sprintf('%.3F %.3F m %.3F %.3F l S', ($x0 + $w - ($border_top/2))*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK, ($x0 + ($border_top/2))*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK ));
  19156. }
  19157. }
  19158. }
  19159. if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') {
  19160. $tbd = $this->blk[$blvl]['border_bottom'];
  19161. if (isset($tbd['s']) && $tbd['s']) {
  19162. if (!$brset && $tbd['style']=='double') {
  19163. $this->SetLineWidth($tbd['w']/3);
  19164. $this->SetDColor($tbcol);
  19165. $this->_out(sprintf('%.3F %.3F m %.3F %.3F l S', ($x0 + ($border_bottom/2))*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK, ($x0 + $w - ($border_bottom/2) )*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK ));
  19166. }
  19167. }
  19168. }
  19169. if ($this->blk[$blvl]['border_left']) {
  19170. $tbd = $this->blk[$blvl]['border_left'];
  19171. if (isset($tbd['s']) && $tbd['s']) {
  19172. if (!$brset && $tbd['style']=='double') {
  19173. $this->SetLineWidth($tbd['w']/3);
  19174. $this->SetDColor($tbcol);
  19175. $this->_out(sprintf('%.3F %.3F m %.3F %.3F l S', ($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + ($border_left/2)))*_MPDFK, ($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + $h - ($border_left/2)) )*_MPDFK));
  19176. }
  19177. }
  19178. }
  19179. if ($this->blk[$blvl]['border_right']) {
  19180. $tbd = $this->blk[$blvl]['border_right'];
  19181. if (isset($tbd['s']) && $tbd['s']) {
  19182. if (!$brset && $tbd['style']=='double') {
  19183. $this->SetLineWidth($tbd['w']/3);
  19184. $this->SetDColor($tbcol);
  19185. $this->_out(sprintf('%.3F %.3F m %.3F %.3F l S', ($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + $h - ($border_right/2)))*_MPDFK, ($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + ($border_right/2)) )*_MPDFK));
  19186. }
  19187. }
  19188. }
  19189. $this->SetDash();
  19190. $this->y = $save_y;
  19191. // BACKGROUNDS are disabled in columns/kbt/headers - messes up the repositioning in printcolumnbuffer
  19192. if ($this->ColActive || $this->kwt || $this->keep_block_together) { return ; }
  19193. $bgx0 = $x0;
  19194. $bgx1 = $x1;
  19195. $bgy0 = $y0;
  19196. $bgy1 = $y1;
  19197. /*-- BORDER-RADIUS --*/
  19198. // Defined br values represent the radius of the outer curve - need to take border-width/2 from each radius for drawing the borders
  19199. if (isset($this->blk[$blvl]['background_clip']) && $this->blk[$blvl]['background_clip'] == 'padding-box') {
  19200. $brbgTL_H = max(0, $brTL_H - $this->blk[$blvl]['border_left']['w']);
  19201. $brbgTL_V = max(0, $brTL_V - $this->blk[$blvl]['border_top']['w']);
  19202. $brbgTR_H = max(0, $brTR_H - $this->blk[$blvl]['border_right']['w']);
  19203. $brbgTR_V = max(0, $brTR_V - $this->blk[$blvl]['border_top']['w']);
  19204. $brbgBL_H = max(0, $brBL_H - $this->blk[$blvl]['border_left']['w']);
  19205. $brbgBL_V = max(0, $brBL_V - $this->blk[$blvl]['border_bottom']['w']);
  19206. $brbgBR_H = max(0, $brBR_H - $this->blk[$blvl]['border_right']['w']);
  19207. $brbgBR_V = max(0, $brBR_V - $this->blk[$blvl]['border_bottom']['w']);
  19208. $bgx0 += $this->blk[$blvl]['border_left']['w'];
  19209. $bgx1 -= $this->blk[$blvl]['border_right']['w'];
  19210. if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) {
  19211. $bgy0 += $this->blk[$blvl]['border_top']['w'];
  19212. }
  19213. if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') {
  19214. $bgy1 -= $this->blk[$blvl]['border_bottom']['w'];
  19215. }
  19216. }
  19217. else {
  19218. /*-- END BORDER-RADIUS --*/
  19219. $brbgTL_H = $brTL_H;
  19220. $brbgTL_V = $brTL_V;
  19221. $brbgTR_H = $brTR_H;
  19222. $brbgTR_V = $brTR_V;
  19223. $brbgBL_H = $brBL_H;
  19224. $brbgBL_V = $brBL_V;
  19225. $brbgBR_H = $brBR_H;
  19226. $brbgBR_V = $brBR_V;
  19227. /*-- BORDER-RADIUS --*/
  19228. }
  19229. /*-- END BORDER-RADIUS --*/
  19230. // Set clipping path
  19231. $s = ' q 0 w '; // Line width=0
  19232. $s .= sprintf('%.3F %.3F m ', ($bgx0+$brbgTL_H )*_MPDFK, ($this->h-$bgy0)*_MPDFK); // start point TL before the arc
  19233. /*-- BORDER-RADIUS --*/
  19234. if ($brbgTL_H || $brbgTL_V) {
  19235. $s .= $this->_EllipseArc($bgx0+$brbgTL_H, $bgy0+$brbgTL_V, $brbgTL_H , $brbgTL_V , 2); // segment 2 TL
  19236. }
  19237. /*-- END BORDER-RADIUS --*/
  19238. $s .= sprintf('%.3F %.3F l ', ($bgx0)*_MPDFK, ($this->h-($bgy1-$brbgBL_V ))*_MPDFK); // line to BL
  19239. /*-- BORDER-RADIUS --*/
  19240. if ($brbgBL_H || $brbgBL_V) {
  19241. $s .= $this->_EllipseArc($bgx0+$brbgBL_H, $bgy1-$brbgBL_V, $brbgBL_H , $brbgBL_V , 3); // segment 3 BL
  19242. }
  19243. /*-- END BORDER-RADIUS --*/
  19244. $s .= sprintf('%.3F %.3F l ', ($bgx1-$brbgBR_H )*_MPDFK, ($this->h-($bgy1))*_MPDFK); // line to BR
  19245. /*-- BORDER-RADIUS --*/
  19246. if ($brbgBR_H || $brbgBR_V) {
  19247. $s .= $this->_EllipseArc($bgx1-$brbgBR_H, $bgy1-$brbgBR_V, $brbgBR_H , $brbgBR_V , 4); // segment 4 BR
  19248. }
  19249. /*-- END BORDER-RADIUS --*/
  19250. $s .= sprintf('%.3F %.3F l ', ($bgx1)*_MPDFK, ($this->h-($bgy0+$brbgTR_V))*_MPDFK); // line to TR
  19251. /*-- BORDER-RADIUS --*/
  19252. if ($brbgTR_H || $brbgTR_V) {
  19253. $s .= $this->_EllipseArc($bgx1-$brbgTR_H, $bgy0+$brbgTR_V, $brbgTR_H , $brbgTR_V , 1); // segment 1 TR
  19254. }
  19255. /*-- END BORDER-RADIUS --*/
  19256. $s .= sprintf('%.3F %.3F l ', ($bgx0+$brbgTL_H )*_MPDFK, ($this->h-$bgy0)*_MPDFK); // line to TL
  19257. // mPDF 5.3.A1
  19258. // Box Shadow
  19259. $shadow = '';
  19260. if (isset($this->blk[$blvl]['box_shadow']) && $this->blk[$blvl]['box_shadow'] && $h > 0) {
  19261. foreach($this->blk[$blvl]['box_shadow'] AS $sh) {
  19262. // Colors
  19263. if ($sh['col']{0}==1) {
  19264. $colspace = 'Gray';
  19265. if ($sh['col']{2}==1) { $col1 = '1'.$sh['col'][1].'1'.$sh['col'][3]; }
  19266. else { $col1 = '1'.$sh['col'][1].'1'.chr(100); }
  19267. $col2 = '1'.$sh['col'][1].'1'.chr(0);
  19268. }
  19269. else if ($sh['col']{0}==4) { // CMYK
  19270. $colspace = 'CMYK';
  19271. $col1 = '6'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4].chr(100);
  19272. $col2 = '6'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4].chr(0);
  19273. }
  19274. else if ($sh['col']{0}==5) { // RGBa
  19275. $colspace = 'RGB';
  19276. $col1 = '5'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4];
  19277. $col2 = '5'.$sh['col'][1].$sh['col'][2].$sh['col'][3].chr(0);
  19278. }
  19279. else if ($sh['col']{0}==6) { // CMYKa
  19280. $colspace = 'CMYK';
  19281. $col1 = '6'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4].$sh['col'][5];
  19282. $col2 = '6'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4].chr(0);
  19283. }
  19284. else {
  19285. $colspace = 'RGB';
  19286. $col1 = '5'.$sh['col'][1].$sh['col'][2].$sh['col'][3].chr(100);
  19287. $col2 = '5'.$sh['col'][1].$sh['col'][2].$sh['col'][3].chr(0);
  19288. }
  19289. // Use clipping path as set above (and rectangle around page) to clip area outside box
  19290. $shadow .= $s; // Use the clipping path with W*
  19291. $shadow .= sprintf('0 %.3F m %.3F %.3F l ', $this->h*_MPDFK, $this->w*_MPDFK, $this->h*_MPDFK);
  19292. $shadow .= sprintf('%.3F 0 l 0 0 l 0 %.3F l ', $this->w*_MPDFK, $this->h*_MPDFK);
  19293. $shadow .= 'W n'."\n";
  19294. $sh['blur'] = abs($sh['blur']); // cannot have negative blur value
  19295. // Ensure spread/blur do not make effective shadow width/height < 0
  19296. // Could do more complex things but this just adjusts spread value
  19297. if (-$sh['spread'] + $sh['blur']/2 > min($w/2, $h/2)) {
  19298. $sh['spread'] = $sh['blur']/2 - min($w/2, $h/2) + 0.01;
  19299. }
  19300. // Shadow Offset
  19301. if ($sh['x'] || $sh['y']) $shadow .= sprintf(' q 1 0 0 1 %.4F %.4F cm', $sh['x']*_MPDFK, -$sh['y']*_MPDFK)."\n";
  19302. // Set path for INNER shadow
  19303. $shadow .= ' q 0 w ';
  19304. $shadow .= $this->SetFColor($col1, true)."\n";
  19305. if ($col1{0}==5 && ord($col1{4})<100) { // RGBa
  19306. $shadow .= $this->SetAlpha(ord($col1{4})/100, 'Normal', true, 'F')."\n";
  19307. }
  19308. else if ($col1{0}==6 && ord($col1{5})<100) { // CMYKa
  19309. $shadow .= $this->SetAlpha(ord($col1{5})/100, 'Normal', true, 'F')."\n";
  19310. }
  19311. else if ($col1{0}==1 && $col1{2}==1 && ord($col1{3})<100) { // Gray
  19312. $shadow .= $this->SetAlpha(ord($col1{3})/100, 'Normal', true, 'F')."\n";
  19313. }
  19314. // Blur edges
  19315. $mag = 0.551784; // Bezier Control magic number for 4-part spline for circle/ellipse
  19316. $mag2 = 0.551784; // Bezier Control magic number to fill in edge of blurred rectangle
  19317. $d1 = $sh['spread']+$sh['blur']/2;
  19318. $d2 = $sh['spread']-$sh['blur']/2;
  19319. $bl = $sh['blur'];
  19320. $x00 = $x0 - $d1;
  19321. $y00 = $y0 - $d1;
  19322. $w00 = $w + $d1*2;
  19323. $h00 = $h + $d1*2;
  19324. // If any border-radius is greater width-negative spread(inner edge), ignore radii for shadow or screws up
  19325. $flatten = false;
  19326. if (max($brbgTR_H, $brbgTL_H, $brbgBR_H, $brbgBL_H) >= $w+$d2) { $flatten = true; }
  19327. if (max($brbgTR_V, $brbgTL_V, $brbgBR_V, $brbgBL_V) >= $h+$d2) { $flatten = true; }
  19328. // TOP RIGHT corner
  19329. $p1x = $x00+$w00-$d1-$brbgTR_H; $p1c2x = $p1x +($d2+$brbgTR_H)*$mag;
  19330. $p1y = $y00+$bl;
  19331. $p2x = $x00+$w00-$d1-$brbgTR_H; $p2c2x = $p2x + ($d1+$brbgTR_H)*$mag;
  19332. $p2y = $y00; $p2c1y = $p2y + $bl/2;
  19333. $p3x = $x00+$w00; $p3c2x = $p3x - $bl/2;
  19334. $p3y = $y00+$d1+$brbgTR_V; $p3c1y = $p3y - ($d1+$brbgTR_V)*$mag;
  19335. $p4x = $x00+$w00-$bl;
  19336. $p4y = $y00+$d1+$brbgTR_V; $p4c2y = $p4y - ($d2+$brbgTR_V)*$mag;
  19337. if (-$d2 > min($brbgTR_H, $brbgTR_V) || $flatten) {
  19338. $p1x = $x00+$w00-$bl; $p1c2x = $p1x;
  19339. $p2x = $x00+$w00-$bl; $p2c2x = $p2x + $bl*$mag2;
  19340. $p3y = $y00+$bl; $p3c1y = $p3y - $bl*$mag2;
  19341. $p4y = $y00+$bl; $p4c2y = $p4y ;
  19342. }
  19343. $shadow .= sprintf('%.3F %.3F m ', ($p1x )*_MPDFK, ($this->h-($p1y ))*_MPDFK);
  19344. $shadow .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', ($p1c2x)*_MPDFK, ($this->h-($p1y))*_MPDFK, ($p4x)*_MPDFK, ($this->h-($p4c2y))*_MPDFK, ($p4x)*_MPDFK, ($this->h-($p4y))*_MPDFK);
  19345. $patch_array[0]['f']=0;
  19346. $patch_array[0]['points']=array($p1x,$p1y, $p1x,$p1y,
  19347. $p2x,$p2c1y, $p2x,$p2y, $p2c2x,$p2y,
  19348. $p3x,$p3c1y, $p3x,$p3y, $p3c2x,$p3y,
  19349. $p4x,$p4y, $p4x,$p4y, $p4x,$p4c2y,
  19350. $p1c2x,$p1y);
  19351. $patch_array[0]['colors'] = array($col1,$col2,$col2,$col1);
  19352. // RIGHT
  19353. $p1x = $x00+$w00; // control point only matches p3 preceding
  19354. $p1y = $y00+$d1+$brbgTR_V;
  19355. $p2x = $x00+$w00-$bl; // control point only matches p4 preceding
  19356. $p2y = $y00+$d1+$brbgTR_V;
  19357. $p3x = $x00+$w00-$bl;
  19358. $p3y = $y00+$h00-$d1-$brbgBR_V;
  19359. $p4x = $x00+$w00; $p4c1x = $p4x-$bl/2;
  19360. $p4y = $y00+$h00-$d1-$brbgBR_V;
  19361. if (-$d2 > min($brbgTR_H, $brbgTR_V) || $flatten) {
  19362. $p1y = $y00+$bl;
  19363. $p2y = $y00+$bl;
  19364. }
  19365. if (-$d2 > min($brbgBR_H, $brbgBR_V) || $flatten) {
  19366. $p3y = $y00+$h00-$bl;
  19367. $p4y = $y00+$h00-$bl;
  19368. }
  19369. $shadow .= sprintf('%.3F %.3F l ', ($p3x )*_MPDFK, ($this->h-($p3y ))*_MPDFK);
  19370. $patch_array[1]['f']=2;
  19371. $patch_array[1]['points']=array($p2x,$p2y,
  19372. $p3x,$p3y, $p3x,$p3y, $p3x,$p3y,
  19373. $p4c1x,$p4y, $p4x,$p4y, $p4x,$p4y,
  19374. $p1x,$p1y);
  19375. $patch_array[1]['colors'] = array($col1,$col2);
  19376. // BOTTOM RIGHT corner
  19377. $p1x = $x00+$w00-$bl; // control points only matches p3 preceding
  19378. $p1y = $y00+$h00-$d1-$brbgBR_V; $p1c2y = $p1y + ($d2+$brbgBR_V)*$mag;
  19379. $p2x = $x00+$w00; // control point only matches p4 preceding
  19380. $p2y = $y00+$h00-$d1-$brbgBR_V; $p2c2y = $p2y + ($d1+$brbgBR_V)*$mag;
  19381. $p3x = $x00+$w00-$d1-$brbgBR_H; $p3c1x = $p3x + ($d1+$brbgBR_H)*$mag;
  19382. $p3y = $y00+$h00; $p3c2y = $p3y - $bl/2;
  19383. $p4x = $x00+$w00-$d1-$brbgBR_H; $p4c2x = $p4x + ($d2+$brbgBR_H)*$mag;
  19384. $p4y = $y00+$h00-$bl;
  19385. if (-$d2 > min($brbgBR_H, $brbgBR_V) || $flatten) {
  19386. $p1y = $y00+$h00-$bl; $p1c2y = $p1y;
  19387. $p2y = $y00+$h00-$bl; $p2c2y = $p2y + $bl*$mag2;
  19388. $p3x = $x00+$w00-$bl; $p3c1x = $p3x + $bl*$mag2;
  19389. $p4x = $x00+$w00-$bl; $p4c2x = $p4x;
  19390. }
  19391. $shadow .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', ($p1x)*_MPDFK, ($this->h-($p1c2y))*_MPDFK, ($p4c2x)*_MPDFK, ($this->h-($p4y))*_MPDFK, ($p4x)*_MPDFK, ($this->h-($p4y))*_MPDFK);
  19392. $patch_array[2]['f']=2;
  19393. $patch_array[2]['points']=array($p2x,$p2c2y,
  19394. $p3c1x,$p3y, $p3x,$p3y, $p3x,$p3c2y,
  19395. $p4x,$p4y, $p4x,$p4y, $p4c2x,$p4y,
  19396. $p1x,$p1c2y);
  19397. $patch_array[2]['colors'] = array($col2,$col1);
  19398. // BOTTOM
  19399. $p1x = $x00+$w00-$d1-$brbgBR_H; // control point only matches p3 preceding
  19400. $p1y = $y00+$h00;
  19401. $p2x = $x00+$w00-$d1-$brbgBR_H; // control point only matches p4 preceding
  19402. $p2y = $y00+$h00-$bl;
  19403. $p3x = $x00+$d1+$brbgBL_H;
  19404. $p3y = $y00+$h00-$bl;
  19405. $p4x = $x00+$d1+$brbgBL_H;
  19406. $p4y = $y00+$h00; $p4c1y = $p4y - $bl/2;
  19407. if (-$d2 > min($brbgBR_H, $brbgBR_V) || $flatten) {
  19408. $p1x = $x00+$w00-$bl;
  19409. $p2x = $x00+$w00-$bl;
  19410. }
  19411. if (-$d2 > min($brbgBL_H, $brbgBL_V) || $flatten) {
  19412. $p3x = $x00+$bl;
  19413. $p4x = $x00+$bl;
  19414. }
  19415. $shadow .= sprintf('%.3F %.3F l ', ($p3x )*_MPDFK, ($this->h-($p3y ))*_MPDFK);
  19416. $patch_array[3]['f']=2;
  19417. $patch_array[3]['points']=array($p2x,$p2y,
  19418. $p3x,$p3y, $p3x,$p3y, $p3x,$p3y,
  19419. $p4x,$p4c1y, $p4x,$p4y, $p4x,$p4y,
  19420. $p1x,$p1y);
  19421. $patch_array[3]['colors'] = array($col1,$col2);
  19422. // BOTTOM LEFT corner
  19423. $p1x = $x00+$d1+$brbgBL_H; $p1c2x = $p1x - ($d2+$brbgBL_H)*$mag; // control points only matches p3 preceding
  19424. $p1y = $y00+$h00-$bl;
  19425. $p2x = $x00+$d1+$brbgBL_H; $p2c2x = $p2x - ($d1+$brbgBL_H)*$mag; // control point only matches p4 preceding
  19426. $p2y = $y00+$h00;
  19427. $p3x = $x00; $p3c2x = $p3x + $bl/2;
  19428. $p3y = $y00+$h00-$d1-$brbgBL_V; $p3c1y = $p3y + ($d1+$brbgBL_V)*$mag;
  19429. $p4x = $x00+$bl;
  19430. $p4y = $y00+$h00-$d1-$brbgBL_V; $p4c2y = $p4y + ($d2+$brbgBL_V)*$mag;
  19431. if (-$d2 > min($brbgBL_H, $brbgBL_V) || $flatten) {
  19432. $p1x = $x00+$bl; $p1c2x = $p1x;
  19433. $p2x = $x00+$bl; $p2c2x = $p2x - $bl*$mag2;
  19434. $p3y = $y00+$h00-$bl; $p3c1y = $p3y + $bl*$mag2;
  19435. $p4y = $y00+$h00-$bl; $p4c2y = $p4y;
  19436. }
  19437. $shadow .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', ($p1c2x)*_MPDFK, ($this->h-($p1y))*_MPDFK, ($p4x)*_MPDFK, ($this->h-($p4c2y))*_MPDFK, ($p4x)*_MPDFK, ($this->h-($p4y))*_MPDFK);
  19438. $patch_array[4]['f']=2;
  19439. $patch_array[4]['points']=array($p2c2x,$p2y,
  19440. $p3x,$p3c1y, $p3x,$p3y, $p3c2x,$p3y,
  19441. $p4x,$p4y, $p4x,$p4y, $p4x,$p4c2y,
  19442. $p1c2x,$p1y);
  19443. $patch_array[4]['colors'] = array($col2,$col1);
  19444. // LEFT - joins on the right (C3-C4 of previous): f = 2
  19445. $p1x = $x00; // control point only matches p3 preceding
  19446. $p1y = $y00+$h00-$d1-$brbgBL_V;
  19447. $p2x = $x00+$bl; // control point only matches p4 preceding
  19448. $p2y = $y00+$h00-$d1-$brbgBL_V;
  19449. $p3x = $x00+$bl;
  19450. $p3y = $y00+$d1+$brbgTL_V;
  19451. $p4x = $x00; $p4c1x = $p4x + $bl/2;
  19452. $p4y = $y00+$d1+$brbgTL_V;
  19453. if (-$d2 > min($brbgBL_H, $brbgBL_V) || $flatten) {
  19454. $p1y = $y00+$h00-$bl;
  19455. $p2y = $y00+$h00-$bl;
  19456. }
  19457. if (-$d2 > min($brbgTL_H, $brbgTL_V) || $flatten) {
  19458. $p3y = $y00+$bl;
  19459. $p4y = $y00+$bl;
  19460. }
  19461. $shadow .= sprintf('%.3F %.3F l ', ($p3x )*_MPDFK, ($this->h-($p3y ))*_MPDFK);
  19462. $patch_array[5]['f']=2;
  19463. $patch_array[5]['points']=array($p2x,$p2y,
  19464. $p3x,$p3y, $p3x,$p3y, $p3x,$p3y,
  19465. $p4c1x,$p4y, $p4x,$p4y, $p4x,$p4y,
  19466. $p1x,$p1y);
  19467. $patch_array[5]['colors'] = array($col1,$col2);
  19468. // TOP LEFT corner
  19469. $p1x = $x00+$bl; // control points only matches p3 preceding
  19470. $p1y = $y00+$d1+$brbgTL_V; $p1c2y = $p1y - ($d2+$brbgTL_V)*$mag;
  19471. $p2x = $x00; // control point only matches p4 preceding
  19472. $p2y = $y00+$d1+$brbgTL_V; $p2c2y = $p2y - ($d1+$brbgTL_V)*$mag;
  19473. $p3x = $x00+$d1+$brbgTL_H; $p3c1x = $p3x - ($d1+$brbgTL_H)*$mag;
  19474. $p3y = $y00; $p3c2y = $p3y + $bl/2;
  19475. $p4x = $x00+$d1+$brbgTL_H; $p4c2x = $p4x - ($d2+$brbgTL_H)*$mag;
  19476. $p4y = $y00+$bl;
  19477. if (-$d2 > min($brbgTL_H, $brbgTL_V) || $flatten) {
  19478. $p1y = $y00+$bl; $p1c2y = $p1y;
  19479. $p2y = $y00+$bl; $p2c2y = $p2y - $bl*$mag2;
  19480. $p3x = $x00+$bl; $p3c1x = $p3x - $bl*$mag2;
  19481. $p4x = $x00+$bl; $p4c2x = $p4x ;
  19482. }
  19483. $shadow .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', ($p1x)*_MPDFK, ($this->h-($p1c2y))*_MPDFK, ($p4c2x)*_MPDFK, ($this->h-($p4y))*_MPDFK, ($p4x)*_MPDFK, ($this->h-($p4y))*_MPDFK);
  19484. $patch_array[6]['f']=2;
  19485. $patch_array[6]['points']=array($p2x,$p2c2y,
  19486. $p3c1x,$p3y, $p3x,$p3y, $p3x,$p3c2y,
  19487. $p4x,$p4y, $p4x,$p4y, $p4c2x,$p4y,
  19488. $p1x,$p1c2y);
  19489. $patch_array[6]['colors'] = array($col2,$col1);
  19490. // TOP - joins on the right (C3-C4 of previous): f = 2
  19491. $p1x = $x00+$d1+$brbgTL_H; // control point only matches p3 preceding
  19492. $p1y = $y00;
  19493. $p2x = $x00+$d1+$brbgTL_H; // control point only matches p4 preceding
  19494. $p2y = $y00+$bl;
  19495. $p3x = $x00+$w00-$d1-$brbgTR_H;
  19496. $p3y = $y00+$bl;
  19497. $p4x = $x00+$w00-$d1-$brbgTR_H;
  19498. $p4y = $y00; $p4c1y = $p4y + $bl/2;
  19499. if (-$d2 > min($brbgTL_H, $brbgTL_V) || $flatten) {
  19500. $p1x = $x00+$bl;
  19501. $p2x = $x00+$bl;
  19502. }
  19503. if (-$d2 > min($brbgTR_H, $brbgTR_V) || $flatten) {
  19504. $p3x = $x00+$w00-$bl;
  19505. $p4x = $x00+$w00-$bl;
  19506. }
  19507. $shadow .= sprintf('%.3F %.3F l ', ($p3x )*_MPDFK, ($this->h-($p3y ))*_MPDFK);
  19508. $patch_array[7]['f']=2;
  19509. $patch_array[7]['points']=array($p2x,$p2y,
  19510. $p3x,$p3y, $p3x,$p3y, $p3x,$p3y,
  19511. $p4x,$p4c1y, $p4x,$p4y, $p4x,$p4y,
  19512. $p1x,$p1y);
  19513. $patch_array[7]['colors'] = array($col1,$col2);
  19514. $shadow .= ' h f Q '."\n"; // Close path and Fill the inner solid shadow
  19515. if ($bl) $shadow .= $this->grad->CoonsPatchMesh($x00,$y00,$w00,$h00,$patch_array,$x00,$x00+$w00,$y00,$y00+$h00, $colspace, true);
  19516. if ($sh['x'] || $sh['y']) $shadow .= ' Q'."\n"; // Shadow Offset
  19517. $shadow .= ' Q'."\n"; // Ends path no-op & Sets the clipping path
  19518. }
  19519. }
  19520. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  19521. if ($this->blk[$blvl]['bgcolor']) {
  19522. $this->pageBackgrounds[$blvl][] = array('x'=>$x0, 'y'=>$y0, 'w'=>$w, 'h'=>$h, 'col'=>$this->blk[$blvl]['bgcolorarray'], 'clippath'=>$s, 'visibility'=>$this->visibility, 'shadow'=>$shadow); // mPDF 5.3.42 // mPDF 5.3.A1
  19523. }
  19524. // mPDF 5.3.A1
  19525. else if ($shadow) {
  19526. $this->pageBackgrounds[$blvl][] = array('shadowonly'=>true, 'col'=>'', 'clippath'=>'', 'visibility'=>$this->visibility, 'shadow'=>$shadow); // mPDF 5.3.42 // mPDF 5.3.A1
  19527. }
  19528. /*-- BACKGROUNDS --*/
  19529. if (isset($this->blk[$blvl]['gradient'])) {
  19530. $g = $this->grad->parseBackgroundGradient($this->blk[$blvl]['gradient']);
  19531. if ($g) {
  19532. $gx = $x0;
  19533. $gy = $y0;
  19534. $this->pageBackgrounds[$blvl][] = array('gradient'=>true, 'x'=>$gx, 'y'=>$gy, 'w'=>$w, 'h'=>$h, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>$s, 'visibility'=>$this->visibility); // mPDF 5.3.42
  19535. }
  19536. }
  19537. if (isset($this->blk[$blvl]['background-image'])) {
  19538. if ($this->blk[$blvl]['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $this->blk[$blvl]['background-image']['gradient'] )) {
  19539. $g = $this->grad->parseMozGradient( $this->blk[$blvl]['background-image']['gradient'] );
  19540. if ($g) {
  19541. $gx = $x0;
  19542. $gy = $y0;
  19543. $this->pageBackgrounds[$blvl][] = array('gradient'=>true, 'x'=>$gx, 'y'=>$gy, 'w'=>$w, 'h'=>$h, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>$s, 'visibility'=>$this->visibility); // mPDF 5.3.42
  19544. }
  19545. }
  19546. else {
  19547. $image_id = $this->blk[$blvl]['background-image']['image_id'];
  19548. $orig_w = $this->blk[$blvl]['background-image']['orig_w'];
  19549. $orig_h = $this->blk[$blvl]['background-image']['orig_h'];
  19550. $x_pos = $this->blk[$blvl]['background-image']['x_pos'];
  19551. $y_pos = $this->blk[$blvl]['background-image']['y_pos'];
  19552. $x_repeat = $this->blk[$blvl]['background-image']['x_repeat'];
  19553. $y_repeat = $this->blk[$blvl]['background-image']['y_repeat'];
  19554. $resize = $this->blk[$blvl]['background-image']['resize'];
  19555. $opacity = $this->blk[$blvl]['background-image']['opacity'];
  19556. $itype = $this->blk[$blvl]['background-image']['itype'];
  19557. $this->pageBackgrounds[$blvl][] = array('x'=>$x0, 'y'=>$y0, 'w'=>$w, 'h'=>$h, 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>$s, 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$itype, 'visibility'=>$this->visibility); // mPDF 5.3.42
  19558. }
  19559. }
  19560. /*-- END BACKGROUNDS --*/
  19561. // Float DIV
  19562. $this->blk[$blvl]['bb_painted'][$this->page] = true;
  19563. }
  19564. /*-- BORDER-RADIUS --*/
  19565. function _EllipseArc($x0, $y0, $rx, $ry, $seg = 1, $part=false, $start=false) { // Anticlockwise segment 1-4 TR-TL-BL-BR (part=1 or 2)
  19566. $s = '';
  19567. if ($rx<0) { $rx = 0; }
  19568. if ($ry<0) { $ry = 0; }
  19569. $rx *= _MPDFK;
  19570. $ry *= _MPDFK;
  19571. $astart = 0;
  19572. if ($seg == 1) { // Top Right
  19573. $afinish = 90;
  19574. $nSeg = 4;
  19575. }
  19576. else if ($seg == 2) { // Top Left
  19577. $afinish = 180;
  19578. $nSeg = 8;
  19579. }
  19580. else if ($seg == 3) { // Bottom Left
  19581. $afinish = 270;
  19582. $nSeg = 12;
  19583. }
  19584. else { // Bottom Right
  19585. $afinish = 360;
  19586. $nSeg = 16;
  19587. }
  19588. $astart = deg2rad((float) $astart);
  19589. $afinish = deg2rad((float) $afinish);
  19590. $totalAngle = $afinish - $astart;
  19591. $dt = $totalAngle / $nSeg; // segment angle
  19592. $dtm = $dt/3;
  19593. $x0 *= _MPDFK;
  19594. $y0 = ($this->h - $y0) * _MPDFK;
  19595. $t1 = $astart;
  19596. $a0 = $x0 + ($rx * cos($t1));
  19597. $b0 = $y0 + ($ry * sin($t1));
  19598. $c0 = -$rx * sin($t1);
  19599. $d0 = $ry * cos($t1);
  19600. $op = false;
  19601. for ($i = 1; $i <= $nSeg; $i++) {
  19602. // Draw this bit of the total curve
  19603. $t1 = ($i * $dt) + $astart;
  19604. $a1 = $x0 + ($rx * cos($t1));
  19605. $b1 = $y0 + ($ry * sin($t1));
  19606. $c1 = -$rx * sin($t1);
  19607. $d1 = $ry * cos($t1);
  19608. if ($i>($nSeg-4) && (!$part || ($part == 1 && $i<=$nSeg-2) || ($part == 2 && $i>$nSeg-2))) {
  19609. if ($start && !$op) {
  19610. $s .= sprintf('%.3F %.3F m ', $a0, $b0);
  19611. }
  19612. $s .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', ($a0 + ($c0 * $dtm)), ($b0 + ($d0 * $dtm)), ($a1 - ($c1 * $dtm)) , ($b1 - ($d1 * $dtm)), $a1 , $b1 );
  19613. $op = true;
  19614. }
  19615. $a0 = $a1;
  19616. $b0 = $b1;
  19617. $c0 = $c1;
  19618. $d0 = $d1;
  19619. }
  19620. return $s;
  19621. }
  19622. /*-- END BORDER-RADIUS --*/
  19623. function PaintDivLnBorder($state=0,$blvl=0,$h) {
  19624. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  19625. $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y + $h;
  19626. $save_y = $this->y;
  19627. $w = $this->blk[$blvl]['width'];
  19628. $x0 = $this->x; // left
  19629. $y0 = $this->y; // top
  19630. $x1 = $this->x + $w; // bottom
  19631. $y1 = $this->y + $h; // bottom
  19632. if ($this->blk[$blvl]['border_top'] && ($state==1 || $state==3)) {
  19633. $tbd = $this->blk[$blvl]['border_top'];
  19634. if (isset($tbd['s']) && $tbd['s']) {
  19635. $this->_setBorderLine($tbd);
  19636. $this->y = $y0 + ($tbd['w']/2);
  19637. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'T'); }
  19638. $this->Line($x0 + ($tbd['w']/2) , $this->y , $x0 + $w - ($tbd['w']/2), $this->y);
  19639. $this->y += $tbd['w'];
  19640. // Reset Corners and Dash off
  19641. $this->SetLineJoin(2);
  19642. $this->SetLineCap(2);
  19643. $this->SetDash();
  19644. }
  19645. }
  19646. if ($this->blk[$blvl]['border_left']) {
  19647. $tbd = $this->blk[$blvl]['border_left'];
  19648. if (isset($tbd['s']) && $tbd['s']) {
  19649. $this->_setBorderLine($tbd);
  19650. $this->y = $y0 + ($tbd['w']/2);
  19651. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'L'); }
  19652. $this->Line($x0 + ($tbd['w']/2), $this->y, $x0 + ($tbd['w']/2), $y0 + $h -($tbd['w']/2));
  19653. $this->y += $tbd['w'];
  19654. // Reset Corners and Dash off
  19655. $this->SetLineJoin(2);
  19656. $this->SetLineCap(2);
  19657. $this->SetDash();
  19658. }
  19659. }
  19660. if ($this->blk[$blvl]['border_right']) {
  19661. $tbd = $this->blk[$blvl]['border_right'];
  19662. if (isset($tbd['s']) && $tbd['s']) {
  19663. $this->_setBorderLine($tbd);
  19664. $this->y = $y0 + ($tbd['w']/2);
  19665. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'R'); }
  19666. $this->Line($x0 + $w - ($tbd['w']/2), $this->y, $x0 + $w - ($tbd['w']/2), $y0 + $h - ($tbd['w']/2));
  19667. $this->y += $tbd['w'];
  19668. // Reset Corners and Dash off
  19669. $this->SetLineJoin(2);
  19670. $this->SetLineCap(2);
  19671. $this->SetDash();
  19672. }
  19673. }
  19674. if ($this->blk[$blvl]['border_bottom'] && $state > 1) {
  19675. $tbd = $this->blk[$blvl]['border_bottom'];
  19676. if (isset($tbd['s']) && $tbd['s']) {
  19677. $this->_setBorderLine($tbd);
  19678. $this->y = $y0 + $h - ($tbd['w']/2);
  19679. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'B'); }
  19680. $this->Line($x0 + ($tbd['w']/2) , $this->y, $x0 + $w - ($tbd['w']/2), $this->y);
  19681. $this->y += $tbd['w'];
  19682. // Reset Corners and Dash off
  19683. $this->SetLineJoin(2);
  19684. $this->SetLineCap(2);
  19685. $this->SetDash();
  19686. }
  19687. }
  19688. $this->SetDash();
  19689. $this->y = $save_y;
  19690. }
  19691. function PaintImgBorder($objattr,$is_table) {
  19692. // Borders are disabled in columns - messes up the repositioning in printcolumnbuffer
  19693. if ($this->ColActive) { return ; } // *COLUMNS*
  19694. if ($is_table) { $k = $this->shrin_k; } else { $k = 1; }
  19695. $h = (isset($objattr['BORDER-HEIGHT']) ? $objattr['BORDER-HEIGHT'] : 0);
  19696. $w = (isset($objattr['BORDER-WIDTH']) ? $objattr['BORDER-WIDTH'] : 0);
  19697. $x0 = (isset($objattr['BORDER-X']) ? $objattr['BORDER-X'] : 0);
  19698. $y0 = (isset($objattr['BORDER-Y']) ? $objattr['BORDER-Y'] : 0);
  19699. // BORDERS
  19700. if ($objattr['border_top']) {
  19701. $tbd = $objattr['border_top'];
  19702. if (!empty($tbd['s'])) {
  19703. $this->_setBorderLine($tbd,$k);
  19704. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','T'); }
  19705. $this->Line($x0, $y0, $x0 + $w, $y0);
  19706. // Reset Corners and Dash off
  19707. $this->SetLineJoin(2);
  19708. $this->SetLineCap(2);
  19709. $this->SetDash();
  19710. }
  19711. }
  19712. if ($objattr['border_left']) {
  19713. $tbd = $objattr['border_left'];
  19714. if (!empty($tbd['s'])) {
  19715. $this->_setBorderLine($tbd,$k);
  19716. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','L'); }
  19717. $this->Line($x0, $y0, $x0, $y0 + $h);
  19718. // Reset Corners and Dash off
  19719. $this->SetLineJoin(2);
  19720. $this->SetLineCap(2);
  19721. $this->SetDash();
  19722. }
  19723. }
  19724. if ($objattr['border_right']) {
  19725. $tbd = $objattr['border_right'];
  19726. if (!empty($tbd['s'])) {
  19727. $this->_setBorderLine($tbd,$k);
  19728. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','R'); }
  19729. $this->Line($x0 + $w, $y0, $x0 + $w, $y0 + $h);
  19730. // Reset Corners and Dash off
  19731. $this->SetLineJoin(2);
  19732. $this->SetLineCap(2);
  19733. $this->SetDash();
  19734. }
  19735. }
  19736. if ($objattr['border_bottom']) {
  19737. $tbd = $objattr['border_bottom'];
  19738. if (!empty($tbd['s'])) {
  19739. $this->_setBorderLine($tbd,$k);
  19740. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','B'); }
  19741. $this->Line($x0, $y0 + $h, $x0 + $w, $y0 + $h);
  19742. // Reset Corners and Dash off
  19743. $this->SetLineJoin(2);
  19744. $this->SetLineCap(2);
  19745. $this->SetDash();
  19746. }
  19747. }
  19748. $this->SetDash();
  19749. $this->SetAlpha(1);
  19750. }
  19751. /*-- END HTML-CSS --*/
  19752. function Reset() {
  19753. $this->SetTColor($this->ConvertColor(0));
  19754. $this->SetDColor($this->ConvertColor(0));
  19755. $this->SetFColor($this->ConvertColor(255));
  19756. $this->SetAlpha(1);
  19757. $this->colorarray = ''; // mPDF 5.3.76
  19758. $this->spanbgcolorarray = ''; // mPDF 5.3.76
  19759. $this->spanbgcolor = false;
  19760. // mPDF 5.3.61
  19761. $this->spanborder = false;
  19762. $this->spanborddet = array();
  19763. $this->ResetStyles();
  19764. $this->HREF = '';
  19765. $this->outlineparam = array();
  19766. $this->outline_on = false;
  19767. $this->SetTextOutline(false);
  19768. $this->SUP = false;
  19769. $this->SUB = false;
  19770. $this->strike = false;
  19771. $this->textshadow = ''; // mPDF 5.3.A2
  19772. $this->SetFont($this->default_font,'',0,false);
  19773. $this->SetFontSize($this->default_font_size,false);
  19774. $this->currentfontfamily = '';
  19775. $this->currentfontsize = '';
  19776. /*-- TABLES --*/
  19777. if ($this->tableLevel) {
  19778. $this->SetLineHeight('',$this->table_lineheight); // *TABLES*
  19779. }
  19780. else
  19781. /*-- END TABLES --*/
  19782. /*-- LISTS --*/
  19783. if ($this->listlvl && $this->list_lineheight[$this->listlvl][$this->bulletarray['occur']]) {
  19784. $this->SetLineHeight('',$this->list_lineheight[$this->listlvl][$this->bulletarray['occur']]); // sets default line height
  19785. }
  19786. else
  19787. /*-- END LISTS --*/
  19788. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  19789. $this->SetLineHeight('',$this->blk[$this->blklvl]['line_height']); // sets default line height
  19790. }
  19791. $this->toupper = false;
  19792. $this->tolower = false;
  19793. $this->kerning = false;
  19794. $this->lSpacingCSS = '';
  19795. $this->wSpacingCSS = '';
  19796. $this->fixedlSpacing = false;
  19797. $this->minwSpacing = 0;
  19798. $this->capitalize = false;
  19799. $this->SetDash(); //restore to no dash
  19800. $this->dash_on = false;
  19801. $this->dotted_on = false;
  19802. $this->divwidth = 0;
  19803. $this->divheight = 0;
  19804. $this->divalign = '';
  19805. $this->divrevert = false;
  19806. $this->oldy = -1;
  19807. $bodystyle = array();
  19808. if (isset($this->CSS['BODY']['FONT-STYLE'])) { $bodystyle['FONT-STYLE'] = $this->CSS['BODY']['FONT-STYLE']; }
  19809. if (isset($this->CSS['BODY']['FONT-WEIGHT'])) { $bodystyle['FONT-WEIGHT'] = $this->CSS['BODY']['FONT-WEIGHT']; }
  19810. if (isset($this->CSS['BODY']['COLOR'])) { $bodystyle['COLOR'] = $this->CSS['BODY']['COLOR']; }
  19811. if (isset($bodystyle)) { $this->setCSS($bodystyle,'BLOCK','BODY'); }
  19812. }
  19813. /*-- HTML-CSS --*/
  19814. function ReadMetaTags($html) {
  19815. // changes anykey=anyvalue to anykey="anyvalue" (only do this when this happens inside tags)
  19816. $regexp = '/ (\\w+?)=([^\\s>"]+)/si';
  19817. $html = preg_replace($regexp," \$1=\"\$2\"",$html);
  19818. if (preg_match('/<title>(.*?)<\/title>/si',$html,$m)) {
  19819. $this->SetTitle($m[1]);
  19820. }
  19821. preg_match_all('/<meta [^>]*?(name|content)="([^>]*?)" [^>]*?(name|content)="([^>]*?)".*?>/si',$html,$aux);
  19822. $firstattr = $aux[1];
  19823. $secondattr = $aux[3];
  19824. for( $i = 0 ; $i < count($aux[0]) ; $i++) {
  19825. $name = ( strtoupper($firstattr[$i]) == "NAME" )? strtoupper($aux[2][$i]) : strtoupper($aux[4][$i]);
  19826. $content = ( strtoupper($firstattr[$i]) == "CONTENT" )? $aux[2][$i] : $aux[4][$i];
  19827. switch($name) {
  19828. case "KEYWORDS": $this->SetKeywords($content); break;
  19829. case "AUTHOR": $this->SetAuthor($content); break;
  19830. case "DESCRIPTION": $this->SetSubject($content); break;
  19831. }
  19832. }
  19833. }
  19834. function ReadCharset($html) {
  19835. // Charset conversion
  19836. if ($this->allow_charset_conversion) {
  19837. if (preg_match('/<head.*charset=([^\'\"\s]*).*<\/head>/si',$html,$m)) {
  19838. if (strtoupper($m[1]) != 'UTF-8') {
  19839. $this->charset_in = strtoupper($m[1]);
  19840. }
  19841. }
  19842. }
  19843. }
  19844. /*-- END HTML-CSS --*/
  19845. //////////////////
  19846. /// CSS parser ///
  19847. //////////////////
  19848. //////////////////
  19849. /// CSS parser ///
  19850. //////////////////
  19851. //////////////////
  19852. /// CSS parser ///
  19853. //////////////////
  19854. /*-- HTML-CSS --*/
  19855. function ReadDefaultCSS($CSSstr) {
  19856. $CSS = array();
  19857. $CSSstr = preg_replace('|/\*.*?\*/|s',' ',$CSSstr);
  19858. $CSSstr = preg_replace('/[\s\n\r\t\f]/s',' ',$CSSstr);
  19859. $CSSstr = preg_replace('/(<\!\-\-|\-\->)/s',' ',$CSSstr);
  19860. if ($CSSstr ) {
  19861. preg_match_all('/(.*?)\{(.*?)\}/',$CSSstr,$styles);
  19862. for($i=0; $i < count($styles[1]) ; $i++) {
  19863. $stylestr= trim($styles[2][$i]);
  19864. $stylearr = explode(';',$stylestr);
  19865. foreach($stylearr AS $sta) {
  19866. if (trim($sta)) {
  19867. // Changed to allow style="background: url('http://www.bpm1.com/bg.jpg')"
  19868. list($property,$value) = explode(':',$sta,2);
  19869. $property = trim($property);
  19870. $value = preg_replace('/\s*!important/i','',$value);
  19871. $value = trim($value);
  19872. if ($property && ($value || $value==='0')) {
  19873. $classproperties[strtoupper($property)] = $value;
  19874. }
  19875. }
  19876. }
  19877. $classproperties = $this->fixCSS($classproperties);
  19878. $tagstr = strtoupper(trim($styles[1][$i]));
  19879. $tagarr = explode(',',$tagstr);
  19880. foreach($tagarr AS $tg) {
  19881. $tags = preg_split('/\s+/',trim($tg));
  19882. $level = count($tags);
  19883. if ($level == 1) { // e.g. p or .class or #id or p.class or p#id
  19884. $t = trim($tags[0]);
  19885. if ($t) {
  19886. $tag = '';
  19887. if (preg_match('/^('.$this->allowedCSStags.')$/',$t)) { $tag= $t; }
  19888. if ($this->CSS[$tag] && $tag) { $CSS[$tag] = $this->array_merge_recursive_unique($CSS[$tag], $classproperties); }
  19889. else if ($tag) { $CSS[$tag] = $classproperties; }
  19890. }
  19891. }
  19892. }
  19893. $properties = array();
  19894. $values = array();
  19895. $classproperties = array();
  19896. }
  19897. } // end of if
  19898. return $CSS;
  19899. }
  19900. function ReadCSS($html) {
  19901. preg_match_all('/<style[^>]*media=["\']([^"\'>]*)["\'].*?<\/style>/is',$html,$m);
  19902. for($i=0; $i<count($m[0]); $i++) {
  19903. if ($this->CSSselectMedia && !preg_match('/('.trim($this->CSSselectMedia).'|all)/i',$m[1][$i])) {
  19904. $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html);
  19905. }
  19906. }
  19907. preg_match_all('/<link[^>]*media=["\']([^"\'>]*)["\'].*?>/is',$html,$m);
  19908. for($i=0; $i<count($m[0]); $i++) {
  19909. if ($this->CSSselectMedia && !preg_match('/('.trim($this->CSSselectMedia).'|all)/i',$m[1][$i])) {
  19910. $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html);
  19911. }
  19912. }
  19913. // Remove Comment tags <!-- --> inside CSS as <style> in HTML document
  19914. // Remove Comment tags /* ... */ inside CSS as <style> in HTML document
  19915. preg_match_all('/<style.*?>(.*?)<\/style>/si',$html,$m);
  19916. if (count($m[1])) {
  19917. for($i=0;$i<count($m[1]);$i++) {
  19918. // Remove comment tags
  19919. $sub = preg_replace('/(<\!\-\-|\-\->)/s',' ',$m[1][$i]);
  19920. $sub = preg_replace('|/\*.*?\*/|s',' ',$sub);
  19921. $html = preg_replace('/'.preg_quote($m[1][$i], '/').'/si', $sub, $html);
  19922. }
  19923. }
  19924. $html = preg_replace('/<!--mpdf/i','',$html);
  19925. $html = preg_replace('/mpdf-->/i','',$html);
  19926. $html = preg_replace('/<\!\-\-.*?\-\->/s',' ',$html);
  19927. $match = 0; // no match for instance
  19928. $regexp = ''; // This helps debugging: showing what is the REAL string being processed
  19929. $CSSext = array();
  19930. //CSS inside external files
  19931. $regexp = '/<link[^>]*rel=["\']stylesheet["\'][^>]*href=["\']([^>"\']*)["\'].*?>/si';
  19932. $x = preg_match_all($regexp,$html,$cxt);
  19933. if ($x) {
  19934. $match += $x;
  19935. $CSSext = $cxt[1];
  19936. }
  19937. $regexp = '/<link[^>]*href=["\']([^>"\']*)["\'][^>]*?rel=["\']stylesheet["\'].*?>/si';
  19938. $x = preg_match_all($regexp,$html,$cxt);
  19939. if ($x) {
  19940. $match += $x;
  19941. $CSSext = array_merge($CSSext,$cxt[1]);
  19942. }
  19943. // look for @import stylesheets
  19944. //$regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css)[\'\"]{0,1}\)/si';
  19945. $regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css(\?\S+)?)[\'\"]{0,1}\)/si'; // mPDF 5.3.63
  19946. $x = preg_match_all($regexp,$html,$cxt);
  19947. if ($x) {
  19948. $match += $x;
  19949. $CSSext = array_merge($CSSext,$cxt[1]);
  19950. }
  19951. // look for @import without the url()
  19952. //$regexp = '/@import [\'\"]{0,1}([^;]*?\.css)[\'\"]{0,1}/si';
  19953. $regexp = '/@import [\'\"]{0,1}([^;]*?\.css(\?\S+)?)[\'\"]{0,1}/si'; // mPDF 5.3.63
  19954. $x = preg_match_all($regexp,$html,$cxt);
  19955. if ($x) {
  19956. $match += $x;
  19957. $CSSext = array_merge($CSSext,$cxt[1]);
  19958. }
  19959. $ind = 0;
  19960. $CSSstr = '';
  19961. if (!is_array($this->cascadeCSS)) $this->cascadeCSS = array();
  19962. while($match){
  19963. $path = $CSSext[$ind];
  19964. $this->GetFullPath($path);
  19965. $CSSextblock = $this->_get_file($path);
  19966. if ($CSSextblock) {
  19967. // look for embedded @import stylesheets in other stylesheets
  19968. // and fix url paths (including background-images) relative to stylesheet
  19969. //$regexpem = '/@import url\([\'\"]{0,1}(.*?\.css)[\'\"]{0,1}\)/si';
  19970. $regexpem = '/@import url\([\'\"]{0,1}(.*?\.css(\?\S+)?)[\'\"]{0,1}\)/si'; // mPDF 5.3.63
  19971. $xem = preg_match_all($regexpem,$CSSextblock,$cxtem);
  19972. $cssBasePath = preg_replace('/\/[^\/]*$/','',$path) . '/';
  19973. if ($xem) {
  19974. foreach($cxtem[1] AS $cxtembedded) {
  19975. // path is relative to original stlyesheet!!
  19976. $this->GetFullPath($cxtembedded, $cssBasePath );
  19977. $match++;
  19978. $CSSext[] = $cxtembedded;
  19979. }
  19980. }
  19981. $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si';
  19982. $xem = preg_match_all($regexpem,$CSSextblock,$cxtem);
  19983. if ($xem) {
  19984. for ($i=0;$i<count($cxtem[0]);$i++) {
  19985. // path is relative to original stlyesheet!!
  19986. $embedded = $cxtem[2][$i];
  19987. $this->GetFullPath($embedded, $cssBasePath );
  19988. $CSSextblock = preg_replace('/'.preg_quote($cxtem[0][$i],'/').'/', ($cxtem[1][$i].$embedded.$cxtem[3][$i]), $CSSextblock);
  19989. }
  19990. }
  19991. $CSSstr .= ' '.$CSSextblock;
  19992. }
  19993. $match--;
  19994. $ind++;
  19995. } //end of match
  19996. $match = 0; // reset value, if needed
  19997. // CSS as <style> in HTML document
  19998. $regexp = '/<style.*?>(.*?)<\/style>/si';
  19999. $match = preg_match_all($regexp,$html,$CSSblock);
  20000. if ($match) {
  20001. $tmpCSSstr = implode(' ',$CSSblock[1]);
  20002. $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si';
  20003. $xem = preg_match_all($regexpem,$tmpCSSstr ,$cxtem);
  20004. if ($xem) {
  20005. for ($i=0;$i<count($cxtem[0]);$i++) {
  20006. $embedded = $cxtem[2][$i];
  20007. $this->GetFullPath($embedded);
  20008. $tmpCSSstr = preg_replace('/'.preg_quote($cxtem[0][$i],'/').'/', ($cxtem[1][$i].$embedded.$cxtem[3][$i]), $tmpCSSstr );
  20009. }
  20010. }
  20011. $CSSstr .= ' '.$tmpCSSstr;
  20012. }
  20013. // Remove comments
  20014. $CSSstr = preg_replace('|/\*.*?\*/|s',' ',$CSSstr);
  20015. $CSSstr = preg_replace('/[\s\n\r\t\f]/s',' ',$CSSstr);
  20016. if (preg_match('/@media/',$CSSstr)) {
  20017. preg_match_all('/@media(.*?)\{(([^\{\}]*\{[^\{\}]*\})+)\s*\}/is',$CSSstr,$m);
  20018. for($i=0; $i<count($m[0]); $i++) {
  20019. if ($this->CSSselectMedia && !preg_match('/('.trim($this->CSSselectMedia).'|all)/i',$m[1][$i])) {
  20020. $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$CSSstr);
  20021. }
  20022. else {
  20023. $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/',' '.$m[2][$i].' ',$CSSstr);
  20024. }
  20025. }
  20026. }
  20027. $CSSstr = preg_replace('/(<\!\-\-|\-\->)/s',' ',$CSSstr);
  20028. if ($CSSstr ) {
  20029. preg_match_all('/(.*?)\{(.*?)\}/',$CSSstr,$styles);
  20030. for($i=0; $i < count($styles[1]) ; $i++) {
  20031. // SET array e.g. $classproperties['COLOR'] = '#ffffff';
  20032. $stylestr= trim($styles[2][$i]);
  20033. $stylearr = explode(';',$stylestr);
  20034. foreach($stylearr AS $sta) {
  20035. if (trim($sta)) {
  20036. // Changed to allow style="background: url('http://www.bpm1.com/bg.jpg')"
  20037. list($property,$value) = explode(':',$sta,2);
  20038. $property = trim($property);
  20039. $value = preg_replace('/\s*!important/i','',$value);
  20040. $value = trim($value);
  20041. if ($property && ($value || $value==='0')) {
  20042. // Ignores -webkit-gradient so doesn't override -moz-
  20043. if ((strtoupper($property)=='BACKGROUND-IMAGE' || strtoupper($property)=='BACKGROUND') && preg_match('/-webkit-gradient/i',$value)) {
  20044. continue;
  20045. }
  20046. $classproperties[strtoupper($property)] = $value;
  20047. }
  20048. }
  20049. }
  20050. $classproperties = $this->fixCSS($classproperties);
  20051. $tagstr = strtoupper(trim($styles[1][$i]));
  20052. $tagarr = explode(',',$tagstr);
  20053. $pageselectors = false; // used to turn on $this->mirrorMargins
  20054. foreach($tagarr AS $tg) {
  20055. $tags = preg_split('/\s+/',trim($tg));
  20056. $level = count($tags);
  20057. $t = '';
  20058. $t2 = '';
  20059. $t3 = '';
  20060. if (trim($tags[0])=='@PAGE') {
  20061. if (isset($tags[0])) { $t = trim($tags[0]); }
  20062. if (isset($tags[1])) { $t2 = trim($tags[1]); }
  20063. if (isset($tags[2])) { $t3 = trim($tags[2]); }
  20064. $tag = '';
  20065. if ($level==1) { $tag = $t; }
  20066. else if ($level==2 && preg_match('/^[:](.*)$/',$t2,$m)) {
  20067. $tag = $t.'>>PSEUDO>>'.$m[1];
  20068. if ($m[1]=='LEFT' || $m[1]=='RIGHT') { $pageselectors = true; } // used to turn on $this->mirrorMargins
  20069. }
  20070. else if ($level==2) { $tag = $t.'>>NAMED>>'.$t2; }
  20071. else if ($level==3 && preg_match('/^[:](.*)$/',$t3,$m)) {
  20072. $tag = $t.'>>NAMED>>'.$t2.'>>PSEUDO>>'.$m[1];
  20073. if ($m[1]=='LEFT' || $m[1]=='RIGHT') { $pageselectors = true; } // used to turn on $this->mirrorMargins
  20074. }
  20075. if (isset($this->CSS[$tag]) && $tag) { $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties); }
  20076. else if ($tag) { $this->CSS[$tag] = $classproperties; }
  20077. }
  20078. else if ($level == 1) { // e.g. p or .class or #id or p.class or p#id
  20079. if (isset($tags[0])) { $t = trim($tags[0]); }
  20080. if ($t) {
  20081. $tag = '';
  20082. if (preg_match('/^[.](.*)$/',$t,$m)) { $tag = 'CLASS>>'.$m[1]; }
  20083. else if (preg_match('/^[#](.*)$/',$t,$m)) { $tag = 'ID>>'.$m[1]; }
  20084. else if (preg_match('/^('.$this->allowedCSStags.')[.](.*)$/',$t,$m)) { $tag = $m[1].'>>CLASS>>'.$m[2]; }
  20085. else if (preg_match('/^('.$this->allowedCSStags.')\s*:NTH-CHILD\((.*)\)$/',$t,$m)) { $tag = $m[1].'>>SELECTORNTHCHILD>>'.$m[2]; } // mPDF 5.3.82
  20086. else if (preg_match('/^('.$this->allowedCSStags.')[#](.*)$/',$t,$m)) { $tag = $m[1].'>>ID>>'.$m[2]; }
  20087. else if (preg_match('/^('.$this->allowedCSStags.')$/',$t)) { $tag= $t; }
  20088. if (isset($this->CSS[$tag]) && $tag) { $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties); }
  20089. else if ($tag) { $this->CSS[$tag] = $classproperties; }
  20090. }
  20091. }
  20092. else {
  20093. $tmp = array();
  20094. for($n=0;$n<$level;$n++) {
  20095. if (isset($tags[$n])) { $t = trim($tags[$n]); }
  20096. else { $t = ''; }
  20097. if ($t) {
  20098. $tag = '';
  20099. if (preg_match('/^[.](.*)$/',$t,$m)) { $tag = 'CLASS>>'.$m[1]; }
  20100. else if (preg_match('/^[#](.*)$/',$t,$m)) { $tag = 'ID>>'.$m[1]; }
  20101. else if (preg_match('/^('.$this->allowedCSStags.')[.](.*)$/',$t,$m)) { $tag = $m[1].'>>CLASS>>'.$m[2]; }
  20102. else if (preg_match('/^('.$this->allowedCSStags.')\s*:NTH-CHILD\((.*)\)$/',$t,$m)) { $tag = $m[1].'>>SELECTORNTHCHILD>>'.$m[2]; } // mPDF 5.3.82
  20103. else if (preg_match('/^('.$this->allowedCSStags.')[#](.*)$/',$t,$m)) { $tag = $m[1].'>>ID>>'.$m[2]; }
  20104. else if (preg_match('/^('.$this->allowedCSStags.')$/',$t)) { $tag= $t; }
  20105. if ($tag) $tmp[] = $tag;
  20106. else { break; }
  20107. }
  20108. }
  20109. if ($tag) {
  20110. $x = &$this->cascadeCSS;
  20111. foreach($tmp AS $tp) { $x = &$x[$tp]; }
  20112. $x = $this->array_merge_recursive_unique($x, $classproperties);
  20113. $x['depth'] = $level;
  20114. }
  20115. }
  20116. }
  20117. if ($pageselectors) { $this->mirrorMargins = true; }
  20118. $properties = array();
  20119. $values = array();
  20120. $classproperties = array();
  20121. }
  20122. } // end of if
  20123. //Remove CSS (tags and content), if any
  20124. $regexp = '/<style.*?>(.*?)<\/style>/si'; // it can be <style> or <style type="txt/css">
  20125. $html = preg_replace($regexp,'',$html);
  20126. //print_r($this->CSS); exit;
  20127. //print_r($this->cascadeCSS); exit;
  20128. return $html;
  20129. }
  20130. function readInlineCSS($html) {
  20131. //Fix incomplete CSS code
  20132. $size = strlen($html)-1;
  20133. if (substr($html,$size,1) != ';') $html .= ';';
  20134. //Make CSS[Name-of-the-class] = array(key => value)
  20135. $regexp = '|\\s*?(\\S+?):(.+?);|i';
  20136. preg_match_all( $regexp, $html, $styleinfo);
  20137. $properties = $styleinfo[1];
  20138. $values = $styleinfo[2];
  20139. //Array-properties and Array-values must have the SAME SIZE!
  20140. $classproperties = array();
  20141. for($i = 0; $i < count($properties) ; $i++) {
  20142. // Ignores -webkit-gradient so doesn't override -moz-
  20143. if ((strtoupper($properties[$i])=='BACKGROUND-IMAGE' || strtoupper($properties[$i])=='BACKGROUND') && preg_match('/-webkit-gradient/i',$values[$i])) {
  20144. continue;
  20145. }
  20146. $classproperties[strtoupper($properties[$i])] = trim($values[$i]);
  20147. }
  20148. return $this->fixCSS($classproperties);
  20149. }
  20150. function setCSS($arrayaux,$type='',$tag='') { // type= INLINE | BLOCK | LIST // tag= BODY
  20151. if (!is_array($arrayaux)) return; //Removes PHP Warning
  20152. // Set font size first so that e.g. MARGIN 0.83em works on font size for this element
  20153. if (isset($arrayaux['FONT-SIZE'])) {
  20154. $v = $arrayaux['FONT-SIZE'];
  20155. if(is_numeric($v[0])) {
  20156. // mPDF 5.3.28
  20157. if ($type == 'BLOCK' && $this->blklvl>0 && isset($this->blk[$this->blklvl-1]['InlineProperties']) && isset($this->blk[$this->blklvl-1]['InlineProperties']['size'])) {
  20158. $mmsize = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['InlineProperties']['size']);
  20159. }
  20160. else {
  20161. $mmsize = $this->ConvertSize($v,$this->FontSize);
  20162. }
  20163. $this->SetFontSize( $mmsize*(_MPDFK),false ); //Get size in points (pt)
  20164. }
  20165. else{
  20166. $v = strtoupper($v);
  20167. if (isset($this->fontsizes[$v])) {
  20168. $this->SetFontSize( $this->fontsizes[$v]* $this->default_font_size,false);
  20169. }
  20170. }
  20171. if ($tag == 'BODY') { $this->SetDefaultFontSize($this->FontSizePt); }
  20172. }
  20173. if ($this->useLang && !$this->usingCoreFont) {
  20174. if (isset($arrayaux['LANG']) && $arrayaux['LANG'] && $arrayaux['LANG'] != $this->default_lang && ((strlen($arrayaux['LANG']) == 5 && $arrayaux['LANG'] != 'UTF-8') || strlen($arrayaux['LANG']) == 2)) {
  20175. list ($coreSuitable,$mpdf_pdf_unifonts) = GetLangOpts($arrayaux['LANG'], $this->useAdobeCJK);
  20176. if ($mpdf_pdf_unifonts) { $this->RestrictUnicodeFonts($mpdf_pdf_unifonts); }
  20177. else { $this->RestrictUnicodeFonts($this->default_available_fonts ); }
  20178. if ($tag == 'BODY') {
  20179. $this->currentLang = $arrayaux['LANG'];
  20180. $this->default_lang = $arrayaux['LANG'];
  20181. if ($mpdf_pdf_unifonts) { $this->default_available_fonts = $mpdf_pdf_unifonts; }
  20182. }
  20183. }
  20184. else {
  20185. $this->RestrictUnicodeFonts($this->default_available_fonts );
  20186. }
  20187. }
  20188. // FOR INLINE and BLOCK OR 'BODY'
  20189. if (isset($arrayaux['FONT-FAMILY'])) {
  20190. $v = $arrayaux['FONT-FAMILY'];
  20191. //If it is a font list, get all font types
  20192. $aux_fontlist = explode(",",$v);
  20193. $found = 0;
  20194. foreach($aux_fontlist AS $f) {
  20195. $fonttype = trim($f);
  20196. $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
  20197. $fonttype = preg_replace('/ /','',$fonttype);
  20198. $v = strtolower(trim($fonttype));
  20199. if (isset($this->fonttrans[$v]) && $this->fonttrans[$v]) { $v = $this->fonttrans[$v]; }
  20200. if ((!$this->onlyCoreFonts && in_array($v,$this->available_unifonts)) ||
  20201. in_array($v,array('ccourier','ctimes','chelvetica')) || /* mPDF 5.3.21 & 22 */
  20202. ($this->onlyCoreFonts && in_array($v,array('courier','times','helvetica','arial'))) ||
  20203. in_array($v, array('sjis','uhc','big5','gb'))) {
  20204. $fonttype = $v;
  20205. $found = 1;
  20206. break;
  20207. }
  20208. }
  20209. if (!$found) {
  20210. foreach($aux_fontlist AS $f) {
  20211. $fonttype = trim($f);
  20212. $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
  20213. $fonttype = preg_replace('/ /','',$fonttype);
  20214. $v = strtolower(trim($fonttype));
  20215. if (isset($this->fonttrans[$v]) && $this->fonttrans[$v]) { $v = $this->fonttrans[$v]; }
  20216. if (in_array($v,$this->sans_fonts) || in_array($v,$this->serif_fonts) || in_array($v,$this->mono_fonts) ) {
  20217. $fonttype = $v;
  20218. break;
  20219. }
  20220. }
  20221. }
  20222. if ($tag == 'BODY') {
  20223. $this->SetDefaultFont($fonttype);
  20224. }
  20225. $this->SetFont($fonttype,$this->currentfontstyle,0,false);
  20226. }
  20227. else {
  20228. $this->SetFont($this->currentfontfamily,$this->currentfontstyle,0,false);
  20229. }
  20230. foreach($arrayaux as $k => $v) {
  20231. if ($type != 'INLINE' && $tag != 'BODY' && $type != 'LIST') { // mPDF 5.3.65
  20232. switch($k){
  20233. // BORDERS
  20234. case 'BORDER-TOP':
  20235. $this->blk[$this->blklvl]['border_top'] = $this->border_details($v);
  20236. if ($this->blk[$this->blklvl]['border_top']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  20237. break;
  20238. case 'BORDER-BOTTOM':
  20239. $this->blk[$this->blklvl]['border_bottom'] = $this->border_details($v);
  20240. if ($this->blk[$this->blklvl]['border_bottom']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  20241. break;
  20242. case 'BORDER-LEFT':
  20243. $this->blk[$this->blklvl]['border_left'] = $this->border_details($v);
  20244. if ($this->blk[$this->blklvl]['border_left']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  20245. break;
  20246. case 'BORDER-RIGHT':
  20247. $this->blk[$this->blklvl]['border_right'] = $this->border_details($v);
  20248. if ($this->blk[$this->blklvl]['border_right']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  20249. break;
  20250. // PADDING
  20251. case 'PADDING-TOP':
  20252. $this->blk[$this->blklvl]['padding_top'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20253. break;
  20254. case 'PADDING-BOTTOM':
  20255. $this->blk[$this->blklvl]['padding_bottom'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20256. break;
  20257. case 'PADDING-LEFT':
  20258. $this->blk[$this->blklvl]['padding_left'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20259. break;
  20260. case 'PADDING-RIGHT':
  20261. $this->blk[$this->blklvl]['padding_right'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20262. break;
  20263. // MARGINS
  20264. case 'MARGIN-TOP':
  20265. $tmp = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20266. if (isset($this->blk[$this->blklvl]['lastbottommargin'])) {
  20267. if ($tmp > $this->blk[$this->blklvl]['lastbottommargin']) {
  20268. $tmp -= $this->blk[$this->blklvl]['lastbottommargin'];
  20269. }
  20270. else {
  20271. $tmp = 0;
  20272. }
  20273. }
  20274. $this->blk[$this->blklvl]['margin_top'] = $tmp;
  20275. break;
  20276. case 'MARGIN-BOTTOM':
  20277. $this->blk[$this->blklvl]['margin_bottom'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20278. break;
  20279. case 'MARGIN-LEFT':
  20280. $this->blk[$this->blklvl]['margin_left'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20281. break;
  20282. case 'MARGIN-RIGHT':
  20283. $this->blk[$this->blklvl]['margin_right'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20284. break;
  20285. /*-- BORDER-RADIUS --*/
  20286. case 'BORDER-TOP-LEFT-RADIUS-H':
  20287. $this->blk[$this->blklvl]['border_radius_TL_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20288. break;
  20289. case 'BORDER-TOP-LEFT-RADIUS-V':
  20290. $this->blk[$this->blklvl]['border_radius_TL_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20291. break;
  20292. case 'BORDER-TOP-RIGHT-RADIUS-H':
  20293. $this->blk[$this->blklvl]['border_radius_TR_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20294. break;
  20295. case 'BORDER-TOP-RIGHT-RADIUS-V':
  20296. $this->blk[$this->blklvl]['border_radius_TR_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20297. break;
  20298. case 'BORDER-BOTTOM-LEFT-RADIUS-H':
  20299. $this->blk[$this->blklvl]['border_radius_BL_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20300. break;
  20301. case 'BORDER-BOTTOM-LEFT-RADIUS-V':
  20302. $this->blk[$this->blklvl]['border_radius_BL_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20303. break;
  20304. case 'BORDER-BOTTOM-RIGHT-RADIUS-H':
  20305. $this->blk[$this->blklvl]['border_radius_BR_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20306. break;
  20307. case 'BORDER-BOTTOM-RIGHT-RADIUS-V':
  20308. $this->blk[$this->blklvl]['border_radius_BR_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20309. break;
  20310. /*-- END BORDER-RADIUS --*/
  20311. // mPDF 5.3.A1
  20312. case 'BOX-SHADOW':
  20313. $bs = $this->setCSSboxshadow($v);
  20314. if ($bs) { $this->blk[$this->blklvl]['box_shadow'] = $bs; }
  20315. break;
  20316. case 'BACKGROUND-CLIP':
  20317. if (strtoupper($v) == 'PADDING-BOX') { $this->blk[$this->blklvl]['background_clip'] = 'padding-box'; }
  20318. break;
  20319. case 'PAGE-BREAK-AFTER':
  20320. if (strtoupper($v) == 'AVOID') { $this->blk[$this->blklvl]['page_break_after_avoid'] = true; }
  20321. // mPDF 5.3.03
  20322. else if (strtoupper($v) == 'ALWAYS' || strtoupper($v) == 'LEFT' || strtoupper($v) == 'RIGHT') { $this->blk[$this->blklvl]['page_break_after'] = strtoupper($v) ; }
  20323. break;
  20324. case 'WIDTH':
  20325. if (strtoupper($v) != 'AUTO') {
  20326. $this->blk[$this->blklvl]['css_set_width'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20327. }
  20328. break;
  20329. case 'TEXT-INDENT':
  20330. // Left as raw value (may include 1% or 2em)
  20331. $this->blk[$this->blklvl]['text_indent'] = $v;
  20332. break;
  20333. }//end of switch($k)
  20334. }
  20335. if ($type != 'INLINE' && $type != 'LIST') { // includes BODY tag // mPDF 5.3.65
  20336. switch($k){
  20337. case 'MARGIN-COLLAPSE': // Custom tag to collapse margins at top and bottom of page
  20338. if (strtoupper($v) == 'COLLAPSE') { $this->blk[$this->blklvl]['margin_collapse'] = true; }
  20339. break;
  20340. case 'LINE-HEIGHT':
  20341. $this->blk[$this->blklvl]['line_height'] = $this->fixLineheight($v);
  20342. if (!$this->blk[$this->blklvl]['line_height'] ) { $this->blk[$this->blklvl]['line_height'] = $this->normalLineheight; }
  20343. break;
  20344. case 'TEXT-ALIGN': //left right center justify
  20345. switch (strtoupper($v)) {
  20346. case 'LEFT':
  20347. $this->blk[$this->blklvl]['align']="L";
  20348. break;
  20349. case 'CENTER':
  20350. $this->blk[$this->blklvl]['align']="C";
  20351. break;
  20352. case 'RIGHT':
  20353. $this->blk[$this->blklvl]['align']="R";
  20354. break;
  20355. case 'JUSTIFY':
  20356. $this->blk[$this->blklvl]['align']="J";
  20357. break;
  20358. }
  20359. break;
  20360. /*-- BACKGROUNDS --*/
  20361. case 'BACKGROUND-GRADIENT':
  20362. if ($type == 'BLOCK') {
  20363. $this->blk[$this->blklvl]['gradient'] = $v;
  20364. }
  20365. break;
  20366. /*-- END BACKGROUNDS --*/
  20367. case 'DIRECTION':
  20368. if ($v) { $this->blk[$this->blklvl]['direction'] = strtolower($v); }
  20369. break;
  20370. }//end of switch($k)
  20371. }
  20372. // FOR INLINE ONLY
  20373. if ($type == 'INLINE' || $type == 'LIST') { // mPDF 5.3.65
  20374. switch($k){
  20375. case 'DISPLAY': // Custom tag to collapse margins at top and bottom of page
  20376. if (strtoupper($v) == 'NONE') { $this->inlineDisplayOff = true; }
  20377. break;
  20378. case 'DIRECTION':
  20379. break;
  20380. }//end of switch($k)
  20381. }
  20382. // FOR INLINE ONLY
  20383. if ($type == 'INLINE') { // mPDF 5.3.65
  20384. switch($k){
  20385. // mPDF 5.3.61
  20386. // BORDERS
  20387. case 'BORDER-TOP':
  20388. $this->spanborddet['T'] = $this->border_details($v);
  20389. $this->spanborder = true;
  20390. break;
  20391. case 'BORDER-BOTTOM':
  20392. $this->spanborddet['B'] = $this->border_details($v);
  20393. $this->spanborder = true;
  20394. break;
  20395. case 'BORDER-LEFT':
  20396. $this->spanborddet['L'] = $this->border_details($v);
  20397. $this->spanborder = true;
  20398. break;
  20399. case 'BORDER-RIGHT':
  20400. $this->spanborddet['R'] = $this->border_details($v);
  20401. $this->spanborder = true;
  20402. break;
  20403. }//end of switch($k)
  20404. }
  20405. // FOR INLINE and BLOCK
  20406. switch($k){
  20407. case 'TEXT-ALIGN': //left right center justify
  20408. if (strtoupper($v) == 'NOJUSTIFY' && $this->blk[$this->blklvl]['align']=="J") {
  20409. $this->blk[$this->blklvl]['align']="";
  20410. }
  20411. break;
  20412. // bgcolor only - to stay consistent with original html2fpdf
  20413. case 'BACKGROUND':
  20414. case 'BACKGROUND-COLOR':
  20415. $cor = $this->ConvertColor($v);
  20416. if ($cor) {
  20417. if ($tag == 'BODY') {
  20418. $this->bodyBackgroundColor = $cor;
  20419. }
  20420. else if ($type == 'INLINE' || $type == 'LIST') { // mPDF 5.3.93
  20421. $this->spanbgcolorarray = $cor;
  20422. $this->spanbgcolor = true;
  20423. }
  20424. else {
  20425. $this->blk[$this->blklvl]['bgcolorarray'] = $cor;
  20426. $this->blk[$this->blklvl]['bgcolor'] = true;
  20427. }
  20428. }
  20429. else if ($type != 'INLINE' && $type != 'LIST') { // mPDF 5.3.93
  20430. if ($this->ColActive || $this->keep_block_together) {
  20431. $this->blk[$this->blklvl]['bgcolorarray'] = $this->blk[$this->blklvl-1]['bgcolorarray'] ;
  20432. $this->blk[$this->blklvl]['bgcolor'] = $this->blk[$this->blklvl-1]['bgcolor'] ;
  20433. }
  20434. }
  20435. break;
  20436. // auto | normal | none
  20437. case 'FONT-KERNING':
  20438. if ((strtoupper($v) == 'NORMAL' || strtoupper($v) == 'AUTO') && $this->useKerning) { $this->kerning = true; }
  20439. else if (strtoupper($v) == 'NONE') { $this->kerning = false; }
  20440. break;
  20441. // normal | <length>
  20442. case 'LETTER-SPACING':
  20443. $this->lSpacingCSS = $v;
  20444. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') {
  20445. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  20446. }
  20447. break;
  20448. // normal | <length>
  20449. case 'WORD-SPACING':
  20450. $this->wSpacingCSS = $v;
  20451. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  20452. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  20453. }
  20454. break;
  20455. case 'FONT-STYLE': // italic normal oblique
  20456. switch (strtoupper($v)) {
  20457. case 'ITALIC':
  20458. case 'OBLIQUE':
  20459. $this->SetStyle('I',true);
  20460. break;
  20461. case 'NORMAL':
  20462. $this->SetStyle('I',false);
  20463. break;
  20464. }
  20465. break;
  20466. case 'FONT-WEIGHT': // normal bold //Does not support: bolder, lighter, 100..900(step value=100)
  20467. switch (strtoupper($v)) {
  20468. case 'BOLD':
  20469. $this->SetStyle('B',true);
  20470. break;
  20471. case 'NORMAL':
  20472. $this->SetStyle('B',false);
  20473. break;
  20474. }
  20475. break;
  20476. case 'VERTICAL-ALIGN': //super and sub only dealt with here e.g. <SUB> and <SUP>
  20477. switch (strtoupper($v)) {
  20478. case 'SUPER':
  20479. $this->SUP=true;
  20480. break;
  20481. case 'SUB':
  20482. $this->SUB=true;
  20483. break;
  20484. }
  20485. break;
  20486. case 'TEXT-DECORATION': // none underline line-through (strikeout) //Does not support: overline, blink
  20487. if (stristr($v,'LINE-THROUGH')) {
  20488. $this->strike = true;
  20489. }
  20490. if (stristr($v,'UNDERLINE')) {
  20491. $this->SetStyle('U',true);
  20492. }
  20493. break;
  20494. case 'FONT-VARIANT':
  20495. switch (strtoupper($v)) {
  20496. case 'SMALL-CAPS':
  20497. $this->SetStyle('S',true);
  20498. break;
  20499. case 'NORMAL':
  20500. $this->SetStyle('S',false);
  20501. break;
  20502. }
  20503. break;
  20504. case 'TEXT-TRANSFORM': // none uppercase lowercase //Does support: capitalize
  20505. switch (strtoupper($v)) { //Not working 100%
  20506. case 'CAPITALIZE':
  20507. $this->capitalize=true;
  20508. break;
  20509. case 'UPPERCASE':
  20510. $this->toupper=true;
  20511. break;
  20512. case 'LOWERCASE':
  20513. $this->tolower=true;
  20514. break;
  20515. case 'NONE': break;
  20516. }
  20517. break;
  20518. // mPDF 5.3.A2
  20519. case 'TEXT-SHADOW':
  20520. $ts = $this->setCSStextshadow($v);
  20521. if ($ts) { $this->textshadow = $ts; }
  20522. break;
  20523. case 'OUTLINE-WIDTH':
  20524. switch(strtoupper($v)) {
  20525. case 'THIN': $v = '0.03em'; break;
  20526. case 'MEDIUM': $v = '0.05em'; break;
  20527. case 'THICK': $v = '0.07em'; break;
  20528. }
  20529. $this->outlineparam['WIDTH'] = $this->ConvertSize($v,$this->blk[$this->blklvl]['inner_width'],$this->FontSize);
  20530. break;
  20531. case 'OUTLINE-COLOR':
  20532. if (strtoupper($v) == 'INVERT') {
  20533. if ($this->colorarray) {
  20534. $cor = $this->colorarray;
  20535. $this->outlineparam['COLOR'] = $this->_invertColor($cor);
  20536. }
  20537. else {
  20538. $this->outlineparam['COLOR'] = $this->ConvertColor(255);
  20539. }
  20540. }
  20541. else {
  20542. $cor = $this->ConvertColor($v);
  20543. if ($cor) { $this->outlineparam['COLOR'] = $cor ; }
  20544. }
  20545. break;
  20546. case 'COLOR': // font color
  20547. $cor = $this->ConvertColor($v);
  20548. if ($cor) {
  20549. $this->colorarray = $cor;
  20550. $this->SetTColor($cor);
  20551. }
  20552. break;
  20553. }//end of switch($k)
  20554. }//end of foreach
  20555. }
  20556. /*-- END HTML-CSS --*/
  20557. function SetStyle($tag,$enable) {
  20558. $this->$tag=$enable;
  20559. $style='';
  20560. foreach(array('B','I','U','S') as $s) {
  20561. if($this->$s) {
  20562. $style.=$s;
  20563. }
  20564. }
  20565. if ($this->S && empty($this->upperCase)) { @include(_MPDF_PATH.'includes/upperCase.php'); } // mPDF 5.3.99
  20566. $this->currentfontstyle=$style;
  20567. $this->SetFont('',$style,0,false);
  20568. }
  20569. // Set multiple styles at one $str e.g. "BIS"
  20570. function SetStylesArray($arr) {
  20571. $style='';
  20572. foreach(array('B','I','U','S') as $s) {
  20573. if (isset($arr[$s])) {
  20574. if ($arr[$s]) {
  20575. $this->$s = true;
  20576. $style.=$s;
  20577. }
  20578. else { $this->$s = false; }
  20579. }
  20580. else if ($this->$s) { $style.=$s; }
  20581. }
  20582. $this->currentfontstyle=$style;
  20583. $this->SetFont('',$style,0,false);
  20584. }
  20585. // Set multiple styles at one $str e.g. "BIS"
  20586. function SetStyles($str) {
  20587. $style='';
  20588. foreach(array('B','I','U','S') as $s) {
  20589. if (strpos($str,$s) !== false) {
  20590. $this->$s = true;
  20591. $style.=$s;
  20592. }
  20593. else { $this->$s = false; }
  20594. }
  20595. $this->currentfontstyle=$style;
  20596. $this->SetFont('',$style,0,false);
  20597. }
  20598. function ResetStyles() {
  20599. foreach(array('B','I','U','S') as $s) {
  20600. $this->$s = false;
  20601. }
  20602. $this->currentfontstyle='';
  20603. $this->SetFont('','',0,false);
  20604. }
  20605. function DisableTags($str='')
  20606. {
  20607. if ($str == '') //enable all tags
  20608. {
  20609. //Insert new supported tags in the long string below.
  20610. $this->enabledtags = "<span><s><strike><del><bdo><big><small><ins><cite><acronym><font><sup><sub><b><u><i><a><strong><em><code><samp><tt><kbd><var><q><table><thead><tfoot><tbody><tr><th><td><ol><ul><li><dl><dt><dd><form><input><select><textarea><option><div><p><h1><h2><h3><h4><h5><h6><pre><center><blockquote><address><hr><img><br><indexentry><indexinsert><bookmark><watermarktext><watermarkimage><tts><ttz><tta><column_break><columnbreak><newcolumn><newpage><page_break><pagebreak><formfeed><columns><toc><tocentry><tocpagebreak><pageheader><pagefooter><setpageheader><setpagefooter><sethtmlpageheader><sethtmlpagefooter><annotation><template><jpgraph><barcode><dottab><caption><textcircle>"; // mPDF 5.3.56 5.3.A5
  20611. }
  20612. else
  20613. {
  20614. $str = explode(",",$str);
  20615. foreach($str as $v) $this->enabledtags = str_replace(trim($v),'',$this->enabledtags);
  20616. }
  20617. }
  20618. /*-- TABLES --*/
  20619. function finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight) {
  20620. $af = 0; // Above font
  20621. $bf = 0; // Below font
  20622. $mta = 0; // Maximum top-aligned
  20623. $mba = 0; // Maximum bottom-aligned
  20624. if ($lhxt['BS']) {
  20625. $af = max($af, ($lhxt['BS'] - ($maxfontsize * (0.5 + $this->baselineC))));
  20626. }
  20627. if ($lhxt['M']) {
  20628. $af = max($af, ($lhxt['M'] - $maxfontsize)/2);
  20629. $bf = max($bf, ($lhxt['M'] - $maxfontsize)/2);
  20630. }
  20631. if ($lhxt['TT']) {
  20632. $bf = max($bf, ($lhxt['TT'] - $maxfontsize));
  20633. }
  20634. if ($lhxt['TB']) {
  20635. $af = max($af, ($lhxt['TB'] - $maxfontsize));
  20636. }
  20637. if ($lhxt['T']) {
  20638. $mta = max($mta, $lhxt['T']);
  20639. }
  20640. if ($lhxt['B']) {
  20641. $mba = max($mba, $lhxt['B']);
  20642. }
  20643. if ((!$lhfixed || !$forceExactLineheight) && ($af > (($maxlineHeight - $maxfontsize)/2) || $bf > (($maxlineHeight - $maxfontsize)/2))) {
  20644. $maxlineHeight = $maxfontsize + $af + $bf;
  20645. }
  20646. else if (!$lhfixed) { $af = $bf = ($maxlineHeight - $maxfontsize)/2; }
  20647. if ($mta > $maxlineHeight) {
  20648. $bf += ($mta - $maxlineHeight);
  20649. $maxlineHeight = $mta;
  20650. }
  20651. if ($mba > $maxlineHeight) {
  20652. $af += ($mba - $maxlineHeight);
  20653. $maxlineHeight = $mba;
  20654. }
  20655. return $maxlineHeight;
  20656. }
  20657. function TableWordWrap($maxwidth, $forcewrap = 0, $textbuffer = '', $def_fontsize, $returnarray=false) { // NB ** returnarray used in flowchart
  20658. $biggestword=0;
  20659. $toonarrow=false;
  20660. $curlyquote = mb_convert_encoding("\xe2\x80\x9e",$this->mb_enc,'UTF-8');
  20661. $curlylowquote = mb_convert_encoding("\xe2\x80\x9d",$this->mb_enc,'UTF-8');
  20662. $textbuffer[0][0] = preg_replace('/^[ ]*/','',$textbuffer[0][0]);
  20663. if ((count($textbuffer) == 0) or ((count($textbuffer) == 1) && ($textbuffer[0][0] == ''))) { return 0; }
  20664. $text = '';
  20665. $lhfixed = false;
  20666. if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight)) { $lhfixed = true; }
  20667. if ($lhfixed) { $def_lineheight = $this->_computeLineheight($this->table_lineheight, $def_fontsize);}
  20668. else { $def_lineheight = 0; }
  20669. // START OF NEW LINE
  20670. // Initialise lineheight variables
  20671. $maxfontsize = 0;
  20672. $forceExactLineheight = true;
  20673. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20674. $maxlineHeight = $def_lineheight ;
  20675. $ch = 0;
  20676. $width = 0;
  20677. $ln = 1; // Counts line number
  20678. $mxw = $this->GetCharWidth('W',false); // mPDF 5.3.04
  20679. foreach ($textbuffer as $cctr=>$chunk) {
  20680. $line = $chunk[0];
  20681. //IMAGE
  20682. if (substr($line,0,3) == "\xbb\xa4\xac") { //identifier has been identified!
  20683. $objattr = $this->_getObjAttr($line);
  20684. if ($objattr['type'] == 'nestedtable') {
  20685. // END OF LINE
  20686. // Finalise & add lineheight
  20687. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20688. $level = $objattr['level'];
  20689. $ih = $this->table[($level+1)][$objattr['nestedcontent']]['h']; // nested table width
  20690. $ch += $ih;
  20691. // START OF NEW LINE
  20692. // Initialise lineheight variables
  20693. $ln++;
  20694. $maxfontsize = 0;
  20695. $forceExactLineheight = true;
  20696. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20697. $maxlineHeight = $def_lineheight ;
  20698. $width = 0;
  20699. $text = "";
  20700. continue;
  20701. }
  20702. list($skipln,$iw,$ih) = $this->inlineObject((isset($specialcontent['type']) ? $specialcontent['type'] : null),0,0, $objattr, $this->lMargin,$width,$maxwidth,$maxlineHeight,false,true);
  20703. if ($objattr['type'] == 'hr') {
  20704. // END OF LINE
  20705. // Finalise & add lineheight
  20706. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20707. // Add HR height
  20708. $ch += $ih;
  20709. // START OF NEW LINE
  20710. // Initialise lineheight variables
  20711. $ln++;
  20712. $maxfontsize = 0;
  20713. $forceExactLineheight = true;
  20714. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20715. $maxlineHeight = $def_lineheight ;
  20716. $width = 0;
  20717. $text = "";
  20718. continue;
  20719. }
  20720. if ($skipln==1 || $skipln==-2) {
  20721. // Finish last line
  20722. // END OF LINE
  20723. // Finalise & add lineheight
  20724. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20725. // START OF NEW LINE
  20726. // Initialise lineheight variables
  20727. $maxfontsize = 0;
  20728. $forceExactLineheight = true;
  20729. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20730. $maxlineHeight = $def_lineheight ;
  20731. $ln++;
  20732. $width = 0;
  20733. $text = "";
  20734. }
  20735. $va = (isset($objattr['vertical-align']) ? $objattr['vertical-align'] : null);
  20736. if ($va) {
  20737. $lhxt[$va] = max($lhxt[$va], $ih);
  20738. }
  20739. if ($lhfixed && $ih > $def_fontsize) { $forceExactLineheight = false; }
  20740. $maxlineHeight = max($maxlineHeight ,$ih);
  20741. $width += $iw;
  20742. continue;
  20743. }
  20744. // SET FONT SIZE/STYLE from $chunk[n]
  20745. // FONTSIZE
  20746. if(isset($chunk[11]) and $chunk[11] != '') {
  20747. if ($this->shrin_k) {
  20748. $this->SetFontSize($chunk[11]/$this->shrin_k,false);
  20749. }
  20750. else {
  20751. $this->SetFontSize($chunk[11],false);
  20752. }
  20753. }
  20754. if ($line == "\n") {
  20755. // END OF LINE
  20756. $maxfontsize = max($maxfontsize,$this->FontSize);
  20757. $fh = $this->_computeLineheight($this->table_lineheight);
  20758. if ($lhfixed && $this->FontSize > $def_fontsize) {
  20759. $fh = $this->FontSize;
  20760. $forceExactLineheight = false;
  20761. }
  20762. $maxlineHeight = max($maxlineHeight,$fh);
  20763. // Finalise & add lineheight
  20764. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20765. // START OF NEW LINE
  20766. // Initialise lineheight variables
  20767. $maxfontsize = 0;
  20768. $forceExactLineheight = true;
  20769. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20770. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  20771. $ln++;
  20772. $text = "";
  20773. $width = 0;
  20774. if(isset($chunk[11]) and $chunk[11] != '') {
  20775. $this->SetFontSize($this->default_font_size,false);
  20776. }
  20777. continue;
  20778. }
  20779. // mPDF 5.3.61
  20780. $lbw = $rbw = 0; // Border widths
  20781. if(isset($chunk[16]) && !empty($chunk[16])) { //Border
  20782. $this->spanborddet = $chunk[16];
  20783. if (isset($this->spanborddet['L'])) $lbw = $this->spanborddet['L']['w']; // mPDF 5.3.76
  20784. if (isset($this->spanborddet['R'])) $rbw = $this->spanborddet['R']['w'];
  20785. }
  20786. if(isset($chunk[15])) { // Word spacing
  20787. $this->wSpacingCSS = $chunk[15];
  20788. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  20789. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  20790. }
  20791. }
  20792. if(isset($chunk[14])) { // Letter spacing
  20793. $this->lSpacingCSS = $chunk[14];
  20794. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') {
  20795. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  20796. }
  20797. }
  20798. if(isset($chunk[13])) { // Font Kerning // mPDF 5.3.99
  20799. $this->kerning = $chunk[13];
  20800. }
  20801. // FONTFAMILY
  20802. if(isset($chunk[4]) and $chunk[4] != '') { $font = $this->SetFont($chunk[4],$this->FontStyle,0,false); }
  20803. // FONT STYLE B I U
  20804. if(isset($chunk[2]) and $chunk[2] != '') {
  20805. $this->SetStyles($chunk[2]);
  20806. }
  20807. $space = $this->GetCharWidth(' ',false); // mPDF 5.3.04
  20808. if (mb_substr($line,0,1,$this->mb_enc ) == ' ') { // line (chunk) starts with a space
  20809. $width += $space;
  20810. $text .= ' ';
  20811. }
  20812. if (mb_substr($line,(mb_strlen($line,$this->mb_enc )-1),1,$this->mb_enc ) == ' ') { $lsend = true; } // line (chunk) ends with a space
  20813. else { $lsend = false; }
  20814. $line= trim($line);
  20815. if ($line == '') { continue; }
  20816. // mPDF ITERATION
  20817. if ($this->iterationCounter) $line = preg_replace('/{iteration ([a-zA-Z0-9_]+)}/','\\1', $line);
  20818. $words = explode(' ', $line);
  20819. foreach ($words as $k=>$word) { // mPDF 5.3.61
  20820. $word = trim($word);
  20821. $wordwidth = $this->GetStringWidth($word);
  20822. // mPDF 5.3.61
  20823. if ($k==0) { $wordwidth += $lbw; }
  20824. if ($k==(count($words)-1)) { $wordwidth += $rbw; }
  20825. //maxwidth is insufficient for one word
  20826. if ($wordwidth > $maxwidth + 0.0001) {
  20827. $firstchunk=true;
  20828. while($wordwidth > $maxwidth + 0.0001) {
  20829. $chw = 0; // check width
  20830. $oneCJKorphan = false;
  20831. $mlen = mb_strlen($word, $this->mb_enc ); // mPDF 5.3.07
  20832. for ( $i = 0; $i < $mlen; $i++ ) { // mPDF 5.3.07
  20833. $chw = $this->GetStringWidth(mb_substr($word,0,$i+1,$this->mb_enc ));
  20834. // mPDF 5.3.61
  20835. if ($k==0) { $chw += $lbw; }
  20836. if ($k==(count($words)-1)) { $chw += $rbw; }
  20837. if ($chw > $maxwidth) {
  20838. if ($i==0 && $firstchunk) {
  20839. // If first letter of line does not fit
  20840. $wordwidth = $maxwidth - 0.0001;
  20841. if ($this->debug) { $this->Error("Table cell width calculated less than that needed for one character!"); }
  20842. break;
  20843. }
  20844. if (!$oneCJKorphan && (preg_match('/[\.\]),;:!?"'.$curlyquote . $curlylowquote.']$/',mb_substr($word,0,$i+1,$this->mb_enc )) || (!$this->usingCoreFont && preg_match('/['.$this->CJKoverflow.']$/u',mb_substr($word,0,$i+1,$this->mb_enc ))))) {
  20845. $wordwidth = $maxwidth - 0.0001;
  20846. $oneCJKorphan = true;
  20847. continue;
  20848. }
  20849. if ($text && $firstchunk) {
  20850. // END OF LINE
  20851. // Finalise & add lineheight
  20852. $maxfontsize = max($maxfontsize,$this->FontSize);
  20853. $fh = $this->_computeLineheight($this->table_lineheight);
  20854. if ($lhfixed && $this->FontSize > $def_fontsize) {
  20855. $fh = $this->FontSize;
  20856. $forceExactLineheight = false;
  20857. }
  20858. $maxlineHeight = max($maxlineHeight,$fh);
  20859. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20860. // START OF NEW LINE
  20861. // Initialise lineheight variables
  20862. $maxfontsize = $this->FontSize;
  20863. $forceExactLineheight = true;
  20864. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20865. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  20866. $ln++;
  20867. }
  20868. // END OF LINE
  20869. // Finalise & add lineheight
  20870. $maxfontsize = max($maxfontsize,$this->FontSize);
  20871. $fh = $this->_computeLineheight($this->table_lineheight);
  20872. if ($lhfixed && $this->FontSize > $def_fontsize) {
  20873. $fh = $this->FontSize;
  20874. $forceExactLineheight = false;
  20875. }
  20876. $maxlineHeight = max($maxlineHeight,$fh);
  20877. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20878. // START OF NEW LINE
  20879. // Initialise lineheight variables
  20880. $maxfontsize = $this->FontSize;
  20881. $forceExactLineheight = true;
  20882. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20883. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  20884. $ln++;
  20885. $mxw = $maxwidth;
  20886. $text = mb_substr($word,0,$i,$this->mb_enc );
  20887. $word = mb_substr($word,$i,mb_strlen($word, $this->mb_enc )-$i,$this->mb_enc );
  20888. $wordwidth = $this->GetStringWidth($word);
  20889. $width = 0;
  20890. $firstchunk=false;
  20891. break;
  20892. }
  20893. }
  20894. if (mb_strlen($word, $this->mb_enc )<2 && $wordwidth > $maxwidth + 0.0001) {
  20895. $wordwidth = $maxwidth - 0.0001;
  20896. if ($this->debug) { $this->Error("Table cell width calculated less than that needed for single character!"); }
  20897. }
  20898. $firstchunk=false;
  20899. }
  20900. }
  20901. // Word fits on line...
  20902. if ($width + $wordwidth < $maxwidth + 0.0001) {
  20903. $mxw = max($mxw, ($width+$wordwidth));
  20904. $width += $wordwidth + $space;
  20905. $text .= $word.' ';
  20906. }
  20907. // Word does not fit on line...
  20908. else {
  20909. $alloworphans = false;
  20910. // In case of orphan punctuation or SUB/SUP
  20911. // Strip end punctuation
  20912. $tmp = preg_replace('/[\.\]),;:!?"'.$curlyquote . $curlylowquote.']{1}$/','',$word);
  20913. if (!$this->usingCoreFont) { $tmp = preg_replace('/['.$this->CJKoverflow.']{1}$/u','',$tmp); } // *CJK-FONTS*
  20914. if ($tmp !== $word && (($this->usingCoreFont && !preg_match('/[\.\]),;:!?"'.$curlyquote . $curlylowquote.']$/',$tmp)) || (!$this->usingCoreFont && !preg_match('/[\.\]),;:!?"'.$curlyquote . $curlylowquote .$this->CJKoverflow.']$/u',$tmp)))) {
  20915. $tmpwidth = $this->GetStringWidth($tmp);
  20916. // mPDF 5.3.61
  20917. if ($k==0) { $tmpwidth += $lbw; }
  20918. if ($k==(count($words)-1)) { $tmpwidth += $rbw; }
  20919. if ($width + $tmpwidth < $maxwidth + 0.0001) { $alloworphans = true; }
  20920. }
  20921. // If line = SUB/SUP to max of orphansallowed ( $this->SUP || $this->SUB )
  20922. if(( (isset($chunk[5]) and $chunk[5]) || (isset($chunk[6]) and $chunk[6])) && strlen($word) <= $this->orphansAllowed) {
  20923. $alloworphans = true;
  20924. }
  20925. // if [stripped] word fits
  20926. if ($alloworphans) {
  20927. $mxw = $maxwidth;
  20928. $width += $wordwidth + $space;
  20929. $text .= $word.' ';
  20930. }
  20931. else {
  20932. /*-- HYPHENATION --*/
  20933. // Soft Hyphens chr(173)
  20934. if ((!$this->usingCoreFont && preg_match("/\xc2\xad/",$word)) || ($this->usingCoreFont && preg_match("/".chr(173)."/",$word) && ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats')) ) {
  20935. list($success,$pre,$post,$prelength) = $this->softHyphenate($word, ($maxwidth - $width));
  20936. if ($success) {
  20937. $text .= $pre.'-';
  20938. $word = $post;
  20939. $wordwidth = $this->GetStringWidth($word);
  20940. // mPDF 5.3.61
  20941. if ($k==(count($words)-1)) { $wordwidth += $rbw; }
  20942. }
  20943. }
  20944. else if ($this->hyphenate || ($this->hyphenateTables)) {
  20945. list($success,$pre,$post,$prelength) = $this->hyphenateWord($word, ($maxwidth - $width));
  20946. if ($success) {
  20947. $text .= $pre.'-';
  20948. $word = $post;
  20949. $wordwidth = $this->GetStringWidth($word);
  20950. // mPDF 5.3.61
  20951. if ($k==(count($words)-1)) { $wordwidth += $rbw; }
  20952. }
  20953. }
  20954. /*-- END HYPHENATION --*/
  20955. // END OF LINE
  20956. // Finalise & add lineheight
  20957. $maxfontsize = max($maxfontsize,$this->FontSize);
  20958. $fh = $this->_computeLineheight($this->table_lineheight);
  20959. if ($lhfixed && $this->FontSize > $def_fontsize) {
  20960. $fh = $this->FontSize;
  20961. $forceExactLineheight = false;
  20962. }
  20963. $maxlineHeight = max($maxlineHeight,$fh);
  20964. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20965. $mxw = $maxwidth;
  20966. // START OF NEW LINE
  20967. // Initialise lineheight variables
  20968. $maxfontsize = $this->FontSize;
  20969. $forceExactLineheight = true;
  20970. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20971. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  20972. $ln++;
  20973. $width = $wordwidth + $space;
  20974. $text = $word.' ';
  20975. }
  20976. }
  20977. $maxfontsize = max($maxfontsize,$this->FontSize);
  20978. $fh = $this->_computeLineheight($this->table_lineheight);
  20979. if ($lhfixed && $this->FontSize > $def_fontsize) {
  20980. $fh = $this->FontSize;
  20981. $forceExactLineheight = false;
  20982. }
  20983. $maxlineHeight = max($maxlineHeight,$fh);
  20984. }
  20985. // End of textbuffer chunk
  20986. if (!$lsend) {
  20987. $width -= $space;
  20988. $text = rtrim($text);
  20989. }
  20990. // RESET FONT SIZE/STYLE
  20991. // RESETTING VALUES
  20992. //Now we must deactivate what we have used
  20993. if(isset($chunk[2]) and $chunk[2] != '') {
  20994. $this->ResetStyles();
  20995. }
  20996. if(isset($chunk[4]) and $chunk[4] != '') {
  20997. $this->SetFont($this->default_font,$this->FontStyle,0,false);
  20998. }
  20999. if(isset($chunk[11]) and $chunk[11] != '') {
  21000. $this->SetFontSize($this->default_font_size,false);
  21001. }
  21002. $this->spanborddet = array(); // mPDF 5.3.61
  21003. $this->kerning = false;
  21004. $this->lSpacingCSS = '';
  21005. $this->wSpacingCSS = '';
  21006. $this->fixedlSpacing = false;
  21007. $this->minwSpacing = 0;
  21008. }
  21009. // Finalise lineheight if something output on line and add
  21010. if ($width) {
  21011. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  21012. }
  21013. if ($returnarray) { return array($ch,$ln,$mxw); }
  21014. else { return $ch; }
  21015. }
  21016. function TableCheckMinWidth($maxwidth, $forcewrap = 0, $textbuffer) { // mPDF 5.3.78
  21017. $biggestword=0;
  21018. $toonarrow=false;
  21019. if ((count($textbuffer) == 0) or ((count($textbuffer) == 1) && ($textbuffer[0][0] == ''))) { return 0; }
  21020. foreach ($textbuffer as $chunk) {
  21021. $line = $chunk[0];
  21022. // mPDF ITERATION
  21023. if ($this->iterationCounter) $line = preg_replace('/{iteration ([a-zA-Z0-9_]+)}/','\\1', $line);
  21024. // IMAGES & FORM ELEMENTS
  21025. if (substr($line,0,3) == "\xbb\xa4\xac") { //inline object - FORM element or IMAGE!
  21026. $objattr = $this->_getObjAttr($line);
  21027. if ($objattr['type']!='hr' && isset($objattr['width']) && ($objattr['width']/$this->shrin_k) > ($maxwidth + 0.0001) ) {
  21028. if (($objattr['width']/$this->shrin_k) > $biggestword) { $biggestword = ($objattr['width']/$this->shrin_k); }
  21029. $toonarrow=true;
  21030. }
  21031. continue;
  21032. }
  21033. if ($line == "\n") {
  21034. continue;
  21035. }
  21036. $line = trim($line );
  21037. // SET FONT SIZE/STYLE from $chunk[n]
  21038. // FONTSIZE
  21039. if(isset($chunk[11]) and $chunk[11] != '') {
  21040. if ($this->shrin_k) {
  21041. $this->SetFontSize($chunk[11]/$this->shrin_k,false);
  21042. }
  21043. else {
  21044. $this->SetFontSize($chunk[11],false);
  21045. }
  21046. }
  21047. // FONTFAMILY
  21048. if(isset($chunk[4]) and $chunk[4] != '') { $font = $this->SetFont($chunk[4],$this->FontStyle,0,false); }
  21049. // B I U
  21050. if(isset($chunk[2]) and $chunk[2] != '') {
  21051. $this->SetStyles($chunk[2]);
  21052. }
  21053. // mPDF 5.3.61
  21054. $lbw = $rbw = 0; // Border widths
  21055. if(isset($chunk[16]) && !empty($chunk[16])) { //Border
  21056. $this->spanborddet = $chunk[16];
  21057. $lbw = $this->spanborddet['L']['w'];
  21058. $rbw = $this->spanborddet['R']['w'];
  21059. }
  21060. if(isset($chunk[15])) { // Word spacing
  21061. $this->wSpacingCSS = $chunk[15];
  21062. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  21063. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  21064. }
  21065. }
  21066. if(isset($chunk[14])) { // Letter spacing
  21067. $this->lSpacingCSS = $chunk[14];
  21068. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') {
  21069. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  21070. }
  21071. }
  21072. if(isset($chunk[13])) { // Font Kerning
  21073. $this->kerning = $chunk[13];
  21074. }
  21075. $words = explode(' ', $line);
  21076. foreach ($words as $k=>$word) { // mPDF 5.3.61
  21077. $word = trim($word);
  21078. $wordwidth = $this->GetStringWidth($word);
  21079. // mPDF 5.3.61
  21080. if ($k==0) { $wordwidth += $lbw; }
  21081. if ($k==(count($words)-1)) { $wordwidth += $rbw; }
  21082. //Warn user that maxwidth is insufficient
  21083. if ($wordwidth > $maxwidth + 0.0001) {
  21084. if ($wordwidth > $biggestword) { $biggestword = $wordwidth; }
  21085. $toonarrow=true;
  21086. }
  21087. }
  21088. // RESET FONT SIZE/STYLE
  21089. // RESETTING VALUES
  21090. //Now we must deactivate what we have used
  21091. if(isset($chunk[2]) and $chunk[2] != '') {
  21092. $this->ResetStyles();
  21093. }
  21094. if(isset($chunk[4]) and $chunk[4] != '') {
  21095. $this->SetFont($this->default_font,$this->FontStyle,0,false);
  21096. }
  21097. if(isset($chunk[11]) and $chunk[11] != '') {
  21098. $this->SetFontSize($this->default_font_size,false);
  21099. }
  21100. // mPDF 5.3.61
  21101. $this->spanborddet = array();
  21102. $this->kerning = false;
  21103. $this->lSpacingCSS = '';
  21104. $this->wSpacingCSS = '';
  21105. $this->fixedlSpacing = false;
  21106. $this->minwSpacing = 0;
  21107. }
  21108. //Return -(wordsize) if word is bigger than maxwidth
  21109. // ADDED
  21110. if (($toonarrow) && ($this->table_error_report)) {
  21111. $this->Error("Word is too long to fit in table - ".$this->table_error_report_param);
  21112. }
  21113. if ($toonarrow) return -$biggestword;
  21114. else return 1;
  21115. }
  21116. function shrinkTable(&$table,$k) {
  21117. $table['border_spacing_H'] /= $k;
  21118. $table['border_spacing_V'] /= $k;
  21119. $table['padding']['T'] /= $k;
  21120. $table['padding']['R'] /= $k;
  21121. $table['padding']['B'] /= $k;
  21122. $table['padding']['L'] /= $k;
  21123. $table['margin']['T'] /= $k;
  21124. $table['margin']['R'] /= $k;
  21125. $table['margin']['B'] /= $k;
  21126. $table['margin']['L'] /= $k;
  21127. $table['border_details']['T']['w'] /= $k;
  21128. $table['border_details']['R']['w'] /= $k;
  21129. $table['border_details']['B']['w'] /= $k;
  21130. $table['border_details']['L']['w'] /= $k;
  21131. if (isset($table['max_cell_border_width']['T'])) $table['max_cell_border_width']['T'] /= $k;
  21132. if (isset($table['max_cell_border_width']['R'])) $table['max_cell_border_width']['R'] /= $k;
  21133. if (isset($table['max_cell_border_width']['B'])) $table['max_cell_border_width']['B'] /= $k;
  21134. if (isset($table['max_cell_border_width']['L'])) $table['max_cell_border_width']['L'] /= $k;
  21135. if ($this->simpleTables){
  21136. $table['simple']['border_details']['T']['w'] /= $k;
  21137. $table['simple']['border_details']['R']['w'] /= $k;
  21138. $table['simple']['border_details']['B']['w'] /= $k;
  21139. $table['simple']['border_details']['L']['w'] /= $k;
  21140. }
  21141. $table['miw'] /= $k;
  21142. $table['maw'] /= $k;
  21143. // mPDF 5.3.79
  21144. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  21145. for($j = 0 ; $j < $table['nc'] ; $j++ ) { //columns
  21146. $table['wc'][$j]['miw'] /= $k;
  21147. $table['wc'][$j]['maw'] /= $k;
  21148. if (isset($table['wc'][$j]['absmiw']) && $table['wc'][$j]['absmiw'] ) $table['wc'][$j]['absmiw'] /= $k;
  21149. for($i = 0 ; $i < $table['nr']; $i++ ) { //rows
  21150. // mPDF 5.3.79
  21151. if ($this->cacheTables) {
  21152. $c = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  21153. }
  21154. else
  21155. $c = &$table['cells'][$i][$j];
  21156. if (isset($c) && $c) {
  21157. if (!$this->simpleTables){
  21158. if ($this->packTableData) {
  21159. $cell = $this->_unpackCellBorder($c['borderbin'] );
  21160. $cell['border_details']['T']['w'] /= $k;
  21161. $cell['border_details']['R']['w'] /= $k;
  21162. $cell['border_details']['B']['w'] /= $k;
  21163. $cell['border_details']['L']['w'] /= $k;
  21164. $cell['border_details']['mbw']['TL'] /= $k;
  21165. $cell['border_details']['mbw']['TR'] /= $k;
  21166. $cell['border_details']['mbw']['BL'] /= $k;
  21167. $cell['border_details']['mbw']['BR'] /= $k;
  21168. $cell['border_details']['mbw']['LT'] /= $k;
  21169. $cell['border_details']['mbw']['LB'] /= $k;
  21170. $cell['border_details']['mbw']['RT'] /= $k;
  21171. $cell['border_details']['mbw']['RB'] /= $k;
  21172. $c['borderbin'] = $this->_packCellBorder($cell);
  21173. }
  21174. else {
  21175. $c['border_details']['T']['w'] /= $k;
  21176. $c['border_details']['R']['w'] /= $k;
  21177. $c['border_details']['B']['w'] /= $k;
  21178. $c['border_details']['L']['w'] /= $k;
  21179. $c['border_details']['mbw']['TL'] /= $k;
  21180. $c['border_details']['mbw']['TR'] /= $k;
  21181. $c['border_details']['mbw']['BL'] /= $k;
  21182. $c['border_details']['mbw']['BR'] /= $k;
  21183. $c['border_details']['mbw']['LT'] /= $k;
  21184. $c['border_details']['mbw']['LB'] /= $k;
  21185. $c['border_details']['mbw']['RT'] /= $k;
  21186. $c['border_details']['mbw']['RB'] /= $k;
  21187. }
  21188. }
  21189. $c['padding']['T'] /= $k;
  21190. $c['padding']['R'] /= $k;
  21191. $c['padding']['B'] /= $k;
  21192. $c['padding']['L'] /= $k;
  21193. $c['maxs'] /= $k;
  21194. if (isset($c['w'])) { $c['w'] /= $k; }
  21195. $c['s'] /= $k;
  21196. $c['maw'] /= $k;
  21197. $c['miw'] /= $k;
  21198. if (isset($c['absmiw'])) $c['absmiw'] /= $k;
  21199. if (isset($c['nestedmaw'])) $c['nestedmaw'] /= $k;
  21200. if (isset($c['nestedmiw'])) $c['nestedmiw'] /= $k;
  21201. // mPDF 5.3.61
  21202. if (isset($c['textbuffer'])) {
  21203. foreach($c['textbuffer'] AS $n=>$tb) {
  21204. if (!empty($tb[16])) {
  21205. $c['textbuffer'][$n][16]['T']['w'] /= $k;
  21206. $c['textbuffer'][$n][16]['B']['w'] /= $k;
  21207. $c['textbuffer'][$n][16]['L']['w'] /= $k;
  21208. $c['textbuffer'][$n][16]['R']['w'] /= $k;
  21209. }
  21210. }
  21211. }
  21212. // mPDF 5.3.79
  21213. if ($this->cacheTables) {
  21214. $this->_cacheCell($c, '', "W", $fh, $table['cells'][$i][$j]);
  21215. }
  21216. unset($c); // mPDF 5.3.79
  21217. }
  21218. }//rows
  21219. }//columns
  21220. // mPDF 5.3.79
  21221. if ($this->cacheTables) { fclose($fh); }
  21222. }
  21223. // mPDF 5.3.79
  21224. function _cacheCell($c, $file, $mode="A", $fh=null, $offset=0) { // mode = Append or (over)Write (needs offset and fh)
  21225. // Requires either $file OR $fh (file_handle)
  21226. if (!is_array($c) || !isset($c)) { return ''; }
  21227. if(isset($c['w'])) { $cw = $c['w']; } else { $cw = -1; }
  21228. if(isset($c['w0'])) { $cw0 = $c['w0']; } else { $cw0 = -1; }
  21229. if(isset($c['h0'])) { $ch0 = $c['h0']; } else { $ch0 = -1; }
  21230. $data = pack("n2d19A1A1n2sA32A128",
  21231. $c['colspan'], /* n (16 bit; 2 bytes) [pos 0] */
  21232. $c['rowspan'], /* n (16 bit; 2 bytes) [pos 2] */
  21233. $c['s'], /* d NB machine-dependent size (64 bit; 8 bytes on test winOS) [pos 4] */
  21234. $c['maxs'], /* d NB machine-dependent size [pos 4 + 1*D] */
  21235. $c['nestedmaw'], /* d NB machine-dependent size [pos 4 + 2*D] */
  21236. $c['nestedmiw'], /* d NB machine-dependent size [pos 4 + 3*D] */
  21237. $c['padding']['L'], /* d NB machine-dependent size [pos 4 + 4*D] */
  21238. $c['padding']['R'], /* d NB machine-dependent size [pos 4 + 5*D] */
  21239. $c['padding']['T'], /* d NB machine-dependent size [pos 4 + 6*D] */
  21240. $c['padding']['B'], /* d NB machine-dependent size [pos 4 + 7*D] */
  21241. $c['dfs'], /* d NB machine-dependent size [pos 4 + 8*D] */
  21242. $cw, /* d NB machine-dependent size [pos 4 + 9*D] */
  21243. $c['h'], /* d NB machine-dependent size [pos 4 + 10*D] */
  21244. $c['absmiw'], /* d NB machine-dependent size [pos 4 + 11*D] */
  21245. $c['maw'], /* d NB machine-dependent size [pos 4 + 12*D] */
  21246. $c['miw'], /* d NB machine-dependent size [pos 4 + 13*D] */
  21247. $c['mih'], /* d NB machine-dependent size [pos 4 + 14*D] */
  21248. $c['x0'], /* d NB machine-dependent size [pos 4 + 15*D] */
  21249. $cw0, /* d NB machine-dependent size [pos 4 + 16*D] */
  21250. $c['y0'], /* d NB machine-dependent size [pos 4 + 17*D] */
  21251. $ch0, /* d NB machine-dependent size [pos 4 + 18*D] */
  21252. $c['a'], /* A1 (1 byte) [pos 4 + 19*D] */
  21253. $c['va'], /* A1 (1 byte) [pos 5 + 19*D] */
  21254. $c['nowrap'], /* 1 or blank n (16 bit; 2 bytes) [pos 6 + 19*D] */
  21255. $c['wpercent'], /* 0 - 100 n (16 bit; 2 bytes) [pos 8 + 19*D] */
  21256. $c['R'], /* 90 or -90 s (16 bit; 2 bytes) [pos 10 + 19*D] */
  21257. $c['bgcolor'], /* A32 (32 bytes) [pos 12 + 19*D] */
  21258. $c['gradient'] /* A128 (128 bytes) [pos 44 + 19*D] */
  21259. );
  21260. if ($c['background-image']) {
  21261. $data .= pack("n2d2A6A6n3dA4A128",
  21262. strlen($data), /* offset in main data to start of bgimage data */
  21263. $c['background-image']['image_id'], /* n */
  21264. $c['background-image']['orig_w'], /* d NB machine-dependent size */
  21265. $c['background-image']['orig_h'], /* d NB machine-dependent size */
  21266. $c['background-image']['x_pos'], /* A6 calc size or "50%" */
  21267. $c['background-image']['y_pos'], /* A6 calc size or "50%" */
  21268. $c['background-image']['x_repeat'], /* n true or false*/
  21269. $c['background-image']['y_repeat'], /* n true or false */
  21270. $c['background-image']['resize'], /* n 0 - 6 */
  21271. $c['background-image']['opacity'], /* d 0-1 */
  21272. $c['background-image']['itype'], /* A4 jpg etc */
  21273. $c['background-image']['gradient'] /* A128 CSS string */
  21274. );
  21275. }
  21276. else $data .= pack("n",0);
  21277. $tb_offset = 2 + 186 + 2 + strlen($data);
  21278. $stb = serialize($c['textbuffer']).' '; // buffer to allow updating in reverseTableDir
  21279. $lentb = strlen($stb);
  21280. $data2 = pack("nA".$lentb, $lentb, $stb);
  21281. $tempfh = true;
  21282. if ($mode=="W" && $offset) {
  21283. if (!$fh) { $fh = fopen($file, "r+b"); } // Overwrite (but not truncate)
  21284. else $tempfh = false;
  21285. fseek($fh, $offset);
  21286. }
  21287. else {
  21288. $fh = fopen($file, "ab"); // APPEND
  21289. }
  21290. fwrite($fh, pack("n",$tb_offset)); // Offset to Text buffer 2 bytes
  21291. fwrite($fh, $c['borderbin']); // border details 186 bytes
  21292. fwrite($fh, pack("n",strlen($data))); // Length of Main data
  21293. fwrite($fh, $data); // Main data
  21294. fwrite($fh, $data2); // Text buffer (starts with "n" length of text buffer)
  21295. if ($tempfh) fclose($fh);
  21296. return ($tb_offset + 2 + $lentb);
  21297. }
  21298. // mPDF 5.3.79
  21299. function _cacheUpdateTxB($c, $fh, $offset) {
  21300. fseek($fh, $offset);
  21301. $tb_offset = $this->read_short($fh); // First entry = Offset to Text buffer 2 bytes
  21302. fseek($fh, ($tb_offset-2), SEEK_CUR);
  21303. $lentb = $this->read_short($fh); // First entry in textbuffer = Length of serialized textbuffer - do not update
  21304. $stb = serialize($c['textbuffer']);
  21305. fwrite($fh, pack("A".$lentb, $stb));
  21306. }
  21307. // mPDF 5.3.79
  21308. function _cacheUpdateBorder($c, $fh, $offset) {
  21309. $offset += 2;
  21310. fseek($fh, $offset);
  21311. fwrite($fh, $c['borderbin']);
  21312. }
  21313. // mPDF 5.3.79
  21314. function _cacheUpdateMtx($c, $fh, $offset, $var) {
  21315. if ($var=='mih') { $offset += (2 + 186 + 2 + 4 + 14*_DSIZE); }
  21316. else if ($var=='x0') { $offset += (2 + 186 + 2 + 4 + 15*_DSIZE); } // x0 and w0
  21317. else if ($var=='y0') { $offset += (2 + 186 + 2 + 4 + 17*_DSIZE); } // y0 and h0
  21318. fseek($fh, $offset);
  21319. if ($var=='mih') { fwrite($fh, pack("d",$c['mih'])); }
  21320. else if ($var=='x0') { fwrite($fh, pack("d2",$c['x0'],$c['w0'])); }
  21321. else if ($var=='y0') { fwrite($fh, pack("d2",$c['y0'],$c['h0'])); }
  21322. }
  21323. // mPDF 5.3.79
  21324. function _uncacheCell($ptr, $file, $fh) {
  21325. // Requires either $file or $fh (file_handle)
  21326. if ($ptr==0) { return null; }
  21327. if (is_array($ptr)) { $this->Error("Probable cause - missing end tag &lt;/td&gt;. You may be able to change the configurable variable: allow_html_optional_endtags "); }
  21328. $tempfh = true;
  21329. if (!$fh) { $fh = fopen($file, "rb"); }
  21330. else $tempfh = false;
  21331. fseek($fh, $ptr);
  21332. $c = array();
  21333. $tb_offset = $this->read_short($fh); // First entry = Offset to Text buffer 2 bytes
  21334. $c['borderbin'] = fread($fh,186); // border details 186 bytes
  21335. $maindatalen = $this->read_short($fh); // Length of Main data (2 bytes)
  21336. $str = fread($fh,$maindatalen ); // Main data
  21337. $data = unpack("ncolspan/nrowspan/ds/dmaxs/dnmaw/dnmiw/dpl/dpr/dpt/dpb/ddfs/dw/dh/dabsmiw/dmaw/dmiw/dmih/dx0/dw0/dy0/dh0/A1a/A1va/nnowrap/nwpercent/sR/A32bgcol/A128grad/nbgimage", $str);
  21338. if ($data['colspan']>0) $c['colspan'] = $data['colspan']; /* n */
  21339. if ($data['rowspan']>0) $c['rowspan'] = $data['rowspan']; /* n */
  21340. $c['s'] = $data['s']; /* d NB machine-dependent size */
  21341. $c['maxs'] = $data['maxs']; /* d NB machine-dependent size */
  21342. if ($data['nmaw']>0) $c['nestedmaw'] = $data['nmaw']; /* d NB machine-dependent size */
  21343. if ($data['nmiw']>0) $c['nestedmiw'] = $data['nmiw']; /* d NB machine-dependent size */
  21344. $c['padding']['L'] = $data['pl']; /* d NB machine-dependent size */
  21345. $c['padding']['R'] = $data['pr']; /* d NB machine-dependent size */
  21346. $c['padding']['T'] = $data['pt']; /* d NB machine-dependent size */
  21347. $c['padding']['B'] = $data['pb']; /* d NB machine-dependent size */
  21348. $c['dfs'] = $data['dfs']; /* d NB machine-dependent size */
  21349. if ($data['w']>=0) $c['w'] = $data['w']; /* d NB machine-dependent size */
  21350. if ($data['h']>0) $c['h'] = $data['h']; /* d NB machine-dependent size */
  21351. if ($data['absmiw']>0) $c['absmiw'] = $data['absmiw']; /* d NB machine-dependent size */
  21352. if ($data['maw']>0) $c['maw'] = $data['maw']; /* d NB machine-dependent size */
  21353. if ($data['miw']>0) $c['miw'] = $data['miw']; /* d NB machine-dependent size */
  21354. if ($data['mih']>0) $c['mih'] = $data['mih']; /* d NB machine-dependent size */
  21355. if ($data['w0']>=0) { $c['w0'] = $data['w0']; /* d NB machine-dependent size */
  21356. $c['x0'] = $data['x0']; } /* d NB machine-dependent size */
  21357. if ($data['h0']>=0) { $c['h0'] = $data['h0']; /* d NB machine-dependent size */
  21358. $c['y0'] = $data['y0']; } /* d NB machine-dependent size */
  21359. $c['a'] = trim($data['a']); /* A1 */
  21360. $c['va'] = trim($data['va']); /* A1 */
  21361. if ($data['nowrap']) $c['nowrap'] = $data['nowrap']; /* 1 or blank n */
  21362. else $c['nowrap'] = false;
  21363. if ($data['wpercent']>0) $c['wpercent'] = $data['wpercent']; /* 0 - 100 n */
  21364. if ($data['R']<>0) $c['R'] = $data['R']; /* 90 or -90 s */
  21365. else $c['R'] = false;
  21366. $c['bgcolor'] = trim($data['bgcol']); /* A32 */
  21367. if (trim($data['grad']))
  21368. $c['gradient'] = trim($data['grad']); /* A128 */
  21369. else $c['gradient'] = false;
  21370. if ($data['bgimage']>0) {
  21371. $bgidata = substr($str, ($data['bgimage']+2));
  21372. $c['background-image'] = unpack("nimage_id/dorig_w/dorig_h/A6x_pos/A6y_pos/nx_repeat/ny_repeat/nresize/dopacity/A4itype/A128gradient", $bgidata);
  21373. }
  21374. $tblen = $this->read_short($fh); // Length of Textbuffer
  21375. $tbsp = fread($fh,$tblen); // Textbuffer (serialised and packed)
  21376. $tbs = unpack("A".$tblen."textbuffer",$tbsp); // Textbuffer unpacked
  21377. $c['textbuffer'] = unserialize(trim($tbs['textbuffer'])); // Textbuffer unserialized
  21378. if ($tempfh) { fclose($fh); }
  21379. return ($c);
  21380. }
  21381. // mPDF 5.3.79
  21382. function read_short(&$fh) {
  21383. $s = fread($fh,2);
  21384. $a = (ord($s[0])<<8) + ord($s[1]);
  21385. if ($a & (1 << 15) ) {
  21386. $a = ($a - (1 << 16));
  21387. }
  21388. return $a;
  21389. }
  21390. // mPDF 5.3.79
  21391. function _backupCacheFiles() {
  21392. foreach($this->table AS $lvl=>$t) {
  21393. foreach($this->table[$lvl] AS $c=>$t2) {
  21394. ///////////////////////////if (!file_exists($t2['cache'])) { echo $lvl; echo $c; print_r($this->table); exit; }
  21395. copy( $t2['cache'], $t2['cache'].'.bak');
  21396. }
  21397. }
  21398. }
  21399. // mPDF 5.3.79
  21400. function _restoreCacheFiles() {
  21401. foreach($this->table AS $lvl=>$t) {
  21402. foreach($this->table[$lvl] AS $c=>$t2) {
  21403. copy( $t2['cache'].'.bak', $t2['cache']);
  21404. }
  21405. }
  21406. }
  21407. function _packCellBorder($cell) {
  21408. if (!is_array($cell) || !isset($cell)) { return ''; }
  21409. if (!$this->packTableData) { return $cell; }
  21410. // mPDF 5.3.74
  21411. // = 186 bytes
  21412. $bindata = pack("nnda6A10nnda6A10nnda6A10nnda6A10nd9",
  21413. $cell['border'],
  21414. $cell['border_details']['R']['s'],
  21415. $cell['border_details']['R']['w'],
  21416. $cell['border_details']['R']['c'],
  21417. $cell['border_details']['R']['style'],
  21418. $cell['border_details']['R']['dom'],
  21419. $cell['border_details']['L']['s'],
  21420. $cell['border_details']['L']['w'],
  21421. $cell['border_details']['L']['c'],
  21422. $cell['border_details']['L']['style'],
  21423. $cell['border_details']['L']['dom'],
  21424. $cell['border_details']['T']['s'],
  21425. $cell['border_details']['T']['w'],
  21426. $cell['border_details']['T']['c'],
  21427. $cell['border_details']['T']['style'],
  21428. $cell['border_details']['T']['dom'],
  21429. $cell['border_details']['B']['s'],
  21430. $cell['border_details']['B']['w'],
  21431. $cell['border_details']['B']['c'],
  21432. $cell['border_details']['B']['style'],
  21433. $cell['border_details']['B']['dom'],
  21434. $cell['border_details']['mbw']['BL'],
  21435. $cell['border_details']['mbw']['BR'],
  21436. $cell['border_details']['mbw']['RT'],
  21437. $cell['border_details']['mbw']['RB'],
  21438. $cell['border_details']['mbw']['TL'],
  21439. $cell['border_details']['mbw']['TR'],
  21440. $cell['border_details']['mbw']['LT'],
  21441. $cell['border_details']['mbw']['LB'],
  21442. $cell['border_details']['cellposdom']
  21443. );
  21444. return $bindata;
  21445. }
  21446. function _getBorderWidths($bindata) {
  21447. if (!$bindata) { return array(0,0,0,0); }
  21448. if (!$this->packTableData) { return array($bindata['border_details']['T']['w'], $bindata['border_details']['R']['w'], $bindata['border_details']['B']['w'], $bindata['border_details']['L']['w']); }
  21449. // mPDF 5.3.74
  21450. $bd = unpack("nbord/nrs/drw/a6rca/A10rst/nrd/nls/dlw/a6lca/A10lst/nld/nts/dtw/a6tca/A10tst/ntd/nbs/dbw/a6bca/A10bst/nbd/dmbl/dmbr/dmrt/dmrb/dmtl/dmtr/dmlt/dmlb/dcpd", $bindata);
  21451. $cell['border_details']['R']['w'] = $bd['rw'];
  21452. $cell['border_details']['L']['w'] = $bd['lw'];
  21453. $cell['border_details']['T']['w'] = $bd['tw'];
  21454. $cell['border_details']['B']['w'] = $bd['bw'];
  21455. return array($bd['tw'], $bd['rw'], $bd['bw'], $bd['lw']);
  21456. }
  21457. function _unpackCellBorder($bindata) {
  21458. if (!$bindata) { return array(); }
  21459. if (!$this->packTableData) { return $bindata; }
  21460. // mPDF 5.3.74
  21461. $bd = unpack("nbord/nrs/drw/a6rca/A10rst/nrd/nls/dlw/a6lca/A10lst/nld/nts/dtw/a6tca/A10tst/ntd/nbs/dbw/a6bca/A10bst/nbd/dmbl/dmbr/dmrt/dmrb/dmtl/dmtr/dmlt/dmlb/dcpd", $bindata);
  21462. $cell['border'] = $bd['bord'];
  21463. $cell['border_details']['R']['s'] = $bd['rs'];
  21464. $cell['border_details']['R']['w'] = $bd['rw'];
  21465. $cell['border_details']['R']['c'] = $bd['rca'];
  21466. $cell['border_details']['R']['style'] = trim($bd['rst']);
  21467. $cell['border_details']['R']['dom'] = $bd['rd'];
  21468. $cell['border_details']['L']['s'] = $bd['ls'];
  21469. $cell['border_details']['L']['w'] = $bd['lw'];
  21470. $cell['border_details']['L']['c'] = $bd['lca'];
  21471. $cell['border_details']['L']['style'] = trim($bd['lst']);
  21472. $cell['border_details']['L']['dom'] = $bd['ld'];
  21473. $cell['border_details']['T']['s'] = $bd['ts'];
  21474. $cell['border_details']['T']['w'] = $bd['tw'];
  21475. $cell['border_details']['T']['c'] = $bd['tca'];
  21476. $cell['border_details']['T']['style'] = trim($bd['tst']);
  21477. $cell['border_details']['T']['dom'] = $bd['td'];
  21478. $cell['border_details']['B']['s'] = $bd['bs'];
  21479. $cell['border_details']['B']['w'] = $bd['bw'];
  21480. $cell['border_details']['B']['c'] = $bd['bca'];
  21481. $cell['border_details']['B']['style'] = trim($bd['bst']);
  21482. $cell['border_details']['B']['dom'] = $bd['bd'];
  21483. $cell['border_details']['mbw']['BL'] = $bd['mbl'];
  21484. $cell['border_details']['mbw']['BR'] = $bd['mbr'];
  21485. $cell['border_details']['mbw']['RT'] = $bd['mrt'];
  21486. $cell['border_details']['mbw']['RB'] = $bd['mrb'];
  21487. $cell['border_details']['mbw']['TL'] = $bd['mtl'];
  21488. $cell['border_details']['mbw']['TR'] = $bd['mtr'];
  21489. $cell['border_details']['mbw']['LT'] = $bd['mlt'];
  21490. $cell['border_details']['mbw']['LB'] = $bd['mlb'];
  21491. $cell['border_details']['cellposdom'] = $bd['cpd'];
  21492. return($cell);
  21493. }
  21494. ////////////////////////TABLE CODE (from PDFTable)/////////////////////////////////////
  21495. ////////////////////////TABLE CODE (from PDFTable)/////////////////////////////////////
  21496. ////////////////////////TABLE CODE (from PDFTable)/////////////////////////////////////
  21497. //table Array of (w, h, bc, nr, wc, hr, cells)
  21498. //w Width of table
  21499. //h Height of table
  21500. //nc Number column
  21501. //nr Number row
  21502. //hr List of height of each row
  21503. //wc List of width of each column
  21504. //cells List of cells of each rows, cells[i][j] is a cell in the table
  21505. function _tableColumnWidth(&$table,$firstpass=false){
  21506. $cs = &$table['cells'];
  21507. $nc = $table['nc'];
  21508. $nr = $table['nr'];
  21509. $listspan = array();
  21510. if ($table['borders_separate']) {
  21511. $tblbw = $table['border_details']['L']['w'] + $table['border_details']['R']['w'] + $table['margin']['L'] + $table['margin']['R'] + $table['padding']['L'] + $table['padding']['R'] + $table['border_spacing_H'];
  21512. }
  21513. else { $tblbw = $table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2 + $table['margin']['L'] + $table['margin']['R']; }
  21514. // mPDF 5.3.79
  21515. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  21516. else { $fh = null; }
  21517. // ADDED table['l'][colno]
  21518. // = total length of text approx (using $c['s']) in that column - used to approximately distribute col widths in _tableWidth
  21519. //
  21520. for($j = 0 ; $j < $nc ; $j++ ) { //columns
  21521. $wc = &$table['wc'][$j];
  21522. for($i = 0 ; $i < $nr ; $i++ ) { //rows
  21523. if (isset($cs[$i][$j]) && $cs[$i][$j]) {
  21524. // mPDF 5.3.79
  21525. if ($this->cacheTables) {
  21526. $c = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  21527. }
  21528. else
  21529. $c = &$cs[$i][$j];
  21530. if ($this->simpleTables){
  21531. if ($table['borders_separate']) { // NB twice border width
  21532. $extrcw = $table['simple']['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'] + $c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H'];
  21533. }
  21534. else {
  21535. $extrcw = $table['simple']['border_details']['L']['w']/2 + $table['simple']['border_details']['R']['w']/2 + $c['padding']['L'] + $c['padding']['R'];
  21536. }
  21537. }
  21538. else {
  21539. if ($this->packTableData) {
  21540. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  21541. }
  21542. else {
  21543. $br = $c['border_details']['R']['w'];
  21544. $bl = $c['border_details']['L']['w'];
  21545. }
  21546. if ($table['borders_separate']) { // NB twice border width
  21547. $extrcw = $bl + $br + $c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H'];
  21548. }
  21549. else {
  21550. $extrcw = $bl/2 + $br/2 + $c['padding']['L'] + $c['padding']['R'];
  21551. }
  21552. }
  21553. //$mw = $this->GetStringWidth('W') + $extrcw ;
  21554. $mw = 0;
  21555. $c['absmiw'] = $mw;
  21556. if (isset($c['R']) && $c['R']) {
  21557. $c['maw'] = $c['miw'] = $this->FontSize + $extrcw ;
  21558. if (isset($c['w'])) { // If cell width is specified
  21559. if ($c['miw'] <$c['w']) { $c['miw'] = $c['w']; }
  21560. }
  21561. if (!isset($c['colspan'])) {
  21562. if ($wc['miw'] < $c['miw']) { $wc['miw'] = $c['miw']; }
  21563. if ($wc['maw'] < $c['maw']) { $wc['maw'] = $c['maw']; }
  21564. if ($firstpass) {
  21565. if (isset($table['l'][$j]) ) {
  21566. $table['l'][$j] += $c['miw'] ;
  21567. }
  21568. else {
  21569. $table['l'][$j] = $c['miw'] ;
  21570. }
  21571. }
  21572. }
  21573. if ($c['miw'] > $wc['miw']) { $wc['miw'] = $c['miw']; }
  21574. if ($wc['miw'] > $wc['maw']) { $wc['maw'] = $wc['miw']; }
  21575. continue;
  21576. }
  21577. if ($firstpass) {
  21578. if (isset($c['s'])) { $c['s'] += $extrcw; }
  21579. if (isset($c['maxs'])) { $c['maxs'] += $extrcw; }
  21580. if (isset($c['nestedmiw'])) { $c['nestedmiw'] += $extrcw; }
  21581. if (isset($c['nestedmaw'])) { $c['nestedmaw'] += $extrcw; }
  21582. }
  21583. // If minimum width has already been set by a nested table or inline object (image/form), use it
  21584. if (isset($c['nestedmiw']) && $this->table[1][1]['overflow']!='visible') { $miw = $c['nestedmiw']; } // mPDF 5.3.36
  21585. else { $miw = $mw; }
  21586. if (isset($c['maxs']) && $c['maxs'] != '') { $c['s'] = $c['maxs']; }
  21587. // If maximum width has already been set by a nested table, use it
  21588. if (isset($c['nestedmaw'])) { $c['maw'] = $c['nestedmaw']; }
  21589. else $c['maw'] = $c['s'];
  21590. // mPDF 5.3.36
  21591. if (isset($table['overflow']) && $table['overflow']=='visible' && $table['level']==1) {
  21592. if (($c['maw'] + $tblbw) > $this->blk[$this->blklvl]['inner_width']) {
  21593. $c['maw'] = $this->blk[$this->blklvl]['inner_width'] - $tblbw;
  21594. }
  21595. }
  21596. if (isset($c['nowrap']) && $c['nowrap']) { $miw = $c['maw']; }
  21597. if (isset($c['wpercent']) && $firstpass) {
  21598. if (isset($c['colspan'])) { // Not perfect - but % set on colspan is shared equally on cols.
  21599. for($k=0;$k<$c['colspan'];$k++) {
  21600. $table['wc'][($j+$k)]['wpercent'] = $c['wpercent'] / $c['colspan'];
  21601. }
  21602. }
  21603. else {
  21604. if (isset($table['w']) && $table['w']) { $c['w'] = $c['wpercent']/100 * ($table['w'] - $tblbw ); }
  21605. $wc['wpercent'] = $c['wpercent'];
  21606. }
  21607. }
  21608. // mPDF 5.3.36
  21609. if (isset($table['overflow']) && $table['overflow']=='visible' && $table['level']==1) {
  21610. if (($c['w'] + $tblbw) > $this->blk[$this->blklvl]['inner_width']) {
  21611. $c['w'] = $this->blk[$this->blklvl]['inner_width'] - $tblbw;
  21612. }
  21613. }
  21614. if (isset($c['w'])) { // If cell width is specified
  21615. if ($miw<$c['w']) { $c['miw'] = $c['w']; } // Cell min width = that specified
  21616. if ($miw>$c['w']) { $c['miw'] = $c['w'] = $miw; } // If width specified is less than minimum allowed (W) increase it
  21617. if (!isset($wc['w'])) { $wc['w'] = 1; } // If the Col width is not specified = set it to 1
  21618. }
  21619. else { $c['miw'] = $miw; } // If cell width not specified -> set Cell min width it to minimum allowed (W)
  21620. if ($c['maw'] < $c['miw']) { $c['maw'] = $c['miw']; } // If Cell max width < Minwidth - increase it to =
  21621. if (!isset($c['colspan'])) {
  21622. if ($wc['miw'] < $c['miw']) { $wc['miw'] = $c['miw']; } // Update Col Minimum and maximum widths
  21623. if ($wc['maw'] < $c['maw']) { $wc['maw'] = $c['maw']; }
  21624. if ((isset($wc['absmiw']) && $wc['absmiw'] < $c['absmiw']) || !isset($wc['absmiw'])) { $wc['absmiw'] = $c['absmiw']; } // Update Col Minimum and maximum widths
  21625. if (isset($table['l'][$j]) ) {
  21626. $table['l'][$j] += $c['s'];
  21627. }
  21628. else {
  21629. $table['l'][$j] = $c['s'];
  21630. }
  21631. }
  21632. else {
  21633. $listspan[] = array($i,$j);
  21634. }
  21635. //Check if minimum width of the whole column is big enough for largest word to fit
  21636. if (isset($c['textbuffer']) && !$this->tableCJK && (!isset($table['overflow']) || $table['overflow']!='wrap')) { // mPDF 5.3.50
  21637. $minwidth = $this->TableCheckMinWidth($wc['miw']- $extrcw ,0,$c['textbuffer']); // mPDF 5.3.78
  21638. }
  21639. else { $minwidth = 0; }
  21640. if ($minwidth < 0) {
  21641. //increase minimum width
  21642. if (!isset($c['colspan'])) {
  21643. $wc['miw'] = max($wc['miw'],((-$minwidth) + $extrcw) );
  21644. }
  21645. else {
  21646. $c['miw'] = max($c['miw'],((-$minwidth) + $extrcw) );
  21647. }
  21648. }
  21649. if (!isset($c['colspan'])) {
  21650. if ($wc['miw'] > $wc['maw']) { $wc['maw'] = $wc['miw']; } //update maximum width, if needed
  21651. }
  21652. // mPDF 5.3.79
  21653. if ($this->cacheTables) {
  21654. $this->_cacheCell($c, '', "W", $fh, $table['cells'][$i][$j]);
  21655. }
  21656. }
  21657. unset($c);
  21658. }//rows
  21659. }//columns
  21660. // COLUMN SPANS
  21661. $wc = &$table['wc'];
  21662. foreach ($listspan as $span) {
  21663. list($i,$j) = $span;
  21664. // mPDF 5.3.79
  21665. if ($this->cacheTables) {
  21666. $c = $this->_uncacheCell($cs[$i][$j], '', $fh);
  21667. }
  21668. else
  21669. $c = &$cs[$i][$j];
  21670. $lc = $j + $c['colspan'];
  21671. if ($lc > $nc) { $lc = $nc; }
  21672. $wis = $wisa = 0;
  21673. $was = $wasa = 0;
  21674. $list = array();
  21675. for($k=$j;$k<$lc;$k++) {
  21676. if (isset($table['l'][$k]) ) {
  21677. if ($c['R']) { $table['l'][$k] += $c['miw']/$c['colspan'] ; }
  21678. else { $table['l'][$k] += $c['s']/$c['colspan']; }
  21679. }
  21680. else {
  21681. if ($c['R']) { $table['l'][$k] = $c['miw']/$c['colspan'] ; }
  21682. else { $table['l'][$k] = $c['s']/$c['colspan']; }
  21683. }
  21684. $wis += $wc[$k]['miw'];
  21685. $was += $wc[$k]['maw'];
  21686. if (!isset($c['w'])) {
  21687. $list[] = $k;
  21688. $wisa += $wc[$k]['miw'];
  21689. $wasa += $wc[$k]['maw'];
  21690. }
  21691. }
  21692. if ($c['miw'] > $wis) {
  21693. if (!$wis) {
  21694. for($k=$j;$k<$lc;$k++) { $wc[$k]['miw'] = $c['miw']/$c['colspan']; }
  21695. }
  21696. else if (!count($list)) {
  21697. $wi = $c['miw'] - $wis;
  21698. for($k=$j;$k<$lc;$k++) { $wc[$k]['miw'] += ($wc[$k]['miw']/$wis)*$wi; }
  21699. }
  21700. else {
  21701. $wi = $c['miw'] - $wis;
  21702. foreach ($list as $k) { $wc[$k]['miw'] += ($wc[$k]['miw']/$wisa)*$wi; }
  21703. }
  21704. }
  21705. if ($c['maw'] > $was) {
  21706. if (!$wis) {
  21707. for($k=$j;$k<$lc;$k++) { $wc[$k]['maw'] = $c['maw']/$c['colspan']; }
  21708. }
  21709. else if (!count($list)) {
  21710. $wi = $c['maw'] - $was;
  21711. for($k=$j;$k<$lc;$k++) { $wc[$k]['maw'] += ($wc[$k]['maw']/$was)*$wi; }
  21712. }
  21713. else {
  21714. $wi = $c['maw'] - $was;
  21715. foreach ($list as $k) { $wc[$k]['maw'] += ($wc[$k]['maw']/$wasa)*$wi; }
  21716. }
  21717. }
  21718. unset($c);
  21719. }
  21720. // mPDF 5.3.79
  21721. if ($this->cacheTables) { fclose($fh); }
  21722. $checkminwidth = 0;
  21723. $checkmaxwidth = 0;
  21724. $totallength = 0;
  21725. for( $i = 0 ; $i < $nc ; $i++ ) {
  21726. $checkminwidth += $table['wc'][$i]['miw'];
  21727. $checkmaxwidth += $table['wc'][$i]['maw'];
  21728. $totallength += $table['l'][$i];
  21729. }
  21730. if (!isset($table['w']) && $firstpass) {
  21731. $sumpc = 0;
  21732. $notset = 0;
  21733. for( $i = 0 ; $i < $nc ; $i++ ) {
  21734. if (isset($table['wc'][$i]['wpercent']) && $table['wc'][$i]['wpercent']) {
  21735. $sumpc += $table['wc'][$i]['wpercent'];
  21736. }
  21737. else { $notset++; }
  21738. }
  21739. // If sum of widths as % >= 100% and not all columns are set
  21740. // Set a nominal width of 1% for unset columns
  21741. if ($sumpc >= 100 && $notset) {
  21742. for( $i = 0 ; $i < $nc ; $i++ ) {
  21743. if ((!isset($table['wc'][$i]['wpercent']) || !$table['wc'][$i]['wpercent']) &&
  21744. (!isset($table['wc'][$i]['w']) || !$table['wc'][$i]['w'])) {
  21745. $table['wc'][$i]['wpercent'] = 1;
  21746. }
  21747. }
  21748. }
  21749. if ($sumpc) { // if any percents are set
  21750. $sumnonpc = (100 - $sumpc);
  21751. $sumpc = max($sumpc,100);
  21752. $miwleft = 0;
  21753. $miwleftcount = 0;
  21754. $miwsurplusnonpc = 0;
  21755. $maxcalcmiw = 0;
  21756. $mawleft = 0;
  21757. $mawleftcount = 0;
  21758. $mawsurplusnonpc = 0;
  21759. $maxcalcmaw = 0;
  21760. for( $i = 0 ; $i < $nc ; $i++ ) {
  21761. if (isset($table['wc'][$i]['wpercent'])) {
  21762. $maxcalcmiw = max($maxcalcmiw, ($table['wc'][$i]['miw'] * $sumpc /$table['wc'][$i]['wpercent']) );
  21763. $maxcalcmaw = max($maxcalcmaw, ($table['wc'][$i]['maw'] * $sumpc /$table['wc'][$i]['wpercent']) );
  21764. }
  21765. else {
  21766. $miwleft += $table['wc'][$i]['miw'];
  21767. $mawleft += $table['wc'][$i]['maw'];
  21768. if (!isset($table['wc'][$i]['w'])) { $miwleftcount++; $mawleftcount++; }
  21769. }
  21770. }
  21771. if ($miwleft && $sumnonpc > 0) { $miwnon = $miwleft * 100 / $sumnonpc; }
  21772. if ($mawleft && $sumnonpc > 0) { $mawnon = $mawleft * 100 / $sumnonpc; }
  21773. if (($miwnon > $checkminwidth || $maxcalcmiw > $checkminwidth) && $this->keep_table_proportions) {
  21774. if ($miwnon > $maxcalcmiw) {
  21775. $miwsurplusnonpc = round((($miwnon * $sumnonpc / 100) - $miwleft),3);
  21776. $checkminwidth = $miwnon;
  21777. }
  21778. else { $checkminwidth = $maxcalcmiw; }
  21779. for( $i = 0 ; $i < $nc ; $i++ ) {
  21780. if (isset($table['wc'][$i]['wpercent'])) {
  21781. $newmiw = $checkminwidth * $table['wc'][$i]['wpercent']/100;
  21782. if ($table['wc'][$i]['miw'] < $newmiw) {
  21783. $table['wc'][$i]['miw'] = $newmiw;
  21784. }
  21785. $table['wc'][$i]['w'] = 1;
  21786. }
  21787. else if ($miwsurplusnonpc && !$table['wc'][$i]['w']) {
  21788. $table['wc'][$i]['miw'] += $miwsurplusnonpc / $miwleftcount;
  21789. }
  21790. }
  21791. }
  21792. if (($mawnon > $checkmaxwidth || $maxcalcmaw > $checkmaxwidth )) {
  21793. if ($mawnon > $maxcalcmaw) {
  21794. $mawsurplusnonpc = round((($mawnon * $sumnonpc / 100) - $mawleft),3);
  21795. $checkmaxwidth = $mawnon;
  21796. }
  21797. else { $checkmaxwidth = $maxcalcmaw; }
  21798. for( $i = 0 ; $i < $nc ; $i++ ) {
  21799. if (isset($table['wc'][$i]['wpercent'])) {
  21800. $newmaw = $checkmaxwidth * $table['wc'][$i]['wpercent']/100;
  21801. if ($table['wc'][$i]['maw'] < $newmaw) {
  21802. $table['wc'][$i]['maw'] = $newmaw;
  21803. }
  21804. $table['wc'][$i]['w'] = 1;
  21805. }
  21806. else if ($mawsurplusnonpc && !$table['wc'][$i]['w']) {
  21807. $table['wc'][$i]['maw'] += $mawsurplusnonpc / $mawleftcount;
  21808. }
  21809. if ($table['wc'][$i]['maw'] < $table['wc'][$i]['miw']) { $table['wc'][$i]['maw'] = $table['wc'][$i]['miw']; }
  21810. }
  21811. }
  21812. if ($checkminwidth > $checkmaxwidth) { $checkmaxwidth = $checkminwidth; }
  21813. }
  21814. }
  21815. if (isset($table['wpercent']) && $table['wpercent']) {
  21816. $checkminwidth *= (100 / $table['wpercent']);
  21817. $checkmaxwidth *= (100 / $table['wpercent']);
  21818. }
  21819. $checkminwidth += $tblbw ;
  21820. $checkmaxwidth += $tblbw ;
  21821. // Table['miw'] set by percent in first pass may be larger than sum of column miw
  21822. if ((isset($table['miw']) && $checkminwidth > $table['miw']) || !isset($table['miw'])) { $table['miw'] = $checkminwidth; }
  21823. if ((isset($table['maw']) && $checkmaxwidth > $table['maw']) || !isset($table['maw'])) { $table['maw'] = $checkmaxwidth; }
  21824. $table['tl'] = $totallength ;
  21825. if (!$this->tableCJK) {
  21826. if ($this->table_rotate) {
  21827. $mxw = $this->tbrot_maxw;
  21828. }
  21829. else {
  21830. $mxw = $this->blk[$this->blklvl]['inner_width'];
  21831. }
  21832. if(!isset($table['overflow'])) { $table['overflow'] = null; }
  21833. // mPDF 5.3.36
  21834. if ($table['overflow']=='visible') {
  21835. return array(0,0);
  21836. }
  21837. else if ($table['overflow']=='hidden' && !$this->table_rotate && !$this->ColActive && $checkminwidth > $mxw) { // mPDF 5.3.36
  21838. $table['w'] = $table['miw'];
  21839. return array(0,0);
  21840. }
  21841. else if ($table['overflow']=='wrap') { return array(0,0); }
  21842. if (isset($table['w']) && $table['w'] ) {
  21843. if ($table['w'] >= $checkminwidth && $table['w'] <= $mxw) { $table['maw'] = $mxw = $table['w']; }
  21844. else if ($table['w'] >= $checkminwidth && $table['w'] > $mxw && $this->keep_table_proportions) { $checkminwidth = $table['w']; }
  21845. else {
  21846. unset($table['w']);
  21847. }
  21848. }
  21849. $ratio = $checkminwidth/$mxw;
  21850. if ($checkminwidth > $mxw) { return array(($ratio +0.001),$checkminwidth); } // 0.001 to allow for rounded numbers when resizing
  21851. }
  21852. unset($cs);
  21853. return array(0,0);
  21854. }
  21855. function _tableWidth(&$table){
  21856. $widthcols = &$table['wc'];
  21857. $numcols = $table['nc'];
  21858. $tablewidth = 0;
  21859. if ($table['borders_separate']) {
  21860. $tblbw = $table['border_details']['L']['w'] + $table['border_details']['R']['w'] + $table['margin']['L'] + $table['margin']['R'] + $table['padding']['L'] + $table['padding']['R'] + $table['border_spacing_H'];
  21861. }
  21862. else { $tblbw = $table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2 + $table['margin']['L'] + $table['margin']['R']; }
  21863. if ($table['level']>1 && isset($table['w'])) {
  21864. if (isset($table['wpercent']) && $table['wpercent']) {
  21865. $table['w'] = $temppgwidth = (($table['w']-$tblbw) * $table['wpercent'] / 100) + $tblbw ;
  21866. }
  21867. else {
  21868. $temppgwidth = $table['w'] ;
  21869. }
  21870. }
  21871. else if ($this->table_rotate) {
  21872. $temppgwidth = $this->tbrot_maxw;
  21873. // If it is less than 1/20th of the remaining page height to finish the DIV (i.e. DIV padding + table bottom margin)
  21874. // then allow for this
  21875. $enddiv = $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'];
  21876. if ($enddiv/$temppgwidth <0.05) { $temppgwidth -= $enddiv; }
  21877. }
  21878. else {
  21879. if (isset($table['w']) && $table['w']< $this->blk[$this->blklvl]['inner_width']) {
  21880. $notfullwidth = 1;
  21881. $temppgwidth = $table['w'] ;
  21882. }
  21883. else if ($table['overflow']=='visible' && $table['level'] ==1) { // mPDF 5.3.36
  21884. $temppgwidth = null;
  21885. }
  21886. else if ($table['overflow']=='hidden' && !$this->ColActive && isset($table['w']) && $table['w'] > $this->blk[$this->blklvl]['inner_width'] && $table['w']==$table['miw']) { // mPDF 5.3.36
  21887. //$temppgwidth = $this->blk[$this->blklvl]['inner_width'];
  21888. $temppgwidth = $table['w'] ; // mPDF 5.3.50
  21889. }
  21890. else { $temppgwidth = $this->blk[$this->blklvl]['inner_width']; }
  21891. }
  21892. $totaltextlength = 0; // Added - to sum $table['l'][colno]
  21893. $totalatextlength = 0; // Added - to sum $table['l'][colno] for those columns where width not set
  21894. $percentages_set = 0;
  21895. for ( $i = 0 ; $i < $numcols ; $i++ ) {
  21896. if (isset($widthcols[$i]['wpercent'])) { $tablewidth += $widthcols[$i]['maw']; $percentages_set = 1; }
  21897. else if (isset($widthcols[$i]['w'])) { $tablewidth += $widthcols[$i]['miw']; }
  21898. else { $tablewidth += $widthcols[$i]['maw']; }
  21899. $totaltextlength += $table['l'][$i];
  21900. }
  21901. if (!$totaltextlength) { $totaltextlength =1; }
  21902. $tablewidth += $tblbw; // Outer half of table borders
  21903. if ($tablewidth > $temppgwidth) {
  21904. $table['w'] = $temppgwidth;
  21905. }
  21906. // if any widths set as percentages and max width fits < page width
  21907. else if ($tablewidth < $temppgwidth && !isset($table['w']) && $percentages_set) {
  21908. $table['w'] = $table['maw'];
  21909. }
  21910. // if table width is set and is > allowed width
  21911. if (isset($table['w']) && $table['w'] > $temppgwidth) { $table['w'] = $temppgwidth; }
  21912. // IF the table width is now set - Need to distribute columns widths
  21913. if (isset($table['w'])) {
  21914. $wis = $wisa = 0;
  21915. $list = array();
  21916. $notsetlist = array();
  21917. for( $i = 0 ; $i < $numcols ; $i++ ) {
  21918. $wis += $widthcols[$i]['miw'];
  21919. if (!isset($widthcols[$i]['w']) || ($widthcols[$i]['w'] && $table['w'] > $temppgwidth && !$this->keep_table_proportions && !$notfullwidth )){
  21920. $list[] = $i;
  21921. $wisa += $widthcols[$i]['miw'];
  21922. $totalatextlength += $table['l'][$i];
  21923. }
  21924. }
  21925. if (!$totalatextlength) { $totalatextlength =1; }
  21926. // Allocate spare (more than col's minimum width) across the cols according to their approx total text length
  21927. // Do it by setting minimum width here
  21928. if ($table['w'] > $wis + $tblbw) {
  21929. // First set any cell widths set as percentages
  21930. if ($table['w'] < $temppgwidth || $this->keep_table_proportions) {
  21931. for($k=0;$k<$numcols;$k++) {
  21932. if (isset($widthcols[$k]['wpercent'])) {
  21933. $curr = $widthcols[$k]['miw'];
  21934. $widthcols[$k]['miw'] = ($table['w']-$tblbw) * $widthcols[$k]['wpercent']/100;
  21935. $wis += $widthcols[$k]['miw'] - $curr;
  21936. $wisa += $widthcols[$k]['miw'] - $curr;
  21937. }
  21938. }
  21939. }
  21940. // Now allocate surplus up to maximum width of each column
  21941. $surplus = 0; $ttl = 0; // number of surplus columns
  21942. if (!count($list)) {
  21943. $wi = ($table['w']-($wis + $tblbw)); // i.e. extra space to distribute
  21944. for($k=0;$k<$numcols;$k++) {
  21945. $spareratio = ($table['l'][$k] / $totaltextlength); // gives ratio to divide up free space
  21946. // Don't allocate more than Maximum required width - save rest in surplus
  21947. if ($widthcols[$k]['miw'] + ($wi * $spareratio) > $widthcols[$k]['maw']) {
  21948. $surplus += ($wi * $spareratio) - ($widthcols[$k]['maw']-$widthcols[$k]['miw']);
  21949. $widthcols[$k]['miw'] = $widthcols[$k]['maw'];
  21950. }
  21951. else {
  21952. $notsetlist[] = $k;
  21953. $ttl += $table['l'][$k];
  21954. $widthcols[$k]['miw'] += ($wi * $spareratio);
  21955. }
  21956. }
  21957. }
  21958. else {
  21959. $wi = ($table['w'] - ($wis + $tblbw)); // i.e. extra space to distribute
  21960. foreach ($list as $k) {
  21961. $spareratio = ($table['l'][$k] / $totalatextlength); // gives ratio to divide up free space
  21962. // Don't allocate more than Maximum required width - save rest in surplus
  21963. if ($widthcols[$k]['miw'] + ($wi * $spareratio) > $widthcols[$k]['maw']) {
  21964. $surplus += ($wi * $spareratio) - ($widthcols[$k]['maw']-$widthcols[$k]['miw']);
  21965. $widthcols[$k]['miw'] = $widthcols[$k]['maw'];
  21966. }
  21967. else {
  21968. $notsetlist[] = $k;
  21969. $ttl += $table['l'][$k];
  21970. $widthcols[$k]['miw'] += ($wi * $spareratio);
  21971. }
  21972. }
  21973. }
  21974. // If surplus still left over apportion it across columns
  21975. if ($surplus) {
  21976. // if some are set only add to remaining - otherwise add to all of them
  21977. if (count($notsetlist) && count($notsetlist) < $numcols) {
  21978. foreach ($notsetlist AS $i) {
  21979. if ($ttl) $widthcols[$i]['miw'] += $surplus * $table['l'][$i] / $ttl ;
  21980. }
  21981. }
  21982. // If some widths are defined, and others have been added up to their maxmum
  21983. else if (count($list) && count($list) < $numcols) {
  21984. foreach ($list AS $i) {
  21985. $widthcols[$i]['miw'] += $surplus / count($list) ;
  21986. }
  21987. }
  21988. else if ($numcols) { // If all columns
  21989. $ttl = array_sum($table['l']);
  21990. for ($i=0;$i<$numcols;$i++) {
  21991. $widthcols[$i]['miw'] += $surplus * $table['l'][$i] / $ttl;
  21992. }
  21993. }
  21994. }
  21995. }
  21996. // This sets the columns all to minimum width (which has been increased above if appropriate)
  21997. for ($i=0;$i<$numcols;$i++) {
  21998. $widthcols[$i] = $widthcols[$i]['miw'];
  21999. }
  22000. // TABLE NOT WIDE ENOUGH EVEN FOR MINIMUM CONTENT WIDTH
  22001. // If sum of column widths set are too wide for table
  22002. $checktablewidth = 0;
  22003. for ( $i = 0 ; $i < $numcols ; $i++ ) {
  22004. $checktablewidth += $widthcols[$i];
  22005. }
  22006. if ($checktablewidth > ($temppgwidth + 0.001 - $tblbw)) {
  22007. $usedup = 0; $numleft = 0;
  22008. for ($i=0;$i<$numcols;$i++) {
  22009. if ((isset($widthcols[$i]) && $widthcols[$i] > (($temppgwidth - $tblbw) / $numcols)) && (!isset($widthcols[$i]['w']))) {
  22010. $numleft++;
  22011. unset($widthcols[$i]);
  22012. }
  22013. else { $usedup += $widthcols[$i]; }
  22014. }
  22015. for ($i=0;$i<$numcols;$i++) {
  22016. if (!isset($widthcols[$i]) || !$widthcols[$i]) {
  22017. $widthcols[$i] = ((($temppgwidth - $tblbw) - $usedup)/ ($numleft));
  22018. }
  22019. }
  22020. }
  22021. }
  22022. else { //table has no width defined
  22023. $table['w'] = $tablewidth;
  22024. for ( $i = 0 ; $i < $numcols ; $i++) {
  22025. if (isset($widthcols[$i]['wpercent']) && $this->keep_table_proportions) { $colwidth = $widthcols[$i]['maw']; }
  22026. else if (isset($widthcols[$i]['w'])) { $colwidth = $widthcols[$i]['miw']; }
  22027. else { $colwidth = $widthcols[$i]['maw']; }
  22028. unset($widthcols[$i]);
  22029. $widthcols[$i] = $colwidth;
  22030. }
  22031. }
  22032. // mPDF 5.3.36
  22033. if ($table['overflow']=='visible' && $table['level'] ==1) { // mPDF 5.3.36
  22034. if ($tablewidth > $this->blk[$this->blklvl]['inner_width']) {
  22035. // mPDF 5.3.79
  22036. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  22037. else { $fh = null; }
  22038. for ($j = 0 ; $j < $numcols; $j++) { //columns
  22039. for ($i = 0 ; $i < $table['nr']; $i++) { //rows
  22040. if (isset($table['cells'][$i][$j]) && $table['cells'][$i][$j]) {
  22041. // mPDF 5.3.79
  22042. if ($this->cacheTables) {
  22043. $cc = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22044. $colspan = $cc['colspan'];
  22045. }
  22046. else
  22047. $colspan = $table['cells'][$i][$j]['colspan'];
  22048. if ($colspan > 1) {
  22049. $w = 0;
  22050. for ($c = $j; $c < ($j + $colspan); $c++) {
  22051. $w += $widthcols[$c];
  22052. }
  22053. if ($w > $this->blk[$this->blklvl]['inner_width']) {
  22054. $diff = $w - ($this->blk[$this->blklvl]['inner_width'] - $tblbw);
  22055. for ($c = $j; $c < ($j + $colspan); $c++) {
  22056. $widthcols[$c] -= $diff * ($widthcols[$c]/$w);
  22057. }
  22058. $table['w'] -= $diff;
  22059. $table['csp'][$j] = $w - $diff; // mPDF 5.3.44
  22060. }
  22061. }
  22062. }
  22063. }
  22064. }
  22065. // mPDF 5.3.79
  22066. if ($this->cacheTables) { fclose($fh); }
  22067. }
  22068. $pgNo = 0;
  22069. $currWc = 0;
  22070. for ($i = 0 ; $i < $numcols; $i++) { //columns
  22071. if (isset($table['csp'][$i])) {
  22072. $w = $table['csp'][$i];
  22073. unset($table['csp'][$i]);
  22074. }
  22075. else { $w = $widthcols[$i]; }
  22076. if (($currWc + $w + $tblbw) > $this->blk[$this->blklvl]['inner_width']) {
  22077. $pgNo++;
  22078. $currWc = $widthcols[$i] ;
  22079. }
  22080. else { $currWc += $widthcols[$i] ; }
  22081. $table['colPg'][$i] = $pgNo;
  22082. }
  22083. }
  22084. }
  22085. function _tableHeight(&$table){
  22086. $level = $table['level'];
  22087. $levelid = $table['levelid'];
  22088. $cells = &$table['cells'];
  22089. $numcols = $table['nc'];
  22090. $numrows = $table['nr'];
  22091. $listspan = array();
  22092. $checkmaxheight = 0;
  22093. $headerrowheight = 0;
  22094. $checkmaxheightplus = 0;
  22095. $headerrowheightplus = 0;
  22096. $firstrowheight = 0;
  22097. $footerrowheight = 0;
  22098. $footerrowheightplus = 0;
  22099. if ($this->table_rotate) {
  22100. $temppgheight = $this->tbrot_maxh;
  22101. $remainingpage = $this->tbrot_maxh;
  22102. }
  22103. else {
  22104. $temppgheight = ($this->h - $this->bMargin - $this->tMargin) - $this->kwt_height;
  22105. $remainingpage = ($this->h - $this->bMargin - $this->y) - $this->kwt_height;
  22106. // If it is less than 1/20th of the remaining page height to finish the DIV (i.e. DIV padding + table bottom margin)
  22107. // then allow for this
  22108. $enddiv = $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $table['margin']['B'];
  22109. if ($remainingpage > $enddiv && $enddiv/$remainingpage <0.05) { $remainingpage -= $enddiv; }
  22110. else if ($remainingpage == 0) { $remainingpage = 0.001; }
  22111. if ($temppgheight > $enddiv && $enddiv/$temppgheight <0.05) { $temppgheight -= $enddiv; }
  22112. else if ($temppgheight == 0) { $temppgheight = 0.001; }
  22113. }
  22114. // mPDF 5.3.79
  22115. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  22116. else { $fh = null; }
  22117. for( $i = 0 ; $i < $numrows ; $i++ ) { //rows
  22118. $heightrow = &$table['hr'][$i];
  22119. for( $j = 0 ; $j < $numcols ; $j++ ) { //columns
  22120. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  22121. // mPDF 5.3.79
  22122. if ($this->cacheTables) {
  22123. $c = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22124. }
  22125. else
  22126. $c = &$cells[$i][$j];
  22127. if ($this->simpleTables){
  22128. if ($table['borders_separate']) { // NB twice border width
  22129. $extraWLR = ($table['simple']['border_details']['L']['w']+$table['simple']['border_details']['R']['w']) + ($c['padding']['L']+$c['padding']['R'])+$table['border_spacing_H'];
  22130. $extrh = ($table['simple']['border_details']['T']['w']+$table['simple']['border_details']['B']['w']) + ($c['padding']['T']+$c['padding']['B'])+$table['border_spacing_V'];
  22131. }
  22132. else {
  22133. $extraWLR = ($table['simple']['border_details']['L']['w']+$table['simple']['border_details']['R']['w'])/2 + ($c['padding']['L']+$c['padding']['R']);
  22134. $extrh = ($table['simple']['border_details']['T']['w']+$table['simple']['border_details']['B']['w'])/2 + ($c['padding']['T']+$c['padding']['B']);
  22135. }
  22136. }
  22137. else {
  22138. if ($this->packTableData) {
  22139. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  22140. }
  22141. else {
  22142. $bt = $c['border_details']['T']['w'];
  22143. $bb = $c['border_details']['B']['w'];
  22144. $br = $c['border_details']['R']['w'];
  22145. $bl = $c['border_details']['L']['w'];
  22146. }
  22147. if ($table['borders_separate']) { // NB twice border width
  22148. $extraWLR = $bl + $br + $c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H'];
  22149. $extrh = $bt + $bb + $c['padding']['T'] + $c['padding']['B'] + $table['border_spacing_V'];
  22150. }
  22151. else {
  22152. $extraWLR = $bl/2 + $br/2 + $c['padding']['L'] + $c['padding']['R'];
  22153. $extrh = $bt/2 + $bb/2 + $c['padding']['T']+$c['padding']['B'];
  22154. }
  22155. }
  22156. // mPDF 5.3.36
  22157. if ($table['overflow']=='visible' && $level==1)
  22158. list($x,$cw) = $this->_splitTableGetWidth($table, $i,$j, $fh);
  22159. else
  22160. list($x,$cw) = $this->_tableGetWidth($table, $i,$j, $fh);
  22161. // Get CELL HEIGHT
  22162. // ++ extra parameter forces wrap to break word
  22163. if ($c['R']) {
  22164. // mPDF 5.3.78
  22165. $str = '';
  22166. foreach($c['textbuffer'] AS $t) { $str .= $t[0].' '; }
  22167. $str = trim($str);
  22168. $s_fs = $this->FontSizePt;
  22169. $s_f = $this->FontFamily;
  22170. $s_st = $this->FontStyle;
  22171. $this->SetFont($c['textbuffer'][0][4],$c['textbuffer'][0][2],$c['textbuffer'][0][11] / $this->shrin_k,true,true);
  22172. $tempch = $this->GetStringWidth($str); // mPDF 5.3.78
  22173. if ($c['R'] >= 45 && $c['R'] < 90) {
  22174. $tempch = ((sin(deg2rad($c['R']))) * $tempch ) + ((sin(deg2rad($c['R']))) * (($c['textbuffer'][0][11]/_MPDFK) / $this->shrin_k));
  22175. }
  22176. $this->SetFont($s_f,$s_st,$s_fs,true,true);
  22177. $ch = ($tempch ) + $extrh ;
  22178. }
  22179. else {
  22180. if (isset($c['textbuffer'])) {
  22181. $tempch = $this->TableWordWrap(($cw-$extraWLR),1,$c['textbuffer'], $c['dfs']);
  22182. }
  22183. else { $tempch = 0; }
  22184. // Added cellpadding top and bottom. (Lineheight already adjusted to table_lineheight)
  22185. $ch = $tempch + $extrh ;
  22186. }
  22187. //If height is defined and it is bigger than calculated $ch then update values
  22188. if (isset($c['h']) && $c['h'] > $ch) {
  22189. $c['mih'] = $ch; //in order to keep valign working
  22190. $ch = $c['h'];
  22191. }
  22192. else $c['mih'] = $ch;
  22193. // mPDF 5.3.79
  22194. if ($this->cacheTables) {
  22195. $this->_cacheUpdateMtx($c, $fh, $table['cells'][$i][$j], 'mih');
  22196. }
  22197. if (isset($c['rowspan'])) $listspan[] = array($i,$j);
  22198. elseif ($heightrow < $ch) $heightrow = $ch;
  22199. // this is the extra used in _tableWrite to determine whether to trigger a page change
  22200. if ($table['borders_separate']) {
  22201. if ($i == ($numrows-1) || (isset($c['rowspan']) && ($i+$c['rowspan']) == ($numrows)) ) {
  22202. $extra = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  22203. }
  22204. else {
  22205. $extra = $table['border_spacing_V']/2;
  22206. }
  22207. }
  22208. else {
  22209. if (!$this->simpleTables){
  22210. $extra = $bb/2;
  22211. }
  22212. else if ($this->simpleTables){
  22213. $extra = $table['simple']['border_details']['B']['w'] /2;
  22214. }
  22215. }
  22216. if (isset($table['is_thead'][$i]) && $table['is_thead'][$i]) { // mPDF 5.3.62
  22217. if ($j==0) {
  22218. $headerrowheight += $ch;
  22219. $headerrowheightplus += $ch+$extra;
  22220. }
  22221. }
  22222. else if (isset($table['is_tfoot'][$i]) && $table['is_tfoot'][$i]) {
  22223. if ($j==0) {
  22224. $footerrowheight += $ch;
  22225. $footerrowheightplus += $ch+$extra;
  22226. }
  22227. }
  22228. else {
  22229. $checkmaxheight = max($checkmaxheight,$ch);
  22230. $checkmaxheightplus = max($checkmaxheightplus,$ch+$extra);
  22231. }
  22232. if ($this->tableLevel==1 && $i == $table['headernrows']) { $firstrowheight = max($ch,$firstrowheight); } // mPDF 5.3.62 // mPDF 5.3.76
  22233. unset($c);
  22234. }
  22235. }//end of columns
  22236. }//end of rows
  22237. $heightrow = &$table['hr'];
  22238. foreach ($listspan as $span) {
  22239. list($i,$j) = $span;
  22240. // mPDF 5.3.79
  22241. if ($this->cacheTables) {
  22242. $c = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22243. }
  22244. else
  22245. $c = &$cells[$i][$j];
  22246. $lr = $i + $c['rowspan'];
  22247. if ($lr > $numrows) $lr = $numrows;
  22248. $hs = $hsa = 0;
  22249. $list = array();
  22250. for($k=$i;$k<$lr;$k++) {
  22251. $hs += $heightrow[$k];
  22252. if (!isset($c['h'])) {
  22253. $list[] = $k;
  22254. $hsa += $heightrow[$k];
  22255. }
  22256. }
  22257. if ($table['borders_separate']) {
  22258. if ($i == ($numrows-1) || ($i+$c['rowspan']) == ($numrows) ) {
  22259. $extra = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  22260. }
  22261. else {
  22262. $extra = $table['border_spacing_V']/2;
  22263. }
  22264. }
  22265. else {
  22266. if (!$this->simpleTables){
  22267. if ($this->packTableData) {
  22268. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  22269. }
  22270. else {
  22271. $bb = $c['border_details']['B']['w'];
  22272. }
  22273. $extra = $bb/2;
  22274. }
  22275. else if ($this->simpleTables){
  22276. $extra = $table['simple']['border_details']['B']['w'] /2;
  22277. }
  22278. }
  22279. if (!empty($table['is_thead'][$i])) { // mPDF 5.3.62
  22280. $headerrowheight = max($headerrowheight,$hs);
  22281. $headerrowheightplus = max($headerrowheightplus,$hs+$extra);
  22282. }
  22283. else if (!empty($table['is_tfoot'][$i])) {
  22284. $footerrowheight = max($footerrowheight,$hs);
  22285. $footerrowheightplus = max($footerrowheightplus,$hs+$extra);
  22286. }
  22287. else {
  22288. $checkmaxheight = max($checkmaxheight,$hs);
  22289. $checkmaxheightplus = max($checkmaxheightplus,$hs+$extra);
  22290. }
  22291. if ($this->tableLevel==1 && $i == $table['headernrows']) { $firstrowheight = max($hs,$firstrowheight); } // mPDF 5.3.62 // mPDF 5.3.76
  22292. if ($c['mih'] > $hs) {
  22293. if (!$hs) {
  22294. for($k=$i;$k<$lr;$k++) $heightrow[$k] = $c['mih']/$c['rowspan'];
  22295. }
  22296. elseif (!count($list)) {
  22297. $hi = $c['mih'] - $hs;
  22298. for($k=$i;$k<$lr;$k++) $heightrow[$k] += ($heightrow[$k]/$hs)*$hi;
  22299. }
  22300. else {
  22301. $hi = $c['mih'] - $hsa;
  22302. foreach ($list as $k) $heightrow[$k] += ($heightrow[$k]/$hsa)*$hi;
  22303. }
  22304. }
  22305. unset($c);
  22306. // If rowspans overlap so that one or more rows do not have a height set...
  22307. // i.e. for one or more rows, the only cells (explicit) in that row have rowspan>1
  22308. // so heightrow is still == 0
  22309. if ($heightrow[$i]==0) {
  22310. // Get row extent to analyse above and below
  22311. $top = $i;
  22312. foreach ($listspan as $checkspan) {
  22313. list($cki,$ckj) = $checkspan;
  22314. if ($this->cacheTables) {
  22315. $c = $this->_uncacheCell($table['cells'][$cki][$ckj], '', $fh);
  22316. }
  22317. else
  22318. $c = &$cells[$cki][$ckj];
  22319. if (isset($c['rowspan']) && $c['rowspan']>1) {
  22320. if (($cki + $c['rowspan']-1) >= $i) { $top = min($top, $cki); }
  22321. }
  22322. }
  22323. $bottom = $i + $c['rowspan']-1;
  22324. // Check for overconstrained conditions
  22325. for ($k=$top; $k<=$bottom; $k++) {
  22326. // if ['hr'] for any of the others is also 0, then abort (too complicated)
  22327. if ($k != $i && $heightrow[$k]==0) { break(1); }
  22328. // check again that top and bottom are not crossed by rowspans - or abort (too complicated)
  22329. if ($k==$top) {
  22330. // ???? take account of colspan as well???
  22331. for( $m = 0 ; $m < $numcols ; $m++ ) { //columns
  22332. if (!isset($cells[$k][$m]) || $cells[$k][$m]==0) {
  22333. break(2);
  22334. }
  22335. }
  22336. }
  22337. else if ($k==$bottom) {
  22338. // ???? take account of colspan as well???
  22339. for( $m = 0 ; $m < $numcols ; $m++ ) { //columns
  22340. if ($this->cacheTables) {
  22341. $c = $this->_uncacheCell($table['cells'][$k][$m], '', $fh);
  22342. }
  22343. else
  22344. $c = &$cells[$k][$m];
  22345. if (isset($c['rowspan']) && $c['rowspan']>1) {
  22346. break(2);
  22347. }
  22348. }
  22349. }
  22350. }
  22351. // By columns add up col height using ['h'] if set or ['mih'] if not
  22352. // Intentionally do not substract border-spacing
  22353. $colH = array();
  22354. $extH = 0;
  22355. $newhr = array();
  22356. for( $m = 0 ; $m < $numcols ; $m++ ) { //columns
  22357. for ($k=$top; $k<=$bottom; $k++) {
  22358. if (isset($cells[$k][$m]) && $cells[$k][$m]!=0) {
  22359. if ($this->cacheTables) {
  22360. $c = $this->_uncacheCell($table['cells'][$k][$m], '', $fh);
  22361. }
  22362. else
  22363. $c = &$cells[$k][$m];
  22364. if (isset($c['h']) && $c['h']) {
  22365. $useh = $c['h'];
  22366. }
  22367. // ???? take account of colspan as well???
  22368. else {
  22369. $useh = $c['mih'];
  22370. }
  22371. $colH[$m] += $useh;
  22372. if (!isset($c['rowspan']) || $c['rowspan']<2) { $newhr[$k] = max($newhr[$k], $useh); }
  22373. }
  22374. }
  22375. $extH = max($tabH, $colH[$m]);
  22376. }
  22377. $newhr[$i] = $extH - array_sum($newhr);
  22378. for ($k=$top; $k<=$bottom; $k++) { $heightrow[$k] = $newhr[$k]; }
  22379. }
  22380. unset($c);
  22381. }
  22382. $table['h'] = array_sum($heightrow); // mPDF 5.3.80
  22383. unset($heightrow); // mPDF 5.3.80
  22384. // mPDF 5.3.79
  22385. if ($this->cacheTables) { fclose($fh); }
  22386. if ($table['borders_separate']) {
  22387. $table['h'] += $table['margin']['T'] + $table['margin']['B'] + $table['border_details']['T']['w'] + $table['border_details']['B']['w'] + $table['border_spacing_V'] + $table['padding']['T'] + $table['padding']['B'];
  22388. }
  22389. else {
  22390. $table['h'] += $table['margin']['T'] + $table['margin']['B'] + $table['max_cell_border_width']['T']/2 + $table['max_cell_border_width']['B']/2;
  22391. }
  22392. $maxrowheight = $checkmaxheightplus + $headerrowheightplus + $footerrowheightplus;
  22393. $maxfirstrowheight = $firstrowheight + $headerrowheightplus + $footerrowheightplus; // includes thead, 1st row and tfoot
  22394. return array($table['h'],$maxrowheight,$temppgheight,$remainingpage,$maxfirstrowheight);
  22395. }
  22396. function _tableGetWidth(&$table, $i,$j, $fh){
  22397. // mPDF 5.3.79
  22398. if ($this->cacheTables) {
  22399. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22400. }
  22401. else
  22402. $cell = &$table['cells'][$i][$j];
  22403. if ($cell) {
  22404. if (isset($cell['x0'])) { return array($cell['x0'], $cell['w0']); }
  22405. $x = 0;
  22406. $widthcols = &$table['wc'];
  22407. for( $k = 0 ; $k < $j ; $k++ ) $x += $widthcols[$k];
  22408. $w = $widthcols[$j];
  22409. if (isset($cell['colspan'])) {
  22410. for ( $k = $j+$cell['colspan']-1 ; $k > $j ; $k-- ) $w += $widthcols[$k];
  22411. }
  22412. $cell['x0'] = $x;
  22413. $cell['w0'] = $w;
  22414. // mPDF 5.3.79
  22415. if ($this->cacheTables) {
  22416. $this->_cacheUpdateMtx($cell, $fh, $table['cells'][$i][$j], 'x0');
  22417. }
  22418. return array($x, $w);
  22419. }
  22420. return array(0,0);
  22421. }
  22422. // mPDF 5.3.36
  22423. function _splitTableGetWidth(&$table, $i,$j, $fh){
  22424. // mPDF 5.3.79
  22425. if ($this->cacheTables) {
  22426. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22427. }
  22428. else
  22429. $cell = &$table['cells'][$i][$j];
  22430. if ($cell) {
  22431. if (isset($cell['x0'])) return array($cell['x0'], $cell['w0']);
  22432. $x = 0;
  22433. $widthcols = &$table['wc'];
  22434. $pg = $table['colPg'][$j];
  22435. for( $k = 0 ; $k < $j ; $k++ ) {
  22436. if ($table['colPg'][$k]==$pg) $x += $widthcols[$k];
  22437. }
  22438. $w = $widthcols[$j];
  22439. if (isset($cell['colspan'])) {
  22440. for ( $k = $j+$cell['colspan']-1 ; $k > $j ; $k-- ) if ($table['colPg'][$k]==$pg) $w += $widthcols[$k];
  22441. }
  22442. $cell['x0'] = $x;
  22443. $cell['w0'] = $w;
  22444. // mPDF 5.3.79
  22445. if ($this->cacheTables) {
  22446. $this->_cacheUpdateMtx($cell, $fh, $table['cells'][$i][$j], 'x0');
  22447. }
  22448. return array($x, $w);
  22449. }
  22450. return array(0,0);
  22451. }
  22452. function _tableGetHeight(&$table, $i,$j, $fh){
  22453. // mPDF 5.3.79
  22454. if ($this->cacheTables) {
  22455. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22456. }
  22457. else
  22458. $cell = &$table['cells'][$i][$j];
  22459. if ($cell){
  22460. if (isset($cell['y0'])) return array($cell['y0'], $cell['h0']);
  22461. $y = 0;
  22462. $heightrow = &$table['hr'];
  22463. for ($k=0;$k<$i;$k++) $y += $heightrow[$k];
  22464. $h = $heightrow[$i];
  22465. if (isset($cell['rowspan'])){
  22466. for ($k=$i+$cell['rowspan']-1;$k>$i;$k--)
  22467. $h += $heightrow[$k];
  22468. }
  22469. $cell['y0'] = $y;
  22470. $cell['h0'] = $h;
  22471. // mPDF 5.3.79
  22472. if ($this->cacheTables) {
  22473. $this->_cacheUpdateMtx($cell, $fh, $table['cells'][$i][$j], 'y0');
  22474. }
  22475. return array($y, $h);
  22476. }
  22477. return array(0,0);
  22478. }
  22479. // mPDF 5.3.A7
  22480. function _tableGetMaxRowHeight($table, $row, $fh) {
  22481. if ($row==$table['nc']-1) { return $table['hr'][$row]; }
  22482. $maxrowheight = $table['hr'][$row];
  22483. for ($i=$row+1;$i<$table['nr'];$i++) {
  22484. $cellsset = 0;
  22485. for ($j=0;$j<$table['nc'];$j++) {
  22486. if ($this->cacheTables) {
  22487. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22488. if ($cell) {
  22489. if (isset($cell['colspan'])) { $cellsset += $cell['colspan']; }
  22490. else $cellsset += 1;
  22491. }
  22492. }
  22493. else {
  22494. if ($table['cells'][$i][$j]) {
  22495. if (isset($table['cells'][$i][$j]['colspan'])) { $cellsset += $table['cells'][$i][$j]['colspan']; }
  22496. else $cellsset += 1;
  22497. }
  22498. }
  22499. }
  22500. if ($cellsset == $table['nc']) { return $maxrowheight; }
  22501. else { $maxrowheight += $table['hr'][$i]; }
  22502. }
  22503. return $maxrowheight;
  22504. }
  22505. // CHANGED TO ALLOW TABLE BORDER TO BE SPECIFIED CORRECTLY - added border_details
  22506. function _tableRect($x, $y, $w, $h, $bord=-1, $details=array(), $buffer=false, $bSeparate=false, $cort='cell', $tablecorner='', $bsv=0, $bsh=0) {
  22507. $cellBorderOverlay = array();
  22508. if ($bord==-1) { $this->Rect($x, $y, $w, $h); }
  22509. else if ($this->simpleTables && ($cort=='cell')) {
  22510. $this->SetLineWidth($details['L']['w']);
  22511. if ($details['L']['c']) {
  22512. $this->SetDColor($details['L']['c']);
  22513. }
  22514. else { $this->SetDColor($this->ConvertColor(0)); }
  22515. $this->SetLineJoin(0);
  22516. $this->Rect($x, $y, $w, $h);
  22517. }
  22518. else if ($bord){
  22519. if (!$bSeparate && $buffer) {
  22520. $priority = 'LRTB';
  22521. for($p=0;$p<strlen($priority);$p++) {
  22522. $side = $priority[$p];
  22523. $details['p'] = $side ;
  22524. $dom = 0;
  22525. if (isset($details[$side]['w'])) { $dom += ($details[$side]['w'] * 100000); }
  22526. if (isset($details[$side]['style'])) { $dom += (array_search($details[$side]['style'],$this->borderstyles)*100) ; }
  22527. if (isset($details[$side]['dom'])) { $dom += ($details[$side]['dom']*10); }
  22528. // Precedence to darker colours at joins
  22529. $coldom = 0;
  22530. if (isset($details[$side]['c']) && is_array($details[$side]['c'])) {
  22531. // mPDF 5.3.74
  22532. if ($details[$side]['c']{0}==3) { // RGB
  22533. $coldom = 10-(((ord($details[$side]['c']{1})*1.00)+(ord($details[$side]['c']{2})*1.00)+(ord($details[$side]['c']{3})*1.00))/76.5);
  22534. }
  22535. } // 10 black - 0 white
  22536. if ($coldom) { $dom += $coldom; }
  22537. // Lastly precedence to RIGHT and BOTTOM cells at joins
  22538. if (isset($details['cellposdom'])) { $dom += $details['cellposdom']; }
  22539. $save = false;
  22540. if ($side == 'T' && $this->issetBorder($bord, _BORDER_TOP)) { $cbord = _BORDER_TOP; $save = true; }
  22541. else if ($side == 'L' && $this->issetBorder($bord, _BORDER_LEFT)) { $cbord = _BORDER_LEFT; $save = true; }
  22542. else if ($side == 'R' && $this->issetBorder($bord, _BORDER_RIGHT)) { $cbord = _BORDER_RIGHT; $save = true; }
  22543. else if ($side == 'B' && $this->issetBorder($bord, _BORDER_BOTTOM)) { $cbord = _BORDER_BOTTOM; $save = true; }
  22544. if ($save) {
  22545. // mPDF 5.3.74
  22546. $this->cellBorderBuffer[] = pack("A16nCnda6A10d14",
  22547. str_pad(sprintf("%08.7f", $dom),16,"0",STR_PAD_LEFT),
  22548. $cbord,
  22549. ord($side),
  22550. $details[$side]['s'],
  22551. $details[$side]['w'],
  22552. $details[$side]['c'],
  22553. $details[$side]['style'],
  22554. $x, $y, $w, $h,
  22555. $details['mbw']['BL'],
  22556. $details['mbw']['BR'],
  22557. $details['mbw']['RT'],
  22558. $details['mbw']['RB'],
  22559. $details['mbw']['TL'],
  22560. $details['mbw']['TR'],
  22561. $details['mbw']['LT'],
  22562. $details['mbw']['LB'],
  22563. $details['cellposdom'],
  22564. 0
  22565. );
  22566. if ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'groove' || $details[$side]['style'] == 'inset' || $details[$side]['style'] == 'outset' || $details[$side]['style'] == 'double' ) {
  22567. $details[$side]['overlay'] = true;
  22568. // mPDF 5.3.74
  22569. $this->cellBorderBuffer[] = pack("A16nCnda6A10d14",
  22570. str_pad(sprintf("%08.7f", ($dom+4)),16,"0",STR_PAD_LEFT),
  22571. $cbord,
  22572. ord($side),
  22573. $details[$side]['s'],
  22574. $details[$side]['w'],
  22575. $details[$side]['c'],
  22576. $details[$side]['style'],
  22577. $x, $y, $w, $h,
  22578. $details['mbw']['BL'],
  22579. $details['mbw']['BR'],
  22580. $details['mbw']['RT'],
  22581. $details['mbw']['RB'],
  22582. $details['mbw']['TL'],
  22583. $details['mbw']['TR'],
  22584. $details['mbw']['LT'],
  22585. $details['mbw']['LB'],
  22586. $details['cellposdom'],
  22587. 1
  22588. );
  22589. }
  22590. }
  22591. }
  22592. return;
  22593. }
  22594. if (isset($details['p']) && strlen($details['p'])>1) { $priority = $details['p']; }
  22595. else { $priority='LTRB'; }
  22596. $Tw = 0;
  22597. $Rw = 0;
  22598. $Bw = 0;
  22599. $Lw = 0;
  22600. if (isset($details['T']['w'])) { $Tw = $details['T']['w']; }
  22601. if (isset($details['R']['w'])) { $Rw = $details['R']['w']; }
  22602. if (isset($details['B']['w'])) { $Bw = $details['B']['w']; }
  22603. if (isset($details['L']['w'])) { $Lw = $details['L']['w']; }
  22604. $x2 = $x + $w; $y2 = $y + $h;
  22605. $oldlinewidth = $this->LineWidth;
  22606. for($p=0;$p<strlen($priority);$p++) {
  22607. $side = $priority[$p];
  22608. $xadj = 0;
  22609. $xadj2 = 0;
  22610. $yadj = 0;
  22611. $yadj2 = 0;
  22612. $print = false;
  22613. if ($Tw && $side=='T' && $this->issetBorder($bord, _BORDER_TOP)) { // TOP
  22614. $ly1 = $y;
  22615. $ly2 = $y;
  22616. $lx1 = $x;
  22617. $lx2 = $x2;
  22618. $this->SetLineWidth($Tw);
  22619. if ($cort == 'cell' || strpos($tablecorner,'L')!==false) {
  22620. if ($Tw > $Lw) $xadj = ($Tw - $Lw)/2;
  22621. if ($Tw < $Lw) $xadj = ($Tw + $Lw)/2;
  22622. }
  22623. else { $xadj = $Tw/2 - $bsh/2; }
  22624. if ($cort == 'cell' || strpos($tablecorner,'R')!==false) {
  22625. if ($Tw > $Rw) $xadj2 = ($Tw - $Rw)/2;
  22626. if ($Tw < $Rw) $xadj2 = ($Tw + $Rw)/2;
  22627. }
  22628. else { $xadj2 = $Tw/2 - $bsh/2; }
  22629. if (!$bSeparate && $details['mbw']['TL']) {
  22630. $xadj = ($Tw - $details['mbw']['TL'])/2 ;
  22631. }
  22632. if (!$bSeparate && $details['mbw']['TR']) {
  22633. $xadj2 = ($Tw - $details['mbw']['TR'])/2;
  22634. }
  22635. $print = true;
  22636. }
  22637. if ($Lw && $side=='L' && $this->issetBorder($bord, _BORDER_LEFT)) { // LEFT
  22638. $ly1 = $y;
  22639. $ly2 = $y2;
  22640. $lx1 = $x;
  22641. $lx2 = $x;
  22642. $this->SetLineWidth($Lw);
  22643. if ($cort == 'cell' || strpos($tablecorner,'T')!==false) {
  22644. if ($Lw > $Tw) $yadj = ($Lw - $Tw)/2;
  22645. if ($Lw < $Tw) $yadj = ($Lw + $Tw)/2;
  22646. }
  22647. else { $yadj = $Lw/2 - $bsv/2; }
  22648. if ($cort == 'cell' || strpos($tablecorner,'B')!==false) {
  22649. if ($Lw > $Bw) $yadj2 = ($Lw - $Bw)/2;
  22650. if ($Lw < $Bw) $yadj2 = ($Lw + $Bw)/2;
  22651. }
  22652. else { $yadj2 = $Lw/2 - $bsv/2; }
  22653. if (!$bSeparate && $details['mbw']['LT']) {
  22654. $yadj = ($Lw - $details['mbw']['LT'])/2;
  22655. }
  22656. if (!$bSeparate && $details['mbw']['LB']) {
  22657. $yadj2 = ($Lw - $details['mbw']['LB'])/2;
  22658. }
  22659. $print = true;
  22660. }
  22661. if ($Rw && $side=='R' && $this->issetBorder($bord, _BORDER_RIGHT)) { // RIGHT
  22662. $ly1 = $y;
  22663. $ly2 = $y2;
  22664. $lx1 = $x2;
  22665. $lx2 = $x2;
  22666. $this->SetLineWidth($Rw);
  22667. if ($cort == 'cell' || strpos($tablecorner,'T')!==false) {
  22668. if ($Rw < $Tw) $yadj = ($Rw + $Tw)/2;
  22669. if ($Rw > $Tw) $yadj = ($Rw - $Tw)/2;
  22670. }
  22671. else { $yadj = $Rw/2 - $bsv/2; }
  22672. if ($cort == 'cell' || strpos($tablecorner,'B')!==false) {
  22673. if ($Rw > $Bw) $yadj2 = ($Rw - $Bw)/2;
  22674. if ($Rw < $Bw) $yadj2 = ($Rw + $Bw)/2;
  22675. }
  22676. else { $yadj2 = $Rw/2 - $bsv/2; }
  22677. if (!$bSeparate && $details['mbw']['RT']) {
  22678. $yadj = ($Rw - $details['mbw']['RT'])/2;
  22679. }
  22680. if (!$bSeparate && $details['mbw']['RB']) {
  22681. $yadj2 = ($Rw - $details['mbw']['RB'])/2;
  22682. }
  22683. $print = true;
  22684. }
  22685. if ($Bw && $side=='B' && $this->issetBorder($bord, _BORDER_BOTTOM)) { // BOTTOM
  22686. $ly1 = $y2;
  22687. $ly2 = $y2;
  22688. $lx1 = $x;
  22689. $lx2 = $x2;
  22690. $this->SetLineWidth($Bw);
  22691. if ($cort == 'cell' || strpos($tablecorner,'L')!==false) {
  22692. if ($Bw > $Lw) $xadj = ($Bw - $Lw)/2;
  22693. if ($Bw < $Lw) $xadj = ($Bw + $Lw)/2;
  22694. }
  22695. else { $xadj = $Bw/2 - $bsh/2; }
  22696. if ($cort == 'cell' || strpos($tablecorner,'R')!==false) {
  22697. if ($Bw > $Rw) $xadj2 = ($Bw - $Rw)/2;
  22698. if ($Bw < $Rw) $xadj2 = ($Bw + $Rw)/2;
  22699. }
  22700. else { $xadj2 = $Bw/2 - $bsh/2; }
  22701. if (!$bSeparate && $details['mbw']['BL']) {
  22702. $xadj = ($Bw - $details['mbw']['BL'])/2;
  22703. }
  22704. if (!$bSeparate && $details['mbw']['BR']) {
  22705. $xadj2 = ($Bw - $details['mbw']['BR'])/2;
  22706. }
  22707. $print = true;
  22708. }
  22709. // Now draw line
  22710. if ($print) {
  22711. /*-- TABLES-ADVANCED-BORDERS --*/
  22712. if ($details[$side]['style'] == 'double') {
  22713. if (!isset($details[$side]['overlay']) || !$details[$side]['overlay'] || $bSeparate) {
  22714. if ($details[$side]['c']) {
  22715. $this->SetDColor($details[$side]['c']);
  22716. }
  22717. else { $this->SetDColor($this->ConvertColor(0)); }
  22718. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  22719. }
  22720. if ((isset($details[$side]['overlay']) && $details[$side]['overlay']) || $bSeparate) {
  22721. if ($bSeparate && $cort=='table') {
  22722. if ($side=='T') {
  22723. $xadj -= $this->LineWidth/2;
  22724. $xadj2 -= $this->LineWidth;
  22725. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  22726. $xadj += $this->LineWidth/2;
  22727. }
  22728. if ($this->issetBorder($bord, _BORDER_RIGHT)) {
  22729. $xadj2 += $this->LineWidth;
  22730. }
  22731. }
  22732. if ($side=='L') {
  22733. $yadj -= $this->LineWidth/2;
  22734. $yadj2 -= $this->LineWidth;
  22735. if ($this->issetBorder($bord, _BORDER_TOP)) {
  22736. $yadj += $this->LineWidth/2;
  22737. }
  22738. if ($this->issetBorder($bord, _BORDER_BOTTOM)) {
  22739. $yadj2 += $this->LineWidth;
  22740. }
  22741. }
  22742. if ($side=='B') {
  22743. $xadj -= $this->LineWidth/2;
  22744. $xadj2 -= $this->LineWidth;
  22745. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  22746. $xadj += $this->LineWidth/2;
  22747. }
  22748. if ($this->issetBorder($bord, _BORDER_RIGHT)) {
  22749. $xadj2 += $this->LineWidth;
  22750. }
  22751. }
  22752. if ($side=='R') {
  22753. $yadj -= $this->LineWidth/2;
  22754. $yadj2 -= $this->LineWidth;
  22755. if ($this->issetBorder($bord, _BORDER_TOP)) {
  22756. $yadj += $this->LineWidth/2;
  22757. }
  22758. if ($this->issetBorder($bord, _BORDER_BOTTOM)) {
  22759. $yadj2 += $this->LineWidth;
  22760. }
  22761. }
  22762. }
  22763. $this->SetLineWidth($this->LineWidth/3);
  22764. $tbcol = $this->ConvertColor(255);
  22765. for($l=0; $l <= $this->blklvl; $l++) {
  22766. if ($this->blk[$l]['bgcolor']) {
  22767. $tbcol = array($this->blk[$l]['bgcolorarray']);
  22768. }
  22769. }
  22770. if ($bSeparate) {
  22771. $cellBorderOverlay[] = array(
  22772. 'x' => $lx1 + $xadj,
  22773. 'y' => $ly1 + $yadj,
  22774. 'x2' => $lx2 - $xadj2,
  22775. 'y2' => $ly2 - $yadj2,
  22776. 'col' => $tbcol,
  22777. 'lw' => $this->LineWidth,
  22778. );
  22779. }
  22780. else {
  22781. $this->SetDColor($tbcol);
  22782. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  22783. }
  22784. }
  22785. }
  22786. else if (isset($details[$side]['style']) && ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'groove' || $details[$side]['style'] == 'inset' || $details[$side]['style'] == 'outset')) {
  22787. if (!isset($details[$side]['overlay']) || !$details[$side]['overlay'] || $bSeparate) {
  22788. if ($details[$side]['c']) {
  22789. $this->SetDColor($details[$side]['c']);
  22790. }
  22791. else { $this->SetDColor($this->ConvertColor(0)); }
  22792. if ($details[$side]['style'] == 'outset' || $details[$side]['style'] == 'groove') {
  22793. $nc = $this->_darkenColor($details[$side]['c']);
  22794. $this->SetDColor($nc);
  22795. }
  22796. else if ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'inset') {
  22797. $nc = $this->_lightenColor($details[$side]['c']);
  22798. $this->SetDColor($nc);
  22799. }
  22800. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  22801. }
  22802. if ((isset($details[$side]['overlay']) && $details[$side]['overlay']) || $bSeparate) {
  22803. if ($details[$side]['c']) {
  22804. $this->SetDColor($details[$side]['c']);
  22805. }
  22806. else { $this->SetDColor($this->ConvertColor(0)); }
  22807. $doubleadj = ($this->LineWidth)/3;
  22808. $this->SetLineWidth($this->LineWidth/2);
  22809. $xadj3 = $yadj3 = $wadj3 = $hadj3 = 0;
  22810. if ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'inset') {
  22811. $nc = $this->_darkenColor($details[$side]['c']);
  22812. if ($bSeparate && $cort=='table') {
  22813. if ($side=='T') {
  22814. $yadj3 = $this->LineWidth/2;
  22815. $xadj3 = -$this->LineWidth/2;
  22816. $wadj3 = $this->LineWidth;
  22817. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  22818. $xadj3 += $this->LineWidth; $wadj3 -= $this->LineWidth;
  22819. }
  22820. if ($this->issetBorder($bord, _BORDER_RIGHT)) {
  22821. $wadj3 -= $this->LineWidth*2;
  22822. }
  22823. }
  22824. if ($side=='L') {
  22825. $xadj3 = $this->LineWidth/2;
  22826. $yadj3 = -$this->LineWidth/2;
  22827. $hadj3 = $this->LineWidth;
  22828. if ($this->issetBorder($bord, _BORDER_TOP)) {
  22829. $yadj3 += $this->LineWidth; $hadj3 -= $this->LineWidth;
  22830. }
  22831. if ($this->issetBorder($bord, _BORDER_BOTTOM)) {
  22832. $hadj3 -= $this->LineWidth*2;
  22833. }
  22834. }
  22835. if ($side=='B') {
  22836. $yadj3 = $this->LineWidth/2;
  22837. $xadj3 = -$this->LineWidth/2;
  22838. $wadj3 = $this->LineWidth;
  22839. }
  22840. if ($side=='R') {
  22841. $xadj3 = $this->LineWidth/2;
  22842. $yadj3 = -$this->LineWidth/2;
  22843. $hadj3 = $this->LineWidth;
  22844. }
  22845. }
  22846. else if ($side=='T') { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; $wadj3 = -$this->LineWidth*2; }
  22847. else if ($side=='L') { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; $hadj3 = -$this->LineWidth*2; }
  22848. else if ($side=='B' && $bSeparate) { $yadj3 = $this->LineWidth/2; $wadj3 = $this->LineWidth/2; }
  22849. else if ($side=='R' && $bSeparate) { $xadj3 = $this->LineWidth/2; $hadj3 = $this->LineWidth/2; }
  22850. else if ($side=='B') { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; }
  22851. else if ($side=='R') { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; }
  22852. }
  22853. else {
  22854. $nc = $this->_lightenColor($details[$side]['c']);
  22855. if ($bSeparate && $cort=='table') {
  22856. if ($side=='T') {
  22857. $yadj3 = $this->LineWidth/2;
  22858. $xadj3 = -$this->LineWidth/2;
  22859. $wadj3 = $this->LineWidth;
  22860. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  22861. $xadj3 += $this->LineWidth; $wadj3 -= $this->LineWidth;
  22862. }
  22863. }
  22864. if ($side=='L') {
  22865. $xadj3 = $this->LineWidth/2;
  22866. $yadj3 = -$this->LineWidth/2;
  22867. $hadj3 = $this->LineWidth;
  22868. if ($this->issetBorder($bord, _BORDER_TOP)) {
  22869. $yadj3 += $this->LineWidth; $hadj3 -= $this->LineWidth;
  22870. }
  22871. }
  22872. if ($side=='B') {
  22873. $yadj3 = $this->LineWidth/2;
  22874. $xadj3 = -$this->LineWidth/2;
  22875. $wadj3 = $this->LineWidth;
  22876. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  22877. $xadj3 += $this->LineWidth; $wadj3 -= $this->LineWidth;
  22878. }
  22879. }
  22880. if ($side=='R') {
  22881. $xadj3 = $this->LineWidth/2;
  22882. $yadj3 = -$this->LineWidth/2;
  22883. $hadj3 = $this->LineWidth;
  22884. if ($this->issetBorder($bord, _BORDER_TOP)) {
  22885. $yadj3 += $this->LineWidth; $hadj3 -= $this->LineWidth;
  22886. }
  22887. }
  22888. }
  22889. else if ($side=='T') { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; }
  22890. else if ($side=='L') { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; }
  22891. else if ($side=='B' && $bSeparate) { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; }
  22892. else if ($side=='R' && $bSeparate) { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; }
  22893. else if ($side=='B') { $yadj3 = $this->LineWidth/2; $xadj3 = -$this->LineWidth/2; $wadj3 = $this->LineWidth; }
  22894. else if ($side=='R') { $xadj3 = $this->LineWidth/2; $yadj3 = -$this->LineWidth/2; $hadj3 = $this->LineWidth; }
  22895. }
  22896. if ($bSeparate) {
  22897. $cellBorderOverlay[] = array(
  22898. 'x' => $lx1 + $xadj + $xadj3,
  22899. 'y' => $ly1 + $yadj + $yadj3,
  22900. 'x2' => $lx2 - $xadj2 + $xadj3 + $wadj3,
  22901. 'y2' => $ly2 - $yadj2 + $yadj3 + $hadj3,
  22902. 'col' => $nc,
  22903. 'lw' => $this->LineWidth,
  22904. );
  22905. }
  22906. else {
  22907. $this->SetDColor($nc);
  22908. $this->Line($lx1 + $xadj + $xadj3, $ly1 + $yadj + $yadj3, $lx2 - $xadj2 + $xadj3 + $wadj3, $ly2 - $yadj2 + $yadj3 + $hadj3);
  22909. }
  22910. }
  22911. }
  22912. else {
  22913. /*-- END TABLES-ADVANCED-BORDERS --*/
  22914. if ($details[$side]['style'] == 'dashed') {
  22915. $dashsize = 2; // final dash will be this + 1*linewidth
  22916. $dashsizek = 1.5; // ratio of Dash/Blank
  22917. $this->SetDash($dashsize,($dashsize/$dashsizek)+($this->LineWidth*2));
  22918. }
  22919. else if ($details[$side]['style'] == 'dotted') {
  22920. $this->SetLineJoin(1);
  22921. $this->SetLineCap(1);
  22922. $this->SetDash(0.001,($this->LineWidth*2));
  22923. }
  22924. if ($details[$side]['c']) {
  22925. $this->SetDColor($details[$side]['c']);
  22926. }
  22927. else { $this->SetDColor($this->ConvertColor(0)); }
  22928. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  22929. /*-- TABLES-ADVANCED-BORDERS --*/
  22930. }
  22931. /*-- END TABLES-ADVANCED-BORDERS --*/
  22932. // Reset Corners
  22933. $this->SetDash();
  22934. //BUTT style line cap
  22935. $this->SetLineCap(2);
  22936. }
  22937. }
  22938. if ($bSeparate && count($cellBorderOverlay)) {
  22939. foreach($cellBorderOverlay AS $cbo) {
  22940. $this->SetLineWidth($cbo['lw']);
  22941. $this->SetDColor($cbo['col']);
  22942. $this->Line($cbo['x'], $cbo['y'], $cbo['x2'], $cbo['y2']);
  22943. }
  22944. }
  22945. // $this->SetLineWidth($oldlinewidth);
  22946. // $this->SetDColor($this->ConvertColor(0));
  22947. }
  22948. }
  22949. /*-- TABLES --*/
  22950. /*-- TABLES-ADVANCED-BORDERS --*/
  22951. function _lightenColor($c) {
  22952. // mPDF 5.3.74
  22953. if (is_array($c)) { die('Color error in _lightencolor'); }
  22954. if ($c{0}==3 || $c{0}==5) { // RGB
  22955. list($h,$s,$l) = $this->rgb2hsl(ord($c{1})/255,ord($c{2})/255,ord($c{3})/255);
  22956. $l += ((1 - $l)*0.8);
  22957. list($r,$g,$b) = $this->hsl2rgb($h,$s,$l);
  22958. $ret = array(3,$r,$g,$b);
  22959. }
  22960. else if ($c{0}==4 || $c{0}==6) { // CMYK
  22961. $ret = array(4, max(0,(ord($c{1})-20)), max(0,(ord($c{2})-20)), max(0,(ord($c{3})-20)), max(0,(ord($c{4})-20)) );
  22962. }
  22963. else if ($c{0}==1) { // Grayscale
  22964. $ret = array(1,min(255,(ord($c{1})+32)));
  22965. }
  22966. $c = array_pad($ret, 6, 0);
  22967. $cstr = pack("a1ccccc", $c[0], ($c[1] & 0xFF), ($c[2] & 0xFF), ($c[3] & 0xFF), ($c[4] & 0xFF), ($c[5] & 0xFF) );
  22968. return $cstr;
  22969. }
  22970. function _darkenColor($c) {
  22971. if (is_array($c)) { die('Color error in _darkenColor'); }
  22972. // mPDF 5.3.74
  22973. if ($c{0}==3 || $c{0}==5) { // RGB
  22974. list($h,$s,$l) = $this->rgb2hsl(ord($c{1})/255,ord($c{2})/255,ord($c{3})/255);
  22975. $s *= 0.25;
  22976. $l *= 0.75;
  22977. list($r,$g,$b) = $this->hsl2rgb($h,$s,$l);
  22978. $ret = array(3,$r,$g,$b);
  22979. }
  22980. else if ($c{0}==4 || $c{0}==6) { // CMYK
  22981. $ret = array(4, min(100,(ord($c{1})+20)), min(100,(ord($c{2})+20)), min(100,(ord($c{3})+20)), min(100,(ord($c{4})+20)) );
  22982. }
  22983. else if ($c{0}==1) { // Grayscale
  22984. $ret = array(1,max(0,(ord($c{1})-32)));
  22985. }
  22986. $c = array_pad($ret, 6, 0);
  22987. $cstr = pack("a1ccccc", $c[0], ($c[1] & 0xFF), ($c[2] & 0xFF), ($c[3] & 0xFF), ($c[4] & 0xFF), ($c[5] & 0xFF) );
  22988. return $cstr;
  22989. }
  22990. /*-- END TABLES-ADVANCED-BORDERS --*/
  22991. function setBorder(&$var, $flag, $set = true) {
  22992. $flag = intval($flag);
  22993. if ($set) { $set = true; }
  22994. $var = intval($var);
  22995. $var = $set ? ($var | $flag) : ($var & ~$flag);
  22996. }
  22997. function issetBorder($var, $flag) {
  22998. $flag = intval($flag);
  22999. $var = intval($var);
  23000. return (($var & $flag) == $flag);
  23001. }
  23002. function _table2cellBorder(&$tableb, &$cbdb, &$cellb, $bval) {
  23003. if ($tableb && $tableb['w'] > $cbdb['w']) {
  23004. $cbdb = $tableb;
  23005. $this->setBorder($cellb, $bval);
  23006. }
  23007. else if ($tableb && $tableb['w'] == $cbdb['w']
  23008. && array_search($tableb['style'],$this->borderstyles) > array_search($cbdb['style'],$this->borderstyles)) {
  23009. $cbdb = $tableb;
  23010. $this->setBorder($cellb, $bval);
  23011. }
  23012. }
  23013. // FIX BORDERS ********************************************
  23014. function _fixTableBorders(&$table){
  23015. // mPDF 5.3.79
  23016. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  23017. else { $fh = null; }
  23018. if (!$table['borders_separate'] && $table['border_details']['L']['w']) {
  23019. $table['max_cell_border_width']['L'] = $table['border_details']['L']['w'];
  23020. }
  23021. if (!$table['borders_separate'] && $table['border_details']['R']['w']) {
  23022. $table['max_cell_border_width']['R'] = $table['border_details']['R']['w'];
  23023. }
  23024. if (!$table['borders_separate'] && $table['border_details']['T']['w']) {
  23025. $table['max_cell_border_width']['T'] = $table['border_details']['T']['w'];
  23026. }
  23027. if (!$table['borders_separate'] && $table['border_details']['B']['w']) {
  23028. $table['max_cell_border_width']['B'] = $table['border_details']['B']['w'];
  23029. }
  23030. if ($this->simpleTables) { return; }
  23031. $cells = &$table['cells'];
  23032. $numcols = $table['nc'];
  23033. $numrows = $table['nr'];
  23034. /*-- TABLES-ADVANCED-BORDERS --*/
  23035. // mPDF 5.3.64
  23036. if (isset($table['topntail']) && $table['topntail']) { $tntborddet = $this->border_details($table['topntail']); }
  23037. if (isset($table['thead-underline']) && $table['thead-underline']) { $thuborddet = $this->border_details($table['thead-underline']); }
  23038. /*-- END TABLES-ADVANCED-BORDERS --*/
  23039. for( $i = 0 ; $i < $numrows ; $i++ ) { //Rows
  23040. for( $j = 0 ; $j < $numcols ; $j++ ) { //Columns
  23041. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  23042. // mPDF 5.3.79
  23043. if ($this->cacheTables) {
  23044. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  23045. }
  23046. else
  23047. $cell = &$cells[$i][$j];
  23048. if ($this->packTableData) { // includes $this->cacheTables
  23049. $cbord = $this->_unpackCellBorder($cell['borderbin']);
  23050. }
  23051. else {
  23052. $cbord = &$cells[$i][$j];
  23053. }
  23054. if (!$cbord['border'] && isset($table['border']) && $table['border'] && $this->table_border_attr_set) {
  23055. $cbord['border'] = $table['border'];
  23056. $cbord['border_details'] = $table['border_details'];
  23057. }
  23058. if (isset($cell['colspan']) && $cell['colspan']>1) { $ccolsp = $cell['colspan']; }
  23059. else { $ccolsp = 1; }
  23060. if (isset($cell['rowspan']) && $cell['rowspan']>1) { $crowsp = $cell['rowspan']; }
  23061. else { $crowsp = 1; }
  23062. $cbord['border_details']['cellposdom'] = ((($i+1)/$numrows) / 10000 ) + ((($j+1)/$numcols) / 10 );
  23063. // Inherit Cell border from Table border
  23064. if ($this->table_border_css_set && !$table['borders_separate']) {
  23065. if ($i == 0) {
  23066. $this->_table2cellBorder($table['border_details']['T'], $cbord['border_details']['T'], $cbord['border'], _BORDER_TOP);
  23067. }
  23068. if ($i == ($numrows-1) || ($i+$crowsp) == ($numrows) ) {
  23069. $this->_table2cellBorder($table['border_details']['B'], $cbord['border_details']['B'], $cbord['border'], _BORDER_BOTTOM);
  23070. }
  23071. if ($j == 0) {
  23072. $this->_table2cellBorder($table['border_details']['L'], $cbord['border_details']['L'], $cbord['border'], _BORDER_LEFT);
  23073. }
  23074. if ($j == ($numcols-1) || ($j+$ccolsp) == ($numcols) ) {
  23075. $this->_table2cellBorder($table['border_details']['R'], $cbord['border_details']['R'], $cbord['border'], _BORDER_RIGHT);
  23076. }
  23077. }
  23078. /*-- TABLES-ADVANCED-BORDERS --*/
  23079. $fixbottom = true; // mPDF 5.3.64
  23080. if (isset($table['topntail']) && $table['topntail']) {
  23081. if ($i == 0) {
  23082. $cbord['border_details']['T'] = $tntborddet;
  23083. $this->setBorder($cbord['border'], _BORDER_TOP);
  23084. }
  23085. if ($this->tableLevel==1 && $table['headernrows']>0 && $i == $table['headernrows']-1) { // mPDF 5.3.62 // mPDF 5.3.76
  23086. $cbord['border_details']['B'] = $tntborddet;
  23087. $this->setBorder($cbord['border'], _BORDER_BOTTOM);
  23088. $fixbottom = false; // mPDF 5.3.64
  23089. }
  23090. else if ($this->tableLevel==1 && $table['headernrows']>0 && $i == $table['headernrows']) { // mPDF 5.3.62
  23091. if (!$table['borders_separate']) {
  23092. $cbord['border_details']['T'] = $tntborddet;
  23093. $this->setBorder($cbord['border'], _BORDER_TOP);
  23094. }
  23095. }
  23096. if ($this->tableLevel==1 && $table['footernrows']>0 && $i == ($numrows-$table['footernrows']-1)) { // mPDF 5.3.62
  23097. if (!$table['borders_separate']) {
  23098. $cbord['border_details']['B'] = $tntborddet;
  23099. $this->setBorder($cbord['border'], _BORDER_BOTTOM);
  23100. $fixbottom = false; // mPDF 5.3.64
  23101. }
  23102. }
  23103. else if ($this->tableLevel==1 && $table['footernrows']>0 && $i == ($numrows-$table['footernrows'])) { // mPDF 5.3.62
  23104. $cbord['border_details']['T'] = $tntborddet;
  23105. $this->setBorder($cbord['border'], _BORDER_TOP);
  23106. }
  23107. if ($this->tabletheadjustfinished) { // $this->tabletheadjustfinished called from tableheader
  23108. if (!$table['borders_separate']) {
  23109. $cbord['border_details']['T'] = $tntborddet;
  23110. $this->setBorder($cbord['border'], _BORDER_TOP);
  23111. }
  23112. }
  23113. if ($i == ($numrows-1) || ($i+$crowsp) == ($numrows) ) {
  23114. $cbord['border_details']['B'] = $tntborddet;
  23115. $this->setBorder($cbord['border'], _BORDER_BOTTOM);
  23116. }
  23117. }
  23118. if (isset($table['thead-underline']) && $table['thead-underline']) {
  23119. if ($table['borders_separate']) {
  23120. if ($i == 0) {
  23121. $cbord['border_details']['B'] = $thuborddet;
  23122. $this->setBorder($cbord['border'], _BORDER_BOTTOM);
  23123. $fixbottom = false; // mPDF 5.3.64
  23124. }
  23125. }
  23126. else {
  23127. if ($this->tableLevel==1 && $table['headernrows']>0 && $i == $table['headernrows']-1) { // mPDF 5.3.62
  23128. $cbord['border_details']['T'] = $thuborddet;
  23129. $this->setBorder($cbord['border'], _BORDER_TOP);
  23130. }
  23131. else if ($this->tabletheadjustfinished) { // $this->tabletheadjustfinished called from tableheader
  23132. $cbord['border_details']['T'] = $thuborddet;
  23133. $this->setBorder($cbord['border'], _BORDER_TOP);
  23134. }
  23135. }
  23136. }
  23137. // Collapse Border - Algorithm for conflicting borders
  23138. // Hidden >> Width >> double>solid>dashed>dotted... >> style set on cell>table >> top/left>bottom/right
  23139. // Do not turn off border which is overridden
  23140. // Needed for page break for TOP/BOTTOM both to be defined in Collapsed borders
  23141. // Means it is painted twice. (Left/Right can still disable overridden border)
  23142. if (!$table['borders_separate']) { // mPDF 5.3.64
  23143. if (($i < ($numrows-1) || ($i+$crowsp) < $numrows ) && $fixbottom ) { // Bottom // mPDF 5.3.64
  23144. for ($cspi = 0; $cspi<$ccolsp; $cspi++) {
  23145. // already defined Top for adjacent cell below
  23146. if (isset($cells[($i+$crowsp)][$j+$cspi])) {
  23147. if ($this->packTableData) {
  23148. // mPDF 5.3.79
  23149. if ($this->cacheTables) {
  23150. $adjc = $this->_uncacheCell($table['cells'][$i+$crowsp][$j+$cspi], '', $fh);
  23151. }
  23152. else { $adjc = $cells[($i+$crowsp)][$j+$cspi]; }
  23153. $celladj = $this->_unpackCellBorder($adjc['borderbin']);
  23154. }
  23155. else { $celladj =& $cells[($i+$crowsp)][$j+$cspi]; }
  23156. }
  23157. else { $celladj = false; }
  23158. if ($celladj && $celladj['border_details']['T']['s'] == 1) {
  23159. $csadj = $celladj['border_details']['T']['w'];
  23160. $csthis = $cbord['border_details']['B']['w'];
  23161. // Hidden
  23162. if ($cbord['border_details']['B']['style']=='hidden') {
  23163. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  23164. $this->setBorder($celladj['border'] , _BORDER_TOP, false);
  23165. $this->setBorder($cbord['border'] , _BORDER_BOTTOM , false);
  23166. }
  23167. else if ($celladj['border_details']['T']['style']=='hidden') {
  23168. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  23169. $this->setBorder($cbord['border'] , _BORDER_BOTTOM , false);
  23170. $this->setBorder($celladj['border'] , _BORDER_TOP, false);
  23171. }
  23172. // Width
  23173. else if ($csthis > $csadj) {
  23174. if (!isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) || (isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) && $cells[($i+$crowsp)][$j+$cspi]['colspan']<2)) { // don't overwrite bordering cells that span
  23175. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  23176. $this->setBorder($cbord['border'] , _BORDER_BOTTOM);
  23177. }
  23178. }
  23179. else if ($csadj > $csthis) {
  23180. if ($ccolsp < 2) { // don't overwrite this cell if it spans
  23181. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  23182. $this->setBorder($celladj['border'] , _BORDER_TOP);
  23183. }
  23184. }
  23185. // double>solid>dashed>dotted...
  23186. else if (array_search($cbord['border_details']['B']['style'],$this->borderstyles) > array_search($celladj['border_details']['T']['style'],$this->borderstyles)) {
  23187. if (!isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) || (isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) && $cells[($i+$crowsp)][$j+$cspi]['colspan']<2)) { // don't overwrite bordering cells that span
  23188. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  23189. $this->setBorder($cbord['border'] , _BORDER_BOTTOM );
  23190. }
  23191. }
  23192. else if (array_search($celladj['border_details']['T']['style'],$this->borderstyles) > array_search($cbord['border_details']['B']['style'],$this->borderstyles)) {
  23193. if ($ccolsp < 2) { // don't overwrite this cell if it spans
  23194. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  23195. $this->setBorder($celladj['border'] , _BORDER_TOP);
  23196. }
  23197. }
  23198. // Style set on cell vs. table
  23199. else if ($celladj['border_details']['T']['dom'] > $cbord['border_details']['B']['dom']) {
  23200. if ($ccolsp < 2) { // don't overwrite this cell if it spans
  23201. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  23202. $this->setBorder($celladj['border'] , _BORDER_TOP);
  23203. }
  23204. }
  23205. // Style set on cell vs. table - OR - LEFT/TOP (cell) in preference to BOTTOM/RIGHT
  23206. else {
  23207. if (!isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) || (isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) && $cells[($i+$crowsp)][$j+$cspi]['colspan']<2)) { // don't overwrite bordering cells that span
  23208. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  23209. $this->setBorder($cbord['border'] , _BORDER_BOTTOM );
  23210. }
  23211. }
  23212. }
  23213. else if ($celladj) {
  23214. if (!isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) || (isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) && $cells[($i+$crowsp)][$j+$cspi]['colspan']<2)) { // don't overwrite bordering cells that span
  23215. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  23216. }
  23217. }
  23218. // mPDF 5.3.79
  23219. if ($celladj && $this->packTableData) {
  23220. $celladj['borderbin'] = $this->_packCellBorder($celladj);
  23221. unset($celladj['border']);
  23222. unset($celladj['border_details']);
  23223. }
  23224. if ($this->cacheTables) {
  23225. $this->_cacheUpdateBorder($celladj, $fh, $table['cells'][$i+$crowsp][$j+$cspi]);
  23226. }
  23227. unset($celladj);
  23228. }
  23229. }
  23230. if ($j < ($numcols-1) || ($j+$ccolsp) < $numcols ) { // Right-Left
  23231. for ($cspi = 0; $cspi<$crowsp; $cspi++) {
  23232. // already defined Left for adjacent cell to R
  23233. if (isset($cells[($i+$cspi)][$j+$ccolsp])) {
  23234. if ($this->packTableData) {
  23235. // mPDF 5.3.79
  23236. if ($this->cacheTables) {
  23237. $adjc = $this->_uncacheCell($table['cells'][$i+$cspi][$j+$ccolsp], '', $fh);
  23238. }
  23239. else { $adjc = $cells[($i+$cspi)][$j+$ccolsp]; }
  23240. $celladj = $this->_unpackCellBorder($adjc['borderbin']);
  23241. }
  23242. else { $celladj =& $cells[$i+$cspi][$j+$ccolsp]; }
  23243. }
  23244. else { $celladj = false; }
  23245. if ($celladj && $celladj['border_details']['L']['s'] == 1) {
  23246. $csadj = $celladj['border_details']['L']['w'];
  23247. $csthis = $cbord['border_details']['R']['w'];
  23248. // Hidden
  23249. if ($cbord['border_details']['R']['style']=='hidden') {
  23250. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  23251. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  23252. $this->setBorder($cbord['border'] , _BORDER_RIGHT , false);
  23253. }
  23254. else if ($celladj['border_details']['L']['style']=='hidden') {
  23255. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  23256. $this->setBorder($cbord['border'] , _BORDER_RIGHT , false);
  23257. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  23258. }
  23259. // Width
  23260. else if ($csthis > $csadj) {
  23261. if (!isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) || (isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) && $cells[($i+$cspi)][$j+$ccolsp]['rowspan']<2)) { // don't overwrite bordering cells that span
  23262. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  23263. $this->setBorder($cbord['border'] , _BORDER_RIGHT);
  23264. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  23265. }
  23266. }
  23267. else if ($csadj > $csthis) {
  23268. if ($crowsp < 2) { // don't overwrite this cell if it spans
  23269. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  23270. $this->setBorder($cbord['border'] , _BORDER_RIGHT, false);
  23271. $this->setBorder($celladj['border'] , _BORDER_LEFT);
  23272. }
  23273. }
  23274. // double>solid>dashed>dotted...
  23275. else if (array_search($cbord['border_details']['R']['style'],$this->borderstyles) > array_search($celladj['border_details']['L']['style'],$this->borderstyles)) {
  23276. if (!isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) || (isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) && $cells[($i+$cspi)][$j+$ccolsp]['rowspan']<2)) { // don't overwrite bordering cells that span
  23277. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  23278. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  23279. $this->setBorder($cbord['border'] , _BORDER_RIGHT);
  23280. }
  23281. }
  23282. else if (array_search($celladj['border_details']['L']['style'],$this->borderstyles) > array_search($cbord['border_details']['R']['style'],$this->borderstyles)) {
  23283. if ($crowsp < 2) { // don't overwrite this cell if it spans
  23284. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  23285. $this->setBorder($cbord['border'] , _BORDER_RIGHT , false);
  23286. $this->setBorder($celladj['border'] , _BORDER_LEFT);
  23287. }
  23288. }
  23289. // Style set on cell vs. table
  23290. else if ($celladj['border_details']['L']['dom'] > $cbord['border_details']['R']['dom']) {
  23291. if ($crowsp < 2) { // don't overwrite this cell if it spans
  23292. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  23293. $this->setBorder($celladj['border'] , _BORDER_LEFT);
  23294. }
  23295. }
  23296. // Style set on cell vs. table - OR - LEFT/TOP (cell) in preference to BOTTOM/RIGHT
  23297. else {
  23298. if (!isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) || (isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) && $cells[($i+$cspi)][$j+$ccolsp]['rowspan']<2)) { // don't overwrite bordering cells that span
  23299. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  23300. $this->setBorder($cbord['border'] , _BORDER_RIGHT);
  23301. }
  23302. }
  23303. }
  23304. else if ($celladj) {
  23305. // if right-cell border is not set
  23306. if (!isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) || (isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) && $cells[($i+$cspi)][$j+$ccolsp]['rowspan']<2)) { // don't overwrite bordering cells that span
  23307. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  23308. }
  23309. }
  23310. // mPDF 5.3.79
  23311. if ($celladj && $this->packTableData) {
  23312. $celladj['borderbin'] = $this->_packCellBorder($celladj);
  23313. unset($celladj['border']);
  23314. unset($celladj['border_details']);
  23315. }
  23316. if ($this->cacheTables) {
  23317. $this->_cacheUpdateBorder($celladj, $fh, $table['cells'][$i+$cspi][$j+$ccolsp]);
  23318. }
  23319. unset($celladj);
  23320. }
  23321. }
  23322. }
  23323. // Set maximum cell border width meeting at LRTB edges of cell - used for extended cell border
  23324. // ['border_details']['mbw']['LT'] = meeting border width - Left border - Top end
  23325. if (!$table['borders_separate']) {
  23326. $cbord['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['BL'], $cbord['border_details']['L']['w']);
  23327. $cbord['border_details']['mbw']['BR'] = max($cbord['border_details']['mbw']['BR'], $cbord['border_details']['R']['w']);
  23328. $cbord['border_details']['mbw']['RT'] = max($cbord['border_details']['mbw']['RT'], $cbord['border_details']['T']['w']);
  23329. $cbord['border_details']['mbw']['RB'] = max($cbord['border_details']['mbw']['RB'], $cbord['border_details']['B']['w']);
  23330. $cbord['border_details']['mbw']['TL'] = max($cbord['border_details']['mbw']['TL'], $cbord['border_details']['L']['w']);
  23331. $cbord['border_details']['mbw']['TR'] = max($cbord['border_details']['mbw']['TR'], $cbord['border_details']['R']['w']);
  23332. $cbord['border_details']['mbw']['LT'] = max($cbord['border_details']['mbw']['LT'], $cbord['border_details']['T']['w']);
  23333. $cbord['border_details']['mbw']['LB'] = max($cbord['border_details']['mbw']['LB'], $cbord['border_details']['B']['w']);
  23334. if (($i+$crowsp) < $numrows && isset($cells[$i+$crowsp][$j])) { // Has Bottom adjoining cell
  23335. if ($this->packTableData) {
  23336. // mPDF 5.3.79
  23337. if ($this->cacheTables) {
  23338. $adjc = $this->_uncacheCell($table['cells'][$i+$crowsp][$j], '', $fh);
  23339. }
  23340. else { $adjc = $cells[$i+$crowsp][$j]; }
  23341. $celladj = $this->_unpackCellBorder($adjc['borderbin']);
  23342. }
  23343. else { $celladj =& $cells[$i+$crowsp][$j]; }
  23344. $cbord['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['BL'], $celladj['border_details']['L']['w'], $celladj['border_details']['mbw']['TL']);
  23345. $cbord['border_details']['mbw']['BR'] = max($cbord['border_details']['mbw']['BR'], $celladj['border_details']['R']['w'], $celladj['border_details']['mbw']['TR']);
  23346. $cbord['border_details']['mbw']['LB'] = max($cbord['border_details']['mbw']['LB'], $celladj['border_details']['mbw']['LT']);
  23347. $cbord['border_details']['mbw']['RB'] = max($cbord['border_details']['mbw']['RB'], $celladj['border_details']['mbw']['RT']);
  23348. unset($celladj);
  23349. }
  23350. if (($j+$ccolsp) < $numcols && isset($cells[$i][$j+$ccolsp])) { // Has Right adjoining cell
  23351. if ($this->packTableData) {
  23352. // mPDF 5.3.79
  23353. if ($this->cacheTables) {
  23354. $adjc = $this->_uncacheCell($table['cells'][$i][$j+$ccolsp], '', $fh);
  23355. }
  23356. else { $adjc = $cells[$i][$j+$ccolsp]; }
  23357. $celladj = $this->_unpackCellBorder($adjc['borderbin']);
  23358. }
  23359. else { $celladj =& $cells[$i][$j+$ccolsp]; }
  23360. $cbord['border_details']['mbw']['RT'] = max($cbord['border_details']['mbw']['RT'], $celladj['border_details']['T']['w'], $celladj['border_details']['mbw']['LT']);
  23361. $cbord['border_details']['mbw']['RB'] = max($cbord['border_details']['mbw']['RB'], $celladj['border_details']['B']['w'], $celladj['border_details']['mbw']['LB']);
  23362. $cbord['border_details']['mbw']['TR'] = max($cbord['border_details']['mbw']['TR'], $celladj['border_details']['mbw']['TL']);
  23363. $cbord['border_details']['mbw']['BR'] = max($cbord['border_details']['mbw']['BR'], $celladj['border_details']['mbw']['BL']);
  23364. unset($celladj);
  23365. }
  23366. if ($i > 0 && isset($cells[$i-1][$j]) && (($this->packTableData && $cells[$i-1][$j]['borderbin']) || $cells[$i-1][$j]['border'])) { // Has Top adjoining cell
  23367. if ($this->packTableData) {
  23368. // mPDF 5.3.79
  23369. if ($this->cacheTables) {
  23370. $adjc = $this->_uncacheCell($table['cells'][$i-1][$j], '', $fh);
  23371. }
  23372. else { $adjc = $cells[$i-1][$j]; }
  23373. $celladj = $this->_unpackCellBorder($adjc['borderbin']);
  23374. }
  23375. else { $celladj =& $cells[$i-1][$j]; }
  23376. $cbord['border_details']['mbw']['TL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['L']['w'], $celladj['border_details']['mbw']['BL']);
  23377. $cbord['border_details']['mbw']['TR'] = max($cbord['border_details']['mbw']['TR'], $celladj['border_details']['R']['w'], $celladj['border_details']['mbw']['BR']);
  23378. $cbord['border_details']['mbw']['LT'] = max($cbord['border_details']['mbw']['LT'], $celladj['border_details']['mbw']['LB']);
  23379. $cbord['border_details']['mbw']['RT'] = max($cbord['border_details']['mbw']['RT'], $celladj['border_details']['mbw']['RB']);
  23380. if ($celladj['border_details']['mbw']['BL']) {
  23381. $celladj['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['mbw']['BL']);
  23382. }
  23383. if ($celladj['border_details']['mbw']['BR'] ) {
  23384. $celladj['border_details']['mbw']['BR'] = max($celladj['border_details']['mbw']['BR'], $cbord['border_details']['mbw']['TR']);
  23385. }
  23386. if ($this->packTableData) { $cells[$i-1][$j]['borderbin'] = $this->_packCellBorder($celladj); }
  23387. unset($celladj);
  23388. }
  23389. if ($j > 0 && isset($cells[$i][$j-1]) && (($this->packTableData && $cells[$i][$j-1]['borderbin']) || $cells[$i][$j-1]['border'])) { // Has Left adjoining cell
  23390. if ($this->packTableData) {
  23391. // mPDF 5.3.79
  23392. if ($this->cacheTables) {
  23393. $adjc = $this->_uncacheCell($table['cells'][$i][$j-1], '', $fh);
  23394. }
  23395. else { $adjc = $cells[$i][$j-1]; }
  23396. $celladj = $this->_unpackCellBorder($adjc['borderbin']);
  23397. }
  23398. else { $celladj =& $cells[$i][$j-1]; }
  23399. $cbord['border_details']['mbw']['LT'] = max($cbord['border_details']['mbw']['LT'], $celladj['border_details']['T']['w'], $celladj['border_details']['mbw']['RT']);
  23400. $cbord['border_details']['mbw']['LB'] = max($cbord['border_details']['mbw']['LB'], $celladj['border_details']['B']['w'], $celladj['border_details']['mbw']['RB']);
  23401. $cbord['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['BL'], $celladj['border_details']['mbw']['BR']);
  23402. $cbord['border_details']['mbw']['TL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['mbw']['TR']);
  23403. if ($celladj['border_details']['mbw']['RT']) {
  23404. $celladj['border_details']['mbw']['RT'] = max($celladj['border_details']['mbw']['RT'], $cbord['border_details']['mbw']['LT']);
  23405. }
  23406. if ($celladj['border_details']['mbw']['RB']) {
  23407. $celladj['border_details']['mbw']['RB'] = max($celladj['border_details']['mbw']['RB'], $cbord['border_details']['mbw']['LB']);
  23408. }
  23409. if ($this->packTableData) { $cells[$i][$j-1]['borderbin'] = $this->_packCellBorder($celladj); }
  23410. unset($celladj);
  23411. }
  23412. // Update maximum cell border width at LRTB edges of table - used for overall table width
  23413. if ($j == 0 && $cbord['border_details']['L']['w']) {
  23414. $table['max_cell_border_width']['L'] = max($table['max_cell_border_width']['L'],$cbord['border_details']['L']['w']);
  23415. }
  23416. if (($j == ($numcols-1) || ($j+$ccolsp) == $numcols ) && $cbord['border_details']['R']['w']) {
  23417. $table['max_cell_border_width']['R'] = max($table['max_cell_border_width']['R'],$cbord['border_details']['R']['w']);
  23418. }
  23419. if ($i == 0 && $cbord['border_details']['T']['w']) {
  23420. $table['max_cell_border_width']['T'] = max($table['max_cell_border_width']['T'],$cbord['border_details']['T']['w']);
  23421. }
  23422. if (($i == ($numrows-1) || ($i+$crowsp) == $numrows ) && $cbord['border_details']['B']['w']) {
  23423. $table['max_cell_border_width']['B'] = max($table['max_cell_border_width']['B'],$cbord['border_details']['B']['w']);
  23424. }
  23425. }
  23426. /*-- END TABLES-ADVANCED-BORDERS --*/
  23427. if ($this->packTableData) { $cell['borderbin'] = $this->_packCellBorder($cbord); }
  23428. // mPDF 5.3.79
  23429. if ($this->cacheTables) {
  23430. $this->_cacheUpdateBorder($cell, $fh, $table['cells'][$i][$j]);
  23431. }
  23432. unset($cbord );
  23433. unset($cell );
  23434. }
  23435. }
  23436. }
  23437. // mPDF 5.3.79
  23438. if ($this->cacheTables) { fclose($fh); }
  23439. unset($cell );
  23440. }
  23441. // END FIX BORDERS ************************************************************************************
  23442. function _reverseTableDir(&$table) {
  23443. // mPDF 5.3.79
  23444. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  23445. $cells = &$table['cells'];
  23446. $numcols = $table['nc'];
  23447. $numrows = $table['nr'];
  23448. for( $i = 0 ; $i < $numrows ; $i++ ) { //Rows
  23449. $row = array();
  23450. for( $j = ($numcols-1) ; $j >= 0 ; $j-- ) { //Columns
  23451. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  23452. // mPDF 5.3.79
  23453. if ($this->cacheTables) {
  23454. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  23455. }
  23456. else
  23457. $cell = &$cells[$i][$j];
  23458. $col = $numcols - $j - 1;
  23459. if (isset($cell['colspan']) && $cell['colspan'] > 1) { $col -= ($cell['colspan']-1); }
  23460. // Nested content
  23461. for ($n=0; $n < count($cell['textbuffer']); $n++) {
  23462. $t = $cell['textbuffer'][$n][0];
  23463. if (substr($t,0,19) == "\xbb\xa4\xactype=nestedtable") { // mPDF 5.3.79
  23464. $objattr = $this->_getObjAttr($t);
  23465. $objattr['col'] = $col;
  23466. $cell['textbuffer'][$n][0] = "\xbb\xa4\xactype=nestedtable,objattr=".serialize($objattr)."\xbb\xa4\xac";
  23467. $this->table[($this->tableLevel+1)][$objattr['nestedcontent']]['nestedpos'][1] = $col;
  23468. // mPDF 5.3.79
  23469. if ($this->cacheTables) {
  23470. $this->_cacheUpdateTxB($cell, $fh, $table['cells'][$i][$j]);
  23471. }
  23472. }
  23473. }
  23474. $row[$col] = $cells[$i][$j];
  23475. unset($cell); // mPDF 5.3.79
  23476. }
  23477. }
  23478. for($f=0; $f < $numcols; $f++) {
  23479. if (!isset($row[$f])) { $row[$f] = 0; } // mPDF 5.3.79
  23480. }
  23481. $table['cells'][$i] = $row;
  23482. }
  23483. // mPDF 5.3.79
  23484. if ($this->cacheTables) { fclose($fh); }
  23485. }
  23486. function _tableWrite(&$table, $split=false, $startrow=0, $startcol=0, $splitpg=0, $rety = 0){ // mPDF 5.3.36
  23487. $level = $table['level'];
  23488. $levelid = $table['levelid'];
  23489. $cells = &$table['cells'];
  23490. $numcols = $table['nc'];
  23491. $numrows = $table['nr'];
  23492. if ($this->ColActive && $level==1) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  23493. if (!$split || ($startrow==0 && $splitpg==0) || $startrow>0){ // mPDF 5.3.36
  23494. // TABLE TOP MARGIN
  23495. if ($table['margin']['T']) {
  23496. if (!$this->table_rotate && $level==1) {
  23497. $this->DivLn($table['margin']['T'],$this->blklvl,true,1); // collapsible
  23498. }
  23499. else {
  23500. $this->y += ($table['margin']['T']);
  23501. }
  23502. }
  23503. // Advance down page by half width of top border
  23504. if ($table['borders_separate']) {
  23505. // mPDF 5.3.36
  23506. if ($startrow>0 && (!isset($table['is_thead']) || count($table['is_thead'])==0))
  23507. $adv = $table['border_spacing_V']/2;
  23508. else
  23509. $adv = $table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2;
  23510. }
  23511. else {
  23512. $adv = $table['max_cell_border_width']['T']/2;
  23513. }
  23514. if (!$this->table_rotate && $level==1) { $this->DivLn($adv); }
  23515. else { $this->y += $adv; }
  23516. } // mPDF 5.3.36
  23517. if ($level==1) {
  23518. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w'];
  23519. $x0 = $this->x;
  23520. $y0 = $this->y;
  23521. $right = $x0 + $this->blk[$this->blklvl]['inner_width'];
  23522. $outerfilled = $this->y; // Keep track of how far down the outer DIV bgcolor is painted (NB rowspans)
  23523. $this->outerfilled = $this->y;
  23524. $this->colsums = array(); // mPDF 5.3.92
  23525. }
  23526. else {
  23527. $x0 = $this->x;
  23528. $y0 = $this->y;
  23529. $right = $x0 + $table['w'];
  23530. }
  23531. if ($this->table_rotate) {
  23532. $temppgwidth = $this->tbrot_maxw;
  23533. $this->PageBreakTrigger = $pagetrigger = $y0 + ($this->blk[$this->blklvl]['inner_width']);
  23534. if ($level==1) {
  23535. $this->tbrot_y0 = $this->y - $adv - $table['margin']['T'] ;
  23536. $this->tbrot_x0 = $this->x;
  23537. $this->tbrot_w = $table['w'];
  23538. if ($table['borders_separate']) { $this->tbrot_h = $table['margin']['T'] + $table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2; }
  23539. else { $this->tbrot_h = $table['margin']['T'] + $table['padding']['T'] + $table['max_cell_border_width']['T']; }
  23540. }
  23541. }
  23542. else {
  23543. $this->PageBreakTrigger = $pagetrigger = ($this->h - $this->bMargin);
  23544. if ($level==1) {
  23545. $temppgwidth = $this->blk[$this->blklvl]['inner_width'];
  23546. if (isset($table['a']) and ($table['w'] < $this->blk[$this->blklvl]['inner_width'])) {
  23547. if ($table['a']=='C') { $x0 += ((($right-$x0) - $table['w'])/2); }
  23548. else if ($table['a']=='R') { $x0 = $right - $table['w']; }
  23549. }
  23550. }
  23551. else {
  23552. $temppgwidth = $table['w'];
  23553. }
  23554. }
  23555. if(!isset($table['overflow'])) { $table['overflow'] = null; }
  23556. if ($table['overflow']=='hidden' && $level==1 && !$this->table_rotate && !$this->ColActive) {
  23557. //Bounding rectangle to clip
  23558. $this->tableClipPath = sprintf('q %.3F %.3F %.3F %.3F re W n',$x0*_MPDFK,$this->h*_MPDFK,$this->blk[$this->blklvl]['inner_width']*_MPDFK,-$this->h*_MPDFK);
  23559. $this->_out($this->tableClipPath);
  23560. }
  23561. else { $this->tableClipPath = ''; }
  23562. if ($table['borders_separate']) { $indent = $table['margin']['L'] + $table['border_details']['L']['w'] + $table['padding']['L'] + $table['border_spacing_H']/2; }
  23563. else { $indent = $table['margin']['L'] + $table['max_cell_border_width']['L']/2; }
  23564. $x0 += $indent;
  23565. $returny = 0;
  23566. $lastCol = 0; // mPDF 5.3.36
  23567. $tableheader = array();
  23568. $tablefooter = array();
  23569. $tableheaderrowheight = 0; // mPDF 5.3.36
  23570. $tablefooterrowheight = 0;
  23571. $footery = 0;
  23572. // mPD 3.0 Set the Page & Column where table starts
  23573. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  23574. $tablestartpage = 'EVEN';
  23575. }
  23576. else if (($this->mirrorMargins) && (($this->page)%2==1)) { // ODD
  23577. $tablestartpage = 'ODD';
  23578. }
  23579. else { $tablestartpage = ''; }
  23580. if ($this->ColActive) { $tablestartcolumn = $this->CurrCol; }
  23581. else { $tablestartcolumn = ''; }
  23582. // mPDF 5.3.79
  23583. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  23584. else { $fh = null; }
  23585. $y = $h = 0;
  23586. for( $i = 0; $i < $numrows ; $i++ ) { //Rows
  23587. if ($this->progressBar) { $this->UpdateProgressBar(7,intval(30 + ($i*40/$numrows)),' '); } // *PROGRESS-BAR*
  23588. if (isset($table['is_tfoot'][$i]) && $table['is_tfoot'][$i] && $level==1) {
  23589. $tablefooterrowheight += $table['hr'][$i];
  23590. // mPDF 5.3.36
  23591. $tablefooter[$i][0]['trbackground-images'] = $table['trbackground-images'][$i];
  23592. $tablefooter[$i][0]['trgradients'] = $table['trgradients'][$i];
  23593. $tablefooter[$i][0]['trbgcolor'] = $table['bgcolor'][$i];
  23594. for( $j = $startcol ; $j < $numcols ; $j++ ) { //Columns // mPDF 5.3.36
  23595. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  23596. // mPDF 5.3.79
  23597. if ($this->cacheTables) {
  23598. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  23599. }
  23600. else
  23601. $cell = &$cells[$i][$j];
  23602. // mPDF 5.3.36
  23603. if ($split) {
  23604. if ($table['colPg'][$j] != $splitpg) { continue; }
  23605. list($x,$w) = $this->_splitTableGetWidth($table, $i, $j, $fh);
  23606. $js = $j - $startcol;
  23607. }
  23608. else {
  23609. list($x,$w) = $this->_tableGetWidth($table, $i, $j, $fh);
  23610. $js = $j;
  23611. }
  23612. list($y,$h) = $this->_tableGetHeight($table, $i, $j, $fh);
  23613. $x += $x0;
  23614. $y += $y0;
  23615. //Get info of tfoot ==>> table footer
  23616. $tablefooter[$i][$js]['x'] = $x;
  23617. $tablefooter[$i][$js]['y'] = $y;
  23618. $tablefooter[$i][$js]['h'] = $h;
  23619. $tablefooter[$i][$js]['w'] = $w;
  23620. if (isset($cell['textbuffer'])) { $tablefooter[$i][$js]['textbuffer'] = $cell['textbuffer']; }
  23621. else { $tablefooter[$i][$js]['textbuffer'] = ''; }
  23622. $tablefooter[$i][$js]['a'] = $cell['a'];
  23623. $tablefooter[$i][$js]['R'] = $cell['R'];
  23624. $tablefooter[$i][$js]['va'] = $cell['va'];
  23625. $tablefooter[$i][$js]['mih'] = $cell['mih'];
  23626. $tablefooter[$i][$js]['gradient'] = $cell['gradient']; // *BACKGROUNDS*
  23627. $tablefooter[$i][$js]['background-image'] = $cell['background-image']; // *BACKGROUNDS*
  23628. //CELL FILL BGCOLOR
  23629. if (!$this->simpleTables){
  23630. if ($this->packTableData) {
  23631. $c = $this->_unpackCellBorder($cell['borderbin']);
  23632. $tablefooter[$i][$js]['border'] = $c['border'];
  23633. $tablefooter[$i][$js]['border_details'] = $c['border_details'];
  23634. }
  23635. else {
  23636. $tablefooter[$i][$js]['border'] = $cell['border'];
  23637. $tablefooter[$i][$js]['border_details'] = $cell['border_details'];
  23638. }
  23639. }
  23640. else if ($this->simpleTables){
  23641. $tablefooter[$i][$js]['border'] = $table['simple']['border'];
  23642. $tablefooter[$i][$js]['border_details'] = $table['simple']['border_details'];
  23643. }
  23644. $tablefooter[$i][$js]['bgcolor'] = $cell['bgcolor'];
  23645. $tablefooter[$i][$js]['padding'] = $cell['padding'];
  23646. $tablefooter[$i][$js]['rowspan'] = $cell['rowspan'];
  23647. $tablefooter[$i][$js]['colspan'] = $cell['colspan'];
  23648. }
  23649. }
  23650. }
  23651. }
  23652. if ($level==1) { $this->_out('___TABLE___BACKGROUNDS'.date('jY')); }
  23653. $tableheaderadj = 0;
  23654. $tablefooteradj = 0;
  23655. $tablestartpageno = $this->page;
  23656. //Draw Table Contents and Borders
  23657. for( $i = 0; $i < $numrows ; $i++ ) { //Rows
  23658. // mPDF 5.3.36
  23659. if ($split && $startrow > 0) {
  23660. $thnr = (isset($table['is_thead']) ? count($table['is_thead']) : 0);
  23661. if ($i >= $thnr && $i < $startrow) { continue; }
  23662. if ($i == $startrow){ $returny = $rety - $tableheaderrowheight; }
  23663. }
  23664. // Get Maximum row/cell height in row - including rowspan>1 + 1 overlapping
  23665. // mPDF 5.3.A7
  23666. $maxrowheight = $this->_tableGetMaxRowHeight($table, $i, $fh); // mPDF 5.3.6
  23667. $skippage = false;
  23668. $newpagestarted = false;
  23669. for( $j = $startcol ; $j < $numcols ; $j++ ) { //Columns // mPDF 5.3.36
  23670. // mPDF 5.3.36
  23671. if ($split) {
  23672. if ($table['colPg'][$j] > $splitpg) { break; }
  23673. $lastCol = $j;
  23674. }
  23675. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  23676. // mPDF 5.3.79
  23677. if ($this->cacheTables) {
  23678. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  23679. }
  23680. else
  23681. $cell = &$cells[$i][$j];
  23682. // mPDF 5.3.36
  23683. if ($split) {
  23684. $lastCol = $j + (isset($cell['colspan']) ? ($cell['colspan']-1) : 0) ;
  23685. list($x,$w) = $this->_splitTableGetWidth($table, $i, $j, $fh);
  23686. }
  23687. else { list($x,$w) = $this->_tableGetWidth($table, $i, $j, $fh); }
  23688. list($y,$h) = $this->_tableGetHeight($table, $i, $j, $fh);
  23689. $x += $x0;
  23690. $y += $y0;
  23691. $y -= $returny;
  23692. if ($table['borders_separate']) {
  23693. if (!empty($tablefooter) || $i == ($numrows-1) || (isset($cell['rowspan']) && ($i+$cell['rowspan']) == $numrows) || (!isset($cell['rowspan']) && ($i+1) == $numrows) ) {
  23694. $extra = $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  23695. //$extra = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  23696. }
  23697. else {
  23698. $extra = $table['border_spacing_V']/2;
  23699. }
  23700. }
  23701. else { $extra = $table['max_cell_border_width']['B']/2; }
  23702. // mPDF 5.3.36
  23703. if ($j==$startcol && ((($y + $maxrowheight + $extra ) > ($pagetrigger+0.001)) || (($this->keepColumns || !$this->ColActive) && !empty($tablefooter) && ($y + $maxrowheight + $tablefooterrowheight + $extra) > $pagetrigger) && ($this->tableLevel==1 && $i < ($numrows - $table['headernrows']))) && ($y0 >0 || $x0 > 0) && !$this->InFooter && $this->autoPageBreak ) { // mPDF 5.3.62 // mPDF 5.3.76
  23704. if (!$skippage) {
  23705. // mPDF 5.3.36
  23706. $finalSpread = true;
  23707. $firstSpread = true;
  23708. if ($split) {
  23709. for($t=$startcol; $t<$numcols; $t++) {
  23710. // Are there more columns to print on a next page?
  23711. if ($table['colPg'][$t] > $splitpg) {
  23712. $finalSpread = false;
  23713. break;
  23714. }
  23715. }
  23716. if ($startcol>0) { $firstSpread = false; }
  23717. }
  23718. if (($this->keepColumns || !$this->ColActive) && !empty($tablefooter) && $i > 0 ) {
  23719. $this->y = $y;
  23720. $ya = $this->y;
  23721. $this->TableHeaderFooter($tablefooter,$tablestartpage,$tablestartcolumn,'F',$level, $firstSpread, $finalSpread); // mPDF 5.3.36
  23722. if ($this->table_rotate) {
  23723. $this->tbrot_h += $this->y - $ya ;
  23724. }
  23725. $tablefooteradj = $this->y - $ya ;
  23726. }
  23727. $y -= $y0;
  23728. $returny += $y;
  23729. $oldcolumn = $this->CurrCol;
  23730. if ($this->AcceptPageBreak()) {
  23731. $newpagestarted = true;
  23732. $this->y = $y + $y0;
  23733. // Move down to account for border-spacing or
  23734. // extra half border width in case page breaks in middle
  23735. if($i>0 && !$this->table_rotate && $level==1 && !$this->ColActive) {
  23736. if ($table['borders_separate']) {
  23737. $adv = $table['border_spacing_V']/2;
  23738. // If table footer
  23739. if (($this->keepColumns || !$this->ColActive) && !empty($tablefooter) && $i > 0 ) {
  23740. $adv += ($table['padding']['B'] + $table['border_details']['B']['w']);
  23741. }
  23742. }
  23743. else {
  23744. $maxbwtop = 0;
  23745. $maxbwbottom = 0;
  23746. if (!$this->simpleTables){
  23747. if (!empty($tablefooter)) { $maxbwbottom = $table['max_cell_border_width']['B']; }
  23748. else {
  23749. $brow = $i-1;
  23750. for( $ctj = 0 ; $ctj < $numcols ; $ctj++ ) {
  23751. if (isset($cells[$brow][$ctj]) && $cells[$brow][$ctj]) {
  23752. // mPDF 5.3.79
  23753. if ($this->cacheTables) {
  23754. $cadj = $this->_uncacheCell($table['cells'][$brow][$ctj], '', $fh);
  23755. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cadj['borderbin']);
  23756. }
  23757. else if ($this->packTableData) {
  23758. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cells[$brow][$ctj]['borderbin']);
  23759. }
  23760. else {
  23761. $bb = $cells[$brow][$ctj]['border_details']['B']['w'];
  23762. }
  23763. $maxbwbottom = max($maxbwbottom , $bb);
  23764. }
  23765. }
  23766. }
  23767. if (!empty($tableheader)) { $maxbwtop = $table['max_cell_border_width']['T']; }
  23768. else {
  23769. $trow = $i-1;
  23770. for( $ctj = 0 ; $ctj < $numcols ; $ctj++ ) {
  23771. if (isset($cells[$trow][$ctj]) && $cells[$trow][$ctj]) {
  23772. // mPDF 5.3.79
  23773. if ($this->cacheTables) {
  23774. $cadj = $this->_uncacheCell($table['cells'][$trow][$ctj], '', $fh);
  23775. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cadj['borderbin']);
  23776. }
  23777. else if ($this->packTableData) {
  23778. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cells[$trow][$ctj]['borderbin']);
  23779. }
  23780. else {
  23781. $bt = $cells[$trow][$ctj]['border_details']['T']['w'];
  23782. }
  23783. $maxbwtop = max($maxbwtop , $bt);
  23784. }
  23785. }
  23786. }
  23787. }
  23788. else if ($this->simpleTables){
  23789. $maxbwtop = $table['simple']['border_details']['T']['w'];
  23790. $maxbwbottom = $table['simple']['border_details']['B']['w'];
  23791. }
  23792. $adv = $maxbwbottom /2;
  23793. }
  23794. $this->y += $adv;
  23795. }
  23796. // Rotated table split over pages - needs this->y for borders/backgrounds
  23797. if($i>0 && $this->table_rotate && $level==1) {
  23798. // $this->y = $y0 + $this->tbrot_w; // mPDF 5.3.62
  23799. }
  23800. if ($this->tableClipPath ) { $this->_out("Q"); }
  23801. $bx = $x0;
  23802. $by = $y0;
  23803. if ($table['borders_separate']) {
  23804. $bx -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['border_spacing_H']/2);
  23805. if ($tablestartpageno != $this->page) { // IF already broken across a previous pagebreak
  23806. $by += $table['max_cell_border_width']['T']/2;
  23807. if (empty($tableheader)) { $by -= ($table['border_spacing_V']/2); }
  23808. }
  23809. else {
  23810. $by -= ($table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2);
  23811. }
  23812. }
  23813. else if ($tablestartpageno != $this->page && !empty($tableheader)) { $by += $maxbwtop /2; }
  23814. $by -= $tableheaderadj;
  23815. $bh = $this->y - $by + $tablefooteradj;
  23816. if (!$table['borders_separate']) { $bh -= $adv ; }
  23817. // mPDF 5.3.36
  23818. if ($split) {
  23819. $bw = 0;
  23820. for($t=$startcol; $t<$numcols; $t++) {
  23821. if ($table['colPg'][$t] == $splitpg) { $bw += $table['wc'][$t]; }
  23822. if ($table['colPg'][$t] > $splitpg) { break; }
  23823. }
  23824. if ($table['borders_separate']) {
  23825. if ($firstSpread) {
  23826. $bw += $table['padding']['L'] + $table['border_details']['L']['w'] + $table['border_spacing_H'];
  23827. }
  23828. else {
  23829. $bx += ($table['padding']['L'] + $table['border_details']['L']['w']);
  23830. $bw += $table['border_spacing_H'];
  23831. }
  23832. if ($finalSpread) {
  23833. $bw += $table['padding']['R'] + $table['border_details']['R']['w']/2 + $table['border_spacing_H'];
  23834. }
  23835. }
  23836. }
  23837. else {
  23838. $bw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  23839. }
  23840. if (!$this->ColActive && ($i > 0 || $j > 0)) { // mPDF 5.3.36
  23841. if (isset($table['bgcolor'][-1])) {
  23842. $color = $this->ConvertColor($table['bgcolor'][-1]);
  23843. if ($color) {
  23844. if (!$table['borders_separate']) { $bh -= $table['max_cell_border_width']['B']/2; }
  23845. $this->tableBackgrounds[$level*9][] = array('gradient'=>false, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'col'=>$color);
  23846. }
  23847. }
  23848. /*-- BACKGROUNDS --*/
  23849. if (isset($table['gradient'])) {
  23850. $g = $this->grad->parseBackgroundGradient($table['gradient']);
  23851. if ($g) {
  23852. $this->tableBackgrounds[$level*9+1][] = array('gradient'=>true, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  23853. }
  23854. }
  23855. if (isset($table['background-image'])) {
  23856. if ($table['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $table['background-image']['gradient'] )) {
  23857. $g = $this->grad->parseMozGradient( $table['background-image']['gradient'] );
  23858. if ($g) {
  23859. $this->tableBackgrounds[$level*9+1][] = array('gradient'=>true, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  23860. }
  23861. }
  23862. else {
  23863. $image_id = $table['background-image']['image_id'];
  23864. $orig_w = $table['background-image']['orig_w'];
  23865. $orig_h = $table['background-image']['orig_h'];
  23866. $x_pos = $table['background-image']['x_pos'];
  23867. $y_pos = $table['background-image']['y_pos'];
  23868. $x_repeat = $table['background-image']['x_repeat'];
  23869. $y_repeat = $table['background-image']['y_repeat'];
  23870. $resize = $table['background-image']['resize'];
  23871. $opacity = $table['background-image']['opacity'];
  23872. $itype = $table['background-image']['itype'];
  23873. $this->tableBackgrounds[$level*9+2][] = array('x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>'', 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$itype);
  23874. }
  23875. }
  23876. /*-- END BACKGROUNDS --*/
  23877. }
  23878. // $this->AcceptPageBreak() has moved tablebuffer to $this->pages content
  23879. if ($this->tableBackgrounds) {
  23880. $s = $this->PrintTableBackgrounds();
  23881. if ($this->bufferoutput) {
  23882. $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->headerbuffer);
  23883. $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->headerbuffer );
  23884. }
  23885. else {
  23886. $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  23887. $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->pages[$this->page]);
  23888. }
  23889. $this->tableBackgrounds = array();
  23890. }
  23891. // mPDF 5.3.36
  23892. if ($split) {
  23893. if ($i == 0 && $j == 0) { $y0 = -1; }
  23894. else if ($finalSpread) {
  23895. $splitpg = 0;
  23896. $startcol = 0;
  23897. $startrow = $i;
  23898. }
  23899. else {
  23900. $splitpg++;
  23901. $startcol = $t;
  23902. $returny -= $y;
  23903. }
  23904. return array(false, $startrow, $startcol, $splitpg, $returny, $y0);
  23905. }
  23906. $this->AddPage($this->CurOrientation);
  23907. $this->_out('___TABLE___BACKGROUNDS'.date('jY'));
  23908. if ($this->tableClipPath ) { $this->_out($this->tableClipPath); }
  23909. // Added to correct for OddEven Margins
  23910. $x=$x +$this->MarginCorrection;
  23911. $x0=$x0 +$this->MarginCorrection;
  23912. // Move down to account for half of top border-spacing or
  23913. // extra half border width in case page was broken in middle
  23914. if($i>0 && !$this->table_rotate && $level==1 && $table['headernrows']==0) { // mPDF 5.3.62
  23915. if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2; }
  23916. else {
  23917. $maxbwtop = 0;
  23918. for( $ctj = 0 ; $ctj < $numcols ; $ctj++ ) {
  23919. if (isset($cells[$i][$ctj]) && $cells[$i][$ctj]) {
  23920. if (!$this->simpleTables){
  23921. // mPDF 5.3.79
  23922. if ($this->cacheTables) {
  23923. $celltj = $this->_uncacheCell($table['cells'][$i][$ctj], '', $fh);
  23924. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($celltj['borderbin']);
  23925. }
  23926. else if ($this->packTableData) {
  23927. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cells[$i][$ctj]['borderbin']);
  23928. }
  23929. else {
  23930. $bt = $cells[$i][$ctj]['border_details']['T']['w'];
  23931. }
  23932. $maxbwtop = max($maxbwtop, $bt);
  23933. }
  23934. else if ($this->simpleTables){
  23935. $maxbwtop = max($maxbwtop, $table['simple']['border_details']['T']['w']);
  23936. }
  23937. }
  23938. }
  23939. $adv = $maxbwtop /2;
  23940. }
  23941. $this->y += $adv;
  23942. }
  23943. if ($this->table_rotate) {
  23944. $this->tbrot_x0 = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w'];
  23945. if ($table['borders_separate']) { $this->tbrot_h = $table['margin']['T'] + $table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2; }
  23946. else { $this->tbrot_h = $table['margin']['T'] + $table['max_cell_border_width']['T'] ; }
  23947. $this->tbrot_y0 = $this->y;
  23948. $pagetrigger = $y0 - $tableheaderadj + ($this->blk[$this->blklvl]['inner_width']);
  23949. }
  23950. else {
  23951. $pagetrigger = $this->PageBreakTrigger;
  23952. }
  23953. if ($this->kwt_saved && $level==1) {
  23954. $this->kwt_moved = true;
  23955. }
  23956. // Disable Table header repeat if Keep Block together
  23957. if (!$this->keep_block_together && !empty($tableheader)) { // mPDF 5.3.62
  23958. $ya = $this->y;
  23959. $this->TableHeaderFooter($tableheader,$tablestartpage,$tablestartcolumn,'H',$level);
  23960. if ($this->table_rotate) {
  23961. $this->tbrot_h = $this->y - $ya ;
  23962. }
  23963. $tableheaderadj = $this->y - $ya ;
  23964. }
  23965. else if ($i==0 && !$this->keep_block_together && !$this->table_rotate && $level==1 && !$this->ColActive) {
  23966. // Advance down page
  23967. if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2 + $table['border_details']['T']['w'] + $table['padding']['T']; }
  23968. else { $adv = $table['max_cell_border_width']['T'] /2 ; }
  23969. if ($adv) {
  23970. if ($this->table_rotate) {
  23971. $this->y += ($adv);
  23972. }
  23973. else {
  23974. $this->DivLn($adv,$this->blklvl,true);
  23975. }
  23976. }
  23977. }
  23978. $outerfilled = 0;
  23979. $y = $y0 = $this->y;
  23980. }
  23981. /*-- COLUMNS --*/
  23982. // COLS
  23983. // COLUMN CHANGE
  23984. if ($this->CurrCol != $oldcolumn) {
  23985. // Added to correct for Columns
  23986. $x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  23987. $x0 += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  23988. if ($this->CurrCol == 0) { // just added a page - possibly with tableheader
  23989. $y0 = $this->y; // this->y0 is global used by Columns - $y0 is internal to tablewrite
  23990. }
  23991. else {
  23992. $y0 = $this->y0; // this->y0 is global used by Columns - $y0 is internal to tablewrite
  23993. }
  23994. $y = $y0;
  23995. $outerfilled = 0;
  23996. if ($this->CurrCol != 0 && ($this->keepColumns && $this->ColActive) && !empty($tableheader) && $i > 0 ) {
  23997. $this->x = $x;
  23998. $this->y = $y;
  23999. $this->TableHeaderFooter($tableheader,$tablestartpage,$tablestartcolumn,'H',$level);
  24000. $y0 = $y=$this->y;
  24001. }
  24002. }
  24003. /*-- END COLUMNS --*/
  24004. }
  24005. $skippage = true;
  24006. }
  24007. $this->x = $x;
  24008. $this->y = $y;
  24009. if ($this->kwt_saved && $level==1) {
  24010. $this->printkwtbuffer();
  24011. $x0 = $x = $this->x;
  24012. $y0 = $y = $this->y;
  24013. $this->kwt_moved = false;
  24014. $this->kwt_saved = false;
  24015. }
  24016. // Set the Page & Column where table actually starts
  24017. if ($i==0 && $j==0 && $level==1) {
  24018. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  24019. $tablestartpage = 'EVEN';
  24020. }
  24021. else if (($this->mirrorMargins) && (($this->page)%2==1)) { // ODD
  24022. $tablestartpage = 'ODD';
  24023. }
  24024. else { $tablestartpage = ''; }
  24025. $tablestartpageno = $this->page;
  24026. if ($this->ColActive) { $tablestartcolumn = $this->CurrCol; } // *COLUMNS*
  24027. }
  24028. //ALIGN
  24029. $align = $cell['a'];
  24030. /*-- COLUMNS --*/
  24031. // If outside columns, this is done in PaintDivBB
  24032. if ($this->ColActive) {
  24033. //OUTER FILL BGCOLOR of DIVS
  24034. if ($this->blklvl > 0 && ($j==0) && !$this->table_rotate && $level==1) {
  24035. $firstblockfill = $this->GetFirstBlockFill();
  24036. if ($firstblockfill && $this->blklvl >= $firstblockfill) {
  24037. $divh = $maxrowheight;
  24038. // Last row
  24039. if (isset($cell['rowspan']) && (($i == $numrows-1 && $cell['rowspan']<2) || ($cell['rowspan']>1 && ($i + $cell['rowspan']-1) == $numrows-1))) {
  24040. if ($table['borders_separate']) {
  24041. $adv = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  24042. }
  24043. else {
  24044. $adv = $table['margin']['B'] + $table['max_cell_border_width']['B']/2;
  24045. }
  24046. $divh += $adv; //last row: fill bottom half of bottom border (y advanced at end)
  24047. }
  24048. if (($this->y + $divh) > $outerfilled ) { // if not already painted by previous rowspan
  24049. $bak_x = $this->x;
  24050. $bak_y = $this->y;
  24051. if ($outerfilled > $this->y) {
  24052. $divh = ($this->y + $divh) - $outerfilled;
  24053. $this->y = $outerfilled;
  24054. }
  24055. $this->DivLn($divh,-3,false);
  24056. $outerfilled = $this->y + $divh;
  24057. // Reset current block fill
  24058. $bcor = $this->blk[$this->blklvl]['bgcolorarray'];
  24059. if ($bcor ) $this->SetFColor($bcor);
  24060. $this->x = $bak_x;
  24061. $this->y = $bak_y;
  24062. }
  24063. }
  24064. }
  24065. }
  24066. //TABLE BACKGROUND FILL BGCOLOR - for cellSpacing
  24067. if ($this->ColActive) {
  24068. if ($table['borders_separate']) {
  24069. $fill = isset($table['bgcolor'][-1]) ? $table['bgcolor'][-1] : 0;
  24070. if ($fill) {
  24071. $color = $this->ConvertColor($fill);
  24072. if ($color) {
  24073. $xadj = ($table['border_spacing_H']/2);
  24074. $yadj = ($table['border_spacing_V']/2);
  24075. $wadj = $table['border_spacing_H'];
  24076. $hadj = $table['border_spacing_V'];
  24077. if ($i == 0) { // Top
  24078. $yadj += $table['padding']['T'] + $table['border_details']['T']['w'] ;
  24079. $hadj += $table['padding']['T'] + $table['border_details']['T']['w'] ;
  24080. }
  24081. if ($j == 0) { // Left
  24082. $xadj += $table['padding']['L'] + $table['border_details']['L']['w'] ;
  24083. $wadj += $table['padding']['L'] + $table['border_details']['L']['w'] ;
  24084. }
  24085. if ($i == ($numrows-1) || (isset($cell['rowspan']) && ($i+$cell['rowspan']) == $numrows) || (!isset($cell['rowspan']) && ($i+1) == $numrows)) { // Bottom
  24086. $hadj += $table['padding']['B'] + $table['border_details']['B']['w'] ;
  24087. }
  24088. if ($j == ($numcols-1) || (isset($cell['colspan']) && ($j+$cell['colspan']) == $numcols) || (!isset($cell['colspan']) && ($j+1) == $numcols)) { // Right
  24089. $wadj += $table['padding']['R'] + $table['border_details']['R']['w'] ;
  24090. }
  24091. $this->SetFColor($color);
  24092. $this->Rect($x - $xadj, $y - $yadj, $w + $wadj, $h + $hadj, 'F');
  24093. }
  24094. }
  24095. }
  24096. }
  24097. /*-- END COLUMNS --*/
  24098. if ($table['empty_cells']!='hide' || !empty($cell['textbuffer']) || (isset($cell['nestedcontent']) && $cell['nestedcontent']) || !$table['borders_separate'] ) { $paintcell = true; }
  24099. else { $paintcell = false; }
  24100. //Set Borders
  24101. $bord = 0;
  24102. $bord_det = array();
  24103. if (!$this->simpleTables){
  24104. if ($this->packTableData) {
  24105. if ($cell['borderbin']) {
  24106. $c = $this->_unpackCellBorder($cell['borderbin']);
  24107. $bord = $c['border'];
  24108. $bord_det = $c['border_details'];
  24109. }
  24110. }
  24111. else if ($cell['border']) {
  24112. $bord = $cell['border'];
  24113. $bord_det = $cell['border_details'];
  24114. }
  24115. }
  24116. else if ($this->simpleTables){
  24117. if ($table['simple']['border']) {
  24118. $bord = $table['simple']['border'];
  24119. $bord_det = $table['simple']['border_details'];
  24120. }
  24121. }
  24122. //TABLE ROW OR CELL FILL BGCOLOR
  24123. $fill = 0;
  24124. if (isset($cell['bgcolor']) && $cell['bgcolor'] && $cell['bgcolor']!='transparent') {
  24125. $fill = $cell['bgcolor'];
  24126. $leveladj = 6;
  24127. }
  24128. else if (isset($table['bgcolor'][$i]) && $table['bgcolor'][$i] && $table['bgcolor'][$i]!='transparent') { // Row color
  24129. $fill = $table['bgcolor'][$i];
  24130. $leveladj = 3;
  24131. }
  24132. if ($fill && $paintcell) {
  24133. $color = $this->ConvertColor($fill);
  24134. if ($color) {
  24135. if ($table['borders_separate']) {
  24136. if ($this->ColActive) {
  24137. $this->SetFColor($color);
  24138. $this->Rect($x+ ($table['border_spacing_H']/2), $y+ ($table['border_spacing_V']/2), $w- $table['border_spacing_H'], $h- $table['border_spacing_V'], 'F');
  24139. }
  24140. else {
  24141. $this->tableBackgrounds[$level*9+$leveladj][] = array('gradient'=>false, 'x'=>($x + ($table['border_spacing_H']/2)), 'y'=>($y + ($table['border_spacing_V']/2)), 'w'=>($w - $table['border_spacing_H']), 'h'=>($h - $table['border_spacing_V']), 'col'=>$color);
  24142. }
  24143. }
  24144. else {
  24145. if ($this->ColActive) {
  24146. $this->SetFColor($color);
  24147. $this->Rect($x, $y, $w, $h, 'F');
  24148. }
  24149. else {
  24150. $this->tableBackgrounds[$level*9+$leveladj][] = array('gradient'=>false, 'x'=>$x, 'y'=>$y, 'w'=>$w, 'h'=>$h, 'col'=>$color);
  24151. }
  24152. }
  24153. }
  24154. }
  24155. /*-- BACKGROUNDS --*/
  24156. if (isset($cell['gradient']) && $cell['gradient'] && $paintcell){
  24157. $g = $this->grad->parseBackgroundGradient($cell['gradient']);
  24158. if ($g) {
  24159. if ($table['borders_separate']) {
  24160. $px = $x+ ($table['border_spacing_H']/2);
  24161. $py = $y+ ($table['border_spacing_V']/2);
  24162. $pw = $w- $table['border_spacing_H'];
  24163. $ph = $h- $table['border_spacing_V'];
  24164. }
  24165. else {
  24166. $px = $x;
  24167. $py = $y;
  24168. $pw = $w;
  24169. $ph = $h;
  24170. }
  24171. if ($this->ColActive) {
  24172. $this->grad->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']);
  24173. }
  24174. else {
  24175. $this->tableBackgrounds[$level*9+7][] = array('gradient'=>true, 'x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  24176. }
  24177. }
  24178. }
  24179. if (isset($cell['background-image']) && $paintcell) {
  24180. if ($cell['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $cell['background-image']['gradient'] )) {
  24181. $g = $this->grad->parseMozGradient( $cell['background-image']['gradient'] );
  24182. if ($g) {
  24183. if ($table['borders_separate']) {
  24184. $px = $x+ ($table['border_spacing_H']/2);
  24185. $py = $y+ ($table['border_spacing_V']/2);
  24186. $pw = $w- $table['border_spacing_H'];
  24187. $ph = $h- $table['border_spacing_V'];
  24188. }
  24189. else {
  24190. $px = $x;
  24191. $py = $y;
  24192. $pw = $w;
  24193. $ph = $h;
  24194. }
  24195. if ($this->ColActive) {
  24196. $this->grad->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']);
  24197. }
  24198. else {
  24199. $this->tableBackgrounds[$level*9+7][] = array('gradient'=>true, 'x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  24200. }
  24201. }
  24202. }
  24203. else if ($cell['background-image']['image_id']) { // Background pattern
  24204. $n = count($this->patterns)+1;
  24205. if ($table['borders_separate']) {
  24206. $px = $x+ ($table['border_spacing_H']/2);
  24207. $py = $y+ ($table['border_spacing_V']/2);
  24208. $pw = $w- $table['border_spacing_H'];
  24209. $ph = $h- $table['border_spacing_V'];
  24210. }
  24211. else {
  24212. $px = $x;
  24213. $py = $y;
  24214. $pw = $w;
  24215. $ph = $h;
  24216. }
  24217. if ($this->ColActive) {
  24218. list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this->_resizeBackgroundImage($cell['background-image']['orig_w'], $cell['background-image']['orig_h'], $pw, $ph, $cell['background-image']['resize'], $cell['background-image']['x_repeat'], $cell['background-image']['y_repeat']);
  24219. $this->patterns[$n] = array('x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'pgh'=>$this->h, 'image_id'=>$cell['background-image']['image_id'], 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$cell['background-image']['x_pos'] , 'y_pos'=>$cell['background-image']['y_pos'] , 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat);
  24220. if ($cell['background-image']['opacity']>0 && $cell['background-image']['opacity']<1) { $opac = $this->SetAlpha($cell['background-image']['opacity'],'Normal',true); }
  24221. else { $opac = ''; }
  24222. $this->_out(sprintf('q /Pattern cs /P%d scn %s %.3F %.3F %.3F %.3F re f Q', $n, $opac, $px*_MPDFK, ($this->h-$py)*_MPDFK, $pw*_MPDFK, -$ph*_MPDFK));
  24223. }
  24224. else {
  24225. $image_id = $cell['background-image']['image_id'];
  24226. $orig_w = $cell['background-image']['orig_w'];
  24227. $orig_h = $cell['background-image']['orig_h'];
  24228. $x_pos = $cell['background-image']['x_pos'];
  24229. $y_pos = $cell['background-image']['y_pos'];
  24230. $x_repeat = $cell['background-image']['x_repeat'];
  24231. $y_repeat = $cell['background-image']['y_repeat'];
  24232. $resize = $cell['background-image']['resize'];
  24233. $opacity = $cell['background-image']['opacity'];
  24234. $itype = $cell['background-image']['itype'];
  24235. $this->tableBackgrounds[$level*9+8][] = array('x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>'', 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$itype);
  24236. }
  24237. }
  24238. }
  24239. /*-- END BACKGROUNDS --*/
  24240. if (isset($cell['colspan']) && $cell['colspan']>1) { $ccolsp = $cell['colspan']; }
  24241. else { $ccolsp = 1; }
  24242. if (isset($cell['rowspan']) && $cell['rowspan']>1) { $crowsp = $cell['rowspan']; }
  24243. else { $crowsp = 1; }
  24244. // but still need to do this for repeated headers...
  24245. if (!$table['borders_separate'] && $this->tabletheadjustfinished && !$this->simpleTables){
  24246. if (isset($table['topntail']) && $table['topntail']) {
  24247. $bord_det['T'] = $this->border_details($table['topntail']);
  24248. $bord_det['T']['w'] /= $this->shrin_k;
  24249. $this->setBorder($bord, _BORDER_TOP);
  24250. }
  24251. if (isset($table['thead-underline']) && $table['thead-underline']) {
  24252. $bord_det['T'] = $this->border_details($table['thead-underline']);
  24253. $bord_det['T']['w'] /= $this->shrin_k;
  24254. $this->setBorder($bord, _BORDER_TOP);
  24255. }
  24256. }
  24257. //Get info of first row ==>> table header
  24258. //Use > 1 row if THEAD
  24259. if (isset($table['is_thead'][$i]) && $table['is_thead'][$i] && $level==1) { // mPDF 5.3.62
  24260. if ($j==0) $tableheaderrowheight += $table['hr'][$i]; // mPDF 5.3.36
  24261. $tableheader[$i][0]['trbackground-images'] = (isset($table['trbackground-images'][$i]) ? $table['trbackground-images'][$i] : null);
  24262. $tableheader[$i][0]['trgradients'] = (isset($table['trgradients'][$i]) ? $table['trgradients'][$i] : null);
  24263. $tableheader[$i][0]['trbgcolor'] = (isset($table['bgcolor'][$i]) ? $table['bgcolor'][$i] : null);
  24264. $tableheader[$i][$j]['x'] = $x;
  24265. $tableheader[$i][$j]['y'] = $y;
  24266. $tableheader[$i][$j]['h'] = $h;
  24267. $tableheader[$i][$j]['w'] = $w;
  24268. if (isset($cell['textbuffer'])) { $tableheader[$i][$j]['textbuffer'] = $cell['textbuffer']; }
  24269. else { $tableheader[$i][$j]['textbuffer'] = ''; }
  24270. $tableheader[$i][$j]['a'] = $cell['a'];
  24271. $tableheader[$i][$j]['R'] = $cell['R'];
  24272. $tableheader[$i][$j]['va'] = $cell['va'];
  24273. $tableheader[$i][$j]['mih'] = $cell['mih'];
  24274. $tableheader[$i][$j]['gradient'] = (isset($cell['gradient']) ? $cell['gradient'] : null); // *BACKGROUNDS*
  24275. $tableheader[$i][$j]['background-image'] = (isset($cell['background-image']) ? $cell['background-image'] : null); // *BACKGROUNDS*
  24276. $tableheader[$i][$j]['rowspan'] = (isset($cell['rowspan']) ? $cell['rowspan'] : null);
  24277. $tableheader[$i][$j]['colspan'] = (isset($cell['colspan']) ? $cell['colspan'] : null);
  24278. $tableheader[$i][$j]['bgcolor'] = $cell['bgcolor'];
  24279. if (!$this->simpleTables){
  24280. $tableheader[$i][$j]['border'] = $bord;
  24281. $tableheader[$i][$j]['border_details'] = $bord_det;
  24282. }
  24283. else if ($this->simpleTables){
  24284. $tableheader[$i][$j]['border'] = $table['simple']['border'];
  24285. $tableheader[$i][$j]['border_details'] = $table['simple']['border_details'];
  24286. }
  24287. $tableheader[$i][$j]['padding'] = $cell['padding'];
  24288. }
  24289. // CELL BORDER
  24290. if ($bord || $bord_det) {
  24291. if ($table['borders_separate'] && $paintcell) {
  24292. $this->_tableRect($x + ($table['border_spacing_H']/2)+($bord_det['L']['w'] /2), $y+ ($table['border_spacing_V']/2)+($bord_det['T']['w'] /2), $w-$table['border_spacing_H']-($bord_det['L']['w'] /2)-($bord_det['R']['w'] /2), $h- $table['border_spacing_V']-($bord_det['T']['w'] /2)-($bord_det['B']['w']/2), $bord, $bord_det, false, $table['borders_separate']);
  24293. }
  24294. else if (!$table['borders_separate']) {
  24295. $this->_tableRect($x, $y, $w, $h, $bord, $bord_det, true, $table['borders_separate']); // true causes buffer
  24296. }
  24297. }
  24298. //VERTICAL ALIGN
  24299. if ($cell['R'] && INTVAL($cell['R']) > 0 && INTVAL($cell['R']) < 90 && isset($cell['va']) && $cell['va']!='B') { $cell['va']='B';}
  24300. if (!isset($cell['va']) || $cell['va']=='M') $this->y += ($h-$cell['mih'])/2;
  24301. elseif (isset($cell['va']) && $cell['va']=='B') $this->y += $h-$cell['mih'];
  24302. // NESTED CONTENT
  24303. // TEXT (and nested tables)
  24304. $this->divalign=$align;
  24305. $this->divwidth=$w;
  24306. if (!empty($cell['textbuffer'])) {
  24307. if ($level==1) { // mPDF 5.3.92
  24308. if (isset($table['is_tfoot'][$i]) && $table['is_tfoot'][$i]) {
  24309. if (preg_match('/{colsum([0-9]*)[_]*}/', $cell['textbuffer'][0][0], $m)) {
  24310. $rep = sprintf("%01.".intval($m[1])."f", $this->colsums[$j]);
  24311. $cell['textbuffer'][0][0] = preg_replace('/{colsum[0-9_]*}/', $rep ,$cell['textbuffer'][0][0]);
  24312. }
  24313. }
  24314. else { $this->colsums[$j] += floatval(preg_replace('/^[^0-9\.\,]*/','',$cell['textbuffer'][0][0])); }
  24315. }
  24316. $opy = $this->y;
  24317. // mPDF ITERATION
  24318. if ($this->iterationCounter) {
  24319. foreach($cell['textbuffer'] AS $k=>$t) { // mPDF 5.3.78
  24320. if (preg_match('/{iteration ([a-zA-Z0-9_]+)}/',$t[0], $m)) {
  24321. $vname = '__'.$m[1].'_';
  24322. if (!isset($this->$vname)) { $this->$vname = 1; }
  24323. else { $this->$vname++; }
  24324. $cell['textbuffer'][$k][0] = preg_replace('/{iteration '.$m[1].'}/', $this->$vname, $cell['textbuffer'][$k][0]);
  24325. }
  24326. }
  24327. }
  24328. if ($cell['R']) {
  24329. $cellPtSize = $cell['textbuffer'][0][11] / $this->shrin_k;
  24330. if (!$cellPtSize) { $cellPtSize = $this->default_font_size; }
  24331. $cellFontHeight = ($cellPtSize/_MPDFK);
  24332. $opx = $this->x;
  24333. $angle = INTVAL($cell['R']);
  24334. // Only allow 45 to 89 degrees (when bottom-aligned) or exactly 90 or -90
  24335. if ($angle > 90) { $angle = 90; }
  24336. else if ($angle > 0 && $angle <45) { $angle = 45; }
  24337. else if ($angle < 0) { $angle = -90; }
  24338. $offset = ((sin(deg2rad($angle))) * 0.37 * $cellFontHeight);
  24339. if (isset($cell['a']) && $cell['a']=='R') {
  24340. $this->x += ($w) + ($offset) - ($cellFontHeight/3) - ($cell['padding']['R'] + ($table['border_spacing_H']/2));
  24341. }
  24342. else if (!isset($cell['a']) || $cell['a']=='C') {
  24343. $this->x += ($w/2) + ($offset);
  24344. }
  24345. else {
  24346. $this->x += ($offset) + ($cellFontHeight/3)+($cell['padding']['L'] +($table['border_spacing_H']/2));
  24347. }
  24348. // mPDF 5.3.78
  24349. $str = '';
  24350. foreach($cell['textbuffer'] AS $t) { $str .= $t[0].' '; }
  24351. $str = trim($str);
  24352. if (!isset($cell['va']) || $cell['va']=='M') {
  24353. $this->y -= ($h-$cell['mih'])/2; //Undo what was added earlier VERTICAL ALIGN
  24354. if ($angle > 0) { $this->y += (($h-$cell['mih'])/2) + $cell['padding']['T'] + ($cell['mih']-($cell['padding']['T'] + $cell['padding']['B'])); }
  24355. else if ($angle < 0) { $this->y += (($h-$cell['mih'])/2)+ ($cell['padding']['T'] + ($table['border_spacing_V']/2)); }
  24356. }
  24357. elseif (isset($cell['va']) && $cell['va']=='B') {
  24358. $this->y -= $h-$cell['mih']; //Undo what was added earlier VERTICAL ALIGN
  24359. if ($angle > 0) { $this->y += $h-($cell['padding']['B'] + ($table['border_spacing_V']/2)); }
  24360. else if ($angle < 0) { $this->y += $h-$cell['mih'] + ($cell['padding']['T'] + ($table['border_spacing_V']/2)); }
  24361. }
  24362. elseif (isset($cell['va']) && $cell['va']=='T') {
  24363. if ($angle > 0) { $this->y += $cell['mih']-($cell['padding']['B'] + ($table['border_spacing_V']/2)); }
  24364. else if ($angle < 0) { $this->y += ($cell['padding']['T'] + ($table['border_spacing_V']/2)); }
  24365. }
  24366. $this->Rotate($angle,$this->x,$this->y);
  24367. $s_fs = $this->FontSizePt;
  24368. $s_f = $this->FontFamily;
  24369. $s_st = $this->FontStyle;
  24370. // mPDF 5.3.34
  24371. if (!empty($cell['textbuffer'][0][3])) { //Font Color
  24372. $cor = $cell['textbuffer'][0][3];
  24373. $this->SetTColor($cor);
  24374. }
  24375. // mPDF 5.3.54
  24376. $s_str = $this->strike;
  24377. $this->strike = $cell['textbuffer'][0][8]; //Strikethrough
  24378. $this->SetFont($cell['textbuffer'][0][4],$cell['textbuffer'][0][2],$cellPtSize,true,true);
  24379. $this->Text($this->x,$this->y,$str);
  24380. $this->Rotate(0);
  24381. $this->SetFont($s_f,$s_st,$s_fs,true,true);
  24382. $this->SetTColor(0); // mPDF 5.3.34
  24383. $this->strike = $s_str; // mPDF 5.3.54
  24384. $this->x = $opx;
  24385. }
  24386. else {
  24387. if (!$this->simpleTables){
  24388. // mPDF 5.3.76
  24389. if ($bord_det) {
  24390. $btlw = $bord_det['L']['w'];
  24391. $btrw = $bord_det['R']['w'];
  24392. $bttw = $bord_det['T']['w'];
  24393. }
  24394. else {
  24395. $btlw = 0;
  24396. $btrw = 0;
  24397. $bttw = 0;
  24398. }
  24399. if ($table['borders_separate']) {
  24400. $xadj = $btlw + $cell['padding']['L'] +($table['border_spacing_H']/2);
  24401. $wadj = $btlw + $btrw + $cell['padding']['L'] +$cell['padding']['R'] + $table['border_spacing_H'];
  24402. $yadj = $bttw + $cell['padding']['T'] + ($table['border_spacing_H']/2);
  24403. }
  24404. else {
  24405. $xadj = $btlw/2 + $cell['padding']['L'];
  24406. $wadj = ($btlw + $btrw)/2 + $cell['padding']['L'] + $cell['padding']['R'];
  24407. $yadj = $bttw/2 + $cell['padding']['T'];
  24408. }
  24409. }
  24410. else if ($this->simpleTables){
  24411. if ($table['borders_separate']) { // NB twice border width
  24412. $xadj = $table['simple']['border_details']['L']['w'] + $cell['padding']['L'] +($table['border_spacing_H']/2);
  24413. $wadj = $table['simple']['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'] + $cell['padding']['L'] +$cell['padding']['R'] + $table['border_spacing_H'];
  24414. $yadj = $table['simple']['border_details']['T']['w'] + $cell['padding']['T'] + ($table['border_spacing_H']/2);
  24415. }
  24416. else {
  24417. $xadj = $table['simple']['border_details']['L']['w']/2 + $cell['padding']['L'];
  24418. $wadj = ($table['simple']['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'])/2 + $cell['padding']['L'] + $cell['padding']['R'];
  24419. $yadj = $table['simple']['border_details']['T']['w']/2 + $cell['padding']['T'];
  24420. }
  24421. }
  24422. $this->divwidth=$w-$wadj;
  24423. if ($this->divwidth == 0) { $this->divwidth = 0.0001; }
  24424. $this->x += $xadj;
  24425. $this->y += $yadj;
  24426. $this->printbuffer($cell['textbuffer'],'',true);
  24427. }
  24428. $this->y = $opy;
  24429. }
  24430. /*-- BACKGROUNDS --*/
  24431. if (!$this->ColActive) {
  24432. if (isset($table['trgradients'][$i]) && ($j==0 || $table['borders_separate'])) {
  24433. $g = $this->grad->parseBackgroundGradient($table['trgradients'][$i]);
  24434. if ($g) {
  24435. $gx = $x0;
  24436. $gy = $y;
  24437. $gh = $h;
  24438. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  24439. if ($table['borders_separate']) {
  24440. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  24441. $s = '';
  24442. $clx = $x+ ($table['border_spacing_H']/2);
  24443. $cly = $y+ ($table['border_spacing_V']/2);
  24444. $clw = $w- $table['border_spacing_H'];
  24445. $clh = $h- $table['border_spacing_V'];
  24446. // Set clipping path
  24447. $s = ' q 0 w '; // Line width=0
  24448. $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc
  24449. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL
  24450. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR
  24451. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR
  24452. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL
  24453. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  24454. $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx + ($table['border_spacing_H']/2), 'y'=>$gy + ($table['border_spacing_V']/2), 'w'=>$gw - $table['border_spacing_V'], 'h'=>$gh - $table['border_spacing_H'], 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>$s);
  24455. }
  24456. else {
  24457. $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx, 'y'=>$gy, 'w'=>$gw, 'h'=>$gh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  24458. }
  24459. }
  24460. }
  24461. if (isset($table['trbackground-images'][$i]) && ($j==0 || $table['borders_separate'])) {
  24462. if ($table['trbackground-images'][$i]['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $table['trbackground-images'][$i]['gradient'] )) {
  24463. $g = $this->grad->parseMozGradient( $table['trbackground-images'][$i]['gradient'] );
  24464. if ($g) {
  24465. $gx = $x0;
  24466. $gy = $y;
  24467. $gh = $h;
  24468. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  24469. if ($table['borders_separate']) {
  24470. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  24471. $s = '';
  24472. $clx = $x+ ($table['border_spacing_H']/2);
  24473. $cly = $y+ ($table['border_spacing_V']/2);
  24474. $clw = $w- $table['border_spacing_H'];
  24475. $clh = $h- $table['border_spacing_V'];
  24476. // Set clipping path
  24477. $s = ' q 0 w '; // Line width=0
  24478. $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc
  24479. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL
  24480. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR
  24481. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR
  24482. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL
  24483. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  24484. $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx + ($table['border_spacing_H']/2), 'y'=>$gy + ($table['border_spacing_V']/2), 'w'=>$gw - $table['border_spacing_V'], 'h'=>$gh - $table['border_spacing_H'], 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>$s);
  24485. }
  24486. else {
  24487. $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx, 'y'=>$gy, 'w'=>$gw, 'h'=>$gh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  24488. }
  24489. }
  24490. }
  24491. else {
  24492. $image_id = $table['trbackground-images'][$i]['image_id'];
  24493. $orig_w = $table['trbackground-images'][$i]['orig_w'];
  24494. $orig_h = $table['trbackground-images'][$i]['orig_h'];
  24495. $x_pos = $table['trbackground-images'][$i]['x_pos'];
  24496. $y_pos = $table['trbackground-images'][$i]['y_pos'];
  24497. $x_repeat = $table['trbackground-images'][$i]['x_repeat'];
  24498. $y_repeat = $table['trbackground-images'][$i]['y_repeat'];
  24499. $resize = $table['trbackground-images'][$i]['resize'];
  24500. $opacity = $table['trbackground-images'][$i]['opacity'];
  24501. $itype = $table['trbackground-images'][$i]['itype'];
  24502. $clippath = '';
  24503. $gx = $x0;
  24504. $gy = $y;
  24505. $gh = $h;
  24506. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  24507. if ($table['borders_separate']) {
  24508. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  24509. $s = '';
  24510. $clx = $x + ($table['border_spacing_H']/2);
  24511. $cly = $y + ($table['border_spacing_V']/2);
  24512. $clw = $w - $table['border_spacing_H'];
  24513. $clh = $h - $table['border_spacing_V'];
  24514. // Set clipping path
  24515. $s = ' q 0 w '; // Line width=0
  24516. $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL
  24517. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL
  24518. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR
  24519. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR
  24520. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL
  24521. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  24522. $this->tableBackgrounds[$level*9+5][] = array('x'=>$gx + ($table['border_spacing_H']/2), 'y'=>$gy + ($table['border_spacing_V']/2), 'w'=>$gw - $table['border_spacing_V'], 'h'=>$gh - $table['border_spacing_H'], 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>$s, 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$itype);
  24523. }
  24524. else {
  24525. $this->tableBackgrounds[$level*9+5][] = array('x'=>$gx, 'y'=>$gy, 'w'=>$gw, 'h'=>$gh, 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>'', 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$itype);
  24526. }
  24527. }
  24528. }
  24529. }
  24530. /*-- END BACKGROUNDS --*/
  24531. // TABLE BORDER - if separate
  24532. // mPDF 5.3.15
  24533. if (($table['borders_separate'] || ($this->simpleTables && !$table['simple']['border'])) && $table['border']) {
  24534. $halfspaceL = $table['padding']['L'] + ($table['border_spacing_H']/2);
  24535. $halfspaceR = $table['padding']['R'] + ($table['border_spacing_H']/2);
  24536. $halfspaceT = $table['padding']['T'] + ($table['border_spacing_V']/2);
  24537. $halfspaceB = $table['padding']['B'] + ($table['border_spacing_V']/2);
  24538. $tbx = $x;
  24539. $tby = $y;
  24540. $tbw = $w;
  24541. $tbh = $h;
  24542. $tab_bord = 0;
  24543. $corner = '';
  24544. if ($i == 0) { // Top
  24545. $tby -= $halfspaceT + ($table['border_details']['T']['w']/2);
  24546. $tbh += $halfspaceT + ($table['border_details']['T']['w']/2);
  24547. $this->setBorder($tab_bord , _BORDER_TOP);
  24548. $corner .= 'T';
  24549. }
  24550. if ($i == ($numrows-1) || (isset($cell['rowspan']) && ($i+$cell['rowspan']) == $numrows)) { // Bottom // mPDF 5.3.15
  24551. $tbh += $halfspaceB + ($table['border_details']['B']['w']/2);
  24552. $this->setBorder($tab_bord , _BORDER_BOTTOM);
  24553. $corner .= 'B';
  24554. }
  24555. if ($j == 0) { // Left
  24556. $tbx -= $halfspaceL + ($table['border_details']['L']['w']/2);
  24557. $tbw += $halfspaceL + ($table['border_details']['L']['w']/2);
  24558. $this->setBorder($tab_bord , _BORDER_LEFT);
  24559. $corner .= 'L';
  24560. }
  24561. if ($j == ($numcols-1) || (isset($cell['colspan']) && ($j+$cell['colspan']) == $numcols)) { // Right // mPDF 5.3.15
  24562. $tbw += $halfspaceR + ($table['border_details']['R']['w']/2);
  24563. $this->setBorder($tab_bord , _BORDER_RIGHT);
  24564. $corner .= 'R';
  24565. }
  24566. $this->_tableRect($tbx, $tby, $tbw, $tbh, $tab_bord , $table['border_details'], false, $table['borders_separate'], 'table', $corner, $table['border_spacing_V'], $table['border_spacing_H'] );
  24567. }
  24568. unset($cell );
  24569. //Reset values
  24570. $this->Reset();
  24571. }//end of (if isset(cells)...)
  24572. }// end of columns
  24573. $newpagestarted = false;
  24574. $this->tabletheadjustfinished = false;
  24575. if ($this->ColActive && $i < $numrows-1 && $level==1) { $this->breakpoints[$this->CurrCol][] = $y + $h; } // *COLUMNS*
  24576. /*-- COLUMNS --*/
  24577. if ($this->ColActive) {
  24578. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); }
  24579. }
  24580. /*-- END COLUMNS --*/
  24581. if ($i == $numrows-1) { $this->y = $y + $h; } //last row jump (update this->y position)
  24582. if ($this->table_rotate && $level==1) {
  24583. $this->tbrot_h += $h;
  24584. }
  24585. }// end of rows
  24586. if ($this->progressBar) { $this->UpdateProgressBar(7,70,' '); } // *PROGRESS-BAR*
  24587. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); }
  24588. if ($this->tableClipPath ) { $this->_out("Q"); }
  24589. $this->tableClipPath = '';
  24590. // Advance down page by half width of bottom border
  24591. if ($table['borders_separate']) { $this->y += $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2; }
  24592. else { $this->y += $table['max_cell_border_width']['B']/2; }
  24593. if ($table['borders_separate'] && $level==1) { $this->tbrot_h += $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2; }
  24594. else if ($level==1) { $this->tbrot_h += $table['margin']['B'] + $table['max_cell_border_width']['B']/2; }
  24595. $bx = $x0;
  24596. $by = $y0;
  24597. if ($table['borders_separate']) {
  24598. $bx -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['border_spacing_H']/2);
  24599. if ($tablestartpageno != $this->page) { // IF broken across page
  24600. $by += $table['max_cell_border_width']['T']/2;
  24601. if (empty($tableheader)) { $by -= ($table['border_spacing_V']/2); }
  24602. }
  24603. // mPDF 5.3.36
  24604. else if ($split && $startrow > 0 && empty($tableheader)) {
  24605. $by -= ($table['border_spacing_V']/2);
  24606. }
  24607. else {
  24608. $by -= ($table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2);
  24609. }
  24610. }
  24611. else if ($tablestartpageno != $this->page && !empty($tableheader)) { $by += $maxbwtop /2; }
  24612. $by -= $tableheaderadj;
  24613. $bh = $this->y - $by;
  24614. if (!$table['borders_separate']) { $bh -= $table['max_cell_border_width']['B']/2; }
  24615. // mPDF 5.3.36
  24616. if ($split) {
  24617. $bw = 0;
  24618. $finalSpread = true;
  24619. for($t=$startcol; $t<$numcols; $t++) {
  24620. if ($table['colPg'][$t] == $splitpg) { $bw += $table['wc'][$t]; }
  24621. if ($table['colPg'][$t] > $splitpg) { $finalSpread = false; break; }
  24622. }
  24623. if ($startcol==0) { $firstSpread = true; }
  24624. else { $firstSpread = false; }
  24625. if ($table['borders_separate']) {
  24626. // mPDF 5.3.83
  24627. $bw += $table['border_spacing_H'];
  24628. if ($firstSpread) {
  24629. $bw += $table['padding']['L'] + $table['border_details']['L']['w'];
  24630. }
  24631. else {
  24632. $bx += ($table['padding']['L'] + $table['border_details']['L']['w']);
  24633. }
  24634. if ($finalSpread) {
  24635. $bw += $table['padding']['R'] + $table['border_details']['R']['w'];
  24636. }
  24637. }
  24638. }
  24639. else {
  24640. $bw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  24641. }
  24642. if (!$this->ColActive) {
  24643. if (isset($table['bgcolor'][-1])) {
  24644. $color = $this->ConvertColor($table['bgcolor'][-1]);
  24645. if ($color) {
  24646. $this->tableBackgrounds[$level*9][] = array('gradient'=>false, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'col'=>$color);
  24647. }
  24648. }
  24649. /*-- BACKGROUNDS --*/
  24650. if (isset($table['gradient'])) {
  24651. $g = $this->grad->parseBackgroundGradient($table['gradient']);
  24652. if ($g) {
  24653. $this->tableBackgrounds[$level*9+1][] = array('gradient'=>true, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  24654. }
  24655. }
  24656. if (isset($table['background-image'])) {
  24657. if ($table['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $table['background-image']['gradient'] )) {
  24658. $g = $this->grad->parseMozGradient( $table['background-image']['gradient'] );
  24659. if ($g) {
  24660. $this->tableBackgrounds[$level*9+1][] = array('gradient'=>true, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  24661. }
  24662. }
  24663. else {
  24664. $image_id = $table['background-image']['image_id'];
  24665. $orig_w = $table['background-image']['orig_w'];
  24666. $orig_h = $table['background-image']['orig_h'];
  24667. $x_pos = $table['background-image']['x_pos'];
  24668. $y_pos = $table['background-image']['y_pos'];
  24669. $x_repeat = $table['background-image']['x_repeat'];
  24670. $y_repeat = $table['background-image']['y_repeat'];
  24671. $resize = $table['background-image']['resize'];
  24672. $opacity = $table['background-image']['opacity'];
  24673. $itype = $table['background-image']['itype'];
  24674. $this->tableBackgrounds[$level*9+2][] = array('x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>'', 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$itype);
  24675. }
  24676. }
  24677. /*-- END BACKGROUNDS --*/
  24678. }
  24679. if ($this->tableBackgrounds && $level == 1) {
  24680. $s = $this->PrintTableBackgrounds();
  24681. if ($this->table_rotate && !$this->processingHeader && !$this->processingFooter) {
  24682. $this->tablebuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->tablebuffer);
  24683. if ($level == 1) { $this->tablebuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->tablebuffer); }
  24684. }
  24685. else if ($this->bufferoutput) {
  24686. $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->headerbuffer);
  24687. if ($level == 1) { $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->headerbuffer ); }
  24688. }
  24689. else {
  24690. $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  24691. if ($level == 1) { $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->pages[$this->page]); }
  24692. }
  24693. $this->tableBackgrounds = array();
  24694. }
  24695. // TABLE BOTTOM MARGIN
  24696. if ($table['margin']['B']) {
  24697. if (!$this->table_rotate && $level==1) {
  24698. $this->DivLn($table['margin']['B'],$this->blklvl,true); // collapsible
  24699. }
  24700. else {
  24701. $this->y += ($table['margin']['B']);
  24702. }
  24703. }
  24704. if ($this->ColActive && $level==1) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  24705. // mPDF 5.3.79
  24706. if ($this->cacheTables) { fclose($fh); }
  24707. // mPDF 5.3.36
  24708. if ($split) {
  24709. // Are there more columns to print on a next page?
  24710. if ($lastCol < $numcols-1) {
  24711. $splitpg++;
  24712. $startcol = $lastCol + 1;
  24713. return array(false, $startrow, $startcol, $splitpg, $returny, $y0);
  24714. }
  24715. else {
  24716. // mPDF 5.3.79
  24717. if ($this->cacheTables) {
  24718. unlink($table['cache']);
  24719. @unlink($table['cache'].'.bak');
  24720. }
  24721. return array(true,0,0,0);
  24722. }
  24723. }
  24724. // mPDF 5.3.79
  24725. if ($this->cacheTables) {
  24726. unlink($table['cache']);
  24727. @unlink($table['cache'].'.bak');
  24728. }
  24729. }//END OF FUNCTION _tableWrite()
  24730. /////////////////////////END OF TABLE CODE//////////////////////////////////
  24731. /*-- END TABLES --*/
  24732. function _putextgstates() {
  24733. for ($i = 1; $i <= count($this->extgstates); $i++) {
  24734. $this->_newobj();
  24735. $this->extgstates[$i]['n'] = $this->n;
  24736. $this->_out('<</Type /ExtGState');
  24737. foreach ($this->extgstates[$i]['parms'] as $k=>$v)
  24738. $this->_out('/'.$k.' '.$v);
  24739. $this->_out('>>');
  24740. $this->_out('endobj');
  24741. }
  24742. }
  24743. // mPDF 5.3.41 Visibility
  24744. function _putocg() {
  24745. $this->_newobj();
  24746. $this->n_ocg_print=$this->n;
  24747. $this->_out('<</Type /OCG /Name '.$this->_textstring('print'));
  24748. $this->_out('/Usage <</Print <</PrintState /ON>> /View <</ViewState /OFF>>>>>>');
  24749. $this->_out('endobj');
  24750. $this->_newobj();
  24751. $this->n_ocg_view=$this->n;
  24752. $this->_out('<</Type /OCG /Name '.$this->_textstring('view'));
  24753. $this->_out('/Usage <</Print <</PrintState /OFF>> /View <</ViewState /ON>>>>>>');
  24754. $this->_out('endobj');
  24755. $this->_newobj();
  24756. $this->n_ocg_hidden=$this->n;
  24757. $this->_out('<</Type /OCG /Name '.$this->_textstring('hidden'));
  24758. $this->_out('/Usage <</Print <</PrintState /OFF>> /View <</ViewState /OFF>>>>>>');
  24759. $this->_out('endobj');
  24760. }
  24761. /*-- IMPORTS --*/
  24762. // from mPDFI
  24763. function _putimportedobjects() {
  24764. if (is_array($this->parsers) && count($this->parsers) > 0) {
  24765. foreach($this->parsers AS $filename => $p) {
  24766. $this->current_parser =& $this->parsers[$filename];
  24767. if (is_array($this->_obj_stack[$filename])) {
  24768. while($n = key($this->_obj_stack[$filename])) {
  24769. $nObj = $this->current_parser->pdf_resolve_object($this->current_parser->c,$this->_obj_stack[$filename][$n][1]);
  24770. $this->_newobj($this->_obj_stack[$filename][$n][0]);
  24771. if ($nObj[0] == PDF_TYPE_STREAM) {
  24772. $this->pdf_write_value($nObj);
  24773. }
  24774. else {
  24775. $this->pdf_write_value($nObj[1]);
  24776. }
  24777. $this->_out('endobj');
  24778. $this->_obj_stack[$filename][$n] = null; // free memory
  24779. unset($this->_obj_stack[$filename][$n]);
  24780. reset($this->_obj_stack[$filename]);
  24781. }
  24782. }
  24783. }
  24784. }
  24785. }
  24786. function _putformxobjects() {
  24787. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  24788. reset($this->tpls);
  24789. foreach($this->tpls AS $tplidx => $tpl) {
  24790. $p=($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer'];
  24791. $this->_newobj();
  24792. $this->tpls[$tplidx]['n'] = $this->n;
  24793. $this->_out('<<'.$filter.'/Type /XObject');
  24794. $this->_out('/Subtype /Form');
  24795. $this->_out('/FormType 1');
  24796. // Left/Bottom/Right/Top
  24797. $this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]',
  24798. $tpl['box']['x']*_MPDFK,
  24799. $tpl['box']['y']*_MPDFK,
  24800. ($tpl['box']['x'] + $tpl['box']['w'])*_MPDFK,
  24801. ($tpl['box']['y'] + $tpl['box']['h'])*_MPDFK )
  24802. );
  24803. if (isset($tpl['box']))
  24804. $this->_out(sprintf('/Matrix [1 0 0 1 %.5F %.5F]',-$tpl['box']['x']*_MPDFK, -$tpl['box']['y']*_MPDFK));
  24805. $this->_out('/Resources ');
  24806. if (isset($tpl['resources'])) {
  24807. $this->current_parser =& $tpl['parser'];
  24808. $this->pdf_write_value($tpl['resources']);
  24809. } else {
  24810. $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  24811. if (isset($this->_res['tpl'][$tplidx]['fonts']) && count($this->_res['tpl'][$tplidx]['fonts'])) {
  24812. $this->_out('/Font <<');
  24813. foreach($this->_res['tpl'][$tplidx]['fonts'] as $font)
  24814. $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  24815. $this->_out('>>');
  24816. }
  24817. if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) ||
  24818. isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls']))
  24819. {
  24820. $this->_out('/XObject <<');
  24821. if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) {
  24822. foreach($this->_res['tpl'][$tplidx]['images'] as $image)
  24823. $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
  24824. }
  24825. if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) {
  24826. foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $itpl)
  24827. $this->_out($this->tplprefix.$i.' '.$itpl['n'].' 0 R');
  24828. }
  24829. $this->_out('>>');
  24830. }
  24831. $this->_out('>>');
  24832. }
  24833. $this->_out('/Length '.strlen($p).' >>');
  24834. $this->_putstream($p);
  24835. $this->_out('endobj');
  24836. }
  24837. }
  24838. /*-- END IMPORTS --*/
  24839. function _putpatterns() {
  24840. for ($i = 1; $i <= count($this->patterns); $i++) {
  24841. $x = $this->patterns[$i]['x'];
  24842. $y = $this->patterns[$i]['y'];
  24843. $w = $this->patterns[$i]['w'];
  24844. $h = $this->patterns[$i]['h'];
  24845. $pgh = $this->patterns[$i]['pgh'];
  24846. $orig_w = $this->patterns[$i]['orig_w'];
  24847. $orig_h = $this->patterns[$i]['orig_h'];
  24848. $image_id = $this->patterns[$i]['image_id'];
  24849. $itype = $this->patterns[$i]['itype'];
  24850. if ($this->patterns[$i]['x_repeat']) { $x_repeat = true; }
  24851. else { $x_repeat = false; }
  24852. if ($this->patterns[$i]['y_repeat']) { $y_repeat = true; }
  24853. else { $y_repeat = false; }
  24854. $x_pos = $this->patterns[$i]['x_pos'];
  24855. if (stristr($x_pos ,'%') ) {
  24856. $x_pos += 0;
  24857. $x_pos /= 100;
  24858. $x_pos = ($w * $x_pos) - ($orig_w/_MPDFK * $x_pos);
  24859. }
  24860. $y_pos = $this->patterns[$i]['y_pos'];
  24861. if (stristr($y_pos ,'%') ) {
  24862. $y_pos += 0;
  24863. $y_pos /= 100;
  24864. $y_pos = ($h * $y_pos) - ($orig_h/_MPDFK * $y_pos);
  24865. }
  24866. $adj_x = ($x_pos + $x) *_MPDFK;
  24867. $adj_y = (($pgh - $y_pos - $y)*_MPDFK) - $orig_h ;
  24868. $img_obj = false;
  24869. if ($itype == 'svg' || $itype == 'wmf') {
  24870. foreach($this->formobjects AS $fo) {
  24871. if ($fo['i'] == $image_id) {
  24872. $img_obj = $fo['n'];
  24873. $fo_w = $fo['w'];
  24874. $fo_h = -$fo['h'];
  24875. $wmf_x = $fo['x'];
  24876. $wmf_y = $fo['y'];
  24877. break;
  24878. }
  24879. }
  24880. }
  24881. else {
  24882. foreach($this->images AS $img) {
  24883. if ($img['i'] == $image_id) { $img_obj = $img['n']; break; }
  24884. }
  24885. }
  24886. if (!$img_obj ) { echo "Problem: Image object not found for background pattern ".$img['i']; exit; }
  24887. $this->_newobj();
  24888. $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  24889. if ($itype == 'svg' || $itype == 'wmf') {
  24890. $this->_out('/XObject <</FO'.$image_id.' '.$img_obj.' 0 R >>');
  24891. // ******* ADD ANY ExtGStates, Shading AND Fonts needed for the FormObject
  24892. // Set in classes/svg array['fo'] = true
  24893. // Required that _putshaders comes before _putpatterns in _putresources
  24894. // This adds any resources associated with any FormObject to every Formobject - overkill but works!
  24895. if (count($this->extgstates)) {
  24896. $this->_out('/ExtGState <<');
  24897. foreach($this->extgstates as $k=>$extgstate)
  24898. if (isset($extgstate['fo']) && $extgstate['fo']) {
  24899. if (isset($extgstate['trans'])) $this->_out('/'.$extgstate['trans'].' '.$extgstate['n'].' 0 R');
  24900. else $this->_out('/GS'.$k.' '.$extgstate['n'].' 0 R');
  24901. }
  24902. $this->_out('>>');
  24903. }
  24904. /*-- BACKGROUNDS --*/
  24905. if (isset($this->gradients) AND (count($this->gradients) > 0)) {
  24906. $this->_out('/Shading <<');
  24907. foreach ($this->gradients as $id => $grad) {
  24908. if (isset($grad['fo']) && $grad['fo']) {
  24909. $this->_out('/Sh'.$id.' '.$grad['id'].' 0 R');
  24910. }
  24911. }
  24912. $this->_out('>>');
  24913. }
  24914. /*-- END BACKGROUNDS --*/
  24915. $this->_out('/Font <<');
  24916. foreach($this->fonts as $font) {
  24917. if (!$font['used'] && $font['type']=='TTF') { continue; }
  24918. if (isset($font['fo']) && $font['fo']) {
  24919. if ($font['type']=='TTF' && ($font['sip'] || $font['smp'])) {
  24920. foreach($font['n'] AS $k => $fid) {
  24921. $this->_out('/F'.$font['subsetfontids'][$k].' '.$font['n'][$k].' 0 R');
  24922. }
  24923. }
  24924. else {
  24925. $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  24926. }
  24927. }
  24928. }
  24929. $this->_out('>>');
  24930. }
  24931. else {
  24932. $this->_out('/XObject <</I'.$image_id.' '.$img_obj.' 0 R >>');
  24933. }
  24934. $this->_out('>>');
  24935. $this->_out('endobj');
  24936. $this->_newobj();
  24937. $this->patterns[$i]['n'] = $this->n;
  24938. $this->_out('<< /Type /Pattern /PatternType 1 /PaintType 1 /TilingType 2');
  24939. $this->_out('/Resources '. ($this->n-1) .' 0 R');
  24940. $this->_out(sprintf('/BBox [0 0 %.3F %.3F]',$orig_w,$orig_h));
  24941. if ($x_repeat) { $this->_out(sprintf('/XStep %.3F',$orig_w)); }
  24942. else { $this->_out(sprintf('/XStep %d',99999)); }
  24943. if ($y_repeat) { $this->_out(sprintf('/YStep %.3F',$orig_h)); }
  24944. else { $this->_out(sprintf('/YStep %d',99999)); }
  24945. if ($itype == 'svg' || $itype == 'wmf') {
  24946. $this->_out(sprintf('/Matrix [1 0 0 -1 %.3F %.3F]', $adj_x, ($adj_y+$orig_h)));
  24947. $s = sprintf("q %.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q",($orig_w/$fo_w), (-$orig_h/$fo_h), -($orig_w/$fo_w)*$wmf_x, ($orig_w/$fo_w)*$wmf_y, $image_id);
  24948. }
  24949. else {
  24950. $this->_out(sprintf('/Matrix [1 0 0 1 %.3F %.3F]',$adj_x,$adj_y));
  24951. $s = sprintf("q %.3F 0 0 %.3F 0 0 cm /I%d Do Q",$orig_w,$orig_h,$image_id);
  24952. }
  24953. if ($this->compress) {
  24954. $this->_out('/Filter /FlateDecode');
  24955. $s = gzcompress($s);
  24956. }
  24957. $this->_out('/Length '.strlen($s).'>>');
  24958. $this->_putstream($s);
  24959. $this->_out('endobj');
  24960. }
  24961. }
  24962. /*-- BACKGROUNDS --*/
  24963. function _putshaders() {
  24964. $maxid = count($this->gradients); //index for transparency gradients
  24965. foreach ($this->gradients as $id => $grad) {
  24966. if (($grad['type'] == 2 || $grad['type'] == 3) && empty($grad['is_mask'])) {
  24967. $this->_newobj();
  24968. $this->_out('<<');
  24969. $this->_out('/FunctionType 3');
  24970. $this->_out('/Domain [0 1]');
  24971. $fn = array();
  24972. $bd = array();
  24973. $en = array();
  24974. for($i=0; $i<(count($grad['stops'])-1); $i++) {
  24975. $fn[] = ($this->n+1+$i).' 0 R';
  24976. $en[] = '0 1';
  24977. if ($i>0) { $bd[] = sprintf('%.3F', $grad['stops'][$i]['offset']); }
  24978. }
  24979. $this->_out('/Functions ['.implode(' ',$fn).']');
  24980. $this->_out('/Bounds ['.implode(' ',$bd).']');
  24981. $this->_out('/Encode ['.implode(' ',$en).']');
  24982. $this->_out('>>');
  24983. $this->_out('endobj');
  24984. $f1 = $this->n;
  24985. for($i=0; $i<(count($grad['stops'])-1); $i++) {
  24986. $this->_newobj();
  24987. $this->_out('<<');
  24988. $this->_out('/FunctionType 2');
  24989. $this->_out('/Domain [0 1]');
  24990. $this->_out('/C0 ['.$grad['stops'][$i]['col'].']');
  24991. $this->_out('/C1 ['.$grad['stops'][$i+1]['col'].']');
  24992. $this->_out('/N 1');
  24993. $this->_out('>>');
  24994. $this->_out('endobj');
  24995. }
  24996. }
  24997. if ($grad['type'] == 2 || $grad['type'] == 3) { // mPDF 5.3.A1
  24998. if (isset($grad['trans']) && $grad['trans']) {
  24999. $this->_newobj();
  25000. $this->_out('<<');
  25001. $this->_out('/FunctionType 3');
  25002. $this->_out('/Domain [0 1]');
  25003. $fn = array();
  25004. $bd = array();
  25005. $en = array();
  25006. for($i=0; $i<(count($grad['stops'])-1); $i++) {
  25007. $fn[] = ($this->n+1+$i).' 0 R';
  25008. $en[] = '0 1';
  25009. if ($i>0) { $bd[] = sprintf('%.3F', $grad['stops'][$i]['offset']); }
  25010. }
  25011. $this->_out('/Functions ['.implode(' ',$fn).']');
  25012. $this->_out('/Bounds ['.implode(' ',$bd).']');
  25013. $this->_out('/Encode ['.implode(' ',$en).']');
  25014. $this->_out('>>');
  25015. $this->_out('endobj');
  25016. $f2 = $this->n;
  25017. for($i=0; $i<(count($grad['stops'])-1); $i++) {
  25018. $this->_newobj();
  25019. $this->_out('<<');
  25020. $this->_out('/FunctionType 2');
  25021. $this->_out('/Domain [0 1]');
  25022. $this->_out(sprintf('/C0 [%.3F]', $grad['stops'][$i]['opacity']));
  25023. $this->_out(sprintf('/C1 [%.3F]', $grad['stops'][$i+1]['opacity']));
  25024. $this->_out('/N 1');
  25025. $this->_out('>>');
  25026. $this->_out('endobj');
  25027. }
  25028. }
  25029. }
  25030. if (empty($grad['is_mask'])) {
  25031. $this->_newobj();
  25032. $this->_out('<<');
  25033. $this->_out('/ShadingType '.$grad['type']);
  25034. if (isset($grad['colorspace'])) {
  25035. $this->_out('/ColorSpace /Device'.$grad['colorspace']); // Can use CMYK if all C0 and C1 above have 4 values
  25036. } else {
  25037. $this->_out('/ColorSpace /DeviceRGB');
  25038. }
  25039. if ($grad['type'] == 2) {
  25040. $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]));
  25041. $this->_out('/Function '.$f1.' 0 R');
  25042. $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] ');
  25043. $this->_out('>>');
  25044. }
  25045. else if ($grad['type'] == 3) {
  25046. //x0, y0, r0, x1, y1, r1
  25047. //at this this time radius of inner circle is 0
  25048. $ir = 0;
  25049. if (isset($grad['coords'][5]) && $grad['coords'][5]) { $ir = $grad['coords'][5]; }
  25050. $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $ir, $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]));
  25051. $this->_out('/Function '.$f1.' 0 R');
  25052. $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] ');
  25053. $this->_out('>>');
  25054. }
  25055. // mPDF 5.3.A1
  25056. else if ($grad['type']==6) {
  25057. $this->_out('/BitsPerCoordinate 16');
  25058. $this->_out('/BitsPerComponent 8');
  25059. if ($grad['colorspace'] == 'CMYK') { $this->_out('/Decode[0 1 0 1 0 1 0 1 0 1 0 1]'); }
  25060. else if ($grad['colorspace'] == 'Gray') { $this->_out('/Decode[0 1 0 1 0 1]'); }
  25061. else { $this->_out('/Decode[0 1 0 1 0 1 0 1 0 1]'); }
  25062. $this->_out('/BitsPerFlag 8');
  25063. $this->_out('/Length '.strlen($grad['stream']));
  25064. $this->_out('>>');
  25065. $this->_putstream($grad['stream']);
  25066. }
  25067. $this->_out('endobj');
  25068. }
  25069. $this->gradients[$id]['id'] = $this->n;
  25070. // set pattern object
  25071. $this->_newobj();
  25072. $out = '<< /Type /Pattern /PatternType 2';
  25073. $out .= ' /Shading '.$this->gradients[$id]['id'].' 0 R';
  25074. $out .= ' >>';
  25075. $out .= "\n".'endobj';
  25076. $this->_out($out);
  25077. $this->gradients[$id]['pattern'] = $this->n;
  25078. if (isset($grad['trans']) && $grad['trans']) {
  25079. // luminosity pattern
  25080. $transid = $id + $maxid;
  25081. $this->_newobj();
  25082. $this->_out('<<');
  25083. $this->_out('/ShadingType '.$grad['type']);
  25084. $this->_out('/ColorSpace /DeviceGray');
  25085. if ($grad['type'] == 2) {
  25086. $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]));
  25087. $this->_out('/Function '.$f2.' 0 R');
  25088. $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] ');
  25089. $this->_out('>>');
  25090. }
  25091. else if ($grad['type'] == 3) {
  25092. //x0, y0, r0, x1, y1, r1
  25093. //at this this time radius of inner circle is 0
  25094. $ir = 0;
  25095. if (isset($grad['coords'][5]) && $grad['coords'][5]) { $ir = $grad['coords'][5]; }
  25096. $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $ir, $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]));
  25097. $this->_out('/Function '.$f2.' 0 R');
  25098. $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] ');
  25099. $this->_out('>>');
  25100. }
  25101. // mPDF 5.3.A1
  25102. else if ($grad['type']==6) {
  25103. $this->_out('/BitsPerCoordinate 16');
  25104. $this->_out('/BitsPerComponent 8');
  25105. $this->_out('/Decode[0 1 0 1 0 1]');
  25106. $this->_out('/BitsPerFlag 8');
  25107. $this->_out('/Length '.strlen($grad['stream_trans']));
  25108. $this->_out('>>');
  25109. $this->_putstream($grad['stream_trans']);
  25110. }
  25111. $this->_out('endobj');
  25112. $this->gradients[$transid]['id'] = $this->n;
  25113. $this->_newobj();
  25114. $this->_out('<< /Type /Pattern /PatternType 2');
  25115. $this->_out('/Shading '.$this->gradients[$transid]['id'].' 0 R');
  25116. $this->_out('>>');
  25117. $this->_out('endobj');
  25118. $this->gradients[$transid]['pattern'] = $this->n;
  25119. $this->_newobj();
  25120. // Need to extend size of viewing box in case of transformations
  25121. $str = 'q /a0 gs /Pattern cs /p'.$transid.' scn -'.($this->wPt/2).' -'.($this->hPt/2).' '.(2*$this->wPt).' '.(2*$this->hPt).' re f Q';
  25122. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  25123. $p=($this->compress) ? gzcompress($str) : $str;
  25124. $this->_out('<< /Type /XObject /Subtype /Form /FormType 1 '.$filter);
  25125. $this->_out('/Length '.strlen($p));
  25126. $this->_out('/BBox [-'.($this->wPt/2).' -'.($this->hPt/2).' '.(2*$this->wPt).' '.(2*$this->hPt).']');
  25127. $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceGray >>');
  25128. $this->_out('/Resources <<');
  25129. $this->_out('/ExtGState << /a0 << /ca 1 /CA 1 >> >>');
  25130. $this->_out('/Pattern << /p'.$transid.' '.$this->gradients[$transid]['pattern'].' 0 R >>');
  25131. $this->_out('>>');
  25132. $this->_out('>>');
  25133. $this->_putstream($p);
  25134. $this->_out('endobj');
  25135. $this->_newobj();
  25136. $this->_out('<< /Type /Mask /S /Luminosity /G '.($this->n - 1).' 0 R >>'."\n".'endobj');
  25137. $this->_newobj();
  25138. $this->_out('<< /Type /ExtGState /SMask '.($this->n - 1).' 0 R /AIS false >>'."\n".'endobj');
  25139. if ($grad['fo']) { $this->extgstates[] = array('n' => $this->n, 'trans' => 'TGS'.$id, 'fo'=>true); }
  25140. else { $this->extgstates[] = array('n' => $this->n, 'trans' => 'TGS'.$id); }
  25141. }
  25142. }
  25143. }
  25144. /*-- END BACKGROUNDS --*/
  25145. function _putspotcolors() {
  25146. foreach($this->spotColors as $name=>$color) {
  25147. $this->_newobj();
  25148. $this->_out('[/Separation /'.str_replace(' ','#20',$name));
  25149. $this->_out('/DeviceCMYK <<');
  25150. $this->_out('/Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0] ');
  25151. $this->_out(sprintf('/C1 [%.3F %.3F %.3F %.3F] ',$color['c']/100,$color['m']/100,$color['y']/100,$color['k']/100));
  25152. $this->_out('/FunctionType 2 /Domain [0 1] /N 1>>]');
  25153. $this->_out('endobj');
  25154. $this->spotColors[$name]['n']=$this->n;
  25155. }
  25156. }
  25157. function _putresources() {
  25158. if ($this->hasOC) // mPDF 5.3.45
  25159. $this->_putocg(); // mPDF 5.3.41 Visibility
  25160. $this->_putextgstates();
  25161. $this->_putspotcolors();
  25162. if ($this->progressBar) { $this->UpdateProgressBar(2,'40','Compiling Fonts'); } // *PROGRESS-BAR*
  25163. $this->_putfonts();
  25164. if ($this->progressBar) { $this->UpdateProgressBar(2,'50','Compiling Images'); } // *PROGRESS-BAR*
  25165. $this->_putimages();
  25166. $this->_putformobjects(); // *IMAGES-CORE*
  25167. /*-- IMPORTS --*/
  25168. if ($this->enableImports) {
  25169. $this->_putformxobjects();
  25170. $this->_putimportedobjects();
  25171. }
  25172. /*-- END IMPORTS --*/
  25173. /*-- BACKGROUNDS --*/
  25174. $this->_putshaders();
  25175. $this->_putpatterns();
  25176. /*-- END BACKGROUNDS --*/
  25177. //Resource dictionary
  25178. $this->offsets[2]=strlen($this->buffer);
  25179. $this->_out('2 0 obj');
  25180. $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  25181. $this->_out('/Font <<');
  25182. foreach($this->fonts as $font) {
  25183. if (!$font['used'] && $font['type']=='TTF') { continue; }
  25184. if ($font['type']=='TTF' && ($font['sip'] || $font['smp'])) {
  25185. foreach($font['n'] AS $k => $fid) {
  25186. $this->_out('/F'.$font['subsetfontids'][$k].' '.$font['n'][$k].' 0 R');
  25187. }
  25188. }
  25189. else {
  25190. $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  25191. }
  25192. }
  25193. $this->_out('>>');
  25194. if (count($this->spotColors)) {
  25195. $this->_out('/ColorSpace <<');
  25196. foreach($this->spotColors as $color)
  25197. $this->_out('/CS'.$color['i'].' '.$color['n'].' 0 R');
  25198. $this->_out('>>');
  25199. }
  25200. if (count($this->extgstates)) {
  25201. $this->_out('/ExtGState <<');
  25202. foreach($this->extgstates as $k=>$extgstate)
  25203. if (isset($extgstate['trans'])) $this->_out('/'.$extgstate['trans'].' '.$extgstate['n'].' 0 R');
  25204. else $this->_out('/GS'.$k.' '.$extgstate['n'].' 0 R');
  25205. $this->_out('>>');
  25206. }
  25207. /*-- BACKGROUNDS --*/
  25208. if (isset($this->gradients) AND (count($this->gradients) > 0)) {
  25209. $this->_out('/Shading <<');
  25210. foreach ($this->gradients as $id => $grad) {
  25211. $this->_out('/Sh'.$id.' '.$grad['id'].' 0 R');
  25212. }
  25213. $this->_out('>>');
  25214. /*
  25215. // ??? Not needed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  25216. $this->_out('/Pattern <<');
  25217. foreach ($this->gradients as $id => $grad) {
  25218. $this->_out('/P'.$id.' '.$grad['pattern'].' 0 R');
  25219. }
  25220. $this->_out('>>');
  25221. */
  25222. }
  25223. /*-- END BACKGROUNDS --*/
  25224. if(count($this->images) || count($this->formobjects) || ($this->enableImports && count($this->tpls))) {
  25225. $this->_out('/XObject <<');
  25226. foreach($this->images as $image)
  25227. $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
  25228. foreach($this->formobjects as $formobject)
  25229. $this->_out('/FO'.$formobject['i'].' '.$formobject['n'].' 0 R');
  25230. /*-- IMPORTS --*/
  25231. if ($this->enableImports && count($this->tpls)) {
  25232. foreach($this->tpls as $tplidx => $tpl) {
  25233. $this->_out($this->tplprefix.$tplidx.' '.$tpl['n'].' 0 R');
  25234. }
  25235. }
  25236. /*-- END IMPORTS --*/
  25237. $this->_out('>>');
  25238. }
  25239. /*-- BACKGROUNDS --*/
  25240. if (count($this->patterns)) {
  25241. $this->_out('/Pattern <<');
  25242. foreach($this->patterns as $k=>$patterns)
  25243. $this->_out('/P'.$k.' '.$patterns['n'].' 0 R');
  25244. $this->_out('>>');
  25245. }
  25246. /*-- END BACKGROUNDS --*/
  25247. // mPDF 5.3.41 Visibility
  25248. if ($this->hasOC) // mPDF 5.3.45
  25249. $this->_out('/Properties <</OC1 '.$this->n_ocg_print.' 0 R /OC2 '.$this->n_ocg_view.' 0 R /OC3 '.$this->n_ocg_hidden.' 0 R>>');
  25250. $this->_out('>>');
  25251. $this->_out('endobj'); // end resource dictionary
  25252. $this->_putbookmarks(); // *BOOKMARKS*
  25253. if (isset($this->js) && $this->js) {
  25254. $this->_putjavascript();
  25255. }
  25256. /*-- ENCRYPTION --*/
  25257. if ($this->encrypted) {
  25258. $this->_newobj();
  25259. $this->enc_obj_id = $this->n;
  25260. $this->_out('<<');
  25261. $this->_putencryption();
  25262. $this->_out('>>');
  25263. $this->_out('endobj');
  25264. }
  25265. /*-- END ENCRYPTION --*/
  25266. }
  25267. function _putjavascript() {
  25268. $this->_newobj();
  25269. $this->n_js = $this->n;
  25270. $this->_out('<<');
  25271. $this->_out('/Names [(EmbeddedJS) '.(1 + $this->n).' 0 R ]');
  25272. $this->_out('>>');
  25273. $this->_out('endobj');
  25274. $this->_newobj();
  25275. $this->_out('<<');
  25276. $this->_out('/S /JavaScript');
  25277. $this->_out('/JS '.$this->_textstring($this->js));
  25278. $this->_out('>>');
  25279. $this->_out('endobj');
  25280. }
  25281. /*-- ENCRYPTION --*/
  25282. function _putencryption() {
  25283. $this->_out('/Filter /Standard');
  25284. if ($this->useRC128encryption) {
  25285. $this->_out('/V 2');
  25286. $this->_out('/R 3');
  25287. $this->_out('/Length 128');
  25288. }
  25289. else {
  25290. $this->_out('/V 1');
  25291. $this->_out('/R 2');
  25292. }
  25293. $this->_out('/O ('.$this->_escape($this->Ovalue).')');
  25294. $this->_out('/U ('.$this->_escape($this->Uvalue).')');
  25295. $this->_out('/P '.$this->Pvalue);
  25296. }
  25297. /*-- END ENCRYPTION --*/
  25298. function _puttrailer() {
  25299. $this->_out('/Size '.($this->n+1));
  25300. $this->_out('/Root '.$this->n.' 0 R');
  25301. $this->_out('/Info '.$this->InfoRoot.' 0 R');
  25302. /*-- ENCRYPTION --*/
  25303. if ($this->encrypted) {
  25304. $this->_out('/Encrypt '.$this->enc_obj_id.' 0 R');
  25305. $this->_out('/ID [<'.$this->uniqid.'> <'.$this->uniqid.'>]');
  25306. }
  25307. else {
  25308. /*-- END ENCRYPTION --*/
  25309. $uniqid = md5(time() . $this->buffer);
  25310. $this->_out('/ID [<'.$uniqid.'> <'.$uniqid.'>]');
  25311. /*-- ENCRYPTION --*/
  25312. }
  25313. /*-- END ENCRYPTION --*/
  25314. }
  25315. /*-- ENCRYPTION --*/
  25316. function SetProtection($permissions=array(),$user_pass='',$owner_pass=null, $length=40) {
  25317. $this->encrypted=false;
  25318. if (is_string($permissions) && strlen($permissions)>0) { $permissions = array($permissions); }
  25319. else if (!is_array($permissions)) { return 0; }
  25320. $this->last_rc4_key='';
  25321. $this->padding="\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08".
  25322. "\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
  25323. $options = array(
  25324. 'print' => 4, // bit 3
  25325. 'modify' => 8, // bit 4
  25326. 'copy' => 16, // bit 5
  25327. 'annot-forms' => 32, // bit 6
  25328. 'fill-forms' => 256, // bit 9
  25329. 'extract' => 512, // bit 10
  25330. 'assemble' => 1024,// bit 11
  25331. 'print-highres' => 2048 // bit 12
  25332. );
  25333. // bit 31 = 1073741824
  25334. // bit 32 = 2147483648
  25335. // bits 13-31 = 2147479552
  25336. // bits 13-32 = 4294963200 + 192 = 4294963392
  25337. $protection = 4294963392; // bits 7,8,13-32
  25338. foreach ($permissions as $permission) {
  25339. if (!isset($options[$permission]))
  25340. $this->Error('Incorrect permission: '.$permission);
  25341. if ($options[$permission] > 32) { $this->useRC128encryption = true; }
  25342. if (isset($options[$permission])) $protection += $options[$permission];
  25343. }
  25344. if ($length==128) { $this->useRC128encryption = true; }
  25345. if ($owner_pass === null)
  25346. $owner_pass = uniqid(rand());
  25347. $this->encrypted = true;
  25348. $this->_generateencryptionkey($user_pass, $owner_pass, $protection);
  25349. }
  25350. // Compute key depending on object number where the encrypted data is stored
  25351. function _objectkey($n) {
  25352. if ($this->useRC128encryption)
  25353. $len = 16;
  25354. else
  25355. $len = 10;
  25356. return substr($this->_md5_16($this->encryption_key.pack('VXxx',$n)),0,$len);
  25357. }
  25358. // RC4 is the standard encryption algorithm used in PDF format
  25359. function _RC4($key, $text) {
  25360. if ($this->last_rc4_key != $key) {
  25361. $k = str_repeat($key, 256/strlen($key)+1);
  25362. $rc4 = range(0,255);
  25363. $j = 0;
  25364. for ($i=0; $i<256; $i++){
  25365. $t = $rc4[$i];
  25366. $j = ($j + $t + ord($k[$i])) % 256;
  25367. $rc4[$i] = $rc4[$j];
  25368. $rc4[$j] = $t;
  25369. }
  25370. $this->last_rc4_key = $key;
  25371. $this->last_rc4_key_c = $rc4;
  25372. } else {
  25373. $rc4 = $this->last_rc4_key_c;
  25374. }
  25375. $len = strlen($text);
  25376. $a = 0;
  25377. $b = 0;
  25378. $out = '';
  25379. for ($i=0; $i<$len; $i++){
  25380. $a = ($a+1)%256;
  25381. $t= $rc4[$a];
  25382. $b = ($b+$t)%256;
  25383. $rc4[$a] = $rc4[$b];
  25384. $rc4[$b] = $t;
  25385. $k = $rc4[($rc4[$a]+$rc4[$b])%256];
  25386. $out.= chr(ord($text[$i]) ^ $k);
  25387. }
  25388. return $out;
  25389. }
  25390. // Get MD5 as binary string
  25391. function _md5_16($string) {
  25392. return pack('H*',md5($string));
  25393. }
  25394. // Compute O value
  25395. function _Ovalue($user_pass, $owner_pass) {
  25396. $tmp = $this->_md5_16($owner_pass);
  25397. if ($this->useRC128encryption) {
  25398. for ($i = 0; $i < 50; ++$i) {
  25399. $tmp = $this->_md5_16($tmp);
  25400. }
  25401. }
  25402. if ($this->useRC128encryption)
  25403. $keybytelen = (128 / 8);
  25404. else
  25405. $keybytelen = (40 / 8);
  25406. $owner_RC4_key = substr($tmp,0,$keybytelen);
  25407. $enc = $this->_RC4($owner_RC4_key, $user_pass);
  25408. if ($this->useRC128encryption) {
  25409. $len = strlen($owner_RC4_key);
  25410. for ($i = 1; $i <= 19; ++$i) {
  25411. $key = '';
  25412. for ($j = 0; $j < $len; ++$j) {
  25413. $key .= chr(ord($owner_RC4_key{$j}) ^ $i);
  25414. }
  25415. $enc = $this->_RC4($key, $enc);
  25416. }
  25417. }
  25418. return $enc;
  25419. }
  25420. // Compute U value
  25421. function _Uvalue() {
  25422. if ($this->useRC128encryption) {
  25423. $tmp = $this->_md5_16($this->padding.$this->_hexToString($this->uniqid));
  25424. $enc = $this->_RC4($this->encryption_key, $tmp);
  25425. $len = strlen($tmp);
  25426. for ($i=1; $i<=19; ++$i) {
  25427. $key = '';
  25428. for ($j=0; $j<$len; ++$j) {
  25429. $key .= chr(ord($this->encryption_key{$j}) ^ $i);
  25430. }
  25431. $enc = $this->_RC4($key, $enc);
  25432. }
  25433. $enc .= str_repeat("\x00", 16);
  25434. return substr($enc, 0, 32);
  25435. }
  25436. else {
  25437. return $this->_RC4($this->encryption_key, $this->padding);
  25438. }
  25439. }
  25440. // Compute encryption key
  25441. function _generateencryptionkey($user_pass, $owner_pass, $protection) {
  25442. // Pad passwords
  25443. $user_pass = substr($user_pass.$this->padding,0,32);
  25444. $owner_pass = substr($owner_pass.$this->padding,0,32);
  25445. $chars = 'ABCDEF1234567890';
  25446. $id = '';
  25447. for ($i=0; $i<32; $i++) { $id .= $chars{rand(0, 15)}; }
  25448. $this->uniqid = md5($id);
  25449. // Compute O value
  25450. $this->Ovalue = $this->_Ovalue($user_pass,$owner_pass);
  25451. // Compute encyption key
  25452. if ($this->useRC128encryption)
  25453. $keybytelen = (128/8);
  25454. else
  25455. $keybytelen = (40/8);
  25456. $prot = sprintf('%032b', $protection);
  25457. $perms = chr(bindec(substr($prot,24,8)));
  25458. $perms .= chr(bindec(substr($prot,16,8)));
  25459. $perms .= chr(bindec(substr($prot,8,8)));
  25460. $perms .= chr(bindec(substr($prot,0,8)));
  25461. $tmp = $this->_md5_16($user_pass.$this->Ovalue.$perms.$this->_hexToString($this->uniqid));
  25462. if ($this->useRC128encryption) {
  25463. for ($i=0; $i<50; ++$i) {
  25464. $tmp = $this->_md5_16(substr($tmp, 0, $keybytelen));
  25465. }
  25466. }
  25467. $this->encryption_key = substr($tmp,0,$keybytelen);
  25468. // Compute U value
  25469. $this->Uvalue = $this->_Uvalue();
  25470. // Compute P value
  25471. $this->Pvalue = $protection;
  25472. }
  25473. function _hexToString($hs) {
  25474. $s = '';
  25475. $len = strlen($hs);
  25476. if (($len % 2) != 0) {
  25477. $hs .= '0';
  25478. ++$len;
  25479. }
  25480. for ($i = 0; $i < $len; $i += 2) {
  25481. $s .= chr(hexdec($hs{$i}.$hs{($i + 1)}));
  25482. }
  25483. return $s;
  25484. }
  25485. /*-- END ENCRYPTION --*/
  25486. //=========================================
  25487. /*-- BOOKMARKS --*/
  25488. // FROM class PDF_Bookmark
  25489. function Bookmark($txt,$level=0,$y=0) {
  25490. $txt = $this->purify_utf8_text($txt);
  25491. if ($this->text_input_as_HTML) {
  25492. $txt = $this->all_entities_to_utf8($txt);
  25493. }
  25494. if($y==-1) {
  25495. if (!$this->ColActive){ $y=$this->y; }
  25496. else { $y = $this->y0; } // If columns are on - mark top of columns
  25497. }
  25498. // else y is used as set, or =0 i.e. top of page
  25499. // DIRECTIONALITY RTL
  25500. $bmo = array('t'=>$txt,'l'=>$level,'y'=>$y,'p'=>$this->page);
  25501. if ($this->keep_block_together) {
  25502. $this->ktBMoutlines[]= $bmo;
  25503. }
  25504. /*-- TABLES --*/
  25505. else if ($this->table_rotate) {
  25506. $this->tbrot_BMoutlines[]= $bmo;
  25507. }
  25508. else if ($this->kwt) {
  25509. $this->kwt_BMoutlines[]= $bmo;
  25510. }
  25511. /*-- END TABLES --*/
  25512. else if ($this->ColActive) { // *COLUMNS*
  25513. $this->col_BMoutlines[]= $bmo; // *COLUMNS*
  25514. } // *COLUMNS*
  25515. else {
  25516. $this->BMoutlines[]= $bmo;
  25517. }
  25518. }
  25519. function _putbookmarks()
  25520. {
  25521. $nb=count($this->BMoutlines);
  25522. if($nb==0)
  25523. return;
  25524. $lru=array();
  25525. $level=0;
  25526. foreach($this->BMoutlines as $i=>$o)
  25527. {
  25528. if($o['l']>0)
  25529. {
  25530. $parent=$lru[$o['l']-1];
  25531. //Set parent and last pointers
  25532. $this->BMoutlines[$i]['parent']=$parent;
  25533. $this->BMoutlines[$parent]['last']=$i;
  25534. if($o['l']>$level)
  25535. {
  25536. //Level increasing: set first pointer
  25537. $this->BMoutlines[$parent]['first']=$i;
  25538. }
  25539. }
  25540. else
  25541. $this->BMoutlines[$i]['parent']=$nb;
  25542. if($o['l']<=$level and $i>0)
  25543. {
  25544. //Set prev and next pointers
  25545. $prev=$lru[$o['l']];
  25546. $this->BMoutlines[$prev]['next']=$i;
  25547. $this->BMoutlines[$i]['prev']=$prev;
  25548. }
  25549. $lru[$o['l']]=$i;
  25550. $level=$o['l'];
  25551. }
  25552. //Outline items
  25553. $n=$this->n+1;
  25554. foreach($this->BMoutlines as $i=>$o)
  25555. {
  25556. $this->_newobj();
  25557. $this->_out('<</Title '.$this->_UTF16BEtextstring($o['t']));
  25558. $this->_out('/Parent '.($n+$o['parent']).' 0 R');
  25559. if(isset($o['prev']))
  25560. $this->_out('/Prev '.($n+$o['prev']).' 0 R');
  25561. if(isset($o['next']))
  25562. $this->_out('/Next '.($n+$o['next']).' 0 R');
  25563. if(isset($o['first']))
  25564. $this->_out('/First '.($n+$o['first']).' 0 R');
  25565. if(isset($o['last']))
  25566. $this->_out('/Last '.($n+$o['last']).' 0 R');
  25567. if (isset($this->pageDim[$o['p']]['h'])) { $h=$this->pageDim[$o['p']]['h']; }
  25568. else { $h = 0; }
  25569. $this->_out(sprintf('/Dest [%d 0 R /XYZ 0 %.3F null]',1+2*($o['p']),($h-$o['y'])*_MPDFK));
  25570. // mPDF 5.3.39
  25571. if (isset($this->bookmarkStyles) && isset($this->bookmarkStyles[$o['l']])) {
  25572. // font style
  25573. $bms = $this->bookmarkStyles[$o['l']]['style'];
  25574. $style = 0;
  25575. if (strpos($bms,'B') !== false) { $style += 2; }
  25576. if (strpos($bms,'I') !== false) { $style += 1; }
  25577. $this->_out(sprintf('/F %d', $style));
  25578. // Colour
  25579. $col = $this->bookmarkStyles[$o['l']]['color'];
  25580. if (isset($col) && is_array($col) && count($col)==3) {
  25581. $this->_out(sprintf('/C [%.3F %.3F %.3F]', ($col[0]/255), ($col[1]/255), ($col[2]/255)));
  25582. }
  25583. }
  25584. $this->_out('/Count 0>>');
  25585. $this->_out('endobj');
  25586. }
  25587. //Outline root
  25588. $this->_newobj();
  25589. $this->OutlineRoot=$this->n;
  25590. $this->_out('<</Type /BMoutlines /First '.$n.' 0 R');
  25591. $this->_out('/Last '.($n+$lru[0]).' 0 R>>');
  25592. $this->_out('endobj');
  25593. }
  25594. /*-- END BOOKMARKS --*/
  25595. // *BOOKMARKS*
  25596. //======================================================
  25597. // DEPRACATED but included for backwards compatability
  25598. function startPageNums() {
  25599. }
  25600. //======================================================
  25601. /*-- TOC --*/
  25602. // ToC TABLE OF CONTENTS
  25603. // Initiate, and Mark a place for the Table of Contents to be inserted
  25604. function TOC($tocfont='', $tocfontsize=8, $tocindent=5, $resetpagenum='', $pagenumstyle='', $suppress='', $toc_orientation='', $TOCusePaging=true, $TOCuseLinking=false, $toc_id=0) {
  25605. if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); }
  25606. if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); }
  25607. $this->tocontents->TOC($tocfont, $tocfontsize, $tocindent, $resetpagenum, $pagenumstyle, $suppress, $toc_orientation, $TOCusePaging, $TOCuseLinking, $toc_id);
  25608. }
  25609. function TOCpagebreakByArray($a) {
  25610. if (!is_array($a)) { $a = array(); }
  25611. if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); }
  25612. if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); }
  25613. // mPDF 5.3.48
  25614. $tocfont = (isset($a['tocfont']) ? $a['tocfont'] : (isset($a['font']) ? $a['font'] : ''));
  25615. $tocfontsize = (isset($a['tocfontsize']) ? $a['tocfontsize'] : (isset($a['font-size']) ? $a['font-size'] : ''));
  25616. $tocindent = (isset($a['tocindent']) ? $a['tocindent'] : (isset($a['indent']) ? $a['indent'] : ''));
  25617. $TOCusePaging = (isset($a['TOCusePaging']) ? $a['TOCusePaging'] : (isset($a['paging']) ? $a['paging'] : true));
  25618. $TOCuseLinking = (isset($a['TOCuseLinking']) ? $a['TOCuseLinking'] : (isset($a['links']) ? $a['links'] : ''));
  25619. $toc_orientation = (isset($a['toc_orientation']) ? $a['toc_orientation'] : (isset($a['toc-orientation']) ? $a['toc-orientation'] : ''));
  25620. $toc_mgl = (isset($a['toc_mgl']) ? $a['toc_mgl'] : (isset($a['toc-margin-left']) ? $a['toc-margin-left'] : ''));
  25621. $toc_mgr = (isset($a['toc_mgr']) ? $a['toc_mgr'] : (isset($a['toc-margin-right']) ? $a['toc-margin-right'] : ''));
  25622. $toc_mgt = (isset($a['toc_mgt']) ? $a['toc_mgt'] : (isset($a['toc-margin-top']) ? $a['toc-margin-top'] : ''));
  25623. $toc_mgb = (isset($a['toc_mgb']) ? $a['toc_mgb'] : (isset($a['toc-margin-bottom']) ? $a['toc-margin-bottom'] : ''));
  25624. $toc_mgh = (isset($a['toc_mgh']) ? $a['toc_mgh'] : (isset($a['toc-margin-header']) ? $a['toc-margin-header'] : ''));
  25625. $toc_mgf = (isset($a['toc_mgf']) ? $a['toc_mgf'] : (isset($a['toc-margin-footer']) ? $a['toc-margin-footer'] : ''));
  25626. $toc_ohname = (isset($a['toc_ohname']) ? $a['toc_ohname'] : (isset($a['toc-odd-header-name']) ? $a['toc-odd-header-name'] : ''));
  25627. $toc_ehname = (isset($a['toc_ehname']) ? $a['toc_ehname'] : (isset($a['toc-even-header-name']) ? $a['toc-even-header-name'] : ''));
  25628. $toc_ofname = (isset($a['toc_ofname']) ? $a['toc_ofname'] : (isset($a['toc-odd-footer-name']) ? $a['toc-odd-footer-name'] : ''));
  25629. $toc_efname = (isset($a['toc_efname']) ? $a['toc_efname'] : (isset($a['toc-even-footer-name']) ? $a['toc-even-footer-name'] : ''));
  25630. $toc_ohvalue = (isset($a['toc_ohvalue']) ? $a['toc_ohvalue'] : (isset($a['toc-odd-header-value']) ? $a['toc-odd-header-value'] : 0));
  25631. $toc_ehvalue = (isset($a['toc_ehvalue']) ? $a['toc_ehvalue'] : (isset($a['toc-even-header-value']) ? $a['toc-even-header-value'] : 0));
  25632. $toc_ofvalue = (isset($a['toc_ofvalue']) ? $a['toc_ofvalue'] : (isset($a['toc-odd-footer-value']) ? $a['toc-odd-footer-value'] : 0));
  25633. $toc_efvalue = (isset($a['toc_efvalue']) ? $a['toc_efvalue'] : (isset($a['toc-even-footer-value']) ? $a['toc-even-footer-value'] : 0));
  25634. $toc_preHTML = (isset($a['toc_preHTML']) ? $a['toc_preHTML'] : (isset($a['toc-preHTML']) ? $a['toc-preHTML'] : ''));
  25635. $toc_postHTML = (isset($a['toc_postHTML']) ? $a['toc_postHTML'] : (isset($a['toc-postHTML']) ? $a['toc-postHTML'] : ''));
  25636. $toc_bookmarkText = (isset($a['toc_bookmarkText']) ? $a['toc_bookmarkText'] : (isset($a['toc-bookmarkText']) ? $a['toc-bookmarkText'] : ''));
  25637. $resetpagenum = (isset($a['resetpagenum']) ? $a['resetpagenum'] : '');
  25638. $pagenumstyle = (isset($a['pagenumstyle']) ? $a['pagenumstyle'] : '');
  25639. $suppress = (isset($a['suppress']) ? $a['suppress'] : '');
  25640. $orientation = (isset($a['orientation']) ? $a['orientation'] : '');
  25641. $mgl = (isset($a['mgl']) ? $a['mgl'] : (isset($a['margin-left']) ? $a['margin-left'] : ''));
  25642. $mgr = (isset($a['mgr']) ? $a['mgr'] : (isset($a['margin-right']) ? $a['margin-right'] : ''));
  25643. $mgt = (isset($a['mgt']) ? $a['mgt'] : (isset($a['margin-top']) ? $a['margin-top'] : ''));
  25644. $mgb = (isset($a['mgb']) ? $a['mgb'] : (isset($a['margin-bottom']) ? $a['margin-bottom'] : ''));
  25645. $mgh = (isset($a['mgh']) ? $a['mgh'] : (isset($a['margin-header']) ? $a['margin-header'] : ''));
  25646. $mgf = (isset($a['mgf']) ? $a['mgf'] : (isset($a['margin-footer']) ? $a['margin-footer'] : ''));
  25647. $ohname = (isset($a['ohname']) ? $a['ohname'] : (isset($a['odd-header-name']) ? $a['odd-header-name'] : ''));
  25648. $ehname = (isset($a['ehname']) ? $a['ehname'] : (isset($a['even-header-name']) ? $a['even-header-name'] : ''));
  25649. $ofname = (isset($a['ofname']) ? $a['ofname'] : (isset($a['odd-footer-name']) ? $a['odd-footer-name'] : ''));
  25650. $efname = (isset($a['efname']) ? $a['efname'] : (isset($a['even-footer-name']) ? $a['even-footer-name'] : ''));
  25651. $ohvalue = (isset($a['ohvalue']) ? $a['ohvalue'] : (isset($a['odd-header-value']) ? $a['odd-header-value'] : 0));
  25652. $ehvalue = (isset($a['ehvalue']) ? $a['ehvalue'] : (isset($a['even-header-value']) ? $a['even-header-value'] : 0));
  25653. $ofvalue = (isset($a['ofvalue']) ? $a['ofvalue'] : (isset($a['odd-footer-value']) ? $a['odd-footer-value'] : 0));
  25654. $efvalue = (isset($a['efvalue']) ? $a['efvalue'] : (isset($a['even-footer-value']) ? $a['even-footer-value'] : 0));
  25655. $toc_id = (isset($a['toc_id']) ? $a['toc_id'] : (isset($a['name']) ? $a['name'] : 0));
  25656. $pagesel = (isset($a['pagesel']) ? $a['pagesel'] : (isset($a['pageselector']) ? $a['pageselector'] : ''));
  25657. $toc_pagesel = (isset($a['toc_pagesel']) ? $a['toc_pagesel'] : (isset($a['toc-pageselector']) ? $a['toc-pageselector'] : ''));
  25658. $sheetsize = (isset($a['sheetsize']) ? $a['sheetsize'] : (isset($a['sheet-size']) ? $a['sheet-size'] : ''));
  25659. $toc_sheetsize = (isset($a['toc_sheetsize']) ? $a['toc_sheetsize'] : (isset($a['toc-sheet-size']) ? $a['toc-sheet-size'] : ''));
  25660. $this->tocontents->TOCpagebreak($tocfont, $tocfontsize, $tocindent, $TOCusePaging, $TOCuseLinking, $toc_orientation, $toc_mgl, $toc_mgr, $toc_mgt, $toc_mgb, $toc_mgh, $toc_mgf, $toc_ohname, $toc_ehname, $toc_ofname, $toc_efname, $toc_ohvalue, $toc_ehvalue, $toc_ofvalue, $toc_efvalue, $toc_preHTML, $toc_postHTML, $toc_bookmarkText, $resetpagenum, $pagenumstyle, $suppress, $orientation, $mgl, $mgr, $mgt, $mgb, $mgh, $mgf, $ohname, $ehname, $ofname, $efname, $ohvalue, $ehvalue, $ofvalue, $efvalue, $toc_id, $pagesel, $toc_pagesel, $sheetsize, $toc_sheetsize);
  25661. }
  25662. function TOCpagebreak($tocfont='', $tocfontsize='', $tocindent='', $TOCusePaging=true, $TOCuseLinking='', $toc_orientation='', $toc_mgl='',$toc_mgr='',$toc_mgt='',$toc_mgb='',$toc_mgh='',$toc_mgf='',$toc_ohname='',$toc_ehname='',$toc_ofname='',$toc_efname='',$toc_ohvalue=0,$toc_ehvalue=0,$toc_ofvalue=0, $toc_efvalue=0, $toc_preHTML='', $toc_postHTML='', $toc_bookmarkText='', $resetpagenum='', $pagenumstyle='', $suppress='', $orientation='', $mgl='',$mgr='',$mgt='',$mgb='',$mgh='',$mgf='',$ohname='',$ehname='',$ofname='',$efname='',$ohvalue=0,$ehvalue=0,$ofvalue=0,$efvalue=0, $toc_id=0, $pagesel='', $toc_pagesel='', $sheetsize='', $toc_sheetsize='') {
  25663. if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); }
  25664. if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); }
  25665. //Start a new page
  25666. if($this->state==0) $this->AddPage();
  25667. if ($this->y == $this->tMargin && (!$this->mirrorMargins ||($this->mirrorMargins && $this->page % 2==1))) {
  25668. // Don't add a page
  25669. if ($this->page==1 && count($this->PageNumSubstitutions)==0) {
  25670. if (!$suppress) { $suppress = 'off'; }
  25671. if (!$resetpagenum) { $resetpagenum= 1; }
  25672. //$this->PageNumSubstitutions[] = array('from'=>1, 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=> $suppress);
  25673. }
  25674. $this->PageNumSubstitutions[] = array('from'=>$this->page, 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=> $suppress);
  25675. }
  25676. else {
  25677. $this->AddPage($orientation,'NEXT-ODD', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$sheetsize);
  25678. }
  25679. $this->tocontents->TOCpagebreak($tocfont, $tocfontsize, $tocindent, $TOCusePaging, $TOCuseLinking, $toc_orientation, $toc_mgl, $toc_mgr, $toc_mgt, $toc_mgb, $toc_mgh, $toc_mgf, $toc_ohname, $toc_ehname, $toc_ofname, $toc_efname, $toc_ohvalue, $toc_ehvalue, $toc_ofvalue, $toc_efvalue, $toc_preHTML, $toc_postHTML, $toc_bookmarkText, $resetpagenum, $pagenumstyle, $suppress, $orientation, $mgl, $mgr, $mgt, $mgb, $mgh, $mgf, $ohname, $ehname, $ofname, $efname, $ohvalue, $ehvalue, $ofvalue, $efvalue, $toc_id, $pagesel, $toc_pagesel, $sheetsize, $toc_sheetsize);
  25680. }
  25681. function TOC_Entry($txt, $level=0, $toc_id=0) {
  25682. $txt = $this->purify_utf8_text($txt);
  25683. if ($this->text_input_as_HTML) {
  25684. $txt = $this->all_entities_to_utf8($txt);
  25685. }
  25686. if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  25687. if ($this->ColActive) { $ily = $this->y0; } else { $ily = $this->y; } // use top of columns
  25688. $linkn = $this->AddLink();
  25689. $this->SetLink($linkn,$ily,$this->page);
  25690. /*-- RTL --*/
  25691. if ($this->biDirectional) {
  25692. $txt = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $txt );
  25693. }
  25694. /*-- END RTL --*/
  25695. if (strtoupper($toc_id)=='ALL') { $toc_id = '_mpdf_all'; }
  25696. else if (!$toc_id) { $toc_id = 0; }
  25697. else { $toc_id = strtolower($toc_id); }
  25698. $btoc = array('t'=>$txt,'l'=>$level,'p'=>$this->page, 'link'=>$linkn, 'toc_id'=>$toc_id);
  25699. if ($this->keep_block_together) {
  25700. $this->_kttoc[]= $btoc;
  25701. }
  25702. /*-- TABLES --*/
  25703. else if ($this->table_rotate) {
  25704. $this->tbrot_toc[]= $btoc;
  25705. }
  25706. else if ($this->kwt) {
  25707. $this->kwt_toc[]= $btoc;
  25708. }
  25709. /*-- END TABLES --*/
  25710. else if ($this->ColActive) { // *COLUMNS*
  25711. $this->col_toc[]= $btoc; // *COLUMNS*
  25712. } // *COLUMNS*
  25713. else {
  25714. $this->tocontents->_toc[]= $btoc;
  25715. }
  25716. }
  25717. /*-- END TOC --*/
  25718. //======================================================
  25719. function MovePages($target_page, $start_page, $end_page=-1) {
  25720. // move a page/pages EARLIER in the document
  25721. if ($end_page<1) { $end_page = $start_page; }
  25722. $n_toc = $end_page - $start_page + 1;
  25723. // Set/Update PageNumSubstitutions changes before moving anything
  25724. if (count($this->PageNumSubstitutions)) {
  25725. $tp_present = false;
  25726. $sp_present = false;
  25727. $ep_present = false;
  25728. foreach($this->PageNumSubstitutions AS $k=>$v) {
  25729. if ($this->PageNumSubstitutions[$k]['from']==$target_page) {
  25730. $tp_present = true;
  25731. if ($this->PageNumSubstitutions[$k]['suppress']!='on' && $this->PageNumSubstitutions[$k]['suppress']!=1) {
  25732. $this->PageNumSubstitutions[$k]['suppress']='off';
  25733. }
  25734. }
  25735. if ($this->PageNumSubstitutions[$k]['from']==$start_page) {
  25736. $sp_present = true;
  25737. if ($this->PageNumSubstitutions[$k]['suppress']!='on' && $this->PageNumSubstitutions[$k]['suppress']!=1) {
  25738. $this->PageNumSubstitutions[$k]['suppress']='off';
  25739. }
  25740. }
  25741. if ($this->PageNumSubstitutions[$k]['from']==($end_page+1)) {
  25742. $ep_present = true;
  25743. if ($this->PageNumSubstitutions[$k]['suppress']!='on' && $this->PageNumSubstitutions[$k]['suppress']!=1) {
  25744. $this->PageNumSubstitutions[$k]['suppress']='off';
  25745. }
  25746. }
  25747. }
  25748. if (!$tp_present) {
  25749. list($tp_type, $tp_suppress, $tp_reset) = $this->docPageSettings($target_page);
  25750. }
  25751. if (!$sp_present) {
  25752. list($sp_type, $sp_suppress, $sp_reset) = $this->docPageSettings($start_page);
  25753. }
  25754. if (!$ep_present) {
  25755. list($ep_type, $ep_suppress, $ep_reset) = $this->docPageSettings($start_page-1);
  25756. }
  25757. }
  25758. $last = array();
  25759. //store pages
  25760. for($i = $start_page;$i <= $end_page ;$i++)
  25761. $last[]=$this->pages[$i];
  25762. //move pages
  25763. for($i=$start_page - 1;$i>=($target_page);$i--) {
  25764. $this->pages[$i+$n_toc]=$this->pages[$i];
  25765. }
  25766. //Put toc pages at insert point
  25767. for($i = 0;$i < $n_toc;$i++) {
  25768. $this->pages[$target_page + $i]=$last[$i];
  25769. }
  25770. /*-- BOOKMARKS --*/
  25771. // Update Bookmarks
  25772. foreach($this->BMoutlines as $i=>$o) {
  25773. if($o['p']>=$target_page) {
  25774. $this->BMoutlines[$i]['p'] += $n_toc;
  25775. }
  25776. }
  25777. /*-- END BOOKMARKS --*/
  25778. // Update Page Links
  25779. if (count($this->PageLinks)) {
  25780. $newarr = array();
  25781. foreach($this->PageLinks as $i=>$o) {
  25782. foreach($this->PageLinks[$i] as $key => $pl) {
  25783. if (strpos($pl[4],'@')===0) {
  25784. $p=substr($pl[4],1);
  25785. if($p>=$start_page && $p<=$end_page) {
  25786. $this->PageLinks[$i][$key][4] = '@'.($p + ($target_page - $start_page));
  25787. }
  25788. else if($p>=$target_page && $p<$start_page) {
  25789. $this->PageLinks[$i][$key][4] = '@'.($p+$n_toc);
  25790. }
  25791. }
  25792. }
  25793. if($i>=$start_page && $i<=$end_page) {
  25794. $newarr[($i + ($target_page - $start_page))] = $this->PageLinks[$i];
  25795. }
  25796. else if($i>=$target_page && $i<$start_page) {
  25797. $newarr[($i + $n_toc)] = $this->PageLinks[$i];
  25798. }
  25799. else {
  25800. $newarr[$i] = $this->PageLinks[$i];
  25801. }
  25802. }
  25803. $this->PageLinks = $newarr;
  25804. }
  25805. // OrientationChanges
  25806. if (count($this->OrientationChanges)) {
  25807. $newarr = array();
  25808. foreach($this->OrientationChanges AS $p=>$v) {
  25809. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->OrientationChanges[$p]; }
  25810. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->OrientationChanges[$p]; }
  25811. else { $newarr[$p] = $this->OrientationChanges[$p]; }
  25812. }
  25813. ksort($newarr);
  25814. $this->OrientationChanges = $newarr;
  25815. }
  25816. // Page Dimensions
  25817. if (count($this->pageDim)) {
  25818. $newarr = array();
  25819. foreach($this->pageDim AS $p=>$v) {
  25820. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->pageDim[$p]; }
  25821. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->pageDim[$p]; }
  25822. else { $newarr[$p] = $this->pageDim[$p]; }
  25823. }
  25824. ksort($newarr);
  25825. $this->pageDim = $newarr;
  25826. }
  25827. // HTML Headers & Footers
  25828. if (count($this->saveHTMLHeader)) {
  25829. $newarr = array();
  25830. foreach($this->saveHTMLHeader AS $p=>$v) {
  25831. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->saveHTMLHeader[$p]; }
  25832. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->saveHTMLHeader[$p]; }
  25833. else { $newarr[$p] = $this->saveHTMLHeader[$p]; }
  25834. }
  25835. ksort($newarr);
  25836. $this->saveHTMLHeader = $newarr;
  25837. }
  25838. if (count($this->saveHTMLFooter)) {
  25839. $newarr = array();
  25840. foreach($this->saveHTMLFooter AS $p=>$v) {
  25841. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->saveHTMLFooter[$p]; }
  25842. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->saveHTMLFooter[$p]; }
  25843. else { $newarr[$p] = $this->saveHTMLFooter[$p]; }
  25844. }
  25845. ksort($newarr);
  25846. $this->saveHTMLFooter = $newarr;
  25847. }
  25848. // Update Internal Links
  25849. if (count($this->internallink)) {
  25850. foreach($this->internallink as $key=>$o) {
  25851. if($o['PAGE']>=$start_page && $o['PAGE']<=$end_page) {
  25852. $this->internallink[$key]['PAGE'] += ($target_page - $start_page);
  25853. }
  25854. else if($o['PAGE']>=$target_page && $o['PAGE']<$start_page) {
  25855. $this->internallink[$key]['PAGE'] += $n_toc;
  25856. }
  25857. }
  25858. }
  25859. // Update Links
  25860. if (count($this->links)) {
  25861. foreach($this->links as $key=>$o) {
  25862. if($o[0]>=$start_page && $o[0]<=$end_page) {
  25863. $this->links[$key][0] += ($target_page - $start_page);
  25864. }
  25865. if($o[0]>=$target_page && $o[0]<$start_page) {
  25866. $this->links[$key][0] += $n_toc;
  25867. }
  25868. }
  25869. }
  25870. // Update Form fields
  25871. if (count($this->form->forms)) {
  25872. foreach($this->form->forms as $key=>$f) {
  25873. if($f['page']>=$start_page && $f['page']<=$end_page) {
  25874. $this->form->forms[$key]['page'] += ($target_page - $start_page);
  25875. }
  25876. if($f['page']>=$target_page && $f['page']<$start_page) {
  25877. $this->form->forms[$key]['page'] += $n_toc;
  25878. }
  25879. }
  25880. }
  25881. /*-- ANNOTATIONS --*/
  25882. // Update Annotations
  25883. if (count($this->PageAnnots)) {
  25884. $newarr = array();
  25885. foreach($this->PageAnnots as $p=>$anno) {
  25886. if($p>=$start_page && $p<=$end_page) {
  25887. $np = $p + ($target_page - $start_page);
  25888. foreach($anno as $o) {
  25889. $newarr[$np][] = $o;
  25890. }
  25891. }
  25892. else if($p>=$target_page && $p<$start_page) {
  25893. $np = $p + $n_toc;
  25894. foreach($anno as $o) {
  25895. $newarr[$np][] = $o;
  25896. }
  25897. }
  25898. else {
  25899. $newarr[$p] = $this->PageAnnots[$p];
  25900. }
  25901. }
  25902. $this->PageAnnots = $newarr;
  25903. unset($newarr);
  25904. }
  25905. /*-- END ANNOTATIONS --*/
  25906. // Update PageNumSubstitutions
  25907. if (count($this->PageNumSubstitutions)) {
  25908. $newarr = array();
  25909. foreach($this->PageNumSubstitutions AS $k=>$v) {
  25910. if($this->PageNumSubstitutions[$k]['from']>=$start_page && $this->PageNumSubstitutions[$k]['from']<=$end_page) {
  25911. $this->PageNumSubstitutions[$k]['from'] += ($target_page - $start_page);
  25912. $newarr[$this->PageNumSubstitutions[$k]['from']] = $this->PageNumSubstitutions[$k];
  25913. }
  25914. else if($this->PageNumSubstitutions[$k]['from']>=$target_page && $this->PageNumSubstitutions[$k]['from']<$start_page) {
  25915. $this->PageNumSubstitutions[$k]['from'] += $n_toc;
  25916. $newarr[$this->PageNumSubstitutions[$k]['from']] = $this->PageNumSubstitutions[$k];
  25917. }
  25918. else {
  25919. $newarr[$this->PageNumSubstitutions[$k]['from']] = $this->PageNumSubstitutions[$k];
  25920. }
  25921. }
  25922. if (!$sp_present) {
  25923. $newarr[$target_page] = array('from'=>$target_page, 'suppress'=>$sp_suppress, 'reset'=>$sp_reset, 'type'=>$sp_type);
  25924. }
  25925. if (!$tp_present) {
  25926. $newarr[($target_page + $n_toc)] = array('from'=>($target_page+$n_toc), 'suppress'=>$tp_suppress, 'reset'=>$tp_reset, 'type'=>$tp_type);
  25927. }
  25928. if (!$ep_present && $end_page>count($this->pages)) {
  25929. $newarr[($end_page+1)] = array('from'=>($end_page+1), 'suppress'=>$ep_suppress, 'reset'=>$ep_reset, 'type'=>$ep_type);
  25930. }
  25931. ksort($newarr);
  25932. $this->PageNumSubstitutions = array();
  25933. foreach($newarr as $v) {
  25934. $this->PageNumSubstitutions[] = $v;
  25935. }
  25936. }
  25937. }
  25938. //======================================================
  25939. function DeletePages($start_page, $end_page=-1) {
  25940. // move a page/pages EARLIER in the document
  25941. if ($end_page<1) { $end_page = $start_page; }
  25942. $n_tod = $end_page - $start_page + 1;
  25943. $last_page = count($this->pages);
  25944. $n_atend = $last_page - $end_page + 1;
  25945. //move pages
  25946. for($i=0;$i<$n_atend;$i++) {
  25947. $this->pages[$start_page+$i]=$this->pages[$end_page+1+$i];
  25948. }
  25949. //delete pages
  25950. for($i = 0;$i < $n_tod ;$i++)
  25951. unset($this->pages[$last_page-$i]);
  25952. /*-- BOOKMARKS --*/
  25953. // Update Bookmarks
  25954. foreach($this->BMoutlines as $i=>$o) {
  25955. if($o['p']>=$end_page) { $this->BMoutlines[$i]['p'] -= $n_tod; }
  25956. else if($p<$start_page) { unset($this->BMoutlines[$i]); }
  25957. }
  25958. /*-- END BOOKMARKS --*/
  25959. // Update Page Links
  25960. if (count($this->PageLinks)) {
  25961. $newarr = array();
  25962. foreach($this->PageLinks as $i=>$o) {
  25963. foreach($this->PageLinks[$i] as $key => $pl) {
  25964. if (strpos($pl[4],'@')===0) {
  25965. $p=substr($pl[4],1);
  25966. if($p>$end_page) { $this->PageLinks[$i][$key][4] = '@'.($p - $n_tod); }
  25967. else if($p<$start_page) { unset($this->PageLinks[$i][$key]); }
  25968. }
  25969. }
  25970. if($i>$end_page) { $newarr[($i - $n_tod)] = $this->PageLinks[$i]; }
  25971. else if($p<$start_page) { $newarr[$i] = $this->PageLinks[$i]; }
  25972. }
  25973. $this->PageLinks = $newarr;
  25974. }
  25975. // OrientationChanges
  25976. if (count($this->OrientationChanges)) {
  25977. $newarr = array();
  25978. foreach($this->OrientationChanges AS $p=>$v) {
  25979. if($p>$end_page) { $newarr[($p - $t_tod)] = $this->OrientationChanges[$p]; }
  25980. else if($p<$start_page) { $newarr[$p] = $this->OrientationChanges[$p]; }
  25981. }
  25982. ksort($newarr);
  25983. $this->OrientationChanges = $newarr;
  25984. }
  25985. // Page Dimensions
  25986. if (count($this->pageDim)) {
  25987. $newarr = array();
  25988. foreach($this->pageDim AS $p=>$v) {
  25989. if($p>$end_page) { $newarr[($p - $n_tod)] = $this->pageDim[$p]; }
  25990. else if($p<$start_page) { $newarr[$p] = $this->pageDim[$p]; }
  25991. }
  25992. ksort($newarr);
  25993. $this->pageDim = $newarr;
  25994. }
  25995. // HTML Headers & Footers
  25996. if (count($this->saveHTMLHeader)) {
  25997. foreach($this->saveHTMLHeader AS $p=>$v) {
  25998. if($p>end_page) { $newarr[($p - $n_tod)] = $this->saveHTMLHeader[$p]; }
  25999. else if($p<$start_page) { $newarr[$p] = $this->saveHTMLHeader[$p]; }
  26000. }
  26001. ksort($newarr);
  26002. $this->saveHTMLHeader = $newarr;
  26003. }
  26004. if (count($this->saveHTMLFooter)) {
  26005. $newarr = array();
  26006. foreach($this->saveHTMLFooter AS $p=>$v) {
  26007. if($p>$end_page) { $newarr[($p - $n_tod)] = $this->saveHTMLFooter[$p]; }
  26008. else if($p<$start_page) { $newarr[$p] = $this->saveHTMLFooter[$p]; }
  26009. }
  26010. ksort($newarr);
  26011. $this->saveHTMLFooter = $newarr;
  26012. }
  26013. // Update Internal Links
  26014. foreach($this->internallink as $key=>$o) {
  26015. if($o['PAGE']>$end_page) { $this->internallink[$key]['PAGE'] -= $n_tod; }
  26016. else if($o['PAGE']<$start_page) { unset($this->internallink[$key]); }
  26017. }
  26018. // Update Links
  26019. foreach($this->links as $key=>$o) {
  26020. if($o[0]>$end_page) { $this->links[$key][0] -= $n_tod; }
  26021. else if($o[0]<$start_page) { unset($this->links[$key]); }
  26022. }
  26023. // Update Form fields
  26024. foreach($this->form->forms as $key=>$f) {
  26025. if($f['page']>$end_page) { $this->form->forms[$key]['page'] -= $n_tod; }
  26026. else if($f['page']<$start_page) { unset($this->form->forms[$key]); }
  26027. }
  26028. /*-- ANNOTATIONS --*/
  26029. // Update Annotations
  26030. if (count($this->PageAnnots)) {
  26031. $newarr = array();
  26032. foreach($this->PageAnnots as $p=>$anno) {
  26033. if($p>$end_page) { foreach($anno as $o) { $newarr[($p - $n_tod)][] = $o; } }
  26034. else if($p<$start_page) { $newarr[$p] = $this->PageAnnots[$p]; }
  26035. }
  26036. ksort($newarr);
  26037. $this->PageAnnots = $newarr;
  26038. }
  26039. /*-- END ANNOTATIONS --*/
  26040. // Update PageNumSubstitutions
  26041. foreach($this->PageNumSubstitutions AS $k=>$v) {
  26042. if($this->PageNumSubstitutions[$k]['from']>$end_page) { $this->PageNumSubstitutions[$k]['from'] -= $n_tod; }
  26043. else if($this->PageNumSubstitutions[$k]['from']<$start_page) { unset($this->PageNumSubstitutions[$k]); }
  26044. }
  26045. unset($newarr);
  26046. $this->page = count($this->pages);
  26047. }
  26048. //======================================================
  26049. /*-- INDEX --*/
  26050. // FROM class PDF_Ref == INDEX
  26051. function Reference($txt) {
  26052. $this->IndexEntry($txt);
  26053. }
  26054. function IndexEntry($txt, $xref='') {
  26055. if ($xref) {
  26056. $this->IndexEntrySee($txt,$xref);
  26057. return;
  26058. }
  26059. $txt = strip_tags($txt);
  26060. $txt = $this->purify_utf8_text($txt);
  26061. if ($this->text_input_as_HTML) {
  26062. $txt = $this->all_entities_to_utf8($txt);
  26063. }
  26064. if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  26065. $Present=0;
  26066. $size=sizeof($this->Reference);
  26067. if ($this->directionality == 'rtl') { // *RTL*
  26068. $txt = str_replace(':',' - ',$txt); // *RTL*
  26069. } // *RTL*
  26070. else { // *RTL*
  26071. $txt = str_replace(':',', ',$txt);
  26072. } // *RTL*
  26073. //Search the reference (AND Ref/PageNo) in the array
  26074. for ($i=0;$i<$size;$i++){
  26075. if ($this->keep_block_together) {
  26076. if (isset($this->ktReference[$i]['t']) && $this->ktReference[$i]['t']==$txt){
  26077. $Present=1;
  26078. if (!in_array($this->page,$this->ktReference[$i]['p'])) {
  26079. $this->ktReference[$i]['op'] = $this->page;
  26080. }
  26081. }
  26082. }
  26083. /*-- TABLES --*/
  26084. else if ($this->table_rotate) {
  26085. if (isset($this->tbrot_Reference[$i]['t']) && $this->tbrot_Reference[$i]['t']==$txt){
  26086. $Present=1;
  26087. if (!in_array($this->page,$this->tbrot_Reference[$i]['p'])) {
  26088. $this->tbrot_Reference[$i]['op'] = $this->page;
  26089. }
  26090. }
  26091. }
  26092. else if ($this->kwt) {
  26093. if (isset($this->kwt_Reference[$i]['t']) && $this->kwt_Reference[$i]['t']==$txt){
  26094. $Present=1;
  26095. if (!in_array($this->page,$this->kwt_Reference[$i]['p'])) {
  26096. $this->kwt_Reference[$i]['op'] = $this->page;
  26097. }
  26098. }
  26099. }
  26100. /*-- END TABLES --*/
  26101. /*-- COLUMNS --*/
  26102. else if ($this->ColActive) {
  26103. if (isset($this->col_Reference[$i]['t']) && $this->col_Reference[$i]['t']==$txt){
  26104. $Present=1;
  26105. if (!in_array($this->page,$this->col_Reference[$i]['p'])) {
  26106. $this->col_Reference[$i]['op'] = $this->page;
  26107. }
  26108. }
  26109. }
  26110. /*-- END COLUMNS --*/
  26111. else {
  26112. if (isset($this->Reference[$i]['t']) && $this->Reference[$i]['t']==$txt){
  26113. $Present=1;
  26114. if (!in_array($this->page,$this->Reference[$i]['p'])) {
  26115. $this->Reference[$i]['p'][] = $this->page;
  26116. }
  26117. }
  26118. }
  26119. }
  26120. //If not found, add it
  26121. if ($Present==0) {
  26122. $opr = array('t'=>$txt, 'op'=>$this->page);
  26123. if ($this->keep_block_together) {
  26124. $this->ktReference[]= $opr;
  26125. }
  26126. /*-- TABLES --*/
  26127. else if ($this->table_rotate) {
  26128. $this->tbrot_Reference[]= $opr;
  26129. }
  26130. else if ($this->kwt) {
  26131. $this->kwt_Reference[]= $opr;
  26132. }
  26133. /*-- END TABLES --*/
  26134. /*-- COLUMNS --*/
  26135. else if ($this->ColActive) {
  26136. $this->col_Reference[]= $opr;
  26137. }
  26138. /*-- END COLUMNS --*/
  26139. else {
  26140. $this->Reference[]=array('t'=>$txt,'p'=>array($this->page));
  26141. }
  26142. }
  26143. }
  26144. // Added function to add a reference "Elephants. See Chickens"
  26145. function ReferenceSee($txta,$txtb) {
  26146. $this->IndexEntrySee($txta,$txtb);
  26147. }
  26148. function IndexEntrySee($txta,$txtb) {
  26149. $txta = strip_tags($txta);
  26150. $txtb = strip_tags($txtb);
  26151. $txta = $this->purify_utf8_text($txta);
  26152. $txtb = $this->purify_utf8_text($txtb);
  26153. if ($this->text_input_as_HTML) {
  26154. $txta = $this->all_entities_to_utf8($txta);
  26155. $txtb = $this->all_entities_to_utf8($txtb);
  26156. }
  26157. if ($this->usingCoreFont) {
  26158. $txta = mb_convert_encoding($txta,$this->mb_enc,'UTF-8');
  26159. $txtb = mb_convert_encoding($txtb,$this->mb_enc,'UTF-8');
  26160. }
  26161. if ($this->directionality == 'rtl') { // *RTL*
  26162. $txta = str_replace(':',' - ',$txta); // *RTL*
  26163. $txtb = str_replace(':',' - ',$txtb); // *RTL*
  26164. } // *RTL*
  26165. else { // *RTL*
  26166. $txta = str_replace(':',', ',$txta);
  26167. $txtb = str_replace(':',', ',$txtb);
  26168. } // *RTL*
  26169. $this->Reference[]=array('t'=>$txta.' - see '.$txtb,'p'=>array());
  26170. }
  26171. function CreateReference($NbCol=1, $reffontsize='', $linespacing='', $offset=3, $usedivletters=1, $divlettfontsize='', $gap=5, $reffont='',$divlettfont='', $useLinking=false) {
  26172. $this->CreateIndex($NbCol, $reffontsize, $linespacing, $offset, $usedivletters, $divlettfontsize, $gap, $reffont, $divlettfont, $useLinking);
  26173. }
  26174. function CreateIndex($NbCol=1, $reffontsize='', $linespacing='', $offset=3, $usedivletters=1, $divlettfontsize='', $gap=5, $reffont='',$divlettfont='', $useLinking=false) {
  26175. if (!$reffontsize) { $reffontsize = $this->default_font_size; }
  26176. if (!$divlettfontsize) { $divlettfontsize = ($this->default_font_size * 1.8); }
  26177. if (!$reffont) { $reffont = $this->default_font; }
  26178. if (!$divlettfont) { $divlettfont = $reffont; }
  26179. if (!$linespacing) { $linespacing= $this->default_lineheight_correction; }
  26180. if ($this->ColActive) { $this->SetColumns(0); } // *COLUMNS*
  26181. $size=sizeof($this->Reference);
  26182. if ($size == 0) { return false; }
  26183. if ($NbCol<2) {
  26184. $NbCol = 1;
  26185. $colWidth = $this->pgwidth;
  26186. }
  26187. else {
  26188. $this->SetColumns($NbCol,'',$gap);
  26189. $colWidth = $this->ColWidth;
  26190. }
  26191. if ($this->directionality == 'rtl') { $align = 'R'; }
  26192. else { $align = 'L'; }
  26193. $lett = '';
  26194. if (!function_exists('cmp')) { // mPDF 5.3.07
  26195. function cmp ($a, $b) {
  26196. return strnatcmp(strtolower($a['t']), strtolower($b['t']));
  26197. }
  26198. }
  26199. //Alphabetic sort of the references
  26200. usort($this->Reference, 'cmp');
  26201. $size=sizeof($this->Reference);
  26202. $this->breakpoints[$this->CurrCol][] = $this->y; // *COLUMNS*
  26203. $divlettjuststarted = false;
  26204. $this->OpenTag('DIV',array('STYLE'=>'line-height: '.$linespacing.'; font-family: '.$reffont.'; font-size: '.$reffontsize.'pt; '));
  26205. $last_lett = '';
  26206. for ($i=0;$i<$size;$i++){
  26207. if ($this->Reference[$i]['t']) {
  26208. if ($usedivletters) {
  26209. $lett = mb_strtoupper(mb_substr($this->Reference[$i]['t'],0,1,$this->mb_enc ),$this->mb_enc );
  26210. if ($lett != $last_lett) {
  26211. $save_bp = $this->breakpoints[$this->CurrCol]; // *COLUMNS*
  26212. $divlettjuststarted = true;
  26213. if ($i>0) {
  26214. $this->OpenTag('DIV',array('STYLE'=>'line-height: '.$linespacing.'; font-family: '.$divlettfont.'; font-size: '.$divlettfontsize.'pt; font-weight: bold; page-break-after: avoid; margin-top: 0.5em; margin-collapse: collapse; '));
  26215. }
  26216. else {
  26217. $this->OpenTag('DIV',array('STYLE'=>'line-height: '.$linespacing.'; font-family: '.$divlettfont.'; font-size: '.$divlettfontsize.'pt; font-weight: bold; page-break-after: avoid; '));
  26218. }
  26219. $this->_saveTextBuffer($lett); // mPDF 5.3.99
  26220. $this->CloseTag('DIV');
  26221. }
  26222. }
  26223. $this->OpenTag('DIV',array('STYLE'=>'text-indent: -'.$offset.'mm; line-height: '.$linespacing.'; font-family: '.$reffont.'; font-size: '.$reffontsize.'pt; '));
  26224. /*-- RTL --*/
  26225. // Change Arabic + Persian. to Presentation Forms
  26226. if ($this->biDirectional) {
  26227. $this->Reference[$i]['t'] = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $this->Reference[$i]['t'] );
  26228. }
  26229. /*-- END RTL --*/
  26230. // Font-specific ligature substitution for Indic fonts
  26231. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($this->Reference[$i]['t']); // *INDIC*
  26232. $this->_saveTextBuffer($this->Reference[$i]['t']); // mPDF 5.3.99
  26233. $ppp = $this->Reference[$i]['p']; // = array of page numbers to point to
  26234. if (count($ppp)) {
  26235. sort($ppp);
  26236. $newarr = array();
  26237. $range_start = $ppp[0];
  26238. $range_end = 0;
  26239. if (!$this->usingCoreFont) { $spacer = "\xc2\xa0 "; }
  26240. else { $spacer = chr(160).' '; }
  26241. $this->_saveTextBuffer($spacer); // mPDF 5.3.99
  26242. if ($this->directionality == 'rtl') { $sep = '.'; $joiner = '-'; }
  26243. else { $sep = ', '; $joiner = '-'; }
  26244. for ($zi=1;$zi<count($ppp);$zi++) {
  26245. // RTL - Each number separately
  26246. if ($this->directionality == 'rtl') {
  26247. /*-- RTL --*/
  26248. if ($zi<count($ppp)-1) {
  26249. $txt = $sep . $this->docPageNum($ppp[$zi]);
  26250. if ($useLinking) { $href = '@'.$ppp[$zi]; }
  26251. else { $href = ''; }
  26252. $this->_saveTextBuffer($txt, $href); // mPDF 5.3.99
  26253. }
  26254. /*-- END RTL --*/
  26255. }
  26256. else if ($ppp[$zi] == ($ppp[($zi-1)]+1)) {
  26257. $range_end = $ppp[$zi];
  26258. }
  26259. else {
  26260. if ($range_end) {
  26261. if ($range_end == $range_start+1) {
  26262. if ($useLinking) { $href = '@'.$range_start; }
  26263. else { $href = ''; }
  26264. $txt = $this->docPageNum($range_start) . $sep;
  26265. $this->_saveTextBuffer($txt, $href); // mPDF 5.3.99
  26266. if ($useLinking) { $href = '@'.$ppp[$zi-1]; }
  26267. else { $href = ''; }
  26268. $txt = $this->docPageNum($ppp[$zi-1]) . $sep;
  26269. $this->_saveTextBuffer($txt, $href); // mPDF 5.3.99
  26270. }
  26271. else {
  26272. if ($useLinking) { $href = '@'.$range_start; }
  26273. else { $href = ''; }
  26274. }
  26275. }
  26276. else {
  26277. if ($useLinking) { $href = '@'.$ppp[$zi-1]; }
  26278. else { $href = ''; }
  26279. $txt = $this->docPageNum($ppp[$zi-1]) . $sep;
  26280. $this->_saveTextBuffer($txt, $href); // mPDF 5.3.99
  26281. }
  26282. $range_start = $ppp[$zi];
  26283. $range_end = 0;
  26284. }
  26285. }
  26286. if ($range_end) {
  26287. if ($range_end == $range_start+1) {
  26288. if ($useLinking) { $href = '@'.$range_start; }
  26289. else { $href = ''; }
  26290. $txt = $this->docPageNum($range_start) . $sep;
  26291. $this->_saveTextBuffer($txt, $href); // mPDF 5.3.99
  26292. if ($useLinking) { $href = '@'.$range_end; }
  26293. else { $href = ''; }
  26294. $txt = $this->docPageNum($range_end);
  26295. $this->_saveTextBuffer($txt, $href); // mPDF 5.3.99
  26296. }
  26297. else {
  26298. if ($useLinking) { $href = '@'.$range_start; }
  26299. else { $href = ''; }
  26300. $txt = $this->docPageNum($range_start) . $joiner;
  26301. $this->_saveTextBuffer($txt, $href); // mPDF 5.3.99
  26302. if ($useLinking) { $href = '@'.$range_end; }
  26303. else { $href = ''; }
  26304. $txt = $this->docPageNum($range_end);
  26305. $this->_saveTextBuffer($txt, $href); // mPDF 5.3.99
  26306. }
  26307. }
  26308. else {
  26309. if ($useLinking) { $href = '@'.$ppp[(count($ppp)-1)]; }
  26310. else { $href = ''; }
  26311. $txt = $this->docPageNum($ppp[(count($ppp)-1)]);
  26312. $this->_saveTextBuffer($txt, $href); // mPDF 5.3.99
  26313. }
  26314. }
  26315. }
  26316. $this->CloseTag('DIV');
  26317. if ($divlettjuststarted) { $this->breakpoints[$this->CurrCol] = $save_bp; } // *COLUMNS*
  26318. $divlettjuststarted = false;
  26319. $this->breakpoints[$this->CurrCol][] = $this->y; // *COLUMNS*
  26320. $last_lett = $lett;
  26321. }
  26322. $this->CloseTag('DIV');
  26323. $this->breakpoints[$this->CurrCol][] = $this->y; // *COLUMNS*
  26324. if ($this->ColActive) { $this->SetColumns(0); } // *COLUMNS*
  26325. }
  26326. /*-- END INDEX --*/
  26327. function AcceptPageBreak() {
  26328. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); } // *TABLES*
  26329. /*-- COLUMNS --*/
  26330. if ($this->ColActive==1) {
  26331. if($this->CurrCol<$this->NbCol-1) {
  26332. //Go to the next column
  26333. $this->CurrCol++;
  26334. $this->SetCol($this->CurrCol);
  26335. $this->y=$this->y0;
  26336. $this->ChangeColumn=1; // Number (and direction) of columns changed +1, +2, -2 etc.
  26337. // DIRECTIONALITY RTL
  26338. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  26339. //Stay on the page
  26340. return false;
  26341. }
  26342. else {
  26343. //Go back to the first column - NEW PAGE
  26344. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  26345. $this->SetCol(0);
  26346. $this->y0 = $this->tMargin;
  26347. $this->ChangeColumn= -($this->NbCol-1);
  26348. // DIRECTIONALITY RTL
  26349. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  26350. //Page break
  26351. return true;
  26352. }
  26353. }
  26354. /*-- END COLUMNS --*/
  26355. /*-- TABLES --*/
  26356. else if ($this->table_rotate) {
  26357. if ($this->tablebuffer) { $this->printtablebuffer(); }
  26358. return true;
  26359. }
  26360. /*-- END TABLES --*/
  26361. else { // *COLUMNS*
  26362. $this->ChangeColumn=0;
  26363. return $this->autoPageBreak;
  26364. } // *COLUMNS*
  26365. return $this->autoPageBreak;
  26366. }
  26367. //----------- COLUMNS ---------------------
  26368. /*-- COLUMNS --*/
  26369. function SetColumns($NbCol,$vAlign='',$gap=5) {
  26370. // NbCol = number of columns
  26371. // CurrCol = Number of the current column starting at 0
  26372. // Called externally to set columns on/off and number
  26373. // Integer 2 upwards sets columns on to that number
  26374. // Anything less than 2 turns columns off
  26375. if ($NbCol<2) { // SET COLUMNS OFF
  26376. if ($this->ColActive) {
  26377. $this->ColActive=0;
  26378. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  26379. $this->NbCol=1;
  26380. $this->ResetMargins();
  26381. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  26382. $this->divwidth = 0;
  26383. $this->Ln();
  26384. }
  26385. $this->ColActive=0;
  26386. $this->columnbuffer = array();
  26387. $this->ColDetails = array();
  26388. $this->columnLinks = array();
  26389. $this->columnAnnots = array();
  26390. $this->columnForms = array();
  26391. $this->col_Reference = array();
  26392. $this->col_BMoutlines = array();
  26393. $this->col_toc = array();
  26394. $this->breakpoints = array();
  26395. }
  26396. else { // SET COLUMNS ON
  26397. if ($this->ColActive) {
  26398. $this->ColActive=0;
  26399. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  26400. $this->ResetMargins();
  26401. }
  26402. if (isset($this->y) && $this->y>$this->tMargin) $this->Ln();
  26403. $this->NbCol=$NbCol;
  26404. $this->ColGap = $gap;
  26405. $this->divwidth = 0;
  26406. $this->ColActive=1;
  26407. $this->ColumnAdjust = true; // enables column height adjustment for the page
  26408. $this->columnbuffer = array();
  26409. $this->ColDetails = array();
  26410. $this->columnLinks = array();
  26411. $this->columnAnnots = array();
  26412. $this->columnForms = array();
  26413. $this->col_Reference = array();
  26414. $this->col_BMoutlines = array();
  26415. $this->col_toc = array();
  26416. $this->breakpoints = array();
  26417. if ((strtoupper($vAlign) == 'J') || (strtoupper($vAlign) == 'JUSTIFY')) { $vAlign = 'J'; }
  26418. else { $vAlign = ''; }
  26419. $this->colvAlign = $vAlign;
  26420. //Save the ordinate
  26421. $absL = $this->DeflMargin-($gap/2);
  26422. $absR = $this->DefrMargin-($gap/2);
  26423. $PageWidth = $this->w-$absL-$absR; // virtual pagewidth for calculation only
  26424. $ColWidth = (($PageWidth - ($gap * ($NbCol)))/$NbCol);
  26425. $this->ColWidth = $ColWidth;
  26426. /*-- RTL --*/
  26427. if ($this->directionality == 'rtl') {
  26428. for ($i=0;$i<$this->NbCol;$i++) {
  26429. $this->ColL[$i] = $absL + ($gap/2) + (($NbCol - ($i+1))*($PageWidth/$NbCol)) ;
  26430. $this->ColR[$i] = $this->ColL[$i] + $ColWidth; // NB This is not R margin -> R pos
  26431. }
  26432. }
  26433. else {
  26434. /*-- END RTL --*/
  26435. for ($i=0;$i<$this->NbCol;$i++) {
  26436. $this->ColL[$i] = $absL + ($gap/2) + ($i* ($PageWidth/$NbCol) );
  26437. $this->ColR[$i] = $this->ColL[$i] + $ColWidth; // NB This is not R margin -> R pos
  26438. }
  26439. } // *RTL*
  26440. $this->pgwidth = $ColWidth;
  26441. $this->SetCol(0);
  26442. $this->y0=$this->y;
  26443. }
  26444. $this->x = $this->lMargin;
  26445. }
  26446. function SetCol($CurrCol) {
  26447. // Used internally to set column by number: 0 is 1st column
  26448. //Set position on a column
  26449. $this->CurrCol=$CurrCol;
  26450. $x = $this->ColL[$CurrCol];
  26451. $xR = $this->ColR[$CurrCol]; // NB This is not R margin -> R pos
  26452. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  26453. $x += $this->MarginCorrection ;
  26454. $xR += $this->MarginCorrection ;
  26455. }
  26456. $this->SetMargins($x,($this->w - $xR),$this->tMargin);
  26457. }
  26458. function AddColumn() {
  26459. $this->NewColumn();
  26460. $this->ColumnAdjust = false; // disables all column height adjustment for the page.
  26461. }
  26462. function NewColumn() {
  26463. if ($this->ColActive==1) {
  26464. if($this->CurrCol<$this->NbCol-1) {
  26465. //Go to the next column
  26466. $this->CurrCol++;
  26467. $this->SetCol($this->CurrCol);
  26468. $this->y = $this->y0;
  26469. $this->ChangeColumn=1;
  26470. // DIRECTIONALITY RTL
  26471. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  26472. //Stay on the page
  26473. }
  26474. else {
  26475. //Go back to the first column
  26476. //Page break
  26477. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  26478. $this->AddPage($this->CurOrientation);
  26479. $this->SetCol(0);
  26480. $this->y0 = $this->tMargin;
  26481. $this->ChangeColumn= -($this->NbCol-1);
  26482. // DIRECTIONALITY RTL
  26483. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  26484. }
  26485. $this->x = $this->lMargin;
  26486. }
  26487. else {
  26488. $this->AddPage($this->CurOrientation);
  26489. }
  26490. }
  26491. function printcolumnbuffer() {
  26492. // Columns ended (but page not ended) -> try to match all columns - unless disabled by using a custom column-break
  26493. if (!$this->ColActive && $this->ColumnAdjust && !$this->keepColumns) {
  26494. // Calculate adjustment to add to each column to calculate rel_y value
  26495. $this->ColDetails[0]['add_y'] = 0;
  26496. $last_col = 0;
  26497. // Recursively add previous column's height
  26498. for($i=1;$i<$this->NbCol;$i++) {
  26499. if (isset($this->ColDetails[$i]['bottom_margin']) && $this->ColDetails[$i]['bottom_margin']) { // If any entries in the column
  26500. $this->ColDetails[$i]['add_y'] = ($this->ColDetails[$i-1]['bottom_margin'] - $this->y0) + $this->ColDetails[$i-1]['add_y'];
  26501. $last_col = $i; // Last column actually printed
  26502. }
  26503. }
  26504. // Calculate value for each position sensitive entry as though for one column
  26505. foreach($this->columnbuffer AS $key=>$s) {
  26506. $t = $s['s'];
  26507. if ($t == 'ACROFORM') {
  26508. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26509. $this->columnbuffer[$key]['s'] = '';
  26510. }
  26511. else if (preg_match('/BT \d+\.\d\d+ (\d+\.\d\d+) Td/',$t)) {
  26512. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26513. }
  26514. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ [\-]{0,1}\d+\.\d\d+ re/',$t)) {
  26515. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26516. }
  26517. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/',$t)) {
  26518. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26519. }
  26520. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/',$t)) {
  26521. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26522. }
  26523. else if (preg_match('/q \d+\.\d\d+ 0 0 \d+\.\d\d+ \d+\.\d\d+ (\d+\.\d\d+) cm \/(I|FO)\d+ Do Q/',$t)) {
  26524. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26525. }
  26526. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/',$t)) {
  26527. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26528. }
  26529. }
  26530. // mPDF 5.3.01
  26531. foreach($this->internallink AS $key => $f) {
  26532. if (is_array($f) && isset($f['col'])) {
  26533. $this->internallink[$key]['rel_y'] = $f['Y'] + $this->ColDetails[$f['col']]['add_y'] - $this->y0;
  26534. }
  26535. }
  26536. $breaks = array();
  26537. foreach($this->breakpoints AS $c => $bpa) {
  26538. foreach($bpa AS $rely) {
  26539. $breaks[] = $rely + $this->ColDetails[$c]['add_y'] - $this->y0;
  26540. }
  26541. }
  26542. if (isset($this->ColDetails[$last_col]['bottom_margin'])) { $lcbm = $this->ColDetails[$last_col]['bottom_margin']; }
  26543. else { $lcbm = 0; }
  26544. $sum_h = $this->ColDetails[$last_col]['add_y'] + $lcbm - $this->y0;
  26545. //$sum_h = max($this->ColDetails[$last_col]['add_y'] + $this->ColDetails[$last_col]['bottom_margin'] - $this->y0, end($breaks));
  26546. $target_h = ($sum_h / $this->NbCol);
  26547. $cbr = array();
  26548. for($i=1;$i<$this->NbCol;$i++) {
  26549. $th = ($sum_h * $i / $this->NbCol);
  26550. foreach($breaks AS $bk=>$val) {
  26551. if ($val > $th) {
  26552. if (($val-$th) < ($th-$breaks[$bk-1])) { $cbr[$i-1] = $val; }
  26553. else { $cbr[$i-1] = $breaks[$bk-1]; }
  26554. break;
  26555. }
  26556. }
  26557. }
  26558. $cbr[($this->NbCol-1)] = $sum_h;
  26559. // Now update the columns - divide into columns of approximately equal value
  26560. $last_new_col = 0;
  26561. $yadj = 0; // mm
  26562. $xadj = 0;
  26563. $last_col_bottom = 0;
  26564. $lowest_bottom_y = 0;
  26565. $block_bottom = 0;
  26566. $newcolumn = 0;
  26567. foreach($this->columnbuffer AS $key=>$s) {
  26568. if (isset($s['rel_y'])) { // only process position sensitive data
  26569. if ($s['rel_y'] >= $cbr[$newcolumn]) {
  26570. $newcolumn++;
  26571. }
  26572. else {
  26573. $newcolumn = $last_new_col ;
  26574. }
  26575. $block_bottom = max($block_bottom,($s['rel_y']+$s['h']));
  26576. if ($this->directionality == 'rtl') { // *RTL*
  26577. $xadj = -(($newcolumn - $s['col']) * ($this->ColWidth + $this->ColGap)); // *RTL*
  26578. } // *RTL*
  26579. else { // *RTL*
  26580. $xadj = ($newcolumn - $s['col']) * ($this->ColWidth + $this->ColGap);
  26581. } // *RTL*
  26582. if ($last_new_col != $newcolumn) { // Added new column
  26583. $last_col_bottom = $this->columnbuffer[$key]['rel_y'];
  26584. $block_bottom = 0;
  26585. }
  26586. $yadj = ($s['rel_y'] - $s['y']) - ($last_col_bottom)+$this->y0;
  26587. // callback function in htmltoolkit
  26588. $t = $s['s'];
  26589. $t = preg_replace('/BT (\d+\.\d\d+) (\d+\.\d\d+) Td/e',"\$this->columnAdjustAdd('Td',_MPDFK,$xadj,$yadj,'\\1','\\2')",$t);
  26590. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) ([\-]{0,1}\d+\.\d\d+) re/e',"\$this->columnAdjustAdd('re',_MPDFK,$xadj,$yadj,'\\1','\\2','\\3','\\4')",$t);
  26591. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) l/e',"\$this->columnAdjustAdd('l',_MPDFK,$xadj,$yadj,'\\1','\\2')",$t);
  26592. $t = preg_replace('/q (\d+\.\d\d+) 0 0 (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) cm \/(I|FO)/e',"\$this->columnAdjustAdd('img',_MPDFK,$xadj,$yadj,'\\1','\\2','\\3','\\4','\\5')",$t);
  26593. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) m/e',"\$this->columnAdjustAdd('draw',_MPDFK,$xadj,$yadj,'\\1','\\2')",$t);
  26594. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) c/e',"\$this->columnAdjustAdd('bezier',_MPDFK,$xadj,$yadj,'\\1','\\2','\\3','\\4','\\5','\\6')",$t);
  26595. $this->columnbuffer[$key]['s'] = $t;
  26596. $this->columnbuffer[$key]['newcol'] = $newcolumn;
  26597. $this->columnbuffer[$key]['newy'] = $s['y'] + $yadj;
  26598. $last_new_col = $newcolumn;
  26599. $clb = $s['y'] + $yadj + $s['h'] ; // bottom_margin of current
  26600. if ((isset($this->ColDetails[$newcolumn]['max_bottom']) && $clb > $this->ColDetails[$newcolumn]['max_bottom']) || (!isset($this->ColDetails[$newcolumn]['max_bottom']) && $clb)) { $this->ColDetails[$newcolumn]['max_bottom'] = $clb; }
  26601. if ($clb > $lowest_bottom_y) { $lowest_bottom_y = $clb; }
  26602. // Adjust LINKS
  26603. if (isset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26604. $ref = $this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26605. $this->PageLinks[$this->page][$ref][0] += ($xadj*_MPDFK);
  26606. $this->PageLinks[$this->page][$ref][1] -= ($yadj*_MPDFK);
  26607. unset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26608. }
  26609. // Adjust FORM FIELDS
  26610. if (isset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26611. $ref = $this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26612. $this->form->forms[$ref]['x'] += ($xadj);
  26613. $this->form->forms[$ref]['y'] += ($yadj);
  26614. unset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26615. }
  26616. /*-- ANNOTATIONS --*/
  26617. if (isset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26618. $ref = $this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26619. if ($this->PageAnnots[$this->page][$ref]['x'] < 0) {
  26620. $this->PageAnnots[$this->page][$ref]['x'] -= ($xadj);
  26621. }
  26622. else {
  26623. $this->PageAnnots[$this->page][$ref]['x'] += ($xadj);
  26624. }
  26625. $this->PageAnnots[$this->page][$ref]['y'] += ($yadj); // unlike PageLinks, Page annots has y values from top in mm
  26626. unset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26627. }
  26628. /*-- END ANNOTATIONS --*/
  26629. }
  26630. }
  26631. /*-- BOOKMARKS --*/
  26632. // Adjust Bookmarks
  26633. foreach($this->col_BMoutlines AS $v) {
  26634. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$this->y0,'p'=>$v['p']);
  26635. }
  26636. /*-- END BOOKMARKS --*/
  26637. /*-- INDEX --*/
  26638. // Adjust Reference (index)
  26639. foreach($this->col_Reference AS $v) {
  26640. $Present=0;
  26641. //Search the reference (AND Ref/PageNo) in the array
  26642. for ($i=0;$i<count($this->Reference);$i++){
  26643. if ($this->Reference[$i]['t']==$v['t']){
  26644. $Present=1;
  26645. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  26646. $this->Reference[$i]['p'][] = $v['op'];
  26647. }
  26648. }
  26649. }
  26650. if ($Present==0) {
  26651. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  26652. }
  26653. }
  26654. /*-- END INDEX --*/
  26655. /*-- TOC --*/
  26656. // Adjust ToC
  26657. foreach($this->col_toc AS $v) {
  26658. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26659. $this->links[$v['link']][1] = $this->y0;
  26660. }
  26661. /*-- END TOC --*/
  26662. // Adjust column length to be equal
  26663. if ($this->colvAlign == 'J') {
  26664. foreach($this->columnbuffer AS $key=>$s) {
  26665. if (isset($s['rel_y'])) { // only process position sensitive data
  26666. // Set ratio to expand y values or heights
  26667. if (isset($this->ColDetails[$s['newcol']]['max_bottom']) && $this->ColDetails[$s['newcol']]['max_bottom'] && $this->ColDetails[$s['newcol']]['max_bottom']!=$this->y0) {
  26668. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['newcol']]['max_bottom'] - ($this->y0));
  26669. }
  26670. else { $ratio = 1; }
  26671. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26672. $yadj = ($s['newy'] - $this->y0) * ($ratio - 1);
  26673. // Adjust LINKS
  26674. if (isset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26675. $ref = $this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26676. $this->PageLinks[$this->page][$ref][1] -= ($yadj*_MPDFK); // y value
  26677. $this->PageLinks[$this->page][$ref][3] *= $ratio; // height
  26678. unset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26679. }
  26680. // Adjust FORM FIELDS
  26681. if (isset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26682. $ref = $this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26683. $this->form->forms[$ref]['x'] += ($xadj);
  26684. $this->form->forms[$ref]['y'] += ($yadj);
  26685. unset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26686. }
  26687. /*-- ANNOTATIONS --*/
  26688. if (isset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26689. $ref = $this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26690. $this->PageAnnots[$this->page][$ref]['y'] += ($yadj);
  26691. unset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26692. }
  26693. /*-- END ANNOTATIONS --*/
  26694. }
  26695. }
  26696. }
  26697. // mPDF 5.3.01
  26698. foreach($this->internallink AS $key => $f) {
  26699. if (is_array($f) && isset($f['col'])) {
  26700. $last_col_bottom = 0;
  26701. for ($nbc=0; $nbc<$this->NbCol; $nbc++) {
  26702. if ($f['rel_y'] >= $cbr[$nbc]) { $last_col_bottom = $cbr[$nbc]; }
  26703. }
  26704. $yadj = ($f['rel_y'] - $f['Y']) - $last_col_bottom + $this->y0;
  26705. $f['Y'] += $yadj;
  26706. unset($f['col']);
  26707. unset($f['rel_y']);
  26708. $this->internallink[$key] = $f;
  26709. }
  26710. }
  26711. $last_col = -1;
  26712. $trans_on = false;
  26713. foreach($this->columnbuffer AS $key=>$s) {
  26714. if (isset($s['rel_y'])) { // only process position sensitive data
  26715. // Set ratio to expand y values or heights
  26716. if (isset($this->ColDetails[$s['newcol']]['max_bottom']) && $this->ColDetails[$s['newcol']]['max_bottom'] && $this->ColDetails[$s['newcol']]['max_bottom']!=$this->y0) {
  26717. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['newcol']]['max_bottom'] - ($this->y0));
  26718. }
  26719. else { $ratio = 1; }
  26720. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26721. //Start Transformation
  26722. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  26723. $this->pages[$this->page] .= $this->transformScale(100, $ratio*100, $x='', $this->y0, true)."\n";
  26724. $trans_on = true;
  26725. }
  26726. }
  26727. // Now output the adjusted values
  26728. $this->pages[$this->page] .= $s['s']."\n";
  26729. if (isset($s['rel_y']) && ($ratio > 1) && ($ratio <= $this->max_colH_correction)) { // only process position sensitive data
  26730. //Stop Transformation
  26731. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  26732. $trans_on = false;
  26733. }
  26734. }
  26735. if ($trans_on) { $this->pages[$this->page] .= $this->StopTransform(true)."\n"; }
  26736. }
  26737. else { // if NOT $this->colvAlign == 'J'
  26738. // Now output the adjusted values
  26739. foreach($this->columnbuffer AS $s) {
  26740. $this->pages[$this->page] .= $s['s']."\n";
  26741. }
  26742. }
  26743. if ($lowest_bottom_y > 0) { $this->y = $lowest_bottom_y ; }
  26744. }
  26745. // Columns not ended but new page -> align columns (can leave the columns alone - just tidy up the height)
  26746. else if ($this->colvAlign == 'J' && $this->ColumnAdjust && !$this->keepColumns) {
  26747. // calculate the lowest bottom margin
  26748. $lowest_bottom_y = 0;
  26749. foreach($this->columnbuffer AS $key=>$s) {
  26750. // Only process output data
  26751. $t = $s['s'];
  26752. if ($t == 'ACROFORM' || (preg_match('/BT \d+\.\d\d+ (\d+\.\d\d+) Td/',$t)) || (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ [\-]{0,1}\d+\.\d\d+ re/',$t)) ||
  26753. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/',$t)) ||
  26754. (preg_match('/q \d+\.\d\d+ 0 0 \d+\.\d\d+ \d+\.\d\d+ (\d+\.\d\d+) cm \/(I|FO)\d+ Do Q/',$t)) ||
  26755. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/',$t)) ||
  26756. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/',$t)) ) {
  26757. $clb = $s['y'] + $s['h'];
  26758. if ((isset($this->ColDetails[$s['col']]['max_bottom']) && $clb > $this->ColDetails[$s['col']]['max_bottom']) || !isset($this->ColDetails[$s['col']]['max_bottom'])) { $this->ColDetails[$s['col']]['max_bottom'] = $clb; }
  26759. if ($clb > $lowest_bottom_y) { $lowest_bottom_y = $clb; }
  26760. $this->columnbuffer[$key]['rel_y'] = $s['y']; // Marks position sensitive data to process later
  26761. if ($t == 'ACROFORM') { $this->columnbuffer[$key]['s'] = ''; }
  26762. }
  26763. }
  26764. // Adjust column length equal
  26765. foreach($this->columnbuffer AS $key=>$s) {
  26766. // Set ratio to expand y values or heights
  26767. if (isset($this->ColDetails[$s['col']]['max_bottom']) && $this->ColDetails[$s['col']]['max_bottom']) {
  26768. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['col']]['max_bottom'] - ($this->y0));
  26769. }
  26770. else { $ratio = 1; }
  26771. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26772. $yadj = ($s['y'] - $this->y0) * ($ratio - 1);
  26773. // Adjust LINKS
  26774. if (isset($s['rel_y'])) { // only process position sensitive data
  26775. // otherwise triggers for all entries in column buffer (.e.g. formatting) and makes below adjustments more than once
  26776. if (isset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26777. $ref = $this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26778. $this->PageLinks[$this->page][$ref][1] -= ($yadj*_MPDFK); // y value
  26779. $this->PageLinks[$this->page][$ref][3] *= $ratio; // height
  26780. unset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26781. }
  26782. // Adjust FORM FIELDS
  26783. if (isset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26784. $ref = $this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26785. $this->form->forms[$ref]['x'] += ($xadj);
  26786. $this->form->forms[$ref]['y'] += ($yadj);
  26787. unset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26788. }
  26789. /*-- ANNOTATIONS --*/
  26790. if (isset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26791. $ref = $this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26792. $this->PageAnnots[$this->page][$ref]['y'] += ($yadj);
  26793. unset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26794. }
  26795. /*-- END ANNOTATIONS --*/
  26796. }
  26797. }
  26798. }
  26799. /*-- BOOKMARKS --*/
  26800. // Adjust Bookmarks
  26801. foreach($this->col_BMoutlines AS $v) {
  26802. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$this->y0,'p'=>$v['p']);
  26803. }
  26804. /*-- END BOOKMARKS --*/
  26805. /*-- INDEX --*/
  26806. // Adjust Reference (index)
  26807. foreach($this->col_Reference AS $v) {
  26808. $Present=0;
  26809. //Search the reference (AND Ref/PageNo) in the array
  26810. for ($i=0;$i<count($this->Reference);$i++){
  26811. if ($this->Reference[$i]['t']==$v['t']){
  26812. $Present=1;
  26813. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  26814. $this->Reference[$i]['p'][] = $v['op'];
  26815. }
  26816. }
  26817. }
  26818. if ($Present==0) {
  26819. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  26820. }
  26821. }
  26822. /*-- END INDEX --*/
  26823. /*-- TOC --*/
  26824. // Adjust ToC
  26825. foreach($this->col_toc AS $v) {
  26826. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26827. $this->links[$v['link']][1] = $this->y0;
  26828. }
  26829. /*-- END TOC --*/
  26830. $trans_on = false;
  26831. foreach($this->columnbuffer AS $key=>$s) {
  26832. if (isset($s['rel_y'])) { // only process position sensitive data
  26833. // Set ratio to expand y values or heights
  26834. if ($this->ColDetails[$s['col']]['max_bottom']) {
  26835. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['col']]['max_bottom'] - ($this->y0));
  26836. }
  26837. else { $ratio = 1; }
  26838. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26839. //Start Transformation
  26840. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  26841. $this->pages[$this->page] .= $this->transformScale(100, $ratio*100, $x='', $this->y0, true)."\n";
  26842. $trans_on = true;
  26843. }
  26844. }
  26845. // Now output the adjusted values
  26846. $this->pages[$this->page] .= $s['s']."\n";
  26847. if (isset($s['rel_y']) && ($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26848. //Stop Transformation
  26849. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  26850. $trans_on = false; // mPDF 5.1.001
  26851. }
  26852. }
  26853. if ($trans_on) { $this->pages[$this->page] .= $this->StopTransform(true)."\n"; }
  26854. if ($lowest_bottom_y > 0) { $this->y = $lowest_bottom_y ; }
  26855. }
  26856. // Just reproduce the page as it was
  26857. else {
  26858. // If page has not ended but height adjustment was disabled by custom column-break - adjust y
  26859. $lowest_bottom_y = 0;
  26860. if (!$this->ColActive && (!$this->ColumnAdjust || $this->keepColumns)) {
  26861. // calculate the lowest bottom margin
  26862. foreach($this->columnbuffer AS $key=>$s) {
  26863. // Only process output data
  26864. $t = $s['s'];
  26865. if ($t == 'ACROFORM' || (preg_match('/BT \d+\.\d\d+ (\d+\.\d\d+) Td/',$t)) || (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ [\-]{0,1}\d+\.\d\d+ re/',$t)) ||
  26866. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/',$t)) ||
  26867. (preg_match('/q \d+\.\d\d+ 0 0 \d+\.\d\d+ \d+\.\d\d+ (\d+\.\d\d+) cm \/(I|FO)\d+ Do Q/',$t)) ||
  26868. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/',$t)) ||
  26869. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/',$t)) ) {
  26870. $clb = $s['y'] + $s['h'];
  26871. if ($clb > $this->ColDetails[$s['col']]['max_bottom']) { $this->ColDetails[$s['col']]['max_bottom'] = $clb; }
  26872. if ($clb > $lowest_bottom_y) { $lowest_bottom_y = $clb; }
  26873. }
  26874. }
  26875. }
  26876. foreach($this->columnbuffer AS $key=>$s) {
  26877. if ($s['s'] != 'ACROFORM')
  26878. $this->pages[$this->page] .= $s['s']."\n";
  26879. }
  26880. if ($lowest_bottom_y > 0) { $this->y = $lowest_bottom_y ; }
  26881. /*-- INDEX --*/
  26882. // Output Reference (index)
  26883. foreach($this->col_Reference AS $v) {
  26884. $Present=0;
  26885. for ($i=0;$i<count($this->Reference);$i++){
  26886. if ($this->Reference[$i]['t']==$v['t']){
  26887. $Present=1;
  26888. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  26889. $this->Reference[$i]['p'][] = $v['op'];
  26890. }
  26891. }
  26892. }
  26893. if ($Present==0) {
  26894. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  26895. }
  26896. }
  26897. /*-- END INDEX --*/
  26898. /*-- BOOKMARKS --*/
  26899. // Output Bookmarks
  26900. foreach($this->col_BMoutlines AS $v) {
  26901. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  26902. }
  26903. /*-- END BOOKMARKS --*/
  26904. /*-- TOC --*/
  26905. // Output ToC
  26906. foreach($this->col_toc AS $v) {
  26907. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26908. }
  26909. /*-- END TOC --*/
  26910. }
  26911. // mPDF 5.3.01
  26912. foreach($this->internallink AS $key => $f) {
  26913. if (isset($this->internallink[$key]['col'])) unset($this->internallink[$key]['col']);
  26914. if (isset($this->internallink[$key]['rel_y'])) unset($this->internallink[$key]['rel_y']);
  26915. }
  26916. $this->columnbuffer = array();
  26917. $this->ColDetails = array();
  26918. $this->columnLinks = array();
  26919. $this->columnAnnots = array();
  26920. $this->columnForms = array();
  26921. $this->col_Reference = array();
  26922. $this->col_BMoutlines = array();
  26923. $this->col_toc = array();
  26924. $this->breakpoints = array();
  26925. }
  26926. /*-- END COLUMNS --*/
  26927. //==================================================================
  26928. /*-- TABLES --*/
  26929. function printcellbuffer() {
  26930. if (count($this->cellBorderBuffer )) {
  26931. sort($this->cellBorderBuffer);
  26932. foreach($this->cellBorderBuffer AS $cbb) {
  26933. // mPDF 5.3.74
  26934. $cba = unpack("A16dom/nbord/A1side/ns/dbw/a6ca/A10style/dx/dy/dw/dh/dmbl/dmbr/dmrt/dmrb/dmtl/dmtr/dmlt/dmlb/dcpd/dover/", $cbb);
  26935. $side = $cba['side'];
  26936. $details = array();
  26937. $details[$side]['dom'] = (float) $cba['dom'];
  26938. $details[$side]['s'] = $cba['s'];
  26939. $details[$side]['w'] = $cba['bw'];
  26940. $details[$side]['c'] = $cba['ca'];
  26941. $details[$side]['style'] = trim($cba['style']);
  26942. $details['mbw']['BL'] = $cba['mbl'];
  26943. $details['mbw']['BR'] = $cba['mbr'];
  26944. $details['mbw']['RT'] = $cba['mrt'];
  26945. $details['mbw']['RB'] = $cba['mrb'];
  26946. $details['mbw']['TL'] = $cba['mtl'];
  26947. $details['mbw']['TR'] = $cba['mtr'];
  26948. $details['mbw']['LT'] = $cba['mlt'];
  26949. $details['mbw']['LB'] = $cba['mlb'];
  26950. $details['cellposdom'] = $cba['cpd'];
  26951. $details['p'] = $side;
  26952. if ($cba['over']==1) { $details[$side]['overlay'] = true; }
  26953. else { $details[$side]['overlay'] = false; }
  26954. $this->_tableRect($cba['x'],$cba['y'],$cba['w'],$cba['h'],$cba['bord'],$details, false, false);
  26955. }
  26956. $this->cellBorderBuffer = array();
  26957. }
  26958. }
  26959. //==================================================================
  26960. function printtablebuffer() {
  26961. if (!$this->table_rotate) {
  26962. $this->pages[$this->page] .= $this->tablebuffer;
  26963. foreach($this->tbrot_Links AS $p => $l) {
  26964. foreach($l AS $v) {
  26965. $this->PageLinks[$p][] = $v;
  26966. }
  26967. }
  26968. $this->tbrot_Links = array();
  26969. /*-- ANNOTATIONS --*/
  26970. foreach($this->tbrot_Annots AS $p => $l) {
  26971. foreach($l AS $v) {
  26972. $this->PageAnnots[$p][] = $v;
  26973. }
  26974. }
  26975. $this->tbrot_Annots = array();
  26976. /*-- END ANNOTATIONS --*/
  26977. /*-- INDEX --*/
  26978. // Output Reference (index)
  26979. foreach($this->tbrot_Reference AS $v) {
  26980. $Present=0;
  26981. for ($i=0;$i<count($this->Reference);$i++){
  26982. if ($this->Reference[$i]['t']==$v['t']){
  26983. $Present=1;
  26984. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  26985. $this->Reference[$i]['p'][] = $v['op'];
  26986. }
  26987. }
  26988. }
  26989. if ($Present==0) {
  26990. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  26991. }
  26992. }
  26993. $this->tbrot_Reference = array();
  26994. /*-- END INDEX --*/
  26995. /*-- BOOKMARKS --*/
  26996. // Output Bookmarks
  26997. foreach($this->tbrot_BMoutlines AS $v) {
  26998. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  26999. }
  27000. $this->tbrot_BMoutlines = array();
  27001. /*-- END BOOKMARKS --*/
  27002. /*-- TOC --*/
  27003. // Output ToC
  27004. foreach($this->tbrot_toc AS $v) {
  27005. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  27006. }
  27007. $this->tbrot_toc = array();
  27008. /*-- END TOC --*/
  27009. return;
  27010. }
  27011. // else if rotated
  27012. $lm = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_left'];
  27013. $pw = $this->blk[$this->blklvl]['inner_width'];
  27014. //Start Transformation
  27015. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  27016. if ($this->table_rotate > 1) { // clockwise
  27017. if ($this->tbrot_align == 'L') {
  27018. $xadj = $this->tbrot_h ; // align L (as is)
  27019. }
  27020. else if ($this->tbrot_align == 'R') {
  27021. $xadj = $lm-$this->tbrot_x0+($pw) ; // align R
  27022. }
  27023. else {
  27024. $xadj = $lm-$this->tbrot_x0+(($pw + $this->tbrot_h)/2) ; // align C
  27025. }
  27026. $yadj = 0;
  27027. }
  27028. else { // anti-clockwise
  27029. if ($this->tbrot_align == 'L') {
  27030. $xadj = 0 ; // align L (as is)
  27031. }
  27032. else if ($this->tbrot_align == 'R') {
  27033. $xadj = $lm-$this->tbrot_x0+($pw - $this->tbrot_h) ; // align R
  27034. }
  27035. else {
  27036. $xadj = $lm-$this->tbrot_x0+(($pw - $this->tbrot_h)/2) ; // align C
  27037. }
  27038. $yadj = $this->tbrot_w;
  27039. }
  27040. $this->pages[$this->page] .= $this->transformTranslate($xadj, $yadj , true)."\n";
  27041. $this->pages[$this->page] .= $this->transformRotate($this->table_rotate, $this->tbrot_x0 , $this->tbrot_y0 , true)."\n";
  27042. // Now output the adjusted values
  27043. $this->pages[$this->page] .= $this->tablebuffer;
  27044. foreach($this->tbrot_Links AS $p => $l) {
  27045. foreach($l AS $v) {
  27046. $w = $v[2]/_MPDFK;
  27047. $h = $v[3]/_MPDFK;
  27048. $ax = ($v[0]/_MPDFK) - $this->tbrot_x0;
  27049. $ay = (($this->hPt-$v[1])/_MPDFK) - $this->tbrot_y0;
  27050. if ($this->table_rotate > 1) { // clockwise
  27051. $bx = $this->tbrot_x0+$xadj-$ay-$h;
  27052. $by = $this->tbrot_y0+$yadj+$ax;
  27053. }
  27054. else {
  27055. $bx = $this->tbrot_x0+$xadj+$ay;
  27056. $by = $this->tbrot_y0+$yadj-$ax-$w;
  27057. }
  27058. $v[0] = $bx*_MPDFK;
  27059. $v[1] = ($this->h-$by)*_MPDFK;
  27060. $v[2] = $h*_MPDFK; // swap width and height
  27061. $v[3] = $w*_MPDFK;
  27062. $this->PageLinks[$p][] = $v;
  27063. }
  27064. }
  27065. $this->tbrot_Links = array();
  27066. // mPDF 5.3.01
  27067. foreach($this->internallink AS $key => $f) {
  27068. if (is_array($f) && isset($f['tbrot'])) {
  27069. $f['Y'] = $this->tbrot_y0;
  27070. $f['PAGE'] = $this->page;
  27071. unset($f['tbrot']);
  27072. $this->internallink[$key] = $f;
  27073. }
  27074. }
  27075. /*-- ANNOTATIONS --*/
  27076. foreach($this->tbrot_Annots AS $p => $l) {
  27077. foreach($l AS $v) {
  27078. $ax = abs($v['x']) - $this->tbrot_x0; // abs because -ve values are internally set and held for reference if annotMargin set
  27079. $ay = $v['y'] - $this->tbrot_y0;
  27080. if ($this->table_rotate > 1) { // clockwise
  27081. $bx = $this->tbrot_x0+$xadj-$ay;
  27082. $by = $this->tbrot_y0+$yadj+$ax;
  27083. }
  27084. else {
  27085. $bx = $this->tbrot_x0+$xadj+$ay;
  27086. $by = $this->tbrot_y0+$yadj-$ax;
  27087. }
  27088. if ($v['x'] < 0) {
  27089. $v['x'] = -$bx;
  27090. }
  27091. else {
  27092. $v['x'] = $bx;
  27093. }
  27094. $v['y'] = ($by);
  27095. $this->PageAnnots[$p][] = $v;
  27096. }
  27097. }
  27098. $this->tbrot_Annots = array();
  27099. /*-- END ANNOTATIONS --*/
  27100. /*-- BOOKMARKS --*/
  27101. // Adjust Bookmarks
  27102. foreach($this->tbrot_BMoutlines AS $v) {
  27103. $v['y'] = $this->tbrot_y0;
  27104. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$this->page);
  27105. }
  27106. /*-- END BOOKMARKS --*/
  27107. /*-- INDEX --*/
  27108. // Adjust Reference (index)
  27109. foreach($this->tbrot_Reference AS $v) {
  27110. $Present=0;
  27111. //Search the reference (AND Ref/PageNo) in the array
  27112. for ($i=0;$i<count($this->Reference);$i++){
  27113. if ($this->Reference[$i]['t']==$v['t']){
  27114. $Present=1;
  27115. if (!in_array($this->page,$this->Reference[$i]['p'])) {
  27116. $this->Reference[$i]['p'][] = $this->page;
  27117. }
  27118. }
  27119. }
  27120. if ($Present==0) {
  27121. $this->Reference[]=array('t'=>$v['t'],'p'=>array($this->page));
  27122. }
  27123. }
  27124. /*-- END INDEX --*/
  27125. /*-- TOC --*/
  27126. // Adjust ToC - uses document page number
  27127. foreach($this->tbrot_toc AS $v) {
  27128. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$this->page,'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  27129. $this->links[$v['link']][1] = $this->tbrot_y0;
  27130. }
  27131. /*-- END TOC --*/
  27132. $this->tbrot_Reference = array();
  27133. $this->tbrot_BMoutlines = array();
  27134. $this->tbrot_toc = array();
  27135. //Stop Transformation
  27136. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  27137. $this->y = $this->tbrot_y0 + $this->tbrot_w;
  27138. $this->x = $this->lMargin;
  27139. $this->tablebuffer = '';
  27140. }
  27141. //==================================================================
  27142. // Keep-with-table This buffers contents of h1-6 to keep on page with table
  27143. function printkwtbuffer() {
  27144. if (!$this->kwt_moved) {
  27145. foreach($this->kwt_buffer AS $s) { $this->pages[$this->page] .= $s['s']."\n"; }
  27146. foreach($this->kwt_Links AS $p => $l) {
  27147. foreach($l AS $v) {
  27148. $this->PageLinks[$p][] = $v;
  27149. }
  27150. }
  27151. $this->kwt_Links = array();
  27152. /*-- ANNOTATIONS --*/
  27153. foreach($this->kwt_Annots AS $p => $l) {
  27154. foreach($l AS $v) {
  27155. $this->PageAnnots[$p][] = $v;
  27156. }
  27157. }
  27158. $this->kwt_Annots = array();
  27159. /*-- END ANNOTATIONS --*/
  27160. /*-- INDEX --*/
  27161. // Output Reference (index)
  27162. foreach($this->kwt_Reference AS $v) {
  27163. $Present=0;
  27164. for ($i=0;$i<count($this->Reference);$i++){
  27165. if ($this->Reference[$i]['t']==$v['t']){
  27166. $Present=1;
  27167. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  27168. $this->Reference[$i]['p'][] = $v['op'];
  27169. }
  27170. }
  27171. }
  27172. if ($Present==0) {
  27173. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  27174. }
  27175. }
  27176. $this->kwt_Reference = array();
  27177. /*-- END INDEX --*/
  27178. /*-- BOOKMARKS --*/
  27179. // Output Bookmarks
  27180. foreach($this->kwt_BMoutlines AS $v) {
  27181. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  27182. }
  27183. $this->kwt_BMoutlines = array();
  27184. /*-- END BOOKMARKS --*/
  27185. /*-- TOC --*/
  27186. // Output ToC
  27187. foreach($this->kwt_toc AS $v) {
  27188. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  27189. }
  27190. $this->kwt_toc = array();
  27191. /*-- END TOC --*/
  27192. return;
  27193. }
  27194. //Start Transformation
  27195. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  27196. $xadj = $this->lMargin - $this->kwt_x0 ;
  27197. //$yadj = $this->y - $this->kwt_y0 ;
  27198. $yadj = $this->tMargin - $this->kwt_y0 ;
  27199. $this->pages[$this->page] .= $this->transformTranslate($xadj, $yadj , true)."\n";
  27200. // Now output the adjusted values
  27201. foreach($this->kwt_buffer AS $s) { $this->pages[$this->page] .= $s['s']."\n"; }
  27202. // Adjust hyperLinks
  27203. foreach($this->kwt_Links AS $p => $l) {
  27204. foreach($l AS $v) {
  27205. $bx = $this->kwt_x0+$xadj;
  27206. $by = $this->kwt_y0+$yadj;
  27207. $v[0] = $bx*_MPDFK;
  27208. $v[1] = ($this->h-$by)*_MPDFK;
  27209. $this->PageLinks[$p][] = $v;
  27210. }
  27211. }
  27212. // mPDF 5.3.01
  27213. foreach($this->internallink AS $key => $f) {
  27214. if (is_array($f) && isset($f['kwt'])) {
  27215. $f['Y'] += $yadj;
  27216. $f['PAGE'] = $this->page;
  27217. unset($f['kwt']);
  27218. $this->internallink[$key] = $f;
  27219. }
  27220. }
  27221. /*-- ANNOTATIONS --*/
  27222. foreach($this->kwt_Annots AS $p => $l) {
  27223. foreach($l AS $v) {
  27224. $bx = $this->kwt_x0+$xadj;
  27225. $by = $this->kwt_y0+$yadj;
  27226. if ($v['x'] < 0) {
  27227. $v['x'] = -$bx;
  27228. }
  27229. else {
  27230. $v['x'] = $bx;
  27231. }
  27232. $v['y'] = $by;
  27233. $this->PageAnnots[$p][] = $v;
  27234. }
  27235. }
  27236. /*-- END ANNOTATIONS --*/
  27237. /*-- BOOKMARKS --*/
  27238. // Adjust Bookmarks
  27239. foreach($this->kwt_BMoutlines AS $v) {
  27240. if ($v['y'] != 0) { $v['y'] += $yadj; }
  27241. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$this->page);
  27242. }
  27243. /*-- END BOOKMARKS --*/
  27244. /*-- INDEX --*/
  27245. // Adjust Reference (index)
  27246. foreach($this->kwt_Reference AS $v) {
  27247. $Present=0;
  27248. //Search the reference (AND Ref/PageNo) in the array
  27249. for ($i=0;$i<count($this->Reference);$i++){
  27250. if ($this->Reference[$i]['t']==$v['t']){
  27251. $Present=1;
  27252. if (!in_array($this->page,$this->Reference[$i]['p'])) {
  27253. $this->Reference[$i]['p'][] = $this->page;
  27254. }
  27255. }
  27256. }
  27257. if ($Present==0) {
  27258. $this->Reference[]=array('t'=>$v['t'],'p'=>array($this->page));
  27259. }
  27260. }
  27261. /*-- END INDEX --*/
  27262. /*-- TOC --*/
  27263. // Adjust ToC
  27264. foreach($this->kwt_toc AS $v) {
  27265. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$this->page,'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  27266. $this->links[$v['link']][0] = $this->page;
  27267. $this->links[$v['link']][1] += $yadj;
  27268. }
  27269. /*-- END TOC --*/
  27270. $this->kwt_Links = array();
  27271. $this->kwt_Annots = array();
  27272. $this->kwt_Reference = array();
  27273. $this->kwt_BMoutlines = array();
  27274. $this->kwt_toc = array();
  27275. //Stop Transformation
  27276. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  27277. $this->kwt_buffer = array();
  27278. $this->y += $this->kwt_height;
  27279. }
  27280. /*-- END TABLES --*/
  27281. //==================================================================
  27282. function printfloatbuffer() {
  27283. if (count($this->floatbuffer)) {
  27284. $this->objectbuffer = $this->floatbuffer;
  27285. $this->printobjectbuffer(false);
  27286. $this->objectbuffer = array();
  27287. $this->floatbuffer = array();
  27288. $this->floatmargins = array();
  27289. }
  27290. }
  27291. //==================================================================
  27292. function printdivbuffer() {
  27293. $p1 = $this->blk[$this->blklvl]['startpage'];
  27294. $p2 = $this->page;
  27295. $bottom[$p1] = $this->ktBlock[$p1]['bottom_margin'];
  27296. $bottom[$p2] = $this->y; // $this->ktBlock[$p2]['bottom_margin'];
  27297. $top[$p1] = $this->kt_y00;
  27298. $top2 = $this->h;
  27299. foreach($this->divbuffer AS $key=>$s) {
  27300. if ($s['page'] == $p2) {
  27301. $top2 = MIN($s['y'], $top2);
  27302. }
  27303. }
  27304. $top[$p2] = $top2;
  27305. $height[$p1] = ($bottom[$p1] - $top[$p1]);
  27306. $height[$p2] = ($bottom[$p2] - $top[$p2]);
  27307. $xadj[$p1] = $this->MarginCorrection;
  27308. $yadj[$p1] = -($top[$p1] - $top[$p2]);
  27309. $xadj[$p2] = 0;
  27310. $yadj[$p2] = $height[$p1];
  27311. // Output without any transformation
  27312. if ($this->ColActive || !$this->keep_block_together || $this->blk[$this->blklvl]['startpage'] == $this->page || ($this->page - $this->blk[$this->blklvl]['startpage']) > 1 || ($height[$p1]+$height[$p2]) > $this->h) {
  27313. foreach($this->divbuffer AS $s) { $this->pages[$s['page']] .= $s['s']."\n"; }
  27314. foreach($this->ktLinks AS $p => $l) {
  27315. foreach($l AS $v) {
  27316. $this->PageLinks[$p][] = $v;
  27317. }
  27318. }
  27319. foreach($this->ktForms AS $key => $f) {
  27320. $this->form->forms[$f['n']] = $f;
  27321. }
  27322. /*-- ANNOTATIONS --*/
  27323. foreach($this->ktAnnots AS $p => $l) {
  27324. foreach($l AS $v) {
  27325. $this->PageAnnots[$p][] = $v;
  27326. }
  27327. }
  27328. /*-- END ANNOTATIONS --*/
  27329. /*-- INDEX --*/
  27330. // Adjust Reference (index)
  27331. foreach($this->ktReference AS $v) {
  27332. $Present=0;
  27333. //Search the reference (AND Ref/PageNo) in the array
  27334. for ($i=0;$i<count($this->Reference);$i++){
  27335. if ($this->Reference[$i]['t']==$v['t']){
  27336. $Present=1;
  27337. if (!in_array($p2,$this->Reference[$i]['p'])) {
  27338. $this->Reference[$i]['p'][] = $p2;
  27339. }
  27340. }
  27341. }
  27342. //If not found, add it
  27343. if ($Present==0) {
  27344. $this->Reference[]=array('t'=>$v['t'],'p'=>array($p2));
  27345. }
  27346. }
  27347. /*-- END INDEX --*/
  27348. /*-- BOOKMARKS --*/
  27349. // Adjust Bookmarks
  27350. foreach($this->ktBMoutlines AS $v) {
  27351. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  27352. }
  27353. /*-- END BOOKMARKS --*/
  27354. /*-- TOC --*/
  27355. // Adjust ToC
  27356. foreach($this->_kttoc AS $v) {
  27357. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  27358. }
  27359. /*-- END TOC --*/
  27360. $this->divbuffer = array();
  27361. $this->ktLinks = array();
  27362. $this->ktAnnots = array();
  27363. $this->ktForms = array();
  27364. $this->ktBlock = array();
  27365. $this->ktReference = array();
  27366. $this->ktBMoutlines = array();
  27367. $this->_kttoc = array();
  27368. $this->keep_block_together = 0;
  27369. return;
  27370. }
  27371. else {
  27372. $np = '';
  27373. $pre = '';
  27374. $ispre = true;
  27375. foreach($this->divbuffer AS $key=>$s) {
  27376. // callback function
  27377. $t = $s['s'];
  27378. $p = $s['page'];
  27379. if (preg_match('/(___PAGE___START'.date('jY').')/', $t)) { $ispre = false; }
  27380. else if (preg_match('/(___HEADER___MARKER'.date('jY').')/', $t)) {
  27381. $np .= $t."\n".$pre;
  27382. continue;
  27383. }
  27384. else {
  27385. $t = preg_replace('/BT (\d+\.\d\d+) (\d+\.\d\d+) Td/e',"\$this->blockAdjust('Td',_MPDFK,$xadj[$p],$yadj[$p],'\\1','\\2')",$t);
  27386. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) ([\-]{0,1}\d+\.\d\d+) re/e',"\$this->blockAdjust('re',_MPDFK,$xadj[$p],$yadj[$p],'\\1','\\2','\\3','\\4')",$t);
  27387. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) l/e',"\$this->blockAdjust('l',_MPDFK,$xadj[$p],$yadj[$p],'\\1','\\2')",$t);
  27388. $t = preg_replace('/q (\d+\.\d\d+) 0 0 (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) cm \/(I|FO)/e',"\$this->blockAdjust('img',_MPDFK,$xadj[$p],$yadj[$p],'\\1','\\2','\\3','\\4','\\5')",$t);
  27389. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) m/e',"\$this->blockAdjust('draw',_MPDFK,$xadj[$p],$yadj[$p],'\\1','\\2')",$t);
  27390. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) c/e',"\$this->blockAdjust('bezier',_MPDFK,$xadj[$p],$yadj[$p],'\\1','\\2','\\3','\\4','\\5','\\6')",$t);
  27391. }
  27392. if ($ispre) $pre .= $t."\n";
  27393. else $np .= $t."\n";
  27394. }
  27395. if ($ispre && $pre) $np = $pre ."\n". $np;
  27396. $this->pages[$this->page] .= $np;
  27397. // Adjust hyperLinks
  27398. foreach($this->ktLinks AS $p => $l) {
  27399. foreach($l AS $v) {
  27400. $v[0] += ($xadj[$p]*_MPDFK);
  27401. $v[1] -= ($yadj[$p]*_MPDFK);
  27402. $this->PageLinks[$p2][] = $v;
  27403. }
  27404. }
  27405. foreach($this->ktForms AS $key => $f) {
  27406. $p = $f['page'];
  27407. $f['x'] += ($xadj[$p]);
  27408. $f['y'] += ($yadj[$p]);
  27409. $f['page'] = $p2;
  27410. $this->form->forms[$f['n']] = $f;
  27411. }
  27412. // mPDF 5.3.01
  27413. foreach($this->internallink AS $key => $f) {
  27414. if (is_array($f) && isset($f['kt'])) {
  27415. $f['Y'] += ($yadj[$f['PAGE']]);
  27416. $f['PAGE'] = $p2;
  27417. unset($f['kt']);
  27418. $this->internallink[$key] = $f;
  27419. }
  27420. }
  27421. /*-- ANNOTATIONS --*/
  27422. foreach($this->ktAnnots AS $p => $l) {
  27423. foreach($l AS $v) {
  27424. if ($v['x']>0) { $v['x'] += $xadj[$p]; }
  27425. else if ($v['x']<0) { $v['x'] -= $xadj[$p]; }
  27426. $v['y'] += $yadj[$p];
  27427. $this->PageAnnots[$p2][] = $v;
  27428. }
  27429. }
  27430. /*-- END ANNOTATIONS --*/
  27431. /*-- BOOKMARKS --*/
  27432. // Adjust Bookmarks
  27433. foreach($this->ktBMoutlines AS $v) {
  27434. if ($v['y'] != 0) { $v['y'] += ($yadj[$v['p']]); }
  27435. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$p2);
  27436. }
  27437. /*-- END BOOKMARKS --*/
  27438. /*-- INDEX --*/
  27439. // Adjust Reference (index)
  27440. foreach($this->ktReference AS $v) {
  27441. $Present=0;
  27442. //Search the reference (AND Ref/PageNo) in the array
  27443. for ($i=0;$i<count($this->Reference);$i++){
  27444. if ($this->Reference[$i]['t']==$v['t']){
  27445. $Present=1;
  27446. if (!in_array($p2,$this->Reference[$i]['p'])) {
  27447. $this->Reference[$i]['p'][] = $p2;
  27448. }
  27449. }
  27450. }
  27451. //If not found, add it
  27452. if ($Present==0) {
  27453. $this->Reference[]=array('t'=>$v['t'],'p'=>array($p2));
  27454. }
  27455. }
  27456. /*-- END INDEX --*/
  27457. /*-- TOC --*/
  27458. // Adjust ToC
  27459. foreach($this->_kttoc AS $v) {
  27460. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$p2,'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  27461. $this->links[$v['link']][0] = $p2;
  27462. $this->links[$v['link']][1] += $yadj[$v['p']]; // mPDF 5.3.02
  27463. }
  27464. /*-- END TOC --*/
  27465. $this->y = $top[$p2] + $height[$p1] + $height[$p2];
  27466. $this->x = $this->lMargin;
  27467. $this->divbuffer = array();
  27468. $this->ktLinks = array();
  27469. $this->ktAnnots = array();
  27470. $this->ktForms = array();
  27471. $this->ktBlock = array();
  27472. $this->ktReference = array();
  27473. $this->ktBMoutlines = array();
  27474. $this->_kttoc = array();
  27475. $this->keep_block_together = 0;
  27476. }
  27477. }
  27478. //==================================================================
  27479. // Added ELLIPSES and CIRCLES
  27480. function Circle($x,$y,$r,$style='S') {
  27481. $this->Ellipse($x,$y,$r,$r,$style);
  27482. }
  27483. function Ellipse($x,$y,$rx,$ry,$style='S') {
  27484. if($style=='F') { $op='f'; }
  27485. elseif($style=='FD' or $style=='DF') { $op='B'; }
  27486. else { $op='S'; }
  27487. $lx=4/3*(M_SQRT2-1)*$rx;
  27488. $ly=4/3*(M_SQRT2-1)*$ry;
  27489. $h=$this->h;
  27490. $this->_out(sprintf('%.3F %.3F m %.3F %.3F %.3F %.3F %.3F %.3F c', ($x+$rx)*_MPDFK,($h-$y)*_MPDFK, ($x+$rx)*_MPDFK,($h-($y-$ly))*_MPDFK, ($x+$lx)*_MPDFK,($h-($y-$ry))*_MPDFK, $x*_MPDFK,($h-($y-$ry))*_MPDFK));
  27491. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c', ($x-$lx)*_MPDFK,($h-($y-$ry))*_MPDFK, ($x-$rx)*_MPDFK,($h-($y-$ly))*_MPDFK, ($x-$rx)*_MPDFK,($h-$y)*_MPDFK));
  27492. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c', ($x-$rx)*_MPDFK,($h-($y+$ly))*_MPDFK, ($x-$lx)*_MPDFK,($h-($y+$ry))*_MPDFK, $x*_MPDFK,($h-($y+$ry))*_MPDFK));
  27493. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c %s', ($x+$lx)*_MPDFK,($h-($y+$ry))*_MPDFK, ($x+$rx)*_MPDFK,($h-($y+$ly))*_MPDFK, ($x+$rx)*_MPDFK,($h-$y)*_MPDFK, $op));
  27494. }
  27495. /*-- DIRECTW --*/
  27496. // Added adaptation of shaded_box = AUTOSIZE-TEXT
  27497. function AutosizeText($text,$w,$font,$style,$szfont=72) {
  27498. $text = $this->purify_utf8_text($text);
  27499. if ($this->text_input_as_HTML) {
  27500. $text = $this->all_entities_to_utf8($text);
  27501. }
  27502. if ($this->usingCoreFont) { $text = mb_convert_encoding($text,$this->mb_enc,'UTF-8'); } // mPDF 5.3.22
  27503. $text = ' '.$text.' ';
  27504. $width = $this->ConvertSize($w);
  27505. $loop = 0;
  27506. while ( $loop == 0 ) {
  27507. $this->SetFont($font,$style,$szfont);
  27508. $sz = $this->GetStringWidth( $text );
  27509. if ( $sz > $w ) { $szfont --; }
  27510. else { $loop ++; }
  27511. }
  27512. $this->SetFont($font,$style,$szfont);
  27513. $this->Cell($w, 0, $text, 0, 0, "C");
  27514. }
  27515. /*-- END DIRECTW --*/
  27516. // ====================================================
  27517. // ====================================================
  27518. /*-- RTL --*/
  27519. function reverse_letters($str) {
  27520. $str = strtr($str, '{}[]()', '}{][)(');
  27521. return $this->mb_strrev($str, $this->mb_enc);
  27522. }
  27523. function magic_reverse_dir(&$chunk, $join=true, $dir) {
  27524. if ($this->usingCoreFont) { return 0; }
  27525. if ($this->biDirectional) {
  27526. // Change Arabic + Persian. to Presentation Forms
  27527. if ($join) {
  27528. $chunk = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $chunk );
  27529. }
  27530. $contains_rtl = false;
  27531. $all_rtl = true;
  27532. $initSpace = false;
  27533. $endSpace = false;
  27534. $nonDirchars = "\x{A0}\"\'\(\)\{\}\[\].,:\-=";
  27535. if (preg_match("/[".$this->pregRTLchars."]/u",$chunk)) { // Chunk contains RTL characters
  27536. if (preg_match("/^[ ]/",$chunk)) { $initSpace = true; $chunk = preg_replace("/^[ ]/",'',$chunk); }
  27537. if (preg_match("/[ ]$/",$chunk)) { $endSpace = true; $chunk = preg_replace("/[ ]$/",'',$chunk); }
  27538. if (preg_match("/[^".$this->pregRTLchars.$nonDirchars." ]/u",$chunk)) { // Chunk also contains LTR characters
  27539. $all_rtl = false;
  27540. if ($dir == 'rtl') {
  27541. $chunk = preg_replace("/([^".$this->pregRTLchars.$nonDirchars."][".$nonDirchars."]*) ([".$nonDirchars."]*[^".$this->pregRTLchars.$nonDirchars."])/u","\\1\x07\\2",$chunk);
  27542. }
  27543. $chunk = preg_replace("/([".$this->pregRTLchars."][".$nonDirchars."]*) ([".$nonDirchars."]*[".$this->pregRTLchars."])/u","\\1\x07\\2",$chunk);
  27544. $bits = explode(' ',$chunk);
  27545. foreach($bits AS $bitkey=>$bit) {
  27546. $bit = preg_replace("/\x07/"," ",$bit);
  27547. if (preg_match("/^[".$this->pregRTLchars.$nonDirchars." ]*$/u",$bit)) {
  27548. $bits[$bitkey] = $this->reverse_letters($bit);
  27549. }
  27550. else if (preg_match("/[".$this->pregRTLchars."]/u",$bit)) {
  27551. if ($dir == 'rtl') {
  27552. $bit = preg_replace("/([^".$this->pregRTLchars.$nonDirchars." ])([".$nonDirchars."]*[".$this->pregRTLchars."])/u","\\1\x07\\2",$bit );
  27553. $bit = preg_replace("/([".$this->pregRTLchars."][".$nonDirchars."]*)([^".$this->pregRTLchars.$nonDirchars." ])/u","\\1\x07\\2",$bit );
  27554. }
  27555. else {
  27556. $bit = preg_replace("/([^".$this->pregRTLchars." ][".$nonDirchars."]*)([".$this->pregRTLchars." ])/u","\\1\x07\\2",$bit );
  27557. $bit = preg_replace("/([".$this->pregRTLchars." ])([".$nonDirchars."]*[^".$this->pregRTLchars." ])/u","\\1\x07\\2",$bit );
  27558. }
  27559. $sbits = explode("\x07",$bit );
  27560. foreach($sbits AS $sbitkey=>$sbit) {
  27561. $sbit = preg_replace("/\x07/","",$sbit);
  27562. if (preg_match("/^[".$this->pregRTLchars.$nonDirchars." ]*$/u",$sbit)) {
  27563. $sbits[$sbitkey] = $this->reverse_letters($sbit);
  27564. }
  27565. else if (preg_match("/[".$this->pregRTLchars."]/u",$sbit) && $dir=='rtl') {
  27566. $sbits[$sbitkey] = $this->reverse_letters($sbit);
  27567. }
  27568. else {
  27569. $sbits[$sbitkey] = $sbit;
  27570. }
  27571. }
  27572. if ($dir == 'rtl') { $sbits = array_reverse($sbits,false); }
  27573. $bits[$bitkey] = implode('',$sbits);
  27574. }
  27575. else if (preg_match("/[".$this->pregRTLchars."]/u",$bit) && $dir=='rtl') {
  27576. $bits[$bitkey] = $this->reverse_letters($bit);
  27577. }
  27578. else {
  27579. $bits[$bitkey] = $bit;
  27580. }
  27581. }
  27582. if ($dir == 'rtl') { $bits = array_reverse($bits,false); }
  27583. $chunk = implode(' ',$bits);
  27584. }
  27585. else { $chunk = $this->reverse_letters($chunk); }
  27586. $contains_rtl = true;
  27587. // Un-Reverse numerals back to ltr
  27588. $chunk = preg_replace("/([\x{0660}-\x{0669}]+)/ue", '$this->reverse_letters(\'\\1\')', $chunk );
  27589. if ($dir == 'rtl') {
  27590. if ($endSpace) { $chunk = ' '.$chunk; }
  27591. if ($initSpace) { $chunk .= ' '; }
  27592. }
  27593. else {
  27594. if ($initSpace) { $chunk = ' '.$chunk; }
  27595. if ($endSpace) { $chunk .= ' '; }
  27596. }
  27597. }
  27598. else { $all_rtl = false; }
  27599. if ($all_rtl) { return 2; }
  27600. else if ($contains_rtl) { return 1; }
  27601. else { return 0; }
  27602. }
  27603. return 0;
  27604. }
  27605. /*-- END RTL --*/
  27606. //
  27607. // ****************************
  27608. // ****************************
  27609. function SetSubstitutions() {
  27610. $subsarray = array();
  27611. @include(_MPDF_PATH.'includes/subs_win-1252.php');
  27612. $this->substitute = array();
  27613. foreach($subsarray AS $key => $val) {
  27614. $this->substitute[code2utf($key)] = $val;
  27615. }
  27616. }
  27617. function SubstituteChars($html) {
  27618. // only substitute characters between tags
  27619. if (count($this->substitute)) {
  27620. $a=preg_split('/(<.*?>)/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
  27621. $html = '';
  27622. foreach($a as $i => $e) {
  27623. if($i%2==0) {
  27624. $e = strtr($e, $this->substitute);
  27625. }
  27626. $html .= $e;
  27627. }
  27628. }
  27629. return $html;
  27630. }
  27631. function SubstituteCharsSIP(&$writehtml_a, &$writehtml_i, &$writehtml_e) {
  27632. if (preg_match("/^(.*?)([\x{20000}-\x{2FFFF}]+)(.*)/u", $writehtml_e, $m)) {
  27633. if (isset($this->CurrentFont['sipext']) && $this->CurrentFont['sipext']) {
  27634. $font = $this->CurrentFont['sipext'];
  27635. if (!in_array($font, $this->available_unifonts)) { return 0; }
  27636. $writehtml_a[$writehtml_i] = $writehtml_e = $m[1];
  27637. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  27638. $this->subPos = $writehtml_i;
  27639. return 4;
  27640. }
  27641. }
  27642. return 0;
  27643. }
  27644. // mPDF 5.3.22
  27645. // If core font is selected in document which is not onlyCoreFonts - substitute with non-core font
  27646. function SubstituteCharsNonCore(&$writehtml_a, &$writehtml_i, &$writehtml_e) {
  27647. if (mb_convert_encoding(mb_convert_encoding($writehtml_e, $this->mb_enc, "UTF-8"), "UTF-8", $this->mb_enc) == $writehtml_e) {
  27648. return 0;
  27649. }
  27650. $cw = &$this->CurrentFont['cw'];
  27651. $unicode = $this->UTF8StringToArray($writehtml_e, false);
  27652. $start = -1;
  27653. $end = 0;
  27654. $flag = 0;
  27655. $ftype = '';
  27656. $u = array();
  27657. if (!$this->subArrMB) {
  27658. include(_MPDF_PATH.'includes/subs_core.php');
  27659. $this->subArrMB['a'] = $aarr;
  27660. $this->subArrMB['s'] = $sarr;
  27661. $this->subArrMB['z'] = $zarr;
  27662. }
  27663. foreach($unicode AS $c => $char) {
  27664. if (($char> 127 || ($flag==1 && $char==32)) && $char != 173 && (!isset($this->subArrMB['a'][$char]) || ($flag==1 && $char==32)) && ($char<1536 || ($char>1791 && $char < 2304) || $char>3455)) {
  27665. if ($flag==0) { $start=$c; }
  27666. $flag=1;
  27667. $u[] = $char;
  27668. }
  27669. else if ($flag>0) { $end=$c-1; break; }
  27670. }
  27671. if ($flag>0 && !$end) { $end=count($unicode)-1; }
  27672. if ($start==-1) { return 0; }
  27673. // TRY IN BACKUP SUBS FONT
  27674. if (!is_array($this->backupSubsFont)) { $this->backupSubsFont = array("$this->backupSubsFont"); }
  27675. foreach($this->backupSubsFont AS $bsfctr=>$bsf) {
  27676. if ($this->fonttrans[$bsf] == 'chelvetica' || $this->fonttrans[$bsf] == 'ctimes' || $this->fonttrans[$bsf] == 'ccourier') { continue; }
  27677. $font = $bsf;
  27678. unset($cw);
  27679. $cw = '';
  27680. if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; }
  27681. else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); }
  27682. else {
  27683. $prevFontFamily = $this->FontFamily;
  27684. $prevFontStyle = $this->currentfontstyle;
  27685. $prevFontSizePt = $this->FontSizePt;
  27686. $this->SetFont($bsf, '', '', false);
  27687. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat');
  27688. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false);
  27689. }
  27690. if (!$cw) { continue; }
  27691. $l = 0;
  27692. foreach($u AS $char) {
  27693. if ($char == 173 || $this->_charDefined($cw,$char) || ($char>1536 && $char<1791) || ($char>2304 && $char<3455 )) {
  27694. $l++;
  27695. }
  27696. else {
  27697. if ($l==0 && $bsfctr == (count($this->backupSubsFont)-1)) { // Not found even in last backup font
  27698. $cont = mb_substr($writehtml_e, $start+1);
  27699. $writehtml_e = mb_substr($writehtml_e, 0, $start+1, 'UTF-8');
  27700. array_splice($writehtml_a, $writehtml_i+1, 0, array('', $cont));
  27701. $this->subPos = $writehtml_i+1;
  27702. return 2;
  27703. }
  27704. else { break; }
  27705. }
  27706. }
  27707. if ($l > 0) {
  27708. $patt = mb_substr($writehtml_e, $start, $l, 'UTF-8');
  27709. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  27710. $writehtml_e = $m[1];
  27711. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  27712. $this->subPos = $writehtml_i+3;
  27713. return 4;
  27714. }
  27715. }
  27716. }
  27717. unset($cw);
  27718. return 0;
  27719. }
  27720. function SubstituteCharsMB(&$writehtml_a, &$writehtml_i, &$writehtml_e) {
  27721. $cw = &$this->CurrentFont['cw'];
  27722. $unicode = $this->UTF8StringToArray($writehtml_e, false);
  27723. $start = -1;
  27724. $end = 0;
  27725. $flag = 0;
  27726. $ftype = '';
  27727. $u = array();
  27728. foreach($unicode AS $c => $char) {
  27729. if (($flag == 0 || $flag==2) && (!$this->_charDefined($cw,$char) || ($flag==2 && $char==32)) && $this->checkSIP && $char > 131071) { // Unicode Plane 2 (SIP)
  27730. if (in_array($this->FontFamily ,$this->available_CJK_fonts)) { return 0; }
  27731. if ($flag==0) { $start=$c; }
  27732. $flag=2;
  27733. $u[] = $char;
  27734. }
  27735. //else if (($flag == 0 || $flag==1) && $char != 173 && !$this->_charDefined($cw,$char) && ($char<1423 || ($char>3583 && $char < 11263))) {
  27736. else if (($flag == 0 || $flag==1) && $char != 173 && (!$this->_charDefined($cw,$char) || ($flag==1 && $char==32)) && ($char<1536 || ($char>1791 && $char < 2304) || $char>3455)) {
  27737. if ($flag==0) { $start=$c; }
  27738. $flag=1;
  27739. $u[] = $char;
  27740. }
  27741. else if ($flag>0) { $end=$c-1; break; }
  27742. }
  27743. if ($flag>0 && !$end) { $end=count($unicode)-1; }
  27744. if ($start==-1) { return 0; }
  27745. if ($flag == 2) { // SIP
  27746. // Check if current CJK font has a ext-B related font
  27747. if (isset($this->CurrentFont['sipext']) && $this->CurrentFont['sipext']) {
  27748. $font = $this->CurrentFont['sipext'];
  27749. unset($cw);
  27750. $cw = '';
  27751. if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; }
  27752. else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); }
  27753. else {
  27754. $prevFontFamily = $this->FontFamily;
  27755. $prevFontStyle = $this->currentfontstyle;
  27756. $prevFontSizePt = $this->FontSizePt;
  27757. $this->SetFont($font, '', '', false);
  27758. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat');
  27759. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false);
  27760. }
  27761. if (!$cw) { return 0; }
  27762. $l = 0;
  27763. foreach($u AS $char) {
  27764. if ($this->_charDefined($cw,$char) || $char > 131071) {
  27765. $l++;
  27766. }
  27767. else { break; }
  27768. }
  27769. if ($l > 0) {
  27770. $patt = mb_substr($writehtml_e, $start, $l);
  27771. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  27772. $writehtml_e = $m[1];
  27773. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  27774. $this->subPos = $writehtml_i+3;
  27775. return 4;
  27776. }
  27777. }
  27778. }
  27779. // Check Backup SIP font (defined in config_fonts.php)
  27780. if (isset($this->backupSIPFont) && $this->backupSIPFont) {
  27781. if ($this->currentfontfamily != $this->backupSIPFont) { $font = $this->backupSIPFont; }
  27782. else { unset($cw); return 0; }
  27783. unset($cw);
  27784. $cw = '';
  27785. if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; }
  27786. else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); }
  27787. else {
  27788. $prevFontFamily = $this->FontFamily;
  27789. $prevFontStyle = $this->currentfontstyle;
  27790. $prevFontSizePt = $this->FontSizePt;
  27791. $this->SetFont($this->backupSIPFont, '', '', false);
  27792. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat');
  27793. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false);
  27794. }
  27795. if (!$cw) { return 0; }
  27796. $l = 0;
  27797. foreach($u AS $char) {
  27798. if ($this->_charDefined($cw,$char) || $char > 131071) {
  27799. $l++;
  27800. }
  27801. else { break; }
  27802. }
  27803. if ($l > 0) {
  27804. $patt = mb_substr($writehtml_e, $start, $l);
  27805. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  27806. $writehtml_e = $m[1];
  27807. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  27808. $this->subPos = $writehtml_i+3;
  27809. return 4;
  27810. }
  27811. }
  27812. }
  27813. return 0;
  27814. }
  27815. // FIRST TRY CORE FONTS
  27816. if (!$this->PDFA && !$this->PDFX) {
  27817. $repl = array();
  27818. if (!$this->subArrMB) {
  27819. include(_MPDF_PATH.'includes/subs_core.php');
  27820. $this->subArrMB['a'] = $aarr;
  27821. $this->subArrMB['s'] = $sarr;
  27822. $this->subArrMB['z'] = $zarr;
  27823. }
  27824. if (isset($this->subArrMB['a'][$u[0]])) {
  27825. $font = 'tta'; $ftype = 'C';
  27826. foreach($u AS $char) {
  27827. if ($this->subArrMB['a'][$char]) { $repl[] = $this->subArrMB['a'][$char]; }
  27828. else { break; }
  27829. }
  27830. }
  27831. else if (isset($this->subArrMB['z'][$u[0]])) {
  27832. $font = 'ttz'; $ftype = 'C';
  27833. foreach($u AS $char) {
  27834. if ($this->subArrMB['z'][$char]) { $repl[] = $this->subArrMB['z'][$char]; }
  27835. else { break; }
  27836. }
  27837. }
  27838. else if (isset($this->subArrMB['s'][$u[0]])) {
  27839. $font = 'tts'; $ftype = 'C';
  27840. foreach($u AS $char) {
  27841. if ($this->subArrMB['s'][$char]) { $repl[] = $this->subArrMB['s'][$char]; }
  27842. else { break; }
  27843. }
  27844. }
  27845. if ($ftype=='C') {
  27846. $patt = mb_substr($writehtml_e, $start, count($repl));
  27847. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  27848. $writehtml_e = $m[1];
  27849. array_splice($writehtml_a, $writehtml_i+1, 0, array($font, implode('|', $repl), '/'.$font, $m[3])); // e.g. <tts>
  27850. $this->subPos = $writehtml_i+3;
  27851. return 4;
  27852. }
  27853. return 0;
  27854. }
  27855. }
  27856. // FIND IN DEFAULT FONT - removed mPDF 5.0
  27857. // LASTLY TRY IN BACKUP SUBS FONT
  27858. if (!is_array($this->backupSubsFont)) { $this->backupSubsFont = array("$this->backupSubsFont"); }
  27859. foreach($this->backupSubsFont AS $bsfctr=>$bsf) {
  27860. if ($this->currentfontfamily != $bsf) { $font = $bsf; }
  27861. else { continue; }
  27862. unset($cw);
  27863. $cw = '';
  27864. if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; }
  27865. else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); }
  27866. else {
  27867. $prevFontFamily = $this->FontFamily;
  27868. $prevFontStyle = $this->currentfontstyle;
  27869. $prevFontSizePt = $this->FontSizePt;
  27870. $this->SetFont($bsf, '', '', false);
  27871. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat');
  27872. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false);
  27873. }
  27874. if (!$cw) { continue; }
  27875. $l = 0;
  27876. foreach($u AS $char) {
  27877. if ($char == 173 || $this->_charDefined($cw,$char) || ($char>1536 && $char<1791) || ($char>2304 && $char<3455 )) { // Arabic and Indic
  27878. $l++;
  27879. }
  27880. else {
  27881. if ($l==0 && $bsfctr == (count($this->backupSubsFont)-1)) { // Not found even in last backup font
  27882. $cont = mb_substr($writehtml_e, $start+1);
  27883. $writehtml_e = mb_substr($writehtml_e, 0, $start+1);
  27884. array_splice($writehtml_a, $writehtml_i+1, 0, array('', $cont));
  27885. $this->subPos = $writehtml_i+1;
  27886. return 2;
  27887. }
  27888. else { break; }
  27889. }
  27890. }
  27891. if ($l > 0) {
  27892. $patt = mb_substr($writehtml_e, $start, $l);
  27893. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  27894. $writehtml_e = $m[1];
  27895. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  27896. $this->subPos = $writehtml_i+3;
  27897. return 4;
  27898. }
  27899. }
  27900. }
  27901. unset($cw);
  27902. return 0;
  27903. }
  27904. function setHiEntitySubstitutions() {
  27905. $entarr = array (
  27906. 'nbsp' => '160', 'iexcl' => '161', 'cent' => '162', 'pound' => '163', 'curren' => '164', 'yen' => '165', 'brvbar' => '166', 'sect' => '167',
  27907. 'uml' => '168', 'copy' => '169', 'ordf' => '170', 'laquo' => '171', 'not' => '172', 'shy' => '173', 'reg' => '174', 'macr' => '175',
  27908. 'deg' => '176', 'plusmn' => '177', 'sup2' => '178', 'sup3' => '179', 'acute' => '180', 'micro' => '181', 'para' => '182', 'middot' => '183',
  27909. 'cedil' => '184', 'sup1' => '185', 'ordm' => '186', 'raquo' => '187', 'frac14' => '188', 'frac12' => '189', 'frac34' => '190',
  27910. 'iquest' => '191', 'Agrave' => '192', 'Aacute' => '193', 'Acirc' => '194', 'Atilde' => '195', 'Auml' => '196', 'Aring' => '197',
  27911. 'AElig' => '198', 'Ccedil' => '199', 'Egrave' => '200', 'Eacute' => '201', 'Ecirc' => '202', 'Euml' => '203', 'Igrave' => '204',
  27912. 'Iacute' => '205', 'Icirc' => '206', 'Iuml' => '207', 'ETH' => '208', 'Ntilde' => '209', 'Ograve' => '210', 'Oacute' => '211',
  27913. 'Ocirc' => '212', 'Otilde' => '213', 'Ouml' => '214', 'times' => '215', 'Oslash' => '216', 'Ugrave' => '217', 'Uacute' => '218',
  27914. 'Ucirc' => '219', 'Uuml' => '220', 'Yacute' => '221', 'THORN' => '222', 'szlig' => '223', 'agrave' => '224', 'aacute' => '225',
  27915. 'acirc' => '226', 'atilde' => '227', 'auml' => '228', 'aring' => '229', 'aelig' => '230', 'ccedil' => '231', 'egrave' => '232',
  27916. 'eacute' => '233', 'ecirc' => '234', 'euml' => '235', 'igrave' => '236', 'iacute' => '237', 'icirc' => '238', 'iuml' => '239',
  27917. 'eth' => '240', 'ntilde' => '241', 'ograve' => '242', 'oacute' => '243', 'ocirc' => '244', 'otilde' => '245', 'ouml' => '246',
  27918. 'divide' => '247', 'oslash' => '248', 'ugrave' => '249', 'uacute' => '250', 'ucirc' => '251', 'uuml' => '252', 'yacute' => '253',
  27919. 'thorn' => '254', 'yuml' => '255', 'OElig' => '338', 'oelig' => '339', 'Scaron' => '352', 'scaron' => '353', 'Yuml' => '376',
  27920. 'fnof' => '402', 'circ' => '710', 'tilde' => '732', 'Alpha' => '913', 'Beta' => '914', 'Gamma' => '915', 'Delta' => '916',
  27921. 'Epsilon' => '917', 'Zeta' => '918', 'Eta' => '919', 'Theta' => '920', 'Iota' => '921', 'Kappa' => '922', 'Lambda' => '923',
  27922. 'Mu' => '924', 'Nu' => '925', 'Xi' => '926', 'Omicron' => '927', 'Pi' => '928', 'Rho' => '929', 'Sigma' => '931', 'Tau' => '932',
  27923. 'Upsilon' => '933', 'Phi' => '934', 'Chi' => '935', 'Psi' => '936', 'Omega' => '937', 'alpha' => '945', 'beta' => '946', 'gamma' => '947',
  27924. 'delta' => '948', 'epsilon' => '949', 'zeta' => '950', 'eta' => '951', 'theta' => '952', 'iota' => '953', 'kappa' => '954',
  27925. 'lambda' => '955', 'mu' => '956', 'nu' => '957', 'xi' => '958', 'omicron' => '959', 'pi' => '960', 'rho' => '961', 'sigmaf' => '962',
  27926. 'sigma' => '963', 'tau' => '964', 'upsilon' => '965', 'phi' => '966', 'chi' => '967', 'psi' => '968', 'omega' => '969',
  27927. 'thetasym' => '977', 'upsih' => '978', 'piv' => '982', 'ensp' => '8194', 'emsp' => '8195', 'thinsp' => '8201', 'zwnj' => '8204',
  27928. 'zwj' => '8205', 'lrm' => '8206', 'rlm' => '8207', 'ndash' => '8211', 'mdash' => '8212', 'lsquo' => '8216', 'rsquo' => '8217',
  27929. 'sbquo' => '8218', 'ldquo' => '8220', 'rdquo' => '8221', 'bdquo' => '8222', 'dagger' => '8224', 'Dagger' => '8225', 'bull' => '8226',
  27930. 'hellip' => '8230', 'permil' => '8240', 'prime' => '8242', 'Prime' => '8243', 'lsaquo' => '8249', 'rsaquo' => '8250', 'oline' => '8254',
  27931. 'frasl' => '8260', 'euro' => '8364', 'image' => '8465', 'weierp' => '8472', 'real' => '8476', 'trade' => '8482', 'alefsym' => '8501',
  27932. 'larr' => '8592', 'uarr' => '8593', 'rarr' => '8594', 'darr' => '8595', 'harr' => '8596', 'crarr' => '8629', 'lArr' => '8656',
  27933. 'uArr' => '8657', 'rArr' => '8658', 'dArr' => '8659', 'hArr' => '8660', 'forall' => '8704', 'part' => '8706', 'exist' => '8707',
  27934. 'empty' => '8709', 'nabla' => '8711', 'isin' => '8712', 'notin' => '8713', 'ni' => '8715', 'prod' => '8719', 'sum' => '8721',
  27935. 'minus' => '8722', 'lowast' => '8727', 'radic' => '8730', 'prop' => '8733', 'infin' => '8734', 'ang' => '8736', 'and' => '8743',
  27936. 'or' => '8744', 'cap' => '8745', 'cup' => '8746', 'int' => '8747', 'there4' => '8756', 'sim' => '8764', 'cong' => '8773',
  27937. 'asymp' => '8776', 'ne' => '8800', 'equiv' => '8801', 'le' => '8804', 'ge' => '8805', 'sub' => '8834', 'sup' => '8835', 'nsub' => '8836',
  27938. 'sube' => '8838', 'supe' => '8839', 'oplus' => '8853', 'otimes' => '8855', 'perp' => '8869', 'sdot' => '8901', 'lceil' => '8968',
  27939. 'rceil' => '8969', 'lfloor' => '8970', 'rfloor' => '8971', 'lang' => '9001', 'rang' => '9002', 'loz' => '9674', 'spades' => '9824',
  27940. 'clubs' => '9827', 'hearts' => '9829', 'diams' => '9830',
  27941. );
  27942. foreach($entarr AS $key => $val) {
  27943. $this->entsearch[] = '&'.$key.';';
  27944. $this->entsubstitute[] = code2utf($val);
  27945. }
  27946. }
  27947. function SubstituteHiEntities($html) {
  27948. // converts html_entities > ASCII 127 to unicode
  27949. // Leaves in particular &lt; to distinguish from tag marker
  27950. if (count($this->entsearch)) {
  27951. $html = str_replace($this->entsearch,$this->entsubstitute,$html);
  27952. }
  27953. return $html;
  27954. }
  27955. // Edited v1.2 Pass by reference; option to continue if invalid UTF-8 chars
  27956. function is_utf8(&$string) {
  27957. if ($string === mb_convert_encoding(mb_convert_encoding($string, "UTF-32", "UTF-8"), "UTF-8", "UTF-32")) {
  27958. return true;
  27959. }
  27960. else {
  27961. if ($this->ignore_invalid_utf8) {
  27962. $string = mb_convert_encoding(mb_convert_encoding($string, "UTF-32", "UTF-8"), "UTF-8", "UTF-32") ;
  27963. return true;
  27964. }
  27965. else {
  27966. return false;
  27967. }
  27968. }
  27969. }
  27970. function purify_utf8($html,$lo=true) {
  27971. // For HTML
  27972. // Checks string is valid UTF-8 encoded
  27973. // converts html_entities > ASCII 127 to UTF-8
  27974. // Only exception - leaves low ASCII entities e.g. &lt; &amp; etc.
  27975. // Leaves in particular &lt; to distinguish from tag marker
  27976. if (!$this->is_utf8($html)) {
  27977. echo "<p><b>HTML contains invalid UTF-8 character(s)</b></p>";
  27978. while (mb_convert_encoding(mb_convert_encoding($html, "UTF-32", "UTF-8"), "UTF-8", "UTF-32") != $html) {
  27979. $a = iconv('UTF-8', 'UTF-8', $html);
  27980. echo ($a);
  27981. $pos = $start = strlen($a);
  27982. $err = '';
  27983. while ( ord(substr($html,$pos,1)) > 128 ) {
  27984. $err .= '[[#'.ord(substr($html,$pos,1)).']]';
  27985. $pos++;
  27986. }
  27987. echo '<span style="color:red; font-weight:bold">'.$err.'</span>';
  27988. $html = substr($html, $pos);
  27989. }
  27990. echo $html;
  27991. $this->Error("");
  27992. }
  27993. $html = preg_replace("/\r/", "", $html );
  27994. // converts html_entities > ASCII 127 to UTF-8
  27995. // Leaves in particular &lt; to distinguish from tag marker
  27996. $html = $this->SubstituteHiEntities($html);
  27997. // converts all &#nnn; or &#xHHH; to UTF-8 multibyte
  27998. // If $lo==true then includes ASCII < 128
  27999. $html = strcode2utf($html,$lo);
  28000. return ($html);
  28001. }
  28002. function purify_utf8_text($txt) {
  28003. // For TEXT
  28004. // Make sure UTF-8 string of characters
  28005. if (!$this->is_utf8($txt)) { $this->Error("Text contains invalid UTF-8 character(s)"); }
  28006. $txt = preg_replace("/\r/", "", $txt );
  28007. return ($txt);
  28008. }
  28009. function all_entities_to_utf8($txt) {
  28010. // converts txt_entities > ASCII 127 to UTF-8
  28011. // Leaves in particular &lt; to distinguish from tag marker
  28012. $txt = $this->SubstituteHiEntities($txt);
  28013. // converts all &#nnn; or &#xHHH; to UTF-8 multibyte
  28014. $txt = strcode2utf($txt);
  28015. $txt = $this->lesser_entity_decode($txt);
  28016. return ($txt);
  28017. }
  28018. // ====================================================
  28019. /*-- BARCODES --*/
  28020. // UPC/EAN barcode
  28021. // EAN13, EAN8, UPCA, UPCE, ISBN, ISSN
  28022. // Accepts 12 or 13 digits with or without - hyphens
  28023. function WriteBarcode($code, $showtext=1, $x='', $y='', $size=1, $border=0, $paddingL=1, $paddingR=1, $paddingT=2, $paddingB=2, $height=1, $bgcol=false, $col=false, $btype='ISBN', $supplement='0', $supplement_code='', $k=1) {
  28024. if (empty($code)) {
  28025. return;
  28026. }
  28027. $codestr = $code;
  28028. $code = preg_replace('/\-/','',$code);
  28029. if (!class_exists('PDFBarcode', false)) {
  28030. include(_MPDF_PATH.'classes/barcode.php');
  28031. }
  28032. $this->barcode = new PDFBarcode();
  28033. if ($btype == 'ISSN' || $btype == 'ISBN') {
  28034. $arrcode = $this->barcode->getBarcodeArray($code, 'EAN13');
  28035. }
  28036. else { $arrcode = $this->barcode->getBarcodeArray($code, $btype); }
  28037. if ($arrcode === false) { $this->Error('Error in barcode string: '.$codestr); }
  28038. if((($btype=='EAN13' || $btype=='ISBN' || $btype=='ISSN') && strlen($code) == 12) || ($btype=='UPCA' && strlen($code) == 11)
  28039. || ($btype=='UPCE' && strlen($code) == 11) || ($btype=='EAN8' && strlen($code) == 7)) {
  28040. $code .= $arrcode['checkdigit'];
  28041. if (stristr($codestr,'-')) { $codestr .= '-' . $arrcode['checkdigit']; }
  28042. else { $codestr .= $arrcode['checkdigit']; }
  28043. }
  28044. if ($btype == 'ISBN') { $codestr = 'ISBN '.$codestr; }
  28045. if ($btype == 'ISSN') { $codestr = 'ISSN '.$codestr; }
  28046. if (empty($x)) {
  28047. $x = $this->x;
  28048. }
  28049. if (empty($y)) {
  28050. $y = $this->y;
  28051. }
  28052. // set foreground color
  28053. $prevDrawColor = $this->DrawColor;
  28054. $prevTextColor = $this->TextColor;
  28055. $prevFillColor = $this->FillColor;
  28056. $lw = $this->LineWidth;
  28057. $this->SetLineWidth(0.01);
  28058. $size /= $k; // in case resized in a table
  28059. $xres = $arrcode['nom-X'] * $size;
  28060. $llm = $arrcode['lightmL'] * $arrcode['nom-X'] * $size; // Left Light margin
  28061. $rlm = $arrcode['lightmR'] * $arrcode['nom-X'] * $size; // Right Light margin
  28062. $bcw = ($arrcode["maxw"] * $xres); // Barcode width = Should always be 31.35mm * $size
  28063. $fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins
  28064. $ow = $fbw + $paddingL + $paddingR; // Full overall width incl. user-defined padding
  28065. $fbwi = $fbw - 2; // Full barcode width incl. light margins - 2mm - for isbn string
  28066. // cf. http://www.gs1uk.org/downloads/bar_code/Bar coding getting it right.pdf
  28067. $num_height = 3 * $size; // Height of numerals
  28068. $fbh = $arrcode['nom-H'] * $size * $height; // Full barcode height incl. numerals
  28069. $bch = $fbh - (1.5 * $size); // Barcode height of bars (3mm for numerals)
  28070. if (($btype=='EAN13' && $showtext) || $btype == 'ISSN' || $btype == 'ISBN') { // Add height for ISBN string + margin from top of bars
  28071. $tisbnm = 1.5 * $size; // Top margin between isbn (if shown) & bars
  28072. $codestr_fontsize = 2.1 * $size;
  28073. $paddingT += $codestr_fontsize + $tisbnm ;
  28074. }
  28075. $oh = $fbh + $paddingT + $paddingB; // Full overall height incl. user-defined padding
  28076. // PRINT border background color
  28077. $xpos = $x;
  28078. $ypos = $y;
  28079. if ($col) { // from <barcode /> // mPDF 5.3.A4
  28080. $this->SetDColor($col);
  28081. $this->SetTColor($col);
  28082. }
  28083. else {
  28084. $this->SetDColor($this->ConvertColor(0));
  28085. $this->SetTColor($this->ConvertColor(0));
  28086. }
  28087. if ($bgcol) { // mPDF 5.3.A4
  28088. $this->SetFColor($bgcol);
  28089. }
  28090. else { $this->SetFColor($this->ConvertColor(255)); }
  28091. if (!$bgcol && !$col) { // fn. called directly - not via HTML
  28092. if ($border) { $fillb = 'DF'; } else { $fillb = 'F'; }
  28093. $this->Rect($xpos, $ypos, $ow, $oh, $fillb);
  28094. }
  28095. // PRINT BARS
  28096. $xpos = $x + $paddingL + $llm ;
  28097. $ypos = $y + $paddingT;
  28098. if ($col) { $this->SetFColor($col); } // mPDF 5.3.A4
  28099. else { $this->SetFColor($this->ConvertColor(0)); }
  28100. if ($arrcode !== false) {
  28101. foreach ($arrcode["bcode"] AS $v) {
  28102. $bw = ($v["w"] * $xres);
  28103. if ($v["t"]) {
  28104. // draw a vertical bar
  28105. $this->Rect($xpos, $ypos, $bw, $bch, 'F');
  28106. }
  28107. $xpos += $bw;
  28108. }
  28109. }
  28110. // print text
  28111. $prevFontFamily = $this->FontFamily;
  28112. $prevFontStyle = $this->FontStyle;
  28113. $prevFontSizePt = $this->FontSizePt;
  28114. // ISBN string
  28115. if (($btype=='EAN13' && $showtext) || $btype=='ISBN' || $btype=='ISSN') {
  28116. if ($this->onlyCoreFonts) {
  28117. $this->SetFont('chelvetica');
  28118. }
  28119. else {
  28120. $this->SetFont('sans');
  28121. }
  28122. if ($bgcol) { $this->SetFColor($bgcol); } // mPDF 5.3.A4
  28123. else { $this->SetFColor($this->ConvertColor(255)); }
  28124. $this->x = $x + $paddingL + 1; // 1mm left margin (cf. $fbwi above)
  28125. // max width is $fbwi
  28126. $loop = 0;
  28127. while ( $loop == 0 ) {
  28128. $this->SetFontSize($codestr_fontsize*1.4*_MPDFK, false); // don't write
  28129. $sz = $this->GetStringWidth( $codestr );
  28130. if ($sz > $fbwi)
  28131. $codestr_fontsize -= 0.1;
  28132. else
  28133. $loop ++;
  28134. }
  28135. $this->SetFont('','',$codestr_fontsize*1.4*_MPDFK, true, true); // * 1.4 because font height is only 7/10 of given mm
  28136. // WORD SPACING
  28137. if ($fbwi > $sz) {
  28138. $xtra = $fbwi - $sz;
  28139. $charspacing = $xtra / (strlen($codestr)-1);
  28140. if ($charspacing) { $this->_out(sprintf('BT %.3F Tc ET',$charspacing*_MPDFK)); }
  28141. }
  28142. $this->y = $y + $paddingT - ($codestr_fontsize ) - $tisbnm ;
  28143. $this->Cell($fbw , $codestr_fontsize, $codestr);
  28144. if ($charspacing) { $this->_out('BT 0 Tc ET'); }
  28145. }
  28146. // Bottom NUMERALS
  28147. if ($this->onlyCoreFonts) {
  28148. $this->SetFont('mono');
  28149. }
  28150. else {
  28151. if (in_array('ocrb',$this->available_unifonts)) { $this->SetFont('ocrb'); }
  28152. else { $this->SetFont('mono'); }
  28153. }
  28154. // mPDF 5.3.A9
  28155. if (isset($this->CurrentFont['desc']['CapHeight'])) { $fh = (1000/$this->CurrentFont['desc']['CapHeight']); }
  28156. else if (isset($this->CurrentFont['desc']['Ascent'])) { $fh = (1000/$this->CurrentFont['desc']['Ascent']); }
  28157. else { $fh = 1.2; }
  28158. $charRO = '';
  28159. if ($btype=='EAN13' || $btype=='ISBN' || $btype=='ISSN') {
  28160. $outerfontsize = 3; // Inner fontsize = 3
  28161. $outerp = $xres * 4;
  28162. $innerp = $xres * 2.5;
  28163. $textw = ($bcw*0.5) - $outerp - $innerp;
  28164. $chars = 6; // number of numerals in each half
  28165. $charLO = substr($code,0,1); // Left Outer
  28166. $charLI = substr($code,1,6); // Left Inner
  28167. $charRI = substr($code,7,6); // Right Inner
  28168. if (!$supplement) $charRO = '>'; // Right Outer
  28169. }
  28170. else if ($btype=='UPCA') {
  28171. $outerfontsize = 2.3; // Inner fontsize = 3
  28172. $outerp = $xres * 10;
  28173. $innerp = $xres * 2.5;
  28174. $textw = ($bcw*0.5) - $outerp - $innerp;
  28175. $chars = 5;
  28176. $charLO = substr($code,0,1); // Left Outer
  28177. $charLI = substr($code,1,5); // Left Inner
  28178. $charRI = substr($code,6,5); // Right Inner
  28179. $charRO = substr($code,11,1); // Right Outer
  28180. }
  28181. else if ($btype=='UPCE') {
  28182. $outerfontsize = 2.3; // Inner fontsize = 3
  28183. $outerp = $xres * 4;
  28184. $innerp = 0;
  28185. $textw = ($bcw*0.5) - $outerp - $innerp;
  28186. $chars = 3;
  28187. $upce_code = $arrcode['code'];
  28188. $charLO = substr($code,0,1); // Left Outer
  28189. $charLI = substr($upce_code,0,3); // Left Inner
  28190. $charRI = substr($upce_code,3,3); // Right Inner
  28191. $charRO = substr($code,11,1); // Right Outer
  28192. }
  28193. else if ($btype=='EAN8') {
  28194. $outerfontsize = 3; // Inner fontsize = 3
  28195. $outerp = $xres * 4;
  28196. $innerp = $xres * 2.5;
  28197. $textw = ($bcw*0.5) - $outerp - $innerp;
  28198. $chars = 4;
  28199. $charLO = '<'; // Left Outer
  28200. $charLI = substr($code,0,4); // Left Inner
  28201. $charRI = substr($code,4,4); // Right Inner
  28202. if (!$supplement) $charRO = '>'; // Right Outer
  28203. }
  28204. $this->SetFontSize(($outerfontsize/3)*3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters)
  28205. if (!$this->usingCoreFont) { $cw = $this->_getCharWidth($this->CurrentFont['cw'],32)*3*$fh*$size/1000; } // character width at 3mm
  28206. else { $cw = $this->_getCharWidth($this->CurrentFont['cw'],48)*3*$fh*$size/1000; } // 48 == char "0"
  28207. // Outer left character
  28208. $y_text = $y + $paddingT + $bch - ($num_height/2);
  28209. $y_text_outer = $y + $paddingT + $bch - ($num_height*($outerfontsize/3)/2);
  28210. $this->x = $x + $paddingL - ($cw*($outerfontsize/3)*0.1); // 0.1 is correction as char does not fill full width;
  28211. $this->y = $y_text_outer;
  28212. $this->Cell($cw, $num_height, $charLO );
  28213. // WORD SPACING for inner chars
  28214. $xtra = $textw - ($cw*$chars);
  28215. $charspacing = $xtra / ($chars-1);
  28216. if ($charspacing) { $this->_out(sprintf('BT %.3F Tc ET',$charspacing*_MPDFK)); }
  28217. if ($bgcol) { $this->SetFColor($bgcol); } // mPDF 5.3.A4
  28218. else { $this->SetFColor($this->ConvertColor(255)); }
  28219. $this->SetFontSize(3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters)
  28220. // Inner left half characters
  28221. $this->x = $x + $paddingL + $llm + $outerp;
  28222. $this->y = $y_text;
  28223. $this->Cell($textw, $num_height, $charLI , 0, 0, '', 1);
  28224. // Inner right half characters
  28225. $this->x = $x + $paddingL + $llm + ($bcw*0.5) + $innerp;
  28226. $this->y = $y_text;
  28227. $this->Cell($textw, $num_height, $charRI , 0, 0, '', 1);
  28228. if ($charspacing) { $this->_out('BT 0 Tc ET'); }
  28229. // Outer Right character
  28230. $this->SetFontSize(($outerfontsize/3)*3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters)
  28231. $this->x = $x + $paddingL + $llm + $bcw + $rlm - ($cw*($outerfontsize/3)*0.9); // 0.9 is correction as char does not fill full width
  28232. $this->y = $y_text_outer;
  28233. $this->Cell($cw*($outerfontsize/3), $num_height, $charRO , 0, 0, 'R');
  28234. if ($supplement) { // EAN-2 or -5 Supplement
  28235. // PRINT BARS
  28236. $supparrcode = $this->barcode->getBarcodeArray($supplement_code, 'EAN'.$supplement);
  28237. if ($supparrcode === false) { $this->Error('Error in barcode string (supplement): '.$codestr.' '.$supplement_code); }
  28238. if(strlen($supplement_code) != $supplement) {
  28239. $this->Error('Barcode supplement incorrect: '.$supplement_code);
  28240. }
  28241. $llm = $fbw - (($arrcode['lightmR'] - $supparrcode['sepM']) * $arrcode['nom-X'] * $size); // Left Light margin
  28242. $rlm = $arrcode['lightmR'] * $arrcode['nom-X'] * $size; // Right Light margin
  28243. $bcw = ($supparrcode["maxw"] * $xres); // Barcode width = Should always be 31.35mm * $size
  28244. $fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins
  28245. $ow = $fbw + $paddingL + $paddingR; // Full overall width incl. user-defined padding
  28246. $bch = $fbh - (1.5 * $size) - ($num_height + 0.5); // Barcode height of bars (3mm for numerals)
  28247. $xpos = $x + $paddingL + $llm ;
  28248. $ypos = $y + $paddingT + $num_height + 0.5;
  28249. if ($col) { $this->SetFColor($col); } // mPDF 5.3.A4
  28250. else { $this->SetFColor($this->ConvertColor(0)); }
  28251. if ($supparrcode !== false) {
  28252. foreach ($supparrcode["bcode"] AS $v) {
  28253. $bw = ($v["w"] * $xres);
  28254. if ($v["t"]) {
  28255. // draw a vertical bar
  28256. $this->Rect($xpos, $ypos, $bw, $bch, 'F');
  28257. }
  28258. $xpos += $bw;
  28259. }
  28260. }
  28261. // Characters
  28262. if ($bgcol) { $this->SetFColor($bgcol); } // mPDF 5.3.A4
  28263. else { $this->SetFColor($this->ConvertColor(255)); }
  28264. $this->SetFontSize(3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters)
  28265. $this->x = $x + $paddingL + $llm;
  28266. $this->y = $y + $paddingT;
  28267. $this->Cell($bcw, $num_height, $supplement_code, 0, 0, 'C');
  28268. // Outer Right character (light margin)
  28269. $this->SetFontSize(($outerfontsize/3)*3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters)
  28270. $this->x = $x + $paddingL + $llm + $bcw + $rlm - ($cw*0.9); // 0.9 is correction as char does not fill full width
  28271. $this->y = $y + $paddingT;
  28272. $this->Cell($cw*($outerfontsize/3), $num_height, '>', 0, 0, 'R');
  28273. }
  28274. // Restore **************
  28275. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt);
  28276. $this->DrawColor = $prevDrawColor;
  28277. $this->TextColor = $prevTextColor;
  28278. $this->FillColor = $prevFillColor;
  28279. $this->SetLineWidth($lw);
  28280. $this->SetY($y);
  28281. }
  28282. // ====================================================
  28283. // POSTAL and OTHER barcodes
  28284. function WriteBarcode2($code, $x='', $y='', $size=1, $height=1, $bgcol=false, $col=false, $btype='IMB', $print_ratio='', $k=1) {
  28285. if (empty($code)) { return; }
  28286. if (!class_exists('PDFBarcode', false)) {
  28287. include(_MPDF_PATH.'classes/barcode.php');
  28288. }
  28289. $this->barcode = new PDFBarcode();
  28290. $arrcode = $this->barcode->getBarcodeArray($code, $btype, $print_ratio);
  28291. if ($arrcode === false) { $this->Error('Error in barcode string: '.$code); }
  28292. if (empty($x)) { $x = $this->x; }
  28293. if (empty($y)) { $y = $this->y; }
  28294. $prevDrawColor = $this->DrawColor;
  28295. $prevTextColor = $this->TextColor;
  28296. $prevFillColor = $this->FillColor;
  28297. $lw = $this->LineWidth;
  28298. $this->SetLineWidth(0.01);
  28299. $size /= $k; // in case resized in a table
  28300. $xres = $arrcode['nom-X'] * $size;
  28301. if ($btype == 'IMB' || $btype == 'RM4SCC' || $btype == 'KIX' || $btype == 'POSTNET' || $btype == 'PLANET') {
  28302. $llm = $arrcode['quietL'] / $k; // Left Quiet margin
  28303. $rlm = $arrcode['quietR'] / $k; // Right Quiet margin
  28304. $tlm = $blm = $arrcode['quietTB'] / $k;
  28305. $height=1; // Overrides
  28306. }
  28307. else if (in_array($btype, array('C128A','C128B','C128C','EAN128A','EAN128B','EAN128C','C39','C39+','C39E','C39E+','S25','S25+','I25','I25+','I25B','I25B+','C93','MSI','MSI+','CODABAR','CODE11'))) {
  28308. $llm = $arrcode['lightmL'] * $xres; // Left Quiet margin
  28309. $rlm = $arrcode['lightmR'] * $xres; // Right Quiet margin
  28310. $tlm = $blm = $arrcode['lightTB'] * $xres * $height;
  28311. }
  28312. $bcw = ($arrcode["maxw"] * $xres);
  28313. $fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins
  28314. $bch = ($arrcode["nom-H"] * $size * $height);
  28315. $fbh = $bch + $tlm + $blm; // Full barcode height
  28316. // PRINT border background color
  28317. $xpos = $x;
  28318. $ypos = $y;
  28319. if ($col) { // from <barcode /> // mPDF 5.3.A4
  28320. $this->SetDColor($col);
  28321. $this->SetTColor($col);
  28322. }
  28323. else {
  28324. $this->SetDColor($this->ConvertColor(0));
  28325. $this->SetTColor($this->ConvertColor(0));
  28326. }
  28327. if ($bgcol) { // from <barcode /> // mPDF 5.3.A4
  28328. $this->SetFColor($bgcol);
  28329. }
  28330. else { $this->SetFColor($this->ConvertColor(255)); }
  28331. // PRINT BARS
  28332. if ($col) { $this->SetFColor($col); } // mPDF 5.3.A4
  28333. else { $this->SetFColor($this->ConvertColor(0)); }
  28334. $xpos = $x + $llm ;
  28335. if ($arrcode !== false) {
  28336. foreach ($arrcode["bcode"] AS $v) {
  28337. $bw = ($v["w"] * $xres);
  28338. if ($v["t"]) {
  28339. $ypos = $y + $tlm + ($bch * $v['p'] / $arrcode['maxh']);
  28340. $this->Rect($xpos, $ypos, $bw, ($v['h'] * $bch / $arrcode['maxh']), 'F');
  28341. }
  28342. $xpos += $bw;
  28343. }
  28344. }
  28345. // PRINT BEARER BARS
  28346. if ($btype == 'I25B' || $btype == 'I25B+') {
  28347. $this->Rect($x, $y, $fbw, ($arrcode['lightTB'] * $xres * $height), 'F');
  28348. $this->Rect($x, $y+$tlm+$bch, $fbw, ($arrcode['lightTB'] * $xres * $height), 'F');
  28349. }
  28350. // Restore **************
  28351. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt);
  28352. $this->DrawColor = $prevDrawColor;
  28353. $this->TextColor = $prevTextColor;
  28354. $this->FillColor = $prevFillColor;
  28355. $this->SetLineWidth($lw);
  28356. $this->SetY($y);
  28357. }
  28358. /*-- END BARCODES --*/
  28359. // ====================================================
  28360. // ====================================================
  28361. function StartTransform($returnstring=false) {
  28362. if ($returnstring) { return('q'); }
  28363. else { $this->_out('q'); }
  28364. }
  28365. function StopTransform($returnstring=false) {
  28366. if ($returnstring) { return('Q'); }
  28367. else { $this->_out('Q'); }
  28368. }
  28369. function transformScale($s_x, $s_y, $x='', $y='', $returnstring=false) {
  28370. if ($x === '') {
  28371. $x=$this->x;
  28372. }
  28373. if ($y === '') {
  28374. $y=$this->y;
  28375. }
  28376. if (($s_x == 0) OR ($s_y == 0)) {
  28377. $this->Error('Please do not use values equal to zero for scaling');
  28378. }
  28379. $y = ($this->h - $y) * _MPDFK;
  28380. $x *= _MPDFK;
  28381. //calculate elements of transformation matrix
  28382. $s_x /= 100;
  28383. $s_y /= 100;
  28384. $tm[0] = $s_x;
  28385. $tm[1] = 0;
  28386. $tm[2] = 0;
  28387. $tm[3] = $s_y;
  28388. $tm[4] = $x * (1 - $s_x);
  28389. $tm[5] = $y * (1 - $s_y);
  28390. //scale the coordinate system
  28391. if ($returnstring) { return($this->_transform($tm, true)); }
  28392. else { $this->_transform($tm); }
  28393. }
  28394. function transformTranslate($t_x, $t_y, $returnstring=false) {
  28395. //calculate elements of transformation matrix
  28396. $tm[0] = 1;
  28397. $tm[1] = 0;
  28398. $tm[2] = 0;
  28399. $tm[3] = 1;
  28400. $tm[4] = $t_x * _MPDFK;
  28401. $tm[5] = -$t_y * _MPDFK;
  28402. //translate the coordinate system
  28403. if ($returnstring) { return($this->_transform($tm, true)); }
  28404. else { $this->_transform($tm); }
  28405. }
  28406. function transformRotate($angle, $x='', $y='', $returnstring=false) {
  28407. if ($x === '') {
  28408. $x=$this->x;
  28409. }
  28410. if ($y === '') {
  28411. $y=$this->y;
  28412. }
  28413. $angle = -$angle;
  28414. $y = ($this->h - $y) * _MPDFK;
  28415. $x *= _MPDFK;
  28416. //calculate elements of transformation matrix
  28417. $tm[0] = cos(deg2rad($angle));
  28418. $tm[1] = sin(deg2rad($angle));
  28419. $tm[2] = -$tm[1];
  28420. $tm[3] = $tm[0];
  28421. $tm[4] = $x + $tm[1] * $y - $tm[0] * $x;
  28422. $tm[5] = $y - $tm[0] * $y - $tm[1] * $x;
  28423. //rotate the coordinate system around ($x,$y)
  28424. if ($returnstring) { return($this->_transform($tm, true)); }
  28425. else { $this->_transform($tm); }
  28426. }
  28427. function _transform($tm, $returnstring=false) {
  28428. // mPDF 5.3.53
  28429. if ($returnstring) { return(sprintf('%.4F %.4F %.4F %.4F %.4F %.4F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); }
  28430. else { $this->_out(sprintf('%.4F %.4F %.4F %.4F %.4F %.4F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); }
  28431. }
  28432. /*-- INDIC --*/
  28433. // INDIC ============================
  28434. // This conversion can only be done when font is set
  28435. function ConvertIndic(&$str) {
  28436. if (preg_match('/^ind_([a-z]{2})_/',$this->currentfontfamily, $m)) {
  28437. if (!class_exists('indic', false)) { include(_MPDF_PATH.'classes/indic.php'); }
  28438. if (empty($this->indic)) { $this->indic = new indic($this); }
  28439. $earr = $this->UTF8StringToArray($str, false);
  28440. $str = $this->indic->substituteIndic($earr, $m[1], $this->currentfontfamily);
  28441. }
  28442. }
  28443. /*-- END INDIC --*/
  28444. // AUTOFONT =========================
  28445. function AutoFont($html) {
  28446. if ($this->onlyCoreFonts) { return $html; } // mPDF 5.3.22
  28447. $this->useLang = true;
  28448. if ($this->autoFontGroupSize == 1) { $extra = $this->pregASCIIchars1; }
  28449. else if ($this->autoFontGroupSize == 3) { $extra = $this->pregASCIIchars3; }
  28450. else { $extra = $this->pregASCIIchars2; }
  28451. $n = '';
  28452. $a=preg_split('/<(.*?)>/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
  28453. foreach($a as $i => $e) {
  28454. if($i%2==0) {
  28455. $e = strcode2utf($e);
  28456. $e = $this->lesser_entity_decode($e);
  28457. // Use U=FFF0 and U+FFF1 to mark start and end of span tags to prevent nesting occurring
  28458. // "\xef\xbf\xb0" ##lthtmltag## "\xef\xbf\xb1" ##gthtmltag##
  28459. /*-- CJK-FONTS --*/
  28460. if ($this->autoFontGroups & AUTOFONT_CJK) {
  28461. $e = preg_replace("/([".$this->pregCJKchars.$extra."]*[".$this->pregCJKchars."][".$this->pregCJKchars.$extra."]*)/ue", '$this->replaceCJK(stripslashes(\'\\1\'))', $e);
  28462. }
  28463. /*-- END CJK-FONTS --*/
  28464. /*-- RTL --*/
  28465. if ($this->autoFontGroups & AUTOFONT_RTL) {
  28466. // HEBREW
  28467. $e = preg_replace("/([".$this->pregHEBchars .$extra."]*[".$this->pregHEBchars ."][".$this->pregHEBchars .$extra."]*)/u", "\xef\xbf\xb0span lang=\"he\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  28468. // All Arabic
  28469. $e = preg_replace("/([".$this->pregARABICchars .$extra."]*[".$this->pregARABICchars ."][".$this->pregARABICchars .$extra."]*)/ue", '$this->replaceArabic(stripslashes(\'\\1\'))', $e);
  28470. }
  28471. /*-- END RTL --*/
  28472. /*-- INDIC --*/
  28473. // INDIC
  28474. if ($this->autoFontGroups & AUTOFONT_INDIC) {
  28475. // Bengali
  28476. $e = preg_replace("/([".$this->pregBNchars .$this->pregINDextra."]*[".$this->pregBNchars ."][".$this->pregBNchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"bn\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  28477. // Devanagari (= script for Hindi, Nepali + Sindhi)
  28478. $e = preg_replace("/([".$this->pregHIchars .$this->pregINDextra."]*[".$this->pregHIchars ."][".$this->pregHIchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"hi\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  28479. // Gujarati
  28480. $e = preg_replace("/([".$this->pregGUchars .$this->pregINDextra."]*[".$this->pregGUchars ."][".$this->pregGUchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"gu\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  28481. // Malayalam
  28482. $e = preg_replace("/([".$this->pregMLchars .$this->pregINDextra."]*[".$this->pregMLchars ."][".$this->pregMLchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"ml\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  28483. // Kannada
  28484. $e = preg_replace("/([".$this->pregKNchars .$this->pregINDextra."]*[".$this->pregKNchars ."][".$this->pregKNchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"kn\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  28485. // Oriya
  28486. $e = preg_replace("/([".$this->pregORchars .$this->pregINDextra."]*[".$this->pregORchars ."][".$this->pregORchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"or\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  28487. // Punjabi ?= Gurmuhki
  28488. $e = preg_replace("/([".$this->pregPAchars .$this->pregINDextra."]*[".$this->pregPAchars ."][".$this->pregPAchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"pa\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  28489. // Tamil
  28490. $e = preg_replace("/([".$this->pregTAchars .$this->pregINDextra."]*[".$this->pregTAchars ."][".$this->pregTAchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"ta\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  28491. // Telugu
  28492. $e = preg_replace("/([".$this->pregTEchars .$this->pregINDextra."]*[".$this->pregTEchars ."][".$this->pregTEchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"te\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  28493. }
  28494. /*-- END INDIC --*/
  28495. if ($this->autoFontGroups & AUTOFONT_THAIVIET) {
  28496. // THAI
  28497. $e = preg_replace("/([\x{0E00}-\x{0E7F}".$extra."]*[\x{0E00}-\x{0E7F}][\x{0E00}-\x{0E7F}".$extra."]*)/u", "\xef\xbf\xb0span lang=\"th\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  28498. // Vietnamese
  28499. $e = preg_replace("/([".$this->pregVIETchars .$this->pregVIETPluschars ."]*[".$this->pregVIETchars ."][".$this->pregVIETchars .$this->pregVIETPluschars ."]*)/u", "\xef\xbf\xb0span lang=\"vi\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  28500. }
  28501. $e = preg_replace('/[&]/','&amp;',$e);
  28502. $e = preg_replace('/[<]/','&lt;',$e);
  28503. $e = preg_replace('/[>]/','&gt;',$e);
  28504. $e = preg_replace("/(\xef\xbf\xb0span lang=\"([a-z\-A-Z]{2,5})\"\xef\xbf\xb1)\s+/",' \\1',$e);
  28505. $e = preg_replace("/[ ]+(\xef\xbf\xb0\/span\xef\xbf\xb1)/",'\\1 ',$e);
  28506. $e = preg_replace("/\xef\xbf\xb0span lang=\"([a-z\-A-Z]{2,5})\"\xef\xbf\xb1/","\xef\xbf\xb0span lang=\"\\1\" class=\"lang_\\1\"\xef\xbf\xb1",$e);
  28507. $e = preg_replace("/\xef\xbf\xb0/",'<',$e);
  28508. $e = preg_replace("/\xef\xbf\xb1/",'>',$e);
  28509. $a[$i] = $e;
  28510. }
  28511. else {
  28512. $a[$i] = '<'.$e.'>';
  28513. }
  28514. }
  28515. $n = implode('',$a);
  28516. return $n;
  28517. }
  28518. /*-- CJK-FONTS --*/
  28519. function replaceCJK($str) {
  28520. // Use U=FFF0 and U+FFF1 to mark start and end of span tags to prevent nesting occurring
  28521. // "\xef\xbf\xb0" ##lthtmltag## "\xef\xbf\xb1" ##gthtmltag##
  28522. if (preg_match("/[".$this->pregUHCchars."]/u", $str)) {
  28523. return "\xef\xbf\xb0span lang=\"ko\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  28524. }
  28525. else if (preg_match("/[".$this->pregSJISchars."]/u", $str)) {
  28526. return "\xef\xbf\xb0span lang=\"ja\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  28527. }
  28528. // if in Unicode Plane 2, probably HKCS (incl in BIG5) if not Japanese
  28529. else if (preg_match("/[\x{20000}-\x{2FFFF}]/u", $str)) {
  28530. return "\xef\xbf\xb0span lang=\"zh-HK\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  28531. }
  28532. else{
  28533. return "\xef\xbf\xb0span lang=\"zh-CN\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  28534. }
  28535. return $str;
  28536. }
  28537. /*-- END CJK-FONTS --*/
  28538. /*-- RTL --*/
  28539. function replaceArabic($str) {
  28540. // PASHTO, SINDHI, URDU, ARABIC, PERSIAN
  28541. $persian = "\x{067E}\x{0686}\x{0698}\x{06AF}";
  28542. $urdu = "\x{0679}\x{0688}\x{0691}\x{06BA}\x{06BE}\x{06C1}\x{06D2}";
  28543. $pashto = "\x{067C}\x{0681}\x{0685}\x{0689}\x{0693}\x{0696}\x{069A}\x{06BC}\x{06D0}";
  28544. $sindhi = "\x{067A}\x{067B}\x{067D}\x{067F}\x{0680}\x{0684}\x{068D}\x{068A}\x{068F}\x{068C}\x{0687}\x{0683}\x{0699}\x{06AA}\x{06A6}\x{06BB}\x{06B1}\x{06B3}";
  28545. // Use U=FFF0 and U+FFF1 to mark start and end of span tags to prevent nesting occurring
  28546. // "\xef\xbf\xb0" ##lthtmltag## "\xef\xbf\xb1" ##gthtmltag##
  28547. if (preg_match("/[".$this->pregNonARABICchars ."]/u", $str) ) {
  28548. if (preg_match("/[".$sindhi ."]/u", $str) ) {
  28549. return "\xef\xbf\xb0span lang=\"sd\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28550. }
  28551. else if (preg_match("/[".$urdu ."]/u", $str) ) {
  28552. return "\xef\xbf\xb0span lang=\"ur\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28553. }
  28554. else if (preg_match("/[".$pashto ."]/u", $str) ) {
  28555. return "\xef\xbf\xb0span lang=\"ps\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28556. }
  28557. else if (preg_match("/[".$persian ."]/u", $str) ) {
  28558. return "\xef\xbf\xb0span lang=\"fa\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28559. }
  28560. else {
  28561. return "\xef\xbf\xb0span lang=\"ar\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28562. }
  28563. }
  28564. if (preg_match("/[".$persian ."]/u", $str) ) {
  28565. return "\xef\xbf\xb0span lang=\"fa\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28566. }
  28567. else {
  28568. return "\xef\xbf\xb0span lang=\"ar\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28569. }
  28570. return $str;
  28571. }
  28572. // ARABIC ===========================
  28573. function InitArabic() {
  28574. // JOIN TO FOLLOWING LETTER IN LOGICAL ORDER
  28575. // U+060c U+061f; U+061b; U+0640; U+0626; U+0628; U+062a; U+062b; U+062c; U+062d; U+062e; U+0633; U+0634; U+0635; U+0636; U+0637;
  28576. // U+0638; U+0639; U+063a; U+0641; U+0642; U+0643; U+0644; U+0645; U+0646; U+0647; U+064a; U+06a9; U+06cc; U+0686; U+06af; U+067e;
  28577. // U+06D0; U+0681; U+06C1;
  28578. $this->arabPrevLink = "\xd8\x8c\xd8\x9f\xd8\x9b\xd9\x80\xd8\xa6\xd8\xa8\xd8\xaa\xd8\xab\xd8\xac\xd8\xad\xd8\xae\xd8\xb3\xd8\xb4\xd8\xb5\xd8\xb6\xd8\xb7\xd8\xb8\xd8\xb9\xd8\xba\xd9\x81\xd9\x82\xd9\x83\xd9\x84\xd9\x85\xd9\x86\xd9\x87\xd9\x8a\xda\xa9\xdb\x8c\xda\x86\xda\xaf\xd9\xbe\xdb\x90\xda\x81\xdb\x81";
  28579. // \xda\x98 (U+0698) removed from arabPrevLink
  28580. // \xd9\xb1 (U+0671) added to arabNextLink & final form added to Persian Glyphs (FB51)
  28581. // JOIN TO PREVIOUS LETTER IN LOGICAL ORDER
  28582. // U+0640 U+0622; U+0623; U+0624; U+0625; U+0627; U+0626; U+0628; U+0629; U+062a; U+062b; U+062c; U+062d; U+062e; U+062f; U+0630;
  28583. // U+0631; U+0632; U+0633; U+0634; U+0635; U+0636; U+0637; U+0638; U+0639; U+063a; U+0641; U+0642; U+0643; U+0644; U+0645; U+0646;
  28584. // U+0647; U+0648; U+0649; U+064a; U+06a9; U+06cc; U+0686; U+06af; U+0698; U+067e;
  28585. // U+0671; U+06D0; U+0696; U+0693; U+06D2; U+06C1;
  28586. $this->arabNextLink = "\xd9\x80\xd8\xa2\xd8\xa3\xd8\xa4\xd8\xa5\xd8\xa7\xd8\xa6\xd8\xa8\xd8\xa9\xd8\xaa\xd8\xab\xd8\xac\xd8\xad\xd8\xae\xd8\xaf\xd8\xb0\xd8\xb1\xd8\xb2\xd8\xb3\xd8\xb4\xd8\xb5\xd8\xb6\xd8\xb7\xd8\xb8\xd8\xb9\xd8\xba\xd9\x81\xd9\x82\xd9\x83\xd9\x84\xd9\x85\xd9\x86\xd9\x87\xd9\x88\xd9\x89\xd9\x8a\xda\xa9\xdb\x8c\xda\x86\xda\xaf\xda\x98\xd9\xbe\xd9\xb1\xdb\x90\xda\x96\xda\x93\xdb\x92\xdb\x81";
  28587. // U+064b U+064c; U+064d; U+064e; U+064f; U+0650; U+0651; U+0652;
  28588. $this->arabVowels = "\xd9\x8b\xd9\x8c\xd9\x8d\xd9\x8e\xd9\x8f\xd9\x90\xd9\x91\xd9\x92";
  28589. // Added chars that may not be vowels but should not interrupt joining
  28590. // U+0670; U+0653;
  28591. $this->arabVowels .= "\xd9\xb0\xd9\x93";
  28592. // ? should also add - U+615, 616, 617-61A, 653-65E, 6D6-6DC, 6DF-6E4, 6E7, 6E8, 6EA-6ED
  28593. // DON'T ADD ANY MORE TO ARABGLYPHS - cf. ArabJoin() counts 48 then does ligatures - use PersianGlyphs below
  28594. // ISOLATED FORM :: FINAL :: INITIAL :: MEDIAL
  28595. // U+064B; U+064C; U+064D; U+064E; U+064F; U+0650; U+0651; U+0652;
  28596. $this->arabGlyphs = "\xd9\x8b\xd9\x8c\xd9\x8d\xd9\x8e\xd9\x8f\xd9\x90\xd9\x91\xd9\x92";
  28597. $this->arabHex = '064B064B064B064B064C064C064C064C064D064D064D064D064E064E064E064E064F064F064F064F065006500650065006510651065106510652065206520652';
  28598. // U+0621; U+0622; U+0623; U+0624; U+0625; U+0626; U+0627; U+0628;
  28599. $this->arabGlyphs .= "\xd8\xa1\xd8\xa2\xd8\xa3\xd8\xa4\xd8\xa5\xd8\xa6\xd8\xa7\xd8\xa8";
  28600. $this->arabHex .= '06210621062106210622FE820622FE820623FE840623FE840624FE860624FE860625FE880625FE880626FE8AFE8BFE8C0627FE8E0627FE8E0628FE90FE91FE92';
  28601. // U+0629; U+062A; U+062B; U+062C; U+062D; U+062E; U+062F; U+0630;
  28602. $this->arabGlyphs .= "\xd8\xa9\xd8\xaa\xd8\xab\xd8\xac\xd8\xad\xd8\xae\xd8\xaf\xd8\xb0";
  28603. $this->arabHex .= '0629FE940629FE94062AFE96FE97FE98062BFE9AFE9BFE9C062CFE9EFE9FFEA0062DFEA2FEA3FEA4062EFEA6FEA7FEA8062FFEAA062FFEAA0630FEAC0630FEAC';
  28604. // U+0631; U+0632; U+0633; U+0634; U+0635; U+0636; U+0637; U+0638;
  28605. $this->arabGlyphs .= "\xd8\xb1\xd8\xb2\xd8\xb3\xd8\xb4\xd8\xb5\xd8\xb6\xd8\xb7\xd8\xb8";
  28606. $this->arabHex .= '0631FEAE0631FEAE0632FEB00632FEB00633FEB2FEB3FEB40634FEB6FEB7FEB80635FEBAFEBBFEBC0636FEBEFEBFFEC00637FEC2FEC3FEC40638FEC6FEC7FEC8';
  28607. // U+0639; U+063A; U+0641; U+0642; U+0643; U+0644; U+0645; U+0646;
  28608. $this->arabGlyphs .= "\xd8\xb9\xd8\xba\xd9\x81\xd9\x82\xd9\x83\xd9\x84\xd9\x85\xd9\x86";
  28609. $this->arabHex .= '0639FECAFECBFECC063AFECEFECFFED00641FED2FED3FED40642FED6FED7FED80643FEDAFEDBFEDC0644FEDEFEDFFEE00645FEE2FEE3FEE40646FEE6FEE7FEE8';
  28610. // U+0647; U+0648; U+0649; U+064A; U+0640; U+060C; U+061F; U+061B;
  28611. $this->arabGlyphs .= "\xd9\x87\xd9\x88\xd9\x89\xd9\x8a\xd9\x80\xd8\x8c\xd8\x9f\xd8\x9b";
  28612. // 0649 Initial or medial probably meant to be YEH (064A) so Initial and Medial forms of YEH given
  28613. $this->arabHex .= '0647FEEAFEEBFEEC0648FEEE0648FEEE0649FEF0FEF3FEF4064AFEF2FEF3FEF40640064006400640060C060C060C060C061F061F061F061F061B061B061B061B';
  28614. // 0649 Alef Maksura should only appear at end of word (in Arabic) So final form given as FEF0. Initial and medial are shown as isolated/final
  28615. // $this->arabHex .= '0647FEEAFEEBFEEC0648FEEE0648FEEE0649FEF00649FEF0064AFEF2FEF3FEF40640064006400640060C060C060C060C061F061F061F061F061B061B061B061B';
  28616. // 0649 Alef Maksura Initial and Medial forms as given in Unicode FBE8 and FBE9 (not in most fonts) - dotless vesions of above
  28617. // $this->arabHex .= '0647FEEAFEEBFEEC0648FEEE0648FEEE0649FEF0FBE8FBE9064AFEF2FEF3FEF40640064006400640060C060C060C060C061F061F061F061F061B061B061B061B';
  28618. // LAM with ALEF ligatures
  28619. // U+0644; U+0622; U+0644; U+0623; U+0644; U+0625; U+0644; U+0627;
  28620. $this->arabGlyphs .= "\xd9\x84\xd8\xa2\xd9\x84\xd8\xa3\xd9\x84\xd8\xa5\xd9\x84\xd8\xa7";
  28621. $this->arabHex .= 'FEF5FEF6FEF5FEF6FEF7FEF8FEF7FEF8FEF9FEFAFEF9FEFAFEFBFEFCFEFBFEFC';
  28622. // Added Arabic Presentation Forms - A - for Persian and other langauges
  28623. // U+067B; U+067E; U+0680; U+067A; U+067F; U+0679; U+06A4; U+06A6;
  28624. $this->persianGlyphs = "\xd9\xbb\xd9\xbe\xda\x80\xd9\xba\xd9\xbf\xd9\xb9\xda\xa4\xda\xa6";
  28625. $this->persianHex = '067BFB53FB54FB55067EFB57FB58FB590680FB5BFB5CFB5D067AFB5FFB60FB61067FFB63FB64FB650679FB67FB68FB6906A4FB6BFB6CFB6D06A6FB6FFB70FB71';
  28626. // U+0684; U+0683; U+0686; U+0687; U+0698; U+0691; U+06A9; U+06Af;
  28627. $this->persianGlyphs .= "\xda\x84\xda\x83\xda\x86\xda\x87\xda\x98\xda\x91\xda\xa9\xda\xaf";
  28628. $this->persianHex .= '0684FB73FB74FB750683FB77FB78FB790686FB7BFB7CFB7D0687FB7FFB80FB810698FB8B0698FB8B0691FB8D0691FB8D06A9FB8FFB90FB9106AfFB93FB94FB95';
  28629. // U+06BA; U+06CC; U+06C1; U+0671; U+06D0; U+06D2;
  28630. // 06C1 final form is same as isolated so use 06C1
  28631. $this->persianGlyphs .= "\xda\xba\xdb\x8c\xdb\x81\xd9\xb1\xdb\x90\xdb\x92";
  28632. $this->persianHex .= '06BAFB9F06BAFB9F06CCFBFDFBFEFBFF06C106C1FBA8FBA90671FB510671FB5106D0FBE5FBE6FBE706D2FBAF06D2FBAF';
  28633. }
  28634. // ----------------------------------------------------------------------
  28635. // Derived from ArPHP
  28636. // by Khaled Al-Shamaa
  28637. // http://www.ar-php.org
  28638. // ----------------------------------------------------------------------
  28639. function ArabJoin($str) {
  28640. if (!$this->arabGlyphs) { $this->InitArabic(); }
  28641. $crntChar = null;
  28642. $prevChar = null;
  28643. $nextChar = null;
  28644. $output = array();
  28645. $chars = preg_split('//u', $str);
  28646. $max = count($chars);
  28647. for ($i = $max - 1; $i >= 0; $i--) {
  28648. $crntChar = $chars[$i];
  28649. if ($i > 0){ $prevChar = $chars[$i - 1]; }
  28650. else{ $prevChar = NULL; }
  28651. if ($prevChar && mb_strpos($this->arabVowels, $prevChar, 0, 'utf-8') !== false) {
  28652. $prevChar = $chars[$i - 2];
  28653. if ($prevChar && mb_strpos($this->arabVowels, $prevChar, 0, 'utf-8') !== false) {
  28654. $prevChar = $chars[$i - 3];
  28655. }
  28656. }
  28657. if ($crntChar && mb_strpos($this->arabVowels, $crntChar, 0, 'utf-8') !== false) {
  28658. // If next_char = nextLink && prev_char = prevLink:
  28659. // Added && $prevchar (defined) else error on mb_strpos()
  28660. if ($chars[$i + 1] && (mb_strpos($this->arabNextLink, $chars[$i + 1], 0, 'utf-8') !== false) && $prevChar && (mb_strpos($this->arabPrevLink, $prevChar, 0, 'utf-8') !== false)) {
  28661. $output[] = '&#x' . $this->get_arab_glyphs($crntChar, 1) . ';'; // <final> form
  28662. }
  28663. else {
  28664. $output[] = '&#x' . $this->get_arab_glyphs($crntChar, 0) . ';'; // <isolated> form
  28665. }
  28666. continue;
  28667. }
  28668. // NB = &#x622 &#x623; &#x625; &#x627; &#x644;
  28669. if (isset($chars[$i + 1]) && in_array($chars[$i + 1], array("\xd8\xa2","\xd8\xa3","\xd8\xa5","\xd8\xa7")) && $crntChar == "\xd9\x84"){
  28670. continue;
  28671. }
  28672. if (ord($crntChar) < 128) {
  28673. $output[] = $crntChar;
  28674. $nextChar = $crntChar;
  28675. continue;
  28676. }
  28677. $form = 0;
  28678. if (in_array($crntChar, array("\xd8\xa2", "\xd8\xa3", "\xd8\xa5", "\xd8\xa7")) && $prevChar == "\xd9\x84") {
  28679. if ($chars[$i - 2] && mb_strpos($this->arabPrevLink, $chars[$i - 2], 0, 'utf-8') !== false) {
  28680. $form++; // <final> form
  28681. }
  28682. $output[] = '&#x' . $this->get_arab_glyphs($prevChar . $crntChar, $form) . ';';
  28683. $nextChar = $prevChar;
  28684. continue;
  28685. }
  28686. if ($prevChar && mb_strpos($this->arabPrevLink, $prevChar, 0, 'utf-8') !== false) {
  28687. $form++;
  28688. }
  28689. if ($nextChar && mb_strpos($this->arabNextLink, $nextChar, 0, 'utf-8') !== false) {
  28690. $form += 2;
  28691. }
  28692. $output[] = '&#x' . $this->get_arab_glyphs($crntChar, $form) . ';';
  28693. $nextChar = $crntChar;
  28694. }
  28695. $ra = array_reverse($output);
  28696. $s = implode($ra);
  28697. $s = strcode2utf($s);
  28698. return $s;
  28699. }
  28700. function get_arab_glyphs($char, $type) {
  28701. $pos = mb_strpos($this->arabGlyphs, $char, 0, 'utf-8');
  28702. if ($pos === false) { // If character not covered here
  28703. $pos = mb_strpos($this->persianGlyphs, $char, 0, 'utf-8'); // Try Persian additions
  28704. if ($pos === false) { // return original character
  28705. $x = mb_encode_numericentity ($char, array (0x0, 0xffff, 0, 0xffff), 'UTF-8');
  28706. preg_match('/&#(\d+);/', $x, $m);
  28707. return dechex($m[1]);
  28708. }
  28709. else { // if covered by Added Persian chars
  28710. $pos = $pos*16 + $type*4;
  28711. return mb_substr($this->persianHex, $pos, 4, 'utf-8');
  28712. }
  28713. }
  28714. if ($pos > 48){
  28715. $pos = ($pos-48)/2 + 48;
  28716. }
  28717. $pos = $pos*16 + $type*4;
  28718. return mb_substr($this->arabHex, $pos, 4, 'utf-8');
  28719. }
  28720. /*-- END RTL --*/
  28721. function _getMQR() {
  28722. $mqr=ini_get("magic_quotes_runtime");
  28723. if (PHP_VERSION_ID < 50300) { return @get_magic_quotes_runtime(); }
  28724. else { return 0; }
  28725. }
  28726. //===========================
  28727. // Functions originally in htmltoolkit - moved mPDF 4.0
  28728. // Call-back function Used for usort in fn _tableWrite
  28729. function _cmpdom($a, $b) {
  28730. return ($a["dom"] < $b["dom"]) ? -1 : 1;
  28731. }
  28732. function mb_strrev($str, $enc = 'utf-8'){
  28733. $ch = array();
  28734. $ch = preg_split('//u',$str);
  28735. $revch = array_reverse($ch);
  28736. return implode('',$revch);
  28737. }
  28738. /*-- COLUMNS --*/
  28739. // Callback function from function printcolumnbuffer in mpdf
  28740. function columnAdjustAdd($type,$k,$xadj,$yadj,$a,$b,$c=0,$d=0,$e=0,$f=0) {
  28741. if ($type == 'Td') { // xpos,ypos
  28742. $a += ($xadj * $k);
  28743. $b -= ($yadj * $k);
  28744. return 'BT '.sprintf('%.3F %.3F',$a,$b).' Td';
  28745. }
  28746. else if ($type == 're') { // xpos,ypos,width,height
  28747. $a += ($xadj * $k);
  28748. $b -= ($yadj * $k);
  28749. return sprintf('%.3F %.3F %.3F %.3F',$a,$b,$c,$d).' re';
  28750. }
  28751. else if ($type == 'l') { // xpos,ypos,x2pos,y2pos
  28752. $a += ($xadj * $k);
  28753. $b -= ($yadj * $k);
  28754. return sprintf('%.3F %.3F l',$a,$b);
  28755. }
  28756. else if ($type == 'img') { // width,height,xpos,ypos
  28757. $c += ($xadj * $k);
  28758. $d -= ($yadj * $k);
  28759. return sprintf('q %.3F 0 0 %.3F %.3F %.3F',$a,$b,$c,$d).' cm /'.$e;
  28760. }
  28761. else if ($type == 'draw') { // xpos,ypos
  28762. $a += ($xadj * $k);
  28763. $b -= ($yadj * $k);
  28764. return sprintf('%.3F %.3F m',$a,$b);
  28765. }
  28766. else if ($type == 'bezier') { // xpos,ypos,x2pos,y2pos,x3pos,y3pos
  28767. $a += ($xadj * $k);
  28768. $b -= ($yadj * $k);
  28769. $c += ($xadj * $k);
  28770. $d -= ($yadj * $k);
  28771. $e += ($xadj * $k);
  28772. $f -= ($yadj * $k);
  28773. return sprintf('%.3F %.3F %.3F %.3F %.3F %.3F',$a,$b,$c,$d,$e,$f).' c';
  28774. }
  28775. }
  28776. /*-- END COLUMNS --*/
  28777. // Callback function from function printdivbuffer in mpdf - keeping block together on one page
  28778. function blockAdjust($type,$k,$xadj,$yadj,$a,$b,$c=0,$d=0,$e=0,$f=0) {
  28779. if ($type == 'Td') { // xpos,ypos
  28780. $a += ($xadj * $k);
  28781. $b -= ($yadj * $k);
  28782. return 'BT '.sprintf('%.3F %.3F',$a,$b).' Td';
  28783. }
  28784. else if ($type == 're') { // xpos,ypos,width,height
  28785. $a += ($xadj * $k);
  28786. $b -= ($yadj * $k);
  28787. return sprintf('%.3F %.3F %.3F %.3F',$a,$b,$c,$d).' re';
  28788. }
  28789. else if ($type == 'l') { // xpos,ypos,x2pos,y2pos
  28790. $a += ($xadj * $k);
  28791. $b -= ($yadj * $k);
  28792. return sprintf('%.3F %.3F l',$a,$b);
  28793. }
  28794. else if ($type == 'img') { // width,height,xpos,ypos
  28795. $c += ($xadj * $k);
  28796. $d -= ($yadj * $k);
  28797. return sprintf('q %.3F 0 0 %.3F %.3F %.3F',$a,$b,$c,$d).' cm /'.$e;
  28798. }
  28799. else if ($type == 'draw') { // xpos,ypos
  28800. $a += ($xadj * $k);
  28801. $b -= ($yadj * $k);
  28802. return sprintf('%.3F %.3F m',$a,$b);
  28803. }
  28804. else if ($type == 'bezier') { // xpos,ypos,x2pos,y2pos,x3pos,y3pos
  28805. $a += ($xadj * $k);
  28806. $b -= ($yadj * $k);
  28807. $c += ($xadj * $k);
  28808. $d -= ($yadj * $k);
  28809. $e += ($xadj * $k);
  28810. $f -= ($yadj * $k);
  28811. return sprintf('%.3F %.3F %.3F %.3F %.3F %.3F',$a,$b,$c,$d,$e,$f).' c';
  28812. }
  28813. }
  28814. function ConvertColor($color="#000000"){
  28815. $color = trim(strtolower($color));
  28816. $c = false;
  28817. if ($color=='transparent') { return false; }
  28818. else if ($color=='inherit') { return false; }
  28819. else if (isset($this->SVGcolors[$color])) $color = $this->SVGcolors[$color];
  28820. if (preg_match('/^[\d]+$/',$color)) { $c = (array(1,$color)); } // i.e. integer only
  28821. else if ($color[0] == '#') { //case of #nnnnnn or #nnn
  28822. $cor = preg_replace('/\s+.*/','',$color); // in case of Background: #CCC url() x-repeat etc.
  28823. if (strlen($cor) == 4) { // Turn #RGB into #RRGGBB
  28824. $cor = "#" . $cor[1] . $cor[1] . $cor[2] . $cor[2] . $cor[3] . $cor[3];
  28825. }
  28826. $r = hexdec(substr($cor, 1, 2));
  28827. $g = hexdec(substr($cor, 3, 2));
  28828. $b = hexdec(substr($cor, 5, 2));
  28829. $c = array(3,$r,$g,$b);
  28830. }
  28831. else if (preg_match('/(rgba|rgb|cmyka|cmyk|hsla|hsl|spot)\((.*?)\)/',$color,$m)) {
  28832. $type= $m[1];
  28833. $cores = explode(",", $m[2]);
  28834. $ncores = count($cores); // mPDF 5.3.76
  28835. if (stristr($cores[0],'%') ) {
  28836. $cores[0] += 0;
  28837. if ($type=='rgb' || $type=='rgba') { $cores[0] = intval($cores[0]*255/100); }
  28838. }
  28839. if ($ncores>1 && stristr($cores[1],'%') ) {
  28840. $cores[1] += 0;
  28841. if ($type=='rgb' || $type=='rgba') { $cores[1] = intval($cores[1]*255/100); }
  28842. if ($type=='hsl' || $type=='hsla') { $cores[1] = $cores[1]/100; }
  28843. }
  28844. if ($ncores>2 && stristr($cores[2],'%') ) {
  28845. $cores[2] += 0;
  28846. if ($type=='rgb' || $type=='rgba') { $cores[2] = intval($cores[2]*255/100); }
  28847. if ($type=='hsl' || $type=='hsla') { $cores[2] = $cores[2]/100; }
  28848. }
  28849. if ($ncores>3 && stristr($cores[3],'%') ) {
  28850. $cores[3] += 0;
  28851. }
  28852. if ($type=='rgb') { $c = array(3,$cores[0],$cores[1],$cores[2]); }
  28853. else if ($type=='rgba') { $c = array(5,$cores[0],$cores[1],$cores[2],$cores[3]*100); } // mPDF 5.3.74
  28854. else if ($type=='cmyk') { $c = array(4,$cores[0],$cores[1],$cores[2],$cores[3]); }
  28855. else if ($type=='cmyka') { $c = array(6,$cores[0],$cores[1],$cores[2],$cores[3],$cores[4]*100); } // mPDF 5.3.74
  28856. else if ($type=='hsl' || $type=='hsla') {
  28857. $conv = $this->hsl2rgb($cores[0]/360,$cores[1],$cores[2]);
  28858. if ($type=='hsl') { $c = array(3,$conv[0],$conv[1],$conv[2]); }
  28859. else if ($type=='hsla') { $c = array(5,$conv[0],$conv[1],$conv[2],$cores[3]*100); } // mPDF 5.3.74
  28860. }
  28861. else if ($type=='spot') {
  28862. $name = strtoupper(trim($cores[0]));
  28863. if(!isset($this->spotColors[$name])) $this->Error('Undefined spot color: '.$name);
  28864. $c = array(2,$this->spotColors[$name]['i'],$cores[1]);
  28865. }
  28866. }
  28867. // $this->restrictColorSpace
  28868. // 1 - allow GRAYSCALE only [convert CMYK/RGB->gray]
  28869. // 2 - allow RGB / SPOT COLOR / Grayscale [convert CMYK->RGB]
  28870. // 3 - allow CMYK / SPOT COLOR / Grayscale [convert RGB->CMYK]
  28871. if ($this->PDFA || $this->PDFX || $this->restrictColorSpace) {
  28872. if ($c[0]==1) { // GRAYSCALE
  28873. }
  28874. else if ($c[0]==2) { // SPOT COLOR
  28875. if (!isset($this->spotColorIDs[$c[1]])) { die('Error: Spot colour has not been defined - '.$this->spotColorIDs[$c[1]]); }
  28876. if ($this->PDFA) {
  28877. if ($this->PDFA && !$this->PDFAauto) { $this->PDFAXwarnings[] = "Spot color specified '".$this->spotColorIDs[$c[1]]."' (converted to process color)"; }
  28878. if ($this->restrictColorSpace!=3) {
  28879. $sp = $this->spotColors[$this->spotColorIDs[$c[1]]];
  28880. $c = $this->cmyk2rgb(array(4,$sp['c'],$sp['m'],$sp['y'],$sp['k']));
  28881. }
  28882. }
  28883. else if ($this->restrictColorSpace==1) {
  28884. $sp = $this->spotColors[$this->spotColorIDs[$c[1]]];
  28885. $c = $this->cmyk2gray(array(4,$sp['c'],$sp['m'],$sp['y'],$sp['k']));
  28886. }
  28887. }
  28888. else if ($c[0]==3) { // RGB
  28889. if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3)) {
  28890. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "RGB color specified '".$color."' (converted to CMYK)"; }
  28891. $c = $this->rgb2cmyk($c);
  28892. }
  28893. else if ($this->restrictColorSpace==1) { $c = $this->rgb2gray($c); }
  28894. else if ($this->restrictColorSpace==3) { $c = $this->rgb2cmyk($c); }
  28895. }
  28896. else if ($c[0]==4) { // CMYK
  28897. if ($this->PDFA && $this->restrictColorSpace!=3) {
  28898. if ($this->PDFA && !$this->PDFAauto) { $this->PDFAXwarnings[] = "CMYK color specified '".$color."' (converted to RGB)"; }
  28899. $c = $this->cmyk2rgb($c);
  28900. }
  28901. else if ($this->restrictColorSpace==1) { $c = $this->cmyk2gray($c); }
  28902. else if ($this->restrictColorSpace==2) { $c = $this->cmyk2rgb($c); }
  28903. }
  28904. else if ($c[0]==5) { // RGBa
  28905. if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3)) {
  28906. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "RGB color with transparency specified '".$color."' (converted to CMYK without transparency)"; }
  28907. $c = $this->rgb2cmyk($c);
  28908. $c = array(4, $c[1], $c[2], $c[3], $c[4]);
  28909. }
  28910. else if ($this->PDFA && $this->restrictColorSpace!=3) {
  28911. if (!$this->PDFAauto) { $this->PDFAXwarnings[] = "RGB color with transparency specified '".$color."' (converted to RGB without transparency)"; }
  28912. $c = $this->rgb2cmyk($c);
  28913. $c = array(4, $c[1], $c[2], $c[3], $c[4]);
  28914. }
  28915. else if ($this->restrictColorSpace==1) { $c = $this->rgb2gray($c); }
  28916. else if ($this->restrictColorSpace==3) { $c = $this->rgb2cmyk($c); }
  28917. }
  28918. else if ($c[0]==6) { // CMYKa
  28919. if ($this->PDFA && $this->restrictColorSpace!=3) {
  28920. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "CMYK color with transparency specified '".$color."' (converted to RGB without transparency)"; }
  28921. $c = $this->cmyk2rgb($c);
  28922. $c = array(3, $c[1], $c[2], $c[3]);
  28923. }
  28924. else if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3)) {
  28925. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "CMYK color with transparency specified '".$color."' (converted to CMYK without transparency)"; }
  28926. $c = $this->cmyk2rgb($c);
  28927. $c = array(3, $c[1], $c[2], $c[3]);
  28928. }
  28929. else if ($this->restrictColorSpace==1) { $c = $this->cmyk2gray($c); }
  28930. else if ($this->restrictColorSpace==2) { $c = $this->cmyk2rgb($c); }
  28931. }
  28932. }
  28933. // mPDF 5.3.74
  28934. if (is_array($c)) {
  28935. $c = array_pad($c, 6, 0);
  28936. $cstr = pack("a1ccccc", $c[0], ($c[1] & 0xFF), ($c[2] & 0xFF), ($c[3] & 0xFF), ($c[4] & 0xFF), ($c[5] & 0xFF) );
  28937. }
  28938. return $cstr;
  28939. }
  28940. function rgb2gray($c) {
  28941. // mPDF 5.3.74
  28942. if (isset($c[4])) { return array(1,(($c[1] * .21) + ($c[2] * .71) + ($c[3] * .07)), ord(1), $c[4]); }
  28943. else { return array(1,(($c[1] * .21) + ($c[2] * .71) + ($c[3] * .07))); }
  28944. }
  28945. function cmyk2gray($c) {
  28946. $rgb = $this->cmyk2rgb($c);
  28947. return $this->rgb2gray($rgb);
  28948. }
  28949. function rgb2cmyk($c) {
  28950. $cyan = 1 - ($c[1] / 255);
  28951. $magenta = 1 - ($c[2] / 255);
  28952. $yellow = 1 - ($c[3] / 255);
  28953. $min = min($cyan, $magenta, $yellow);
  28954. if ($min == 1) {
  28955. if ($c[0]==5) { return array (6,100,100,100,100, $c[4]); }
  28956. else { return array (4,100,100,100,100); }
  28957. // For K-Black
  28958. //if ($c[0]==5) { return array (6,0,0,0,100, $c[4]); }
  28959. //else { return array (4,0,0,0,100); }
  28960. }
  28961. $K = $min;
  28962. $black = 1 - $K;
  28963. if ($c[0]==5) { return array (6,($cyan-$K)*100/$black, ($magenta-$K)*100/$black, ($yellow-$K)*100/$black, $K*100, $c[4]); }
  28964. else { return array (4,($cyan-$K)*100/$black, ($magenta-$K)*100/$black, ($yellow-$K)*100/$black, $K*100); }
  28965. }
  28966. function cmyk2rgb($c) {
  28967. $rgb = array();
  28968. $colors = 255 - ($c[4]*2.55);
  28969. $rgb[0] = intval($colors * (255 - ($c[1]*2.55))/255);
  28970. $rgb[1] = intval($colors * (255 - ($c[2]*2.55))/255);
  28971. $rgb[2] = intval($colors * (255 - ($c[3]*2.55))/255);
  28972. if ($c[0]==6) { return array (5,$rgb[0],$rgb[1],$rgb[2], $c[5]); }
  28973. else { return array (3,$rgb[0],$rgb[1],$rgb[2]); }
  28974. }
  28975. function rgb2hsl($var_r, $var_g, $var_b) {
  28976. $var_min = min($var_r,$var_g,$var_b);
  28977. $var_max = max($var_r,$var_g,$var_b);
  28978. $del_max = $var_max - $var_min;
  28979. $l = ($var_max + $var_min) / 2;
  28980. if ($del_max == 0) {
  28981. $h = 0;
  28982. $s = 0;
  28983. }
  28984. else {
  28985. if ($l < 0.5) { $s = $del_max / ($var_max + $var_min); }
  28986. else { $s = $del_max / (2 - $var_max - $var_min); }
  28987. $del_r = ((($var_max - $var_r) / 6) + ($del_max / 2)) / $del_max;
  28988. $del_g = ((($var_max - $var_g) / 6) + ($del_max / 2)) / $del_max;
  28989. $del_b = ((($var_max - $var_b) / 6) + ($del_max / 2)) / $del_max;
  28990. if ($var_r == $var_max) { $h = $del_b - $del_g; }
  28991. elseif ($var_g == $var_max) { $h = (1 / 3) + $del_r - $del_b; }
  28992. elseif ($var_b == $var_max) { $h = (2 / 3) + $del_g - $del_r; };
  28993. if ($h < 0) { $h += 1; }
  28994. if ($h > 1) { $h -= 1; }
  28995. }
  28996. return array($h,$s,$l);
  28997. }
  28998. function hsl2rgb($h2,$s2,$l2) {
  28999. // Input is HSL value of complementary colour, held in $h2, $s, $l as fractions of 1
  29000. // Output is RGB in normal 255 255 255 format, held in $r, $g, $b
  29001. // Hue is converted using function hue_2_rgb, shown at the end of this code
  29002. if ($s2 == 0) {
  29003. $r = $l2 * 255;
  29004. $g = $l2 * 255;
  29005. $b = $l2 * 255;
  29006. }
  29007. else {
  29008. if ($l2 < 0.5) { $var_2 = $l2 * (1 + $s2); }
  29009. else { $var_2 = ($l2 + $s2) - ($s2 * $l2); }
  29010. $var_1 = 2 * $l2 - $var_2;
  29011. $r = round(255 * $this->hue_2_rgb($var_1,$var_2,$h2 + (1 / 3)));
  29012. $g = round(255 * $this->hue_2_rgb($var_1,$var_2,$h2));
  29013. $b = round(255 * $this->hue_2_rgb($var_1,$var_2,$h2 - (1 / 3)));
  29014. }
  29015. return array($r,$g,$b);
  29016. }
  29017. function hue_2_rgb($v1,$v2,$vh) {
  29018. // Function to convert hue to RGB, called from above
  29019. if ($vh < 0) { $vh += 1; };
  29020. if ($vh > 1) { $vh -= 1; };
  29021. if ((6 * $vh) < 1) { return ($v1 + ($v2 - $v1) * 6 * $vh); };
  29022. if ((2 * $vh) < 1) { return ($v2); };
  29023. if ((3 * $vh) < 2) { return ($v1 + ($v2 - $v1) * ((2 / 3 - $vh) * 6)); };
  29024. return ($v1);
  29025. }
  29026. function _invertColor($cor) {
  29027. if ($cor[0]==3 || $cor[0]==5) { // RGB
  29028. return array(3, (255-$cor[1]), (255-$cor[2]), (255-$cor[3]));
  29029. }
  29030. else if ($cor[0]==4 || $cor[0]==6) { // CMYK
  29031. return array(4, (100-$cor[1]), (100-$cor[2]), (100-$cor[3]), (100-$cor[4]));
  29032. }
  29033. else if ($cor[0]==1) { // Grayscale
  29034. return array(1, (255-$cor[1]));
  29035. }
  29036. // Cannot cope with non-RGB colors at present
  29037. die('Error in _invertColor - trying to invert non-RGB color');
  29038. }
  29039. function _colAtoString($cor) {
  29040. $s = '';
  29041. // mPDF 5.3.74
  29042. if ($cor{0}==1) $s = 'rgb('.ord($cor{1}).','.ord($cor{1}).','.ord($cor{1}).')';
  29043. else if ($cor{0}==2) $s = 'spot('.ord($cor{1}).','.ord($cor{2}).')'; // SPOT COLOR
  29044. else if ($cor{0}==3) $s = 'rgb('.ord($cor{1}).','.ord($cor{2}).','.ord($cor{3}).')';
  29045. else if ($cor{0}==4) $s = 'cmyk('.ord($cor{1}).','.ord($cor{2}).','.ord($cor{3}).','.ord($cor{4}).')';
  29046. else if ($cor{0}==5) $s = 'rgba('.ord($cor{1}).','.ord($cor{2}).','.ord($cor{3}).','.sprintf('%0.2F',ord($cor{4})/100).')';
  29047. else if ($cor{0}==6) $s = 'cmyka('.ord($cor{1}).','.ord($cor{2}).','.ord($cor{3}).','.ord($cor{4}).','.sprintf('%0.2F',ord($cor{5})/100).')';
  29048. return $s;
  29049. }
  29050. function ConvertSize($size=5,$maxsize=0,$fontsize=false,$usefontsize=true){
  29051. // usefontsize - setfalse for e.g. margins - will ignore fontsize for % values
  29052. // Depends of maxsize value to make % work properly. Usually maxsize == pagewidth
  29053. // For text $maxsize = Fontsize
  29054. // Setting e.g. margin % will use maxsize (pagewidth) and em will use fontsize
  29055. //Identify size (remember: we are using 'mm' units here)
  29056. $size = trim(strtolower($size));
  29057. if ( $size == 'thin' ) $size = 1*(25.4/$this->dpi); //1 pixel width for table borders
  29058. elseif ( stristr($size,'px') ) $size *= (25.4/$this->dpi); //pixels
  29059. elseif ( stristr($size,'cm') ) $size *= 10; //centimeters
  29060. elseif ( stristr($size,'mm') ) $size += 0; //millimeters
  29061. elseif ( stristr($size,'pt') ) $size *= 25.4/72; //72 pts/inch
  29062. elseif ( stristr($size,'em') ) {
  29063. $size += 0; //make "0.83em" become simply "0.83"
  29064. if ($fontsize) { $size *= $fontsize; }
  29065. else { $size *= $maxsize; }
  29066. }
  29067. elseif ( stristr($size,'%') ) {
  29068. $size += 0; //make "90%" become simply "90"
  29069. if ($fontsize && $usefontsize) { $size *= $fontsize/100; }
  29070. else { $size *= $maxsize/100; }
  29071. }
  29072. elseif ( stristr($size,'in') ) $size *= 25.4; //inches
  29073. elseif ( stristr($size,'pc') ) $size *= 38.1/9; //PostScript picas
  29074. elseif ( stristr($size,'ex') ) { // Approximates "ex" as half of font height
  29075. $size += 0; //make "3.5ex" become simply "3.5"
  29076. if ($fontsize) { $size *= $fontsize/2; }
  29077. else { $size *= $maxsize/2; }
  29078. }
  29079. elseif ( $size == 'medium' ) $size = 3*(25.4/$this->dpi); //3 pixel width for table borders
  29080. elseif ( $size == 'thick' ) $size = 5*(25.4/$this->dpi); //5 pixel width for table borders
  29081. elseif ($size == 'xx-small') {
  29082. if ($fontsize) { $size *= $fontsize*0.7; }
  29083. else { $size *= $maxsize*0.7; }
  29084. }
  29085. elseif ($size == 'x-small') {
  29086. if ($fontsize) { $size *= $fontsize*0.77; }
  29087. else { $size *= $maxsize*0.77; }
  29088. }
  29089. elseif ($size == 'small') {
  29090. if ($fontsize) { $size *= $fontsize*0.86; }
  29091. else { $size *= $maxsize*0.86; }
  29092. }
  29093. elseif ($size == 'medium') {
  29094. if ($fontsize) { $size *= $fontsize; }
  29095. else { $size *= $maxsize; }
  29096. }
  29097. elseif ($size == 'large') {
  29098. if ($fontsize) { $size *= $fontsize*1.2; }
  29099. else { $size *= $maxsize*1.2; }
  29100. }
  29101. elseif ($size == 'x-large') {
  29102. if ($fontsize) { $size *= $fontsize*1.5; }
  29103. else { $size *= $maxsize*1.5; }
  29104. }
  29105. elseif ($size == 'xx-large') {
  29106. if ($fontsize) { $size *= $fontsize*2; }
  29107. else { $size *= $maxsize*2; }
  29108. }
  29109. else $size *= (25.4/$this->dpi); //nothing == px
  29110. return $size;
  29111. }
  29112. function lesser_entity_decode($html) {
  29113. //supports the most used entity codes (only does ascii safe characters)
  29114. //$html = str_replace("&nbsp;"," ",$html); // mPDF 5.3.59
  29115. $html = str_replace("&lt;","<",$html);
  29116. $html = str_replace("&gt;",">",$html);
  29117. $html = str_replace("&apos;","'",$html);
  29118. $html = str_replace("&quot;",'"',$html);
  29119. $html = str_replace("&amp;","&",$html);
  29120. return $html;
  29121. }
  29122. function AdjustHTML($html, $tabSpaces=8) { // mPDF 5.3.99
  29123. //Try to make the html text more manageable (turning it into XHTML)
  29124. // mPDF 5.3.97
  29125. if (PHP_VERSION_ID < 50307) {
  29126. if (strlen($html) > 100000) {
  29127. if (PHP_VERSION_ID < 50200) $this->Error("The HTML code is more than 100,000 characters. You should use WriteHTML() with smaller string lengths.");
  29128. else ini_set("pcre.backtrack_limit","1000000");
  29129. }
  29130. }
  29131. /*-- ANNOTATIONS --*/
  29132. preg_match_all("/(<annotation.*?>)/si", $html, $m);
  29133. if (count($m[1])) {
  29134. for($i=0;$i<count($m[1]);$i++) {
  29135. $sub = preg_replace("/\n/si", "\xbb\xa4\xac", $m[1][$i]);
  29136. $html = preg_replace('/'.preg_quote($m[1][$i], '/').'/si', $sub, $html);
  29137. }
  29138. }
  29139. /*-- END ANNOTATIONS --*/
  29140. // mPDF 5.3.A6
  29141. preg_match_all("/(<svg.*?<\/svg>)/si", $html, $svgi);
  29142. if (count($svgi[0])) {
  29143. for($i=0;$i<count($svgi[0]);$i++) {
  29144. $file = _MPDF_TEMP_PATH.'_tempSVG'.RAND(1,10000).'_'.$i.'.svg';
  29145. //Save to local file
  29146. file_put_contents($file, $svgi[0][$i]);
  29147. $html = preg_replace('/'.preg_quote($svgi[0][$i], '/').'/si', '<img src="'.$file.'" />', $html);
  29148. }
  29149. }
  29150. //Remove javascript code from HTML (should not appear in the PDF file)
  29151. $html = preg_replace('/<script.*?<\/script>/is','',$html);
  29152. //Remove special comments
  29153. $html = preg_replace('/<!--mpdf/i','',$html);
  29154. $html = preg_replace('/mpdf-->/i','',$html);
  29155. //Remove comments from HTML (should not appear in the PDF file)
  29156. $html = preg_replace('/<!--.*?-->/s','',$html);
  29157. $html = preg_replace('/\f/','',$html); //replace formfeed by nothing
  29158. $html = preg_replace('/\r/','',$html); //replace carriage return by nothing
  29159. // Well formed XHTML end tags
  29160. $html = preg_replace('/<(br|hr)\/>/i',"<\\1 />",$html);
  29161. // Get rid of empty <thead></thead>
  29162. $html = preg_replace('/<thead>\s*<\/thead>/i','',$html);
  29163. $html = preg_replace('/<tfoot>\s*<\/tfoot>/i','',$html);
  29164. $html = preg_replace('/<table[^>]*>\s*<\/table>/i','',$html);
  29165. $html = preg_replace('/<tr>\s*<\/tr>/i','',$html);
  29166. // Remove spaces at end of table cells
  29167. $html = preg_replace("/[ ]+<\/t(d|h)/",'</t\\1',$html);
  29168. $html = preg_replace("/[ ]*<dottab\s*[\/]*>[ ]*/",'<dottab />',$html);
  29169. // Concatenates any Substitute characters from symbols/dingbats
  29170. $html = str_replace('</tts><tts>','|',$html);
  29171. $html = str_replace('</ttz><ttz>','|',$html);
  29172. $html = str_replace('</tta><tta>','|',$html);
  29173. $html = preg_replace('/<br \/>\s*/is',"<br />",$html); // mPDF 5.3.07
  29174. // Preserve '\n's in content between the tags <pre> and </pre>
  29175. if (preg_match('/<pre/',$html)) {
  29176. $html_a = preg_split('/(\<\/?pre[^\>]*\>)/', $html, -1, 2);
  29177. $h = array();
  29178. $c=0;
  29179. foreach($html_a AS $s) {
  29180. if ($c>1 && preg_match('/^<\/pre/i',$s)) { $c--; $s=preg_replace('/<\/pre/i','</innerpre',$s); }
  29181. else if ($c>0 && preg_match('/^<pre/i',$s)) { $c++; $s=preg_replace('/<pre/i','<innerpre',$s); }
  29182. else if (preg_match('/^<pre/i',$s)) { $c++; }
  29183. else if (preg_match('/^<\/pre/i',$s)) { $c--; }
  29184. array_push($h, $s);
  29185. }
  29186. $html = implode("", $h);
  29187. }
  29188. $thereispre = preg_match_all('#<pre(.*?)>(.*?)</pre>#si',$html,$temp);
  29189. // Preserve '\n's in content between the tags <textarea> and </textarea>
  29190. $thereistextarea = preg_match_all('#<textarea(.*?)>(.*?)</textarea>#si',$html,$temp2);
  29191. $html = preg_replace('/[\n]/',' ',$html); //replace linefeed by spaces
  29192. $html = preg_replace('/[\t]/',' ',$html); //replace tabs by spaces
  29193. // Converts < to &lt; when not a tag
  29194. $html = preg_replace('/<([^!\/a-zA-Z])/i','&lt;\\1',$html);
  29195. $html = preg_replace("/[ ]+/",' ',$html);
  29196. $html = preg_replace('/\/li>\s+<\/(u|o)l/i','/li></\\1l',$html);
  29197. $html = preg_replace('/\/(u|o)l>\s+<\/li/i','/\\1l></li',$html);
  29198. $html = preg_replace('/\/li>\s+<\/(u|o)l/i','/li></\\1l',$html);
  29199. $html = preg_replace('/\/li>\s+<li/i','/li><li',$html);
  29200. $html = preg_replace('/<(u|o)l([^>]*)>[ ]+/i','<\\1l\\2>',$html);
  29201. $html = preg_replace('/[ ]+<(u|o)l/i','<\\1l',$html);
  29202. $iterator = 0;
  29203. while($thereispre) //Recover <pre attributes>content</pre>
  29204. {
  29205. $temp[2][$iterator] = preg_replace("/^([^\n\t]*?)\t/me", "stripslashes('\\1') . str_repeat(' ', ( $tabSpaces - (mb_strlen(stripslashes('\\1')) % $tabSpaces)) )",$temp[2][$iterator]);
  29206. $temp[2][$iterator] = preg_replace('/\t/',str_repeat(" ",$tabSpaces),$temp[2][$iterator]);
  29207. $temp[2][$iterator] = preg_replace('/\n/',"<br />",$temp[2][$iterator]);
  29208. $temp[2][$iterator] = str_replace('\\',"\\\\",$temp[2][$iterator]); // mPDF 5.3.88
  29209. $html = preg_replace('#<pre(.*?)>(.*?)</pre>#si','<erp'.$temp[1][$iterator].'>'.$temp[2][$iterator].'</erp>',$html,1);
  29210. $thereispre--;
  29211. $iterator++;
  29212. }
  29213. $iterator = 0;
  29214. while($thereistextarea) //Recover <textarea attributes>content</textarea>
  29215. {
  29216. // $temp2[2][$iterator] = preg_replace('/&/',"&amp;",$temp2[2][$iterator]); // mPDF 5.3.59
  29217. // $temp2[2][$iterator] = preg_replace('/</',"&lt;",$temp2[2][$iterator]); // mPDF 5.3.59
  29218. $temp2[2][$iterator] = preg_replace('/\t/',str_repeat(" ",$tabSpaces),$temp2[2][$iterator]);
  29219. $temp2[2][$iterator] = str_replace('\\',"\\\\",$temp2[2][$iterator]); // mPDF 5.3.88
  29220. // $temp2[2][$iterator] = preg_replace('/[ ]/',"&nbsp;",$temp2[2][$iterator]); // mPDF 5.3.59
  29221. $html = preg_replace('#<textarea(.*?)>(.*?)</textarea>#si','<aeratxet'.$temp2[1][$iterator].'>'.trim($temp2[2][$iterator]) .'</aeratxet>',$html,1);
  29222. $thereistextarea--;
  29223. $iterator++;
  29224. }
  29225. //Restore original tag names
  29226. $html = str_replace("<erp","<pre",$html);
  29227. $html = str_replace("</erp>","</pre>",$html);
  29228. $html = str_replace("<aeratxet","<textarea",$html);
  29229. $html = str_replace("</aeratxet>","</textarea>",$html);
  29230. $html = str_replace("</innerpre","</pre",$html);
  29231. $html = str_replace("<innerpre","<pre",$html);
  29232. $html = preg_replace('/<textarea([^>]*)><\/textarea>/si','<textarea\\1> </textarea>',$html);
  29233. // mPDF 5.3.56
  29234. $html = preg_replace('/(<table[^>]*>)\s*(<caption)(.*?<\/caption>)(.*?<\/table>)/si','\\2 position="top"\\3\\1\\4\\2 position="bottom"\\3',$html); // *TABLES*
  29235. $html = preg_replace('/<(h[1-6])([^>]*)(>(?:(?!h[1-6]).)*?<\/\\1>\s*<table)/si','<\\1\\2 keep-with-table="1"\\3',$html); // *TABLES*
  29236. $html = preg_replace("/\xbb\xa4\xac/", "\n", $html);
  29237. return $html;
  29238. }
  29239. /*-- LISTS --*/
  29240. function dec2other($num, $cp) {
  29241. $nstr = (string) $num;
  29242. $rnum = '';
  29243. for ($i=0;$i<strlen($nstr);$i++) {
  29244. if ($this->_charDefined($this->CurrentFont['cw'],$cp+intval($nstr[$i]))) { // contains arabic-indic numbers
  29245. $rnum .= code2utf($cp+intval($nstr[$i]));
  29246. }
  29247. else { $rnum .= $nstr[$i]; }
  29248. }
  29249. return $rnum;
  29250. }
  29251. function dec2alpha($valor,$toupper="true"){
  29252. // returns a string from A-Z to AA-ZZ to AAA-ZZZ
  29253. // OBS: A = 65 ASCII TABLE VALUE
  29254. if (($valor < 1) || ($valor > 18278)) return "?"; //supports 'only' up to 18278
  29255. $c1 = $c2 = $c3 = '';
  29256. if ($valor > 702) // 3 letters (up to 18278)
  29257. {
  29258. $c1 = 65 + floor(($valor-703)/676);
  29259. $c2 = 65 + floor((($valor-703)%676)/26);
  29260. $c3 = 65 + floor((($valor-703)%676)%26);
  29261. }
  29262. elseif ($valor > 26) // 2 letters (up to 702)
  29263. {
  29264. $c1 = (64 + (int)(($valor-1) / 26));
  29265. $c2 = (64 + (int)($valor % 26));
  29266. if ($c2 == 64) $c2 += 26;
  29267. }
  29268. else // 1 letter (up to 26)
  29269. {
  29270. $c1 = (64 + $valor);
  29271. }
  29272. $alpha = chr($c1);
  29273. if ($c2 != '') $alpha .= chr($c2);
  29274. if ($c3 != '') $alpha .= chr($c3);
  29275. if (!$toupper) $alpha = strtolower($alpha);
  29276. return $alpha;
  29277. }
  29278. function dec2roman($valor,$toupper=true){
  29279. //returns a string as a roman numeral
  29280. $r1=$r2=$r3=$r4='';
  29281. if (($valor >= 5000) || ($valor < 1)) return "?"; //supports 'only' up to 4999
  29282. $aux = (int)($valor/1000);
  29283. if ($aux!==0)
  29284. {
  29285. $valor %= 1000;
  29286. while($aux!==0)
  29287. {
  29288. $r1 .= "M";
  29289. $aux--;
  29290. }
  29291. }
  29292. $aux = (int)($valor/100);
  29293. if ($aux!==0)
  29294. {
  29295. $valor %= 100;
  29296. switch($aux){
  29297. case 3: $r2="C";
  29298. case 2: $r2.="C";
  29299. case 1: $r2.="C"; break;
  29300. case 9: $r2="CM"; break;
  29301. case 8: $r2="C";
  29302. case 7: $r2.="C";
  29303. case 6: $r2.="C";
  29304. case 5: $r2="D".$r2; break;
  29305. case 4: $r2="CD"; break;
  29306. default: break;
  29307. }
  29308. }
  29309. $aux = (int)($valor/10);
  29310. if ($aux!==0)
  29311. {
  29312. $valor %= 10;
  29313. switch($aux){
  29314. case 3: $r3="X";
  29315. case 2: $r3.="X";
  29316. case 1: $r3.="X"; break;
  29317. case 9: $r3="XC"; break;
  29318. case 8: $r3="X";
  29319. case 7: $r3.="X";
  29320. case 6: $r3.="X";
  29321. case 5: $r3="L".$r3; break;
  29322. case 4: $r3="XL"; break;
  29323. default: break;
  29324. }
  29325. }
  29326. switch($valor){
  29327. case 3: $r4="I";
  29328. case 2: $r4.="I";
  29329. case 1: $r4.="I"; break;
  29330. case 9: $r4="IX"; break;
  29331. case 8: $r4="I";
  29332. case 7: $r4.="I";
  29333. case 6: $r4.="I";
  29334. case 5: $r4="V".$r4; break;
  29335. case 4: $r4="IV"; break;
  29336. default: break;
  29337. }
  29338. $roman = $r1.$r2.$r3.$r4;
  29339. if (!$toupper) $roman = strtolower($roman);
  29340. return $roman;
  29341. }
  29342. /*-- END LISTS --*/
  29343. //===========================
  29344. /*-- IMPORTS --*/
  29345. function SetImportUse() {
  29346. $this->enableImports = true;
  29347. ini_set('auto_detect_line_endings',1);
  29348. require_once(_MPDF_PATH."mpdfi/pdf_context.php");
  29349. require_once(_MPDF_PATH."mpdfi/pdf_parser.php");
  29350. require_once(_MPDF_PATH."mpdfi/fpdi_pdf_parser.php");
  29351. }
  29352. // from mPDFI
  29353. function hex2str($hex) {
  29354. return pack("H*", str_replace(array("\r","\n"," "),"", $hex));
  29355. }
  29356. function str2hex($str) {
  29357. return current(unpack("H*",$str));
  29358. }
  29359. function pdf_write_value(&$value) {
  29360. switch ($value[0]) {
  29361. case PDF_TYPE_NUMERIC :
  29362. case PDF_TYPE_TOKEN :
  29363. // A numeric value or a token.
  29364. // Simply output them
  29365. $this->_out($value[1]." ", false);
  29366. break;
  29367. case PDF_TYPE_ARRAY :
  29368. // An array. Output the proper
  29369. // structure and move on.
  29370. $this->_out("[",false);
  29371. for ($i = 0; $i < count($value[1]); $i++) {
  29372. $this->pdf_write_value($value[1][$i]);
  29373. }
  29374. $this->_out("]");
  29375. break;
  29376. case PDF_TYPE_DICTIONARY :
  29377. // A dictionary.
  29378. $this->_out("<<",false);
  29379. reset ($value[1]);
  29380. while (list($k, $v) = each($value[1])) {
  29381. $this->_out($k . " ",false);
  29382. $this->pdf_write_value($v);
  29383. }
  29384. $this->_out(">>");
  29385. break;
  29386. case PDF_TYPE_OBJREF :
  29387. // An indirect object reference
  29388. // Fill the object stack if needed
  29389. $cpfn =& $this->current_parser->filename;
  29390. if (!isset($this->_don_obj_stack[$cpfn][$value[1]])) {
  29391. $this->_newobj(false,true);
  29392. $this->_obj_stack[$cpfn][$value[1]] = array($this->n, $value);
  29393. $this->_don_obj_stack[$cpfn][$value[1]] = array($this->n, $value);
  29394. }
  29395. $objid = $this->_don_obj_stack[$cpfn][$value[1]][0];
  29396. $this->_out("{$objid} 0 R"); //{$value[2]}
  29397. break;
  29398. case PDF_TYPE_STRING :
  29399. if ($this->encrypted) {
  29400. $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
  29401. $value[1] = $this->_escape($value[1]);
  29402. }
  29403. // A string.
  29404. $this->_out('('.$value[1].')');
  29405. break;
  29406. case PDF_TYPE_STREAM :
  29407. // A stream. First, output the
  29408. // stream dictionary, then the
  29409. // stream data itself.
  29410. $this->pdf_write_value($value[1]);
  29411. if ($this->encrypted) {
  29412. $value[2][1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[2][1]);
  29413. }
  29414. $this->_out("stream");
  29415. $this->_out($value[2][1]);
  29416. $this->_out("endstream");
  29417. break;
  29418. case PDF_TYPE_HEX :
  29419. if ($this->encrypted) {
  29420. $value[1] = $this->hex2str($value[1]);
  29421. $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
  29422. // remake hexstring of encrypted string
  29423. $value[1] = $this->str2hex($value[1]);
  29424. }
  29425. $this->_out("<".$value[1].">");
  29426. break;
  29427. case PDF_TYPE_NULL :
  29428. // The null object.
  29429. $this->_out("null");
  29430. break;
  29431. }
  29432. }
  29433. // ========== OVERWRITE SEARCH STRING IN A PDF FILE ================
  29434. function OverWrite($file_in, $search, $replacement, $dest="D", $file_out="mpdf" ) {
  29435. $pdf = file_get_contents($file_in);
  29436. if (!is_array($search)) {
  29437. $x = $search;
  29438. $search = array($x);
  29439. }
  29440. if (!is_array($replacement)) {
  29441. $x = $replacement;
  29442. $search = array($x);
  29443. }
  29444. if (!$this->onlyCoreFonts && !$this->usingCoreFont) {
  29445. foreach($search AS $k=>$val) {
  29446. $search[$k] = $this->UTF8ToUTF16BE($search[$k] , false);
  29447. $search[$k] = $this->_escape($search[$k]);
  29448. $replacement[$k] = $this->UTF8ToUTF16BE($replacement[$k], false);
  29449. $replacement[$k] = $this->_escape($replacement[$k]);
  29450. }
  29451. }
  29452. else {
  29453. foreach($replacement AS $k=>$val) {
  29454. $replacement[$k] = mb_convert_encoding($replacement[$k],$this->mb_enc,'utf-8');
  29455. $replacement[$k] = $this->_escape($replacement[$k]);
  29456. }
  29457. }
  29458. // Get xref into array
  29459. $xref = array();
  29460. preg_match("/xref\n0 (\d+)\n(.*?)\ntrailer/s",$pdf,$m);
  29461. $xref_objid = $m[1];
  29462. preg_match_all('/(\d{10}) (\d{5}) (f|n)/',$m[2],$x);
  29463. for($i=0; $i<count($x[0]); $i++) {
  29464. $xref[] = array(intval($x[1][$i]), $x[2][$i], $x[3][$i]);
  29465. }
  29466. $changes = array();
  29467. preg_match("/<<\s*\/Type\s*\/Pages\s*\/Kids\s*\[(.*?)\]\s*\/Count/s",$pdf,$m);
  29468. preg_match_all("/(\d+) 0 R /s",$m[1],$o);
  29469. $objlist = $o[1];
  29470. foreach($objlist AS $obj) {
  29471. if ($this->compress) {
  29472. preg_match("/".($obj+1)." 0 obj\n<<\s*\/Filter\s*\/FlateDecode\s*\/Length (\d+)>>\nstream\n(.*?)\nendstream\n/s",$pdf,$m);
  29473. }
  29474. else {
  29475. preg_match("/".($obj+1)." 0 obj\n<<\s*\/Length (\d+)>>\nstream\n(.*?)\nendstream\n/s",$pdf,$m);
  29476. }
  29477. $s = $m[2];
  29478. if (!$s) { continue; }
  29479. $oldlen = $m[1];
  29480. if ($this->encrypted) {
  29481. $s = $this->_RC4($this->_objectkey($obj+1), $s);
  29482. }
  29483. if ($this->compress) {
  29484. $s = gzuncompress($s);
  29485. }
  29486. foreach($search AS $k=>$val) {
  29487. $s = str_replace($search[$k],$replacement[$k],$s);
  29488. }
  29489. if ($this->compress) {
  29490. $s = gzcompress($s);
  29491. }
  29492. if ($this->encrypted) {
  29493. $s = $this->_RC4($this->_objectkey($obj+1), $s);
  29494. }
  29495. $newlen = strlen($s);
  29496. $changes[($xref[$obj+1][0])] = ($newlen - $oldlen) + (strlen($newlen) - strlen($oldlen ));
  29497. if ($this->compress) {
  29498. $newstr = ($obj+1) . " 0 obj\n<</Filter /FlateDecode /Length ".$newlen.">>\nstream\n".$s."\nendstream\n";
  29499. }
  29500. else {
  29501. $newstr = ($obj+1) . " 0 obj\n<</Length ".$newlen.">>\nstream\n".$s."\nendstream\n";
  29502. }
  29503. $pdf = str_replace($m[0],$newstr,$pdf);
  29504. }
  29505. // Update xref in PDF
  29506. krsort($changes);
  29507. $newxref = "xref\n0 ".$xref_objid."\n";
  29508. foreach($xref AS $v) {
  29509. foreach($changes AS $ck => $cv) {
  29510. if ($v[0] > $ck) { $v[0] += $cv; }
  29511. }
  29512. $newxref .= sprintf('%010d',$v[0]) . ' ' . $v[1] . ' ' .$v[2] . " \n";
  29513. }
  29514. $newxref .= "trailer";
  29515. $pdf = preg_replace("/xref\n0 \d+\n.*?\ntrailer/s",$newxref,$pdf);
  29516. // Update startxref in PDF
  29517. preg_match("/startxref\n(\d+)\n%%EOF/s", $pdf, $m);
  29518. $startxref = $m[1];
  29519. $startxref += array_sum($changes);
  29520. $pdf = preg_replace("/startxref\n(\d+)\n%%EOF/s","startxref\n".$startxref."\n%%EOF",$pdf);
  29521. // OUTPUT
  29522. switch($dest) {
  29523. case 'I':
  29524. //Send to standard output
  29525. if(isset($_SERVER['SERVER_NAME']))
  29526. {
  29527. //We send to a browser
  29528. Header('Content-Type: application/pdf');
  29529. Header('Content-Length: '.strlen($pdf));
  29530. Header('Content-disposition: inline; filename='.$file_out);
  29531. }
  29532. echo $pdf;
  29533. break;
  29534. case 'F':
  29535. //Save to local file
  29536. if (!$file_out) { $file_out = 'mpdf.pdf'; }
  29537. $f=fopen($file_out,'wb');
  29538. if(!$f) die('Unable to create output file: '.$file_out);
  29539. fwrite($f,$pdf,strlen($pdf));
  29540. fclose($f);
  29541. break;
  29542. case 'S':
  29543. //Return as a string
  29544. return $pdf;
  29545. case 'D':
  29546. default:
  29547. //Download file
  29548. if(isset($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
  29549. Header('Content-Type: application/force-download');
  29550. else
  29551. Header('Content-Type: application/octet-stream');
  29552. Header('Content-Length: '.strlen($pdf));
  29553. Header('Content-disposition: attachment; filename='.$file_out);
  29554. echo $pdf;
  29555. break;
  29556. }
  29557. }
  29558. function GetTemplateSize($tplidx, $_w=0, $_h=0) {
  29559. if (!$this->tpls[$tplidx])
  29560. return false;
  29561. $w = $this->tpls[$tplidx]['box']['w'];
  29562. $h = $this->tpls[$tplidx]['box']['h'];
  29563. if ($_w == 0 and $_h == 0) {
  29564. $_w = $w;
  29565. $_h = $h;
  29566. }
  29567. if($_w==0)
  29568. $_w=$_h*$w/$h;
  29569. if($_h==0)
  29570. $_h=$_w*$h/$w;
  29571. return array("w" => $_w, "h" => $_h);
  29572. }
  29573. // Thumbnails
  29574. function Thumbnail($file, $npr=3, $spacing=10) { //$npr = number per row
  29575. $w = (($this->pgwidth + $spacing)/$npr) - $spacing;
  29576. $oldlinewidth = $this->LineWidth;
  29577. $this->SetLineWidth(0.02);
  29578. $this->SetDColor($this->ConvertColor(0));
  29579. $h = 0;
  29580. $maxh = 0;
  29581. $x = $_x = $this->lMargin;
  29582. $_y = $this->tMargin;
  29583. if ($this->y==0) { $y = $_y; } else { $y = $this->y; }
  29584. $pagecount = $this->SetSourceFile($file);
  29585. for ($n = 1; $n <= $pagecount; $n++) {
  29586. $tplidx = $this->ImportPage($n);
  29587. $size = $this->useTemplate($tplidx, $x, $y, $w);
  29588. $this->Rect($x, $y, $size['w'], $size['h']);
  29589. $h = max($h, $size['h']);
  29590. $maxh = max($h, $maxh);
  29591. if ($n % $npr == 0) {
  29592. if (($y + $h + $spacing + $maxh)>$this->PageBreakTrigger && $n != $pagecount) {
  29593. $this->AddPage();
  29594. $x = $_x;
  29595. $y = $_y;
  29596. }
  29597. else {
  29598. $y += $h+$spacing ;
  29599. $x = $_x;
  29600. $h = 0;
  29601. }
  29602. }
  29603. else {
  29604. $x += $w+$spacing ;
  29605. }
  29606. }
  29607. $this->SetLineWidth($oldlinewidth);
  29608. }
  29609. function SetSourceFile($filename) {
  29610. $this->current_filename = $filename;
  29611. $fn =& $this->current_filename;
  29612. if (!isset($this->parsers[$fn]))
  29613. // $this->parsers[$fn] =& new fpdi_pdf_parser($fn,$this);
  29614. $this->parsers[$fn] = new fpdi_pdf_parser($fn,$this);
  29615. if (!$this->parsers[$fn]->success) {
  29616. $this->Error($this->parsers[$fn]->errormsg); // Delete this line to return false on fail
  29617. return false;
  29618. }
  29619. $this->current_parser =& $this->parsers[$fn];
  29620. return $this->parsers[$fn]->getPageCount();
  29621. }
  29622. function ImportPage($pageno=1, $crop_x=null, $crop_y=null, $crop_w=0, $crop_h=0, $boxName='/CropBox') {
  29623. $fn =& $this->current_filename;
  29624. $parser =& $this->parsers[$fn];
  29625. $parser->setPageno($pageno);
  29626. $this->tpl++;
  29627. $this->tpls[$this->tpl] = array();
  29628. $tpl =& $this->tpls[$this->tpl];
  29629. $tpl['parser'] =& $parser;
  29630. $tpl['resources'] = $parser->getPageResources();
  29631. $tpl['buffer'] = $parser->getContent();
  29632. if (!in_array($boxName, $parser->availableBoxes))
  29633. return $this->Error(sprintf("Unknown box: %s", $boxName));
  29634. $pageboxes = $parser->getPageBoxes($pageno);
  29635. /**
  29636. * MediaBox
  29637. * CropBox: Default -> MediaBox
  29638. * BleedBox: Default -> CropBox
  29639. * TrimBox: Default -> CropBox
  29640. * ArtBox: Default -> CropBox
  29641. */
  29642. if (!isset($pageboxes[$boxName]) && ($boxName == "/BleedBox" || $boxName == "/TrimBox" || $boxName == "/ArtBox"))
  29643. $boxName = "/CropBox";
  29644. if (!isset($pageboxes[$boxName]) && $boxName == "/CropBox")
  29645. $boxName = "/MediaBox";
  29646. if (!isset($pageboxes[$boxName]))
  29647. return false;
  29648. $box = $pageboxes[$boxName];
  29649. $tpl['box'] = $box;
  29650. // To build an array that can be used by useTemplate()
  29651. $this->tpls[$this->tpl] = array_merge($this->tpls[$this->tpl],$box);
  29652. // An imported page will start at 0,0 everytime. Translation will be set in _putformxobjects()
  29653. $tpl['x'] = 0;
  29654. $tpl['y'] = 0;
  29655. $tpl['w'] = $tpl['box']['w'] ;
  29656. $tpl['h'] = $tpl['box']['h'] ;
  29657. if ($crop_w) { $tpl['box']['w'] = $crop_w; }
  29658. if ($crop_h) { $tpl['box']['h'] = $crop_h; }
  29659. if (isset($crop_x)) { $tpl['box']['x'] = $crop_x; }
  29660. if (isset($crop_y)) {$tpl['box']['y'] = $tpl['h'] - $crop_y - $crop_h ; }
  29661. $page =& $parser->pages[$parser->pageno];
  29662. // fix for rotated pages
  29663. $rotation = $parser->getPageRotation($pageno);
  29664. if (isset($rotation[1]) && ($angle = $rotation[1] % 360) != 0 && $tpl['box']['w'] == $tpl['w']) {
  29665. $steps = $angle / 90;
  29666. $_w = $tpl['w'];
  29667. $_h = $tpl['h'];
  29668. $tpl['w'] = $steps % 2 == 0 ? $_w : $_h;
  29669. $tpl['h'] = $steps % 2 == 0 ? $_h : $_w;
  29670. if ($steps % 2 != 0) {
  29671. $x = $y = ($steps == 1 || $steps == -3) ? $tpl['h'] : $tpl['w'];
  29672. } else {
  29673. $x = $tpl['w'];
  29674. $y = $tpl['h'];
  29675. }
  29676. $cx=($x/2+$tpl['box']['x'])*_MPDFK;
  29677. $cy=($y/2+$tpl['box']['y'])*_MPDFK;
  29678. $angle*=-1;
  29679. $angle*=M_PI/180;
  29680. $c=cos($angle);
  29681. $s=sin($angle);
  29682. $tpl['box']['w'] = $tpl['w'] ;
  29683. $tpl['box']['h'] = $tpl['h'] ;
  29684. $tpl['buffer'] = sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm %s Q',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy, $tpl['buffer']);
  29685. }
  29686. return $this->tpl;
  29687. }
  29688. function UseTemplate($tplidx, $_x=null, $_y=null, $_w=0, $_h=0) {
  29689. if (!isset($this->tpls[$tplidx]))
  29690. $this->Error("Template does not exist!");
  29691. if($this->state==0) { $this->AddPage(); }
  29692. $out = 'q 0 J 1 w 0 j 0 G'."\n"; // reset standard values
  29693. $x = $this->tpls[$tplidx]['x'];
  29694. $y = $this->tpls[$tplidx]['y'];
  29695. $w = $this->tpls[$tplidx]['w'];
  29696. $h = $this->tpls[$tplidx]['h'];
  29697. if ($_x == null) { $_x = $x; }
  29698. if ($_y == null) { $_y = $y; }
  29699. if ($_x === -1) { $_x = $this->x; }
  29700. if ($_y === -1) { $_y = $this->y; }
  29701. $wh = $this->getTemplateSize($tplidx,$_w,$_h);
  29702. $_w = $wh['w'];
  29703. $_h = $wh['h'];
  29704. $out .= sprintf("q %.4F 0 0 %.4F %.2F %.2F cm", ($_w/$this->tpls[$tplidx]['box']['w']), ($_h/$this->tpls[$tplidx]['box']['h']), $_x*_MPDFK, ($this->h-($_y+$_h))*_MPDFK)."\n";
  29705. $out .= $this->tplprefix.$tplidx." Do Q\n";
  29706. $s = array("w" => $_w, "h" => $_h);
  29707. $out .= "Q\n";
  29708. $this->pages[$this->page] = $out . $this->pages[$this->page];
  29709. return $s;
  29710. }
  29711. function SetPageTemplate($tplidx='') {
  29712. if (!isset($this->tpls[$tplidx])) {
  29713. $this->pageTemplate = '';
  29714. return false;
  29715. }
  29716. $this->pageTemplate = $tplidx;
  29717. }
  29718. function SetDocTemplate($file='', $continue=0) {
  29719. $this->docTemplate = $file;
  29720. $this->docTemplateContinue = $continue;
  29721. }
  29722. /*-- END IMPORTS --*/
  29723. /* ---------------------------------------------- */
  29724. /* ---------------------------------------------- */
  29725. /* ---------------------------------------------- */
  29726. /* ---------------------------------------------- */
  29727. /* ---------------------------------------------- */
  29728. // JAVASCRIPT
  29729. function _set_object_javascript ($string) {
  29730. $this->_newobj();
  29731. $this->_out('<<');
  29732. $this->_out('/S /JavaScript ');
  29733. $this->_out('/JS '.$this->_textstring($string));
  29734. $this->_out('>>');
  29735. $this->_out('endobj');
  29736. }
  29737. function SetJS($script) {
  29738. $this->js = $script;
  29739. }
  29740. }//end of Class
  29741. ?>